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