xref: /csrg-svn/share/man/man5/stab.5 (revision 61610)
1*61610Sbostic.\" Copyright (c) 1980, 1991, 1993
2*61610Sbostic.\"	The Regents of the University of California.  All rights reserved.
320764Smckusick.\"
449647Scael.\" %sccs.include.redist.man%
520764Smckusick.\"
6*61610Sbostic.\"     @(#)stab.5	8.1 (Berkeley) 06/05/93
748928Scael.\"
849647Scael.Dd
949647Scael.Dt STAB 5
1049647Scael.Os BSD 4
1149647Scael.Sh NAME
1249647Scael.Nm stab
1349647Scael.Nd symbol table types
1449647Scael.Sh SYNOPSIS
1549647Scael.Fd #include <stab.h>
1649647Scael.Sh DESCRIPTION
1749647ScaelThe file
1849647Scael.Aq Pa stab.h
1949647Scaeldefines some of the symbol table
2049647Scael.Fa n_type
2149647Scaelfield values for a.out files.
2220764SmckusickThese are the types for permanent symbols (i.e. not local labels, etc.)
2320765Smckusickused by the old debugger
2449647Scael.Em sdb
2520764Smckusickand the Berkeley Pascal compiler
2649647Scael.Xr pc 1 .
2720764SmckusickSymbol table entries can be produced by the
2849647Scael.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
3549647Scael.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
3849647Scael.Pa .stabn
3920764Smckusickdirective.
4020764SmckusickThe loader promises to preserve the order of symbol table entries produced
4120764Smckusickby
4249647Scael.Pa .stab
4320764Smckusickdirectives.
4420765SmckusickAs described in
4549647Scael.Xr a.out 5 ,
4620765Smckusickan element of the symbol table
4720764Smckusickconsists of the following structure:
4849647Scael.Bd -literal
4920764Smckusick/*
5020764Smckusick* Format of a symbol table entry.
5120764Smckusick*/
5249647Scael
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};
6349647Scael.Ed
6449647Scael.Pp
6549647ScaelThe low bits of the
6649647Scael.Fa n_type
6749647Scaelfield are used to place a symbol into
6820764Smckusickat most one segment, according to
6920764Smckusickthe following masks, defined in
7049647Scael.Aq Pa a.out.h .
7120764SmckusickA symbol can be in none of these segments by having none of these segment
7220764Smckusickbits set.
7349647Scael.Bd -literal
7420764Smckusick/*
7520764Smckusick* Simple values for n_type.
7620764Smckusick*/
7749647Scael
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 */
8549647Scael.Ed
8649647Scael.Pp
8749647ScaelThe
8849647Scael.Fa n_value
8949647Scaelfield of a symbol is relocated by the linker,
9049647Scael.Xr ld 1
9120764Smckusickas an address within the appropriate segment.
9249647Scael.Fa N_value
9349647Scaelfields of symbols not in any segment are unchanged by the linker.
9420764SmckusickIn addition, the linker will discard certain symbols, according to rules
9549647Scaelof its own, unless the
9649647Scael.Fa n_type
9749647Scaelfield has one of the following bits set:
9849647Scael.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
10449647Scael#define	N_STAB	0xe0	/* if any of these bits set, don't discard */
10549647Scael.Ed
10649647Scael.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,
11149647Scael.Em sdb ,
11220764Smckusickuses the following n_type values:
11349647Scael.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 */
13349647Scael.Ed
13449647Scael.Pp
13520765Smckusickwhere the comments give
13649647Scael.Em sdb
13720764Smckusickconventional use for
13849647Scael.Pa .stab
13949647Scael.Fa s
14049647Scaeland the
14149647Scael.Fa n_name ,
14249647Scael.Fa n_other ,
14349647Scael.Fa n_desc ,
14449647Scaeland
14549647Scael.Fa n_value
14649647Scaelfields
14749647Scaelof the given
14849647Scael.Fa n_type .
14949647Scael.Em Sdb
15049647Scaeluses the
15149647Scael.Fa n_desc
15249647Scaelfield to hold a type specifier in the form used
15320764Smckusickby the Portable C Compiler,
15449647Scael.Xr cc 1 ;
15549647Scaelsee the header file
15649647Scael.Pa pcc.h
15728283Sdonnfor details on the format of these type values.
15849647Scael.Pp
15920764SmckusickThe Berkeley Pascal compiler,
16049647Scael.Xr pc 1 ,
16149647Scaeluses the following
16249647Scael.Fa n_type
16349647Scaelvalue:
16449647Scael.Bd -literal
16520764Smckusick#define	N_PC	0x30	/* global pascal symbol: name,,0,subtype,line */
16649647Scael.Ed
16749647Scael.Pp
16820764Smckusickand uses the following subtypes to do type checking across separately
16920764Smckusickcompiled files:
17049647Scael.Bd -unfilled -offset indent
17149647Scael1	source file name
17249647Scael2	included file name
17349647Scael3	global label
17449647Scael4	global constant
17549647Scael5	global type
17649647Scael6	global variable
17749647Scael7	global function
17849647Scael8	global procedure
17949647Scael9	external function
18049647Scael10	external procedure
18149647Scael11	library variable
18249647Scael12	library routine
18349647Scael.Ed
18449647Scael.Sh SEE ALSO
18549647Scael.Xr as 1 ,
18649647Scael.Xr ld 1 ,
18749647Scael.Xr dbx 1 ,
18849647Scael.Xr a.out 5
18949647Scael.Sh BUGS
19049647Scael.Pp
19120764SmckusickMore basic types are needed.
19249647Scael.Sh HISTORY
19349647ScaelThe
19449647Scael.Nm stab
19549647Scaelfile appeared in
19649647Scael.Bx 4.0 .
197