Re: [Dwarf-Discuss] Retrieving variables, function address using dwarf

2021-03-05 Thread David Blaikie via Dwarf-Discuss
On Fri, Mar 5, 2021 at 8:28 PM Archana Deshmukh via Dwarf-Discuss <
dwarf-discuss@lists.dwarfstd.org> wrote:

> Hello,
>
> I need to read the address of local variable, global variable, function
> name and function arguments from the process.
>
> For global variables , I read the address "55b51afea000" from
> /proc//maps file. I use DW_OP_addr parameter to retrieve the address.
> 55b51afea000 + DW_OP_addr gives me the address of global variable.
>
> I need to read the stack segment, heap.
>

As you found with the global variables, DWARF doesn't provide you with the
means to read things, but does tell you where the things are and then you
go find out how to read them with OS features to read process memory, etc.

But for the stack, for instance - if you read the pc register, then use
that to look through the DWARF to find the DW_TAG_subprogram with either
DW_AT_low_pc/DW_AT_high_pc or DW_AT_ranges that cover the address the pc
points to, then look at the frame_base in the DWARF to figure out which
register you should look at to figure out where the frame starts - then you
can use that to figure out how to interpret the DW_AT_locations of any
local DW_AT_variables that are covered by any scope that includes that pc.

Heap similarly - you'll start at the global or local variables, and then
look at the data they point to, and follow the description of the
variable's value, query the memory, follow the pointers, etc...


> Is there any way to read segments? DW_AT_segment parameter seems to be for
> 16 bit.
>
> I need to read the following process map using dwarf.
>
> Any suggestion, pointers are welcome.
>
> 55b51afea000-55b51afeb000 r-xp  fd:00 5902563
>
> 55b51b1ea000-55b51b1eb000 r--p  fd:00 5902563
>
> 55b51b1eb000-55b51b1ec000 rw-p 1000 fd:00 5902563
>
> 55b51c094000-55b51c0b5000 rw-p  00:00 0 [heap]
>
> 7fca24956000-7fca24957000 rwxp  00:00 0
>
> 7fca24958000-7fca24959000 rwxp  00:00 0
>
> 7fca2496d000-7fca2496f000 rwxp  00:00 0
>
> 7fca24974000-7fca24975000 rwxp  00:00 0
>
> 7fca2497f000-7fca2498 rwxp  00:00 0
>
> 7fca24983000-7fca2498c000 rwxp  00:00 0
>
> 7fca2498f000-7fca2499a000 rwxp  00:00 0
>
> 7fca2499b000-7fca24aec000 rwxp  00:00 0
>
> 7fca24aec000-7fca24af8000 rwxp  00:00 0
>
> 7fca24af8000-7fca24afa000 rwxp  00:00 0
>
> 7fca24afa000-7fca24ce1000 r-xp  fd:00 10230842
>
> 7fca24ce1000-7fca24ee1000 ---p 001e7000 fd:00 10230842
>
> 7fca24ee1000-7fca24ee5000 r--p 001e7000 fd:00 10230842
>
> 7fca24ee5000-7fca24ee7000 rw-p 001eb000 fd:00 10230842
>
> 7fca24ee7000-7fca24eeb000 rw-p  00:00 0
>
> 7fca24eeb000-7fca24f2d000 rwxp  00:00 0
>
> 7fca24f2d000-7fca24f32000 rwxp  00:00 0
>
> 7fca24f32000-7fca24f34000 rw-p  00:00 0
>
> 7fca24f34000-7fca24f36000 rwxp  00:00 0
>
> 7fca24f36000-7fca251a rwxp  00:00 0
>
> 7fca251a-7fca350e ---p  00:00 0
>
> 7fca350e-7fca361f3000 rwxp  00:00 0
>
> 7fca361f3000-7fca36f4b000 rw-p  00:00 0
>
> 7fca36f4b000-7fca36f81000 r--p  fd:00 5902405
>
> 7fca36f81000-7fca3719a000 r-xp 00036000 fd:00 5902405
>
> 7fca3719a000-7fca37218000 r--p 0024f000 fd:00 5902405
>
> 7fca37218000-7fca3722c000 r--p 002cc000 fd:00 5902405
>
> 7fca3722d000-7fca3723 rw-p  00:00 0
>
> 7fca3723-7fca37426000 r-xp  fd:00 5902408
>
> 7fca37426000-7fca37625000 ---p  00:00 0
>
> 7fca37625000-7fca37627000 r--p 001f5000 fd:00 5902408
>
> 7fca37627000-7fca37629000 rw-p 001f7000 fd:00 5902408
>
> 7fca37629000-7fca3764d000 rw-p  00:00 0
>
> 7fca3764d000-7fca376dc000 r-xp  fd:00 5902391
>
> 7fca376dc000-7fca378db000 ---p  00:00 0
>
> 7fca378db000-7fca378de000 r--p 0008e000 fd:00 5902391
>
> 7fca378de000-7fca378df000 rw-p 00091000 fd:00 5902391
>
> 7fca378df000-7fca37908000 rw-p  00:00 0
>
> 7fca37908000-7fca37937000 r-xp  fd:00 5902373
>
> 7fca37937000-7fca37b36000 ---p  00:00 0
>
> 7fca37b36000-7fca37b37000 r--p 0002e000 fd:00 5902373
>
> 7fca37b37000-7fca37b38000 rw-p 0002f000 fd:00 5902373
>
> 7fca37b38000-7fca37bd8000 r-xp  fd:00 5902368
>
> 7fca37bd8000-7fca37dd7000 ---p  00:00 0
>
> 7fca37dd7000-7fca37ddb000 r--p 0009f000 fd:00 5902368
>
> 7fca37ddb000-7fca37ddc000 rw-p 000a3000 fd:00 5902368
>
> 7fca37ddc000-7fca37ddd000 rw-p  00:00 0
>
> 7fca37ddd000-7fca37dec000 r-xp  fd:00 5902381
>
> 7fca37dec000-7fca37feb000 ---p  00:00 0
>
> Best Regards,
> Archana
>
> ___
> Dwarf-Discuss mailing list
> Dwarf-Discuss@lists.dwarfstd.org
> http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org
>
___
Dwarf-Discuss mailing list
Dwarf-Discuss@lists.dwarfstd.org
http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org


