Gdb/Armulator 源代码分析
作者Email: Anti_chen2000@sohu.com 摘要 Gdb/Armulator 是Gdb自带的arm7模拟器,是调试arm程序的一个好工具.而了解它的原码结构对扩展它的IO功能有重要意义.本文介绍了从Armulator的启动到其内部运作和IO扩展的大部分原代码功能. 说明 源代码用的是gdb-5.0.tar+ gdb-5.0-uclinux-armulator-20021127.patch A. 和GDB间的通迅 Armulator一般和Gdb通讯有两种方式,其一是在Gdb内部直接调用模拟器的相关函数,另一方法则是用pipe或socket传递RDP协议来连接Gdb和Amulator.而第一种方法是现在Gdb/Armulator所真正使用的(第二种是早期使用的方法),下面就分析了函数直接调用法. 函数直接调用 这个方法是由Steve (sac@cygnus.com) 修改原RDP方法而来的,Steve本人的描述如下: /****************************************************** This directory contains the standard release of the ARMulator from Advanced RISC Machines, and was ftp"d from. ftp.cl.cam.ac.uk:/arm/gnu It likes to use TCP/IP between the simulator and the host, which is nice, but is a pain to use under anything non-unix. I"ve added created a new Makefile.in (the original in Makefile.orig) to build a version of the simulator without the TCP/IP stuff, and a wrapper.c to link directly into gdb and the run command. It should be possible (barring major changes in the layout of the armulator) to upgrade the simulator by copying all the files out of a release into this directory and renaming the Makefile. (Except that I changed armos.c to work more simply with our simulator rigs) ********************************************************/ db/target.c,/gdb/remote_sim.c以及在/sim/arm/wrapper.c是在Armulator和Gdb的通信中起着至关重要做用的几个文件.所有的Gdb调试命令最后都是通过在target.h里定义的target_ops结构中的函数指针调用在/sim/arm /wrapper.c中型如sim_xxx的函数完成的.以前这些sim_xxx函数是位于/sim/common中的,是建立RDP通讯的关键,代码修改后此目录中的文件不再有用,被wrapper.c取而代之了. 以下是RDP 通讯和直接函数调用的图示: