Problems calling a gdb stack trace from inside the program thats being traced.

Problems calling a gdb stack trace from inside the program thats being traced.

Post by Joe Rutled » Thu, 20 Jun 2002 22:55:32



I'm trying to get my C program to stack trace itself using gdb.

Upon detecting an error my program does a

system("gdb -x configfile programname programPID > outputfile");

Where the configfile contains the lines:-

bt
quit

Now that works fine from a bash shell but all I get when my program
hits it is a frozen program that needs a Ctrl-C.

Whats going on? Can I use this technique to stack trace my program?

It is a multi-threaded (pthreads) program, compiled using -gstabs+ in
the compile line, with gcc 3.1.

I don't want to have to write my own stack tracing routines!

Thanks,

Joe

 
 
 

Problems calling a gdb stack trace from inside the program thats being traced.

Post by Bruce Stephen » Fri, 21 Jun 2002 08:49:00


[...]

Quote:> I don't want to have to write my own stack tracing routines!

% info '(libc) Debugging Support'

 
 
 

Problems calling a gdb stack trace from inside the program thats being traced.

Post by Joe Rutled » Fri, 21 Jun 2002 17:35:00


Many MANY thanks!

There is so much information it is hard to know where to look sometimes.

Joe.



> [...]

> > I don't want to have to write my own stack tracing routines!

> % info '(libc) Debugging Support'

 
 
 

Problems calling a gdb stack trace from inside the program thats being traced.

Post by Michel Bardiau » Fri, 21 Jun 2002 21:53:10




> [...]

> > I don't want to have to write my own stack tracing routines!

> % info '(libc) Debugging Support'

Unfortunately this gives you only the function names and addresses.

If you want the source file name and line numbers, you have to use
system("addr2line ...

--
Michel Bardiaux
Peaktime Belgium S.A.  Bd. du Souverain, 191  B-1160 Bruxelles
Tel : +32 2 790.29.41

 
 
 

Problems calling a gdb stack trace from inside the program thats being traced.

Post by Michel Bardiau » Fri, 21 Jun 2002 22:06:45



> I'm trying to get my C program to stack trace itself using gdb.

> Upon detecting an error my program does a

> system("gdb -x configfile programname programPID > outputfile");

> Where the configfile contains the lines:-

> bt
> quit

> Now that works fine from a bash shell but all I get when my program
> hits it is a frozen program that needs a Ctrl-C.

Reason: you see it when doing that manually:

(gdb) quit
The program is running.  Quit anyway (and detach it)? (y or n) yes
Detaching from program:
/usrco/dsk2/people/colin/dev/rh7.1/pktbe/horo/horo, process 11116

Hence you need a 3rd line in your script.

BTW I'm running GNU gdb 5.0rh-5 Red Hat Linux 7.1 and it has a slight
bug: the prompt is 'y or n' but the proper answer is "yes"; if you just
answer "y" it says "Not implemented yet".

Quote:

> Whats going on? Can I use this technique to stack trace my program?

> It is a multi-threaded (pthreads) program, compiled using -gstabs+ in
> the compile line, with gcc 3.1.

> I don't want to have to write my own stack tracing routines!

I give some pointers in my reply to someone else's reply to your
question.

Quote:

> Thanks,

> Joe

Greetings,
--
Michel Bardiaux
 
 
 

Problems calling a gdb stack trace from inside the program thats being traced.

Post by Joe Rutled » Sat, 22 Jun 2002 17:27:24


Well, I'm getting there... But.

All I get is the addresses of the functions, and no symbols. Now,
according to the info page I need to pass -rdynamic to the gnu linker.
I do this, and yet it makes no difference. Also in the man page for ld
I see no -rdynamic flag, though ld happily takes it. What am I doing
wrong?

I'm creating a whole slew of object files, then linking them together
with -rdynamic then linking the final executable together to the
system libs, without -rdynamic because using -rdynamic causes the
linker to fail when linking libc, which strangely enough, is the only
part of my stack trace that does show symbols!

Ooooh. Confusing. Also which approach do you suggest is best? Using
GDB or using the backtrace function of libc?

Thanks,

Joe




> > [...]

> > > I don't want to have to write my own stack tracing routines!

> > % info '(libc) Debugging Support'

> Unfortunately this gives you only the function names and addresses.

> If you want the source file name and line numbers, you have to use
> system("addr2line ...

 
 
 

1. getting stack trace from inside program?

i would like to get a stack trace from inside a program.  that is, i would
like to obtain the name of the current function's caller, the name of that
function's caller, and so on, all the way up to "main", and do all of this
from inside a running program.  is such a thing possible?  i am running
under SunOS 4.1.3/gcc 2.5.8 if it matters.  thanks!

--
never speak before you strike. it's bad luck. - Psin, "Until The Sun Falls"

Mike Nemeth          Virtual Universe Corp      Calgary, Alberta, Canada

2. Seyon successful!

3. GDB does not show full stack trace

4. Various Solaris 2.5.1 questions

5. gdb: core dump stack trace

6. Rexx implemented for AIX31 / RS6000?

7. gdb, solaris 2.3, and thread stack traces

8. KMail w/ SpamAssassin?

9. Call back trace inside signal handler

10. Tracing system calls with gdb

11. Printing a stack trace upon program error

12. How can I get a stack trace within a program?

13. stack trace of C/C++ programs (under SunOS)