動機

之前debug有JTAG,沒有需要remote debug,一樣可以做iteration。今天有人提了一下,就來試一下這種scenario。

 

顴念

觀念是這樣,可以跑gdbserver的環境,應該也可以直接跑gdb。那為什麼要用remote debug?

1. gdbserver遠比gdb小,因此容易porting,也因此可以很快的開始debug

2. 不同os的tradeoff。如RTOS沒什麼resource,在做開發時利用remote debug會比較有效率,比如cross compile。

3. 其他。有想到/找到/用到 時再加上。

 

環境

host為一般linux,target是一個embedded arm system。gdbserver跑在target,在host端執行一樣的程式,透過serial port或是TCP溝通。因為是同一台機器,ip是192.168.19.14,這會有問題,見下述。

 

開始

手上沒有真實的板子,因此虛擬了一個arm的rootfile system:

sudo build-arm-chroot karmic eabi-chroot http://ports.ubuntu.com/ubuntu-ports

這樣就會建立一個arm filesystem,包括second stage的utility,連qemu-arm-static都有,因此可以直接chroot。再把proc 跟sys mount起來

mount -t proc proc /proc

mount -t sysfs sys /sys

隨便寫個hello.c,並compile成armel,記得加上-g:

在target安裝gdbserver:

apt-get install gdbserver

此時執行gdbserver,並指定任意port:

gdbserver 192.168.19.14:2222 hello

會出現qemu: Unsupported syscall: 26的錯誤,從host是連不上的。這應該是在本機使用chroot會有一些小問題,用兩台機器,不同ip很順利的就可以連上。用力google了一下,試出以下解法:

qemu-arm-static -g 2222 hello

此時進入等待畫面。再來是host端,對同樣一份執行檔:

latrell@lucid:~/rootfs/root1/home$ /opt/arm-2010q1/bin/arm-none-eabi-gdb ./hello
GNU gdb (Sourcery G++ Lite 2010q1-188) 7.0.50.20100218-cvs
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 "--host=i686-pc-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
<https://support.codesourcery.com/GNUToolchain/>...

warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB.  Attempting to continue with the default arm settings.

Reading symbols from /home/latrell/rootfs/root1/home/hello...done.
(gdb) l
1    #include <stdio.h>
2    
3    int main(int argc, char **argv)
4    {
5    
6        printf("hello\n");
7        return 0;
8    }
(gdb) target remote localhost:2222
Remote debugging using localhost:2222
warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB.  Attempting to continue with the default arm settings.

[New Remote target]
[Switching to Remote target]
0x400817f0 in ?? ()
(gdb) b 5
Breakpoint 2 at 0x83ba: file hello.c, line 5.
(gdb) c
Continuing.

Breakpoint 2, main (argc=1, argv=0x4007f8dc) at hello.c:6
6        printf("hello\n");

 

可看出已attach上,可以開始debug。再進階一點還有結合一些IDE tool如eclipse,可以dump多一點資訊,有空再繼續。

 

 

 

 

 

arrow
arrow
    全站熱搜

    kezeodsnx 發表在 痞客邦 留言(0) 人氣()