Access to program information that gdb sees in C ++

I have a program written in C ++ on Linux compiled with -g.

When I run it under gdb, I can

1) set breakpoints 2) at those breakpoints, print out variables 3) see the stackframe 4) given a variable that a structure, print out parts of the structure (ie how ddd displays information). 

Now, given that my program is compiled with "-g" - is there anyway that I can access this power inside my program itself?

those. that my program is compiled with "-g", are there any

 std::vector<string> getStackFrame(); 

Function that I can call to get the current frame stack at the current execution point?

Given a pointer to an object and its type ... can I do

std :: vector getClassMember (class_name);

?

I understand that the default answer is “no, C ++ does not support this level of introspection” - however, remember that I am on Linux, my program is compiled with “-g”, and gdb can do this, so it’s clear that the information there is. The question is, is there an API to access it?

EDIT: PS Naysers, I would like to see a reason to close this question.

+6
c ++ gdb
source share
2 answers

The debugging format is called dwarf. This should give you a hint where to look next.

Library for reading DWARF ELF debug file information

+3
source share

I remember using libbfd to get function names from object files. This is a library for reading object formats, maybe you can also read other debugging information using this. (I don’t know, to be honest)

http://www.skyfree.org/linux/references/bfd.pdf

+2
source share

All Articles