DWARF Proposal For Heterogeneous Debugging¶
Warning
This document describes a provisional proposal for DWARF Version 6 [DWARF] to support heterogeneous debugging. It is not currently fully implemented and is subject to change.
Introduction¶
AMD [AMD] has been working on supporting heterogeneous computing through the AMD Radeon Open Compute Platform (ROCm) [AMD-ROCm]. A heterogeneous computing program can be written in a high level language such as C++ or Fortran with OpenMP pragmas, OpenCL, or HIP (a portable C++ programming environment for heterogeneous computing [HIP]). A heterogeneous compiler and runtime allows a program to execute on multiple devices within the same native process. Devices could include CPUs, GPUs, DSPs, FPGAs, or other special purpose accelerators. Currently HIP programs execute on systems with CPUs and GPUs.
ROCm is fully open sourced and includes contributions to open source projects such as LLVM for compilation [LLVM] and GDB for debugging [GDB], as well as collaboration with other third party projects such as the GCC compiler [GCC] and the Perforce TotalView HPC debugger [Perforce-TotalView].
To support debugging heterogeneous programs several features that are not provided by current DWARF Version 5 [DWARF] have been identified. This document contains a collection of proposals to address providing those features.
The Motivation section describes the issues that are being addressed for heterogeneous computing. That is followed by the Proposed Changes Relative to DWARF Version 5 section containing the proposed textual changes relative to the DWARF Version 5 standard. Then there is an Examples section that links to the AMD GPU specific usage of the features in the proposal that includes an example. Finally, there is a References section. There are a number of notes included that raise open questions, or provide alternative approaches considered. The draft proposal seeks to be general in nature and backwards compatible with DWARF Version 5. Its goal is to be applicable to meeting the needs of any heterogeneous system and not be vendor or architecture specific.
A fundamental aspect of the draft proposal is that it allows DWARF expression location descriptions as stack elements. The draft proposal is based on DWARF Version 5 and maintains compatibility with DWARF Version 5. After attempting several alternatives, the current thinking is that such an addition to DWARF Version 5 is the simplest and cleanest way to support debugging optimized GPU code. It also appears to be generally useful and may be able to address other reported DWARF issues, as well as being helpful in providing better optimization support for non-GPU code.
General feedback on this draft proposal is sought, together with suggestions on how to clarify, simplify, or organize it before submitting it as a formal DWARF proposal. The current draft proposal is large and may need to be split into separate proposals before formal submission. Any suggestions on how best to do that are appreciated. However, at the initial review stage it is believed there is value in presenting a unified proposal as there are mutual dependencies between the various parts that would not be as apparent if it was broken up into separate independent proposals.
We are in the process of modifying LLVM and GDB to support this draft proposal which is providing experience and insights. We plan to upstream the changes to those projects for any final form of the proposal.
The author very much appreciates the input provided so far by many others which has been incorporated into this current version.
Motivation¶
This document proposes a set of backwards compatible extensions to DWARF Version 5 [DWARF] for consideration of inclusion into a future DWARF Version 6 standard to support heterogeneous debugging.
The remainder of this section provides motivation for each proposed feature in terms of heterogeneous debugging on commercially available AMD GPU hardware (AMDGPU). The goal is to add support to the AMD [AMD] open source Radeon Open Compute Platform (ROCm) [AMD-ROCm] which is an implementation of the industry standard for heterogeneous computing devices defined by the Heterogeneous System Architecture (HSA) Foundation [HSA]. ROCm includes the LLVM compiler [LLVM] with upstreamed support for AMDGPU [AMDGPU-LLVM]. The goal is to also add the GDB debugger [GDB] with upstreamed support for AMDGPU [AMD-ROCgdb]. In addition, the goal is to work with third parties to enable support for AMDGPU debugging in the GCC compiler [GCC] and the Perforce TotalView HPC debugger [Perforce-TotalView].
However, the proposal is intended to be vendor and architecture neutral. It is believed to apply to other heterogeous hardware devices including GPUs, DSPs, FPGAs, and other specialized hardware. These collectively include similar characteristics and requirements as AMDGPU devices. Parts of the proposal can also apply to traditional CPU hardware that supports large vector registers. Compilers can map source languages and extensions that describe large scale parallel execution onto the lanes of the vector registers. This is common in programming languages used in ML and HPC. The proposal also includes improved support for optimized code on any architecture. Some of the generalizations may also benefit other issues that have been raised.
The proposal has evolved though collaboration with many individuals and active prototyping within the GDB debugger and LLVM compiler. Input has also been very much appreciated from the developers working on the Perforce TotalView HPC Debugger and GCC compiler.
The AMDGPU has several features that require additional DWARF functionality in order to support optimized code.
AMDGPU optimized code may spill vector registers to non-global address space
memory, and this spilling may be done only for lanes that are active on entry
to the subprogram. To support this, a location description that can be created
as a masked select is required. See DW_OP_LLVM_select_bit_piece.
Since the active lane mask may be held in a register, a way to get the value
of a register on entry to a subprogram is required. To support this an
operation that returns the caller value of a register as specified by the Call
Frame Information (CFI) is required. See DW_OP_LLVM_call_frame_entry_reg
and Call Frame Information.
Current DWARF uses an empty expression to indicate an undefined location
description. Since the masked select composite location description operation
takes more than one location description, it is necessary to have an explicit
way to specify an undefined location description. Otherwise it is not possible
to specify that a particular one of the input location descriptions is
undefined. See DW_OP_LLVM_undefined.
CFI describes restoring callee saved registers that are spilled. Currently CFI only allows a location description that is a register, memory address, or implicit location description. AMDGPU optimized code may spill scalar registers into portions of vector registers. This requires extending CFI to allow any location description. See Call Frame Information.
The vector registers of the AMDGPU are represented as their full wavefront size, meaning the wavefront size times the dword size. This reflects the actual hardware and allows the compiler to generate DWARF for languages that map a thread to the complete wavefront. It also allows more efficient DWARF to be generated to describe the CFI as only a single expression is required for the whole vector register, rather than a separate expression for each lane’s dword of the vector register. It also allows the compiler to produce DWARF that indexes the vector register if it spills scalar registers into portions of a vector registers.
Since DWARF stack value entries have a base type and AMDGPU registers are a
vector of dwords, the ability to specify that a base type is a vector is
required. See DW_AT_LLVM_vector_size.
If the source language is mapped onto the AMDGPU wavefronts in a SIMT manner,
then the variable DWARF location expressions must compute the location for a
single lane of the wavefront. Therefore, a DWARF operation is required to
denote the current lane, much like DW_OP_push_object_address denotes the
current object. The DW_OP_*piece operations only allow literal indices.
Therefore, a way to use a computed offset of an arbitrary location description
(such as a vector register) is required. See DW_OP_LLVM_push_lane,
DW_OP_LLVM_offset, DW_OP_LLVM_offset_uconst, and
DW_OP_LLVM_bit_offset.
If the source language is mapped onto the AMDGPU wavefronts in a SIMT manner
the compiler can use the AMDGPU execution mask register to control which lanes
are active. To describe the conceptual location of non-active lanes a DWARF
expression is needed that can compute a per lane PC. For efficiency, this is
done for the wavefront as a whole. This expression benefits by having a masked
select composite location description operation. This requires an attribute
for source location of each lane. The AMDGPU may update the execution mask for
whole wavefront operations and so needs an attribute that computes the current
active lane mask. See DW_OP_LLVM_select_bit_piece, DW_OP_LLVM_extend,
DW_AT_LLVM_lane_pc, and DW_AT_LLVM_active_lane.
AMDGPU needs to be able to describe addresses that are in different kinds of memory. Optimized code may need to describe a variable that resides in pieces that are in different kinds of storage which may include parts of registers, memory that is in a mixture of memory kinds, implicit values, or be undefined. DWARF has the concept of segment addresses. However, the segment cannot be specified within a DWARF expression, which is only able to specify the offset portion of a segment address. The segment index is only provided by the entity that specifies the DWARF expression. Therefore, the segment index is a property that can only be put on complete objects, such as a variable. That makes it only suitable for describing an entity (such as variable or subprogram code) that is in a single kind of memory. Therefore, AMDGPU uses the DWARF concept of address spaces. For example, a variable may be allocated in a register that is partially spilled to the call stack which is in the private address space, and partially spilled to the local address space.
DWARF uses the concept of an address in many expression operations but does not
define how it relates to address spaces. For example,
DW_OP_push_object_address pushes the address of an object. Other contexts
implicitly push an address on the stack before evaluating an expression. For
example, the DW_AT_use_location attribute of the
DW_TAG_ptr_to_member_type. The expression that uses the address needs to
do so in a general way and not need to be dependent on the address space of
the address. For example, a pointer to member value may want to be applied to
an object that may reside in any address space.
The number of registers and the cost of memory operations is much higher for
AMDGPU than a typical CPU. The compiler attempts to optimize whole variables
and arrays into registers. Currently DWARF only allows
DW_OP_push_object_address and related operations to work with a global
memory location. To support AMDGPU optimized code it is required to generalize
DWARF to allow any location description to be used. This allows registers, or
composite location descriptions that may be a mixture of memory, registers, or
even implicit values.
DWARF Version 5 does not allow location descriptions to be entries on the DWARF stack. They can only be the final result of the evaluation of a DWARF expression. However, by allowing a location description to be a first-class entry on the DWARF stack it becomes possible to compose expressions containing both values and location descriptions naturally. It allows objects to be located in any kind of memory address space, in registers, be implicit values, be undefined, or a composite of any of these. By extending DWARF carefully, all existing DWARF expressions can retain their current semantic meaning. DWARF has implicit conversions that convert from a value that represents an address in the default address space to a memory location description. This can be extended to allow a default address space memory location description to be implicitly converted back to its address value. This allows all DWARF Version 5 expressions to retain their same meaning, while adding the ability to explicitly create memory location descriptions in non-default address spaces and generalizing the power of composite location descriptions to any kind of location description. See DWARF Operation Expressions.
To allow composition of composite location descriptions, an explicit operation
that indicates the end of the definition of a composite location description
is required. This can be implied if the end of a DWARF expression is reached,
allowing current DWARF expressions to remain legal. See
DW_OP_LLVM_piece_end.
The DW_OP_plus and DW_OP_minus can be defined to operate on a memory
location description in the default target architecture specific address space
and a generic type value to produce an updated memory location description. This
allows them to continue to be used to offset an address. To generalize
offsetting to any location description, including location descriptions that
describe when bytes are in registers, are implicit, or a composite of these, the
DW_OP_LLVM_offset, DW_OP_LLVM_offset_uconst, and
DW_OP_LLVM_bit_offset offset operations are added. Unlike DW_OP_plus,
DW_OP_plus_uconst, and DW_OP_minus arithmetic operations, these do not
define that integer overflow causes wrap-around. The offset operations can
operate on location storage of any size. For example, implicit location storage
could be any number of bits in size. It is simpler to define offsets that exceed
the size of the location storage as being ill-formed, than having to force an
implementation to support potentially infinite precision offsets to allow it to
correctly track a series of positive and negative offsets that may transiently
overflow or underflow, but end up in range. This is simple for the arithmetic
operations as they are defined in terms of two’s compliment arithmetic on a base
type of a fixed size.
Having the offset operations allows DW_OP_push_object_address to push a
location description that may be in a register, or be an implicit value, and the
DWARF expression of DW_TAG_ptr_to_member_type can contain them to offset
within it. DW_OP_LLVM_bit_offset generalizes DWARF to work with bit fields
which is not possible in DWARF Version 5.
The DWARF DW_OP_xderef* operations allow a value to be converted into an
address of a specified address space which is then read. But it provides no
way to create a memory location description for an address in the non-default
address space. For example, AMDGPU variables can be allocated in the local
address space at a fixed address. It is required to have an operation to
create an address in a specific address space that can be used to define the
location description of the variable. Defining this operation to produce a
location description allows the size of addresses in an address space to be
larger than the generic type. See DW_OP_LLVM_form_aspace_address.
If the DW_OP_LLVM_form_aspace_address operation had to produce a value
that can be implicitly converted to a memory location description, then it
would be limited to the size of the generic type which matches the size of the
default address space. Its value would be unspecified and likely not match any
value in the actual program. By making the result a location description, it
allows a consumer great freedom in how it implements it. The implicit
conversion back to a value can be limited only to the default address space to
maintain compatibility with DWARF Version 5. For other address spaces the
producer can use the new operations that explicitly specify the address space.
DW_OP_breg* treats the register as containing an address in the default
address space. It is required to be able to specify the address space of the
register value. See DW_OP_LLVM_aspace_bregx.
Similarly, DW_OP_implicit_pointer treats its implicit pointer value as
being in the default address space. It is required to be able to specify the
address space of the pointer value. See
DW_OP_LLVM_aspace_implicit_pointer.
Almost all uses of addresses in DWARF are limited to defining location
descriptions, or to be dereferenced to read memory. The exception is
DW_CFA_val_offset which uses the address to set the value of a register.
By defining the CFA DWARF expression as being a memory location description,
it can maintain what address space it is, and that can be used to convert the
offset address back to an address in that address space. See
Call Frame Information.
This approach allows all existing DWARF to have the identical semantics. It
allows the compiler to explicitly specify the address space it is using. For
example, a compiler could choose to access private memory in a swizzled manner
when mapping a source language to a wavefront in a SIMT manner, or to access
it in an unswizzled manner if mapping the same language with the wavefront
being the thread. It also allows the compiler to mix the address space it uses
to access private memory. For example, for SIMT it can still spill entire
vector registers in an unswizzled manner, while using a swizzled private
memory for SIMT variable access. This approach allows memory location
descriptions for different address spaces to be combined using the regular
DW_OP_*piece operations.
Location descriptions are an abstraction of storage, they give freedom to the
consumer on how to implement them. They allow the address space to encode lane
information so they can be used to read memory with only the memory
description and no extra arguments. The same set of operations can operate on
locations independent of their kind of storage. The DW_OP_deref* therefore
can be used on any storage kind. DW_OP_xderef* is unnecessary except to
become a more compact way to convert a non-default address space address
followed by dereferencing it.
In DWARF Version 5 a location description is defined as a single location
description or a location list. A location list is defined as either
effectively an undefined location description or as one or more single
location descriptions to describe an object with multiple places. The
DW_OP_push_object_address and DW_OP_call* operations can put a
location description on the stack. Furthermore, debugger information entry
attributes such as DW_AT_data_member_location, DW_AT_use_location, and
DW_AT_vtable_elem_location are defined as pushing a location description
on the expression stack before evaluating the expression. However, DWARF
Version 5 only allows the stack to contain values and so only a single memory
address can be on the stack which makes these incapable of handling location
descriptions with multiple places, or places other than memory. Since this
proposal allows the stack to contain location descriptions, the operations are
generalized to support location descriptions that can have multiple places.
This is backwards compatible with DWARF Version 5 and allows objects with
multiple places to be supported. For example, the expression that describes
how to access the field of an object can be evaluated with a location
description that has multiple places and will result in a location description
with multiple places as expected. With this change, the separate DWARF Version
5 sections that described DWARF expressions and location lists have been
unified into a single section that describes DWARF expressions in general.
This unification seems to be a natural consequence and a necessity of allowing
location descriptions to be part of the evaluation stack.
For those familiar with the definition of location descriptions in DWARF Version 5, the definition in this proposal is presented differently, but does in fact define the same concept with the same fundamental semantics. However, it does so in a way that allows the concept to extend to support address spaces, bit addressing, the ability for composite location descriptions to be composed of any kind of location description, and the ability to support objects located at multiple places. Collectively these changes expand the set of processors that can be supported and improves support for optimized code.
Several approaches were considered, and the one proposed appears to be the cleanest and offers the greatest improvement of DWARF’s ability to support optimized code. Examining the GDB debugger and LLVM compiler, it appears only to require modest changes as they both already have to support general use of location descriptions. It is anticipated that will also be the case for other debuggers and compilers.
As an experiment, GDB was modified to evaluate DWARF Version 5 expressions with location descriptions as stack entries and implicit conversions. All GDB tests have passed, except one that turned out to be an invalid test by DWARF Version 5 rules. The code in GDB actually became simpler as all evaluation was on the stack and there was no longer a need to maintain a separate structure for the location description result. This gives confidence of the backwards compatibility.
Since the AMDGPU supports languages such as OpenCL [OpenCL], there is a need to define source language address classes so they can be used in a consistent way by consumers. It would also be desirable to add support for using them in defining language types rather than the current target architecture specific address spaces. See Segmented Addresses.
A DW_AT_LLVM_augmentation attribute is added to a compilation unit
debugger information entry to indicate that there is additional target
architecture specific information in the debugging information entries of that
compilation unit. This allows a consumer to know what extensions are present
in the debugger information entries as is possible with the augmentation
string of other sections. The format that should be used for the augmentation
string in the lookup by name table and CFI Common Information Entry is also
recommended to allow a consumer to parse the string when it contains
information from multiple vendors.
The AMDGPU supports programming languages that include online compilation where the source text may be created at runtime. Therefore, a way to embed the source text in the debug information is required. For example, the OpenCL language runtime supports online compilation. See Line Number Information.
Support to allow MD5 checksums to be optionally present in the line table is added. This allows linking together compilation units where some have MD5 checksums and some do not. In DWARF Version 5 the file timestamp and file size can be optional, but if the MD5 checksum is present it must be valid for all files. See Line Number Information.
Support is added for the HIP programming language [HIP] which is supported by the AMDGPU. See Unit Entities.
The following sections provide the definitions for the additional operations, as well as clarifying how existing expression operations, CFI operations, and attributes behave with respect to generalized location descriptions that support address spaces and location descriptions that support multiple places. It has been defined such that it is backwards compatible with DWARF Version 5. The definitions are intended to fully define well-formed DWARF in a consistent style based on the DWARF Version 5 specification. Non-normative text is shown in italics.
The names for the new operations, attributes, and constants include “LLVM” and are encoded with vendor specific codes so this proposal can be
implemented as an LLVM vendor extension to DWARF Version 5. If accepted these
names would not include the “LLVM” and would not use encodings in the
vendor range.
The proposal is described in Proposed Changes Relative to DWARF Version 5 and is organized to follow the section ordering of DWARF Version 5. It includes notes to indicate the corresponding DWARF Version 5 sections to which they pertain. Other notes describe additional changes that may be worth considering, and to raise questions.
Proposed Changes Relative to DWARF Version 5¶
General Description¶
Attribute Types¶
Note
This augments DWARF Version 5 section 2.2 and Table 2.2.
The following table provides the additional attributes. See Debugging Information Entry Attributes.
Attribute |
Usage |
|---|---|
|
SIMD or SIMT active lanes |
|
Compilation unit augmentation string |
|
SIMD or SIMT lane program location |
|
SIMD or SIMT thread lane count |
|
Base type vector size |
DWARF Expressions¶
Note
This section, and its nested sections, replaces DWARF Version 5 section 2.5 and section 2.6. The new proposed DWARF expression operations are defined as well as clarifying the extensions to already existing DWARF Version 5 operations. It is based on the text of the existing DWARF Version 5 standard.
DWARF expressions describe how to compute a value or specify a location.
The evaluation of a DWARF expression can provide the location of an object, the value of an array bound, the length of a dynamic string, the desired value itself, and so on.
The evaluation of a DWARF expression can either result in a value or a location description:
value
A value has a type and a literal value. It can represent a literal value of any supported base type of the target architecture. The base type specifies the size and encoding of the literal value.
Note
It may be desirable to add an implicit pointer base type encoding. It would be used for the type of the value that is produced when the
DW_OP_deref*operation retrieves the full contents of an implicit pointer location storage created by theDW_OP_implicit_pointerorDW_OP_LLVM_aspace_implicit_pointeroperations. The literal value would record the debugging information entry and byte dispacement specified by the associatedDW_OP_implicit_pointerorDW_OP_LLVM_aspace_implicit_pointeroperations.Instead of a base type, a value can have a distinguished generic type, which is an integral type that has the size of an address in the target architecture default address space and unspecified signedness.
The generic type is the same as the unspecified type used for stack operations defined in DWARF Version 4 and before.
An integral type is a base type that has an encoding of
DW_ATE_signed,DW_ATE_signed_char,DW_ATE_unsigned,DW_ATE_unsigned_char,DW_ATE_boolean, or any target architecture defined integral encoding in the inclusive rangeDW_ATE_lo_usertoDW_ATE_hi_user.Note
It is unclear if
DW_ATE_addressis an integral type. GDB does not seem to consider it as integral.
location description
Debugging information must provide consumers a way to find the location of program variables, determine the bounds of dynamic arrays and strings, and possibly to find the base address of a subprogram’s stack frame or the return address of a subprogram. Furthermore, to meet the needs of recent computer architectures and optimization techniques, debugging information must be able to describe the location of an object whose location changes over the object’s lifetime, and may reside at multiple locations simultaneously during parts of an object’s lifetime.
Information about the location of program objects is provided by location descriptions.
Location descriptions can consist of one or more single location descriptions.
A single location description specifies the location storage that holds a program object and a position within the location storage where the program object starts. The position within the location storage is expressed as a bit offset relative to the start of the location storage.
A location storage is a linear stream of bits that can hold values. Each location storage has a size in bits and can be accessed using a zero-based bit offset. The ordering of bits within a location storage uses the bit numbering and direction conventions that are appropriate to the current language on the target architecture.
There are five kinds of location storage:
- memory location storage
Corresponds to the target architecture memory address spaces.
- register location storage
Corresponds to the target architecture registers.
- implicit location storage
Corresponds to fixed values that can only be read.
- undefined location storage
Indicates no value is available and therefore cannot be read or written.
- composite location storage
Allows a mixture of these where some bits come from one location storage and some from another location storage, or from disjoint parts of the same location storage.
Note
It may be better to add an implicit pointer location storage kind used by the
DW_OP_implicit_pointerandDW_OP_LLVM_aspace_implicit_pointeroperations. It would specify the debugger information entry and byte offset provided by the operations.Location descriptions are a language independent representation of addressing rules. They are created using DWARF operation expressions of arbitrary complexity. They can be the result of evaluting a debugger information entry attribute that specifies an operation expression. In this usage they can describe the location of an object as long as its lifetime is either static or the same as the lexical block (see DWARF Version 5 section 3.5) that owns it, and it does not move during its lifetime. They can be the result of evaluating a debugger information entry attribute that specifies a location list expression. In this usage they can describe the location of an object that has a limited lifetime, changes its location during its lifetime, or has multiple locations over part or all of its lifetime.
If a location description has more than one single location description, the DWARF expression is ill-formed if the object value held in each single location description’s position within the associated location storage is not the same value, except for the parts of the value that are uninitialized.
A location description that has more than one single location description can only be created by a location list expression that has overlapping program location ranges, or certain expression operations that act on a location description that has more than one single location description. There are no operation expression operations that can directly create a location description with more than one single location description.
A location description with more than one single location description can be used to describe objects that reside in more than one piece of storage at the same time. An object may have more than one location as a result of optimization. For example, a value that is only read may be promoted from memory to a register for some region of code, but later code may revert to reading the value from memory as the register may be used for other purposes. For the code region where the value is in a register, any change to the object value must be made in both the register and the memory so both regions of code will read the updated value.
A consumer of a location description with more than one single location description can read the object’s value from any of the single location descriptions (since they all refer to location storage that has the same value), but must write any changed value to all the single location descriptions.
A DWARF expression can either be encoded as a operation expression (see DWARF Operation Expressions), or as a location list expression (see DWARF Location List Expressions).
A DWARF expression is evaluated in the context of:
- A current subprogram
This may be used in the evaluation of register access operations to support virtual unwinding of the call stack (see Call Frame Information).
- A current program location
This may be used in the evaluation of location list expressions to select amongst multiple program location ranges. It should be the program location corresponding to the current subprogram. If the current subprogram was reached by virtual call stack unwinding, then the program location will correspond to the associated call site.
- An initial stack
This is a list of values or location descriptions that will be pushed on the operation expression evaluation stack in the order provided before evaluation of an operation expression starts.
Some debugger information entries have attributes that evaluate their DWARF expression value with initial stack entries. In all other cases the initial stack is empty.
When a DWARF expression is evaluated, it may be specified whether a value or location description is required as the result kind.
If a result kind is specified, and the result of the evaluation does not match the specified result kind, then the implicit conversions described in Memory Location Description Operations are performed if valid. Otherwise, the DWARF expression is ill-formed.
DWARF Operation Expressions¶
An operation expression is comprised of a stream of operations, each consisting of an opcode followed by zero or more operands. The number of operands is implied by the opcode.
Operations represent a postfix operation on a simple stack machine. Each stack entry can hold either a value or a location description. Operations can act on entries on the stack, including adding entries and removing entries. If the kind of a stack entry does not match the kind required by the operation and is not implicitly convertible to the required kind (see Memory Location Description Operations), then the DWARF operation expression is ill-formed.
Evaluation of an operation expression starts with an empty stack on which the entries from the initial stack provided by the context are pushed in the order provided. Then the operations are evaluated, starting with the first operation of the stream, until one past the last operation of the stream is reached. The result of the evaluation is:
If evaluation of the DWARF expression requires a location description, then:
If the stack is empty, the result is a location description with one undefined location description.
This rule is for backwards compatibility with DWARF Version 5 which has no explicit operation to create an undefined location description, and uses an empty operation expression for this purpose.
If the top stack entry is a location description, or can be converted to one (see Memory Location Description Operations), then the result is that, possibly converted, location description. Any other entries on the stack are discarded.
Otherwise the DWARF expression is ill-formed.
Note
Could define this case as returning an implicit location description as if the
DW_OP_implicitoperation is performed.
If evaluation of the DWARF expression requires a value, then:
If the top stack entry is a value, or can be converted to one (see Memory Location Description Operations), then the result is that, possibly converted, value. Any other entries on the stack are discarded.
Otherwise the DWARF expression is ill-formed.
If evaluation of the DWARF expression does not specify if a value or location description is required, then:
If the stack is empty, the result is a location description with one undefined location description.
This rule is for backwards compatibility with DWARF Version 5 which has no explicit operation to create an undefined location description, and uses an empty operation expression for this purpose.
Note
This rule is consistent with the rule above for when a location description is requested. However, GDB appears to report this as an error and no GDB tests appear to cause an empty stack for this case.
Otherwise, the top stack entry is returned. Any other entries on the stack are discarded.
An operation expression is encoded as a byte block with some form of prefix that specifies the byte count. It can be used:
as the value of a debugging information entry attribute that is encoded using class
exprloc(see DWARF Version 5 section 7.5.5),as the operand to certain operation expression operations,
as the operand to certain call frame information operations (see Call Frame Information),
and in location list entries (see DWARF Location List Expressions).
Stack Operations¶
The following operations manipulate the DWARF stack. Operations that index the stack assume that the top of the stack (most recently added entry) has index 0. They allow the stack entries to be either a value or location description.
If any stack entry accessed by a stack operation is an incomplete composite location description (see Composite Location Description Operations), then the DWARF expression is ill-formed.
Note
These operations now support stack entries that are values and location descriptions.
Note
If it is desired to also make them work with incomplete composite location descriptions, then would need to define that the composite location storage specified by the incomplete composite location description is also replicated when a copy is pushed. This ensures that each copy of the incomplete composite location description can update the composite location storage they specify independently.
DW_OP_dupDW_OP_dupduplicates the stack entry at the top of the stack.DW_OP_dropDW_OP_droppops the stack entry at the top of the stack and discards it.DW_OP_pickDW_OP_pickhas a single unsigned 1-byte operand that represents an index I. A copy of the stack entry with index I is pushed onto the stack.DW_OP_overDW_OP_overpushes a copy of the entry with index 1.This is equivalent to a ``DW_OP_pick 1`` operation.
DW_OP_swapDW_OP_swapswaps the top two stack entries. The entry at the top of the stack becomes the second stack entry, and the second stack entry becomes the top of the stack.DW_OP_rotDW_OP_rotrotates the first three stack entries. The entry at the top of the stack becomes the third stack entry, the second entry becomes the top of the stack, and the third entry becomes the second entry.
Control Flow Operations¶
The following operations provide simple control of the flow of a DWARF operation expression.
DW_OP_nopDW_OP_nopis a place holder. It has no effect on the DWARF stack entries.DW_OP_le,DW_OP_ge,DW_OP_eq,DW_OP_lt,DW_OP_gt,DW_OP_neNote
The same as in DWARF Version 5 section 2.5.1.5.
DW_OP_skipDW_OP_skipis an unconditional branch. Its single operand is a 2-byte signed integer constant. The 2-byte constant is the number of bytes of the DWARF expression to skip forward or backward from the current operation, beginning after the 2-byte constant.If the updated position is at one past the end of the last operation, then the operation expression evaluation is complete.
Otherwise, the DWARF expression is ill-formed if the updated operation position is not in the range of the first to last operation inclusive, or not at the start of an operation.
DW_OP_braDW_OP_brais a conditional branch. Its single operand is a 2-byte signed integer constant. This operation pops the top of stack. If the value popped is not the constant 0, the 2-byte constant operand is the number of bytes of the DWARF operation expression to skip forward or backward from the current operation, beginning after the 2-byte constant.If the updated position is at one past the end of the last operation, then the operation expression evaluation is complete.
Otherwise, the DWARF expression is ill-formed if the updated operation position is not in the range of the first to last operation inclusive, or not at the start of an operation.
DW_OP_call2, DW_OP_call4, DW_OP_call_refDW_OP_call2,DW_OP_call4, andDW_OP_call_refperform DWARF procedure calls during evaluation of a DWARF expression.DW_OP_call2andDW_OP_call4, have one operand that is a 2- or 4-byte unsigned offset, respectively, of a debugging information entry D in the current compilation unit.DW_OP_call_refhas one operand that is a 4-byte unsigned value in the 32-bit DWARF format, or an 8-byte unsigned value in the 64-bit DWARF format, that represents an offset of a debugging information entry D in a.debug_infosection, which may be contained in an executable or shared object file other than that containing the operation. For references from one executable or shared object file to another, the relocation must be performed by the consumer.Operand interpretation of
DW_OP_call2,DW_OP_call4, andDW_OP_call_refis exactly like that forDW_FORM_ref2, ``DW_FORM_ref4``*, andDW_FORM_ref_addr, respectively.The call operation is evaluated by:
If D has a
DW_AT_locationattribute that is encoded as aexprlocthat specifies an operation expression E, then execution of the current operation expression continues from the first operation of E. Execution continues until one past the last operation of E is reached, at which point execution continues with the operation following the call operation. Since E is evaluated on the same stack as the call, E can use, add, and/or remove entries already on the stack.Values on the stack at the time of the call may be used as parameters by the called expression and values left on the stack by the called expression may be used as return values by prior agreement between the calling and called expressions.
If D has a
DW_AT_locationattribute that is encoded as aloclistorloclistsptr, then the specified location list expression E is evaluated, and the resulting location description is pushed on the stack. The evaluation of E uses a context that has the same current frame and current program location as the current operation expression, but an empty initial stack.Note
This rule avoids having to define how to execute a matched location list entry operation expression on the same stack as the call when there are multiple matches. But it allows the call to obtain the location description for a variable or formal parameter which may use a location list expression.
An alternative is to treat the case when D has a
DW_AT_locationattribute that is encoded as aloclistorloclistsptr, and the specified location list expression E’ matches a single location list entry with operation expression E, the same as theexprloccase and evaluate on the same stack.But this is not attractive as if the attribute is for a variable that happens to end with a non-singleton stack, it will not simply put a location description on the stack. Presumably the intent of using
DW_OP_call*on a variable or formal parameter debugger information entry is to push just one location description on the stack. That location description may have more than one single location description.The previous rule for
exprlocalso has the same problem as normally a variable or formal parameter location expression may leave multiple entries on the stack and only return the top entry.GDB implements
DW_OP_call*by always executing E on the same stack. If the location list has multiple matching entries, it simply picks the first one and ignores the rest. This seems fundementally at odds with the desire to supporting multiple places for variables.So, it feels like
DW_OP_call*should both support pushing a location description on the stack for a variable or formal parameter, and also support being able to execute an operation expression on the same stack. Being able to specify a different operation expression for different program locations seems a desirable feature to retain.A solution to that is to have a distinct
DW_AT_LLVM_procattribute for theDW_TAG_dwarf_proceduredebugging information entry. Then theDW_AT_locationattribute expression is always executed separately and pushes a location description (that may have multiple single location descriptions), and theDW_AT_LLVM_procattribute expression is always executed on the same stack and can leave anything on the stack.The
DW_AT_LLVM_procattribute could have the new classesexprproc,loclistproc, andloclistsptrprocto indicate that the expression is executed on the same stack.exprprocis the same encoding asexprloc.loclistprocandloclistsptrprocare the same encoding as their non-proccounterparts except the DWARF is ill-formed if the location list does not match exactly one location list entry and a default entry is required. These forms indicate explicitly that the matched single operation expression must be executed on the same stack. This is better than ad hoc special rules forloclistprocandloclistsptrprocwhich are currently clearly defined to always return a location description. The producer then explicitly indicates the intent through the attribute classes.Such a change would be a breaking change for how GDB implements
DW_OP_call*. However, are the breaking cases actually occurring in practice? GDB could implement the current approach for DWARF Version 5, and the new semantics for DWARF Version 6 which has been done for some other features.Another option is to limit the execution to be on the same stack only to the evaluation of an expression E that is the value of a
DW_AT_locationattribute of aDW_TAG_dwarf_proceduredebugging information entry. The DWARF would be ill-formed if E is a location list expression that does not match exactly one location list entry. In all other cases the evaluation of an expression E that is the value of aDW_AT_locationattribute would evaluate E with a context that has the same current frame and current program location as the current operation expression, but an empty initial stack, and push the resulting location description on the stack.If D has a
DW_AT_const_valueattribute with a value V, then it is as if aDW_OP_implicit_value Voperation was executed.This allows a call operation to be used to compute the location description for any variable or formal parameter regardless of whether the producer has optimized it to a constant. This is consistent with the ``DW_OP_implicit_pointer`` operation.
Note
Alternatively, could deprecate using
DW_AT_const_valueforDW_TAG_variableandDW_TAG_formal_parameterdebugger information entries that are constants and instead useDW_AT_locationwith an operation expression that results in a location description with one implicit location description. Then this rule would not be required.Otherwise, there is no effect and no changes are made to the stack.
Note
In DWARF Version 5, if D does not have a
DW_AT_locationthenDW_OP_call*is defined to have no effect. It is unclear that this is the right definition as a producer should be able to rely on usingDW_OP_call*to get a location description for any non-DW_TAG_dwarf_proceduredebugging information entries. Also, the producer should not be creating DWARF withDW_OP_call*to aDW_TAG_dwarf_procedurethat does not have aDW_AT_locationattribute. So, should this case be defined as an ill-formed DWARF expression?
The
DW_TAG_dwarf_proceduredebugging information entry can be used to define DWARF procedures that can be called.
Value Operations¶
This section describes the operations that push values on the stack.
Each value stack entry has a type and a literal value and can represent a literal value of any supported base type of the target architecture. The base type specifies the size and encoding of the literal value.
Instead of a base type, value stack entries can have a distinguished generic type, which is an integral type that has the size of an address in the target architecture default address space and unspecified signedness.
The generic type is the same as the unspecified type used for stack operations defined in DWARF Version 4 and before.
An integral type is a base type that has an encoding of DW_ATE_signed,
DW_ATE_signed_char, DW_ATE_unsigned, DW_ATE_unsigned_char,
DW_ATE_boolean, or any target architecture defined integral encoding in the
inclusive range DW_ATE_lo_user to DW_ATE_hi_user.
Note
Unclear if DW_ATE_address is an integral type. GDB does not seem to
consider it as integral.
The following operations all push a literal value onto the DWARF stack.
Operations other than DW_OP_const_type push a value V with the generic type.
If V is larger than the generic type, then V is truncated to the generic type
size and the low-order bits used.
DW_OP_lit0,DW_OP_lit1, …,DW_OP_lit31DW_OP_lit<N>operations encode an unsigned literal value N from 0 through 31, inclusive. They push the value N with the generic type.DW_OP_const1u,DW_OP_const2u,DW_OP_const4u,DW_OP_const8uDW_OP_const<N>uoperations have a single operand that is a 1, 2, 4, or 8-byte unsigned integer constant U, respectively. They push the value U with the generic type.DW_OP_const1s,DW_OP_const2s,DW_OP_const4s,DW_OP_const8sDW_OP_const<N>soperations have a single operand that is a 1, 2, 4, or 8-byte signed integer constant S, respectively. They push the value S with the generic type.DW_OP_constuDW_OP_constuhas a single unsigned LEB128 integer operand N. It pushes the value N with the generic type.DW_OP_constsDW_OP_constshas a single signed LEB128 integer operand N. It pushes the value N with the generic type.DW_OP_constxDW_OP_constxhas a single unsigned LEB128 integer operand that represents a zero-based index into the.debug_addrsection relative to the value of theDW_AT_addr_baseattribute of the associated compilation unit. The value N in the.debug_addrsection has the size of the generic type. It pushes the value N with the generic type.The
DW_OP_constxoperation is provided for constants that require link-time relocation but should not be interpreted by the consumer as a relocatable address (for example, offsets to thread-local storage).
DW_OP_const_typeDW_OP_const_typehas three operands. The first is an unsigned LEB128 integer that represents the offset of a debugging information entry D in the current compilation unit, that provides the type of the constant value. The second is a 1-byte unsigned integral constant S. The third is a block of bytes B, with a length equal to S.T is the bit size of the type D. The least significant T bits of B are interpreted as a value V of the type D. It pushes the value V with the type D.
The DWARF is ill-formed if D is not a
DW_TAG_base_typedebugging information entry, or if T divided by 8 and rounded up to a multiple of 8 (the byte size) is not equal to S.While the size of the byte block B can be inferred from the type D definition, it is encoded explicitly into the operation so that the operation can be parsed easily without reference to the
.debug_infosection.DW_OP_LLVM_push_laneNewDW_OP_LLVM_push_lanepushes a value with the generic type that is the target architecture specific lane identifier of the thread of execution for which a user presented expression is currently being evaluated.For languages that are implemented using a SIMD or SIMT execution model, this is the lane number that corresponds to the source language thread of execution upon which the user is focused.
Note
This section is the same as DWARF Version 5 section 2.5.1.4.
Note
This section is the same as DWARF Version 5 section 2.5.1.6.
There are these special value operations currently defined:
DW_OP_regval_typeDW_OP_regval_typehas two operands. The first is an unsigned LEB128 integer that represents a register number R. The second is an unsigned LEB128 integer that represents the offset of a debugging information entry D in the current compilation unit, that provides the type of the register value.The contents of register R are interpreted as a value V of the type D. The value V is pushed on the stack with the type D.
The DWARF is ill-formed if D is not a
DW_TAG_base_typedebugging information entry, or if the size of type D is not the same as the size of register R.Note
Should DWARF allow the type D to be a different size to the size of the register R? Requiring them to be the same bit size avoids any issue of conversion as the bit contents of the register is simply interpreted as a value of the specified type. If a conversion is wanted it can be done explicitly using a
DW_OP_convertoperation.GDB has a per register hook that allows a target specific conversion on a register by register basis. It defaults to truncation of bigger registers, and to actually reading bytes from the next register (or reads out of bounds for the last register) for smaller registers. There are no GDB tests that read a register out of bounds (except an illegal hand written assembly test).
DW_OP_derefThe
DW_OP_derefoperation pops one stack entry that must be a location description L.A value of the bit size of the generic type is retrieved from the location storage specified by L. The value V retrieved is pushed on the stack with the generic type.
If any bit of the value is retrieved from the undefined location storage, or the offset of any bit exceeds the size of the location storage specified by L, then the DWARF expression is ill-formed.
See Implicit Location Description Operations for special rules concerning implicit location descriptions created by the
DW_OP_implicit_pointerandDW_OP_LLVM_implicit_aspace_pointeroperations.If L, or the location description of any composite location description part that is a subcomponent of L, has more than one single location description, then any one of them can be selected as they are required to all have the same value. For any single location description SL, bits are retrieved from the associated storage location starting at the bit offset specified by SL. For a composite location description, the retrieved bits are the concatenation of the N bits from each composite location part PL, where N is limited to the size of PL.
DW_OP_deref_sizeDW_OP_deref_sizehas a single 1-byte unsigned integral constant that represents a byte result size S.It pops one stack entry that must be a location description L.
T is the smaller of the generic type size and S scaled by 8 (the byte size). A value V of T bits is retrieved from the location storage specified by L. If V is smaller than the size of the generic type, V is zero-extended to the generic type size. V is pushed onto the stack with the generic type.
The DWARF expression is ill-formed if any bit of the value is retrieved from the undefined location storage, or if the offset of any bit exceeds the size of the location storage specified by L.
Note
Truncating the value when S is larger than the generic type matches what GDB does. This allows the generic type size to not be a integral byte size. It does allow S to be arbitrarily large. Should S be restricted to the size of the generic type rounded up to a multiple of 8?
See Implicit Location Description Operations for special rules concerning implicit location descriptions created by the
DW_OP_implicit_pointerandDW_OP_LLVM_implicit_aspace_pointeroperations.DW_OP_deref_typeDW_OP_deref_typehas two operands. The first is a 1-byte unsigned integral constant S. The second is an unsigned LEB128 integer that represents the offset of a debugging information entry D in the current compilation unit, that provides the type of the result value.It pops one stack entry that must be a location description L. T is the bit size of the type D. A value V of T bits is retrieved from the location storage specified by L. V is pushed on the stack with the type D.
The DWARF is ill-formed if D is not a
DW_TAG_base_typedebugging information entry, if T divided by 8 and rounded up to a multiple of 8 (the byte size) is not equal to S, if any bit of the value is retrieved from the undefined location storage, or if the offset of any bit exceeds the size of the location storage specified by L.See Implicit Location Description Operations for special rules concerning implicit location descriptions created by the
DW_OP_implicit_pointerandDW_OP_LLVM_implicit_aspace_pointeroperations.While the size of the pushed value V can be inferred from the type D definition, it is encoded explicitly into the operation so that the operation can be parsed easily without reference to the
.debug_infosection.Note
It is unclear why the operand S is needed. Unlike
DW_OP_const_type, the size is not needed for parsing. Any evaluation needs to get the base type to record with the value to know its encoding and bit size.This definition allows the base type to be a bit size since there seems no reason to restrict it.
DW_OP_xderefDeprecatedDW_OP_xderefpops two stack entries. The first must be an integral type value that represents an address A. The second must be an integral type value that represents a target architecture specific address space identifier AS.The operation is equivalent to performing
DW_OP_swap; DW_OP_LLVM_form_aspace_address; DW_OP_deref. The value V retrieved is left on the stack with the generic type.This operation is deprecated as the
DW_OP_LLVM_form_aspace_addressoperation can be used and provides greater expressiveness.DW_OP_xderef_sizeDeprecatedDW_OP_xderef_sizehas a single 1-byte unsigned integral constant that represents a byte result size S.It pops two stack entries. The first must be an integral type value that represents an address A. The second must be an integral type value that represents a target architecture specific address space identifier AS.
The operation is equivalent to performing
DW_OP_swap; DW_OP_LLVM_form_aspace_address; DW_OP_deref_size S. The zero-extended value V retrieved is left on the stack with the generic type.This operation is deprecated as the
DW_OP_LLVM_form_aspace_addressoperation can be used and provides greater expressiveness.DW_OP_xderef_typeDeprecatedDW_OP_xderef_typehas two operands. The first is a 1-byte unsigned integral constant S. The second operand is an unsigned LEB128 integer R that represents the offset of a debugging information entry D in the current compilation unit, that provides the type of the result value.It pops two stack entries. The first must be an integral type value that represents an address A. The second must be an integral type value that represents a target architecture specific address space identifier AS.
The operation is equivalent to performing
DW_OP_swap; DW_OP_LLVM_form_aspace_address; DW_OP_deref_type S R. The value V retrieved is left on the stack with the type D.This operation is deprecated as the
DW_OP_LLVM_form_aspace_addressoperation can be used and provides greater expressiveness.DW_OP_entry_valueDeprecatedDW_OP_entry_valuepushes the value that the described location held upon entering the current subprogram.It has two operands. The first is an unsigned LEB128 integer S. The second is a block of bytes, with a length equal S, interpreted as a DWARF operation expression E.
E is evaluated as if it had been evaluated upon entering the current subprogram with an empty initial stack.
Note
It is unclear what this means. What is the current program location and current frame that must be used? Does this require reverse execution so the register and memory state are as it was on entry to the current subprogram?
The DWARF expression is ill-formed if the evaluation of E executes a
DW_OP_push_object_addressoperation.If the result of E is a location description with one register location description (see Register Location Description Operations),
DW_OP_entry_valuepushes the value that register had upon entering the current subprogram. The value entry type is the target architecture register base type. If the register value is undefined or the register location description bit offset is not 0, then the DWARF expression is ill-formed.The register location description provides a more compact form for the case where the value was in a register on entry to the subprogram.
If the result of E is a value V,
DW_OP_entry_valuepushes V on the stack.Otherwise, the DWARF expression is ill-formed.
The values needed to evaluate
DW_OP_entry_valuecould be obtained in several ways. The consumer could suspend execution on entry to the subprogram, record values needed byDW_OP_entry_valueexpressions within the subprogram, and then continue. When evaluatingDW_OP_entry_value, the consumer would use these recorded values rather than the current values. Or, when evaluatingDW_OP_entry_value, the consumer could virtually unwind using the Call Frame Information (see Call Frame Information) to recover register values that might have been clobbered since the subprogram entry point.The
DW_OP_entry_valueoperation is deprecated as its main usage is provided by other means. DWARF Version 5 added theDW_TAG_call_site_parameterdebugger information entry for call sites that hasDW_AT_call_value,DW_AT_call_data_location, andDW_AT_call_data_valueattributes that provide DWARF expressions to compute actual parameter values at the time of the call, and requires the producer to ensure the expressions are valid to evaluate even when virtually unwound. TheDW_OP_LLVM_call_frame_entry_regoperation provides access to registers in the virtually unwound calling frame.Note
It is unclear why this operation is defined this way. How would a consumer know what values have to be saved on entry to the subprogram? Does it have to parse every expression of every
DW_OP_entry_valueoperation to capture all the possible results needed? Or does it have to implement reverse execution so it can evaluate the expression in the context of the entry of the subprogram so it can obtain the entry point register and memory values? Or does the compiler somehow instruct the consumer how to create the saved copies of the variables on entry?If the expression is simply using existing variables, then it is just a regular expression and no special operation is needed. If the main purpose is only to read the entry value of a register using CFI then it would be better to have an operation that explicitly does just that such as the proposed
DW_OP_LLVM_call_frame_entry_regoperation.GDB only seems to implement
DW_OP_entry_valuewhen E is exactlyDW_OP_reg*orDW_OP_breg*; DW_OP_deref*. It evaluates E in the context of the calling subprogram and the calling call site program location. But the wording suggests that is not the intention.Given these issues it is suggested
DW_OP_entry_valueis deprecated in favor of using the new facities that have well defined semantics and implementations.
Location Description Operations¶
This section describes the operations that push location descriptions on the stack.
DW_OP_LLVM_offsetNewDW_OP_LLVM_offsetpops two stack entries. The first must be an integral type value that represents a byte displacement B. The second must be a location description L.It adds the value of B scaled by 8 (the byte size) to the bit offset of each single location description SL of L, and pushes the updated L.
If the updated bit offset of any SL is less than 0 or greater than or equal to the size of the location storage specified by SL, then the DWARF expression is ill-formed.
DW_OP_LLVM_offset_uconstNewDW_OP_LLVM_offset_uconsthas a single unsigned LEB128 integer operand that represents a byte displacement B.The operation is equivalent to performing
DW_OP_constu B; DW_OP_LLVM_offset.This operation is supplied specifically to be able to encode more field displacements in two bytes than can be done with
DW_OP_lit*; DW_OP_LLVM_offset.Note
Should this be named
DW_OP_LLVM_offset_uconstto matchDW_OP_plus_uconst, orDW_OP_LLVM_offset_constuto matchDW_OP_constu?DW_OP_LLVM_bit_offsetNewDW_OP_LLVM_bit_offsetpops two stack entries. The first must be an integral type value that represents a bit displacement B. The second must be a location description L.It adds the value of B to the bit offset of each single location description SL of L, and pushes the updated L.
If the updated bit offset of any SL is less than 0 or greater than or equal to the size of the location storage specified by SL, then the DWARF expression is ill-formed.
DW_OP_push_object_addressDW_OP_push_object_addresspushes the location description L of the object currently being evaluated as part of evaluation of a user presented expression.This object may correspond to an independent variable described by its own debugging information entry or it may be a component of an array, structure, or class whose address has been dynamically determined by an earlier step during user expression evaluation.
This operation provides explicit functionality (especially for arrays involving descriptions) that is analogous to the implicit push of the base location description of a structure prior to evaluation of a ``DW_AT_data_member_location`` to access a data member of a structure.
DW_OP_LLVM_call_frame_entry_regNewDW_OP_LLVM_call_frame_entry_reghas a single unsigned LEB128 integer operand that represents a target architecture register number R.It pushes a location description L that holds the value of register R on entry to the current subprogram as defined by the Call Frame Information (see Call Frame Information).
If there is no Call Frame Information defined, then the default rules for the target architecture are used. If the register rule is undefined, then the undefined location description is pushed. If the register rule is same value, then a register location description for R is pushed.
The undefined location storage represents a piece or all of an object that is present in the source but not in the object code (perhaps due to optimization). Neither reading nor writing to the undefined location storage is meaningful.
An undefined location description specifies the undefined location storage.
There is no concept of the size of the undefined location storage, nor of a bit
offset for an undefined location description. The DW_OP_LLVM_*offset
operations leave an undefined location description unchanged. The
DW_OP_*piece operations can explicitly or implicitly specify an undefined
location description, allowing any size and offset to be specified, and results
in a part with all undefined bits.
DW_OP_LLVM_undefinedNewDW_OP_LLVM_undefinedpushes a location description L that comprises one undefined location description SL.
Each of the target architecture specific address spaces has a corresponding memory location storage that denotes the linear addressable memory of that address space. The size of each memory location storage corresponds to the range of the addresses in the corresponding address space.
It is target architecture defined how address space location storage maps to target architecture physical memory. For example, they may be independent memory, or more than one location storage may alias the same physical memory possibly at different offsets and with different interleaving. The mapping may also be dictated by the source language address classes.
A memory location description specifies a memory location storage. The bit offset corresponds to a bit position within a byte of the memory. Bits accessed using a memory location description, access the corresponding target architecture memory starting at the bit position within the byte specified by the bit offset.
A memory location description that has a bit offset that is a multiple of 8 (the byte size) is defined to be a byte address memory location description. It has a memory byte address A that is equal to the bit offset divided by 8.
A memory location description that does not have a bit offset that is a multiple of 8 (the byte size) is defined to be a bit field memory location description. It has a bit position B equal to the bit offset modulo 8, and a memory byte address A equal to the bit offset minus B that is then divided by 8.
The address space AS of a memory location description is defined to be the address space that corresponds to the memory location storage associated with the memory location description.
A location description that is comprised of one byte address memory location description SL is defined to be a memory byte address location description. It has a byte address equal to A and an address space equal to AS of the corresponding SL.
DW_ASPACE_none is defined as the target architecture default address space.
If a stack entry is required to be a location description, but it is a value V with the generic type, then it is implicitly converted to a location description L with one memory location description SL. SL specifies the memory location storage that corresponds to the target architecture default address space with a bit offset equal to V scaled by 8 (the byte size).
Note
If it is wanted to allow any integral type value to be implicitly converted to a memory location description in the target architecture default address space:
If a stack entry is required to be a location description, but is a value V with an integral type, then it is implicitly converted to a location description L with a one memory location description SL. If the type size of V is less than the generic type size, then the value V is zero extended to the size of the generic type. The least significant generic type size bits are treated as a twos-complement unsigned value to be used as an address A. SL specifies memory location storage corresponding to the target architecture default address space with a bit offset equal to A scaled by 8 (the byte size).
The implicit conversion could also be defined as target architecture specific. For example, GDB checks if V is an integral type. If it is not it gives an error. Otherwise, GDB zero-extends V to 64 bits. If the GDB target defines a hook function, then it is called. The target specific hook function can modify the 64-bit value, possibly sign extending based on the original value type. Finally, GDB treats the 64-bit value V as a memory location address.
If a stack entry is required to be a location description, but it is an implicit pointer value IPV with the target architecture default address space, then it is implicitly converted to a location description with one single location description specified by IPV. See Implicit Location Description Operations.
Note
Is this rule required for DWARF Version 5 backwards compatibility? If not, it
can be eliminated, and the producer can use
DW_OP_LLVM_form_aspace_address.
If a stack entry is required to be a value, but it is a location description L with one memory location description SL in the target architecture default address space with a bit offset B that is a multiple of 8, then it is implicitly converted to a value equal to B divided by 8 (the byte size) with the generic type.
DW_OP_addrDW_OP_addrhas a single byte constant value operand, which has the size of the generic type, that represents an address A.It pushes a location description L with one memory location description SL on the stack. SL specifies the memory location storage corresponding to the target architecture default address space with a bit offset equal to A scaled by 8 (the byte size).
If the DWARF is part of a code object, then A may need to be relocated. For example, in the ELF code object format, A must be adjusted by the difference between the ELF segment virtual address and the virtual address at which the segment is loaded.
DW_OP_addrxDW_OP_addrxhas a single unsigned LEB128 integer operand that represents a zero-based index into the.debug_addrsection relative to the value of theDW_AT_addr_baseattribute of the associated compilation unit. The address value A in the.debug_addrsection has the size of the generic type.It pushes a location description L with one memory location description SL on the stack. SL specifies the memory location storage corresponding to the target architecture default address space with a bit offset equal to A scaled by 8 (the byte size).
If the DWARF is part of a code object, then A may need to be relocated. For example, in the ELF code object format, A must be adjusted by the difference between the ELF segment virtual address and the virtual address at which the segment is loaded.
DW_OP_LLVM_form_aspace_addressNewDW_OP_LLVM_form_aspace_addresspops top two stack entries. The first must be an integral type value that represents a target architecture specific address space identifier AS. The second must be an integral type value that represents an address A.The address size S is defined as the address bit size of the target architecture specific address space that corresponds to AS.
A is adjusted to S bits by zero extending if necessary, and then treating the least significant S bits as a twos-complement unsigned value A’.
It pushes a location description L with one memory location description SL on the stack. SL specifies the memory location storage that corresponds to AS with a bit offset equal to A’ scaled by 8 (the byte size).
The DWARF expression is ill-formed if AS is not one of the values defined by the target architecture specific
DW_ASPACE_*values.See Implicit Location Description Operations for special rules concerning implicit pointer values produced by dereferencing implicit location descriptions created by the
DW_OP_implicit_pointerandDW_OP_LLVM_implicit_aspace_pointeroperations.DW_OP_form_tls_addressDW_OP_form_tls_addresspops one stack entry that must be an integral type value and treats it as a thread-local storage address T.It pushes a location description L with one memory location description SL on the stack. SL is the target architecture specific memory location description that corresponds to the thread-local storage address T.
The meaning of the thread-local storage address T is defined by the run-time environment. If the run-time environment supports multiple thread-local storage blocks for a single thread, then the block corresponding to the executable or shared library containing this DWARF expression is used.
Some implementations of C, C++, Fortran, and other languages support a thread-local storage class. Variables with this storage class have distinct values and addresses in distinct threads, much as automatic variables have distinct values and addresses in each subprogram invocation. Typically, there is a single block of storage containing all thread-local variables declared in the main executable, and a separate block for the variables declared in each shared library. Each thread-local variable can then be accessed in its block using an identifier. This identifier is typically a byte offset into the block and pushed onto the DWARF stack by one of the
DW_OP_const*operations prior to theDW_OP_form_tls_addressoperation. Computing the address of the appropriate block can be complex (in some cases, the compiler emits a function call to do it), and difficult to describe using ordinary DWARF location descriptions. Instead of forcing complex thread-local storage calculations into the DWARF expressions, theDW_OP_form_tls_addressallows the consumer to perform the computation based on the target architecture specific run-time environment.DW_OP_call_frame_cfaDW_OP_call_frame_cfapushes the location description L of the Canonical Frame Address (CFA) of the current subprogram, obtained from the Call Frame Information on the stack. See Call Frame Information.Although the value of the
DW_AT_frame_baseattribute of the debugger information entry corresponding to the current subprogram can be computed using a location list expression, in some cases this would require an extensive location list because the values of the registers used in computing the CFA change during a subprogram execution. If the Call Frame Information is present, then it already encodes such changes, and it is space efficient to reference that using theDW_OP_call_frame_cfaoperation.DW_OP_fbregDW_OP_fbreghas a single signed LEB128 integer operand that represents a byte displacement B.The location description L for the frame base of the current subprogram is obtained from the
DW_AT_frame_baseattribute of the debugger information entry corresponding to the current subprogram as described in Debugging Information Entry Attributes.The location description L is updated as if the
DW_OP_LLVM_offset_uconst Boperation was applied. The updated L is pushed on the stack.DW_OP_breg0,DW_OP_breg1, …,DW_OP_breg31The
DW_OP_breg<N>operations encode the numbers of up to 32 registers, numbered from 0 through 31, inclusive. The register number R corresponds to the N in the operation name.They have a single signed LEB128 integer operand that represents a byte displacement B.
The address space identifier AS is defined as the one corresponding to the target architecture specific default address space.
The address size S is defined as the address bit size of the target architecture specific address space corresponding to AS.
The contents of the register specified by R are retrieved as a twos-complement unsigned value and zero extended to S bits. B is added and the least significant S bits are treated as a twos-complement unsigned value to be used as an address A.
They push a location description L comprising one memory location description LS on the stack. LS specifies the memory location storage that corresponds to AS with a bit offset equal to A scaled by 8 (the byte size).
DW_OP_bregxDW_OP_bregxhas two operands. The first is an unsigned LEB128 integer that represents a register number R. The second is a signed LEB128 integer that represents a byte displacement B.The action is the same as for
DW_OP_breg<N>except that R is used as the register number and B is used as the byte displacement.DW_OP_LLVM_aspace_bregxNewDW_OP_LLVM_aspace_bregxhas two operands. The first is an unsigned LEB128 integer that represents a register number R. The second is a signed LEB128 integer that represents a byte displacement B. It pops one stack entry that is required to be an integral type value that represents a target architecture specific address space identifier AS.The action is the same as for
DW_OP_breg<N>except that R is used as the register number, B is used as the byte displacement, and AS is used as the address space identifier.The DWARF expression is ill-formed if AS is not one of the values defined by the target architecture specific
DW_ASPACE_*values.Note
Could also consider adding
DW_OP_aspace_breg0, DW_OP_aspace_breg1, ..., DW_OP_aspace_bref31which would save encoding size.
There is a register location storage that corresponds to each of the target architecture registers. The size of each register location storage corresponds to the size of the corresponding target architecture register.
A register location description specifies a register location storage. The bit offset corresponds to a bit position within the register. Bits accessed using a register location description access the corresponding target architecture register starting at the specified bit offset.
DW_OP_reg0,DW_OP_reg1, …,DW_OP_reg31DW_OP_reg<N>operations encode the numbers of up to 32 registers, numbered from 0 through 31, inclusive. The target architecture register number R corresponds to the N in the operation name.They push a location description L that specifies one register location description SL on the stack. SL specifies the register location storage that corresponds to R with a bit offset of 0.
DW_OP_regxDW_OP_regxhas a single unsigned LEB128 integer operand that represents a target architecture register number R.It pushes a location description L that specifies one register location description SL on the stack. SL specifies the register location storage that correspond
