annotate lwasm/debug.c @ 448:5cccf90bf838 3.0 tip

Fixed bug with complex external references generating invalid relocations in the object file
author lost@l-w.ca
date Fri, 05 Nov 2010 22:27:00 -0600
parents eacdae8a1575
children
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 */
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
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
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
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 {
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
eacdae8a1575 Various bugfixes
lost@starbug
parents: 372
diff changeset
50 debug_message(as, 100, " PB: %02X; LINT: %X; LINT2: %X", cl -> pb, cl -> lint, cl -> lint2);
370
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
51 for (le = cl -> exprs; le; le = le -> next)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
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
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
54 }
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
55 if (cl -> outputl > 0)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
56 {
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
57 int i;
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
58 for (i = 0; i < cl -> outputl; i++)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
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
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
61 }
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 for (e = cl -> err; e; e = e -> next)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
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
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 for (e = cl -> warn; e; e = e -> next)
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
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
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents:
diff changeset
70 }
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 }
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 }