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