Binary Tree Debug II ( Insert Function )

commandline and also gdb session related

$pwd
/home/jeffrin
$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) 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) l
7	};
8	typedef struct bin_tree node;
9
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;
(gdb) watch temp
Hardware watchpoint 2: temp
(gdb) bt
#0  insert (tree=0x7fffffffe830, val=9) at btree-c.c:12
#1  0x0000000000400852 in main () at btree-c.c:103
(gdb) next
13	  if(!(*tree))
(gdb) print *tree
$1 = (node *) 0x0
(gdb) print !(*tree)
$2 = 1
(gdb) next
15	      temp = (node *)malloc(sizeof(node));
(gdb) print temp
$3 = (node *) 0x0
(gdb) next
Hardware watchpoint 2: temp

Old value = (node *) 0x0
New value = (node *) 0x601010
insert (tree=0x7fffffffe830, val=9) at btree-c.c:16
16	      temp->left = temp->right = NULL;
(gdb) print *temp
$4 = {data = 0, right = 0x0, left = 0x0}
(gdb) watch *temp
Hardware watchpoint 3: *temp
(gdb) bt
#0  insert (tree=0x7fffffffe830, val=9) at btree-c.c:16
#1  0x0000000000400852 in main () at btree-c.c:103
(gdb) l
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;
20	    }
(gdb) next
17	      temp->data = val;
(gdb) print val
$5 = 9
(gdb) next
Hardware watchpoint 3: *temp

Old value = {data = 0, right = 0x0, left = 0x0}
New value = {data = 9, right = 0x0, left = 0x0}
insert (tree=0x7fffffffe830, val=9) at btree-c.c:18
18	      *tree = temp;
(gdb) next
19	      return;
(gdb) next
31	}
(gdb) next

Watchpoint 2 deleted because the program has left the block in
which its expression is valid.

Watchpoint 3 deleted because the program has left the block in
which its expression is valid.
main () at btree-c.c:104
104	  insert(&root, 4);
(gdb) bt
#0  main () at btree-c.c:104
(gdb) l
99	  //int i;
100
101	  root = NULL;
102	  /* Inserting nodes into tree */
103	  insert(&root, 9);
104	  insert(&root, 4);
105	  insert(&root, 15);
106	  insert(&root, 6);
107	  insert(&root, 12);
108	  insert(&root, 17);
(gdb) next

Breakpoint 1, insert (tree=0x7fffffffe830, val=4) at btree-c.c:12
12	  node *temp = NULL;
(gdb) next
13	  if(!(*tree))
(gdb) print *tree
$6 = (node *) 0x601010
(gdb) print !(*tree)
$7 = 0
(gdb) l
8	typedef struct bin_tree node;
9
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;
(gdb) next
22	  if(val data)
(gdb) l
17	      temp->data = val;
18	      *tree = temp;
19	      return;
20	    }
21
22	  if(val data)
23	    {
24	      insert(&(*tree)->left, val);
25	    }
26	  else if(val > (*tree)->data)
(gdb) print (*tree)->data
$8 = 9
(gdb) print val
$9 = 4
(gdb) next
24	      insert(&(*tree)->left, val);
(gdb) l
19	      return;
20	    }
21
22	  if(val data)
23	    {
24	      insert(&(*tree)->left, val);
25	    }
26	  else if(val > (*tree)->data)
27	    {
28	      insert(&(*tree)->right, val);
(gdb) next

Breakpoint 1, insert (tree=0x601020, val=4) 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) next
17	      temp->data = val;
(gdb) print val
$10 = 4
(gdb) next
18	      *tree = temp;
(gdb) print *tree
$11 = (node *) 0x0
(gdb) print *temp
$12 = {data = 4, right = 0x0, left = 0x0}
(gdb) next
19	      return;
(gdb) bt
#0  insert (tree=0x601020, val=4) at btree-c.c:19
#1  0x00000000004001005 in insert (tree=0x7fffffffe830, val=4) at btree-c.c:24
#2  0x0000000000400863 in main () at btree-c.c:104
(gdb) next
31	}
(gdb) l
26	  else if(val > (*tree)->data)
27	    {
28	      insert(&(*tree)->right, val);
29	    }
30
31	}
32
33	void print_preorder(node * tree)
34	{
35	  if (tree)
(gdb) next
31	}
(gdb) bt
#0  insert (tree=0x7fffffffe830, val=4) at btree-c.c:31
#1  0x0000000000400863 in main () at btree-c.c:104
(gdb) next
main () at btree-c.c:105
105	  insert(&root, 15);
(gdb) next

Breakpoint 1, insert (tree=0x7fffffffe830, val=15) at btree-c.c:12
12	  node *temp = NULL;
(gdb) next
13	  if(!(*tree))
(gdb) print!(*tree)
$13 = 0
(gdb) next
22	  if(val data)
(gdb) print (*tree)
$14 = (node *) 0x601010
(gdb) next
26	  else if(val > (*tree)->data)
(gdb) next
28	      insert(&(*tree)->right, val);
(gdb) next

Breakpoint 1, insert (tree=0x601018, val=15) at btree-c.c:12
12	  node *temp = NULL;
(gdb) next
13	  if(!(*tree))
(gdb) next
15	      temp = (node *)malloc(sizeof(node));
(gdb) next
16	      temp->left = temp->right = NULL;
(gdb) next
17	      temp->data = val;
(gdb) print val
$15 = 15
(gdb) print temp-data
No symbol "data" in current context.
(gdb) print temp->data
$16 = 0
(gdb) print val
$17 = 15
(gdb) next
18	      *tree = temp;
(gdb) print temp->data
$18 = 15
(gdb) bt
#0  insert (tree=0x601018, val=15) at btree-c.c:18
#1  0x000000000040067d in insert (tree=0x7fffffffe830, val=15) at btree-c.c:28
#2  0x0000000000400874 in main () at btree-c.c:105
(gdb) l
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;
20	    }
21
22	  if(val data)
(gdb) l
23	    {
24	      insert(&(*tree)->left, val);
25	    }
26	  else if(val > (*tree)->data)
27	    {
28	      insert(&(*tree)->right, val);
29	    }
30
31	}
32
(gdb)