[转]GDBINT gdb internal Notes …
来源:互联网 发布:阿里云静态资源 编辑:程序博客网 时间:2024/06/09 07:37
Addinga New Target
为了建立一个target,需要添加以下文件:
gdb/config/arch/ttt.mt
gdb/ttt-tdep.c
gdb/arch-tdep.c
gdb/arch-tdep.h registers, stack ...的描述, it is included by`ttt-tdep.h'.
如果是为一个新的os添加支持(cpu已存在),则只需要添加`config/tm-os.h' ,描述此os的特殊facilities即可,比如extra symbol table info;the breakpoint instruction needed; 等等),然后写一个`arch/tm-os.h',就include`tm-arch.h'和config/tm-os.h即可.
TargetDescriptions
Target DescriptionsImplementation
Adding Target DescribedRegister Support
Targetdescriptions通过体系特定的支持函数,可以报告更多的寄存器到target.
一个targetdescription或者没有寄存器,或者有完整的寄存器集.
如果 tdesc_has_registers 返回1,代表这个description包含寄存器,architecture's gdbarch_init函数应该完成如下功能:
- 通过tdesc_data_alloc分配内存(在搜索匹配的gdbarch后者分配新的之前进行)
- 通过tdesc_find_feature,根据name确定标准属性集.
- 通过tdesc_numbered_register 和tdesc_numbered_register_choices 确定standard features需要的registers.
- 如果需要的feature缺失,返回NULL, 如standardfeature缺失必要寄存器,返回NULL.
- 释放分配的数据,除非调用了tdesc_use_registers.
- Call set_gdbarch_num_regs asusual, with a number higher than any fixed number passed totdesc_numbered_register.
- 返回新创建的gdbarch之前,调用tdesc_use_registers.
调用tdesc_use_registers后,这个architecture的register_name, register_type, 和 register_reggroup_proutines将不会被调用;这些信息将从target description获取. num_regs或许增加,因为可能有新的寄存器加进来.
Pseudo-registers require some extracare:
- Using tdesc_numbered_registerallows the architecture to give constant register numbers tostandard architectural registers, e.g. as an enum in `arch-tdep.h'.But because pseudo-registers are always numbered above num_regs,which may be increased by the description, constant numbers can notbe used for pseudos. They must be numbered relative to num_regsinstead.
- The description will not describepseudo-registers, so the architecture must callset_tdesc_pseudo_register_name, set_tdesc_pseudo_register_type, andset_tdesc_pseudo_register_reggroup_p to supply routines describingpseudo registers. These routines will be passed internal registernumbers, so the same routines used for the gdbarch equivalents areusually suitable.
http://sourceware.org/ml/gdb-patches/2000-07/msg00127.html
Target VectorDefinition
Managing Execution State
completelyinactive
active but not running:pushed, butnot connected to a fully manifested inferior
completelyactive
persistent connections to a targeteven when the target has exited or not yet started.如:
使用targetsim连接到simulator是,并不创建进程,寄存器和内存在run前都不可访问.类似的,kill之后,程序也不能继续运行.但是这两种情况下GDB仍然连接到simulator.
如果target仅仅支持completeactivation,则在其to_open函数中,应该使用push_target将自己压入堆栈(rfc),在其to_mourn_inferior函数中通过unpush_target将自己出栈.
如果target支持partial和completeactivation,就不应该在to_mourn_inferior中出栈(但是仍然需要在to_open中入栈),而应调用target_mark_running或者target_mark_exited. 只要任何时候inferior fullyactive就应该调用target_mark_running(如在to_create_inferior和to_attach中),而inferior inactive(to_mourn_inferior)时就掉用target_mark_exited.在to_kill中,应该调用target_mourn_inferior确保target进入inactive状态.
Existing Targets
File Targets
executables 和 core files 都有targetvectors.
Standard Protocol and RemoteStubs
GDB 文件remote.c 通过串口和targetsystem通讯.GDB 提供一系列的stubs:stub集成到target系统中作为GDB的通讯断点.其名称一般是*-stub.c.
stub中的trap处理代码假设trap_low的接口如下:
- %l1 和 %l2 分别包含pc 和 npc;
- traps 以禁止;
- 已经在正确的trap window(rfc).
满足以上条件时,可以从hw trapvector直接跳到stub.一般情况下stub使用的trap,操作系统是不使用的(一般是不可恢复性错误),也没有共享问题(有也可以支持).最重要的trap之一ta 1(rfc):用于单步执行或者breakpoint.
这里有个remote stub的参考文档:http://sca.uwaterloo.ca/coldfire/gcc-doc/docs/porting_4.html
Native Debugging
如下文件控制native support的配置:
许多通用函数可以为很多系统共享,如果你的系统可以使用这些函数,使用NATDEPFILES定义所需要的.o即可.否则,你需要重新实现这些函数,并放到xyz-nat.c中.
`inftarg.c' 包含
Native core fileSupport
当 在一个新的OS上运行GDBnative时,为了确保能够调试core file,就要写代码支持解析这个OS的corefile,或者修改`bfd/trad-core.c'. 首先,定义一个寄存器结构来描述OS Core file中的寄存器(比如corefile 的u-area),将定义core file header的头文件包含进来(u-area or a struct core).然后,修改trad_unix_core_file_p 使用这些信息建立core file总的data segment, stacksegment和其他段的信息(shared library ,control information), 以及"registers"segment(如果有两组寄存器,比如integer和float),即 "reg2" segment. 这些section的信息使BFD知道如何从corefile读取这些信息.然后,修改GDB:定义fetch_core_registers,使用通用的core-aout.c,或者自己的`xyz-nat.c'.GDB使用这个函数来将寄存器的值转移到GDB的"registers" array中.
`nm-system.h'中可能存在的configure:
[Note that this is incorrectlydefined in `xm-system.h' files currently.]
SupportLibrariesBFD
access to sections offiles
广泛用于binutils.提供反汇编支持.
readlinelibiberty
此库提供一系列的函数用于补足,替换和扩展操作系统提供的功能.GDB使用很多这个库提供的特性:如 C++demangler,IEEE
obstacks in GDB
主要用于object files管理.每个obj文件有一个对应的obstack,许多对象在obstack上分配:....(略)
Regexconditionals.
Array Containers
see `vec.h' (略)
例子:
DEF_VEC_P(tree); //non-managed tree vector.struct my_struct {
VEC(tree) *v; // A (pointer to) a vector of treepointers.
};
struct my_struct *s;
if (VEC_length(tree, s->v)) { we have somecontents }
VEC_safe_push(tree, s->v, decl); // append somedecl onto the end
for (ix = 0; VEC_iterate(tree, s->v, ix, elt);ix++)
{ do something with elt }其他接口函数:
VEC_length
Cleanups
Cleanups 是GDB使用的一个通用机制.cleanup会在以后的合适时间执行:命令完成,error处理等.
使用方式:
struct cleanup *old_chain;
Per-architecture moduledata
向gdbarch 添加module specificper-architecture data-pointers的机制:(see GDBINT)
Function:These functions return a structgdbarch_data that is used to identify the per-architecturedata-pointer added for that module.
The per-architecture data-pointeris accessed using the function:
Function:Wrapping OutputLines
输出换行的标准. 细节参考GDBINT.
GDB Coding Standards以下部分请参考GDBINT.
ISO C
GDB assumes an ISO/IEC 9899:1990(a.k.a. ISO C90) compliant compiler.
GDB does not assume an ISO C orPOSIX compliant C library.
GDB does not use the functionsmalloc, realloc, calloc, free and asprintf.
GDB uses the functions xmalloc,xrealloc and xcalloc....
CompilerWarnings
所有操作target的函数必须使用 target_opsvector.不能假定host和target是同一台机器(除了native),尤其不能假定target机器的头文件可以在host上使用.
more detail see GDBINT在新的machine上编译GDB需要很多配置工作,需要修改许多头文件和配置脚本.假定新的host是xyz (e.g.,`sun4'), 其配置名是 arch-xvend-xos (e.g., `sparc-sun-sunos4') :
- 在根目录,编辑 `config.sub' 添加 arch,xvend, and xos到architecture列表.添加xyz作为arch-xvend-xos的别名.运行以下命令测试修改:
./config.subxyz
./config.sub arch-xvend-xos
(或许需要port BFD)
- 配置GDB:编辑`gdb/configure.host'时期认识你的系统,设置 gdb_host 为 xyz,编辑`gdb/configure.tgt',设置gdb_target为合适值,如xyz.
- 最后,开始写对应的host-,native-,
target-dependent的 `.h' 和 `.c'文件.......(不少啊).
Other
为完整性,以下部分没有阅读,这些部分描述GDB的代码配置管理部分内容,以及代码阅读的一些提示:16. Versions and Branches
17. Start of New YearProcedure
18. Releasing GDB
19. Testsuite
20. Hints
A. GDB Currently availableobservers
B. GNU Free DocumentationLicense
转自:http://hi.baidu.com/systemsoftware/blog/item/7b33333d69cf9e0ebba16772
- [转]GDBINT gdb internal Notes …
- [转]GDBINT gdb internal Notes …
- [转]GDBINT gdb internal Notes …
- [转]GDBINT gdb internal Notes …
- [转]GDBINT gdb internal Notes …
- [转]GDBINT gdb internal Notes …
- [转] 彼尔…
- ORA-00700: soft internal error, …
- ORA-00600: internal er…
- [转]GCC 4.6 warning: variable …
- [转]GCC 4.6 warning: variable …
-  
- Lotus Notes 中Sametime 无法自动…
- 集线器 交换机 路由器 网桥 …
- HTTP 错误 500.0 - Internal Serve…
- HTTP error 500 Internal server e…
-
- 使用BBED修改SCN …
- [转] linux的压缩解压命令 —— tar…
- linux的命令混合使用
- [转]Gdb/Armulator 源代码分析
- [转]GDBINT gdb internal Notes …
- [转]GDBINT gdb internal Notes …
- [转]GDBINT gdb internal Notes …
- undefined reference to 'pthread_…
- 【转】gcc命令
- [转]Linux下运行OProfile进行系…
- [转]linux shell if 参数
- [转]再谈shell之“>/dev/null 2>&…
- [转]逃离x86架构
- [转]CPU体系结构CISC与RISC之争
- [转]int* p[2] 与 int (*p)[2]…