1 .. _amdgpu-dwarf-extensions-for-heterogeneous-debugging:
3 ********************************************
4 DWARF Extensions For Heterogeneous Debugging
5 ********************************************
12 This document describes **provisional extensions** to DWARF Version 5
13 [:ref:`DWARF <amdgpu-dwarf-DWARF>`] to support heterogeneous debugging. It is
14 not currently fully implemented and is subject to change.
16 .. _amdgpu-dwarf-introduction:
21 AMD [:ref:`AMD <amdgpu-dwarf-AMD>`] has been working on supporting heterogeneous
22 computing. A heterogeneous computing program can be written in a high level
23 language such as C++ or Fortran with OpenMP pragmas, OpenCL, or HIP (a portable
24 C++ programming environment for heterogeneous computing [:ref:`HIP
25 <amdgpu-dwarf-HIP>`]). A heterogeneous compiler and runtime allows a program to
26 execute on multiple devices within the same native process. Devices could
27 include CPUs, GPUs, DSPs, FPGAs, or other special purpose accelerators.
28 Currently HIP programs execute on systems with CPUs and GPUs.
30 The AMD [:ref:`AMD <amdgpu-dwarf-AMD>`] ROCm platform [:ref:`AMD-ROCm
31 <amdgpu-dwarf-AMD-ROCm>`] is an implementation of the industry standard for
32 heterogeneous computing devices defined by the Heterogeneous System Architecture
33 (HSA) Foundation [:ref:`HSA <amdgpu-dwarf-HSA>`]. It is open sourced and
34 includes contributions to open source projects such as LLVM [:ref:`LLVM
35 <amdgpu-dwarf-LLVM>`] for compilation and GDB for debugging [:ref:`GDB
38 The LLVM compiler has upstream support for commercially available AMD GPU
39 hardware (AMDGPU) [:ref:`AMDGPU-LLVM <amdgpu-dwarf-AMDGPU-LLVM>`]. The open
40 source ROCgdb [:ref:`AMD-ROCgdb <amdgpu-dwarf-AMD-ROCgdb>`] GDB based debugger
41 also has support for AMDGPU which is being upstreamed. Support for AMDGPU is
42 also being added by third parties to the GCC [:ref:`GCC <amdgpu-dwarf-GCC>`]
43 compiler and the Perforce TotalView HPC Debugger [:ref:`Perforce-TotalView
44 <amdgpu-dwarf-Perforce-TotalView>`].
46 To support debugging heterogeneous programs several features that are not
47 provided by current DWARF Version 5 [:ref:`DWARF <amdgpu-dwarf-DWARF>`] have
48 been identified. The :ref:`amdgpu-dwarf-extensions` section gives an overview of
49 the extensions devised to address the missing features. The extensions seek to
50 be general in nature and backwards compatible with DWARF Version 5. Their goal
51 is to be applicable to meeting the needs of any heterogeneous system and not be
52 vendor or architecture specific. That is followed by appendix
53 :ref:`amdgpu-dwarf-changes-relative-to-dwarf-version-5` which contains the
54 textual changes for the extensions relative to the DWARF Version 5 standard.
55 There are a number of notes included that raise open questions, or provide
56 alternative approaches that may be worth considering. Then appendix
57 :ref:`amdgpu-dwarf-further-examples` links to the AMD GPU specific usage of the
58 extensions that includes an example. Finally, appendix
59 :ref:`amdgpu-dwarf-references` provides references to further information.
61 .. _amdgpu-dwarf-extensions:
66 The extensions continue to evolve through collaboration with many individuals and
67 active prototyping within the GDB debugger and LLVM compiler. Input has also
68 been very much appreciated from the developers working on the Perforce TotalView
69 HPC Debugger and GCC compiler.
71 The inputs provided and insights gained so far have been incorporated into this
72 current version. The plan is to participate in upstreaming the work and
73 addressing any feedback. If there is general interest then some or all of these
74 extensions could be submitted as future DWARF standard proposals.
76 The general principles in designing the extensions have been:
78 1. Be backwards compatible with the DWARF Version 5 [:ref:`DWARF
79 <amdgpu-dwarf-DWARF>`] standard.
81 2. Be vendor and architecture neutral. They are intended to apply to other
82 heterogeneous hardware devices including GPUs, DSPs, FPGAs, and other
83 specialized hardware. These collectively include similar characteristics and
84 requirements as AMDGPU devices.
86 3. Provide improved optimization support for non-GPU code. For example, some
87 extensions apply to traditional CPU hardware that supports large vector
88 registers. Compilers can map source languages, and source language
89 extensions, that describe large scale parallel execution, onto the lanes of
90 the vector registers. This is common in programming languages used in ML and
93 4. Fully define well-formed DWARF in a consistent style based on the DWARF
94 Version 5 specification.
96 It is possible that some of the generalizations may also benefit other DWARF
97 issues that have been raised.
99 The remainder of this section enumerates the extensions and provides motivation
100 for each in terms of heterogeneous debugging.
102 .. _amdgpu-dwarf-allow-location-description-on-the-dwarf-evaluation-stack:
104 2.1 Allow Location Description on the DWARF Expression Stack
105 ------------------------------------------------------------
107 DWARF Version 5 does not allow location descriptions to be entries on the DWARF
108 expression stack. They can only be the final result of the evaluation of a DWARF
109 expression. However, by allowing a location description to be a first-class
110 entry on the DWARF expression stack it becomes possible to compose expressions
111 containing both values and location descriptions naturally. It allows objects to
112 be located in any kind of memory address space, in registers, be implicit
113 values, be undefined, or a composite of any of these.
115 By extending DWARF carefully, all existing DWARF expressions can retain their
116 current semantic meaning. DWARF has implicit conversions that convert from a
117 value that represents an address in the default address space to a memory
118 location description. This can be extended to allow a default address space
119 memory location description to be implicitly converted back to its address
120 value. This allows all DWARF Version 5 expressions to retain their same meaning,
121 while enabling the ability to explicitly create memory location descriptions in
122 non-default address spaces and generalizing the power of composite location
123 descriptions to any kind of location description.
125 For those familiar with the definition of location descriptions in DWARF Version
126 5, the definitions in these extensions are presented differently, but does in
127 fact define the same concept with the same fundamental semantics. However, it
128 does so in a way that allows the concept to extend to support address spaces,
129 bit addressing, the ability for composite location descriptions to be composed
130 of any kind of location description, and the ability to support objects located
131 at multiple places. Collectively these changes expand the set of architectures
132 that can be supported and improves support for optimized code.
134 Several approaches were considered, and the one presented, together with the
135 extensions it enables, appears to be the simplest and cleanest one that offers
136 the greatest improvement of DWARF's ability to support debugging optimized GPU
137 and non-GPU code. Examining the GDB debugger and LLVM compiler, it appears only
138 to require modest changes as they both already have to support general use of
139 location descriptions. It is anticipated that will also be the case for other
140 debuggers and compilers.
142 GDB has been modified to evaluate DWARF Version 5 expressions with location
143 descriptions as stack entries and with implicit conversions. All GDB tests have
144 passed, except one that turned out to be an invalid test case by DWARF Version 5
145 rules. The code in GDB actually became simpler as all evaluation is done on a
146 single stack and there was no longer a need to maintain a separate structure for
147 the location description results. This gives confidence in backwards
150 See :ref:`amdgpu-dwarf-expressions` and nested sections.
152 This extension is separately described at *Allow Location Descriptions on the
153 DWARF Expression Stack* [:ref:`AMDGPU-DWARF-LOC
154 <amdgpu-dwarf-AMDGPU-DWARF-LOC>`].
156 2.2 Generalize CFI to Allow Any Location Description Kind
157 ---------------------------------------------------------
159 CFI describes restoring callee saved registers that are spilled. Currently CFI
160 only allows a location description that is a register, memory address, or
161 implicit location description. AMDGPU optimized code may spill scalar registers
162 into portions of vector registers. This requires extending CFI to allow any
163 location description kind to be supported.
165 See :ref:`amdgpu-dwarf-call-frame-information`.
167 2.3 Generalize DWARF Operation Expressions to Support Multiple Places
168 ---------------------------------------------------------------------
170 In DWARF Version 5 a location description is defined as a single location
171 description or a location list. A location list is defined as either
172 effectively an undefined location description or as one or more single
173 location descriptions to describe an object with multiple places.
176 :ref:`amdgpu-dwarf-allow-location-description-on-the-dwarf-evaluation-stack`,
177 the ``DW_OP_push_object_address`` and ``DW_OP_call*`` operations can put a
178 location description on the stack. Furthermore, debugger information entry
179 attributes such as ``DW_AT_data_member_location``, ``DW_AT_use_location``, and
180 ``DW_AT_vtable_elem_location`` are defined as pushing a location description on
181 the expression stack before evaluating the expression.
183 DWARF Version 5 only allows the stack to contain values and so only a single
184 memory address can be on the stack. This makes these operations and attributes
185 incapable of handling location descriptions with multiple places, or places
189 :ref:`amdgpu-dwarf-allow-location-description-on-the-dwarf-evaluation-stack`
190 allows the stack to contain location descriptions, the operations are
191 generalized to support location descriptions that can have multiple places. This
192 is backwards compatible with DWARF Version 5 and allows objects with multiple
193 places to be supported. For example, the expression that describes how to access
194 the field of an object can be evaluated with a location description that has
195 multiple places and will result in a location description with multiple places.
197 With this change, the separate DWARF Version 5 sections that described DWARF
198 expressions and location lists are unified into a single section that describes
199 DWARF expressions in general. This unification is a natural consequence of, and
200 a necessity of, allowing location descriptions to be part of the evaluation
203 See :ref:`amdgpu-dwarf-location-description`.
205 2.4 Generalize Offsetting of Location Descriptions
206 --------------------------------------------------
208 The ``DW_OP_plus`` and ``DW_OP_minus`` operations can be defined to operate on a
209 memory location description in the default target architecture specific address
210 space and a generic type value to produce an updated memory location
211 description. This allows them to continue to be used to offset an address.
213 To generalize offsetting to any location description, including location
214 descriptions that describe when bytes are in registers, are implicit, or a
215 composite of these, the ``DW_OP_LLVM_offset``, ``DW_OP_LLVM_offset_uconst``, and
216 ``DW_OP_LLVM_bit_offset`` offset operations are added.
218 The offset operations can operate on location storage of any size. For example,
219 implicit location storage could be any number of bits in size. It is simpler to
220 define offsets that exceed the size of the location storage as being an
221 evaluation error, than having to force an implementation to support potentially
222 infinite precision offsets to allow it to correctly track a series of positive
223 and negative offsets that may transiently overflow or underflow, but end up in
224 range. This is simple for the arithmetic operations as they are defined in terms
225 of two's complement arithmetic on a base type of a fixed size. Therefore, the
226 offset operation define that integer overflow is ill-formed. This is in contrast
227 to the ``DW_OP_plus``, ``DW_OP_plus_uconst``, and ``DW_OP_minus`` arithmetic
228 operations which define that it causes wrap-around.
230 Having the offset operations allows ``DW_OP_push_object_address`` to push a
231 location description that may be in a register, or be an implicit value. The
232 DWARF expression of ``DW_TAG_ptr_to_member_type`` can use the offset operations
233 without regard to what kind of location description was pushed.
236 :ref:`amdgpu-dwarf-allow-location-description-on-the-dwarf-evaluation-stack` has
237 generalized location storage to be bit indexable, ``DW_OP_LLVM_bit_offset``
238 generalizes DWARF to work with bit fields. This is generally not possible in
241 The ``DW_OP_*piece`` operations only allow literal indices. A way to use a
242 computed offset of an arbitrary location description (such as a vector register)
243 is required. The offset operations provide this ability since they can be used
244 to compute a location description on the stack.
246 It could be possible to define ``DW_OP_plus``, ``DW_OP_plus_uconst``, and
247 ``DW_OP_minus`` to operate on location descriptions to avoid needing
248 ``DW_OP_LLVM_offset`` and ``DW_OP_LLVM_offset_uconst``. However, this is not
249 proposed since currently the arithmetic operations are defined to require values
250 of the same base type and produces a result with the same base type. Allowing
251 these operations to act on location descriptions would permit the first operand
252 to be a location description and the second operand to be an integral value
253 type, or vice versa, and return a location description. This complicates the
254 rules for implicit conversions between default address space memory location
255 descriptions and generic base type values. Currently the rules would convert
256 such a location description to the memory address value and then perform two's
257 compliment wrap around arithmetic. If the result was used as a location
258 description, it would be implicitly converted back to a default address space
259 memory location description. This is different to the overflow rules on location
260 descriptions. To allow control, an operation that converts a memory location
261 description to an address integral type value would be required. Keeping a
262 separation of location description operations and arithmetic operations avoids
263 this semantic complexity.
265 See ``DW_OP_LLVM_offset``, ``DW_OP_LLVM_offset_uconst``, and
266 ``DW_OP_LLVM_bit_offset`` in
267 :ref:`amdgpu-dwarf-general-location-description-operations`.
269 2.5 Generalize Creation of Undefined Location Descriptions
270 ----------------------------------------------------------
272 Current DWARF uses an empty expression to indicate an undefined location
274 :ref:`amdgpu-dwarf-allow-location-description-on-the-dwarf-evaluation-stack`
275 allows location descriptions to be created on the stack, it is necessary to have
276 an explicit way to specify an undefined location description.
278 For example, the ``DW_OP_LLVM_select_bit_piece`` (see
279 :ref:`amdgpu-dwarf-support-for-divergent-control-flow-of-simt-hardware`)
280 operation takes more than one location description on the stack. Without this
281 ability, it is not possible to specify that a particular one of the input
282 location descriptions is undefined.
284 See the ``DW_OP_LLVM_undefined`` operation in
285 :ref:`amdgpu-dwarf-undefined-location-description-operations`.
287 2.6 Generalize Creation of Composite Location Descriptions
288 ----------------------------------------------------------
290 To allow composition of composite location descriptions, an explicit operation
291 that indicates the end of the definition of a composite location description is
292 required. This can be implied if the end of a DWARF expression is reached,
293 allowing current DWARF expressions to remain legal.
295 See ``DW_OP_LLVM_piece_end`` in
296 :ref:`amdgpu-dwarf-composite-location-description-operations`.
298 2.7 Generalize DWARF Base Objects to Allow Any Location Description Kind
299 ------------------------------------------------------------------------
301 The number of registers and the cost of memory operations is much higher for
302 AMDGPU than a typical CPU. The compiler attempts to optimize whole variables and
303 arrays into registers.
305 Currently DWARF only allows ``DW_OP_push_object_address`` and related operations
306 to work with a global memory location. To support AMDGPU optimized code it is
307 required to generalize DWARF to allow any location description to be used. This
308 allows registers, or composite location descriptions that may be a mixture of
309 memory, registers, or even implicit values.
311 See ``DW_OP_push_object_address`` in
312 :ref:`amdgpu-dwarf-general-location-description-operations`.
314 2.8 General Support for Address Spaces
315 --------------------------------------
317 AMDGPU needs to be able to describe addresses that are in different kinds of
318 memory. Optimized code may need to describe a variable that resides in pieces
319 that are in different kinds of storage which may include parts of registers,
320 memory that is in a mixture of memory kinds, implicit values, or be undefined.
322 DWARF has the concept of segment addresses. However, the segment cannot be
323 specified within a DWARF expression, which is only able to specify the offset
324 portion of a segment address. The segment index is only provided by the entity
325 that specifies the DWARF expression. Therefore, the segment index is a property
326 that can only be put on complete objects, such as a variable. That makes it only
327 suitable for describing an entity (such as variable or subprogram code) that is
328 in a single kind of memory.
330 AMDGPU uses multiple address spaces. For example, a variable may be allocated in
331 a register that is partially spilled to the call stack which is in the private
332 address space, and partially spilled to the local address space. DWARF mentions
333 address spaces, for example as an argument to the ``DW_OP_xderef*`` operations.
334 A new section that defines address spaces is added (see
335 :ref:`amdgpu-dwarf-address-spaces`).
337 A new attribute ``DW_AT_LLVM_address_space`` is added to pointer and reference
338 types (see :ref:`amdgpu-dwarf-type-modifier-entries`). This allows the compiler
339 to specify which address space is being used to represent the pointer or
342 DWARF uses the concept of an address in many expression operations but does not
343 define how it relates to address spaces. For example,
344 ``DW_OP_push_object_address`` pushes the address of an object. Other contexts
345 implicitly push an address on the stack before evaluating an expression. For
346 example, the ``DW_AT_use_location`` attribute of the
347 ``DW_TAG_ptr_to_member_type``. The expression belongs to a source language type
348 which may apply to objects allocated in different kinds of storage. Therefore,
349 it is desirable that the expression that uses the address can do so without
350 regard to what kind of storage it specifies, including the address space of a
351 memory location description. For example, a pointer to member value may want to
352 be applied to an object that may reside in any address space.
354 The DWARF ``DW_OP_xderef*`` operations allow a value to be converted into an
355 address of a specified address space which is then read. But it provides no
356 way to create a memory location description for an address in the non-default
357 address space. For example, AMDGPU variables can be allocated in the local
358 address space at a fixed address.
360 The ``DW_OP_LLVM_form_aspace_address`` (see
361 :ref:`amdgpu-dwarf-memory-location-description-operations`) operation is defined
362 to create a memory location description from an address and address space. If
363 can be used to specify the location of a variable that is allocated in a
364 specific address space. This allows the size of addresses in an address space to
365 be larger than the generic type. It also allows a consumer great implementation
366 freedom. It allows the implicit conversion back to a value to be limited only to
367 the default address space to maintain compatibility with DWARF Version 5. For
368 other address spaces the producer can use the new operations that explicitly
369 specify the address space.
371 In contrast, if the ``DW_OP_LLVM_form_aspace_address`` operation had been
372 defined to produce a value, and an implicit conversion to a memory location
373 description was defined, then it would be limited to the size of the generic
374 type (which matches the size of the default address space). An implementation
375 would likely have to use *reserved ranges* of value to represent different
376 address spaces. Such a value would likely not match any address value in the
377 actual hardware. That would require the consumer to have special treatment for
380 ``DW_OP_breg*`` treats the register as containing an address in the default
381 address space. A ``DW_OP_LLVM_aspace_bregx`` (see
382 :ref:`amdgpu-dwarf-memory-location-description-operations`) operation is added
383 to allow the address space of the address held in a register to be specified.
385 Similarly, ``DW_OP_implicit_pointer`` treats its implicit pointer value as being
386 in the default address space. A ``DW_OP_LLVM_aspace_implicit_pointer``
387 (:ref:`amdgpu-dwarf-implicit-location-description-operations`) operation is
388 added to allow the address space to be specified.
390 Almost all uses of addresses in DWARF are limited to defining location
391 descriptions, or to be dereferenced to read memory. The exception is
392 ``DW_CFA_val_offset`` which uses the address to set the value of a register. In
393 order to support address spaces, the CFA DWARF expression is defined to be a
394 memory location description. This allows it to specify an address space which is
395 used to convert the offset address back to an address in that address space. See
396 :ref:`amdgpu-dwarf-call-frame-information`.
398 This approach of extending memory location descriptions to support address
399 spaces, allows all existing DWARF Version 5 expressions to have the identical
400 semantics. It allows the compiler to explicitly specify the address space it is
401 using. For example, a compiler could choose to access private memory in a
402 swizzled manner when mapping a source language thread to the lane of a wavefront
403 in a SIMT manner. Or a compiler could choose to access it in an unswizzled
404 manner if mapping the same language with the wavefront being the thread.
406 It also allows the compiler to mix the address space it uses to access private
407 memory. For example, for SIMT it can still spill entire vector registers in an
408 unswizzled manner, while using a swizzled private memory for SIMT variable
411 This approach also allows memory location descriptions for different address
412 spaces to be combined using the regular ``DW_OP_*piece`` operations.
414 Location descriptions are an abstraction of storage. They give freedom to the
415 consumer on how to implement them. They allow the address space to encode lane
416 information so they can be used to read memory with only the memory location
417 description and no extra information. The same set of operations can operate on
418 locations independent of their kind of storage. The ``DW_OP_deref*`` therefore
419 can be used on any storage kind, including memory location descriptions of
420 different address spaces. Therefore, the ``DW_OP_xderef*`` operations are
421 unnecessary, except to become a more compact way to encode a non-default address
422 space address followed by dereferencing it. See
423 :ref:`amdgpu-dwarf-general-operations`.
425 2.9 Support for Vector Base Types
426 ---------------------------------
428 The vector registers of the AMDGPU are represented as their full wavefront
429 size, meaning the wavefront size times the dword size. This reflects the
430 actual hardware and allows the compiler to generate DWARF for languages that
431 map a thread to the complete wavefront. It also allows more efficient DWARF to
432 be generated to describe the CFI as only a single expression is required for
433 the whole vector register, rather than a separate expression for each lane's
434 dword of the vector register. It also allows the compiler to produce DWARF
435 that indexes the vector register if it spills scalar registers into portions
436 of a vector register.
438 Since DWARF stack value entries have a base type and AMDGPU registers are a
439 vector of dwords, the ability to specify that a base type is a vector is
442 See ``DW_AT_LLVM_vector_size`` in :ref:`amdgpu-dwarf-base-type-entries`.
444 .. _amdgpu-dwarf-operation-to-create-vector-composite-location-descriptions:
446 2.10 DWARF Operations to Create Vector Composite Location Descriptions
447 ----------------------------------------------------------------------
449 AMDGPU optimized code may spill vector registers to non-global address space
450 memory, and this spilling may be done only for SIMT lanes that are active on
451 entry to the subprogram. To support this the CFI rule for the partially spilled
452 register needs to use an expression that uses the EXEC register as a bit mask to
453 select between the register (for inactive lanes) and the stack spill location
454 (for active lanes that are spilled). This needs to evaluate to a location
455 description, and not a value, as a debugger needs to change the value if the
456 user assigns to the variable.
458 Another usage is to create an expression that evaluates to provide a vector of
459 logical PCs for active and inactive lanes in a SIMT execution model. Again the
460 EXEC register is used to select between active and inactive PC values. In order
461 to represent a vector of PC values, a way to create a composite location
462 description that is a vector of a single location is used.
464 It may be possible to use existing DWARF to incrementally build the composite
465 location description, possibly using the DWARF operations for control flow to
466 create a loop. However, for the AMDGPU that would require loop iteration of 64.
467 A concern is that the resulting DWARF would have a significant size and would be
468 reasonably common as it is needed for every vector register that is spilled in a
469 function. AMDGPU can have up to 512 vector registers. Another concern is the
470 time taken to evaluate such non-trivial expressions repeatedly.
472 To avoid these issues, a composite location description that can be created as a
473 masked select is proposed. In addition, an operation that creates a composite
474 location description that is a vector on another location description is needed.
475 These operations generate the composite location description using a single
476 DWARF operation that combines all lanes of the vector in one step. The DWARF
477 expression is more compact, and can be evaluated by a consumer far more
480 An example that uses these operations is referenced in the
481 :ref:`amdgpu-dwarf-further-examples` appendix.
483 See ``DW_OP_LLVM_select_bit_piece`` and ``DW_OP_LLVM_extend`` in
484 :ref:`amdgpu-dwarf-composite-location-description-operations`.
486 2.11 DWARF Operation to Access Call Frame Entry Registers
487 ---------------------------------------------------------
490 :ref:`amdgpu-dwarf-operation-to-create-vector-composite-location-descriptions`,
491 a DWARF expression involving the set of SIMT lanes active on entry to a
492 subprogram is required. The SIMT active lane mask may be held in a register that
493 is modified as the subprogram executes. However, its value may be saved on entry
496 The Call Frame Information (CFI) already encodes such register saving, so it is
497 more efficient to provide an operation to return the location of a saved
498 register than have to generate a loclist to describe the same information. This
499 is now possible since
500 :ref:`amdgpu-dwarf-allow-location-description-on-the-dwarf-evaluation-stack`
501 allows location descriptions on the stack.
503 See ``DW_OP_LLVM_call_frame_entry_reg`` in
504 :ref:`amdgpu-dwarf-general-location-description-operations` and
505 :ref:`amdgpu-dwarf-call-frame-information`.
507 2.12 Support for Source Languages Mapped to SIMT Hardware
508 ---------------------------------------------------------
510 If the source language is mapped onto the AMDGPU wavefronts in a SIMT manner,
511 then the variable DWARF location expressions must compute the location for a
512 single lane of the wavefront. Therefore, a DWARF operation is required to denote
513 the current lane, much like ``DW_OP_push_object_address`` denotes the current
514 object. See ``DW_OP_LLVM_push_lane`` in :ref:`amdgpu-dwarf-literal-operations`.
516 In addition, a way is needed for the compiler to communicate how many source
517 language threads of execution are mapped to a target architecture thread's SIMT
518 lanes. See ``DW_AT_LLVM_lanes`` in :ref:`amdgpu-dwarf-low-level-information`.
520 .. _amdgpu-dwarf-support-for-divergent-control-flow-of-simt-hardware:
522 2.13 Support for Divergent Control Flow of SIMT Hardware
523 --------------------------------------------------------
525 If the source language is mapped onto the AMDGPU wavefronts in a SIMT manner the
526 compiler can use the AMDGPU execution mask register to control which lanes are
527 active. To describe the conceptual location of non-active lanes requires an
528 attribute that has an expression that computes the source location PC for each
531 For efficiency, the expression calculates the source location the wavefront as a
532 whole. This can be done using the ``DW_OP_LLVM_select_bit_piece`` (see
533 :ref:`amdgpu-dwarf-operation-to-create-vector-composite-location-descriptions`)
536 The AMDGPU may update the execution mask to perform whole wavefront operations.
537 Therefore, there is a need for an attribute that computes the current active
538 lane mask. This can have an expression that may evaluate to the SIMT active lane
539 mask register or to a saved mask when in whole wavefront execution mode.
541 An example that uses these attributes is referenced in the
542 :ref:`amdgpu-dwarf-further-examples` appendix.
544 See ``DW_AT_LLVM_lane_pc`` and ``DW_AT_LLVM_active_lane`` in
545 :ref:`amdgpu-dwarf-composite-location-description-operations`.
547 2.14 Define Source Language Memory Classes
548 -------------------------------------------
550 AMDGPU supports languages, such as OpenCL [:ref:`OpenCL <amdgpu-dwarf-OpenCL>`],
551 that define source language memory classes. Support is added to define language
552 specific memory spaces so they can be used in a consistent way by consumers.
554 Support for using memory spaces in defining source language types and data
555 object allocation is also added.
557 See :ref:`amdgpu-dwarf-memory-spaces`.
559 2.15 Define Augmentation Strings to Support Multiple Extensions
560 ---------------------------------------------------------------
562 A ``DW_AT_LLVM_augmentation`` attribute is added to a compilation unit debugger
563 information entry to indicate that there is additional target architecture
564 specific information in the debugging information entries of that compilation
565 unit. This allows a consumer to know what extensions are present in the debugger
566 information entries as is possible with the augmentation string of other
569 The format that should be used for an augmentation string is also recommended.
570 This allows a consumer to parse the string when it contains information from
571 multiple vendors. Augmentation strings occur in the ``DW_AT_LLVM_augmentation``
572 attribute, in the lookup by name table, and in the CFI Common Information Entry
575 See :ref:`amdgpu-dwarf-full-and-partial-compilation-unit-entries`,
576 :ref:`amdgpu-dwarf-name-index-section-header`, and
577 :ref:`amdgpu-dwarf-structure_of-call-frame-information`.
579 2.16 Support Embedding Source Text for Online Compilation
580 ---------------------------------------------------------
582 AMDGPU supports programming languages that include online compilation where the
583 source text may be created at runtime. For example, the OpenCL and HIP language
584 runtimes support online compilation. To support is, a way to embed the source
585 text in the debug information is provided.
587 See :ref:`amdgpu-dwarf-line-number-information`.
589 2.17 Allow MD5 Checksums to be Optionally Present
590 -------------------------------------------------
592 In DWARF Version 5 the file timestamp and file size can be optional, but if the
593 MD5 checksum is present it must be valid for all files. This is a problem if
594 using link time optimization to combine compilation units where some have MD5
595 checksums and some do not. Therefore, sSupport to allow MD5 checksums to be
596 optionally present in the line table is added.
598 See :ref:`amdgpu-dwarf-line-number-information`.
600 2.18 Add the HIP Programing Language
601 ------------------------------------
603 The HIP programming language [:ref:`HIP <amdgpu-dwarf-HIP>`], which is supported
604 by the AMDGPU, is added.
606 See :ref:`amdgpu-dwarf-language-names-table`.
608 2.19 Support for Source Language Optimizations that Result in Concurrent Iteration Execution
609 --------------------------------------------------------------------------------------------
611 A compiler can perform loop optimizations that result in the generated code
612 executing multiple iterations concurrently. For example, software pipelining
613 schedules multiple iterations in an interleaved fashion to allow the
614 instructions of one iteration to hide the latencies of the instructions of
615 another iteration. Another example is vectorization that can exploit SIMD
616 hardware to allow a single instruction to execute multiple iterations using
619 Note that although this is similar to SIMT execution, the way a client debugger
620 uses the information is fundamentally different. In SIMT execution the debugger
621 needs to present the concurrent execution as distinct source language threads
622 that the user can list and switch focus between. With iteration concurrency
623 optimizations, such as software pipelining and vectorized SIMD, the debugger
624 must not present the concurrency as distinct source language threads. Instead,
625 it must inform the user that multiple loop iterations are executing in parallel
626 and allow the user to select between them.
628 In general, SIMT execution fixes the number of concurrent executions per target
629 architecture thread. However, both software pipelining and SIMD vectorization
630 may vary the number of concurrent iterations for different loops executed by a
631 single source language thread.
633 It is possible for the compiler to use both SIMT concurrency and iteration
634 concurrency techniques in the code of a single source language thread.
636 Therefore, a DWARF operation is required to denote the current concurrent
637 iteration instance, much like ``DW_OP_push_object_address`` denotes the current
638 object. See ``DW_OP_LLVM_push_iteration`` in
639 :ref:`amdgpu-dwarf-literal-operations`.
641 In addition, a way is needed for the compiler to communicate how many source
642 language loop iterations are executing concurrently. See
643 ``DW_AT_LLVM_iterations`` in :ref:`amdgpu-dwarf-low-level-information`.
645 2.20 DWARF Operation to Create Runtime Overlay Composite Location Description
646 -----------------------------------------------------------------------------
648 It is common in SIMD vectorization for the compiler to generate code that
649 promotes portions of an array into vector registers. For example, if the
650 hardware has vector registers with 8 elements, and 8 wide SIMD instructions, the
651 compiler may vectorize a loop so that is executes 8 iterations concurrently for
652 each vectorized loop iteration.
654 On the first iteration of the generated vectorized loop, iterations 0 to 7 of
655 the source language loop will be executed using SIMD instructions. Then on the
656 next iteration of the generated vectorized loop, iteration 8 to 15 will be
659 If the source language loop accesses an array element based on the loop
660 iteration index, the compiler may read the element into a register for the
661 duration of that iteration. Next iteration it will read the next element into
662 the register, and so on. With SIMD, this generalizes to the compiler reading
663 array elements 0 to 7 into a vector register on the first vectorized loop
664 iteration, then array elements 8 to 15 on the next iteration, and so on.
666 The DWARF location description for the array needs to express that all elements
667 are in memory, except the slice that has been promoted to the vector register.
668 The starting position of the slice is a runtime value based on the iteration
669 index modulo the vectorization size. This cannot be expressed by ``DW_OP_piece``
670 and ``DW_OP_bit_piece`` which only allow constant offsets to be expressed.
672 Therefore, a new operator is defined that takes two location descriptions, an
673 offset and a size, and creates a composite that effectively uses the second
674 location description as an overlay of the first, positioned according to the
675 offset and size. See ``DW_OP_LLVM_overlay`` and ``DW_OP_LLVM_bit_overlay`` in
676 :ref:`amdgpu-dwarf-composite-location-description-operations`.
678 Consider an array that has been partially registerized such that the currently
679 processed elements are held in registers, whereas the remainder of the array
680 remains in memory. Consider the loop in this C function, for example:
685 extern void foo(uint32_t dst[], uint32_t src[], int len) {
686 for (int i = 0; i < len; ++i)
690 Inside the loop body, the machine code loads ``src[i]`` and ``dst[i]`` into
691 registers, adds them, and stores the result back into ``dst[i]``.
693 Considering the location of ``dst`` and ``src`` in the loop body, the elements
694 ``dst[i]`` and ``src[i]`` would be located in registers, all other elements are
695 located in memory. Let register ``R0`` contain the base address of ``dst``,
696 register ``R1`` contain ``i``, and register ``R2`` contain the registerized
697 ``dst[i]`` element. We can describe the location of ``dst`` as a memory location
698 with a register location overlaid at a runtime offset involving ``i``:
703 // 1. Memory location description of dst elements located in memory:
706 // 2. Register location description of element dst[i] is located in R2:
709 // 3. Offset of the register within the memory of dst:
714 // 4. The size of the register element:
717 // 5. Make a composite location description for dst that is the memory #1 with
718 // the register #2 positioned as an overlay at offset #3 of size #4:
721 2.21 Support for Source Language Memory Spaces
722 ----------------------------------------------
724 AMDGPU supports languages, such as OpenCL, that define source language memory
725 spaces. Support is added to define language specific memory spaces so they can
726 be used in a consistent way by consumers. See :ref:`amdgpu-dwarf-memory-spaces`.
728 A new attribute ``DW_AT_LLVM_memory_space`` is added to support using memory
729 spaces in defining source language pointer and reference types (see
730 :ref:`amdgpu-dwarf-type-modifier-entries`) and data object allocation (see
731 :ref:`amdgpu-dwarf-data-object-entries`).
733 2.22 Expression Operation Vendor Extensibility Opcode
734 -----------------------------------------------------
736 The vendor extension encoding space for DWARF expression operations
737 accommodates only 32 unique operations. In practice, the lack of a central
738 registry and a desire for backwards compatibility means vendor extensions are
739 never retired, even when standard versions are accepted into DWARF proper. This
740 has produced a situation where the effective encoding space available for new
741 vendor extensions is miniscule today.
743 To expand this encoding space a new DWARF operation ``DW_OP_LLVM_user`` is
744 added which acts as a "prefix" for vendor extensions. It is followed by a
745 ULEB128 encoded vendor extension opcode, which is then followed by the operands
746 of the corresponding vendor extension operation.
748 This approach allows all remaining operations defined in these extensions to be
749 encoded without conflicting with existing vendor extensions.
751 See ``DW_OP_LLVM_user`` in :ref:`amdgpu-dwarf-vendor-extensions-operations`.
753 .. _amdgpu-dwarf-changes-relative-to-dwarf-version-5:
755 A. Changes Relative to DWARF Version 5
756 ======================================
760 This appendix provides changes relative to DWARF Version 5. It has been
761 defined such that it is backwards compatible with DWARF Version 5.
762 Non-normative text is shown in *italics*. The section numbers generally
763 correspond to those in the DWARF Version 5 standard unless specified
764 otherwise. Definitions are given for the additional operations, as well as
765 clarifying how existing expression operations, CFI operations, and attributes
766 behave with respect to generalized location descriptions that support address
767 spaces and multiple places.
769 The names for the new operations, attributes, and constants include "\
770 ``LLVM``\ " and are encoded with vendor specific codes so these extensions
771 can be implemented as an LLVM vendor extension to DWARF Version 5. New
772 operations other than ``DW_OP_LLVM_user`` are "prefixed" by
773 ``DW_OP_LLVM_user`` to make enough encoding space available for their
778 Notes are included to describe how the changes are to be applied to the
779 DWARF Version 5 standard. They also describe rational and issues that may
780 need further consideration.
782 A.2 General Description
783 -----------------------
785 A.2.2 Attribute Types
786 ~~~~~~~~~~~~~~~~~~~~~
790 This augments DWARF Version 5 section 2.2 and Table 2.2.
792 The following table provides the additional attributes.
794 .. table:: Attribute names
795 :name: amdgpu-dwarf-attribute-names-table
797 ============================ ====================================
799 ============================ ====================================
800 ``DW_AT_LLVM_active_lane`` SIMT active lanes (see :ref:`amdgpu-dwarf-low-level-information`)
801 ``DW_AT_LLVM_augmentation`` Compilation unit augmentation string (see :ref:`amdgpu-dwarf-full-and-partial-compilation-unit-entries`)
802 ``DW_AT_LLVM_lane_pc`` SIMT lane program location (see :ref:`amdgpu-dwarf-low-level-information`)
803 ``DW_AT_LLVM_lanes`` SIMT lane count (see :ref:`amdgpu-dwarf-low-level-information`)
804 ``DW_AT_LLVM_iterations`` Concurrent iteration count (see :ref:`amdgpu-dwarf-low-level-information`)
805 ``DW_AT_LLVM_vector_size`` Base type vector size (see :ref:`amdgpu-dwarf-base-type-entries`)
806 ``DW_AT_LLVM_address_space`` Architecture specific address space (see :ref:`amdgpu-dwarf-address-spaces`)
807 ``DW_AT_LLVM_memory_space`` Pointer or reference types (see 5.3 "Type Modifier Entries")
808 Data objects (see 4.1 "Data Object Entries")
809 ============================ ====================================
811 .. _amdgpu-dwarf-expressions:
813 A.2.5 DWARF Expressions
814 ~~~~~~~~~~~~~~~~~~~~~~~
818 This section, and its nested sections, replaces DWARF Version 5 section 2.5
819 and section 2.6. The new DWARF expression operation extensions are defined as
820 well as clarifying the extensions to already existing DWARF Version 5
821 operations. It is based on the text of the existing DWARF Version 5 standard.
823 DWARF expressions describe how to compute a value or specify a location.
825 *The evaluation of a DWARF expression can provide the location of an object, the
826 value of an array bound, the length of a dynamic string, the desired value
829 If the evaluation of a DWARF expression does not encounter an error, then it can
830 either result in a value (see :ref:`amdgpu-dwarf-expression-value`) or a
831 location description (see :ref:`amdgpu-dwarf-location-description`). When a
832 DWARF expression is evaluated, it may be specified whether a value or location
833 description is required as the result kind.
835 If a result kind is specified, and the result of the evaluation does not match
836 the specified result kind, then the implicit conversions described in
837 :ref:`amdgpu-dwarf-memory-location-description-operations` are performed if
838 valid. Otherwise, the DWARF expression is ill-formed.
840 If the evaluation of a DWARF expression encounters an evaluation error, then the
841 result is an evaluation error.
845 Decided to define the concept of an evaluation error. An alternative is to
846 introduce an undefined value base type in a similar way to location
847 descriptions having an undefined location description. Then operations that
848 encounter an evaluation error can return the undefined location description or
849 value with an undefined base type.
851 All operations that act on values would return an undefined entity if given an
852 undefined value. The expression would then always evaluate to completion, and
853 can be tested to determine if it is an undefined entity.
855 However, this would add considerable additional complexity and does not match
856 that GDB throws an exception when these evaluation errors occur.
858 If a DWARF expression is ill-formed, then the result is undefined.
860 The following sections detail the rules for when a DWARF expression is
861 ill-formed or results in an evaluation error.
863 A DWARF expression can either be encoded as an operation expression (see
864 :ref:`amdgpu-dwarf-operation-expressions`), or as a location list expression
865 (see :ref:`amdgpu-dwarf-location-list-expressions`).
867 .. _amdgpu-dwarf-expression-evaluation-context:
869 A.2.5.1 DWARF Expression Evaluation Context
870 +++++++++++++++++++++++++++++++++++++++++++
872 A DWARF expression is evaluated in a context that can include a number of
873 context elements. If multiple context elements are specified then they must be
874 self consistent or the result of the evaluation is undefined. The context
875 elements that can be specified are:
877 *A current result kind*
879 The kind of result required by the DWARF expression evaluation. If specified
880 it can be a location description or a value.
884 The target architecture thread identifier. For source languages that are not
885 implemented using a SIMT execution model, this corresponds to the source
886 program thread of execution for which a user presented expression is currently
887 being evaluated. For source languages that are implemented using a SIMT
888 execution model, this together with the current lane corresponds to the source
889 program thread of execution for which a user presented expression is currently
892 It is required for operations that are related to target architecture threads.
894 *For example, the* ``DW_OP_regval_type`` *operation, or the*
895 ``DW_OP_form_tls_address`` *and* ``DW_OP_LLVM_form_aspace_address``
896 *operations when given an address space that is target architecture thread
901 The 0 based SIMT lane identifier to be used in evaluating a user presented
902 expression. This applies to source languages that are implemented for a target
903 architecture using a SIMT execution model. These implementations map source
904 language threads of execution to lanes of the target architecture threads.
906 It is required for operations that are related to SIMT lanes.
908 *For example, the* ``DW_OP_LLVM_push_lane`` *operation and*
909 ``DW_OP_LLVM_form_aspace_address`` *operation when given an address space that
910 is SIMT lane specific.*
912 If specified, it must be consistent with the value of the ``DW_AT_LLVM_lanes``
913 attribute of the subprogram corresponding to context's frame and program
914 location. It is consistent if the value is greater than or equal to 0 and less
915 than the, possibly default, value of the ``DW_AT_LLVM_lanes`` attribute.
916 Otherwise the result is undefined.
918 *A current iteration*
920 The 0 based source language iteration instance to be used in evaluating a user
921 presented expression. This applies to target architectures that support
922 optimizations that result in executing multiple source language loop iterations
925 *For example, software pipelining and SIMD vectorization.*
927 It is required for operations that are related to source language loop
930 *For example, the* ``DW_OP_LLVM_push_iteration`` *operation.*
932 If specified, it must be consistent with the value of the
933 ``DW_AT_LLVM_iterations`` attribute of the subprogram corresponding to
934 context's frame and program location. It is consistent if the value is greater
935 than or equal to 0 and less than the, possibly default, value of the
936 ``DW_AT_LLVM_iterations`` attribute. Otherwise the result is undefined.
938 *A current call frame*
940 The target architecture call frame identifier. It identifies a call frame that
941 corresponds to an active invocation of a subprogram in the current thread. It
942 is identified by its address on the call stack. The address is referred to as
943 the Canonical Frame Address (CFA). The call frame information is used to
944 determine the CFA for the call frames of the current thread's call stack (see
945 :ref:`amdgpu-dwarf-call-frame-information`).
947 It is required for operations that specify target architecture registers to
948 support virtual unwinding of the call stack.
950 *For example, the* ``DW_OP_*reg*`` *operations.*
952 If specified, it must be an active call frame in the current thread. If the
953 current lane is specified, then that lane must have been active on entry to
954 the call frame (see the ``DW_AT_LLVM_lane_pc`` attribute). Otherwise the
957 If it is the currently executing call frame, then it is termed the top call
960 *A current program location*
962 The target architecture program location corresponding to the current call
963 frame of the current thread.
965 The program location of the top call frame is the target architecture program
966 counter for the current thread. The call frame information is used to obtain
967 the value of the return address register to determine the program location of
968 the other call frames (see :ref:`amdgpu-dwarf-call-frame-information`).
970 It is required for the evaluation of location list expressions to select
971 amongst multiple program location ranges. It is required for operations that
972 specify target architecture registers to support virtual unwinding of the call
973 stack (see :ref:`amdgpu-dwarf-call-frame-information`).
977 * If the current lane is not specified:
979 * If the current call frame is the top call frame, it must be the current
980 target architecture program location.
982 * If the current call frame F is not the top call frame, it must be the
983 program location associated with the call site in the current caller frame
984 F that invoked the callee frame.
986 * If the current lane is specified and the architecture program location LPC
987 computed by the ``DW_AT_LLVM_lane_pc`` attribute for the current lane is not
988 the undefined location description (indicating the lane was not active on
989 entry to the call frame), it must be LPC.
991 * Otherwise the result is undefined.
993 *A current compilation unit*
995 The compilation unit debug information entry that contains the DWARF expression
998 It is required for operations that reference debug information associated with
999 the same compilation unit, including indicating if such references use the
1000 32-bit or 64-bit DWARF format. It can also provide the default address space
1001 address size if no current target architecture is specified.
1003 *For example, the* ``DW_OP_constx`` *and* ``DW_OP_addrx`` *operations.*
1005 *Note that this compilation unit may not be the same as the compilation unit
1006 determined from the loaded code object corresponding to the current program
1007 location. For example, the evaluation of the expression E associated with a*
1008 ``DW_AT_location`` *attribute of the debug information entry operand of the*
1009 ``DW_OP_call*`` *operations is evaluated with the compilation unit that
1010 contains E and not the one that contains the* ``DW_OP_call*`` *operation
1013 *A current target architecture*
1015 The target architecture.
1017 It is required for operations that specify target architecture specific
1020 *For example, target architecture specific entities include DWARF register
1021 identifiers, DWARF lane identifiers, DWARF address space identifiers, the
1022 default address space, and the address space address sizes.*
1026 * If the current frame is specified, then the current target architecture must
1027 be the same as the target architecture of the current frame.
1029 * If the current frame is specified and is the top frame, and if the current
1030 thread is specified, then the current target architecture must be the same
1031 as the target architecture of the current thread.
1033 * If the current compilation unit is specified, then the current target
1034 architecture default address space address size must be the same as the
1035 ``address_size`` field in the header of the current compilation unit and any
1036 associated entry in the ``.debug_aranges`` section.
1038 * If the current program location is specified, then the current target
1039 architecture must be the same as the target architecture of any line number
1040 information entry (see :ref:`amdgpu-dwarf-line-number-information`)
1041 corresponding to the current program location.
1043 * If the current program location is specified, then the current target
1044 architecture default address space address size must be the same as the
1045 ``address_size`` field in the header of any entry corresponding to the
1046 current program location in the ``.debug_addr``, ``.debug_line``,
1047 ``.debug_rnglists``, ``.debug_rnglists.dwo``, ``.debug_loclists``, and
1048 ``.debug_loclists.dwo`` sections.
1050 * Otherwise the result is undefined.
1054 The location description of a program object.
1056 It is required for the ``DW_OP_push_object_address`` operation.
1058 *For example, the* ``DW_AT_data_location`` *attribute on type debug
1059 information entries specifies the program object corresponding to a runtime
1060 descriptor as the current object when it evaluates its associated expression.*
1062 The result is undefined if the location description is invalid (see
1063 :ref:`amdgpu-dwarf-location-description`).
1067 This is a list of values or location descriptions that will be pushed on the
1068 operation expression evaluation stack in the order provided before evaluation
1069 of an operation expression starts.
1071 Some debugger information entries have attributes that evaluate their DWARF
1072 expression value with initial stack entries. In all other cases the initial
1075 The result is undefined if any location descriptions are invalid (see
1076 :ref:`amdgpu-dwarf-location-description`).
1078 If the evaluation requires a context element that is not specified, then the
1079 result of the evaluation is an error.
1081 *A DWARF expression for a location description may be able to be evaluated
1082 without a thread, lane, call frame, program location, or architecture context.
1083 For example, the location of a global variable may be able to be evaluated
1084 without such context. If the expression evaluates with an error then it may
1085 indicate the variable has been optimized and so requires more context.*
1087 *The DWARF expression for call frame information (see*
1088 :ref:`amdgpu-dwarf-call-frame-information`\ *) operations are restricted to
1089 those that do not require the compilation unit context to be specified.*
1091 The DWARF is ill-formed if all the ``address_size`` fields in the headers of all
1092 the entries in the ``.debug_info``, ``.debug_addr``, ``.debug_line``,
1093 ``.debug_rnglists``, ``.debug_rnglists.dwo``, ``.debug_loclists``, and
1094 ``.debug_loclists.dwo`` sections corresponding to any given program location do
1097 .. _amdgpu-dwarf-expression-value:
1099 A.2.5.2 DWARF Expression Value
1100 ++++++++++++++++++++++++++++++
1102 A value has a type and a literal value. It can represent a literal value of any
1103 supported base type of the target architecture. The base type specifies the
1104 size, encoding, and endianity of the literal value.
1108 It may be desirable to add an implicit pointer base type encoding. It would be
1109 used for the type of the value that is produced when the ``DW_OP_deref*``
1110 operation retrieves the full contents of an implicit pointer location storage
1111 created by the ``DW_OP_implicit_pointer`` or
1112 ``DW_OP_LLVM_aspace_implicit_pointer`` operations. The literal value would
1113 record the debugging information entry and byte displacement specified by the
1114 associated ``DW_OP_implicit_pointer`` or
1115 ``DW_OP_LLVM_aspace_implicit_pointer`` operations.
1117 There is a distinguished base type termed the generic type, which is an integral
1118 type that has the size of an address in the target architecture default address
1119 space, a target architecture defined endianity, and unspecified signedness.
1121 *The generic type is the same as the unspecified type used for stack operations
1122 defined in DWARF Version 4 and before.*
1124 An integral type is a base type that has an encoding of ``DW_ATE_signed``,
1125 ``DW_ATE_signed_char``, ``DW_ATE_unsigned``, ``DW_ATE_unsigned_char``,
1126 ``DW_ATE_boolean``, or any target architecture defined integral encoding in the
1127 inclusive range ``DW_ATE_lo_user`` to ``DW_ATE_hi_user``.
1131 It is unclear if ``DW_ATE_address`` is an integral type. GDB does not seem to
1132 consider it as integral.
1134 .. _amdgpu-dwarf-location-description:
1136 A.2.5.3 DWARF Location Description
1137 ++++++++++++++++++++++++++++++++++
1139 *Debugging information must provide consumers a way to find the location of
1140 program variables, determine the bounds of dynamic arrays and strings, and
1141 possibly to find the base address of a subprogram’s call frame or the return
1142 address of a subprogram. Furthermore, to meet the needs of recent computer
1143 architectures and optimization techniques, debugging information must be able to
1144 describe the location of an object whose location changes over the object’s
1145 lifetime, and may reside at multiple locations simultaneously during parts of an
1148 Information about the location of program objects is provided by location
1151 Location descriptions can consist of one or more single location descriptions.
1153 A single location description specifies the location storage that holds a
1154 program object and a position within the location storage where the program
1155 object starts. The position within the location storage is expressed as a bit
1156 offset relative to the start of the location storage.
1158 A location storage is a linear stream of bits that can hold values. Each
1159 location storage has a size in bits and can be accessed using a zero-based bit
1160 offset. The ordering of bits within a location storage uses the bit numbering
1161 and direction conventions that are appropriate to the current language on the
1162 target architecture.
1164 There are five kinds of location storage:
1166 *memory location storage*
1167 Corresponds to the target architecture memory address spaces.
1169 *register location storage*
1170 Corresponds to the target architecture registers.
1172 *implicit location storage*
1173 Corresponds to fixed values that can only be read.
1175 *undefined location storage*
1176 Indicates no value is available and therefore cannot be read or written.
1178 *composite location storage*
1179 Allows a mixture of these where some bits come from one location storage and
1180 some from another location storage, or from disjoint parts of the same
1185 It may be better to add an implicit pointer location storage kind used by the
1186 ``DW_OP_implicit_pointer`` and ``DW_OP_LLVM_aspace_implicit_pointer``
1187 operations. It would specify the debugger information entry and byte offset
1188 provided by the operations.
1190 *Location descriptions are a language independent representation of addressing
1193 * *They can be the result of evaluating a debugger information entry attribute
1194 that specifies an operation expression of arbitrary complexity. In this usage
1195 they can describe the location of an object as long as its lifetime is either
1196 static or the same as the lexical block (see
1197 :ref:`amdgpu-dwarf-lexical-block-entries`) that owns it, and it does not move
1198 during its lifetime.*
1200 * *They can be the result of evaluating a debugger information entry attribute
1201 that specifies a location list expression. In this usage they can describe the
1202 location of an object that has a limited lifetime, changes its location during
1203 its lifetime, or has multiple locations over part or all of its lifetime.*
1205 If a location description has more than one single location description, the
1206 DWARF expression is ill-formed if the object value held in each single location
1207 description's position within the associated location storage is not the same
1208 value, except for the parts of the value that are uninitialized.
1210 *A location description that has more than one single location description can
1211 only be created by a location list expression that has overlapping program
1212 location ranges, or certain expression operations that act on a location
1213 description that has more than one single location description. There are no
1214 operation expression operations that can directly create a location description
1215 with more than one single location description.*
1217 *A location description with more than one single location description can be
1218 used to describe objects that reside in more than one piece of storage at the
1219 same time. An object may have more than one location as a result of
1220 optimization. For example, a value that is only read may be promoted from memory
1221 to a register for some region of code, but later code may revert to reading the
1222 value from memory as the register may be used for other purposes. For the code
1223 region where the value is in a register, any change to the object value must be
1224 made in both the register and the memory so both regions of code will read the
1227 *A consumer of a location description with more than one single location
1228 description can read the object's value from any of the single location
1229 descriptions (since they all refer to location storage that has the same value),
1230 but must write any changed value to all the single location descriptions.*
1232 The evaluation of an expression may require context elements to create a
1233 location description. If such a location description is accessed, the storage it
1234 denotes is that associated with the context element values specified when the
1235 location description was created, which may differ from the context at the time
1238 *For example, creating a register location description requires the thread
1239 context: the location storage is for the specified register of that thread.
1240 Creating a memory location description for an address space may required a
1241 thread and a lane context: the location storage is the memory associated with
1242 that thread and lane.*
1244 If any of the context elements required to create a location description change,
1245 the location description becomes invalid and accessing it is undefined.
1247 *Examples of context that can invalidate a location description are:*
1249 * *The thread context is required and execution causes the thread to terminate.*
1250 * *The call frame context is required and further execution causes the call
1251 frame to return to the calling frame.*
1252 * *The program location is required and further execution of the thread occurs.
1253 That could change the location list entry or call frame information entry that
1255 * *An operation uses call frame information:*
1257 * *Any of the frames used in the virtual call frame unwinding return.*
1258 * *The top call frame is used, the program location is used to select the call
1259 frame information entry, and further execution of the thread occurs.*
1261 *A DWARF expression can be used to compute a location description for an object.
1262 A subsequent DWARF expression evaluation can be given the object location
1263 description as the object context or initial stack context to compute a
1264 component of the object. The final result is undefined if the object location
1265 description becomes invalid between the two expression evaluations.*
1267 A change of a thread's program location may not make a location description
1268 invalid, yet may still render it as no longer meaningful. Accessing such a
1269 location description, or using it as the object context or initial stack context
1270 of an expression evaluation, may produce an undefined result.
1272 *For example, a location description may specify a register that no longer holds
1273 the intended program object after a program location change. One way to avoid
1274 such problems is to recompute location descriptions associated with threads when
1275 their program locations change.*
1277 .. _amdgpu-dwarf-operation-expressions:
1279 A.2.5.4 DWARF Operation Expressions
1280 +++++++++++++++++++++++++++++++++++
1282 An operation expression is comprised of a stream of operations, each consisting
1283 of an opcode followed by zero or more operands. The number of operands is
1284 implied by the opcode.
1286 Operations represent a postfix operation on a simple stack machine. Each stack
1287 entry can hold either a value or a location description. Operations can act on
1288 entries on the stack, including adding entries and removing entries. If the kind
1289 of a stack entry does not match the kind required by the operation and is not
1290 implicitly convertible to the required kind (see
1291 :ref:`amdgpu-dwarf-memory-location-description-operations`), then the DWARF
1292 operation expression is ill-formed.
1294 Evaluation of an operation expression starts with an empty stack on which the
1295 entries from the initial stack provided by the context are pushed in the order
1296 provided. Then the operations are evaluated, starting with the first operation
1297 of the stream. Evaluation continues until either an operation has an evaluation
1298 error, or until one past the last operation of the stream is reached.
1300 The result of the evaluation is:
1302 * If an operation has an evaluation error, or an operation evaluates an
1303 expression that has an evaluation error, then the result is an evaluation
1306 * If the current result kind specifies a location description, then:
1308 * If the stack is empty, the result is a location description with one
1309 undefined location description.
1311 *This rule is for backwards compatibility with DWARF Version 5 which has no
1312 explicit operation to create an undefined location description, and uses an
1313 empty operation expression for this purpose.*
1315 * If the top stack entry is a location description, or can be converted
1316 to one (see :ref:`amdgpu-dwarf-memory-location-description-operations`),
1317 then the result is that, possibly converted, location description. Any other
1318 entries on the stack are discarded.
1320 * Otherwise the DWARF expression is ill-formed.
1324 Could define this case as returning an implicit location description as
1325 if the ``DW_OP_implicit`` operation is performed.
1327 * If the current result kind specifies a value, then:
1329 * If the top stack entry is a value, or can be converted to one (see
1330 :ref:`amdgpu-dwarf-memory-location-description-operations`), then the result
1331 is that, possibly converted, value. Any other entries on the stack are
1334 * Otherwise the DWARF expression is ill-formed.
1336 * If the current result kind is not specified, then:
1338 * If the stack is empty, the result is a location description with one
1339 undefined location description.
1341 *This rule is for backwards compatibility with DWARF Version 5 which has no
1342 explicit operation to create an undefined location description, and uses an
1343 empty operation expression for this purpose.*
1347 This rule is consistent with the rule above for when a location
1348 description is requested. However, GDB appears to report this as an error
1349 and no GDB tests appear to cause an empty stack for this case.
1351 * Otherwise, the top stack entry is returned. Any other entries on the stack
1354 An operation expression is encoded as a byte block with some form of prefix that
1355 specifies the byte count. It can be used:
1357 * as the value of a debugging information entry attribute that is encoded using
1358 class ``exprloc`` (see :ref:`amdgpu-dwarf-classes-and-forms`),
1360 * as the operand to certain operation expression operations,
1362 * as the operand to certain call frame information operations (see
1363 :ref:`amdgpu-dwarf-call-frame-information`),
1365 * and in location list entries (see
1366 :ref:`amdgpu-dwarf-location-list-expressions`).
1368 .. _amdgpu-dwarf-vendor-extensions-operations:
1370 A.2.5.4.0 Vendor Extension Operations
1371 #####################################
1373 1. ``DW_OP_LLVM_user``
1375 ``DW_OP_LLVM_user`` encodes a vendor extension operation. It has at least one
1376 operand: a ULEB128 constant identifying a vendor extension operation. The
1377 remaining operands are defined by the vendor extension. The vendor extension
1378 opcode 0 is reserved and cannot be used by any vendor extension.
1380 *The DW_OP_user encoding space can be understood to supplement the space
1381 defined by DW_OP_lo_user and DW_OP_hi_user that is allocated by the standard
1382 for the same purpose.*
1384 .. _amdgpu-dwarf-stack-operations:
1386 A.2.5.4.1 Stack Operations
1387 ##########################
1391 This section replaces DWARF Version 5 section 2.5.1.3.
1393 The following operations manipulate the DWARF stack. Operations that index the
1394 stack assume that the top of the stack (most recently added entry) has index 0.
1395 They allow the stack entries to be either a value or location description.
1397 If any stack entry accessed by a stack operation is an incomplete composite
1398 location description (see
1399 :ref:`amdgpu-dwarf-composite-location-description-operations`), then the DWARF
1400 expression is ill-formed.
1404 These operations now support stack entries that are values and location
1409 If it is desired to also make them work with incomplete composite location
1410 descriptions, then would need to define that the composite location storage
1411 specified by the incomplete composite location description is also replicated
1412 when a copy is pushed. This ensures that each copy of the incomplete composite
1413 location description can update the composite location storage they specify
1418 ``DW_OP_dup`` duplicates the stack entry at the top of the stack.
1422 ``DW_OP_drop`` pops the stack entry at the top of the stack and discards it.
1426 ``DW_OP_pick`` has a single unsigned 1-byte operand that represents an index
1427 I. A copy of the stack entry with index I is pushed onto the stack.
1431 ``DW_OP_over`` pushes a copy of the entry with index 1.
1433 *This is equivalent to a* ``DW_OP_pick 1`` *operation.*
1437 ``DW_OP_swap`` swaps the top two stack entries. The entry at the top of the
1438 stack becomes the second stack entry, and the second stack entry becomes the
1443 ``DW_OP_rot`` rotates the first three stack entries. The entry at the top of
1444 the stack becomes the third stack entry, the second entry becomes the top of
1445 the stack, and the third entry becomes the second entry.
1447 *Examples illustrating many of these stack operations are found in Appendix
1450 .. _amdgpu-dwarf-control-flow-operations:
1452 A.2.5.4.2 Control Flow Operations
1453 #################################
1457 This section replaces DWARF Version 5 section 2.5.1.5.
1459 The following operations provide simple control of the flow of a DWARF operation
1464 ``DW_OP_nop`` is a place holder. It has no effect on the DWARF stack
1467 2. ``DW_OP_le``, ``DW_OP_ge``, ``DW_OP_eq``, ``DW_OP_lt``, ``DW_OP_gt``,
1472 The same as in DWARF Version 5 section 2.5.1.5.
1476 ``DW_OP_skip`` is an unconditional branch. Its single operand is a 2-byte
1477 signed integer constant. The 2-byte constant is the number of bytes of the
1478 DWARF expression to skip forward or backward from the current operation,
1479 beginning after the 2-byte constant.
1481 If the updated position is at one past the end of the last operation, then
1482 the operation expression evaluation is complete.
1484 Otherwise, the DWARF expression is ill-formed if the updated operation
1485 position is not in the range of the first to last operation inclusive, or
1486 not at the start of an operation.
1490 ``DW_OP_bra`` is a conditional branch. Its single operand is a 2-byte signed
1491 integer constant. This operation pops the top of stack. If the value popped
1492 is not the constant 0, the 2-byte constant operand is the number of bytes of
1493 the DWARF operation expression to skip forward or backward from the current
1494 operation, beginning after the 2-byte constant.
1496 If the updated position is at one past the end of the last operation, then
1497 the operation expression evaluation is complete.
1499 Otherwise, the DWARF expression is ill-formed if the updated operation
1500 position is not in the range of the first to last operation inclusive, or
1501 not at the start of an operation.
1503 5. ``DW_OP_call2, DW_OP_call4, DW_OP_call_ref``
1505 ``DW_OP_call2``, ``DW_OP_call4``, and ``DW_OP_call_ref`` perform DWARF
1506 procedure calls during evaluation of a DWARF operation expression.
1508 ``DW_OP_call2`` and ``DW_OP_call4``, have one operand that is, respectively,
1509 a 2-byte or 4-byte unsigned offset DR that represents the byte offset of a
1510 debugging information entry D relative to the beginning of the current
1513 ``DW_OP_call_ref`` has one operand that is a 4-byte unsigned value in the
1514 32-bit DWARF format, or an 8-byte unsigned value in the 64-bit DWARF format,
1515 that represents the byte offset DR of a debugging information entry D
1516 relative to the beginning of the ``.debug_info`` section that contains the
1517 current compilation unit. D may not be in the current compilation unit.
1521 DWARF Version 5 states that DR can be an offset in a ``.debug_info``
1522 section other than the one that contains the current compilation unit. It
1523 states that relocation of references from one executable or shared object
1524 file to another must be performed by the consumer. But given that DR is
1525 defined as an offset in a ``.debug_info`` section this seems impossible.
1526 If DR was defined as an implementation defined value, then the consumer
1527 could choose to interpret the value in an implementation defined manner to
1528 reference a debug information in another executable or shared object.
1530 In ELF the ``.debug_info`` section is in a non-\ ``PT_LOAD`` segment so
1531 standard dynamic relocations cannot be used. But even if they were loaded
1532 segments and dynamic relocations were used, DR would need to be the
1533 address of D, not an offset in a ``.debug_info`` section. That would also
1534 need DR to be the size of a global address. So it would not be possible to
1535 use the 32-bit DWARF format in a 64-bit global address space. In addition,
1536 the consumer would need to determine what executable or shared object the
1537 relocated address was in so it could determine the containing compilation
1540 GDB only interprets DR as an offset in the ``.debug_info`` section that
1541 contains the current compilation unit.
1543 This comment also applies to ``DW_OP_implicit_pointer`` and
1544 ``DW_OP_LLVM_aspace_implicit_pointer``.
1546 *Operand interpretation of* ``DW_OP_call2``\ *,* ``DW_OP_call4``\ *, and*
1547 ``DW_OP_call_ref`` *is exactly like that for* ``DW_FORM_ref2``\ *,
1548 ``DW_FORM_ref4``\ *, and* ``DW_FORM_ref_addr``\ *, respectively.*
1550 The call operation is evaluated by:
1552 * If D has a ``DW_AT_location`` attribute that is encoded as a ``exprloc``
1553 that specifies an operation expression E, then execution of the current
1554 operation expression continues from the first operation of E. Execution
1555 continues until one past the last operation of E is reached, at which
1556 point execution continues with the operation following the call operation.
1557 The operations of E are evaluated with the same current context, except
1558 current compilation unit is the one that contains D and the stack is the
1559 same as that being used by the call operation. After the call operation
1560 has been evaluated, the stack is therefore as it is left by the evaluation
1561 of the operations of E. Since E is evaluated on the same stack as the call
1562 operation, E can use, and/or remove entries already on the stack, and can
1563 add new entries to the stack.
1565 *Values on the stack at the time of the call may be used as parameters by
1566 the called expression and values left on the stack by the called expression
1567 may be used as return values by prior agreement between the calling and
1568 called expressions.*
1570 * If D has a ``DW_AT_location`` attribute that is encoded as a ``loclist`` or
1571 ``loclistsptr``, then the specified location list expression E is
1572 evaluated. The evaluation of E uses the current context, except the result
1573 kind is a location description, the compilation unit is the one that
1574 contains D, and the initial stack is empty. The location description
1575 result is pushed on the stack.
1579 This rule avoids having to define how to execute a matched location list
1580 entry operation expression on the same stack as the call when there are
1581 multiple matches. But it allows the call to obtain the location
1582 description for a variable or formal parameter which may use a location
1585 An alternative is to treat the case when D has a ``DW_AT_location``
1586 attribute that is encoded as a ``loclist`` or ``loclistsptr``, and the
1587 specified location list expression E' matches a single location list
1588 entry with operation expression E, the same as the ``exprloc`` case and
1589 evaluate on the same stack.
1591 But this is not attractive as if the attribute is for a variable that
1592 happens to end with a non-singleton stack, it will not simply put a
1593 location description on the stack. Presumably the intent of using
1594 ``DW_OP_call*`` on a variable or formal parameter debugger information
1595 entry is to push just one location description on the stack. That
1596 location description may have more than one single location description.
1598 The previous rule for ``exprloc`` also has the same problem, as normally
1599 a variable or formal parameter location expression may leave multiple
1600 entries on the stack and only return the top entry.
1602 GDB implements ``DW_OP_call*`` by always executing E on the same stack.
1603 If the location list has multiple matching entries, it simply picks the
1604 first one and ignores the rest. This seems fundamentally at odds with
1605 the desire to support multiple places for variables.
1607 So, it feels like ``DW_OP_call*`` should both support pushing a location
1608 description on the stack for a variable or formal parameter, and also
1609 support being able to execute an operation expression on the same stack.
1610 Being able to specify a different operation expression for different
1611 program locations seems a desirable feature to retain.
1613 A solution to that is to have a distinct ``DW_AT_LLVM_proc`` attribute
1614 for the ``DW_TAG_dwarf_procedure`` debugging information entry. Then the
1615 ``DW_AT_location`` attribute expression is always executed separately
1616 and pushes a location description (that may have multiple single
1617 location descriptions), and the ``DW_AT_LLVM_proc`` attribute expression
1618 is always executed on the same stack and can leave anything on the
1621 The ``DW_AT_LLVM_proc`` attribute could have the new classes
1622 ``exprproc``, ``loclistproc``, and ``loclistsptrproc`` to indicate that
1623 the expression is executed on the same stack. ``exprproc`` is the same
1624 encoding as ``exprloc``. ``loclistproc`` and ``loclistsptrproc`` are the
1625 same encoding as their non-\ ``proc`` counterparts, except the DWARF is
1626 ill-formed if the location list does not match exactly one location list
1627 entry and a default entry is required. These forms indicate explicitly
1628 that the matched single operation expression must be executed on the
1629 same stack. This is better than ad hoc special rules for ``loclistproc``
1630 and ``loclistsptrproc`` which are currently clearly defined to always
1631 return a location description. The producer then explicitly indicates
1632 the intent through the attribute classes.
1634 Such a change would be a breaking change for how GDB implements
1635 ``DW_OP_call*``. However, are the breaking cases actually occurring in
1636 practice? GDB could implement the current approach for DWARF Version 5,
1637 and the new semantics for DWARF Version 6 which has been done for some
1640 Another option is to limit the execution to be on the same stack only to
1641 the evaluation of an expression E that is the value of a
1642 ``DW_AT_location`` attribute of a ``DW_TAG_dwarf_procedure`` debugging
1643 information entry. The DWARF would be ill-formed if E is a location list
1644 expression that does not match exactly one location list entry. In all
1645 other cases the evaluation of an expression E that is the value of a
1646 ``DW_AT_location`` attribute would evaluate E with the current context,
1647 except the result kind is a location description, the compilation unit
1648 is the one that contains D, and the initial stack is empty. The location
1649 description result is pushed on the stack.
1651 * If D has a ``DW_AT_const_value`` attribute with a value V, then it is as
1652 if a ``DW_OP_implicit_value V`` operation was executed.
1654 *This allows a call operation to be used to compute the location
1655 description for any variable or formal parameter regardless of whether the
1656 producer has optimized it to a constant. This is consistent with the*
1657 ``DW_OP_implicit_pointer`` *operation.*
1661 Alternatively, could deprecate using ``DW_AT_const_value`` for
1662 ``DW_TAG_variable`` and ``DW_TAG_formal_parameter`` debugger information
1663 entries that are constants and instead use ``DW_AT_location`` with an
1664 operation expression that results in a location description with one
1665 implicit location description. Then this rule would not be required.
1667 * Otherwise, there is no effect and no changes are made to the stack.
1671 In DWARF Version 5, if D does not have a ``DW_AT_location`` then
1672 ``DW_OP_call*`` is defined to have no effect. It is unclear that this is
1673 the right definition as a producer should be able to rely on using
1674 ``DW_OP_call*`` to get a location description for any non-\
1675 ``DW_TAG_dwarf_procedure`` debugging information entries. Also, the
1676 producer should not be creating DWARF with ``DW_OP_call*`` to a
1677 ``DW_TAG_dwarf_procedure`` that does not have a ``DW_AT_location``
1678 attribute. So, should this case be defined as an ill-formed DWARF
1681 *The* ``DW_TAG_dwarf_procedure`` *debugging information entry can be used to
1682 define DWARF procedures that can be called.*
1684 .. _amdgpu-dwarf-value-operations:
1686 A.2.5.4.3 Value Operations
1687 ##########################
1689 This section describes the operations that push values on the stack.
1691 Each value stack entry has a type and a literal value. It can represent a
1692 literal value of any supported base type of the target architecture. The base
1693 type specifies the size, encoding, and endianity of the literal value.
1695 The base type of value stack entries can be the distinguished generic type.
1697 .. _amdgpu-dwarf-literal-operations:
1699 A.2.5.4.3.1 Literal Operations
1700 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1704 This section replaces DWARF Version 5 section 2.5.1.1.
1706 The following operations all push a literal value onto the DWARF stack.
1708 Operations other than ``DW_OP_const_type`` push a value V with the generic type.
1709 If V is larger than the generic type, then V is truncated to the generic type
1710 size and the low-order bits used.
1712 1. ``DW_OP_lit0``, ``DW_OP_lit1``, ..., ``DW_OP_lit31``
1714 ``DW_OP_lit<N>`` operations encode an unsigned literal value N from 0
1715 through 31, inclusive. They push the value N with the generic type.
1717 2. ``DW_OP_const1u``, ``DW_OP_const2u``, ``DW_OP_const4u``, ``DW_OP_const8u``
1719 ``DW_OP_const<N>u`` operations have a single operand that is a 1, 2, 4, or
1720 8-byte unsigned integer constant U, respectively. They push the value U with
1723 3. ``DW_OP_const1s``, ``DW_OP_const2s``, ``DW_OP_const4s``, ``DW_OP_const8s``
1725 ``DW_OP_const<N>s`` operations have a single operand that is a 1, 2, 4, or
1726 8-byte signed integer constant S, respectively. They push the value S with
1731 ``DW_OP_constu`` has a single unsigned LEB128 integer operand N. It pushes
1732 the value N with the generic type.
1736 ``DW_OP_consts`` has a single signed LEB128 integer operand N. It pushes the
1737 value N with the generic type.
1741 ``DW_OP_constx`` has a single unsigned LEB128 integer operand that
1742 represents a zero-based index into the ``.debug_addr`` section relative to
1743 the value of the ``DW_AT_addr_base`` attribute of the associated compilation
1744 unit. The value N in the ``.debug_addr`` section has the size of the generic
1745 type. It pushes the value N with the generic type.
1747 *The* ``DW_OP_constx`` *operation is provided for constants that require
1748 link-time relocation but should not be interpreted by the consumer as a
1749 relocatable address (for example, offsets to thread-local storage).*
1751 7. ``DW_OP_const_type``
1753 ``DW_OP_const_type`` has three operands. The first is an unsigned LEB128
1754 integer DR that represents the byte offset of a debugging information entry
1755 D relative to the beginning of the current compilation unit, that provides
1756 the type T of the constant value. The second is a 1-byte unsigned integral
1757 constant S. The third is a block of bytes B, with a length equal to S.
1759 TS is the bit size of the type T. The least significant TS bits of B are
1760 interpreted as a value V of the type D. It pushes the value V with the type
1763 The DWARF is ill-formed if D is not a ``DW_TAG_base_type`` debugging
1764 information entry in the current compilation unit, or if TS divided by 8
1765 (the byte size) and rounded up to a whole number is not equal to S.
1767 *While the size of the byte block B can be inferred from the type D
1768 definition, it is encoded explicitly into the operation so that the
1769 operation can be parsed easily without reference to the* ``.debug_info``
1772 8. ``DW_OP_LLVM_push_lane`` *New*
1774 ``DW_OP_LLVM_push_lane`` pushes the current lane as a value with the generic
1777 *For source languages that are implemented using a SIMT execution model,
1778 this is the zero-based lane number that corresponds to the source language
1779 thread of execution upon which the user is focused.*
1781 The value must be greater than or equal to 0 and less than the value of the
1782 ``DW_AT_LLVM_lanes`` attribute, otherwise the DWARF expression is
1783 ill-formed. See :ref:`amdgpu-dwarf-low-level-information`.
1785 9. ``DW_OP_LLVM_push_iteration`` *New*
1787 ``DW_OP_LLVM_push_iteration`` pushes the current iteration as a value with
1790 *For source language implementations with optimizations that cause multiple
1791 loop iterations to execute concurrently, this is the zero-based iteration
1792 number that corresponds to the source language concurrent loop iteration
1793 upon which the user is focused.*
1795 The value must be greater than or equal to 0 and less than the value of the
1796 ``DW_AT_LLVM_iterations`` attribute, otherwise the DWARF expression is
1797 ill-formed. See :ref:`amdgpu-dwarf-low-level-information`.
1799 .. _amdgpu-dwarf-arithmetic-logical-operations:
1801 A.2.5.4.3.2 Arithmetic and Logical Operations
1802 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1806 This section is the same as DWARF Version 5 section 2.5.1.4.
1808 .. _amdgpu-dwarf-type-conversions-operations:
1810 A.2.5.4.3.3 Type Conversion Operations
1811 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1815 This section is the same as DWARF Version 5 section 2.5.1.6.
1817 .. _amdgpu-dwarf-general-operations:
1819 A.2.5.4.3.4 Special Value Operations
1820 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1824 This section replaces parts of DWARF Version 5 sections 2.5.1.2, 2.5.1.3, and
1827 There are these special value operations currently defined:
1829 1. ``DW_OP_regval_type``
1831 ``DW_OP_regval_type`` has two operands. The first is an unsigned LEB128
1832 integer that represents a register number R. The second is an unsigned
1833 LEB128 integer DR that represents the byte offset of a debugging information
1834 entry D relative to the beginning of the current compilation unit, that
1835 provides the type T of the register value.
1837 The operation is equivalent to performing ``DW_OP_regx R; DW_OP_deref_type
1842 Should DWARF allow the type T to be a larger size than the size of the
1843 register R? Restricting a larger bit size avoids any issue of conversion
1844 as the, possibly truncated, bit contents of the register is simply
1845 interpreted as a value of T. If a conversion is wanted it can be done
1846 explicitly using a ``DW_OP_convert`` operation.
1848 GDB has a per register hook that allows a target specific conversion on a
1849 register by register basis. It defaults to truncation of bigger registers.
1850 Removing use of the target hook does not cause any test failures in common
1851 architectures. If the compiler for a target architecture did want some
1852 form of conversion, including a larger result type, it could always
1853 explicitly use the ``DW_OP_convert`` operation.
1855 If T is a larger type than the register size, then the default GDB
1856 register hook reads bytes from the next register (or reads out of bounds
1857 for the last register!). Removing use of the target hook does not cause
1858 any test failures in common architectures (except an illegal hand written
1859 assembly test). If a target architecture requires this behavior, these
1860 extensions allow a composite location description to be used to combine
1865 S is the bit size of the generic type divided by 8 (the byte size) and
1866 rounded up to a whole number. DR is the offset of a hypothetical debug
1867 information entry D in the current compilation unit for a base type of the
1870 The operation is equivalent to performing ``DW_OP_deref_type S, DR``.
1872 3. ``DW_OP_deref_size``
1874 ``DW_OP_deref_size`` has a single 1-byte unsigned integral constant that
1875 represents a byte result size S.
1877 TS is the smaller of the generic type bit size and S scaled by 8 (the byte
1878 size). If TS is smaller than the generic type bit size then T is an unsigned
1879 integral type of bit size TS, otherwise T is the generic type. DR is the
1880 offset of a hypothetical debug information entry D in the current
1881 compilation unit for a base type T.
1885 Truncating the value when S is larger than the generic type matches what
1886 GDB does. This allows the generic type size to not be an integral byte
1887 size. It does allow S to be arbitrarily large. Should S be restricted to
1888 the size of the generic type rounded up to a multiple of 8?
1890 The operation is equivalent to performing ``DW_OP_deref_type S, DR``, except
1891 if T is not the generic type, the value V pushed is zero-extended to the
1892 generic type bit size and its type changed to the generic type.
1894 4. ``DW_OP_deref_type``
1896 ``DW_OP_deref_type`` has two operands. The first is a 1-byte unsigned
1897 integral constant S. The second is an unsigned LEB128 integer DR that
1898 represents the byte offset of a debugging information entry D relative to
1899 the beginning of the current compilation unit, that provides the type T of
1902 TS is the bit size of the type T.
1904 *While the size of the pushed value V can be inferred from the type T, it is
1905 encoded explicitly as the operand S so that the operation can be parsed
1906 easily without reference to the* ``.debug_info`` *section.*
1910 It is unclear why the operand S is needed. Unlike ``DW_OP_const_type``,
1911 the size is not needed for parsing. Any evaluation needs to get the base
1912 type T to push with the value to know its encoding and bit size.
1914 It pops one stack entry that must be a location description L.
1916 A value V of TS bits is retrieved from the location storage LS specified by
1917 one of the single location descriptions SL of L.
1919 *If L, or the location description of any composite location description
1920 part that is a subcomponent of L, has more than one single location
1921 description, then any one of them can be selected as they are required to
1922 all have the same value. For any single location description SL, bits are
1923 retrieved from the associated storage location starting at the bit offset
1924 specified by SL. For a composite location description, the retrieved bits
1925 are the concatenation of the N bits from each composite location part PL,
1926 where N is limited to the size of PL.*
1928 V is pushed on the stack with the type T.
1932 This definition makes it an evaluation error if L is a register location
1933 description that has less than TS bits remaining in the register storage.
1934 Particularly since these extensions extend location descriptions to have
1935 a bit offset, it would be odd to define this as performing sign extension
1936 based on the type, or be target architecture dependent, as the number of
1937 remaining bits could be any number. This matches the GDB implementation
1938 for ``DW_OP_deref_type``.
1940 These extensions define ``DW_OP_*breg*`` in terms of
1941 ``DW_OP_regval_type``. ``DW_OP_regval_type`` is defined in terms of
1942 ``DW_OP_regx``, which uses a 0 bit offset, and ``DW_OP_deref_type``.
1943 Therefore, it requires the register size to be greater or equal to the
1944 address size of the address space. This matches the GDB implementation for
1947 The DWARF is ill-formed if D is not in the current compilation unit, D is
1948 not a ``DW_TAG_base_type`` debugging information entry, or if TS divided by
1949 8 (the byte size) and rounded up to a whole number is not equal to S.
1953 This definition allows the base type to be a bit size since there seems no
1954 reason to restrict it.
1956 It is an evaluation error if any bit of the value is retrieved from the
1957 undefined location storage or the offset of any bit exceeds the size of the
1958 location storage LS specified by any single location description SL of L.
1960 See :ref:`amdgpu-dwarf-implicit-location-description-operations` for special
1961 rules concerning implicit location descriptions created by the
1962 ``DW_OP_implicit_pointer`` and ``DW_OP_LLVM_aspace_implicit_pointer``
1965 5. ``DW_OP_xderef`` *Deprecated*
1967 ``DW_OP_xderef`` pops two stack entries. The first must be an integral type
1968 value that represents an address A. The second must be an integral type
1969 value that represents a target architecture specific address space
1972 The operation is equivalent to performing ``DW_OP_swap;
1973 DW_OP_LLVM_form_aspace_address; DW_OP_deref``. The value V retrieved is left
1974 on the stack with the generic type.
1976 *This operation is deprecated as the* ``DW_OP_LLVM_form_aspace_address``
1977 *operation can be used and provides greater expressiveness.*
1979 6. ``DW_OP_xderef_size`` *Deprecated*
1981 ``DW_OP_xderef_size`` has a single 1-byte unsigned integral constant that
1982 represents a byte result size S.
1984 It pops two stack entries. The first must be an integral type value that
1985 represents an address A. The second must be an integral type value that
1986 represents a target architecture specific address space identifier AS.
1988 The operation is equivalent to performing ``DW_OP_swap;
1989 DW_OP_LLVM_form_aspace_address; DW_OP_deref_size S``. The zero-extended
1990 value V retrieved is left on the stack with the generic type.
1992 *This operation is deprecated as the* ``DW_OP_LLVM_form_aspace_address``
1993 *operation can be used and provides greater expressiveness.*
1995 7. ``DW_OP_xderef_type`` *Deprecated*
1997 ``DW_OP_xderef_type`` has two operands. The first is a 1-byte unsigned
1998 integral constant S. The second operand is an unsigned LEB128 integer DR
1999 that represents the byte offset of a debugging information entry D relative
2000 to the beginning of the current compilation unit, that provides the type T
2001 of the result value.
2003 It pops two stack entries. The first must be an integral type value that
2004 represents an address A. The second must be an integral type value that
2005 represents a target architecture specific address space identifier AS.
2007 The operation is equivalent to performing ``DW_OP_swap;
2008 DW_OP_LLVM_form_aspace_address; DW_OP_deref_type S DR``. The value V
2009 retrieved is left on the stack with the type T.
2011 *This operation is deprecated as the* ``DW_OP_LLVM_form_aspace_address``
2012 *operation can be used and provides greater expressiveness.*
2014 8. ``DW_OP_entry_value`` *Deprecated*
2016 ``DW_OP_entry_value`` pushes the value of an expression that is evaluated in
2017 the context of the calling frame.
2019 *It may be used to determine the value of arguments on entry to the current
2020 call frame provided they are not clobbered.*
2022 It has two operands. The first is an unsigned LEB128 integer S. The second
2023 is a block of bytes, with a length equal S, interpreted as a DWARF
2024 operation expression E.
2026 E is evaluated with the current context, except the result kind is
2027 unspecified, the call frame is the one that called the current frame, the
2028 program location is the call site in the calling frame, the object is
2029 unspecified, and the initial stack is empty. The calling frame information
2030 is obtained by virtually unwinding the current call frame using the call
2031 frame information (see :ref:`amdgpu-dwarf-call-frame-information`).
2033 If the result of E is a location description L (see
2034 :ref:`amdgpu-dwarf-register-location-description-operations`), and the last
2035 operation executed by E is a ``DW_OP_reg*`` for register R with a target
2036 architecture specific base type of T, then the contents of the register are
2037 retrieved as if a ``DW_OP_deref_type DR`` operation was performed where DR
2038 is the offset of a hypothetical debug information entry in the current
2039 compilation unit for T. The resulting value V s pushed on the stack.
2041 *Using* ``DW_OP_reg*`` *provides a more compact form for the case where the
2042 value was in a register on entry to the subprogram.*
2046 It is unclear how this provides a more compact expression, as
2047 ``DW_OP_regval_type`` could be used which is marginally larger.
2049 If the result of E is a value V, then V is pushed on the stack.
2051 Otherwise, the DWARF expression is ill-formed.
2053 *The* ``DW_OP_entry_value`` *operation is deprecated as its main usage is
2054 provided by other means. DWARF Version 5 added the*
2055 ``DW_TAG_call_site_parameter`` *debugger information entry for call sites
2056 that has* ``DW_AT_call_value``\ *,* ``DW_AT_call_data_location``\ *, and*
2057 ``DW_AT_call_data_value`` *attributes that provide DWARF expressions to
2058 compute actual parameter values at the time of the call, and requires the
2059 producer to ensure the expressions are valid to evaluate even when virtually
2060 unwound. The* ``DW_OP_LLVM_call_frame_entry_reg`` *operation provides access
2061 to registers in the virtually unwound calling frame.*
2065 GDB only implements ``DW_OP_entry_value`` when E is exactly
2066 ``DW_OP_reg*`` or ``DW_OP_breg*; DW_OP_deref*``.
2068 .. _amdgpu-dwarf-location-description-operations:
2070 A.2.5.4.4 Location Description Operations
2071 #########################################
2073 This section describes the operations that push location descriptions on the
2076 .. _amdgpu-dwarf-general-location-description-operations:
2078 A.2.5.4.4.1 General Location Description Operations
2079 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2083 This section replaces part of DWARF Version 5 section 2.5.1.3.
2085 1. ``DW_OP_LLVM_offset`` *New*
2087 ``DW_OP_LLVM_offset`` pops two stack entries. The first must be an integral
2088 type value that represents a byte displacement B. The second must be a
2089 location description L.
2091 It adds the value of B scaled by 8 (the byte size) to the bit offset of each
2092 single location description SL of L, and pushes the updated L.
2094 It is an evaluation error if the updated bit offset of any SL is less than 0
2095 or greater than or equal to the size of the location storage specified by
2098 2. ``DW_OP_LLVM_offset_uconst`` *New*
2100 ``DW_OP_LLVM_offset_uconst`` has a single unsigned LEB128 integer operand
2101 that represents a byte displacement B.
2103 The operation is equivalent to performing ``DW_OP_constu B;
2104 DW_OP_LLVM_offset``.
2106 *This operation is supplied specifically to be able to encode more field
2107 displacements in two bytes than can be done with* ``DW_OP_lit*;
2108 DW_OP_LLVM_offset``\ *.*
2112 Should this be named ``DW_OP_LLVM_offset_uconst`` to match
2113 ``DW_OP_plus_uconst``, or ``DW_OP_LLVM_offset_constu`` to match
2116 3. ``DW_OP_LLVM_bit_offset`` *New*
2118 ``DW_OP_LLVM_bit_offset`` pops two stack entries. The first must be an
2119 integral type value that represents a bit displacement B. The second must be
2120 a location description L.
2122 It adds the value of B to the bit offset of each single location description
2123 SL of L, and pushes the updated L.
2125 It is an evaluation error if the updated bit offset of any SL is less than 0
2126 or greater than or equal to the size of the location storage specified by
2129 4. ``DW_OP_push_object_address``
2131 ``DW_OP_push_object_address`` pushes the location description L of the
2134 *This object may correspond to an independent variable that is part of a
2135 user presented expression that is being evaluated. The object location
2136 description may be determined from the variable's own debugging information
2137 entry or it may be a component of an array, structure, or class whose
2138 address has been dynamically determined by an earlier step during user
2139 expression evaluation.*
2141 *This operation provides explicit functionality (especially for arrays
2142 involving descriptors) that is analogous to the implicit push of the base
2143 location description of a structure prior to evaluation of a*
2144 ``DW_AT_data_member_location`` *to access a data member of a structure.*
2148 This operation could be removed and the object location description
2149 specified as the initial stack as for ``DW_AT_data_member_location``.
2151 Or this operation could be used instead of needing to specify an initial
2152 stack. The latter approach is more composable as access to the object may
2153 be needed at any point of the expression, and passing it as the initial
2154 stack requires the entire expression to be aware where on the stack it is.
2155 If this were done, ``DW_AT_use_location`` would require a
2156 ``DW_OP_push_object2_address`` operation for the second object.
2158 Or a more general way to pass an arbitrary number of arguments in and an
2159 operation to get the Nth one such as ``DW_OP_arg N``. A vector of
2160 arguments would then be passed in the expression context rather than an
2161 initial stack. This could also resolve the issues with ``DW_OP_call*`` by
2162 allowing a specific number of arguments passed in and returned to be
2163 specified. The ``DW_OP_call*`` operation could then always execute on a
2164 separate stack: the number of arguments would be specified in a new call
2165 operation and taken from the callers stack, and similarly the number of
2166 return results specified and copied from the called stack back to the
2167 callee stack when the called expression was complete.
2169 The only attribute that specifies a current object is
2170 ``DW_AT_data_location`` so the non-normative text seems to overstate how
2171 this is being used. Or are there other attributes that need to state they
2174 5. ``DW_OP_LLVM_call_frame_entry_reg`` *New*
2176 ``DW_OP_LLVM_call_frame_entry_reg`` has a single unsigned LEB128 integer
2177 operand that represents a target architecture register number R.
2179 It pushes a location description L that holds the value of register R on
2180 entry to the current subprogram as defined by the call frame information
2181 (see :ref:`amdgpu-dwarf-call-frame-information`).
2183 *If there is no call frame information defined, then the default rules for
2184 the target architecture are used. If the register rule is* undefined\ *, then
2185 the undefined location description is pushed. If the register rule is* same
2186 value\ *, then a register location description for R is pushed.*
2188 .. _amdgpu-dwarf-undefined-location-description-operations:
2190 A.2.5.4.4.2 Undefined Location Description Operations
2191 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2195 This section replaces DWARF Version 5 section 2.6.1.1.1.
2197 *The undefined location storage represents a piece or all of an object that is
2198 present in the source but not in the object code (perhaps due to optimization).
2199 Neither reading nor writing to the undefined location storage is meaningful.*
2201 An undefined location description specifies the undefined location storage.
2202 There is no concept of the size of the undefined location storage, nor of a bit
2203 offset for an undefined location description. The ``DW_OP_LLVM_*offset``
2204 operations leave an undefined location description unchanged. The
2205 ``DW_OP_*piece`` operations can explicitly or implicitly specify an undefined
2206 location description, allowing any size and offset to be specified, and results
2207 in a part with all undefined bits.
2209 1. ``DW_OP_LLVM_undefined`` *New*
2211 ``DW_OP_LLVM_undefined`` pushes a location description L that comprises one
2212 undefined location description SL.
2214 .. _amdgpu-dwarf-memory-location-description-operations:
2216 A.2.5.4.4.3 Memory Location Description Operations
2217 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2221 This section replaces parts of DWARF Version 5 section 2.5.1.1, 2.5.1.2,
2222 2.5.1.3, and 2.6.1.1.2.
2224 Each of the target architecture specific address spaces has a corresponding
2225 memory location storage that denotes the linear addressable memory of that
2226 address space. The size of each memory location storage corresponds to the range
2227 of the addresses in the corresponding address space.
2229 *It is target architecture defined how address space location storage maps to
2230 target architecture physical memory. For example, they may be independent
2231 memory, or more than one location storage may alias the same physical memory
2232 possibly at different offsets and with different interleaving. The mapping may
2233 also be dictated by the source language address classes.*
2235 A memory location description specifies a memory location storage. The bit
2236 offset corresponds to a bit position within a byte of the memory. Bits accessed
2237 using a memory location description, access the corresponding target
2238 architecture memory starting at the bit position within the byte specified by
2241 A memory location description that has a bit offset that is a multiple of 8 (the
2242 byte size) is defined to be a byte address memory location description. It has a
2243 memory byte address A that is equal to the bit offset divided by 8.
2245 A memory location description that does not have a bit offset that is a multiple
2246 of 8 (the byte size) is defined to be a bit field memory location description.
2247 It has a bit position B equal to the bit offset modulo 8, and a memory byte
2248 address A equal to the bit offset minus B that is then divided by 8.
2250 The address space AS of a memory location description is defined to be the
2251 address space that corresponds to the memory location storage associated with
2252 the memory location description.
2254 A location description that is comprised of one byte address memory location
2255 description SL is defined to be a memory byte address location description. It
2256 has a byte address equal to A and an address space equal to AS of the
2259 ``DW_ASPACE_LLVM_none`` is defined as the target architecture default address
2260 space. See :ref:`amdgpu-dwarf-address-spaces`.
2262 If a stack entry is required to be a location description, but it is a value V
2263 with the generic type, then it is implicitly converted to a location description
2264 L with one memory location description SL. SL specifies the memory location
2265 storage that corresponds to the target architecture default address space with a
2266 bit offset equal to V scaled by 8 (the byte size).
2270 If it is wanted to allow any integral type value to be implicitly converted to
2271 a memory location description in the target architecture default address
2274 If a stack entry is required to be a location description, but is a value V
2275 with an integral type, then it is implicitly converted to a location
2276 description L with a one memory location description SL. If the type size of
2277 V is less than the generic type size, then the value V is zero extended to
2278 the size of the generic type. The least significant generic type size bits
2279 are treated as an unsigned value to be used as an address A. SL specifies
2280 memory location storage corresponding to the target architecture default
2281 address space with a bit offset equal to A scaled by 8 (the byte size).
2283 The implicit conversion could also be defined as target architecture specific.
2284 For example, GDB checks if V is an integral type. If it is not it gives an
2285 error. Otherwise, GDB zero-extends V to 64 bits. If the GDB target defines a
2286 hook function, then it is called. The target specific hook function can modify
2287 the 64-bit value, possibly sign extending based on the original value type.
2288 Finally, GDB treats the 64-bit value V as a memory location address.
2290 If a stack entry is required to be a location description, but it is an implicit
2291 pointer value IPV with the target architecture default address space, then it is
2292 implicitly converted to a location description with one single location
2293 description specified by IPV. See
2294 :ref:`amdgpu-dwarf-implicit-location-description-operations`.
2298 Is this rule required for DWARF Version 5 backwards compatibility? If not, it
2299 can be eliminated, and the producer can use
2300 ``DW_OP_LLVM_form_aspace_address``.
2302 If a stack entry is required to be a value, but it is a location description L
2303 with one memory location description SL in the target architecture default
2304 address space with a bit offset B that is a multiple of 8, then it is implicitly
2305 converted to a value equal to B divided by 8 (the byte size) with the generic
2310 ``DW_OP_addr`` has a single byte constant value operand, which has the size
2311 of the generic type, that represents an address A.
2313 It pushes a location description L with one memory location description SL
2314 on the stack. SL specifies the memory location storage corresponding to the
2315 target architecture default address space with a bit offset equal to A
2316 scaled by 8 (the byte size).
2318 *If the DWARF is part of a code object, then A may need to be relocated. For
2319 example, in the ELF code object format, A must be adjusted by the difference
2320 between the ELF segment virtual address and the virtual address at which the
2325 ``DW_OP_addrx`` has a single unsigned LEB128 integer operand that represents
2326 a zero-based index into the ``.debug_addr`` section relative to the value of
2327 the ``DW_AT_addr_base`` attribute of the associated compilation unit. The
2328 address value A in the ``.debug_addr`` section has the size of the generic
2331 It pushes a location description L with one memory location description SL
2332 on the stack. SL specifies the memory location storage corresponding to the
2333 target architecture default address space with a bit offset equal to A
2334 scaled by 8 (the byte size).
2336 *If the DWARF is part of a code object, then A may need to be relocated. For
2337 example, in the ELF code object format, A must be adjusted by the difference
2338 between the ELF segment virtual address and the virtual address at which the
2341 3. ``DW_OP_LLVM_form_aspace_address`` *New*
2343 ``DW_OP_LLVM_form_aspace_address`` pops top two stack entries. The first
2344 must be an integral type value that represents a target architecture
2345 specific address space identifier AS. The second must be an integral type
2346 value that represents an address A.
2348 The address size S is defined as the address bit size of the target
2349 architecture specific address space that corresponds to AS.
2351 A is adjusted to S bits by zero extending if necessary, and then treating
2352 the least significant S bits as an unsigned value A'.
2354 It pushes a location description L with one memory location description SL
2355 on the stack. SL specifies the memory location storage LS that corresponds
2356 to AS with a bit offset equal to A' scaled by 8 (the byte size).
2358 If AS is an address space that is specific to context elements, then LS
2359 corresponds to the location storage associated with the current context.
2361 *For example, if AS is for per thread storage then LS is the location
2362 storage for the current thread. For languages that are implemented using a
2363 SIMT execution model, then if AS is for per lane storage then LS is the
2364 location storage for the current lane of the current thread. Therefore, if L
2365 is accessed by an operation, the location storage selected when the location
2366 description was created is accessed, and not the location storage associated
2367 with the current context of the access operation.*
2369 The DWARF expression is ill-formed if AS is not one of the values defined by
2370 the target architecture specific ``DW_ASPACE_LLVM_*`` values.
2372 See :ref:`amdgpu-dwarf-implicit-location-description-operations` for special
2373 rules concerning implicit pointer values produced by dereferencing implicit
2374 location descriptions created by the ``DW_OP_implicit_pointer`` and
2375 ``DW_OP_LLVM_aspace_implicit_pointer`` operations.
2377 4. ``DW_OP_form_tls_address``
2379 ``DW_OP_form_tls_address`` pops one stack entry that must be an integral
2380 type value and treats it as a thread-local storage address TA.
2382 It pushes a location description L with one memory location description SL
2383 on the stack. SL is the target architecture specific memory location
2384 description that corresponds to the thread-local storage address TA.
2386 The meaning of the thread-local storage address TA is defined by the
2387 run-time environment. If the run-time environment supports multiple
2388 thread-local storage blocks for a single thread, then the block
2389 corresponding to the executable or shared library containing this DWARF
2392 *Some implementations of C, C++, Fortran, and other languages, support a
2393 thread-local storage class. Variables with this storage class have distinct
2394 values and addresses in distinct threads, much as automatic variables have
2395 distinct values and addresses in each subprogram invocation. Typically,
2396 there is a single block of storage containing all thread-local variables
2397 declared in the main executable, and a separate block for the variables
2398 declared in each shared library. Each thread-local variable can then be
2399 accessed in its block using an identifier. This identifier is typically a
2400 byte offset into the block and pushed onto the DWARF stack by one of the*
2401 ``DW_OP_const*`` *operations prior to the* ``DW_OP_form_tls_address``
2402 *operation. Computing the address of the appropriate block can be complex
2403 (in some cases, the compiler emits a function call to do it), and difficult
2404 to describe using ordinary DWARF location descriptions. Instead of forcing
2405 complex thread-local storage calculations into the DWARF expressions, the*
2406 ``DW_OP_form_tls_address`` *allows the consumer to perform the computation
2407 based on the target architecture specific run-time environment.*
2409 5. ``DW_OP_call_frame_cfa``
2411 ``DW_OP_call_frame_cfa`` pushes the location description L of the Canonical
2412 Frame Address (CFA) of the current subprogram, obtained from the call frame
2413 information on the stack. See :ref:`amdgpu-dwarf-call-frame-information`.
2415 *Although the value of the* ``DW_AT_frame_base`` *attribute of the debugger
2416 information entry corresponding to the current subprogram can be computed
2417 using a location list expression, in some cases this would require an
2418 extensive location list because the values of the registers used in
2419 computing the CFA change during a subprogram execution. If the call frame
2420 information is present, then it already encodes such changes, and it is
2421 space efficient to reference that using the* ``DW_OP_call_frame_cfa``
2426 ``DW_OP_fbreg`` has a single signed LEB128 integer operand that represents a
2427 byte displacement B.
2429 The location description L for the *frame base* of the current subprogram is
2430 obtained from the ``DW_AT_frame_base`` attribute of the debugger information
2431 entry corresponding to the current subprogram as described in
2432 :ref:`amdgpu-dwarf-low-level-information`.
2434 The location description L is updated as if the ``DW_OP_LLVM_offset_uconst
2435 B`` operation was applied. The updated L is pushed on the stack.
2437 7. ``DW_OP_breg0``, ``DW_OP_breg1``, ..., ``DW_OP_breg31``
2439 The ``DW_OP_breg<N>`` operations encode the numbers of up to 32 registers,
2440 numbered from 0 through 31, inclusive. The register number R corresponds to
2441 the N in the operation name.
2443 They have a single signed LEB128 integer operand that represents a byte
2446 The address space identifier AS is defined as the one corresponding to the
2447 target architecture specific default address space.
2449 The address size S is defined as the address bit size of the target
2450 architecture specific address space corresponding to AS.
2452 The contents of the register specified by R are retrieved as if a
2453 ``DW_OP_regval_type R, DR`` operation was performed where DR is the offset
2454 of a hypothetical debug information entry in the current compilation unit
2455 for an unsigned integral base type of size S bits. B is added and the least
2456 significant S bits are treated as an unsigned value to be used as an address
2459 They push a location description L comprising one memory location
2460 description LS on the stack. LS specifies the memory location storage that
2461 corresponds to AS with a bit offset equal to A scaled by 8 (the byte size).
2465 ``DW_OP_bregx`` has two operands. The first is an unsigned LEB128 integer
2466 that represents a register number R. The second is a signed LEB128
2467 integer that represents a byte displacement B.
2469 The action is the same as for ``DW_OP_breg<N>``, except that R is used as
2470 the register number and B is used as the byte displacement.
2472 9. ``DW_OP_LLVM_aspace_bregx`` *New*
2474 ``DW_OP_LLVM_aspace_bregx`` has two operands. The first is an unsigned
2475 LEB128 integer that represents a register number R. The second is a signed
2476 LEB128 integer that represents a byte displacement B. It pops one stack
2477 entry that is required to be an integral type value that represents a target
2478 architecture specific address space identifier AS.
2480 The action is the same as for ``DW_OP_breg<N>``, except that R is used as
2481 the register number, B is used as the byte displacement, and AS is used as
2482 the address space identifier.
2484 The DWARF expression is ill-formed if AS is not one of the values defined by
2485 the target architecture specific ``DW_ASPACE_LLVM_*`` values.
2489 Could also consider adding ``DW_OP_LLVM_aspace_breg0,
2490 DW_OP_LLVM_aspace_breg1, ..., DW_OP_LLVM_aspace_bref31`` which would save
2493 .. _amdgpu-dwarf-register-location-description-operations:
2495 A.2.5.4.4.4 Register Location Description Operations
2496 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2500 This section replaces DWARF Version 5 section 2.6.1.1.3.
2502 There is a register location storage that corresponds to each of the target
2503 architecture registers. The size of each register location storage corresponds
2504 to the size of the corresponding target architecture register.
2506 A register location description specifies a register location storage. The bit
2507 offset corresponds to a bit position within the register. Bits accessed using a
2508 register location description access the corresponding target architecture
2509 register starting at the specified bit offset.
2511 1. ``DW_OP_reg0``, ``DW_OP_reg1``, ..., ``DW_OP_reg31``
2513 ``DW_OP_reg<N>`` operations encode the numbers of up to 32 registers,
2514 numbered from 0 through 31, inclusive. The target architecture register
2515 number R corresponds to the N in the operation name.
2517 The operation is equivalent to performing ``DW_OP_regx R``.
2521 ``DW_OP_regx`` has a single unsigned LEB128 integer operand that represents
2522 a target architecture register number R.
2524 If the current call frame is the top call frame, it pushes a location
2525 description L that specifies one register location description SL on the
2526 stack. SL specifies the register location storage that corresponds to R with
2527 a bit offset of 0 for the current thread.
2529 If the current call frame is not the top call frame, call frame information
2530 (see :ref:`amdgpu-dwarf-call-frame-information`) is used to determine the
2531 location description that holds the register for the current call frame and
2532 current program location of the current thread. The resulting location
2533 description L is pushed.
2535 *Note that if call frame information is used, the resulting location
2536 description may be register, memory, or undefined.*
2538 *An implementation may evaluate the call frame information immediately, or
2539 may defer evaluation until L is accessed by an operation. If evaluation is
2540 deferred, R and the current context can be recorded in L. When accessed, the
2541 recorded context is used to evaluate the call frame information, not the
2542 current context of the access operation.*
2544 *These operations obtain a register location. To fetch the contents of a
2545 register, it is necessary to use* ``DW_OP_regval_type``\ *, use one of the*
2546 ``DW_OP_breg*`` *register-based addressing operations, or use* ``DW_OP_deref*``
2547 *on a register location description.*
2549 .. _amdgpu-dwarf-implicit-location-description-operations:
2551 A.2.5.4.4.5 Implicit Location Description Operations
2552 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2556 This section replaces DWARF Version 5 section 2.6.1.1.4.
2558 Implicit location storage represents a piece or all of an object which has no
2559 actual location in the program but whose contents are nonetheless known, either
2560 as a constant or can be computed from other locations and values in the program.
2562 An implicit location description specifies an implicit location storage. The bit
2563 offset corresponds to a bit position within the implicit location storage. Bits
2564 accessed using an implicit location description, access the corresponding
2565 implicit storage value starting at the bit offset.
2567 1. ``DW_OP_implicit_value``
2569 ``DW_OP_implicit_value`` has two operands. The first is an unsigned LEB128
2570 integer that represents a byte size S. The second is a block of bytes with a
2571 length equal to S treated as a literal value V.
2573 An implicit location storage LS is created with the literal value V and a
2576 It pushes location description L with one implicit location description SL
2577 on the stack. SL specifies LS with a bit offset of 0.
2579 2. ``DW_OP_stack_value``
2581 ``DW_OP_stack_value`` pops one stack entry that must be a value V.
2583 An implicit location storage LS is created with the literal value V using
2584 the size, encoding, and endianity specified by V's base type.
2586 It pushes a location description L with one implicit location description SL
2587 on the stack. SL specifies LS with a bit offset of 0.
2589 *The* ``DW_OP_stack_value`` *operation specifies that the object does not
2590 exist in memory, but its value is nonetheless known. In this form, the
2591 location description specifies the actual value of the object, rather than
2592 specifying the memory or register storage that holds the value.*
2594 See ``DW_OP_implicit_pointer`` (following) for special rules concerning
2595 implicit pointer values produced by dereferencing implicit location
2596 descriptions created by the ``DW_OP_implicit_pointer`` and
2597 ``DW_OP_LLVM_aspace_implicit_pointer`` operations.
2599 Note: Since location descriptions are allowed on the stack, the
2600 ``DW_OP_stack_value`` operation no longer terminates the DWARF operation
2601 expression execution as in DWARF Version 5.
2603 3. ``DW_OP_implicit_pointer``
2605 *An optimizing compiler may eliminate a pointer, while still retaining the
2606 value that the pointer addressed.* ``DW_OP_implicit_pointer`` *allows a
2607 producer to describe this value.*
2609 ``DW_OP_implicit_pointer`` *specifies an object is a pointer to the target
2610 architecture default address space that cannot be represented as a real
2611 pointer, even though the value it would point to can be described. In this
2612 form, the location description specifies a debugging information entry that
2613 represents the actual location description of the object to which the
2614 pointer would point. Thus, a consumer of the debug information would be able
2615 to access the dereferenced pointer, even when it cannot access the pointer
2618 ``DW_OP_implicit_pointer`` has two operands. The first operand is a 4-byte
2619 unsigned value in the 32-bit DWARF format, or an 8-byte unsigned value in
2620 the 64-bit DWARF format, that represents the byte offset DR of a debugging
2621 information entry D relative to the beginning of the ``.debug_info`` section
2622 that contains the current compilation unit. The second operand is a signed
2623 LEB128 integer that represents a byte displacement B.
2625 *Note that D might not be in the current compilation unit.*
2627 *The first operand interpretation is exactly like that for*
2628 ``DW_FORM_ref_addr``\ *.*
2630 The address space identifier AS is defined as the one corresponding to the
2631 target architecture specific default address space.
2633 The address size S is defined as the address bit size of the target
2634 architecture specific address space corresponding to AS.
2636 An implicit location storage LS is created with the debugging information
2637 entry D, address space AS, and size of S.
2639 It pushes a location description L that comprises one implicit location
2640 description SL on the stack. SL specifies LS with a bit offset of 0.
2642 It is an evaluation error if a ``DW_OP_deref*`` operation pops a location
2643 description L', and retrieves S bits, such that any retrieved bits come from
2644 an implicit location storage that is the same as LS, unless both the
2645 following conditions are met:
2647 1. All retrieved bits come from an implicit location description that
2648 refers to an implicit location storage that is the same as LS.
2650 *Note that all bits do not have to come from the same implicit location
2651 description, as L' may involve composite location descriptions.*
2653 2. The bits come from consecutive ascending offsets within their respective
2654 implicit location storage.
2656 *These rules are equivalent to retrieving the complete contents of LS.*
2658 If both the above conditions are met, then the value V pushed by the
2659 ``DW_OP_deref*`` operation is an implicit pointer value IPV with a target
2660 architecture specific address space of AS, a debugging information entry of
2661 D, and a base type of T. If AS is the target architecture default address
2662 space, then T is the generic type. Otherwise, T is a target architecture
2663 specific integral type with a bit size equal to S.
2665 If IPV is either implicitly converted to a location description (only done
2666 if AS is the target architecture default address space) or used by
2667 ``DW_OP_LLVM_form_aspace_address`` (only done if the address space popped by
2668 ``DW_OP_LLVM_form_aspace_address`` is AS), then the resulting location
2671 * If D has a ``DW_AT_location`` attribute, the DWARF expression E from the
2672 ``DW_AT_location`` attribute is evaluated with the current context, except
2673 that the result kind is a location description, the compilation unit is
2674 the one that contains D, the object is unspecified, and the initial stack
2675 is empty. RL is the expression result.
2677 *Note that E is evaluated with the context of the expression accessing
2678 IPV, and not the context of the expression that contained the*
2679 ``DW_OP_implicit_pointer`` *or* ``DW_OP_LLVM_aspace_implicit_pointer``
2680 *operation that created L.*
2682 * If D has a ``DW_AT_const_value`` attribute, then an implicit location
2683 storage RLS is created from the ``DW_AT_const_value`` attribute's value
2684 with a size matching the size of the ``DW_AT_const_value`` attribute's
2685 value. RL comprises one implicit location description SRL. SRL specifies
2686 RLS with a bit offset of 0.
2690 If using ``DW_AT_const_value`` for variables and formal parameters is
2691 deprecated and instead ``DW_AT_location`` is used with an implicit
2692 location description, then this rule would not be required.
2694 * Otherwise, it is an evaluation error.
2696 The bit offset of RL is updated as if the ``DW_OP_LLVM_offset_uconst B``
2697 operation was applied.
2699 If a ``DW_OP_stack_value`` operation pops a value that is the same as IPV,
2700 then it pushes a location description that is the same as L.
2702 It is an evaluation error if LS or IPV is accessed in any other manner.
2704 *The restrictions on how an implicit pointer location description created
2705 by* ``DW_OP_implicit_pointer`` *and* ``DW_OP_LLVM_aspace_implicit_pointer``
2706 *can be used are to simplify the DWARF consumer. Similarly, for an implicit
2707 pointer value created by* ``DW_OP_deref*`` *and* ``DW_OP_stack_value``\ *.*
2709 4. ``DW_OP_LLVM_aspace_implicit_pointer`` *New*
2711 ``DW_OP_LLVM_aspace_implicit_pointer`` has two operands that are the same as
2712 for ``DW_OP_implicit_pointer``.
2714 It pops one stack entry that must be an integral type value that represents
2715 a target architecture specific address space identifier AS.
2717 The location description L that is pushed on the stack is the same as for
2718 ``DW_OP_implicit_pointer``, except that the address space identifier used is
2721 The DWARF expression is ill-formed if AS is not one of the values defined by
2722 the target architecture specific ``DW_ASPACE_LLVM_*`` values.
2726 This definition of ``DW_OP_LLVM_aspace_implicit_pointer`` may change when
2727 full support for address classes is added as required for languages such
2730 *Typically a* ``DW_OP_implicit_pointer`` *or*
2731 ``DW_OP_LLVM_aspace_implicit_pointer`` *operation is used in a DWARF expression
2732 E*\ :sub:`1` *of a* ``DW_TAG_variable`` *or* ``DW_TAG_formal_parameter``
2733 *debugging information entry D*\ :sub:`1`\ *'s* ``DW_AT_location`` *attribute.
2734 The debugging information entry referenced by the* ``DW_OP_implicit_pointer``
2735 *or* ``DW_OP_LLVM_aspace_implicit_pointer`` *operations is typically itself a*
2736 ``DW_TAG_variable`` *or* ``DW_TAG_formal_parameter`` *debugging information
2737 entry D*\ :sub:`2` *whose* ``DW_AT_location`` *attribute gives a second DWARF
2738 expression E*\ :sub:`2`\ *.*
2740 *D*\ :sub:`1` *and E*\ :sub:`1` *are describing the location of a pointer type
2741 object. D*\ :sub:`2` *and E*\ :sub:`2` *are describing the location of the
2742 object pointed to by that pointer object.*
2744 *However, D*\ :sub:`2` *may be any debugging information entry that contains a*
2745 ``DW_AT_location`` *or* ``DW_AT_const_value`` *attribute (for example,*
2746 ``DW_TAG_dwarf_procedure``\ *). By using E*\ :sub:`2`\ *, a consumer can
2747 reconstruct the value of the object when asked to dereference the pointer
2748 described by E*\ :sub:`1` *which contains the* ``DW_OP_implicit_pointer`` *or*
2749 ``DW_OP_LLVM_aspace_implicit_pointer`` *operation.*
2751 .. _amdgpu-dwarf-composite-location-description-operations:
2753 A.2.5.4.4.6 Composite Location Description Operations
2754 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2758 This section replaces DWARF Version 5 section 2.6.1.2.
2760 A composite location storage represents an object or value which may be
2761 contained in part of another location storage or contained in parts of more
2762 than one location storage.
2764 Each part has a part location description L and a part bit size S. L can have
2765 one or more single location descriptions SL. If there are more than one SL then
2766 that indicates that part is located in more than one place. The bits of each
2767 place of the part comprise S contiguous bits from the location storage LS
2768 specified by SL starting at the bit offset specified by SL. All the bits must
2769 be within the size of LS or the DWARF expression is ill-formed.
2771 A composite location storage can have zero or more parts. The parts are
2772 contiguous such that the zero-based location storage bit index will range over
2773 each part with no gaps between them. Therefore, the size of a composite location
2774 storage is the sum of the size of its parts. The DWARF expression is ill-formed
2775 if the size of the contiguous location storage is larger than the size of the
2776 memory location storage corresponding to the largest target architecture
2777 specific address space.
2779 A composite location description specifies a composite location storage. The bit
2780 offset corresponds to a bit position within the composite location storage.
2782 There are operations that create a composite location storage.
2784 There are other operations that allow a composite location storage to be
2785 incrementally created. Each part is created by a separate operation. There may
2786 be one or more operations to create the final composite location storage. A
2787 series of such operations describes the parts of the composite location storage
2788 that are in the order that the associated part operations are executed.
2790 To support incremental creation, a composite location storage can be in an
2791 incomplete state. When an incremental operation operates on an incomplete
2792 composite location storage, it adds a new part, otherwise it creates a new
2793 composite location storage. The ``DW_OP_LLVM_piece_end`` operation explicitly
2794 makes an incomplete composite location storage complete.
2796 A composite location description that specifies a composite location storage
2797 that is incomplete is termed an incomplete composite location description. A
2798 composite location description that specifies a composite location storage that
2799 is complete is termed a complete composite location description.
2801 If the top stack entry is a location description that has one incomplete
2802 composite location description SL after the execution of an operation expression
2803 has completed, SL is converted to a complete composite location description.
2805 *Note that this conversion does not happen after the completion of an operation
2806 expression that is evaluated on the same stack by the* ``DW_OP_call*``
2807 *operations. Such executions are not a separate evaluation of an operation
2808 expression, but rather the continued evaluation of the same operation expression
2809 that contains the* ``DW_OP_call*`` *operation.*
2811 If a stack entry is required to be a location description L, but L has an
2812 incomplete composite location description, then the DWARF expression is
2813 ill-formed. The exception is for the operations involved in incrementally
2814 creating a composite location description as described below.
2816 *Note that a DWARF operation expression may arbitrarily compose composite
2817 location descriptions from any other location description, including those that
2818 have multiple single location descriptions, and those that have composite
2819 location descriptions.*
2821 *The incremental composite location description operations are defined to be
2822 compatible with the definitions in DWARF Version 5.*
2826 ``DW_OP_piece`` has a single unsigned LEB128 integer that represents a byte
2829 The action is based on the context:
2831 * If the stack is empty, then a location description L comprised of one
2832 incomplete composite location description SL is pushed on the stack.
2834 An incomplete composite location storage LS is created with a single part
2835 P. P specifies a location description PL and has a bit size of S scaled by
2836 8 (the byte size). PL is comprised of one undefined location description
2839 SL specifies LS with a bit offset of 0.
2841 * Otherwise, if the top stack entry is a location description L comprised of
2842 one incomplete composite location description SL, then the incomplete
2843 composite location storage LS that SL specifies is updated to append a new
2844 part P. P specifies a location description PL and has a bit size of S
2845 scaled by 8 (the byte size). PL is comprised of one undefined location
2846 description PSL. L is left on the stack.
2848 * Otherwise, if the top stack entry is a location description or can be
2849 converted to one, then it is popped and treated as a part location
2850 description PL. Then:
2852 * If the top stack entry (after popping PL) is a location description L
2853 comprised of one incomplete composite location description SL, then the
2854 incomplete composite location storage LS that SL specifies is updated to
2855 append a new part P. P specifies the location description PL and has a
2856 bit size of S scaled by 8 (the byte size). L is left on the stack.
2858 * Otherwise, a location description L comprised of one incomplete
2859 composite location description SL is pushed on the stack.
2861 An incomplete composite location storage LS is created with a single
2862 part P. P specifies the location description PL and has a bit size of S
2863 scaled by 8 (the byte size).
2865 SL specifies LS with a bit offset of 0.
2867 * Otherwise, the DWARF expression is ill-formed
2869 *Many compilers store a single variable in sets of registers or store a
2870 variable partially in memory and partially in registers.* ``DW_OP_piece``
2871 *provides a way of describing where a part of a variable is located.*
2873 *If a non-0 byte displacement is required, the* ``DW_OP_LLVM_offset``
2874 *operation can be used to update the location description before using it as
2875 the part location description of a* ``DW_OP_piece`` *operation.*
2877 *The evaluation rules for the* ``DW_OP_piece`` *operation allow it to be
2878 compatible with the DWARF Version 5 definition.*
2882 Since these extensions allow location descriptions to be entries on the
2883 stack, a simpler operation to create composite location descriptions could
2884 be defined. For example, just one operation that specifies how many parts,
2885 and pops pairs of stack entries for the part size and location
2886 description. Not only would this be a simpler operation and avoid the
2887 complexities of incomplete composite location descriptions, but it may
2888 also have a smaller encoding in practice. However, the desire for
2889 compatibility with DWARF Version 5 is likely a stronger consideration.
2891 2. ``DW_OP_bit_piece``
2893 ``DW_OP_bit_piece`` has two operands. The first is an unsigned LEB128
2894 integer that represents the part bit size S. The second is an unsigned
2895 LEB128 integer that represents a bit displacement B.
2897 The action is the same as for ``DW_OP_piece``, except that any part created
2898 has the bit size S, and the location description PL of any created part is
2899 updated as if the ``DW_OP_constu B; DW_OP_LLVM_bit_offset`` operations were
2902 ``DW_OP_bit_piece`` *is used instead of* ``DW_OP_piece`` *when the piece to
2903 be assembled is not byte-sized or is not at the start of the part location
2906 *If a computed bit displacement is required, the* ``DW_OP_LLVM_bit_offset``
2907 *operation can be used to update the location description before using it as
2908 the part location description of a* ``DW_OP_bit_piece`` *operation.*
2912 The bit offset operand is not needed as ``DW_OP_LLVM_bit_offset`` can be
2913 used on the part's location description.
2915 3. ``DW_OP_LLVM_piece_end`` *New*
2917 If the top stack entry is not a location description L comprised of one
2918 incomplete composite location description SL, then the DWARF expression is
2921 Otherwise, the incomplete composite location storage LS specified by SL is
2922 updated to be a complete composite location description with the same parts.
2924 4. ``DW_OP_LLVM_extend`` *New*
2926 ``DW_OP_LLVM_extend`` has two operands. The first is an unsigned LEB128
2927 integer that represents the element bit size S. The second is an unsigned
2928 LEB128 integer that represents a count C.
2930 It pops one stack entry that must be a location description and is treated
2931 as the part location description PL.
2933 A location description L comprised of one complete composite location
2934 description SL is pushed on the stack.
2936 A complete composite location storage LS is created with C identical parts
2937 P. Each P specifies PL and has a bit size of S.
2939 SL specifies LS with a bit offset of 0.
2941 The DWARF expression is ill-formed if the element bit size or count are 0.
2943 5. ``DW_OP_LLVM_select_bit_piece`` *New*
2945 ``DW_OP_LLVM_select_bit_piece`` has two operands. The first is an unsigned
2946 LEB128 integer that represents the element bit size S. The second is an
2947 unsigned LEB128 integer that represents a count C.
2949 It pops three stack entries. The first must be an integral type value that
2950 represents a bit mask value M. The second must be a location description
2951 that represents the one-location description L1. The third must be a
2952 location description that represents the zero-location description L0.
2954 A complete composite location storage LS is created with C parts P\ :sub:`N`
2955 ordered in ascending N from 0 to C-1 inclusive. Each P\ :sub:`N` specifies
2956 location description PL\ :sub:`N` and has a bit size of S.
2958 PL\ :sub:`N` is as if the ``DW_OP_LLVM_bit_offset N*S`` operation was
2959 applied to PLX\ :sub:`N`\ .
2961 PLX\ :sub:`N` is the same as L0 if the N\ :sup:`th` least significant bit of
2962 M is a zero, otherwise it is the same as L1.
2964 A location description L comprised of one complete composite location
2965 description SL is pushed on the stack. SL specifies LS with a bit offset of
2968 The DWARF expression is ill-formed if S or C are 0, or if the bit size of M
2973 Should the count operand for DW_OP_extend and DW_OP_select_bit_piece be
2974 changed to get the count value off the stack? This would allow support for
2975 architectures that have variable length vector instructions such as ARM
2978 6. ``DW_OP_LLVM_overlay`` *New*
2980 ``DW_OP_LLVM_overlay`` pops four stack entries. The first must be an
2981 integral type value that represents the overlay byte size value S. The
2982 second must be an integral type value that represents the overlay byte
2983 offset value O. The third must be a location description that represents the
2984 overlay location description OL. The fourth must be a location description
2985 that represents the base location description BL.
2987 The action is the same as for ``DW_OP_LLVM_bit_overlay``, except that the
2988 overlay bit size BS and overlay bit offset BO used are S and O respectively
2989 scaled by 8 (the byte size).
2991 7. ``DW_OP_LLVM_bit_overlay`` *New*
2993 ``DW_OP_LLVM_bit_overlay`` pops four stack entries. The first must be an
2994 integral type value that represents the overlay bit size value BS. The
2995 second must be an integral type value that represents the overlay bit offset
2996 value BO. The third must be a location description that represents the
2997 overlay location description OL. The fourth must be a location description
2998 that represents the base location description BL.
3000 The DWARF expression is ill-formed if BS or BO are negative values.
3002 *rbss(L)* is the minimum remaining bit storage size of L which is defined as
3003 follows. LS is the location storage and LO is the location bit offset
3004 specified by a single location description SL of L. The remaining bit
3005 storage size RBSS of SL is the bit size of LS minus LO. *rbss(L)* is the
3006 minimum RBSS of each single location description SL of L.
3008 The DWARF expression is ill-formed if *rbss(BL)* is less than BO plus BS.
3010 If BS is 0, then the operation pushes BL.
3012 If BO is 0 and BS equals *rbss(BL)*, then the operation pushes OL.
3014 Otherwise, the operation is equivalent to performing the following steps to
3015 push a composite location description.
3017 *The composite location description is conceptually the base location
3018 description BL with the overlay location description OL positioned as an
3019 overlay starting at the overlay offset BO and covering overlay bit size BS.*
3021 1. If BO is not 0 then push BL followed by performing the ``DW_OP_bit_piece
3023 2. Push OL followed by performing the ``DW_OP_bit_piece BS, 0`` operation.
3024 3. If *rbss(BL)* is greater than BO plus BS, push BL followed by performing
3025 the ``DW_OP_bit_piece (rbss(BL) - BO - BS), (BO + BS)`` operation.
3026 4. Perform the ``DW_OP_LLVM_piece_end`` operation.
3028 .. _amdgpu-dwarf-location-list-expressions:
3030 A.2.5.5 DWARF Location List Expressions
3031 +++++++++++++++++++++++++++++++++++++++
3035 This section replaces DWARF Version 5 section 2.6.2.
3037 *To meet the needs of recent computer architectures and optimization techniques,
3038 debugging information must be able to describe the location of an object whose
3039 location changes over the object’s lifetime, and may reside at multiple
3040 locations during parts of an object's lifetime. Location list expressions are
3041 used in place of operation expressions whenever the object whose location is
3042 being described has these requirements.*
3044 A location list expression consists of a series of location list entries. Each
3045 location list entry is one of the following kinds:
3047 *Bounded location description*
3049 This kind of location list entry provides an operation expression that
3050 evaluates to the location description of an object that is valid over a
3051 lifetime bounded by a starting and ending address. The starting address is the
3052 lowest address of the address range over which the location is valid. The
3053 ending address is the address of the first location past the highest address
3054 of the address range.
3056 The location list entry matches when the current program location is within
3059 There are several kinds of bounded location description entries which differ
3060 in the way that they specify the starting and ending addresses.
3062 *Default location description*
3064 This kind of location list entry provides an operation expression that
3065 evaluates to the location description of an object that is valid when no
3066 bounded location description entry applies.
3068 The location list entry matches when the current program location is not
3069 within the range of any bounded location description entry.
3073 This kind of location list entry provides an address to be used as the base
3074 address for beginning and ending address offsets given in certain kinds of
3075 bounded location description entries. The applicable base address of a bounded
3076 location description entry is the address specified by the closest preceding
3077 base address entry in the same location list. If there is no preceding base
3078 address entry, then the applicable base address defaults to the base address
3079 of the compilation unit (see DWARF Version 5 section 3.1.1).
3081 In the case of a compilation unit where all of the machine code is contained
3082 in a single contiguous section, no base address entry is needed.
3086 This kind of location list entry marks the end of the location list
3089 The address ranges defined by the bounded location description entries of a
3090 location list expression may overlap. When they do, they describe a situation in
3091 which an object exists simultaneously in more than one place.
3093 If all of the address ranges in a given location list expression do not
3094 collectively cover the entire range over which the object in question is
3095 defined, and there is no following default location description entry, it is
3096 assumed that the object is not available for the portion of the range that is
3099 The result of the evaluation of a DWARF location list expression is:
3101 * If the current program location is not specified, then it is an evaluation
3106 If the location list only has a single default entry, should that be
3107 considered a match if there is no program location? If there are non-default
3108 entries then it seems it has to be an evaluation error when there is no
3109 program location as that indicates the location depends on the program
3110 location which is not known.
3112 * If there are no matching location list entries, then the result is a location
3113 description that comprises one undefined location description.
3115 * Otherwise, the operation expression E of each matching location list entry is
3116 evaluated with the current context, except that the result kind is a location
3117 description, the object is unspecified, and the initial stack is empty. The
3118 location list entry result is the location description returned by the
3121 The result is a location description that is comprised of the union of the
3122 single location descriptions of the location description result of each
3123 matching location list entry.
3125 A location list expression can only be used as the value of a debugger
3126 information entry attribute that is encoded using class ``loclist`` or
3127 ``loclistsptr`` (see :ref:`amdgpu-dwarf-classes-and-forms`). The value of the
3128 attribute provides an index into a separate object file section called
3129 ``.debug_loclists`` or ``.debug_loclists.dwo`` (for split DWARF object files)
3130 that contains the location list entries.
3132 A ``DW_OP_call*`` and ``DW_OP_implicit_pointer`` operation can be used to
3133 specify a debugger information entry attribute that has a location list
3134 expression. Several debugger information entry attributes allow DWARF
3135 expressions that are evaluated with an initial stack that includes a location
3136 description that may originate from the evaluation of a location list
3139 *This location list representation, the* ``loclist`` *and* ``loclistsptr``
3140 *class, and the related* ``DW_AT_loclists_base`` *attribute are new in DWARF
3141 Version 5. Together they eliminate most, or all of the code object relocations
3142 previously needed for location list expressions.*
3146 The rest of this section is the same as DWARF Version 5 section 2.6.2.
3148 .. _amdgpu-dwarf-address-spaces:
3150 A.2.13 Address Spaces
3151 ~~~~~~~~~~~~~~~~~~~~~
3155 This is a new section after DWARF Version 5 section 2.12 Segmented Addresses.
3157 DWARF address spaces correspond to target architecture specific linear
3158 addressable memory areas. They are used in DWARF expression location
3159 descriptions to describe in which target architecture specific memory area data
3162 *Target architecture specific DWARF address spaces may correspond to hardware
3163 supported facilities such as memory utilizing base address registers, scratchpad
3164 memory, and memory with special interleaving. The size of addresses in these
3165 address spaces may vary. Their access and allocation may be hardware managed
3166 with each thread or group of threads having access to independent storage. For
3167 these reasons they may have properties that do not allow them to be viewed as
3168 part of the unified global virtual address space accessible by all threads.*
3170 *It is target architecture specific whether multiple DWARF address spaces are
3171 supported and how source language memory spaces map to target architecture
3172 specific DWARF address spaces. A target architecture may map multiple source
3173 language memory spaces to the same target architecture specific DWARF address
3174 class. Optimization may determine that variable lifetime and access pattern
3175 allows them to be allocated in faster scratchpad memory represented by a
3176 different DWARF address space than the default for the source language memory
3179 Although DWARF address space identifiers are target architecture specific,
3180 ``DW_ASPACE_LLVM_none`` is a common address space supported by all target
3181 architectures, and defined as the target architecture default address space.
3183 DWARF address space identifiers are used by:
3185 * The ``DW_AT_LLVM_address_space`` attribute.
3187 * The DWARF expression operations: ``DW_OP_aspace_bregx``,
3188 ``DW_OP_form_aspace_address``, ``DW_OP_aspace_implicit_pointer``, and
3191 * The CFI instructions: ``DW_CFA_def_aspace_cfa`` and
3192 ``DW_CFA_def_aspace_cfa_sf``.
3196 Currently, DWARF defines address class values as being target architecture
3197 specific, and defines a DW_AT_address_class attribute. With the removal of
3198 DW_AT_segment in DWARF 6, it is unclear how the address class is intended to
3199 be used as the term is not used elsewhere. Should these be replaced by this
3200 proposal's more complete address space? Or are they intended to represent
3201 source language memory spaces such as in OpenCL?
3203 .. _amdgpu-dwarf-memory-spaces:
3205 A.2.14 Memory Spaces
3206 ~~~~~~~~~~~~~~~~~~~~
3210 This is a new section after DWARF Version 5 section 2.12 Segmented Addresses.
3212 DWARF memory spaces are used for source languages that have the concept of
3213 memory spaces. They are used in the ``DW_AT_LLVM_memory_space`` attribute for
3214 pointer type, reference type, variable, formal parameter, and constant debugger
3215 information entries.
3217 Each DWARF memory space is conceptually a separate source language memory space
3218 with its own lifetime and aliasing rules. DWARF memory spaces are used to
3219 specify the source language memory spaces that pointer type and reference type
3220 values refer, and to specify the source language memory space in which variables
3223 Although DWARF memory space identifiers are source language specific,
3224 ``DW_MSPACE_LLVM_none`` is a common memory space supported by all source
3225 languages, and defined as the source language default memory space.
3227 The set of currently defined DWARF memory spaces, together with source language
3228 mappings, is given in :ref:`amdgpu-dwarf-source-language-memory-spaces-table`.
3230 Vendor defined source language memory spaces may be defined using codes in the
3231 range ``DW_MSPACE_LLVM_lo_user`` to ``DW_MSPACE_LLVM_hi_user``.
3233 .. table:: Source language memory spaces
3234 :name: amdgpu-dwarf-source-language-memory-spaces-table
3236 =========================== ============ ============== ============== ==============
3237 Memory Space Name Meaning C/C++ OpenCL CUDA/HIP
3238 =========================== ============ ============== ============== ==============
3239 ``DW_MSPACE_LLVM_none`` generic *default* generic *default*
3240 ``DW_MSPACE_LLVM_global`` global global
3241 ``DW_MSPACE_LLVM_constant`` constant constant constant
3242 ``DW_MSPACE_LLVM_group`` thread-group local shared
3243 ``DW_MSPACE_LLVM_private`` thread private
3244 ``DW_MSPACE_LLVM_lo_user``
3245 ``DW_MSPACE_LLVM_hi_user``
3246 =========================== ============ ============== ============== ==============
3250 The approach presented in
3251 :ref:`amdgpu-dwarf-source-language-memory-spaces-table` is to define the
3252 default ``DW_MSPACE_LLVM_none`` to be the generic address class and not the
3253 global address class. This matches how CLANG and LLVM have added support for
3254 CUDA-like languages on top of existing C++ language support. This allows all
3255 addresses to be generic by default which matches CUDA-like languages.
3257 An alternative approach is to define ``DW_MSPACE_LLVM_none`` as being the
3258 global memory space and then change ``DW_MSPACE_LLVM_global`` to
3259 ``DW_MSPACE_LLVM_generic``. This would match the reality that languages that
3260 do not support multiple memory spaces only have one default global memory
3261 space. Generally, in these languages if they expose that the target
3262 architecture supports multiple memory spaces, the default one is still the
3263 global memory space. Then a language that does support multiple memory spaces
3264 has to explicitly indicate which pointers have the added ability to reference
3265 more than the global memory space. However, compilers generating DWARF for
3266 CUDA-like languages would then have to define every CUDA-like language pointer
3267 type or reference type with a ``DW_AT_LLVM_memory_space`` attribute of
3268 ``DW_MSPACE_LLVM_generic`` to match the language semantics.
3270 A.3 Program Scope Entries
3271 -------------------------
3275 This section provides changes to existing debugger information entry
3276 attributes. These would be incorporated into the corresponding DWARF Version 5
3282 .. _amdgpu-dwarf-full-and-partial-compilation-unit-entries:
3284 A.3.1.1 Full and Partial Compilation Unit Entries
3285 +++++++++++++++++++++++++++++++++++++++++++++++++
3289 This augments DWARF Version 5 section 3.1.1 and Table 3.1.
3291 Additional language codes defined for use with the ``DW_AT_language`` attribute
3292 are defined in :ref:`amdgpu-dwarf-language-names-table`.
3294 .. table:: Language Names
3295 :name: amdgpu-dwarf-language-names-table
3297 ==================== =============================
3298 Language Name Meaning
3299 ==================== =============================
3300 ``DW_LANG_LLVM_HIP`` HIP Language.
3301 ==================== =============================
3303 The HIP language [:ref:`HIP <amdgpu-dwarf-HIP>`] can be supported by extending
3308 The following new attribute is added.
3310 1. A ``DW_TAG_compile_unit`` debugger information entry for a compilation unit
3311 may have a ``DW_AT_LLVM_augmentation`` attribute, whose value is an
3312 augmentation string.
3314 *The augmentation string allows producers to indicate that there is
3315 additional vendor or target specific information in the debugging
3316 information entries. For example, this might be information about the
3317 version of vendor specific extensions that are being used.*
3319 If not present, or if the string is empty, then the compilation unit has no
3320 augmentation string.
3322 The format for the augmentation string is:
3324 | ``[``\ *vendor*\ ``:v``\ *X*\ ``.``\ *Y*\ [\ ``:``\ *options*\ ]\ ``]``\ *
3326 Where *vendor* is the producer, ``vX.Y`` specifies the major X and minor Y
3327 version number of the extensions used, and *options* is an optional string
3328 providing additional information about the extensions. The version number
3329 must conform to semantic versioning [:ref:`SEMVER <amdgpu-dwarf-SEMVER>`].
3330 The *options* string must not contain the "\ ``]``\ " character.
3336 [abc:v0.0][def:v1.2:feature-a=on,feature-b=3]
3338 A.3.3 Subroutine and Entry Point Entries
3339 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3341 .. _amdgpu-dwarf-low-level-information:
3343 A.3.3.5 Low-Level Information
3344 +++++++++++++++++++++++++++++
3346 1. A ``DW_TAG_subprogram``, ``DW_TAG_inlined_subroutine``, or
3347 ``DW_TAG_entry_point`` debugger information entry may have a
3348 ``DW_AT_return_addr`` attribute, whose value is a DWARF expression E.
3350 The result of the attribute is obtained by evaluating E with a context that
3351 has a result kind of a location description, an unspecified object, the
3352 compilation unit that contains E, an empty initial stack, and other context
3353 elements corresponding to the source language thread of execution upon which
3354 the user is focused, if any. The result of the evaluation is the location
3355 description L of the place where the return address for the current call
3356 frame's subprogram or entry point is stored.
3358 The DWARF is ill-formed if L is not comprised of one memory location
3359 description for one of the target architecture specific address spaces.
3363 It is unclear why ``DW_TAG_inlined_subroutine`` has a
3364 ``DW_AT_return_addr`` attribute but not a ``DW_AT_frame_base`` or
3365 ``DW_AT_static_link`` attribute. Seems it would either have all of them or
3366 none. Since inlined subprograms do not have a call frame it seems they
3367 would have none of these attributes.
3369 2. A ``DW_TAG_subprogram`` or ``DW_TAG_entry_point`` debugger information entry
3370 may have a ``DW_AT_frame_base`` attribute, whose value is a DWARF expression
3373 The result of the attribute is obtained by evaluating E with a context that
3374 has a result kind of a location description, an unspecified object, the
3375 compilation unit that contains E, an empty initial stack, and other context
3376 elements corresponding to the source language thread of execution upon which
3377 the user is focused, if any.
3379 The DWARF is ill-formed if E contains a ``DW_OP_fbreg`` operation, or the
3380 resulting location description L is not comprised of one single location
3383 If SL is a register location description for register R, then L is replaced
3384 with the result of evaluating a ``DW_OP_bregx R, 0`` operation. This
3385 computes the frame base memory location description in the target
3386 architecture default address space.
3388 *This allows the more compact* ``DW_OP_reg*`` *to be used instead of*
3389 ``DW_OP_breg* 0``\ *.*
3393 This rule could be removed and require the producer to create the required
3394 location description directly using ``DW_OP_call_frame_cfa``,
3395 ``DW_OP_breg*``, or ``DW_OP_LLVM_aspace_bregx``. This would also then
3396 allow a target to implement the call frames within a large register.
3398 Otherwise, the DWARF is ill-formed if SL is not a memory location
3399 description in any of the target architecture specific address spaces.
3401 The resulting L is the *frame base* for the subprogram or entry point.
3403 *Typically, E will use the* ``DW_OP_call_frame_cfa`` *operation or be a
3404 stack pointer register plus or minus some offset.*
3406 *The frame base for a subprogram is typically an address relative to the
3407 first unit of storage allocated for the subprogram's stack frame. The*
3408 ``DW_AT_frame_base`` *attribute can be used in several ways:*
3410 1. *In subprograms that need location lists to locate local variables, the*
3411 ``DW_AT_frame_base`` *can hold the needed location list, while all
3412 variables' location descriptions can be simpler ones involving the frame
3415 2. *It can be used in resolving "up-level" addressing within
3416 nested routines. (See also* ``DW_AT_static_link``\ *, below)*
3418 *Some languages support nested subroutines. In such languages, it is
3419 possible to reference the local variables of an outer subroutine from within
3420 an inner subroutine. The* ``DW_AT_static_link`` *and* ``DW_AT_frame_base``
3421 *attributes allow debuggers to support this same kind of referencing.*
3423 3. If a ``DW_TAG_subprogram`` or ``DW_TAG_entry_point`` debugger information
3424 entry is lexically nested, it may have a ``DW_AT_static_link`` attribute,
3425 whose value is a DWARF expression E.
3427 The result of the attribute is obtained by evaluating E with a context that
3428 has a result kind of a location description, an unspecified object, the
3429 compilation unit that contains E, an empty initial stack, and other context
3430 elements corresponding to the source language thread of execution upon which
3431 the user is focused, if any. The result of the evaluation is the location
3432 description L of the *canonical frame address* (see
3433 :ref:`amdgpu-dwarf-call-frame-information`) of the relevant call frame of
3434 the subprogram instance that immediately lexically encloses the current call
3435 frame's subprogram or entry point.
3437 The DWARF is ill-formed if L is not comprised of one memory location
3438 description for one of the target architecture specific address spaces.
3440 In the context of supporting nested subroutines, the DW_AT_frame_base
3441 attribute value obeys the following constraints:
3443 1. It computes a value that does not change during the life of the
3446 2. The computed value is unique among instances of the same subroutine.
3448 *For typical DW_AT_frame_base use, this means that a recursive subroutine's
3449 stack frame must have non-zero size.*
3451 *If a debugger is attempting to resolve an up-level reference to a variable,
3452 it uses the nesting structure of DWARF to determine which subroutine is the
3453 lexical parent and the* ``DW_AT_static_link`` *value to identify the
3454 appropriate active frame of the parent. It can then attempt to find the
3455 reference within the context of the parent.*
3459 The following new attributes are added.
3461 4. For languages that are implemented using a SIMT execution model, a
3462 ``DW_TAG_subprogram``, ``DW_TAG_inlined_subroutine``, or
3463 ``DW_TAG_entry_point`` debugger information entry may have a
3464 ``DW_AT_LLVM_lanes`` attribute whose value is an integer constant that is
3465 the number of source language threads of execution per target architecture
3468 *For example, a compiler may map source language threads of execution onto
3469 lanes of a target architecture thread using a SIMT execution model.*
3471 It is the static number of source language threads of execution per target
3472 architecture thread. It is not the dynamic number of source language threads
3473 of execution with which the target architecture thread was initiated, for
3474 example, due to smaller or partial work-groups.
3476 If not present, the default value of 1 is used.
3478 The DWARF is ill-formed if the value is less than or equal to 0.
3480 5. For source languages that are implemented using a SIMT execution model, a
3481 ``DW_TAG_subprogram``, ``DW_TAG_inlined_subroutine``, or
3482 ``DW_TAG_entry_point`` debugging information entry may have a
3483 ``DW_AT_LLVM_lane_pc`` attribute whose value is a DWARF expression E.
3485 The result of the attribute is obtained by evaluating E with a context that
3486 has a result kind of a location description, an unspecified object, the
3487 compilation unit that contains E, an empty initial stack, and other context
3488 elements corresponding to the source language thread of execution upon which
3489 the user is focused, if any.
3491 The resulting location description L is for a lane count sized vector of
3492 generic type elements. The lane count is the value of the
3493 ``DW_AT_LLVM_lanes`` attribute. Each element holds the conceptual program
3494 location of the corresponding lane. If the lane was not active when the
3495 current subprogram was called, its element is an undefined location
3498 The DWARF is ill-formed if L does not have exactly one single location
3501 ``DW_AT_LLVM_lane_pc`` *allows the compiler to indicate conceptually where
3502 each SIMT lane of a target architecture thread is positioned even when it is
3503 in divergent control flow that is not active.*
3505 *Typically, the result is a location description with one composite location
3506 description with each part being a location description with either one
3507 undefined location description or one memory location description.*
3509 If not present, the target architecture thread is not being used in a SIMT
3510 manner, and the thread's current program location is used.
3512 6. For languages that are implemented using a SIMT execution model, a
3513 ``DW_TAG_subprogram``, ``DW_TAG_inlined_subroutine``, or
3514 ``DW_TAG_entry_point`` debugger information entry may have a
3515 ``DW_AT_LLVM_active_lane`` attribute whose value is a DWARF expression E.
3517 E is evaluated with a context that has a result kind of a location
3518 description, an unspecified object, the compilation unit that contains E, an
3519 empty initial stack, and other context elements corresponding to the source
3520 language thread of execution upon which the user is focused, if any.
3522 The DWARF is ill-formed if L does not have exactly one single location
3525 The active lane bit mask V for the current program location is obtained by
3526 reading from SL using a target architecture specific integral base type T
3527 that has a bit size equal to the value of the ``DW_AT_LLVM_lanes`` attribute
3528 of the subprogram corresponding to context's frame and program location. The
3529 N\ :sup:`th` least significant bit of the mask corresponds to the N\
3530 :sup:`th` lane. If the bit is 1 the lane is active, otherwise it is
3531 inactive. The result of the attribute is the value V.
3533 *Some targets may update the target architecture execution mask for regions
3534 of code that must execute with different sets of lanes than the current
3535 active lanes. For example, some code must execute with all lanes made
3536 temporarily active.* ``DW_AT_LLVM_active_lane`` *allows the compiler to
3537 provide the means to determine the source language active lanes at any
3538 program location. Typically, this attribute will use a loclist to express
3539 different locations of the active lane mask at different program locations.*
3541 If not present and ``DW_AT_LLVM_lanes`` is greater than 1, then the target
3542 architecture execution mask is used.
3544 7. A ``DW_TAG_subprogram``, ``DW_TAG_inlined_subroutine``, or
3545 ``DW_TAG_entry_point`` debugger information entry may have a
3546 ``DW_AT_LLVM_iterations`` attribute whose value is an integer constant or a
3547 DWARF expression E. Its value is the number of source language loop
3548 iterations executing concurrently by the target architecture for a single
3549 source language thread of execution.
3551 *A compiler may generate code that executes more than one iteration of a
3552 source language loop concurrently using optimization techniques such as
3553 software pipelining or SIMD vectorization. The number of concurrent
3554 iterations may vary for different loop nests in the same subprogram.
3555 Typically, this attribute will use a loclist to express different values at
3556 different program locations.*
3558 If the attribute is an integer constant, then the value is the constant. The
3559 DWARF is ill-formed if the constant is less than or equal to 0.
3561 Otherwise, E is evaluated with a context that has a result kind of a
3562 location description, an unspecified object, the compilation unit that
3563 contains E, an empty initial stack, and other context elements corresponding
3564 to the source language thread of execution upon which the user is focused,
3565 if any. The DWARF is ill-formed if the result is not a location description
3566 comprised of one implicit location description, that when read as the
3567 generic type, results in a value V that is less than or equal to 0. The
3568 result of the attribute is the value V.
3570 If not present, the default value of 1 is used.
3572 A.3.4 Call Site Entries and Parameters
3573 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3575 A.3.4.2 Call Site Parameters
3576 ++++++++++++++++++++++++++++
3578 1. The call site entry may own ``DW_TAG_call_site_parameter`` debugging
3579 information entries representing the parameters passed to the call. Call
3580 site parameter entries occur in the same order as the corresponding
3581 parameters in the source. Each such entry has a ``DW_AT_location`` attribute
3582 which is a location description. This location description describes where
3583 the parameter is passed (usually either some register, or a memory location
3584 expressible as the contents of the stack register plus some offset).
3586 2. A ``DW_TAG_call_site_parameter`` debugger information entry may have a
3587 ``DW_AT_call_value`` attribute, whose value is a DWARF operation expression
3590 The result of the ``DW_AT_call_value`` attribute is obtained by evaluating
3591 E\ :sub:`1` with a context that has a result kind of a value, an unspecified
3592 object, the compilation unit that contains E, an empty initial stack, and
3593 other context elements corresponding to the source language thread of
3594 execution upon which the user is focused, if any. The resulting value V\
3595 :sub:`1` is the value of the parameter at the time of the call made by the
3598 For parameters passed by reference, where the code passes a pointer to a
3599 location which contains the parameter, or for reference type parameters, the
3600 ``DW_TAG_call_site_parameter`` debugger information entry may also have a
3601 ``DW_AT_call_data_location`` attribute whose value is a DWARF operation
3602 expression E\ :sub:`2`\ , and a ``DW_AT_call_data_value`` attribute whose
3603 value is a DWARF operation expression E\ :sub:`3`\ .
3605 The value of the ``DW_AT_call_data_location`` attribute is obtained by
3606 evaluating E\ :sub:`2` with a context that has a result kind of a location
3607 description, an unspecified object, the compilation unit that contains E, an
3608 empty initial stack, and other context elements corresponding to the source
3609 language thread of execution upon which the user is focused, if any. The
3610 resulting location description L\ :sub:`2` is the location where the
3611 referenced parameter lives during the call made by the call site. If E\
3612 :sub:`2` would just be a ``DW_OP_push_object_address``, then the
3613 ``DW_AT_call_data_location`` attribute may be omitted.
3617 The DWARF Version 5 implies that ``DW_OP_push_object_address`` may be used
3618 but does not state what object must be specified in the context. Either
3619 ``DW_OP_push_object_address`` cannot be used, or the object to be passed
3620 in the context must be defined.
3622 The value of the ``DW_AT_call_data_value`` attribute is obtained by
3623 evaluating E\ :sub:`3` with a context that has a result kind of a value, an
3624 unspecified object, the compilation unit that contains E, an empty initial
3625 stack, and other context elements corresponding to the source language
3626 thread of execution upon which the user is focused, if any. The resulting
3627 value V\ :sub:`3` is the value in L\ :sub:`2` at the time of the call made
3630 The result of these attributes is undefined if the current call frame is not
3631 for the subprogram containing the ``DW_TAG_call_site_parameter`` debugger
3632 information entry or the current program location is not for the call site
3633 containing the ``DW_TAG_call_site_parameter`` debugger information entry in
3634 the current call frame.
3636 *The consumer may have to virtually unwind to the call site (see*
3637 :ref:`amdgpu-dwarf-call-frame-information`\ *) in order to evaluate these
3638 attributes. This will ensure the source language thread of execution upon
3639 which the user is focused corresponds to the call site needed to evaluate
3642 If it is not possible to avoid the expressions of these attributes from
3643 accessing registers or memory locations that might be clobbered by the
3644 subprogram being called by the call site, then the associated attribute
3645 should not be provided.
3647 *The reason for the restriction is that the parameter may need to be
3648 accessed during the execution of the callee. The consumer may virtually
3649 unwind from the called subprogram back to the caller and then evaluate the
3650 attribute expressions. The call frame information (see*
3651 :ref:`amdgpu-dwarf-call-frame-information`\ *) will not be able to restore
3652 registers that have been clobbered, and clobbered memory will no longer have
3653 the value at the time of the call.*
3655 3. Each call site parameter entry may also have a ``DW_AT_call_parameter``
3656 attribute which contains a reference to a ``DW_TAG_formal_parameter`` entry,
3657 ``DW_AT_type attribute`` referencing the type of the parameter or
3658 ``DW_AT_name`` attribute describing the parameter's name.
3660 *Examples using call site entries and related attributes are found in Appendix
3663 .. _amdgpu-dwarf-lexical-block-entries:
3665 A.3.5 Lexical Block Entries
3666 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
3670 This section is the same as DWARF Version 5 section 3.5.
3672 A.4 Data Object and Object List Entries
3673 ---------------------------------------
3677 This section provides changes to existing debugger information entry
3678 attributes. These would be incorporated into the corresponding DWARF Version 5
3681 .. _amdgpu-dwarf-data-object-entries:
3683 A.4.1 Data Object Entries
3684 ~~~~~~~~~~~~~~~~~~~~~~~~~
3686 Program variables, formal parameters and constants are represented by debugging
3687 information entries with the tags ``DW_TAG_variable``,
3688 ``DW_TAG_formal_parameter`` and ``DW_TAG_constant``, respectively.
3690 *The tag DW_TAG_constant is used for languages that have true named constants.*
3692 The debugging information entry for a program variable, formal parameter or
3693 constant may have the following attributes:
3695 1. A ``DW_AT_location`` attribute, whose value is a DWARF expression E that
3696 describes the location of a variable or parameter at run-time.
3698 The result of the attribute is obtained by evaluating E with a context that
3699 has a result kind of a location description, an unspecified object, the
3700 compilation unit that contains E, an empty initial stack, and other context
3701 elements corresponding to the source language thread of execution upon which
3702 the user is focused, if any. The result of the evaluation is the location
3703 description of the base of the data object.
3705 See :ref:`amdgpu-dwarf-control-flow-operations` for special evaluation rules
3706 used by the ``DW_OP_call*`` operations.
3710 Delete the description of how the ``DW_OP_call*`` operations evaluate a
3711 ``DW_AT_location`` attribute as that is now described in the operations.
3715 See the discussion about the ``DW_AT_location`` attribute in the
3716 ``DW_OP_call*`` operation. Having each attribute only have a single
3717 purpose and single execution semantics seems desirable. It makes it easier
3718 for the consumer that no longer have to track the context. It makes it
3719 easier for the producer as it can rely on a single semantics for each
3722 For that reason, limiting the ``DW_AT_location`` attribute to only
3723 supporting evaluating the location description of an object, and using a
3724 different attribute and encoding class for the evaluation of DWARF
3725 expression *procedures* on the same operation expression stack seems
3728 2. ``DW_AT_const_value``
3732 Could deprecate using the ``DW_AT_const_value`` attribute for
3733 ``DW_TAG_variable`` or ``DW_TAG_formal_parameter`` debugger information
3734 entries that have been optimized to a constant. Instead,
3735 ``DW_AT_location`` could be used with a DWARF expression that produces an
3736 implicit location description now that any location description can be
3737 used within a DWARF expression. This allows the ``DW_OP_call*`` operations
3738 to be used to push the location description of any variable regardless of
3739 how it is optimized.
3741 3. ``DW_AT_LLVM_memory_space``
3743 A ``DW_AT_memory_space`` attribute with a constant value representing a source
3744 language specific DWARF memory space (see 2.14 "Memory Spaces"). If omitted,
3745 defaults to ``DW_MSPACE_none``.
3748 A.4.2 Common Block Entries
3749 ~~~~~~~~~~~~~~~~~~~~~~~~~~
3751 A common block entry also has a ``DW_AT_location`` attribute whose value is a
3752 DWARF expression E that describes the location of the common block at run-time.
3753 The result of the attribute is obtained by evaluating E with a context that has
3754 a result kind of a location description, an unspecified object, the compilation
3755 unit that contains E, an empty initial stack, and other context elements
3756 corresponding to the source language thread of execution upon which the user is
3757 focused, if any. The result of the evaluation is the location description of the
3758 base of the common block. See :ref:`amdgpu-dwarf-control-flow-operations` for
3759 special evaluation rules used by the ``DW_OP_call*`` operations.
3766 This section provides changes to existing debugger information entry
3767 attributes. These would be incorporated into the corresponding DWARF Version 5
3770 .. _amdgpu-dwarf-base-type-entries:
3772 A.5.1 Base Type Entries
3773 ~~~~~~~~~~~~~~~~~~~~~~~
3777 The following new attribute is added.
3779 1. A ``DW_TAG_base_type`` debugger information entry for a base type T may have
3780 a ``DW_AT_LLVM_vector_size`` attribute whose value is an integer constant
3781 that is the vector type size N.
3783 The representation of a vector base type is as N contiguous elements, each
3784 one having the representation of a base type T' that is the same as T
3785 without the ``DW_AT_LLVM_vector_size`` attribute.
3787 If a ``DW_TAG_base_type`` debugger information entry does not have a
3788 ``DW_AT_LLVM_vector_size`` attribute, then the base type is not a vector
3791 The DWARF is ill-formed if N is not greater than 0.
3795 LLVM has mention of a non-upstreamed debugger information entry that is
3796 intended to support vector types. However, that was not for a base type so
3797 would not be suitable as the type of a stack value entry. But perhaps that
3798 could be replaced by using this attribute.
3802 Compare this with the ``DW_AT_GNU_vector`` extension supported by GNU. Is
3803 it better to add an attribute to the existing ``DW_TAG_base_type`` debug
3804 entry, or allow some forms of ``DW_TAG_array_type`` (those that have the
3805 ``DW_AT_GNU_vector`` attribute) to be used as stack entry value types?
3807 .. _amdgpu-dwarf-type-modifier-entries:
3809 A.5.3 Type Modifier Entries
3810 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
3814 This section augments DWARF Version 5 section 5.3.
3816 A modified type entry describing a pointer or reference type (using
3817 ``DW_TAG_pointer_type``, ``DW_TAG_reference_type`` or
3818 ``DW_TAG_rvalue_reference_type``\ ) may have a ``DW_AT_LLVM_memory_space``
3819 attribute with a constant value representing a source language specific DWARF
3820 memory space (see :ref:`amdgpu-dwarf-memory-spaces`). If omitted, defaults to
3821 DW_MSPACE_LLVM_none.
3823 A modified type entry describing a pointer or reference type (using
3824 ``DW_TAG_pointer_type``, ``DW_TAG_reference_type`` or
3825 ``DW_TAG_rvalue_reference_type``\ ) may have a ``DW_AT_LLVM_address_space``
3826 attribute with a constant value AS representing an architecture specific DWARF
3827 address space (see :ref:`amdgpu-dwarf-address-spaces`). If omitted, defaults to
3828 ``DW_ASPACE_LLVM_none``. DR is the offset of a hypothetical debug information
3829 entry D in the current compilation unit for an integral base type matching the
3830 address size of AS. An object P having the given pointer or reference type are
3831 dereferenced as if the ``DW_OP_push_object_address; DW_OP_deref_type DR;
3832 DW_OP_constu AS; DW_OP_form_aspace_address`` operation expression was evaluated
3833 with the current context except: the result kind is location description; the
3834 initial stack is empty; and the object is the location description of P.
3838 What if the current context does not have a current target architecture
3843 With the expanded support for DWARF address spaces, it may be worth examining
3844 if they can be used for what was formerly supported by DWARF 5 segments. That
3845 would include specifying the address space of all code addresses (compilation
3846 units, subprograms, subprogram entries, labels, subprogram types, etc.).
3847 Either the code address attributes could be extended to allow a exprloc form
3848 (so that ``DW_OP_form_aspace_address`` can be used) or the
3849 ``DW_AT_LLVM_address_space`` attribute be allowed on all DIEs that allow
3852 A.5.7 Structure, Union, Class and Interface Type Entries
3853 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3855 A.5.7.3 Derived or Extended Structures, Classes and Interfaces
3856 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3858 1. For a ``DW_AT_data_member_location`` attribute there are two cases:
3860 1. If the attribute is an integer constant B, it provides the offset in
3861 bytes from the beginning of the containing entity.
3863 The result of the attribute is obtained by evaluating a
3864 ``DW_OP_LLVM_offset B`` operation with an initial stack comprising the
3865 location description of the beginning of the containing entity. The
3866 result of the evaluation is the location description of the base of the
3869 *If the beginning of the containing entity is not byte aligned, then the
3870 beginning of the member entry has the same bit displacement within a
3873 2. Otherwise, the attribute must be a DWARF expression E which is evaluated
3874 with a context that has a result kind of a location description, an
3875 unspecified object, the compilation unit that contains E, an initial
3876 stack comprising the location description of the beginning of the
3877 containing entity, and other context elements corresponding to the
3878 source language thread of execution upon which the user is focused, if
3879 any. The result of the evaluation is the location description of the
3880 base of the member entry.
3884 The beginning of the containing entity can now be any location
3885 description, including those with more than one single location
3886 description, and those with single location descriptions that are of any
3887 kind and have any bit offset.
3889 A.5.7.8 Member Function Entries
3890 +++++++++++++++++++++++++++++++
3892 1. An entry for a virtual function also has a ``DW_AT_vtable_elem_location``
3893 attribute whose value is a DWARF expression E.
3895 The result of the attribute is obtained by evaluating E with a context that
3896 has a result kind of a location description, an unspecified object, the
3897 compilation unit that contains E, an initial stack comprising the location
3898 description of the object of the enclosing type, and other context elements
3899 corresponding to the source language thread of execution upon which the user
3900 is focused, if any. The result of the evaluation is the location description
3901 of the slot for the function within the virtual function table for the
3904 A.5.14 Pointer to Member Type Entries
3905 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3907 1. The ``DW_TAG_ptr_to_member_type`` debugging information entry has a
3908 ``DW_AT_use_location`` attribute whose value is a DWARF expression E. It is
3909 used to compute the location description of the member of the class to which
3910 the pointer to member entry points.
3912 *The method used to find the location description of a given member of a
3913 class, structure, or union is common to any instance of that class,
3914 structure, or union and to any instance of the pointer to member type. The
3915 method is thus associated with the pointer to member type, rather than with
3916 each object that has a pointer to member type.*
3918 The ``DW_AT_use_location`` DWARF expression is used in conjunction with the
3919 location description for a particular object of the given pointer to member
3920 type and for a particular structure or class instance.
3922 The result of the attribute is obtained by evaluating E with a context that
3923 has a result kind of a location description, an unspecified object, the
3924 compilation unit that contains E, an initial stack comprising two entries,
3925 and other context elements corresponding to the source language thread of
3926 execution upon which the user is focused, if any. The first stack entry is
3927 the value of the pointer to member object itself. The second stack entry is
3928 the location description of the base of the entire class, structure, or
3929 union instance containing the member whose location is being calculated. The
3930 result of the evaluation is the location description of the member of the
3931 class to which the pointer to member entry points.
3933 A.5.18 Dynamic Properties of Types
3934 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3936 A.5.18.1 Data Location
3937 ++++++++++++++++++++++
3939 *Some languages may represent objects using descriptors to hold information,
3940 including a location and/or run-time parameters, about the data that represents
3941 the value for that object.*
3943 1. The ``DW_AT_data_location`` attribute may be used with any type that
3944 provides one or more levels of hidden indirection and/or run-time parameters
3945 in its representation. Its value is a DWARF operation expression E which
3946 computes the location description of the data for an object. When this
3947 attribute is omitted, the location description of the data is the same as
3948 the location description of the object.
3950 The result of the attribute is obtained by evaluating E with a context that
3951 has a result kind of a location description, an object that is the location
3952 description of the data descriptor, the compilation unit that contains E, an
3953 empty initial stack, and other context elements corresponding to the source
3954 language thread of execution upon which the user is focused, if any. The
3955 result of the evaluation is the location description of the base of the
3958 *E will typically involve an operation expression that begins with a*
3959 ``DW_OP_push_object_address`` *operation which loads the location
3960 description of the object which can then serve as a descriptor in subsequent
3965 Since ``DW_AT_data_member_location``, ``DW_AT_use_location``, and
3966 ``DW_AT_vtable_elem_location`` allow both operation expressions and
3967 location list expressions, why does ``DW_AT_data_location`` not allow
3968 both? In all cases they apply to data objects so less likely that
3969 optimization would cause different operation expressions for different
3970 program location ranges. But if supporting for some then should be for
3973 It seems odd this attribute is not the same as
3974 ``DW_AT_data_member_location`` in having an initial stack with the
3975 location description of the object since the expression has to need it.
3977 A.6 Other Debugging Information
3978 -------------------------------
3982 This section provides changes to existing debugger information entry
3983 attributes. These would be incorporated into the corresponding DWARF Version 5
3986 A.6.1 Accelerated Access
3987 ~~~~~~~~~~~~~~~~~~~~~~~~
3989 .. _amdgpu-dwarf-lookup-by-name:
3991 A.6.1.1 Lookup By Name
3992 ++++++++++++++++++++++
3994 A.6.1.1.1 Contents of the Name Index
3995 ####################################
3999 The following provides changes to DWARF Version 5 section 6.1.1.1.
4001 The rule for debugger information entries included in the name index in the
4002 optional ``.debug_names`` section is extended to also include named
4003 ``DW_TAG_variable`` debugging information entries with a ``DW_AT_location``
4004 attribute that includes a ``DW_OP_LLVM_form_aspace_address`` operation.
4006 The name index must contain an entry for each debugging information entry that
4007 defines a named subprogram, label, variable, type, or namespace, subject to the
4010 * ``DW_TAG_variable`` debugging information entries with a ``DW_AT_location``
4011 attribute that includes a ``DW_OP_addr``, ``DW_OP_LLVM_form_aspace_address``,
4012 or ``DW_OP_form_tls_address`` operation are included; otherwise, they are
4015 A.6.1.1.4 Data Representation of the Name Index
4016 ###############################################
4018 .. _amdgpu-dwarf-name-index-section-header:
4021 A.6.1.1.4.1 Section Header
4022 ^^^^^^^^^^^^^^^^^^^^^^^^^^
4026 The following provides an addition to DWARF Version 5 section 6.1.1.4.1 item
4027 14 ``augmentation_string``.
4029 A null-terminated UTF-8 vendor specific augmentation string, which provides
4030 additional information about the contents of this index. If provided, the
4031 recommended format for augmentation string is:
4033 | ``[``\ *vendor*\ ``:v``\ *X*\ ``.``\ *Y*\ [\ ``:``\ *options*\ ]\ ``]``\ *
4035 Where *vendor* is the producer, ``vX.Y`` specifies the major X and minor Y
4036 version number of the extensions used in the DWARF of the compilation unit, and
4037 *options* is an optional string providing additional information about the
4038 extensions. The version number must conform to semantic versioning [:ref:`SEMVER
4039 <amdgpu-dwarf-SEMVER>`]. The *options* string must not contain the "\ ``]``\ "
4046 [abc:v0.0][def:v1.2:feature-a=on,feature-b=3]
4050 This is different to the definition in DWARF Version 5 but is consistent with
4051 the other augmentation strings and allows multiple vendor extensions to be
4054 .. _amdgpu-dwarf-line-number-information:
4056 A.6.2 Line Number Information
4057 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4059 A.6.2.4 The Line Number Program Header
4060 ++++++++++++++++++++++++++++++++++++++
4062 A.6.2.4.1 Standard Content Descriptions
4063 #######################################
4067 This augments DWARF Version 5 section 6.2.4.1.
4069 .. _amdgpu-dwarf-line-number-information-dw-lnct-llvm-source:
4071 1. ``DW_LNCT_LLVM_source``
4073 The component is a null-terminated UTF-8 source text string with "\ ``\n``\
4074 " line endings. This content code is paired with the same forms as
4075 ``DW_LNCT_path``. It can be used for file name entries.
4077 The value is an empty null-terminated string if no source is available. If
4078 the source is available but is an empty file then the value is a
4079 null-terminated single "\ ``\n``\ ".
4081 *When the source field is present, consumers can use the embedded source
4082 instead of attempting to discover the source on disk using the file path
4083 provided by the* ``DW_LNCT_path`` *field. When the source field is absent,
4084 consumers can access the file to get the source text.*
4086 *This is particularly useful for programming languages that support runtime
4087 compilation and runtime generation of source text. In these cases, the
4088 source text does not reside in any permanent file. For example, the OpenCL
4089 language [:ref:`OpenCL <amdgpu-dwarf-OpenCL>`] supports online compilation.*
4091 2. ``DW_LNCT_LLVM_is_MD5``
4093 ``DW_LNCT_LLVM_is_MD5`` indicates if the ``DW_LNCT_MD5`` content kind, if
4094 present, is valid: when 0 it is not valid and when 1 it is valid. If
4095 ``DW_LNCT_LLVM_is_MD5`` content kind is not present, and ``DW_LNCT_MD5``
4096 content kind is present, then the MD5 checksum is valid.
4098 ``DW_LNCT_LLVM_is_MD5`` is always paired with the ``DW_FORM_udata`` form.
4100 *This allows a compilation unit to have a mixture of files with and without
4101 MD5 checksums. This can happen when multiple relocatable files are linked
4104 .. _amdgpu-dwarf-call-frame-information:
4106 A.6.4 Call Frame Information
4107 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4111 This section provides changes to existing call frame information and defines
4112 instructions added by these extensions. Additional support is added for
4113 address spaces. Register unwind DWARF expressions are generalized to allow any
4114 location description, including those with composite and implicit location
4117 These changes would be incorporated into the DWARF Version 5 section 6.4.
4119 .. _amdgpu-dwarf-structure_of-call-frame-information:
4121 A.6.4.1 Structure of Call Frame Information
4122 +++++++++++++++++++++++++++++++++++++++++++
4124 The register rules are:
4127 A register that has this rule has no recoverable value in the previous frame.
4128 The previous value of this register is the undefined location description (see
4129 :ref:`amdgpu-dwarf-undefined-location-description-operations`).
4131 *By convention, the register is not preserved by a callee.*
4134 This register has not been modified from the previous caller frame.
4136 If the current frame is the top frame, then the previous value of this
4137 register is the location description L that specifies one register location
4138 description SL. SL specifies the register location storage that corresponds to
4139 the register with a bit offset of 0 for the current thread.
4141 If the current frame is not the top frame, then the previous value of this
4142 register is the location description obtained using the call frame information
4143 for the callee frame and callee program location invoked by the current caller
4144 frame for the same register.
4146 *By convention, the register is preserved by the callee, but the callee has
4150 N is a signed byte offset. The previous value of this register is saved at the
4151 location description computed as if the DWARF operation expression
4152 ``DW_OP_LLVM_offset N`` is evaluated with the current context, except the
4153 result kind is a location description, the compilation unit is unspecified,
4154 the object is unspecified, and an initial stack comprising the location
4155 description of the current CFA (see
4156 :ref:`amdgpu-dwarf-operation-expressions`).
4159 N is a signed byte offset. The previous value of this register is the memory
4160 byte address of the location description computed as if the DWARF operation
4161 expression ``DW_OP_LLVM_offset N`` is evaluated with the current context,
4162 except the result kind is a location description, the compilation unit is
4163 unspecified, the object is unspecified, and an initial stack comprising the
4164 location description of the current CFA (see
4165 :ref:`amdgpu-dwarf-operation-expressions`).
4167 The DWARF is ill-formed if the CFA location description is not a memory byte
4168 address location description, or if the register size does not match the size
4169 of an address in the address space of the current CFA location description.
4171 *Since the CFA location description is required to be a memory byte address
4172 location description, the value of val_offset(N) will also be a memory byte
4173 address location description since it is offsetting the CFA location
4174 description by N bytes. Furthermore, the value of val_offset(N) will be a
4175 memory byte address in the same address space as the CFA location
4180 Should DWARF allow the address size to be a different size to the size of
4181 the register? Requiring them to be the same bit size avoids any issue of
4182 conversion as the bit contents of the register is simply interpreted as a
4183 value of the address.
4185 GDB has a per register hook that allows a target specific conversion on a
4186 register by register basis. It defaults to truncation of bigger registers,
4187 and to actually reading bytes from the next register (or reads out of bounds
4188 for the last register) for smaller registers. There are no GDB tests that
4189 read a register out of bounds (except an illegal hand written assembly
4193 This register has been stored in another register numbered R.
4195 The previous value of this register is the location description obtained using
4196 the call frame information for the current frame and current program location
4199 The DWARF is ill-formed if the size of this register does not match the size
4200 of register R or if there is a cyclic dependency in the call frame
4205 Should this also allow R to be larger than this register? If so is the value
4206 stored in the low order bits and it is undefined what is stored in the
4210 The previous value of this register is located at the location description
4211 produced by evaluating the DWARF operation expression E (see
4212 :ref:`amdgpu-dwarf-operation-expressions`).
4214 E is evaluated with the current context, except the result kind is a location
4215 description, the compilation unit is unspecified, the object is unspecified,
4216 and an initial stack comprising the location description of the current CFA
4217 (see :ref:`amdgpu-dwarf-operation-expressions`).
4220 The previous value of this register is located at the implicit location
4221 description created from the value produced by evaluating the DWARF operation
4222 expression E (see :ref:`amdgpu-dwarf-operation-expressions`).
4224 E is evaluated with the current context, except the result kind is a value,
4225 the compilation unit is unspecified, the object is unspecified, and an initial
4226 stack comprising the location description of the current CFA (see
4227 :ref:`amdgpu-dwarf-operation-expressions`).
4229 The DWARF is ill-formed if the resulting value type size does not match the
4234 This has limited usefulness as the DWARF expression E can only produce
4235 values up to the size of the generic type. This is due to not allowing any
4236 operations that specify a type in a CFI operation expression. This makes it
4237 unusable for registers that are larger than the generic type. However,
4238 *expression(E)* can be used to create an implicit location description of
4242 The rule is defined externally to this specification by the augmenter.
4244 *This table would be extremely large if actually constructed as described. Most
4245 of the entries at any point in the table are identical to the ones above them.
4246 The whole table can be represented quite compactly by recording just the
4247 differences starting at the beginning address of each subroutine in the
4250 The virtual unwind information is encoded in a self-contained section called
4251 ``.debug_frame``. Entries in a ``.debug_frame`` section are aligned on a
4252 multiple of the address size relative to the start of the section and come in
4253 two forms: a Common Information Entry (CIE) and a Frame Description Entry (FDE).
4255 *If the range of code addresses for a function is not contiguous, there may be
4256 multiple CIEs and FDEs corresponding to the parts of that function.*
4258 A Common Information Entry (CIE) holds information that is shared among many
4259 Frame Description Entries (FDE). There is at least one CIE in every non-empty
4260 ``.debug_frame`` section. A CIE contains the following fields, in order:
4262 1. ``length`` (initial length)
4264 A constant that gives the number of bytes of the CIE structure, not
4265 including the length field itself (see Section 7.2.2 Initial Length Values).
4266 The size of the length field plus the value of length must be an integral
4267 multiple of the address size specified in the ``address_size`` field.
4269 2. ``CIE_id`` (4 or 8 bytes, see
4270 :ref:`amdgpu-dwarf-32-bit-and-64-bit-dwarf-formats`)
4272 A constant that is used to distinguish CIEs from FDEs.
4274 In the 32-bit DWARF format, the value of the CIE id in the CIE header is
4275 0xffffffff; in the 64-bit DWARF format, the value is 0xffffffffffffffff.
4277 3. ``version`` (ubyte)
4279 A version number (see Section 7.24 Call Frame Information). This number is
4280 specific to the call frame information and is independent of the DWARF
4283 The value of the CIE version number is 4.
4287 Would this be increased to 5 to reflect the changes in these extensions?
4289 4. ``augmentation`` (sequence of UTF-8 characters)
4291 A null-terminated UTF-8 string that identifies the augmentation to this CIE
4292 or to the FDEs that use it. If a reader encounters an augmentation string
4293 that is unexpected, then only the following fields can be read:
4295 * CIE: length, CIE_id, version, augmentation
4296 * FDE: length, CIE_pointer, initial_location, address_range
4298 If there is no augmentation, this value is a zero byte.
4300 *The augmentation string allows users to indicate that there is additional
4301 vendor and target architecture specific information in the CIE or FDE which
4302 is needed to virtually unwind a stack frame. For example, this might be
4303 information about dynamically allocated data which needs to be freed on exit
4306 *Because the* ``.debug_frame`` *section is useful independently of any*
4307 ``.debug_info`` *section, the augmentation string always uses UTF-8
4310 The recommended format for the augmentation string is:
4312 | ``[``\ *vendor*\ ``:v``\ *X*\ ``.``\ *Y*\ [\ ``:``\ *options*\ ]\ ``]``\ *
4314 Where *vendor* is the producer, ``vX.Y`` specifies the major X and minor Y
4315 version number of the extensions used, and *options* is an optional string
4316 providing additional information about the extensions. The version number
4317 must conform to semantic versioning [:ref:`SEMVER <amdgpu-dwarf-SEMVER>`].
4318 The *options* string must not contain the "\ ``]``\ " character.
4324 [abc:v0.0][def:v1.2:feature-a=on,feature-b=3]
4326 5. ``address_size`` (ubyte)
4328 The size of a target address in this CIE and any FDEs that use it, in bytes.
4329 If a compilation unit exists for this frame, its address size must match the
4332 6. ``segment_selector_size`` (ubyte)
4334 The size of a segment selector in this CIE and any FDEs that use it, in
4337 7. ``code_alignment_factor`` (unsigned LEB128)
4339 A constant that is factored out of all advance location instructions (see
4340 :ref:`amdgpu-dwarf-row-creation-instructions`). The resulting value is
4341 ``(operand * code_alignment_factor)``.
4343 8. ``data_alignment_factor`` (signed LEB128)
4345 A constant that is factored out of certain offset instructions (see
4346 :ref:`amdgpu-dwarf-cfa-definition-instructions` and
4347 :ref:`amdgpu-dwarf-register-rule-instructions`). The resulting value is
4348 ``(operand * data_alignment_factor)``.
4350 9. ``return_address_register`` (unsigned LEB128)
4352 An unsigned LEB128 constant that indicates which column in the rule table
4353 represents the return address of the subprogram. Note that this column might
4354 not correspond to an actual machine register.
4356 The value of the return address register is used to determine the program
4357 location of the caller frame. The program location of the top frame is the
4358 target architecture program counter value of the current thread.
4360 10. ``initial_instructions`` (array of ubyte)
4362 A sequence of rules that are interpreted to create the initial setting of
4363 each column in the table.
4365 The default rule for all columns before interpretation of the initial
4366 instructions is the undefined rule. However, an ABI authoring body or a
4367 compilation system authoring body may specify an alternate default value for
4370 11. ``padding`` (array of ubyte)
4372 Enough ``DW_CFA_nop`` instructions to make the size of this entry match the
4375 An FDE contains the following fields, in order:
4377 1. ``length`` (initial length)
4379 A constant that gives the number of bytes of the header and instruction
4380 stream for this subprogram, not including the length field itself (see
4381 Section 7.2.2 Initial Length Values). The size of the length field plus the
4382 value of length must be an integral multiple of the address size.
4384 2. ``CIE_pointer`` (4 or 8 bytes, see
4385 :ref:`amdgpu-dwarf-32-bit-and-64-bit-dwarf-formats`)
4387 A constant offset into the ``.debug_frame`` section that denotes the CIE
4388 that is associated with this FDE.
4390 3. ``initial_location`` (segment selector and target address)
4392 The address of the first location associated with this table entry. If the
4393 segment_selector_size field of this FDE’s CIE is non-zero, the initial
4394 location is preceded by a segment selector of the given length.
4396 4. ``address_range`` (target address)
4398 The number of bytes of program instructions described by this entry.
4400 5. ``instructions`` (array of ubyte)
4402 A sequence of table defining instructions that are described in
4403 :ref:`amdgpu-dwarf-call-frame-instructions`.
4405 6. ``padding`` (array of ubyte)
4407 Enough ``DW_CFA_nop`` instructions to make the size of this entry match the
4410 .. _amdgpu-dwarf-call-frame-instructions:
4412 A.6.4.2 Call Frame Instructions
4413 +++++++++++++++++++++++++++++++
4415 Each call frame instruction is defined to take 0 or more operands. Some of the
4416 operands may be encoded as part of the opcode (see
4417 :ref:`amdgpu-dwarf-call-frame-information-encoding`). The instructions are
4418 defined in the following sections.
4420 Some call frame instructions have operands that are encoded as DWARF operation
4421 expressions E (see :ref:`amdgpu-dwarf-operation-expressions`). The DWARF
4422 operations that can be used in E have the following restrictions:
4424 * ``DW_OP_addrx``, ``DW_OP_call2``, ``DW_OP_call4``, ``DW_OP_call_ref``,
4425 ``DW_OP_const_type``, ``DW_OP_constx``, ``DW_OP_convert``,
4426 ``DW_OP_deref_type``, ``DW_OP_fbreg``, ``DW_OP_implicit_pointer``,
4427 ``DW_OP_regval_type``, ``DW_OP_reinterpret``, and ``DW_OP_xderef_type``
4428 operations are not allowed because the call frame information must not depend
4429 on other debug sections.
4431 * ``DW_OP_push_object_address`` is not allowed because there is no object
4432 context to provide a value to push.
4434 * ``DW_OP_LLVM_push_lane`` and ``DW_OP_LLVM_push_iteration`` are not allowed
4435 because the call frame instructions describe the actions for the whole target
4436 architecture thread, not the lanes or iterations independently.
4438 * ``DW_OP_call_frame_cfa`` and ``DW_OP_entry_value`` are not allowed because
4439 their use would be circular.
4441 * ``DW_OP_LLVM_call_frame_entry_reg`` is not allowed if evaluating E causes a
4442 circular dependency between ``DW_OP_LLVM_call_frame_entry_reg`` operations.
4444 *For example, if a register R1 has a* ``DW_CFA_def_cfa_expression``
4445 *instruction that evaluates a* ``DW_OP_LLVM_call_frame_entry_reg`` *operation
4446 that specifies register R2, and register R2 has a*
4447 ``DW_CFA_def_cfa_expression`` *instruction that that evaluates a*
4448 ``DW_OP_LLVM_call_frame_entry_reg`` *operation that specifies register R1.*
4450 *Call frame instructions to which these restrictions apply include*
4451 ``DW_CFA_def_cfa_expression``\ *,* ``DW_CFA_expression``\ *, and*
4452 ``DW_CFA_val_expression``\ *.*
4454 .. _amdgpu-dwarf-row-creation-instructions:
4456 A.6.4.2.1 Row Creation Instructions
4457 ###################################
4461 These instructions are the same as in DWARF Version 5 section 6.4.2.1.
4463 .. _amdgpu-dwarf-cfa-definition-instructions:
4465 A.6.4.2.2 CFA Definition Instructions
4466 #####################################
4468 1. ``DW_CFA_def_cfa``
4470 The ``DW_CFA_def_cfa`` instruction takes two unsigned LEB128 operands
4471 representing a register number R and a (non-factored) byte displacement B.
4472 AS is set to the target architecture default address space identifier. The
4473 required action is to define the current CFA rule to be equivalent to the
4474 result of evaluating the DWARF operation expression ``DW_OP_constu AS;
4475 DW_OP_LLVM_aspace_bregx R, B`` as a location description.
4477 2. ``DW_CFA_def_cfa_sf``
4479 The ``DW_CFA_def_cfa_sf`` instruction takes two operands: an unsigned LEB128
4480 value representing a register number R and a signed LEB128 factored byte
4481 displacement B. AS is set to the target architecture default address space
4482 identifier. The required action is to define the current CFA rule to be
4483 equivalent to the result of evaluating the DWARF operation expression
4484 ``DW_OP_constu AS; DW_OP_LLVM_aspace_bregx R, B * data_alignment_factor`` as
4485 a location description.
4487 *The action is the same as* ``DW_CFA_def_cfa``\ *, except that the second
4488 operand is signed and factored.*
4490 3. ``DW_CFA_LLVM_def_aspace_cfa`` *New*
4492 The ``DW_CFA_LLVM_def_aspace_cfa`` instruction takes three unsigned LEB128
4493 operands representing a register number R, a (non-factored) byte
4494 displacement B, and a target architecture specific address space identifier
4495 AS. The required action is to define the current CFA rule to be equivalent
4496 to the result of evaluating the DWARF operation expression ``DW_OP_constu
4497 AS; DW_OP_LLVM_aspace_bregx R, B`` as a location description.
4499 If AS is not one of the values defined by the target architecture specific
4500 ``DW_ASPACE_LLVM_*`` values then the DWARF expression is ill-formed.
4502 4. ``DW_CFA_LLVM_def_aspace_cfa_sf`` *New*
4504 The ``DW_CFA_LLVM_def_aspace_cfa_sf`` instruction takes three operands: an
4505 unsigned LEB128 value representing a register number R, a signed LEB128
4506 factored byte displacement B, and an unsigned LEB128 value representing a
4507 target architecture specific address space identifier AS. The required
4508 action is to define the current CFA rule to be equivalent to the result of
4509 evaluating the DWARF operation expression ``DW_OP_constu AS;
4510 DW_OP_LLVM_aspace_bregx R, B * data_alignment_factor`` as a location
4513 If AS is not one of the values defined by the target architecture specific
4514 ``DW_ASPACE_LLVM_*`` values, then the DWARF expression is ill-formed.
4516 *The action is the same as* ``DW_CFA_aspace_def_cfa``\ *, except that the
4517 second operand is signed and factored.*
4519 5. ``DW_CFA_def_cfa_register``
4521 The ``DW_CFA_def_cfa_register`` instruction takes a single unsigned LEB128
4522 operand representing a register number R. The required action is to define
4523 the current CFA rule to be equivalent to the result of evaluating the DWARF
4524 operation expression ``DW_OP_constu AS; DW_OP_LLVM_aspace_bregx R, B`` as a
4525 location description. B and AS are the old CFA byte displacement and address
4528 If the subprogram has no current CFA rule, or the rule was defined by a
4529 ``DW_CFA_def_cfa_expression`` instruction, then the DWARF is ill-formed.
4531 6. ``DW_CFA_def_cfa_offset``
4533 The ``DW_CFA_def_cfa_offset`` instruction takes a single unsigned LEB128
4534 operand representing a (non-factored) byte displacement B. The required
4535 action is to define the current CFA rule to be equivalent to the result of
4536 evaluating the DWARF operation expression ``DW_OP_constu AS;
4537 DW_OP_LLVM_aspace_bregx R, B`` as a location description. R and AS are the
4538 old CFA register number and address space respectively.
4540 If the subprogram has no current CFA rule, or the rule was defined by a
4541 ``DW_CFA_def_cfa_expression`` instruction, then the DWARF is ill-formed.
4543 7. ``DW_CFA_def_cfa_offset_sf``
4545 The ``DW_CFA_def_cfa_offset_sf`` instruction takes a signed LEB128 operand
4546 representing a factored byte displacement B. The required action is to
4547 define the current CFA rule to be equivalent to the result of evaluating the
4548 DWARF operation expression ``DW_OP_constu AS; DW_OP_LLVM_aspace_bregx R, B *
4549 data_alignment_factor`` as a location description. R and AS are the old CFA
4550 register number and address space respectively.
4552 If the subprogram has no current CFA rule, or the rule was defined by a
4553 ``DW_CFA_def_cfa_expression`` instruction, then the DWARF is ill-formed.
4555 *The action is the same as* ``DW_CFA_def_cfa_offset``\ *, except that the
4556 operand is signed and factored.*
4558 8. ``DW_CFA_def_cfa_expression``
4560 The ``DW_CFA_def_cfa_expression`` instruction takes a single operand encoded
4561 as a ``DW_FORM_exprloc`` value representing a DWARF operation expression E.
4562 The required action is to define the current CFA rule to be equivalent to
4563 the result of evaluating E with the current context, except the result kind
4564 is a location description, the compilation unit is unspecified, the object
4565 is unspecified, and an empty initial stack.
4567 *See* :ref:`amdgpu-dwarf-call-frame-instructions` *regarding restrictions on
4568 the DWARF expression operations that can be used in E.*
4570 The DWARF is ill-formed if the result of evaluating E is not a memory byte
4571 address location description.
4573 .. _amdgpu-dwarf-register-rule-instructions:
4575 A.6.4.2.3 Register Rule Instructions
4576 ####################################
4578 1. ``DW_CFA_undefined``
4580 The ``DW_CFA_undefined`` instruction takes a single unsigned LEB128 operand
4581 that represents a register number R. The required action is to set the rule
4582 for the register specified by R to ``undefined``.
4584 2. ``DW_CFA_same_value``
4586 The ``DW_CFA_same_value`` instruction takes a single unsigned LEB128 operand
4587 that represents a register number R. The required action is to set the rule
4588 for the register specified by R to ``same value``.
4590 3. ``DW_CFA_offset``
4592 The ``DW_CFA_offset`` instruction takes two operands: a register number R
4593 (encoded with the opcode) and an unsigned LEB128 constant representing a
4594 factored displacement B. The required action is to change the rule for the
4595 register specified by R to be an *offset(B \* data_alignment_factor)* rule.
4599 Seems this should be named ``DW_CFA_offset_uf`` since the offset is
4602 4. ``DW_CFA_offset_extended``
4604 The ``DW_CFA_offset_extended`` instruction takes two unsigned LEB128
4605 operands representing a register number R and a factored displacement B.
4606 This instruction is identical to ``DW_CFA_offset``, except for the encoding
4607 and size of the register operand.
4611 Seems this should be named ``DW_CFA_offset_extended_uf`` since the
4612 displacement is unsigned factored.
4614 5. ``DW_CFA_offset_extended_sf``
4616 The ``DW_CFA_offset_extended_sf`` instruction takes two operands: an
4617 unsigned LEB128 value representing a register number R and a signed LEB128
4618 factored displacement B. This instruction is identical to
4619 ``DW_CFA_offset_extended``, except that B is signed.
4621 6. ``DW_CFA_val_offset``
4623 The ``DW_CFA_val_offset`` instruction takes two unsigned LEB128 operands
4624 representing a register number R and a factored displacement B. The required
4625 action is to change the rule for the register indicated by R to be a
4626 *val_offset(B \* data_alignment_factor)* rule.
4630 Seems this should be named ``DW_CFA_val_offset_uf`` since the displacement
4631 is unsigned factored.
4635 An alternative is to define ``DW_CFA_val_offset`` to implicitly use the
4636 target architecture default address space, and add another operation that
4637 specifies the address space.
4639 7. ``DW_CFA_val_offset_sf``
4641 The ``DW_CFA_val_offset_sf`` instruction takes two operands: an unsigned
4642 LEB128 value representing a register number R and a signed LEB128 factored
4643 displacement B. This instruction is identical to ``DW_CFA_val_offset``,
4644 except that B is signed.
4646 8. ``DW_CFA_register``
4648 The ``DW_CFA_register`` instruction takes two unsigned LEB128 operands
4649 representing register numbers R1 and R2 respectively. The required action is
4650 to set the rule for the register specified by R1 to be a *register(R2)* rule.
4652 9. ``DW_CFA_expression``
4654 The ``DW_CFA_expression`` instruction takes two operands: an unsigned LEB128
4655 value representing a register number R, and a ``DW_FORM_block`` value
4656 representing a DWARF operation expression E. The required action is to
4657 change the rule for the register specified by R to be an *expression(E)*
4660 *That is, E computes the location description where the register value can
4663 *See* :ref:`amdgpu-dwarf-call-frame-instructions` *regarding restrictions on
4664 the DWARF expression operations that can be used in E.*
4666 10. ``DW_CFA_val_expression``
4668 The ``DW_CFA_val_expression`` instruction takes two operands: an unsigned
4669 LEB128 value representing a register number R, and a ``DW_FORM_block`` value
4670 representing a DWARF operation expression E. The required action is to
4671 change the rule for the register specified by R to be a *val_expression(E)*
4674 *That is, E computes the value of register R.*
4676 *See* :ref:`amdgpu-dwarf-call-frame-instructions` *regarding restrictions on
4677 the DWARF expression operations that can be used in E.*
4679 If the result of evaluating E is not a value with a base type size that
4680 matches the register size, then the DWARF is ill-formed.
4682 11. ``DW_CFA_restore``
4684 The ``DW_CFA_restore`` instruction takes a single operand (encoded with the
4685 opcode) that represents a register number R. The required action is to
4686 change the rule for the register specified by R to the rule assigned it by
4687 the ``initial_instructions`` in the CIE.
4689 12. ``DW_CFA_restore_extended``
4691 The ``DW_CFA_restore_extended`` instruction takes a single unsigned LEB128
4692 operand that represents a register number R. This instruction is identical
4693 to ``DW_CFA_restore``, except for the encoding and size of the register
4696 A.6.4.2.4 Row State Instructions
4697 ################################
4701 These instructions are the same as in DWARF Version 5 section 6.4.2.4.
4703 A.6.4.2.5 Padding Instruction
4704 #############################
4708 These instructions are the same as in DWARF Version 5 section 6.4.2.5.
4710 A.6.4.3 Call Frame Instruction Usage
4711 ++++++++++++++++++++++++++++++++++++
4715 The same as in DWARF Version 5 section 6.4.3.
4717 .. _amdgpu-dwarf-call-frame-calling-address:
4719 A.6.4.4 Call Frame Calling Address
4720 ++++++++++++++++++++++++++++++++++
4724 The same as in DWARF Version 5 section 6.4.4.
4726 A.7 Data Representation
4727 -----------------------
4731 This section provides changes to existing debugger information entry
4732 attributes. These would be incorporated into the corresponding DWARF Version 5
4735 .. _amdgpu-dwarf-32-bit-and-64-bit-dwarf-formats:
4737 A.7.4 32-Bit and 64-Bit DWARF Formats
4738 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4742 This augments DWARF Version 5 section 7.4 list item 3's table.
4744 .. table:: ``.debug_info`` section attribute form roles
4745 :name: amdgpu-dwarf-debug-info-section-attribute-form-roles-table
4747 ================================== ===================================
4749 ================================== ===================================
4750 DW_OP_LLVM_aspace_implicit_pointer offset in ``.debug_info``
4751 ================================== ===================================
4753 A.7.5 Format of Debugging Information
4754 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4756 A.7.5.4 Attribute Encodings
4757 +++++++++++++++++++++++++++
4761 This augments DWARF Version 5 section 7.5.4 and Table 7.5.
4763 The following table gives the encoding of the additional debugging information
4766 .. table:: Attribute encodings
4767 :name: amdgpu-dwarf-attribute-encodings-table
4769 ================================== ====== ===================================
4770 Attribute Name Value Classes
4771 ================================== ====== ===================================
4772 ``DW_AT_LLVM_active_lane`` 0x3e08 exprloc, loclist
4773 ``DW_AT_LLVM_augmentation`` 0x3e09 string
4774 ``DW_AT_LLVM_lanes`` 0x3e0a constant
4775 ``DW_AT_LLVM_lane_pc`` 0x3e0b exprloc, loclist
4776 ``DW_AT_LLVM_vector_size`` 0x3e0c constant
4777 ``DW_AT_LLVM_iterations`` 0x3e0a constant, exprloc, loclist
4778 ``DW_AT_LLVM_address_space`` TBA constant
4779 ``DW_AT_LLVM_memory_space`` TBA constant
4780 ================================== ====== ===================================
4782 .. _amdgpu-dwarf-classes-and-forms:
4784 A.7.5.5 Classes and Forms
4785 +++++++++++++++++++++++++
4789 The following modifies the matching text in DWARF Version 5 section 7.5.5.
4792 There are four types of reference.
4794 - The first type of reference...
4796 - The second type of reference can identify any debugging information
4797 entry within a .debug_info section; in particular, it may refer to an
4798 entry in a different compilation unit from the unit containing the
4799 reference, and may refer to an entry in a different shared object file.
4800 This type of reference (DW_FORM_ref_addr) is an offset from the
4801 beginning of the .debug_info section of the target executable or shared
4802 object file, or, for references within a supplementary object file, an
4803 offset from the beginning of the local .debug_info section; it is
4804 relocatable in a relocatable object file and frequently relocated in an
4805 executable or shared object file. In the 32-bit DWARF format, this
4806 offset is a 4-byte unsigned value; in the 64-bit DWARF format, it is an
4807 8-byte unsigned value (see
4808 :ref:`amdgpu-dwarf-32-bit-and-64-bit-dwarf-formats`).
4810 *A debugging information entry that may be referenced by another
4811 compilation unit using DW_FORM_ref_addr must have a global symbolic
4814 *For a reference from one executable or shared object file to another,
4815 the reference is resolved by the debugger to identify the executable or
4816 shared object file and the offset into that file's* ``.debug_info``
4817 *section in the same fashion as the run time loader, either when the
4818 debug information is first read, or when the reference is used.*
4820 A.7.7 DWARF Expressions
4821 ~~~~~~~~~~~~~~~~~~~~~~~
4825 Rename DWARF Version 5 section 7.7 to reflect the unification of location
4826 descriptions into DWARF expressions.
4828 A.7.7.1 Operation Expressions
4829 +++++++++++++++++++++++++++++
4833 Rename DWARF Version 5 section 7.7.1 and delete section 7.7.2 to reflect the
4834 unification of location descriptions into DWARF expressions.
4836 This augments DWARF Version 5 section 7.7.1 and Table 7.9, and adds a new
4837 table describing vendor extension operations for ``DW_OP_LLVM_user``.
4839 A DWARF operation expression is stored in a block of contiguous bytes. The bytes
4840 form a sequence of operations. Each operation is a 1-byte code that identifies
4841 that operation, followed by zero or more bytes of additional data. The encoding
4842 for the operation ``DW_OP_LLVM_user`` is described in
4843 :ref:`amdgpu-dwarf-operation-encodings-table`, and the encoding of all
4844 ``DW_OP_LLVM_user`` vendor extensions operations are described in
4845 :ref:`amdgpu-dwarf-dw-op-llvm-user-vendor-extension-operation-encodings-table`.
4847 .. table:: DWARF Operation Encodings
4848 :name: amdgpu-dwarf-operation-encodings-table
4850 ====================================== ===== ======== =========================================================================================
4851 Operation Code Number Notes
4854 ====================================== ===== ======== =========================================================================================
4855 ``DW_OP_LLVM_user`` 0xe9 1+ ULEB128 vendor extension opcode, followed by vendor extension operands
4856 defined in :ref:`amdgpu-dwarf-dw-op-llvm-user-vendor-extension-operation-encodings-table`
4857 ====================================== ===== ======== =========================================================================================
4859 .. table:: DWARF DW_OP_LLVM_user Vendor Extension Operation Encodings
4860 :name: amdgpu-dwarf-dw-op-llvm-user-vendor-extension-operation-encodings-table
4862 ====================================== ========= ========== ===============================
4863 Operation Vendor Number Notes
4867 ====================================== ========= ========== ===============================
4868 ``DW_OP_LLVM_form_aspace_address`` 0x02 0
4869 ``DW_OP_LLVM_push_lane`` 0x03 0
4870 ``DW_OP_LLVM_offset`` 0x04 0
4871 ``DW_OP_LLVM_offset_uconst`` 0x05 1 ULEB128 byte displacement
4872 ``DW_OP_LLVM_bit_offset`` 0x06 0
4873 ``DW_OP_LLVM_call_frame_entry_reg`` 0x07 1 ULEB128 register number
4874 ``DW_OP_LLVM_undefined`` 0x08 0
4875 ``DW_OP_LLVM_aspace_bregx`` 0x09 2 ULEB128 register number,
4876 SLEB128 byte displacement
4877 ``DW_OP_LLVM_piece_end`` 0x0a 0
4878 ``DW_OP_LLVM_extend`` 0x0b 2 ULEB128 bit size,
4880 ``DW_OP_LLVM_select_bit_piece`` 0x0c 2 ULEB128 bit size,
4882 ``DW_OP_LLVM_aspace_implicit_pointer`` TBA 2 4-byte or 8-byte offset of DIE,
4883 SLEB128 byte displacement
4884 ``DW_OP_LLVM_push_iteration`` TBA 0
4885 ``DW_OP_LLVM_overlay`` TBA 0
4886 ``DW_OP_LLVM_bit_overlay`` TBA 0
4887 ====================================== ========= ========== ===============================
4889 A.7.7.3 Location List Expressions
4890 +++++++++++++++++++++++++++++++++
4894 Rename DWARF Version 5 section 7.7.3 to reflect that location lists are a kind
4895 of DWARF expression.
4897 A.7.12 Source Languages
4898 ~~~~~~~~~~~~~~~~~~~~~~~
4902 This augments DWARF Version 5 section 7.12 and Table 7.17.
4904 The following table gives the encoding of the additional DWARF languages.
4906 .. table:: Language encodings
4907 :name: amdgpu-dwarf-language-encodings-table
4909 ==================== ====== ===================
4910 Language Name Value Default Lower Bound
4911 ==================== ====== ===================
4912 ``DW_LANG_LLVM_HIP`` 0x8100 0
4913 ==================== ====== ===================
4915 A.7.14 Address Space Encodings
4916 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4920 This is a new section after DWARF Version 5 section 7.13 "Address Class and
4921 Address Space Encodings".
4923 The value of the common address space encoding ``DW_ASPACE_LLVM_none`` is 0.
4925 A.7.15 Memory Space Encodings
4926 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4930 This is a new section after DWARF Version 5 section 7.13 "Address Class and
4931 Address Space Encodings".
4933 The encodings of the constants used for the currently defined memory spaces
4934 are given in :ref:`amdgpu-dwarf-memory-space-encodings-table`.
4936 .. table:: Memory space encodings
4937 :name: amdgpu-dwarf-memory-space-encodings-table
4939 =========================== ======
4940 Memory Space Name Value
4941 =========================== ======
4942 ``DW_MSPACE_LLVM_none`` 0x0000
4943 ``DW_MSPACE_LLVM_global`` 0x0001
4944 ``DW_MSPACE_LLVM_constant`` 0x0002
4945 ``DW_MSPACE_LLVM_group`` 0x0003
4946 ``DW_MSPACE_LLVM_private`` 0x0004
4947 ``DW_MSPACE_LLVM_lo_user`` 0x8000
4948 ``DW_MSPACE_LLVM_hi_user`` 0xffff
4949 =========================== ======
4951 A.7.22 Line Number Information
4952 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4956 This augments DWARF Version 5 section 7.22 and Table 7.27.
4958 The following table gives the encoding of the additional line number header
4961 .. table:: Line number header entry format encodings
4962 :name: amdgpu-dwarf-line-number-header-entry-format-encodings-table
4964 ==================================== ====================
4965 Line number header entry format name Value
4966 ==================================== ====================
4967 ``DW_LNCT_LLVM_source`` 0x2001
4968 ``DW_LNCT_LLVM_is_MD5`` 0x2002
4969 ==================================== ====================
4971 .. _amdgpu-dwarf-call-frame-information-encoding:
4973 A.7.24 Call Frame Information
4974 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4978 This augments DWARF Version 5 section 7.24 and Table 7.29.
4980 The following table gives the encoding of the additional call frame information
4983 .. table:: Call frame instruction encodings
4984 :name: amdgpu-dwarf-call-frame-instruction-encodings-table
4986 ================================= ====== ====== ================ ================ =====================
4987 Instruction High 2 Low 6 Operand 1 Operand 2 Operand 3
4989 ================================= ====== ====== ================ ================ =====================
4990 ``DW_CFA_LLVM_def_aspace_cfa`` 0 0x30 ULEB128 register ULEB128 offset ULEB128 address space
4991 ``DW_CFA_LLVM_def_aspace_cfa_sf`` 0 0x31 ULEB128 register SLEB128 offset ULEB128 address space
4992 ================================= ====== ====== ================ ================ =====================
4994 A.7.32 Type Signature Computation
4995 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4999 This augments (in alphabetical order) DWARF Version 5 section 7.32, Table
5002 .. table:: Attributes used in type signature computation
5003 :name: amdgpu-dwarf-attributes-used-in-type-signature-computation-table
5005 ================================== =======
5006 ``DW_AT_LLVM_address_space``
5007 ``DW_AT_LLVM_memory_space``
5008 ``DW_AT_LLVM_vector_size``
5009 ================================== =======
5011 A. Attributes by Tag Value (Informative)
5012 ----------------------------------------
5016 This augments DWARF Version 5 Appendix A and Table A.1.
5018 The following table provides the additional attributes that are applicable to
5019 debugger information entries.
5021 .. table:: Attributes by tag value
5022 :name: amdgpu-dwarf-attributes-by-tag-value-table
5024 ================================== =============================
5025 Tag Name Applicable Attributes
5026 ================================== =============================
5027 ``DW_TAG_base_type`` * ``DW_AT_LLVM_vector_size``
5028 ``DW_TAG_pointer_type`` * ``DW_AT_LLVM_address_space``
5029 * ``DW_AT_LLVM_memory_space``
5030 ``DW_TAG_reference_type`` * ``DW_AT_LLVM_address_space``
5031 * ``DW_AT_LLVM_memory_space``
5032 ``DW_TAG_rvalue_reference_type`` * ``DW_AT_LLVM_address_space``
5033 * ``DW_AT_LLVM_memory_space``
5034 ``DW_TAG_variable`` * ``DW_AT_LLVM_memory_space``
5035 ``DW_TAG_formal_parameter`` * ``DW_AT_LLVM_memory_space``
5036 ``DW_TAG_constant`` * ``DW_AT_LLVM_memory_space``
5037 ``DW_TAG_compile_unit`` * ``DW_AT_LLVM_augmentation``
5038 ``DW_TAG_entry_point`` * ``DW_AT_LLVM_active_lane``
5039 * ``DW_AT_LLVM_lane_pc``
5040 * ``DW_AT_LLVM_lanes``
5041 * ``DW_AT_LLVM_iterations``
5042 ``DW_TAG_inlined_subroutine`` * ``DW_AT_LLVM_active_lane``
5043 * ``DW_AT_LLVM_lane_pc``
5044 * ``DW_AT_LLVM_lanes``
5045 * ``DW_AT_LLVM_iterations``
5046 ``DW_TAG_subprogram`` * ``DW_AT_LLVM_active_lane``
5047 * ``DW_AT_LLVM_lane_pc``
5048 * ``DW_AT_LLVM_lanes``
5049 * ``DW_AT_LLVM_iterations``
5050 ================================== =============================
5052 D. Examples (Informative)
5053 -------------------------
5057 This modifies the corresponding DWARF Version 5 Appendix D examples.
5059 D.1 General Description Examples
5060 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5062 D.1.3 DWARF Location Description Examples
5063 +++++++++++++++++++++++++++++++++++++++++
5065 ``DW_OP_offset_uconst 4``
5066 A structure member is four bytes from the start of the structure instance. The
5067 location description of the base of the structure instance is assumed to be
5068 already on the stack.
5070 ``DW_OP_entry_value 1 DW_OP_reg5 DW_OP_offset_uconst 16``
5071 The address of the memory location is calculated by adding 16 to the value
5072 contained in register 5 upon entering the current subprogram.
5074 D.2 Aggregate Examples
5075 ~~~~~~~~~~~~~~~~~~~~~~
5077 D.2.1 Fortran Simple Array Example
5078 ++++++++++++++++++++++++++++++++++
5080 Figure D.4: Fortran array example: DWARF description
5085 -------------------------------------------------------------------------------
5086 ! Description for type of 'ap'
5088 1$: DW_TAG_array_type
5089 ! No name, default (Fortran) ordering, default stride
5090 DW_AT_type(reference to REAL)
5091 DW_AT_associated(expression= ! Test 'ptr_assoc' flag
5092 DW_OP_push_object_address
5093 DW_OP_lit<n> ! where n == offset(ptr_assoc)
5096 DW_OP_lit1 ! mask for 'ptr_assoc' flag
5098 DW_AT_data_location(expression= ! Get raw data address
5099 DW_OP_push_object_address
5100 DW_OP_lit<n> ! where n == offset(base)
5102 DW_OP_deref) ! Type of index of array 'ap'
5103 2$: DW_TAG_subrange_type
5104 ! No name, default stride
5105 DW_AT_type(reference to INTEGER)
5106 DW_AT_lower_bound(expression=
5107 DW_OP_push_object_address
5108 DW_OP_lit<n> ! where n ==
5109 ! offset(desc, dims) +
5110 ! offset(dims_str, lower_bound)
5113 DW_AT_upper_bound(expression=
5114 DW_OP_push_object_address
5115 DW_OP_lit<n> ! where n ==
5116 ! offset(desc, dims) +
5117 ! offset(dims_str, upper_bound)
5120 ! Note: for the m'th dimension, the second operator becomes
5121 ! DW_OP_lit<n> where
5122 ! n == offset(desc, dims) +
5123 ! (m-1)*sizeof(dims_str) +
5124 ! offset(dims_str, [lower|upper]_bound)
5125 ! That is, the expression does not get longer for each successive
5126 ! dimension (other than to express the larger offsets involved).
5127 3$: DW_TAG_structure_type
5128 DW_AT_name("array_ptr")
5129 DW_AT_byte_size(constant sizeof(REAL) + sizeof(desc<1>))
5132 DW_AT_type(reference to REAL)
5133 DW_AT_data_member_location(constant 0)
5136 DW_AT_type(reference to 1$)
5137 DW_AT_data_member_location(constant sizeof(REAL))
5138 6$: DW_TAG_array_type
5139 ! No name, default (Fortran) ordering, default stride
5140 DW_AT_type(reference to 3$)
5141 DW_AT_allocated(expression= ! Test 'ptr_alloc' flag
5142 DW_OP_push_object_address
5143 DW_OP_lit<n> ! where n == offset(ptr_alloc)
5146 DW_OP_lit2 ! Mask for 'ptr_alloc' flag
5148 DW_AT_data_location(expression= ! Get raw data address
5149 DW_OP_push_object_address
5150 DW_OP_lit<n> ! where n == offset(base)
5153 7$: DW_TAG_subrange_type
5154 ! No name, default stride
5155 DW_AT_type(reference to INTEGER)
5156 DW_AT_lower_bound(expression=
5157 DW_OP_push_object_address
5158 DW_OP_lit<n> ! where n == ...
5161 DW_AT_upper_bound(expression=
5162 DW_OP_push_object_address
5163 DW_OP_lit<n> ! where n == ...
5167 DW_AT_name("arrayvar")
5168 DW_AT_type(reference to 6$)
5169 DW_AT_location(expression=
5170 ...as appropriate...) ! Assume static allocation
5171 -------------------------------------------------------------------------------
5173 D.2.3 Fortran 2008 Assumed-rank Array Example
5174 +++++++++++++++++++++++++++++++++++++++++++++
5176 Figure D.13: Sample DWARF for the array descriptor in Figure D.12
5181 ----------------------------------------------------------------------------
5182 10$: DW_TAG_array_type
5183 DW_AT_type(reference to real)
5184 DW_AT_rank(expression=
5185 DW_OP_push_object_address
5189 DW_AT_data_location(expression=
5190 DW_OP_push_object_address
5194 11$: DW_TAG_generic_subrange
5195 DW_AT_type(reference to integer)
5196 ! offset of rank in descriptor
5197 ! offset of data in descriptor
5198 DW_AT_lower_bound(expression=
5199 ! Looks up the lower bound of dimension i.
5200 ! Operation ! Stack effect
5202 DW_OP_lit<n> ! i sizeof(dim)
5204 DW_OP_lit<n> ! dim[i] offsetof(dim)
5205 DW_OP_plus ! dim[i]+offset
5206 DW_OP_push_object_address ! dim[i]+offsetof(dim) objptr
5207 DW_OP_swap ! objptr dim[i]+offsetof(dim)
5208 DW_OP_offset ! objptr.dim[i]
5209 DW_OP_lit<n> ! objptr.dim[i] offsetof(lb)
5210 DW_OP_offset ! objptr.dim[i].lowerbound
5211 DW_OP_deref) ! *objptr.dim[i].lowerbound
5212 DW_AT_upper_bound(expression=
5213 ! Looks up the upper bound of dimension i.
5214 DW_OP_lit<n> ! sizeof(dim)
5216 DW_OP_lit<n> ! offsetof(dim)
5218 DW_OP_push_object_address
5221 DW_OP_lit<n> ! offset of upperbound in dim
5224 DW_AT_byte_stride(expression=
5225 ! Looks up the byte stride of dimension i.
5227 ! (analogous to DW_AT_upper_bound)
5229 ----------------------------------------------------------------------------
5233 This example suggests that ``DW_AT_lower_bound`` and ``DW_AT_upper_bound``
5234 evaluate an exprloc with an initial stack containing the rank value. The
5235 attribute definition should be updated to state this.
5240 Figure D.20: Ada example: DWARF description
5245 ----------------------------------------------------------------------------
5246 11$: DW_TAG_variable
5248 DW_AT_type(reference to INTEGER)
5249 12$: DW_TAG_array_type
5250 ! No name, default (Ada) order, default stride
5251 DW_AT_type(reference to INTEGER)
5252 13$: DW_TAG_subrange_type
5253 DW_AT_type(reference to INTEGER)
5254 DW_AT_lower_bound(constant 1)
5255 DW_AT_upper_bound(reference to variable M at 11$)
5256 14$: DW_TAG_variable
5258 DW_AT_type(reference to array type at 12$)
5260 21$: DW_TAG_subrange_type
5262 DW_AT_type(reference to INTEGER)
5263 DW_AT_lower_bound(constant 1)
5264 DW_AT_upper_bound(constant 100)
5266 26$: DW_TAG_structure_type
5270 DW_AT_type(reference to subtype TEENY at 21$)
5271 DW_AT_data_member_location(constant 0)
5272 28$: DW_TAG_array_type
5273 ! No name, default (Ada) order, default stride
5274 ! Default data location
5275 DW_AT_type(reference to INTEGER)
5276 29$: DW_TAG_subrange_type
5277 DW_AT_type(reference to subrange TEENY at 21$)
5278 DW_AT_lower_bound(constant 1)
5279 DW_AT_upper_bound(reference to member N at 27$)
5282 DW_AT_type(reference to array "subtype" at 28$)
5283 DW_AT_data_member_location(machine=
5284 DW_OP_lit<n> ! where n == offset(REC2, VEC2)
5287 41$: DW_TAG_variable
5289 DW_AT_type(reference to REC2 at 26$)
5290 DW_AT_location(...as appropriate...)
5291 ----------------------------------------------------------------------------
5293 .. _amdgpu-dwarf-further-examples:
5298 The AMD GPU specific usage of the features in these extensions, including
5299 examples, is available at *User Guide for AMDGPU Backend* section
5300 :ref:`amdgpu-dwarf-debug-information`.
5304 Change examples to use ``DW_OP_LLVM_offset`` instead of ``DW_OP_add`` when
5305 acting on a location description.
5307 Need to provide examples of new features.
5309 .. _amdgpu-dwarf-references:
5314 .. _amdgpu-dwarf-AMD:
5316 1. [AMD] `Advanced Micro Devices <https://www.amd.com/>`__
5318 .. _amdgpu-dwarf-AMD-ROCgdb:
5320 2. [AMD-ROCgdb] `AMD ROCm Debugger (ROCgdb) <https://github.com/ROCm-Developer-Tools/ROCgdb>`__
5322 .. _amdgpu-dwarf-AMD-ROCm:
5324 3. [AMD-ROCm] `AMD ROCm Platform <https://rocm-documentation.readthedocs.io>`__
5326 .. _amdgpu-dwarf-AMDGPU-DWARF-LOC:
5328 4. [AMDGPU-DWARF-LOC] `Allow Location Descriptions on the DWARF Expression Stack <https://llvm.org/docs/AMDGPUDwarfExtensionAllowLocationDescriptionOnTheDwarfExpressionStack/AMDGPUDwarfExtensionAllowLocationDescriptionOnTheDwarfExpressionStack.html>`__
5330 .. _amdgpu-dwarf-AMDGPU-LLVM:
5332 5. [AMDGPU-LLVM] `User Guide for AMDGPU LLVM Backend <https://llvm.org/docs/AMDGPUUsage.html>`__
5334 .. _amdgpu-dwarf-CUDA:
5336 6. [CUDA] `Nvidia CUDA Language <https://docs.nvidia.com/cuda/cuda-c-programming-guide/>`__
5338 .. _amdgpu-dwarf-DWARF:
5340 7. [DWARF] `DWARF Debugging Information Format <http://dwarfstd.org/>`__
5342 .. _amdgpu-dwarf-ELF:
5344 8. [ELF] `Executable and Linkable Format (ELF) <http://www.sco.com/developers/gabi/>`__
5346 .. _amdgpu-dwarf-GCC:
5348 9. [GCC] `GCC: The GNU Compiler Collection <https://www.gnu.org/software/gcc/>`__
5350 .. _amdgpu-dwarf-GDB:
5352 10. [GDB] `GDB: The GNU Project Debugger <https://www.gnu.org/software/gdb/>`__
5354 .. _amdgpu-dwarf-HIP:
5356 11. [HIP] `HIP Programming Guide <https://rocm-documentation.readthedocs.io/en/latest/Programming_Guides/Programming-Guides.html#hip-programing-guide>`__
5358 .. _amdgpu-dwarf-HSA:
5360 12. [HSA] `Heterogeneous System Architecture (HSA) Foundation <http://www.hsafoundation.com/>`__
5362 .. _amdgpu-dwarf-LLVM:
5364 13. [LLVM] `The LLVM Compiler Infrastructure <https://llvm.org/>`__
5366 .. _amdgpu-dwarf-OpenCL:
5368 14. [OpenCL] `The OpenCL Specification Version 2.0 <http://www.khronos.org/registry/cl/specs/opencl-2.0.pdf>`__
5370 .. _amdgpu-dwarf-Perforce-TotalView:
5372 15. [Perforce-TotalView] `Perforce TotalView HPC Debugging Software <https://totalview.io/products/totalview>`__
5374 .. _amdgpu-dwarf-SEMVER:
5376 16. [SEMVER] `Semantic Versioning <https://semver.org/>`__