make: Update pecoff.h related deps
[nasm/avx512.git] / output / outdbg.c
blob13d53bd831e88716f418c5f834fbe4a3e62cfbab
1 /* ----------------------------------------------------------------------- *
2 *
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
9 * conditions are met:
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
36 * a debugging trace
39 #include "compiler.h"
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <ctype.h>
45 #include <inttypes.h>
47 #include "nasm.h"
48 #include "nasmlib.h"
49 #include "output/outform.h"
51 #ifdef OF_DBG
53 struct Section {
54 struct Section *next;
55 int32_t number;
56 char *name;
57 } *dbgsect;
59 struct ofmt of_dbg;
60 static void dbg_init(void)
62 dbgsect = NULL;
63 fprintf(ofile, "NASM Output format debug dump\n");
66 static void dbg_cleanup(int debuginfo)
68 (void)debuginfo;
69 of_dbg.current_dfmt->cleanup();
70 while (dbgsect) {
71 struct Section *tmp = dbgsect;
72 dbgsect = dbgsect->next;
73 nasm_free(tmp->name);
74 nasm_free(tmp);
78 static int32_t dbg_section_names(char *name, int pass, int *bits)
80 int seg;
83 * We must have an initial default: let's make it 16.
85 if (!name)
86 *bits = 16;
88 if (!name)
89 fprintf(ofile, "section_name on init: returning %d\n",
90 seg = seg_alloc());
91 else {
92 int n = strcspn(name, " \t");
93 char *sname = nasm_strndup(name, n);
94 struct Section *s;
96 seg = NO_SEG;
97 for (s = dbgsect; s; s = s->next)
98 if (!strcmp(s->name, sname))
99 seg = s->number;
101 if (seg == NO_SEG) {
102 s = nasm_malloc(sizeof(*s));
103 s->name = sname;
104 s->number = seg = seg_alloc();
105 s->next = dbgsect;
106 dbgsect = s;
107 fprintf(ofile, "section_name %s (pass %d): returning %d\n",
108 name, pass, seg);
111 return seg;
114 static void dbg_deflabel(char *name, int32_t segment, int64_t offset,
115 int is_global, char *special)
117 fprintf(ofile, "deflabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
118 name, segment, offset,
119 is_global == 2 ? "common" : is_global ? "global" : "local",
120 is_global, special ? ": " : "", special);
123 static void dbg_out(int32_t segto, const void *data,
124 enum out_type type, uint64_t size,
125 int32_t segment, int32_t wrt)
127 int32_t ldata;
128 int id;
130 fprintf(ofile, "out to %"PRIx32", len = %"PRIu64": ", segto, size);
132 switch (type) {
133 case OUT_RESERVE:
134 fprintf(ofile, "reserved.\n");
135 break;
136 case OUT_RAWDATA:
137 fprintf(ofile, "raw data = ");
138 while (size--) {
139 id = *(uint8_t *)data;
140 data = (char *)data + 1;
141 fprintf(ofile, "%02x ", id);
143 fprintf(ofile, "\n");
144 break;
145 case OUT_ADDRESS:
146 ldata = *(int64_t *)data;
147 fprintf(ofile, "addr %08"PRIx32" (seg %08"PRIx32", wrt %08"PRIx32")\n", ldata,
148 segment, wrt);
149 break;
150 case OUT_REL2ADR:
151 fprintf(ofile, "rel2adr %04"PRIx16" (seg %08"PRIx32")\n",
152 (uint16_t)*(int64_t *)data, segment);
153 break;
154 case OUT_REL4ADR:
155 fprintf(ofile, "rel4adr %08"PRIx32" (seg %08"PRIx32")\n",
156 (uint32_t)*(int64_t *)data,
157 segment);
158 break;
159 case OUT_REL8ADR:
160 fprintf(ofile, "rel8adr %016"PRIx64" (seg %08"PRIx32")\n",
161 (uint64_t)*(int64_t *)data, segment);
162 break;
163 default:
164 fprintf(ofile, "unknown\n");
165 break;
169 static void dbg_sectalign(int32_t seg, unsigned int value)
171 fprintf(ofile, "set alignment (%d) for segment (%d)\n",
172 seg, value);
175 static int32_t dbg_segbase(int32_t segment)
177 return segment;
180 static int dbg_directive(enum directives directive, char *value, int pass)
182 fprintf(ofile, "directive [%s] value [%s] (pass %d)\n",
183 directives[directive], value, pass);
184 return 1;
187 static void dbg_filename(char *inname, char *outname)
189 standard_extension(inname, outname, ".dbg");
192 static int dbg_set_info(enum geninfo type, char **val)
194 (void)type;
195 (void)val;
196 return 0;
199 char *types[] = {
200 "unknown", "label", "byte", "word", "dword", "float", "qword", "tbyte"
202 void dbgdbg_init(void)
204 fprintf(ofile, " With debug info\n");
206 static void dbgdbg_cleanup(void)
210 static void dbgdbg_linnum(const char *lnfname, int32_t lineno, int32_t segto)
212 fprintf(ofile, "dbglinenum %s(%"PRId32") := %08"PRIx32"\n",
213 lnfname, lineno, segto);
215 static void dbgdbg_deflabel(char *name, int32_t segment,
216 int64_t offset, int is_global, char *special)
218 fprintf(ofile, "dbglabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
219 name,
220 segment, offset,
221 is_global == 2 ? "common" : is_global ? "global" : "local",
222 is_global, special ? ": " : "", special);
224 static void dbgdbg_define(const char *type, const char *params)
226 fprintf(ofile, "dbgdirective [%s] value [%s]\n", type, params);
228 static void dbgdbg_output(int output_type, void *param)
230 (void)output_type;
231 (void)param;
233 static void dbgdbg_typevalue(int32_t type)
235 fprintf(ofile, "new type: %s(%"PRIX32")\n",
236 types[TYM_TYPE(type) >> 3], TYM_ELEMENTS(type));
238 static struct dfmt debug_debug_form = {
239 "Trace of all info passed to debug stage",
240 "debug",
241 dbgdbg_init,
242 dbgdbg_linnum,
243 dbgdbg_deflabel,
244 dbgdbg_define,
245 dbgdbg_typevalue,
246 dbgdbg_output,
247 dbgdbg_cleanup,
250 static struct dfmt *debug_debug_arr[3] = {
251 &debug_debug_form,
252 &null_debug_form,
253 NULL
256 struct ofmt of_dbg = {
257 "Trace of all info passed to output stage",
258 "dbg",
259 OFMT_TEXT,
260 debug_debug_arr,
261 &debug_debug_form,
262 NULL,
263 dbg_init,
264 dbg_set_info,
265 dbg_out,
266 dbg_deflabel,
267 dbg_section_names,
268 dbg_sectalign,
269 dbg_segbase,
270 dbg_directive,
271 dbg_filename,
272 dbg_cleanup
275 #endif /* OF_DBG */