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