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.
31 static void dbg_init(FILE *fp
, efunc errfunc
, ldfunc ldef
, evalfunc eval
)
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
)
47 of_dbg
.current_dfmt
->cleanup();
49 struct Section
*tmp
= dbgsect
;
50 dbgsect
= dbgsect
->next
;
51 nasm_free (tmp
->name
);
57 static long dbg_section_names (char *name
, int pass
, int *bits
)
62 * We must have an initial default: let's make it 16.
68 fprintf(dbgf
, "section_name on init: returning %d\n",
71 int n
= strcspn(name
, " \t");
72 char *sname
= nasm_strndup(name
, n
);
76 for (s
= dbgsect
; s
; s
= s
->next
)
77 if (!strcmp(s
->name
, sname
))
81 s
= nasm_malloc(sizeof(*s
));
83 s
->number
= seg
= seg_alloc();
86 fprintf(dbgf
, "section_name %s (pass %d): returning %d\n",
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",
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
;
112 fprintf(dbgf
,"out to %lx, len = %ld: ",segto
,realbytes
);
116 fprintf(dbgf
,"reserved.\n"); break;
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;
126 ldata
= 0; /* placate gcc */
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
,
136 fprintf(dbgf
,"rel2adr %04x (seg %08lx)\n",(int)*(short *)data
,segment
);
139 fprintf(dbgf
,"rel4adr %08lx (seg %08lx)\n",*(long *)data
,segment
);
142 fprintf(dbgf
,"unknown\n");
147 static long dbg_segbase(long 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
);
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
)
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
, 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",
196 is_global
== 2 ? "common" : is_global
? "global" : "local",
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
)
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",
226 static struct dfmt
*debug_debug_arr
[3] = {
231 struct ofmt of_dbg
= {
232 "Trace of all info passed to output stage",