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.
32 static void dbg_init(FILE * fp
, efunc errfunc
, ldfunc ldef
, evalfunc eval
)
40 fprintf(fp
, "NASM Output format debug dump\n");
41 of_dbg
.current_dfmt
->init(&of_dbg
, 0, fp
, errfunc
);
45 static void dbg_cleanup(int debuginfo
)
48 of_dbg
.current_dfmt
->cleanup();
50 struct Section
*tmp
= dbgsect
;
51 dbgsect
= dbgsect
->next
;
58 static int32_t dbg_section_names(char *name
, int pass
, int *bits
)
63 * We must have an initial default: let's make it 16.
69 fprintf(dbgf
, "section_name on init: returning %d\n",
72 int n
= strcspn(name
, " \t");
73 char *sname
= nasm_strndup(name
, n
);
77 for (s
= dbgsect
; s
; s
= s
->next
)
78 if (!strcmp(s
->name
, sname
))
82 s
= nasm_malloc(sizeof(*s
));
84 s
->number
= seg
= seg_alloc();
87 fprintf(dbgf
, "section_name %s (pass %d): returning %d\n",
94 static void dbg_deflabel(char *name
, int32_t segment
, int32_t offset
,
95 int is_global
, char *special
)
97 fprintf(dbgf
, "deflabel %s := %08lx:%08lx %s (%d)%s%s\n",
98 name
, segment
, offset
,
99 is_global
== 2 ? "common" : is_global
? "global" : "local",
100 is_global
, special
? ": " : "", special
);
103 static void dbg_out(int32_t segto
, const void *data
, uint32_t type
,
104 int32_t segment
, int32_t wrt
)
106 int32_t realbytes
= type
& OUT_SIZMASK
;
112 fprintf(dbgf
, "out to %lx, len = %ld: ", segto
, realbytes
);
116 fprintf(dbgf
, "reserved.\n");
119 fprintf(dbgf
, "raw data = ");
120 while (realbytes
--) {
121 id
= *(uint8_t *)data
;
122 data
= (char *)data
+ 1;
123 fprintf(dbgf
, "%02x ", id
);
128 ldata
= 0; /* placate gcc */
130 ldata
= *((char *)data
);
131 else if (realbytes
== 2)
132 ldata
= *((int16_t *)data
);
133 else if (realbytes
== 4)
134 ldata
= *((int32_t *)data
);
135 fprintf(dbgf
, "addr %08lx (seg %08lx, wrt %08lx)\n", ldata
,
139 fprintf(dbgf
, "rel2adr %04x (seg %08lx)\n", (int)*(int16_t *)data
,
143 fprintf(dbgf
, "rel4adr %08lx (seg %08lx)\n", *(int32_t *)data
,
147 fprintf(dbgf
, "unknown\n");
152 static int32_t dbg_segbase(int32_t segment
)
157 static int dbg_directive(char *directive
, char *value
, int pass
)
159 fprintf(dbgf
, "directive [%s] value [%s] (pass %d)\n",
160 directive
, value
, pass
);
164 static void dbg_filename(char *inname
, char *outname
, efunc error
)
166 standard_extension(inname
, outname
, ".dbg", error
);
169 static int dbg_set_info(enum geninfo type
, char **val
)
177 "unknown", "label", "byte", "word", "dword", "float", "qword", "tbyte"
179 void dbgdbg_init(struct ofmt
*of
, void *id
, FILE * fp
, efunc error
)
185 fprintf(fp
, " With debug info\n");
187 static void dbgdbg_cleanup(void)
191 static void dbgdbg_linnum(const char *lnfname
, int32_t lineno
, int32_t segto
)
193 fprintf(dbgf
, "dbglinenum %s(%ld) := %08lx\n", lnfname
, lineno
, segto
);
195 static void dbgdbg_deflabel(char *name
, int32_t segment
,
196 int32_t offset
, int is_global
, char *special
)
198 fprintf(dbgf
, "dbglabel %s := %08lx:%08lx %s (%d)%s%s\n",
201 is_global
== 2 ? "common" : is_global
? "global" : "local",
202 is_global
, special
? ": " : "", special
);
204 static void dbgdbg_define(const char *type
, const char *params
)
206 fprintf(dbgf
, "dbgdirective [%s] value [%s]\n", type
, params
);
208 static void dbgdbg_output(int output_type
, void *param
)
213 static void dbgdbg_typevalue(int32_t type
)
215 fprintf(dbgf
, "new type: %s(%lX)\n",
216 types
[TYM_TYPE(type
) >> 3], TYM_ELEMENTS(type
));
218 static struct dfmt debug_debug_form
= {
219 "Trace of all info passed to debug stage",
230 static struct dfmt
*debug_debug_arr
[3] = {
235 struct ofmt of_dbg
= {
236 "Trace of all info passed to output stage",