NASM 0.93
[nasm/avx512.git] / outdbg.c
bloba55d3db8b583d90602a8e1e5a76f85054946b9d3
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 FILE *dbgf;
22 efunc dbgef;
24 int segcode,segdata,segbss;
26 static void dbg_init(FILE *fp, efunc errfunc, ldfunc ldef)
28 dbgf = fp;
29 dbgef = errfunc;
30 (void) ldef;
31 segcode = seg_alloc();
32 segdata = seg_alloc();
33 segbss = seg_alloc();
34 fprintf(fp,"NASM Output format debug dump - code=%d,data=%d,bss=%d\n",
35 segcode,segdata,segbss);
38 static void dbg_cleanup(void)
40 fclose(dbgf);
43 static long dbg_section_names (char *name, int pass, int *bits)
46 * We must have an initial default: let's make it 16.
48 if (!name)
49 *bits = 16;
51 if (!name)
52 return 0;
54 if (!strcmp(name, ".text"))
55 return segcode;
56 else if (!strcmp(name, ".data"))
57 return segdata;
58 else if (!strcmp(name, ".bss"))
59 return segbss;
60 else
61 return NO_SEG;
64 static void dbg_deflabel (char *name, long segment, long offset,
65 int is_global) {
66 fprintf(dbgf,"deflabel %s := %08lx:%08lx %s (%d)\n",name,segment,offset,
67 is_global ? "global" : "local", is_global);
70 static void dbg_out (long segto, void *data, unsigned long type,
71 long segment, long wrt) {
72 long realbytes = type & OUT_SIZMASK;
73 long ldata;
74 int id;
76 type &= OUT_TYPMASK;
78 fprintf(dbgf,"out to %lx, len = %ld: ",segto,realbytes);
80 switch(type) {
81 case OUT_RESERVE:
82 fprintf(dbgf,"reserved.\n"); break;
83 case OUT_RAWDATA:
84 fprintf(dbgf,"raw data = ");
85 while (realbytes--) {
86 id = *(unsigned char *)data;
87 data = (char *)data + 1;
88 fprintf(dbgf,"%02x ",id);
90 fprintf(dbgf,"\n"); break;
91 case OUT_ADDRESS:
92 ldata = 0; /* placate gcc */
93 if (realbytes == 1)
94 ldata = *((char *)data);
95 else if (realbytes == 2)
96 ldata = *((short *)data);
97 else if (realbytes == 4)
98 ldata = *((long *)data);
99 fprintf(dbgf,"addr %08lx (seg %08lx, wrt %08lx)\n",ldata,
100 segment,wrt);break;
101 case OUT_REL2ADR:
102 fprintf(dbgf,"rel2adr %04x (seg %08lx)\n",(int)*(short *)data,segment);
103 break;
104 case OUT_REL4ADR:
105 fprintf(dbgf,"rel4adr %08lx (seg %08lx)\n",*(long *)data,segment);
106 break;
107 default:
108 fprintf(dbgf,"unknown\n");
109 break;
113 static long dbg_segbase(long segment) {
114 return segment;
117 static int dbg_directive (char *directive, char *value, int pass) {
118 return 0;
121 static void dbg_filename (char *inname, char *outname, efunc error) {
122 standard_extension (inname, outname, ".dbg", error);
125 struct ofmt of_dbg = {
126 "Trace of all info passed to output stage",
127 "dbg",
128 dbg_init,
129 dbg_out,
130 dbg_deflabel,
131 dbg_section_names,
132 dbg_segbase,
133 dbg_directive,
134 dbg_filename,
135 dbg_cleanup
138 #endif /* OF_DBG */