tags:

views:

75

answers:

2

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's a structure, print out parts of the structure (i.e. how ddd displays information).

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

I.e. given that my program is compiled with "-g", is there some

std::vector<string> getStackFrame();

function I can call to get the current stackframe at the current point of execution?

Given a pointer to an object and it's type ... can I do

std::vector getClassMember(class_name);

?

I realize the default answer is "no, C++ doesn't support that level of introspection" -- however, recall I'm on linux, my program is compiled with "-g", and gdb can do it, so clearly the inforamtion is there. Question is: is there some API for accessing it?

EDIT: PS Naysers, I'd love to see a reason for closing this question.

+2  A: 

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

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

Ronny
+3  A: 

The debugging format is called dwarf. This should give you hint where to search further.

http://stackoverflow.com/questions/1101272/library-to-read-elf-file-dwarf-debug-information

Ronny