xref: /csrg-svn/share/man/man5/stab.5 (revision 49647)
1*49647Scael.\" Copyright (c) 1980, 1991 Regents of the University of California.
248928Scael.\" All rights reserved.
320764Smckusick.\"
4*49647Scael.\" %sccs.include.redist.man%
520764Smckusick.\"
6*49647Scael.\"     @(#)stab.5	6.5 (Berkeley) 05/10/91
748928Scael.\"
8*49647Scael.Dd
9*49647Scael.Dt STAB 5
10*49647Scael.Os BSD 4
11*49647Scael.Sh NAME
12*49647Scael.Nm stab
13*49647Scael.Nd symbol table types
14*49647Scael.Sh SYNOPSIS
15*49647Scael.Fd #include <stab.h>
16*49647Scael.Sh DESCRIPTION
17*49647ScaelThe file
18*49647Scael.Aq Pa stab.h
19*49647Scaeldefines some of the symbol table
20*49647Scael.Fa n_type
21*49647Scaelfield values for a.out files.
2220764SmckusickThese are the types for permanent symbols (i.e. not local labels, etc.)
2320765Smckusickused by the old debugger
24*49647Scael.Em sdb
2520764Smckusickand the Berkeley Pascal compiler
26*49647Scael.Xr pc 1 .
2720764SmckusickSymbol table entries can be produced by the
28*49647Scael.Pa .stabs
2920764Smckusickassembler directive.
3020764SmckusickThis allows one to specify a double-quote delimited name, a symbol type,
3120764Smckusickone char and one short of information about the symbol, and an unsigned
3220764Smckusicklong (usually an address).
3320764SmckusickTo avoid having to produce an explicit label for the address field,
3420764Smckusickthe
35*49647Scael.Pa .stabd
3620764Smckusickdirective can be used to implicitly address the current location.
3720764SmckusickIf no name is needed, symbol table entries can be generated using the
38*49647Scael.Pa .stabn
3920764Smckusickdirective.
4020764SmckusickThe loader promises to preserve the order of symbol table entries produced
4120764Smckusickby
42*49647Scael.Pa .stab
4320764Smckusickdirectives.
4420765SmckusickAs described in
45*49647Scael.Xr a.out 5 ,
4620765Smckusickan element of the symbol table
4720764Smckusickconsists of the following structure:
48*49647Scael.Bd -literal
4920764Smckusick/*
5020764Smckusick* Format of a symbol table entry.
5120764Smckusick*/
52*49647Scael
5320764Smckusickstruct nlist {
5420764Smckusick	union {
5520764Smckusick		char	*n_name;	/* for use when in-core */
5620764Smckusick		long	n_strx;		/* index into file string table */
5720764Smckusick	} n_un;
5820764Smckusick	unsigned char	n_type;		/* type flag */
5920764Smckusick	char		n_other;	/* unused */
6020764Smckusick	short		n_desc;		/* see struct desc, below */
6120764Smckusick	unsigned	n_value;	/* address or offset or line */
6220764Smckusick};
63*49647Scael.Ed
64*49647Scael.Pp
65*49647ScaelThe low bits of the
66*49647Scael.Fa n_type
67*49647Scaelfield are used to place a symbol into
6820764Smckusickat most one segment, according to
6920764Smckusickthe following masks, defined in
70*49647Scael.Aq Pa a.out.h .
7120764SmckusickA symbol can be in none of these segments by having none of these segment
7220764Smckusickbits set.
73*49647Scael.Bd -literal
7420764Smckusick/*
7520764Smckusick* Simple values for n_type.
7620764Smckusick*/
77*49647Scael
7820764Smckusick#define	N_UNDF	0x0	/* undefined */
7920764Smckusick#define	N_ABS	0x2	/* absolute */
8020764Smckusick#define	N_TEXT	0x4	/* text */
8120764Smckusick#define	N_DATA	0x6	/* data */
8220764Smckusick#define	N_BSS	0x8	/* bss */
8320764Smckusick
8420764Smckusick#define	N_EXT	01	/* external bit, or'ed in */
85*49647Scael.Ed
86*49647Scael.Pp
87*49647ScaelThe
88*49647Scael.Fa n_value
89*49647Scaelfield of a symbol is relocated by the linker,
90*49647Scael.Xr ld 1
9120764Smckusickas an address within the appropriate segment.
92*49647Scael.Fa N_value
93*49647Scaelfields of symbols not in any segment are unchanged by the linker.
9420764SmckusickIn addition, the linker will discard certain symbols, according to rules
95*49647Scaelof its own, unless the
96*49647Scael.Fa n_type
97*49647Scaelfield has one of the following bits set:
98*49647Scael.Bd -literal
9920764Smckusick/*
10020764Smckusick* Other permanent symbol table entries have some of the N_STAB bits set.
10120764Smckusick* These are given in <stab.h>
10220764Smckusick*/
10320764Smckusick
104*49647Scael#define	N_STAB	0xe0	/* if any of these bits set, don't discard */
105*49647Scael.Ed
106*49647Scael.Pp
10720764SmckusickThis allows up to 112 (7 \(** 16) symbol types, split between the various
10820764Smckusicksegments.
10920764SmckusickSome of these have already been claimed.
11020765SmckusickThe old symbolic debugger,
111*49647Scael.Em sdb ,
11220764Smckusickuses the following n_type values:
113*49647Scael.Bd -literal
11420764Smckusick#define	N_GSYM	0x20	/* global symbol: name,,0,type,0 */
11520764Smckusick#define	N_FNAME	0x22	/* procedure name (f77 kludge): name,,0 */
11620764Smckusick#define	N_FUN	0x24	/* procedure: name,,0,linenumber,address */
11720764Smckusick#define	N_STSYM	0x26	/* static symbol: name,,0,type,address */
11820764Smckusick#define	N_LCSYM	0x28	/* .lcomm symbol: name,,0,type,address */
11920764Smckusick#define	N_RSYM	0x40	/* register sym: name,,0,type,register */
12020764Smckusick#define	N_SLINE	0x44	/* src line: 0,,0,linenumber,address */
12120764Smckusick#define	N_SSYM	0x60	/* structure elt: name,,0,type,struct_offset */
12220764Smckusick#define	N_SO	0x64	/* source file name: name,,0,0,address */
12320764Smckusick#define	N_LSYM	0x80	/* local sym: name,,0,type,offset */
12420764Smckusick#define	N_SOL	0x84	/* #included file name: name,,0,0,address */
12520764Smckusick#define	N_PSYM	0xa0	/* parameter: name,,0,type,offset */
12620764Smckusick#define	N_ENTRY	0xa4	/* alternate entry: name,linenumber,address */
12720764Smckusick#define	N_LBRAC	0xc0	/* left bracket: 0,,0,nesting level,address */
12820764Smckusick#define	N_RBRAC	0xe0	/* right bracket: 0,,0,nesting level,address */
12920764Smckusick#define	N_BCOMM	0xe2	/* begin common: name,, */
13020764Smckusick#define	N_ECOMM	0xe4	/* end common: name,, */
13120764Smckusick#define	N_ECOML	0xe8	/* end common (local name): ,,address */
13220764Smckusick#define	N_LENG	0xfe	/* second stab entry with length information */
133*49647Scael.Ed
134*49647Scael.Pp
13520765Smckusickwhere the comments give
136*49647Scael.Em sdb
13720764Smckusickconventional use for
138*49647Scael.Pa .stab
139*49647Scael.Fa s
140*49647Scaeland the
141*49647Scael.Fa n_name ,
142*49647Scael.Fa n_other ,
143*49647Scael.Fa n_desc ,
144*49647Scaeland
145*49647Scael.Fa n_value
146*49647Scaelfields
147*49647Scaelof the given
148*49647Scael.Fa n_type .
149*49647Scael.Em Sdb
150*49647Scaeluses the
151*49647Scael.Fa n_desc
152*49647Scaelfield to hold a type specifier in the form used
15320764Smckusickby the Portable C Compiler,
154*49647Scael.Xr cc 1 ;
155*49647Scaelsee the header file
156*49647Scael.Pa pcc.h
15728283Sdonnfor details on the format of these type values.
158*49647Scael.Pp
15920764SmckusickThe Berkeley Pascal compiler,
160*49647Scael.Xr pc 1 ,
161*49647Scaeluses the following
162*49647Scael.Fa n_type
163*49647Scaelvalue:
164*49647Scael.Bd -literal
16520764Smckusick#define	N_PC	0x30	/* global pascal symbol: name,,0,subtype,line */
166*49647Scael.Ed
167*49647Scael.Pp
16820764Smckusickand uses the following subtypes to do type checking across separately
16920764Smckusickcompiled files:
170*49647Scael.Bd -unfilled -offset indent
171*49647Scael1	source file name
172*49647Scael2	included file name
173*49647Scael3	global label
174*49647Scael4	global constant
175*49647Scael5	global type
176*49647Scael6	global variable
177*49647Scael7	global function
178*49647Scael8	global procedure
179*49647Scael9	external function
180*49647Scael10	external procedure
181*49647Scael11	library variable
182*49647Scael12	library routine
183*49647Scael.Ed
184*49647Scael.Sh SEE ALSO
185*49647Scael.Xr as 1 ,
186*49647Scael.Xr ld 1 ,
187*49647Scael.Xr dbx 1 ,
188*49647Scael.Xr a.out 5
189*49647Scael.Sh BUGS
190*49647Scael.Pp
19120764SmckusickMore basic types are needed.
192*49647Scael.Sh HISTORY
193*49647ScaelThe
194*49647Scael.Nm stab
195*49647Scaelfile appeared in
196*49647Scael.Bx 4.0 .
197