Noeud:One Step at a Time - Step+Next, Noeud « Next »:, Noeud « Previous »:Taking Control of the Running Program - Breakpoints, Noeud « Up »:An example debugging session using gdb



One Step at a Time - Step+Next

What we need to do now is run the program a line at a time and see if we can spot the problem that is causing us to get a Usage: message even when the arguments are correct.

Let's look at the program again. We'll use the gdb list command to examine the code.

     (gdb) list
     8
     9	#include <stdio.h>
     10
     11	int main( int argc, char *argv[] )
     12	{
     13	  char *buf=NULL;
     14	  int count, i;
     15
     16	  /* check we have a parameter */
     17
     18	  if( argc = 1 )
     

gdb is sat at line 13, where NULL is assigned to buf. There are two commands which will cause us to move one line forward in the file, step and next.

step will always go to the next line to be executed, following function calls if there are any on the line. next will run until the next line which executes without following function calls. A large amount of your program can be run between two next commands, whereas only one line of code can run between step commands.

Since we have no functions to go into, we'll generally use step.

     (gdb) next
     18	  if( argc = 1 )
     (gdb)
     

We are now on line 18. Why didn't it run to line 14? That's because there are only variable declarations on that line, so no code was actually executed for that line. All it does is tell the compiler those variables exist.