xref: /freebsd/share/man/man5/stab.5 (revision afe61c15161c324a7af299a9b8457aba5afc92db)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)stab.5	8.1 (Berkeley) 6/5/93
33.\"
34.Dd June 5, 1993
35.Dt STAB 5
36.Os BSD 4
37.Sh NAME
38.Nm stab
39.Nd symbol table types
40.Sh SYNOPSIS
41.Fd #include <stab.h>
42.Sh DESCRIPTION
43The file
44.Aq Pa stab.h
45defines some of the symbol table
46.Fa n_type
47field values for a.out files.
48These are the types for permanent symbols (i.e. not local labels, etc.)
49used by the old debugger
50.Em sdb
51and the Berkeley Pascal compiler
52.Xr pc 1 .
53Symbol table entries can be produced by the
54.Pa .stabs
55assembler directive.
56This allows one to specify a double-quote delimited name, a symbol type,
57one char and one short of information about the symbol, and an unsigned
58long (usually an address).
59To avoid having to produce an explicit label for the address field,
60the
61.Pa .stabd
62directive can be used to implicitly address the current location.
63If no name is needed, symbol table entries can be generated using the
64.Pa .stabn
65directive.
66The loader promises to preserve the order of symbol table entries produced
67by
68.Pa .stab
69directives.
70As described in
71.Xr a.out 5 ,
72an element of the symbol table
73consists of the following structure:
74.Bd -literal
75/*
76* Format of a symbol table entry.
77*/
78
79struct nlist {
80	union {
81		char	*n_name;	/* for use when in-core */
82		long	n_strx;		/* index into file string table */
83	} n_un;
84	unsigned char	n_type;		/* type flag */
85	char		n_other;	/* unused */
86	short		n_desc;		/* see struct desc, below */
87	unsigned	n_value;	/* address or offset or line */
88};
89.Ed
90.Pp
91The low bits of the
92.Fa n_type
93field are used to place a symbol into
94at most one segment, according to
95the following masks, defined in
96.Aq Pa a.out.h .
97A symbol can be in none of these segments by having none of these segment
98bits set.
99.Bd -literal
100/*
101* Simple values for n_type.
102*/
103
104#define	N_UNDF	0x0	/* undefined */
105#define	N_ABS	0x2	/* absolute */
106#define	N_TEXT	0x4	/* text */
107#define	N_DATA	0x6	/* data */
108#define	N_BSS	0x8	/* bss */
109
110#define	N_EXT	01	/* external bit, or'ed in */
111.Ed
112.Pp
113The
114.Fa n_value
115field of a symbol is relocated by the linker,
116.Xr ld 1
117as an address within the appropriate segment.
118.Fa N_value
119fields of symbols not in any segment are unchanged by the linker.
120In addition, the linker will discard certain symbols, according to rules
121of its own, unless the
122.Fa n_type
123field has one of the following bits set:
124.Bd -literal
125/*
126* Other permanent symbol table entries have some of the N_STAB bits set.
127* These are given in <stab.h>
128*/
129
130#define	N_STAB	0xe0	/* if any of these bits set, don't discard */
131.Ed
132.Pp
133This allows up to 112 (7 \(** 16) symbol types, split between the various
134segments.
135Some of these have already been claimed.
136The old symbolic debugger,
137.Em sdb ,
138uses the following n_type values:
139.Bd -literal
140#define	N_GSYM	0x20	/* global symbol: name,,0,type,0 */
141#define	N_FNAME	0x22	/* procedure name (f77 kludge): name,,0 */
142#define	N_FUN	0x24	/* procedure: name,,0,linenumber,address */
143#define	N_STSYM	0x26	/* static symbol: name,,0,type,address */
144#define	N_LCSYM	0x28	/* .lcomm symbol: name,,0,type,address */
145#define	N_RSYM	0x40	/* register sym: name,,0,type,register */
146#define	N_SLINE	0x44	/* src line: 0,,0,linenumber,address */
147#define	N_SSYM	0x60	/* structure elt: name,,0,type,struct_offset */
148#define	N_SO	0x64	/* source file name: name,,0,0,address */
149#define	N_LSYM	0x80	/* local sym: name,,0,type,offset */
150#define	N_SOL	0x84	/* #included file name: name,,0,0,address */
151#define	N_PSYM	0xa0	/* parameter: name,,0,type,offset */
152#define	N_ENTRY	0xa4	/* alternate entry: name,linenumber,address */
153#define	N_LBRAC	0xc0	/* left bracket: 0,,0,nesting level,address */
154#define	N_RBRAC	0xe0	/* right bracket: 0,,0,nesting level,address */
155#define	N_BCOMM	0xe2	/* begin common: name,, */
156#define	N_ECOMM	0xe4	/* end common: name,, */
157#define	N_ECOML	0xe8	/* end common (local name): ,,address */
158#define	N_LENG	0xfe	/* second stab entry with length information */
159.Ed
160.Pp
161where the comments give
162.Em sdb
163conventional use for
164.Pa .stab
165.Fa s
166and the
167.Fa n_name ,
168.Fa n_other ,
169.Fa n_desc ,
170and
171.Fa n_value
172fields
173of the given
174.Fa n_type .
175.Em Sdb
176uses the
177.Fa n_desc
178field to hold a type specifier in the form used
179by the Portable C Compiler,
180.Xr cc 1 ;
181see the header file
182.Pa pcc.h
183for details on the format of these type values.
184.Pp
185The Berkeley Pascal compiler,
186.Xr pc 1 ,
187uses the following
188.Fa n_type
189value:
190.Bd -literal
191#define	N_PC	0x30	/* global pascal symbol: name,,0,subtype,line */
192.Ed
193.Pp
194and uses the following subtypes to do type checking across separately
195compiled files:
196.Bd -unfilled -offset indent
1971	source file name
1982	included file name
1993	global label
2004	global constant
2015	global type
2026	global variable
2037	global function
2048	global procedure
2059	external function
20610	external procedure
20711	library variable
20812	library routine
209.Ed
210.Sh SEE ALSO
211.Xr as 1 ,
212.Xr ld 1 ,
213.Xr dbx 1 ,
214.Xr a.out 5
215.Sh BUGS
216.Pp
217More basic types are needed.
218.Sh HISTORY
219The
220.Nm stab
221file appeared in
222.Bx 4.0 .
223