Cross compile gdbserver and use it in ARM linux (在ARM uClinux下编译和使用gdbserver)
来源:互联网 发布:黄金时时彩计划软件 编辑:程序博客网 时间:2024/06/16 10:21
1. get and unzip src
# mkdir /usr/src/debug
# cd /usr/src/debug
# wget ftp://ftp.gnu.org/pub/gnu/gdb/gdb-6.3.tar.bz2
# tar -jxvf gdb-6.3.tar.bz2
2. apply gdb patch for ARM
# cp [PATCH_PATH]/gdb-6.3-tango-20050204.patch /usr/src/debug/gdb-6.3
# patch -p1 < gdb-6.3-tango-20050204.patch
replace [PATCH_PATH] to your patch path.
use patch-gdb-5.2.1-arm7tdmi-20020920 in the reference document is another choice, it's more complexity which need modify some code before compile.
3. build gdb
# mkdir /usr/src/debug/build_gdb
# cd /usr/src/debug/build_gdb
# ../gdb-6.3/configure --target=arm-linux --host=i386-pc-linux --prefix=/opt/gdebug
# make
# make install
4. build gdbserver
# mkdir /usr/src/debug/build_gdbserver
# cd /usr/src/debug/build_gdbserver
# export PATH=[TOOLCHAIN_PATH]:$PATH
# CC=arm-elf-gcc LDFLAGS='-Wl,-elf2flt' ../gdb-6.3/gdb/gdbserver/configure --target=arm-elf-linux --host=arm-elf-linux --prefix=/opt/gdebug/arm-linux
# make
# make install
set [TOOLCHAIN_PATH] to your toolchain patch.
after build, deploy the gdbserver binary to your target filesystem.
5.use gdb and gdbserve(command line or eclipse):
examples:
host pc ip:192.168.1.45
board ip:192.168.1.180
copy program and gdbserver to host/tftpboot/
and then in Target borad:
# mount 192.168.1.108:/tftpboot /mnt/nfs
# cd /mnt/nfs
# ./gdbserver 192.168.1.45:1234 gdbtest
In host pc:
# cd /usr/local/arm-gdb/bin/
# copy gdbtest /usr/local/arm-gdb/bin/
# ./arm-linux-gdb gdbtest
(gdb)target remote 192.168.1.180:1234
(gdb)list or l
(gdb)break func
(gdb)break 22
(gdb)info br
(gdb)continue or c
(gdb)next or n
(gdb)print or p result
(gdb) finish
(gdb) next
(gdb) quit
Appendix:
1). reference: http://www.uclinux.org/pub/uClinux/archive/10734.html
2). gdb-6.3-tango-20050204.patch:
/* start of gdb-6.3-tango-20050204.patch */
diff -Nur gdb-6.3/gdb/arm-tdep.c gdb-6.3.patched/gdb/arm-tdep.c
--- gdb-6.3/gdb/arm-tdep.c 2004-08-02 19:02:20.000000000 -0700
+++ gdb-6.3.patched/gdb/arm-tdep.c 2005-02-04 10:14:11.000000000 -0800
@@ -1925,10 +1925,12 @@
/* NOTE rearnsha 2002-02-18: for now we allow a non-multi-arch gdb to
override these definitions. */
#ifndef ARM_LE_BREAKPOINT
-#define ARM_LE_BREAKPOINT {0xFE,0xDE,0xFF,0xE7}
+//#define ARM_LE_BREAKPOINT {0xFE,0xDE,0xFF,0xE7}
+#define ARM_LE_BREAKPOINT {0x01,0x00,0x9f,0xEF}
#endif
#ifndef ARM_BE_BREAKPOINT
-#define ARM_BE_BREAKPOINT {0xE7,0xFF,0xDE,0xFE}
+//#define ARM_BE_BREAKPOINT {0xE7,0xFF,0xDE,0xFE}
+#define ARM_BE_BREAKPOINT {0xEF,0x9f,0x00,0x01}
#endif
#ifndef THUMB_LE_BREAKPOINT
#define THUMB_LE_BREAKPOINT {0xfe,0xdf}
diff -Nur gdb-6.3/gdb/config/arm/tm-embed.h gdb-6.3.patched/gdb/config/arm/tm-embed.h
--- gdb-6.3/gdb/config/arm/tm-embed.h 2004-04-30 13:52:16.000000000 -0700
+++ gdb-6.3.patched/gdb/config/arm/tm-embed.h 2005-02-04 10:14:11.000000000 -0800
@@ -27,7 +27,7 @@
/* The remote stub should be able to single-step. */
#undef SOFTWARE_SINGLE_STEP_P
-#define SOFTWARE_SINGLE_STEP_P() 0
+#define SOFTWARE_SINGLE_STEP_P() 1
/* The first 0x20 bytes are the trap vectors. */
#undef LOWEST_PC
diff -Nur gdb-6.3/gdb/gdbserver/linux-arm-low.c gdb-6.3.patched/gdb/gdbserver/linux-arm-low.c
--- gdb-6.3/gdb/gdbserver/linux-arm-low.c 2004-02-29 08:43:49.000000000 -0800
+++ gdb-6.3.patched/gdb/gdbserver/linux-arm-low.c 2005-02-04 10:14:11.000000000 -0800
@@ -23,7 +23,7 @@
#include "linux-low.h"
#ifdef HAVE_SYS_REG_H
-#include <sys/reg.h>
+//#include <sys/reg.h>
#endif
#define arm_num_regs 26
diff -Nur gdb-6.3/gdb/gdbserver/linux-low.c gdb-6.3.patched/gdb/gdbserver/linux-low.c
--- gdb-6.3/gdb/gdbserver/linux-low.c 2004-10-16 10:42:00.000000000 -0700
+++ gdb-6.3.patched/gdb/gdbserver/linux-low.c 2005-02-04 10:14:11.000000000 -0800
@@ -78,6 +78,24 @@
/* FIXME: Delete eventually. */
#define inferior_pid (pid_of (get_thread_process (current_inferior)))
+void send_area(char* buf) {
+
+ unsigned int x;
+ unsigned int code_start = ptrace (PTRACE_PEEKUSER, inferior_pid,
+ (PTRACE_ARG3_TYPE) 49*4, 0);
+ unsigned int data_start = ptrace (PTRACE_PEEKUSER, inferior_pid,
+ (PTRACE_ARG3_TYPE) 50*4, 0);
+ unsigned int bss_start = data_start;
+ unsigned int code_end = ptrace(PTRACE_PEEKUSER, inferior_pid,
+ (PTRACE_ARG3_TYPE) 51*4, 0);
+
+ printf("code at %p - %p, data at %p/n", code_start, code_end, data_start);
+
+ x = data_start - (code_end - code_start);
+ sprintf(buf,"Text=%x;Data=%x;Bss=%x;", code_start, x, x);
+};
+
+
/* This function should only be called if the process got a SIGTRAP.
The SIGTRAP could mean several things.
@@ -139,7 +157,7 @@
void *new_process;
int pid;
- pid = fork ();
+ pid = vfork ();
if (pid < 0)
perror_with_name ("fork");
diff -Nur gdb-6.3/gdb/gdbserver/server.c gdb-6.3.patched/gdb/gdbserver/server.c
--- gdb-6.3/gdb/gdbserver/server.c 2004-03-04 19:44:27.000000000 -0800
+++ gdb-6.3.patched/gdb/gdbserver/server.c 2005-02-04 10:14:11.000000000 -0800
@@ -89,6 +89,12 @@
handle_query (char *own_buf)
{
static struct inferior_list_entry *thread_ptr;
+
+ if (strcmp ("qOffsets", own_buf) == 0)
+ {
+ send_area(own_buf);
+ return;
+ }
if (strcmp ("qSymbol::", own_buf) == 0)
{
/* end of gdb-6.3-tango-20050204.patch */
- Cross compile gdbserver and use it in ARM linux (在ARM uClinux下编译和使用gdbserver)
- Cross compile gdbserver and use it in ARM linux (在ARM uClinux下编译和使用gdbserver)
- Building GDB and GDBserver for cross debugging / Linux下交叉编译gdb和gdbserver
- 编译gdbserver和arm-linux-gdb
- 使用gdb、gdbserver在ARM-Linux下进行远程调试
- 使用gdb、gdbserver在ARM-Linux下进行远程调试
- Ubuntu下arm-linux-gdb+gdbserver的编译及安装
- 重新编译arm-linux-androideabi-gdb和gdbserver
- arm-linux-gdb和gdbserver调试交叉编译的程序
- 嵌入式arm-linux-gdb和 gdbserver 编译及调试
- arm-linux-gdb、gdbserver的编译安装
- 关于gdbserver在arm环境中的使用
- 使用gdbserver+arm-linux-gdb 调试应用程序
- 制作GDB和GDBServer, arm-linux-gdb
- arm-linux-gdb与gdbserver
- 使用gdbserver调试arm应用程序
- linux arm cross-compile
- Linux下交叉编译gdb和gdbserver
- 编写和调试程序
- 把单元格显示不下的文本用省略号代替,并且当mouseover时用提示信息显示全部内容
- S3C2410 & Linux 2.6 内核
- 常用DBA脚本
- 网上下载和上传数据(一)
- Cross compile gdbserver and use it in ARM linux (在ARM uClinux下编译和使用gdbserver)
- 对自己的工资有意见啦!
- 网上下载和上传数据(二)
- 使用虚拟机(zt)
- 使用.NET自带的类实现DataGrid报表的打印
- [十三问之十]&& and ||
- C#积木模块ABC:13.如何在C#中发送邮件?
- 用c#写的smtp邮件发送类
- 大家好!