gdb+jlin纯linux环境调试arm

1 安装jlinkfor linux


J-Link SEGGER 公司为支持仿真ARM 内核芯片推出的JTAG 仿真器。配合IAR EWARMADSKEILWINARMRealView等集成开发环境支持所有ARM7/ARM9 内核芯片的仿真,通过 RDI接口和各集成开发环境无缝连接,操作方便、连接方便、简单易学,是学习开发ARM 最好最实用的开发工具。

http://www.segger.com/上可以找到J-Link Commander linux 下的可执行程序。将下载的JLink_Linux_090804.tar解压到/home/jianglu/arm-tools/jlink/ 目录下。按照README 的说明,安装libusb 库、复制udev 规则文件45-jlink.rules/etc/udev/rules.d/、添加用户到plugdev 组、重启计算机。这样jlink 就可以使用了。

插入 J-LinkUSB口,使用root 权限启动./start脚本

sudo ./start

程序错误,提示./JLinkExe:errorwhileloadingsharedlibraries:./libjlinkarm.so.0:file too short

删除 2个无效的软连接libjlinkarm.solibjlinkarm.so.0

rm libjlinkarm.so
rm libjlinkarm.so.0

重建 libjlinkarm.solibjlinkarm.so.0连接

ln -s libjlinkarm.so.0.0 libjlinkarm.so.0
ln -s libjlinkarm.so.0.0 libjlinkarm.so

再次启动脚本

sudo ./start

出现 J-Link>提示符,J-Link成功启动。



2 建立ARM平台上的交叉编译器gdb

下载gdb源码

建立配置文件,编译



3 cd jlink的安装目录运行#./JlinkGDBServer

SEGGER J-Link GDB Server V4.22



JLinkARM.dll V4.22 (DLL compiled Dec 17 2010 17:41:06)



Listening on TCP/IP port 2331



J-Link connected

Firmware: J-Link ARM V8 compiled Dec 16 2010 20:21:29

Hardware: V8.00

S/N: 20100214

Feature(s): RDI,FlashDL,FlashBP,JFlash,GDBFull



J-Link found 1 JTAG device, Total IRLen = 4

JTAG ID: 0x0032409D (ARM9)



4 运行生成elf文件,要加上-g选项生成调试符号信息。



5 程序当前目录下编译GDB配置文件.gdbinit

#

# This connects to a GDB Server listening

# for commands on localhost at tcp port 2331

target remote localhost:2331

# Set JTAG speed to 30 kHz

monitor speed 30

# Set GDBServer to big endian

monitor endian little

# Reset the chip to get to a known state.

monitor reset

#

# CPU core initialization (to be done by user)

#

# Set the processor mode

monitor reg cpsr = 0xd3

# Set auto JTAG speed

monitor speed auto

# Setup GDB FOR FASTER DOWNLOADS

set remote memory-write-packet-size 1024

set remote memory-write-packet-size fixed

# Load the program executable called "image.elf"

# load image.elf



6 运行arm-linux-gdb开始调试程序



[root@zax leds]# arm-linux-gdb leds_elf

GNU gdb (GDB) 7.2

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 "showcopying"

and "show warranty" for details.

This GDB was configured as "--host=x86_64-unknown-linux-gnu--target=arm-linux".

For bug reporting instructions, please see:

<http://www.gnu.org/software/gdb/bugs/>...

Reading symbols from/home/zax/Documents/hardware/leds/leds_elf...done.

_start () at crt0.S:9

9 ldr r0, =0x56000010

JTAG speed set to 30 kHz

Target endianess set to "little endian"

Resetting target

Writing register (CPSR = 0x000000D3)

Select auto JTAG speed (8000 kHz)

The target may not be able to correctly handle amemory-write-packet-size

of 1024 bytes. Change the packet size? (y or n) [answered Y; inputnot from terminal]

(gdb) load

Loading section .text, size 0x6c lma 0x0

Start address 0x0, load size 108

Transfer rate: 15 KB/sec, 108 bytes/write.

(gdb) list

4 @******************************************************************************

5

6 .text

7 .global _start

8 _start:

9 ldr r0, =0x56000010

10 mov r1, #0x0

11 str r1, [r0]

12

13 ldr sp, =1024*4

(gdb) s

10 mov r1, #0x0

(gdb) n

11 str r1, [r0]

(gdb) b main

Breakpoint 1 at 0x40: file leds.c, line 17.

(gdb) c

Continuing.



Breakpoint 1, main () at leds.c:17

17 unsigned long i = 0;

(gdb) n

19 GPBCON = GPB5_out|GPB6_out|GPB7_out|GPB8_out;

(gdb)

22 wait(30000);

(gdb)

23 GPBDAT = (~(i<<5)); 4

(gdb) b 23

Breakpoint 2 at 0x54: file leds.c, line 23.

(gdb) display /i pc

No symbol "pc" in current context.

(gdb) display /i $pc

1: x/i $pc

=> 0x54 <main+36>: mvn r3, r4, lsl #5

(gdb) c

Continuing.



Breakpoint 2, main () at leds.c:23

23 GPBDAT = (~(i<<5));

1: x/i $pc

=> 0x54 <main+36>: mvn r3, r4, lsl #5

(gdb)

Continuing.



Breakpoint 2, main () at leds.c:23

23 GPBDAT = (~(i<<5));

1: x/i $pc

=> 0x54 <main+36>: mvn r3, r4, lsl #5

(gdb)

Continuing.



Breakpoint 2, main () at leds.c:23

23 GPBDAT = (~(i<<5));

1: x/i $pc

=> 0x54 <main+36>: mvn r3, r4, lsl #5

(gdb)

Continuing.



Breakpoint 2, main () at leds.c:23

23 GPBDAT = (~(i<<5));

1: x/i $pc

=> 0x54 <main+36>: mvn r3, r4, lsl #5

(gdb) disconnect

Ending remote debugging.

(gdb) q



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值