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