Commit | Line | Data |
---|---|---|
ced7ad5d HK |
1 | .so /usr/lib/tmac/tmac.s |
2 | .MF | |
3 | .TL | |
4 | Symbol Table Format for Sdb | |
5 | .ft R | |
6 | .br | |
7 | .ps -2 | |
8 | Case: 39394 File 39394 | |
9 | .ps +2 | |
10 | .ft R | |
11 | .AU | |
12 | H.P. Katseff | |
13 | .AI | |
14 | .HO | |
15 | .NH | |
16 | Introduction. | |
17 | .PP | |
18 | A symbolic debugger, sdb, | |
19 | has been implemented for the UNIX/32V operating system. | |
20 | This document describes modifications made to | |
21 | the C compiler to generate additional | |
22 | information about the compiled program and to the | |
23 | assembler and loader to process the information. | |
24 | It also describes information recognized by the assembler, the loader | |
25 | and sdb which are intended for use by compilers for other languages | |
26 | such as F77. | |
27 | .NH | |
28 | The C Compiler | |
29 | .PP | |
30 | The C compiler was modified to generate additional symbol table | |
31 | information describing a compiled program. | |
32 | Two new types of symbol table entries are made. | |
33 | One describes the variables, giving | |
34 | their class (local, register, parameter, global, etc.), | |
35 | their declared type in the program | |
36 | and their address or offset. | |
37 | An additional entry is made for structures giving their size. | |
38 | The other type of entry provides a mapping between the source program | |
39 | and the object program. | |
40 | There is an entry for each source line, procedure and source file | |
41 | giving their addresses in the object file. | |
42 | All line numbers are relative to the beginning of | |
43 | the source file. | |
44 | .PP | |
45 | All entries are generated with the new assembler pseudo-operation | |
46 | `.stab'. | |
47 | It always takes 12 arguments of which the first eight usually | |
48 | represent the name of the symbol as declared in the C program. | |
49 | An underscore is | |
50 | .ul | |
51 | not | |
52 | prepended to the name as in some other symbol table entries. | |
53 | A typical entry would be | |
54 | .DS C | |
55 | \&.stab 'e,'r,'r,'f,'l,'g,0,0,046,0,05,_errflg | |
56 | .DE | |
57 | For expository convenience, | |
58 | names in .stab entries will be listed as one word instead of | |
59 | eight separate characters. | |
60 | .NH 2 | |
61 | External symbols defined with .comm | |
62 | .PP | |
63 | The following entry is made for each external symbol which is | |
64 | defined with a .comm pseudo-op. | |
65 | .DS C | |
66 | \&.stab name,040,0,type,0 | |
67 | .DE | |
68 | The type is a 16-bit value describing the variable's declared type. | |
69 | This field is described in section 2.13. | |
70 | The debugger determines the variable's address | |
71 | from the entry made with the .comm. | |
72 | It assumes that the name for this entry is _name. | |
73 | .NH 2 | |
74 | Symbols defined within .data areas | |
75 | .PP | |
76 | The following entry is made for each symbol which is defined | |
77 | as a label in a data area. | |
78 | .DS C | |
79 | \&.stab name,046,0,type,address | |
80 | .DE | |
81 | The type is the variable's declared type. | |
82 | The address is given symbolically as the label. | |
83 | .NH 2 | |
84 | Symbols defined with .lcomm | |
85 | .PP | |
86 | The following entry is made for each symbol which is defined with | |
87 | a .lcomm pseudo-op. | |
88 | .DS C | |
89 | \&.stab name,048,0,type,address | |
90 | .DE | |
91 | The type is the variable's declared type. | |
92 | The address is given symbolically as the label. | |
93 | The specification of an octal constant with an 8 occurs for historical | |
94 | reasons. | |
95 | .NH 2 | |
96 | Register symbols | |
97 | .PP | |
98 | The following entry is made for each variable whose value | |
99 | is in a register. | |
100 | .DS C | |
101 | \&.stab name,0100,0,type,register | |
102 | .DE | |
103 | The type is the variable's declared type. | |
104 | The register is the register number assigned to the variable. | |
105 | .NH 2 | |
106 | Local non-register symbols | |
107 | .PP | |
108 | The following entry is made for each local, non-register variable. | |
109 | .DS C | |
110 | \&.stab name,0200,0,type,offset | |
111 | .DE | |
112 | The type is the variable's declared type. | |
113 | The offset is a positive number indicating its offset in bytes for the | |
114 | frame pointer. | |
115 | .NH 2 | |
116 | Parameter symbols | |
117 | .PP | |
118 | The following entry is made for each procedure parameter. | |
119 | .DS C | |
120 | \&.stab name,0240,0,type,offset | |
121 | .DE | |
122 | The type is the variable's declared type. | |
123 | The offset is a positive number indicating its offset in bytes from | |
124 | the stack pointer. | |
125 | .NH 2 | |
126 | Structure elements | |
127 | .PP | |
128 | The following entry is made for each structure element. | |
129 | .DS C | |
130 | \&.stab name,0140,0,type,offset | |
131 | .DE | |
132 | The type is the element's declared type. | |
133 | The offset is its offset within the structure in bytes. | |
134 | .NH 2 | |
135 | Structure symbols | |
136 | .PP | |
137 | An additional entry is made for structures giving their size in bytes. | |
138 | It immediately follows their defining .stab entry. | |
139 | It is of the form | |
140 | .DS C | |
141 | \&.stab name,0376,0,0,length | |
142 | .DE | |
143 | .NH 2 | |
144 | Common blocks | |
145 | .PP | |
146 | The following sequence of entries is used to describe elements of | |
147 | Fortran equivalence and common blocks. | |
148 | The first is of the form | |
149 | .DS C | |
150 | \&.stab 0,0342,0,0,0 | |
151 | .DE | |
152 | The entries for each element of the block should then appear | |
153 | as if they were structure elements. | |
154 | Finally, one of the following | |
155 | two entries is used depending on the type of common | |
156 | or equivalence block. | |
157 | If the block is defined as a .globl symbol, use the entry | |
158 | .DS C | |
159 | \&.stab name,0344,0,0,0 | |
160 | .DE | |
161 | where name is the name of the block defined in the .globl statement. | |
162 | It the block is defined in some other way, use | |
163 | .DS C | |
164 | \&.stab 0,0348,0,0,address | |
165 | .DE | |
166 | .NH 2 | |
167 | Brackets | |
168 | .PP | |
169 | Since C is a block-structured language, | |
170 | it is necessary to know the extent of each block containing symbol definitions. | |
171 | An entry is made for each right and left bracket which encloses | |
172 | a block with definitions. | |
173 | The 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 | |
178 | The nesting level is the static nesting level of the block. | |
179 | It is currently ignored by the debugger. | |
180 | The address is the address of the first byte of code for the block | |
181 | for the left brackets and the first byte following the block | |
182 | for right brackets. | |
183 | .NH 2 | |
184 | Procedures | |
185 | .PP | |
186 | The following entry is made for each procedure. | |
187 | .DS C | |
188 | \&.stab name,044,0,linenumber,address | |
189 | .DE | |
190 | The linenumber is the number of the first line of the procedure in the | |
191 | source file. | |
192 | The address is the address of the first byte of the procedure. | |
193 | .NH 2 | |
194 | Lines | |
195 | .PP | |
196 | The following entry is made for each line in the source program. | |
197 | .DS C | |
198 | \&.stab 0,0104,0,linenumber,address | |
199 | .DE | |
200 | The linenumber is its number. | |
201 | The address is the address of the first byte of code for the line. | |
202 | For each block of the program, | |
203 | the linenumber entries for that block should follow the entries | |
204 | for the variables of that block. | |
205 | .NH 2 | |
206 | Source files | |
207 | .PP | |
208 | The 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 | |
215 | Each entry contains 8 successive bytes of the name of the source file. | |
216 | The name is terminated by a null byte. | |
217 | All bytes following this one should also be null. | |
218 | The address is the address of the first byte of code for the first | |
219 | procedure of the file. | |
220 | .NH 2 | |
221 | Included source files | |
222 | .PP | |
223 | The following entry is made for each included source file which | |
224 | generates 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 | |
231 | This entry should appear each time the file is included. | |
232 | A similar entry giving the name of the original file should be | |
233 | made at the end of the include. | |
234 | The format of the name is identical to that for files. | |
235 | This feature is heavily used by programs generated by yacc and lex. | |
236 | .NH 2 | |
237 | Format of types. | |
238 | .PP | |
239 | This 16 bit quantity type describes the declared type of a variable. | |
240 | We use the same scheme as in S.C. Johnson's Portable C Compiler | |
241 | [Johnson, 1978]. | |
242 | The 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 | |
254 | There are four derived types: | |
255 | .DS | |
256 | 0 none | |
257 | 1 pointer | |
258 | 2 function | |
259 | 3 array | |
260 | .DE | |
261 | They are indicated in the two bit fields d1, d2, d3, d4, d5 and d6. | |
262 | The 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 | |
282 | The assembler and loader | |
283 | .PP | |
284 | Each .stab pseudo-operation generates one entry in the symbol table. | |
285 | The 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 | |
296 | The loader uses the four least significant bits of the type field | |
297 | to determine how to relocate the .stab entry. | |
298 | The following are currently used. | |
299 | .DS | |
300 | 0 none | |
301 | 4 text | |
302 | 6 data | |
303 | .DE | |
304 | .PP | |
305 | It is necessary for the assembler and loader to preserve the order | |
306 | of symbol table entries produced by .stab pseudo-ops. | |
307 | .SH | |
308 | Reference | |
309 | .LP | |
310 | Johnson, S.C., "A Portable Compiler: Theory and Practice", | |
311 | .I | |
312 | Proc. 5th ACM Symp. on Principles of Programming Languages, | |
313 | .R | |
314 | January 1978. | |
315 | .bp | |
316 | .SH | |
317 | Appendix | |
318 | .PP | |
319 | The following definitions are extracted from the file /usr/include/a.out.h. | |
320 | .sp 1 | |
321 | .nf | |
322 | .na | |
323 | struct 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 | |
367 | Copy to | |
368 | .br | |
369 | R.W. Lucky | |
370 | .br | |
371 | C.S. Roberts |