Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Ashwin Bharambe" <ashwinb@gmail.com>
To: gdb@sourceware.org
Subject: Re: Programmatic access to stack traces in C or C++ programs
Date: Fri, 20 Oct 2006 12:41:00 -0000	[thread overview]
Message-ID: <3ef5826d0610200541g4804ec15sc2b3167b455c735e@mail.gmail.com> (raw)
In-Reply-To: <20061020031303.GA11223@nevyn.them.org>

Sweet. Thanks Daniel for pointing me to libunwind.. Now, given the
instruction pointer and stack pointer values, do you think I can use
some parts of gdb code to dump out a more readable version of the
stackframe? It would be _really_ nice if I could dump out argument
values as well, but I suspect that might be much harder.

Ashwin

On 10/19/06, Daniel Jacobowitz <drow@false.org> wrote:
> On Thu, Oct 19, 2006 at 10:27:08PM -0400, Ashwin Bharambe wrote:
> > Hi all,
> >
> > I wanted to create a "stacktrace library" which would provide a
> > routine to obtain the stacktrace of the program from any point
> > _programmatically_ (like Java's stacktraces, for example..)
> >
> > I was aware of libc's non-standard stacktrace API but it did not quite
> > work in many cases failing to resolve addresses, etc. It seems like
> > stacktrace functionality is quite implementation and
> > architecture-dependent. So, I was wondering if I could use portions of
> > gdb's code to create such a library. Currently, to print a stacktrace,
> > I utilize a piece of code (not mine, it's off the net) which fork()s a
> > gdb sub-process, makes it ptrace the parent and run the command
> > "backtrace". However this is quite time-consuming and sort of ugly.
>
> Your best bet for reliability is to work with libunwind, if you can
> restrict yourself to code with unwind information - which is more and
> more practical nowadays.
>
> > My question, therefore, is: are there pieces of the code I can steal
> > from libgdb to make this happen programmatically. I tried some naive
> > ways of performing gdb_init() and then having it execute the
> > 'backtrace' command (by invoking backtrace_command directly, for
> > example), however gdb says there's no stack. This seems to be the case
> > because it does not initialize its data structures without starting a
> > process.
> >
> > I would appreciate any pointers regarding how I can make gdb believe
> > the current process is the one it should use, without really
> > ptrace()ing it...
>
> You can not readily do this.  It will be easier and faster to stick
> with forking another copy of GDB.
>
> --
> Daniel Jacobowitz
> CodeSourcery
>


-- 
Ashwin Bharambe,  Ph.D. Candidate, Carnegie Mellon University.
Office: 412-268-7555            Web: http://www.cs.cmu.edu/~ashu


  reply	other threads:[~2006-10-20 12:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-20  2:27 Ashwin Bharambe
2006-10-20  3:10 ` Neo Jia
2006-10-20  3:13 ` Daniel Jacobowitz
2006-10-20 12:41   ` Ashwin Bharambe [this message]
2006-10-20 14:27     ` Daniel Jacobowitz
2006-10-20 20:18 ` Michael Snyder
2006-10-20 21:47   ` David Carlton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3ef5826d0610200541g4804ec15sc2b3167b455c735e@mail.gmail.com \
    --to=ashwinb@gmail.com \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox