BSD 3 development
[unix-history] / usr / doc / sdb / sdbsymtab.n
CommitLineData
ced7ad5d
HK
1.so /usr/lib/tmac/tmac.s
2.MF
3.TL
4Symbol Table Format for Sdb
5.ft R
6.br
7.ps -2
8Case: 39394 File 39394
9.ps +2
10.ft R
11.AU
12H.P. Katseff
13.AI
14.HO
15.NH
16Introduction.
17.PP
18A symbolic debugger, sdb,
19has been implemented for the UNIX/32V operating system.
20This document describes modifications made to
21the C compiler to generate additional
22information about the compiled program and to the
23assembler and loader to process the information.
24It also describes information recognized by the assembler, the loader
25and sdb which are intended for use by compilers for other languages
26such as F77.
27.NH
28The C Compiler
29.PP
30The C compiler was modified to generate additional symbol table
31information describing a compiled program.
32Two new types of symbol table entries are made.
33One describes the variables, giving
34their class (local, register, parameter, global, etc.),
35their declared type in the program
36and their address or offset.
37An additional entry is made for structures giving their size.
38The other type of entry provides a mapping between the source program
39and the object program.
40There is an entry for each source line, procedure and source file
41giving their addresses in the object file.
42All line numbers are relative to the beginning of
43the source file.
44.PP
45All entries are generated with the new assembler pseudo-operation
46`.stab'.
47It always takes 12 arguments of which the first eight usually
48represent the name of the symbol as declared in the C program.
49An underscore is
50.ul
51not
52prepended to the name as in some other symbol table entries.
53A typical entry would be
54.DS C
55\&.stab 'e,'r,'r,'f,'l,'g,0,0,046,0,05,_errflg
56.DE
57For expository convenience,
58names in .stab entries will be listed as one word instead of
59eight separate characters.
60.NH 2
61External symbols defined with .comm
62.PP
63The following entry is made for each external symbol which is
64defined with a .comm pseudo-op.
65.DS C
66\&.stab name,040,0,type,0
67.DE
68The type is a 16-bit value describing the variable's declared type.
69This field is described in section 2.13.
70The debugger determines the variable's address
71from the entry made with the .comm.
72It assumes that the name for this entry is _name.
73.NH 2
74Symbols defined within .data areas
75.PP
76The following entry is made for each symbol which is defined
77as a label in a data area.
78.DS C
79\&.stab name,046,0,type,address
80.DE
81The type is the variable's declared type.
82The address is given symbolically as the label.
83.NH 2
84Symbols defined with .lcomm
85.PP
86The following entry is made for each symbol which is defined with
87a .lcomm pseudo-op.
88.DS C
89\&.stab name,048,0,type,address
90.DE
91The type is the variable's declared type.
92The address is given symbolically as the label.
93The specification of an octal constant with an 8 occurs for historical
94reasons.
95.NH 2
96Register symbols
97.PP
98The following entry is made for each variable whose value
99is in a register.
100.DS C
101\&.stab name,0100,0,type,register
102.DE
103The type is the variable's declared type.
104The register is the register number assigned to the variable.
105.NH 2
106Local non-register symbols
107.PP
108The following entry is made for each local, non-register variable.
109.DS C
110\&.stab name,0200,0,type,offset
111.DE
112The type is the variable's declared type.
113The offset is a positive number indicating its offset in bytes for the
114frame pointer.
115.NH 2
116Parameter symbols
117.PP
118The following entry is made for each procedure parameter.
119.DS C
120\&.stab name,0240,0,type,offset
121.DE
122The type is the variable's declared type.
123The offset is a positive number indicating its offset in bytes from
124the stack pointer.
125.NH 2
126Structure elements
127.PP
128The following entry is made for each structure element.
129.DS C
130\&.stab name,0140,0,type,offset
131.DE
132The type is the element's declared type.
133The offset is its offset within the structure in bytes.
134.NH 2
135Structure symbols
136.PP
137An additional entry is made for structures giving their size in bytes.
138It immediately follows their defining .stab entry.
139It is of the form
140.DS C
141\&.stab name,0376,0,0,length
142.DE
143.NH 2
144Common blocks
145.PP
146The following sequence of entries is used to describe elements of
147Fortran equivalence and common blocks.
148The first is of the form
149.DS C
150\&.stab 0,0342,0,0,0
151.DE
152The entries for each element of the block should then appear
153as if they were structure elements.
154Finally, one of the following
155two entries is used depending on the type of common
156or equivalence block.
157If the block is defined as a .globl symbol, use the entry
158.DS C
159\&.stab name,0344,0,0,0
160.DE
161where name is the name of the block defined in the .globl statement.
162It the block is defined in some other way, use
163.DS C
164\&.stab 0,0348,0,0,address
165.DE
166.NH 2
167Brackets
168.PP
169Since C is a block-structured language,
170it is necessary to know the extent of each block containing symbol definitions.
171An entry is made for each right and left bracket which encloses
172a block with definitions.
173The following entries are for left and right brackets respectively.
174.DS C
175\&.stab 0,0300,0,nesting level,address
176\&.stab 0,0340,0,nesting level,address
177.DE
178The nesting level is the static nesting level of the block.
179It is currently ignored by the debugger.
180The address is the address of the first byte of code for the block
181for the left brackets and the first byte following the block
182for right brackets.
183.NH 2
184Procedures
185.PP
186The following entry is made for each procedure.
187.DS C
188\&.stab name,044,0,linenumber,address
189.DE
190The linenumber is the number of the first line of the procedure in the
191source file.
192The address is the address of the first byte of the procedure.
193.NH 2
194Lines
195.PP
196The following entry is made for each line in the source program.
197.DS C
198\&.stab 0,0104,0,linenumber,address
199.DE
200The linenumber is its number.
201The address is the address of the first byte of code for the line.
202For each block of the program,
203the linenumber entries for that block should follow the entries
204for the variables of that block.
205.NH 2
206Source files
207.PP
208The following entries are made for each source file.
209.DS C
210\&.stab name1,0144,0,0,address
211\&.stab name2,0144,0,0,address
212\&...
213\&.stab namen,0144,0,0,address
214.DE
215Each entry contains 8 successive bytes of the name of the source file.
216The name is terminated by a null byte.
217All bytes following this one should also be null.
218The address is the address of the first byte of code for the first
219procedure of the file.
220.NH 2
221Included source files
222.PP
223The following entry is made for each included source file which
224generates code.
225.DS C
226\&.stab name1,0204,0,0,address
227\&.stab name2,0204,0,0,address
228\&...
229\&.stab namen,0204,0,0,address
230.DE
231This entry should appear each time the file is included.
232A similar entry giving the name of the original file should be
233made at the end of the include.
234The format of the name is identical to that for files.
235This feature is heavily used by programs generated by yacc and lex.
236.NH 2
237Format of types.
238.PP
239This 16 bit quantity type describes the declared type of a variable.
240We use the same scheme as in S.C. Johnson's Portable C Compiler
241[Johnson, 1978].
242The type is divided into the following fields:
243.DS
244 struct {
245 short basic:4;
246 d1:2,
247 d2:2,
248 d3:2,
249 d4:2,
250 d5:2,
251 d6:2,
252 }
253.DE
254There are four derived types:
255.DS
256 0 none
257 1 pointer
258 2 function
259 3 array
260.DE
261They are indicated in the two bit fields d1, d2, d3, d4, d5 and d6.
262The four bit field basic indicates the basic type as follows:
263.DS
264 0 undefined
265 1 function argument
266 2 character
267 3 short
268 4 int
269 5 long
270 6 float
271 7 double
272 8 structure
273 9 union
274 10 enumerated type
275 11 member of enumerated type
276 12 unsigned character
277 13 unsigned short
278 14 unsigned
279 15 unsigned long
280.DE
281.NH 1
282The assembler and loader
283.PP
284Each .stab pseudo-operation generates one entry in the symbol table.
285The entry is of the form:
286.DS
287 struct {
288 char name[8];
289 char type;
290 char other;
291 short desc;
292 unsigned value;
293 }
294.DE
295.PP
296The loader uses the four least significant bits of the type field
297to determine how to relocate the .stab entry.
298The following are currently used.
299.DS
300 0 none
301 4 text
302 6 data
303.DE
304.PP
305It is necessary for the assembler and loader to preserve the order
306of symbol table entries produced by .stab pseudo-ops.
307.SH
308Reference
309.LP
310Johnson, S.C., "A Portable Compiler: Theory and Practice",
311.I
312Proc. 5th ACM Symp. on Principles of Programming Languages,
313.R
314January 1978.
315.bp
316.SH
317Appendix
318.PP
319The following definitions are extracted from the file /usr/include/a.out.h.
320.sp 1
321.nf
322.na
323struct nlist { /* symbol table entry */
324 char n_name[8]; /* symbol name */
325 char n_type; /* type flag */
326 char n_other;
327 short n_desc;
328 unsigned n_value; /* value */
329};
330
331 /* values for type flag */
332#define N_UNDF 0 /* undefined */
333#define N_ABS 02 /* absolute */
334#define N_TEXT 04 /* text */
335#define N_DATA 06 /* data */
336#define N_BSS 08
337#define N_TYPE 037
338#define N_FN 037 /* file name symbol */
339
340#define N_GSYM 0040 /* global sym: name,,type,0 */
341#define N_FUN 0044 /* function: name,,linenumber,address */
342#define N_STSYM 0046 /* static symbol: name,,type,address */
343#define N_LCSYM 0048 /* .lcomm symbol: name,,type,address */
344#define N_RSYM 0100 /* register sym: name,,register,offset */
345#define N_SLINE 0104 /* src line: ,,linenumber,address */
346#define N_SSYM 0140 /* structure elt: name,,type,struct_offset */
347#define N_SO 0144 /* source file name: name,,,address */
348#define N_LSYM 0200 /* local sym: name,,type,offset */
349#define N_SOL 0204 /* #line source filename: name,,,address */
350#define N_PSYM 0240 /* parameter: name,,type,offset */
351#define N_LBRAC 0300 /* left bracket: ,,nesting level,address */
352#define N_RBRAC 0340 /* right bracket: ,,nesting level,address */
353#define N_BCOMM 0342 /* begin common: name,,, */
354#define N_ECOMM 0344 /* end common: name,,, */
355#define N_ECOML 0348 /* end common (local name): ,,,address */
356#define N_LENG 0376 /* second stab entry with length information */
357
358#define N_EXT 01 /* external bit, or'ed in */
359
360#define FORMAT "%08x"
361
362#define STABTYPES 0340
363.fi
364.ad
365.SG HO-1353-HPK-sdb
366.sp 2
367Copy to
368.br
369R.W. Lucky
370.br
371C.S. Roberts