Automatic export of symbols array in C debugging (teaching purpose)
I need to teach C to children (10-15 years old, teaching is through a website) and I want to be able to show them a step by step execution of a program but I don't want them to use a debugger directly (too complex for them, they are total beginners).
My idea was to pre-compute all the needed data and to show it to them (with a cool javascript animation, with the current line in the code, the values of the variables and the standard output).
What I need is a way to run a debugger on a C code and to export the values of the variables at each possible step (no struct, just basic variables and arrays).
Is there any interface to gdb or some other debugger that can to that ?
For some context : we are training st开发者_运维百科udents for the IOI (International Olympiad in Informatics) though a website with courses, exercices (automatically corrected)... The code (in C) can be edited , compiled, tested and submitted online (with a javascript editor). This way no need to install anything (at first) so more people can just "try it".
The basic "step by step" debugging was only to show the beginners how variables are modified, how a "for" or a "while" are working. The kind of stuff you can do on a whiteboard as a teacher. More advanced students will install some IDE and will/or not use the debugger.
So for the beginners we want them to be able to play, on the website, with some basic code (affectations, maths operations, function call,for,while,if) to "see things".
If you're limited to programs with specific input, or without input at all, you can maybe use gdb scripting, in something like this:
try.c (the input program):
#include <stdio.h>
int main()
{
int i;
for (i = 0; i < 10; i++)
{
printf("the number now is %d\n", i);
i++;
}
return 0;
}
trace.gdb (a basic gdb script):
break main
run
while 1
info locals
step
end
quit
the results of gdb -x trace.gdb -batch try
Breakpoint 1 at 0x40053c: file try.c, line 6.
Breakpoint 1, main () at try.c:6
6 for (i = 0; i < 10; i++)
i = 0
8 printf("the number now is %d\n", i);
i = 0
the number now is 0
9 i++;
i = 0
6 for (i = 0; i < 10; i++)
i = 1
8 printf("the number now is %d\n", i);
i = 2
the number now is 2
9 i++;
i = 2
6 for (i = 0; i < 10; i++)
i = 3
8 printf("the number now is %d\n", i);
i = 4
the number now is 4
9 i++;
i = 4
6 for (i = 0; i < 10; i++)
i = 5
8 printf("the number now is %d\n", i);
i = 6
the number now is 6
9 i++;
i = 6
6 for (i = 0; i < 10; i++)
i = 7
8 printf("the number now is %d\n", i);
i = 8
the number now is 8
9 i++;
i = 8
6 for (i = 0; i < 10; i++)
i = 9
11 return 0;
i = 10
12 }
i = 10
0x000000300161ebbd in __libc_start_main () from /lib/libc.so.6
No symbol table info available.
Single stepping until exit from function __libc_start_main,
which has no line number information.
Program exited normally.
trace.gdb:6: Error in sourced command file:
No frame selected.
There are ways to change gdb's output so you can perhaps tune the script to make the output parsable in a way that will allow you to make it something playable by javascript.
And you'll also need to make sure the program does not loop endlessly, probably by using convenience variables to limit number of while loops in the script.
精彩评论