xref: /csrg-svn/usr.bin/pascal/src/stab.c (revision 772)
1 /* Copyright (c) 1979 Regents of the University of California */
2 
3     /*
4      *	procedures to put out sdb symbol table information
5      *	    these use the new .stabs, .stabn, and .stabd directives
6      */
7 
8 static	char sccsid[] = "@(#)stab.c 1.1 08/27/80";
9 
10 #include	"whoami.h"
11 #ifdef	PC
12     /*	and the rest of the file */
13 #   include	"0.h"
14 #   include	<stab.h>
15 
16     /*
17      *	here's that ugly name length limit of 8 characters
18      *	until someone fixes sdb.
19      */
20 #define	SNAMELENGTH	8
21 #define	SNAMEFORMAT	"%.*s"
22 /*
23  *  the file "p.a.out" has an additional symbol definition for "a.out.h"
24  *	that is used by the separate compilation facility --
25  *	eventually, "a.out.h" must be updated to include this
26  */
27 
28 #   include	"p.a.out.h"
29 #   include	"pc.h"
30 
31     /*
32      *	variables
33      */
34 stabvar( name , type , level , offset , length )
35     char	*name;
36     int		type;
37     int		level;
38     int		offset;
39     int		length;
40     {
41 	char	*nullchar;
42 	char	*cp;
43 
44 	/* for separate compilation */
45 
46 	if ((level == 1) && (strcmp(name, DISPLAYNAME) != 0)) {
47 		nullchar = name;
48 		while ( *nullchar ) {
49 	    		nullchar ++;
50 		}
51 		for ( cp = name ; cp < nullchar ; cp += SNAMELENGTH ) {
52 		    putprintf( "	.stabs	\"" , 1 );
53 		    putprintf( SNAMEFORMAT , 1 , SNAMELENGTH , cp );
54 	    	    putprintf( "\",0%o,0,0,0" , 0 , N_PGVAR , 0 );
55 		}
56 		if ( cp == nullchar ) {
57 		/*
58 		 * then the name was exactly a multiple of SNAMELENGTH long,
59 		 * and i have to put out a null to terminate it.
60 		 */
61 	    	putprintf( "	.stabn	0%o,0,0,0" , 0
62 			, N_PGVAR, 0 );
63 		}
64     	}
65 
66 	/* for sdb */
67 	if ( ! opt('g') ) {
68 		return;
69 	}
70 	putprintf( "	.stabs	\"" , 1 );
71 	putprintf( NAMEFORMAT , 1 , name );
72 	if ( level == 1 ) {
73 		putprintf( "\",0%o,0,0%o,0" , 0 , N_GSYM , type );
74 	} else {
75 		putprintf( "\",0%o,0,0%o,%d" , 0
76 				, N_LSYM , type , offset);
77 	}
78 	putprintf( "	.stabs	\"" , 1 );
79 	putprintf( NAMEFORMAT , 1 , name );
80 	putprintf( "\",0%o,0,0,0%o" , 0 , N_LENG , length );
81 
82 }
83 
84 
85     /*
86      *	parameters
87      */
88 stabparam( name , type , offset , length )
89     char	*name;
90     int		type;
91     int		offset;
92     int		length;
93     {
94 
95 	if ( ! opt('g') ) {
96 		return;
97 	}
98 	putprintf( "	.stabs	\"" , 1 );
99 	putprintf( NAMEFORMAT , 1 , name );
100 	putprintf( "\",0%o,0,0%o,%d" , 0 , N_PSYM , type , offset );
101 	putprintf( "	.stabs	\"" , 1 );
102 	putprintf( NAMEFORMAT , 1 , name );
103 	putprintf( "\",0%o,0,0,0%o" , 0 , N_LENG , length );
104     }
105 
106     /*
107      *	fields
108      */
109 stabfield( name , type , offset , length )
110     char	*name;
111     int		type;
112     int		offset;
113     int		length;
114     {
115 
116 	if ( ! opt('g') ) {
117 		return;
118 	}
119 	putprintf( "	.stabs	\"" , 1 );
120 	putprintf( NAMEFORMAT , 1 , name );
121 	putprintf( "\",0%o,0,0%o,%d" , 0 , N_SSYM , type , offset );
122 	putprintf( "	.stabs	\"" , 1 );
123 	putprintf( NAMEFORMAT , 1 , name );
124 	putprintf( "\",0%o,0,0,0%o" , 0 , N_LENG , length );
125     }
126 
127     /*
128      *	left brackets
129      */
130 stablbrac( level )
131     int	level;
132     {
133 
134 	if ( ! opt('g') ) {
135 		return;
136 	}
137 	putprintf( "	.stabd	0%o,0,%d" , 0 , N_LBRAC , level );
138     }
139 
140     /*
141      *	right brackets
142      */
143 stabrbrac( level )
144     int	level;
145     {
146 
147 	if ( ! opt('g') ) {
148 		return;
149 	}
150 	putprintf( "	.stabd	0%o,0,%d" , 0 , N_RBRAC , level );
151     }
152 
153     /*
154      *	functions
155      */
156 stabfunc( name , line , level )
157     char	*name;
158     int		line;
159     long	level;
160     {
161 
162 	char	*nullchar;
163 	char	*cp;
164 	int	i;
165 
166 	/*
167 	 *	for separate compilation
168 	 */
169 	nullchar = name;
170 	while ( *nullchar ) {
171 	    	nullchar ++;
172 	}
173 	for ( cp = name ; cp < nullchar ; cp += SNAMELENGTH ) {
174 		putprintf( "	.stabs	\"" , 1 );
175 		putprintf( SNAMEFORMAT , 1 , SNAMELENGTH , cp );
176 	    	putprintf( "\",0%o,0,0,0" , 0 , N_PFUN , 0 );
177 	}
178 	if ( cp == nullchar ) {
179 	putprintf( "	.stabn	0%o,0,0,0" , 0 , N_PFUN, 0 );
180 	}
181 
182 	/* for sdb */
183 	if ( ! opt('g') ) {
184 		return;
185 	}
186 	putprintf( "	.stabs	\"" , 1 );
187 	putprintf( NAMEFORMAT , 1 , name );
188 	putprintf( "\",0%o,0,%d," , 1 , N_FUN , line );
189 	for ( i = 1 ; i < level ; i++ ) {
190 	    putprintf( EXTFORMAT , 1 , enclosing[ i ] );
191 	}
192 	putprintf( EXTFORMAT , 0 , name );
193     }
194 
195     /*
196      *	source line numbers
197      */
198 stabline( line )
199     int	line;
200     {
201 	if ( ! opt('g') ) {
202 		return;
203 	}
204 	if ( line < 0 ) {
205 		/*
206 		 *	line numbers get to be negative if there was an error.
207 		 */
208 	    line = -line;
209 	}
210 
211 	putprintf( "	.stabd	0%o,0,%d" , 0 , N_SLINE , line );
212     }
213 
214     /*
215      *	source files
216      */
217 stabsource( filename )
218     char	*filename;
219     {
220 	int	label = getlab();
221 	char	*nullchar;
222 	char	*cp;
223 
224 	nullchar = filename;
225 	while ( *nullchar ) {
226     		nullchar ++;
227 	}
228 	for ( cp = filename ; cp < nullchar ; cp += SNAMELENGTH ) {
229 	    putprintf( "	.stabs	\"" , 1 );
230 	    putprintf( SNAMEFORMAT , 1 , SNAMELENGTH , cp );
231     	    putprintf( "\",0%o,0,0,0" , 0 , N_PSO , 0 );
232 	}
233 	if ( cp == nullchar ) {
234 	/*
235 	 * then the name was exactly a multiple of SNAMELENGTH long,
236 	 */
237     	putprintf( "	.stabn	0%o,0,0,0" , 0 , N_PSO, 0 );
238 	}
239 
240 	/* for sdb */
241 	if ( ! opt('g') ) {
242 		return;
243 	}
244 	putprintf( "	.stabs	\"" , 1 );
245 	putprintf( NAMEFORMAT , 1 , filename );
246 	putprintf( "\",0%o,0,0," , 1 , N_SO );
247 	putprintf( PREFIXFORMAT , 0 , LLABELPREFIX , label );
248 	putprintf( PREFIXFORMAT , 1 , LLABELPREFIX , label );
249 	putprintf( ":" , 0 );
250     }
251 
252     /*
253      *	included files get one or more of these:
254      *	one as they are entered by a #include,
255      *	and one every time they are returned to by nested #includes
256      */
257 stabinclude( filename )
258     char	*filename;
259     {
260 	int	label = getlab();
261 	char	*nullchar;
262 	char	*cp;
263 
264 	nullchar = filename;
265 	while ( *nullchar ) {
266     		nullchar ++;
267 	}
268 	for ( cp = filename ; cp < nullchar ; cp += SNAMELENGTH ) {
269 	    putprintf( "	.stabs	\"" , 1 );
270 	    putprintf( SNAMEFORMAT , 1 , SNAMELENGTH , cp );
271     	    putprintf( "\",0%o,0,0,0" , 0 , N_PSOL , 0 );
272 	}
273 	if ( cp == nullchar ) {
274 	/*
275 	 * then the name was exactly a multiple of SNAMELENGTH long,
276 	 */
277     	putprintf( "	.stabn	0%o,0,0,0" , 0 , N_PSOL, 0 );
278 	}
279 
280 	/* for sdb */
281 	if ( ! opt('g') ) {
282 		return;
283 	}
284 	putprintf( "	.stabs	\"" , 1 );
285 	putprintf( NAMEFORMAT , 1 , filename );
286 	putprintf( "\",0%o,0,0," , 1 , N_SOL );
287 	putprintf( PREFIXFORMAT , 0 , LLABELPREFIX , label );
288 	putprintf( PREFIXFORMAT , 1 , LLABELPREFIX , label );
289 	putprintf( ":" , 0 );
290     }
291 
292 
293 /*
294  * global Pascal symbols :
295  *   labels, types, constants, and external procedure and function names:
296  *   These are used by the separate compilation facility
297  *   to be able to check for disjoint header files.
298  *   New symbol codes : (N_PGVAR, N_PFUN defined above),
299  *   N_PGLAB, N_PGCON, N_PGTYP
300  *   and N_PEFUN are defined for these additional global Pascal
301  *   symbols in p.a.out.h so that
302  *   they can be ignored by "sdb".  The only information
303  *   put out for constants and types is their names.
304  *   For labels, the integer label is put out. For external functions
305  *   and procedures, the name of the function or procedure is put out.
306  */
307 
308 /* global constants */
309 stabcname( name )
310     char *name;
311 
312     {
313 	char	*nullchar;
314 	char	*cp;
315 
316 	nullchar = name;
317 	while ( *nullchar ) {
318     		nullchar ++;
319 	}
320 	for ( cp = name ; cp < nullchar ; cp += SNAMELENGTH ) {
321 	    putprintf( "	.stabs	\"" , 1 );
322 	    putprintf( SNAMEFORMAT , 1 , SNAMELENGTH , cp );
323     	    putprintf( "\",0%o,0,0,0" , 0 , N_PGCON , 0 );
324 	}
325 	if ( cp == nullchar ) {
326     	putprintf( "	.stabn	0%o,0,0,0" , 0 , N_PGCON, 0 );
327 	}
328 
329     }
330 
331 /* global types */
332 stabtname( name )
333     char *name;
334 
335     {
336 	char	*nullchar;
337 	char	*cp;
338 
339 	nullchar = name;
340 	while ( *nullchar ) {
341     		nullchar ++;
342 	}
343 	for ( cp = name ; cp < nullchar ; cp += SNAMELENGTH ) {
344 	    putprintf( "	.stabs	\"" , 1 );
345 	    putprintf( SNAMEFORMAT , 1 , SNAMELENGTH , cp );
346     	    putprintf( "\",0%o,0,0,0" , 0 , N_PGTYP , 0 );
347 	}
348 	if ( cp == nullchar ) {
349     	putprintf( "	.stabn	0%o,0,0,0" , 0 , N_PGTYP, 0 );
350 	}
351     }
352 
353 /* global labels */
354 stabglab( label )
355     int label;
356 
357     {
358 
359 	putprintf( "	.stabs	\"" , 1 );
360 	putprintf( PREFIXFORMAT , 1 , PLABELPREFIX , label );
361 	putprintf( "\",0%o,0,0,0" , 0 , N_PGLAB , 0 );
362     }
363 
364 
365 /* external functions and procedures */
366 stabefunc( name , line )
367     char *name;
368     int line;
369     {
370 
371 	char	*nullchar;
372 	char	*cp;
373 
374 	nullchar = name;
375 	while ( *nullchar ) {
376     		nullchar ++;
377 	}
378 	for ( cp = name ; cp < nullchar ; cp += SNAMELENGTH ) {
379 	    putprintf( "	.stabs	\"" , 1 );
380 	    putprintf( SNAMEFORMAT , 1 , SNAMELENGTH , cp );
381     	    putprintf( "\",0%o,0,0,0" , 0 , N_PEFUN , 0 );
382 	}
383 	if ( cp == nullchar ) {
384     	putprintf( "	.stabn	0%o,0,0,0" , 0 , N_PEFUN, 0 );
385 	}
386     }
387 
388 #endif PC
389 
390 
391