1# Allow Location Descriptions on the DWARF Expression Stack <!-- omit in toc -->
2
3- [1. Extension](#extension)
4- [2. Heterogeneous Computing Devices](#heterogeneous-computing-devices)
5- [3. DWARF 5](#dwarf-5)
6  - [3.1 How DWARF Maps Source Language To Hardware](#how-dwarf-maps-source-language-to-hardware)
7  - [3.2 Examples](#examples)
8    - [3.2.1 Dynamic Array Size](#dynamic-array-size)
9    - [3.2.2 Variable Location in Register](#variable-location-in-register)
10    - [3.2.3 Variable Location in Memory](#variable-location-in-memory)
11    - [3.2.4 Variable Spread Across Different Locations](#variable-spread-across-different-locations)
12    - [3.2.5 Offsetting a Composite Location](#offsetting-a-composite-location)
13  - [3.3 Limitations](#limitations)
14- [4. Extension Solution](#extension-solution)
15  - [4.1 Location Description](#location-description)
16  - [4.2 Stack Location Description Operations](#stack-location-description-operations)
17  - [4.3 Examples](#examples-1)
18    - [4.3.1 Source Language Variable Spilled to Part of a Vector Register](#source-language-variable-spilled-to-part-of-a-vector-register)
19    - [4.3.2 Source Language Variable Spread Across Multiple Vector Registers](#source-language-variable-spread-across-multiple-vector-registers)
20    - [4.3.3 Source Language Variable Spread Across Multiple Kinds of Locations](#source-language-variable-spread-across-multiple-kinds-of-locations)
21    - [4.3.4 Address Spaces](#address-spaces)
22    - [4.3.5 Bit Offsets](#bit-offsets)
23  - [4.4 Call Frame Information (CFI)](#call-frame-information-cfi)
24  - [4.5 Objects Not In Byte Aligned Global Memory](#objects-not-in-byte-aligned-global-memory)
25  - [4.6 Higher Order Operations](#higher-order-operations)
26  - [4.7 Objects In Multiple Places](#objects-in-multiple-places)
27- [5. Conclusion](#conclusion)
28- [A. Changes to DWARF Debugging Information Format Version 5](#a-changes-to-dwarf-debugging-information-format-version-5)
29  - [A.2 General Description](#a-2-general-description)
30    - [A.2.5 DWARF Expressions](#a-2-5-dwarf-expressions)
31      - [A.2.5.1 DWARF Expression Evaluation Context](#a-2-5-1-dwarf-expression-evaluation-context)
32      - [A.2.5.2 DWARF Expression Value](#a-2-5-2-dwarf-expression-value)
33      - [A.2.5.3 DWARF Location Description](#a-2-5-3-dwarf-location-description)
34      - [A.2.5.4 DWARF Operation Expressions](#a-2-5-4-dwarf-operation-expressions)
35        - [A.2.5.4.1 Stack Operations](#a-2-5-4-1-stack-operations)
36        - [A.2.5.4.2 Control Flow Operations](#a-2-5-4-2-control-flow-operations)
37        - [A.2.5.4.3 Value Operations](#a-2-5-4-3-value-operations)
38          - [A.2.5.4.3.1 Literal Operations](#a-2-5-4-3-1-literal-operations)
39          - [A.2.5.4.3.2 Arithmetic and Logical Operations](#a-2-5-4-3-2-arithmetic-and-logical-operations)
40          - [A.2.5.4.3.3 Type Conversion Operations](#a-2-5-4-3-3-type-conversion-operations)
41          - [A.2.5.4.3.4 Special Value Operations](#a-2-5-4-3-4-special-value-operations)
42        - [A.2.5.4.4 Location Description Operations](#a-2-5-4-4-location-description-operations)
43          - [A.2.5.4.4.1 General Location Description Operations](#a-2-5-4-4-1-general-location-description-operations)
44          - [A.2.5.4.4.2 Undefined Location Description Operations](#a-2-5-4-4-2-undefined-location-description-operations)
45          - [A.2.5.4.4.3 Memory Location Description Operations](#a-2-5-4-4-3-memory-location-description-operations)
46          - [A.2.5.4.4.4 Register Location Description Operations](#a-2-5-4-4-4-register-location-description-operations)
47          - [A.2.5.4.4.5 Implicit Location Description Operations](#a-2-5-4-4-5-implicit-location-description-operations)
48          - [A.2.5.4.4.6 Composite Location Description Operations](#a-2-5-4-4-6-composite-location-description-operations)
49      - [A.2.5.5 DWARF Location List Expressions](#a-2-5-5-dwarf-location-list-expressions)
50  - [A.3 Program Scope Entries](#a-3-program-scope-entries)
51    - [A.3.3 Subroutine and Entry Point Entries](#a-3-3-subroutine-and-entry-point-entries)
52      - [A.3.3.5 Low-Level Information](#a-3-3-5-low-level-information)
53    - [A.3.4 Call Site Entries and Parameters](#a-3-4-call-site-entries-and-parameters)
54      - [A.3.4.2 Call Site Parameters](#a-3-4-2-call-site-parameters)
55    - [A.3.5 Lexical Block Entries](#a-3-5-lexical-block-entries)
56  - [A.4 Data Object and Object List Entries](#a-4-data-object-and-object-list-entries)
57    - [A.4.1 Data Object Entries](#a-4-1-data-object-entries)
58  - [A.5 Type Entries](#a-5-type-entries)
59    - [A.5.7 Structure, Union, Class and Interface Type Entries](#a-5-7-structure-union-class-and-interface-type-entries)
60      - [A.5.7.3 Derived or Extended Structures, Classes and Interfaces](#a-5-7-3-derived-or-extended-structures-classes-and-interfaces)
61      - [A.5.7.8 Member Function Entries](#a-5-7-8-member-function-entries)
62    - [A.5.14 Pointer to Member Type Entries](#a-5-14-pointer-to-member-type-entries)
63    - [A.5.16 Dynamic Type Entries](#a-5-16-dynamic-type-entries)
64  - [A.6 Other Debugging Information](#a-6-other-debugging-information)
65    - [A.6.2 Line Number Information](#a-6-2-line-number-information)
66    - [A.6.4 Call Frame Information](#a-6-4-call-frame-information)
67      - [A.6.4.1 Structure of Call Frame Information](#a-6-4-1-structure-of-call-frame-information)
68      - [A.6.4.2 Call Frame Instructions](#a-6-4-2-call-frame-instructions)
69        - [A.6.4.2.1 Row Creation Instructions](#a-6-4-2-1-row-creation-instructions)
70        - [A.6.4.2.2 CFA Definition Instructions](#a-6-4-2-2-cfa-definition-instructions)
71        - [A.6.4.2.3 Register Rule Instructions](#a-6-4-2-3-register-rule-instructions)
72        - [A.6.4.2.4 Row State Instructions](#a-6-4-2-4-row-state-instructions)
73        - [A.6.4.2.5 Padding Instruction](#a-6-4-2-5-padding-instruction)
74      - [A.6.4.3 Call Frame Instruction Usage](#a-6-4-3-call-frame-instruction-usage)
75      - [A.6.4.4 Call Frame Calling Address](#a-6-4-4-call-frame-calling-address)
76  - [A.7 Data Representation](#a-7-data-representation)
77    - [A.7.4 32-Bit and 64-Bit DWARF Formats](#a-7-4-32-bit-and-64-bit-dwarf-formats)
78    - [A.7.5 Format of Debugging Information](#a-7-5-format-of-debugging-information)
79      - [A.7.5.5 Classes and Forms](#a-7-5-5-classes-and-forms)
80    - [A.7.7 DWARF Expressions](#a-7-7-dwarf-expressions)
81      - [A.7.7.1 Operation Expressions](#a-7-7-1-operation-expressions)
82      - [A.7.7.3 Location List Expressions](#a-7-7-3-location-list-expressions)
83- [B. Further Information](#b-further-information)
84
85# 1. Extension
86
87In DWARF 5, expressions are evaluated using a typed value stack, a separate
88location area, and an independent loclist mechanism. This extension unifies all
89three mechanisms into a single generalized DWARF expression evaluation model
90that allows both typed values and location descriptions to be manipulated on the
91evaluation stack. Both single and multiple location descriptions are supported
92on the stack. In addition, the call frame information (CFI) is extended to
93support the full generality of location descriptions. This is done in a manner
94that is backwards compatible with DWARF 5. The extension involves changes to the
95DWARF 5 sections 2.5 (pp 26-38), 2.6 (pp 38-45), and 6.4 (pp 171-182).
96
97The extension permits operations to act on location descriptions in an
98incremental, consistent, and composable manner. It allows a small number of
99operations to be defined to address the requirements of heterogeneous devices as
100well as providing benefits to non-heterogeneous devices. It acts as a foundation
101to provide support for other issues that have been raised that would benefit all
102devices.
103
104Other approaches were explored that involved adding specialized operations and
105rules. However, these resulted in the need for more operations that did not
106compose. It also resulted in operations with context sensitive semantics and
107corner cases that had to be defined. The observation was that numerous
108specialized context sensitive operations are harder for both produces and
109consumers than a smaller number of general composable operations that have
110consistent semantics regardless of context.
111
112First, section [2. Heterogeneous Computing
113Devices](#heterogeneous-computing-devices) describes heterogeneous devices and
114the features they have that are not addressed by DWARF 5. Then section [3. DWARF
1155](#dwarf-5) presents a brief simplified overview of the DWARF 5 expression
116evaluation model that highlights the difficulties for supporting the
117heterogeneous features. Next, section [4. Extension
118Solution](#extension-solution) provides an overview of the proposal, using
119simplified examples to illustrate how it can address the issues of heterogeneous
120devices and also benefit non-heterogeneous devices. Then overall conclusions are
121covered in section [5. Conclusion](#conclusion). Appendix [A. Changes to DWARF
122Debugging Information Format Version
1235](#a-changes-to-dwarf-debugging-information-format-version-5) gives changes
124relative to the DWARF Version 5 standard. Finally, appendix [B. Further
125Information](#b-further-information) has references to further information.
126
127# 2. Heterogeneous Computing Devices
128
129GPUs and other heterogeneous computing devices have features not common to CPU
130computing devices.
131
132These devices often have many more registers than a CPU. This helps reduce
133memory accesses which tend to be more expensive than on a CPU due to the much
134larger number of threads concurrently executing. In addition to traditional
135scalar registers of a CPU, these devices often have many wide vector registers.
136
137![Example GPU Hardware](images/example-gpu-hardware.png)
138
139They may support masked vector instructions that are used by the compiler to map
140high level language threads onto the lanes of the vector registers. As a
141consequence, multiple language threads execute in lockstep as the vector
142instructions are executed. This is termed single instruction multiple thread
143(SIMT) execution.
144
145![SIMT/SIMD Execution Model](images/simt-execution-model.png)
146
147GPUs can have multiple memory address spaces in addition to the single global
148memory address space of a CPU. These additional address spaces are accessed
149using distinct instructions and are often local to a particular thread or group
150of threads.
151
152For example, a GPU may have a per thread block address space that is implemented
153as scratch pad memory with explicit hardware support to isolate portions to
154specific groups of threads created as a single thread block.
155
156A GPU may also use global memory in a non linear manner. For example, to support
157providing a SIMT per lane address space efficiently, there may be instructions
158that support interleaved access.
159
160Through optimization, the source variables may be located across these different
161storage kinds. SIMT execution requires locations to be able to express selection
162of runtime defined pieces of vector registers. With the more complex locations,
163there is a benefit to be able to factorize their calculation which requires all
164location kinds to be supported uniformly, otherwise duplication is necessary.
165
166# 3. DWARF 5
167
168Before presenting the proposed solution to supporting heterogeneous devices, a
169brief overview of the DWARF 5 expression evaluation model will be given to
170highlight the aspects being addressed by the extension.
171
172## 3.1 How DWARF Maps Source Language To Hardware
173
174DWARF is a standardized way to specify debug information. It describes source
175language entities such as compilation units, functions, types, variables, etc.
176It is either embedded directly in sections of the code object executables, or
177split into separate files that they reference.
178
179DWARF maps between source program language entities and their hardware
180representations. For example:
181
182- It maps a hardware instruction program counter to a source language program
183  line, and vice versa.
184- It maps a source language function to the hardware instruction program counter
185  for its entry point.
186- It maps a source language variable to its hardware location when at a
187  particular program counter.
188- It provides information to allow virtual unwinding of hardware registers for a
189  source language function call stack.
190- In addition, it provides numerous other information about the source language
191  program.
192
193In particular, there is great diversity in the way a source language entity
194could be mapped to a hardware location. The location may involve runtime values.
195For example, a source language variable location could be:
196
197- In register.
198- At a memory address.
199- At an offset from the current stack pointer.
200- Optimized away, but with a known compiler time value.
201- Optimized away, but with an unknown value, such as happens for unused
202  variables.
203- Spread across combination of the above kinds of locations.
204- At a memory address, but also transiently loaded into registers.
205
206To support this DWARF 5 defines a rich expression language comprised of loclist
207expressions and operation expressions. Loclist expressions allow the result to
208vary depending on the PC. Operation expressions are made up of a list of
209operations that are evaluated on a simple stack machine.
210
211A DWARF expression can be used as the value of different attributes of different
212debug information entries (DIE). A DWARF expression can also be used as an
213argument to call frame information information (CFI) entry operations. An
214expression is evaluated in a context dictated by where it is used. The context
215may include:
216
217- Whether the expression needs to produce a value or the location of an entity.
218- The current execution point including process, thread, PC, and stack frame.
219- Some expressions are evaluated with the stack initialized with a specific
220  value or with the location of a base object that is available using the
221  DW_OP_push_object_address operation.
222
223## 3.2 Examples
224
225The following examples illustrate how DWARF expressions involving operations are
226evaluated in DWARF 5. DWARF also has expressions involving location lists that
227are not covered in these examples.
228
229### 3.2.1 Dynamic Array Size
230
231The first example is for an operation expression associated with a DIE attribute
232that provides the number of elements in a dynamic array type. Such an attribute
233dictates that the expression must be evaluated in the context of providing a
234value result kind.
235
236![Dynamic Array Size Example](images/01-value.example.png)
237
238In this hypothetical example, the compiler has allocated an array descriptor in
239memory and placed the descriptor's address in architecture register SGPR0. The
240first location of the array descriptor is the runtime size of the array.
241
242A possible expression to retrieve the dynamic size of the array is:
243
244    DW_OP_regval_type SGPR0 Generic
245    DW_OP_deref
246
247The expression is evaluated one operation at a time. Operations have operands
248and can pop and push entries on a stack.
249
250![Dynamic Array Size Example: Step 1](images/01-value.example.frame.1.png)
251
252The expression evaluation starts with the first DW_OP_regval_type operation.
253This operation reads the current value of an architecture register specified by
254its first operand: SGPR0. The second operand specifies the size of the data to
255read. The read value is pushed on the stack. Each stack element is a value and
256its associated type.
257
258![Dynamic Array Size Example: Step 2](images/01-value.example.frame.2.png)
259
260The type must be a DWARF base type. It specifies the encoding, byte ordering,
261and size of values of the type. DWARF defines that each architecture has a
262default generic type: it is an architecture specific integral encoding and byte
263ordering, that is the size of the architecture's global memory address.
264
265The DW_OP_deref operation pops a value off the stack, treats it as a global
266memory address, and reads the contents of that location using the generic type.
267It pushes the read value on the stack as the value and its associated generic
268type.
269
270![Dynamic Array Size Example: Step 3](images/01-value.example.frame.3.png)
271
272The evaluation stops when it reaches the end of the expression. The result of an
273expression that is evaluated with a value result kind context is the top element
274of the stack, which provides the value and its type.
275
276### 3.2.2 Variable Location in Register
277
278This example is for an operation expression associated with a DIE attribute that
279provides the location of a source language variable. Such an attribute dictates
280that the expression must be evaluated in the context of providing a location
281result kind.
282
283DWARF defines the locations of objects in terms of location descriptions.
284
285In this example, the compiler has allocated a source language variable in
286architecture register SGPR0.
287
288![Variable Location in Register Example](images/02-reg.example.png)
289
290A possible expression to specify the location of the variable is:
291
292    DW_OP_regx SGPR0
293
294![Variable Location in Register Example: Step 1](images/02-reg.example.frame.1.png)
295
296The DW_OP_regx operation creates a location description that specifies the
297location of the architecture register specified by the operand: SGPR0. Unlike
298values, location descriptions are not pushed on the stack. Instead they are
299conceptually placed in a location area. Unlike values, location descriptions do
300not have an associated type, they only denote the location of the base of the
301object.
302
303![Variable Location in Register Example: Step 2](images/02-reg.example.frame.2.png)
304
305Again, evaluation stops when it reaches the end of the expression. The result of
306an expression that is evaluated with a location result kind context is the
307location description in the location area.
308
309### 3.2.3 Variable Location in Memory
310
311The next example is for an operation expression associated with a DIE attribute
312that provides the location of a source language variable that is allocated in a
313stack frame. The compiler has placed the stack frame pointer in architecture
314register SGPR0, and allocated the variable at offset 0x10 from the stack frame
315base. The stack frames are allocated in global memory, so SGPR0 contains a
316global memory address.
317
318![Variable Location in Memory Example](images/03-memory.example.png)
319
320A possible expression to specify the location of the variable is:
321
322    DW_OP_regval_type SGPR0 Generic
323    DW_OP_plus_uconst 0x10
324
325![Variable Location in Memory Example: Step 1](images/03-memory.example.frame.1.png)
326
327As in the previous example, the DW_OP_regval_type operation pushes the stack
328frame pointer global memory address onto the stack. The generic type is the size
329of a global memory address.
330
331![Variable Location in Memory Example: Step 2](images/03-memory.example.frame.2.png)
332
333The DW_OP_plus_uconst operation pops a value from the stack, which must have a
334type with an integral encoding, adds the value of its operand, and pushes the
335result back on the stack with the same associated type. In this example, that
336computes the global memory address of the source language variable.
337
338![Variable Location in Memory Example: Step 3](images/03-memory.example.frame.3.png)
339
340Evaluation stops when it reaches the end of the expression. If the expression
341that is evaluated has a location result kind context, and the location area is
342empty, then the top stack element must be a value with the generic type. The
343value is implicitly popped from the stack, and treated as a global memory
344address to create a global memory location description, which is placed in the
345location area. The result of the expression is the location description in the
346location area.
347
348![Variable Location in Memory Example: Step 4](images/03-memory.example.frame.4.png)
349
350### 3.2.4 Variable Spread Across Different Locations
351
352This example is for a source variable that is partly in a register, partly undefined, and partly in memory.
353
354![Variable Spread Across Different Locations Example](images/04-composite.example.png)
355
356DWARF defines composite location descriptions that can have one or more parts.
357Each part specifies a location description and the number of bytes used from it.
358The following operation expression creates a composite location description.
359
360    DW_OP_regx SGPR3
361    DW_OP_piece 4
362    DW_OP_piece 2
363    DW_OP_bregx SGPR0 0x10
364    DW_OP_piece 2
365
366![Variable Spread Across Different Locations Example: Step 1](images/04-composite.example.frame.1.png)
367
368The DW_OP_regx operation creates a register location description in the location
369area.
370
371![Variable Spread Across Different Locations Example: Step 2](images/04-composite.example.frame.2.png)
372
373The first DW_OP_piece operation creates an incomplete composite location
374description in the location area with a single part. The location description in
375the location area is used to define the beginning of the part for the size
376specified by the operand, namely 4 bytes.
377
378![Variable Spread Across Different Locations Example: Step 3](images/04-composite.example.frame.3.png)
379
380A subsequent DW_OP_piece adds a new part to an incomplete composite location
381description already in the location area. The parts form a contiguous set of
382bytes. If there are no other location descriptions in the location area, and no
383value on the stack, then the part implicitly uses the undefined location
384description. Again, the operand specifies the size of the part in bytes. The
385undefined location description can be used to indicate a part that has been
386optimized away. In this case, 2 bytes of undefined value.
387
388![Variable Spread Across Different Locations Example: Step 4](images/04-composite.example.frame.4.png)
389
390The DW_OP_bregx operation reads the architecture register specified by the first
391operand (SGPR0) as the generic type, adds the value of the second operand
392(0x10), and pushes the value on the stack.
393
394![Variable Spread Across Different Locations Example: Step 5](images/04-composite.example.frame.5.png)
395
396The next DW_OP_piece operation adds another part to the already created
397incomplete composite location.
398
399If there is no other location in the location area, but there is a value on
400stack, the new part is a memory location description. The memory address used is
401popped from the stack. In this case, the operand of 2 indicates there are 2
402bytes from memory.
403
404![Variable Spread Across Different Locations Example: Step 6](images/04-composite.example.frame.6.png)
405
406Evaluation stops when it reaches the end of the expression. If the expression
407that is evaluated has a location result kind context, and the location area has
408an incomplete composite location description, the incomplete composite location
409is implicitly converted to a complete composite location description. The result
410of the expression is the location description in the location area.
411
412![Variable Spread Across Different Locations Example: Step 7](images/04-composite.example.frame.7.png)
413
414### 3.2.5 Offsetting a Composite Location
415
416This example attempts to extend the previous example to offset the composite
417location description it created. The [3.2.3 Variable Location in
418Memory](#variable-location-in-memory) example conveniently used the DW_OP_plus
419operation to offset a memory address.
420
421    DW_OP_regx SGPR3
422    DW_OP_piece 4
423    DW_OP_piece 2
424    DW_OP_bregx SGPR0 0x10
425    DW_OP_piece 2
426    DW_OP_plus_uconst 5
427
428![Offsetting a Composite Location Example: Step 6](images/05-composite-plus.example.frame.1.png)
429
430However, DW_OP_plus cannot be used to offset a composite location. It only
431operates on the stack.
432
433![Offsetting a Composite Location Example: Step 7](images/05-composite-plus.example.frame.2.png)
434
435To offset a composite location description, the compiler would need to make a
436different composite location description, starting at the part corresponding to
437the offset. For example:
438
439    DW_OP_piece 1
440    DW_OP_bregx SGPR0 0x10
441    DW_OP_piece 2
442
443This illustrates that operations on stack values are not composable with
444operations on location descriptions.
445
446## 3.3 Limitations
447
448DWARF 5 is unable to describe variables in runtime indexed parts of registers.
449This is required to describe a source variable that is located in a lane of a
450SIMT vector register.
451
452Some features only work when located in global memory. The type attribute
453expressions require a base object which could be in any kind of location.
454
455DWARF procedures can only accept global memory address arguments. This limits
456the ability to factorize the creation of locations that involve other location
457kinds.
458
459There are no vector base types. This is required to describe vector registers.
460
461There is no operation to create a memory location in a non-global address space.
462Only the dereference operation supports providing an address space.
463
464CFI location expressions do not allow composite locations or non-global address
465space memory locations. Both these are needed in optimized code for devices with
466vector registers and address spaces.
467
468Bit field offsets are only supported in a limited way for register locations.
469Supporting them in a uniform manner for all location kinds is required to
470support languages with bit sized entities.
471
472# 4. Extension Solution
473
474This section outlines the extension to generalize the DWARF expression evaluation
475model to allow location descriptions to be manipulated on the stack. It presents
476a number of simplified examples to demonstrate the benefits and how the extension
477solves the issues of heterogeneous devices. It presents how this is done in
478a manner that is backwards compatible with DWARF 5.
479
480## 4.1 Location Description
481
482In order to have consistent, composable operations that act on location
483descriptions, the extension defines a uniform way to handle all location kinds.
484That includes memory, register, implicit, implicit pointer, undefined, and
485composite location descriptions.
486
487Each kind of location description is conceptually a zero-based offset within a
488piece of storage. The storage is a contiguous linear organization of a certain
489number of bytes (see below for how this is extended to support bit sized
490storage).
491
492- For global memory, the storage is the linear stream of bytes of the
493  architecture's address size.
494- For each separate architecture register, it is the linear stream of bytes of
495  the size of that specific register.
496- For an implicit, it is the linear stream of bytes of the value when
497  represented using the value's base type which specifies the encoding, size,
498  and byte ordering.
499- For undefined, it is an infinitely sized linear stream where every byte is
500  undefined.
501- For composite, it is a linear stream of bytes defined by the composite's parts.
502
503## 4.2 Stack Location Description Operations
504
505The DWARF expression stack is extended to allow each stack entry to either be a
506value or a location description.
507
508Evaluation rules are defined to implicitly convert a stack element that is a
509value to a location description, or vice versa, so that all DWARF 5 expressions
510continue to have the same semantics. This reflects that a memory address is
511effectively used as a proxy for a memory location description.
512
513For each place that allows a DWARF expression to be specified, it is defined if
514the expression is to be evaluated as a value or a location description.
515
516Existing DWARF expression operations that are used to act on memory addresses
517are generalized to act on any location description kind. For example, the
518DW_OP_deref operation pops a location description rather than a memory address
519value from the stack and reads the storage associated with the location kind
520starting at the location description's offset.
521
522Existing DWARF expression operations that create location descriptions are
523changed to pop and push location descriptions on the stack. For example, the
524DW_OP_value, DW_OP_regx, DW_OP_implicit_value, DW_OP_implicit_pointer,
525DW_OP_stack_value, and DW_OP_piece.
526
527New operations that act on location descriptions can be added. For example, a
528DW_OP_offset operation that modifies the offset of the location description on
529top of the stack. Unlike the DW_OP_plus operation that only works with memory
530address, a DW_OP_offset operation can work with any location kind.
531
532To allow incremental and nested creation of composite location descriptions, a
533DW_OP_piece_end can be defined to explicitly indicate the last part of a
534composite. Currently, creating a composite must always be the last operation of
535an expression.
536
537A DW_OP_undefined operation can be defined that explicitly creates the undefined
538location description. Currently this is only possible as a piece of a composite
539when the stack is empty.
540
541## 4.3 Examples
542
543This section provides some motivating examples to illustrate the benefits that
544result from allowing location descriptions on the stack.
545
546### 4.3.1 Source Language Variable Spilled to Part of a Vector Register
547
548A compiler generating code for a GPU may allocate a source language variable
549that it proves has the same value for every lane of a SIMT thread in a scalar
550register. It may then need to spill that scalar register. To avoid the high cost
551of spilling to memory, it may spill to a fixed lane of one of the numerous
552vector registers.
553
554![Source Language Variable Spilled to Part of a Vector Register Example](images/06-extension-spill-sgpr-to-static-vpgr-lane.example.png)
555
556The following expression defines the location of a source language variable that
557the compiler allocated in a scalar register, but had to spill to lane 5 of a
558vector register at this point of the code.
559
560    DW_OP_regx VGPR0
561    DW_OP_offset_uconst 20
562
563![Source Language Variable Spilled to Part of a Vector Register Example: Step 1](images/06-extension-spill-sgpr-to-static-vpgr-lane.example.frame.1.png)
564
565The DW_OP_regx pushes a register location description on the stack. The storage
566for the register is the size of the vector register. The register location
567description conceptually references that storage with an initial offset of 0.
568The architecture defines the byte ordering of the register.
569
570![Source Language Variable Spilled to Part of a Vector Register Example: Step 2](images/06-extension-spill-sgpr-to-static-vpgr-lane.example.frame.2.png)
571
572The DW_OP_offset_uconst pops a location description off the stack, adds its
573operand value to the offset, and pushes the updated location description back on
574the stack. In this case the source language variable is being spilled to lane 5
575and each lane's component which is 32-bits (4 bytes), so the offset is 5*4=20.
576
577![Source Language Variable Spilled to Part of a Vector Register Example: Step 3](images/06-extension-spill-sgpr-to-static-vpgr-lane.example.frame.3.png)
578
579The result of the expression evaluation is the location description on the top
580of the stack.
581
582An alternative approach could be for the target to define distinct register
583names for each part of each vector register. However, this is not practical for
584GPUs due to the sheer number of registers that would have to be defined. It
585would also not permit a runtime index into part of the whole register to be used
586as shown in the next example.
587
588### 4.3.2 Source Language Variable Spread Across Multiple Vector Registers
589
590A compiler may generate SIMT code for a GPU. Each source language thread of
591execution is mapped to a single lane of the GPU thread. Source language
592variables that are mapped to a register, are mapped to the lane component of the
593vector registers corresponding to the source language's thread of execution.
594
595The location expression for such variables must therefore be executed in the
596context of the focused source language thread of execution. A DW_OP_push_lane
597operation can be defined to push the value of the lane for the currently focused
598source language thread of execution. The value to use would be provided by the
599consumer of DWARF when it evaluates the location expression.
600
601If the source language variable is larger than the size of the vector register
602lane component, then multiple vector registers are used. Each source language
603thread of execution will only use the vector register components for its
604associated lane.
605
606![Source Language Variable Spread Across Multiple Vector Registers Example](images/07-extension-multi-lane-vgpr.example.png)
607
608The following expression defines the location of a source language variable that
609has to occupy two vector registers. A composite location description is created
610that combines the two parts. It will give the correct result regardless of which
611lane corresponds to the source language thread of execution that the user is
612focused on.
613
614    DW_OP_regx VGPR0
615    DW_OP_push_lane
616    DW_OP_uconst 4
617    DW_OP_mul
618    DW_OP_offset
619    DW_OP_piece 4
620    DW_OP_regx VGPR1
621    DW_OP_push_lane
622    DW_OP_uconst 4
623    DW_OP_mul
624    DW_OP_offset
625    DW_OP_piece 4
626
627![Source Language Variable Spread Across Multiple Vector Registers Example: Step 1](images/07-extension-multi-lane-vgpr.example.frame.1.png)
628
629The DW_OP_regx VGPR0 pushes a location description for the first register.
630
631![Source Language Variable Spread Across Multiple Vector Registers Example: Step 2](images/07-extension-multi-lane-vgpr.example.frame.2.png)
632
633The DW_OP_push_lane; DW_OP_uconst 4; DW_OP_mul calculates the offset for the
634focused lanes vector register component as 4 times the lane number.
635
636![Source Language Variable Spread Across Multiple Vector Registers Example: Step 3](images/07-extension-multi-lane-vgpr.example.frame.3.png)
637
638![Source Language Variable Spread Across Multiple Vector Registers Example: Step 4](images/07-extension-multi-lane-vgpr.example.frame.4.png)
639
640![Source Language Variable Spread Across Multiple Vector Registers Example: Step 5](images/07-extension-multi-lane-vgpr.example.frame.5.png)
641
642The DW_OP_offset adjusts the register location description's offset to the
643runtime computed value.
644
645![Source Language Variable Spread Across Multiple Vector Registers Example: Step 6](images/07-extension-multi-lane-vgpr.example.frame.6.png)
646
647The DW_OP_piece either creates a new composite location description, or adds a
648new part to an existing incomplete one. It pops the location description to use
649for the new part. It then pops the next stack element if it is an incomplete
650composite location description, otherwise it creates a new incomplete composite
651location description with no parts. Finally it pushes the incomplete composite
652after adding the new part.
653
654In this case a register location description is added to a new incomplete
655composite location description. The 4 of the DW_OP_piece specifies the size of
656the register storage that comprises the part. Note that the 4 bytes start at the
657computed register offset.
658
659For backwards compatibility, if the stack is empty or the top stack element is
660an incomplete composite, an undefined location description is used for the part.
661If the top stack element is a generic base type value, then it is implicitly
662converted to a global memory location description with an offset equal to the
663value.
664
665![Source Language Variable Spread Across Multiple Vector Registers Example: Step 7](images/07-extension-multi-lane-vgpr.example.frame.7.png)
666
667The rest of the expression does the same for VGPR1. However, when the
668DW_OP_piece is evaluated there is an incomplete composite on the stack. So the
669VGPR1 register location description is added as a second part.
670
671![Source Language Variable Spread Across Multiple Vector Registers Example: Step 8](images/07-extension-multi-lane-vgpr.example.frame.8.png)
672
673![Source Language Variable Spread Across Multiple Vector Registers Example: Step 9](images/07-extension-multi-lane-vgpr.example.frame.9.png)
674
675![Source Language Variable Spread Across Multiple Vector Registers Example: Step 10](images/07-extension-multi-lane-vgpr.example.frame.10.png)
676
677![Source Language Variable Spread Across Multiple Vector Registers Example: Step 11](images/07-extension-multi-lane-vgpr.example.frame.11.png)
678
679![Source Language Variable Spread Across Multiple Vector Registers Example: Step 12](images/07-extension-multi-lane-vgpr.example.frame.12.png)
680
681![Source Language Variable Spread Across Multiple Vector Registers Example: Step 13](images/07-extension-multi-lane-vgpr.example.frame.13.png)
682
683At the end of the expression, if the top stack element is an incomplete
684composite location description, it is converted to a complete location
685description and returned as the result.
686
687![Source Language Variable Spread Across Multiple Vector Registers Example: Step 14](images/07-extension-multi-lane-vgpr.example.frame.14.png)
688
689### 4.3.3 Source Language Variable Spread Across Multiple Kinds of Locations
690
691This example is the same as the previous one, except the first 2 bytes of the
692second vector register have been spilled to memory, and the last 2 bytes have
693been proven to be a constant and optimized away.
694
695![Source Language Variable Spread Across Multiple Kinds of Locations Example](images/08-extension-mixed-composite.example.png)
696
697    DW_OP_regx VGPR0
698    DW_OP_push_lane
699    DW_OP_uconst 4
700    DW_OP_mul
701    DW_OP_offset
702    DW_OP_piece 4
703    DW_OP_addr 0xbeef
704    DW_OP_piece 2
705    DW_OP_uconst 0xf00d
706    DW_OP_stack_value
707    DW_OP_piece 2
708    DW_OP_piece_end
709
710The first 6 operations are the same.
711
712![Source Language Variable Spread Across Multiple Kinds of Locations Example: Step 7](images/08-extension-mixed-composite.example.frame.1.png)
713
714The DW_OP_addr operation pushes a global memory location description on the
715stack with an offset equal to the address.
716
717![Source Language Variable Spread Across Multiple Kinds of Locations Example: Step 8](images/08-extension-mixed-composite.example.frame.2.png)
718
719The next DW_OP_piece adds the global memory location description as the next 2
720byte part of the composite.
721
722![Source Language Variable Spread Across Multiple Kinds of Locations Example: Step 9](images/08-extension-mixed-composite.example.frame.3.png)
723
724The DW_OP_uconst 0xf00d; DW_OP_stack_value pushes an implicit location
725description on the stack. The storage of the implicit location description is
726the representation of the value 0xf00d using the generic base type's encoding,
727size, and byte ordering.
728
729![Source Language Variable Spread Across Multiple Kinds of Locations Example: Step 10](images/08-extension-mixed-composite.example.frame.4.png)
730
731![Source Language Variable Spread Across Multiple Kinds of Locations Example: Step 11](images/08-extension-mixed-composite.example.frame.5.png)
732
733The final DW_OP_piece adds 2 bytes of the implicit location description as the
734third part of the composite location description.
735
736![Source Language Variable Spread Across Multiple Kinds of Locations Example: Step 12](images/08-extension-mixed-composite.example.frame.6.png)
737
738The DW_OP_piece_end operation explicitly makes the incomplete composite location
739description into a complete location description. This allows a complete
740composite location description to be created on the stack that can be used as
741the location description of another following operation. For example, the
742DW_OP_offset can be applied to it. More practically, it permits creation of
743multiple composite location descriptions on the stack which can be used to pass
744arguments to a DWARF procedure using a DW_OP_call* operation. This can be
745beneficial to factor the incrementally creation of location descriptions.
746
747![Source Language Variable Spread Across Multiple Kinds of Locations Example: Step 12](images/08-extension-mixed-composite.example.frame.7.png)
748
749### 4.3.4 Address Spaces
750
751Heterogeneous devices can have multiple hardware supported address spaces which
752use specific hardware instructions to access them.
753
754For example, GPUs that use SIMT execution may provide hardware support to access
755memory such that each lane can see a linear memory view, while the backing
756memory is actually being accessed in an interleaved manner so that the locations
757for each lanes Nth dword are contiguous. This minimizes cache lines read by the
758SIMT execution.
759
760![Address Spaces Example](images/09-extension-form-aspace.example.png)
761
762The following expression defines the location of a source language variable that
763is allocated at offset 0x10 in the current subprograms stack frame. The
764subprogram stack frames are per lane and reside in an interleaved address space.
765
766    DW_OP_regval_type SGPR0 Generic
767    DW_OP_uconst 1
768    DW_OP_form_aspace_address
769    DW_OP_offset 0x10
770
771![Address Spaces Example: Step 1](images/09-extension-form-aspace.example.frame.1.png)
772
773The DW_OP_regval_type operation pushes the contents of SGPR0 as a generic value.
774This is the register that holds the address of the current stack frame.
775
776![Address Spaces Example: Step 2](images/09-extension-form-aspace.example.frame.2.png)
777
778The DW_OP_uconst operation pushes the address space number. Each architecture
779defines the numbers it uses in DWARF. In this case, address space 1 is being
780used as the per lane memory.
781
782![Address Spaces Example: Step 3](images/09-extension-form-aspace.example.frame.3.png)
783
784The DW_OP_form_aspace_address operation pops a value and an address space
785number. Each address space is associated with a separate storage. A memory
786location description is pushed which refers to the address space's storage, with
787an offset of the popped value.
788
789![Address Spaces Example: Step 4](images/09-extension-form-aspace.example.frame.4.png)
790
791All operations that act on location descriptions work with memory locations
792regardless of their address space.
793
794Every architecture defines address space 0 as the default global memory address
795space.
796
797Generalizing memory location descriptions to include an address space component
798avoids having to create specialized operations to work with address spaces.
799
800The source variable is at offset 0x10 in the stack frame. The DW_OP_offset
801operation works on memory location descriptions that have an address space just
802like for any other kind of location description.
803
804![Address Spaces Example: Step 5](images/09-extension-form-aspace.example.frame.5.png)
805
806The only operations in DWARF 5 that take an address space are DW_OP_xderef*.
807They treat a value as the address in a specified address space, and read its
808contents. There is no operation to actually create a location description that
809references an address space. There is no way to include address space memory
810locations in parts of composite locations.
811
812Since DW_OP_piece now takes any kind of location description for its pieces, it
813is now possible for parts of a composite to involve locations in different
814address spaces. For example, this can happen when parts of a source variable
815allocated in a register are spilled to a stack frame that resides in the
816non-global address space.
817
818### 4.3.5 Bit Offsets
819
820With the generalization of location descriptions on the stack, it is possible to
821define a DW_OP_bit_offset operation that adjusts the offset of any kind of
822location in terms of bits rather than bytes. The offset can be a runtime
823computed value. This is generally useful for any source language that support
824bit sized entities, and for registers that are not a whole number of bytes.
825
826DWARF 5 only supports bit fields in composites using DW_OP_bit_piece. It does
827not support runtime computed offsets which can happen for bit field packed
828arrays. It is also not generally composable as it must be the last part of an
829expression.
830
831The following example defines a location description for a source variable that
832is allocated starting at bit 20 of a register. A similar expression could be
833used if the source variable was at a bit offset within memory or a particular
834address space, or if the offset is a runtime value.
835
836![Bit Offsets Example](images/10-extension-bit-offset.example.png)
837
838    DW_OP_regx SGPR3
839    DW_OP_uconst 20
840    DW_OP_bit_offset
841
842![Bit Offsets Example: Step 1](images/10-extension-bit-offset.example.frame.1.png)
843
844![Bit Offsets Example: Step 2](images/10-extension-bit-offset.example.frame.2.png)
845
846![Bit Offsets Example: Step 3](images/10-extension-bit-offset.example.frame.3.png)
847
848The DW_OP_bit_offset operation pops a value and location description from the
849stack. It pushes the location description after updating its offset using the
850value as a bit count.
851
852![Bit Offsets Example: Step 4](images/10-extension-bit-offset.example.frame.4.png)
853
854The ordering of bits within a byte, like byte ordering, is defined by the target
855architecture. A base type could be extended to specify bit ordering in addition
856to byte ordering.
857
858## 4.4 Call Frame Information (CFI)
859
860DWARF defines call frame information (CFI) that can be used to virtually unwind
861the subprogram call stack. This involves determining the location where register
862values have been spilled. DWARF 5 limits these locations to either be registers
863or global memory. As shown in the earlier examples, heterogeneous devices may
864spill registers to parts of other registers, to non-global memory address
865spaces, or even a composite of different location kinds.
866
867Therefore, the extension extends the CFI rules to support any kind of location
868description, and operations to create locations in address spaces.
869
870## 4.5 Objects Not In Byte Aligned Global Memory
871
872DWARF 5 only effectively supports byte aligned memory locations on the stack by
873using a global memory address as a proxy for a memory location description. This
874is a problem for attributes that define DWARF expressions that require the
875location of some source language entity that is not allocated in byte aligned
876global memory.
877
878For example, the DWARF expression of the DW_AT_data_member_location attribute is
879evaluated with an initial stack containing the location of a type instance
880object. That object could be located in a register, in a non-global memory
881address space, be described by a composite location description, or could even
882be an implicit location description.
883
884A similar problem exists for DWARF expressions that use the
885DW_OP_push_object_address operation. This operation pushes the location of a
886program object associated with the attribute that defines the expression.
887
888Allowing any kind of location description on the stack permits the DW_OP_call*
889operations to be used to factor the creation of location descriptions. The
890inputs and outputs of the call are passed on the stack. For example, on GPUs an
891expression can be defined to describe the effective PC of inactive lanes of SIMT
892execution. This is naturally done by composing the result of expressions for
893each nested control flow region. This can be done by making each control flow
894region have its own DWARF procedure, and then calling it from the expressions of
895the nested control flow regions. The alternative is to make each control flow
896region have the complete expression which results in much larger DWARF and is
897less convenient to generate.
898
899GPU compilers work hard to allocate objects in the larger number of registers to
900reduce memory accesses, they have to use different memory address spaces, and
901they perform optimizations that result in composites of these. Allowing
902operations to work with any kind of location description enables creating
903expressions that support all of these.
904
905Full general support for bit fields and implicit locations benefits
906optimizations on any target.
907
908## 4.6 Higher Order Operations
909
910The generalization allows an elegant way to add higher order operations that
911create location descriptions out of other location descriptions in a general
912composable manner.
913
914For example, a DW_OP_extend operation could create a composite location
915description out of a location description, an element size, and an element
916count. The resulting composite would effectively be a vector of element count
917elements with each element being the same location description of the specified
918bit size.
919
920A DW_OP_select_bit_piece operation could create a composite location description
921out of two location descriptions, a bit mask value, and an element size. The
922resulting composite would effectively be a vector of elements, selecting from
923one of the two input locations according to the bit mask.
924
925These could be used in the expression of an attribute that computes the
926effective PC of lanes of SIMT execution. The vector result efficiently computes
927the PC for each SIMT lane at once. The mask could be the hardware execution mask
928register that controls which SIMT lanes are executing. For active divergent
929lanes the vector element would be the current PC, and for inactive divergent
930lanes the PC would correspond to the source language line at which the lane is
931logically positioned.
932
933Similarly, a DW_OP_overlay_piece operation could be defined that creates a
934composite location description out of two location descriptions, an offset
935value, and a size. The resulting composite would consist of parts that are
936equivalent to one of the location descriptions, but with the other location
937description replacing a slice defined by the offset and size. This could be used
938to efficiently express a source language array that has had a set of elements
939promoted into a vector register when executing a set of iterations of a loop in
940a SIMD manner.
941
942## 4.7 Objects In Multiple Places
943
944A compiler may allocate a source variable in stack frame memory, but for some
945range of code may promote it to a register. If the generated code does not
946change the register value, then there is no need to save it back to memory.
947Effectively, during that range, the source variable is in both memory and a
948register. If a consumer, such as a debugger, allows the user to change the value
949of the source variable in that PC range, then it would need to change both
950places.
951
952DWARF 5 supports loclists which are able to specify the location of a source
953language entity is in different places at different PC locations. It can also
954express that a source language entity is in multiple places at the same time.
955
956DWARF 5 defines operation expressions and loclists separately. In general, this
957is adequate as non-memory location descriptions can only be computed as the last
958step of an expression evaluation.
959
960However, allowing location descriptions on the stack permits non-memory location
961descriptions to be used in the middle of expression evaluation. For example, the
962DW_OP_call* and DW_OP_implicit_pointer operations can result in evaluating the
963expression of a DW_AT_location attribute of a DIE. The DW_AT_location attribute
964allows the loclist form. So the result could include multiple location
965descriptions.
966
967Similarly, the DWARF expression associated with attributes such as
968DW_AT_data_member_location that are evaluated with an initial stack containing a
969location description, or a DWARF operation expression that uses the
970DW_OP_push_object_address operation, may want to act on the result of another
971expression that returned a location description involving multiple places.
972
973Therefore, the extension needs to define how expression operations that use those
974results will behave. The extension does this by generalizing the expression stack
975to allow an entry to be one or more single location descriptions. In doing this,
976it unifies the definitions of DWARF operation expressions and loclist
977expressions in a natural way.
978
979All operations that act on location descriptions are extended to act on multiple
980single location descriptions. For example, the DW_OP_offset operation adds the
981offset to each single location description. The DW_OP_deref* operations simply
982read the storage of one of the single location descriptions, since multiple
983single location descriptions must all hold the same value. Similarly, if the
984evaluation of a DWARF expression results in multiple single location
985descriptions, the consumer can ensure any updates are done to all of them, and
986any reads can use any one of them.
987
988# 5. Conclusion
989
990A strength of DWARF is that it has generally sought to provide generalized
991composable solutions that address many problems, rather than solutions that only
992address one-off issues. This extension attempts to follow that tradition by
993defining a backwards compatible composable generalization that can address a
994significant family of issues. It addresses the specific issues present for
995heterogeneous computing devices, provides benefits for non-heterogeneous
996devices, and can help address a number of other previously reported issues.
997
998# A. Changes to DWARF Debugging Information Format Version 5
999
1000> NOTE: This appendix provides changes relative to DWARF Version 5. It has been
1001> defined such that it is backwards compatible with DWARF Version 5.
1002> Non-normative text is shown in <i>italics</i>. The section numbers generally
1003> correspond to those in the DWARF Version 5 standard unless specified
1004> otherwise. Definitions are given to clarify how existing expression
1005> operations, CFI operations, and attributes behave with respect to generalized
1006> location descriptions that support multiple places.
1007>
1008> > NOTE: Notes are included to describe how the changes are to be applied to
1009> > the DWARF Version 5 standard. They also describe rational and issues that
1010> > may need further consideration.
1011
1012## A.2 General Description
1013
1014### A.2.5 DWARF Expressions
1015
1016> NOTE: This section, and its nested sections, replaces DWARF Version 5 section
1017> 2.5 and section 2.6. It is based on the text of the existing DWARF Version 5
1018> standard.
1019
1020DWARF expressions describe how to compute a value or specify a location.
1021
1022<i>The evaluation of a DWARF expression can provide the location of an object,
1023the value of an array bound, the length of a dynamic string, the desired value
1024itself, and so on.</i>
1025
1026If the evaluation of a DWARF expression does not encounter an error, then it can
1027either result in a value (see [2.5.2 DWARF Expression
1028Value](#dwarf-expression-value)) or a location description (see [2.5.3 DWARF
1029Location Description](#dwarf-location-description)). When a DWARF expression
1030is evaluated, it may be specified whether a value or location description is
1031required as the result kind.
1032
1033If a result kind is specified, and the result of the evaluation does not match
1034the specified result kind, then the implicit conversions described in [2.5.4.4.3
1035Memory Location Description
1036Operations](#memory-location-description-operations) are performed if
1037valid. Otherwise, the DWARF expression is ill-formed.
1038
1039If the evaluation of a DWARF expression encounters an evaluation error, then the
1040result is an evaluation error.
1041
1042> NOTE: Decided to define the concept of an evaluation error. An alternative is
1043> to introduce an undefined value base type in a similar way to location
1044> descriptions having an undefined location description. Then operations that
1045> encounter an evaluation error can return the undefined location description or
1046> value with an undefined base type.
1047>
1048> All operations that act on values would return an undefined entity if given an
1049> undefined value. The expression would then always evaluate to completion, and
1050> can be tested to determine if it is an undefined entity.
1051>
1052> However, this would add considerable additional complexity and does not match
1053> that GDB throws an exception when these evaluation errors occur.
1054
1055If a DWARF expression is ill-formed, then the result is undefined.
1056
1057The following sections detail the rules for when a DWARF expression is
1058ill-formed or results in an evaluation error.
1059
1060A DWARF expression can either be encoded as an operation expression (see [2.5.4
1061DWARF Operation Expressions](#dwarf-operation-expressions)), or as a
1062location list expression (see [2.5.5 DWARF Location List
1063Expressions](#dwarf-location-list-expressions)).
1064
1065#### A.2.5.1 DWARF Expression Evaluation Context
1066
1067A DWARF expression is evaluated in a context that can include a number of
1068context elements. If multiple context elements are specified then they must be
1069self consistent or the result of the evaluation is undefined. The context
1070elements that can be specified are:
1071
10721.  <i>A current result kind</i>
1073
1074    The kind of result required by the DWARF expression evaluation. If specified
1075    it can be a location description or a value.
1076
10772.  <i>A current thread</i>
1078
1079    The target architecture thread identifier of the source program thread of
1080    execution for which a user presented expression is currently being
1081    evaluated.
1082
1083    It is required for operations that are related to target architecture
1084    threads.
1085
1086    <i>For example, the `DW_OP_regval_type` operation.</i>
1087
10883.  <i>A current call frame</i>
1089
1090    The target architecture call frame identifier. It identifies a call frame
1091    that corresponds to an active invocation of a subprogram in the current
1092    thread. It is identified by its address on the call stack. The address is
1093    referred to as the Canonical Frame Address (CFA). The call frame information
1094    is used to determine the CFA for the call frames of the current thread's
1095    call stack (see [6.4 Call Frame Information](#call-frame-information)).
1096
1097    It is required for operations that specify target architecture registers to
1098    support virtual unwinding of the call stack.
1099
1100    <i>For example, the `DW_OP_*reg*` operations.</i>
1101
1102    If specified, it must be an active call frame in the current thread.
1103    Otherwise the result is undefined.
1104
1105    If it is the currently executing call frame, then it is termed the top call
1106    frame.
1107
11084.  <i>A current program location</i>
1109
1110    The target architecture program location corresponding to the current call
1111    frame of the current thread.
1112
1113    The program location of the top call frame is the target architecture
1114    program counter for the current thread. The call frame information is used
1115    to obtain the value of the return address register to determine the program
1116    location of the other call frames (see [6.4 Call Frame
1117    Information](#call-frame-information)).
1118
1119    It is required for the evaluation of location list expressions to select
1120    amongst multiple program location ranges. It is required for operations that
1121    specify target architecture registers to support virtual unwinding of the
1122    call stack (see [6.4 Call Frame Information](#call-frame-information)).
1123
1124    If specified:
1125
1126    - If the current call frame is the top call frame, it must be the current
1127      target architecture program location.
1128    - If the current call frame F is not the top call frame, it must be the
1129      program location associated with the call site in the current caller frame
1130      F that invoked the callee frame.
1131    - Otherwise the result is undefined.
1132
11335.  <i>A current compilation unit</i>
1134
1135    The compilation unit debug information entry that contains the DWARF
1136    expression being evaluated.
1137
1138    It is required for operations that reference debug information associated
1139    with the same compilation unit, including indicating if such references use
1140    the 32-bit or 64-bit DWARF format. It can also provide the default address
1141    space address size if no current target architecture is specified.
1142
1143    <i>For example, the `DW_OP_constx` and `DW_OP_addrx` operations.</i>
1144
1145    <i>Note that this compilation unit may not be the same as the compilation
1146    unit determined from the loaded code object corresponding to the current
1147    program location. For example, the evaluation of the expression E associated
1148    with a `DW_AT_location` attribute of the debug information entry operand of
1149    the `DW_OP_call*` operations is evaluated with the compilation unit that
1150    contains E and not the one that contains the `DW_OP_call*` operation
1151    expression.</i>
1152
11536.  <i>A current target architecture</i>
1154
1155    The target architecture.
1156
1157    It is required for operations that specify target architecture specific
1158    entities.
1159
1160    <i>For example, target architecture specific entities include DWARF register
1161    identifiers, DWARF address space identifiers, the default address space, and
1162    the address space address sizes.</i>
1163
1164    If specified:
1165
1166    - If the current thread is specified, then the current target architecture
1167      must be the same as the target architecture of the current thread.
1168    - If the current compilation unit is specified, then the current target
1169      architecture default address space address size must be the same as the
1170      `address_size` field in the header of the current compilation unit and any
1171      associated entry in the `.debug_aranges` section.
1172    - If the current program location is specified, then the current target
1173      architecture must be the same as the target architecture of any line
1174      number information entry (see [6.2 Line Number
1175      Information](#line-number-information)) corresponding to the current
1176      program location.
1177    - If the current program location is specified, then the current target
1178      architecture default address space address size must be the same as the
1179      `address_size` field in the header of any entry corresponding to the
1180      current program location in the `.debug_addr`, `.debug_line`,
1181      `.debug_rnglists`, `.debug_rnglists.dwo`, `.debug_loclists`, and
1182      `.debug_loclists.dwo` sections.
1183    - Otherwise the result is undefined.
1184
11857.  <i>A current object</i>
1186
1187    The location description of a program object.
1188
1189    It is required for the `DW_OP_push_object_address` operation.
1190
1191    <i>For example, the `DW_AT_data_location` attribute on type debug
1192    information entries specifies the program object corresponding to a runtime
1193    descriptor as the current object when it evaluates its associated
1194    expression.</i>
1195
1196    The result is undefined if the location descriptor is invalid (see [3.5.3
1197    DWARF Location Description](#dwarf-location-description)).
1198
11998.  <i>An initial stack</i>
1200
1201    This is a list of values or location descriptions that will be pushed on the
1202    operation expression evaluation stack in the order provided before
1203    evaluation of an operation expression starts.
1204
1205    Some debugger information entries have attributes that evaluate their DWARF
1206    expression value with initial stack entries. In all other cases the initial
1207    stack is empty.
1208
1209    The result is undefined if any location descriptors are invalid (see [3.5.3
1210    DWARF Location Description](#dwarf-location-description)).
1211
1212If the evaluation requires a context element that is not specified, then the
1213result of the evaluation is an error.
1214
1215<i>A DWARF expression for a location description may be able to be evaluated
1216without a thread, call frame, program location, or architecture context. For
1217example, the location of a global variable may be able to be evaluated without
1218such context. If the expression evaluates with an error then it may indicate the
1219variable has been optimized and so requires more context.</i>
1220
1221<i>The DWARF expression for call frame information (see [6.4 Call Frame
1222Information](#call-frame-information)) operations are restricted to those
1223that do not require the compilation unit context to be specified.</i>
1224
1225The DWARF is ill-formed if all the `address_size` fields in the headers of all
1226the entries in the `.debug_info`, `.debug_addr`, `.debug_line`,
1227`.debug_rnglists`, `.debug_rnglists.dwo`, `.debug_loclists`, and
1228`.debug_loclists.dwo` sections corresponding to any given program location do
1229not match.
1230
1231#### A.2.5.2 DWARF Expression Value
1232
1233A value has a type and a literal value. It can represent a literal value of any
1234supported base type of the target architecture. The base type specifies the
1235size, encoding, and endianity of the literal value.
1236
1237> NOTE: It may be desirable to add an implicit pointer base type encoding. It
1238> would be used for the type of the value that is produced when the
1239> `DW_OP_deref*` operation retrieves the full contents of an implicit pointer
1240> location storage created by the `DW_OP_implicit_pointer` operation. The
1241> literal value would record the debugging information entry and byte
1242> displacement specified by the associated `DW_OP_implicit_pointer` operation.
1243
1244There is a distinguished base type termed the generic type, which is an integral
1245type that has the size of an address in the target architecture default address
1246space, a target architecture defined endianity, and unspecified signedness.
1247
1248<i>The generic type is the same as the unspecified type used for stack
1249operations defined in DWARF Version 4 and before.</i>
1250
1251An integral type is a base type that has an encoding of `DW_ATE_signed`,
1252`DW_ATE_signed_char`, `DW_ATE_unsigned`, `DW_ATE_unsigned_char`,
1253`DW_ATE_boolean`, or any target architecture defined integral encoding in the
1254inclusive range `DW_ATE_lo_user` to `DW_ATE_hi_user`.
1255
1256> NOTE: It is unclear if `DW_ATE_address` is an integral type. GDB does not seem
1257> to consider it as integral.
1258
1259#### A.2.5.3 DWARF Location Description
1260
1261<i>Debugging information must provide consumers a way to find the location of
1262program variables, determine the bounds of dynamic arrays and strings, and
1263possibly to find the base address of a subprogram's call frame or the return
1264address of a subprogram. Furthermore, to meet the needs of recent computer
1265architectures and optimization techniques, debugging information must be able to
1266describe the location of an object whose location changes over the object's
1267lifetime, and may reside at multiple locations simultaneously during parts of an
1268object's lifetime.</i>
1269
1270Information about the location of program objects is provided by location
1271descriptions.
1272
1273Location descriptions can consist of one or more single location descriptions.
1274
1275A single location description specifies the location storage that holds a
1276program object and a position within the location storage where the program
1277object starts. The position within the location storage is expressed as a bit
1278offset relative to the start of the location storage.
1279
1280A location storage is a linear stream of bits that can hold values. Each
1281location storage has a size in bits and can be accessed using a zero-based bit
1282offset. The ordering of bits within a location storage uses the bit numbering
1283and direction conventions that are appropriate to the current language on the
1284target architecture.
1285
1286There are five kinds of location storage:
1287
12881.  <i>memory location storage</i>
1289
1290    Corresponds to the target architecture memory address spaces.
1291
12922.  <i>register location storage</i>
1293
1294    Corresponds to the target architecture registers.
1295
12963.  <i>implicit location storage</i>
1297
1298    Corresponds to fixed values that can only be read.
1299
13004.  <i>undefined location storage</i>
1301
1302    Indicates no value is available and therefore cannot be read or written.
1303
13045.  <i>composite location storage</i>
1305
1306    Allows a mixture of these where some bits come from one location storage and
1307    some from another location storage, or from disjoint parts of the same
1308    location storage.
1309
1310> NOTE: It may be better to add an implicit pointer location storage kind used
1311> by the `DW_OP_implicit_pointer` operation. It would specify the debugger
1312> information entry and byte offset provided by the operations.
1313
1314<i>Location descriptions are a language independent representation of addressing
1315rules.</i>
1316
1317- <i>They can be the result of evaluating a debugger information entry attribute
1318  that specifies an operation expression of arbitrary complexity. In this usage
1319  they can describe the location of an object as long as its lifetime is either
1320  static or the same as the lexical block (see [3.5 Lexical Block
1321  Entries](#lexical-block-entries)) that owns it, and it does not move during
1322  its lifetime.</i>
1323
1324- <i>They can be the result of evaluating a debugger information entry attribute
1325  that specifies a location list expression. In this usage they can describe the
1326  location of an object that has a limited lifetime, changes its location during
1327  its lifetime, or has multiple locations over part or all of its lifetime.</i>
1328
1329If a location description has more than one single location description, the
1330DWARF expression is ill-formed if the object value held in each single location
1331description's position within the associated location storage is not the same
1332value, except for the parts of the value that are uninitialized.
1333
1334<i>A location description that has more than one single location description can
1335only be created by a location list expression that has overlapping program
1336location ranges, or certain expression operations that act on a location
1337description that has more than one single location description. There are no
1338operation expression operations that can directly create a location description
1339with more than one single location description.</i>
1340
1341<i>A location description with more than one single location description can be
1342used to describe objects that reside in more than one piece of storage at the
1343same time. An object may have more than one location as a result of
1344optimization. For example, a value that is only read may be promoted from memory
1345to a register for some region of code, but later code may revert to reading the
1346value from memory as the register may be used for other purposes. For the code
1347region where the value is in a register, any change to the object value must be
1348made in both the register and the memory so both regions of code will read the
1349updated value.</i>
1350
1351<i>A consumer of a location description with more than one single location
1352description can read the object's value from any of the single location
1353descriptions (since they all refer to location storage that has the same value),
1354but must write any changed value to all the single location descriptions.</i>
1355
1356Updating a location description L by a bit offset B is defined as adding the
1357value of B to the bit offset of each single location description SL of L. It is
1358an evaluation error if the updated bit offset of any SL is less than 0 or
1359greater than or equal to the size of the location storage specified by SL.
1360
1361The evaluation of an expression may require context elements to create a
1362location description. If such a location description is accessed, the storage it
1363denotes is that associated with the context element values specified when the
1364location description was created, which may differ from the context at the time
1365it is accessed.
1366
1367<i>For example, creating a register location description requires the thread
1368context: the location storage is for the specified register of that thread.
1369Creating a memory location description for an address space may required a
1370thread context: the location storage is the memory associated with that
1371thread.</i>
1372
1373If any of the context elements required to create a location description change,
1374the location description becomes invalid and accessing it is undefined.
1375
1376<i>Examples of context that can invalidate a location description are:</i>
1377
1378- <i>The thread context is required and execution causes the thread to
1379  terminate.</i>
1380- <i>The call frame context is required and further execution causes the call
1381  frame to return to the calling frame.</i>
1382- <i>The program location is required and further execution of the thread
1383  occurs. That could change the location list entry or call frame information
1384  entry that applies.</i>
1385- <i>An operation uses call frame information:</i>
1386  - <i>Any of the frames used in the virtual call frame unwinding return.</i>
1387  - <i>The top call frame is used, the program location is used to select the
1388    call frame information entry, and further execution of the thread
1389    occurs.</i>
1390
1391<i>A DWARF expression can be used to compute a location description for an
1392object. A subsequent DWARF expression evaluation can be given the object
1393location description as the object context or initial stack context to compute a
1394component of the object. The final result is undefined if the object location
1395description becomes invalid between the two expression evaluations.</i>
1396
1397A change of a thread's program location may not make a location description
1398invalid, yet may still render it as no longer meaningful. Accessing such a
1399location description, or using it as the object context or initial stack context
1400of an expression evaluation, may produce an undefined result.
1401
1402<i>For example, a location description may specify a register that no longer
1403holds the intended program object after a program location change. One way to
1404avoid such problems is to recompute location descriptions associated with
1405threads when their program locations change.</i>
1406
1407#### A.2.5.4 DWARF Operation Expressions
1408
1409An operation expression is comprised of a stream of operations, each consisting
1410of an opcode followed by zero or more operands. The number of operands is
1411implied by the opcode.
1412
1413Operations represent a postfix operation on a simple stack machine. Each stack
1414entry can hold either a value or a location description. Operations can act on
1415entries on the stack, including adding entries and removing entries. If the kind
1416of a stack entry does not match the kind required by the operation and is not
1417implicitly convertible to the required kind (see [2.5.4.4.3 Memory Location
1418Description Operations](#memory-location-description-operations)), then
1419the DWARF operation expression is ill-formed.
1420
1421Evaluation of an operation expression starts with an empty stack on which the
1422entries from the initial stack provided by the context are pushed in the order
1423provided. Then the operations are evaluated, starting with the first operation
1424of the stream. Evaluation continues until either an operation has an evaluation
1425error, or until one past the last operation of the stream is reached.
1426
1427The result of the evaluation is:
1428
1429- If an operation has an evaluation error, or an operation evaluates an
1430  expression that has an evaluation error, then the result is an evaluation
1431  error.
1432- If the current result kind specifies a location description, then:
1433  - If the stack is empty, the result is a location description with one
1434    undefined location description.
1435
1436    <i>This rule is for backwards compatibility with DWARF Version 5 which uses
1437    an empty operation expression for this purpose.</i>
1438
1439  - If the top stack entry is a location description, or can be converted to one
1440    (see [2.5.4.4.3 Memory Location Description
1441    Operations](#memory-location-description-operations)), then the result
1442    is that, possibly converted, location description. Any other entries on the
1443    stack are discarded.
1444  - Otherwise the DWARF expression is ill-formed.
1445
1446    > NOTE: Could define this case as returning an implicit location description
1447    > as if the `DW_OP_implicit` operation is performed.
1448
1449- If the current result kind specifies a value, then:
1450  - If the top stack entry is a value, or can be converted to one (see
1451    [2.5.4.4.3 Memory Location Description
1452    Operations](#memory-location-description-operations)), then the result is
1453    that, possibly converted, value. Any other entries on the stack are
1454    discarded.
1455  - Otherwise the DWARF expression is ill-formed.
1456- If the current result kind is not specified, then:
1457  - If the stack is empty, the result is a location description with one
1458    undefined location description.
1459
1460    <i>This rule is for backwards compatibility with DWARF Version 5 which uses
1461    an empty operation expression for this purpose.</i>
1462
1463    > NOTE: This rule is consistent with the rule above for when a location
1464    > description is requested. However, GDB appears to report this as an error
1465    > and no GDB tests appear to cause an empty stack for this case.
1466
1467  - Otherwise, the top stack entry is returned. Any other entries on the stack
1468    are discarded.
1469
1470An operation expression is encoded as a byte block with some form of prefix that
1471specifies the byte count. It can be used:
1472
1473- as the value of a debugging information entry attribute that is encoded using
1474  class `exprloc` (see [7.5.5 Classes and Forms](#classes-and-forms)),
1475- as the operand to certain operation expression operations,
1476- as the operand to certain call frame information operations (see [6.4 Call
1477  Frame Information](#call-frame-information)),
1478- and in location list entries (see [2.5.5 DWARF Location List
1479  Expressions](#dwarf-location-list-expressions)).
1480
1481##### A.2.5.4.1 Stack Operations
1482
1483> NOTE: This section replaces DWARF Version 5 section 2.5.1.3.
1484
1485The following operations manipulate the DWARF stack. Operations that index the
1486stack assume that the top of the stack (most recently added entry) has index 0.
1487They allow the stack entries to be either a value or location description.
1488
1489If any stack entry accessed by a stack operation is an incomplete composite
1490location description (see [2.5.4.4.6 Composite Location Description
1491Operations](#composite-location-description-operations)), then the DWARF
1492expression is ill-formed.
1493
1494> NOTE: These operations now support stack entries that are values and location
1495> descriptions.
1496
1497> NOTE: If it is desired to also make them work with incomplete composite
1498> location descriptions, then would need to define that the composite location
1499> storage specified by the incomplete composite location description is also
1500> replicated when a copy is pushed. This ensures that each copy of the
1501> incomplete composite location description can update the composite location
1502> storage they specify independently.
1503
15041.  `DW_OP_dup`
1505
1506    `DW_OP_dup` duplicates the stack entry at the top of the stack.
1507
15082.  `DW_OP_drop`
1509
1510    `DW_OP_drop` pops the stack entry at the top of the stack and discards it.
1511
15123.  `DW_OP_pick`
1513
1514    `DW_OP_pick` has a single unsigned 1-byte operand that represents an index
1515    I.  A copy of the stack entry with index I is pushed onto the stack.
1516
15174.  `DW_OP_over`
1518
1519    `DW_OP_over` pushes a copy of the entry with index 1.
1520
1521    <i>This is equivalent to a `DW_OP_pick 1` operation.</i>
1522
15235.  `DW_OP_swap`
1524
1525    `DW_OP_swap` swaps the top two stack entries. The entry at the top of the
1526    stack becomes the second stack entry, and the second stack entry becomes the
1527    top of the stack.
1528
15296.  `DW_OP_rot`
1530
1531    `DW_OP_rot` rotates the first three stack entries. The entry at the top of
1532    the stack becomes the third stack entry, the second entry becomes the top of
1533    the stack, and the third entry becomes the second entry.
1534
1535##### A.2.5.4.2 Control Flow Operations
1536
1537> NOTE: This section replaces DWARF Version 5 section 2.5.1.5.
1538
1539The following operations provide simple control of the flow of a DWARF operation
1540expression.
1541
15421.  `DW_OP_nop`
1543
1544    `DW_OP_nop` is a place holder. It has no effect on the DWARF stack entries.
1545
15462.  `DW_OP_le`, `DW_OP_ge`, `DW_OP_eq`, `DW_OP_lt`, `DW_OP_gt`,
1547    `DW_OP_ne`
1548
1549    > NOTE: The same as in DWARF Version 5 section 2.5.1.5.
1550
15513.  `DW_OP_skip`
1552
1553    `DW_OP_skip` is an unconditional branch. Its single operand is a 2-byte
1554    signed integer constant. The 2-byte constant is the number of bytes of the
1555    DWARF expression to skip forward or backward from the current operation,
1556    beginning after the 2-byte constant.
1557
1558    If the updated position is at one past the end of the last operation, then
1559    the operation expression evaluation is complete.
1560
1561    Otherwise, the DWARF expression is ill-formed if the updated operation
1562    position is not in the range of the first to last operation inclusive, or
1563    not at the start of an operation.
1564
15654.  `DW_OP_bra`
1566
1567    `DW_OP_bra` is a conditional branch. Its single operand is a 2-byte signed
1568    integer constant. This operation pops the top of stack. If the value popped
1569    is not the constant 0, the 2-byte constant operand is the number of bytes of
1570    the DWARF operation expression to skip forward or backward from the current
1571    operation, beginning after the 2-byte constant.
1572
1573    If the updated position is at one past the end of the last operation, then
1574    the operation expression evaluation is complete.
1575
1576    Otherwise, the DWARF expression is ill-formed if the updated operation
1577    position is not in the range of the first to last operation inclusive, or
1578    not at the start of an operation.
1579
15805.  `DW_OP_call2, DW_OP_call4, DW_OP_call_ref`
1581
1582    `DW_OP_call2`, `DW_OP_call4`, and `DW_OP_call_ref` perform DWARF procedure
1583    calls during evaluation of a DWARF expression.
1584
1585    `DW_OP_call2` and `DW_OP_call4`, have one operand that is, respectively, a
1586    2-byte or 4-byte unsigned offset DR that represents the byte offset of a
1587    debugging information entry D relative to the beginning of the current
1588    compilation unit.
1589
1590    `DW_OP_call_ref` has one operand that is a 4-byte unsigned value in the
1591    32-bit DWARF format, or an 8-byte unsigned value in the 64-bit DWARF format,
1592    that represents the byte offset DR of a debugging information entry D
1593    relative to the beginning of the `.debug_info` section that contains the
1594    current compilation unit. D may not be in the current compilation unit.
1595
1596    > NOTE: DWARF Version 5 states that DR can be an offset in a `.debug_info`
1597    > section other than the one that contains the current compilation unit. It
1598    > states that relocation of references from one executable or shared object
1599    > file to another must be performed by the consumer. But given that DR is
1600    > defined as an offset in a `.debug_info` section this seems impossible. If
1601    > DR was defined as an implementation defined value, then the consumer could
1602    > choose to interpret the value in an implementation defined manner to
1603    > reference a debug information in another executable or shared object.
1604    >
1605    > In ELF the `.debug_info` section is in a non-`PT_LOAD` segment so standard
1606    > dynamic relocations cannot be used. But even if they were loaded segments
1607    > and dynamic relocations were used, DR would need to be the address of D,
1608    > not an offset in a `.debug_info` section. That would also need DR to be
1609    > the size of a global address. So it would not be possible to use the
1610    > 32-bit DWARF format in a 64-bit global address space. In addition, the
1611    > consumer would need to determine what executable or shared object the
1612    > relocated address was in so it could determine the containing compilation
1613    > unit.
1614    >
1615    > GDB only interprets DR as an offset in the `.debug_info` section that
1616    > contains the current compilation unit.
1617    >
1618    > This comment also applies to `DW_OP_implicit_pointer`.
1619
1620    <i>Operand interpretation of `DW_OP_call2`, `DW_OP_call4`, and
1621    `DW_OP_call_ref` is exactly like that for `DW_FORM_ref2`, `DW_FORM_ref4`,
1622    and `DW_FORM_ref_addr`, respectively.</i>
1623
1624    The call operation is evaluated by:
1625
1626    - If D has a `DW_AT_location` attribute that is encoded as a `exprloc` that
1627      specifies an operation expression E, then execution of the current
1628      operation expression continues from the first operation of E. Execution
1629      continues until one past the last operation of E is reached, at which
1630      point execution continues with the operation following the call operation.
1631      The operations of E are evaluated with the same current context, except
1632      current compilation unit is the one that contains D and the stack is the
1633      same as that being used by the call operation. After the call operation
1634      has been evaluated, the stack is therefore as it is left by the evaluation
1635      of the operations of E. Since E is evaluated on the same stack as the call
1636      operation, E can use, and/or remove entries already on the stack, and can
1637      add new entries to the stack.
1638
1639      <i>Values on the stack at the time of the call may be used as parameters
1640      by the called expression and values left on the stack by the called
1641      expression may be used as return values by prior agreement between the
1642      calling and called expressions.</i>
1643
1644    - If D has a `DW_AT_location` attribute that is encoded as a `loclist` or
1645      `loclistsptr`, then the specified location list expression E is evaluated.
1646      The evaluation of E uses the current context, except the result kind is a
1647      location description, the compilation unit is the one that contains D, and
1648      the initial stack is empty. The location description result is pushed on
1649      the stack.
1650
1651      > NOTE: This rule avoids having to define how to execute a matched
1652      > location list entry operation expression on the same stack as the call
1653      > when there are multiple matches. But it allows the call to obtain the
1654      > location description for a variable or formal parameter which may use a
1655      > location list expression.
1656      >
1657      > An alternative is to treat the case when D has a `DW_AT_location`
1658      > attribute that is encoded as a `loclist` or `loclistsptr`, and the
1659      > specified location list expression E' matches a single location list
1660      > entry with operation expression E, the same as the `exprloc` case and
1661      > evaluate on the same stack.
1662      >
1663      > But this is not attractive as if the attribute is for a variable that
1664      > happens to end with a non-singleton stack, it will not simply put a
1665      > location description on the stack. Presumably the intent of using
1666      > `DW_OP_call*` on a variable or formal parameter debugger information
1667      > entry is to push just one location description on the stack. That
1668      > location description may have more than one single location description.
1669      >
1670      > The previous rule for `exprloc` also has the same problem, as normally a
1671      > variable or formal parameter location expression may leave multiple
1672      > entries on the stack and only return the top entry.
1673      >
1674      > GDB implements `DW_OP_call*` by always executing E on the same stack. If
1675      > the location list has multiple matching entries, it simply picks the
1676      > first one and ignores the rest. This seems fundamentally at odds with
1677      > the desire to support multiple places for variables.
1678      >
1679      > So, it feels like `DW_OP_call*` should both support pushing a location
1680      > description on the stack for a variable or formal parameter, and also
1681      > support being able to execute an operation expression on the same stack.
1682      > Being able to specify a different operation expression for different
1683      > program locations seems a desirable feature to retain.
1684      >
1685      > A solution to that is to have a distinct `DW_AT_proc` attribute for the
1686      > `DW_TAG_dwarf_procedure` debugging information entry. Then the
1687      > `DW_AT_location` attribute expression is always executed separately and
1688      > pushes a location description (that may have multiple single location
1689      > descriptions), and the `DW_AT_proc` attribute expression is always
1690      > executed on the same stack and can leave anything on the stack.
1691      >
1692      > The `DW_AT_proc` attribute could have the new classes `exprproc`,
1693      > `loclistproc`, and `loclistsptrproc` to indicate that the expression is
1694      > executed on the same stack. `exprproc` is the same encoding as
1695      > `exprloc`. `loclistproc` and `loclistsptrproc` are the same encoding as
1696      > their non-`proc` counterparts, except the DWARF is ill-formed if the
1697      > location list does not match exactly one location list entry and a
1698      > default entry is required. These forms indicate explicitly that the
1699      > matched single operation expression must be executed on the same stack.
1700      > This is better than ad hoc special rules for `loclistproc` and
1701      > `loclistsptrproc` which are currently clearly defined to always return a
1702      > location description. The producer then explicitly indicates the intent
1703      > through the attribute classes.
1704      >
1705      > Such a change would be a breaking change for how GDB implements
1706      > `DW_OP_call*`. However, are the breaking cases actually occurring in
1707      > practice? GDB could implement the current approach for DWARF Version 5,
1708      > and the new semantics for DWARF Version 6 which has been done for some
1709      > other features.
1710      >
1711      > Another option is to limit the execution to be on the same stack only to
1712      > the evaluation of an expression E that is the value of a
1713      > `DW_AT_location` attribute of a `DW_TAG_dwarf_procedure` debugging
1714      > information entry. The DWARF would be ill-formed if E is a location list
1715      > expression that does not match exactly one location list entry. In all
1716      > other cases the evaluation of an expression E that is the value of a
1717      > `DW_AT_location` attribute would evaluate E with the current context,
1718      > except the result kind is a location description, the compilation unit
1719      > is the one that contains D, and the initial stack is empty. The location
1720      > description result is pushed on the stack.
1721
1722    - If D has a `DW_AT_const_value` attribute with a value V, then it is as if
1723      a `DW_OP_implicit_value V` operation was executed.
1724
1725      <i>This allows a call operation to be used to compute the location
1726      description for any variable or formal parameter regardless of whether the
1727      producer has optimized it to a constant. This is consistent with the
1728      `DW_OP_implicit_pointer` operation.</i>
1729
1730      > NOTE: Alternatively, could deprecate using `DW_AT_const_value` for
1731      > `DW_TAG_variable` and `DW_TAG_formal_parameter` debugger information
1732      > entries that are constants and instead use `DW_AT_location` with an
1733      > operation expression that results in a location description with one
1734      > implicit location description. Then this rule would not be required.
1735
1736    - Otherwise, there is no effect and no changes are made to the stack.
1737
1738      > NOTE: In DWARF Version 5, if D does not have a `DW_AT_location` then
1739      > `DW_OP_call*` is defined to have no effect. It is unclear that this is
1740      > the right definition as a producer should be able to rely on using
1741      > `DW_OP_call*` to get a location description for any
1742      > non-`DW_TAG_dwarf_procedure` debugging information entries. Also, the
1743      > producer should not be creating DWARF with `DW_OP_call*` to a
1744      > `DW_TAG_dwarf_procedure` that does not have a `DW_AT_location`
1745      > attribute. So, should this case be defined as an ill-formed DWARF
1746      > expression?
1747
1748    <i>The `DW_TAG_dwarf_procedure` debugging information entry can be used to
1749    define DWARF procedures that can be called.</i>
1750
1751##### A.2.5.4.3 Value Operations
1752
1753This section describes the operations that push values on the stack.
1754
1755Each value stack entry has a type and a literal value. It can represent a
1756literal value of any supported base type of the target architecture. The base
1757type specifies the size, encoding, and endianity of the literal value.
1758
1759The base type of value stack entries can be the distinguished generic type.
1760
1761###### A.2.5.4.3.1 Literal Operations
1762
1763> NOTE: This section replaces DWARF Version 5 section 2.5.1.1.
1764
1765The following operations all push a literal value onto the DWARF stack.
1766
1767Operations other than `DW_OP_const_type` push a value V with the generic type.
1768If V is larger than the generic type, then V is truncated to the generic type
1769size and the low-order bits used.
1770
17711.  `DW_OP_lit0`, `DW_OP_lit1`, ..., `DW_OP_lit31`
1772
1773    `DW_OP_lit<N>` operations encode an unsigned literal value N from 0 through
1774    31, inclusive. They push the value N with the generic type.
1775
17762.  `DW_OP_const1u`, `DW_OP_const2u`, `DW_OP_const4u`, `DW_OP_const8u`
1777
1778    `DW_OP_const<N>u` operations have a single operand that is a 1, 2, 4, or
1779    8-byte unsigned integer constant U, respectively. They push the value U with
1780    the generic type.
1781
17823.  `DW_OP_const1s`, `DW_OP_const2s`, `DW_OP_const4s`, `DW_OP_const8s`
1783
1784    `DW_OP_const<N>s` operations have a single operand that is a 1, 2, 4, or
1785    8-byte signed integer constant S, respectively. They push the value S with
1786    the generic type.
1787
17884.  `DW_OP_constu`
1789
1790    `DW_OP_constu` has a single unsigned LEB128 integer operand N. It pushes the
1791    value N with the generic type.
1792
17935.  `DW_OP_consts`
1794
1795    `DW_OP_consts` has a single signed LEB128 integer operand N. It pushes the
1796    value N with the generic type.
1797
17986.  `DW_OP_constx`
1799
1800    `DW_OP_constx` has a single unsigned LEB128 integer operand that represents
1801    a zero-based index into the `.debug_addr` section relative to the value of
1802    the `DW_AT_addr_base` attribute of the associated compilation unit. The
1803    value N in the `.debug_addr` section has the size of the generic type. It
1804    pushes the value N with the generic type.
1805
1806    <i>The `DW_OP_constx` operation is provided for constants that require
1807    link-time relocation but should not be interpreted by the consumer as a
1808    relocatable address (for example, offsets to thread-local storage).</i>
1809
18107.  `DW_OP_const_type`
1811
1812    `DW_OP_const_type` has three operands. The first is an unsigned LEB128
1813    integer DR that represents the byte offset of a debugging information entry
1814    D relative to the beginning of the current compilation unit, that provides
1815    the type T of the constant value. The second is a 1-byte unsigned integral
1816    constant S. The third is a block of bytes B, with a length equal to S.
1817
1818    TS is the bit size of the type T. The least significant TS bits of B are
1819    interpreted as a value V of the type D. It pushes the value V with the type
1820    D.
1821
1822    The DWARF is ill-formed if D is not a `DW_TAG_base_type` debugging
1823    information entry in the current compilation unit, or if TS divided by 8
1824    (the byte size) and rounded up to a whole number is not equal to S.
1825
1826    <i>While the size of the byte block B can be inferred from the type D
1827    definition, it is encoded explicitly into the operation so that the
1828    operation can be parsed easily without reference to the `.debug_info`
1829    section.</i>
1830
1831###### A.2.5.4.3.2 Arithmetic and Logical Operations
1832
1833> NOTE: This section is the same as DWARF Version 5 section 2.5.1.4.
1834
1835###### A.2.5.4.3.3 Type Conversion Operations
1836
1837> NOTE: This section is the same as DWARF Version 5 section 2.5.1.6.
1838
1839###### A.2.5.4.3.4 Special Value Operations
1840
1841> NOTE: This section replaces parts of DWARF Version 5 sections 2.5.1.2,
1842  2.5.1.3, and 2.5.1.7.
1843
1844There are these special value operations currently defined:
1845
18461.  `DW_OP_regval_type`
1847
1848    `DW_OP_regval_type` has two operands. The first is an unsigned LEB128
1849    integer that represents a register number R. The second is an unsigned
1850    LEB128 integer DR that represents the byte offset of a debugging information
1851    entry D relative to the beginning of the current compilation unit, that
1852    provides the type T of the register value.
1853
1854    The operation is equivalent to performing `DW_OP_regx R; DW_OP_deref_type
1855    DR`.
1856
1857    > NOTE: Should DWARF allow the type T to be a larger size than the size of
1858    > the register R? Restricting a larger bit size avoids any issue of
1859    > conversion as the, possibly truncated, bit contents of the register is
1860    > simply interpreted as a value of T. If a conversion is wanted it can be
1861    > done explicitly using a `DW_OP_convert` operation.
1862    >
1863    > GDB has a per register hook that allows a target specific conversion on a
1864    > register by register basis. It defaults to truncation of bigger registers.
1865    > Removing use of the target hook does not cause any test failures in common
1866    > architectures. If the compiler for a target architecture did want some
1867    > form of conversion, including a larger result type, it could always
1868    > explicitly used the `DW_OP_convert` operation.
1869    >
1870    > If T is a larger type than the register size, then the default GDB
1871    > register hook reads bytes from the next register (or reads out of bounds
1872    > for the last register!). Removing use of the target hook does not cause
1873    > any test failures in common architectures (except an illegal hand written
1874    > assembly test). If a target architecture requires this behavior, these
1875    > extensions allow a composite location description to be used to combine
1876    > multiple registers.
1877
18782.  `DW_OP_deref`
1879
1880    S is the bit size of the generic type divided by 8 (the byte size) and
1881    rounded up to a whole number. DR is the offset of a hypothetical debug
1882    information entry D in the current compilation unit for a base type of the
1883    generic type.
1884
1885    The operation is equivalent to performing `DW_OP_deref_type S, DR`.
1886
18873.  `DW_OP_deref_size`
1888
1889    `DW_OP_deref_size` has a single 1-byte unsigned integral constant that
1890    represents a byte result size S.
1891
1892    TS is the smaller of the generic type bit size and S scaled by 8 (the byte
1893    size). If TS is smaller than the generic type bit size then T is an unsigned
1894    integral type of bit size TS, otherwise T is the generic type. DR is the
1895    offset of a hypothetical debug information entry D in the current
1896    compilation unit for a base type T.
1897
1898    > NOTE: Truncating the value when S is larger than the generic type matches
1899    > what GDB does. This allows the generic type size to not be an integral
1900    > byte size. It does allow S to be arbitrarily large. Should S be restricted
1901    > to the size of the generic type rounded up to a multiple of 8?
1902
1903    The operation is equivalent to performing `DW_OP_deref_type S, DR`, except
1904    if T is not the generic type, the value V pushed is zero-extended to the
1905    generic type bit size and its type changed to the generic type.
1906
19074.  `DW_OP_deref_type`
1908
1909    `DW_OP_deref_type` has two operands. The first is a 1-byte unsigned integral
1910    constant S. The second is an unsigned LEB128 integer DR that represents the
1911    byte offset of a debugging information entry D relative to the beginning of
1912    the current compilation unit, that provides the type T of the result value.
1913
1914    TS is the bit size of the type T.
1915
1916    <i>While the size of the pushed value V can be inferred from the type T, it
1917    is encoded explicitly as the operand S so that the operation can be parsed
1918    easily without reference to the `.debug_info` section.</i>
1919
1920    > NOTE: It is unclear why the operand S is needed. Unlike
1921    > `DW_OP_const_type`, the size is not needed for parsing. Any evaluation
1922    > needs to get the base type T to push with the value to know its encoding
1923    > and bit size.
1924
1925    It pops one stack entry that must be a location description L.
1926
1927    A value V of TS bits is retrieved from the location storage LS specified by
1928    one of the single location descriptions SL of L.
1929
1930    <i>If L, or the location description of any composite location description
1931    part that is a subcomponent of L, has more than one single location
1932    description, then any one of them can be selected as they are required to
1933    all have the same value. For any single location description SL, bits are
1934    retrieved from the associated storage location starting at the bit offset
1935    specified by SL. For a composite location description, the retrieved bits
1936    are the concatenation of the N bits from each composite location part PL,
1937    where N is limited to the size of PL.</i>
1938
1939    V is pushed on the stack with the type T.
1940
1941    > NOTE: This definition makes it an evaluation error if L is a register
1942    > location description that has less than TS bits remaining in the register
1943    > storage. Particularly since these extensions extend location descriptions
1944    > to have a bit offset, it would be odd to define this as performing sign
1945    > extension based on the type, or be target architecture dependent, as the
1946    > number of remaining bits could be any number. This matches the GDB
1947    > implementation for `DW_OP_deref_type`.
1948    >
1949    > These extensions define `DW_OP_*breg*` in terms of `DW_OP_regval_type`.
1950    > `DW_OP_regval_type` is defined in terms of `DW_OP_regx`, which uses a 0
1951    > bit offset, and `DW_OP_deref_type`. Therefore, it requires the register
1952    > size to be greater or equal to the address size of the address space. This
1953    > matches the GDB implementation for `DW_OP_*breg*`.
1954
1955    The DWARF is ill-formed if D is not in the current compilation unit, D is
1956    not a `DW_TAG_base_type` debugging information entry, or if TS divided by 8
1957    (the byte size) and rounded up to a whole number is not equal to S.
1958
1959    > NOTE: This definition allows the base type to be a bit size since there
1960    > seems no reason to restrict it.
1961
1962    It is an evaluation error if any bit of the value is retrieved from the
1963    undefined location storage or the offset of any bit exceeds the size of the
1964    location storage LS specified by any single location description SL of L.
1965
1966    See [2.5.4.4.5 Implicit Location Description
1967    Operations](#implicit-location-description-operations) for special
1968    rules concerning implicit location descriptions created by the
1969    `DW_OP_implicit_pointer` operation.
1970
19715.  `DW_OP_xderef`
1972
1973    `DW_OP_xderef` pops two stack entries. The first must be an integral type
1974    value that represents an address A. The second must be an integral type
1975    value that represents a target architecture specific address space
1976    identifier AS.
1977
1978    The address size S is defined as the address bit size of the target
1979    architecture specific address space that corresponds to AS.
1980
1981    A is adjusted to S bits by zero extending if necessary, and then treating
1982    the least significant S bits as an unsigned value A'.
1983
1984    It creates a location description L with one memory location description SL.
1985    SL specifies the memory location storage LS that corresponds to AS with a
1986    bit offset equal to A' scaled by 8 (the byte size).
1987
1988    If AS is an address space that is specific to context elements, then LS
1989    corresponds to the location storage associated with the current context.
1990
1991    <i>For example, if AS is for per thread storage then LS is the location
1992    storage for the current thread. Therefore, if L is accessed by an operation,
1993    the location storage selected when the location description was created is
1994    accessed, and not the location storage associated with the current context
1995    of the access operation.</i>
1996
1997    The DWARF expression is ill-formed if AS is not one of the values defined by
1998    the target architecture specific `DW_ASPACE_*` values.
1999
2000    The operation is equivalent to popping A and AS, pushing L, and then
2001    performing `DW_OP_deref`. The value V retrieved is left on the stack with
2002    the generic type.
2003
20046.  `DW_OP_xderef_size`
2005
2006    `DW_OP_xderef_size` has a single 1-byte unsigned integral constant that
2007    represents a byte result size S.
2008
2009    It pops two stack entries. The first must be an integral type value
2010    that represents an address A. The second must be an integral type
2011    value that represents a target architecture specific address space
2012    identifier AS.
2013
2014    It creates a location description L as described for `DW_OP_xderef`.
2015
2016    The operation is equivalent to popping A and AS, pushing L, and then
2017    performing `DW_OP_deref_size S` . The zero-extended value V retrieved is
2018    left on the stack with the generic type.
2019
20207.  `DW_OP_xderef_type`
2021
2022    `DW_OP_xderef_type` has two operands. The first is a 1-byte unsigned
2023    integral constant S. The second operand is an unsigned LEB128 integer DR
2024    that represents the byte offset of a debugging information entry D relative
2025    to the beginning of the current compilation unit, that provides the type T
2026    of the result value.
2027
2028    It pops two stack entries. The first must be an integral type value that
2029    represents an address A. The second must be an integral type value that
2030    represents a target architecture specific address space identifier AS.
2031
2032    It creates a location description L as described for `DW_OP_xderef`.
2033
2034    The operation is equivalent to popping A and AS, pushing L, and then
2035    performing `DW_OP_deref_type DR` . The value V retrieved is left on the
2036    stack with the type T.
2037
20388.  `DW_OP_entry_value` <i>Deprecated</i>
2039
2040    `DW_OP_entry_value` pushes the value of an expression that is evaluated in
2041    the context of the calling frame.
2042
2043    <i>It may be used to determine the value of arguments on entry to the
2044    current call frame provided they are not clobbered.</i>
2045
2046    It has two operands. The first is an unsigned LEB128 integer S. The second
2047    is a block of bytes, with a length equal S, interpreted as a DWARF operation
2048    expression E.
2049
2050    E is evaluated with the current context, except the result kind is
2051    unspecified, the call frame is the one that called the current frame, the
2052    program location is the call site in the calling frame, the object is
2053    unspecified, and the initial stack is empty. The calling frame information
2054    is obtained by virtually unwinding the current call frame using the call
2055    frame information (see [6.4 Call Frame
2056    Information](#call-frame-information)).
2057
2058    If the result of E is a location description L (see [2.5.4.4.4 Register
2059    Location Description
2060    Operations](#register-location-description-operations)), and the last
2061    operation executed by E is a `DW_OP_reg*` for register R with a target
2062    architecture specific base type of T, then the contents of the register are
2063    retrieved as if a `DW_OP_deref_type DR` operation was performed where DR is
2064    the offset of a hypothetical debug information entry in the current
2065    compilation unit for T. The resulting value V s pushed on the stack.
2066
2067    <i>Using `DW_OP_reg*` provides a more compact form for the case where the
2068    value was in a register on entry to the subprogram.</i>
2069
2070    > NOTE: It is unclear how this provides a more compact expression, as
2071    > `DW_OP_regval_type` could be used which is marginally larger.
2072
2073    If the result of E is a value V, then V is pushed on the stack.
2074
2075    Otherwise, the DWARF expression is ill-formed.
2076
2077    <i>The `DW_OP_entry_value` operation is deprecated as its main usage is
2078    provided by other means. DWARF Version 5 added the
2079    `DW_TAG_call_site_parameter` debugger information entry for call sites that
2080    has `DW_AT_call_value`, `DW_AT_call_data_location`, and
2081    `DW_AT_call_data_value` attributes that provide DWARF expressions to compute
2082    actual parameter values at the time of the call, and requires the producer
2083    to ensure the expressions are valid to evaluate even when virtually
2084    unwound.</i>
2085
2086    > NOTE: GDB only implements `DW_OP_entry_value` when E is exactly
2087    > `DW_OP_reg*` or `DW_OP_breg*; DW_OP_deref*`.
2088
2089##### A.2.5.4.4 Location Description Operations
2090
2091This section describes the operations that push location descriptions on the
2092stack.
2093
2094###### A.2.5.4.4.1 General Location Description Operations
2095
2096> NOTE: This section replaces part of DWARF Version 5 section 2.5.1.3.
2097
20981.  `DW_OP_push_object_address`
2099
2100    `DW_OP_push_object_address` pushes the location description L of the current
2101    object.
2102
2103    <i>This object may correspond to an independent variable that is part of a
2104    user presented expression that is being evaluated. The object location
2105    description may be determined from the variable's own debugging information
2106    entry or it may be a component of an array, structure, or class whose
2107    address has been dynamically determined by an earlier step during user
2108    expression evaluation.</i>
2109
2110    <i>This operation provides explicit functionality (especially for arrays
2111    involving descriptors) that is analogous to the implicit push of the base
2112    location description of a structure prior to evaluation of a
2113    `DW_AT_data_member_location` to access a data member of a structure.</i>
2114
2115    > NOTE: This operation could be removed and the object location description
2116    > specified as the initial stack as for `DW_AT_data_member_location`.
2117    >
2118    > Or this operation could be used instead of needing to specify an initial
2119    > stack. The latter approach is more composable as access to the object may
2120    > be needed at any point of the expression, and passing it as the initial
2121    > stack requires the entire expression to be aware where on the stack it is.
2122    > If this were done, ``DW_AT_use_location`` would require a
2123    > ``DW_OP_push_object2_address`` operation for the second object.
2124    >
2125    > Or a more general way to pass an arbitrary number of arguments in and an
2126    > operation to get the Nth one such as ``DW_OP_arg N``. A vector of
2127    > arguments would then be passed in the expression context rather than an
2128    > initial stack. This could also resolve the issues with ``DW_OP_call*`` by
2129    > allowing a specific number of arguments passed in and returned to be
2130    > specified. The ``DW_OP_call*`` operation could then always execute on a
2131    > separate stack: the number of arguments would be specified in a new call
2132    > operation and taken from the callers stack, and similarly the number of
2133    > return results specified and copied from the called stack back to the
2134    > callee stack when the called expression was complete.
2135    >
2136    > The only attribute that specifies a current object is
2137    > `DW_AT_data_location` so the non-normative text seems to overstate how
2138    > this is being used. Or are there other attributes that need to state they
2139    > pass an object?
2140
2141###### A.2.5.4.4.2 Undefined Location Description Operations
2142
2143> NOTE: This section replaces DWARF Version 5 section 2.6.1.1.1.
2144
2145<i>The undefined location storage represents a piece or all of an object that is
2146present in the source but not in the object code (perhaps due to optimization).
2147Neither reading nor writing to the undefined location storage is meaningful.</i>
2148
2149An undefined location description specifies the undefined location storage.
2150There is no concept of the size of the undefined location storage, nor of a bit
2151offset for an undefined location description. The `DW_OP_*piece` operations can
2152implicitly specify an undefined location description, allowing any size and
2153offset to be specified, and results in a part with all undefined bits.
2154
2155###### A.2.5.4.4.3 Memory Location Description Operations
2156
2157> NOTE: This section replaces parts of DWARF Version 5 section 2.5.1.1, 2.5.1.2,
2158> 2.5.1.3, and 2.6.1.1.2.
2159
2160Each of the target architecture specific address spaces has a corresponding
2161memory location storage that denotes the linear addressable memory of that
2162address space. The size of each memory location storage corresponds to the range
2163of the addresses in the corresponding address space.
2164
2165<i>It is target architecture defined how address space location storage maps to
2166target architecture physical memory. For example, they may be independent
2167memory, or more than one location storage may alias the same physical memory
2168possibly at different offsets and with different interleaving. The mapping may
2169also be dictated by the source language address classes.</i>
2170
2171A memory location description specifies a memory location storage. The bit
2172offset corresponds to a bit position within a byte of the memory. Bits accessed
2173using a memory location description, access the corresponding target
2174architecture memory starting at the bit position within the byte specified by
2175the bit offset.
2176
2177A memory location description that has a bit offset that is a multiple of 8 (the
2178byte size) is defined to be a byte address memory location description. It has a
2179memory byte address A that is equal to the bit offset divided by 8.
2180
2181A memory location description that does not have a bit offset that is a multiple
2182of 8 (the byte size) is defined to be a bit field memory location description.
2183It has a bit position B equal to the bit offset modulo 8, and a memory byte
2184address A equal to the bit offset minus B that is then divided by 8.
2185
2186The address space AS of a memory location description is defined to be the
2187address space that corresponds to the memory location storage associated with
2188the memory location description.
2189
2190A location description that is comprised of one byte address memory location
2191description SL is defined to be a memory byte address location description. It
2192has a byte address equal to A and an address space equal to AS of the
2193corresponding SL.
2194
2195`DW_ASPACE_none` is defined as the target architecture default address space.
2196
2197If a stack entry is required to be a location description, but it is a value V
2198with the generic type, then it is implicitly converted to a location description
2199L with one memory location description SL. SL specifies the memory location
2200storage that corresponds to the target architecture default address space with a
2201bit offset equal to V scaled by 8 (the byte size).
2202
2203> NOTE: If it is wanted to allow any integral type value to be implicitly
2204> converted to a memory location description in the target architecture default
2205> address space:
2206>
2207> > If a stack entry is required to be a location description, but is a value V
2208> > with an integral type, then it is implicitly converted to a location
2209> > description L with a one memory location description SL. If the type size of
2210> > V is less than the generic type size, then the value V is zero extended to
2211> > the size of the generic type. The least significant generic type size bits
2212> > are treated as an unsigned value to be used as an address A. SL specifies
2213> > memory location storage corresponding to the target architecture default
2214> > address space with a bit offset equal to A scaled by 8 (the byte size).
2215>
2216> The implicit conversion could also be defined as target architecture specific.
2217> For example, GDB checks if V is an integral type. If it is not it gives an
2218> error. Otherwise, GDB zero-extends V to 64 bits. If the GDB target defines a
2219> hook function, then it is called. The target specific hook function can modify
2220> the 64-bit value, possibly sign extending based on the original value type.
2221> Finally, GDB treats the 64-bit value V as a memory location address.
2222
2223If a stack entry is required to be a location description, but it is an implicit
2224pointer value IPV with the target architecture default address space, then it is
2225implicitly converted to a location description with one single location
2226description specified by IPV. See [2.5.4.4.5 Implicit Location Description
2227Operations](#implicit-location-description-operations).
2228
2229If a stack entry is required to be a value, but it is a location description L
2230with one memory location description SL in the target architecture default
2231address space with a bit offset B that is a multiple of 8, then it is implicitly
2232converted to a value equal to B divided by 8 (the byte size) with the generic
2233type.
2234
22351.  `DW_OP_addr`
2236
2237    `DW_OP_addr` has a single byte constant value operand, which has the size of
2238    the generic type, that represents an address A.
2239
2240    It pushes a location description L with one memory location description SL
2241    on the stack. SL specifies the memory location storage corresponding to the
2242    target architecture default address space with a bit offset equal to A
2243    scaled by 8 (the byte size).
2244
2245    <i>If the DWARF is part of a code object, then A may need to be relocated.
2246    For example, in the ELF code object format, A must be adjusted by the
2247    difference between the ELF segment virtual address and the virtual address
2248    at which the segment is loaded.</i>
2249
22502.  `DW_OP_addrx`
2251
2252    `DW_OP_addrx` has a single unsigned LEB128 integer operand that represents a
2253    zero-based index into the `.debug_addr` section relative to the value of the
2254    `DW_AT_addr_base` attribute of the associated compilation unit. The address
2255    value A in the `.debug_addr` section has the size of the generic type.
2256
2257    It pushes a location description L with one memory location description SL
2258    on the stack. SL specifies the memory location storage corresponding to the
2259    target architecture default address space with a bit offset equal to A
2260    scaled by 8 (the byte size).
2261
2262    <i>If the DWARF is part of a code object, then A may need to be relocated.
2263    For example, in the ELF code object format, A must be adjusted by the
2264    difference between the ELF segment virtual address and the virtual address
2265    at which the segment is loaded.</i>
2266
22673.  `DW_OP_form_tls_address`
2268
2269    `DW_OP_form_tls_address` pops one stack entry that must be an integral type
2270    value and treats it as a thread-local storage address TA.
2271
2272    It pushes a location description L with one memory location description SL
2273    on the stack. SL is the target architecture specific memory location
2274    description that corresponds to the thread-local storage address TA.
2275
2276    The meaning of the thread-local storage address TA is defined by the
2277    run-time environment. If the run-time environment supports multiple
2278    thread-local storage blocks for a single thread, then the block
2279    corresponding to the executable or shared library containing this DWARF
2280    expression is used.
2281
2282    <i>Some implementations of C, C++, Fortran, and other languages support a
2283    thread-local storage class. Variables with this storage class have distinct
2284    values and addresses in distinct threads, much as automatic variables have
2285    distinct values and addresses in each subprogram invocation. Typically,
2286    there is a single block of storage containing all thread-local variables
2287    declared in the main executable, and a separate block for the variables
2288    declared in each shared library. Each thread-local variable can then be
2289    accessed in its block using an identifier. This identifier is typically a
2290    byte offset into the block and pushed onto the DWARF stack by one of the
2291    `DW_OP_const*` operations prior to the `DW_OP_form_tls_address` operation.
2292    Computing the address of the appropriate block can be complex (in some
2293    cases, the compiler emits a function call to do it), and difficult to
2294    describe using ordinary DWARF location descriptions. Instead of forcing
2295    complex thread-local storage calculations into the DWARF expressions, the
2296    `DW_OP_form_tls_address` allows the consumer to perform the computation
2297    based on the target architecture specific run-time environment.</i>
2298
22994.  `DW_OP_call_frame_cfa`
2300
2301    `DW_OP_call_frame_cfa` pushes the location description L of the Canonical
2302    Frame Address (CFA) of the current subprogram, obtained from the call frame
2303    information on the stack. See [6.4 Call Frame
2304    Information](#call-frame-information).
2305
2306    <i>Although the value of the `DW_AT_frame_base` attribute of the debugger
2307    information entry corresponding to the current subprogram can be computed
2308    using a location list expression, in some cases this would require an
2309    extensive location list because the values of the registers used in
2310    computing the CFA change during a subprogram execution. If the call frame
2311    information is present, then it already encodes such changes, and it is
2312    space efficient to reference that using the `DW_OP_call_frame_cfa`
2313    operation.</i>
2314
23155.  `DW_OP_fbreg`
2316
2317    `DW_OP_fbreg` has a single signed LEB128 integer operand that represents a
2318    byte displacement B.
2319
2320    The location description L for the <i>frame base</i> of the current
2321    subprogram is obtained from the `DW_AT_frame_base` attribute of the debugger
2322    information entry corresponding to the current subprogram as described in
2323    [3.3.5 Low-Level Information](#low-level-information).
2324
2325    The location description L is updated by bit offset B scaled by 8 (the byte
2326    size) and pushed on the stack.
2327
23286.  `DW_OP_breg0`, `DW_OP_breg1`, ..., `DW_OP_breg31`
2329
2330    The `DW_OP_breg<N>` operations encode the numbers of up to 32 registers,
2331    numbered from 0 through 31, inclusive. The register number R corresponds to
2332    the N in the operation name.
2333
2334    They have a single signed LEB128 integer operand that represents a byte
2335    displacement B.
2336
2337    The address space identifier AS is defined as the one corresponding to the
2338    target architecture specific default address space.
2339
2340    The address size S is defined as the address bit size of the target
2341    architecture specific address space corresponding to AS.
2342
2343    The contents of the register specified by R are retrieved as if a
2344    `DW_OP_regval_type R, DR` operation was performed where DR is the offset of
2345    a hypothetical debug information entry in the current compilation unit for
2346    an unsigned integral base type of size S bits. B is added and the least
2347    significant S bits are treated as an unsigned value to be used as an address
2348    A.
2349
2350    They push a location description L comprising one memory location
2351    description LS on the stack. LS specifies the memory location storage that
2352    corresponds to AS with a bit offset equal to A scaled by 8 (the byte size).
2353
23547.  `DW_OP_bregx`
2355
2356    `DW_OP_bregx` has two operands. The first is an unsigned LEB128 integer that
2357    represents a register number R. The second is a signed LEB128 integer that
2358    represents a byte displacement B.
2359
2360    The action is the same as for `DW_OP_breg<N>`, except that R is used as the
2361    register number and B is used as the byte displacement.
2362
2363###### A.2.5.4.4.4 Register Location Description Operations
2364
2365> NOTE: This section replaces DWARF Version 5 section 2.6.1.1.3.
2366
2367There is a register location storage that corresponds to each of the target
2368architecture registers. The size of each register location storage corresponds
2369to the size of the corresponding target architecture register.
2370
2371A register location description specifies a register location storage. The bit
2372offset corresponds to a bit position within the register. Bits accessed using a
2373register location description access the corresponding target architecture
2374register starting at the specified bit offset.
2375
23761.  `DW_OP_reg0`, `DW_OP_reg1`, ..., `DW_OP_reg31`
2377
2378    `DW_OP_reg<N>` operations encode the numbers of up to 32 registers, numbered
2379    from 0 through 31, inclusive. The target architecture register number R
2380    corresponds to the N in the operation name.
2381
2382    The operation is equivalent to performing `DW_OP_regx R`.
2383
23842.  `DW_OP_regx`
2385
2386    `DW_OP_regx` has a single unsigned LEB128 integer operand that represents a
2387    target architecture register number R.
2388
2389    If the current call frame is the top call frame, it pushes a location
2390    description L that specifies one register location description SL on the
2391    stack. SL specifies the register location storage that corresponds to R with
2392    a bit offset of 0 for the current thread.
2393
2394    If the current call frame is not the top call frame, call frame information
2395    (see [6.4 Call Frame Information](#call-frame-information)) is used to
2396    determine the location description that holds the register for the current
2397    call frame and current program location of the current thread. The resulting
2398    location description L is pushed.
2399
2400    <i>Note that if call frame information is used, the resulting location
2401    description may be register, memory, or undefined.</i>
2402
2403    <i>An implementation may evaluate the call frame information immediately, or
2404    may defer evaluation until L is accessed by an operation. If evaluation is
2405    deferred, R and the current context can be recorded in L. When accessed, the
2406    recorded context is used to evaluate the call frame information, not the
2407    current context of the access operation.</i>
2408
2409<i>These operations obtain a register location. To fetch the contents of a
2410register, it is necessary to use `DW_OP_regval_type`, use one of the
2411`DW_OP_breg*` register-based addressing operations, or use `DW_OP_deref*` on a
2412register location description.</i>
2413
2414###### A.2.5.4.4.5 Implicit Location Description Operations
2415
2416> NOTE: This section replaces DWARF Version 5 section 2.6.1.1.4.
2417
2418Implicit location storage represents a piece or all of an object which has no
2419actual location in the program but whose contents are nonetheless known, either
2420as a constant or can be computed from other locations and values in the program.
2421
2422An implicit location description specifies an implicit location storage. The bit
2423offset corresponds to a bit position within the implicit location storage. Bits
2424accessed using an implicit location description, access the corresponding
2425implicit storage value starting at the bit offset.
2426
24271.  `DW_OP_implicit_value`
2428
2429    `DW_OP_implicit_value` has two operands. The first is an unsigned LEB128
2430    integer that represents a byte size S. The second is a block of bytes with a
2431    length equal to S treated as a literal value V.
2432
2433    An implicit location storage LS is created with the literal value V and a
2434    size of S.
2435
2436    It pushes location description L with one implicit location description SL
2437    on the stack. SL specifies LS with a bit offset of 0.
2438
24392.  `DW_OP_stack_value`
2440
2441    `DW_OP_stack_value` pops one stack entry that must be a value V.
2442
2443    An implicit location storage LS is created with the literal value V using
2444    the size, encoding, and enianity specified by V's base type.
2445
2446    It pushes a location description L with one implicit location description SL
2447    on the stack. SL specifies LS with a bit offset of 0.
2448
2449    <i>The `DW_OP_stack_value` operation specifies that the object does not
2450    exist in memory, but its value is nonetheless known. In this form, the
2451    location description specifies the actual value of the object, rather than
2452    specifying the memory or register storage that holds the value.</i>
2453
2454    See [2.5.4.4.5 Implicit Location Description
2455    Operations](#implicit-location-description-operations) for special
2456    rules concerning implicit pointer values produced by dereferencing implicit
2457    location descriptions created by the `DW_OP_implicit_pointer` operation.
2458
2459    > NOTE: Since location descriptions are allowed on the stack, the
2460    > `DW_OP_stack_value` operation no longer terminates the DWARF operation
2461    > expression execution as in DWARF Version 5.
2462
24633.  `DW_OP_implicit_pointer`
2464
2465    <i>An optimizing compiler may eliminate a pointer, while still retaining the
2466    value that the pointer addressed. `DW_OP_implicit_pointer` allows a producer
2467    to describe this value.</i>
2468
2469    <i>`DW_OP_implicit_pointer` specifies an object is a pointer to the target
2470    architecture default address space that cannot be represented as a real
2471    pointer, even though the value it would point to can be described. In this
2472    form, the location description specifies a debugging information entry that
2473    represents the actual location description of the object to which the
2474    pointer would point. Thus, a consumer of the debug information would be able
2475    to access the dereferenced pointer, even when it cannot access the pointer
2476    itself.</i>
2477
2478    `DW_OP_implicit_pointer` has two operands. The first operand is a 4-byte
2479    unsigned value in the 32-bit DWARF format, or an 8-byte unsigned value in
2480    the 64-bit DWARF format, that represents the byte offset DR of a debugging
2481    information entry D relative to the beginning of the `.debug_info` section
2482    that contains the current compilation unit. The second operand is a signed
2483    LEB128 integer that represents a byte displacement B.
2484
2485    <i>Note that D may not be in the current compilation unit.</i>
2486
2487    <i>The first operand interpretation is exactly like that for
2488    `DW_FORM_ref_addr`.</i>
2489
2490    The address space identifier AS is defined as the one corresponding to the
2491    target architecture specific default address space.
2492
2493    The address size S is defined as the address bit size of the target
2494    architecture specific address space corresponding to AS.
2495
2496    An implicit location storage LS is created with the debugging information
2497    entry D, address space AS, and size of S.
2498
2499    It pushes a location description L that comprises one implicit location
2500    description SL on the stack. SL specifies LS with a bit offset of 0.
2501
2502    It is an evaluation error if a `DW_OP_deref*` operation pops a location
2503    description L', and retrieves S bits, such that any retrieved bits come from
2504    an implicit location storage that is the same as LS, unless both the
2505    following conditions are met:
2506
2507    1.  All retrieved bits come from an implicit location description that
2508        refers to an implicit location storage that is the same as LS.
2509
2510        <i>Note that all bits do not have to come from the same implicit
2511        location description, as L' may involve composite location
2512        descriptors.</i>
2513
2514    2.  The bits come from consecutive ascending offsets within their respective
2515        implicit location storage.
2516
2517    <i>These rules are equivalent to retrieving the complete contents of LS.</i>
2518
2519    If both the above conditions are met, then the value V pushed by the
2520    `DW_OP_deref*` operation is an implicit pointer value IPV with a target
2521    architecture specific address space of AS, a debugging information entry of
2522    D, and a base type of T. If AS is the target architecture default address
2523    space, then T is the generic type. Otherwise, T is a target architecture
2524    specific integral type with a bit size equal to S.
2525
2526    If IPV is either implicitly converted to a location description (only done
2527    if AS is the target architecture default address space), then the resulting
2528    location description RL is:
2529
2530    - If D has a `DW_AT_location` attribute, the DWARF expression E from the
2531      `DW_AT_location` attribute is evaluated with the current context, except
2532      that the result kind is a location description, the compilation unit is
2533      the one that contains D, the object is unspecified, and the initial stack
2534      is empty. RL is the expression result.
2535
2536      <i>Note that E is evaluated with the context of the expression accessing
2537      IPV, and not the context of the expression that contained the
2538      `DW_OP_implicit_pointer` operation that created L.</i>
2539
2540    - If D has a `DW_AT_const_value` attribute, then an implicit location
2541      storage RLS is created from the `DW_AT_const_value` attribute's value with
2542      a size matching the size of the `DW_AT_const_value` attribute's value. RL
2543      comprises one implicit location description SRL. SRL specifies RLS with a
2544      bit offset of 0.
2545
2546      > NOTE: If using `DW_AT_const_value` for variables and formal parameters
2547      > is deprecated and instead `DW_AT_location` is used with an implicit
2548      > location description, then this rule would not be required.
2549
2550    - Otherwise, it is an evaluation error.
2551
2552    The location description RL is updated by bit offset B scaled by 8 (the byte
2553    size).
2554
2555    If a `DW_OP_stack_value` operation pops a value that is the same as IPV,
2556    then it pushes a location description that is the same as L.
2557
2558    It is an evaluation error if LS or IPV is accessed in any other manner.
2559
2560    <i>The restrictions on how an implicit pointer location description created
2561    by `DW_OP_implicit_pointer` can be used are to simplify the DWARF consumer.
2562    Similarly, for an implicit pointer value created by `DW_OP_deref*` and
2563    `DW_OP_stack_value`.</i>
2564
2565<i>Typically a `DW_OP_implicit_pointer` operation is used in a DWARF expression
2566E<sub>1</sub> of a `DW_TAG_variable` or `DW_TAG_formal_parameter` debugging
2567information entry D<sub>1</sub>'s `DW_AT_location` attribute. The debugging
2568information entry referenced by the `DW_OP_implicit_pointer` operation is
2569typically itself a `DW_TAG_variable` or `DW_TAG_formal_parameter` debugging
2570information entry D<sub>2</sub> whose `DW_AT_location` attribute gives a second
2571DWARF expression E<sub>2</sub>.</i>
2572
2573<i>D<sub>1</sub> and E<sub>1</sub> are describing the location of a pointer type
2574object. D<sub>2</sub> and E<sub>2</sub> are describing the location of the
2575object pointed to by that pointer object.</i>
2576
2577<i>However, D<sub>2</sub> may be any debugging information entry that contains a
2578`DW_AT_location` or `DW_AT_const_value` attribute (for example,
2579`DW_TAG_dwarf_procedure`). By using E<sub>2</sub>, a consumer can reconstruct
2580the value of the object when asked to dereference the pointer described by
2581E<sub>1</sub> which contains the `DW_OP_implicit_pointer` operation.</i>
2582
2583###### A.2.5.4.4.6 Composite Location Description Operations
2584
2585> NOTE: This section replaces DWARF Version 5 section 2.6.1.2.
2586
2587A composite location storage represents an object or value which may be
2588contained in part of another location storage or contained in parts of more than
2589one location storage.
2590
2591Each part has a part location description L and a part bit size S. L can have
2592one or more single location descriptions SL. If there are more than one SL then
2593that indicates that part is located in more than one place. The bits of each
2594place of the part comprise S contiguous bits from the location storage LS
2595specified by SL starting at the bit offset specified by SL. All the bits must be
2596within the size of LS or the DWARF expression is ill-formed.
2597
2598A composite location storage can have zero or more parts. The parts are
2599contiguous such that the zero-based location storage bit index will range over
2600each part with no gaps between them. Therefore, the size of a composite location
2601storage is the sum of the size of its parts. The DWARF expression is ill-formed
2602if the size of the contiguous location storage is larger than the size of the
2603memory location storage corresponding to the largest target architecture
2604specific address space.
2605
2606A composite location description specifies a composite location storage. The bit
2607offset corresponds to a bit position within the composite location storage.
2608
2609There are operations that create a composite location storage.
2610
2611There are other operations that allow a composite location storage to be
2612incrementally created. Each part is created by a separate operation. There may
2613be one or more operations to create the final composite location storage. A
2614series of such operations describes the parts of the composite location storage
2615that are in the order that the associated part operations are executed.
2616
2617To support incremental creation, a composite location storage can be in an
2618incomplete state. When an incremental operation operates on an incomplete
2619composite location storage, it adds a new part.
2620
2621A composite location description that specifies a composite location storage
2622that is incomplete is termed an incomplete composite location description. A
2623composite location description that specifies a composite location storage that
2624is complete is termed a complete composite location description.
2625
2626If the top stack entry is a location description that has one incomplete
2627composite location description SL after the execution of an operation expression
2628has completed, SL is converted to a complete composite location description.
2629
2630<i>Note that this conversion does not happen after the completion of an
2631operation expression that is evaluated on the same stack by the `DW_OP_call*`
2632operations. Such executions are not a separate evaluation of an operation
2633expression, but rather the continued evaluation of the same operation expression
2634that contains the `DW_OP_call*` operation.</i>
2635
2636If a stack entry is required to be a location description L, but L has an
2637incomplete composite location description, then the DWARF expression is
2638ill-formed. The exception is for the operations involved in incrementally
2639creating a composite location description as described below.
2640
2641<i>Note that a DWARF operation expression may arbitrarily compose composite
2642location descriptions from any other location description, including those that
2643have multiple single location descriptions, and those that have composite
2644location descriptions.</i>
2645
2646<i>The incremental composite location description operations are defined to be
2647compatible with the definitions in DWARF Version 5.</i>
2648
26491.  `DW_OP_piece`
2650
2651    `DW_OP_piece` has a single unsigned LEB128 integer that represents a byte
2652    size S.
2653
2654    The action is based on the context:
2655
2656    - If the stack is empty, then a location description L comprised of one
2657      incomplete composite location description SL is pushed on the stack.
2658
2659      An incomplete composite location storage LS is created with a single part
2660      P. P specifies a location description PL and has a bit size of S scaled by
2661      8 (the byte size). PL is comprised of one undefined location description
2662      PSL.
2663
2664      SL specifies LS with a bit offset of 0.
2665
2666    - Otherwise, if the top stack entry is a location description L comprised of
2667      one incomplete composite location description SL, then the incomplete
2668      composite location storage LS that SL specifies is updated to append a new
2669      part P. P specifies a location description PL and has a bit size of S
2670      scaled by 8 (the byte size). PL is comprised of one undefined location
2671      description PSL. L is left on the stack.
2672    - Otherwise, if the top stack entry is a location description or can be
2673      converted to one, then it is popped and treated as a part location
2674      description PL. Then:
2675
2676      - If the top stack entry (after popping PL) is a location description L
2677        comprised of one incomplete composite location description SL, then the
2678        incomplete composite location storage LS that SL specifies is updated to
2679        append a new part P. P specifies the location description PL and has a
2680        bit size of S scaled by 8 (the byte size). L is left on the stack.
2681      - Otherwise, a location description L comprised of one
2682        incomplete composite location description SL is pushed on
2683        the stack.
2684
2685        An incomplete composite location storage LS is created with a single
2686        part P. P specifies the location description PL and has a bit size of S
2687        scaled by 8 (the byte size).
2688
2689        SL specifies LS with a bit offset of 0.
2690
2691    - Otherwise, the DWARF expression is ill-formed
2692
2693    <i>Many compilers store a single variable in sets of registers or store a
2694    variable partially in memory and partially in registers. `DW_OP_piece`
2695    provides a way of describing where a part of a variable is located.</i>
2696
2697    <i>The evaluation rules for the `DW_OP_piece` operation allow it to be
2698    compatible with the DWARF Version 5 definition.</i>
2699
2700    > NOTE: Since these extensions allow location descriptions to be entries on
2701    > the stack, a simpler operation to create composite location descriptions
2702    > could be defined. For example, just one operation that specifies how many
2703    > parts, and pops pairs of stack entries for the part size and location
2704    > description. Not only would this be a simpler operation and avoid the
2705    > complexities of incomplete composite location descriptions, but it may
2706    > also have a smaller encoding in practice. However, the desire for
2707    > compatibility with DWARF Version 5 is likely a stronger consideration.
2708
27092.  `DW_OP_bit_piece`
2710
2711    `DW_OP_bit_piece` has two operands. The first is an unsigned LEB128 integer
2712    that represents the part bit size S. The second is an unsigned LEB128
2713    integer that represents a bit displacement B.
2714
2715    The action is the same as for `DW_OP_piece`, except that any part created
2716    has the bit size S, and the location description PL of any created part is
2717    updated by a bit offset B.
2718
2719    <i>`DW_OP_bit_piece` is used instead of `DW_OP_piece` when the piece to be
2720    assembled is not byte-sized or is not at the start of the part location
2721    description.</i>
2722
2723#### A.2.5.5 DWARF Location List Expressions
2724
2725> NOTE: This section replaces DWARF Version 5 section 2.6.2.
2726
2727<i>To meet the needs of recent computer architectures and optimization
2728techniques, debugging information must be able to describe the location of an
2729object whose location changes over the object's lifetime, and may reside at
2730multiple locations during parts of an object's lifetime. Location list
2731expressions are used in place of operation expressions whenever the object whose
2732location is being described has these requirements.</i>
2733
2734A location list expression consists of a series of location list entries. Each
2735location list entry is one of the following kinds:
2736
27371.  <i>Bounded location description</i>
2738
2739    This kind of location list entry provides an operation expression that
2740    evaluates to the location description of an object that is valid over a
2741    lifetime bounded by a starting and ending address. The starting address is
2742    the lowest address of the address range over which the location is valid.
2743    The ending address is the address of the first location past the highest
2744    address of the address range.
2745
2746    The location list entry matches when the current program location is within
2747    the given range.
2748
2749    There are several kinds of bounded location description entries which differ
2750    in the way that they specify the starting and ending addresses.
2751
27522.  <i>Default location description</i>
2753
2754    This kind of location list entry provides an operation expression that
2755    evaluates to the location description of an object that is valid when no
2756    bounded location description entry applies.
2757
2758    The location list entry matches when the current program location is not
2759    within the range of any bounded location description entry.
2760
27613.  <i>Base address</i>
2762
2763    This kind of location list entry provides an address to be used as the base
2764    address for beginning and ending address offsets given in certain kinds of
2765    bounded location description entries. The applicable base address of a
2766    bounded location description entry is the address specified by the closest
2767    preceding base address entry in the same location list. If there is no
2768    preceding base address entry, then the applicable base address defaults to
2769    the base address of the compilation unit (see DWARF Version 5 section
2770    3.1.1).
2771
2772    In the case of a compilation unit where all of the machine code is contained
2773    in a single contiguous section, no base address entry is needed.
2774
27754.  <i>End-of-list</i>
2776
2777    This kind of location list entry marks the end of the location list
2778    expression.
2779
2780The address ranges defined by the bounded location description entries of a
2781location list expression may overlap. When they do, they describe a situation in
2782which an object exists simultaneously in more than one place.
2783
2784If all of the address ranges in a given location list expression do not
2785collectively cover the entire range over which the object in question is
2786defined, and there is no following default location description entry, it is
2787assumed that the object is not available for the portion of the range that is
2788not covered.
2789
2790The result of the evaluation of a DWARF location list expression is:
2791
2792- If the current program location is not specified, then it is an evaluation
2793  error.
2794
2795  > NOTE: If the location list only has a single default entry, should that be
2796  > considered a match if there is no program location? If there are non-default
2797  > entries then it seems it has to be an evaluation error when there is no
2798  > program location as that indicates the location depends on the program
2799  > location which is not known.
2800
2801- If there are no matching location list entries, then the result is a location
2802  description that comprises one undefined location description.
2803- Otherwise, the operation expression E of each matching location list entry is
2804  evaluated with the current context, except that the result kind is a location
2805  description, the object is unspecified, and the initial stack is empty. The
2806  location list entry result is the location description returned by the
2807  evaluation of E.
2808
2809  The result is a location description that is comprised of the union of the
2810  single location descriptions of the location description result of each
2811  matching location list entry.
2812
2813A location list expression can only be used as the value of a debugger
2814information entry attribute that is encoded using class `loclist` or
2815`loclistsptr` (see [7.5.5 Classes and Forms](#classes-and-forms)). The value of
2816the attribute provides an index into a separate object file section called
2817`.debug_loclists` or `.debug_loclists.dwo` (for split DWARF object files) that
2818contains the location list entries.
2819
2820A `DW_OP_call*` and `DW_OP_implicit_pointer` operation can be used to specify a
2821debugger information entry attribute that has a location list expression.
2822Several debugger information entry attributes allow DWARF expressions that are
2823evaluated with an initial stack that includes a location description that may
2824originate from the evaluation of a location list expression.
2825
2826<i>This location list representation, the `loclist` and `loclistsptr` class, and
2827the related `DW_AT_loclists_base` attribute are new in DWARF Version 5. Together
2828they eliminate most, or all of the code object relocations previously needed for
2829location list expressions.</i>
2830
2831> NOTE: The rest of this section is the same as DWARF Version 5 section 2.6.2.
2832
2833## A.3 Program Scope Entries
2834
2835> NOTE: This section provides changes to existing debugger information entry
2836> attributes. These would be incorporated into the corresponding DWARF Version 5
2837> chapter 3 sections.
2838
2839### A.3.3 Subroutine and Entry Point Entries
2840
2841#### A.3.3.5 Low-Level Information
2842
28431.  A `DW_TAG_subprogram`, `DW_TAG_inlined_subroutine`, or `DW_TAG_entry_point`
2844    debugger information entry may have a `DW_AT_return_addr` attribute, whose
2845    value is a DWARF expression E.
2846
2847    The result of the attribute is obtained by evaluating E with a context that
2848    has a result kind of a location description, an unspecified object, the
2849    compilation unit that contains E, an empty initial stack, and other context
2850    elements corresponding to the source language thread of execution upon which
2851    the user is focused, if any. The result of the evaluation is the location
2852    description L of the place where the return address for the current call
2853    frame's subprogram or entry point is stored.
2854
2855    The DWARF is ill-formed if L is not comprised of one memory location
2856    description for one of the target architecture specific address spaces.
2857
2858    > NOTE: It is unclear why `DW_TAG_inlined_subroutine` has a
2859    > `DW_AT_return_addr` attribute but not a `DW_AT_frame_base` or
2860    > `DW_AT_static_link` attribute. Seems it would either have all of them or
2861    > none. Since inlined subprograms do not have a call frame it seems they
2862    > would have none of these attributes.
2863
28642.  A `DW_TAG_subprogram` or `DW_TAG_entry_point` debugger information entry may
2865    have a `DW_AT_frame_base` attribute, whose value is a DWARF expression E.
2866
2867    The result of the attribute is obtained by evaluating E with a context that
2868    has a result kind of a location description, an unspecified object, the
2869    compilation unit that contains E, an empty initial stack, and other context
2870    elements corresponding to the source language thread of execution upon which
2871    the user is focused, if any.
2872
2873    The DWARF is ill-formed if E contains an `DW_OP_fbreg` operation, or the
2874    resulting location description L is not comprised of one single location
2875    description SL.
2876
2877    If SL is a register location description for register R, then L is replaced
2878    with the result of evaluating a `DW_OP_bregx R, 0` operation. This computes
2879    the frame base memory location description in the target architecture
2880    default address space.
2881
2882    <i>This allows the more compact `DW_OP_reg*` to be used instead of
2883    `DW_OP_breg* 0`.</i>
2884
2885    > NOTE: This rule could be removed and require the producer to create the
2886    > required location description directly using `DW_OP_call_frame_cfa` or
2887    > `DW_OP_breg*`. This would also then allow a target to implement the call
2888    > frames within a large register.
2889
2890    Otherwise, the DWARF is ill-formed if SL is not a memory location
2891    description in any of the target architecture specific address spaces.
2892
2893    The resulting L is the <i>frame base</i> for the subprogram or entry point.
2894
2895    <i>Typically, E will use the `DW_OP_call_frame_cfa` operation or be a stack
2896    pointer register plus or minus some offset.</i>
2897
28983.  If a `DW_TAG_subprogram` or `DW_TAG_entry_point` debugger information entry
2899    is lexically nested, it may have a `DW_AT_static_link` attribute, whose
2900    value is a DWARF expression E.
2901
2902    The result of the attribute is obtained by evaluating E with a context that
2903    has a result kind of a location description, an unspecified object, the
2904    compilation unit that contains E, an empty initial stack, and other context
2905    elements corresponding to the source language thread of execution upon which
2906    the user is focused, if any. The result of the evaluation is the location
2907    description L of the <i>canonical frame address</i> (see [6.4 Call Frame
2908    Information](#call-frame-information)) of the relevant call frame of the
2909    subprogram instance that immediately lexically encloses the current call
2910    frame's subprogram or entry point.
2911
2912    The DWARF is ill-formed if L is is not comprised of one memory location
2913    description for one of the target architecture specific address spaces.
2914
2915### A.3.4 Call Site Entries and Parameters
2916
2917#### A.3.4.2 Call Site Parameters
2918
29191.  A `DW_TAG_call_site_parameter` debugger information entry may have a
2920    `DW_AT_call_value` attribute, whose value is a DWARF operation expression
2921    E<sub>1</sub>.
2922
2923    The result of the `DW_AT_call_value` attribute is obtained by evaluating
2924    E<sub>1</sub> with a context that has a result kind of a value, an unspecified
2925    object, the compilation unit that contains E, an empty initial stack, and other
2926    context elements corresponding to the source language thread of execution upon
2927    which the user is focused, if any. The resulting value V<sub>1</sub> is the
2928    value of the parameter at the time of the call made by the call site.
2929
2930    For parameters passed by reference, where the code passes a pointer to a
2931    location which contains the parameter, or for reference type parameters, the
2932    `DW_TAG_call_site_parameter` debugger information entry may also have a
2933    `DW_AT_call_data_location` attribute whose value is a DWARF operation expression
2934    E<sub>2</sub>, and a `DW_AT_call_data_value` attribute whose value is a DWARF
2935    operation expression E<sub>3</sub>.
2936
2937    The value of the `DW_AT_call_data_location` attribute is obtained by evaluating
2938    E<sub>2</sub> with a context that has a result kind of a location description,
2939    an unspecified object, the compilation unit that contains E, an empty initial
2940    stack, and other context elements corresponding to the source language thread of
2941    execution upon which the user is focused, if any. The resulting location
2942    description L<sub>2</sub> is the location where the referenced parameter lives
2943    during the call made by the call site. If E<sub>2</sub> would just be a
2944    `DW_OP_push_object_address`, then the `DW_AT_call_data_location` attribute may
2945    be omitted.
2946
2947    > NOTE: The DWARF Version 5 implies that `DW_OP_push_object_address` may be
2948    > used but does not state what object must be specified in the context.
2949    > Either `DW_OP_push_object_address` cannot be used, or the object to be
2950    > passed in the context must be defined.
2951
2952    The value of the `DW_AT_call_data_value` attribute is obtained by evaluating
2953    E<sub>3</sub> with a context that has a result kind of a value, an unspecified
2954    object, the compilation unit that contains E, an empty initial stack, and other
2955    context elements corresponding to the source language thread of execution upon
2956    which the user is focused, if any. The resulting value V<sub>3</sub> is the
2957    value in L<sub>2</sub> at the time of the call made by the call site.
2958
2959    The result of these attributes is undefined if the current call frame is not for
2960    the subprogram containing the `DW_TAG_call_site_parameter` debugger information
2961    entry or the current program location is not for the call site containing the
2962    `DW_TAG_call_site_parameter` debugger information entry in the current call
2963    frame.
2964
2965    <i>The consumer may have to virtually unwind to the call site (see [6.4 Call
2966    Frame Information](#call-frame-information)) in order to evaluate these
2967    attributes. This will ensure the source language thread of execution upon which
2968    the user is focused corresponds to the call site needed to evaluate the
2969    expression.</i>
2970
2971    If it is not possible to avoid the expressions of these attributes from
2972    accessing registers or memory locations that might be clobbered by the
2973    subprogram being called by the call site, then the associated attribute should
2974    not be provided.
2975
2976    <i>The reason for the restriction is that the parameter may need to be accessed
2977    during the execution of the callee. The consumer may virtually unwind from the
2978    called subprogram back to the caller and then evaluate the attribute
2979    expressions. The call frame information (see [6.4 Call Frame
2980    Information](#call-frame-information)) will not be able to restore registers
2981    that have been clobbered, and clobbered memory will no longer have the value at
2982    the time of the call.</i>
2983
2984### A.3.5 Lexical Block Entries
2985
2986> NOTE: This section is the same as DWARF Version 5 section 3.5.
2987
2988## A.4 Data Object and Object List Entries
2989
2990> NOTE: This section provides changes to existing debugger information entry
2991> attributes. These would be incorporated into the corresponding DWARF Version 5
2992> chapter 4 sections.
2993
2994### A.4.1 Data Object Entries
2995
29961.  Any debugging information entry describing a data object (which includes
2997    variables and parameters) or common blocks may have a `DW_AT_location`
2998    attribute, whose value is a DWARF expression E.
2999
3000    The result of the attribute is obtained by evaluating E with a context that
3001    has a result kind of a location description, an unspecified object, the
3002    compilation unit that contains E, an empty initial stack, and other context
3003    elements corresponding to the source language thread of execution upon which
3004    the user is focused, if any. The result of the evaluation is the location
3005    description of the base of the data object.
3006
3007    See [2.5.4.2 Control Flow Operations](#control-flow-operations) for special
3008    evaluation rules used by the `DW_OP_call*` operations.
3009
3010    > NOTE: Delete the description of how the `DW_OP_call*` operations evaluate
3011    > a `DW_AT_location` attribute as that is now described in the operations.
3012
3013    > NOTE: See the discussion about the `DW_AT_location` attribute in the
3014    > `DW_OP_call*` operation. Having each attribute only have a single purpose
3015    > and single execution semantics seems desirable. It makes it easier for the
3016    > consumer that no longer have to track the context. It makes it easier for
3017    > the producer as it can rely on a single semantics for each attribute.
3018    >
3019    > For that reason, limiting the `DW_AT_location` attribute to only
3020    > supporting evaluating the location description of an object, and using a
3021    > different attribute and encoding class for the evaluation of DWARF
3022    > expression <i>procedures</i> on the same operation expression stack seems
3023    > desirable.
3024
30252.  `DW_AT_const_value`
3026
3027    > NOTE: Could deprecate using the `DW_AT_const_value` attribute for
3028    > `DW_TAG_variable` or `DW_TAG_formal_parameter` debugger information
3029    > entries that have been optimized to a constant. Instead, `DW_AT_location`
3030    > could be used with a DWARF expression that produces an implicit location
3031    > description now that any location description can be used within a DWARF
3032    > expression. This allows the `DW_OP_call*` operations to be used to push
3033    > the location description of any variable regardless of how it is
3034    > optimized.
3035
3036## A.5 Type Entries
3037
3038> NOTE: This section provides changes to existing debugger information entry
3039> attributes. These would be incorporated into the corresponding DWARF Version 5
3040> chapter 5 sections.
3041
3042### A.5.7 Structure, Union, Class and Interface Type Entries
3043
3044#### A.5.7.3 Derived or Extended Structures, Classes and Interfaces
3045
30461.  For a `DW_AT_data_member_location` attribute there are two cases:
3047
3048    1.  If the attribute is an integer constant B, it provides the offset in
3049        bytes from the beginning of the containing entity.
3050
3051        The result of the attribute is obtained by updating the bit offset of
3052        the location description of the beginning of the containing entity by B
3053        scaled by 8 (the byte size). The result is the location description of
3054        the base of the member entry.
3055
3056        <i>If the beginning of the containing entity is not byte aligned, then
3057        the beginning of the member entry has the same bit displacement within a
3058        byte.</i>
3059
3060    2.  Otherwise, the attribute must be a DWARF expression E which is evaluated
3061        with a context that has a result kind of a location description, an
3062        unspecified object, the compilation unit that contains E, an initial
3063        stack comprising the location description of the beginning of the
3064        containing entity, and other context elements corresponding to the
3065        source language thread of execution upon which the user is focused, if
3066        any. The result of the evaluation is the location description of the
3067        base of the member entry.
3068
3069    > NOTE: The beginning of the containing entity can now be any location
3070    > description, including those with more than one single location
3071    > description, and those with single location descriptions that are of any
3072    > kind and have any bit offset.
3073
3074#### A.5.7.8 Member Function Entries
3075
30761.  An entry for a virtual function also has a `DW_AT_vtable_elem_location`
3077    attribute whose value is a DWARF expression E.
3078
3079    The result of the attribute is obtained by evaluating E with a context that
3080    has a result kind of a location description, an unspecified object, the
3081    compilation unit that contains E, an initial stack comprising the location
3082    description of the object of the enclosing type, and other context elements
3083    corresponding to the source language thread of execution upon which the user
3084    is focused, if any. The result of the evaluation is the location description
3085    of the slot for the function within the virtual function table for the
3086    enclosing class.
3087
3088### A.5.14 Pointer to Member Type Entries
3089
30901.  The `DW_TAG_ptr_to_member_type` debugging information entry has a
3091    `DW_AT_use_location` attribute whose value is a DWARF expression E. It is used
3092    to compute the location description of the member of the class to which the
3093    pointer to member entry points.
3094
3095    <i>The method used to find the location description of a given member of a
3096    class, structure, or union is common to any instance of that class, structure,
3097    or union and to any instance of the pointer to member type. The method is thus
3098    associated with the pointer to member type, rather than with each object that
3099    has a pointer to member type.</i>
3100
3101    The `DW_AT_use_location` DWARF expression is used in conjunction with the
3102    location description for a particular object of the given pointer to member type
3103    and for a particular structure or class instance.
3104
3105    The result of the attribute is obtained by evaluating E with a context that has
3106    a result kind of a location description, an unspecified object, the compilation
3107    unit that contains E, an initial stack comprising two entries, and other context
3108    elements corresponding to the source language thread of execution upon which the
3109    user is focused, if any. The first stack entry is the value of the pointer to
3110    member object itself. The second stack entry is the location description of the
3111    base of the entire class, structure, or union instance containing the member
3112    whose location is being calculated. The result of the evaluation is the location
3113    description of the member of the class to which the pointer to member entry
3114    points.
3115
3116### A.5.16 Dynamic Type Entries
3117
31181.  The `DW_AT_data_location` attribute may be used with any type that provides one
3119    or more levels of hidden indirection and/or run-time parameters in its
3120    representation. Its value is a DWARF operation expression E which computes the
3121    location description of the data for an object. When this attribute is omitted,
3122    the location description of the data is the same as the location description of
3123    the object.
3124
3125    The result of the attribute is obtained by evaluating E with a context that has
3126    a result kind of a location description, an object that is the location
3127    description of the data descriptor, the compilation unit that contains E, an
3128    empty initial stack, and other context elements corresponding to the source
3129    language thread of execution upon which the user is focused, if any. The result
3130    of the evaluation is the location description of the base of the member entry.
3131
3132    <i>E will typically involve an operation expression that begins with a
3133    `DW_OP_push_object_address` operation which loads the location description
3134    of the object which can then serve as a descriptor in subsequent
3135    calculation.</i>
3136
3137    > NOTE: Since `DW_AT_data_member_location`, `DW_AT_use_location`, and
3138    > `DW_AT_vtable_elem_location` allow both operation expressions and location
3139    > list expressions, why does `DW_AT_data_location` not allow both? In all cases
3140    > they apply to data objects so less likely that optimization would cause
3141    > different operation expressions for different program location ranges. But if
3142    > supporting for some then should be for all.
3143    >
3144    > It seems odd this attribute is not the same as `DW_AT_data_member_location` in
3145    > having an initial stack with the location description of the object since the
3146    > expression has to need it.
3147
3148## A.6 Other Debugging Information
3149
3150> NOTE: This section provides changes to existing debugger information entry
3151> attributes. These would be incorporated into the corresponding DWARF Version 5
3152> chapter 6 sections.
3153
3154### A.6.2 Line Number Information
3155
3156> NOTE: This section is the same as DWARF Version 5 section 6.2.
3157
3158### A.6.4 Call Frame Information
3159
3160> NOTE: This section provides changes to DWARF Version 5 section 6.4. Register
3161> unwind DWARF expressions are generalized to allow any location description,
3162> including those with composite and implicit location descriptions.
3163
3164#### A.6.4.1 Structure of Call Frame Information
3165
3166The register rules are:
3167
31681.  <i>undefined</i>
3169
3170    A register that has this rule has no recoverable value in the previous
3171    frame. The previous value of this register is the undefined location
3172    description (see [2.5.4.4.2 Undefined Location Description
3173    Operations](#undefined-location-description-operations)).
3174
3175    <i>By convention, the register is not preserved by a callee.</i>
3176
31772.  <i>same value</i>
3178
3179    This register has not been modified from the previous caller frame.
3180
3181    If the current frame is the top frame, then the previous value of this
3182    register is the location description L that specifies one register location
3183    description SL. SL specifies the register location storage that corresponds
3184    to the register with a bit offset of 0 for the current thread.
3185
3186    If the current frame is not the top frame, then the previous value of this
3187    register is the location description obtained using the call frame
3188    information for the callee frame and callee program location invoked by the
3189    current caller frame for the same register.
3190
3191    <i>By convention, the register is preserved by the callee, but the callee
3192    has not modified it.</i>
3193
31943.  <i>offset(N)</i>
3195
3196    N is a signed byte offset. The previous value of this register is saved at
3197    the location description L. Where L is the location description of the
3198    current CFA (see [2.5.4 DWARF Operation
3199    Expressions](#dwarf-operation-expressions)) updated with the bit offset N
3200    scaled by 8 (the byte size).
3201
32024.  <i>val_offset(N)</i>
3203
3204    N is a signed byte offset. The previous value of this register is the memory
3205    byte address of the location description L. Where L is the location
3206    description of the current CFA (see [2.5.4 DWARF Operation
3207    Expressions](#dwarf-operation-expressions)) updated with the bit offset N
3208    scaled by 8 (the byte size).
3209
3210    The DWARF is ill-formed if the CFA location description is not a memory byte
3211    address location description, or if the register size does not match the
3212    size of an address in the target architecture default address space.
3213
3214    <i>Since the CFA location description is required to be a memory byte
3215    address location description, the value of val_offset(N) will also be a
3216    memory byte address location description since it is offsetting the CFA
3217    location description by N bytes. Furthermore, the value of val_offset(N)
3218    will be a memory byte address in the target architecture default address
3219    space.</i>
3220
3221    > NOTE: Should DWARF allow the address size to be a different size to the
3222    > size of the register? Requiring them to be the same bit size avoids any
3223    > issue of conversion as the bit contents of the register is simply
3224    > interpreted as a value of the address.
3225    >
3226    > GDB has a per register hook that allows a target specific conversion on a
3227    > register by register basis. It defaults to truncation of bigger registers,
3228    > and to actually reading bytes from the next register (or reads out of
3229    > bounds for the last register) for smaller registers. There are no GDB
3230    > tests that read a register out of bounds (except an illegal hand written
3231    > assembly test).
3232
32335.  <i>register(R)</i>
3234
3235    This register has been stored in another register numbered R.
3236
3237    The previous value of this register is the location description obtained
3238    using the call frame information for the current frame and current program
3239    location for register R.
3240
3241    The DWARF is ill-formed if the size of this register does not match the size
3242    of register R or if there is a cyclic dependency in the call frame
3243    information.
3244
3245    > NOTE: Should this also allow R to be larger than this register? If so is
3246    > the value stored in the low order bits and it is undefined what is stored
3247    > in the extra upper bits?
3248
32496.  <i>expression(E)</i>
3250
3251    The previous value of this register is located at the location description
3252    produced by evaluating the DWARF operation expression E (see [2.5.4 DWARF
3253    Operation Expressions](#dwarf-operation-expressions)).
3254
3255    E is evaluated with the current context, except the result kind is a
3256    location description, the compilation unit is unspecified, the object is
3257    unspecified, and an initial stack comprising the location description of the
3258    current CFA (see [2.5.4 DWARF Operation
3259    Expressions](#dwarf-operation-expressions)).
3260
32617.  <i>val_expression(E)</i>
3262
3263    The previous value of this register is the value produced by evaluating the
3264    DWARF operation expression E (see [2.5.4 DWARF Operation
3265    Expressions](#dwarf-operation-expressions)).
3266
3267    E is evaluated with the current context, except the result kind is a value,
3268    the compilation unit is unspecified, the object is unspecified, and an
3269    initial stack comprising the location description of the current CFA (see
3270    [2.5.4 DWARF Operation Expressions](#dwarf-operation-expressions)).
3271
3272    The DWARF is ill-formed if the resulting value type size does not match the
3273    register size.
3274
3275    > NOTE: This has limited usefulness as the DWARF expression E can only
3276    > produce values up to the size of the generic type. This is due to not
3277    > allowing any operations that specify a type in a CFI operation expression.
3278    > This makes it unusable for registers that are larger than the generic
3279    > type. However, <i>expression(E)</i> can be used to create an implicit
3280    > location description of any size.
3281
32828.  <i>architectural</i>
3283
3284    The rule is defined externally to this specification by the augmenter.
3285
3286A Common Information Entry (CIE) holds information that is shared among many
3287Frame Description Entries (FDE). There is at least one CIE in every non-empty
3288`.debug_frame` section. A CIE contains the following fields, in order:
3289
32901.  `length` (initial length)
3291
3292    A constant that gives the number of bytes of the CIE structure, not
3293    including the length field itself. The size of the length field plus the
3294    value of length must be an integral multiple of the address size specified
3295    in the `address_size` field.
3296
32972.  `CIE_id` (4 or 8 bytes, see [7.4 32-Bit and 64-Bit DWARF
3298    Formats](#32-bit-and-64-bit-dwarf-formats))
3299
3300    A constant that is used to distinguish CIEs from FDEs.
3301
3302    In the 32-bit DWARF format, the value of the CIE id in the CIE header is
3303    0xffffffff; in the 64-bit DWARF format, the value is 0xffffffffffffffff.
3304
33053.  `version` (ubyte)
3306
3307    A version number. This number is specific to the call frame information and
3308    is independent of the DWARF version number.
3309
3310    The value of the CIE version number is 4.
3311
3312    > NOTE: Would this be increased to 5 to reflect the changes in these
3313    > extensions?
3314
33154.  `augmentation` (sequence of UTF-8 characters)
3316
3317    A null-terminated UTF-8 string that identifies the augmentation to this CIE
3318    or to the FDEs that use it. If a reader encounters an augmentation string
3319    that is unexpected, then only the following fields can be read:
3320
3321    - CIE: length, CIE_id, version, augmentation
3322    - FDE: length, CIE_pointer, initial_location, address_range
3323
3324    If there is no augmentation, this value is a zero byte.
3325
3326    <i>The augmentation string allows users to indicate that there is additional
3327    vendor and target architecture specific information in the CIE or FDE which
3328    is needed to virtually unwind a stack frame. For example, this might be
3329    information about dynamically allocated data which needs to be freed on exit
3330    from the routine.</i>
3331
3332    <i>Because the `.debug_frame` section is useful independently of any
3333    `.debug_info` section, the augmentation string always uses UTF-8
3334    encoding.</i>
3335
33365.  `address_size` (ubyte)
3337
3338    The size of a target address in this CIE and any FDEs that use it, in bytes.
3339    If a compilation unit exists for this frame, its address size must match the
3340    address size here.
3341
33426.  `segment_selector_size` (ubyte)
3343
3344    The size of a segment selector in this CIE and any FDEs that use it, in
3345    bytes.
3346
33477.  `code_alignment_factor` (unsigned LEB128)
3348
3349    A constant that is factored out of all advance location instructions (see
3350    [6.4.2.1 Row Creation Instructions](#row-creation-instructions)). The
3351    resulting value is `(operand * code_alignment_factor)`.
3352
33538.  `data_alignment_factor` (signed LEB128)
3354
3355    A constant that is factored out of certain offset instructions (see [6.4.2.2
3356    CFA Definition Instructions](#cfa-definition-instructions) and [6.4.2.3
3357    Register Rule Instructions](#register-rule-instructions)). The
3358    resulting value is `(operand * data_alignment_factor)`.
3359
33609.  `return_address_register` (unsigned LEB128)
3361
3362    An unsigned LEB128 constant that indicates which column in the rule table
3363    represents the return address of the subprogram. Note that this column might
3364    not correspond to an actual machine register.
3365
3366    The value of the return address register is used to determine the program
3367    location of the caller frame. The program location of the top frame is the
3368    target architecture program counter value of the current thread.
3369
337010. `initial_instructions` (array of ubyte)
3371
3372    A sequence of rules that are interpreted to create the initial setting of
3373    each column in the table.
3374
3375    The default rule for all columns before interpretation of the initial
3376    instructions is the undefined rule. However, an ABI authoring body or a
3377    compilation system authoring body may specify an alternate default value for
3378    any or all columns.
3379
338011. `padding` (array of ubyte)
3381
3382    Enough `DW_CFA_nop` instructions to make the size of this entry match the
3383    length value above.
3384
3385An FDE contains the following fields, in order:
3386
33871.  `length` (initial length)
3388
3389    A constant that gives the number of bytes of the header and instruction
3390    stream for this subprogram, not including the length field itself. The size
3391    of the length field plus the value of length must be an integral multiple of
3392    the address size.
3393
33942.  `CIE_pointer` (4 or 8 bytes, see [7.4 32-Bit and 64-Bit DWARF
3395    Formats](#32-bit-and-64-bit-dwarf-formats))
3396
3397    A constant offset into the `.debug_frame` section that denotes the CIE that
3398    is associated with this FDE.
3399
34003.  `initial_location` (segment selector and target address)
3401
3402    The address of the first location associated with this table entry. If the
3403    segment_selector_size field of this FDE's CIE is non-zero, the initial
3404    location is preceded by a segment selector of the given length.
3405
34064.  `address_range` (target address)
3407
3408    The number of bytes of program instructions described by this entry.
3409
34105.  `instructions` (array of ubyte)
3411
3412    A sequence of table defining instructions that are described in [6.4.2 Call
3413    Frame Instructions](#call-frame-instructions).
3414
34156.  `padding` (array of ubyte)
3416
3417    Enough `DW_CFA_nop` instructions to make the size of this entry match the
3418    length value above.
3419
3420#### A.6.4.2 Call Frame Instructions
3421
3422Some call frame instructions have operands that are encoded as DWARF operation
3423expressions E (see [2.5.4 DWARF Operation
3424Expressions](#dwarf-operation-expressions)). The DWARF operations that can be
3425used in E have the following restrictions:
3426
3427- `DW_OP_addrx`, `DW_OP_call2`, `DW_OP_call4`, `DW_OP_call_ref`,
3428  `DW_OP_const_type`, `DW_OP_constx`, `DW_OP_convert`, `DW_OP_deref_type`,
3429  `DW_OP_fbreg`, `DW_OP_implicit_pointer`, `DW_OP_regval_type`,
3430  `DW_OP_reinterpret`, and `DW_OP_xderef_type` operations are not allowed
3431  because the call frame information must not depend on other debug sections.
3432- `DW_OP_push_object_address` is not allowed because there is no object context
3433  to provide a value to push.
3434- `DW_OP_call_frame_cfa` and `DW_OP_entry_value` are not allowed because their
3435  use would be circular.
3436
3437<i>Call frame instructions to which these restrictions apply include
3438`DW_CFA_def_cfa_expression`, `DW_CFA_expression`, and
3439`DW_CFA_val_expression`.</i>
3440
3441##### A.6.4.2.1 Row Creation Instructions
3442
3443> NOTE: These instructions are the same as in DWARF Version 5 section 6.4.2.1.
3444
3445##### A.6.4.2.2 CFA Definition Instructions
3446
34471.  `DW_CFA_def_cfa`
3448
3449    The `DW_CFA_def_cfa` instruction takes two unsigned LEB128 operands
3450    representing a register number R and a (non-factored) byte displacement B.
3451    The required action is to define the current CFA rule to be the result of
3452    evaluating the DWARF operation expression `DW_OP_bregx R, B` as a location
3453    description.
3454
34552.  `DW_CFA_def_cfa_sf`
3456
3457    The `DW_CFA_def_cfa_sf` instruction takes two operands: an unsigned LEB128
3458    value representing a register number R and a signed LEB128 factored byte
3459    displacement B. The required action is to define the current CFA rule to be
3460    the result of evaluating the DWARF operation expression `DW_OP_bregx R, B *
3461    data_alignment_factor` as a location description.
3462
3463    <i>The action is the same as `DW_CFA_def_cfa`, except that the second
3464    operand is signed and factored.</i>
3465
34663.  `DW_CFA_def_cfa_register`
3467
3468    The `DW_CFA_def_cfa_register` instruction takes a single unsigned LEB128
3469    operand representing a register number R. The required action is to define
3470    the current CFA rule to be the result of evaluating the DWARF operation
3471    expression `DW_OP_bregx R, B` as a location description. B is the old CFA
3472    byte displacement.
3473
3474    If the subprogram has no current CFA rule, or the rule was defined by a
3475    `DW_CFA_def_cfa_expression` instruction, then the DWARF is ill-formed.
3476
34774.  `DW_CFA_def_cfa_offset`
3478
3479    The `DW_CFA_def_cfa_offset` instruction takes a single unsigned LEB128
3480    operand representing a (non-factored) byte displacement B. The required
3481    action is to define the current CFA rule to be the result of evaluating the
3482    DWARF operation expression `DW_OP_bregx R, B` as a location description. R
3483    is the old CFA register number.
3484
3485    If the subprogram has no current CFA rule, or the rule was defined by a
3486    `DW_CFA_def_cfa_expression` instruction, then the DWARF is ill-formed.
3487
34885.  `DW_CFA_def_cfa_offset_sf`
3489
3490    The `DW_CFA_def_cfa_offset_sf` instruction takes a signed LEB128 operand
3491    representing a factored byte displacement B. The required action is to
3492    define the current CFA rule to be the result of evaluating the DWARF
3493    operation expression `DW_OP_bregx R, B * data_alignment_factor` as a
3494    location description. R is the old CFA register number.
3495
3496    If the subprogram has no current CFA rule, or the rule was defined by a
3497    `DW_CFA_def_cfa_expression` instruction, then the DWARF is ill-formed.
3498
3499    <i>The action is the same as `DW_CFA_def_cfa_offset`, except that the
3500    operand is signed and factored.</i>
3501
35026.  `DW_CFA_def_cfa_expression`
3503
3504    The `DW_CFA_def_cfa_expression` instruction takes a single operand encoded
3505    as a `DW_FORM_exprloc` value representing a DWARF operation expression E.
3506    The required action is to define the current CFA rule to be the result of
3507    evaluating E with the current context, except the result kind is a location
3508    description, the compilation unit is unspecified, the object is unspecified,
3509    and an empty initial stack.
3510
3511    <i>See [6.4.2 Call Frame Instructions](#call-frame-instructions) regarding
3512    restrictions on the DWARF expression operations that can be used in E.</i>
3513
3514    The DWARF is ill-formed if the result of evaluating E is not a memory byte
3515    address location description.
3516
3517##### A.6.4.2.3 Register Rule Instructions
3518
35191.  `DW_CFA_undefined`
3520
3521    The `DW_CFA_undefined` instruction takes a single unsigned LEB128 operand
3522    that represents a register number R. The required action is to set the rule
3523    for the register specified by R to `undefined`.
3524
35252.  `DW_CFA_same_value`
3526
3527    The `DW_CFA_same_value` instruction takes a single unsigned LEB128 operand
3528    that represents a register number R. The required action is to set the rule
3529    for the register specified by R to `same value`.
3530
35313.  `DW_CFA_offset`
3532
3533    The `DW_CFA_offset` instruction takes two operands: a register number R
3534    (encoded with the opcode) and an unsigned LEB128 constant representing a
3535    factored displacement B. The required action is to change the rule for the
3536    register specified by R to be an <i>offset(B * data_alignment_factor)</i>
3537    rule.
3538
3539    > NOTE: Seems this should be named `DW_CFA_offset_uf` since the offset is
3540    > unsigned factored.
3541
35424.  `DW_CFA_offset_extended`
3543
3544    The `DW_CFA_offset_extended` instruction takes two unsigned LEB128 operands
3545    representing a register number R and a factored displacement B. This
3546    instruction is identical to `DW_CFA_offset`, except for the encoding and
3547    size of the register operand.
3548
3549    > NOTE: Seems this should be named `DW_CFA_offset_extended_uf` since the
3550    > displacement is unsigned factored.
3551
35525.  `DW_CFA_offset_extended_sf`
3553
3554    The `DW_CFA_offset_extended_sf` instruction takes two operands: an unsigned
3555    LEB128 value representing a register number R and a signed LEB128 factored
3556    displacement B. This instruction is identical to `DW_CFA_offset_extended`,
3557    except that B is signed.
3558
35596.  `DW_CFA_val_offset`
3560
3561    The `DW_CFA_val_offset` instruction takes two unsigned LEB128 operands
3562    representing a register number R and a factored displacement B. The required
3563    action is to change the rule for the register indicated by R to be a
3564    <i>val_offset(B * data_alignment_factor)</i> rule.
3565
3566    > NOTE: Seems this should be named `DW_CFA_val_offset_uf` since the
3567    displacement is unsigned factored.
3568
35697.  `DW_CFA_val_offset_sf`
3570
3571    The `DW_CFA_val_offset_sf` instruction takes two operands: an unsigned
3572    LEB128 value representing a register number R and a signed LEB128 factored
3573    displacement B. This instruction is identical to `DW_CFA_val_offset`, except
3574    that B is signed.
3575
35768.  `DW_CFA_register`
3577
3578    The `DW_CFA_register` instruction takes two unsigned LEB128 operands
3579    representing register numbers R1 and R2 respectively. The required action is
3580    to set the rule for the register specified by R1 to be a <i>register(R2)</i>
3581    rule.
3582
35839.  `DW_CFA_expression`
3584
3585    The `DW_CFA_expression` instruction takes two operands: an unsigned LEB128
3586    value representing a register number R, and a `DW_FORM_block` value
3587    representing a DWARF operation expression E. The required action is to
3588    change the rule for the register specified by R to be an
3589    <i>expression(E)</i> rule.
3590
3591    <i>That is, E computes the location description where the register value can
3592    be retrieved.</i>
3593
3594    <i>See [6.4.2 Call Frame Instructions](#call-frame-instructions) regarding
3595    restrictions on the DWARF expression operations that can be used in E.</i>
3596
359710. `DW_CFA_val_expression`
3598
3599    The `DW_CFA_val_expression` instruction takes two operands: an unsigned
3600    LEB128 value representing a register number R, and a `DW_FORM_block` value
3601    representing a DWARF operation expression E. The required action is to
3602    change the rule for the register specified by R to be a
3603    <i>val_expression(E)</i> rule.
3604
3605    <i>That is, E computes the value of register R.</i>
3606
3607    <i>See [6.4.2 Call Frame Instructions](#call-frame-instructions) regarding
3608    restrictions on the DWARF expression operations that can be used in E.</i>
3609
3610    If the result of evaluating E is not a value with a base type size that
3611    matches the register size, then the DWARF is ill-formed.
3612
361311. `DW_CFA_restore`
3614
3615    The `DW_CFA_restore` instruction takes a single operand (encoded with the
3616    opcode) that represents a register number R. The required action is to
3617    change the rule for the register specified by R to the rule assigned it by
3618    the `initial_instructions` in the CIE.
3619
362012. `DW_CFA_restore_extended`
3621
3622    The `DW_CFA_restore_extended` instruction takes a single unsigned LEB128
3623    operand that represents a register number R. This instruction is identical
3624    to `DW_CFA_restore`, except for the encoding and size of the register
3625    operand.
3626
3627##### A.6.4.2.4 Row State Instructions
3628
3629> NOTE: These instructions are the same as in DWARF Version 5 section 6.4.2.4.
3630
3631##### A.6.4.2.5 Padding Instruction
3632
3633> NOTE: These instructions are the same as in DWARF Version 5 section 6.4.2.5.
3634
3635#### A.6.4.3 Call Frame Instruction Usage
3636
3637> NOTE: The same as in DWARF Version 5 section 6.4.3.
3638
3639#### A.6.4.4 Call Frame Calling Address
3640
3641> NOTE: The same as in DWARF Version 5 section 6.4.4.
3642
3643## A.7 Data Representation
3644
3645> NOTE: This section provides changes to existing debugger information entry
3646> attributes. These would be incorporated into the corresponding DWARF Version 5
3647> chapter 7 sections.
3648
3649### A.7.4 32-Bit and 64-Bit DWARF Formats
3650
3651> NOTE: This augments DWARF Version 5 section 7.4 list item 3's table.
3652
3653    Form                     Role
3654    ------------------------ --------------------------------------
3655    DW_OP_implicit_pointer   offset in `.debug_info`
3656
3657### A.7.5 Format of Debugging Information
3658
3659#### A.7.5.5 Classes and Forms
3660
3661> NOTE: The same as in DWARF Version 5 section 7.5.5.
3662
3663### A.7.7 DWARF Expressions
3664
3665> NOTE: Rename DWARF Version 5 section 7.7 to reflect the unification of
3666> location descriptions into DWARF expressions.
3667
3668#### A.7.7.1 Operation Expressions
3669
3670> NOTE: Rename DWARF Version 5 section 7.7.1 and delete section 7.7.2 to reflect
3671> the unification of location descriptions into DWARF expressions.
3672
3673#### A.7.7.3 Location List Expressions
3674
3675> NOTE: Rename DWARF Version 5 section 7.7.3 to reflect that location lists are
3676> a kind of DWARF expression.
3677
3678# B. Further Information
3679
3680The following references provide additional information on the extension.
3681
3682A reference to the DWARF standard is provided.
3683
3684A formatted version of this extension is available on the LLVM site. It includes
3685many figures that help illustrate the textual description, especially of the
3686example DWARF expression evaluations.
3687
3688Slides and a video of a presentation at the Linux Plumbers Conference 2021
3689related to this extension are available.
3690
3691The LLVM compiler extension includes the operations mentioned in the motivating
3692examples. It also covers other extensions needed for heterogeneous devices.
3693
3694- [DWARF Debugging Information Format](https://dwarfstd.org/)
3695  - [DWARF Debugging Information Format Version 5](https://dwarfstd.org/Dwarf5Std.php)
3696- [Allow Location Descriptions on the DWARF Expression Stack](https://llvm.org/docs/AMDGPUDwarfExtensionAllowLocationDescriptionOnTheDwarfExpressionStack/AMDGPUDwarfExtensionAllowLocationDescriptionOnTheDwarfExpressionStack.html)
3697- DWARF extensions for optimized SIMT/SIMD (GPU) debugging - Linux Plumbers Conference 2021
3698  - [Video](https://www.youtube.com/watch?v=QiR0ra0ymEY&t=10015s)
3699  - [Slides](https://linuxplumbersconf.org/event/11/contributions/1012/attachments/798/1505/DWARF_Extensions_for_Optimized_SIMT-SIMD_GPU_Debugging-LPC2021.pdf)
3700- [DWARF Extensions For Heterogeneous Debugging](https://llvm.org/docs/AMDGPUDwarfExtensionsForHeterogeneousDebugging.html)
3701