Tag Archive: gdb

GNU grep Debug

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 1
Breakpoint 1 at 0x401595: file grep.c, line 1.
(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"?
#include 
#ifndef errno
extern int errno;
		  strerror(errno));
    error("writing output", errno);
	  error(filename, errno);
	  fatal(optarg, errno);
	      error(argv[optind], errno);
[Inferior 1 (process 29324) exited normally]
(gdb) start
Temporary breakpoint 2 at 0x401f99: file grep.c, line 600.
Starting program: /home/jeffrin/GNUgrep/grep-2.0/grep errno  grep.c
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?

Temporary breakpoint 2, main (argc=3, argv=0x7fffffffe8d8) at grep.c:600
600	{
(gdb) bt
#0  main (argc=3, argv=0x7fffffffe8d8) at grep.c:600
(gdb) break 1
Note: breakpoint 1 also set at pc 0x401595.
Breakpoint 3 at 0x401595: file grep.c, line 1.
(gdb) start
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Temporary breakpoint 4 at 0x401f99: file grep.c, line 600.
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"?

Temporary breakpoint 4, 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) call memchar
No symbol "memchar" in current context.
(gdb) next
609	  prog = argv[0];
(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) bt
#0  main (argc=3, argv=0x7fffffffe8d8) at grep.c:609
(gdb) break 82
Note: breakpoints 1 and 3 also set at pc 0x401595.
Breakpoint 5 at 0x401595: file grep.c, line 82.
(gdb) continue
Continuing.
#include 
#ifndef errno
extern int errno;
		  strerror(errno));
    error("writing output", errno);
	  error(filename, errno);
	  fatal(optarg, errno);
	      error(argv[optind], errno);
[Inferior 1 (process 30092) exited normally]
(gdb)

Binary Tree Debug

commandline session

$gdb a.out
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/a.out...done.
(gdb) break 1
Breakpoint 1 at 0x4005db: file btree-c.c, line 1.
(gdb) l
92	    }
93	}
94
95	void main()
96	{
97	  node *root;
98	  node *tmp;
99	  //int i;
100
101	  root = NULL;
(gdb) r
Starting program: /home/jeffrin/a.out
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, insert (tree=0x7fffffffe830, val=9) at btree-c.c:12
12	  node *temp = NULL;
(gdb) next
13	  if(!(*tree))
(gdb) next
15	      temp = (node *)malloc(sizeof(node));
(gdb) l
10	void insert(node ** tree, int val)
11	{
12	  node *temp = NULL;
13	  if(!(*tree))
14	    {
15	      temp = (node *)malloc(sizeof(node));
16	      temp->left = temp->right = NULL;
17	      temp->data = val;
18	      *tree = temp;
19	      return;
(gdb) next
16	      temp->left = temp->right = NULL;
(gdb) print temp
$1 = (node *) 0x601010
(gdb) print temp-left
No symbol "left" in current context.
(gdb) print temp->left
$2 = (struct bin_tree *) 0x0
(gdb) print temp->left
$3 = (struct bin_tree *) 0x0
(gdb) pwd
Working directory /home/jeffrin.
(gdb) ls
Undefined command: "ls".  Try "help".
(gdb) break 1
Note: breakpoint 1 also set at pc 0x4005db.
Breakpoint 2 at 0x4005db: file btree-c.c, line 1.
(gdb) watch *temp
Hardware watchpoint 3: *temp
(gdb) start
The program being debugged has been started already.
Start it from the beginning? (y or n) y

Temporary breakpoint 4 at 0x400839: file btree-c.c, line 101.
Starting program: /home/jeffrin/a.out
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"?

Temporary breakpoint 4, main () at btree-c.c:101
101	  root = NULL;
(gdb) info watchpoints
No watchpoints.
(gdb) info watchpoint
No watchpoints.
(gdb) watch *temp
No symbol "temp" in current context.
(gdb) watch root
Hardware watchpoint 5: root
(gdb) info watchpoints
Num     Type           Disp Enb Address            What
5       hw watchpoint  keep y                      root
(gdb) next
Hardware watchpoint 5: root

Old value = (node *) 0x7fffffffe920
New value = (node *) 0x0
main () at btree-c.c:103
103	  insert(&root, 9);
(gdb) next

Breakpoint 1, insert (tree=0x7fffffffe830, val=9) at btree-c.c:12
12	  node *temp = NULL;
(gdb) next
13	  if(!(*tree))
(gdb) print !(*tree)
$4 = 1
(gdb) next
15	      temp = (node *)malloc(sizeof(node));
(gdb) print temp
$5 = (node *) 0x0
(gdb) next
16	      temp->left = temp->right = NULL;
(gdb) print temp
$6 = (node *) 0x601010
(gdb) print temp->left
$7 = (struct bin_tree *) 0x0
(gdb) next
17	      temp->data = val;
(gdb) print temp->left
$8 = (struct bin_tree *) 0x0
(gdb) print temp->left
$9 = (struct bin_tree *) 0x0
(gdb) next
18	      *tree = temp;
(gdb) print temp->left
$10 = (struct bin_tree *) 0x0
(gdb) print *tree
$11 = (node *) 0x0
(gdb) next
Hardware watchpoint 5: root

Old value = (node *) 0x0
New value = (node *) 0x601010
insert (tree=0x7fffffffe830, val=9) at btree-c.c:19
19	      return;
(gdb) next
31	}
(gdb) print *tree
$12 = (node *) 0x601010
(gdb) info watchpoints
Num     Type           Disp Enb Address            What
5       hw watchpoint  keep y                      root
	breakpoint already hit 2 times
(gdb)

Loading...
X
Copyright © 2009,  2010,  2011,  2012,  2013,  2014     BeautifulWork Project    e-mail:  ahiliation@yahoo.co.in
BeautifulWork Project comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.