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.
34 static void dbg_init(FILE * fp
, efunc errfunc
, ldfunc ldef
, evalfunc eval
)
42 fprintf(fp
, "NASM Output format debug dump\n");
43 of_dbg
.current_dfmt
->init(&of_dbg
, 0, fp
, errfunc
);
47 static void dbg_cleanup(int debuginfo
)
50 of_dbg
.current_dfmt
->cleanup();
52 struct Section
*tmp
= dbgsect
;
53 dbgsect
= dbgsect
->next
;
60 static int32_t dbg_section_names(char *name
, int pass
, int *bits
)
65 * We must have an initial default: let's make it 16.
71 fprintf(dbgf
, "section_name on init: returning %d\n",
74 int n
= strcspn(name
, " \t");
75 char *sname
= nasm_strndup(name
, n
);
79 for (s
= dbgsect
; s
; s
= s
->next
)
80 if (!strcmp(s
->name
, sname
))
84 s
= nasm_malloc(sizeof(*s
));
86 s
->number
= seg
= seg_alloc();
89 fprintf(dbgf
, "section_name %s (pass %d): returning %d\n",
96 static void dbg_deflabel(char *name
, int32_t segment
, int32_t offset
,
97 int is_global
, char *special
)
99 fprintf(dbgf
, "deflabel %s := %08lx:%08lx %s (%d)%s%s\n",
100 name
, segment
, offset
,
101 is_global
== 2 ? "common" : is_global
? "global" : "local",
102 is_global
, special
? ": " : "", special
);
105 static void dbg_out(int32_t segto
, const void *data
, uint32_t type
,
106 int32_t segment
, int32_t wrt
)
108 int32_t realbytes
= type
& OUT_SIZMASK
;
114 fprintf(dbgf
, "out to %lx, len = %ld: ", segto
, realbytes
);
118 fprintf(dbgf
, "reserved.\n");
121 fprintf(dbgf
, "raw data = ");
122 while (realbytes
--) {
123 id
= *(uint8_t *)data
;
124 data
= (char *)data
+ 1;
125 fprintf(dbgf
, "%02x ", id
);
130 ldata
= 0; /* placate gcc */
132 ldata
= *((char *)data
);
133 else if (realbytes
== 2)
134 ldata
= *((int16_t *)data
);
135 else if (realbytes
== 4)
136 ldata
= *((int32_t *)data
);
137 fprintf(dbgf
, "addr %08lx (seg %08lx, wrt %08lx)\n", ldata
,
141 fprintf(dbgf
, "rel2adr %04x (seg %08lx)\n", (int)*(int16_t *)data
,
145 fprintf(dbgf
, "rel4adr %08lx (seg %08lx)\n", *(int32_t *)data
,
149 fprintf(dbgf
, "unknown\n");
154 static int32_t dbg_segbase(int32_t segment
)
159 static int dbg_directive(char *directive
, char *value
, int pass
)
161 fprintf(dbgf
, "directive [%s] value [%s] (pass %d)\n",
162 directive
, value
, pass
);
166 static void dbg_filename(char *inname
, char *outname
, efunc error
)
168 standard_extension(inname
, outname
, ".dbg", error
);
171 static int dbg_set_info(enum geninfo type
, char **val
)
179 "unknown", "label", "byte", "word", "dword", "float", "qword", "tbyte"
181 void dbgdbg_init(struct ofmt
*of
, void *id
, FILE * fp
, efunc error
)
187 fprintf(fp
, " With debug info\n");
189 static void dbgdbg_cleanup(void)
193 static void dbgdbg_linnum(const char *lnfname
, int32_t lineno
, int32_t segto
)
195 fprintf(dbgf
, "dbglinenum %s(%ld) := %08lx\n", lnfname
, lineno
, segto
);
197 static void dbgdbg_deflabel(char *name
, int32_t segment
,
198 int32_t offset
, int is_global
, char *special
)
200 fprintf(dbgf
, "dbglabel %s := %08lx:%08lx %s (%d)%s%s\n",
203 is_global
== 2 ? "common" : is_global
? "global" : "local",
204 is_global
, special
? ": " : "", special
);
206 static void dbgdbg_define(const char *type
, const char *params
)
208 fprintf(dbgf
, "dbgdirective [%s] value [%s]\n", type
, params
);
210 static void dbgdbg_output(int output_type
, void *param
)
215 static void dbgdbg_typevalue(int32_t type
)
217 fprintf(dbgf
, "new type: %s(%lX)\n",
218 types
[TYM_TYPE(type
) >> 3], TYM_ELEMENTS(type
));
220 static struct dfmt debug_debug_form
= {
221 "Trace of all info passed to debug stage",
232 static struct dfmt
*debug_debug_arr
[3] = {
237 struct ofmt of_dbg
= {
238 "Trace of all info passed to output stage",