gdb debug 信息 stabs 格式

6 篇文章 0 订阅

gdb debug 信息 stabs 格式

stabs是用来做调试的信息,存储在符号表中。 名称来自symbol table entries。

这里是英文的介绍 :http://www.math.utah.edu/docs/info/stabs_toc.html

还有这里 : http://sourceware.org/gdb/current/onlinedocs/stabs/index.html

debug信息流程:

GNU C 编译器把c源代码编译成汇编语言.s文件, .s文件然后被翻译成.o文件,.o文件被链接成可执行文件。

如果编译的时候加了-g 参数 , gcc 会添加额外的调试信息到.s文件中。 这些调试信息最终被带到可执行文件中。这些调试信息包含了源文件的行号,类型变量,函数,以及他们的参数及作用域等等。

对于某些目标文件格式,这些调试信息放在.stab后面,这些信息分散在生成的代码中间。stabs是a.out和xcoff目标文件的原原生格式。GNU工具也可以在coff和ecoff目标文件中加入stabs格式。

汇编器把stabs信息添加到目标文件的符号表和字串表中。链接器再把所有目标文件中的符号表和字串表合并成一个。调试器会最终使用可执行文件中的这两个表最为调试信息的来源。

stabs格式概述

stabs格式中有三个关键字 .stabs (string), .stabn (number), or .stabd (dot).

每种类型的格式为:

.stabs "string",type,0,desc,value
.stabn          type,0,desc,value
.stabd          type,0,desc

.stabs 中 , string 域包含名字和类型信息。

.stabd 中, value 域是隐含的,为当前文件所在的位置,否则,value 域为重定向表的地址,函数帧指针偏移或者寄存器数.

理解stab的关键在于type域,每个可能的type数字定义了一种stab类型,而stab类型进一步定义了其string,desc,value的解释方式。表A 列出了所有可能的type域的值。

.stabs 的 "string" 域则包含了调试信息。这里的格式并没有预先定义下来,这保留了stabs格式的可扩展性。对某些stab类型,string域仅仅包含一个名字,对于另外一些stab类型而言,其中的内容可能是非常复杂的。

"string" 域的格式为:

"name[:symbol_descriptor]
     [type_number[=type_descriptor ...]]"

name 是stab记录的符号的名字。

symbol_descriptor 为字符描述信息,如果这个域没有但是有类型信息,那么这个stab表示一个局部变量。表C中列出了所有的 symbol_descriptors.

类型信息要么是 type_number,要么是  `type_number=’. 单单的 type_number 是一个类型引用,指向一个已经定义的类型。

`type_number=’ 是一个类型定义, 其中数字表示一个即将定义的新类型,这个类型定义可以通过数字引用其他的类型,这些类型值可以通过=来进行递归定义。

在类型定义中,如果=后不是数字,那么他就是一个类型描述,说明什么样的类型将被定义。在类型描述()后可能跟各种东西这个据每种不同的类型而定。如果=后是一个数字,那么这个数字就是一个类型引用。表D 是所有类型描述的列表。

如上所述,sring域可能很长,当string太长时,编译器可以可以把一个stabs分成两个,这两个stabs除了string意外,完全一样。只是第一个stabs的string以双反斜杠结尾。

一个C源码实例

main()
{
printf(“Hello world”);
}

当编译时添加-g参数时,会生成下面的.s文件,行号是后加上去的.

The simple example at the assembly level

1  gcc2_compiled.:
2  .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
3  .stabs "hello.c",100,0,0,Ltext0
4  .text
5  Ltext0:
6  .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
7  .stabs "char:t2=r2;0;127;",128,0,0,0
8  .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
9  .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
10 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
11 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
12 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
13 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
14 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
15 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
16 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
17 .stabs "float:t12=r1;4;0;",128,0,0,0
18 .stabs "double:t13=r1;8;0;",128,0,0,0
19 .stabs "long double:t14=r1;8;0;",128,0,0,0
20 .stabs "void:t15=15",128,0,0,0
21      .align 4
22 LC0:
23      .ascii "Hello, world!\12\0"
24      .align 4
25      .global _main
26      .proc 1
27 _main:
28 .stabn 68,0,4,LM1
29 LM1:
30      !#PROLOGUE# 0
31      save %sp,-136,%sp
32      !#PROLOGUE# 1
33      call ___main,0
34      nop
35 .stabn 68,0,5,LM2
36 LM2:
37 LBB2:
38      sethi %hi(LC0),%o1
39      or %o1,%lo(LC0),%o0
40      call _printf,0
41      nop
42 .stabn 68,0,6,LM3
43 LM3:
44 LBE2:
45 .stabn 68,0,6,LM4
46 LM4:
47 L1:
48      ret
49      restore
50 .stabs "main:F1",36,0,0,_main
51 .stabn 192,0,0,LBB2
52 .stabn 224,0,0,LBE2
要详细解释上面的代码,需要进入顶上的页面进行逐行分析。上面的页面细致的解释了每种类型的详细格式。
另外这里有一篇文章,关于如何查看二进制文件中是否有debug信息。
http://www.dedoimedo.com/computers/linux-cool-hacks-4.html

