Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 1 | .. _amdgpu-dwarf-6-proposal-for-heterogeneous-debugging: |
| 2 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 3 | **************************************************** |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 4 | DWARF Version 6 Proposal For Heterogeneous Debugging |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 5 | **************************************************** |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 6 | |
| 7 | .. contents:: |
| 8 | :local: |
| 9 | |
| 10 | .. warning:: |
| 11 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 12 | This document describes a **provisional proposal** for DWARF Version 6 |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 13 | [:ref:`DWARF <amdgpu-dwarf-DWARF>`] to support heterogeneous debugging. It is |
| 14 | not currently fully implemented and is subject to change. |
| 15 | |
| 16 | Introduction |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 17 | ============ |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 18 | |
| 19 | This document proposes a set of backwards compatible extensions to DWARF Version |
| 20 | 5 [:ref:`DWARF <amdgpu-dwarf-DWARF>`] for consideration of inclusion into a |
| 21 | future DWARF Version 6 standard to support heterogeneous debugging. |
| 22 | |
| 23 | The remainder of this section provides motivation for each proposed feature in |
| 24 | terms of heterogeneous debugging on commercially available AMD GPU hardware |
| 25 | (AMDGPU). The goal is to add support to the AMD [:ref:`AMD <amdgpu-dwarf-AMD>`] |
| 26 | open source Radeon Open Compute Platform (ROCm) [:ref:`AMD-ROCm |
| 27 | <amdgpu-dwarf-AMD-ROCm>`] which is an implementation of the industry standard |
| 28 | for heterogeneous computing devices defined by the Heterogeneous System |
| 29 | Architecture (HSA) Foundation [:ref:`HSA <amdgpu-dwarf-HSA>`]. ROCm includes the |
| 30 | LLVM compiler [:ref:`LLVM <amdgpu-dwarf-LLVM>`] with upstreamed support for |
| 31 | AMDGPU [:ref:`AMDGPU-LLVM <amdgpu-dwarf-AMDGPU-LLVM>`]. The goal is to also add |
| 32 | the GDB debugger [:ref:`GDB <amdgpu-dwarf-GDB>`] with upstreamed support for |
| 33 | AMDGPU [:ref:`AMD-ROCgdb <amdgpu-dwarf-AMD-ROCgdb>`]. In addition, the goal is |
| 34 | to work with third parties to enable support for AMDGPU debugging in the GCC |
| 35 | compiler [:ref:`GCC <amdgpu-dwarf-GCC>`] and the Perforce TotalView HPC debugger |
| 36 | [:ref:`Perforce-TotalView <amdgpu-dwarf-Perforce-TotalView>`]. |
| 37 | |
| 38 | However, the proposal is intended to be vendor and architecture neutral. It is |
| 39 | believed to apply to other heterogeous hardware devices including GPUs, DSPs, |
| 40 | FPGAs, and other specialized hardware. These collectively include similar |
| 41 | characteristics and requirements as AMDGPU devices. Parts of the proposal can |
| 42 | also apply to traditional CPU hardware that supports large vector registers. |
| 43 | Compilers can map source languages and extensions that describe large scale |
| 44 | parallel execution onto the lanes of the vector registers. This is common in |
| 45 | programming languages used in ML and HPC. The proposal also includes improved |
| 46 | support for optimized code on any architecture. Some of the generalizations may |
| 47 | also benefit other issues that have been raised. |
| 48 | |
| 49 | The proposal has evolved though collaboration with many individuals and active |
| 50 | prototyping within the GDB debugger and LLVM compiler. Input has also been very |
| 51 | much appreciated from the developers working on the Perforce TotalView HPC |
| 52 | Debugger and GCC compiler. |
| 53 | |
| 54 | The AMDGPU has several features that require additional DWARF functionality in |
| 55 | order to support optimized code. |
| 56 | |
| 57 | AMDGPU optimized code may spill vector registers to non-global address space |
| 58 | memory, and this spilling may be done only for lanes that are active on entry |
| 59 | to the subprogram. To support this, a location description that can be created |
| 60 | as a masked select is required. See ``DW_OP_LLVM_select_bit_piece``. |
| 61 | |
| 62 | Since the active lane mask may be held in a register, a way to get the value |
| 63 | of a register on entry to a subprogram is required. To support this an |
| 64 | operation that returns the caller value of a register as specified by the Call |
| 65 | Frame Information (CFI) is required. See ``DW_OP_LLVM_call_frame_entry_reg`` |
| 66 | and :ref:`amdgpu-dwarf-call-frame-information`. |
| 67 | |
| 68 | Current DWARF uses an empty expression to indicate an undefined location |
| 69 | description. Since the masked select composite location description operation |
| 70 | takes more than one location description, it is necessary to have an explicit |
| 71 | way to specify an undefined location description. Otherwise it is not possible |
| 72 | to specify that a particular one of the input location descriptions is |
| 73 | undefined. See ``DW_OP_LLVM_undefined``. |
| 74 | |
| 75 | CFI describes restoring callee saved registers that are spilled. Currently CFI |
| 76 | only allows a location description that is a register, memory address, or |
| 77 | implicit location description. AMDGPU optimized code may spill scalar |
| 78 | registers into portions of vector registers. This requires extending CFI to |
| 79 | allow any location description. See |
| 80 | :ref:`amdgpu-dwarf-call-frame-information`. |
| 81 | |
| 82 | The vector registers of the AMDGPU are represented as their full wavefront |
| 83 | size, meaning the wavefront size times the dword size. This reflects the |
| 84 | actual hardware and allows the compiler to generate DWARF for languages that |
| 85 | map a thread to the complete wavefront. It also allows more efficient DWARF to |
| 86 | be generated to describe the CFI as only a single expression is required for |
| 87 | the whole vector register, rather than a separate expression for each lane's |
| 88 | dword of the vector register. It also allows the compiler to produce DWARF |
| 89 | that indexes the vector register if it spills scalar registers into portions |
| 90 | of a vector registers. |
| 91 | |
| 92 | Since DWARF stack value entries have a base type and AMDGPU registers are a |
| 93 | vector of dwords, the ability to specify that a base type is a vector is |
| 94 | required. See ``DW_AT_LLVM_vector_size``. |
| 95 | |
| 96 | If the source language is mapped onto the AMDGPU wavefronts in a SIMT manner, |
| 97 | then the variable DWARF location expressions must compute the location for a |
| 98 | single lane of the wavefront. Therefore, a DWARF operation is required to |
| 99 | denote the current lane, much like ``DW_OP_push_object_address`` denotes the |
| 100 | current object. The ``DW_OP_*piece`` operations only allow literal indices. |
| 101 | Therefore, a way to use a computed offset of an arbitrary location description |
| 102 | (such as a vector register) is required. See ``DW_OP_LLVM_push_lane``, |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 103 | ``DW_OP_LLVM_offset``, ``DW_OP_LLVM_offset_uconst``, and |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 104 | ``DW_OP_LLVM_bit_offset``. |
| 105 | |
| 106 | If the source language is mapped onto the AMDGPU wavefronts in a SIMT manner |
| 107 | the compiler can use the AMDGPU execution mask register to control which lanes |
| 108 | are active. To describe the conceptual location of non-active lanes a DWARF |
| 109 | expression is needed that can compute a per lane PC. For efficiency, this is |
| 110 | done for the wavefront as a whole. This expression benefits by having a masked |
| 111 | select composite location description operation. This requires an attribute |
| 112 | for source location of each lane. The AMDGPU may update the execution mask for |
| 113 | whole wavefront operations and so needs an attribute that computes the current |
| 114 | active lane mask. See ``DW_OP_LLVM_select_bit_piece``, ``DW_OP_LLVM_extend``, |
| 115 | ``DW_AT_LLVM_lane_pc``, and ``DW_AT_LLVM_active_lane``. |
| 116 | |
| 117 | AMDGPU needs to be able to describe addresses that are in different kinds of |
| 118 | memory. Optimized code may need to describe a variable that resides in pieces |
| 119 | that are in different kinds of storage which may include parts of registers, |
| 120 | memory that is in a mixture of memory kinds, implicit values, or be undefined. |
| 121 | DWARF has the concept of segment addresses. However, the segment cannot be |
| 122 | specified within a DWARF expression, which is only able to specify the offset |
| 123 | portion of a segment address. The segment index is only provided by the entity |
| 124 | that specifies the DWARF expression. Therefore, the segment index is a |
| 125 | property that can only be put on complete objects, such as a variable. That |
| 126 | makes it only suitable for describing an entity (such as variable or |
| 127 | subprogram code) that is in a single kind of memory. Therefore, AMDGPU uses |
| 128 | the DWARF concept of address spaces. For example, a variable may be allocated |
| 129 | in a register that is partially spilled to the call stack which is in the |
| 130 | private address space, and partially spilled to the local address space. |
| 131 | |
| 132 | DWARF uses the concept of an address in many expression operations but does not |
| 133 | define how it relates to address spaces. For example, |
| 134 | ``DW_OP_push_object_address`` pushes the address of an object. Other contexts |
| 135 | implicitly push an address on the stack before evaluating an expression. For |
| 136 | example, the ``DW_AT_use_location`` attribute of the |
| 137 | ``DW_TAG_ptr_to_member_type``. The expression that uses the address needs to |
| 138 | do so in a general way and not need to be dependent on the address space of |
| 139 | the address. For example, a pointer to member value may want to be applied to |
| 140 | an object that may reside in any address space. |
| 141 | |
| 142 | The number of registers and the cost of memory operations is much higher for |
| 143 | AMDGPU than a typical CPU. The compiler attempts to optimize whole variables |
| 144 | and arrays into registers. Currently DWARF only allows |
| 145 | ``DW_OP_push_object_address`` and related operations to work with a global |
| 146 | memory location. To support AMDGPU optimized code it is required to generalize |
| 147 | DWARF to allow any location description to be used. This allows registers, or |
| 148 | composite location descriptions that may be a mixture of memory, registers, or |
| 149 | even implicit values. |
| 150 | |
| 151 | DWARF Version 5 does not allow location descriptions to be entries on the |
| 152 | DWARF stack. They can only be the final result of the evaluation of a DWARF |
| 153 | expression. However, by allowing a location description to be a first-class |
| 154 | entry on the DWARF stack it becomes possible to compose expressions containing |
| 155 | both values and location descriptions naturally. It allows objects to be |
| 156 | located in any kind of memory address space, in registers, be implicit values, |
| 157 | be undefined, or a composite of any of these. By extending DWARF carefully, |
| 158 | all existing DWARF expressions can retain their current semantic meaning. |
| 159 | DWARF has implicit conversions that convert from a value that represents an |
| 160 | address in the default address space to a memory location description. This |
| 161 | can be extended to allow a default address space memory location description |
| 162 | to be implicitly converted back to its address value. This allows all DWARF |
| 163 | Version 5 expressions to retain their same meaning, while adding the ability |
| 164 | to explicitly create memory location descriptions in non-default address |
| 165 | spaces and generalizing the power of composite location descriptions to any |
| 166 | kind of location description. See :ref:`amdgpu-dwarf-operation-expressions`. |
| 167 | |
| 168 | To allow composition of composite location descriptions, an explicit operation |
| 169 | that indicates the end of the definition of a composite location description |
| 170 | is required. This can be implied if the end of a DWARF expression is reached, |
| 171 | allowing current DWARF expressions to remain legal. See |
| 172 | ``DW_OP_LLVM_piece_end``. |
| 173 | |
| 174 | The ``DW_OP_plus`` and ``DW_OP_minus`` can be defined to operate on a memory |
| 175 | location description in the default target architecture specific address space |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 176 | and a generic type value to produce an updated memory location description. This |
| 177 | allows them to continue to be used to offset an address. To generalize |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 178 | offsetting to any location description, including location descriptions that |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 179 | describe when bytes are in registers, are implicit, or a composite of these, the |
| 180 | ``DW_OP_LLVM_offset``, ``DW_OP_LLVM_offset_uconst``, and |
| 181 | ``DW_OP_LLVM_bit_offset`` offset operations are added. Unlike ``DW_OP_plus``, |
| 182 | ``DW_OP_plus_uconst``, and ``DW_OP_minus`` arithmetic operations, these do not |
| 183 | define that integer overflow causes wrap-around. The offset operations can |
| 184 | operate on location storage of any size. For example, implicit location storage |
| 185 | could be any number of bits in size. It is simpler to define offsets that exceed |
| 186 | the size of the location storage as being ill-formed, than having to force an |
| 187 | implementation to support potentially infinite precision offsets to allow it to |
| 188 | correctly track a series of positive and negative offsets that may transiently |
| 189 | overflow or underflow, but end up in range. This is simple for the arithmetic |
| 190 | operations as they are defined in terms of two's compliment arithmetic on a base |
| 191 | type of a fixed size. |
| 192 | |
| 193 | Having the offset operations allows ``DW_OP_push_object_address`` to push a |
| 194 | location description that may be in a register, or be an implicit value, and the |
| 195 | DWARF expression of ``DW_TAG_ptr_to_member_type`` can contain them to offset |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 196 | within it. ``DW_OP_LLVM_bit_offset`` generalizes DWARF to work with bit fields |
| 197 | which is not possible in DWARF Version 5. |
| 198 | |
| 199 | The DWARF ``DW_OP_xderef*`` operations allow a value to be converted into an |
| 200 | address of a specified address space which is then read. But it provides no |
| 201 | way to create a memory location description for an address in the non-default |
| 202 | address space. For example, AMDGPU variables can be allocated in the local |
| 203 | address space at a fixed address. It is required to have an operation to |
| 204 | create an address in a specific address space that can be used to define the |
| 205 | location description of the variable. Defining this operation to produce a |
| 206 | location description allows the size of addresses in an address space to be |
| 207 | larger than the generic type. See ``DW_OP_LLVM_form_aspace_address``. |
| 208 | |
| 209 | If the ``DW_OP_LLVM_form_aspace_address`` operation had to produce a value |
| 210 | that can be implicitly converted to a memory location description, then it |
| 211 | would be limited to the size of the generic type which matches the size of the |
| 212 | default address space. Its value would be unspecified and likely not match any |
| 213 | value in the actual program. By making the result a location description, it |
| 214 | allows a consumer great freedom in how it implements it. The implicit |
| 215 | conversion back to a value can be limited only to the default address space to |
| 216 | maintain compatibility with DWARF Version 5. For other address spaces the |
| 217 | producer can use the new operations that explicitly specify the address space. |
| 218 | |
| 219 | ``DW_OP_breg*`` treats the register as containing an address in the default |
| 220 | address space. It is required to be able to specify the address space of the |
| 221 | register value. See ``DW_OP_LLVM_aspace_bregx``. |
| 222 | |
| 223 | Similarly, ``DW_OP_implicit_pointer`` treats its implicit pointer value as |
| 224 | being in the default address space. It is required to be able to specify the |
| 225 | address space of the pointer value. See |
| 226 | ``DW_OP_LLVM_aspace_implicit_pointer``. |
| 227 | |
| 228 | Almost all uses of addresses in DWARF are limited to defining location |
| 229 | descriptions, or to be dereferenced to read memory. The exception is |
| 230 | ``DW_CFA_val_offset`` which uses the address to set the value of a register. |
| 231 | By defining the CFA DWARF expression as being a memory location description, |
| 232 | it can maintain what address space it is, and that can be used to convert the |
| 233 | offset address back to an address in that address space. See |
| 234 | :ref:`amdgpu-dwarf-call-frame-information`. |
| 235 | |
| 236 | This approach allows all existing DWARF to have the identical semantics. It |
| 237 | allows the compiler to explicitly specify the address space it is using. For |
| 238 | example, a compiler could choose to access private memory in a swizzled manner |
| 239 | when mapping a source language to a wavefront in a SIMT manner, or to access |
| 240 | it in an unswizzled manner if mapping the same language with the wavefront |
| 241 | being the thread. It also allows the compiler to mix the address space it uses |
| 242 | to access private memory. For example, for SIMT it can still spill entire |
| 243 | vector registers in an unswizzled manner, while using a swizzled private |
| 244 | memory for SIMT variable access. This approach allows memory location |
| 245 | descriptions for different address spaces to be combined using the regular |
| 246 | ``DW_OP_*piece`` operations. |
| 247 | |
| 248 | Location descriptions are an abstraction of storage, they give freedom to the |
| 249 | consumer on how to implement them. They allow the address space to encode lane |
| 250 | information so they can be used to read memory with only the memory |
| 251 | description and no extra arguments. The same set of operations can operate on |
| 252 | locations independent of their kind of storage. The ``DW_OP_deref*`` therefore |
| 253 | can be used on any storage kind. ``DW_OP_xderef*`` is unnecessary except to |
| 254 | become a more compact way to convert a non-default address space address |
| 255 | followed by dereferencing it. |
| 256 | |
| 257 | In DWARF Version 5 a location description is defined as a single location |
| 258 | description or a location list. A location list is defined as either |
| 259 | effectively an undefined location description or as one or more single |
| 260 | location descriptions to describe an object with multiple places. The |
| 261 | ``DW_OP_push_object_address`` and ``DW_OP_call*`` operations can put a |
| 262 | location description on the stack. Furthermore, debugger information entry |
| 263 | attributes such as ``DW_AT_data_member_location``, ``DW_AT_use_location``, and |
| 264 | ``DW_AT_vtable_elem_location`` are defined as pushing a location description |
| 265 | on the expression stack before evaluating the expression. However, DWARF |
| 266 | Version 5 only allows the stack to contain values and so only a single memory |
| 267 | address can be on the stack which makes these incapable of handling location |
| 268 | descriptions with multiple places, or places other than memory. Since this |
| 269 | proposal allows the stack to contain location descriptions, the operations are |
| 270 | generalized to support location descriptions that can have multiple places. |
| 271 | This is backwards compatible with DWARF Version 5 and allows objects with |
| 272 | multiple places to be supported. For example, the expression that describes |
| 273 | how to access the field of an object can be evaluated with a location |
| 274 | description that has multiple places and will result in a location description |
| 275 | with multiple places as expected. With this change, the separate DWARF Version |
| 276 | 5 sections that described DWARF expressions and location lists have been |
| 277 | unified into a single section that describes DWARF expressions in general. |
| 278 | This unification seems to be a natural consequence and a necessity of allowing |
| 279 | location descriptions to be part of the evaluation stack. |
| 280 | |
| 281 | For those familiar with the definition of location descriptions in DWARF |
| 282 | Version 5, the definition in this proposal is presented differently, but does |
| 283 | in fact define the same concept with the same fundamental semantics. However, |
| 284 | it does so in a way that allows the concept to extend to support address |
| 285 | spaces, bit addressing, the ability for composite location descriptions to be |
| 286 | composed of any kind of location description, and the ability to support |
| 287 | objects located at multiple places. Collectively these changes expand the set |
| 288 | of processors that can be supported and improves support for optimized code. |
| 289 | |
| 290 | Several approaches were considered, and the one proposed appears to be the |
| 291 | cleanest and offers the greatest improvement of DWARF's ability to support |
| 292 | optimized code. Examining the GDB debugger and LLVM compiler, it appears only |
| 293 | to require modest changes as they both already have to support general use of |
| 294 | location descriptions. It is anticipated that will also be the case for other |
| 295 | debuggers and compilers. |
| 296 | |
| 297 | As an experiment, GDB was modified to evaluate DWARF Version 5 expressions |
| 298 | with location descriptions as stack entries and implicit conversions. All GDB |
| 299 | tests have passed, except one that turned out to be an invalid test by DWARF |
| 300 | Version 5 rules. The code in GDB actually became simpler as all evaluation was |
| 301 | on the stack and there was no longer a need to maintain a separate structure |
| 302 | for the location description result. This gives confidence of the backwards |
| 303 | compatibility. |
| 304 | |
| 305 | Since the AMDGPU supports languages such as OpenCL [:ref:`OpenCL |
| 306 | <amdgpu-dwarf-OpenCL>`], there is a need to define source language address |
| 307 | classes so they can be used in a consistent way by consumers. It would also be |
| 308 | desirable to add support for using them in defining language types rather than |
| 309 | the current target architecture specific address spaces. See |
| 310 | :ref:`amdgpu-dwarf-segment_addresses`. |
| 311 | |
| 312 | A ``DW_AT_LLVM_augmentation`` attribute is added to a compilation unit |
| 313 | debugger information entry to indicate that there is additional target |
| 314 | architecture specific information in the debugging information entries of that |
| 315 | compilation unit. This allows a consumer to know what extensions are present |
| 316 | in the debugger information entries as is possible with the augmentation |
| 317 | string of other sections. The format that should be used for the augmentation |
| 318 | string in the lookup by name table and CFI Common Information Entry is also |
| 319 | recommended to allow a consumer to parse the string when it contains |
| 320 | information from multiple vendors. |
| 321 | |
| 322 | The AMDGPU supports programming languages that include online compilation |
| 323 | where the source text may be created at runtime. Therefore, a way to embed the |
| 324 | source text in the debug information is required. For example, the OpenCL |
| 325 | language runtime supports online compilation. See |
| 326 | :ref:`amdgpu-dwarf-line-number-information`. |
| 327 | |
| 328 | Support to allow MD5 checksums to be optionally present in the line table is |
| 329 | added. This allows linking together compilation units where some have MD5 |
| 330 | checksums and some do not. In DWARF Version 5 the file timestamp and file size |
| 331 | can be optional, but if the MD5 checksum is present it must be valid for all |
| 332 | files. See :ref:`amdgpu-dwarf-line-number-information`. |
| 333 | |
| 334 | Support is added for the HIP programming language [:ref:`HIP |
| 335 | <amdgpu-dwarf-HIP>`] which is supported by the AMDGPU. See |
| 336 | :ref:`amdgpu-dwarf-language-names`. |
| 337 | |
| 338 | The following sections provide the definitions for the additional operations, |
| 339 | as well as clarifying how existing expression operations, CFI operations, and |
| 340 | attributes behave with respect to generalized location descriptions that |
| 341 | support address spaces and location descriptions that support multiple places. |
| 342 | It has been defined such that it is backwards compatible with DWARF Version 5. |
| 343 | The definitions are intended to fully define well-formed DWARF in a consistent |
| 344 | style based on the DWARF Version 5 specification. Non-normative text is shown |
| 345 | in *italics*. |
| 346 | |
| 347 | The names for the new operations, attributes, and constants include "\ |
| 348 | ``LLVM``\ " and are encoded with vendor specific codes so this proposal can be |
| 349 | implemented as an LLVM vendor extension to DWARF Version 5. If accepted these |
| 350 | names would not include the "\ ``LLVM``\ " and would not use encodings in the |
| 351 | vendor range. |
| 352 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 353 | The proposal is described in |
| 354 | :ref:`amdgpu-dwarf-proposed-changes-relative-to-dwarf-version-5` and is |
| 355 | organized to follow the section ordering of DWARF Version 5. It includes notes |
| 356 | to indicate the corresponding DWARF Version 5 sections to which they pertain. |
| 357 | Other notes describe additional changes that may be worth considering, and to |
| 358 | raise questions. |
| 359 | |
| 360 | .. _amdgpu-dwarf-proposed-changes-relative-to-dwarf-version-5: |
| 361 | |
| 362 | Proposed Changes Relative to DWARF Version 5 |
| 363 | ============================================ |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 364 | |
| 365 | General Description |
| 366 | ------------------- |
| 367 | |
| 368 | Attribute Types |
| 369 | ~~~~~~~~~~~~~~~ |
| 370 | |
| 371 | .. note:: |
| 372 | |
| 373 | This augments DWARF Version 5 section 2.2 and Table 2.2. |
| 374 | |
| 375 | The following table provides the additional attributes. See |
| 376 | :ref:`amdgpu-dwarf-debugging-information-entry-attributes`. |
| 377 | |
| 378 | .. table:: Attribute names |
| 379 | :name: amdgpu-dwarf-attribute-names-table |
| 380 | |
| 381 | =========================== ==================================== |
| 382 | Attribute Usage |
| 383 | =========================== ==================================== |
| 384 | ``DW_AT_LLVM_active_lane`` SIMD or SIMT active lanes |
| 385 | ``DW_AT_LLVM_augmentation`` Compilation unit augmentation string |
| 386 | ``DW_AT_LLVM_lane_pc`` SIMD or SIMT lane program location |
| 387 | ``DW_AT_LLVM_lanes`` SIMD or SIMT thread lane count |
| 388 | ``DW_AT_LLVM_vector_size`` Base type vector size |
| 389 | =========================== ==================================== |
| 390 | |
| 391 | .. _amdgpu-dwarf-expressions: |
| 392 | |
| 393 | DWARF Expressions |
| 394 | ~~~~~~~~~~~~~~~~~ |
| 395 | |
| 396 | .. note:: |
| 397 | |
| 398 | This section, and its nested sections, replaces DWARF Version 5 section 2.5 and |
| 399 | section 2.6. The new proposed DWARF expression operations are defined as well |
| 400 | as clarifying the extensions to already existing DWARF Version 5 operations. It is |
| 401 | based on the text of the existing DWARF Version 5 standard. |
| 402 | |
| 403 | DWARF expressions describe how to compute a value or specify a location. |
| 404 | |
| 405 | *The evaluation of a DWARF expression can provide the location of an object, the |
| 406 | value of an array bound, the length of a dynamic string, the desired value |
| 407 | itself, and so on.* |
| 408 | |
| 409 | The evaluation of a DWARF expression can either result in a value or a location |
| 410 | description: |
| 411 | |
| 412 | *value* |
| 413 | |
| 414 | A value has a type and a literal value. It can represent a literal value of |
| 415 | any supported base type of the target architecture. The base type specifies |
| 416 | the size and encoding of the literal value. |
| 417 | |
| 418 | .. note:: |
| 419 | |
| 420 | It may be desirable to add an implicit pointer base type encoding. It would |
| 421 | be used for the type of the value that is produced when the ``DW_OP_deref*`` |
| 422 | operation retrieves the full contents of an implicit pointer location |
| 423 | storage created by the ``DW_OP_implicit_pointer`` or |
| 424 | ``DW_OP_LLVM_aspace_implicit_pointer`` operations. The literal value would |
| 425 | record the debugging information entry and byte dispacement specified by the |
| 426 | associated ``DW_OP_implicit_pointer`` or |
| 427 | ``DW_OP_LLVM_aspace_implicit_pointer`` operations. |
| 428 | |
| 429 | Instead of a base type, a value can have a distinguished generic type, which |
| 430 | is an integral type that has the size of an address in the target architecture |
| 431 | default address space and unspecified signedness. |
| 432 | |
| 433 | *The generic type is the same as the unspecified type used for stack |
| 434 | operations defined in DWARF Version 4 and before.* |
| 435 | |
| 436 | An integral type is a base type that has an encoding of ``DW_ATE_signed``, |
| 437 | ``DW_ATE_signed_char``, ``DW_ATE_unsigned``, ``DW_ATE_unsigned_char``, |
| 438 | ``DW_ATE_boolean``, or any target architecture defined integral encoding in |
| 439 | the inclusive range ``DW_ATE_lo_user`` to ``DW_ATE_hi_user``. |
| 440 | |
| 441 | .. note:: |
| 442 | |
| 443 | It is unclear if ``DW_ATE_address`` is an integral type. GDB does not seem |
| 444 | to consider it as integral. |
| 445 | |
| 446 | *location description* |
| 447 | |
| 448 | *Debugging information must provide consumers a way to find the location of |
| 449 | program variables, determine the bounds of dynamic arrays and strings, and |
| 450 | possibly to find the base address of a subprogram’s stack frame or the return |
| 451 | address of a subprogram. Furthermore, to meet the needs of recent computer |
| 452 | architectures and optimization techniques, debugging information must be able |
| 453 | to describe the location of an object whose location changes over the object’s |
| 454 | lifetime, and may reside at multiple locations simultaneously during parts of |
| 455 | an object's lifetime.* |
| 456 | |
| 457 | Information about the location of program objects is provided by location |
| 458 | descriptions. |
| 459 | |
| 460 | Location descriptions can consist of one or more single location descriptions. |
| 461 | |
| 462 | A single location description specifies the location storage that holds a |
| 463 | program object and a position within the location storage where the program |
| 464 | object starts. The position within the location storage is expressed as a bit |
| 465 | offset relative to the start of the location storage. |
| 466 | |
| 467 | A location storage is a linear stream of bits that can hold values. Each |
| 468 | location storage has a size in bits and can be accessed using a zero-based bit |
| 469 | offset. The ordering of bits within a location storage uses the bit numbering |
| 470 | and direction conventions that are appropriate to the current language on the |
| 471 | target architecture. |
| 472 | |
| 473 | There are five kinds of location storage: |
| 474 | |
| 475 | *memory location storage* |
| 476 | Corresponds to the target architecture memory address spaces. |
| 477 | |
| 478 | *register location storage* |
| 479 | Corresponds to the target architecture registers. |
| 480 | |
| 481 | *implicit location storage* |
| 482 | Corresponds to fixed values that can only be read. |
| 483 | |
| 484 | *undefined location storage* |
| 485 | Indicates no value is available and therefore cannot be read or written. |
| 486 | |
| 487 | *composite location storage* |
| 488 | Allows a mixture of these where some bits come from one location storage and |
| 489 | some from another location storage, or from disjoint parts of the same |
| 490 | location storage. |
| 491 | |
| 492 | .. note:: |
| 493 | |
| 494 | It may be better to add an implicit pointer location storage kind used by |
| 495 | the ``DW_OP_implicit_pointer`` and ``DW_OP_LLVM_aspace_implicit_pointer`` |
| 496 | operations. It would specify the debugger information entry and byte offset |
| 497 | provided by the operations. |
| 498 | |
| 499 | *Location descriptions are a language independent representation of addressing |
| 500 | rules. They are created using DWARF operation expressions of arbitrary |
| 501 | complexity. They can be the result of evaluting a debugger information entry |
| 502 | attribute that specifies an operation expression. In this usage they can |
| 503 | describe the location of an object as long as its lifetime is either static or |
| 504 | the same as the lexical block (see DWARF Version 5 section 3.5) that owns it, |
| 505 | and it does not move during its lifetime. They can be the result of evaluating |
| 506 | a debugger information entry attribute that specifies a location list |
| 507 | expression. In this usage they can describe the location of an object that has |
| 508 | a limited lifetime, changes its location during its lifetime, or has multiple |
| 509 | locations over part or all of its lifetime.* |
| 510 | |
| 511 | If a location description has more than one single location description, the |
| 512 | DWARF expression is ill-formed if the object value held in each single |
| 513 | location description's position within the associated location storage is not |
| 514 | the same value, except for the parts of the value that are uninitialized. |
| 515 | |
| 516 | *A location description that has more than one single location description can |
| 517 | only be created by a location list expression that has overlapping program |
| 518 | location ranges, or certain expression operations that act on a location |
| 519 | description that has more than one single location description. There are no |
| 520 | operation expression operations that can directly create a location |
| 521 | description with more than one single location description.* |
| 522 | |
| 523 | *A location description with more than one single location description can be |
| 524 | used to describe objects that reside in more than one piece of storage at the |
| 525 | same time. An object may have more than one location as a result of |
| 526 | optimization. For example, a value that is only read may be promoted from |
| 527 | memory to a register for some region of code, but later code may revert to |
| 528 | reading the value from memory as the register may be used for other purposes. |
| 529 | For the code region where the value is in a register, any change to the object |
| 530 | value must be made in both the register and the memory so both regions of code |
| 531 | will read the updated value.* |
| 532 | |
| 533 | *A consumer of a location description with more than one single location |
| 534 | description can read the object's value from any of the single location |
| 535 | descriptions (since they all refer to location storage that has the same |
| 536 | value), but must write any changed value to all the single location |
| 537 | descriptions.* |
| 538 | |
| 539 | A DWARF expression can either be encoded as a operation expression (see |
| 540 | :ref:`amdgpu-dwarf-operation-expressions`), or as a location list expression |
| 541 | (see :ref:`amdgpu-dwarf-location-list-expressions`). |
| 542 | |
| 543 | A DWARF expression is evaluated in the context of: |
| 544 | |
| 545 | *A current subprogram* |
| 546 | This may be used in the evaluation of register access operations to support |
| 547 | virtual unwinding of the call stack (see |
| 548 | :ref:`amdgpu-dwarf-call-frame-information`). |
| 549 | |
| 550 | *A current program location* |
| 551 | This may be used in the evaluation of location list expressions to select |
| 552 | amongst multiple program location ranges. It should be the program location |
| 553 | corresponding to the current subprogram. If the current subprogram was reached |
| 554 | by virtual call stack unwinding, then the program location will correspond to |
| 555 | the associated call site. |
| 556 | |
| 557 | *An initial stack* |
| 558 | This is a list of values or location descriptions that will be pushed on the |
| 559 | operation expression evaluation stack in the order provided before evaluation |
| 560 | of an operation expression starts. |
| 561 | |
| 562 | Some debugger information entries have attributes that evaluate their DWARF |
| 563 | expression value with initial stack entries. In all other cases the initial |
| 564 | stack is empty. |
| 565 | |
| 566 | When a DWARF expression is evaluated, it may be specified whether a value or |
| 567 | location description is required as the result kind. |
| 568 | |
| 569 | If a result kind is specified, and the result of the evaluation does not match |
| 570 | the specified result kind, then the implicit conversions described in |
| 571 | :ref:`amdgpu-dwarf-memory-location-description-operations` are performed if |
| 572 | valid. Otherwise, the DWARF expression is ill-formed. |
| 573 | |
| 574 | .. _amdgpu-dwarf-operation-expressions: |
| 575 | |
| 576 | DWARF Operation Expressions |
| 577 | +++++++++++++++++++++++++++ |
| 578 | |
| 579 | An operation expression is comprised of a stream of operations, each consisting |
| 580 | of an opcode followed by zero or more operands. The number of operands is |
| 581 | implied by the opcode. |
| 582 | |
| 583 | Operations represent a postfix operation on a simple stack machine. Each stack |
| 584 | entry can hold either a value or a location description. Operations can act on |
| 585 | entries on the stack, including adding entries and removing entries. If the kind |
| 586 | of a stack entry does not match the kind required by the operation and is not |
| 587 | implicitly convertible to the required kind (see |
| 588 | :ref:`amdgpu-dwarf-memory-location-description-operations`), then the DWARF |
| 589 | operation expression is ill-formed. |
| 590 | |
| 591 | Evaluation of an operation expression starts with an empty stack on which the |
| 592 | entries from the initial stack provided by the context are pushed in the order |
| 593 | provided. Then the operations are evaluated, starting with the first operation |
| 594 | of the stream, until one past the last operation of the stream is reached. The |
| 595 | result of the evaluation is: |
| 596 | |
| 597 | * If evaluation of the DWARF expression requires a location description, then: |
| 598 | |
| 599 | * If the stack is empty, the result is a location description with one |
| 600 | undefined location description. |
| 601 | |
| 602 | *This rule is for backwards compatibility with DWARF Version 5 which has no |
| 603 | explicit operation to create an undefined location description, and uses an |
| 604 | empty operation expression for this purpose.* |
| 605 | |
| 606 | * If the top stack entry is a location description, or can be converted |
| 607 | to one, then the result is that, possibly converted, location description. |
| 608 | Any other entries on the stack are discarded. |
| 609 | |
| 610 | * Otherwise the DWARF expression is ill-formed. |
| 611 | |
| 612 | .. note:: |
| 613 | |
| 614 | Could define this case as returning an implicit location description as |
| 615 | if the ``DW_OP_implicit`` operation is performed. |
| 616 | |
| 617 | * If evaluation of the DWARF expression requires a value, then: |
| 618 | |
| 619 | * If the top stack entry is a value, or can be converted to one, then the |
| 620 | result is that, possibly converted, value. Any other entries on the stack |
| 621 | are discarded. |
| 622 | |
| 623 | * Otherwise the DWARF expression is ill-formed. |
| 624 | |
| 625 | * If evaluation of the DWARF expression does not specify if a value or location |
| 626 | description is required, then: |
| 627 | |
| 628 | * If the stack is empty, the result is a location description with one |
| 629 | undefined location description. |
| 630 | |
| 631 | *This rule is for backwards compatibility with DWARF Version 5 which has no |
| 632 | explicit operation to create an undefined location description, and uses an |
| 633 | empty operation expression for this purpose.* |
| 634 | |
| 635 | .. note:: |
| 636 | |
| 637 | This rule is consistent with the rule above for when a location |
| 638 | description is requested. However, GDB appears to report this as an error |
| 639 | and no GDB tests appear to cause an empty stack for this case. |
| 640 | |
| 641 | * Otherwise, the top stack entry is returned. Any other entries on the stack |
| 642 | are discarded. |
| 643 | |
| 644 | An operation expression is encoded as a byte block with some form of prefix that |
| 645 | specifies the byte count. It can be used: |
| 646 | |
| 647 | * as the value of a debugging information entry attribute that is encoded using |
| 648 | class ``exprloc`` (see DWARF Version 5 section 7.5.5), |
| 649 | |
| 650 | * as the operand to certain operation expression operations, |
| 651 | |
| 652 | * as the operand to certain call frame information operations (see |
| 653 | :ref:`amdgpu-dwarf-call-frame-information`), |
| 654 | |
| 655 | * and in location list entries (see |
| 656 | :ref:`amdgpu-dwarf-location-list-expressions`). |
| 657 | |
| 658 | .. _amdgpu-dwarf-stack-operations: |
| 659 | |
| 660 | Stack Operations |
| 661 | ################ |
| 662 | |
| 663 | The following operations manipulate the DWARF stack. Operations that index the |
| 664 | stack assume that the top of the stack (most recently added entry) has index 0. |
| 665 | They allow the stack entries to be either a value or location description. |
| 666 | |
| 667 | If any stack entry accessed by a stack operation is an incomplete composite |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 668 | location description (see |
| 669 | :ref:`amdgpu-dwarf-composite-location-description-operations`), then the DWARF |
| 670 | expression is ill-formed. |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 671 | |
| 672 | .. note:: |
| 673 | |
| 674 | These operations now support stack entries that are values and location |
| 675 | descriptions. |
| 676 | |
| 677 | .. note:: |
| 678 | |
| 679 | If it is desired to also make them work with incomplete composite location |
| 680 | descriptions, then would need to define that the composite location storage |
| 681 | specified by the incomplete composite location description is also replicated |
| 682 | when a copy is pushed. This ensures that each copy of the incomplete composite |
| 683 | location description can update the composite location storage they specify |
| 684 | independently. |
| 685 | |
| 686 | 1. ``DW_OP_dup`` |
| 687 | |
| 688 | ``DW_OP_dup`` duplicates the stack entry at the top of the stack. |
| 689 | |
| 690 | 2. ``DW_OP_drop`` |
| 691 | |
| 692 | ``DW_OP_drop`` pops the stack entry at the top of the stack and discards it. |
| 693 | |
| 694 | 3. ``DW_OP_pick`` |
| 695 | |
| 696 | ``DW_OP_pick`` has a single unsigned 1-byte operand that represents an index |
| 697 | I. A copy of the stack entry with index I is pushed onto the stack. |
| 698 | |
| 699 | 4. ``DW_OP_over`` |
| 700 | |
| 701 | ``DW_OP_over`` pushes a copy of the entry with index 1. |
| 702 | |
| 703 | *This is equivalent to a ``DW_OP_pick 1`` operation.* |
| 704 | |
| 705 | 5. ``DW_OP_swap`` |
| 706 | |
| 707 | ``DW_OP_swap`` swaps the top two stack entries. The entry at the top of the |
| 708 | stack becomes the second stack entry, and the second stack entry becomes the |
| 709 | top of the stack. |
| 710 | |
| 711 | 6. ``DW_OP_rot`` |
| 712 | |
| 713 | ``DW_OP_rot`` rotates the first three stack entries. The entry at the top of |
| 714 | the stack becomes the third stack entry, the second entry becomes the top of |
| 715 | the stack, and the third entry becomes the second entry. |
| 716 | |
| 717 | .. _amdgpu-dwarf-control-flow-operations: |
| 718 | |
| 719 | Control Flow Operations |
| 720 | ####################### |
| 721 | |
| 722 | The following operations provide simple control of the flow of a DWARF operation |
| 723 | expression. |
| 724 | |
| 725 | 1. ``DW_OP_nop`` |
| 726 | |
| 727 | ``DW_OP_nop`` is a place holder. It has no effect on the DWARF stack |
| 728 | entries. |
| 729 | |
| 730 | 2. ``DW_OP_le``, ``DW_OP_ge``, ``DW_OP_eq``, ``DW_OP_lt``, ``DW_OP_gt``, |
| 731 | ``DW_OP_ne`` |
| 732 | |
| 733 | .. note:: |
| 734 | |
| 735 | The same as in DWARF Version 5 section 2.5.1.5. |
| 736 | |
| 737 | 3. ``DW_OP_skip`` |
| 738 | |
| 739 | ``DW_OP_skip`` is an unconditional branch. Its single operand is a 2-byte |
| 740 | signed integer constant. The 2-byte constant is the number of bytes of the |
| 741 | DWARF expression to skip forward or backward from the current operation, |
| 742 | beginning after the 2-byte constant. |
| 743 | |
| 744 | If the updated position is at one past the end of the last operation, then |
| 745 | the operation expression evaluation is complete. |
| 746 | |
| 747 | Otherwise, the DWARF expression is ill-formed if the updated operation |
| 748 | position is not in the range of the first to last operation inclusive, or |
| 749 | not at the start of an operation. |
| 750 | |
| 751 | 4. ``DW_OP_bra`` |
| 752 | |
| 753 | ``DW_OP_bra`` is a conditional branch. Its single operand is a 2-byte signed |
| 754 | integer constant. This operation pops the top of stack. If the value popped |
| 755 | is not the constant 0, the 2-byte constant operand is the number of bytes of |
| 756 | the DWARF operation expression to skip forward or backward from the current |
| 757 | operation, beginning after the 2-byte constant. |
| 758 | |
| 759 | If the updated position is at one past the end of the last operation, then |
| 760 | the operation expression evaluation is complete. |
| 761 | |
| 762 | Otherwise, the DWARF expression is ill-formed if the updated operation |
| 763 | position is not in the range of the first to last operation inclusive, or |
| 764 | not at the start of an operation. |
| 765 | |
| 766 | 5. ``DW_OP_call2, DW_OP_call4, DW_OP_call_ref`` |
| 767 | |
| 768 | ``DW_OP_call2``, ``DW_OP_call4``, and ``DW_OP_call_ref`` perform DWARF |
| 769 | procedure calls during evaluation of a DWARF expression. |
| 770 | |
| 771 | ``DW_OP_call2`` and ``DW_OP_call4``, have one operand that is a 2- or 4-byte |
| 772 | unsigned offset, respectively, of a debugging information entry D in the |
| 773 | current compilation unit. |
| 774 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 775 | ``DW_OP_call_ref`` has one operand that is a 4-byte unsigned value in the |
| 776 | 32-bit DWARF format, or an 8-byte unsigned value in the 64-bit DWARF format, |
| 777 | that represents an offset of a debugging information entry D in a |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 778 | ``.debug_info`` section, which may be contained in an executable or shared |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 779 | object file other than that containing the operation. For references from |
| 780 | one executable or shared object file to another, the relocation must be |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 781 | performed by the consumer. |
| 782 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 783 | .. note: |
| 784 | |
| 785 | It is unclear how crossing from one executable or shared object file to |
| 786 | another can work. How would a consumer know which executable or shared |
| 787 | object file is being referenced? In an ELF file the DWARF is in a |
| 788 | non-ALLOC segment so standard dynamic relocations cannot be used. |
| 789 | |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 790 | *Operand interpretation of* ``DW_OP_call2``\ *,* ``DW_OP_call4``\ *, and* |
| 791 | ``DW_OP_call_ref`` *is exactly like that for* ``DW_FORM_ref2``\ *, |
| 792 | ``DW_FORM_ref4``\ *, and* ``DW_FORM_ref_addr``\ *, respectively.* |
| 793 | |
| 794 | The call operation is evaluated by: |
| 795 | |
| 796 | * If D has a ``DW_AT_location`` attribute that is encoded as a ``exprloc`` |
| 797 | that specifies an operation expression E, then execution of the current |
| 798 | operation expression continues from the first operation of E. Execution |
| 799 | continues until one past the last operation of E is reached, at which |
| 800 | point execution continues with the operation following the call operation. |
| 801 | Since E is evaluated on the same stack as the call, E can use, add, and/or |
| 802 | remove entries already on the stack. |
| 803 | |
| 804 | *Values on the stack at the time of the call may be used as parameters by |
| 805 | the called expression and values left on the stack by the called expression |
| 806 | may be used as return values by prior agreement between the calling and |
| 807 | called expressions.* |
| 808 | |
| 809 | * If D has a ``DW_AT_location`` attribute that is encoded as a ``loclist`` or |
| 810 | ``loclistsptr``, then the specified location list expression E is |
| 811 | evaluated, and the resulting location description is pushed on the stack. |
| 812 | The evaluation of E uses a context that has the same current frame and |
| 813 | current program location as the current operation expression, but an empty |
| 814 | initial stack. |
| 815 | |
| 816 | .. note:: |
| 817 | |
| 818 | This rule avoids having to define how to execute a matched location list |
| 819 | entry operation expression on the same stack as the call when there are |
| 820 | multiple matches. But it allows the call to obtain the location |
| 821 | description for a variable or formal parameter which may use a location |
| 822 | list expression. |
| 823 | |
| 824 | An alternative is to treat the case when D has a ``DW_AT_location`` |
| 825 | attribute that is encoded as a ``loclist`` or ``loclistsptr``, and the |
| 826 | specified location list expression E' matches a single location list |
| 827 | entry with operation expression E, the same as the ``exprloc`` case and |
| 828 | evaluate on the same stack. |
| 829 | |
| 830 | But this is not attractive as if the attribute is for a variable that |
| 831 | happens to end with a non-singleton stack, it will not simply put a |
| 832 | location description on the stack. Presumably the intent of using |
| 833 | ``DW_OP_call*`` on a variable or formal parameter debugger information |
| 834 | entry is to push just one location description on the stack. That |
| 835 | location description may have more than one single location description. |
| 836 | |
| 837 | The previous rule for ``exprloc`` also has the same problem as normally |
| 838 | a variable or formal parameter location expression may leave multiple |
| 839 | entries on the stack and only return the top entry. |
| 840 | |
| 841 | GDB implements ``DW_OP_call*`` by always executing E on the same stack. |
| 842 | If the location list has multiple matching entries, it simply picks the |
| 843 | first one and ignores the rest. This seems fundementally at odds with |
| 844 | the desire to supporting multiple places for variables. |
| 845 | |
| 846 | So, it feels like ``DW_OP_call*`` should both support pushing a location |
| 847 | description on the stack for a variable or formal parameter, and also |
| 848 | support being able to execute an operation expression on the same stack. |
| 849 | Being able to specify a different operation expression for different |
| 850 | program locations seems a desirable feature to retain. |
| 851 | |
| 852 | A solution to that is to have a distinct ``DW_AT_LLVM_proc`` attribute |
| 853 | for the ``DW_TAG_dwarf_procedure`` debugging information entry. Then the |
| 854 | ``DW_AT_location`` attribute expression is always executed separately |
| 855 | and pushes a location description (that may have multiple single |
| 856 | location descriptions), and the ``DW_AT_LLVM_proc`` attribute expression |
| 857 | is always executed on the same stack and can leave anything on the |
| 858 | stack. |
| 859 | |
| 860 | The ``DW_AT_LLVM_proc`` attribute could have the new classes |
| 861 | ``exprproc``, ``loclistproc``, and ``loclistsptrproc`` to indicate that |
| 862 | the expression is executed on the same stack. ``exprproc`` is the same |
| 863 | encoding as ``exprloc``. ``loclistproc`` and ``loclistsptrproc`` are the |
| 864 | same encoding as their non-\ ``proc`` counterparts except the DWARF is |
| 865 | ill-formed if the location list does not match exactly one location list |
| 866 | entry and a default entry is required. These forms indicate explicitly |
| 867 | that the matched single operation expression must be executed on the |
| 868 | same stack. This is better than ad hoc special rules for ``loclistproc`` |
| 869 | and ``loclistsptrproc`` which are currently clearly defined to always |
| 870 | return a location description. The producer then explicitly indicates |
| 871 | the intent through the attribute classes. |
| 872 | |
| 873 | Such a change would be a breaking change for how GDB implements |
| 874 | ``DW_OP_call*``. However, are the breaking cases actually occurring in |
| 875 | practice? GDB could implement the current approach for DWARF Version 5, |
| 876 | and the new semantics for DWARF Version 6 which has been done for some |
| 877 | other features. |
| 878 | |
| 879 | Another option is to limit the execution to be on the same stack only to |
| 880 | the evaluation of an expression E that is the value of a |
| 881 | ``DW_AT_location`` attribute of a ``DW_TAG_dwarf_procedure`` debugging |
| 882 | information entry. The DWARF would be ill-formed if E is a location list |
| 883 | expression that does not match exactly one location list entry. In all |
| 884 | other cases the evaluation of an expression E that is the value of a |
| 885 | ``DW_AT_location`` attribute would evaluate E with a context that has |
| 886 | the same current frame and current program location as the current |
| 887 | operation expression, but an empty initial stack, and push the resulting |
| 888 | location description on the stack. |
| 889 | |
| 890 | * If D has a ``DW_AT_const_value`` attribute with a value V, then it is as |
| 891 | if a ``DW_OP_implicit_value V`` operation was executed. |
| 892 | |
| 893 | *This allows a call operation to be used to compute the location |
| 894 | description for any variable or formal parameter regardless of whether the |
| 895 | producer has optimized it to a constant. This is consistent with the |
| 896 | ``DW_OP_implicit_pointer`` operation.* |
| 897 | |
| 898 | .. note:: |
| 899 | |
| 900 | Alternatively, could deprecate using ``DW_AT_const_value`` for |
| 901 | ``DW_TAG_variable`` and ``DW_TAG_formal_parameter`` debugger information |
| 902 | entries that are constants and instead use ``DW_AT_location`` with an |
| 903 | operation expression that results in a location description with one |
| 904 | implicit location description. Then this rule would not be required. |
| 905 | |
| 906 | * Otherwise, there is no effect and no changes are made to the stack. |
| 907 | |
| 908 | .. note:: |
| 909 | |
| 910 | In DWARF Version 5, if D does not have a ``DW_AT_location`` then |
| 911 | ``DW_OP_call*`` is defined to have no effect. It is unclear that this is |
| 912 | the right definition as a producer should be able to rely on using |
| 913 | ``DW_OP_call*`` to get a location description for any non-\ |
| 914 | ``DW_TAG_dwarf_procedure`` debugging information entries. Also, the |
| 915 | producer should not be creating DWARF with ``DW_OP_call*`` to a |
| 916 | ``DW_TAG_dwarf_procedure`` that does not have a ``DW_AT_location`` |
| 917 | attribute. So, should this case be defined as an ill-formed DWARF |
| 918 | expression? |
| 919 | |
| 920 | *The* ``DW_TAG_dwarf_procedure`` *debugging information entry can be used to |
| 921 | define DWARF procedures that can be called.* |
| 922 | |
| 923 | .. _amdgpu-dwarf-value-operations: |
| 924 | |
| 925 | Value Operations |
| 926 | ################ |
| 927 | |
| 928 | This section describes the operations that push values on the stack. |
| 929 | |
| 930 | Each value stack entry has a type and a literal value and can represent a |
| 931 | literal value of any supported base type of the target architecture. The base |
| 932 | type specifies the size and encoding of the literal value. |
| 933 | |
| 934 | Instead of a base type, value stack entries can have a distinguished generic |
| 935 | type, which is an integral type that has the size of an address in the target |
| 936 | architecture default address space and unspecified signedness. |
| 937 | |
| 938 | *The generic type is the same as the unspecified type used for stack operations |
| 939 | defined in DWARF Version 4 and before.* |
| 940 | |
| 941 | An integral type is a base type that has an encoding of ``DW_ATE_signed``, |
| 942 | ``DW_ATE_signed_char``, ``DW_ATE_unsigned``, ``DW_ATE_unsigned_char``, |
| 943 | ``DW_ATE_boolean``, or any target architecture defined integral encoding in the |
| 944 | inclusive range ``DW_ATE_lo_user`` to ``DW_ATE_hi_user``. |
| 945 | |
| 946 | .. note:: |
| 947 | |
| 948 | Unclear if ``DW_ATE_address`` is an integral type. GDB does not seem to |
| 949 | consider it as integral. |
| 950 | |
| 951 | .. _amdgpu-dwarf-literal-operations: |
| 952 | |
| 953 | Literal Operations |
| 954 | ^^^^^^^^^^^^^^^^^^ |
| 955 | |
| 956 | The following operations all push a literal value onto the DWARF stack. |
| 957 | |
| 958 | Operations other than ``DW_OP_const_type`` push a value V with the generic type. |
| 959 | If V is larger than the generic type, then V is truncated to the generic type |
| 960 | size and the low-order bits used. |
| 961 | |
| 962 | 1. ``DW_OP_lit0``, ``DW_OP_lit1``, ..., ``DW_OP_lit31`` |
| 963 | |
| 964 | ``DW_OP_lit<N>`` operations encode an unsigned literal value N from 0 |
| 965 | through 31, inclusive. They push the value N with the generic type. |
| 966 | |
| 967 | 2. ``DW_OP_const1u``, ``DW_OP_const2u``, ``DW_OP_const4u``, ``DW_OP_const8u`` |
| 968 | |
| 969 | ``DW_OP_const<N>u`` operations have a single operand that is a 1, 2, 4, or |
| 970 | 8-byte unsigned integer constant U, respectively. They push the value U with |
| 971 | the generic type. |
| 972 | |
| 973 | 3. ``DW_OP_const1s``, ``DW_OP_const2s``, ``DW_OP_const4s``, ``DW_OP_const8s`` |
| 974 | |
| 975 | ``DW_OP_const<N>s`` operations have a single operand that is a 1, 2, 4, or |
| 976 | 8-byte signed integer constant S, respectively. They push the value S with |
| 977 | the generic type. |
| 978 | |
| 979 | 4. ``DW_OP_constu`` |
| 980 | |
| 981 | ``DW_OP_constu`` has a single unsigned LEB128 integer operand N. It pushes |
| 982 | the value N with the generic type. |
| 983 | |
| 984 | 5. ``DW_OP_consts`` |
| 985 | |
| 986 | ``DW_OP_consts`` has a single signed LEB128 integer operand N. It pushes the |
| 987 | value N with the generic type. |
| 988 | |
| 989 | 6. ``DW_OP_constx`` |
| 990 | |
| 991 | ``DW_OP_constx`` has a single unsigned LEB128 integer operand that |
| 992 | represents a zero-based index into the ``.debug_addr`` section relative to |
| 993 | the value of the ``DW_AT_addr_base`` attribute of the associated compilation |
| 994 | unit. The value N in the ``.debug_addr`` section has the size of the generic |
| 995 | type. It pushes the value N with the generic type. |
| 996 | |
| 997 | *The* ``DW_OP_constx`` *operation is provided for constants that require |
| 998 | link-time relocation but should not be interpreted by the consumer as a |
| 999 | relocatable address (for example, offsets to thread-local storage).* |
| 1000 | |
| 1001 | 9. ``DW_OP_const_type`` |
| 1002 | |
| 1003 | ``DW_OP_const_type`` has three operands. The first is an unsigned LEB128 |
| 1004 | integer that represents the offset of a debugging information entry D in the |
| 1005 | current compilation unit, that provides the type of the constant value. The |
| 1006 | second is a 1-byte unsigned integral constant S. The third is a block of |
| 1007 | bytes B, with a length equal to S. |
| 1008 | |
| 1009 | T is the bit size of the type D. The least significant T bits of B are |
| 1010 | interpreted as a value V of the type D. It pushes the value V with the type |
| 1011 | D. |
| 1012 | |
| 1013 | The DWARF is ill-formed if D is not a ``DW_TAG_base_type`` debugging |
| 1014 | information entry, or if T divided by 8 and rounded up to a multiple of 8 |
| 1015 | (the byte size) is not equal to S. |
| 1016 | |
| 1017 | *While the size of the byte block B can be inferred from the type D |
| 1018 | definition, it is encoded explicitly into the operation so that the |
| 1019 | operation can be parsed easily without reference to the* ``.debug_info`` |
| 1020 | *section.* |
| 1021 | |
| 1022 | 10. ``DW_OP_LLVM_push_lane`` *New* |
| 1023 | |
| 1024 | ``DW_OP_LLVM_push_lane`` pushes a value with the generic type that is the |
| 1025 | target architecture specific lane identifier of the thread of execution for |
| 1026 | which a user presented expression is currently being evaluated. |
| 1027 | |
| 1028 | *For languages that are implemented using a SIMD or SIMT execution model, |
| 1029 | this is the lane number that corresponds to the source language thread of |
| 1030 | execution upon which the user is focused.* |
| 1031 | |
| 1032 | .. _amdgpu-dwarf-arithmetic-logical-operations: |
| 1033 | |
| 1034 | Arithmetic and Logical Operations |
| 1035 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1036 | |
| 1037 | .. note:: |
| 1038 | |
| 1039 | This section is the same as DWARF Version 5 section 2.5.1.4. |
| 1040 | |
| 1041 | .. _amdgpu-dwarf-type-conversions-operations: |
| 1042 | |
| 1043 | Type Conversion Operations |
| 1044 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1045 | |
| 1046 | .. note:: |
| 1047 | |
| 1048 | This section is the same as DWARF Version 5 section 2.5.1.6. |
| 1049 | |
| 1050 | .. _amdgpu-dwarf-general-operations: |
| 1051 | |
| 1052 | Special Value Operations |
| 1053 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1054 | |
| 1055 | There are these special value operations currently defined: |
| 1056 | |
| 1057 | 1. ``DW_OP_regval_type`` |
| 1058 | |
| 1059 | ``DW_OP_regval_type`` has two operands. The first is an unsigned LEB128 |
| 1060 | integer that represents a register number R. The second is an unsigned |
| 1061 | LEB128 integer that represents the offset of a debugging information entry D |
| 1062 | in the current compilation unit, that provides the type of the register |
| 1063 | value. |
| 1064 | |
| 1065 | The contents of register R are interpreted as a value V of the type D. The |
| 1066 | value V is pushed on the stack with the type D. |
| 1067 | |
| 1068 | The DWARF is ill-formed if D is not a ``DW_TAG_base_type`` debugging |
| 1069 | information entry, or if the size of type D is not the same as the size of |
| 1070 | register R. |
| 1071 | |
| 1072 | .. note:: |
| 1073 | |
| 1074 | Should DWARF allow the type D to be a different size to the size of the |
| 1075 | register R? Requiring them to be the same bit size avoids any issue of |
| 1076 | conversion as the bit contents of the register is simply interpreted as a |
| 1077 | value of the specified type. If a conversion is wanted it can be done |
| 1078 | explicitly using a ``DW_OP_convert`` operation. |
| 1079 | |
| 1080 | GDB has a per register hook that allows a target specific conversion on a |
| 1081 | register by register basis. It defaults to truncation of bigger registers, |
| 1082 | and to actually reading bytes from the next register (or reads out of |
| 1083 | bounds for the last register) for smaller registers. There are no GDB |
| 1084 | tests that read a register out of bounds (except an illegal hand written |
| 1085 | assembly test). |
| 1086 | |
| 1087 | 2. ``DW_OP_deref`` |
| 1088 | |
| 1089 | The ``DW_OP_deref`` operation pops one stack entry that must be a location |
| 1090 | description L. |
| 1091 | |
| 1092 | A value of the bit size of the generic type is retrieved from the location |
| 1093 | storage specified by L. The value V retrieved is pushed on the stack with |
| 1094 | the generic type. |
| 1095 | |
| 1096 | If any bit of the value is retrieved from the undefined location storage, or |
| 1097 | the offset of any bit exceeds the size of the location storage specified by |
| 1098 | L, then the DWARF expression is ill-formed. |
| 1099 | |
| 1100 | See :ref:`amdgpu-dwarf-implicit-location-descriptions` for special rules |
| 1101 | concerning implicit location descriptions created by the |
| 1102 | ``DW_OP_implicit_pointer`` and ``DW_OP_LLVM_implicit_aspace_pointer`` |
| 1103 | operations. |
| 1104 | |
| 1105 | *If L, or the location description of any composite location description |
| 1106 | part that is a subcomponent of L, has more than one single location |
| 1107 | description, then any one of them can be selected as they are required to |
| 1108 | all have the same value. For any single location description SL, bits are |
| 1109 | retrieved from the associated storage location starting at the bit offset |
| 1110 | specified by SL. For a composite location description, the retrieved bits |
| 1111 | are the concatenation of the N bits from each composite location part PL, |
| 1112 | where N is limited to the size of PL.* |
| 1113 | |
| 1114 | 3. ``DW_OP_deref_size`` |
| 1115 | |
| 1116 | ``DW_OP_deref_size`` has a single 1-byte unsigned integral constant that |
| 1117 | represents a byte result size S. |
| 1118 | |
| 1119 | It pops one stack entry that must be a location description L. |
| 1120 | |
| 1121 | T is the smaller of the generic type size and S scaled by 8 (the byte size). |
| 1122 | A value V of T bits is retrieved from the location storage specified by L. |
| 1123 | If V is smaller than the size of the generic type, V is zero-extended to the |
| 1124 | generic type size. V is pushed onto the stack with the generic type. |
| 1125 | |
| 1126 | The DWARF expression is ill-formed if any bit of the value is retrieved from |
| 1127 | the undefined location storage, or if the offset of any bit exceeds the size |
| 1128 | of the location storage specified by L. |
| 1129 | |
| 1130 | .. note:: |
| 1131 | |
| 1132 | Truncating the value when S is larger than the generic type matches what |
| 1133 | GDB does. This allows the generic type size to not be a integral byte |
| 1134 | size. It does allow S to be arbitrarily large. Should S be restricted to |
| 1135 | the size of the generic type rounded up to a multiple of 8? |
| 1136 | |
| 1137 | See :ref:`amdgpu-dwarf-implicit-location-descriptions` for special rules |
| 1138 | concerning implicit location descriptions created by the |
| 1139 | ``DW_OP_implicit_pointer`` and ``DW_OP_LLVM_implicit_aspace_pointer`` |
| 1140 | operations. |
| 1141 | |
| 1142 | 4. ``DW_OP_deref_type`` |
| 1143 | |
| 1144 | ``DW_OP_deref_type`` has two operands. The first is a 1-byte unsigned |
| 1145 | integral constant S. The second is an unsigned LEB128 integer that |
| 1146 | represents the offset of a debugging information entry D in the current |
| 1147 | compilation unit, that provides the type of the result value. |
| 1148 | |
| 1149 | It pops one stack entry that must be a location description L. T is the bit |
| 1150 | size of the type D. A value V of T bits is retrieved from the location |
| 1151 | storage specified by L. V is pushed on the stack with the type D. |
| 1152 | |
| 1153 | The DWARF is ill-formed if D is not a ``DW_TAG_base_type`` debugging |
| 1154 | information entry, if T divided by 8 and rounded up to a multiple of 8 (the |
| 1155 | byte size) is not equal to S, if any bit of the value is retrieved from the |
| 1156 | undefined location storage, or if the offset of any bit exceeds the size of |
| 1157 | the location storage specified by L. |
| 1158 | |
| 1159 | See :ref:`amdgpu-dwarf-implicit-location-descriptions` for special rules |
| 1160 | concerning implicit location descriptions created by the |
| 1161 | ``DW_OP_implicit_pointer`` and ``DW_OP_LLVM_implicit_aspace_pointer`` |
| 1162 | operations. |
| 1163 | |
| 1164 | *While the size of the pushed value V can be inferred from the type D |
| 1165 | definition, it is encoded explicitly into the operation so that the |
| 1166 | operation can be parsed easily without reference to the* ``.debug_info`` |
| 1167 | *section.* |
| 1168 | |
| 1169 | .. note:: |
| 1170 | |
| 1171 | It is unclear why the operand S is needed. Unlike ``DW_OP_const_type``, |
| 1172 | the size is not needed for parsing. Any evaluation needs to get the base |
| 1173 | type to record with the value to know its encoding and bit size. |
| 1174 | |
| 1175 | This definition allows the base type to be a bit size since there seems no |
| 1176 | reason to restrict it. |
| 1177 | |
| 1178 | 5. ``DW_OP_xderef`` *Deprecated* |
| 1179 | |
| 1180 | ``DW_OP_xderef`` pops two stack entries. The first must be an integral type |
| 1181 | value that represents an address A. The second must be an integral type |
| 1182 | value that represents a target architecture specific address space |
| 1183 | identifier AS. |
| 1184 | |
| 1185 | The operation is equivalent to performing ``DW_OP_swap; |
| 1186 | DW_OP_LLVM_form_aspace_address; DW_OP_deref``. The value V retrieved is left |
| 1187 | on the stack with the generic type. |
| 1188 | |
| 1189 | *This operation is deprecated as the* ``DW_OP_LLVM_form_aspace_address`` |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 1190 | *operation can be used and provides greater expressiveness.* |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 1191 | |
| 1192 | 6. ``DW_OP_xderef_size`` *Deprecated* |
| 1193 | |
| 1194 | ``DW_OP_xderef_size`` has a single 1-byte unsigned integral constant that |
| 1195 | represents a byte result size S. |
| 1196 | |
| 1197 | It pops two stack entries. The first must be an integral type value that |
| 1198 | represents an address A. The second must be an integral type value that |
| 1199 | represents a target architecture specific address space identifier AS. |
| 1200 | |
| 1201 | The operation is equivalent to performing ``DW_OP_swap; |
| 1202 | DW_OP_LLVM_form_aspace_address; DW_OP_deref_size S``. The zero-extended |
| 1203 | value V retrieved is left on the stack with the generic type. |
| 1204 | |
| 1205 | *This operation is deprecated as the* ``DW_OP_LLVM_form_aspace_address`` |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 1206 | *operation can be used and provides greater expressiveness.* |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 1207 | |
| 1208 | 7. ``DW_OP_xderef_type`` *Deprecated* |
| 1209 | |
| 1210 | ``DW_OP_xderef_type`` has two operands. The first is a 1-byte unsigned |
| 1211 | integral constant S. The second operand is an unsigned LEB128 |
| 1212 | integer R that represents the offset of a debugging information entry D in |
| 1213 | the current compilation unit, that provides the type of the result value. |
| 1214 | |
| 1215 | It pops two stack entries. The first must be an integral type value that |
| 1216 | represents an address A. The second must be an integral type value that |
| 1217 | represents a target architecture specific address space identifier AS. |
| 1218 | |
| 1219 | The operation is equivalent to performing ``DW_OP_swap; |
| 1220 | DW_OP_LLVM_form_aspace_address; DW_OP_deref_type S R``. The value V |
| 1221 | retrieved is left on the stack with the type D. |
| 1222 | |
| 1223 | *This operation is deprecated as the* ``DW_OP_LLVM_form_aspace_address`` |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 1224 | *operation can be used and provides greater expressiveness.* |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 1225 | |
| 1226 | 8. ``DW_OP_entry_value`` *Deprecated* |
| 1227 | |
| 1228 | ``DW_OP_entry_value`` pushes the value that the described location held upon |
| 1229 | entering the current subprogram. |
| 1230 | |
| 1231 | It has two operands. The first is an unsigned LEB128 integer S. The second |
| 1232 | is a block of bytes, with a length equal S, interpreted as a DWARF |
| 1233 | operation expression E. |
| 1234 | |
| 1235 | E is evaluated as if it had been evaluated upon entering the current |
| 1236 | subprogram with an empty initial stack. |
| 1237 | |
| 1238 | .. note:: |
| 1239 | |
| 1240 | It is unclear what this means. What is the current program location and |
| 1241 | current frame that must be used? Does this require reverse execution so |
| 1242 | the register and memory state are as it was on entry to the current |
| 1243 | subprogram? |
| 1244 | |
| 1245 | The DWARF expression is ill-formed if the evaluation of E executes a |
| 1246 | ``DW_OP_push_object_address`` operation. |
| 1247 | |
| 1248 | If the result of E is a location description with one register location |
| 1249 | description (see :ref:`amdgpu-dwarf-register-location-descriptions`), |
| 1250 | ``DW_OP_entry_value`` pushes the value that register had upon entering the |
| 1251 | current subprogram. The value entry type is the target architecture register |
| 1252 | base type. If the register value is undefined or the register location |
| 1253 | description bit offset is not 0, then the DWARF expression is ill-formed. |
| 1254 | |
| 1255 | *The register location description provides a more compact form for the case |
| 1256 | where the value was in a register on entry to the subprogram.* |
| 1257 | |
| 1258 | If the result of E is a value V, ``DW_OP_entry_value`` pushes V on the |
| 1259 | stack. |
| 1260 | |
| 1261 | Otherwise, the DWARF expression is ill-formed. |
| 1262 | |
| 1263 | *The values needed to evaluate* ``DW_OP_entry_value`` *could be obtained in |
| 1264 | several ways. The consumer could suspend execution on entry to the |
| 1265 | subprogram, record values needed by* ``DW_OP_entry_value`` *expressions |
| 1266 | within the subprogram, and then continue. When evaluating* |
| 1267 | ``DW_OP_entry_value``\ *, the consumer would use these recorded values |
| 1268 | rather than the current values. Or, when evaluating* ``DW_OP_entry_value``\ |
| 1269 | *, the consumer could virtually unwind using the Call Frame Information |
| 1270 | (see* :ref:`amdgpu-dwarf-call-frame-information`\ *) to recover register |
| 1271 | values that might have been clobbered since the subprogram entry point.* |
| 1272 | |
| 1273 | *The* ``DW_OP_entry_value`` *operation is deprecated as its main usage is |
| 1274 | provided by other means. DWARF Version 5 added the* |
| 1275 | ``DW_TAG_call_site_parameter`` *debugger information entry for call sites |
| 1276 | that has* ``DW_AT_call_value``\ *,* ``DW_AT_call_data_location``\ *, and* |
| 1277 | ``DW_AT_call_data_value`` *attributes that provide DWARF expressions to |
| 1278 | compute actual parameter values at the time of the call, and requires the |
| 1279 | producer to ensure the expressions are valid to evaluate even when virtually |
| 1280 | unwound. The* ``DW_OP_LLVM_call_frame_entry_reg`` *operation provides access |
| 1281 | to registers in the virtually unwound calling frame.* |
| 1282 | |
| 1283 | .. note:: |
| 1284 | |
| 1285 | It is unclear why this operation is defined this way. How would a consumer |
| 1286 | know what values have to be saved on entry to the subprogram? Does it have |
| 1287 | to parse every expression of every ``DW_OP_entry_value`` operation to |
| 1288 | capture all the possible results needed? Or does it have to implement |
| 1289 | reverse execution so it can evaluate the expression in the context of the |
| 1290 | entry of the subprogram so it can obtain the entry point register and |
| 1291 | memory values? Or does the compiler somehow instruct the consumer how to |
| 1292 | create the saved copies of the variables on entry? |
| 1293 | |
| 1294 | If the expression is simply using existing variables, then it is just a |
| 1295 | regular expression and no special operation is needed. If the main purpose |
| 1296 | is only to read the entry value of a register using CFI then it would be |
| 1297 | better to have an operation that explicitly does just that such as the |
| 1298 | proposed ``DW_OP_LLVM_call_frame_entry_reg`` operation. |
| 1299 | |
| 1300 | GDB only seems to implement ``DW_OP_entry_value`` when E is exactly |
| 1301 | ``DW_OP_reg*`` or ``DW_OP_breg*; DW_OP_deref*``. It evaluates E in the |
| 1302 | context of the calling subprogram and the calling call site program |
| 1303 | location. But the wording suggests that is not the intention. |
| 1304 | |
| 1305 | Given these issues it is suggested ``DW_OP_entry_value`` is deprecated in |
| 1306 | favor of using the new facities that have well defined semantics and |
| 1307 | implementations. |
| 1308 | |
| 1309 | .. _amdgpu-dwarf-location-description-operations: |
| 1310 | |
| 1311 | Location Description Operations |
| 1312 | ############################### |
| 1313 | |
| 1314 | This section describes the operations that push location descriptions on the |
| 1315 | stack. |
| 1316 | |
| 1317 | General Location Description Operations |
| 1318 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1319 | |
| 1320 | 1. ``DW_OP_LLVM_offset`` *New* |
| 1321 | |
| 1322 | ``DW_OP_LLVM_offset`` pops two stack entries. The first must be an integral |
| 1323 | type value that represents a byte displacement B. The second must be a |
| 1324 | location description L. |
| 1325 | |
| 1326 | It adds the value of B scaled by 8 (the byte size) to the bit offset of each |
| 1327 | single location description SL of L, and pushes the updated L. |
| 1328 | |
| 1329 | If the updated bit offset of any SL is less than 0 or greater than or equal |
| 1330 | to the size of the location storage specified by SL, then the DWARF |
| 1331 | expression is ill-formed. |
| 1332 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 1333 | 2. ``DW_OP_LLVM_offset_uconst`` *New* |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 1334 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 1335 | ``DW_OP_LLVM_offset_uconst`` has a single unsigned LEB128 integer operand |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 1336 | that represents a byte displacement B. |
| 1337 | |
| 1338 | The operation is equivalent to performing ``DW_OP_constu B; |
| 1339 | DW_OP_LLVM_offset``. |
| 1340 | |
| 1341 | *This operation is supplied specifically to be able to encode more field |
| 1342 | displacements in two bytes than can be done with* ``DW_OP_lit*; |
| 1343 | DW_OP_LLVM_offset``\ *.* |
| 1344 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 1345 | .. note:: |
| 1346 | |
| 1347 | Should this be named ``DW_OP_LLVM_offset_uconst`` to match |
| 1348 | ``DW_OP_plus_uconst``, or ``DW_OP_LLVM_offset_constu`` to match |
| 1349 | ``DW_OP_constu``? |
| 1350 | |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 1351 | 3. ``DW_OP_LLVM_bit_offset`` *New* |
| 1352 | |
| 1353 | ``DW_OP_LLVM_bit_offset`` pops two stack entries. The first must be an |
| 1354 | integral type value that represents a bit displacement B. The second must be |
| 1355 | a location description L. |
| 1356 | |
| 1357 | It adds the value of B to the bit offset of each single location description |
| 1358 | SL of L, and pushes the updated L. |
| 1359 | |
| 1360 | If the updated bit offset of any SL is less than 0 or greater than or equal |
| 1361 | to the size of the location storage specified by SL, then the DWARF |
| 1362 | expression is ill-formed. |
| 1363 | |
| 1364 | 4. ``DW_OP_push_object_address`` |
| 1365 | |
| 1366 | ``DW_OP_push_object_address`` pushes the location description L of the |
| 1367 | object currently being evaluated as part of evaluation of a user presented |
| 1368 | expression. |
| 1369 | |
| 1370 | This object may correspond to an independent variable described by its own |
| 1371 | debugging information entry or it may be a component of an array, structure, |
| 1372 | or class whose address has been dynamically determined by an earlier step |
| 1373 | during user expression evaluation. |
| 1374 | |
| 1375 | *This operation provides explicit functionality (especially for arrays |
| 1376 | involving descriptions) that is analogous to the implicit push of the base |
| 1377 | location description of a structure prior to evaluation of a |
| 1378 | ``DW_AT_data_member_location`` to access a data member of a structure.* |
| 1379 | |
| 1380 | 5. ``DW_OP_LLVM_call_frame_entry_reg`` *New* |
| 1381 | |
| 1382 | ``DW_OP_LLVM_call_frame_entry_reg`` has a single unsigned LEB128 integer |
| 1383 | operand that represents a target architecture register number R. |
| 1384 | |
| 1385 | It pushes a location description L that holds the value of register R on |
| 1386 | entry to the current subprogram as defined by the Call Frame Information |
| 1387 | (see :ref:`amdgpu-dwarf-call-frame-information`). |
| 1388 | |
| 1389 | *If there is no Call Frame Information defined, then the default rules for |
| 1390 | the target architecture are used. If the register rule is* undefined\ *, then |
| 1391 | the undefined location description is pushed. If the register rule is* same |
| 1392 | value\ *, then a register location description for R is pushed.* |
| 1393 | |
| 1394 | Undefined Location Description Operations |
| 1395 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1396 | |
| 1397 | *The undefined location storage represents a piece or all of an object that is |
| 1398 | present in the source but not in the object code (perhaps due to optimization). |
| 1399 | Neither reading nor writing to the undefined location storage is meaningful.* |
| 1400 | |
| 1401 | An undefined location description specifies the undefined location storage. |
| 1402 | There is no concept of the size of the undefined location storage, nor of a bit |
| 1403 | offset for an undefined location description. The ``DW_OP_LLVM_*offset`` |
| 1404 | operations leave an undefined location description unchanged. The |
| 1405 | ``DW_OP_*piece`` operations can explicitly or implicitly specify an undefined |
| 1406 | location description, allowing any size and offset to be specified, and results |
| 1407 | in a part with all undefined bits. |
| 1408 | |
| 1409 | 1. ``DW_OP_LLVM_undefined`` *New* |
| 1410 | |
| 1411 | ``DW_OP_LLVM_undefined`` pushes a location description L that comprises one |
| 1412 | undefined location description SL. |
| 1413 | |
| 1414 | .. _amdgpu-dwarf-memory-location-description-operations: |
| 1415 | |
| 1416 | Memory Location Description Operations |
| 1417 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1418 | |
| 1419 | Each of the target architecture specific address spaces has a corresponding |
| 1420 | memory location storage that denotes the linear addressable memory of that |
| 1421 | address space. The size of each memory location storage corresponds to the range |
| 1422 | of the addresses in the corresponding address space. |
| 1423 | |
| 1424 | *It is target architecture defined how address space location storage maps to |
| 1425 | target architecture physical memory. For example, they may be independent |
| 1426 | memory, or more than one location storage may alias the same physical memory |
| 1427 | possibly at different offsets and with different interleaving. The mapping may |
| 1428 | also be dictated by the source language address classes.* |
| 1429 | |
| 1430 | A memory location description specifies a memory location storage. The bit |
| 1431 | offset corresponds to a bit position within a byte of the memory. Bits accessed |
| 1432 | using a memory location description, access the corresponding target |
| 1433 | architecture memory starting at the bit position within the byte specified by |
| 1434 | the bit offset. |
| 1435 | |
| 1436 | A memory location description that has a bit offset that is a multiple of 8 (the |
| 1437 | byte size) is defined to be a byte address memory location description. It has a |
| 1438 | memory byte address A that is equal to the bit offset divided by 8. |
| 1439 | |
| 1440 | A memory location description that does not have a bit offset that is a multiple |
| 1441 | of 8 (the byte size) is defined to be a bit field memory location description. |
| 1442 | It has a bit position B equal to the bit offset modulo 8, and a memory byte |
| 1443 | address A equal to the bit offset minus B that is then divided by 8. |
| 1444 | |
| 1445 | The address space AS of a memory location description is defined to be the |
| 1446 | address space that corresponds to the memory location storage associated with |
| 1447 | the memory location description. |
| 1448 | |
| 1449 | A location description that is comprised of one byte address memory location |
| 1450 | description SL is defined to be a memory byte address location description. It |
| 1451 | has a byte address equal to A and an address space equal to AS of the |
| 1452 | corresponding SL. |
| 1453 | |
| 1454 | ``DW_ASPACE_none`` is defined as the target architecture default address space. |
| 1455 | |
| 1456 | If a stack entry is required to be a location description, but it is a value V |
| 1457 | with the generic type, then it is implicitly converted to a location description |
| 1458 | L with one memory location description SL. SL specifies the memory location |
| 1459 | storage that corresponds to the target architecture default address space with a |
| 1460 | bit offset equal to V scaled by 8 (the byte size). |
| 1461 | |
| 1462 | .. note:: |
| 1463 | |
| 1464 | If it is wanted to allow any integral type value to be implicitly converted to |
| 1465 | a memory location description in the target architecture default address |
| 1466 | space: |
| 1467 | |
| 1468 | If a stack entry is required to be a location description, but is a value V |
| 1469 | with an integral type, then it is implicitly converted to a location |
| 1470 | description L with a one memory location description SL. If the type size of |
| 1471 | V is less than the generic type size, then the value V is zero extended to |
| 1472 | the size of the generic type. The least significant generic type size bits |
| 1473 | are treated as a twos-complement unsigned value to be used as an address A. |
| 1474 | SL specifies memory location storage corresponding to the target |
| 1475 | architecture default address space with a bit offset equal to A scaled by 8 |
| 1476 | (the byte size). |
| 1477 | |
| 1478 | The implicit conversion could also be defined as target architecture specific. |
| 1479 | For example, GDB checks if V is an integral type. If it is not it gives an |
| 1480 | error. Otherwise, GDB zero-extends V to 64 bits. If the GDB target defines a |
| 1481 | hook function, then it is called. The target specific hook function can modify |
| 1482 | the 64-bit value, possibly sign extending based on the original value type. |
| 1483 | Finally, GDB treats the 64-bit value V as a memory location address. |
| 1484 | |
| 1485 | If a stack entry is required to be a location description, but it is an implicit |
| 1486 | pointer value IPV with the target architecture default address space, then it is |
| 1487 | implicitly converted to a location description with one single location |
| 1488 | description specified by IPV. See |
| 1489 | :ref:`amdgpu-dwarf-implicit-location-descriptions`. |
| 1490 | |
| 1491 | .. note:: |
| 1492 | |
| 1493 | Is this rule required for DWARF Version 5 backwards compatibility? If not, it |
| 1494 | can be eliminated, and the producer can use |
| 1495 | ``DW_OP_LLVM_form_aspace_address``. |
| 1496 | |
| 1497 | If a stack entry is required to be a value, but it is a location description L |
| 1498 | with one memory location description SL in the target architecture default |
| 1499 | address space with a bit offset B that is a multiple of 8, then it is implicitly |
| 1500 | converted to a value equal to B divided by 8 (the byte size) with the generic |
| 1501 | type. |
| 1502 | |
| 1503 | 1. ``DW_OP_addr`` |
| 1504 | |
| 1505 | ``DW_OP_addr`` has a single byte constant value operand, which has the size |
| 1506 | of the generic type, that represents an address A. |
| 1507 | |
| 1508 | It pushes a location description L with one memory location description SL |
| 1509 | on the stack. SL specifies the memory location storage corresponding to the |
| 1510 | target architecture default address space with a bit offset equal to A |
| 1511 | scaled by 8 (the byte size). |
| 1512 | |
| 1513 | *If the DWARF is part of a code object, then A may need to be relocated. For |
| 1514 | example, in the ELF code object format, A must be adjusted by the difference |
| 1515 | between the ELF segment virtual address and the virtual address at which the |
| 1516 | segment is loaded.* |
| 1517 | |
| 1518 | 2. ``DW_OP_addrx`` |
| 1519 | |
| 1520 | ``DW_OP_addrx`` has a single unsigned LEB128 integer operand that represents |
| 1521 | a zero-based index into the ``.debug_addr`` section relative to the value of |
| 1522 | the ``DW_AT_addr_base`` attribute of the associated compilation unit. The |
| 1523 | address value A in the ``.debug_addr`` section has the size of the generic |
| 1524 | type. |
| 1525 | |
| 1526 | It pushes a location description L with one memory location description SL |
| 1527 | on the stack. SL specifies the memory location storage corresponding to the |
| 1528 | target architecture default address space with a bit offset equal to A |
| 1529 | scaled by 8 (the byte size). |
| 1530 | |
| 1531 | *If the DWARF is part of a code object, then A may need to be relocated. For |
| 1532 | example, in the ELF code object format, A must be adjusted by the difference |
| 1533 | between the ELF segment virtual address and the virtual address at which the |
| 1534 | segment is loaded.* |
| 1535 | |
| 1536 | 3. ``DW_OP_LLVM_form_aspace_address`` *New* |
| 1537 | |
| 1538 | ``DW_OP_LLVM_form_aspace_address`` pops top two stack entries. The first |
| 1539 | must be an integral type value that represents a target architecture |
| 1540 | specific address space identifier AS. The second must be an integral type |
| 1541 | value that represents an address A. |
| 1542 | |
| 1543 | The address size S is defined as the address bit size of the target |
| 1544 | architecture specific address space that corresponds to AS. |
| 1545 | |
| 1546 | A is adjusted to S bits by zero extending if necessary, and then treating the |
| 1547 | least significant S bits as a twos-complement unsigned value A'. |
| 1548 | |
| 1549 | It pushes a location description L with one memory location description SL |
| 1550 | on the stack. SL specifies the memory location storage that corresponds to |
| 1551 | AS with a bit offset equal to A' scaled by 8 (the byte size). |
| 1552 | |
| 1553 | The DWARF expression is ill-formed if AS is not one of the values defined by |
| 1554 | the target architecture specific ``DW_ASPACE_*`` values. |
| 1555 | |
| 1556 | See :ref:`amdgpu-dwarf-implicit-location-descriptions` for special rules |
| 1557 | concerning implicit pointer values produced by dereferencing implicit |
| 1558 | location descriptions created by the ``DW_OP_implicit_pointer`` and |
| 1559 | ``DW_OP_LLVM_implicit_aspace_pointer`` operations. |
| 1560 | |
| 1561 | 4. ``DW_OP_form_tls_address`` |
| 1562 | |
| 1563 | ``DW_OP_form_tls_address`` pops one stack entry that must be an integral |
| 1564 | type value and treats it as a thread-local storage address T. |
| 1565 | |
| 1566 | It pushes a location description L with one memory location description SL |
| 1567 | on the stack. SL is the target architecture specific memory location |
| 1568 | description that corresponds to the thread-local storage address T. |
| 1569 | |
| 1570 | The meaning of the thread-local storage address T is defined by the run-time |
| 1571 | environment. If the run-time environment supports multiple thread-local |
| 1572 | storage blocks for a single thread, then the block corresponding to the |
| 1573 | executable or shared library containing this DWARF expression is used. |
| 1574 | |
| 1575 | *Some implementations of C, C++, Fortran, and other languages support a |
| 1576 | thread-local storage class. Variables with this storage class have distinct |
| 1577 | values and addresses in distinct threads, much as automatic variables have |
| 1578 | distinct values and addresses in each subprogram invocation. Typically, |
| 1579 | there is a single block of storage containing all thread-local variables |
| 1580 | declared in the main executable, and a separate block for the variables |
| 1581 | declared in each shared library. Each thread-local variable can then be |
| 1582 | accessed in its block using an identifier. This identifier is typically a |
| 1583 | byte offset into the block and pushed onto the DWARF stack by one of the* |
| 1584 | ``DW_OP_const*`` *operations prior to the* ``DW_OP_form_tls_address`` |
| 1585 | *operation. Computing the address of the appropriate block can be complex |
| 1586 | (in some cases, the compiler emits a function call to do it), and difficult |
| 1587 | to describe using ordinary DWARF location descriptions. Instead of forcing |
| 1588 | complex thread-local storage calculations into the DWARF expressions, the* |
| 1589 | ``DW_OP_form_tls_address`` *allows the consumer to perform the computation |
| 1590 | based on the target architecture specific run-time environment.* |
| 1591 | |
| 1592 | 5. ``DW_OP_call_frame_cfa`` |
| 1593 | |
| 1594 | ``DW_OP_call_frame_cfa`` pushes the location description L of the Canonical |
| 1595 | Frame Address (CFA) of the current subprogram, obtained from the Call Frame |
| 1596 | Information on the stack. See :ref:`amdgpu-dwarf-call-frame-information`. |
| 1597 | |
| 1598 | *Although the value of the* ``DW_AT_frame_base`` *attribute of the debugger |
| 1599 | information entry corresponding to the current subprogram can be computed |
| 1600 | using a location list expression, in some cases this would require an |
| 1601 | extensive location list because the values of the registers used in |
| 1602 | computing the CFA change during a subprogram execution. If the Call Frame |
| 1603 | Information is present, then it already encodes such changes, and it is |
| 1604 | space efficient to reference that using the* ``DW_OP_call_frame_cfa`` |
| 1605 | *operation.* |
| 1606 | |
| 1607 | 6. ``DW_OP_fbreg`` |
| 1608 | |
| 1609 | ``DW_OP_fbreg`` has a single signed LEB128 integer operand that represents a |
| 1610 | byte displacement B. |
| 1611 | |
| 1612 | The location description L for the *frame base* of the current subprogram is |
| 1613 | obtained from the ``DW_AT_frame_base`` attribute of the debugger information |
| 1614 | entry corresponding to the current subprogram as described in |
| 1615 | :ref:`amdgpu-dwarf-debugging-information-entry-attributes`. |
| 1616 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 1617 | The location description L is updated as if the ``DW_OP_LLVM_offset_uconst |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 1618 | B`` operation was applied. The updated L is pushed on the stack. |
| 1619 | |
| 1620 | 7. ``DW_OP_breg0``, ``DW_OP_breg1``, ..., ``DW_OP_breg31`` |
| 1621 | |
| 1622 | The ``DW_OP_breg<N>`` operations encode the numbers of up to 32 registers, |
| 1623 | numbered from 0 through 31, inclusive. The register number R corresponds to |
| 1624 | the N in the operation name. |
| 1625 | |
| 1626 | They have a single signed LEB128 integer operand that represents a byte |
| 1627 | displacement B. |
| 1628 | |
| 1629 | The address space identifier AS is defined as the one corresponding to the |
| 1630 | target architecture specific default address space. |
| 1631 | |
| 1632 | The address size S is defined as the address bit size of the target |
| 1633 | architecture specific address space corresponding to AS. |
| 1634 | |
| 1635 | The contents of the register specified by R are retrieved as a |
| 1636 | twos-complement unsigned value and zero extended to S bits. B is added and |
| 1637 | the least significant S bits are treated as a twos-complement unsigned value |
| 1638 | to be used as an address A. |
| 1639 | |
| 1640 | They push a location description L comprising one memory location |
| 1641 | description LS on the stack. LS specifies the memory location storage that |
| 1642 | corresponds to AS with a bit offset equal to A scaled by 8 (the byte size). |
| 1643 | |
| 1644 | 8. ``DW_OP_bregx`` |
| 1645 | |
| 1646 | ``DW_OP_bregx`` has two operands. The first is an unsigned LEB128 integer |
| 1647 | that represents a register number R. The second is a signed LEB128 |
| 1648 | integer that represents a byte displacement B. |
| 1649 | |
| 1650 | The action is the same as for ``DW_OP_breg<N>`` except that R is used as the |
| 1651 | register number and B is used as the byte displacement. |
| 1652 | |
| 1653 | 9. ``DW_OP_LLVM_aspace_bregx`` *New* |
| 1654 | |
| 1655 | ``DW_OP_LLVM_aspace_bregx`` has two operands. The first is an unsigned |
| 1656 | LEB128 integer that represents a register number R. The second is a signed |
| 1657 | LEB128 integer that represents a byte displacement B. It pops one stack |
| 1658 | entry that is required to be an integral type value that represents a target |
| 1659 | architecture specific address space identifier AS. |
| 1660 | |
| 1661 | The action is the same as for ``DW_OP_breg<N>`` except that R is used as the |
| 1662 | register number, B is used as the byte displacement, and AS is used as the |
| 1663 | address space identifier. |
| 1664 | |
| 1665 | The DWARF expression is ill-formed if AS is not one of the values defined by |
| 1666 | the target architecture specific ``DW_ASPACE_*`` values. |
| 1667 | |
| 1668 | .. note:: |
| 1669 | |
| 1670 | Could also consider adding ``DW_OP_aspace_breg0, DW_OP_aspace_breg1, ..., |
| 1671 | DW_OP_aspace_bref31`` which would save encoding size. |
| 1672 | |
| 1673 | .. _amdgpu-dwarf-register-location-descriptions: |
| 1674 | |
| 1675 | Register Location Description Operations |
| 1676 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1677 | |
| 1678 | There is a register location storage that corresponds to each of the target |
| 1679 | architecture registers. The size of each register location storage corresponds |
| 1680 | to the size of the corresponding target architecture register. |
| 1681 | |
| 1682 | A register location description specifies a register location storage. The bit |
| 1683 | offset corresponds to a bit position within the register. Bits accessed using a |
| 1684 | register location description access the corresponding target architecture |
| 1685 | register starting at the specified bit offset. |
| 1686 | |
| 1687 | 1. ``DW_OP_reg0``, ``DW_OP_reg1``, ..., ``DW_OP_reg31`` |
| 1688 | |
| 1689 | ``DW_OP_reg<N>`` operations encode the numbers of up to 32 registers, |
| 1690 | numbered from 0 through 31, inclusive. The target architecture register |
| 1691 | number R corresponds to the N in the operation name. |
| 1692 | |
| 1693 | They push a location description L that specifies one register location |
| 1694 | description SL on the stack. SL specifies the register location storage that |
| 1695 | corresponds to R with a bit offset of 0. |
| 1696 | |
| 1697 | 2. ``DW_OP_regx`` |
| 1698 | |
| 1699 | ``DW_OP_regx`` has a single unsigned LEB128 integer operand that represents |
| 1700 | a target architecture register number R. |
| 1701 | |
| 1702 | It pushes a location description L that specifies one register location |
| 1703 | description SL on the stack. SL specifies the register location storage that |
| 1704 | corresponds to R with a bit offset of 0. |
| 1705 | |
| 1706 | *These operations obtain a register location. To fetch the contents of a |
| 1707 | register, it is necessary to use* ``DW_OP_regval_type``\ *, use one of the* |
| 1708 | ``DW_OP_breg*`` *register-based addressing operations, or use* ``DW_OP_deref*`` |
| 1709 | *on a register location description.* |
| 1710 | |
| 1711 | .. _amdgpu-dwarf-implicit-location-descriptions: |
| 1712 | |
| 1713 | Implicit Location Description Operations |
| 1714 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1715 | |
| 1716 | Implicit location storage represents a piece or all of an object which has no |
| 1717 | actual location in the program but whose contents are nonetheless known, either |
| 1718 | as a constant or can be computed from other locations and values in the program. |
| 1719 | |
| 1720 | An implicit location description specifies an implicit location storage. The bit |
| 1721 | offset corresponds to a bit position within the implicit location storage. Bits |
| 1722 | accessed using an implicit location description, access the corresponding |
| 1723 | implicit storage value starting at the bit offset. |
| 1724 | |
| 1725 | 1. ``DW_OP_implicit_value`` |
| 1726 | |
| 1727 | ``DW_OP_implicit_value`` has two operands. The first is an unsigned LEB128 |
| 1728 | integer that represents a byte size S. The second is a block of bytes with a |
| 1729 | length equal to S treated as a literal value V. |
| 1730 | |
| 1731 | An implicit location storage LS is created with the literal value V and a |
| 1732 | size of S. |
| 1733 | |
| 1734 | It pushes location description L with one implicit location description SL |
| 1735 | on the stack. SL specifies LS with a bit offset of 0. |
| 1736 | |
| 1737 | 2. ``DW_OP_stack_value`` |
| 1738 | |
| 1739 | ``DW_OP_stack_value`` pops one stack entry that must be a value V. |
| 1740 | |
| 1741 | An implicit location storage LS is created with the literal value V and a |
| 1742 | size equal to V's base type size. |
| 1743 | |
| 1744 | It pushes a location description L with one implicit location description SL |
| 1745 | on the stack. SL specifies LS with a bit offset of 0. |
| 1746 | |
| 1747 | *The* ``DW_OP_stack_value`` *operation specifies that the object does not |
| 1748 | exist in memory, but its value is nonetheless known. In this form, the |
| 1749 | location description specifies the actual value of the object, rather than |
| 1750 | specifying the memory or register storage that holds the value.* |
| 1751 | |
| 1752 | See :ref:`amdgpu-dwarf-implicit-location-descriptions` for special rules |
| 1753 | concerning implicit pointer values produced by dereferencing implicit |
| 1754 | location descriptions created by the ``DW_OP_implicit_pointer`` and |
| 1755 | ``DW_OP_LLVM_implicit_aspace_pointer`` operations. |
| 1756 | |
| 1757 | .. note:: |
| 1758 | |
| 1759 | Since location descriptions are allowed on the stack, the |
| 1760 | ``DW_OP_stack_value`` operation no longer terminates the DWARF operation |
| 1761 | expression execution as in DWARF Version 5. |
| 1762 | |
| 1763 | 3. ``DW_OP_implicit_pointer`` |
| 1764 | |
| 1765 | *An optimizing compiler may eliminate a pointer, while still retaining the |
| 1766 | value that the pointer addressed.* ``DW_OP_implicit_pointer`` *allows a |
| 1767 | producer to describe this value.* |
| 1768 | |
| 1769 | ``DW_OP_implicit_pointer`` *specifies an object is a pointer to the target |
| 1770 | architecture default address space that cannot be represented as a real |
| 1771 | pointer, even though the value it would point to can be described. In this |
| 1772 | form, the location description specifies a debugging information entry that |
| 1773 | represents the actual location description of the object to which the |
| 1774 | pointer would point. Thus, a consumer of the debug information would be able |
| 1775 | to access the dereferenced pointer, even when it cannot access the pointer |
| 1776 | itself.* |
| 1777 | |
| 1778 | ``DW_OP_implicit_pointer`` has two operands. The first is a 4-byte unsigned |
| 1779 | value in the 32-bit DWARF format, or an 8-byte unsigned value in the 64-bit |
| 1780 | DWARF format, that represents a debugging information entry reference R. The |
| 1781 | second is a signed LEB128 integer that represents a byte displacement B. |
| 1782 | |
| 1783 | R is used as the offset of a debugging information entry D in a |
| 1784 | ``.debug_info`` section, which may be contained in an executable or shared |
| 1785 | object file other than that containing the operation. For references from one |
| 1786 | executable or shared object file to another, the relocation must be |
| 1787 | performed by the consumer. |
| 1788 | |
| 1789 | *The first operand interpretation is exactly like that for* |
| 1790 | ``DW_FORM_ref_addr``\ *.* |
| 1791 | |
| 1792 | The address space identifier AS is defined as the one corresponding to the |
| 1793 | target architecture specific default address space. |
| 1794 | |
| 1795 | The address size S is defined as the address bit size of the target |
| 1796 | architecture specific address space corresponding to AS. |
| 1797 | |
| 1798 | An implicit location storage LS is created with the debugging information |
| 1799 | entry D, address space AS, and size of S. |
| 1800 | |
| 1801 | It pushes a location description L that comprises one implicit location |
| 1802 | description SL on the stack. SL specifies LS with a bit offset of 0. |
| 1803 | |
| 1804 | If a ``DW_OP_deref*`` operation pops a location description L', and |
| 1805 | retrieves S bits where both: |
| 1806 | |
| 1807 | 1. All retrieved bits come from an implicit location description that |
| 1808 | refers to an implicit location storage that is the same as LS. |
| 1809 | |
| 1810 | *Note that all bits do not have to come from the same implicit location |
| 1811 | description, as L' may involve composite location descriptors.* |
| 1812 | |
| 1813 | 2. The bits come from consecutive ascending offsets within their respective |
| 1814 | implicit location storage. |
| 1815 | |
| 1816 | *These rules are equivalent to retrieving the complete contents of LS.* |
| 1817 | |
| 1818 | Then the value V pushed by the ``DW_OP_deref*`` operation is an implicit |
| 1819 | pointer value IPV with a target architecture specific address space of AS, a |
| 1820 | debugging information entry of D, and a base type of T. If AS is the target |
| 1821 | architecture default address space, then T is the generic type. Otherwise, T |
| 1822 | is a target architecture specific integral type with a bit size equal to S. |
| 1823 | |
| 1824 | Otherwise, if a ``DW_OP_deref*`` operation is applied to a location |
| 1825 | description such that some retrieved bits come from an implicit location |
| 1826 | storage that is the same as LS, then the DWARF expression is ill-formed. |
| 1827 | |
| 1828 | If IPV is either implicitly converted to a location description (only done |
| 1829 | if AS is the target architecture default address space) or used by |
| 1830 | ``DW_OP_LLVM_form_aspace_address`` (only done if the address space specified |
| 1831 | is AS), then the resulting location description RL is: |
| 1832 | |
| 1833 | * If D has a ``DW_AT_location`` attribute, the DWARF expression E from the |
| 1834 | ``DW_AT_location`` attribute is evaluated as a location description. The |
| 1835 | current subprogram and current program location of the evaluation context |
| 1836 | that is accessing IPV is used for the evaluation context of E, together |
| 1837 | with an empty initial stack. RL is the expression result. |
| 1838 | |
| 1839 | * If D has a ``DW_AT_const_value`` attribute, then an implicit location |
| 1840 | storage RLS is created from the ``DW_AT_const_value`` attribute's value |
| 1841 | with a size matching the size of the ``DW_AT_const_value`` attribute's |
| 1842 | value. RL comprises one implicit location description SRL. SRL specifies |
| 1843 | RLS with a bit offset of 0. |
| 1844 | |
| 1845 | .. note:: |
| 1846 | |
| 1847 | If using ``DW_AT_const_value`` for variables and formal parameters is |
| 1848 | deprecated and instead ``DW_AT_location`` is used with an implicit |
| 1849 | location description, then this rule would not be required. |
| 1850 | |
| 1851 | * Otherwise the DWARF expression is ill-formed. |
| 1852 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 1853 | The bit offset of RL is updated as if the ``DW_OP_LLVM_offset_uconst B`` |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 1854 | operation was applied. |
| 1855 | |
| 1856 | If a ``DW_OP_stack_value`` operation pops a value that is the same as IPV, |
| 1857 | then it pushes a location description that is the same as L. |
| 1858 | |
| 1859 | The DWARF expression is ill-formed if it accesses LS or IPV in any other |
| 1860 | manner. |
| 1861 | |
| 1862 | *The restrictions on how an implicit pointer location description created |
| 1863 | by* ``DW_OP_implicit_pointer`` *and* ``DW_OP_LLVM_aspace_implicit_pointer`` |
| 1864 | *can be used are to simplify the DWARF consumer. Similarly, for an implicit |
| 1865 | pointer value created by* ``DW_OP_deref*`` *and* ``DW_OP_stack_value``\ .* |
| 1866 | |
| 1867 | 4. ``DW_OP_LLVM_aspace_implicit_pointer`` *New* |
| 1868 | |
| 1869 | ``DW_OP_LLVM_aspace_implicit_pointer`` has two operands that are the same as |
| 1870 | for ``DW_OP_implicit_pointer``. |
| 1871 | |
| 1872 | It pops one stack entry that must be an integral type value that represents |
| 1873 | a target architecture specific address space identifier AS. |
| 1874 | |
| 1875 | The location description L that is pushed on the stack is the same as for |
| 1876 | ``DW_OP_implicit_pointer`` except that the address space identifier used is |
| 1877 | AS. |
| 1878 | |
| 1879 | The DWARF expression is ill-formed if AS is not one of the values defined by |
| 1880 | the target architecture specific ``DW_ASPACE_*`` values. |
| 1881 | |
| 1882 | *Typically a* ``DW_OP_implicit_pointer`` *or* |
| 1883 | ``DW_OP_LLVM_aspace_implicit_pointer`` *operation is used in a DWARF expression |
| 1884 | E*\ :sub:`1` *of a* ``DW_TAG_variable`` *or* ``DW_TAG_formal_parameter`` |
| 1885 | *debugging information entry D*\ :sub:`1`\ *'s* ``DW_AT_location`` *attribute. |
| 1886 | The debugging information entry referenced by the* ``DW_OP_implicit_pointer`` |
| 1887 | *or* ``DW_OP_LLVM_aspace_implicit_pointer`` *operations is typically itself a* |
| 1888 | ``DW_TAG_variable`` *or* ``DW_TAG_formal_parameter`` *debugging information |
| 1889 | entry D*\ :sub:`2` *whose* ``DW_AT_location`` *attribute gives a second DWARF |
| 1890 | expression E*\ :sub:`2`\ *.* |
| 1891 | |
| 1892 | *D*\ :sub:`1` *and E*\ :sub:`1` *are describing the location of a pointer type |
| 1893 | object. D*\ :sub:`2` *and E*\ :sub:`2` *are describing the location of the |
| 1894 | object pointed to by that pointer object.* |
| 1895 | |
| 1896 | *However, D*\ :sub:`2` *may be any debugging information entry that contains a* |
| 1897 | ``DW_AT_location`` *or* ``DW_AT_const_value`` *attribute (for example,* |
| 1898 | ``DW_TAG_dwarf_procedure``\ *). By using E*\ :sub:`2`\ *, a consumer can |
| 1899 | reconstruct the value of the object when asked to dereference the pointer |
| 1900 | described by E*\ :sub:`1` *which contains the* ``DW_OP_implicit_pointer`` or |
| 1901 | ``DW_OP_LLVM_aspace_implicit_pointer`` *operation.* |
| 1902 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 1903 | .. _amdgpu-dwarf-composite-location-description-operations: |
| 1904 | |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 1905 | Composite Location Description Operations |
| 1906 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1907 | |
| 1908 | A composite location storage represents an object or value which may be |
| 1909 | contained in part of another location storage or contained in parts of more |
| 1910 | than one location storage. |
| 1911 | |
| 1912 | Each part has a part location description L and a part bit size S. L can have |
| 1913 | one or more single location descriptions SL. If there are more than one SL then |
| 1914 | that indicates that part is located in more than one place. The bits of each |
| 1915 | place of the part comprise S contiguous bits from the location storage LS |
| 1916 | specified by SL starting at the bit offset specified by SL. All the bits must |
| 1917 | be within the size of LS or the DWARF expression is ill-formed. |
| 1918 | |
| 1919 | A composite location storage can have zero or more parts. The parts are |
| 1920 | contiguous such that the zero-based location storage bit index will range over |
| 1921 | each part with no gaps between them. Therefore, the size of a composite location |
| 1922 | storage is the sum of the size of its parts. The DWARF expression is ill-formed |
| 1923 | if the size of the contiguous location storage is larger than the size of the |
| 1924 | memory location storage corresponding to the largest target architecture |
| 1925 | specific address space. |
| 1926 | |
| 1927 | A composite location description specifies a composite location storage. The bit |
| 1928 | offset corresponds to a bit position within the composite location storage. |
| 1929 | |
| 1930 | There are operations that create a composite location storage. |
| 1931 | |
| 1932 | There are other operations that allow a composite location storage to be |
| 1933 | incrementally created. Each part is created by a separate operation. There may |
| 1934 | be one or more operations to create the final composite location storage. A |
| 1935 | series of such operations describes the parts of the composite location storage |
| 1936 | that are in the order that the associated part operations are executed. |
| 1937 | |
| 1938 | To support incremental creation, a composite location storage can be in an |
| 1939 | incomplete state. When an incremental operation operates on an incomplete |
| 1940 | composite location storage, it adds a new part, otherwise it creates a new |
| 1941 | composite location storage. The ``DW_OP_LLVM_piece_end`` operation explicitly |
| 1942 | makes an incomplete composite location storage complete. |
| 1943 | |
| 1944 | A composite location description that specifies a composite location storage |
| 1945 | that is incomplete is termed an incomplete composite location description. A |
| 1946 | composite location description that specifies a composite location storage that |
| 1947 | is complete is termed a complete composite location description. |
| 1948 | |
| 1949 | If the top stack entry is a location description that has one incomplete |
| 1950 | composite location description SL after the execution of an operation expression |
| 1951 | has completed, SL is converted to a complete composite location description. |
| 1952 | |
| 1953 | *Note that this conversion does not happen after the completion of an operation |
| 1954 | expression that is evaluated on the same stack by the* ``DW_OP_call*`` |
| 1955 | *operations. Such executions are not a separate evaluation of an operation |
| 1956 | expression, but rather the continued evaluation of the same operation expression |
| 1957 | that contains the* ``DW_OP_call*`` *operation.* |
| 1958 | |
| 1959 | If a stack entry is required to be a location description L, but L has an |
| 1960 | incomplete composite location description, then the DWARF expression is |
| 1961 | ill-formed. The exception is for the operations involved in incrementally |
| 1962 | creating a composite location description as described below. |
| 1963 | |
| 1964 | *Note that a DWARF operation expression may arbitrarily compose composite |
| 1965 | location descriptions from any other location description, including those that |
| 1966 | have multiple single location descriptions, and those that have composite |
| 1967 | location descriptions.* |
| 1968 | |
| 1969 | *The incremental composite location description operations are defined to be |
| 1970 | compatible with the definitions in DWARF Version 5.* |
| 1971 | |
| 1972 | 1. ``DW_OP_piece`` |
| 1973 | |
| 1974 | ``DW_OP_piece`` has a single unsigned LEB128 integer that represents a byte |
| 1975 | size S. |
| 1976 | |
| 1977 | The action is based on the context: |
| 1978 | |
| 1979 | * If the stack is empty, then a location description L comprised of one |
| 1980 | incomplete composite location description SL is pushed on the stack. |
| 1981 | |
| 1982 | An incomplete composite location storage LS is created with a single part |
| 1983 | P. P specifies a location description PL and has a bit size of S scaled by |
| 1984 | 8 (the byte size). PL is comprised of one undefined location description |
| 1985 | PSL. |
| 1986 | |
| 1987 | SL specifies LS with a bit offset of 0. |
| 1988 | |
| 1989 | * Otherwise, if the top stack entry is a location description L comprised of |
| 1990 | one incomplete composite location description SL, then the incomplete |
| 1991 | composite location storage LS that SL specifies is updated to append a new |
| 1992 | part P. P specifies a location description PL and has a bit size of S |
| 1993 | scaled by 8 (the byte size). PL is comprised of one undefined location |
| 1994 | description PSL. L is left on the stack. |
| 1995 | |
| 1996 | * Otherwise, if the top stack entry is a location description or can be |
| 1997 | converted to one, then it is popped and treated as a part location |
| 1998 | description PL. Then: |
| 1999 | |
| 2000 | * If the top stack entry (after popping PL) is a location description L |
| 2001 | comprised of one incomplete composite location description SL, then the |
| 2002 | incomplete composite location storage LS that SL specifies is updated to |
| 2003 | append a new part P. P specifies the location description PL and has a |
| 2004 | bit size of S scaled by 8 (the byte size). L is left on the stack. |
| 2005 | |
| 2006 | * Otherwise, a location description L comprised of one incomplete |
| 2007 | composite location description SL is pushed on the stack. |
| 2008 | |
| 2009 | An incomplete composite location storage LS is created with a single |
| 2010 | part P. P specifies the location description PL and has a bit size of S |
| 2011 | scaled by 8 (the byte size). |
| 2012 | |
| 2013 | SL specifies LS with a bit offset of 0. |
| 2014 | |
| 2015 | * Otherwise, the DWARF expression is ill-formed |
| 2016 | |
| 2017 | *Many compilers store a single variable in sets of registers or store a |
| 2018 | variable partially in memory and partially in registers.* ``DW_OP_piece`` |
| 2019 | *provides a way of describing where a part of a variable is located.* |
| 2020 | |
| 2021 | *If a non-0 byte displacement is required, the* ``DW_OP_LLVM_offset`` |
| 2022 | *operation can be used to update the location description before using it as |
| 2023 | the part location description of a* ``DW_OP_piece`` *operation.* |
| 2024 | |
| 2025 | *The evaluation rules for the* ``DW_OP_piece`` *operation allow it to be |
| 2026 | compatible with the DWARF Version 5 definition.* |
| 2027 | |
| 2028 | .. note:: |
| 2029 | |
| 2030 | Since this proposal allows location descriptions to be entries on the |
| 2031 | stack, a simpler operation to create composite location descriptions. For |
| 2032 | example, just one operation that specifies how many parts, and pops pairs |
| 2033 | of stack entries for the part size and location description. Not only |
| 2034 | would this be a simpler operation and avoid the complexities of incomplete |
| 2035 | composite location descriptions, but it may also have a smaller encoding |
| 2036 | in practice. However, the desire for compatibility with DWARF Version 5 is |
| 2037 | likely a stronger consideration. |
| 2038 | |
| 2039 | 2. ``DW_OP_bit_piece`` |
| 2040 | |
| 2041 | ``DW_OP_bit_piece`` has two operands. The first is an unsigned LEB128 |
| 2042 | integer that represents the part bit size S. The second is an unsigned |
| 2043 | LEB128 integer that represents a bit displacement B. |
| 2044 | |
| 2045 | The action is the same as for ``DW_OP_piece`` except that any part created |
| 2046 | has the bit size S, and the location description PL of any created part is |
| 2047 | updated as if the ``DW_OP_constu B; DW_OP_LLVM_bit_offset`` operations were |
| 2048 | applied. |
| 2049 | |
| 2050 | ``DW_OP_bit_piece`` *is used instead of* ``DW_OP_piece`` *when the piece to |
| 2051 | be assembled is not byte-sized or is not at the start of the part location |
| 2052 | description.* |
| 2053 | |
| 2054 | *If a computed bit displacement is required, the* ``DW_OP_LLVM_bit_offset`` |
| 2055 | *operation can be used to update the location description before using it as |
| 2056 | the part location description of a* ``DW_OP_bit_piece`` *operation.* |
| 2057 | |
| 2058 | .. note:: |
| 2059 | |
| 2060 | The bit offset operand is not needed as ``DW_OP_LLVM_bit_offset`` can be |
| 2061 | used on the part's location description. |
| 2062 | |
| 2063 | 3. ``DW_OP_LLVM_piece_end`` *New* |
| 2064 | |
| 2065 | If the top stack entry is not a location description L comprised of one |
| 2066 | incomplete composite location description SL, then the DWARF expression is |
| 2067 | ill-formed. |
| 2068 | |
| 2069 | Otherwise, the incomplete composite location storage LS specified by SL is |
| 2070 | updated to be a complete composite location description with the same parts. |
| 2071 | |
| 2072 | 4. ``DW_OP_LLVM_extend`` *New* |
| 2073 | |
| 2074 | ``DW_OP_LLVM_extend`` has two operands. The first is an unsigned LEB128 |
| 2075 | integer that represents the element bit size S. The second is an unsigned |
| 2076 | LEB128 integer that represents a count C. |
| 2077 | |
| 2078 | It pops one stack entry that must be a location description and is treated |
| 2079 | as the part location description PL. |
| 2080 | |
| 2081 | A location description L comprised of one complete composite location |
| 2082 | description SL is pushed on the stack. |
| 2083 | |
| 2084 | A complete composite location storage LS is created with C identical parts |
| 2085 | P. Each P specifies PL and has a bit size of S. |
| 2086 | |
| 2087 | SL specifies LS with a bit offset of 0. |
| 2088 | |
| 2089 | The DWARF expression is ill-formed if the element bit size or count are 0. |
| 2090 | |
| 2091 | 5. ``DW_OP_LLVM_select_bit_piece`` *New* |
| 2092 | |
| 2093 | ``DW_OP_LLVM_select_bit_piece`` has two operands. The first is an unsigned |
| 2094 | LEB128 integer that represents the element bit size S. The second is an |
| 2095 | unsigned LEB128 integer that represents a count C. |
| 2096 | |
| 2097 | It pops three stack entries. The first must be an integral type value that |
| 2098 | represents a bit mask value M. The second must be a location description |
| 2099 | that represents the one-location description L1. The third must be a |
| 2100 | location description that represents the zero-location description L0. |
| 2101 | |
| 2102 | A complete composite location storage LS is created with C parts P\ :sub:`N` |
| 2103 | ordered in ascending N from 0 to C-1 inclusive. Each P\ :sub:`N` specifies |
| 2104 | location description PL\ :sub:`N` and has a bit size of S. |
| 2105 | |
| 2106 | PL\ :sub:`N` is as if the ``DW_OP_LLVM_bit_offset N*S`` operation was |
| 2107 | applied to PLX\ :sub:`N`\ . |
| 2108 | |
| 2109 | PLX\ :sub:`N` is the same as L0 if the N\ :sup:`th` least significant bit of |
| 2110 | M is a zero, otherwise it is the same as L1. |
| 2111 | |
| 2112 | A location description L comprised of one complete composite location |
| 2113 | description SL is pushed on the stack. SL specifies LS with a bit offset of |
| 2114 | 0. |
| 2115 | |
| 2116 | The DWARF expression is ill-formed if S or C are 0, or if the bit size of M |
| 2117 | is less than C. |
| 2118 | |
| 2119 | .. _amdgpu-dwarf-location-list-expressions: |
| 2120 | |
| 2121 | DWARF Location List Expressions |
| 2122 | +++++++++++++++++++++++++++++++ |
| 2123 | |
| 2124 | *To meet the needs of recent computer architectures and optimization techniques, |
| 2125 | debugging information must be able to describe the location of an object whose |
| 2126 | location changes over the object’s lifetime, and may reside at multiple |
| 2127 | locations during parts of an object's lifetime. Location list expressions are |
| 2128 | used in place of operation expressions whenever the object whose location is |
| 2129 | being described has these requirements.* |
| 2130 | |
| 2131 | A location list expression consists of a series of location list entries. Each |
| 2132 | location list entry is one of the following kinds: |
| 2133 | |
| 2134 | *Bounded location description* |
| 2135 | |
| 2136 | This kind of location list entry provides an operation expression that |
| 2137 | evaluates to the location description of an object that is valid over a |
| 2138 | lifetime bounded by a starting and ending address. The starting address is the |
| 2139 | lowest address of the address range over which the location is valid. The |
| 2140 | ending address is the address of the first location past the highest address |
| 2141 | of the address range. |
| 2142 | |
| 2143 | The location list entry matches when the current program location is within |
| 2144 | the given range. |
| 2145 | |
| 2146 | There are several kinds of bounded location description entries which differ |
| 2147 | in the way that they specify the starting and ending addresses. |
| 2148 | |
| 2149 | *Default location description* |
| 2150 | |
| 2151 | This kind of location list entry provides an operation expression that |
| 2152 | evaluates to the location description of an object that is valid when no |
| 2153 | bounded location description entry applies. |
| 2154 | |
| 2155 | The location list entry matches when the current program location is not |
| 2156 | within the range of any bounded location description entry. |
| 2157 | |
| 2158 | *Base address* |
| 2159 | |
| 2160 | This kind of location list entry provides an address to be used as the base |
| 2161 | address for beginning and ending address offsets given in certain kinds of |
| 2162 | bounded location description entries. The applicable base address of a bounded |
| 2163 | location description entry is the address specified by the closest preceding |
| 2164 | base address entry in the same location list. If there is no preceding base |
| 2165 | address entry, then the applicable base address defaults to the base address |
| 2166 | of the compilation unit (see DWARF Version 5 section 3.1.1). |
| 2167 | |
| 2168 | In the case of a compilation unit where all of the machine code is contained |
| 2169 | in a single contiguous section, no base address entry is needed. |
| 2170 | |
| 2171 | *End-of-list* |
| 2172 | |
| 2173 | This kind of location list entry marks the end of the location list |
| 2174 | expression. |
| 2175 | |
| 2176 | The address ranges defined by the bounded location description entries of a |
| 2177 | location list expression may overlap. When they do, they describe a situation in |
| 2178 | which an object exists simultaneously in more than one place. |
| 2179 | |
| 2180 | If all of the address ranges in a given location list expression do not |
| 2181 | collectively cover the entire range over which the object in question is |
| 2182 | defined, and there is no following default location description entry, it is |
| 2183 | assumed that the object is not available for the portion of the range that is |
| 2184 | not covered. |
| 2185 | |
| 2186 | The operation expression of each matching location list entry is evaluated as a |
| 2187 | location description and its result is returned as the result of the location |
| 2188 | list entry. The operation expression is evaluated with the same context as the |
| 2189 | location list expression, including the same current frame, current program |
| 2190 | location, and initial stack. |
| 2191 | |
| 2192 | The result of the evaluation of a DWARF location list expression is a location |
| 2193 | description that is comprised of the union of the single location descriptions |
| 2194 | of the location description result of each matching location list entry. If |
| 2195 | there are no matching location list entries, then the result is a location |
| 2196 | description that comprises one undefined location description. |
| 2197 | |
| 2198 | A location list expression can only be used as the value of a debugger |
| 2199 | information entry attribute that is encoded using class ``loclist`` or |
| 2200 | ``loclistsptr`` (see DWARF Version 5 section 7.5.5). The value of the attribute |
| 2201 | provides an index into a separate object file section called ``.debug_loclists`` |
| 2202 | or ``.debug_loclists.dwo`` (for split DWARF object files) that contains the |
| 2203 | location list entries. |
| 2204 | |
| 2205 | A ``DW_OP_call*`` and ``DW_OP_implicit_pointer`` operation can be used to |
| 2206 | specify a debugger information entry attribute that has a location list |
| 2207 | expression. Several debugger information entry attributes allow DWARF |
| 2208 | expressions that are evaluated with an initial stack that includes a location |
| 2209 | description that may originate from the evaluation of a location list |
| 2210 | expression. |
| 2211 | |
| 2212 | *This location list representation, the* ``loclist`` *and* ``loclistsptr`` |
| 2213 | *class, and the related* ``DW_AT_loclists_base`` *attribute are new in DWARF |
| 2214 | Version 5. Together they eliminate most, or all of the code object relocations |
| 2215 | previously needed for location list expressions.* |
| 2216 | |
| 2217 | .. note:: |
| 2218 | |
| 2219 | The rest of this section is the same as DWARF Version 5 section 2.6.2. |
| 2220 | |
| 2221 | .. _amdgpu-dwarf-segment_addresses: |
| 2222 | |
| 2223 | Segmented Addresses |
| 2224 | ~~~~~~~~~~~~~~~~~~~ |
| 2225 | |
| 2226 | .. note:: |
| 2227 | |
| 2228 | This augments DWARF Version 5 section 2.12. |
| 2229 | |
| 2230 | DWARF address classes are used for source languages that have the concept of |
| 2231 | memory spaces. They are used in the ``DW_AT_address_class`` attribute for |
| 2232 | pointer type, reference type, subprogram, and subprogram type debugger |
| 2233 | information entries. |
| 2234 | |
| 2235 | Each DWARF address class is conceptually a separate source language memory space |
| 2236 | with its own lifetime and aliasing rules. DWARF address classes are used to |
| 2237 | specify the source language memory spaces that pointer type and reference type |
| 2238 | values refer, and to specify the source language memory space in which variables |
| 2239 | are allocated. |
| 2240 | |
| 2241 | The set of currently defined source language DWARF address classes, together |
| 2242 | with source language mappings, is given in |
| 2243 | :ref:`amdgpu-dwarf-address-class-table`. |
| 2244 | |
| 2245 | Vendor defined source language address classes may be defined using codes in the |
| 2246 | range ``DW_ADDR_LLVM_lo_user`` to ``DW_ADDR_LLVM_hi_user``. |
| 2247 | |
| 2248 | .. table:: Address class |
| 2249 | :name: amdgpu-dwarf-address-class-table |
| 2250 | |
| 2251 | ========================= ============ ========= ========= ========= |
| 2252 | Address Class Name Meaning C/C++ OpenCL CUDA/HIP |
| 2253 | ========================= ============ ========= ========= ========= |
| 2254 | ``DW_ADDR_none`` generic *default* generic *default* |
| 2255 | ``DW_ADDR_LLVM_global`` global global |
| 2256 | ``DW_ADDR_LLVM_constant`` constant constant constant |
| 2257 | ``DW_ADDR_LLVM_group`` thread-group local shared |
| 2258 | ``DW_ADDR_LLVM_private`` thread private |
| 2259 | ``DW_ADDR_LLVM_lo_user`` |
| 2260 | ``DW_ADDR_LLVM_hi_user`` |
| 2261 | ========================= ============ ========= ========= ========= |
| 2262 | |
| 2263 | DWARF address spaces correspond to target architecture specific linear |
| 2264 | addressable memory areas. They are used in DWARF expression location |
| 2265 | descriptions to describe in which target architecture specific memory area data |
| 2266 | resides. |
| 2267 | |
| 2268 | *Target architecture specific DWARF address spaces may correspond to hardware |
| 2269 | supported facilities such as memory utilizing base address registers, scratchpad |
| 2270 | memory, and memory with special interleaving. The size of addresses in these |
| 2271 | address spaces may vary. Their access and allocation may be hardware managed |
| 2272 | with each thread or group of threads having access to independent storage. For |
| 2273 | these reasons they may have properties that do not allow them to be viewed as |
| 2274 | part of the unified global virtual address space accessible by all threads.* |
| 2275 | |
| 2276 | *It is target architecture specific whether multiple DWARF address spaces are |
| 2277 | supported and how source language DWARF address classes map to target |
| 2278 | architecture specific DWARF address spaces. A target architecture may map |
| 2279 | multiple source language DWARF address classes to the same target architecture |
| 2280 | specific DWARF address class. Optimization may determine that variable lifetime |
| 2281 | and access pattern allows them to be allocated in faster scratchpad memory |
| 2282 | represented by a different DWARF address space.* |
| 2283 | |
| 2284 | Although DWARF address space identifiers are target architecture specific, |
| 2285 | ``DW_ASPACE_none`` is a common address space supported by all target |
| 2286 | architectures. |
| 2287 | |
| 2288 | DWARF address space identifiers are used by: |
| 2289 | |
| 2290 | * The DWARF expession operations: ``DW_OP_LLVM_aspace_bregx``, |
| 2291 | ``DW_OP_LLVM_form_aspace_address``, ``DW_OP_LLVM_implicit_aspace_pointer``, |
| 2292 | and ``DW_OP_xderef*``. |
| 2293 | |
| 2294 | * The CFI instructions: ``DW_CFA_def_aspace_cfa`` and |
| 2295 | ``DW_CFA_def_aspace_cfa_sf``. |
| 2296 | |
| 2297 | .. note:: |
| 2298 | |
| 2299 | With the definition of DWARF address classes and DWARF address spaces in this |
| 2300 | proposal, DWARF Version 5 table 2.7 needs to be updated. It seems it is an |
| 2301 | example of DWARF address spaces and not DWARF address classes. |
| 2302 | |
| 2303 | .. note:: |
| 2304 | |
| 2305 | With the expanded support for DWARF address spaces in this proposal, it may be |
| 2306 | worth examining if DWARF segments can be eliminated and DWARF address spaces |
| 2307 | used instead. |
| 2308 | |
| 2309 | That may involve extending DWARF address spaces to also be used to specify |
| 2310 | code locations. In target architectures that use different memory areas for |
| 2311 | code and data this would seem a natural use for DWARF address spaces. This |
| 2312 | would allow DWARF expression location descriptions to be used to describe the |
| 2313 | location of subprograms and entry points that are used in expressions |
| 2314 | involving subprogram pointer type values. |
| 2315 | |
| 2316 | Currently, DWARF expressions assume data and code resides in the same default |
| 2317 | DWARF address space, and only the address ranges in DWARF location list |
| 2318 | entries and in the ``.debug_aranges`` section for accelerated access for |
| 2319 | addresses allow DWARF segments to be used to distinguish. |
| 2320 | |
| 2321 | .. note:: |
| 2322 | |
| 2323 | Currently, DWARF defines address class values as being target architecture |
| 2324 | specific. It is unclear how language specific memory spaces are intended to be |
| 2325 | represented in DWARF using these. |
| 2326 | |
| 2327 | For example, OpenCL defines memory spaces (called address spaces in OpenCL) |
| 2328 | for ``global``, ``local``, ``constant``, and ``private``. These are part of |
| 2329 | the type system and are modifiers to pointer types. In addition, OpenCL |
| 2330 | defines ``generic`` pointers that can reference either the ``global``, |
| 2331 | ``local``, or ``private`` memory spaces. To support the OpenCL language the |
| 2332 | debugger would want to support casting pointers between the ``generic`` and |
| 2333 | other memory spaces, querying what memory space a ``generic`` pointer value is |
| 2334 | currently referencing, and possibly using pointer casting to form an address |
| 2335 | for a specific memory space out of an integral value. |
| 2336 | |
| 2337 | The method to use to dereference a pointer type or reference type value is |
| 2338 | defined in DWARF expressions using ``DW_OP_xderef*`` which uses a target |
| 2339 | architecture specific address space. |
| 2340 | |
| 2341 | DWARF defines the ``DW_AT_address_class`` attribute on pointer type and |
| 2342 | reference type debugger information entries. It specifies the method to use to |
| 2343 | dereference them. Why is the value of this not the same as the address space |
| 2344 | value used in ``DW_OP_xderef*``? In both cases it is target architecture |
| 2345 | specific and the architecture presumably will use the same set of methods to |
| 2346 | dereference pointers in both cases. |
| 2347 | |
| 2348 | Since ``DW_AT_address_class`` uses a target architecture specific value, it |
| 2349 | cannot in general capture the source language memory space type modifier |
| 2350 | concept. On some architectures all source language memory space modifiers may |
| 2351 | actually use the same method for dereferencing pointers. |
| 2352 | |
| 2353 | One possibility is for DWARF to add an ``DW_TAG_LLVM_address_class_type`` |
| 2354 | debugger information entry type modifier that can be applied to a pointer type |
| 2355 | and reference type. The ``DW_AT_address_class`` attribute could be re-defined |
| 2356 | to not be target architecture specific and instead define generalized language |
| 2357 | values (as is proposed above for DWARF address classes in the table |
| 2358 | :ref:`amdgpu-dwarf-address-class-table`) that will support OpenCL and other |
| 2359 | languages using memory spaces. The ``DW_AT_address_class`` attribute could be |
| 2360 | defined to not be applied to pointer types or reference types, but instead |
| 2361 | only to the new ``DW_TAG_LLVM_address_class_type`` type modifier debugger |
| 2362 | information entry. |
| 2363 | |
| 2364 | If a pointer type or reference type is not modified by |
| 2365 | ``DW_TAG_LLVM_address_class_type`` or if ``DW_TAG_LLVM_address_class_type`` |
| 2366 | has no ``DW_AT_address_class`` attribute, then the pointer type or reference |
| 2367 | type would be defined to use the ``DW_ADDR_none`` address class as currently. |
| 2368 | Since modifiers can be chained, it would need to be defined if multiple |
| 2369 | ``DW_TAG_LLVM_address_class_type`` modifiers were legal, and if so if the |
| 2370 | outermost one is the one that takes precedence. |
| 2371 | |
| 2372 | A target architecture implementation that supports multiple address spaces |
| 2373 | would need to map ``DW_ADDR_none`` appropriately to support CUDA-like |
| 2374 | languages that have no address classes in the type system but do support |
| 2375 | variable allocation in address classes. Such variable allocation would result |
| 2376 | in the variable's location description needing an address space. |
| 2377 | |
| 2378 | The approach proposed in :ref:`amdgpu-dwarf-address-class-table` is to define |
| 2379 | the default ``DW_ADDR_none`` to be the generic address class and not the |
| 2380 | global address class. This matches how CLANG and LLVM have added support for |
| 2381 | CUDA-like languages on top of existing C++ language support. This allows all |
| 2382 | addresses to be generic by default which matches CUDA-like languages. |
| 2383 | |
| 2384 | An alternative approach is to define ``DW_ADDR_none`` as being the global |
| 2385 | address class and then change ``DW_ADDR_LLVM_global`` to |
| 2386 | ``DW_ADDR_LLVM_generic``. This would match the reality that languages that do |
| 2387 | not support multiple memory spaces only have one default global memory space. |
| 2388 | Generally, in these languages if they expose that the target architecture |
| 2389 | supports multiple address spaces, the default one is still the global memory |
| 2390 | space. Then a language that does support multiple memory spaces has to |
| 2391 | explicitly indicate which pointers have the added ability to reference more |
| 2392 | than the global memory space. However, compilers generating DWARF for |
| 2393 | CUDA-like languages would then have to define every CUDA-like language pointer |
| 2394 | type or reference type using ``DW_TAG_LLVM_address_class_type`` with a |
| 2395 | ``DW_AT_address_class`` attribute of ``DW_ADDR_LLVM_generic`` to match the |
| 2396 | language semantics. |
| 2397 | |
| 2398 | A new ``DW_AT_LLVM_address_space`` attribute could be defined that can be |
| 2399 | applied to pointer type, reference type, subprogram, and subprogram type to |
| 2400 | describe how objects having the given type are dereferenced or called (the |
| 2401 | role that ``DW_AT_address_class`` currently provides). The values of |
| 2402 | ``DW_AT_address_space`` would be target architecture specific and the same as |
| 2403 | used in ``DW_OP_xderef*``. |
| 2404 | |
| 2405 | .. _amdgpu-dwarf-debugging-information-entry-attributes: |
| 2406 | |
| 2407 | Debugging Information Entry Attributes |
| 2408 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2409 | |
| 2410 | .. note:: |
| 2411 | |
| 2412 | This section provides changes to existing debugger information entry |
| 2413 | attributes and defines attributes added by the proposal. These would be |
| 2414 | incorporated into the appropriate DWARF Version 5 chapter 2 sections. |
| 2415 | |
| 2416 | 1. ``DW_AT_location`` |
| 2417 | |
| 2418 | Any debugging information entry describing a data object (which includes |
| 2419 | variables and parameters) or common blocks may have a ``DW_AT_location`` |
| 2420 | attribute, whose value is a DWARF expression E. |
| 2421 | |
| 2422 | The result of the attribute is obtained by evaluating E as a location |
| 2423 | description in the context of the current subprogram, current program |
| 2424 | location, and with an empty initial stack. See |
| 2425 | :ref:`amdgpu-dwarf-expressions`. |
| 2426 | |
| 2427 | See :ref:`amdgpu-dwarf-control-flow-operations` for special evaluation rules |
| 2428 | used by the ``DW_OP_call*`` operations. |
| 2429 | |
| 2430 | .. note:: |
| 2431 | |
| 2432 | Delete the description of how the ``DW_OP_call*`` operations evaluate a |
| 2433 | ``DW_AT_location`` attribute as that is now described in the operations. |
| 2434 | |
| 2435 | .. note:: |
| 2436 | |
| 2437 | See the discussion about the ``DW_AT_location`` attribute in the |
| 2438 | ``DW_OP_call*`` operation. Having each attribute only have a single |
| 2439 | purpose and single execution semantics seems desirable. It makes it easier |
| 2440 | for the consumer that no longer have to track the context. It makes it |
| 2441 | easier for the producer as it can rely on a single semantics for each |
| 2442 | attribute. |
| 2443 | |
| 2444 | For that reason, limiting the ``DW_AT_location`` attribute to only |
| 2445 | supporting evaluating the location description of an object, and using a |
| 2446 | different attribute and encoding class for the evaluation of DWARF |
| 2447 | expression *procedures* on the same operation expression stack seems |
| 2448 | desirable. |
| 2449 | |
| 2450 | 2. ``DW_AT_const_value`` |
| 2451 | |
| 2452 | .. note:: |
| 2453 | |
| 2454 | Could deprecate using the ``DW_AT_const_value`` attribute for |
| 2455 | ``DW_TAG_variable`` or ``DW_TAG_formal_parameter`` debugger information |
| 2456 | entries that have been optimized to a constant. Instead, |
| 2457 | ``DW_AT_location`` could be used with a DWARF expression that produces an |
| 2458 | implicit location description now that any location description can be |
| 2459 | used within a DWARF expression. This allows the ``DW_OP_call*`` operations |
| 2460 | to be used to push the location description of any variable regardless of |
| 2461 | how it is optimized. |
| 2462 | |
| 2463 | 3. ``DW_AT_frame_base`` |
| 2464 | |
| 2465 | A ``DW_TAG_subprogram`` or ``DW_TAG_entry_point`` debugger information entry |
| 2466 | may have a ``DW_AT_frame_base`` attribute, whose value is a DWARF expression |
| 2467 | E. |
| 2468 | |
| 2469 | The result of the attribute is obtained by evaluating E as a location |
| 2470 | description in the context of the current subprogram, current program |
| 2471 | location, and with an empty initial stack. |
| 2472 | |
| 2473 | The DWARF is ill-formed if E contains an ``DW_OP_fbreg`` operation, or the |
| 2474 | resulting location description L is not comprised of one single location |
| 2475 | description SL. |
| 2476 | |
| 2477 | If SL a register location description for register R, then L is replaced |
| 2478 | with the result of evaluating a ``DW_OP_bregx R, 0`` operation. This |
| 2479 | computes the frame base memory location description in the target |
| 2480 | architecture default address space. |
| 2481 | |
| 2482 | *This allows the more compact* ``DW_OPreg*`` *to be used instead of* |
| 2483 | ``DW_OP_breg* 0``\ *.* |
| 2484 | |
| 2485 | .. note:: |
| 2486 | |
| 2487 | This rule could be removed and require the producer to create the required |
| 2488 | location description directly using ``DW_OP_call_frame_cfa``, |
| 2489 | ``DW_OP_breg*``, or ``DW_OP_LLVM_aspace_bregx``. This would also then |
| 2490 | allow a target to implement the call frames within a large register. |
| 2491 | |
| 2492 | Otherwise, the DWARF is ill-formed if SL is not a memory location |
| 2493 | description in any of the target architecture specific address spaces. |
| 2494 | |
| 2495 | The resulting L is the *frame base* for the subprogram or entry point. |
| 2496 | |
| 2497 | *Typically, E will use the* ``DW_OP_call_frame_cfa`` *operation or be a |
| 2498 | stack pointer register plus or minus some offset.* |
| 2499 | |
| 2500 | 4. ``DW_AT_data_member_location`` |
| 2501 | |
| 2502 | For a ``DW_AT_data_member_location`` attribute there are two cases: |
| 2503 | |
| 2504 | 1. If the attribute is an integer constant B, it provides the offset in |
| 2505 | bytes from the beginning of the containing entity. |
| 2506 | |
| 2507 | The result of the attribute is obtained by evaluating a |
| 2508 | ``DW_OP_LLVM_offset B`` operation with an initial stack comprising the |
| 2509 | location description of the beginning of the containing entity. The |
| 2510 | result of the evaluation is the location description of the base of the |
| 2511 | member entry. |
| 2512 | |
| 2513 | *If the beginning of the containing entity is not byte aligned, then the |
| 2514 | beginning of the member entry has the same bit displacement within a |
| 2515 | byte.* |
| 2516 | |
| 2517 | 2. Otherwise, the attribute must be a DWARF expression E which is evaluated |
| 2518 | with a context of the current frame, current program location, and an |
| 2519 | initial stack comprising the location description of the beginning of |
| 2520 | the containing entity. The result of the evaluation is the location |
| 2521 | description of the base of the member entry. |
| 2522 | |
| 2523 | .. note:: |
| 2524 | |
| 2525 | The beginning of the containing entity can now be any location |
| 2526 | description, including those with more than one single location |
| 2527 | description, and those with single location descriptions that are of any |
| 2528 | kind and have any bit offset. |
| 2529 | |
| 2530 | 5. ``DW_AT_use_location`` |
| 2531 | |
| 2532 | The ``DW_TAG_ptr_to_member_type`` debugging information entry has a |
| 2533 | ``DW_AT_use_location`` attribute whose value is a DWARF expression E. It is |
| 2534 | used to compute the location description of the member of the class to which |
| 2535 | the pointer to member entry points. |
| 2536 | |
| 2537 | *The method used to find the location description of a given member of a |
| 2538 | class, structure, or union is common to any instance of that class, |
| 2539 | structure, or union and to any instance of the pointer to member type. The |
| 2540 | method is thus associated with the pointer to member type, rather than with |
| 2541 | each object that has a pointer to member type.* |
| 2542 | |
| 2543 | The ``DW_AT_use_location`` DWARF expression is used in conjunction with the |
| 2544 | location description for a particular object of the given pointer to member |
| 2545 | type and for a particular structure or class instance. |
| 2546 | |
| 2547 | The result of the attribute is obtained by evaluating E as a location |
| 2548 | description with the context of the current subprogram, current program |
| 2549 | location, and an initial stack comprising two entries. The first entry is |
| 2550 | the value of the pointer to member object itself. The second entry is the |
| 2551 | location description of the base of the entire class, structure, or union |
| 2552 | instance containing the member whose location is being calculated. |
| 2553 | |
| 2554 | 6. ``DW_AT_data_location`` |
| 2555 | |
| 2556 | The ``DW_AT_data_location`` attribute may be used with any type that |
| 2557 | provides one or more levels of hidden indirection and/or run-time parameters |
| 2558 | in its representation. Its value is a DWARF operation expression E which |
| 2559 | computes the location description of the data for an object. When this |
| 2560 | attribute is omitted, the location description of the data is the same as |
| 2561 | the location description of the object. |
| 2562 | |
| 2563 | The result of the attribute is obtained by evaluating E as a location |
| 2564 | description with the context of the current subprogram, current program |
| 2565 | location, and an empty initial stack. |
| 2566 | |
| 2567 | *E will typically involve an operation expression that begins with a* |
| 2568 | ``DW_OP_push_object_address`` *operation which loads the location |
| 2569 | description of the object which can then serve as a description in |
| 2570 | subsequent calculation.* |
| 2571 | |
| 2572 | .. note:: |
| 2573 | |
| 2574 | Since ``DW_AT_data_member_location``, ``DW_AT_use_location``, and |
| 2575 | ``DW_AT_vtable_elem_location`` allow both operation expressions and |
| 2576 | location list expressions, why does ``DW_AT_data_location`` not allow |
| 2577 | both? In all cases they apply to data objects so less likely that |
| 2578 | optimization would cause different operation expressions for different |
| 2579 | program location ranges. But if supporting for some then should be for |
| 2580 | all. |
| 2581 | |
| 2582 | It seems odd this attribute is not the same as |
| 2583 | ``DW_AT_data_member_location`` in having an initial stack with the |
| 2584 | location description of the object since the expression has to need it. |
| 2585 | |
| 2586 | 7. ``DW_AT_vtable_elem_location`` |
| 2587 | |
| 2588 | An entry for a virtual function also has a ``DW_AT_vtable_elem_location`` |
| 2589 | attribute whose value is a DWARF expression E. |
| 2590 | |
| 2591 | The result of the attribute is obtained by evaluating E as a location |
| 2592 | description with the context of the current subprogram, current program |
| 2593 | location, and an initial stack comprising the location description of the |
| 2594 | object of the enclosing type. |
| 2595 | |
| 2596 | The resulting location description is the slot for the function within the |
| 2597 | virtual function table for the enclosing class. |
| 2598 | |
| 2599 | 8. ``DW_AT_static_link`` |
| 2600 | |
| 2601 | If a ``DW_TAG_subprogram`` or ``DW_TAG_entry_point`` debugger information |
| 2602 | entry is lexically nested, it may have a ``DW_AT_static_link`` attribute, |
| 2603 | whose value is a DWARF expression E. |
| 2604 | |
| 2605 | The result of the attribute is obtained by evaluating E as a location |
| 2606 | description with the context of the current subprogram, current program |
| 2607 | location, and an empty initial stack. |
| 2608 | |
| 2609 | The DWARF is ill-formed if the resulting location description L is is not |
| 2610 | comprised of one memory location description in any of the target |
| 2611 | architecture specific address spaces. |
| 2612 | |
| 2613 | The resulting L is the *frame base* of the relevant instance of the |
| 2614 | subprogram that immediately lexically encloses the subprogram or entry |
| 2615 | point. |
| 2616 | |
| 2617 | 9. ``DW_AT_return_addr`` |
| 2618 | |
| 2619 | A ``DW_TAG_subprogram``, ``DW_TAG_inlined_subroutine``, or |
| 2620 | ``DW_TAG_entry_point`` debugger information entry may have a |
| 2621 | ``DW_AT_return_addr`` attribute, whose value is a DWARF expression E. |
| 2622 | |
| 2623 | The result of the attribute is obtained by evaluating E as a location |
| 2624 | description with the context of the current subprogram, current program |
| 2625 | location, and an empty initial stack. |
| 2626 | |
| 2627 | The DWARF is ill-formed if the resulting location description L is not |
| 2628 | comprised one memory location description in any of the target architecture |
| 2629 | specific address spaces. |
| 2630 | |
| 2631 | The resulting L is the place where the return address for the subprogram or |
| 2632 | entry point is stored. |
| 2633 | |
| 2634 | .. note:: |
| 2635 | |
| 2636 | It is unclear why ``DW_TAG_inlined_subroutine`` has a |
| 2637 | ``DW_AT_return_addr`` attribute but not a ``DW_AT_frame_base`` or |
| 2638 | ``DW_AT_static_link`` attribute. Seems it would either have all of them or |
| 2639 | none. Since inlined subprograms do not have a frame it seems they would |
| 2640 | have none of these attributes. |
| 2641 | |
| 2642 | 10. ``DW_AT_call_value``, ``DW_AT_call_data_location``, and ``DW_AT_call_data_value`` |
| 2643 | |
| 2644 | A ``DW_TAG_call_site_parameter`` debugger information entry may have a |
| 2645 | ``DW_AT_call_value`` attribute, whose value is a DWARF operation expression |
| 2646 | E\ :sub:`1`\ . |
| 2647 | |
| 2648 | The result of the ``DW_AT_call_value`` attribute is obtained by evaluating |
| 2649 | E\ :sub:`1` as a value with the context of the call site subprogram, call |
| 2650 | site program location, and an empty initial stack. |
| 2651 | |
| 2652 | The call site subprogram is the subprogram containing the |
| 2653 | ``DW_TAG_call_site_parameter`` debugger information entry. The call site |
| 2654 | program location is the location of call site in the call site subprogram. |
| 2655 | |
| 2656 | *The consumer may have to virtually unwind to the call site in order to |
| 2657 | evaluate the attribute. This will provide both the call site subprogram and |
| 2658 | call site program location needed to evaluate the expression.* |
| 2659 | |
| 2660 | The resulting value V\ :sub:`1` is the value of the parameter at the time of |
| 2661 | the call made by the call site. |
| 2662 | |
| 2663 | For parameters passed by reference, where the code passes a pointer to a |
| 2664 | location which contains the parameter, or for reference type parameters, the |
| 2665 | ``DW_TAG_call_site_parameter`` debugger information entry may also have a |
| 2666 | ``DW_AT_call_data_location`` attribute whose value is a DWARF operation |
| 2667 | expression E\ :sub:`2`\ , and a ``DW_AT_call_data_value`` attribute whose |
| 2668 | value is a DWARF operation expression E\ :sub:`3`\ . |
| 2669 | |
| 2670 | The value of the ``DW_AT_call_data_location`` attribute is obtained by |
| 2671 | evaluating E\ :sub:`2` as a location description with the context of the |
| 2672 | call site subprogram, call site program location, and an empty initial |
| 2673 | stack. |
| 2674 | |
| 2675 | The resulting location description L\ :sub:`2` is the location where the |
| 2676 | referenced parameter lives during the call made by the call site. If E\ |
| 2677 | :sub:`2` would just be a ``DW_OP_push_object_address``, then the |
| 2678 | ``DW_AT_call_data_location`` attribute may be omitted. |
| 2679 | |
| 2680 | The value of the ``DW_AT_call_data_value`` attribute is obtained by |
| 2681 | evaluating E\ :sub:`3` as a value with the context of the call site |
| 2682 | subprogram, call site program location, and an empty initial stack. |
| 2683 | |
| 2684 | The resulting value V\ :sub:`3` is the value in L\ :sub:`2` at the time of |
| 2685 | the call made by the call site. |
| 2686 | |
| 2687 | If it is not possible to avoid the expressions of these attributes from |
| 2688 | accessing registers or memory locations that might be clobbered by the |
| 2689 | subprogram being called by the call site, then the associated attribute |
| 2690 | should not be provided. |
| 2691 | |
| 2692 | *The reason for the restriction is that the parameter may need to be |
| 2693 | accessed during the execution of the callee. The consumer may virtually |
| 2694 | unwind from the called subprogram back to the caller and then evaluate the |
| 2695 | attribute expressions. The call frame information (see* |
| 2696 | :ref:`amdgpu-dwarf-call-frame-information`\ *) will not be able to restore |
| 2697 | registers that have been clobbered, and clobbered memory will no longer have |
| 2698 | the value at the time of the call.* |
| 2699 | |
| 2700 | 11. ``DW_AT_LLVM_lanes`` *New* |
| 2701 | |
| 2702 | For languages that are implemented using a SIMD or SIMT execution model, a |
| 2703 | ``DW_TAG_subprogram``, ``DW_TAG_inlined_subroutine``, or |
| 2704 | ``DW_TAG_entry_point`` debugger information entry may have a |
| 2705 | ``DW_AT_LLVM_lanes`` attribute whose value is an integer constant that is |
| 2706 | the number of lanes per thread. This is the static number of lanes per |
| 2707 | thread. It is not the dynamic number of lanes with which the thread was |
| 2708 | initiated, for example, due to smaller or partial work-groups. |
| 2709 | |
| 2710 | If not present, the default value of 1 is used. |
| 2711 | |
| 2712 | The DWARF is ill-formed if the value is 0. |
| 2713 | |
| 2714 | 12. ``DW_AT_LLVM_lane_pc`` *New* |
| 2715 | |
| 2716 | For languages that are implemented using a SIMD or SIMT execution model, a |
| 2717 | ``DW_TAG_subprogram``, ``DW_TAG_inlined_subroutine``, or |
| 2718 | ``DW_TAG_entry_point`` debugging information entry may have a |
| 2719 | ``DW_AT_LLVM_lane_pc`` attribute whose value is a DWARF expression E. |
| 2720 | |
| 2721 | The result of the attribute is obtained by evaluating E as a location |
| 2722 | description with the context of the current subprogram, current program |
| 2723 | location, and an empty initial stack. |
| 2724 | |
| 2725 | The resulting location description L is for a thread lane count sized vector |
| 2726 | of generic type elements. The thread lane count is the value of the |
| 2727 | ``DW_AT_LLVM_lanes`` attribute. Each element holds the conceptual program |
| 2728 | location of the corresponding lane, where the least significant element |
| 2729 | corresponds to the first target architecture specific lane identifier and so |
| 2730 | forth. If the lane was not active when the current subprogram was called, |
| 2731 | its element is an undefined location description. |
| 2732 | |
| 2733 | ``DW_AT_LLVM_lane_pc`` *allows the compiler to indicate conceptually where |
| 2734 | each lane of a SIMT thread is positioned even when it is in divergent |
| 2735 | control flow that is not active.* |
| 2736 | |
| 2737 | *Typically, the result is a location description with one composite location |
| 2738 | description with each part being a location description with either one |
| 2739 | undefined location description or one memory location description.* |
| 2740 | |
| 2741 | If not present, the thread is not being used in a SIMT manner, and the |
| 2742 | thread's current program location is used. |
| 2743 | |
| 2744 | 13. ``DW_AT_LLVM_active_lane`` *New* |
| 2745 | |
| 2746 | For languages that are implemented using a SIMD or SIMT execution model, a |
| 2747 | ``DW_TAG_subprogram``, ``DW_TAG_inlined_subroutine``, or |
| 2748 | ``DW_TAG_entry_point`` debugger information entry may have a |
| 2749 | ``DW_AT_LLVM_active_lane`` attribute whose value is a DWARF expression E. |
| 2750 | |
| 2751 | The result of the attribute is obtained by evaluating E as a value with the |
| 2752 | context of the current subprogram, current program location, and an empty |
| 2753 | initial stack. |
| 2754 | |
| 2755 | The DWARF is ill-formed if the resulting value V is not an integral value. |
| 2756 | |
| 2757 | The resulting V is a bit mask of active lanes for the current program |
| 2758 | location. The N\ :sup:`th` least significant bit of the mask corresponds to |
| 2759 | the N\ :sup:`th` lane. If the bit is 1 the lane is active, otherwise it is |
| 2760 | inactive. |
| 2761 | |
| 2762 | *Some targets may update the target architecture execution mask for regions |
| 2763 | of code that must execute with different sets of lanes than the current |
| 2764 | active lanes. For example, some code must execute with all lanes made |
| 2765 | temporarily active.* ``DW_AT_LLVM_active_lane`` *allows the compiler to |
| 2766 | provide the means to determine the source language active lanes.* |
| 2767 | |
| 2768 | If not present and ``DW_AT_LLVM_lanes`` is greater than 1, then the target |
| 2769 | architecture execution mask is used. |
| 2770 | |
| 2771 | 14. ``DW_AT_LLVM_vector_size`` *New* |
| 2772 | |
| 2773 | A ``DW_TAG_base_type`` debugger information entry for a base type T may have |
| 2774 | a ``DW_AT_LLVM_vector_size`` attribute whose value is an integer constant |
| 2775 | that is the vector type size N. |
| 2776 | |
| 2777 | The representation of a vector base type is as N contiguous elements, each |
| 2778 | one having the representation of a base type T' that is the same as T |
| 2779 | without the ``DW_AT_LLVM_vector_size`` attribute. |
| 2780 | |
| 2781 | If a ``DW_TAG_base_type`` debugger information entry does not have a |
| 2782 | ``DW_AT_LLVM_vector_size`` attribute, then the base type is not a vector |
| 2783 | type. |
| 2784 | |
| 2785 | The DWARF is ill-formed if N is not greater than 0. |
| 2786 | |
| 2787 | .. note:: |
| 2788 | |
| 2789 | LLVM has mention of a non-upstreamed debugger information entry that is |
| 2790 | intended to support vector types. However, that was not for a base type so |
| 2791 | would not be suitable as the type of a stack value entry. But perhaps that |
| 2792 | could be replaced by using this attribute. |
| 2793 | |
| 2794 | 15. ``DW_AT_LLVM_augmentation`` *New* |
| 2795 | |
| 2796 | A ``DW_TAG_compile_unit`` debugger information entry for a compilation unit |
| 2797 | may have a ``DW_AT_LLVM_augmentation`` attribute, whose value is an |
| 2798 | augmentation string. |
| 2799 | |
| 2800 | *The augmentation string allows producers to indicate that there is |
| 2801 | additional vendor or target specific information in the debugging |
| 2802 | information entries. For example, this might be information about the |
| 2803 | version of vendor specific extensions that are being used.* |
| 2804 | |
| 2805 | If not present, or if the string is empty, then the compilation unit has no |
| 2806 | augmentation string. |
| 2807 | |
| 2808 | The format for the augmentation string is: |
| 2809 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 2810 | | ``[``\ *vendor*\ ``:v``\ *X*\ ``.``\ *Y*\ [\ ``:``\ *options*\ ]\ ``]``\ * |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 2811 | |
| 2812 | Where *vendor* is the producer, ``vX.Y`` specifies the major X and minor Y |
| 2813 | version number of the extensions used, and *options* is an optional string |
| 2814 | providing additional information about the extensions. The version number |
| 2815 | must conform to semantic versioning [:ref:`SEMVER <amdgpu-dwarf-SEMVER>`]. |
| 2816 | The *options* string must not contain the "\ ``]``\ " character. |
| 2817 | |
| 2818 | For example: |
| 2819 | |
| 2820 | :: |
| 2821 | |
| 2822 | [abc:v0.0][def:v1.2:feature-a=on,feature-b=3] |
| 2823 | |
| 2824 | Program Scope Entities |
| 2825 | ---------------------- |
| 2826 | |
| 2827 | .. _amdgpu-dwarf-language-names: |
| 2828 | |
| 2829 | Unit Entities |
| 2830 | ~~~~~~~~~~~~~ |
| 2831 | |
| 2832 | .. note:: |
| 2833 | |
| 2834 | This augments DWARF Version 5 section 3.1.1 and Table 3.1. |
| 2835 | |
| 2836 | Additional language codes defined for use with the ``DW_AT_language`` attribute |
| 2837 | are defined in :ref:`amdgpu-dwarf-language-names-table`. |
| 2838 | |
| 2839 | .. table:: Language Names |
| 2840 | :name: amdgpu-dwarf-language-names-table |
| 2841 | |
| 2842 | ==================== ============================= |
| 2843 | Language Name Meaning |
| 2844 | ==================== ============================= |
| 2845 | ``DW_LANG_LLVM_HIP`` HIP Language. |
| 2846 | ==================== ============================= |
| 2847 | |
| 2848 | The HIP language [:ref:`HIP <amdgpu-dwarf-HIP>`] can be supported by extending |
| 2849 | the C++ language. |
| 2850 | |
| 2851 | Other Debugger Information |
| 2852 | -------------------------- |
| 2853 | |
| 2854 | Accelerated Access |
| 2855 | ~~~~~~~~~~~~~~~~~~ |
| 2856 | |
| 2857 | .. _amdgpu-dwarf-lookup-by-name: |
| 2858 | |
| 2859 | Lookup By Name |
| 2860 | ++++++++++++++ |
| 2861 | |
| 2862 | Contents of the Name Index |
| 2863 | ########################## |
| 2864 | |
| 2865 | .. note:: |
| 2866 | |
| 2867 | The following provides changes to DWARF Version 5 section 6.1.1.1. |
| 2868 | |
| 2869 | The rule for debugger information entries included in the name index in the |
| 2870 | optional ``.debug_names`` section is extended to also include named |
| 2871 | ``DW_TAG_variable`` debugging information entries with a ``DW_AT_location`` |
| 2872 | attribute that includes a ``DW_OP_LLVM_form_aspace_address`` operation. |
| 2873 | |
| 2874 | The name index must contain an entry for each debugging information entry that |
| 2875 | defines a named subprogram, label, variable, type, or namespace, subject to the |
| 2876 | following rules: |
| 2877 | |
| 2878 | * ``DW_TAG_variable`` debugging information entries with a ``DW_AT_location`` |
| 2879 | attribute that includes a ``DW_OP_addr``, ``DW_OP_LLVM_form_aspace_address``, |
| 2880 | or ``DW_OP_form_tls_address`` operation are included; otherwise, they are |
| 2881 | excluded. |
| 2882 | |
| 2883 | Data Representation of the Name Index |
| 2884 | ##################################### |
| 2885 | |
| 2886 | Section Header |
| 2887 | ^^^^^^^^^^^^^^ |
| 2888 | |
| 2889 | .. note:: |
| 2890 | |
| 2891 | The following provides an addition to DWARF Version 5 section 6.1.1.4.1 item |
| 2892 | 14 ``augmentation_string``. |
| 2893 | |
| 2894 | A null-terminated UTF-8 vendor specific augmentation string, which provides |
| 2895 | additional information about the contents of this index. If provided, the |
| 2896 | recommended format for augmentation string is: |
| 2897 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 2898 | | ``[``\ *vendor*\ ``:v``\ *X*\ ``.``\ *Y*\ [\ ``:``\ *options*\ ]\ ``]``\ * |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 2899 | |
| 2900 | Where *vendor* is the producer, ``vX.Y`` specifies the major X and minor Y |
| 2901 | version number of the extensions used in the DWARF of the compilation unit, and |
| 2902 | *options* is an optional string providing additional information about the |
| 2903 | extensions. The version number must conform to semantic versioning [:ref:`SEMVER |
| 2904 | <amdgpu-dwarf-SEMVER>`]. The *options* string must not contain the "\ ``]``\ " |
| 2905 | character. |
| 2906 | |
| 2907 | For example: |
| 2908 | |
| 2909 | :: |
| 2910 | |
| 2911 | [abc:v0.0][def:v1.2:feature-a=on,feature-b=3] |
| 2912 | |
| 2913 | .. note:: |
| 2914 | |
| 2915 | This is different to the definition in DWARF Version 5 but is consistent with |
| 2916 | the other augmentation strings and allows multiple vendor extensions to be |
| 2917 | supported. |
| 2918 | |
| 2919 | .. _amdgpu-dwarf-line-number-information: |
| 2920 | |
| 2921 | Line Number Information |
| 2922 | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 2923 | |
| 2924 | The Line Number Program Header |
| 2925 | ++++++++++++++++++++++++++++++ |
| 2926 | |
| 2927 | Standard Content Descriptions |
| 2928 | ############################# |
| 2929 | |
| 2930 | .. note:: |
| 2931 | |
| 2932 | This augments DWARF Version 5 section 6.2.4.1. |
| 2933 | |
| 2934 | .. _amdgpu-dwarf-line-number-information-dw-lnct-llvm-source: |
| 2935 | |
| 2936 | 1. ``DW_LNCT_LLVM_source`` |
| 2937 | |
| 2938 | The component is a null-terminated UTF-8 source text string with "\ ``\n``\ |
| 2939 | " line endings. This content code is paired with the same forms as |
| 2940 | ``DW_LNCT_path``. It can be used for file name entries. |
| 2941 | |
| 2942 | The value is an empty null-terminated string if no source is available. If |
| 2943 | the source is available but is an empty file then the value is a |
| 2944 | null-terminated single "\ ``\n``\ ". |
| 2945 | |
| 2946 | *When the source field is present, consumers can use the embedded source |
| 2947 | instead of attempting to discover the source on disk using the file path |
| 2948 | provided by the* ``DW_LNCT_path`` *field. When the source field is absent, |
| 2949 | consumers can access the file to get the source text.* |
| 2950 | |
| 2951 | *This is particularly useful for programing languages that support runtime |
| 2952 | compilation and runtime generation of source text. In these cases, the |
| 2953 | source text does not reside in any permanent file. For example, the OpenCL |
| 2954 | language [:ref:`OpenCL <amdgpu-dwarf-OpenCL>`] supports online compilation.* |
| 2955 | |
| 2956 | 2. ``DW_LNCT_LLVM_is_MD5`` |
| 2957 | |
| 2958 | ``DW_LNCT_LLVM_is_MD5`` indicates if the ``DW_LNCT_MD5`` content kind, if |
| 2959 | present, is valid: when 0 it is not valid and when 1 it is valid. If |
| 2960 | ``DW_LNCT_LLVM_is_MD5`` content kind is not present, and ``DW_LNCT_MD5`` |
| 2961 | content kind is present, then the MD5 checksum is valid. |
| 2962 | |
| 2963 | ``DW_LNCT_LLVM_is_MD5`` is always paired with the ``DW_FORM_udata`` form. |
| 2964 | |
| 2965 | *This allows a compilation unit to have a mixture of files with and without |
| 2966 | MD5 checksums. This can happen when multiple relocatable files are linked |
| 2967 | together.* |
| 2968 | |
| 2969 | .. _amdgpu-dwarf-call-frame-information: |
| 2970 | |
| 2971 | Call Frame Information |
| 2972 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 2973 | |
| 2974 | .. note:: |
| 2975 | |
| 2976 | This section provides changes to existing Call Frame Information and defines |
| 2977 | instructions added by the proposal. Additional support is added for address |
| 2978 | spaces. Register unwind DWARF expressions are generalized to allow any |
| 2979 | location description, including those with composite and implicit location |
| 2980 | descriptions. |
| 2981 | |
| 2982 | These changes would be incorporated into the DWARF Version 5 section 6.1. |
| 2983 | |
| 2984 | Structure of Call Frame Information |
| 2985 | +++++++++++++++++++++++++++++++++++ |
| 2986 | |
| 2987 | The register rules are: |
| 2988 | |
| 2989 | *undefined* |
| 2990 | A register that has this rule has no recoverable value in the previous frame. |
| 2991 | (By convention, it is not preserved by a callee.) |
| 2992 | |
| 2993 | *same value* |
| 2994 | This register has not been modified from the previous frame. (By convention, |
| 2995 | it is preserved by the callee, but the callee has not modified it.) |
| 2996 | |
| 2997 | *offset(N)* |
| 2998 | N is a signed byte offset. The previous value of this register is saved at the |
| 2999 | location description computed as if the DWARF operation expression |
| 3000 | ``DW_OP_LLVM_offset N`` is evaluated as a location description with an initial |
| 3001 | stack comprising the location description of the current CFA (see |
| 3002 | :ref:`amdgpu-dwarf-operation-expressions`). |
| 3003 | |
| 3004 | *val_offset(N)* |
| 3005 | N is a signed byte offset. The previous value of this register is the memory |
| 3006 | byte address of the location description computed as if the DWARF operation |
| 3007 | expression ``DW_OP_LLVM_offset N`` is evaluated as a location description with |
| 3008 | an initial stack comprising the location description of the current CFA (see |
| 3009 | :ref:`amdgpu-dwarf-operation-expressions`). |
| 3010 | |
| 3011 | The DWARF is ill-formed if the CFA location description is not a memory byte |
| 3012 | address location description, or if the register size does not match the size |
| 3013 | of an address in the address space of the current CFA location description. |
| 3014 | |
| 3015 | *Since the CFA location description is required to be a memory byte address |
| 3016 | location description, the value of val_offset(N) will also be a memory byte |
| 3017 | address location description since it is offsetting the CFA location |
| 3018 | description by N bytes. Furthermore, the value of val_offset(N) will be a |
| 3019 | memory byte address in the same address space as the CFA location |
| 3020 | description.* |
| 3021 | |
| 3022 | .. note:: |
| 3023 | |
| 3024 | Should DWARF allow the address size to be a different size to the size of |
| 3025 | the register? Requiring them to be the same bit size avoids any issue of |
| 3026 | conversion as the bit contents of the register is simply interpreted as a |
| 3027 | value of the address. |
| 3028 | |
| 3029 | GDB has a per register hook that allows a target specific conversion on a |
| 3030 | register by register basis. It defaults to truncation of bigger registers, |
| 3031 | and to actually reading bytes from the next register (or reads out of bounds |
| 3032 | for the last register) for smaller registers. There are no GDB tests that |
| 3033 | read a register out of bounds (except an illegal hand written assembly |
| 3034 | test). |
| 3035 | |
| 3036 | *register(R)* |
| 3037 | The previous value of this register is stored in another register numbered R. |
| 3038 | |
| 3039 | The DWARF is ill-formed if the register sizes do not match. |
| 3040 | |
| 3041 | *expression(E)* |
| 3042 | The previous value of this register is located at the location description |
| 3043 | produced by evaluating the DWARF operation expression E (see |
| 3044 | :ref:`amdgpu-dwarf-operation-expressions`). |
| 3045 | |
| 3046 | E is evaluated as a location description in the context of the current |
| 3047 | subprogram, current program location, and with an initial stack comprising the |
| 3048 | location description of the current CFA. |
| 3049 | |
| 3050 | *val_expression(E)* |
| 3051 | The previous value of this register is the value produced by evaluating the |
| 3052 | DWARF operation expression E (see :ref:`amdgpu-dwarf-operation-expressions`). |
| 3053 | |
| 3054 | E is evaluated as a value in the context of the current subprogram, current |
| 3055 | program location, and with an initial stack comprising the location |
| 3056 | description of the current CFA. |
| 3057 | |
| 3058 | The DWARF is ill-formed if the resulting value type size does not match the |
| 3059 | register size. |
| 3060 | |
| 3061 | .. note:: |
| 3062 | |
| 3063 | This has limited usefulness as the DWARF expression E can only produce |
| 3064 | values up to the size of the generic type. This is due to not allowing any |
| 3065 | operations that specify a type in a CFI operation expression. This makes it |
| 3066 | unusable for registers that are larger than the generic type. However, |
| 3067 | *expression(E)* can be used to create an implicit location description of |
| 3068 | any size. |
| 3069 | |
| 3070 | *architectural* |
| 3071 | The rule is defined externally to this specification by the augmenter. |
| 3072 | |
| 3073 | A Common Information Entry holds information that is shared among many Frame |
| 3074 | Description Entries. There is at least one CIE in every non-empty |
| 3075 | ``.debug_frame`` section. A CIE contains the following fields, in order: |
| 3076 | |
| 3077 | 1. ``length`` (initial length) |
| 3078 | |
| 3079 | A constant that gives the number of bytes of the CIE structure, not |
| 3080 | including the length field itself. The size of the length field plus the |
| 3081 | value of length must be an integral multiple of the address size specified |
| 3082 | in the ``address_size`` field. |
| 3083 | |
| 3084 | 2. ``CIE_id`` (4 or 8 bytes, see |
| 3085 | :ref:`amdgpu-dwarf-32-bit-and-64-bit-dwarf-formats`) |
| 3086 | |
| 3087 | A constant that is used to distinguish CIEs from FDEs. |
| 3088 | |
| 3089 | In the 32-bit DWARF format, the value of the CIE id in the CIE header is |
| 3090 | 0xffffffff; in the 64-bit DWARF format, the value is 0xffffffffffffffff. |
| 3091 | |
| 3092 | 3. ``version`` (ubyte) |
| 3093 | |
| 3094 | A version number. This number is specific to the call frame information and |
| 3095 | is independent of the DWARF version number. |
| 3096 | |
| 3097 | The value of the CIE version number is 4. |
| 3098 | |
| 3099 | .. note:: |
| 3100 | |
| 3101 | Would this be increased to 5 to reflect the changes in the proposal? |
| 3102 | |
| 3103 | 4. ``augmentation`` (sequence of UTF-8 characters) |
| 3104 | |
| 3105 | A null-terminated UTF-8 string that identifies the augmentation to this CIE |
| 3106 | or to the FDEs that use it. If a reader encounters an augmentation string |
| 3107 | that is unexpected, then only the following fields can be read: |
| 3108 | |
| 3109 | * CIE: length, CIE_id, version, augmentation |
| 3110 | * FDE: length, CIE_pointer, initial_location, address_range |
| 3111 | |
| 3112 | If there is no augmentation, this value is a zero byte. |
| 3113 | |
| 3114 | *The augmentation string allows users to indicate that there is additional |
| 3115 | vendor and target architecture specific information in the CIE or FDE which |
| 3116 | is needed to virtually unwind a stack frame. For example, this might be |
| 3117 | information about dynamically allocated data which needs to be freed on exit |
| 3118 | from the routine.* |
| 3119 | |
| 3120 | *Because the* ``.debug_frame`` *section is useful independently of any* |
| 3121 | ``.debug_info`` *section, the augmentation string always uses UTF-8 |
| 3122 | encoding.* |
| 3123 | |
| 3124 | The recommended format for the augmentation string is: |
| 3125 | |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 3126 | | ``[``\ *vendor*\ ``:v``\ *X*\ ``.``\ *Y*\ [\ ``:``\ *options*\ ]\ ``]``\ * |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 3127 | |
| 3128 | Where *vendor* is the producer, ``vX.Y`` specifies the major X and minor Y |
| 3129 | version number of the extensions used, and *options* is an optional string |
| 3130 | providing additional information about the extensions. The version number |
| 3131 | must conform to semantic versioning [:ref:`SEMVER <amdgpu-dwarf-SEMVER>`]. |
| 3132 | The *options* string must not contain the "\ ``]``\ " character. |
| 3133 | |
| 3134 | For example: |
| 3135 | |
| 3136 | :: |
| 3137 | |
| 3138 | [abc:v0.0][def:v1.2:feature-a=on,feature-b=3] |
| 3139 | |
| 3140 | 5. ``address_size`` (ubyte) |
| 3141 | |
| 3142 | The size of a target address in this CIE and any FDEs that use it, in bytes. |
| 3143 | If a compilation unit exists for this frame, its address size must match the |
| 3144 | address size here. |
| 3145 | |
| 3146 | 6. ``segment_selector_size`` (ubyte) |
| 3147 | |
| 3148 | The size of a segment selector in this CIE and any FDEs that use it, in |
| 3149 | bytes. |
| 3150 | |
| 3151 | 7. ``code_alignment_factor`` (unsigned LEB128) |
| 3152 | |
| 3153 | A constant that is factored out of all advance location instructions (see |
| 3154 | :ref:`amdgpu-dwarf-row-creation-instructions`). The resulting value is |
| 3155 | ``(operand * code_alignment_factor)``. |
| 3156 | |
| 3157 | 8. ``data_alignment_factor`` (signed LEB128) |
| 3158 | |
| 3159 | A constant that is factored out of certain offset instructions (see |
| 3160 | :ref:`amdgpu-dwarf-cfa-definition-instructions` and |
| 3161 | :ref:`amdgpu-dwarf-register-rule-instructions`). The resulting value is |
| 3162 | ``(operand * data_alignment_factor)``. |
| 3163 | |
| 3164 | 9. ``return_address_register`` (unsigned LEB128) |
| 3165 | |
| 3166 | An unsigned LEB128 constant that indicates which column in the rule table |
| 3167 | represents the return address of the subprogram. Note that this column might |
| 3168 | not correspond to an actual machine register. |
| 3169 | |
| 3170 | 10. ``initial_instructions`` (array of ubyte) |
| 3171 | |
| 3172 | A sequence of rules that are interpreted to create the initial setting of |
| 3173 | each column in the table. |
| 3174 | |
| 3175 | The default rule for all columns before interpretation of the initial |
| 3176 | instructions is the undefined rule. However, an ABI authoring body or a |
| 3177 | compilation system authoring body may specify an alternate default value for |
| 3178 | any or all columns. |
| 3179 | |
| 3180 | 11. ``padding`` (array of ubyte) |
| 3181 | |
| 3182 | Enough ``DW_CFA_nop`` instructions to make the size of this entry match the |
| 3183 | length value above. |
| 3184 | |
| 3185 | An FDE contains the following fields, in order: |
| 3186 | |
| 3187 | 1. ``length`` (initial length) |
| 3188 | |
| 3189 | A constant that gives the number of bytes of the header and instruction |
| 3190 | stream for this subprogram, not including the length field itself. The size |
| 3191 | of the length field plus the value of length must be an integral multiple of |
| 3192 | the address size. |
| 3193 | |
| 3194 | 2. ``CIE_pointer`` (4 or 8 bytes, see |
| 3195 | :ref:`amdgpu-dwarf-32-bit-and-64-bit-dwarf-formats`) |
| 3196 | |
| 3197 | A constant offset into the ``.debug_frame`` section that denotes the CIE |
| 3198 | that is associated with this FDE. |
| 3199 | |
| 3200 | 3. ``initial_location`` (segment selector and target address) |
| 3201 | |
| 3202 | The address of the first location associated with this table entry. If the |
| 3203 | segment_selector_size field of this FDE’s CIE is non-zero, the initial |
| 3204 | location is preceded by a segment selector of the given length. |
| 3205 | |
| 3206 | 4. ``address_range`` (target address) |
| 3207 | |
| 3208 | The number of bytes of program instructions described by this entry. |
| 3209 | |
| 3210 | 5. ``instructions`` (array of ubyte) |
| 3211 | |
| 3212 | A sequence of table defining instructions that are described in |
| 3213 | :ref:`amdgpu-dwarf-call-frame-instructions`. |
| 3214 | |
| 3215 | 6. ``padding`` (array of ubyte) |
| 3216 | |
| 3217 | Enough ``DW_CFA_nop`` instructions to make the size of this entry match the |
| 3218 | length value above. |
| 3219 | |
| 3220 | .. _amdgpu-dwarf-call-frame-instructions: |
| 3221 | |
| 3222 | Call Frame Instructions |
| 3223 | +++++++++++++++++++++++ |
| 3224 | |
| 3225 | Some call frame instructions have operands that are encoded as DWARF operation |
| 3226 | expressions E (see :ref:`amdgpu-dwarf-operation-expressions`). The DWARF |
| 3227 | operations that can be used in E have the following restrictions: |
| 3228 | |
| 3229 | * ``DW_OP_addrx``, ``DW_OP_call2``, ``DW_OP_call4``, ``DW_OP_call_ref``, |
| 3230 | ``DW_OP_const_type``, ``DW_OP_constx``, ``DW_OP_convert``, |
| 3231 | ``DW_OP_deref_type``, ``DW_OP_fbreg``, ``DW_OP_implicit_pointer``, |
| 3232 | ``DW_OP_regval_type``, ``DW_OP_reinterpret``, and ``DW_OP_xderef_type`` |
| 3233 | operations are not allowed because the call frame information must not depend |
| 3234 | on other debug sections. |
| 3235 | |
| 3236 | * ``DW_OP_push_object_address`` is not allowed because there is no object |
| 3237 | context to provide a value to push. |
| 3238 | |
| 3239 | * ``DW_OP_LLVM_push_lane`` is not allowed because the call frame instructions |
| 3240 | describe the actions for the whole thread, not the lanes independently. |
| 3241 | |
| 3242 | * ``DW_OP_call_frame_cfa`` and ``DW_OP_entry_value`` are not allowed because |
| 3243 | their use would be circular. |
| 3244 | |
| 3245 | * ``DW_OP_LLVM_call_frame_entry_reg`` is not allowed if evaluating E causes a |
| 3246 | circular dependency between ``DW_OP_LLVM_call_frame_entry_reg`` operations. |
| 3247 | |
| 3248 | *For example, if a register R1 has a* ``DW_CFA_def_cfa_expression`` |
| 3249 | *instruction that evaluates a* ``DW_OP_LLVM_call_frame_entry_reg`` *operation |
| 3250 | that specifies register R2, and register R2 has a* |
| 3251 | ``DW_CFA_def_cfa_expression`` *instruction that that evaluates a* |
| 3252 | ``DW_OP_LLVM_call_frame_entry_reg`` *operation that specifies register R1.* |
| 3253 | |
| 3254 | *Call frame instructions to which these restrictions apply include* |
| 3255 | ``DW_CFA_def_cfa_expression``\ *,* ``DW_CFA_expression``\ *, and* |
| 3256 | ``DW_CFA_val_expression``\ *.* |
| 3257 | |
| 3258 | .. _amdgpu-dwarf-row-creation-instructions: |
| 3259 | |
| 3260 | Row Creation Instructions |
| 3261 | ######################### |
| 3262 | |
| 3263 | .. note:: |
| 3264 | |
| 3265 | These instructions are the same as in DWARF Version 5 section 6.4.2.1. |
| 3266 | |
| 3267 | .. _amdgpu-dwarf-cfa-definition-instructions: |
| 3268 | |
| 3269 | CFA Definition Instructions |
| 3270 | ########################### |
| 3271 | |
| 3272 | 1. ``DW_CFA_def_cfa`` |
| 3273 | |
| 3274 | The ``DW_CFA_def_cfa`` instruction takes two unsigned LEB128 operands |
| 3275 | representing a register number R and a (non-factored) byte displacement B. |
| 3276 | AS is set to the target architecture default address space identifier. The |
| 3277 | required action is to define the current CFA rule to be the result of |
| 3278 | evaluating the DWARF operation expression ``DW_OP_constu AS; |
| 3279 | DW_OP_aspace_bregx R, B`` as a location description. |
| 3280 | |
| 3281 | 2. ``DW_CFA_def_cfa_sf`` |
| 3282 | |
| 3283 | The ``DW_CFA_def_cfa_sf`` instruction takes two operands: an unsigned LEB128 |
| 3284 | value representing a register number R and a signed LEB128 factored byte |
| 3285 | displacement B. AS is set to the target architecture default address space |
| 3286 | identifier. The required action is to define the current CFA rule to be the |
| 3287 | result of evaluating the DWARF operation expression ``DW_OP_constu AS; |
| 3288 | DW_OP_aspace_bregx R, B*data_alignment_factor`` as a location description. |
| 3289 | |
| 3290 | *The action is the same as* ``DW_CFA_def_cfa`` *except that the second |
| 3291 | operand is signed and factored.* |
| 3292 | |
| 3293 | 3. ``DW_CFA_def_aspace_cfa`` *New* |
| 3294 | |
| 3295 | The ``DW_CFA_def_aspace_cfa`` instruction takes three unsigned LEB128 |
| 3296 | operands representing a register number R, a (non-factored) byte |
| 3297 | displacement B, and a target architecture specific address space identifier |
| 3298 | AS. The required action is to define the current CFA rule to be the result |
| 3299 | of evaluating the DWARF operation expression ``DW_OP_constu AS; |
| 3300 | DW_OP_aspace_bregx R, B`` as a location description. |
| 3301 | |
| 3302 | If AS is not one of the values defined by the target architecture specific |
| 3303 | ``DW_ASPACE_*`` values then the DWARF expression is ill-formed. |
| 3304 | |
| 3305 | 4. ``DW_CFA_def_aspace_cfa_sf`` *New* |
| 3306 | |
| 3307 | The ``DW_CFA_def_cfa_sf`` instruction takes three operands: an unsigned |
| 3308 | LEB128 value representing a register number R, a signed LEB128 factored byte |
| 3309 | displacement B, and an unsigned LEB128 value representing a target |
| 3310 | architecture specific address space identifier AS. The required action is to |
| 3311 | define the current CFA rule to be the result of evaluating the DWARF |
| 3312 | operation expression ``DW_OP_constu AS; DW_OP_aspace_bregx R, |
| 3313 | B*data_alignment_factor`` as a location description. |
| 3314 | |
| 3315 | If AS is not one of the values defined by the target architecture specific |
| 3316 | ``DW_ASPACE_*`` values, then the DWARF expression is ill-formed. |
| 3317 | |
| 3318 | *The action is the same as* ``DW_CFA_aspace_def_cfa`` *except that the |
| 3319 | second operand is signed and factored.* |
| 3320 | |
| 3321 | 5. ``DW_CFA_def_cfa_register`` |
| 3322 | |
| 3323 | The ``DW_CFA_def_cfa_register`` instruction takes a single unsigned LEB128 |
| 3324 | operand representing a register number R. The required action is to define |
| 3325 | the current CFA rule to be the result of evaluating the DWARF operation |
| 3326 | expression ``DW_OP_constu AS; DW_OP_aspace_bregx R, B`` as a location |
| 3327 | description. B and AS are the old CFA byte displacement and address space |
| 3328 | respectively. |
| 3329 | |
| 3330 | If the subprogram has no current CFA rule, or the rule was defined by a |
| 3331 | ``DW_CFA_def_cfa_expression`` instruction, then the DWARF is ill-formed. |
| 3332 | |
| 3333 | 6. ``DW_CFA_def_cfa_offset`` |
| 3334 | |
| 3335 | The ``DW_CFA_def_cfa_offset`` instruction takes a single unsigned LEB128 |
| 3336 | operand representing a (non-factored) byte displacement B. The required |
| 3337 | action is to define the current CFA rule to be the result of evaluating the |
| 3338 | DWARF operation expression ``DW_OP_constu AS; DW_OP_aspace_bregx R, B`` as a |
| 3339 | location description. R and AS are the old CFA register number and address |
| 3340 | space respectively. |
| 3341 | |
| 3342 | If the subprogram has no current CFA rule, or the rule was defined by a |
| 3343 | ``DW_CFA_def_cfa_expression`` instruction, then the DWARF is ill-formed. |
| 3344 | |
| 3345 | 7. ``DW_CFA_def_cfa_offset_sf`` |
| 3346 | |
| 3347 | The ``DW_CFA_def_cfa_offset_sf`` instruction takes a signed LEB128 operand |
| 3348 | representing a factored byte displacement B. The required action is to |
| 3349 | define the current CFA rule to be the result of evaluating the DWARF |
| 3350 | operation expression ``DW_OP_constu AS; DW_OP_aspace_bregx R, |
| 3351 | B*data_alignment_factor`` as a location description. R and AS are the old |
| 3352 | CFA register number and address space respectively. |
| 3353 | |
| 3354 | If the subprogram has no current CFA rule, or the rule was defined by a |
| 3355 | ``DW_CFA_def_cfa_expression`` instruction, then the DWARF is ill-formed. |
| 3356 | |
| 3357 | *The action is the same as* ``DW_CFA_def_cfa_offset`` *except that the |
| 3358 | operand is signed and factored.* |
| 3359 | |
| 3360 | 8. ``DW_CFA_def_cfa_expression`` |
| 3361 | |
| 3362 | The ``DW_CFA_def_cfa_expression`` instruction takes a single operand encoded |
| 3363 | as a ``DW_FORM_exprloc`` value representing a DWARF operation expression E. |
| 3364 | The required action is to define the current CFA rule to be the result of |
| 3365 | evaluating E as a location description in the context of the current |
| 3366 | subprogram, current program location, and an empty initial stack. |
| 3367 | |
| 3368 | *See* :ref:`amdgpu-dwarf-call-frame-instructions` *regarding restrictions on |
| 3369 | the DWARF expression operations that can be used in E.* |
| 3370 | |
| 3371 | The DWARF is ill-formed if the result of evaluating E is not a memory byte |
| 3372 | address location description. |
| 3373 | |
| 3374 | .. _amdgpu-dwarf-register-rule-instructions: |
| 3375 | |
| 3376 | Register Rule Instructions |
| 3377 | ########################## |
| 3378 | |
| 3379 | 1. ``DW_CFA_undefined`` |
| 3380 | |
| 3381 | The ``DW_CFA_undefined`` instruction takes a single unsigned LEB128 operand |
| 3382 | that represents a register number R. The required action is to set the rule |
| 3383 | for the register specified by R to ``undefined``. |
| 3384 | |
| 3385 | 2. ``DW_CFA_same_value`` |
| 3386 | |
| 3387 | The ``DW_CFA_same_value`` instruction takes a single unsigned LEB128 operand |
| 3388 | that represents a register number R. The required action is to set the rule |
| 3389 | for the register specified by R to ``same value``. |
| 3390 | |
| 3391 | 3. ``DW_CFA_offset`` |
| 3392 | |
| 3393 | The ``DW_CFA_offset`` instruction takes two operands: a register number R |
| 3394 | (encoded with the opcode) and an unsigned LEB128 constant representing a |
| 3395 | factored displacement B. The required action is to change the rule for the |
| 3396 | register specified by R to be an *offset(B\*data_alignment_factor)* rule. |
| 3397 | |
| 3398 | .. note:: |
| 3399 | |
| 3400 | Seems this should be named ``DW_CFA_offset_uf`` since the offset is |
| 3401 | unsigned factored. |
| 3402 | |
| 3403 | 4. ``DW_CFA_offset_extended`` |
| 3404 | |
| 3405 | The ``DW_CFA_offset_extended`` instruction takes two unsigned LEB128 |
| 3406 | operands representing a register number R and a factored displacement B. |
| 3407 | This instruction is identical to ``DW_CFA_offset`` except for the encoding |
| 3408 | and size of the register operand. |
| 3409 | |
| 3410 | .. note:: |
| 3411 | |
| 3412 | Seems this should be named ``DW_CFA_offset_extended_uf`` since the |
| 3413 | displacement is unsigned factored. |
| 3414 | |
| 3415 | 5. ``DW_CFA_offset_extended_sf`` |
| 3416 | |
| 3417 | The ``DW_CFA_offset_extended_sf`` instruction takes two operands: an |
| 3418 | unsigned LEB128 value representing a register number R and a signed LEB128 |
| 3419 | factored displacement B. This instruction is identical to |
| 3420 | ``DW_CFA_offset_extended`` except that B is signed. |
| 3421 | |
| 3422 | 6. ``DW_CFA_val_offset`` |
| 3423 | |
| 3424 | The ``DW_CFA_val_offset`` instruction takes two unsigned LEB128 operands |
| 3425 | representing a register number R and a factored displacement B. The required |
| 3426 | action is to change the rule for the register indicated by R to be a |
| 3427 | *val_offset(B\*data_alignment_factor)* rule. |
| 3428 | |
| 3429 | .. note:: |
| 3430 | |
| 3431 | Seems this should be named ``DW_CFA_val_offset_uf`` since the displacement |
| 3432 | is unsigned factored. |
| 3433 | |
| 3434 | .. note:: |
| 3435 | |
| 3436 | An alternative is to define ``DW_CFA_val_offset`` to implicitly use the |
| 3437 | target architecture default address space, and add another operation that |
| 3438 | specifies the address space. |
| 3439 | |
| 3440 | 7. ``DW_CFA_val_offset_sf`` |
| 3441 | |
| 3442 | The ``DW_CFA_val_offset_sf`` instruction takes two operands: an unsigned |
| 3443 | LEB128 value representing a register number R and a signed LEB128 factored |
| 3444 | displacement B. This instruction is identical to ``DW_CFA_val_offset`` |
| 3445 | except that B is signed. |
| 3446 | |
| 3447 | 8. ``DW_CFA_register`` |
| 3448 | |
| 3449 | The ``DW_CFA_register`` instruction takes two unsigned LEB128 operands |
| 3450 | representing register numbers R1 and R2 respectively. The required action is |
| 3451 | to set the rule for the register specified by R1 to be a *register(R2)* rule. |
| 3452 | |
| 3453 | 9. ``DW_CFA_expression`` |
| 3454 | |
| 3455 | The ``DW_CFA_expression`` instruction takes two operands: an unsigned LEB128 |
| 3456 | value representing a register number R, and a ``DW_FORM_block`` value |
| 3457 | representing a DWARF operation expression E. The required action is to |
| 3458 | change the rule for the register specified by R to be an *expression(E)* |
| 3459 | rule. |
| 3460 | |
| 3461 | *That is, E computes the location description where the register value can |
| 3462 | be retrieved.* |
| 3463 | |
| 3464 | *See* :ref:`amdgpu-dwarf-call-frame-instructions` *regarding restrictions on |
| 3465 | the DWARF expression operations that can be used in E.* |
| 3466 | |
| 3467 | 10. ``DW_CFA_val_expression`` |
| 3468 | |
| 3469 | The ``DW_CFA_val_expression`` instruction takes two operands: an unsigned |
| 3470 | LEB128 value representing a register number R, and a ``DW_FORM_block`` value |
| 3471 | representing a DWARF operation expression E. The required action is to |
| 3472 | change the rule for the register specified by R to be a *val_expression(E)* |
| 3473 | rule. |
| 3474 | |
| 3475 | *That is, E computes the value of register R.* |
| 3476 | |
| 3477 | *See* :ref:`amdgpu-dwarf-call-frame-instructions` *regarding restrictions on |
| 3478 | the DWARF expression operations that can be used in E.* |
| 3479 | |
| 3480 | If the result of evaluating E is not a value with a base type size that |
| 3481 | matches the register size, then the DWARF is ill-formed. |
| 3482 | |
| 3483 | 11. ``DW_CFA_restore`` |
| 3484 | |
| 3485 | The ``DW_CFA_restore`` instruction takes a single operand (encoded with the |
| 3486 | opcode) that represents a register number R. The required action is to |
| 3487 | change the rule for the register specified by R to the rule assigned it by |
| 3488 | the ``initial_instructions`` in the CIE. |
| 3489 | |
| 3490 | 12. ``DW_CFA_restore_extended`` |
| 3491 | |
| 3492 | The ``DW_CFA_restore_extended`` instruction takes a single unsigned LEB128 |
| 3493 | operand that represents a register number R. This instruction is identical |
| 3494 | to ``DW_CFA_restore`` except for the encoding and size of the register |
| 3495 | operand. |
| 3496 | |
| 3497 | Row State Instructions |
| 3498 | ###################### |
| 3499 | |
| 3500 | .. note:: |
| 3501 | |
| 3502 | These instructions are the same as in DWARF Version 5 section 6.4.2.4. |
| 3503 | |
| 3504 | Padding Instruction |
| 3505 | ################### |
| 3506 | |
| 3507 | .. note:: |
| 3508 | |
| 3509 | These instructions are the same as in DWARF Version 5 section 6.4.2.5. |
| 3510 | |
| 3511 | Call Frame Instruction Usage |
| 3512 | ++++++++++++++++++++++++++++ |
| 3513 | |
| 3514 | .. note:: |
| 3515 | |
| 3516 | The same as in DWARF Version 5 section 6.4.3. |
| 3517 | |
| 3518 | .. _amdgpu-dwarf-call-frame-calling-address: |
| 3519 | |
| 3520 | Call Frame Calling Address |
| 3521 | ++++++++++++++++++++++++++ |
| 3522 | |
| 3523 | .. note:: |
| 3524 | |
| 3525 | The same as in DWARF Version 5 section 6.4.4. |
| 3526 | |
| 3527 | Data Representation |
| 3528 | ------------------- |
| 3529 | |
| 3530 | .. _amdgpu-dwarf-32-bit-and-64-bit-dwarf-formats: |
| 3531 | |
| 3532 | 32-Bit and 64-Bit DWARF Formats |
| 3533 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3534 | |
| 3535 | .. note:: |
| 3536 | |
| 3537 | This augments DWARF Version 5 section 7.4. |
| 3538 | |
| 3539 | 1. Within the body of the ``.debug_info`` section, certain forms of attribute |
| 3540 | value depend on the choice of DWARF format as follows. For the 32-bit DWARF |
| 3541 | format, the value is a 4-byte unsigned integer; for the 64-bit DWARF format, |
| 3542 | the value is an 8-byte unsigned integer. |
| 3543 | |
| 3544 | .. table:: ``.debug_info`` section attribute form roles |
| 3545 | :name: amdgpu-dwarf-debug-info-section-attribute-form-roles-table |
| 3546 | |
| 3547 | ================================== =================================== |
| 3548 | Form Role |
| 3549 | ================================== =================================== |
| 3550 | DW_FORM_line_strp offset in ``.debug_line_str`` |
| 3551 | DW_FORM_ref_addr offset in ``.debug_info`` |
| 3552 | DW_FORM_sec_offset offset in a section other than |
| 3553 | ``.debug_info`` or ``.debug_str`` |
| 3554 | DW_FORM_strp offset in ``.debug_str`` |
| 3555 | DW_FORM_strp_sup offset in ``.debug_str`` section of |
| 3556 | supplementary object file |
| 3557 | DW_OP_call_ref offset in ``.debug_info`` |
| 3558 | DW_OP_implicit_pointer offset in ``.debug_info`` |
| 3559 | DW_OP_LLVM_aspace_implicit_pointer offset in ``.debug_info`` |
| 3560 | ================================== =================================== |
| 3561 | |
| 3562 | Format of Debugging Information |
| 3563 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3564 | |
| 3565 | Attribute Encodings |
| 3566 | +++++++++++++++++++ |
| 3567 | |
| 3568 | .. note:: |
| 3569 | |
| 3570 | This augments DWARF Version 5 section 7.5.4 and Table 7.5. |
| 3571 | |
| 3572 | The following table gives the encoding of the additional debugging information |
| 3573 | entry attributes. |
| 3574 | |
| 3575 | .. table:: Attribute encodings |
| 3576 | :name: amdgpu-dwarf-attribute-encodings-table |
| 3577 | |
Scott Linder | 084f3cf | 2020-04-30 14:00:09 -0400 | [diff] [blame^] | 3578 | ================================== ====== =================================== |
| 3579 | Attribute Name Value Classes |
| 3580 | ================================== ====== =================================== |
| 3581 | DW_AT_LLVM_active_lane 0x3e08 exprloc, loclist |
| 3582 | DW_AT_LLVM_augmentation 0x3e09 string |
| 3583 | DW_AT_LLVM_lanes 0x3e0a constant |
| 3584 | DW_AT_LLVM_lane_pc 0x3e0b exprloc, loclist |
| 3585 | DW_AT_LLVM_vector_size 0x3e0c constant |
| 3586 | ================================== ====== =================================== |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 3587 | |
| 3588 | DWARF Expressions |
| 3589 | ~~~~~~~~~~~~~~~~~ |
| 3590 | |
| 3591 | .. note:: |
| 3592 | |
| 3593 | Rename DWARF Version 5 section 7.7 to reflect the unification of location |
| 3594 | descriptions into DWARF expressions. |
| 3595 | |
| 3596 | Operation Expressions |
| 3597 | +++++++++++++++++++++ |
| 3598 | |
| 3599 | .. note:: |
| 3600 | |
| 3601 | Rename DWARF Version 5 section 7.7.1 and delete section 7.7.2 to reflect the |
| 3602 | unification of location descriptions into DWARF expressions. |
| 3603 | |
| 3604 | This augments DWARF Version 5 section 7.7.1 and Table 7.9. |
| 3605 | |
| 3606 | The following table gives the encoding of the additional DWARF expression |
| 3607 | operations. |
| 3608 | |
| 3609 | .. table:: DWARF Operation Encodings |
| 3610 | :name: amdgpu-dwarf-operation-encodings-table |
| 3611 | |
| 3612 | ================================== ===== ======== =============================== |
| 3613 | Operation Code Number Notes |
| 3614 | of |
| 3615 | Operands |
| 3616 | ================================== ===== ======== =============================== |
| 3617 | DW_OP_LLVM_form_aspace_address 0xe1 0 |
| 3618 | DW_OP_LLVM_push_lane 0xe2 0 |
| 3619 | DW_OP_LLVM_offset 0xe3 0 |
Tony | 756ba35 | 2020-04-20 16:55:34 -0400 | [diff] [blame] | 3620 | DW_OP_LLVM_offset_uconst 0xe4 1 ULEB128 byte displacement |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 3621 | DW_OP_LLVM_bit_offset 0xe5 0 |
| 3622 | DW_OP_LLVM_call_frame_entry_reg 0xe6 1 ULEB128 register number |
| 3623 | DW_OP_LLVM_undefined 0xe7 0 |
| 3624 | DW_OP_LLVM_aspace_bregx 0xe8 2 ULEB128 register number, |
| 3625 | ULEB128 byte displacement |
| 3626 | DW_OP_LLVM_aspace_implicit_pointer 0xe9 2 4- or 8-byte offset of DIE, |
| 3627 | SLEB128 byte displacement |
| 3628 | DW_OP_LLVM_piece_end 0xea 0 |
| 3629 | DW_OP_LLVM_extend 0xeb 2 ULEB128 bit size, |
| 3630 | ULEB128 count |
| 3631 | DW_OP_LLVM_select_bit_piece 0xec 2 ULEB128 bit size, |
| 3632 | ULEB128 count |
| 3633 | ================================== ===== ======== =============================== |
| 3634 | |
| 3635 | Location List Expressions |
| 3636 | +++++++++++++++++++++++++ |
| 3637 | |
| 3638 | .. note:: |
| 3639 | |
| 3640 | Rename DWARF Version 5 section 7.7.3 to reflect that location lists are a kind |
| 3641 | of DWARF expression. |
| 3642 | |
| 3643 | Source Languages |
| 3644 | ~~~~~~~~~~~~~~~~ |
| 3645 | |
| 3646 | .. note:: |
| 3647 | |
| 3648 | This augments DWARF Version 5 section 7.12 and Table 7.17. |
| 3649 | |
| 3650 | The following table gives the encoding of the additional DWARF languages. |
| 3651 | |
| 3652 | .. table:: Language encodings |
| 3653 | :name: amdgpu-dwarf-language-encodings-table |
| 3654 | |
| 3655 | ==================== ====== =================== |
| 3656 | Language Name Value Default Lower Bound |
| 3657 | ==================== ====== =================== |
| 3658 | ``DW_LANG_LLVM_HIP`` 0x8100 0 |
| 3659 | ==================== ====== =================== |
| 3660 | |
| 3661 | Address Class and Address Space Encodings |
| 3662 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3663 | |
| 3664 | .. note:: |
| 3665 | |
| 3666 | This replaces DWARF Version 5 section 7.13. |
| 3667 | |
| 3668 | The encodings of the constants used for the currently defined address classes |
| 3669 | are given in :ref:`amdgpu-dwarf-address-class-encodings-table`. |
| 3670 | |
| 3671 | .. table:: Address class encodings |
| 3672 | :name: amdgpu-dwarf-address-class-encodings-table |
| 3673 | |
| 3674 | ========================== ====== |
| 3675 | Address Class Name Value |
| 3676 | ========================== ====== |
| 3677 | ``DW_ADDR_none`` 0x0000 |
| 3678 | ``DW_ADDR_LLVM_global`` 0x0001 |
| 3679 | ``DW_ADDR_LLVM_constant`` 0x0002 |
| 3680 | ``DW_ADDR_LLVM_group`` 0x0003 |
| 3681 | ``DW_ADDR_LLVM_private`` 0x0004 |
| 3682 | ``DW_ADDR_LLVM_lo_user`` 0x8000 |
| 3683 | ``DW_ADDR_LLVM_hi_user`` 0xffff |
| 3684 | ========================== ====== |
| 3685 | |
| 3686 | Line Number Information |
| 3687 | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 3688 | |
| 3689 | .. note:: |
| 3690 | |
| 3691 | This augments DWARF Version 5 section 7.22 and Table 7.27. |
| 3692 | |
| 3693 | The following table gives the encoding of the additional line number header |
| 3694 | entry formats. |
| 3695 | |
| 3696 | .. table:: Line number header entry format encodings |
| 3697 | :name: amdgpu-dwarf-line-number-header-entry-format-encodings-table |
| 3698 | |
| 3699 | ==================================== ==================== |
| 3700 | Line number header entry format name Value |
| 3701 | ==================================== ==================== |
| 3702 | ``DW_LNCT_LLVM_source`` 0x2001 |
| 3703 | ``DW_LNCT_LLVM_is_MD5`` 0x2002 |
| 3704 | ==================================== ==================== |
| 3705 | |
| 3706 | Call Frame Information |
| 3707 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 3708 | |
| 3709 | .. note:: |
| 3710 | |
| 3711 | This augments DWARF Version 5 section 7.24 and Table 7.29. |
| 3712 | |
| 3713 | The following table gives the encoding of the additional call frame information |
| 3714 | instructions. |
| 3715 | |
| 3716 | .. table:: Call frame instruction encodings |
| 3717 | :name: amdgpu-dwarf-call-frame-instruction-encodings-table |
| 3718 | |
| 3719 | ======================== ====== ====== ================ ================ ================ |
| 3720 | Instruction High 2 Low 6 Operand 1 Operand 2 Operand 3 |
| 3721 | Bits Bits |
| 3722 | ======================== ====== ====== ================ ================ ================ |
Scott Linder | 084f3cf | 2020-04-30 14:00:09 -0400 | [diff] [blame^] | 3723 | DW_CFA_def_aspace_cfa 0 0x30 ULEB128 register ULEB128 offset ULEB128 address space |
| 3724 | DW_CFA_def_aspace_cfa_sf 0 0x31 ULEB128 register SLEB128 offset ULEB128 address space |
Tony | 1eac2c5 | 2020-04-14 00:55:43 -0400 | [diff] [blame] | 3725 | ======================== ====== ====== ================ ================ ================ |
| 3726 | |
| 3727 | Attributes by Tag Value (Informative) |
| 3728 | ------------------------------------- |
| 3729 | |
| 3730 | .. note:: |
| 3731 | |
| 3732 | This augments DWARF Version 5 Appendix A and Table A.1. |
| 3733 | |
| 3734 | The following table provides the additional attributes that are applicable to |
| 3735 | debugger information entries. |
| 3736 | |
| 3737 | .. table:: Attributes by tag value |
| 3738 | :name: amdgpu-dwarf-attributes-by-tag-value-table |
| 3739 | |
| 3740 | ============================= ============================= |
| 3741 | Tag Name Applicable Attributes |
| 3742 | ============================= ============================= |
| 3743 | ``DW_TAG_base_type`` * ``DW_AT_LLVM_vector_size`` |
| 3744 | ``DW_TAG_compile_unit`` * ``DW_AT_LLVM_augmentation`` |
| 3745 | ``DW_TAG_entry_point`` * ``DW_AT_LLVM_active_lane`` |
| 3746 | * ``DW_AT_LLVM_lane_pc`` |
| 3747 | * ``DW_AT_LLVM_lanes`` |
| 3748 | ``DW_TAG_inlined_subroutine`` * ``DW_AT_LLVM_active_lane`` |
| 3749 | * ``DW_AT_LLVM_lane_pc`` |
| 3750 | * ``DW_AT_LLVM_lanes`` |
| 3751 | ``DW_TAG_subprogram`` * ``DW_AT_LLVM_active_lane`` |
| 3752 | * ``DW_AT_LLVM_lane_pc`` |
| 3753 | * ``DW_AT_LLVM_lanes`` |
| 3754 | ============================= ============================= |
| 3755 | |
| 3756 | References |
| 3757 | ---------- |
| 3758 | |
| 3759 | .. _amdgpu-dwarf-AMD: |
| 3760 | |
| 3761 | 1. [AMD] `Advanced Micro Devices <https://www.amd.com/>`__ |
| 3762 | |
| 3763 | .. _amdgpu-dwarf-AMD-ROCm: |
| 3764 | |
| 3765 | 2. [AMD-ROCm] `AMD ROCm Platform <https://rocm-documentation.readthedocs.io>`__ |
| 3766 | |
| 3767 | .. _amdgpu-dwarf-AMD-ROCgdb: |
| 3768 | |
| 3769 | 3. [AMD-ROCgdb] `AMD ROCm Debugger (ROCgdb) <https://github.com/ROCm-Developer-Tools/ROCgdb>`__ |
| 3770 | |
| 3771 | .. _amdgpu-dwarf-AMDGPU-LLVM: |
| 3772 | |
| 3773 | 4. [AMDGPU-LLVM] `User Guide for AMDGPU LLVM Backend <https://llvm.org/docs/AMDGPUUsage.html>`__ |
| 3774 | |
| 3775 | .. _amdgpu-dwarf-CUDA: |
| 3776 | |
| 3777 | 5. [CUDA] `Nvidia CUDA Language <https://docs.nvidia.com/cuda/cuda-c-programming-guide/>`__ |
| 3778 | |
| 3779 | .. _amdgpu-dwarf-DWARF: |
| 3780 | |
| 3781 | 6. [DWARF] `DWARF Debugging Information Format <http://dwarfstd.org/>`__ |
| 3782 | |
| 3783 | .. _amdgpu-dwarf-ELF: |
| 3784 | |
| 3785 | 7. [ELF] `Executable and Linkable Format (ELF) <http://www.sco.com/developers/gabi/>`__ |
| 3786 | |
| 3787 | .. _amdgpu-dwarf-GCC: |
| 3788 | |
| 3789 | 8. [GCC] `GCC: The GNU Compiler Collection <https://www.gnu.org/software/gcc/>`__ |
| 3790 | |
| 3791 | .. _amdgpu-dwarf-GDB: |
| 3792 | |
| 3793 | 9. [GDB] `GDB: The GNU Project Debugger <https://www.gnu.org/software/gdb/>`__ |
| 3794 | |
| 3795 | .. _amdgpu-dwarf-HIP: |
| 3796 | |
| 3797 | 10. [HIP] `HIP Programming Guide <https://rocm-documentation.readthedocs.io/en/latest/Programming_Guides/Programming-Guides.html#hip-programing-guide>`__ |
| 3798 | |
| 3799 | .. _amdgpu-dwarf-HSA: |
| 3800 | |
| 3801 | 11. [HSA] `Heterogeneous System Architecture (HSA) Foundation <http://www.hsafoundation.com/>`__ |
| 3802 | |
| 3803 | .. _amdgpu-dwarf-LLVM: |
| 3804 | |
| 3805 | 12. [LLVM] `The LLVM Compiler Infrastructure <https://llvm.org/>`__ |
| 3806 | |
| 3807 | .. _amdgpu-dwarf-OpenCL: |
| 3808 | |
| 3809 | 13. [OpenCL] `The OpenCL Specification Version 2.0 <http://www.khronos.org/registry/cl/specs/opencl-2.0.pdf>`__ |
| 3810 | |
| 3811 | .. _amdgpu-dwarf-Perforce-TotalView: |
| 3812 | |
| 3813 | 14. [Perforce-TotalView] `Perforce TotalView HPC Debugging Software <https://totalview.io/products/totalview>`__ |
| 3814 | |
| 3815 | .. _amdgpu-dwarf-SEMVER: |
| 3816 | |
Scott Linder | 084f3cf | 2020-04-30 14:00:09 -0400 | [diff] [blame^] | 3817 | 15. [SEMVER] `Semantic Versioning <https://semver.org/>`__ |