📄 stabs.texinfo
字号:
@example136 .stabs "g_an_s:G16",32,0,0,0137 .common _g_an_s,20,"bss"@end exampleNotice that the structure tag has the same type number as the typedeffor the structure tag. It is impossible to distinguish between avariable of the struct type and one of its typedef by looking at thedebugging information.@node Unions@section Unions @table @strong@item Directive:@code{.stabs}@item Type:@code{N_LSYM}@item Symbol Descriptor:@code{T}@item Type Descriptor:@code{u}@end tableNext let's look at unions. In example2 this union type is declaredlocally to a procedure and an instance of the union is defined.@example36 union u_tag @{37 int u_int;38 float u_float;39 char* u_char;40 @} an_u;@end exampleThis code generates a stab for the union tag and a stab for the unionvariable. Both use the N_LSYM stab type. Since the union variable isscoped locally to the procedure in which it is defined, its stab islocated immediately preceding the N_LBRAC for the procedure's blockstart.The stab for the union tag, however is located preceding the code forthe procedure in which it is defined. The stab type is N_LSYM. Thiswould seem to imply that the union type is file scope, like the structtype s_tag. This is not true. The contents and position of the stabfor u_type do not convey any infomation about its procedure localscope.@display <128> N_LSYM - type .stabs "name:sym_desc(union tag)type_def(22)=type_desc(union) byte_size(4) elem_name:type_ref(int),bit_offset(0),bit_size(32); elem_name:type_ref(float),bit_offset(0),bit_size(32); elem_name:type_ref(ptr to char),bit_offset(0),bit_size(32);;" N_LSYM, NIL, NIL, NIL@end display@smallexample105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;", 128,0,0,0@end smallexampleThe symbol descriptor, T, following the name: means that the stabdescribes an enumeration struct or type tag. The type descriptor u,following the 23= of the type definition, narrows it down to a uniontype definition. Following the u is the number of bytes in the union.After that is a list of union element descriptions. Their format isname:type, bit offset into the union, and number of bytes for theelement;.The stab for the union variable follows. Notice that the framepointer offset for local variables is negative.@display <128> N_LSYM - local variable (with no symbol descriptor) .stabs "name:type_ref(u_tag)", N_LSYM, NIL, NIL, frame_ptr_offset@end display@example130 .stabs "an_u:23",128,0,0,-20@end example@node Function types@section Function types@displaytype descriptor f@end displayThe last type descriptor in C which remains to be described is usedfor function types. Consider the following source line defining aglobal function pointer.@example4 int (*g_pf)();@end exampleIt generates the following code. Since the variable is notinitialized, the code is located in the common area at the end of thefile.@display <32> N_GSYM - global variable .stabs "name:sym_desc(global)type_def(24)=ptr_to(25)= type_def(func)type_ref(int)@end display@example134 .stabs "g_pf:G24=*25=f1",32,0,0,0135 .common _g_pf,4,"bss"@end exampleSince the variable is global, the stab type is N_GSYM and the symboldescriptor is G. The variable defines a new type, 24, which is apointer to another new type, 25, which is defined as a functionreturning int.@node Symbol tables@chapter Symbol information in symbol tablesThis section examines more closely the format of symbol table entriesand how stab assembler directives map to them. It also describes whattransformations the assembler and linker make on data from stabs.Each time the assembler encounters a stab in its input file it putseach field of the stab into corresponding fields in a symbol tableentry of its output file. If the stab contains a string field, thesymbol table entry for that stab points to a string table entrycontaining the string data from the stab. Assembler labels becomerelocatable addresses. Symbol table entries in a.out have the format:@examplestruct internal_nlist @{ unsigned long n_strx; /* index into string table of name */ unsigned char n_type; /* type of symbol */ unsigned char n_other; /* misc info (usually empty) */ unsigned short n_desc; /* description field */ bfd_vma n_value; /* value of symbol */@};@end exampleFor .stabs directives, the n_strx field holds the character offsetfrom the start of the string table to the string table entrycontaining the "string" field. For other classes of stabs (.stabn and.stabd) this field is null.Symbol table entries with n_type fields containing a value greater orequal to 0x20 originated as stabs generated by the compiler (with onerandom exception). Those with n_type values less than 0x20 wereplaced in the symbol table of the executable by the assembler or thelinker.The linker concatenates object files and does fixups of externallydefined symbols. You can see the transformations made on stab data bythe assembler and linker by examining the symbol table after each passof the build, first the assemble and then the link.To do this use nm with the -ap options. This dumps the symbol table,including debugging information, unsorted. For stab entries thecolumns are: value, other, desc, type, string. For assembler andlinker symbols, the columns are: value, type, string.There are a few important things to notice about symbol tables. Wherethe value field of a stab contains a frame pointer offset, or aregister number, that value is unchanged by the rest of the build.Where the value field of a stab contains an assembly language label,it is transformed by each build step. The assembler turns it into arelocatable address and the linker turns it into an absolute address.This source line defines a static variable at file scope:@example3 static int s_g_repeat@end example@noindentThe following stab describes the symbol.@example26 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat@end example@noindentThe assembler transforms the stab into this symbol table entry in the@file{.o} file. The location is expressed as a data segment offset.@example21 00000084 - 00 0000 STSYM s_g_repeat:S1@end example@noindentin the symbol table entry from the executable, the linker has made therelocatable address absolute.@example22 0000e00c - 00 0000 STSYM s_g_repeat:S1@end exampleStabs for global variables do not contain location information. Inthis case the debugger finds location information in the assembler orlinker symbol table entry describing the variable. The source line:@example1 char g_foo = 'c';@end example@noindentgenerates the stab:@example21 .stabs "g_foo:G2",32,0,0,0@end exampleThe variable is represented by the following two symbol table entriesin the object file. The first one originated as a stab. The secondone is an external symbol. The upper case D signifies that the n_typefield of the symbol table contains 7, N_DATA with local linkage (seeTable B). The value field following the file's line number is emptyfor the stab entry. For the linker symbol it contains therellocatable address corresponding to the variable.@example19 00000000 - 00 0000 GSYM g_foo:G220 00000080 D _g_foo@end example@noindentThese entries as transformed by the linker. The linker symbol tableentry now holds an absolute address.@example21 00000000 - 00 0000 GSYM g_foo:G2@dots{}215 0000e008 D _g_foo@end example@node GNU C++ stabs@chapter GNU C++ stabs@menu* Basic C++ types::* Simple classes::* Class instance::* Methods:: Method definition* Protections::* Method Modifiers:: (const, volatile, const volatile)* Virtual Methods::* Inheritence::* Virtual Base Classes::* Static Members::@end menu@subsection Symbol descriptors added for C++ descriptions:@displayP - register parameter.@end display@subsection type descriptors added for C++ descriptions@table @code@item #method type (two ## if minimal debug)@item xscross-reference@end table@node Basic C++ types@section Basic types for C++<< the examples that follow are based on a01.C >>C++ adds two more builtin types to the set defined for C. These arethe unknown type and the vtable record type. The unknown type, type16, is defined in terms of itself like the void type.The vtable record type, type 17, is defined as a structure type andthen as a structure tag. The structure has four fields, delta, index,pfn, and delta2. pfn is the function pointer.<< In boilerplate $vtbl_ptr_type, what are the fields delta,index, and delta2 used for? >>This basic type is present in all C++ programs even if there are novirtual methods defined.@display.stabs "struct_name:sym_desc(type)type_def(17)=type_desc(struct)struct_bytes(8) elem_name(delta):type_ref(short int),bit_offset(0),field_bits(16); elem_name(index):type_ref(short int),bit_offset(16),field_bits(16); elem_name(pfn):type_def(18)=type_desc(ptr to)type_ref(void), bit_offset(32),field_bits(32); elem_name(delta2):type_def(short int);bit_offset(32),field_bits(16);;" N_LSYM, NIL, NIL@end display @smallexample.stabs "$vtbl_ptr_type:t17=s8 delta:6,0,16;index:6,16,16;pfn:18=*15,32,32;delta2:6,32,16;;" ,128,0,0,0@end smallexample@display.stabs "name:sym_dec(struct tag)type_ref($vtbl_ptr_type)",N_LSYM,NIL,NIL,NIL@end display@example.stabs "$vtbl_ptr_type:T17",128,0,0,0@end example@node Simple classes@section Simple class definition The stabs describing C++ language features are an extension of thestabs describing C. Stabs representing C++ class types elaborateextensively on the stab format used to describe structure types in C.Stabs representing class type variables look just like stabsrepresenting C language variables.Consider the following very simple class definition.@exampleclass baseA @{public: int Adat; int Ameth(int in, char other);@};@end exampleThe class baseA is represented by two stabs. The first stab describesthe class as a structure type. The second stab describes a structuretag of the class type. Both stabs are of stab type N_LSYM. Since thestab is not located between an N_FUN and a N_LBRAC stab this indicatesthat the class is defined at file scope. If it were, then the N_LSYMwould signify a local variable.A stab describing a C++ class type is similar in format to a stabdescribing a C struct, with each class member shown as a field in thestructure. The part of the struct format describing fields isexpanded to include extra information relevent to C++ class members.In addition, if the class has multiple base classes or virtualfunctions the struct format outside of the field parts is alsoaugmented.In this simple example the field part of the C++ class stabrepresenting member data looks just like the field part of a C structstab. The section on protections describes how its format issometimes extended for member data.The field part of a C++ class stab representing a member functiondiffers substantially from the field part of a C struct stab. Itstill begins with `name:' but then goes on to define a new type numberfor the member function, describe its return type, its argument types,its protection level, any qualifiers applied to the method definition,and whether the method is virtual or not. If the method is virtualthen the method description goes on to give the vtable index of themethod, and the type number of the first base class defining themethod. When the field name is a method name it is followed by two colonsrather than one. This is followed by a new type definition for themethod. This is a number followed by an equal sign and then thesymbol descriptor `##', indicating a method type. This is followed bya type reference showing the return type of the method and asemi-colon.The format of an overloaded operator method name differs from thatof other methods. It is "op$::XXXX." where XXXX is the operator namesuch as + or +=. The name ends with a period, and any characters exceptthe period can occur in the XXXX string.The next part of the method description represents the arguments tothe method, preceeded by a colon and ending with a semi-colon. Thetypes of the arguments are expressed in the same way argument typesare expressed in C++ name mangling. In this example an int and a charmap to `ic'.This is followed by a number, a letter, and an asterisk or period,followed by another semicolon. The number indicates the protectionsthat apply to the member function. Here the 2 means public. Theletter encodes any qualifier applied to the method definition. Inthis case A means that it is a normal function definition. The dotshows that the method is not virtual. The sections that followelaborate further on these fields and describe the additionalinformation present for virtual methods.@display.stabs "class_name:sym_desc(type)type_def(20)=type_desc(struct)struct_bytes(4) field_name(Adat):type(int),bit_offset(0),field_bits(32); method_name(Ameth)::type_def(21)=type_desc(method)return_type(int); :arg_types(int char); protection(public)qualifier(normal)virtual(no);;" N_LSYM,NIL,NIL,NIL@end display@smallexample.stabs "baseA:t20=s4Adat:1,0,32;Ameth::21=##1;:ic;2A.;;",128,0,0,0.stabs "class_name:sym_desc(struct tag)",N_LSYM,NIL,NIL,NIL.stabs "baseA:T20",128,0,0,0@end smallexample@node Class instance@section Class instanceAs shown above, describing even a simple C++ class definition isaccomplished by massively extending the stab format used in C to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -