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

📄 stabs.html

📁 vxworks相关论文
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<HTML><HEAD><!-- This HTML file has been created by texi2html 1.52     from stabs.texinfo on 24 March 1999 --><TITLE>STABS</TITLE></HEAD><BODY><H1>The "stabs" debug format</H1><ADDRESS>Julia Menapace, Jim Kingdon, David MacKenzie</ADDRESS><ADDRESS>Cygnus Support</ADDRESS><P><P><HR><P><P></P><P>Copyright (C) 1992, 93, 94, 95, 1997 Free Software Foundation, Inc.Contributed by Cygnus Support.</P><P>Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.</P><H1><A NAME="SEC1" HREF="stabs_toc.html#TOC1">Overview of Stabs</A></H1><P><EM>Stabs</EM> refers to a format for information that describes a programto a debugger.  This format was apparently invented byPeter Kessler atthe University of California at Berkeley, for the <CODE>pdx</CODE> Pascaldebugger; the format has spread widely since then.</P><P>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 (see section <A HREF="stabs.html#SEC70">Table of Symbol Descriptors</A>) and typedescriptors (see section <A HREF="stabs.html#SEC71">Table of Type Descriptors</A>) are believed to be completelycomprehensive.  Stabs for COBOL-specific features and for variantrecords (used by Pascal and Modula-2) are poorly documented here.</P><P>Other sources of information on stabs are <CITE>Dbx and DbxtoolInterfaces</CITE>, 2nd edition, by Sun, 1988, and <CITE>AIX Version 3.2 FilesReference</CITE>, 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 explicitly directsyou to them for more information.</P><H2><A NAME="SEC2" HREF="stabs_toc.html#TOC2">Overview of Debugging Information Flow</A></H2><P>The GNU C compiler compiles C source in a <TT>`.c'</TT> file into assemblylanguage in a <TT>`.s'</TT> file, which the assembler translates intoa <TT>`.o'</TT> file, which the linker combines with other <TT>`.o'</TT> files andlibraries to produce an executable file.</P><P>With the <SAMP>`-g'</SAMP> option, GCC puts in the <TT>`.s'</TT> file additionaldebugging information, which is slightly transformed by the assemblerand linker, and carried through into the final executable.  Thisdebugging information describes features of the source file like linenumbers, the types and scopes of variables, and function names,parameters, and scopes.</P><P>For some object file formats, the debugging information is encapsulatedin assembler directives known collectively as <EM>stab</EM> (symbol table)directives, which are interspersed with the generated code.  Stabs arethe native format for debugging information in the a.out and XCOFFobject file formats.  The GNU tools can also emit stabs in the COFF andECOFF object file formats.</P><P>The assembler adds the information from stabs to the symbol informationit places by default in the symbol table and the string table of the<TT>`.o'</TT> file it is building.  The linker consolidates the <TT>`.o'</TT>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.</P><H2><A NAME="SEC3" HREF="stabs_toc.html#TOC3">Overview of Stab Format</A></H2><P>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 <CODE>.stabs</CODE> (string), <CODE>.stabn</CODE> (number), or <CODE>.stabd</CODE>(dot).  IBM's XCOFF assembler uses <CODE>.stabx</CODE> (and some otherdirectives such as <CODE>.file</CODE> and <CODE>.bi</CODE>) instead of<CODE>.stabs</CODE>, <CODE>.stabn</CODE> or <CODE>.stabd</CODE>.</P><P>The overall format of each class of stab is:</P><PRE>.stabs "<VAR>string</VAR>",<VAR>type</VAR>,<VAR>other</VAR>,<VAR>desc</VAR>,<VAR>value</VAR>.stabn <VAR>type</VAR>,<VAR>other</VAR>,<VAR>desc</VAR>,<VAR>value</VAR>.stabd <VAR>type</VAR>,<VAR>other</VAR>,<VAR>desc</VAR>.stabx "<VAR>string</VAR>",<VAR>value</VAR>,<VAR>type</VAR>,<VAR>sdb-type</VAR></PRE><P>For <CODE>.stabn</CODE> and <CODE>.stabd</CODE>, there is no <VAR>string</VAR> (the<CODE>n_strx</CODE> field is zero; see section <A HREF="stabs.html#SEC46">Symbol Information in Symbol Tables</A>).  For<CODE>.stabd</CODE>, the <VAR>value</VAR> field is implicit and has the value ofthe current file location.  For <CODE>.stabx</CODE>, the <VAR>sdb-type</VAR> fieldis unused for stabs and can always be set to zero.  The <VAR>other</VAR>field is almost always unused and can be set to zero.</P><P>The number in the <VAR>type</VAR> field gives some basic information aboutwhich type of stab this is (or whether it <EM>is</EM> a stab, as opposedto an ordinary symbol).  Each valid type number defines a different stabtype; further, the stab type defines the exact interpretation of, andpossible values for, any remaining <VAR>string</VAR>, <VAR>desc</VAR>, or<VAR>value</VAR> fields present in the stab.  See section <A HREF="stabs.html#SEC67">Table of Stab Types</A>, for a listin numeric order of the valid <VAR>type</VAR> field values for stab directives.</P><H2><A NAME="SEC4" HREF="stabs_toc.html#TOC4">The String Field</A></H2><P>For most stabs the string field holds the meat of thedebugging information.  The flexible nature of this fieldis what makes stabs extensible.  For some stab types the string fieldcontains only a name.  For other stab types the contents can be a greatdeal more complex.</P><P>The overall format of the string field for most stab types is:</P><PRE>"<VAR>name</VAR>:<VAR>symbol-descriptor</VAR> <VAR>type-information</VAR>"</PRE><P><VAR>name</VAR> is the name of the symbol represented by the stab; it cancontain a pair of colons (see section <A HREF="stabs.html#SEC54">Defining a Symbol Within Another Type</A>).  <VAR>name</VAR> can beomitted, which means the stab represents an unnamed object.  Forexample, <SAMP>`:t10=*2'</SAMP> defines type 10 as a pointer to type 2, but doesnot give the type a name.  Omitting the <VAR>name</VAR> field is supported byAIX dbx and 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.</P><P>The <VAR>symbol-descriptor</VAR> following the <SAMP>`:'</SAMP> is an alphabeticcharacter that tells more specifically what kind of symbol the stabrepresents. If the <VAR>symbol-descriptor</VAR> is omitted, but typeinformation follows, then the stab represents a local variable.  For alist of symbol descriptors, see section <A HREF="stabs.html#SEC70">Table of Symbol Descriptors</A>.  The <SAMP>`c'</SAMP>symbol descriptor is an exception in that it is not followed by typeinformation.  See section <A HREF="stabs.html#SEC16">Constants</A>.</P><P><VAR>type-information</VAR> is either a <VAR>type-number</VAR>, or<SAMP>`<VAR>type-number</VAR>='</SAMP>.  A <VAR>type-number</VAR> alone is a typereference, referring directly to a type that has already been defined.</P><P>The <SAMP>`<VAR>type-number</VAR>='</SAMP> form is a type definition, where thenumber represents 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 <SAMP>`='</SAMP> and nested definitions.  Also, the Lucidcompiler will repeat <SAMP>`<VAR>type-number</VAR>='</SAMP> more than once if itwants to define several type numbers at once.</P><P>In a type definition, if the character that follows the equals sign isnon-numeric then it is a <VAR>type-descriptor</VAR>, and tells what kind oftype is about to be defined.  Any other values following the<VAR>type-descriptor</VAR> vary, depending on the <VAR>type-descriptor</VAR>.See section <A HREF="stabs.html#SEC71">Table of Type Descriptors</A>, for a list of <VAR>type-descriptor</VAR> values.  Ifa number follows the <SAMP>`='</SAMP> then the number is a <VAR>type-reference</VAR>.For a full description of types, section <A HREF="stabs.html#SEC29">Defining Types</A>.</P><P>A <VAR>type-number</VAR> is often a single number.  The GNU and Sun toolsadditionally permit a <VAR>type-number</VAR> to be a pair(<VAR>file-number</VAR>,<VAR>filetype-number</VAR>) (the parentheses appear in thestring, and serve to distinguish the two cases).  The <VAR>file-number</VAR>is a number starting with 1 which is incremented for each separatesource file in the compilation (e.g., in C, each header file gets adifferent number).  The <VAR>filetype-number</VAR> is a number starting with1 which is incremented for each new type defined in the file.(Separating the file number and the type number permits the<CODE>N_BINCL</CODE> optimization to succeed more often; see section <A HREF="stabs.html#SEC10">Names of Include Files</A>).</P><P>There is an AIX extension for type attributes.  Following the <SAMP>`='</SAMP>are any number of type attributes.  Each one starts with <SAMP>`@'</SAMP> andends with <SAMP>`;'</SAMP>.  Debuggers, including AIX's dbx and GDB 4.10, skipany type attributes they do not recognize.  GDB 4.9 and other versionsof dbx may not do this.  Because of a conflict with C++(see section <A HREF="stabs.html#SEC52">GNU C++ Stabs</A>), new attributes should not be defined which beginwith a digit, <SAMP>`('</SAMP>, or <SAMP>`-'</SAMP>; GDB may be unable to distinguishthose from the C++ type descriptor <SAMP>`@'</SAMP>.  The attributes are:</P><DL COMPACT><DT><CODE>a<VAR>boundary</VAR></CODE><DD><VAR>boundary</VAR> is an integer specifying the alignment.  I assume itapplies to all variables of this type.<DT><CODE>p<VAR>integer</VAR></CODE><DD>Pointer class (for checking).  Not sure what this means, or how<VAR>integer</VAR> is interpreted.<DT><CODE>P</CODE><DD>Indicate this is a packed type, meaning that structure fields or arrayelements are placed more closely in memory, to save memory at theexpense of speed.<DT><CODE>s<VAR>size</VAR></CODE><DD>Size in bits of a variable of this type.  This is fully supported by GDB4.11 and later.<DT><CODE>S</CODE><DD>Indicate that this type is a string instead of an array of characters,or a bitstring instead of a set.  It doesn't change the layout of thedata being represented, but does enable the debugger to know which typeit is.</DL><P>All of this can make the string field quite long.  All versions of GDB,and some versions of dbx, can handle arbitrarily long strings.  But manyversions of dbx (or assemblers or linkers, I'm not sure which) limit the strings to about 80 characters, so compilers whichmust work with such systems need to split the <CODE>.stabs</CODE> directiveinto several <CODE>.stabs</CODE> directives.  Each stab duplicates every fieldexcept the string field.  The string field of every stab except the lastis marked 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 <SAMP>`?'</SAMP> instead of backslash.</P><H2><A NAME="SEC5" HREF="stabs_toc.html#TOC5">A Simple Example in C Source</A></H2><P>To get the flavor of how stabs describe source information for a Cprogram, let's look at the simple program:</P><PRE>main(){        printf("Hello world");}</PRE><P>When compiled with <SAMP>`-g'</SAMP>, the program above yields the following<TT>`.s'</TT> file.  Line numbers have been added to make it easier to referto parts of the <TT>`.s'</TT> file in the description of the stabs thatfollows.</P><H2><A NAME="SEC6" HREF="stabs_toc.html#TOC6">The Simple Example at the Assembly Level</A></H2><P>This simple "hello world" example demonstrates several of the stabtypes used to describe C language source files.</P><PRE>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,LM3

⌨️ 快捷键说明

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