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