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