xref: /original-bsd/share/man/man5/stab.5 (revision c3e32dec)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)stab.5	8.1 (Berkeley) 06/05/93
7.\"
8.Dd
9.Dt STAB 5
10.Os BSD 4
11.Sh NAME
12.Nm stab
13.Nd symbol table types
14.Sh SYNOPSIS
15.Fd #include <stab.h>
16.Sh DESCRIPTION
17The file
18.Aq Pa stab.h
19defines some of the symbol table
20.Fa n_type
21field values for a.out files.
22These are the types for permanent symbols (i.e. not local labels, etc.)
23used by the old debugger
24.Em sdb
25and the Berkeley Pascal compiler
26.Xr pc 1 .
27Symbol table entries can be produced by the
28.Pa .stabs
29assembler directive.
30This allows one to specify a double-quote delimited name, a symbol type,
31one char and one short of information about the symbol, and an unsigned
32long (usually an address).
33To avoid having to produce an explicit label for the address field,
34the
35.Pa .stabd
36directive can be used to implicitly address the current location.
37If no name is needed, symbol table entries can be generated using the
38.Pa .stabn
39directive.
40The loader promises to preserve the order of symbol table entries produced
41by
42.Pa .stab
43directives.
44As described in
45.Xr a.out 5 ,
46an element of the symbol table
47consists of the following structure:
48.Bd -literal
49/*
50* Format of a symbol table entry.
51*/
52
53struct nlist {
54	union {
55		char	*n_name;	/* for use when in-core */
56		long	n_strx;		/* index into file string table */
57	} n_un;
58	unsigned char	n_type;		/* type flag */
59	char		n_other;	/* unused */
60	short		n_desc;		/* see struct desc, below */
61	unsigned	n_value;	/* address or offset or line */
62};
63.Ed
64.Pp
65The low bits of the
66.Fa n_type
67field are used to place a symbol into
68at most one segment, according to
69the following masks, defined in
70.Aq Pa a.out.h .
71A symbol can be in none of these segments by having none of these segment
72bits set.
73.Bd -literal
74/*
75* Simple values for n_type.
76*/
77
78#define	N_UNDF	0x0	/* undefined */
79#define	N_ABS	0x2	/* absolute */
80#define	N_TEXT	0x4	/* text */
81#define	N_DATA	0x6	/* data */
82#define	N_BSS	0x8	/* bss */
83
84#define	N_EXT	01	/* external bit, or'ed in */
85.Ed
86.Pp
87The
88.Fa n_value
89field of a symbol is relocated by the linker,
90.Xr ld 1
91as an address within the appropriate segment.
92.Fa N_value
93fields of symbols not in any segment are unchanged by the linker.
94In addition, the linker will discard certain symbols, according to rules
95of its own, unless the
96.Fa n_type
97field has one of the following bits set:
98.Bd -literal
99/*
100* Other permanent symbol table entries have some of the N_STAB bits set.
101* These are given in <stab.h>
102*/
103
104#define	N_STAB	0xe0	/* if any of these bits set, don't discard */
105.Ed
106.Pp
107This allows up to 112 (7 \(** 16) symbol types, split between the various
108segments.
109Some of these have already been claimed.
110The old symbolic debugger,
111.Em sdb ,
112uses the following n_type values:
113.Bd -literal
114#define	N_GSYM	0x20	/* global symbol: name,,0,type,0 */
115#define	N_FNAME	0x22	/* procedure name (f77 kludge): name,,0 */
116#define	N_FUN	0x24	/* procedure: name,,0,linenumber,address */
117#define	N_STSYM	0x26	/* static symbol: name,,0,type,address */
118#define	N_LCSYM	0x28	/* .lcomm symbol: name,,0,type,address */
119#define	N_RSYM	0x40	/* register sym: name,,0,type,register */
120#define	N_SLINE	0x44	/* src line: 0,,0,linenumber,address */
121#define	N_SSYM	0x60	/* structure elt: name,,0,type,struct_offset */
122#define	N_SO	0x64	/* source file name: name,,0,0,address */
123#define	N_LSYM	0x80	/* local sym: name,,0,type,offset */
124#define	N_SOL	0x84	/* #included file name: name,,0,0,address */
125#define	N_PSYM	0xa0	/* parameter: name,,0,type,offset */
126#define	N_ENTRY	0xa4	/* alternate entry: name,linenumber,address */
127#define	N_LBRAC	0xc0	/* left bracket: 0,,0,nesting level,address */
128#define	N_RBRAC	0xe0	/* right bracket: 0,,0,nesting level,address */
129#define	N_BCOMM	0xe2	/* begin common: name,, */
130#define	N_ECOMM	0xe4	/* end common: name,, */
131#define	N_ECOML	0xe8	/* end common (local name): ,,address */
132#define	N_LENG	0xfe	/* second stab entry with length information */
133.Ed
134.Pp
135where the comments give
136.Em sdb
137conventional use for
138.Pa .stab
139.Fa s
140and the
141.Fa n_name ,
142.Fa n_other ,
143.Fa n_desc ,
144and
145.Fa n_value
146fields
147of the given
148.Fa n_type .
149.Em Sdb
150uses the
151.Fa n_desc
152field to hold a type specifier in the form used
153by the Portable C Compiler,
154.Xr cc 1 ;
155see the header file
156.Pa pcc.h
157for details on the format of these type values.
158.Pp
159The Berkeley Pascal compiler,
160.Xr pc 1 ,
161uses the following
162.Fa n_type
163value:
164.Bd -literal
165#define	N_PC	0x30	/* global pascal symbol: name,,0,subtype,line */
166.Ed
167.Pp
168and uses the following subtypes to do type checking across separately
169compiled files:
170.Bd -unfilled -offset indent
1711	source file name
1722	included file name
1733	global label
1744	global constant
1755	global type
1766	global variable
1777	global function
1788	global procedure
1799	external function
18010	external procedure
18111	library variable
18212	library routine
183.Ed
184.Sh SEE ALSO
185.Xr as 1 ,
186.Xr ld 1 ,
187.Xr dbx 1 ,
188.Xr a.out 5
189.Sh BUGS
190.Pp
191More basic types are needed.
192.Sh HISTORY
193The
194.Nm stab
195file appeared in
196.Bx 4.0 .
197