Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support DW_OP_implicit_pointer/DW_OP_GNU_implicit_pointer #173

Open
Tracked by #321
osandov opened this issue Apr 28, 2022 · 0 comments
Open
Tracked by #321

Support DW_OP_implicit_pointer/DW_OP_GNU_implicit_pointer #173

osandov opened this issue Apr 28, 2022 · 0 comments
Labels
debuginfo Support for debugging information formats help wanted Seeking volunteers

Comments

@osandov
Copy link
Owner

osandov commented Apr 28, 2022

Background

DWARF specifies the location of a variable (local or global) with a "location description". See section 2.6 in the DWARF 5 specification. A location description is essentially a series of instructions that, when executed, gives the address or value of the desired variable. drgn has code that evaluates a location description and translates it into a drgn object: see drgn_object_from_dwarf_location() and drgn_eval_dwarf_expression().

DWARF location descriptions have an operation, DW_OP_implicit_pointer (section 2.6.1.1.4 in the DWARF 5 spec), which means that a pointer has been optimized out, but the value that it points to can still be described. DW_OP_implicit_pointer is a standardized version of a GNU extension, DW_OP_GNU_implicit_pointer. drgn does not yet support either of these operations.

Example

Consider the following (contrived) source file compiled with gcc -O2:

void func(int *dst)
{
	const int val = 5;
	const int *src = &val;
	*dst = *src;
}

And the generated assembly code:

func:
	movl	$5, (%rdi)
	ret

The compiler has no reason to actually allocate val on the stack, and therefore no meaningful address to assign to src. The DWARF information reflects that. The location list for val indicates that its location is not known but it has a value of 5:

$ eu-readelf --debug-dump=info test.o
...
 [    5a]      variable             abbrev: 1
               name                 (string) "val"
               decl_file            (implicit_const) test.c (1)
               decl_line            (data1) 3
               decl_column          (data1) 12
               type                 (ref4) [    8d]
               location             (sec_offset) location list [     e]
...
$ eu-readelf --debug-dump=loc test.o
...
  Offset: e, Index: 2
    offset_pair 0, 6
      .text+000000000000000000 <func>..
      .text+0x0000000000000005 <func+0x5>
        [ 0] lit5
        [ 1] stack_value
    end_of_list
...

The location list for src indicates that its pointer value is not known, but the value pointed to is DIE 5a (which is val):

$ eu-readelf --debug-dump=info test.o
...
 [    6d]      variable             abbrev: 1
               name                 (string) "src"
               decl_file            (implicit_const) test.c (1)
               decl_line            (data1) 4
               decl_column          (data1) 13
               type                 (ref4) [    92]
               location             (sec_offset) location list [    17]
...
$ eu-readelf --debug-dump=loc test.o
...
  Offset: 17, Index: b
    offset_pair 0, 7
      .text+000000000000000000 <func>..
      .text+0x0000000000000006 <func+0x6>
        [ 0] implicit_pointer [    5a] +0
    end_of_list
...

Problem Statement

As stated above, drgn does not support DW_OP_implicit_pointer or its GNU predecessor, DW_OP_GNU_implicit_pointer. This is mainly because drgn does not have a way to represent an "implicit pointer". So, this project has two parts:

  1. Add the concept of an implicit pointer to drgn's object model. Specifically:
    a. Add a new enum drgn_object_kind (named something like DRGN_OBJECT_IMPLICIT_POINTER).
    b. Store the pointed-to value for implicit pointer objects in struct drgn_object::value.
    c. Add a drgn_object_set_implicit_pointer() function to create implicit pointer objects.
    d. Update all of the object operations to handle implicit pointer objects (e.g., you can't get the value of an implicit pointer object with drgn_object_read() or drgn_object_read_value(), but you can dereference it with drgn_object_dereference() or drgn_object_member_dereference()).
  2. Implement support for DW_OP_implicit_pointer and DW_OP_GNU_implicit_pointer on top of implicit pointer objects.
@osandov osandov added the help wanted Seeking volunteers label Apr 28, 2022
@osandov osandov changed the title Support DW_OP_implicit_pointer/DW_OP_GNU_implicit_pointer Support DW_OP_implicit_pointer/DW_OP_GNU_implicit_pointer Jul 3, 2023
@osandov osandov added the debuginfo Support for debugging information formats label Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debuginfo Support for debugging information formats help wanted Seeking volunteers
Projects
None yet
Development

No branches or pull requests

1 participant