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
#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函数中,和我们的代码一致。