Fix "make doc"
[nasm/avx512.git] / output / outdbg.c
blob723e372d951baea1571832fbe27679f02fde702a
1 /* outdbg.c output routines for the Netwide Assembler to produce
2 * a debugging trace
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.
8 */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <ctype.h>
15 #include "nasm.h"
16 #include "nasmlib.h"
17 #include "outform.h"
19 #ifdef OF_DBG
21 struct Section {
22 struct Section *next;
23 long number;
24 char *name;
25 } *dbgsect;
27 FILE *dbgf;
28 efunc dbgef;
30 struct ofmt of_dbg;
31 static void dbg_init(FILE *fp, efunc errfunc, ldfunc ldef, evalfunc eval)
33 (void) eval;
35 dbgf = fp;
36 dbgef = errfunc;
37 dbgsect = NULL;
38 (void) ldef;
39 fprintf(fp,"NASM Output format debug dump\n");
40 of_dbg.current_dfmt->init(&of_dbg,0,fp,errfunc);
44 static void dbg_cleanup(int debuginfo)
46 (void) debuginfo;
47 of_dbg.current_dfmt->cleanup();
48 while (dbgsect) {
49 struct Section *tmp = dbgsect;
50 dbgsect = dbgsect->next;
51 nasm_free (tmp->name);
52 nasm_free (tmp);
54 fclose(dbgf);
57 static long dbg_section_names (char *name, int pass, int *bits)
59 int seg;
62 * We must have an initial default: let's make it 16.
64 if (!name)
65 *bits = 16;
67 if (!name)
68 fprintf(dbgf, "section_name on init: returning %d\n",
69 seg = seg_alloc());
70 else {
71 int n = strcspn(name, " \t");
72 char *sname = nasm_strndup(name, n);
73 struct Section *s;
75 seg = NO_SEG;
76 for (s = dbgsect; s; s = s->next)
77 if (!strcmp(s->name, sname))
78 seg = s->number;
80 if (seg == NO_SEG) {
81 s = nasm_malloc(sizeof(*s));
82 s->name = sname;
83 s->number = seg = seg_alloc();
84 s->next = dbgsect;
85 dbgsect = s;
86 fprintf(dbgf, "section_name %s (pass %d): returning %d\n",
87 name, pass, seg);
90 return seg;
93 static void dbg_deflabel (char *name, long segment, long offset,
94 int is_global, char *special)
96 fprintf(dbgf,"deflabel %s := %08lx:%08lx %s (%d)%s%s\n",
97 name, segment, offset,
98 is_global == 2 ? "common" : is_global ? "global" : "local",
99 is_global,
100 special ? ": " : "", special);
103 static void dbg_out (long segto, void *data, unsigned long type,
104 long segment, long wrt)
106 long realbytes = type & OUT_SIZMASK;
107 long ldata;
108 int id;
110 type &= OUT_TYPMASK;
112 fprintf(dbgf,"out to %lx, len = %ld: ",segto,realbytes);
114 switch(type) {
115 case OUT_RESERVE:
116 fprintf(dbgf,"reserved.\n"); break;
117 case OUT_RAWDATA:
118 fprintf(dbgf,"raw data = ");
119 while (realbytes--) {
120 id = *(unsigned char *)data;
121 data = (char *)data + 1;
122 fprintf(dbgf,"%02x ",id);
124 fprintf(dbgf,"\n"); break;
125 case OUT_ADDRESS:
126 ldata = 0; /* placate gcc */
127 if (realbytes == 1)
128 ldata = *((char *)data);
129 else if (realbytes == 2)
130 ldata = *((short *)data);
131 else if (realbytes == 4)
132 ldata = *((long *)data);
133 fprintf(dbgf,"addr %08lx (seg %08lx, wrt %08lx)\n",ldata,
134 segment,wrt);break;
135 case OUT_REL2ADR:
136 fprintf(dbgf,"rel2adr %04x (seg %08lx)\n",(int)*(short *)data,segment);
137 break;
138 case OUT_REL4ADR:
139 fprintf(dbgf,"rel4adr %08lx (seg %08lx)\n",*(long *)data,segment);
140 break;
141 default:
142 fprintf(dbgf,"unknown\n");
143 break;
147 static long dbg_segbase(long segment)
149 return segment;
152 static int dbg_directive (char *directive, char *value, int pass)
154 fprintf(dbgf, "directive [%s] value [%s] (pass %d)\n",
155 directive, value, pass);
156 return 1;
159 static void dbg_filename (char *inname, char *outname, efunc error)
161 standard_extension (inname, outname, ".dbg", error);
164 static int dbg_set_info(enum geninfo type, char **val)
166 (void) type;
167 (void) val;
168 return 0;
170 char *types[] = {
171 "unknown", "label", "byte","word","dword","float","qword","tbyte"
173 void dbgdbg_init(struct ofmt * of, void * id, FILE * fp, efunc error)
175 (void) of;
176 (void) id;
177 (void) fp;
178 (void) error;
179 fprintf(fp," With debug info\n");
181 static void dbgdbg_cleanup(void)
185 static void dbgdbg_linnum (const char *lnfname, long lineno, long segto)
187 fprintf(dbgf,"dbglinenum %s(%ld) := %08lx\n",
188 lnfname,lineno,segto);
190 static void dbgdbg_deflabel (char *name, long segment,
191 long offset, int is_global, char *special)
193 fprintf(dbgf,"dbglabel %s := %08lx:%08lx %s (%d)%s%s\n",
194 name,
195 segment, offset,
196 is_global == 2 ? "common" : is_global ? "global" : "local",
197 is_global,
198 special ? ": " : "", special);
200 static void dbgdbg_define(const char *type, const char *params)
202 fprintf(dbgf,"dbgdirective [%s] value [%s]\n",type, params);
204 static void dbgdbg_output (int output_type, void *param)
206 (void) output_type;
207 (void) param;
209 static void dbgdbg_typevalue(long type)
211 fprintf(dbgf,"new type: %s(%lX)\n",
212 types[TYM_TYPE(type) >> 3], TYM_ELEMENTS(type) );
214 static struct dfmt debug_debug_form = {
215 "Trace of all info passed to debug stage",
216 "debug",
217 dbgdbg_init,
218 dbgdbg_linnum,
219 dbgdbg_deflabel,
220 dbgdbg_define,
221 dbgdbg_typevalue,
222 dbgdbg_output,
223 dbgdbg_cleanup,
226 static struct dfmt *debug_debug_arr[3] = {
227 &debug_debug_form,
228 &null_debug_form,
229 NULL
231 struct ofmt of_dbg = {
232 "Trace of all info passed to output stage",
233 "dbg",
234 NULL,
235 debug_debug_arr,
236 &null_debug_form,
237 NULL,
238 dbg_init,
239 dbg_set_info,
240 dbg_out,
241 dbg_deflabel,
242 dbg_section_names,
243 dbg_segbase,
244 dbg_directive,
245 dbg_filename,
246 dbg_cleanup
249 #endif /* OF_DBG */