[youtube https://www.youtube.com/watch?v=yVpbFMhOAwE?rel=0&w=560&h=315]
htop process monitor
[youtube https://www.youtube.com/watch?v=Dbop7NX3ki4?rel=0&w=560&h=315]
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)
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)
ls -X sort alphabetically by entry extension
commandline session
$ls -lX total 1144 -rwxr-xr-x 1 jeffrin jeffrin 115430 Sep 28 01:11 bwt -rwxr-xr-x 1 jeffrin jeffrin 129354 Sep 28 01:11 ds -rw-r--r-- 1 jeffrin jeffrin 1063 May 18 19:23 Makefile -rw------- 1 jeffrin jeffrin 3793 Dec 13 2005 README -rwxr-xr-x 1 jeffrin jeffrin 141313 Sep 28 01:11 testlcp drwxr-xr-x 2 jeffrin jeffrin 4096 Sep 28 02:19 tests -rw-r--r-- 1 jeffrin jeffrin 32 Sep 28 19:32 text -rwxr-xr-x 1 jeffrin jeffrin 21008 Sep 28 01:11 unbwt -rw-r--r-- 1 jeffrin jeffrin 23164 Sep 28 01:11 bwtlcp.a -rw-r--r-- 1 jeffrin jeffrin 166190 Sep 28 01:11 ds_ssort.a -rw-r--r-- 1 jeffrin jeffrin 0 Oct 1 02:00 text.bwt -rw-r--r-- 1 jeffrin jeffrin 12024 May 18 19:08 blind2.c -rw-r--r-- 1 jeffrin jeffrin 9373 Nov 16 2006 bwt_aux.c -rw-r--r-- 1 jeffrin jeffrin 7068 Nov 16 2006 bwt.c -rw-r--r-- 1 jeffrin jeffrin 10074 May 18 19:07 deep2.c -rw-r--r-- 1 jeffrin jeffrin 9245 Nov 16 2006 ds.c -rw-r--r-- 1 jeffrin jeffrin 3804 Nov 16 2006 globals.c -rw-r--r-- 1 jeffrin jeffrin 20961 Nov 16 2006 helped.c -rw-r--r-- 1 jeffrin jeffrin 9930 Nov 16 2006 lcp_aux.c -rw-r--r-- 1 jeffrin jeffrin 17108 May 18 19:05 shallow.c -rw-r--r-- 1 jeffrin jeffrin 14561 Nov 16 2006 suftest2.c -rw-r--r-- 1 jeffrin jeffrin 9432 Nov 16 2006 testlcp.c -rw-r--r-- 1 jeffrin jeffrin 8673 Nov 16 2006 unbwt.c -rw-r--r-- 1 jeffrin jeffrin 912 Nov 16 2006 bwt_aux.h -rw-r--r-- 1 jeffrin jeffrin 1427 May 18 19:19 common.h -rw-r--r-- 1 jeffrin jeffrin 285 Nov 16 2006 ds_ssort.h -rw-r--r-- 1 jeffrin jeffrin 512 Nov 16 2006 lcp_aux.h -rw-r--r-- 1 jeffrin jeffrin 39648 Sep 28 01:11 blind2.o -rw-r--r-- 1 jeffrin jeffrin 11864 Sep 28 01:11 bwt_aux.o -rw-r--r-- 1 jeffrin jeffrin 15968 Sep 28 01:11 deep2.o -rw-r--r-- 1 jeffrin jeffrin 13648 Sep 28 01:11 ds.o -rw-r--r-- 1 jeffrin jeffrin 8944 Sep 28 01:11 globals.o -rw-r--r-- 1 jeffrin jeffrin 32248 Sep 28 01:11 helped.o -rw-r--r-- 1 jeffrin jeffrin 10832 Sep 28 01:11 lcp_aux.o -rw-r--r-- 1 jeffrin jeffrin 54088 Sep 28 01:11 shallow.o -rw-r--r-- 1 jeffrin jeffrin 41916 Sep 28 01:11 suftest2.o -rw-r--r-- 1 jeffrin jeffrin 49195 Jan 18 2011 ds.tgz -rw-r----- 1 jeffrin jeffrin 17992 Mar 22 2002 COPYRIGHT.GPL.txt -rw-r--r-- 1 jeffrin jeffrin 25385 Dec 16 2005 COPYRIGHT.MPL.txt $
Burrows–Wheeler Transform . 1994
commandline session
$cat hello Hello. How are you $../bwt hello $ls hello hello~ hello.bwt $rm hello~ $ls hello hello.bwt $cat hello.bwt u.weo rHellyHaoo $ $hexdump hello.bwt 0000000 750a 772e 6f100 200a 4872 6c100 796c 6148 0000010 6f6f 0520 0000 0000 0000017 $../unbwt hello.bwt $ls hello hello.bwt hello.bwt.y $cat hello.bwt.y Hello. How are you $
Binary Tree Debug (Pre-order Related)
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 111
Breakpoint 1 at 0x4008b8: file btree-c.c, line 111.
(gdb) break 34
Breakpoint 2 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"?
Breakpoint 1, main () at btree-c.c:112
112 printf("Pre Order Displayn");
(gdb) next
Pre Order Display
113 print_preorder(root);
(gdb) next
Breakpoint 2, print_preorder (tree=0x601010) at btree-c.c:35
35 if (tree)
(gdb) bt
#0 print_preorder (tree=0x601010) at btree-c.c:35
#1 0x00000000004008ce in main () at btree-c.c:113
(gdb) print tree
$1 = (node *) 0x601010
(gdb) print *tree
$2 = {data = 9, right = 0x601050, left = 0x601030}
(gdb) next
37 printf("%dn",tree->data);
(gdb) next
9
38 print_preorder(tree->left);
(gdb) print tree-left
No symbol "left" in current context.
(gdb) print tree->left
$3 = (struct bin_tree *) 0x601030
(gdb) print *(tree->left)
$4 = {data = 4, right = 0x601070, left = 0x6010d0}
(gdb) next
Breakpoint 2, print_preorder (tree=0x601030) at btree-c.c:35
35 if (tree)
(gdb) print tree
$5 = (node *) 0x601030
(gdb) next
37 printf("%dn",tree->data);
(gdb) next
4
38 print_preorder(tree->left);
(gdb) next
Breakpoint 2, 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) print tree->left
$6 = (struct bin_tree *) 0x0
(gdb) print *(tree->left)
Cannot access memory at address 0x0
(gdb) next
Breakpoint 2, print_preorder (tree=0x0) at btree-c.c:35
35 if (tree)
(gdb) next
42 }
(gdb) next
print_preorder (tree=0x6010d0) at btree-c.c:39
39 print_preorder(tree->right);
(gdb) print tree->data
$7 = 2
(gdb) next
Breakpoint 2, 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) print tree->right
$8 = (struct bin_tree *) 0x601070
(gdb) next
Breakpoint 2, print_preorder (tree=0x601070) at btree-c.c:35
35 if (tree)
(gdb) next
37 printf("%dn",tree->data);
(gdb) next
6
38 print_preorder(tree->left);
(gdb) print tree->left
$9 = (struct bin_tree *) 0x0
(gdb) next
Breakpoint 2, print_preorder (tree=0x0) at btree-c.c:35
35 if (tree)
(gdb) next
42 }
(gdb) next
print_preorder (tree=0x601070) at btree-c.c:39
39 print_preorder(tree->right);
(gdb) next
Breakpoint 2, print_preorder (tree=0x0) at btree-c.c:35
35 if (tree)
(gdb) next
42 }
(gdb) next
print_preorder (tree=0x601010) at btree-c.c:39
39 print_preorder(tree->right);
(gdb) next
Breakpoint 2, print_preorder (tree=0x601050) at btree-c.c:35
35 if (tree)
(gdb) next
37 printf("%dn",tree->data);
(gdb) next
15
38 print_preorder(tree->left);
(gdb) print tree->left
$10 = (struct bin_tree *) 0x601090
(gdb) next
Breakpoint 2, print_preorder (tree=0x601090) at btree-c.c:35
35 if (tree)
(gdb) next
37 printf("%dn",tree->data);
(gdb) print *(tree->left)
Cannot access memory at address 0x0
(gdb) print *(tree->right)
Cannot access memory at address 0x0
(gdb) next
12
38 print_preorder(tree->left);
(gdb) print *(tree->left)
Cannot access memory at address 0x0
(gdb) next
Breakpoint 2, print_preorder (tree=0x0) at btree-c.c:35
35 if (tree)
(gdb) next
42 }
(gdb) next
print_preorder (tree=0x601090) at btree-c.c:39
39 print_preorder(tree->right);
(gdb) print *(tree->right)
Cannot access memory at address 0x0
(gdb) next
Breakpoint 2, print_preorder (tree=0x0) at btree-c.c:35
35 if (tree)
(gdb) next
42 }
(gdb) next
print_preorder (tree=0x601050) at btree-c.c:39
39 print_preorder(tree->right);
(gdb) print *(tree->right)
$11 = {data = 17, right = 0x0, left = 0x0}
(gdb) next
Breakpoint 2, print_preorder (tree=0x6010b0) at btree-c.c:35
35 if (tree)
(gdb) next
37 printf("%dn",tree->data);
(gdb) next
17
38 print_preorder(tree->left);
(gdb) print *(tree->left)
Cannot access memory at address 0x0
(gdb) next
Breakpoint 2, print_preorder (tree=0x0) at btree-c.c:35
35 if (tree)
(gdb) next
42 }
(gdb) next
print_preorder (tree=0x6010b0) at btree-c.c:39
39 print_preorder(tree->right);
(gdb) next
Breakpoint 2, print_preorder (tree=0x0) at btree-c.c:35
35 if (tree)
(gdb) next
42 }
(gdb) next
main () at btree-c.c:115
115 printf("In Order Displayn");
(gdb)
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)
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)
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)