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.
30 static void dbg_init(FILE *fp
, efunc errfunc
, ldfunc ldef
, evalfunc eval
)
36 fprintf(fp
,"NASM Output format debug dump\n");
39 static void dbg_cleanup(void)
42 struct Section
*tmp
= dbgsect
;
43 dbgsect
= dbgsect
->next
;
44 nasm_free (tmp
->name
);
50 static long dbg_section_names (char *name
, int pass
, int *bits
)
55 * We must have an initial default: let's make it 16.
61 fprintf(dbgf
, "section_name on init: returning %d\n",
64 int n
= strcspn(name
, " \t");
65 char *sname
= nasm_strndup(name
, n
);
69 for (s
= dbgsect
; s
; s
= s
->next
)
70 if (!strcmp(s
->name
, sname
))
74 s
= nasm_malloc(sizeof(*s
));
76 s
->number
= seg
= seg_alloc();
79 fprintf(dbgf
, "section_name %s (pass %d): returning %d\n",
86 static void dbg_deflabel (char *name
, long segment
, long offset
,
87 int is_global
, char *special
) {
88 fprintf(dbgf
,"deflabel %s := %08lx:%08lx %s (%d)%s%s\n",
89 name
, segment
, offset
,
90 is_global
== 2 ? "common" : is_global
? "global" : "local",
92 special
? ": " : "", special
);
95 static void dbg_out (long segto
, void *data
, unsigned long type
,
96 long segment
, long wrt
) {
97 long realbytes
= type
& OUT_SIZMASK
;
103 fprintf(dbgf
,"out to %lx, len = %ld: ",segto
,realbytes
);
107 fprintf(dbgf
,"reserved.\n"); break;
109 fprintf(dbgf
,"raw data = ");
110 while (realbytes
--) {
111 id
= *(unsigned char *)data
;
112 data
= (char *)data
+ 1;
113 fprintf(dbgf
,"%02x ",id
);
115 fprintf(dbgf
,"\n"); break;
117 ldata
= 0; /* placate gcc */
119 ldata
= *((char *)data
);
120 else if (realbytes
== 2)
121 ldata
= *((short *)data
);
122 else if (realbytes
== 4)
123 ldata
= *((long *)data
);
124 fprintf(dbgf
,"addr %08lx (seg %08lx, wrt %08lx)\n",ldata
,
127 fprintf(dbgf
,"rel2adr %04x (seg %08lx)\n",(int)*(short *)data
,segment
);
130 fprintf(dbgf
,"rel4adr %08lx (seg %08lx)\n",*(long *)data
,segment
);
133 fprintf(dbgf
,"unknown\n");
138 static long dbg_segbase(long segment
) {
142 static int dbg_directive (char *directive
, char *value
, int pass
) {
143 fprintf(dbgf
, "directive [%s] value [%s] (pass %d)\n",
144 directive
, value
, pass
);
148 static void dbg_filename (char *inname
, char *outname
, efunc error
) {
149 standard_extension (inname
, outname
, ".dbg", error
);
152 struct ofmt of_dbg
= {
153 "Trace of all info passed to output stage",