Last active
February 3, 2016 15:35
-
-
Save KevinKu/deda38da030e174e0afa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xu6wu6gj@kmtath:~/2016-winter-course/test1$ gdb swap | |
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1 | |
Copyright (C) 2014 Free Software Foundation, Inc. | |
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> | |
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". | |
Type "show configuration" for configuration details. | |
For bug reporting instructions, please see: | |
<http://www.gnu.org/software/gdb/bugs/>. | |
Find the GDB manual and other documentation resources online at: | |
<http://www.gnu.org/software/gdb/documentation/>. | |
For help, type "help". | |
Type "apropos word" to search for commands related to "word"... | |
Reading symbols from swap...done. | |
(gdb) l | |
126 | |
127 | |
128 | |
129 return head; | |
130 | |
131 | |
132 | |
133 } | |
134 | |
135 int main(){return 0;} | |
(gdb) b 135 | |
Breakpoint 1 at 0x40072a: file swap.c, line 135. | |
(gdb) r | |
Starting program: /home/xu6wu6gj/2016-winter-course/test1/swap | |
Breakpoint 1, main () at swap.c:135 | |
135 int main(){return 0;} | |
(gdb) p $head = (List)malloc(sizeof(List)) | |
Invalid cast. | |
(gdb) p $head = (List*)malloc(sizeof(List)) | |
$1 = (List *) 0x602030 | |
(gdb) p $head->value = 1 | |
$2 = 1 | |
(gdb) p $head->next = (List*)malloc(sizeof(List)) | |
$3 = (struct List_node *) 0x602050 | |
(gdb) p $head->next->value = 2 | |
$4 = 2 | |
(gdb) p $head->next->next = (List*)malloc(sizeof(List)) | |
$5 = (struct List_node *) 0x602070 | |
(gdb) p $head->next->next->value = 3 | |
$6 = 3 | |
(gdb) p $head->next->next->next = (List*)0 | |
$7 = (struct List_node *) 0x0 | |
/* | |
以上三行(gdb) p xxxx 開頭是用來製造linked list用的 依序是 1 2 3總共3個node 1 是head | |
(從這邊就可以看出 如果要測比較大的list 這是個笨方法) | |
*/ | |
(gdb) p $head = swap($head,$head->next,$head->next->next) | |
$8 = (List *) 0x602030 | |
/* | |
交換第二個和第三個node 預期應該是 1 3 2 | |
*/ | |
(gdb) p $head->value | |
$9 = 1 | |
(gdb) p $head->next->value | |
$10 = 3 | |
(gdb) p $head->next->next->value | |
$11 = 2 | |
/* | |
果然是XD 再來繼續測別的 | |
*/ | |
(gdb) p $head->next->next->next | |
$12 = (struct List_node *) 0x0 | |
(gdb) p $head = swap($head,$head->next,$head->next->next) | |
$13 = (List *) 0x602030 | |
/* | |
一樣二換三 應該是 1 2 3 | |
*/ | |
(gdb) p $head->value | |
$14 = 1 | |
(gdb) p $head->next->value | |
$15 = 2 | |
(gdb) p $head->next->next->value | |
$16 = 3 | |
(gdb) p $head->next->next->next | |
$17 = (struct List_node *) 0x0 | |
/* | |
果然 | |
*/ | |
(gdb) p $head->next->next->next = (List*)malloc(sizeof(List)) | |
$18 = (struct List_node *) 0x602090 | |
(gdb) p $head->next->next->next->value = 4 | |
$19 = 4 | |
(gdb) p $head->next->next->next->next = (List*)0 | |
$20 = (struct List_node *) 0x0 | |
(gdb) p $head = swap($head,$head->next,$head->next->next->next) | |
$21 = (List *) 0x602030 | |
(gdb) p $head->value | |
$22 = 1 | |
(gdb) p $head->next->value | |
$23 = 4 | |
(gdb) p $head->next->next->value | |
$24 = 3 | |
(gdb) p $head->next->next->next->value | |
$25 = 2 | |
(gdb) p $head->next->next->next->next | |
$26 = (struct List_node *) 0x0 | |
(gdb) p $head = swap($head,$head->next,$head->next->next->next) | |
$27 = (List *) 0x602030 | |
(gdb) p $head->value | |
$28 = 1 | |
(gdb) p $head->next->value | |
$29 = 2 | |
(gdb) p $head->next->next->value | |
$30 = 3 | |
(gdb) p $head->next->next->next->value | |
$31 = 4 | |
(gdb) p $head->next->next->next->next | |
$32 = (struct List_node *) 0x0 | |
(gdb) p $head = swap($head,$head,$head->next->next) | |
$33 = (List *) 0x602070 | |
(gdb) p $head->value | |
$34 = 3 | |
(gdb) p $head->next->value | |
$35 = 2 | |
(gdb) p $head->next->next->value | |
$36 = 1 | |
(gdb) p $head->next->next->next->value | |
$37 = 4 | |
(gdb) p $head->next->next->next->next | |
$38 = (struct List_node *) 0x0 | |
(gdb) p $head = swap($head,$head,$head->next->next) | |
$39 = (List *) 0x602030 | |
(gdb) p $head->value | |
$40 = 1 | |
(gdb) p $head->next->value | |
$41 = 2 | |
(gdb) p $head->next->next->value | |
$42 = 3 | |
(gdb) p $head->next->next->next->value | |
$43 = 4 | |
(gdb) p $head->next->next->next->next | |
$44 = (struct List_node *) 0x0 | |
(gdb) p $head->next->next->next->next->value | |
Cannot access memory at address 0x0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment