GDB问题汇总

来源:互联网 发布:知春大厦兼职是真的吗 编辑:程序博客网 时间:2024/04/25 18:40

gdb交叉编译:
./configure --prefix=/home/sf6/jieen/tmp/gdb_build_mipsel --host=mipsel-linux --target=mipsel-linux  CC=mipsel-linux-gcc
./configure --prefix=/home/sf6/jieen/tmp/gdb_build_mipsel --host=mipsel-linux --target=mipsel-linux  CC=mipsel-linux-gcc
./configure --prefix=/home/sf6/jieen/tmp/gdb_build_mipsel --host=sh4-linux --target=sh4-linux  CC=sh4-linux-gcc


GDB调试动态库
在linux下用户主目录下增加.gdbinit文件,该文件是gdb启动的配置文件

调试动态链接库时,在.gdbinit文件中加入

add-shared-symbol-file  /usr/src/....(动态库的源程序位置)

在调试的时候不能直接加上断点在动态库的函数上

需要将断点加在调用动态库函数的程序上,当程序停止到该断点时,再将断点加在动态库的函数上,单步执行进入动态库的函数中

 


STB:
gdbserver localhost:8495 binfile --attach PID
PC:
mipsel-linux-gdb binfile
指定库路径:SET SOLIB-ABSOLUTE-PREFIX and SET SOLIB-SEARCH-PATH
ex:
(gdb)set solib-absolute-prefix /lib
(gdb)set solib-search-path /lib
(gdb)set solib-search-path .:/opt/toolchains/<toolchain version>/mipsel-linux-uclibc/lib
(gdb)target remote 192.168.1.190:8495


tar jxvf gdb-7.4.tar.bz2
cd gdb-7.4
./configure --host=i686-pc-linux-gnu --target=mipsel-linux
make
cd gdb/
cp gdb ~/jobs/tools/stbgcc-4.4.5-2.0/bin/mipsel-linux-gdb_7.4
cd gdbserver/
./configure --host=mipsel-linux --target=mipsel-linux
make

常用命令:
(gdb)target remote 10.0.1.91:8495
(gdb)file debugbinfile
(gdb)l main
(gdb)b main
(gdb)run
(gdb)watch
(gdb)commands :设置在遇到断点后执行特定的指令
(gdb)disable :让指定断点失效
(gdb)delete :清除断点或自动显示的表达式
(gdb)ignore :忽略断点
(gdb)enable :和disable相反,恢复失效的断点
(gdb)cont n:跳过n次断点,继续运行,n为空当前断点
(gdb)jump 行号:让程序跳到指定行开始调试
(gdb)next n:执行n条语句 步过
(gdb)step/s:步进
(gdb)set 变量:=表达式
(gdb)info display :显示当前所有的要显示值的表达式
(gdb)print :打印变量或表达式的值
(gdb)backtrace :打印指定个数的栈帧(stack frame)。
(gdb)frame :打印栈帧。
(gdb)kill :结束当前程序的调试
(gdb)signal:将一个信号发送到当前执行的程序
(gdb)whatis:显示变量函数类型
(gdb)until:结束当前循环
(gdb)finish:返回调用函数
(gdb)call:调用或执行一个函数

信号:
(gdb)handle SIGBUS stop print:接收到信号BUS后显示打印
(gdb)shell:不退出GDB执行shell
多线程:
info threads
thread id :切换到ID线程

不生成core文件
ulimit -S -c 0 >/dev/null 2>&1
生成core文件方法
ulimit -S -c unlimited > /dev/null 2>&1
2.在/etc/security/limits.conf文件中加入
soft core 0 或者 user soft core 0或者 group soft core 0,需要注释掉1中的内容
修改core文件的保存位置:
echo "/mnt/flash/core" > /proc/sys/kernel/core_pattern
可以修改core名:
echo "1" > /proc/sys/kernel/core_uses_pid 0为core覆盖
关闭core文件
ulimit -c 0
检查core是否打开
ulimit -a

core测试
ulimit -s 1024
ulimit -a
test.c
#include <stdio.h>
char *str="test";
void core_test()
{
 char *ptr;
 strcpy(ptr,str);
}
int main()
{
 core_test();
 return 0;
}
gcc -g test.c -o test
./test
gdb test core.pid
(gdb) where
#0  0x006e2254 in strcpy () from /lib/libc.so.6
#1  0x080483de in core_test ()
#2  0x080483eb in main ()

原创粉丝点击