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