2 * (c) copyright 1990 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 * Author: Ceriel J.H. Jacobs
8 /* D E B U G G E R S Y M B O L T A B L E */
10 /* $Id: stab.c,v 1.3 1994/06/24 12:06:02 ceriel Exp $ */
20 #include <flt_arith.h>
33 extern long full_mask[];
34 extern char *sprint();
38 static struct db_str {
48 db_str.base = Malloc(INCR_SIZE);
49 db_str.sz = INCR_SIZE;
51 db_str.currpos = db_str.base;
58 int df = db_str.currpos - db_str.base;
59 if (df >= db_str.sz-1) {
60 db_str.sz += INCR_SIZE;
61 db_str.base = Realloc(db_str.base, db_str.sz);
62 db_str.currpos = db_str.base + df;
64 *db_str.currpos++ = c;
65 *db_str.currpos = '\0';
72 while (*s) addc_db_str(*s++);
77 register struct type *tp;
83 if (tp->tp_dbindex > 0) {
84 adds_db_str(sprint(buf, "%d", tp->tp_dbindex));
87 if (tp->tp_dbindex < 0 && tp->tp_size < 0) {
88 adds_db_str(sprint(buf, "%d", -tp->tp_dbindex));
91 if (tp->tp_dbindex <= 0) {
92 tp->tp_dbindex = ++stb_count;
94 adds_db_str(sprint(buf, "%d=", tp->tp_dbindex));
96 /* simple types ... */
98 adds_db_str(sprint(buf, "%d", void_type->tp_dbindex));
104 l = full_mask[(int)tp->tp_size];
105 if (tp->tp_unsigned) {
106 adds_db_str(sprint(buf,
112 l &= ~ (1L << ((int)tp->tp_size * 8 - 1));
113 adds_db_str(sprint(buf,
122 adds_db_str(sprint(buf,
128 /* constructed types ... */
134 if (tp->tp_size > 0) {
137 adds_db_str(sprint(buf, ";0;%ld;", tp->tp_size / tp->tp_up->tp_size - 1));
142 if (tp->tp_size < 0) {
143 adds_db_str(sprint(buf,
145 tp->tp_idf->id_text));
146 tp->tp_dbindex = -tp->tp_dbindex;
151 register struct stack_entry *se = local_level->sl_entry;
154 register struct def *edef = se->se_idf->id_def;
156 if (edef->df_type == tp &&
157 edef->df_sc == ENUM) {
158 adds_db_str(sprint(buf,
172 if (tp->tp_size < 0) {
173 adds_db_str(sprint(buf,
175 tp->tp_fund == STRUCT ? 's' : 'u',
176 tp->tp_idf->id_text));
177 tp->tp_dbindex = -tp->tp_dbindex;
180 adds_db_str(sprint(buf,
182 tp->tp_fund == STRUCT ? 's' : 'u',
185 register struct sdef *sdef = tp->tp_sdef;
188 adds_db_str(sdef->sd_idf->id_text);
190 if (sdef->sd_type->tp_fund == FIELD) {
191 stb_type(sdef->sd_type->tp_up);
192 adds_db_str(sprint(buf,
194 sdef->sd_offset*8+sdef->sd_type->tp_field->fd_shift,
195 sdef->sd_type->tp_field->fd_width));
198 stb_type(sdef->sd_type);
199 adds_db_str(sprint(buf,
202 sdef->sd_type->tp_size*8));
204 sdef = sdef->sd_sdef;
216 register struct tag *tg;
222 stb_type(tg->tg_type);
224 C_ms_stb_cst(db_str.base,
226 tg->tg_type == void_type || tg->tg_type->tp_size >= 32767
228 : (int)tg->tg_type->tp_size,
233 register struct type *tp;
241 C_ms_stb_cst(db_str.base,
243 tp == void_type || tp->tp_size >= 32767
249 stb_string(df, kind, str)
250 register struct def *df;
253 register struct type *tp = df->df_type;
260 addc_db_str(df->df_sc == STATIC ? 'f' : 'F');
263 C_ms_stb_pnam(db_str.base, N_FUN, 1 /* proclevel */, str);
266 if (df->df_sc == FORMAL ||
267 (df->df_sc == REGISTER && df->df_address >= 0)) {
268 /* value parameter */
272 C_ms_stb_cst(db_str.base, N_PSYM, 0, df->df_address);
274 else if (df->df_sc != AUTO && df->df_sc != REGISTER) {
276 int stabtp = df->df_initialized ? N_STSYM : N_LCSYM;
277 if (df->df_sc == STATIC) {
278 if (df->df_level >= L_LOCAL) {
290 if (df->df_sc == STATIC && df->df_level >= L_LOCAL) {
291 C_ms_stb_dlb(db_str.base, stabtp, 0, (label) df->df_address, (arith) 0);
294 C_ms_stb_dnam(db_str.base, stabtp, 0, str, (arith) 0);
297 else { /* local variable */
298 stb_type(tp); /* assign type num to avoid
299 difficult to parse string */
301 C_ms_stb_cst(db_str.base, N_LSYM, 0, df->df_address);
307 #endif /* DBSYMTAB */