annotate lwasm/debug.c @ 370:6b33faa21a0a

Debugging output and bugfixing pass 0
author lost@starbug
date Tue, 20 Apr 2010 21:59:58 -0600
parents
children 90de73ba0cac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
370
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
1 /*
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
2 debug.c
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
3
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
4 Copyright © 2010 William Astle
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
5
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
6 This file is part of LWTOOLS.
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
7
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
11 version.
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
12
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
16 more details.
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
17
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
20 */
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
21
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
22 #include <config.h>
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
23
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
24 #include <stdio.h>
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
25 #include <string.h>
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
26
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
27 #include "lwasm.h"
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
28 #include "instab.h"
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
29
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
30 /*
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
31
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
32 Various debug utilities
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
33
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
34 */
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
35 void dump_state(asmstate_t *as, FILE *fp)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
36 {
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
37 line_t *cl;
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
38 exportlist_t *ex;
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
39 struct symtabe *s;
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
40 importlist_t *im;
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
41 struct line_expr_s *le;
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
42 lwasm_error_t *e;
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
43
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
44 fprintf(fp, "Lines:\n");
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
45
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
46 for (cl = as -> line_head; cl; cl = cl -> next)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
47 {
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
48 fprintf(fp, "%p ", cl);
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
49 if (cl -> insn >= 0)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
50 {
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
51 fprintf(fp, "INSN %d (%s) ", cl -> insn, instab[cl -> insn].opcode);
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
52 fprintf(fp, "LEN %d ", cl -> len);
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
53 }
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
54 fprintf(fp, "\n ADDR:");
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
55 lw_expr_print(cl -> addr, fp);
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
56 for (le = cl -> exprs; le; le = le -> next)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
57 {
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
58 fprintf(fp, "\n EXPR %d:", le -> id);
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
59 lw_expr_print(le -> expr, fp);
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
60 }
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
61 if (cl -> outputl > 0)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
62 {
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
63 int i;
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
64 fprintf(fp, "\n OUTPUT:");
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
65 for (i = 0; i < cl -> outputl; i++)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
66 {
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
67 fprintf(fp, "%02X", cl -> output[i]);
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
68 }
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
69 }
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
70 for (e = cl -> err; e; e = e -> next)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
71 {
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
72 fprintf(fp, "\n ERR: %s", e -> mess);
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
73 }
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
74 for (e = cl -> warn; e; e = e -> next)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
75 {
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
76 fprintf(fp, "\n WARN: %s", e -> mess);
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
77 }
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
78 fprintf(fp, "\n");
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
79 }
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
80 }