1 /* Copyright (c) 1980 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)stab.c 1.7 08/27/82"; 4 5 /* 6 * procedures to put out sdb symbol table information. 7 * and stabs for separate compilation type checking. 8 * these use the new .stabs, .stabn, and .stabd directives 9 */ 10 11 #include "whoami.h" 12 #ifdef PC 13 /* and the rest of the file */ 14 # include "0.h" 15 # include <stab.h> 16 17 /* 18 * additional symbol definition for <stab.h> 19 * that is used by the separate compilation facility -- 20 * eventually, <stab.h> should be updated to include this 21 */ 22 23 # include "pstab.h" 24 # include "pc.h" 25 26 /* 27 * absolute value: line numbers are negative if error recovery. 28 */ 29 #define ABS( x ) ( x < 0 ? -x : x ) 30 31 /* 32 * global variables 33 */ 34 stabgvar( name , type , offset , length , line ) 35 char *name; 36 int type; 37 int offset; 38 int length; 39 int line; 40 { 41 42 /* 43 * for separate compilation 44 */ 45 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0 46 , name , N_PC , N_PGVAR , ABS( line ) ); 47 /* 48 * for sdb 49 */ 50 if ( ! opt('g') ) { 51 return; 52 } 53 putprintf( " .stabs \"" , 1 ); 54 putprintf( NAMEFORMAT , 1 , name ); 55 putprintf( "\",0x%x,0,0x%x,0" , 0 , N_GSYM , type ); 56 putprintf( " .stabs \"" , 1 ); 57 putprintf( NAMEFORMAT , 1 , name ); 58 putprintf( "\",0x%x,0,0,0x%x" , 0 , N_LENG , length ); 59 } 60 61 /* 62 * local variables 63 */ 64 stablvar( name , type , level , offset , length ) 65 char *name; 66 int type; 67 int level; 68 int offset; 69 int length; 70 { 71 72 if ( ! opt('g') ) { 73 return; 74 } 75 putprintf( " .stabs \"" , 1 ); 76 putprintf( NAMEFORMAT , 1 , name ); 77 putprintf( "\",0x%x,0,0x%x,0x%x" , 0 , N_LSYM , type , -offset ); 78 putprintf( " .stabs \"" , 1 ); 79 putprintf( NAMEFORMAT , 1 , name ); 80 putprintf( "\",0x%x,0,0,0x%x" , 0 , N_LENG , length ); 81 } 82 83 84 /* 85 * parameters 86 */ 87 stabparam( name , type , offset , length ) 88 char *name; 89 int type; 90 int offset; 91 int length; 92 { 93 94 if ( ! opt('g') ) { 95 return; 96 } 97 putprintf( " .stabs \"" , 1 ); 98 putprintf( NAMEFORMAT , 1 , name ); 99 putprintf( "\",0x%x,0,0x%x,0x%x" , 0 , N_PSYM , type , offset ); 100 putprintf( " .stabs \"" , 1 ); 101 putprintf( NAMEFORMAT , 1 , name ); 102 putprintf( "\",0x%x,0,0,0x%x" , 0 , N_LENG , length ); 103 } 104 105 /* 106 * fields 107 */ 108 stabfield( name , type , offset , length ) 109 char *name; 110 int type; 111 int offset; 112 int length; 113 { 114 115 if ( ! opt('g') ) { 116 return; 117 } 118 putprintf( " .stabs \"" , 1 ); 119 putprintf( NAMEFORMAT , 1 , name ); 120 putprintf( "\",0x%x,0,0x%x,0x%x" , 0 , N_SSYM , type , offset ); 121 putprintf( " .stabs \"" , 1 ); 122 putprintf( NAMEFORMAT , 1 , name ); 123 putprintf( "\",0x%x,0,0,0x%x" , 0 , N_LENG , length ); 124 } 125 126 /* 127 * left brackets 128 */ 129 stablbrac( level ) 130 int level; 131 { 132 133 if ( ! opt('g') ) { 134 return; 135 } 136 putprintf( " .stabd 0x%x,0,0x%x" , 0 , N_LBRAC , level ); 137 } 138 139 /* 140 * right brackets 141 */ 142 stabrbrac( level ) 143 int level; 144 { 145 146 if ( ! opt('g') ) { 147 return; 148 } 149 putprintf( " .stabd 0x%x,0,0x%x" , 0 , N_RBRAC , level ); 150 } 151 152 /* 153 * functions 154 */ 155 stabfunc( name , typeclass , line , level ) 156 char *name; 157 int typeclass; 158 int line; 159 long level; 160 { 161 int type; 162 long i; 163 char extname[ BUFSIZ ]; 164 165 /* 166 * for separate compilation 167 */ 168 if ( level == 1 ) { 169 if ( typeclass == FUNC ) { 170 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0 171 , name , N_PC , N_PGFUNC , ABS( line ) ); 172 } else if ( typeclass == PROC ) { 173 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0 174 , name , N_PC , N_PGPROC , ABS( line ) ); 175 } 176 } 177 /* 178 * for sdb 179 */ 180 if ( ! opt('g') ) { 181 return; 182 } 183 putprintf( " .stabs \"" , 1 ); 184 putprintf( NAMEFORMAT , 1 , name ); 185 sextname( extname , name , level ); 186 putprintf( "\",0x%x,0,0x%x,%s" , 0 , N_FUN , line , extname ); 187 } 188 189 /* 190 * source line numbers 191 */ 192 stabline( line ) 193 int line; 194 { 195 if ( ! opt('g') ) { 196 return; 197 } 198 putprintf( " .stabd 0x%x,0,0x%x" , 0 , N_SLINE , ABS( line ) ); 199 } 200 201 /* 202 * source files 203 */ 204 stabsource( filename ) 205 char *filename; 206 { 207 int label; 208 209 /* 210 * for separate compilation 211 */ 212 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0" , 0 213 , filename , N_PC , N_PSO ); 214 /* 215 * for sdb 216 */ 217 if ( ! opt('g') ) { 218 return; 219 } 220 label = getlab(); 221 putprintf( " .stabs \"" , 1 ); 222 putprintf( NAMEFORMAT , 1 , filename ); 223 putprintf( "\",0x%x,0,0," , 1 , N_SO ); 224 putprintf( PREFIXFORMAT , 0 , LLABELPREFIX , label ); 225 putprintf( PREFIXFORMAT , 1 , LLABELPREFIX , label ); 226 putprintf( ":" , 0 ); 227 } 228 229 /* 230 * included files get one or more of these: 231 * one as they are entered by a #include, 232 * and one every time they are returned to by nested #includes 233 */ 234 stabinclude( filename ) 235 char *filename; 236 { 237 int label; 238 239 /* 240 * for separate compilation 241 */ 242 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0" , 0 243 , filename , N_PC , N_PSOL ); 244 /* 245 * for sdb 246 */ 247 if ( ! opt('g') ) { 248 return; 249 } 250 label = getlab(); 251 putprintf( " .stabs \"" , 1 ); 252 putprintf( NAMEFORMAT , 1 , filename ); 253 putprintf( "\",0x%x,0,0," , 1 , N_SOL ); 254 putprintf( PREFIXFORMAT , 0 , LLABELPREFIX , label ); 255 putprintf( PREFIXFORMAT , 1 , LLABELPREFIX , label ); 256 putprintf( ":" , 0 ); 257 } 258 259 260 /* 261 * global Pascal symbols : 262 * labels, types, constants, and external procedure and function names: 263 * These are used by the separate compilation facility 264 * to be able to check for disjoint header files. 265 */ 266 267 /* 268 * global labels 269 */ 270 stabglabel( label , line ) 271 char *label; 272 int line; 273 { 274 275 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0 276 , label , N_PC , N_PGLABEL , ABS( line ) ); 277 } 278 279 /* 280 * global constants 281 */ 282 stabgconst( const , line ) 283 char *const; 284 int line; 285 { 286 287 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0 288 , const , N_PC , N_PGCONST , ABS( line ) ); 289 } 290 291 /* 292 * global types 293 */ 294 stabgtype( type , line ) 295 char *type; 296 int line; 297 { 298 299 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0 300 , type , N_PC , N_PGTYPE , ABS( line ) ); 301 } 302 303 304 /* 305 * external functions and procedures 306 */ 307 stabefunc( name , typeclass , line ) 308 char *name; 309 int typeclass; 310 int line; 311 { 312 int type; 313 314 if ( typeclass == FUNC ) { 315 type = N_PEFUNC; 316 } else if ( typeclass == PROC ) { 317 type = N_PEPROC; 318 } else { 319 return; 320 } 321 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0 322 , name , N_PC , type , ABS( line ) ); 323 } 324 325 #endif PC 326