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 license given in the file "LICENSE"
7 * distributed in the NASM archive.
20 #include "output/outform.h"
34 static void dbg_init(FILE * fp
, efunc errfunc
, ldfunc ldef
, evalfunc eval
)
42 fprintf(fp
, "NASM Output format debug dump\n");
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
, int64_t offset
,
95 int is_global
, char *special
)
97 fprintf(dbgf
, "deflabel %s := %08"PRIx32
":%016"PRIx64
" %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
,
104 enum out_type type
, uint64_t size
,
105 int32_t segment
, int32_t wrt
)
110 fprintf(dbgf
, "out to %"PRIx32
", len = %"PRIu64
": ", segto
, size
);
114 fprintf(dbgf
, "reserved.\n");
117 fprintf(dbgf
, "raw data = ");
119 id
= *(uint8_t *)data
;
120 data
= (char *)data
+ 1;
121 fprintf(dbgf
, "%02x ", id
);
126 ldata
= *(int64_t *)data
;
127 fprintf(dbgf
, "addr %08"PRIx32
" (seg %08"PRIx32
", wrt %08"PRIx32
")\n", ldata
,
131 fprintf(dbgf
, "rel2adr %04x (seg %08"PRIx32
")\n", (int)*(int16_t *)data
,
135 fprintf(dbgf
, "rel4adr %08"PRIx32
" (seg %08"PRIx32
")\n", *(int32_t *)data
,
139 fprintf(dbgf
, "unknown\n");
144 static int32_t dbg_segbase(int32_t segment
)
149 static int dbg_directive(char *directive
, char *value
, int pass
)
151 fprintf(dbgf
, "directive [%s] value [%s] (pass %d)\n",
152 directive
, value
, pass
);
156 static void dbg_filename(char *inname
, char *outname
, efunc error
)
158 standard_extension(inname
, outname
, ".dbg", error
);
161 static int dbg_set_info(enum geninfo type
, char **val
)
169 "unknown", "label", "byte", "word", "dword", "float", "qword", "tbyte"
171 void dbgdbg_init(struct ofmt
*of
, void *id
, FILE * fp
, efunc error
)
177 fprintf(fp
, " With debug info\n");
179 static void dbgdbg_cleanup(void)
183 static void dbgdbg_linnum(const char *lnfname
, int32_t lineno
, int32_t segto
)
185 fprintf(dbgf
, "dbglinenum %s(%"PRId32
") := %08"PRIx32
"\n",
186 lnfname
, lineno
, segto
);
188 static void dbgdbg_deflabel(char *name
, int32_t segment
,
189 int64_t offset
, int is_global
, char *special
)
191 fprintf(dbgf
, "dbglabel %s := %08"PRIx32
":%016"PRIx64
" %s (%d)%s%s\n",
194 is_global
== 2 ? "common" : is_global
? "global" : "local",
195 is_global
, special
? ": " : "", special
);
197 static void dbgdbg_define(const char *type
, const char *params
)
199 fprintf(dbgf
, "dbgdirective [%s] value [%s]\n", type
, params
);
201 static void dbgdbg_output(int output_type
, void *param
)
206 static void dbgdbg_typevalue(int32_t type
)
208 fprintf(dbgf
, "new type: %s(%"PRIX32
")\n",
209 types
[TYM_TYPE(type
) >> 3], TYM_ELEMENTS(type
));
211 static struct dfmt debug_debug_form
= {
212 "Trace of all info passed to debug stage",
223 static struct dfmt
*debug_debug_arr
[3] = {
229 struct ofmt of_dbg
= {
230 "Trace of all info passed to output stage",