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
,
106 enum out_type type
, uint64_t size
,
107 int32_t segment
, int32_t wrt
)
112 fprintf(dbgf
, "out to %lx, len = %ld: ", segto
, size
);
116 fprintf(dbgf
, "reserved.\n");
119 fprintf(dbgf
, "raw data = ");
121 id
= *(uint8_t *)data
;
122 data
= (char *)data
+ 1;
123 fprintf(dbgf
, "%02x ", id
);
128 ldata
= *(int64_t *)data
;
129 fprintf(dbgf
, "addr %08lx (seg %08lx, wrt %08lx)\n", ldata
,
133 fprintf(dbgf
, "rel2adr %04x (seg %08lx)\n", (int)*(int16_t *)data
,
137 fprintf(dbgf
, "rel4adr %08lx (seg %08lx)\n", *(int32_t *)data
,
141 fprintf(dbgf
, "unknown\n");
146 static int32_t dbg_segbase(int32_t segment
)
151 static int dbg_directive(char *directive
, char *value
, int pass
)
153 fprintf(dbgf
, "directive [%s] value [%s] (pass %d)\n",
154 directive
, value
, pass
);
158 static void dbg_filename(char *inname
, char *outname
, efunc error
)
160 standard_extension(inname
, outname
, ".dbg", error
);
163 static int dbg_set_info(enum geninfo type
, char **val
)
171 "unknown", "label", "byte", "word", "dword", "float", "qword", "tbyte"
173 void dbgdbg_init(struct ofmt
*of
, void *id
, FILE * fp
, efunc error
)
179 fprintf(fp
, " With debug info\n");
181 static void dbgdbg_cleanup(void)
185 static void dbgdbg_linnum(const char *lnfname
, int32_t lineno
, int32_t segto
)
187 fprintf(dbgf
, "dbglinenum %s(%ld) := %08lx\n", lnfname
, lineno
, segto
);
189 static void dbgdbg_deflabel(char *name
, int32_t segment
,
190 int32_t offset
, int is_global
, char *special
)
192 fprintf(dbgf
, "dbglabel %s := %08lx:%08lx %s (%d)%s%s\n",
195 is_global
== 2 ? "common" : is_global
? "global" : "local",
196 is_global
, special
? ": " : "", special
);
198 static void dbgdbg_define(const char *type
, const char *params
)
200 fprintf(dbgf
, "dbgdirective [%s] value [%s]\n", type
, params
);
202 static void dbgdbg_output(int output_type
, void *param
)
207 static void dbgdbg_typevalue(int32_t type
)
209 fprintf(dbgf
, "new type: %s(%lX)\n",
210 types
[TYM_TYPE(type
) >> 3], TYM_ELEMENTS(type
));
212 static struct dfmt debug_debug_form
= {
213 "Trace of all info passed to debug stage",
224 static struct dfmt
*debug_debug_arr
[3] = {
229 struct ofmt of_dbg
= {
230 "Trace of all info passed to output stage",