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