1 /*-------------------------------------------------------------------------
2 SDCCdebug.c - source file for debug infrastructure
3
4 Copyright (C) 2003, Lenny Story and Bernhard Held
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 -------------------------------------------------------------------------*/
20
21 #include "common.h"
22
23 extern DEBUGFILE cdbDebugFile;
24
25 DEBUGFILE *debugFile = &cdbDebugFile;
26
27 void
outputDebugStackSymbols(void)28 outputDebugStackSymbols (void)
29 {
30 if (getenv ("SDCC_DEBUG_VAR_STORAGE"))
31 {
32 dumpSymInfo ("XStack", xstack);
33 dumpSymInfo ("IStack", istack);
34 }
35
36 if (options.debug && debugFile)
37 {
38 symbol *sym;
39
40 if (xstack)
41 {
42 for (sym = setFirstItem (xstack->syms); sym; sym = setNextItem (xstack->syms))
43 debugFile->writeSymbol (sym);
44 }
45
46 if (istack)
47 {
48 for (sym = setFirstItem (istack->syms); sym; sym = setNextItem (istack->syms))
49 debugFile->writeSymbol(sym);
50 }
51 }
52 }
53
54
55 void
outputDebugSymbols(void)56 outputDebugSymbols (void)
57 {
58 if (getenv ("SDCC_DEBUG_VAR_STORAGE"))
59 {
60 dumpSymInfo ("Initialized", initialized);
61 dumpSymInfo ("Code", code);
62 dumpSymInfo ("Data", data);
63 dumpSymInfo ("PData", pdata);
64 dumpSymInfo ("XData", xdata);
65 dumpSymInfo ("XIData", xidata);
66 dumpSymInfo ("XInit", xinit);
67 dumpSymInfo ("IData", idata);
68 dumpSymInfo ("Bit", bit);
69 dumpSymInfo ("Statics", statsg);
70 dumpSymInfo ("SFR", sfr);
71 dumpSymInfo ("SFRBits", sfrbit);
72 dumpSymInfo ("Reg", reg);
73 dumpSymInfo ("Generic", generic);
74 dumpSymInfo ("Overlay", overlay);
75 dumpSymInfo ("EEProm", eeprom);
76 dumpSymInfo ("Home", home);
77 }
78
79 if (options.debug && debugFile)
80 {
81 symbol *sym;
82
83 if(initialized)
84 {
85 for (sym = setFirstItem (initialized->syms); sym; sym = setNextItem (initialized->syms))
86 debugFile->writeSymbol (sym);
87 }
88
89 if (data)
90 {
91 for (sym = setFirstItem (data->syms); sym; sym = setNextItem (data->syms))
92 debugFile->writeSymbol (sym);
93 }
94
95 if (idata)
96 {
97 for (sym = setFirstItem (idata->syms); sym; sym = setNextItem (idata->syms))
98 debugFile->writeSymbol (sym);
99 }
100
101 if (bit)
102 {
103 for (sym = setFirstItem (bit->syms); sym; sym = setNextItem (bit->syms))
104 debugFile->writeSymbol (sym);
105 }
106
107 if (pdata)
108 {
109 for (sym = setFirstItem (pdata->syms); sym; sym = setNextItem (pdata->syms))
110 debugFile->writeSymbol (sym);
111 }
112
113 if (xdata)
114 {
115 for (sym = setFirstItem (xdata->syms); sym; sym = setNextItem (xdata->syms))
116 debugFile->writeSymbol (sym);
117 }
118
119 if (port->genXINIT && xidata)
120 {
121 for (sym = setFirstItem (xidata->syms); sym; sym = setNextItem (xidata->syms))
122 debugFile->writeSymbol (sym);
123 }
124
125 if (sfr)
126 {
127 for (sym = setFirstItem (sfr->syms); sym; sym = setNextItem (sfr->syms))
128 debugFile->writeSymbol (sym);
129 }
130
131 if (sfrbit)
132 {
133 for (sym = setFirstItem (sfrbit->syms); sym; sym = setNextItem (sfrbit->syms))
134 debugFile->writeSymbol (sym);
135 }
136
137 if (home)
138 {
139 for (sym = setFirstItem (home->syms); sym; sym = setNextItem (home->syms))
140 debugFile->writeSymbol (sym);
141 }
142
143 if (code)
144 {
145 for (sym = setFirstItem (code->syms); sym; sym = setNextItem (code->syms))
146 debugFile->writeSymbol (sym);
147 }
148
149 if (statsg)
150 {
151 for (sym = setFirstItem (statsg->syms); sym; sym = setNextItem (statsg->syms))
152 debugFile->writeSymbol (sym);
153 }
154
155 if (port->genXINIT && xinit)
156 {
157 for (sym = setFirstItem (xinit->syms); sym; sym = setNextItem (xinit->syms))
158 debugFile->writeSymbol (sym);
159 }
160 }
161
162 return;
163 }
164
165
166 void
dumpSymInfo(const char * pcName,memmap * memItem)167 dumpSymInfo(const char *pcName, memmap *memItem)
168 {
169 symbol *sym;
170
171 if (!memItem)
172 return;
173
174 printf ("--------------------------------------------\n");
175 printf (" %s\n", pcName);
176
177 for (sym = setFirstItem (memItem->syms); sym; sym = setNextItem (memItem->syms))
178 {
179 printf (" %s, isReqv:%d, reqv:0x%p, onStack:%d, Stack:%d, nRegs:%d, [",
180 sym->rname, sym->isreqv, (void*)(sym->reqv), sym->onStack, sym->stack, sym->nRegs);
181
182 if (sym->reqv)
183 {
184 int i;
185 symbol *TempSym = OP_SYMBOL (sym->reqv);
186
187 for (i = 0; i < 4; i++)
188 if (TempSym->regs[i])
189 printf ("%s,", port->getRegName (TempSym->regs[i]));
190 }
191
192 printf ("]\n");
193 }
194
195 printf ("\n");
196 }
197
198
199 /*------------------------------------------------------------------*/
200 /* emitDebuggerSymbol - call the port specific routine to associate */
201 /* the current code location with a debugger symbol */
202 /*------------------------------------------------------------------*/
203 void
emitDebuggerSymbol(const char * debugSym)204 emitDebuggerSymbol (const char * debugSym)
205 {
206 if (port->debugger.emitDebuggerSymbol)
207 port->debugger.emitDebuggerSymbol (debugSym);
208 }
209