1 /* outdbg.c output routines for the Netwide Assembler to produce
4 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
5 * Julian Hall. All rights reserved. The software is
6 * redistributable under the licence given in the file "Licence"
7 * distributed in the NASM archive.
31 static void dbg_init(FILE * fp
, efunc errfunc
, ldfunc ldef
, evalfunc eval
)
39 fprintf(fp
, "NASM Output format debug dump\n");
40 of_dbg
.current_dfmt
->init(&of_dbg
, 0, fp
, errfunc
);
44 static void dbg_cleanup(int debuginfo
)
47 of_dbg
.current_dfmt
->cleanup();
49 struct Section
*tmp
= dbgsect
;
50 dbgsect
= dbgsect
->next
;
57 static long dbg_section_names(char *name
, int pass
, int *bits
)
62 * We must have an initial default: let's make it 16.
68 fprintf(dbgf
, "section_name on init: returning %d\n",
71 int n
= strcspn(name
, " \t");
72 char *sname
= nasm_strndup(name
, n
);
76 for (s
= dbgsect
; s
; s
= s
->next
)
77 if (!strcmp(s
->name
, sname
))
81 s
= nasm_malloc(sizeof(*s
));
83 s
->number
= seg
= seg_alloc();
86 fprintf(dbgf
, "section_name %s (pass %d): returning %d\n",
93 static void dbg_deflabel(char *name
, long segment
, long offset
,
94 int is_global
, char *special
)
96 fprintf(dbgf
, "deflabel %s := %08lx:%08lx %s (%d)%s%s\n",
97 name
, segment
, offset
,
98 is_global
== 2 ? "common" : is_global
? "global" : "local",
99 is_global
, special
? ": " : "", special
);
102 static void dbg_out(long segto
, void *data
, unsigned long type
,
103 long segment
, long wrt
)
105 long realbytes
= type
& OUT_SIZMASK
;
111 fprintf(dbgf
, "out to %lx, len = %ld: ", segto
, realbytes
);
115 fprintf(dbgf
, "reserved.\n");
118 fprintf(dbgf
, "raw data = ");
119 while (realbytes
--) {
120 id
= *(unsigned char *)data
;
121 data
= (char *)data
+ 1;
122 fprintf(dbgf
, "%02x ", id
);
127 ldata
= 0; /* placate gcc */
129 ldata
= *((char *)data
);
130 else if (realbytes
== 2)
131 ldata
= *((short *)data
);
132 else if (realbytes
== 4)
133 ldata
= *((long *)data
);
134 fprintf(dbgf
, "addr %08lx (seg %08lx, wrt %08lx)\n", ldata
,
138 fprintf(dbgf
, "rel2adr %04x (seg %08lx)\n", (int)*(short *)data
,
142 fprintf(dbgf
, "rel4adr %08lx (seg %08lx)\n", *(long *)data
,
146 fprintf(dbgf
, "unknown\n");
151 static long dbg_segbase(long segment
)
156 static int dbg_directive(char *directive
, char *value
, int pass
)
158 fprintf(dbgf
, "directive [%s] value [%s] (pass %d)\n",
159 directive
, value
, pass
);
163 static void dbg_filename(char *inname
, char *outname
, efunc error
)
165 standard_extension(inname
, outname
, ".dbg", error
);
168 static int dbg_set_info(enum geninfo type
, char **val
)
176 "unknown", "label", "byte", "word", "dword", "float", "qword", "tbyte"
178 void dbgdbg_init(struct ofmt
*of
, void *id
, FILE * fp
, efunc error
)
184 fprintf(fp
, " With debug info\n");
186 static void dbgdbg_cleanup(void)
190 static void dbgdbg_linnum(const char *lnfname
, long lineno
, long segto
)
192 fprintf(dbgf
, "dbglinenum %s(%ld) := %08lx\n", lnfname
, lineno
, segto
);
194 static void dbgdbg_deflabel(char *name
, long segment
,
195 long offset
, int is_global
, char *special
)
197 fprintf(dbgf
, "dbglabel %s := %08lx:%08lx %s (%d)%s%s\n",
200 is_global
== 2 ? "common" : is_global
? "global" : "local",
201 is_global
, special
? ": " : "", special
);
203 static void dbgdbg_define(const char *type
, const char *params
)
205 fprintf(dbgf
, "dbgdirective [%s] value [%s]\n", type
, params
);
207 static void dbgdbg_output(int output_type
, void *param
)
212 static void dbgdbg_typevalue(long type
)
214 fprintf(dbgf
, "new type: %s(%lX)\n",
215 types
[TYM_TYPE(type
) >> 3], TYM_ELEMENTS(type
));
217 static struct dfmt debug_debug_form
= {
218 "Trace of all info passed to debug stage",
229 static struct dfmt
*debug_debug_arr
[3] = {
234 struct ofmt of_dbg
= {
235 "Trace of all info passed to output stage",