Show current line of executable C code

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

You can use GDB quite closely, but I'm wondering if there is something a little more elegant than holding the return key:

$ 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 is not an issue (it will obviously slow down a lot by everyone printf()

'ing, which is good). Ideally the solution would be a command line tool (alternatively, OS X compatible).

Perhaps the use will be carried out line by line ..

$ 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 flag --delay

will wait 0.5 seconds between each line

(This may have been asked before, but I wasn't sure what to look for, so I couldn't find anything)

+2


source to share


5 answers


Probably not ideal, but you can go into TUI (Text User Interface) mode by pressing 'cx a' and go into single key mode 'cx s' . In single key mode, press 'n' for next command.



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

+2


source


You want DDD , which is the gui for GDB. Also: WinDBG is good if you are using Windows.



+2


source


I don't know of any tool for doing this either, but if you're going to write this yourself, you might need to modify / create a hook for the code coverage utility. For example, gcov or lcov both count the number of times a line is executed, so of course you can change the source to print that line and hibernate rather than just increment the counter.

+1


source


Given NormD's comment on this answer , I'm wondering if such a function could be a Codewarrior or Chameleon function.

+1


source


I have never seen or heard of such a tool, however I suspect that since GDB is so embedded it should have a decent API that you could probably use to build this application (and if so, I want a copy! ).

0


source







All Articles