GDB arm-linux交叉编译移植和使用方法(特别是对于正在运行的程序或者段错误的程序进行分析)
来源:互联网 发布:同性电影推荐知乎 编辑:程序博客网 时间:2024/04/19 21:43
目录(?)[+]
1、ncurse库的移植
(5)安装 make install
libncurses.so放在ncurses-5.6/output/arm/lib路径下。
2、gdb库的编译和移植
--enable-shared 动态编译
--host=arm-linux 用arm-linux-gcc编译
--prefix="$PWD/../output/arm-linux" 安装目录
--without-x 取消x windows 支持
--disable-gdbtk 取消gdbtk,应该也是图形界面相关的
--disable-tui 取消tui 界面
--without-included-regex 关闭正则表达式库
--without-included-gettext 去掉用于多语言处理的 gettext库
正则表达式/gettext,暂时不需要,先去掉
CPPFLAGS/LDFLAGS是确保能找到ARM版的ncurses库
(5)安装 make install
3、gdb移植到arm上
#include <stdlib.h>
#include <string.h>
int func(int n)
{
int sum = 0, i;
for(i = 0; i < n; i++)
{
sum += i;
}
return sum;
}
void f2(char * str)
{
char buf[1024];
strcpy(buf,(const char *)str);
}
void f1(void)
{
int x = 0;
f2((char *)x);
}
void test1(void)
{
f1();
}
static int Delay(unsigned int uiTimeS)
{
struct timeval timeout;
timeout.tv_sec= uiTimeS;
timeout.tv_usec = 0;
select(0, NULL, NULL, NULL, &timeout);
return 0;
}
int main(void)
{
int i;
int result = 0;
for(i = 1; i <= 100; i++)
{
result += i;
}
test1();
Delay(10000);
printf("result[1-100] = %d\n", result);
printf("result[1-250] = %d\n", func(250));
return 0;
}
(1)测试程序运行时首先会有个段错误:./gdbtest &
[user0@ user0]$ [65334.020000] pgd = c3e14000
[65334.020000] [00000000] *pgd=43b87031, *pte=00000000, *ppte=00000000
用移植好的gdb来测试运行如下:
./gdb gdbtest
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 "arm-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/user0/gdbtest...done.
(gdb) r
Starting program: /home/user0/gdbtest
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
[65352.710000] pgd = c1cbc000read_db matching inferior's thread library, thread debugging will not be available.
[65352.710000] [00000000] *pgd=41c9c031, *pte=00000000, *ppte=00000000
Program received signal SIGSEGV, Segmentation fault.
0x400ca048 in strcpy () from /lib/libc.so.6
(gdb) bt
#0 0x400ca048 in strcpy () from /lib/libc.so.6
#1 0x00008540 in f2 (str=0x0) at src/gdbtest.c:45
#2 0x0000855c in main () at src/gdbtest.c:73
(gdb)
[1]+ Segmentation fault ./gdbtest
可以看出代码段错误问题出在strcpy上。
(2)测试程序中把
Delay(10000);
test1();
Delay放到test1之前,这样程序会阻塞,阻塞的时候用gdb定位正在运行的进程非常好用:
./gdb gdbtest 1865 第一是运行gdb 第二个进程名称 第三个进程pid,顺序这样子来要
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 "arm-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/user0/gdbtest...done.
Attaching to program: /home/user0/gdbtest, process 1865
Reading symbols from /lib/libpthread.so.0...(no debugging symbols found)...done.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /lib/libdl.so.2...(no debugging symbols found)...done.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
Loaded symbols for /lib/ld-linux.so.2
0x401198dc in select () from /lib/libc.so.6
(gdb) bt
#0 0x401198dc in select () from /lib/libc.so.6
#1 0x000086e0 in Delay (uiTimeS=<value optimized out>) at src/gdbtest.c:67
#2 0x00008598 in _start ()
(gdb) q
A debugging session is active.
bt用来查看堆栈信息,发现阻塞在select函数中,和我们的代码一致。
- GDB arm-linux交叉编译移植和使用方法(特别是对于正在运行的程序或者段错误的程序进行分析)
- GDB arm-linux交叉编译移植和使用方法(特别是对于正在运行的程序或者段错误的程序进行分析)
- arm-linux-gdb和gdbserver调试交叉编译的程序
- GDB调试(正在运行的程序)
- GDB调试(正在运行的程序)
- GDB 调试正在运行的程序
- 使用gdb调试正在运行的程序
- GDB调试正在运行的程序
- 编译可移植到arm上的qt程序错误分析
- 编译arm-linux-gdb和远程调试arm板程序
- 编译arm-linux-gdb和远程调试arm板程序
- 编译arm-linux-gdb和远程调试arm板程序
- 编译arm-linux-gdb和远程调试arm板程序
- 图解如何将Ubuntu上的Qt程序交叉编译出可在ARM平台运行的程序(五部曲)
- C中变量存储区、程序编译后的映像和运行时的段分析
- arm-linux-gdb 交叉编译工具的安装使用
- arm-linux-gdb 交叉编译工具的安装使用
- arm-linux-gdb 交叉编译工具的安装使用
- vim程序编辑器
- win32版QQ隐藏功能,气泡消息显示详细时间
- Android刮彩票效果
- 10+资深软件架构师谈计算机专业——填高考志愿必读
- Android开发-layout布局相关属性总结
- GDB arm-linux交叉编译移植和使用方法(特别是对于正在运行的程序或者段错误的程序进行分析)
- LeetCode第54题之Spiral Matrix
- iOS适配那些事
- ARC基本原理
- 初学MVP
- Java下载文件,文件名中文乱码问题
- Hibernate环境框架搭建
- HDOJ 3923 Invoker
- 使用 Intel HAXM 为 Android 模拟器加速,媲美真机