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.14 1995/12/19 09:30:46 ceriel Exp $ */
20 #include <flt_arith.h>
35 extern char *sprint();
37 static struct db_str {
47 db_str.base = Malloc(INCR_SIZE);
48 db_str.sz = INCR_SIZE;
50 db_str.currpos = db_str.base;
57 int df = db_str.currpos - db_str.base;
58 if (df >= db_str.sz-1) {
59 db_str.sz += INCR_SIZE;
60 db_str.base = Realloc(db_str.base, db_str.sz);
61 db_str.currpos = db_str.base + df;
63 *db_str.currpos++ = c;
64 *db_str.currpos = '\0';
71 while (*s) addc_db_str(*s++);
75 stb_type(tp, assign_num)
81 if (tp->tp_dbindex > 0) {
82 adds_db_str(sprint(buf, "%d", tp->tp_dbindex));
85 if (tp->tp_dbindex < 0) {
86 if (tp->tp_next == 0) {
87 adds_db_str(sprint(buf, "%d", -tp->tp_dbindex));
90 tp->tp_dbindex = -tp->tp_dbindex;
92 if (tp->tp_dbindex == 0 && assign_num) {
93 tp->tp_dbindex = ++stb_count;
95 if (tp->tp_dbindex > 0) {
96 adds_db_str(sprint(buf, "%d=", tp->tp_dbindex));
98 if (tp == void_type) {
99 adds_db_str(sprint(buf, "%d", tp->tp_dbindex));
102 switch(tp->tp_fund) {
103 /* simple types ... */
105 adds_db_str(sprint(buf,
108 (long) min_int[(int)tp->tp_size],
109 (long) max_int[(int)tp->tp_size]));
112 adds_db_str(sprint(buf,
117 adds_db_str(sprint(buf,
123 adds_db_str(sprint(buf,
128 if (tp->tp_size == word_size) {
129 adds_db_str(sprint(buf,
134 adds_db_str(sprint(buf,
140 /* constructed types ... */
142 adds_db_str(sprint(buf,
144 tp->tp_next->tp_dbindex,
149 stb_type(tp->tp_next, 0);
150 if (tp->tp_dbindex < 0) tp->tp_dbindex = -tp->tp_dbindex;
153 if (DefinitionModule && CurrVis == Defined->mod_vis) {
154 tp->tp_dbindex = - ++stb_count;
155 adds_db_str(sprint(buf, "%d", -tp->tp_dbindex));
158 /* ??? what to do here??? */
160 stb_type(void_type, 0);
161 /* ??? this certainly is not correct */
167 stb_type(tp->tp_next, 0);
168 if (tp->tp_dbindex < 0) tp->tp_dbindex = -tp->tp_dbindex;
171 tp->tp_dbindex = - ++stb_count;
172 adds_db_str(sprint(buf, "%d", -tp->tp_dbindex));
177 stb_type(tp->tp_next, 0);
178 adds_db_str(sprint(buf, ";%ld;%ld;", tp->tp_size, tp->set_low));
182 if (IsConformantArray(tp)) {
184 stb_type(tp->tp_next, 0);
185 adds_db_str(sprint(buf, ";0;A%ld", tp->arr_high));
188 stb_type(tp->tp_next, 0);
191 stb_type(tp->arr_elem, 0);
196 register struct def *edef = tp->enm_enums;
199 adds_db_str(sprint(buf, "%s:%ld,",
200 edef->df_idf->id_text,
202 edef = edef->enm_next;
208 adds_db_str(sprint(buf, "s%ld", tp->tp_size));
210 register struct def *sdef = tp->rec_scope->sc_def;
213 adds_db_str(sdef->df_idf->id_text);
215 stb_type(sdef->df_type, 0);
216 adds_db_str(sprint(buf,
219 sdef->df_type->tp_size*8));
220 sdef = sdef->df_nextinscope;
228 stb_type(tp->tp_next ? tp->tp_next : void_type, 0);
232 stb_type(tp->tp_next ? tp->tp_next : void_type, 0);
234 register struct paramlist *p = tp->prc_params;
241 adds_db_str(sprint(buf, ",%d;", paramcount));
244 addc_db_str(IsVarParam(p)
246 : IsConformantArray(TypeOfParam(p))
249 stb_type(TypeOfParam(p), 0);
267 C_ms_stb_cst(db_str.base,
269 tp == void_type || tp->tp_size >= max_int[2]
278 register t_type *tp = df->df_type;
282 adds_db_str(df->df_idf->id_text);
288 stb_type(void_type, 0);
291 adds_db_str(sprint(buf, "M%d;", df->mod_vis->sc_count));
293 C_ms_stb_pnam(db_str.base, N_FUN, gdb_flag ? 0 : proclevel, df->mod_vis->sc_scope->sc_name);
299 else adds_db_str(sprint(buf, "Q%d;", df->prc_vis->sc_count));
300 stb_type(tp->tp_next ? tp->tp_next : void_type, 0);
302 t_scopelist *sc = df->prc_vis;
305 t_def *d = sc->sc_scope->sc_definedby;
307 if (d && d->df_kind == D_PROCEDURE) {
308 adds_db_str(sprint(buf, ",%s", d->df_idf->id_text));
314 else addc_db_str(';');
315 C_ms_stb_pnam(db_str.base, N_FUN, gdb_flag ? 0 : proclevel, df->prc_vis->sc_scope->sc_name);
319 adds_db_str(sprint(buf, "E%d;", df->mod_vis->sc_count));
320 C_ms_stb_cst(db_str.base, N_SCOPE, proclevel, (arith) 0);
324 adds_db_str(sprint(buf, "E%d;", df->prc_vis->sc_count));
325 C_ms_stb_cst(db_str.base, N_SCOPE, proclevel, (arith) 0);
328 if (DefinitionModule && CurrVis != Defined->mod_vis) break;
329 if (df->df_flags & D_VARPAR) { /* VAR parameter */
333 C_ms_stb_cst(db_str.base, N_PSYM, 0, df->var_off);
335 else if (df->df_flags & D_VALPAR) { /* value parameter */
336 addc_db_str(IsConformantArray(tp)
341 C_ms_stb_cst(db_str.base, N_PSYM, 0, df->var_off);
343 else if (!proclevel ||
344 (df->df_flags & D_ADDRGIVEN)) { /* global */
346 if (df->df_flags & D_EXPORTED) {
355 if (df->df_flags & D_ADDRGIVEN) {
356 C_ms_stb_cst(db_str.base, knd, 0, df->var_off);
359 C_ms_stb_dnam(db_str.base, knd, 0, df->var_name, (arith) 0);
362 else { /* local variable */
363 stb_type(tp, 1); /* assign type num to avoid
364 difficult to parse string */
366 C_ms_stb_cst(db_str.base, N_LSYM, 0, df->var_off);
373 C_ms_stb_cst(db_str.base,
375 tp == void_type || tp->tp_size >= max_int[2]
381 if (DefinitionModule && CurrVis != Defined->mod_vis) break;
385 switch(tp->tp_fund) {
392 adds_db_str(sprint(buf, "i%ld;", df->con_const.TOK_INT));
395 adds_db_str(sprint(buf, "c%ld;", df->con_const.TOK_INT));
399 if (! df->con_const.TOK_RSTR) {
400 char buf2[FLT_STRLEN];
402 flt_flt2str(&df->con_const.TOK_RVAL, buf2, FLT_STRLEN);
405 else adds_db_str(df->con_const.TOK_RSTR);
409 register char *p = df->con_const.TOK_STR;
413 if (*p == '\'' || *p == '\\') {
424 adds_db_str(sprint(buf, ",%ld;", df->con_const.TOK_INT));
431 for (i = 0; i < tp->tp_size; i++) {
432 adds_db_str(sprint(buf, ",%ld",
433 (df->con_const.tk_data.tk_set[i/(int) word_size] >> (8*(i%(int)word_size)))&0377));
439 C_ms_stb_cst(db_str.base,
441 tp->tp_size < max_int[2] ? (int)tp->tp_size : 0,
447 #endif /* DBSYMTAB */