Binary Tree Debug (pre-order)

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 34
Breakpoint 1 at 0x40068b: file btree-c.c, line 34.
(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"?
Pre Order Display

Breakpoint 1, print_preorder (tree=0x601010) at btree-c.c:35
35	  if (tree)
(gdb) print *tree
$1 = {data = 9, right = 0x601050, left = 0x601030}
(gdb) print *(tree->right)
$2 = {data = 15, right = 0x6010b0, left = 0x601090}
(gdb) print *tree
$3 = {data = 9, right = 0x601050, left = 0x601030}
(gdb) print *(tree->left)
$4 = {data = 4, right = 0x601070, left = 0x6010d0}
(gdb) next
37	      printf("%dn",tree->data);
(gdb) next
9
38	      print_preorder(tree->left);
(gdb) next

Breakpoint 1, print_preorder (tree=0x601030) at btree-c.c:35
35	  if (tree)
(gdb) print tree
$5 = (node *) 0x601030
(gdb) print *tree
$6 = {data = 4, right = 0x601070, left = 0x6010d0}
(gdb) next
37	      printf("%dn",tree->data);
(gdb) next
4
38	      print_preorder(tree->left);
(gdb) next

Breakpoint 1, print_preorder (tree=0x6010d0) at btree-c.c:35
35	  if (tree)
(gdb) next
37	      printf("%dn",tree->data);
(gdb) next
2
38	      print_preorder(tree->left);
(gdb) next

Breakpoint 1, print_preorder (tree=0x0) at btree-c.c:35
35	  if (tree)
(gdb) print tree-left
No symbol "left" in current context.
(gdb) print tree->left
Cannot access memory at address 0x10
(gdb) next
42	}
(gdb) next
print_preorder (tree=0x6010d0) at btree-c.c:39
39	      print_preorder(tree->right);
(gdb) print tree->left
$7 = (struct bin_tree *) 0x0
(gdb) next

Breakpoint 1, print_preorder (tree=0x0) at btree-c.c:35
35	  if (tree)
(gdb) next
42	}
(gdb) next
print_preorder (tree=0x601030) at btree-c.c:39
39	      print_preorder(tree->right);
(gdb) next

Breakpoint 1, print_preorder (tree=0x601070) at btree-c.c:35
35	  if (tree)
(gdb) print tree->right
$8 = (struct bin_tree *) 0x0
(gdb) next
37	      printf("%dn",tree->data);
(gdb) next
6
38	      print_preorder(tree->left);
(gdb) next

Breakpoint 1, print_preorder (tree=0x0) at btree-c.c:35
35	  if (tree)
(gdb) bt
#0  print_preorder (tree=0x0) at btree-c.c:35
#1  0x00000000004006b9 in print_preorder (tree=0x601070) at btree-c.c:38
#2  0x00000000004006c9 in print_preorder (tree=0x601030) at btree-c.c:39
#3  0x00000000004006b9 in print_preorder (tree=0x601010) at btree-c.c:38
#4  0x00000000004008ce in main () at btree-c.c:113
(gdb)