Mercurial > hg-old > index.cgi
annotate lwasm/debug.c @ 423:079d43b6967b 3.0-beta2 3.0-beta2
Added missing file
author | lost@l-w.ca |
---|---|
date | Sun, 19 Sep 2010 01:44:47 -0600 |
parents | eacdae8a1575 |
children |
rev | line source |
---|---|
370 | 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 <config.h> | |
23 | |
24 #include <stdio.h> | |
25 #include <string.h> | |
26 | |
27 #include "lwasm.h" | |
28 #include "instab.h" | |
29 | |
30 /* | |
31 | |
32 Various debug utilities | |
33 | |
34 */ | |
372
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
35 void dump_state(asmstate_t *as) |
370 | 36 { |
37 line_t *cl; | |
38 exportlist_t *ex; | |
39 struct symtabe *s; | |
40 importlist_t *im; | |
41 struct line_expr_s *le; | |
42 lwasm_error_t *e; | |
43 | |
372
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
44 debug_message(as, 100, "Lines:"); |
370 | 45 |
46 for (cl = as -> line_head; cl; cl = cl -> next) | |
47 { | |
372
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
48 debug_message(as, 100, "%p INSN %d (%s) LEN %d", cl, cl -> insn, (cl -> insn >= 0) ? instab[cl -> insn].opcode : "<none>", cl -> len); |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
49 debug_message(as, 100, " ADDR: %s", lw_expr_print(cl -> addr)); |
382 | 50 debug_message(as, 100, " PB: %02X; LINT: %X; LINT2: %X", cl -> pb, cl -> lint, cl -> lint2); |
370 | 51 for (le = cl -> exprs; le; le = le -> next) |
52 { | |
372
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
53 debug_message(as, 100, " EXPR %d: %s", le -> id, lw_expr_print(le -> expr)); |
370 | 54 } |
55 if (cl -> outputl > 0) | |
56 { | |
57 int i; | |
58 for (i = 0; i < cl -> outputl; i++) | |
59 { | |
372
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
60 debug_message(as, 100, " OBYTE %02X: %02X", i, cl -> output[i]); |
370 | 61 } |
62 } | |
63 for (e = cl -> err; e; e = e -> next) | |
64 { | |
372
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
65 debug_message(as, 100, " ERR: %s", e -> mess); |
370 | 66 } |
67 for (e = cl -> warn; e; e = e -> next) | |
68 { | |
372
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
69 debug_message(as, 100, " WARN: %s", e -> mess); |
370 | 70 } |
71 } | |
72 } | |
372
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
73 |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
74 void debug_message(asmstate_t *as, int level, const char *fmt, ...) |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
75 { |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
76 va_list args; |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
77 |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
78 if (as -> debug_level < level) |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
79 return; |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
80 |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
81 if (as -> debug_file == NULL) |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
82 as -> debug_file = stderr; |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
83 |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
84 va_start(args, fmt); |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
85 |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
86 fprintf(as -> debug_file, "DEBUG %03d: ", level); |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
87 vfprintf(as -> debug_file, fmt, args); |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
88 fputc('\n', as -> debug_file); |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
89 |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
90 va_end(args); |
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
91 } |