anon
anon

Reputation: 42697

Accessing 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'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.

Upvotes: 6

Views: 249

Answers (3)

Carlo Wood
Carlo Wood

Reputation: 6821

This has always been the aim of libcwd, but due to lack of interest by the community, I never got further than reading source-file line-number information from the .debug_line section of DWARF.

Upvotes: 0

Ronny Brendel
Ronny Brendel

Reputation: 4845

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

Library to read ELF file DWARF debug information

Upvotes: 3

Ronny Brendel
Ronny Brendel

Reputation: 4845

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

Upvotes: 2

Related Questions