GNU grep Debug II

commandline session

$gdb grep
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /home/jeffrin/GNUgrep/grep-2.0/grep...done.
(gdb) break 598
Breakpoint 1 at 0x401f99: file grep.c, line 598.
(gdb) r errno grep.c
Starting program: /home/jeffrin/GNUgrep/grep-2.0/grep errno grep.c
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?

Breakpoint 1, main (argc=3, argv=0x7fffffffe8d8) at grep.c:600
600	{
(gdb) l
595
596	int
597	main(argc, argv)
598	     int argc;
599	     char *argv[];
600	{
601	  char *keys;
602	  size_t keycc, oldcc, keyalloc;
603	  int keyfound, count_matches, no_filenames, list_files, suppress_errors;
604	  int opt, cc, desc, count, status;
(gdb) next
609	  prog = argv[0];
(gdb) print argc
$1 = 3
(gdb) print argv
$2 = (char **) 0x7fffffffe8d8
(gdb) print *argv
$3 = 0x7fffffffeb6a "/home/jeffrin/GNUgrep/grep-2.0/grep"
(gdb) print **argv
$4 = 47 '/'
(gdb) l
604	  int opt, cc, desc, count, status;
605	  FILE *fp;
606	  extern char *optarg;
607	  extern int optind;
608
609	  prog = argv[0];
610	  if (prog && strrchr(prog, '/'))
611	    prog = strrchr(prog, '/') + 1;
612
613	  keys = NULL;
(gdb) next
610	  if (prog && strrchr(prog, '/'))
(gdb) print prog
$5 = 0x7fffffffeb6a "/home/jeffrin/GNUgrep/grep-2.0/grep"
(gdb) bt
#0  main (argc=3, argv=0x7fffffffe8d8) at grep.c:610
(gdb) bt full
#0  main (argc=3, argv=0x7fffffffe8d8) at grep.c:610
        keys = 
        keycc = 
        oldcc = 
        keyalloc = 
        keyfound = 
        count_matches = 
        no_filenames = 
        list_files = 
        suppress_errors = 
        opt = 
        cc = 
        desc = 
        count = 
        status = 
        fp = 
(gdb) next
611	    prog = strrchr(prog, '/') + 1;
(gdb) print prog
$6 = 0x7fffffffeb6a "/home/jeffrin/GNUgrep/grep-2.0/grep"
(gdb) call strchr(prog,'/')
$7 = -5270
(gdb) next
620	  matcher = NULL;
(gdb) print prog
$8 = 0x7fffffffeb89 "grep"
(gdb) info locals
keys = 0x0
keycc = 0
oldcc = 
keyalloc = 
keyfound = 0
count_matches = 0
no_filenames = 0
list_files = 0
suppress_errors = 0
opt = 
cc = 
desc = 
count = 
status = 
fp = 
(gdb) bt
#0  main (argc=3, argv=0x7fffffffe8d8) at grep.c:620
(gdb) next
619	  suppress_errors = 0;
(gdb) next
618	  list_files = 0;
(gdb) next
617	  no_filenames = 0;
(gdb) next
616	  count_matches = 0;
(gdb) next
615	  keyfound = 0;
(gdb) next
614	  keycc = 0;
(gdb) next
613	  keys = NULL;
(gdb) next
622	  while ((opt = getopt(argc, argv, "0123456789A:B:CEFGVX:bce:f:hiLlnqsvwxy"))
(gdb) print opt
$9 = 
(gdb) next
755	  if (!keyfound)
(gdb) print opt
$10 = -1
(gdb)