Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Non-interactive stepping
@ 2004-05-01 21:34 Christopher Nebergall
  2004-05-02 13:04 ` Bob Rossi
  0 siblings, 1 reply; 5+ messages in thread
From: Christopher Nebergall @ 2004-05-01 21:34 UTC (permalink / raw)
  To: gdb

Is it possible to use GDB (or another app) to print out the executing source
code file name, line number, function name etc, for an application (compiled
with -g) in a non-interactive manner (print the output to stdout)?  I used a
similar type of debugging in basica years ago and miss having something
similar in modern debuggers.

I want to do something similar to

gdb -[Some command line argument] a.out
a.out: main.c:5 main() May  1 16:18:07 CDT 2004
a.out: main.c:6 main() May  1 16:18:08 CDT 2004
a.out: main.c:7 main() May  1 16:18:09 CDT 2004
a.out: main.c:25 print() May  1 16:18:09 CDT 2004
a.out: main.c:28 print() May  1 16:18:09 CDT 2004
a.out: source2.c:10 echo() May  1 16:18:10 CDT 2004
a.out: source2.c:11 echo() May  1 16:18:10 CDT 2004
a.out: source2.c:11 echo() May  1 16:18:12 CDT 2004
a.out: main.c:29 print() May  1 16:18:13 CDT 2004
a.out: main.c:8 main() May  1 16:18:14 CDT 2004
etc...

The main reason I want this is to record program flow during real execution
of the program without having to step through it line by line in the
debugger. If there is a segfault, it's pretty easy to determine the program
flow which caused it.  It would also be useful to discover how a large
program works, and what operations in a program's GUI or command line touch
which lines of source code. It could also be used for very crude profiling.

Thanks,
Christopher



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Non-interactive stepping
  2004-05-01 21:34 Non-interactive stepping Christopher Nebergall
@ 2004-05-02 13:04 ` Bob Rossi
  2004-05-02 16:03   ` Kip Macy
  0 siblings, 1 reply; 5+ messages in thread
From: Bob Rossi @ 2004-05-02 13:04 UTC (permalink / raw)
  To: Christopher Nebergall; +Cc: gdb

On Sat, May 01, 2004 at 03:34:19PM -0600, Christopher Nebergall wrote:
> Is it possible to use GDB (or another app) to print out the executing source
> code file name, line number, function name etc, for an application (compiled
> with -g) in a non-interactive manner (print the output to stdout)?  I used a
> similar type of debugging in basica years ago and miss having something
> similar in modern debuggers.
> 
> I want to do something similar to
> 
> gdb -[Some command line argument] a.out
> a.out: main.c:5 main() May  1 16:18:07 CDT 2004
> a.out: main.c:6 main() May  1 16:18:08 CDT 2004
> a.out: main.c:7 main() May  1 16:18:09 CDT 2004
> a.out: main.c:25 print() May  1 16:18:09 CDT 2004
> a.out: main.c:28 print() May  1 16:18:09 CDT 2004
> a.out: source2.c:10 echo() May  1 16:18:10 CDT 2004
> a.out: source2.c:11 echo() May  1 16:18:10 CDT 2004
> a.out: source2.c:11 echo() May  1 16:18:12 CDT 2004
> a.out: main.c:29 print() May  1 16:18:13 CDT 2004
> a.out: main.c:8 main() May  1 16:18:14 CDT 2004
> etc...
> 
> The main reason I want this is to record program flow during real execution
> of the program without having to step through it line by line in the
> debugger. If there is a segfault, it's pretty easy to determine the program
> flow which caused it.  It would also be useful to discover how a large
> program works, and what operations in a program's GUI or command line touch
> which lines of source code. It could also be used for very crude profiling.

I don't think you should be using a debugger to do this.

Have you considered a code coverage tool? 
I think gcov might do what you want.

Bob Rossi


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Non-interactive stepping
  2004-05-02 13:04 ` Bob Rossi
@ 2004-05-02 16:03   ` Kip Macy
  0 siblings, 0 replies; 5+ messages in thread
From: Kip Macy @ 2004-05-02 16:03 UTC (permalink / raw)
  To: Bob Rossi; +Cc: Christopher Nebergall, gdb

That would tell him what lines the program executed, not the order in
which they were executed.


			-Kip



On Sun, 2 May 2004, Bob Rossi wrote:

> On Sat, May 01, 2004 at 03:34:19PM -0600, Christopher Nebergall wrote:
> > Is it possible to use GDB (or another app) to print out the executing source
> > code file name, line number, function name etc, for an application (compiled
> > with -g) in a non-interactive manner (print the output to stdout)?  I used a
> > similar type of debugging in basica years ago and miss having something
> > similar in modern debuggers.
> >
> > I want to do something similar to
> >
> > gdb -[Some command line argument] a.out
> > a.out: main.c:5 main() May  1 16:18:07 CDT 2004
> > a.out: main.c:6 main() May  1 16:18:08 CDT 2004
> > a.out: main.c:7 main() May  1 16:18:09 CDT 2004
> > a.out: main.c:25 print() May  1 16:18:09 CDT 2004
> > a.out: main.c:28 print() May  1 16:18:09 CDT 2004
> > a.out: source2.c:10 echo() May  1 16:18:10 CDT 2004
> > a.out: source2.c:11 echo() May  1 16:18:10 CDT 2004
> > a.out: source2.c:11 echo() May  1 16:18:12 CDT 2004
> > a.out: main.c:29 print() May  1 16:18:13 CDT 2004
> > a.out: main.c:8 main() May  1 16:18:14 CDT 2004
> > etc...
> >
> > The main reason I want this is to record program flow during real execution
> > of the program without having to step through it line by line in the
> > debugger. If there is a segfault, it's pretty easy to determine the program
> > flow which caused it.  It would also be useful to discover how a large
> > program works, and what operations in a program's GUI or command line touch
> > which lines of source code. It could also be used for very crude profiling.
>
> I don't think you should be using a debugger to do this.
>
> Have you considered a code coverage tool?
> I think gcov might do what you want.
>
> Bob Rossi
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Non-interactive stepping
  2004-05-02 21:27 Nick Roberts
@ 2004-05-03  2:54 ` C T Nebergall
  0 siblings, 0 replies; 5+ messages in thread
