Mercurial > hg > index.cgi
comparison lwasm/debug.c @ 0:2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
author | lost@l-w.ca |
---|---|
date | Wed, 19 Jan 2011 22:27:17 -0700 |
parents | |
children | 7317fbe024af |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2c24602be78f |
---|---|
1 /* | |
2 debug.c | |
3 | |
4 Copyright © 2010 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 #include <stdio.h> | |
23 #include <string.h> | |
24 #include <stdarg.h> | |
25 | |
26 #include "lwasm.h" | |
27 #include "instab.h" | |
28 | |
29 /* | |
30 | |
31 Various debug utilities | |
32 | |
33 */ | |
34 void dump_state(asmstate_t *as) | |
35 { | |
36 line_t *cl; | |
37 exportlist_t *ex; | |
38 struct symtabe *s; | |
39 importlist_t *im; | |
40 struct line_expr_s *le; | |
41 lwasm_error_t *e; | |
42 | |
43 debug_message(as, 100, "Lines:"); | |
44 | |
45 for (cl = as -> line_head; cl; cl = cl -> next) | |
46 { | |
47 debug_message(as, 100, "%p INSN %d (%s) LEN %d", cl, cl -> insn, (cl -> insn >= 0) ? instab[cl -> insn].opcode : "<none>", cl -> len); | |
48 debug_message(as, 100, " ADDR: %s", lw_expr_print(cl -> addr)); | |
49 debug_message(as, 100, " PB: %02X; LINT: %X; LINT2: %X", cl -> pb, cl -> lint, cl -> lint2); | |
50 for (le = cl -> exprs; le; le = le -> next) | |
51 { | |
52 debug_message(as, 100, " EXPR %d: %s", le -> id, lw_expr_print(le -> expr)); | |
53 } | |
54 if (cl -> outputl > 0) | |
55 { | |
56 int i; | |
57 for (i = 0; i < cl -> outputl; i++) | |
58 { | |
59 debug_message(as, 100, " OBYTE %02X: %02X", i, cl -> output[i]); | |
60 } | |
61 } | |
62 for (e = cl -> err; e; e = e -> next) | |
63 { | |
64 debug_message(as, 100, " ERR: %s", e -> mess); | |
65 } | |
66 for (e = cl -> warn; e; e = e -> next) | |
67 { | |
68 debug_message(as, 100, " WARN: %s", e -> mess); | |
69 } | |
70 } | |
71 } | |
72 | |
73 void debug_message(asmstate_t *as, int level, const char *fmt, ...) | |
74 { | |
75 va_list args; | |
76 | |
77 if (as -> debug_level < level) | |
78 return; | |
79 | |
80 if (as -> debug_file == NULL) | |
81 as -> debug_file = stderr; | |
82 | |
83 va_start(args, fmt); | |
84 | |
85 fprintf(as -> debug_file, "DEBUG %03d: ", level); | |
86 vfprintf(as -> debug_file, fmt, args); | |
87 fputc('\n', as -> debug_file); | |
88 | |
89 va_end(args); | |
90 } |