⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stabs.texinfo

📁 这个是LINUX下的GDB调度工具的源码
💻 TEXINFO
📖 第 1 页 / 共 5 页
字号:
When compiled with @samp{-g}, the program above yields the following@file{.s} file.  Line numbers have been added to make it easier to referto parts of the @file{.s} file in the description of the stabs thatfollows.@node Assembly Code@section The Simple Example at the Assembly LevelThis simple ``hello world'' example demonstrates several of the stabtypes used to describe C language source files.@example1  gcc2_compiled.:2  .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext03  .stabs "hello.c",100,0,0,Ltext04  .text5  Ltext0:6  .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,07  .stabs "char:t2=r2;0;127;",128,0,0,08  .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,09  .stabs "unsigned int:t4=r1;0;-1;",128,0,0,010 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,011 .stabs "short int:t6=r1;-32768;32767;",128,0,0,012 .stabs "long long int:t7=r1;0;-1;",128,0,0,013 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,014 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,015 .stabs "signed char:t10=r1;-128;127;",128,0,0,016 .stabs "unsigned char:t11=r1;0;255;",128,0,0,017 .stabs "float:t12=r1;4;0;",128,0,0,018 .stabs "double:t13=r1;8;0;",128,0,0,019 .stabs "long double:t14=r1;8;0;",128,0,0,020 .stabs "void:t15=15",128,0,0,021      .align 422 LC0:23      .ascii "Hello, world!\12\0"24      .align 425      .global _main26      .proc 127 _main:28 .stabn 68,0,4,LM129 LM1:30      !#PROLOGUE# 031      save %sp,-136,%sp32      !#PROLOGUE# 133      call ___main,034      nop35 .stabn 68,0,5,LM236 LM2:37 LBB2:38      sethi %hi(LC0),%o139      or %o1,%lo(LC0),%o040      call _printf,041      nop42 .stabn 68,0,6,LM343 LM3:44 LBE2:45 .stabn 68,0,6,LM446 LM4:47 L1:48      ret49      restore50 .stabs "main:F1",36,0,0,_main51 .stabn 192,0,0,LBB252 .stabn 224,0,0,LBE2@end example@node Program Structure@chapter Encoding the Structure of the ProgramThe elements of the program structure that stabs encode include the nameof the main function, the names of the source and include files, theline numbers, procedure names and types, and the beginnings and ends ofblocks of code.@menu* Main Program::		Indicate what the main program is* Source Files::		The path and name of the source file* Include Files::               Names of include files* Line Numbers::* Procedures::* Nested Procedures::* Block Structure::* Alternate Entry Points::      Entering procedures except at the beginning.@end menu@node Main Program@section Main Program@findex N_MAINMost languages allow the main program to have any name.  The@code{N_MAIN} stab type tells the debugger the name that is used in thisprogram.  Only the string field is significant; it is the name ofa function which is the main program.  Most C compilers do not use thisstab (they expect the debugger to assume that the name is @code{main}),but some C compilers emit an @code{N_MAIN} stab for the @code{main}function.  I'm not sure how XCOFF handles this.@node Source Files@section Paths and Names of the Source Files@findex N_SOBefore any other stabs occur, there must be a stab specifying the sourcefile.  This information is contained in a symbol of stab type@code{N_SO}; the string field contains the name of the file.  Thevalue of the symbol is the start address of the portion of thetext section corresponding to that file.Some compilers use the desc field to indicate the language of thesource file.  Sun's compilers started this usage, and the firstconstants are derived from their documentation.  Languages addedby gcc/gdb start at 0x32 to avoid conflict with languages Sun mayadd in the future.  A desc field with a value 0 indicates that nolanguage has been specified via this mechanism.@table @asis@item @code{N_SO_AS} (0x1)Assembly language@item @code{N_SO_C}  (0x2)K&R traditional C@item @code{N_SO_ANSI_C} (0x3)ANSI C@item @code{N_SO_CC}  (0x4)C++@item @code{N_SO_FORTRAN} (0x5)Fortran@item @code{N_SO_PASCAL} (0x6)Pascal@item @code{N_SO_FORTRAN90} (0x7)Fortran90@item @code{N_SO_OBJC} (0x32)Objective-C@item @code{N_SO_OBJCPLUS} (0x33)Objective-C++@end tableSome compilers (for example, GCC2 and SunOS4 @file{/bin/cc}) alsoinclude the directory in which the source was compiled, in a second@code{N_SO} symbol preceding the one containing the file name.  Thissymbol can be distinguished by the fact that it ends in a slash.  Codefrom the @code{cfront} C@t{++} compiler can have additional @code{N_SO} symbols fornonexistent source files after the @code{N_SO} for the real source file;these are believed to contain no useful information.For example:@example.stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0     # @r{100 is N_SO}.stabs "hello.c",100,0,0,Ltext0        .textLtext0:@end example@findex C_FILEInstead of @code{N_SO} symbols, XCOFF uses a @code{.file} assemblerdirective which assembles to a @code{C_FILE} symbol; explaining this indetail is outside the scope of this document.@c FIXME: Exactly when should the empty N_SO be used?  Why?If it is useful to indicate the end of a source file, this is done withan @code{N_SO} symbol with an empty string for the name.  The value isthe address of the end of the text section for the file.  For somesystems, there is no indication of the end of a source file, and youjust need to figure it ended when you see an @code{N_SO} for a differentsource file, or a symbol ending in @code{.o} (which at least somelinkers insert to mark the start of a new @code{.o} file).@node Include Files@section Names of Include FilesThere are several schemes for dealing with include files: thetraditional @code{N_SOL} approach, Sun's @code{N_BINCL} approach, and theXCOFF @code{C_BINCL} approach (which despite the similar name has little incommon with @code{N_BINCL}).@findex N_SOLAn @code{N_SOL} symbol specifies which include file subsequent symbolsrefer to.  The string field is the name of the file and the value is thetext address corresponding to the end of the previous include file andthe start of this one.  To specify the main source file again, use an@code{N_SOL} symbol with the name of the main source file.@findex N_BINCL@findex N_EINCL@findex N_EXCLThe @code{N_BINCL} approach works as follows.  An @code{N_BINCL} symbolspecifies the start of an include file.  In an object file, only thestring is significant; the linker puts data into some of the otherfields.  The end of the include file is marked by an @code{N_EINCL}symbol (which has no string field).  In an object file, there is nosignificant data in the @code{N_EINCL} symbol.  @code{N_BINCL} and@code{N_EINCL} can be nested.If the linker detects that two source files have identical stabs betweenan @code{N_BINCL} and @code{N_EINCL} pair (as will generally be the casefor a header file), then it only puts out the stabs once.  Eachadditional occurrence is replaced by an @code{N_EXCL} symbol.  I believethe GNU linker and the Sun (both SunOS4 and Solaris) linker are the onlyones which supports this feature.A linker which supports this feature will set the value of a@code{N_BINCL} symbol to the total of all the characters in the stabsstrings included in the header file, omitting any file numbers.  Thevalue of an @code{N_EXCL} symbol is the same as the value of the@code{N_BINCL} symbol it replaces.  This information can be used tomatch up @code{N_EXCL} and @code{N_BINCL} symbols which have the samefilename.  The @code{N_EINCL} value, and the values of the other anddescription fields for all three, appear to always be zero.@findex C_BINCL@findex C_EINCLFor the start of an include file in XCOFF, use the @file{.bi} assemblerdirective, which generates a @code{C_BINCL} symbol.  A @file{.ei}directive, which generates a @code{C_EINCL} symbol, denotes the end ofthe include file.  Both directives are followed by the name of thesource file in quotes, which becomes the string for the symbol.The value of each symbol, produced automatically by the assemblerand linker, is the offset into the executable of the beginning(inclusive, as you'd expect) or end (inclusive, as you would not expect)of the portion of the COFF line table that corresponds to this includefile.  @code{C_BINCL} and @code{C_EINCL} do not nest.@node Line Numbers@section Line Numbers@findex N_SLINEAn @code{N_SLINE} symbol represents the start of a source line.  Thedesc field contains the line number and the value contains the codeaddress for the start of that source line.  On most machines the addressis absolute; for stabs in sections (@pxref{Stab Sections}), it isrelative to the function in which the @code{N_SLINE} symbol occurs.@findex N_DSLINE@findex N_BSLINEGNU documents @code{N_DSLINE} and @code{N_BSLINE} symbols for linenumbers in the data or bss segments, respectively.  They are identicalto @code{N_SLINE} but are relocated differently by the linker.  Theywere intended to be used to describe the source location of a variabledeclaration, but I believe that GCC2 actually puts the line number inthe desc field of the stab for the variable itself.  GDB has beenignoring these symbols (unless they contain a string field) sinceat least GDB 3.5.For single source lines that generate discontiguous code, such as flowof control statements, there may be more than one line number entry forthe same source line.  In this case there is a line number entry at thestart of each code range, each with the same line number.XCOFF does not use stabs for line numbers.  Instead, it uses COFF linenumbers (which are outside the scope of this document).  Standard COFFline numbers cannot deal with include files, but in XCOFF this is fixedwith the @code{C_BINCL} method of marking include files (@pxref{IncludeFiles}).@node Procedures@section Procedures@findex N_FUN, for functions@findex N_FNAME@findex N_STSYM, for functions (Sun acc)@findex N_GSYM, for functions (Sun acc)All of the following stabs normally use the @code{N_FUN} symbol type.However, Sun's @code{acc} compiler on SunOS4 uses @code{N_GSYM} and@code{N_STSYM}, which means that the value of the stab for the functionis useless and the debugger must get the address of the function fromthe non-stab symbols instead.  On systems where non-stab symbols haveleading underscores, the stabs will lack underscores and the debuggerneeds to know about the leading underscore to match up the stab and thenon-stab symbol.  BSD Fortran is said to use @code{N_FNAME} with thesame restriction; the value of the symbol is not useful (I'm not sure itreally does use this, because GDB doesn't handle this and no one hascomplained).@findex C_FUNA function is represented by an @samp{F} symbol descriptor for a global(extern) function, and @samp{f} for a static (local) function.  Fora.out, the value of the symbol is the address of the start of thefunction; it is already relocated.  For stabs in ELF, the SunPROcompiler version 2.0.1 and GCC put out an address which gets relocatedby the linker.  In a future release SunPRO is planning to put out zero,in which case the address can be found from the ELF (non-stab) symbol.Because looking things up in the ELF symbols would probably be slow, I'mnot sure how to find which symbol of that name is the right one, andthis doesn't provide any way to deal with nested functions, it wouldprobably be better to make the value of the stab an address relative tothe start of the file, or just absolute.  See @ref{ELF LinkerRelocation} for more information on linker relocation of stabs in ELFfiles.  For XCOFF, the stab uses the @code{C_FUN} storage class and thevalue of the stab is meaningless; the address of the function can befound from the csect symbol (XTY_LD/XMC_PR).The type information of the stab represents the return type of thefunction; thus @samp{foo:f5} means that foo is a function returning type5.  There is no need to try to get the line number of the start of thefunction from the stab for the function; it is in the next@code{N_SLINE} symbol.@c FIXME: verify whether the "I suspect" below is true or not.Some compilers (such as Sun's Solaris compiler) support an extension forspecifying the types of the arguments.  I suspect this extension is notused for old (non-prototyped) function definitions in C.  If theextension is in use, the type information of the stab for the functionis followed by type information for each argument, with each argumentpreceded by @samp{;}.  An argument type of 0 means that additionalarguments are being passed, whose types and number may vary (@samp{...}in ANSI C).  GDB has tolerated this extension (parsed the syntax, if notnecessarily used the information) since at least version 4.8; I don'tknow whether all versions of dbx tolerate it.  The argument types givenhere are not redundant with the symbols for the formal parameters(@pxref{Parameters}); they are the types of the arguments as they arepassed, before any conversions might take place.  For example, if a Cfunction which is declared without a prototype takes a @code{float}argument, the value is passed as a @code{double} but then converted to a@code{float}.  Debuggers need to use the types given in the argumentswhen printing values, but when calling the function they need to use thetypes given in the symbol defining the function.If the return type and types of arguments of a function which is defined

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -