Cross compile gdbserver and use it in ARM linux (在ARM uClinux下编译和使用gdbserver)

转载 2007年10月08日 12:21:00
 

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 */

如果有错误的话,还需要打上另外一个补丁:

--- gdb-6.3/sim/arm/iwmmxt~old.c    2003-03-27 12:13:33.000000000 -0500
+++ gdb-6.3/sim/arm/iwmmxt.c        2006-09-18 15:26:05.000000000 -0400
@@ -2114,7 +2114,7 @@
s = (signed long) a * (signed long) b;

-      (signed long long) t += s;
+      t += (signed long long)s;
        }
      else
        {
@@ -2130,7 +2130,7 @@
    wR [BITS (12, 15)] = 0;


  if (BIT (21))    /* Signed.  */
-    (signed long long) wR[BITS (12, 15)] += (signed long long) t;
+    wR[BITS (12, 15)] += (signed long long) t;
  else
    wR [BITS (12, 15)] += t;


@@ -2166,7 +2166,7 @@
      b = wRHALF (BITS (0, 3), i * 2);
      b = EXTEND16 (b);


-      (signed long) s1 = a * b;
+      s1 = (signed long)a * (signed long)b;


      a = wRHALF (BITS (16, 19), i * 2 + 1);
      a = EXTEND16 (a);
@@ -2174,7 +2174,7 @@
      b = wRHALF (BITS (0, 3), i * 2 + 1);
      b = EXTEND16 (b);


-      (signed long) s2 = a * b;
+      s2 = (signed long)a * (signed long)b;
        }
      else            /* Unsigned.  */
        {
@@ -2183,12 +2183,12 @@
      a = wRHALF (BITS (16, 19), i * 2);
      b = wRHALF (BITS ( 0,  3), i * 2);


-      (unsigned long) s1 = a * b;
+      s1 = (unsigned long)a *(unsigned long) b;


      a = wRHALF (BITS (16, 19), i * 2 + 1);
      b = wRHALF (BITS ( 0,  3), i * 2 + 1);


-      (signed long) s2 = a * b;
+      s2 = (signed long)a * (signed long)b;
        }


r |= (ARMdword) ((s1 + s2) & 0xffffffff) << (i ? 32 : 0);

如果生成的gdbserver无法使用的话我也没有办法了,呵呵。我也没有搞定,不好意思!


使用gdbserver+arm-linux-gdb 调试应用程序

1.下载gdb的源码 2.编译:cd gdb-7.10.1 ./configure --target=arm-linux --prefix=$PWD/installed -v解释一下: –targ...
  • k7arm
  • k7arm
  • 2017-02-07 15:53:46
  • 1060

gdbserver调试工具移植到ARM Linux教程

目前,嵌入式 Linux系统中,主要有三种远程调试方法,分别适用于不同场合的调试工作:用ROM Monitor调试目标机程序、用KGDB调试系统内核和用gdbserver调试用户空间程序。这三种调试方...
  • backcrow
  • backcrow
  • 2016-01-11 14:32:24
  • 945

编译gdbserver和arm-linux-gdb

之前我们用buildroot生成带gdbserver的根文件系统,这里顺便介绍如何编译Gdbserver和arm-linux-gdb。 前言原创文章欢迎转载,请保留出处。 若有任何疑问建议,欢迎回复。...
  • maxwell_nc
  • maxwell_nc
  • 2015-03-22 13:53:42
  • 2038

eclipse 平台gdbserver调试arm-linux程序

上回书到gdbserver编译安装完成,接下来该gdb本地调试了,由于gdb命令界面的调试一个大的工程还是很不爽的,那就借助eclipse强大的功能来协助调试吧,整整搞了两天才把这个环境搭建起来,li...
  • fz835304205
  • fz835304205
  • 2013-12-07 17:04:39
  • 1319

Ubuntu下arm-linux-gdb+gdbserver的编译及安装

注:arm-linux-gdb的安装路径是/usr/local/arm/3.4.1 1、arm-linux-gdb的编译安装 下载gdb-6.8.tar.bz2至工作目录 gdb源码下载:htt...
  • lizhibin1091666592
  • lizhibin1091666592
  • 2012-03-04 11:31:36
  • 3591

实现交叉编译gdb和gdbserver(gdb-7.6)

海思SDK环境下实现: 1、下载gdb:   下载地址为:http://ftp.gnu.org/gnu/gdb/ 2、解压缩: tar xvf gdb-7.6.tar.bz2  3、进入该目...
  • gl1987807
  • gl1987807
  • 2013-10-12 19:26:33
  • 5837

交叉编译gdbserver

从官网下载最新的gdb代码 http://ftp.gnu.org/gnu/gdb/ 这才是正宗的, 那些git, googlesource, 镜像,甚至什么补丁,脚本等全见鬼去吧。 这么简单的事为什么...
  • hejinjing_tom_com
  • hejinjing_tom_com
  • 2016-10-09 15:09:07
  • 1190

建立ARM平台上的交叉调试器gdb和gdbserver

建立ARM平台上的交叉调试器gdb和gdbserverhansel@163.com2007.10.18gdb-6.6使用了autoconf/automake,因此通过设置configure脚本的--t...
  • hansel
  • hansel
  • 2007-10-18 11:08:00
  • 12476

arm-linux-gdb、gdbserver的编译安装

下载gdb-7.5.tar.gz(http://www.gnu.org/software/gdb/download/) 解压gdb-7.10.tar.gz tar -zxvf gdb-7.10.t...
  • yangbingzhou
  • yangbingzhou
  • 2015-09-08 09:54:53
  • 1518

Cross compile gdbserver and use it in ARM linux (在ARM uClinux下编译和使用gdbserver)

1. get and unzip src    # mkdir /usr/src/debug  # cd /usr/src/debug  # wget ftp://ftp.gnu.org/pub/gn...
  • gstreamer
  • gstreamer
  • 2006-09-04 16:21:00
  • 3867
收藏助手
不良信息举报
您举报文章:Cross compile gdbserver and use it in ARM linux (在ARM uClinux下编译和使用gdbserver)
举报原因:
原因补充:

(最多只允许输入30个字)