URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [trunk/] [insight/] [gdb/] [doc/] [stabs.info-1] - Rev 1765
Compare with Previous | Blame | View Log
This is stabs.info, produced by makeinfo version 4.0 from./stabs.texinfo.START-INFO-DIR-ENTRY* Stabs: (stabs). The "stabs" debugging information format.END-INFO-DIR-ENTRYThis document describes the stabs debugging symbol tables.Copyright 1992,1993,1994,1995,1997,1998,2000,2001 Free SoftwareFoundation, Inc. Contributed by Cygnus Support. Written by JuliaMenapace, Jim Kingdon, and David MacKenzie.Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.1 orany later version published by the Free Software Foundation; with theInvariant Sections being "Stabs Types" and "Stabs Sections", with theFront-Cover texts being "A GNU Manual," and with the Back-Cover Textsas in (a) below.(a) The FSF's Back-Cover Text is: "You have freedom to copy andmodify this GNU Manual, like GNU software. Copies published by the FreeSoftware Foundation raise funds for GNU development."File: stabs.info, Node: Top, Next: Overview, Up: (dir)The "stabs" representation of debugging information***************************************************This document describes the stabs debugging format.* Menu:* Overview:: Overview of stabs* Program Structure:: Encoding of the structure of the program* Constants:: Constants* Variables::* Types:: Type definitions* Symbol Tables:: Symbol information in symbol tables* Cplusplus:: Stabs specific to C++* Stab Types:: Symbol types in a.out files* Symbol Descriptors:: Table of symbol descriptors* Type Descriptors:: Table of type descriptors* Expanded Reference:: Reference information by stab type* Questions:: Questions and anomalies* Stab Sections:: In some object file formats, stabs arein sections.* Symbol Types Index:: Index of symbolic stab symbol type names.File: stabs.info, Node: Overview, Next: Program Structure, Prev: Top, Up: TopOverview of Stabs*****************"Stabs" refers to a format for information that describes a programto a debugger. This format was apparently invented by Peter Kessler atthe University of California at Berkeley, for the `pdx' Pascaldebugger; the format has spread widely since then.This document is one of the few published sources of documentation onstabs. It is believed to be comprehensive for stabs used by C. Thelists of symbol descriptors (*note Symbol Descriptors::) and typedescriptors (*note Type Descriptors::) are believed to be completelycomprehensive. Stabs for COBOL-specific features and for variantrecords (used by Pascal and Modula-2) are poorly documented here.Other sources of information on stabs are `Dbx and DbxtoolInterfaces', 2nd edition, by Sun, 1988, and `AIX Version 3.2 FilesReference', Fourth Edition, September 1992, "dbx Stabstring Grammar" inthe a.out section, page 2-31. This document is believed to incorporatethe information from those two sources except where it explicitlydirects you to them for more information.* Menu:* Flow:: Overview of debugging information flow* Stabs Format:: Overview of stab format* String Field:: The string field* C Example:: A simple example in C source* Assembly Code:: The simple example at the assembly levelFile: stabs.info, Node: Flow, Next: Stabs Format, Up: OverviewOverview of Debugging Information Flow======================================The GNU C compiler compiles C source in a `.c' file into assemblylanguage in a `.s' file, which the assembler translates into a `.o'file, which the linker combines with other `.o' files and libraries toproduce an executable file.With the `-g' option, GCC puts in the `.s' file additional debugginginformation, which is slightly transformed by the assembler and linker,and carried through into the final executable. This debugginginformation describes features of the source file like line numbers,the types and scopes of variables, and function names, parameters, andscopes.For some object file formats, the debugging information isencapsulated in assembler directives known collectively as "stab"(symbol table) directives, which are interspersed with the generatedcode. Stabs are the native format for debugging information in thea.out and XCOFF object file formats. The GNU tools can also emit stabsin the COFF and ECOFF object file formats.The assembler adds the information from stabs to the symbolinformation it places by default in the symbol table and the stringtable of the `.o' file it is building. The linker consolidates the `.o'files into one executable file, with one symbol table and one stringtable. Debuggers use the symbol and string tables in the executable asa source of debugging information about the program.File: stabs.info, Node: Stabs Format, Next: String Field, Prev: Flow, Up: OverviewOverview of Stab Format=======================There are three overall formats for stab assembler directives,differentiated by the first word of the stab. The name of the directivedescribes which combination of four possible data fields follows. It iseither `.stabs' (string), `.stabn' (number), or `.stabd' (dot). IBM'sXCOFF assembler uses `.stabx' (and some other directives such as`.file' and `.bi') instead of `.stabs', `.stabn' or `.stabd'.The overall format of each class of stab is:.stabs "STRING",TYPE,OTHER,DESC,VALUE.stabn TYPE,OTHER,DESC,VALUE.stabd TYPE,OTHER,DESC.stabx "STRING",VALUE,TYPE,SDB-TYPEFor `.stabn' and `.stabd', there is no STRING (the `n_strx' field iszero; see *Note Symbol Tables::). For `.stabd', the VALUE field isimplicit and has the value of the current file location. For `.stabx',the SDB-TYPE field is unused for stabs and can always be set to zero.The OTHER field is almost always unused and can be set to zero.The number in the TYPE field gives some basic information aboutwhich type of stab this is (or whether it _is_ a stab, as opposed to anordinary symbol). Each valid type number defines a different stabtype; further, the stab type defines the exact interpretation of, andpossible values for, any remaining STRING, DESC, or VALUE fieldspresent in the stab. *Note Stab Types::, for a list in numeric orderof the valid TYPE field values for stab directives.File: stabs.info, Node: String Field, Next: C Example, Prev: Stabs Format, Up: OverviewThe String Field================For most stabs the string field holds the meat of the debugginginformation. The flexible nature of this field is what makes stabsextensible. For some stab types the string field contains only a name.For other stab types the contents can be a great deal more complex.The overall format of the string field for most stab types is:"NAME:SYMBOL-DESCRIPTOR TYPE-INFORMATION"NAME is the name of the symbol represented by the stab; it cancontain a pair of colons (*note Nested Symbols::). NAME can beomitted, which means the stab represents an unnamed object. Forexample, `:t10=*2' defines type 10 as a pointer to type 2, but does notgive the type a name. Omitting the NAME field is supported by AIX dbxand GDB after about version 4.8, but not other debuggers. GCCsometimes uses a single space as the name instead of omitting the namealtogether; apparently that is supported by most debuggers.The SYMBOL-DESCRIPTOR following the `:' is an alphabetic characterthat tells more specifically what kind of symbol the stab represents.If the SYMBOL-DESCRIPTOR is omitted, but type information follows, thenthe stab represents a local variable. For a list of symboldescriptors, see *Note Symbol Descriptors::. The `c' symbol descriptoris an exception in that it is not followed by type information. *NoteConstants::.TYPE-INFORMATION is either a TYPE-NUMBER, or `TYPE-NUMBER='. ATYPE-NUMBER alone is a type reference, referring directly to a typethat has already been defined.The `TYPE-NUMBER=' form is a type definition, where the numberrepresents a new type which is about to be defined. The typedefinition may refer to other types by number, and those type numbersmay be followed by `=' and nested definitions. Also, the Lucidcompiler will repeat `TYPE-NUMBER=' more than once if it wants todefine several type numbers at once.In a type definition, if the character that follows the equals signis non-numeric then it is a TYPE-DESCRIPTOR, and tells what kind oftype is about to be defined. Any other values following theTYPE-DESCRIPTOR vary, depending on the TYPE-DESCRIPTOR. *Note TypeDescriptors::, for a list of TYPE-DESCRIPTOR values. If a numberfollows the `=' then the number is a TYPE-REFERENCE. For a fulldescription of types, *Note Types::.A TYPE-NUMBER is often a single number. The GNU and Sun toolsadditionally permit a TYPE-NUMBER to be a pair(FILE-NUMBER,FILETYPE-NUMBER) (the parentheses appear in the string,and serve to distinguish the two cases). The FILE-NUMBER is 0 for thebase source file, 1 for the first included file, 2 for the next, and soon. The FILETYPE-NUMBER is a number starting with 1 which isincremented for each new type defined in the file. (Separating thefile number and the type number permits the `N_BINCL' optimization tosucceed more often; see *Note Include Files::).There is an AIX extension for type attributes. Following the `='are any number of type attributes. Each one starts with `@' and endswith `;'. Debuggers, including AIX's dbx and GDB 4.10, skip any typeattributes they do not recognize. GDB 4.9 and other versions of dbxmay not do this. Because of a conflict with C++ (*note Cplusplus::),new attributes should not be defined which begin with a digit, `(', or`-'; GDB may be unable to distinguish those from the C++ typedescriptor `@'. The attributes are:`aBOUNDARY'BOUNDARY is an integer specifying the alignment. I assume itapplies to all variables of this type.`pINTEGER'Pointer class (for checking). Not sure what this means, or howINTEGER is interpreted.`P'Indicate this is a packed type, meaning that structure fields orarray elements are placed more closely in memory, to save memoryat the expense of speed.`sSIZE'Size in bits of a variable of this type. This is fully supportedby GDB 4.11 and later.`S'Indicate that this type is a string instead of an array ofcharacters, or a bitstring instead of a set. It doesn't changethe layout of the data being represented, but does enable thedebugger to know which type it is.All of this can make the string field quite long. All versions ofGDB, and some versions of dbx, can handle arbitrarily long strings.But many versions of dbx (or assemblers or linkers, I'm not sure which)cretinously limit the strings to about 80 characters, so compilers whichmust work with such systems need to split the `.stabs' directive intoseveral `.stabs' directives. Each stab duplicates every field exceptthe string field. The string field of every stab except the last ismarked as continued with a backslash at the end (in the assembly codethis may be written as a double backslash, depending on the assembler).Removing the backslashes and concatenating the string fields of eachstab produces the original, long string. Just to be incompatible (or sothey don't have to worry about what the assembler does withbackslashes), AIX can use `?' instead of backslash.File: stabs.info, Node: C Example, Next: Assembly Code, Prev: String Field, Up: OverviewA Simple Example in C Source============================To get the flavor of how stabs describe source information for a Cprogram, let's look at the simple program:main(){printf("Hello world");}When compiled with `-g', the program above yields the following `.s'file. Line numbers have been added to make it easier to refer to partsof the `.s' file in the description of the stabs that follows.File: stabs.info, Node: Assembly Code, Prev: C Example, Up: OverviewThe Simple Example at the Assembly Level========================================This simple "hello world" example demonstrates several of the stabtypes used to describe C language source files.1 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,LBE2File: stabs.info, Node: Program Structure, Next: Constants, Prev: Overview, Up: TopEncoding the Structure of the Program*************************************The elements of the program structure that stabs encode include thename of the main function, the names of the source and include files,the line numbers, procedure names and types, and the beginnings andends of blocks 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.File: stabs.info, Node: Main Program, Next: Source Files, Up: Program StructureMain Program============Most languages allow the main program to have any name. The`N_MAIN' stab type tells the debugger the name that is used in thisprogram. Only the string field is significant; it is the name of afunction which is the main program. Most C compilers do not use thisstab (they expect the debugger to assume that the name is `main'), butsome C compilers emit an `N_MAIN' stab for the `main' function. I'mnot sure how XCOFF handles this.File: stabs.info, Node: Source Files, Next: Include Files, Prev: Main Program, Up: Program StructurePaths and Names of the Source Files===================================Before any other stabs occur, there must be a stab specifying thesource file. This information is contained in a symbol of stab type`N_SO'; the string field contains the name of the file. The value ofthe symbol is the start address of the portion of the text sectioncorresponding to that file.With the Sun Solaris2 compiler, the desc field contains asource-language code.Some compilers (for example, GCC2 and SunOS4 `/bin/cc') also includethe directory in which the source was compiled, in a second `N_SO'symbol preceding the one containing the file name. This symbol can bedistinguished by the fact that it ends in a slash. Code from the`cfront' C++ compiler can have additional `N_SO' symbols fornonexistent source files after the `N_SO' for the real source file;these are believed to contain no useful information.For example:.stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0 # 100 is N_SO.stabs "hello.c",100,0,0,Ltext0.textLtext0:Instead of `N_SO' symbols, XCOFF uses a `.file' assembler directivewhich assembles to a `C_FILE' symbol; explaining this in detail isoutside the scope of this document.If it is useful to indicate the end of a source file, this is donewith an `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 `N_SO' for a differentsource file, or a symbol ending in `.o' (which at least some linkersinsert to mark the start of a new `.o' file).File: stabs.info, Node: Include Files, Next: Line Numbers, Prev: Source Files, Up: Program StructureNames of Include Files======================There are several schemes for dealing with include files: thetraditional `N_SOL' approach, Sun's `N_BINCL' approach, and the XCOFF`C_BINCL' approach (which despite the similar name has little in commonwith `N_BINCL').An `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`N_SOL' symbol with the name of the main source file.The `N_BINCL' approach works as follows. An `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 `N_EINCL' symbol(which has no string field). In an object file, there is nosignificant data in the `N_EINCL' symbol. `N_BINCL' and `N_EINCL' canbe nested.If the linker detects that two source files have identical stabsbetween an `N_BINCL' and `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 `N_EXCL' symbol. I believe theGNU 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`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 `N_EXCL' symbol is the same as the value of the `N_BINCL'symbol it replaces. This information can be used to match up `N_EXCL'and `N_BINCL' symbols which have the same filename. The `N_EINCL'value, and the values of the other and description fields for allthree, appear to always be zero.For the start of an include file in XCOFF, use the `.bi' assemblerdirective, which generates a `C_BINCL' symbol. A `.ei' directive,which generates a `C_EINCL' symbol, denotes the end of the includefile. Both directives are followed by the name of the source file inquotes, which becomes the string for the symbol. The value of eachsymbol, produced automatically by the assembler and linker, is theoffset into the executable of the beginning (inclusive, as you'dexpect) or end (inclusive, as you would not expect) of the portion ofthe COFF line table that corresponds to this include file. `C_BINCL'and `C_EINCL' do not nest.File: stabs.info, Node: Line Numbers, Next: Procedures, Prev: Include Files, Up: Program StructureLine Numbers============An `N_SLINE' symbol represents the start of a source line. The descfield contains the line number and the value contains the code addressfor the start of that source line. On most machines the address isabsolute; for stabs in sections (*note Stab Sections::), it is relativeto the function in which the `N_SLINE' symbol occurs.GNU documents `N_DSLINE' and `N_BSLINE' symbols for line numbers inthe data or bss segments, respectively. They are identical to`N_SLINE' but are relocated differently by the linker. They wereintended 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) since atleast GDB 3.5.For single source lines that generate discontiguous code, such asflow of control statements, there may be more than one line numberentry for the same source line. In this case there is a line numberentry at the start of each code range, each with the same line number.XCOFF does not use stabs for line numbers. Instead, it uses COFFline numbers (which are outside the scope of this document). StandardCOFF line numbers cannot deal with include files, but in XCOFF this isfixed with the `C_BINCL' method of marking include files (*note IncludeFiles::).File: stabs.info, Node: Procedures, Next: Nested Procedures, Prev: Line Numbers, Up: Program StructureProcedures==========All of the following stabs normally use the `N_FUN' symbol type.However, Sun's `acc' compiler on SunOS4 uses `N_GSYM' and `N_STSYM',which means that the value of the stab for the function is useless andthe debugger must get the address of the function from the non-stabsymbols instead. On systems where non-stab symbols have leadingunderscores, the stabs will lack underscores and the debugger needs toknow about the leading underscore to match up the stab and the non-stabsymbol. BSD Fortran is said to use `N_FNAME' with the samerestriction; 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).A function is represented by an `F' symbol descriptor for a global(extern) function, and `f' for a static (local) function. For a.out,the value of the symbol is the address of the start of the function; itis already relocated. For stabs in ELF, the SunPRO compiler version2.0.1 and GCC put out an address which gets relocated by the linker.In a future release SunPRO is planning to put out zero, in which casethe address can be found from the ELF (non-stab) symbol. Becauselooking things up in the ELF symbols would probably be slow, I'm notsure how to find which symbol of that name is the right one, and thisdoesn'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 *Note ELF LinkerRelocation:: for more information on linker relocation of stabs in ELFfiles. For XCOFF, the stab uses the `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 `foo:f5' means that foo is a function returning type 5.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 `N_SLINE'symbol.Some compilers (such as Sun's Solaris compiler) support an extensionfor specifying the types of the arguments. I suspect this extension isnot used 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 `;'. An argument type of 0 means that additional argumentsare being passed, whose types and number may vary (`...' in ANSI C).GDB has tolerated this extension (parsed the syntax, if not necessarilyused the information) since at least version 4.8; I don't know whetherall versions of dbx tolerate it. The argument types given here are notredundant with the symbols for the formal parameters (*noteParameters::); they are the types of the arguments as they are passed,before any conversions might take place. For example, if a C functionwhich is declared without a prototype takes a `float' argument, thevalue is passed as a `double' but then converted to a `float'.Debuggers need to use the types given in the arguments when printingvalues, but when calling the function they need to use the types givenin the symbol defining the function.If the return type and types of arguments of a function which isdefined in another source file are specified (i.e., a functionprototype in ANSI C), traditionally compilers emit no stab; the onlyway for the debugger to find the information is if the source filewhere the function is defined was also compiled with debugging symbols.As an extension the Solaris compiler uses symbol descriptor `P'followed by the return type of the function, followed by the arguments,each preceded by `;', as in a stab with symbol descriptor `f' or `F'.This use of symbol descriptor `P' can be distinguished from its use forregister parameters (*note Register Parameters::) by the fact that ithas symbol type `N_FUN'.The AIX documentation also defines symbol descriptor `J' as aninternal function. I assume this means a function nested within anotherfunction. It also says symbol descriptor `m' is a module in Modula-2or extended Pascal.Procedures (functions which do not return values) are represented asfunctions returning the `void' type in C. I don't see why this couldn'tbe used for all languages (inventing a `void' type for this purpose ifnecessary), but the AIX documentation defines `I', `P', and `Q' forinternal, global, and static procedures, respectively. These symboldescriptors are unusual in that they are not followed by typeinformation.The following example shows a stab for a function `main' whichreturns type number `1'. The `_main' specified for the value is areference to an assembler label which is used to fill in the startaddress of the function..stabs "main:F1",36,0,0,_main # 36 is N_FUNThe stab representing a procedure is located immediately followingthe code of the procedure. This stab is in turn directly followed by agroup of other stabs describing elements of the procedure. These otherstabs describe the procedure's parameters, its block local variables,and its block structure.If functions can appear in different sections, then the debugger maynot be able to find the end of a function. Recent versions of GCC willmark the end of a function with an `N_FUN' symbol with an empty stringfor the name. The value is the address of the end of the currentfunction. Without such a symbol, there is no indication of the addressof the end of a function, and you must assume that it ended at thestarting address of the next function or at the end of the text sectionfor the program.File: stabs.info, Node: Nested Procedures, Next: Block Structure, Prev: Procedures, Up: Program StructureNested Procedures=================For any of the symbol descriptors representing procedures, after thesymbol descriptor and the type information is optionally a scopespecifier. This consists of a comma, the name of the procedure, anothercomma, and the name of the enclosing procedure. The first name is localto the scope specified, and seems to be redundant with the name of thesymbol (before the `:'). This feature is used by GCC, and presumablyPascal, Modula-2, etc., compilers, for nested functions.If procedures are nested more than one level deep, only theimmediately containing scope is specified. For example, this code:intfoo (int x){int bar (int y){int baz (int z){return x + y + z;}return baz (x + 2 * y);}return x + bar (3 * x);}produces the stabs:.stabs "baz:f1,baz,bar",36,0,0,_baz.15 # 36 is N_FUN.stabs "bar:f1,bar,foo",36,0,0,_bar.12.stabs "foo:F1",36,0,0,_fooFile: stabs.info, Node: Block Structure, Next: Alternate Entry Points, Prev: Nested Procedures, Up: Program StructureBlock Structure===============The program's block structure is represented by the `N_LBRAC' (leftbrace) and the `N_RBRAC' (right brace) stab types. The variablesdefined inside a block precede the `N_LBRAC' symbol for most compilers,including GCC. Other compilers, such as the Convex, Acorn RISCmachine, and Sun `acc' compilers, put the variables after the `N_LBRAC'symbol. The values of the `N_LBRAC' and `N_RBRAC' symbols are thestart and end addresses of the code of the block, respectively. Formost machines, they are relative to the starting address of this sourcefile. For the Gould NP1, they are absolute. For stabs in sections(*note Stab Sections::), they are relative to the function in whichthey occur.The `N_LBRAC' and `N_RBRAC' stabs that describe the block scope of aprocedure are located after the `N_FUN' stab that represents theprocedure itself.Sun documents the desc field of `N_LBRAC' and `N_RBRAC' symbols ascontaining the nesting level of the block. However, dbx seems to notcare, and GCC always sets desc to zero.For XCOFF, block scope is indicated with `C_BLOCK' symbols. If thename of the symbol is `.bb', then it is the beginning of the block; ifthe name of the symbol is `.be'; it is the end of the block.File: stabs.info, Node: Alternate Entry Points, Prev: Block Structure, Up: Program StructureAlternate Entry Points======================Some languages, like Fortran, have the ability to enter procedures atsome place other than the beginning. One can declare an alternate entrypoint. The `N_ENTRY' stab is for this; however, the Sun FORTRANcompiler doesn't use it. According to AIX documentation, only the nameof a `C_ENTRY' stab is significant; the address of the alternate entrypoint comes from the corresponding external symbol. A previousrevision of this document said that the value of an `N_ENTRY' stab wasthe address of the alternate entry point, but I don't know the sourcefor that information.File: stabs.info, Node: Constants, Next: Variables, Prev: Program Structure, Up: TopConstants*********The `c' symbol descriptor indicates that this stab represents aconstant. This symbol descriptor is an exception to the general rulethat symbol descriptors are followed by type information. Instead, itis followed by `=' and one of the following:`b VALUE'Boolean constant. VALUE is a numeric value; I assume it is 0 forfalse or 1 for true.`c VALUE'Character constant. VALUE is the numeric value of the constant.`e TYPE-INFORMATION , VALUE'Constant whose value can be represented as integral.TYPE-INFORMATION is the type of the constant, as it would appearafter a symbol descriptor (*note String Field::). VALUE is thenumeric value of the constant. GDB 4.9 does not actually get theright value if VALUE does not fit in a host `int', but it does notdo anything violent, and future debuggers could be extended toaccept integers of any size (whether unsigned or not). Thisconstant type is usually documented as being only for enumerationconstants, but GDB has never imposed that restriction; I don'tknow about other debuggers.`i VALUE'Integer constant. VALUE is the numeric value. The type is somesort of generic integer type (for GDB, a host `int'); to specifythe type explicitly, use `e' instead.`r VALUE'Real constant. VALUE is the real value, which can be `INF'(optionally preceded by a sign) for infinity, `QNAN' for a quietNaN (not-a-number), or `SNAN' for a signalling NaN. If it is anormal number the format is that accepted by the C library function`atof'.`s STRING'String constant. STRING is a string enclosed in either `'' (inwhich case `'' characters within the string are represented as`\'' or `"' (in which case `"' characters within the string arerepresented as `\"').`S TYPE-INFORMATION , ELEMENTS , BITS , PATTERN'Set constant. TYPE-INFORMATION is the type of the constant, as itwould appear after a symbol descriptor (*note String Field::).ELEMENTS is the number of elements in the set (does this means howmany bits of PATTERN are actually used, which would be redundantwith the type, or perhaps the number of bits set in PATTERN? Idon't get it), BITS is the number of bits in the constant (meaningit specifies the length of PATTERN, I think), and PATTERN is ahexadecimal representation of the set. AIX documentation refersto a limit of 32 bytes, but I see no reason why this limit shouldexist. This form could probably be used for arbitrary constants,not just sets; the only catch is that PATTERN should be understoodto be target, not host, byte order and format.The boolean, character, string, and set constants are not supportedby GDB 4.9, but it ignores them. GDB 4.8 and earlier gave an errormessage and refused to read symbols from the file containing theconstants.The above information is followed by `;'.File: stabs.info, Node: Variables, Next: Types, Prev: Constants, Up: TopVariables*********Different types of stabs describe the various ways that variablescan be allocated: on the stack, globally, in registers, in commonblocks, statically, or as arguments to a function.* Menu:* Stack Variables:: Variables allocated on the stack.* Global Variables:: Variables used by more than one source file.* Register Variables:: Variables in registers.* Common Blocks:: Variables statically allocated together.* Statics:: Variables local to one source file.* Based Variables:: Fortran pointer based variables.* Parameters:: Variables for arguments to functions.File: stabs.info, Node: Stack Variables, Next: Global Variables, Up: VariablesAutomatic Variables Allocated on the Stack==========================================If a variable's scope is local to a function and its lifetime isonly as long as that function executes (C calls such variables"automatic"), it can be allocated in a register (*note RegisterVariables::) or on the stack.Each variable allocated on the stack has a stab with the symboldescriptor omitted. Since type information should begin with a digit,`-', or `(', only those characters precluded from being used for symboldescriptors. However, the Acorn RISC machine (ARM) is said to get thiswrong: it puts out a mere type definition here, without the preceding`TYPE-NUMBER='. This is a bad idea; there is no guarantee that typedescriptors are distinct from symbol descriptors. Stabs for stackvariables use the `N_LSYM' stab type, or `C_LSYM' for XCOFF.The value of the stab is the offset of the variable within the localvariables. On most machines this is an offset from the frame pointerand is negative. The location of the stab specifies which block it isdefined in; see *Note Block Structure::.For example, the following C code:intmain (){int x;}produces the following stabs:.stabs "main:F1",36,0,0,_main # 36 is N_FUN.stabs "x:1",128,0,0,-12 # 128 is N_LSYM.stabn 192,0,0,LBB2 # 192 is N_LBRAC.stabn 224,0,0,LBE2 # 224 is N_RBRACSee *Note Procedures:: for more information on the `N_FUN' stab, and*Note Block Structure:: for more information on the `N_LBRAC' and`N_RBRAC' stabs.File: stabs.info, Node: Global Variables, Next: Register Variables, Prev: Stack Variables, Up: VariablesGlobal Variables================A variable whose scope is not specific to just one source file isrepresented by the `G' symbol descriptor. These stabs use the `N_GSYM'stab type (C_GSYM for XCOFF). The type information for the stab (*noteString Field::) gives the type of the variable.For example, the following source code:char g_foo = 'c';yields the following assembly code:.stabs "g_foo:G2",32,0,0,0 # 32 is N_GSYM.global _g_foo.data_g_foo:.byte 99The address of the variable represented by the `N_GSYM' is notcontained in the `N_GSYM' stab. The debugger gets this informationfrom the external symbol for the global variable. In the example above,the `.global _g_foo' and `_g_foo:' lines tell the assembler to producean external symbol.Some compilers, like GCC, output `N_GSYM' stabs only once, where thevariable is defined. Other compilers, like SunOS4 /bin/cc, output a`N_GSYM' stab for each compilation unit which references the variable.File: stabs.info, Node: Register Variables, Next: Common Blocks, Prev: Global Variables, Up: VariablesRegister Variables==================Register variables have their own stab type, `N_RSYM' (`C_RSYM' forXCOFF), and their own symbol descriptor, `r'. The stab's value is thenumber of the register where the variable data will be stored.AIX defines a separate symbol descriptor `d' for floating pointregisters. This seems unnecessary; why not just just give floatingpoint registers different register numbers? I have not verified whetherthe compiler actually uses `d'.If the register is explicitly allocated to a global variable, but notinitialized, as in:register int g_bar asm ("%g5");then the stab may be emitted at the end of the object file, with theother bss symbols.File: stabs.info, Node: Common Blocks, Next: Statics, Prev: Register Variables, Up: VariablesCommon Blocks=============A common block is a statically allocated section of memory which canbe referred to by several source files. It may contain severalvariables. I believe Fortran is the only language with this feature.A `N_BCOMM' stab begins a common block and an `N_ECOMM' stab endsit. The only field that is significant in these two stabs is thestring, which names a normal (non-debugging) symbol that gives theaddress of the common block. According to IBM documentation, only the`N_BCOMM' has the name of the common block (even though their compileractually puts it both places).The stabs for the members of the common block are between the`N_BCOMM' and the `N_ECOMM'; the value of each stab is the offsetwithin the common block of that variable. IBM uses the `C_ECOML' stabtype, and there is a corresponding `N_ECOML' stab type, but Sun'sFortran compiler uses `N_GSYM' instead. The variables within a commonblock use the `V' symbol descriptor (I believe this is true of allFortran variables). Other stabs (at least type declarations using`C_DECL') can also be between the `N_BCOMM' and the `N_ECOMM'.File: stabs.info, Node: Statics, Next: Based Variables, Prev: Common Blocks, Up: VariablesStatic Variables================Initialized static variables are represented by the `S' and `V'symbol descriptors. `S' means file scope static, and `V' meansprocedure scope static. One exception: in XCOFF, IBM's xlc compileralways uses `V', and whether it is file scope or not is distinguishedby whether the stab is located within a function.In a.out files, `N_STSYM' means the data section, `N_FUN' means thetext section, and `N_LCSYM' means the bss section. For those systemswith a read-only data section separate from the text section (Solaris),`N_ROSYM' means the read-only data section.For example, the source lines:static const int var_const = 5;static int var_init = 2;static int var_noinit;yield the following stabs:.stabs "var_const:S1",36,0,0,_var_const # 36 is N_FUN....stabs "var_init:S1",38,0,0,_var_init # 38 is N_STSYM....stabs "var_noinit:S1",40,0,0,_var_noinit # 40 is N_LCSYMIn XCOFF files, the stab type need not indicate the section;`C_STSYM' can be used for all statics. Also, each static variable isenclosed in a static block. A `C_BSTAT' (emitted with a `.bs'assembler directive) symbol begins the static block; its value is thesymbol number of the csect symbol whose value is the address of thestatic block, its section is the section of the variables in thatstatic block, and its name is `.bs'. A `C_ESTAT' (emitted with a `.es'assembler directive) symbol ends the static block; its name is `.es'and its value and section are ignored.In ECOFF files, the storage class is used to specify the section, sothe stab type need not indicate the section.In ELF files, for the SunPRO compiler version 2.0.1, symboldescriptor `S' means that the address is absolute (the linker relocatesit) and symbol descriptor `V' means that the address is relative to thestart of the relevant section for that compilation unit. SunPRO hasplans to have the linker stop relocating stabs; I suspect that their thedebugger gets the address from the corresponding ELF (not stab) symbol.I'm not sure how to find which symbol of that name is the right one.The clean way to do all this would be to have a the value of a symboldescriptor `S' symbol be an offset relative to the start of the file,just like everything else, but that introduces obvious compatibilityproblems. For more information on linker stab relocation, *Note ELFLinker Relocation::.File: stabs.info, Node: Based Variables, Next: Parameters, Prev: Statics, Up: VariablesFortran Based Variables=======================Fortran (at least, the Sun and SGI dialects of FORTRAN-77) has afeature which allows allocating arrays with `malloc', but which avoidsblurring the line between arrays and pointers the way that C does. Instabs such a variable uses the `b' symbol descriptor.For example, the Fortran declarationsreal foo, foo10(10), foo10_5(10,5)pointer (foop, foo)pointer (foo10p, foo10)pointer (foo105p, foo10_5)produce the stabsfoo:b6foo10:bar3;1;10;6foo10_5:bar3;1;5;ar3;1;10;6In this example, `real' is type 6 and type 3 is an integral typewhich is the type of the subscripts of the array (probably `integer').The `b' symbol descriptor is like `V' in that it denotes astatically allocated symbol whose scope is local to a function; see*Note Statics::. The value of the symbol, instead of being the addressof the variable itself, is the address of a pointer to that variable.So in the above example, the value of the `foo' stab is the address ofa pointer to a real, the value of the `foo10' stab is the address of apointer to a 10-element array of reals, and the value of the `foo10_5'stab is the address of a pointer to a 5-element array of 10-elementarrays of reals.File: stabs.info, Node: Parameters, Prev: Based Variables, Up: VariablesParameters==========Formal parameters to a function are represented by a stab (orsometimes two; see below) for each parameter. The stabs are in theorder in which the debugger should print the parameters (i.e., theorder in which the parameters are declared in the source file). Theexact form of the stab depends on how the parameter is being passed.Parameters passed on the stack use the symbol descriptor `p' and the`N_PSYM' symbol type (or `C_PSYM' for XCOFF). The value of the symbolis an offset used to locate the parameter on the stack; its exactmeaning is machine-dependent, but on most machines it is an offset fromthe frame pointer.As a simple example, the code:main (argc, argv)int argc;char **argv;produces the stabs:.stabs "main:F1",36,0,0,_main # 36 is N_FUN.stabs "argc:p1",160,0,0,68 # 160 is N_PSYM.stabs "argv:p20=*21=*2",160,0,0,72The type definition of `argv' is interesting because it containsseveral type definitions. Type 21 is pointer to type 2 (char) and`argv' (type 20) is pointer to type 21.The following symbol descriptors are also said to go with `N_PSYM'.The value of the symbol is said to be an offset from the argumentpointer (I'm not sure whether this is true or not).pP (<<??>>)pF Fortran function parameterX (function result variable)* Menu:* Register Parameters::* Local Variable Parameters::* Reference Parameters::* Conformant Arrays::File: stabs.info, Node: Register Parameters, Next: Local Variable Parameters, Up: ParametersPassing Parameters in Registers-------------------------------If the parameter is passed in a register, then traditionally thereare two symbols for each argument:.stabs "arg:p1" . . . ; N_PSYM.stabs "arg:r1" . . . ; N_RSYMDebuggers use the second one to find the value, and the first one toknow that it is an argument.Because that approach is kind of ugly, some compilers use symboldescriptor `P' or `R' to indicate an argument which is in a register.Symbol type `C_RPSYM' is used in XCOFF and `N_RSYM' is used otherwise.The symbol's value is the register number. `P' and `R' mean the samething; the difference is that `P' is a GNU invention and `R' is an IBM(XCOFF) invention. As of version 4.9, GDB should handle either one.There is at least one case where GCC uses a `p' and `r' pair ratherthan `P'; this is where the argument is passed in the argument list andthen loaded into a register.According to the AIX documentation, symbol descriptor `D' is for aparameter passed in a floating point register. This seemsunnecessary--why not just use `R' with a register number whichindicates that it's a floating point register? I haven't verifiedwhether the system actually does what the documentation indicates.On the sparc and hppa, for a `P' symbol whose type is a structure orunion, the register contains the address of the structure. On thesparc, this is also true of a `p' and `r' pair (using Sun `cc') or a`p' symbol. However, if a (small) structure is really in a register,`r' is used. And, to top it all off, on the hppa it might be astructure which was passed on the stack and loaded into a register andfor which there is a `p' and `r' pair! I believe that symboldescriptor `i' is supposed to deal with this case (it is said to mean"value parameter by reference, indirect access"; I don't know thesource for this information), but I don't know details or whatcompilers or debuggers use it, if any (not GDB or GCC). It is notclear to me whether this case needs to be dealt with differently thanparameters passed by reference (*note Reference Parameters::).File: stabs.info, Node: Local Variable Parameters, Next: Reference Parameters, Prev: Register Parameters, Up: ParametersStoring Parameters as Local Variables-------------------------------------There is a case similar to an argument in a register, which is anargument that is actually stored as a local variable. Sometimes thishappens when the argument was passed in a register and then the compilerstores it as a local variable. If possible, the compiler should claimthat it's in a register, but this isn't always done.If a parameter is passed as one type and converted to a smaller typeby the prologue (for example, the parameter is declared as a `float',but the calling conventions specify that it is passed as a `double'),then GCC2 (sometimes) uses a pair of symbols. The first symbol usessymbol descriptor `p' and the type which is passed. The second symbolhas the type and location which the parameter actually has after theprologue. For example, suppose the following C code appears with noprototypes involved:voidsubr (f)float f;{if `f' is passed as a double at stack offset 8, and the prologueconverts it to a float in register number 0, then the stabs look like:.stabs "f:p13",160,0,3,8 # 160 is `N_PSYM', here 13 is `double'.stabs "f:r12",64,0,3,0 # 64 is `N_RSYM', here 12 is `float'In both stabs 3 is the line number where `f' is declared (*note LineNumbers::).GCC, at least on the 960, has another solution to the same problem.It uses a single `p' symbol descriptor for an argument which is storedas a local variable but uses `N_LSYM' instead of `N_PSYM'. In thiscase, the value of the symbol is an offset relative to the localvariables for that function, not relative to the arguments; on somemachines those are the same thing, but not on all.On the VAX or on other machines in which the calling conventionincludes the number of words of arguments actually passed, the debugger(GDB at least) uses the parameter symbols to keep track of whether itneeds to print nameless arguments in addition to the formal parameterswhich it has printed because each one has a stab. For example, inextern int fprintf (FILE *stream, char *format, ...);...fprintf (stdout, "%d\n", x);there are stabs for `stream' and `format'. On most machines, thedebugger can only print those two arguments (because it has no way ofknowing that additional arguments were passed), but on the VAX or othermachines with a calling convention which indicates the number of wordsof arguments, the debugger can print all three arguments. To do so,the parameter symbol (symbol descriptor `p') (not necessarily `r' orsymbol descriptor omitted symbols) needs to contain the actual type aspassed (for example, `double' not `float' if it is passed as a doubleand converted to a float).File: stabs.info, Node: Reference Parameters, Next: Conformant Arrays, Prev: Local Variable Parameters, Up: ParametersPassing Parameters by Reference-------------------------------If the parameter is passed by reference (e.g., Pascal `VAR'parameters), then the symbol descriptor is `v' if it is in the argumentlist, or `a' if it in a register. Other than the fact that thesecontain the address of the parameter rather than the parameter itself,they are identical to `p' and `R', respectively. I believe `a' is anAIX invention; `v' is supported by all stabs-using systems as far as Iknow.