[Dwarf-Discuss] Retrieving variables, function address using dwarf

2021-03-05 Thread Archana Deshmukh via Dwarf-Discuss
Hello,

I need to read the address of local variable, global variable, function
name and function arguments from the process.

For global variables , I read the address "55b51afea000" from
/proc//maps file. I use DW_OP_addr parameter to retrieve the address.
55b51afea000 + DW_OP_addr gives me the address of global variable.

I need to read the stack segment, heap. Is there any way to read segments?
DW_AT_segment parameter seems to be for 16 bit.

I need to read the following process map using dwarf.

Any suggestion, pointers are welcome.

55b51afea000-55b51afeb000 r-xp  fd:00 5902563

55b51b1ea000-55b51b1eb000 r--p  fd:00 5902563

55b51b1eb000-55b51b1ec000 rw-p 1000 fd:00 5902563

55b51c094000-55b51c0b5000 rw-p  00:00 0 [heap]

7fca24956000-7fca24957000 rwxp  00:00 0

7fca24958000-7fca24959000 rwxp  00:00 0

7fca2496d000-7fca2496f000 rwxp  00:00 0

7fca24974000-7fca24975000 rwxp  00:00 0

7fca2497f000-7fca2498 rwxp  00:00 0

7fca24983000-7fca2498c000 rwxp  00:00 0

7fca2498f000-7fca2499a000 rwxp  00:00 0

7fca2499b000-7fca24aec000 rwxp  00:00 0

7fca24aec000-7fca24af8000 rwxp  00:00 0

7fca24af8000-7fca24afa000 rwxp  00:00 0

7fca24afa000-7fca24ce1000 r-xp  fd:00 10230842

7fca24ce1000-7fca24ee1000 ---p 001e7000 fd:00 10230842

7fca24ee1000-7fca24ee5000 r--p 001e7000 fd:00 10230842

7fca24ee5000-7fca24ee7000 rw-p 001eb000 fd:00 10230842

7fca24ee7000-7fca24eeb000 rw-p  00:00 0

7fca24eeb000-7fca24f2d000 rwxp  00:00 0

7fca24f2d000-7fca24f32000 rwxp  00:00 0

7fca24f32000-7fca24f34000 rw-p  00:00 0

7fca24f34000-7fca24f36000 rwxp  00:00 0

7fca24f36000-7fca251a rwxp  00:00 0

7fca251a-7fca350e ---p  00:00 0

7fca350e-7fca361f3000 rwxp  00:00 0

7fca361f3000-7fca36f4b000 rw-p  00:00 0

7fca36f4b000-7fca36f81000 r--p  fd:00 5902405

7fca36f81000-7fca3719a000 r-xp 00036000 fd:00 5902405

7fca3719a000-7fca37218000 r--p 0024f000 fd:00 5902405

7fca37218000-7fca3722c000 r--p 002cc000 fd:00 5902405

7fca3722d000-7fca3723 rw-p  00:00 0

7fca3723-7fca37426000 r-xp  fd:00 5902408

7fca37426000-7fca37625000 ---p  00:00 0

7fca37625000-7fca37627000 r--p 001f5000 fd:00 5902408

7fca37627000-7fca37629000 rw-p 001f7000 fd:00 5902408

7fca37629000-7fca3764d000 rw-p  00:00 0

7fca3764d000-7fca376dc000 r-xp  fd:00 5902391

7fca376dc000-7fca378db000 ---p  00:00 0

7fca378db000-7fca378de000 r--p 0008e000 fd:00 5902391

7fca378de000-7fca378df000 rw-p 00091000 fd:00 5902391

7fca378df000-7fca37908000 rw-p  00:00 0

7fca37908000-7fca37937000 r-xp  fd:00 5902373

7fca37937000-7fca37b36000 ---p  00:00 0

7fca37b36000-7fca37b37000 r--p 0002e000 fd:00 5902373

7fca37b37000-7fca37b38000 rw-p 0002f000 fd:00 5902373

7fca37b38000-7fca37bd8000 r-xp  fd:00 5902368

7fca37bd8000-7fca37dd7000 ---p  00:00 0

7fca37dd7000-7fca37ddb000 r--p 0009f000 fd:00 5902368

7fca37ddb000-7fca37ddc000 rw-p 000a3000 fd:00 5902368

7fca37ddc000-7fca37ddd000 rw-p  00:00 0

7fca37ddd000-7fca37dec000 r-xp  fd:00 5902381

7fca37dec000-7fca37feb000 ---p  00:00 0

Best Regards,
Archana
___
Dwarf-Discuss mailing list
Dwarf-Discuss@lists.dwarfstd.org
http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org