tags:

views:

168

answers:

5

Is there a way to view C code "live", by displaying the current current line, as it is being executed?

You can pretty close by using GDB, but I'm wondering if there is something slightly more elegant than holding the return key down:

$ gdb ./mycode
(gdb) break 1
Breakpoint 1 at 0x100000f08: file mycode.c, line 1.
(gdb) run
Starting program: mycode 

Breakpoint 1, main () at mycode.c:4
4        for(x = 0; x < 4; x++){
(gdb) next
5            printf("Example\n");
(gdb) [press return]
Example
4        for(x = 0; x < 4; x++){
(gdb) [press return]

Performance isn't an issue (obviously it will be slowed down a lot by all the printf()'ing, which is fine). Ideally the solution would be a command line tool (alternatively a OS X compatible GUI application)

Perhaps the usage would be along the lines of..

$ viewlivec --delay 500 -- ./mycode -mycodes=arg --verbose
01: int main(){
02: int x;
03: for(x = 0; x < 4; x++){
04: printf("Example\n");
05: }
03: for(x = 0; x < 4; x++){
04: printf("Example\n");
05: }
03: for(x = 0; x < 4; x++){
04: printf("Example\n");
05: }
03: for(x = 0; x < 4; x++){
04: printf("Example\n");
05: }
06: }

The --delay flag would wait 0.5 seconds between each line

(This may have been asked previously, but I wasn't really sure what to search for, thus couldn't find anything)

A: 

I've never seen or heard of such a tool, however I suspect that since GDB is so embeddable, it must have a decent API that you could probably use to make this app (and if you do, I want a copy!).

dicroce
+1  A: 

I'm not aware of any tool for this either, but if you were going to write this yourself, you might want to look into modifying/creating a hook for a code coverage utility. For instance, gcov or lcov both count the number of times a line is executed, so certainly you could modify the source to print out that line and sleep instead of just incrementing a counter.

Mark Rushakoff
+2  A: 

Probably not perfect, but you can go to TUI (text user interface) mode by pressing the 'c-x a' and change to single key mode by 'c-x s'. In single key mode press the 'n' for the next command.

See the gdb manual for more information: http://sources.redhat.com/gdb/onlinedocs/gdb_23.html

Vereb
+1  A: 

Given NormD's comment to this answer, I wonder whether a feature like that might be a feature of Codewarrior or Chameleon.

ChrisW
+1 for sense of humour...
Vargas
+2  A: 

You want DDD, which is a gui for GDB. Also: WinDBG is good if you're running Windows.

Pod
+1: a very useful tool.
Atmocreations