stabs_6.html   [plain text]


<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.51
     from /mnt/apple/gdb/source/gdb.apple/source/gdb/gdb/doc/stabs.texinfo on 23 November 1999 -->

<TITLE>STABS - Symbol Information in Symbol Tables</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="stabs_1.html">first</A>, <A HREF="stabs_5.html">previous</A>, <A HREF="stabs_7.html">next</A>, <A HREF="stabs_14.html">last</A> section, <A HREF="stabs_toc.html">table of contents</A>.
<P><HR><P>


<H1><A NAME="SEC46" HREF="stabs_toc.html#TOC46">Symbol Information in Symbol Tables</A></H1>

<P>
This chapter describes the format of symbol table entries
and how stab assembler directives map to them.  It also describes the
transformations that the assembler and linker make on data from stabs.

</P>



<H2><A NAME="SEC47" HREF="stabs_toc.html#TOC47">Symbol Table Format</A></H2>

<P>
Each time the assembler encounters a stab directive, it puts
each field of the stab into a corresponding field in a symbol table
entry of its output file.  If the stab contains a string field, the
symbol table entry for that stab points to a string table entry
containing the string data from the stab.  Assembler labels become
relocatable addresses.  Symbol table entries in a.out have the format:

</P>

<PRE>
struct 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 */
};
</PRE>

<P>
If the stab has a string, the <CODE>n_strx</CODE> field holds the offset in
bytes of the string within the string table.  The string is terminated
by a NUL character.  If the stab lacks a string (for example, it was
produced by a <CODE>.stabn</CODE> or <CODE>.stabd</CODE> directive), the
<CODE>n_strx</CODE> field is zero.

</P>
<P>
Symbol table entries with <CODE>n_type</CODE> field values greater than 0x1f
originated as stabs generated by the compiler (with one random
exception).  The other entries were placed in the symbol table of the
executable by the assembler or the linker.

</P>


<H2><A NAME="SEC48" HREF="stabs_toc.html#TOC48">Transformations on Symbol Tables</A></H2>

<P>
The linker concatenates object files and does fixups of externally
defined symbols.

</P>
<P>
You can see the transformations made on stab data by the assembler and
linker by examining the symbol table after each pass of the build.  To
do this, use <SAMP>`nm -ap'</SAMP>, which dumps the symbol table, including
debugging information, unsorted.  For stab entries the columns are:
<VAR>value</VAR>, <VAR>other</VAR>, <VAR>desc</VAR>, <VAR>type</VAR>, <VAR>string</VAR>.  For
assembler and linker symbols, the columns are: <VAR>value</VAR>, <VAR>type</VAR>,
<VAR>string</VAR>.

</P>
<P>
The low 5 bits of the stab type tell the linker how to relocate the
value of the stab.  Thus for stab types like <CODE>N_RSYM</CODE> and
<CODE>N_LSYM</CODE>, where the value is an offset or a register number, the
low 5 bits are <CODE>N_ABS</CODE>, which tells the linker not to relocate the
value.

</P>
<P>
Where the value of a stab contains an assembly language label,
it is transformed by each build step.  The assembler turns it into a
relocatable address and the linker turns it into an absolute address.

</P>



<H3><A NAME="SEC49" HREF="stabs_toc.html#TOC49">Transformations on Static Variables</A></H3>

<P>
This source line defines a static variable at file scope:

</P>

<PRE>
static int s_g_repeat
</PRE>

<P>
The following stab describes the symbol:

</P>

<PRE>
.stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
</PRE>

<P>
The assembler transforms the stab into this symbol table entry in the
<TT>`.o'</TT> file.  The location is expressed as a data segment offset.

</P>

<PRE>
00000084 - 00 0000 STSYM s_g_repeat:S1
</PRE>

<P>
In the symbol table entry from the executable, the linker has made the
relocatable address absolute.

</P>

<PRE>
0000e00c - 00 0000 STSYM s_g_repeat:S1
</PRE>



<H3><A NAME="SEC50" HREF="stabs_toc.html#TOC50">Transformations on Global Variables</A></H3>

<P>
Stabs for global variables do not contain location information. In
this case, the debugger finds location information in the assembler or
linker symbol table entry describing the variable.  The source line:

</P>

<PRE>
char g_foo = 'c';
</PRE>

<P>
generates the stab:

</P>

<PRE>
.stabs "g_foo:G2",32,0,0,0
</PRE>

<P>
The variable is represented by two symbol table entries in the object
file (see below).  The first one originated as a stab.  The second one
is an external symbol.  The upper case <SAMP>`D'</SAMP> signifies that the
<CODE>n_type</CODE> field of the symbol table contains 7, <CODE>N_DATA</CODE> with
local linkage.  The stab's value is zero since the value is not used for
<CODE>N_GSYM</CODE> stabs.  The value of the linker symbol is the relocatable
address corresponding to the variable.

</P>

<PRE>
00000000 - 00 0000  GSYM g_foo:G2
00000080 D _g_foo
</PRE>

<P>
These entries as transformed by the linker.  The linker symbol table
entry now holds an absolute address:

</P>

<PRE>
00000000 - 00 0000  GSYM g_foo:G2
...
0000e008 D _g_foo
</PRE>



<H3><A NAME="SEC51" HREF="stabs_toc.html#TOC51">Transformations of Stabs in separate sections</A></H3>

<P>
For object file formats using stabs in separate sections (see section <A HREF="stabs_13.html#SEC87">Using Stabs in Their Own Sections</A>), use <CODE>objdump --stabs</CODE> instead of <CODE>nm</CODE> to show the
stabs in an object or executable file.  <CODE>objdump</CODE> is a GNU utility;
Sun does not provide any equivalent.

</P>
<P>
The following example is for a stab whose value is an address is
relative to the compilation unit (see section <A HREF="stabs_13.html#SEC89">Having the Linker Relocate Stabs in ELF</A>).  For
example, if the source line

</P>

<PRE>
static int ld = 5;
</PRE>

<P>
appears within a function, then the assembly language output from the
compiler contains:

</P>

<PRE>
.Ddata.data:
...
        .stabs "ld:V(0,3)",0x26,0,4,.L18-Ddata.data    # 0x26 is N_STSYM
...
.L18:
        .align 4
        .word 0x5
</PRE>

<P>
Because the value is formed by subtracting one symbol from another, the
value is absolute, not relocatable, and so the object file contains

</P>

<PRE>
Symnum n_type n_othr n_desc n_value  n_strx String
31     STSYM  0      4      00000004 680    ld:V(0,3)
</PRE>

<P>
without any relocations, and the executable file also contains

</P>

<PRE>
Symnum n_type n_othr n_desc n_value  n_strx String
31     STSYM  0      4      00000004 680    ld:V(0,3)
</PRE>

<P><HR><P>
Go to the <A HREF="stabs_1.html">first</A>, <A HREF="stabs_5.html">previous</A>, <A HREF="stabs_7.html">next</A>, <A HREF="stabs_14.html">last</A> section, <A HREF="stabs_toc.html">table of contents</A>.
</BODY>
</HTML>