ポインタを指すポインタテスト
12125 ワード
[shidongxue@centossvr testtool]$ vi a.c
#include
int test2(int argc,char** argv)
{
printf("argc=%d, argv[0]=%s
",argc,argv[0]);
return 0;
}
int main(int argc,char** argv)
{
printf("%p
",argv);
printf("sizeof argv=%d
",sizeof(argv));
return test2(argc,argv);
}
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"a.c" 13L, 239C
[shidongxue@centossvr testtool]$ gcc a.c
[shidongxue@centossvr testtool]$ gcc a.c -g
[shidongxue@centossvr testtool]$ gdb
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-80.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later //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-redhat-linux-gnu".
For bug reporting instructions, please see:
//www.gnu.org/software/gdb/bugs/>.
(gdb) file a.out
Reading symbols from /home/shidongxue/work/testtool/a.out...done.
(gdb) b main
Breakpoint 1 at 0x400570: file a.c, line 9.
(gdb) r x
Starting program: /home/shidongxue/work/testtool/a.out x
Breakpoint 1, main (argc=2, argv=0x7fffffffe4a8) at a.c:9
9 printf("%p
",argv);
Missing separate debuginfos, use: debuginfo-install glibc-2.17-106.el7_2.8.x86_64 glibc-2.17-157.el7_3.2.x86_64
(gdb) s
0x7fffffffe4a8
10 printf("sizeof argv=%d
",sizeof(argv));
(gdb) s
sizeof argv=8
11 return test2(argc,argv);
(gdb) x/16c 0x7fffffffe4a8
0x7fffffffe4a8: -12 '\364' -26 '\346' -1 '\377' -1 '\377' -1 '\377' 127 '\177' 0 '\000' 0 '\000'
0x7fffffffe4b0: 25 '\031' -25 '\347' -1 '\377' -1 '\377' -1 '\377' 127 '\177' 0 '\000' 0 '\000'
(gdb) x/16x 0x7fffffffe4a8
0x7fffffffe4a8: 0xf4 0xe6 0xff 0xff 0xff 0x7f 0x00 0x00
0x7fffffffe4b0: 0x19 0xe7 0xff 0xff 0xff 0x7f 0x00 0x00
(gdb) x/32c 0x7fffffffe6f4
0x7fffffffe6f4: 47 '/' 104 'h' 111 'o' 109 'm' 101 'e' 47 '/' 115 's' 104 'h'
0x7fffffffe6fc: 105 'i' 100 'd' 111 'o' 110 'n' 103 'g' 120 'x' 117 'u' 101 'e'
0x7fffffffe704: 47 '/' 119 'w' 111 'o' 114 'r' 107 'k' 47 '/' 116 't' 101 'e'
0x7fffffffe70c: 115 's' 116 't' 116 't' 111 'o' 111 'o' 108 'l' 47 '/' 97 'a'
(gdb) x/32c 0x7fffffffe719
0x7fffffffe719: 120 'x' 0 '\000' 88 'X' 68 'D' 71 'G' 95 '_' 83 'S' 69 'E'
0x7fffffffe721: 83 'S' 83 'S' 73 'I' 79 'O' 78 'N' 95 '_' 73 'I' 68 'D'
0x7fffffffe729: 61 '=' 50 '2' 55 '7' 57 '9' 54 '6' 0 '\000' 72 'H' 79 'O'
0x7fffffffe731: 83 'S' 84 'T' 78 'N' 65 'A' 77 'M' 69 'E' 61 '=' 99 'c'
(gdb) x/1c 0x7fffffffe719
0x7fffffffe719: 120 'x'