GNU gdb (Sourcery G++ Lite 2008q3-72) 6.8.50.20080821-cvs
Copyright (C) 2008 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 "--host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi". For bug reporting instructions, please see: <https:
[root@Frankzfz]$gdbserver 10.27.10.48:9000 ./test_seg_fault Process ./test_seg_fault created; pid = 760 Listening on port 9000 Remote debugging from host 10.27.10.48
然后在宿主机上运行
arm-linux-gdb/bin$ arm-linux-gdb GNU gdb (Sourcery G++ Lite 2008q3-72) 6.8.50.20080821-cvs Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
Thisis 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"--host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi". For bug reporting instructions, please see: <https://support.codesourcery.com/GNUToolchain/>.
(gdb) symbol-file test_seg_fault Reading symbols from /home/zfz/kernel/fs/arm-linux-gdb/bin/test_seg_fault...done. (gdb)break main Breakpoint 1 at 0x84a8:file test_seg_fault.c,line 7. (gdb) info main Undefined info command:"main".Try"help info". (gdb) info b Num Type Disp Enb Address What 1 breakpoint keep y 0x000084a8 in main at test_seg_fault.c:7 (gdb) c The program is not being run. (gdb)
[root@Frankzfz]$gdbserver 10.27.10.48:9000 ./test_seg_fault Process ./test_seg_fault created; pid = 760 Listening on port 9000 Remote debugging from host 10.27.10.48 readchar: Got EOF Remote side has terminated connection. GDBserver will reopen the connection. Listening on port 9000
GNU gdb (GDB) 7.1 Copyright (C) 2010 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 "--host=x86_64-unknown-linux-gnu --target=arm-linux". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>.
zfz@zfz:~/kernel/fs/arm-linux-gdb/bin$ ./arm-linux-gdb test ./arm-linux-gdb: Symbol `acs_map' has different size in shared object, consider re-linking GNU gdb (GDB) 7.1 Copyright (C) 2010 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 "--host=x86_64-unknown-linux-gnu --target=arm-linux". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/zfz/kernel/fs/arm-linux-gdb/bin/test...done. (gdb) target remote 10.27.10.23:9000 Remote debugging using 10.27.10.23:9000 warning: Unable to find dynamic linker breakpoint function. GDB will be unable to debug shared library initializers and track explicitly loaded dynamic code. 0x400007b0 in ?? () (gdb) l Cannot access memory at address 0x0 1 #include <stdio.h> 2 int main( void ) 3 { 4 int i=2; 5 int x, y; 6 7 x=(++i); 8 printf(" %d %d\n", i,x); 9 x+=(++i); 10 printf(" %d %d\n", i,x); (gdb) l 11 x+=(++i); 12 printf(" %d %d\n", i,x); 13 i=2; 14 y=(i++)+(i++)+(i++); 15 printf(" %d %d\n", i,y); 16 17 return 0; 18 } 19 (gdb) break 9 Breakpoint 1 at 0x83b8: file test.c, line 9. (gdb) c Continuing. Error while mapping shared library sections: `/lib/libc.so.6':not in executable format:File format not recognized Errorwhile mapping shared library sections: /lib/ld-linux.so.3: No such fileor directory.
Breakpoint 1, main () at test.c:9 9 x+=(++i); (gdb) step 10 printf(" %d %d\n", i,x); (gdb) next 11 x+=(++i); (gdb) next 12 printf(" %d %d\n", i,x); (gdb) next 13 i=2; (gdb) next 14 y=(i++)+(i++)+(i++); (gdb) next 15 printf(" %d %d\n", i,y); (gdb) next 17 return 0; (gdb) next 18 } (gdb) next
在目标板上的输出:
[root@Frankzfz]$gdbserver 10.27.10.48:9000 ./test Process ./test created; pid = 746 Listening on port 9000 Remote debugging from host 10.27.10.48 3 3 4 7 5 12 5 6
set solib-absolute-prefix /nfsroot/rootfs set solib-search-path /nfsroot/rootfs/lib
调试找不到源代码,如下设置:
directory xfer-1.0.0/src/
下面是调试的情况:
(gdb)set solib-absolute-prefix /home/kernel/fs/root_nfs (gdb)set solib-search-path /home/kernel/fs/root_nfs/lib (gdb) target remote 10.27.10.23:9000 Remote debugging using 10.27.10.23:9000 Reading symbols from /home/kernel/fs/root_nfs/lib/ld-linux.so.3...(no debugging symbols
found)...done. Loaded symbols for/home/kernel/fs/root_nfs/lib/ld-linux.so.3 0x400007b0 in ??() from /home/kernel/fs/root_nfs/lib/ld-linux.so.3 (gdb) l 3 { 4 int i=2; 5 int x, y; 6 7 x=(++i); 8 printf(" %d %d\n", i,x); 9 x+=(++i); 10 printf(" %d %d\n", i,x); 11 x+=(++i); 12 printf(" %d %d\n", i,x); (gdb) l 13 i=2; 14 y=(i++)+(i++)+(i++); 15 printf(" %d %d\n", i,y); 16 17 return 0; 18 } 19 (gdb) b 8 Note: breakpoint 1 also set at pc 0x83a8. Breakpoint 2 at 0x83a8:filetest.c,line 8. (gdb) c Continuing.
Breakpoint 1, main () at test.c:8 8 printf(" %d %d\n", i,x); (gdb) n 9 x+=(++i); (gdb) b 12 Breakpoint 3 at 0x8400:filetest.c,line 12. (gdb) n 10 printf(" %d %d\n", i,x); (gdb) n 11 x+=(++i); (gdb) n
Breakpoint 3, main () at test.c:12 12 printf(" %d %d\n", i,x); (gdb) n 13 i=2; (gdb) n 14 y=(i++)+(i++)+(i++); (gdb) n 15 printf(" %d %d\n", i,y); (gdb) n 17 return 0; (gdb) n 18 } (gdb) n 0x4003b004 in __libc_start_main () from /home/kernel/fs/root_nfs/lib/libc.so.6 (gdb)