1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2009 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
35 * outdbg.c output routines for the Netwide Assembler to produce
49 #include "output/outform.h"
63 static void dbg_init(FILE * fp, efunc errfunc, ldfunc ldef, evalfunc eval)
71 fprintf(fp, "NASM Output format debug dump\n");
74 static void dbg_cleanup(int debuginfo)
77 of_dbg.current_dfmt->cleanup();
79 struct Section *tmp = dbgsect;
80 dbgsect = dbgsect->next;
86 static int32_t dbg_section_names(char *name, int pass, int *bits)
91 * We must have an initial default: let's make it 16.
97 fprintf(dbgf, "section_name on init: returning %d\n",
100 int n = strcspn(name, " \t");
101 char *sname = nasm_strndup(name, n);
105 for (s = dbgsect; s; s = s->next)
106 if (!strcmp(s->name, sname))
110 s = nasm_malloc(sizeof(*s));
112 s->number = seg = seg_alloc();
115 fprintf(dbgf, "section_name %s (pass %d): returning %d\n",
122 static void dbg_deflabel(char *name, int32_t segment, int64_t offset,
123 int is_global, char *special)
125 fprintf(dbgf, "deflabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
126 name, segment, offset,
127 is_global == 2 ? "common" : is_global ? "global" : "local",
128 is_global, special ? ": " : "", special);
131 static void dbg_out(int32_t segto, const void *data,
132 enum out_type type, uint64_t size,
133 int32_t segment, int32_t wrt)
138 fprintf(dbgf, "out to %"PRIx32", len = %"PRIu64": ", segto, size);
142 fprintf(dbgf, "reserved.\n");
145 fprintf(dbgf, "raw data = ");
147 id = *(uint8_t *)data;
148 data = (char *)data + 1;
149 fprintf(dbgf, "%02x ", id);
154 ldata = *(int64_t *)data;
155 fprintf(dbgf, "addr %08"PRIx32" (seg %08"PRIx32", wrt %08"PRIx32")\n", ldata,
159 fprintf(dbgf, "rel2adr %04"PRIx16" (seg %08"PRIx32")\n",
160 (uint16_t)*(int64_t *)data, segment);
163 fprintf(dbgf, "rel4adr %08"PRIx32" (seg %08"PRIx32")\n",
164 (uint32_t)*(int64_t *)data,
168 fprintf(dbgf, "rel8adr %016"PRIx64" (seg %08"PRIx32")\n",
169 (uint64_t)*(int64_t *)data, segment);
172 fprintf(dbgf, "unknown\n");
177 static int32_t dbg_segbase(int32_t segment)
182 static int dbg_directive(enum directives directive, char *value, int pass)
184 fprintf(dbgf, "directive [%s] value [%s] (pass %d)\n",
185 directives[directive], value, pass);
189 static void dbg_filename(char *inname, char *outname, efunc error)
191 standard_extension(inname, outname, ".dbg", error);
194 static int dbg_set_info(enum geninfo type, char **val)
202 "unknown", "label", "byte", "word", "dword", "float", "qword", "tbyte"
204 void dbgdbg_init(struct ofmt *of, void *id, FILE * fp, efunc error)
210 fprintf(fp, " With debug info\n");
212 static void dbgdbg_cleanup(void)
216 static void dbgdbg_linnum(const char *lnfname, int32_t lineno, int32_t segto)
218 fprintf(dbgf, "dbglinenum %s(%"PRId32") := %08"PRIx32"\n",
219 lnfname, lineno, segto);
221 static void dbgdbg_deflabel(char *name, int32_t segment,
222 int64_t offset, int is_global, char *special)
224 fprintf(dbgf, "dbglabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
227 is_global == 2 ? "common" : is_global ? "global" : "local",
228 is_global, special ? ": " : "", special);
230 static void dbgdbg_define(const char *type, const char *params)
232 fprintf(dbgf, "dbgdirective [%s] value [%s]\n", type, params);
234 static void dbgdbg_output(int output_type, void *param)
239 static void dbgdbg_typevalue(int32_t type)
241 fprintf(dbgf, "new type: %s(%"PRIX32")\n",
242 types[TYM_TYPE(type) >> 3], TYM_ELEMENTS(type));
244 static struct dfmt debug_debug_form = {
245 "Trace of all info passed to debug stage",
256 static struct dfmt *debug_debug_arr[3] = {
262 struct ofmt of_dbg = {
263 "Trace of all info passed to output stage",