From: C T Nebergall @ 2004-05-03  2:54 UTC (permalink / raw)
  To: Nick Roberts; +Cc: ct-nebergall, gdb

Thanks! That'll work ok for relatively small programs, so I'll probably
take advantage of it, but I'm still in need of something cleaner for large
programs.  I'm starting to code in Mozilla, a tool like this would be
invaluable for understanding the flow of the code when its running.  I
wouldn't mind hacking GDB to try and get this type of functionality if I
knew where to start.

Thanks,
Christopher


On Sun, 2 May 2004, Nick Roberts wrote:

|> I want to do something similar to
|
|> gdb -[Some command line argument] a.out
|> a.out: main.c:5 main() May  1 16:18:07 CDT 2004
|> a.out: main.c:6 main() May  1 16:18:08 CDT 2004
|> a.out: main.c:7 main() May  1 16:18:09 CDT 2004
|> a.out: main.c:25 print() May  1 16:18:09 CDT 2004
|> a.out: main.c:28 print() May  1 16:18:09 CDT 2004
|> a.out: source2.c:10 echo() May  1 16:18:10 CDT 2004
|> a.out: source2.c:11 echo() May  1 16:18:10 CDT 2004
|> a.out: source2.c:11 echo() May  1 16:18:12 CDT 2004
|> a.out: main.c:29 print() May  1 16:18:13 CDT 2004
|> a.out: main.c:8 main() May  1 16:18:14 CDT 2004
|> etc...
|
|Here's an ugly hack that gives you line information.
|
|Put the following user-defined command in your .gdbinit file:
|
|define mytrace
|  set height 0
|  b main
|  run
|  while 1
|    step
|  end
|end
|
|Run gdb with "gdb -ann=1 myprog" and type "mytrace" at the prompt
|
|to get something like:
|
|(gdb) mytrace
|Breakpoint 1 at 0x804849f: file myprog.c, line 38.
|
|Breakpoint 1, main () at myprog.c:38
|^Z^Z/home/nick/myprog.c:38:389:beg:0x804849f
|^Z^Z/home/nick/myprog.c:44:470:beg:0x80484a6
|^Z^Z/home/nick/myprog.c:49:585:beg:0x80484ec
|^Z^Z/home/nick/myprog.c:50:595:beg:0x80484f5
|^Z^Z/home/nick/myprog.c:51:611:beg:0x804850d
|^Z^Z/home/nick/myprog.c:52:628:beg:0x8048525
|^Z^Z/home/nick/myprog.c:53:637:beg:0x804852c
|...
|
|You might want to re-direct any program output.
|
|Nick
|


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Non-interactive stepping
@ 2004-05-02 21:27 Nick Roberts
  2004-05-03  2:54 ` C T Nebergall
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Roberts @ 2004-05-02 21:27 UTC (permalink / raw)
  To: ct-nebergall; +Cc: gdb

> I want to do something similar to

> gdb -[Some command line argument] a.out
> a.out: main.c:5 main() May  1 16:18:07 CDT 2004
> a.out: main.c:6 main() May  1 16:18:08 CDT 2004
> a.out: main.c:7 main() May  1 16:18:09 CDT 2004
> a.out: main.c:25 print() May  1 16:18:09 CDT 2004
> a.out: main.c:28 print() May  1 16:18:09 CDT 2004
> a.out: source2.c:10 echo() May  1 16:18:10 CDT 2004
> a.out: source2.c:11 echo() May  1 16:18:10 CDT 2004
> a.out: source2.c:11 echo() May  1 16:18:12 CDT 2004
> a.out: main.c:29 print() May  1 16:18:13 CDT 2004
> a.out: main.c:8 main() May  1 16:18:14 CDT 2004
> etc...

Here's an ugly hack that gives you line information.

Put the following user-defined command in your .gdbinit file:

define mytrace
  set height 0
  b main
  run
  while 1
    step
  end
end

Run gdb with "gdb -ann=1 myprog" and type "mytrace" at the prompt

to get something like:

(gdb) mytrace
Breakpoint 1 at 0x804849f: file myprog.c, line 38.

Breakpoint 1, main () at myprog.c:38
^Z^Z/home/nick/myprog.c:38:389:beg:0x804849f
^Z^Z/home/nick/myprog.c:44:470:beg:0x80484a6
^Z^Z/home/nick/myprog.c:49:585:beg:0x80484ec
^Z^Z/home/nick/myprog.c:50:595:beg:0x80484f5
^Z^Z/home/nick/myprog.c:51:611:beg:0x804850d
^Z^Z/home/nick/myprog.c:52:628:beg:0x8048525
^Z^Z/home/nick/myprog.c:53:637:beg:0x804852c
...

You might want to re-direct any program output.

Nick


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-05-03  2:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-01 21:34 Non-interactive stepping Christopher Nebergall
2004-05-02 13:04 ` Bob Rossi
2004-05-02 16:03   ` Kip Macy
2004-05-02 21:27 Nick Roberts
2004-05-03  2:54 ` C T Nebergall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox