Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing program information that gdb sees in C++

Tags:

c++

gdb

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.

like image 479
anon Avatar asked Mar 19 '10 07:03

anon


People also ask

How do I get thread info in GDB?

Use the "info threads" command to see the IDs of currently known threads. The GDB thread debugging facility allows you to observe all threads while your program runs--but whenever GDB takes control, one thread in particular is always the focus of debugging. This thread is called the current thread.

How do I access GDB?

Go to your Linux command prompt and type “gdb”. Gdb open prompt lets you know that it is ready for commands. To exit out of gdb, type quit or q.

How do I run a program under GDB?

Starting your program. Use the run command to start your program under GDB. You must first specify the program name (except on VxWorks) with an argument to GDB (see section Getting In and Out of GDB), or by using the file or exec-file command (see section Commands to specify files).

What does info registers do in GDB?

The info registers command shows the canonical names. For example, on the SPARC, info registers displays the processor status register as $psr but you can also refer to it as $ps . GDB always considers the contents of an ordinary register as an integer when the register is examined in this way.


1 Answers

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

Library to read ELF file DWARF debug information

like image 179
Ronny Brendel Avatar answered Sep 20 '22 23:09

Ronny Brendel