Table A: Symbol types from stabs

Table A lists stab types sorted by type number. Stab type numbers are 32 and greater. This is the full list of stab numbers, including stab types that are used in languages other than C.

The #define names for these stab types are defined in: devo/include/aout/stab.def
type   type     #define   used to describe
dec    hex      name      source program feature
------------------------------------------------
32     0x20     N_GYSM    global symbol
34     0X22     N_FNAME   function name (for BSD Fortran)
36     0x24     N_FUN     function name or text segment variable for C
38     0x26     N_STSYM   static symbol (data segment w/internal linkage)
40     0x28     N_LCSYM   .lcomm symbol(BSS-seg variable w/internal linkage)
42     0x2a     N_MAIN    Name of main routine (not used in C)
48     0x30     N_PC      global symbol (for Pascal)
50     0x32     N_NSYMS   number of symbols (according to Ultrix V4.0)
52     0x34     N_NOMAP   no DST map for sym (according to Ultrix V4.0)
64     0x40     N_RSYM    register variable
66     0x42     N_M2C     Modula-2 compilation unit
68     0x44     N_SLINE   line number in text segment
70     0x46     N_DSLINE  line number in data segment

72     0x48     N_BSLINE  line number in bss segment
72     0x48     N_BROWS   Sun source code browser, path to .cb file

74     0x4a     N_DEFD    GNU Modula2 definition module dependency

80     0x50     N_EHDECL  GNU C++ exception variable
80     0x50     N_MOD2    Modula2 info "for imc" (according to Ultrix V4.0)

84     0x54     N_CATCH   GNU C++ "catch" clause
96     0x60     N_SSYM    structure of union element
100    0x64     N_SO      path and name of source file
128    0x80     N_LSYM    automatic var in the stack
                          (also used for type desc.)
130    0x82     N_BINCL   beginning of an include file (Sun only)
132    0x84     N_SOL     Name of sub-source (#include) file.
160    0xa0     N_PSYM    parameter variable
162    0xa2     N_EINCL   end of an include file
164    0xa4     N_ENTRY   alternate entry point
192    0xc0     N_LBRAC   beginning of a lexical block
194    0xc2     N_EXCL    place holder for a deleted include file
196    0xc4     N_SCOPE   modula2 scope information (Sun linker)
224    0xe0     N_RBRAC   end of a lexical block
226    0xe2     N_BCOMM   begin named common block
228    0xe4     N_ECOMM   end named common block
232    0xe8     N_ECOML   end common (local name)

       << used on Gould systems for non-base registers syms >>
240    0xf0     N_NBTEXT  ??
242    0xf2     N_NBDATA  ??
244    0xf4     N_NBBSS   ??
246    0xf6     N_NBSTS   ??
248    0xf8     N_NBLCS   ??

Table B: Symbol types from assembler and linker

Table B shows the types of symbol table entries that hold assembler and linker symbols.

The #define names for these n_types values are defined in /include/aout/aout64.h

dec     hex     #define
n_type  n_type  name      used to describe
------------------------------------------
1       0x0     N_UNDF    undefined symbol
2       0x2     N_ABS     absolute symbol -- defined at a particular address
3       0x3             extern " (vs. file scope)
4       0x4     N_TEXT    text symbol -- defined at offset in text segment
5       0x5             extern " (vs. file scope)
6       0x6     N_DATA    data symbol -- defined at offset in data segment
7       0x7             extern " (vs. file scope)
8       0x8     N_BSS     BSS symbol -- defined at offset in zero'd segment
9                       extern " (vs. file scope)

12      0x0C    N_FN_SEQ  func name for Sequent compilers (stab exception)

49      0x12    N_COMM    common sym -- visable after shared lib dynamic link
31      0x1f    N_FN      file name of a .o file

Table C: Symbol descriptors

descriptor      meaning
-------------------------------------------------
(empty)         local variable
   f            local function
   F            global function
   G            global variable
   p            value parameter
   r            register variable
   S            static global variable
   t            type name
   T            enumeration, struct or type tag
   V            static local variable

Table D: Type Descriptors

descriptor      meaning
-------------------------------------
(empty)         type reference
   a            array type
   e            enumeration type
   f            function type
   r            range type
   s            structure type
   u            union specifications
   *            pointer type

本文地址: http://www.bagualu.net/wordpress/archives/2349 转载请注明


  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值