<<gdb使用经验技巧>>
Tags: devel,linux,c,cpp
1. 用gcc编译须注意: .o文件必须放在.a文件前
用gcc/g++链接.o文件时, .o文件必须放在.a文件前, 否则出错: "找不到相关库函数的定义":
E:/desktop_item/tmp/0virtual/nehe2/LVHM/Chess/CGfxOpenGL.cpp:74: undefined reference to `glViewport@16'
E:/desktop_item/tmp/0virtual/nehe2/LVHM/Chess/CGfxOpenGL.cpp:75: undefined reference to `glMatrixMode@4'
E:/desktop_item/tmp/0virtual/nehe2/LVHM/Chess/CGfxOpenGL.cpp:77: undefined reference to `glLoadIdentity@0'
E:/desktop_item/tmp/0virtual/nehe2/LVHM/Chess/CGfxOpenGL.cpp:81: undefined reference to `glFrustum@48'
E:/desktop_item/tmp/0virtual/nehe2/LVHM/Chess/CGfxOpenGL.cpp:83: undefined reference to `glMatrixMode@4'
g++ file1.o file2.o file3.o lib1.a lib2.a -o a.out // 正确写法
g++ lib1.a lib2.a file1.o file2.o file3.o -o a.out // 错误写法
2. watch
You can force gdb to use only software watchpoints with the set
can-use-hw-watchpoints 0 command. With this variable set to zero, gdb will
never try to use hardware watchpoints, even if the underlying system supports
them. (Note that hardware-assisted watchpoints that were set before setting
can-use-hw-watchpoints to zero will still use the hardware mechanism of
watching expression values.)
set can-use-hw-watchpoints
Set whether or not to use hardware watchpoints.
show can-use-hw-watchpoints
Show the current mode of using hardware watchpoints.
(gdb)
// Use software watchpoints
(gdb) set can-use-hw-watchpoints 0
// Use hardware watchpoints
(gdb) set can-use-hw-watchpoints 1
100. FAQ
100.1 Target description specified unknown architecture "arm"
用gdb与gdbserver调试, gdb端有可能报如下的错误和警告, 原因一般是由于gdb与
gdbserver不匹配! 解决的办法是使用配套的gdb与gdbserver!
(gdb) target remote 192.168.3.196:2345
Remote debugging using 192.168.3.196:2345
warning: while parsing target description (at line 1): Target description specified unknown architecture "arm"
warning: Could not load XML target description; ignoring
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0x00000000 in ?? ()
(gdb)
Tags: devel,linux,c,cpp
1. 用gcc编译须注意: .o文件必须放在.a文件前
用gcc/g++链接.o文件时, .o文件必须放在.a文件前, 否则出错: "找不到相关库函数的定义":
E:/desktop_item/tmp/0virtual/nehe2/LVHM/Chess/CGfxOpenGL.cpp:74: undefined reference to `glViewport@16'
E:/desktop_item/tmp/0virtual/nehe2/LVHM/Chess/CGfxOpenGL.cpp:75: undefined reference to `glMatrixMode@4'
E:/desktop_item/tmp/0virtual/nehe2/LVHM/Chess/CGfxOpenGL.cpp:77: undefined reference to `glLoadIdentity@0'
E:/desktop_item/tmp/0virtual/nehe2/LVHM/Chess/CGfxOpenGL.cpp:81: undefined reference to `glFrustum@48'
E:/desktop_item/tmp/0virtual/nehe2/LVHM/Chess/CGfxOpenGL.cpp:83: undefined reference to `glMatrixMode@4'
g++ file1.o file2.o file3.o lib1.a lib2.a -o a.out // 正确写法
g++ lib1.a lib2.a file1.o file2.o file3.o -o a.out // 错误写法
2. watch
You can force gdb to use only software watchpoints with the set
can-use-hw-watchpoints 0 command. With this variable set to zero, gdb will
never try to use hardware watchpoints, even if the underlying system supports
them. (Note that hardware-assisted watchpoints that were set before setting
can-use-hw-watchpoints to zero will still use the hardware mechanism of
watching expression values.)
set can-use-hw-watchpoints
Set whether or not to use hardware watchpoints.
show can-use-hw-watchpoints
Show the current mode of using hardware watchpoints.
(gdb)
// Use software watchpoints
(gdb) set can-use-hw-watchpoints 0
// Use hardware watchpoints
(gdb) set can-use-hw-watchpoints 1
100. FAQ
100.1 Target description specified unknown architecture "arm"
用gdb与gdbserver调试, gdb端有可能报如下的错误和警告, 原因一般是由于gdb与
gdbserver不匹配! 解决的办法是使用配套的gdb与gdbserver!
(gdb) target remote 192.168.3.196:2345
Remote debugging using 192.168.3.196:2345
warning: while parsing target description (at line 1): Target description specified unknown architecture "arm"
warning: Could not load XML target description; ignoring
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0x00000000 in ?? ()
(gdb)