1*01869ca4Swiz.\" $NetBSD: stab.5,v 1.15 2017/07/03 21:30:59 wiz Exp $ 2b5930afcSjtc.\" 3b5930afcSjtc.\" Copyright (c) 1980, 1991, 1993 4b5930afcSjtc.\" The Regents of the University of California. All rights reserved. 561f28255Scgd.\" 661f28255Scgd.\" Redistribution and use in source and binary forms, with or without 761f28255Scgd.\" modification, are permitted provided that the following conditions 861f28255Scgd.\" are met: 961f28255Scgd.\" 1. Redistributions of source code must retain the above copyright 1061f28255Scgd.\" notice, this list of conditions and the following disclaimer. 1161f28255Scgd.\" 2. Redistributions in binary form must reproduce the above copyright 1261f28255Scgd.\" notice, this list of conditions and the following disclaimer in the 1361f28255Scgd.\" documentation and/or other materials provided with the distribution. 14075022b3Sagc.\" 3. Neither the name of the University nor the names of its contributors 1561f28255Scgd.\" may be used to endorse or promote products derived from this software 1661f28255Scgd.\" without specific prior written permission. 1761f28255Scgd.\" 1861f28255Scgd.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1961f28255Scgd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2061f28255Scgd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2161f28255Scgd.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2261f28255Scgd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2361f28255Scgd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2461f28255Scgd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2561f28255Scgd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2661f28255Scgd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2761f28255Scgd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2861f28255Scgd.\" SUCH DAMAGE. 2961f28255Scgd.\" 30b5930afcSjtc.\" @(#)stab.5 8.1 (Berkeley) 6/5/93 3161f28255Scgd.\" 32b5930afcSjtc.Dd June 5, 1993 3361f28255Scgd.Dt STAB 5 347a1aea16Sgarbled.Os 3561f28255Scgd.Sh NAME 3661f28255Scgd.Nm stab 3761f28255Scgd.Nd symbol table types 3861f28255Scgd.Sh SYNOPSIS 39472351e1Swiz.In stab.h 4061f28255Scgd.Sh DESCRIPTION 4161f28255ScgdThe file 425e015e5eSjoerg.In stab.h 4361f28255Scgddefines some of the symbol table 4461f28255Scgd.Fa n_type 4561f28255Scgdfield values for a.out files. 4661f28255ScgdThese are the types for permanent symbols (i.e. not local labels, etc.) 4761f28255Scgdused by the old debugger 4861f28255Scgd.Em sdb 4961f28255Scgdand the Berkeley Pascal compiler 50f20ee1a9Swiz.Ic pc . 5161f28255ScgdSymbol table entries can be produced by the 5261f28255Scgd.Pa .stabs 5361f28255Scgdassembler directive. 5461f28255ScgdThis allows one to specify a double-quote delimited name, a symbol type, 5561f28255Scgdone char and one short of information about the symbol, and an unsigned 5661f28255Scgdlong (usually an address). 5761f28255ScgdTo avoid having to produce an explicit label for the address field, 5861f28255Scgdthe 5961f28255Scgd.Pa .stabd 6061f28255Scgddirective can be used to implicitly address the current location. 6161f28255ScgdIf no name is needed, symbol table entries can be generated using the 6261f28255Scgd.Pa .stabn 6361f28255Scgddirective. 6461f28255ScgdThe loader promises to preserve the order of symbol table entries produced 6561f28255Scgdby 6661f28255Scgd.Pa .stab 6761f28255Scgddirectives. 6861f28255ScgdAs described in 6961f28255Scgd.Xr a.out 5 , 7061f28255Scgdan element of the symbol table 7161f28255Scgdconsists of the following structure: 7261f28255Scgd.Bd -literal 7361f28255Scgd/* 7461f28255Scgd* Format of a symbol table entry. 7561f28255Scgd*/ 7661f28255Scgd 7761f28255Scgdstruct nlist { 7861f28255Scgd union { 7961f28255Scgd char *n_name; /* for use when in-core */ 8061f28255Scgd long n_strx; /* index into file string table */ 8161f28255Scgd } n_un; 8261f28255Scgd unsigned char n_type; /* type flag */ 8361f28255Scgd char n_other; /* unused */ 8461f28255Scgd short n_desc; /* see struct desc, below */ 8561f28255Scgd unsigned n_value; /* address or offset or line */ 8661f28255Scgd}; 8761f28255Scgd.Ed 8861f28255Scgd.Pp 8961f28255ScgdThe low bits of the 9061f28255Scgd.Fa n_type 9161f28255Scgdfield are used to place a symbol into 9261f28255Scgdat most one segment, according to 9361f28255Scgdthe following masks, defined in 945e015e5eSjoerg.In a.out.h . 9561f28255ScgdA symbol can be in none of these segments by having none of these segment 9661f28255Scgdbits set. 9761f28255Scgd.Bd -literal 9861f28255Scgd/* 9961f28255Scgd* Simple values for n_type. 10061f28255Scgd*/ 10161f28255Scgd 10261f28255Scgd#define N_UNDF 0x0 /* undefined */ 10361f28255Scgd#define N_ABS 0x2 /* absolute */ 10461f28255Scgd#define N_TEXT 0x4 /* text */ 10561f28255Scgd#define N_DATA 0x6 /* data */ 10661f28255Scgd#define N_BSS 0x8 /* bss */ 10761f28255Scgd 10861f28255Scgd#define N_EXT 01 /* external bit, or'ed in */ 10961f28255Scgd.Ed 11061f28255Scgd.Pp 11161f28255ScgdThe 11261f28255Scgd.Fa n_value 11361f28255Scgdfield of a symbol is relocated by the linker, 11461f28255Scgd.Xr ld 1 11561f28255Scgdas an address within the appropriate segment. 116f35b097bSlukem.Fa n_value 11761f28255Scgdfields of symbols not in any segment are unchanged by the linker. 11861f28255ScgdIn addition, the linker will discard certain symbols, according to rules 11961f28255Scgdof its own, unless the 12061f28255Scgd.Fa n_type 12161f28255Scgdfield has one of the following bits set: 12261f28255Scgd.Bd -literal 12361f28255Scgd/* 12461f28255Scgd* Other permanent symbol table entries have some of the N_STAB bits set. 125*01869ca4Swiz* These are given in <stab.h> 12661f28255Scgd*/ 12761f28255Scgd 12861f28255Scgd#define N_STAB 0xe0 /* if any of these bits set, don't discard */ 12961f28255Scgd.Ed 13061f28255Scgd.Pp 13161f28255ScgdThis allows up to 112 (7 \(** 16) symbol types, split between the various 13261f28255Scgdsegments. 13361f28255ScgdSome of these have already been claimed. 13461f28255ScgdThe old symbolic debugger, 13561f28255Scgd.Em sdb , 13661f28255Scgduses the following n_type values: 13761f28255Scgd.Bd -literal 13861f28255Scgd#define N_GSYM 0x20 /* global symbol: name,,0,type,0 */ 13961f28255Scgd#define N_FNAME 0x22 /* procedure name (f77 kludge): name,,0 */ 14061f28255Scgd#define N_FUN 0x24 /* procedure: name,,0,linenumber,address */ 14161f28255Scgd#define N_STSYM 0x26 /* static symbol: name,,0,type,address */ 14261f28255Scgd#define N_LCSYM 0x28 /* .lcomm symbol: name,,0,type,address */ 14361f28255Scgd#define N_RSYM 0x40 /* register sym: name,,0,type,register */ 14461f28255Scgd#define N_SLINE 0x44 /* src line: 0,,0,linenumber,address */ 14561f28255Scgd#define N_SSYM 0x60 /* structure elt: name,,0,type,struct_offset */ 14661f28255Scgd#define N_SO 0x64 /* source file name: name,,0,0,address */ 14761f28255Scgd#define N_LSYM 0x80 /* local sym: name,,0,type,offset */ 14861f28255Scgd#define N_SOL 0x84 /* #included file name: name,,0,0,address */ 14961f28255Scgd#define N_PSYM 0xa0 /* parameter: name,,0,type,offset */ 15075e150fcSmouse#define N_ENTRY 0xa4 /* alternative entry: name,linenumber,address */ 15161f28255Scgd#define N_LBRAC 0xc0 /* left bracket: 0,,0,nesting level,address */ 15261f28255Scgd#define N_RBRAC 0xe0 /* right bracket: 0,,0,nesting level,address */ 15361f28255Scgd#define N_BCOMM 0xe2 /* begin common: name,, */ 15461f28255Scgd#define N_ECOMM 0xe4 /* end common: name,, */ 15561f28255Scgd#define N_ECOML 0xe8 /* end common (local name): ,,address */ 15661f28255Scgd#define N_LENG 0xfe /* second stab entry with length information */ 15761f28255Scgd.Ed 15861f28255Scgd.Pp 15961f28255Scgdwhere the comments give 16061f28255Scgd.Em sdb 16161f28255Scgdconventional use for 16261f28255Scgd.Pa .stab 16361f28255Scgd.Fa s 16461f28255Scgdand the 16561f28255Scgd.Fa n_name , 16661f28255Scgd.Fa n_other , 16761f28255Scgd.Fa n_desc , 16861f28255Scgdand 16961f28255Scgd.Fa n_value 17061f28255Scgdfields 17161f28255Scgdof the given 17261f28255Scgd.Fa n_type . 17361f28255Scgd.Em Sdb 17461f28255Scgduses the 17561f28255Scgd.Fa n_desc 17661f28255Scgdfield to hold a type specifier in the form used 17761f28255Scgdby the Portable C Compiler, 17861f28255Scgd.Xr cc 1 ; 17961f28255Scgdsee the header file 18061f28255Scgd.Pa pcc.h 18161f28255Scgdfor details on the format of these type values. 18261f28255Scgd.Pp 18361f28255ScgdThe Berkeley Pascal compiler, 184f20ee1a9Swiz.Ic pc , 18561f28255Scgduses the following 18661f28255Scgd.Fa n_type 18761f28255Scgdvalue: 18861f28255Scgd.Bd -literal 18961f28255Scgd#define N_PC 0x30 /* global pascal symbol: name,,0,subtype,line */ 19061f28255Scgd.Ed 19161f28255Scgd.Pp 19261f28255Scgdand uses the following subtypes to do type checking across separately 19361f28255Scgdcompiled files: 19461f28255Scgd.Bd -unfilled -offset indent 19561f28255Scgd1 source file name 19661f28255Scgd2 included file name 19761f28255Scgd3 global label 19861f28255Scgd4 global constant 19961f28255Scgd5 global type 20061f28255Scgd6 global variable 20161f28255Scgd7 global function 20261f28255Scgd8 global procedure 20361f28255Scgd9 external function 20461f28255Scgd10 external procedure 20561f28255Scgd11 library variable 20661f28255Scgd12 library routine 20761f28255Scgd.Ed 20861f28255Scgd.Sh SEE ALSO 20961f28255Scgd.Xr as 1 , 210cb104d7cSmikel.Xr gdb 1 , 21142704c41Swiz.Xr ld 1 , 21261f28255Scgd.Xr a.out 5 21361f28255Scgd.Sh HISTORY 21461f28255ScgdThe 21561f28255Scgd.Nm stab 21661f28255Scgdfile appeared in 21761f28255Scgd.Bx 4.0 . 21842704c41Swiz.Sh BUGS 21942704c41SwizMore basic types are needed. 220