
{"id":14252,"date":"2013-09-25T15:17:55","date_gmt":"2013-09-25T15:17:55","guid":{"rendered":"http:\/\/www.beautifulwork.org\/?p=14252"},"modified":"2013-09-25T15:17:55","modified_gmt":"2013-09-25T15:17:55","slug":"binary-tree-debug-ii-insert-function","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2013\/09\/25\/binary-tree-debug-ii-insert-function\/","title":{"rendered":"Binary Tree Debug II ( Insert Function )"},"content":{"rendered":"<h4><u>commandline and also gdb session related<\/u><\/h4>\n<pre style=\"width:50%;border-color:#ffb502;border-radius:3%;\">\n$pwd\n\/home\/jeffrin\n$gdb a.out\nGNU gdb (GDB) 7.4.1-debian\nCopyright (C) 2012 Free Software Foundation, Inc.\nLicense GPLv3+: GNU GPL version 3 or later \nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\nThis GDB was configured as \"x86_64-linux-gnu\".\nFor bug reporting instructions, please see:\n...\nReading symbols from \/home\/jeffrin\/a.out...done.\n(gdb) break 1\nBreakpoint 1 at 0x4005db: file btree-c.c, line 1.\n(gdb) r\nStarting program: \/home\/jeffrin\/a.out\nwarning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000\nwarning: Could not load shared library symbols for linux-vdso.so.1.\nDo you need \"set solib-search-path\" or \"set sysroot\"?\n\nBreakpoint 1, insert (tree=0x7fffffffe830, val=9) at btree-c.c:12\n12\t  node *temp = NULL;\n(gdb) l\n7\t};\n8\ttypedef struct bin_tree node;\n9\n10\tvoid insert(node ** tree, int val)\n11\t{\n12\t  node *temp = NULL;\n13\t  if(!(*tree))\n14\t    {\n15\t      temp = (node *)malloc(sizeof(node));\n16\t      temp-&gt;left = temp-&gt;right = NULL;\n(gdb) watch temp\nHardware watchpoint 2: temp\n(gdb) bt\n#0  insert (tree=0x7fffffffe830, val=9) at btree-c.c:12\n#1  0x0000000000400852 in main () at btree-c.c:103\n(gdb) next\n13\t  if(!(*tree))\n(gdb) print *tree\n$1 = (node *) 0x0\n(gdb) print !(*tree)\n$2 = 1\n(gdb) next\n15\t      temp = (node *)malloc(sizeof(node));\n(gdb) print temp\n$3 = (node *) 0x0\n(gdb) next\nHardware watchpoint 2: temp\n\nOld value = (node *) 0x0\nNew value = (node *) 0x601010\ninsert (tree=0x7fffffffe830, val=9) at btree-c.c:16\n16\t      temp-&gt;left = temp-&gt;right = NULL;\n(gdb) print *temp\n$4 = {data = 0, right = 0x0, left = 0x0}\n(gdb) watch *temp\nHardware watchpoint 3: *temp\n(gdb) bt\n#0  insert (tree=0x7fffffffe830, val=9) at btree-c.c:16\n#1  0x0000000000400852 in main () at btree-c.c:103\n(gdb) l\n11\t{\n12\t  node *temp = NULL;\n13\t  if(!(*tree))\n14\t    {\n15\t      temp = (node *)malloc(sizeof(node));\n16\t      temp-&gt;left = temp-&gt;right = NULL;\n17\t      temp-&gt;data = val;\n18\t      *tree = temp;\n19\t      return;\n20\t    }\n(gdb) next\n17\t      temp-&gt;data = val;\n(gdb) print val\n$5 = 9\n(gdb) next\nHardware watchpoint 3: *temp\n\nOld value = {data = 0, right = 0x0, left = 0x0}\nNew value = {data = 9, right = 0x0, left = 0x0}\ninsert (tree=0x7fffffffe830, val=9) at btree-c.c:18\n18\t      *tree = temp;\n(gdb) next\n19\t      return;\n(gdb) next\n31\t}\n(gdb) next\n\nWatchpoint 2 deleted because the program has left the block in\nwhich its expression is valid.\n\nWatchpoint 3 deleted because the program has left the block in\nwhich its expression is valid.\nmain () at btree-c.c:104\n104\t  insert(&amp;root, 4);\n(gdb) bt\n#0  main () at btree-c.c:104\n(gdb) l\n99\t  \/\/int i;\n100\n101\t  root = NULL;\n102\t  \/* Inserting nodes into tree *\/\n103\t  insert(&amp;root, 9);\n104\t  insert(&amp;root, 4);\n105\t  insert(&amp;root, 15);\n106\t  insert(&amp;root, 6);\n107\t  insert(&amp;root, 12);\n108\t  insert(&amp;root, 17);\n(gdb) next\n\nBreakpoint 1, insert (tree=0x7fffffffe830, val=4) at btree-c.c:12\n12\t  node *temp = NULL;\n(gdb) next\n13\t  if(!(*tree))\n(gdb) print *tree\n$6 = (node *) 0x601010\n(gdb) print !(*tree)\n$7 = 0\n(gdb) l\n8\ttypedef struct bin_tree node;\n9\n10\tvoid insert(node ** tree, int val)\n11\t{\n12\t  node *temp = NULL;\n13\t  if(!(*tree))\n14\t    {\n15\t      temp = (node *)malloc(sizeof(node));\n16\t      temp-&gt;left = temp-&gt;right = NULL;\n17\t      temp-&gt;data = val;\n(gdb) next\n22\t  if(val data)\n(gdb) l\n17\t      temp-&gt;data = val;\n18\t      *tree = temp;\n19\t      return;\n20\t    }\n21\n22\t  if(val data)\n23\t    {\n24\t      insert(&amp;(*tree)-&gt;left, val);\n25\t    }\n26\t  else if(val &gt; (*tree)-&gt;data)\n(gdb) print (*tree)-&gt;data\n$8 = 9\n(gdb) print val\n$9 = 4\n(gdb) next\n24\t      insert(&amp;(*tree)-&gt;left, val);\n(gdb) l\n19\t      return;\n20\t    }\n21\n22\t  if(val data)\n23\t    {\n24\t      insert(&amp;(*tree)-&gt;left, val);\n25\t    }\n26\t  else if(val &gt; (*tree)-&gt;data)\n27\t    {\n28\t      insert(&amp;(*tree)-&gt;right, val);\n(gdb) next\n\nBreakpoint 1, insert (tree=0x601020, val=4) at btree-c.c:12\n12\t  node *temp = NULL;\n(gdb) next\n13\t  if(!(*tree))\n(gdb) next\n15\t      temp = (node *)malloc(sizeof(node));\n(gdb) l\n10\tvoid insert(node ** tree, int val)\n11\t{\n12\t  node *temp = NULL;\n13\t  if(!(*tree))\n14\t    {\n15\t      temp = (node *)malloc(sizeof(node));\n16\t      temp-&gt;left = temp-&gt;right = NULL;\n17\t      temp-&gt;data = val;\n18\t      *tree = temp;\n19\t      return;\n(gdb) next\n16\t      temp-&gt;left = temp-&gt;right = NULL;\n(gdb) next\n17\t      temp-&gt;data = val;\n(gdb) print val\n$10 = 4\n(gdb) next\n18\t      *tree = temp;\n(gdb) print *tree\n$11 = (node *) 0x0\n(gdb) print *temp\n$12 = {data = 4, right = 0x0, left = 0x0}\n(gdb) next\n19\t      return;\n(gdb) bt\n#0  insert (tree=0x601020, val=4) at btree-c.c:19\n#1  0x00000000004001005 in insert (tree=0x7fffffffe830, val=4) at btree-c.c:24\n#2  0x0000000000400863 in main () at btree-c.c:104\n(gdb) next\n31\t}\n(gdb) l\n26\t  else if(val &gt; (*tree)-&gt;data)\n27\t    {\n28\t      insert(&amp;(*tree)-&gt;right, val);\n29\t    }\n30\n31\t}\n32\n33\tvoid print_preorder(node * tree)\n34\t{\n35\t  if (tree)\n(gdb) next\n31\t}\n(gdb) bt\n#0  insert (tree=0x7fffffffe830, val=4) at btree-c.c:31\n#1  0x0000000000400863 in main () at btree-c.c:104\n(gdb) next\nmain () at btree-c.c:105\n105\t  insert(&amp;root, 15);\n(gdb) next\n\nBreakpoint 1, insert (tree=0x7fffffffe830, val=15) at btree-c.c:12\n12\t  node *temp = NULL;\n(gdb) next\n13\t  if(!(*tree))\n(gdb) print!(*tree)\n$13 = 0\n(gdb) next\n22\t  if(val data)\n(gdb) print (*tree)\n$14 = (node *) 0x601010\n(gdb) next\n26\t  else if(val &gt; (*tree)-&gt;data)\n(gdb) next\n28\t      insert(&amp;(*tree)-&gt;right, val);\n(gdb) next\n\nBreakpoint 1, insert (tree=0x601018, val=15) at btree-c.c:12\n12\t  node *temp = NULL;\n(gdb) next\n13\t  if(!(*tree))\n(gdb) next\n15\t      temp = (node *)malloc(sizeof(node));\n(gdb) next\n16\t      temp-&gt;left = temp-&gt;right = NULL;\n(gdb) next\n17\t      temp-&gt;data = val;\n(gdb) print val\n$15 = 15\n(gdb) print temp-data\nNo symbol \"data\" in current context.\n(gdb) print temp-&gt;data\n$16 = 0\n(gdb) print val\n$17 = 15\n(gdb) next\n18\t      *tree = temp;\n(gdb) print temp-&gt;data\n$18 = 15\n(gdb) bt\n#0  insert (tree=0x601018, val=15) at btree-c.c:18\n#1  0x000000000040067d in insert (tree=0x7fffffffe830, val=15) at btree-c.c:28\n#2  0x0000000000400874 in main () at btree-c.c:105\n(gdb) l\n13\t  if(!(*tree))\n14\t    {\n15\t      temp = (node *)malloc(sizeof(node));\n16\t      temp-&gt;left = temp-&gt;right = NULL;\n17\t      temp-&gt;data = val;\n18\t      *tree = temp;\n19\t      return;\n20\t    }\n21\n22\t  if(val data)\n(gdb) l\n23\t    {\n24\t      insert(&amp;(*tree)-&gt;left, val);\n25\t    }\n26\t  else if(val &gt; (*tree)-&gt;data)\n27\t    {\n28\t      insert(&amp;(*tree)-&gt;right, val);\n29\t    }\n30\n31\t}\n32\n(gdb)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;show copying&#8221; and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2013\/09\/25\/binary-tree-debug-ii-insert-function\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Binary Tree Debug II ( Insert Function )&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[474,639,941],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/14252"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=14252"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/14252\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=14252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=14252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=14252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}