3 SDCDB debugger - Development notes.
8 ========================
9 Martin Helmling added support for ddd GUI debugger.
10 Code added to display assembly, set variables, and other commands
15 in the attachment is my actual patch.
17 The 'up' and 'down' stack commands are not implemented.
18 But the features for 'ddd' to see bopth the c source and the assembler
20 also the display of variables.
21 Set variables are only implemented for basic types.
22 Register variables can also displayed, but here I think a problem in the
24 Sometimes the register name not exists:
26 S:LcacheTxAnalogValue$offset$1$1({1}SC:U),E,0,0
27 S:LcacheTxAnalogValue$i$1$1({1}SC:S),R,0,0,[]
28 S:LcacheTxAnalogValue$val$1$1({4}ST__00020000:S),E,0,0
29 S:LcacheTxAnalogValue$value$1$1({1}SC:U),R,0,0,[]
30 S:LcacheTxAnalogValue$sloc0$1$0({4}SL:U),E,0,0
31 S:LsetRelays$addr$1$1({1}SC:U),R,0,0,[r2]
32 S:LsetRelays$state$1$1({1}SC:U),R,0,0,[r3]
33 S:LsetRelays$value$1$1({1}SC:U),R,0,0,[r5]
34 S:L_main$i$1$1({1}SC:U),R,0,0,[]
35 S:L_main$j$1$1({1}SC:U),R,0,0,[r3]
36 S:L_main$ok$1$1({1}SC:U),R,0,0,[r3]
38 the empty [] I mean !!
40 Is this a known bug in sdcc ?
42 Also sometimes not the correct breakpoints for stepping found in sdcdb.
43 I try to fix this tomorrow.
45 Additional patches and notes from Martin(4-24-03):
46 in the attachment you found three patches:
47 debugpatch: Only for debugging, you can switch on and off the 4 different
48 debug and you can grep the debug by the prefix.
49 signalpatch:Now the simulator stops if the user sends an interrupt
50 ( or 'ddd' ) and also the simulator does not die by another
53 sympatch: This is not a feature, THIS is the fix of a BUG !!!
54 In some circumstances in the *.cdb file the Symbol record
55 comes before the function record. So the symbol was
56 generated TWO TIMES in the symbol list. The L:G and L:XG
58 records then insert entry and exit address to the wrong
59 symbol. So before a new symbol is generated for the
60 function, a lookup in the symboltable is done.
64 S:G$ZpuInitialize$0$0({2}DF,SV:S),C,0,0
65 S:G$ZpuInitialize$0$0({2}DF,SV:S),C,0,0
66 F:G$ZpuInitialize$0$0({2}DF,SV:S),Z,0,0,0,0,0
67 S:LZpuInitialize$i$1$1({2}SI:S),R,0,0,[]
68 L:G$ZpuInitialize$0$0:ADF
69 L:XG$ZpuInitialize$0$0:BBB
72 Notes Feb 10, 2002 - Karl Bongers
73 ========================
75 SDCDB is a debugger for SDCC compiler. It works as a front
76 end to the ucSim simulator/disassembler program.
78 WARNING: SDCDB is EXPERIMENTAL and NOT A FULLY FUNCTIONING TOOL.
80 SDCDB does hold out promise for a nice debugger tool that
81 could integrate well with ucSim and other SDCC tools. It has
82 some nice functionality that could augment ucSim nicely.
83 It reads in a lot of symbolic information from the .CDB
84 debug files as well as the source code and assembly
85 listings referred to in these CDB files.
86 This can be used to display your program data, list
87 c or asm source code and set breakpoints.
89 Unfortunately, SDCDB is not quite finished and does not
90 function well enough yet to recommend for general use.
94 ======================
95 Compile with --debug option:
97 This should generate .cdb symbolic debug files.
99 Load sdcdb, like this:
102 Then you need to do an initial "run" command. It should hopefully
103 stop somewhere at the main() entrypoint.
105 Now you should be able to list code, and set breakpoints. Type
106 "c" to continue running to a breakpoint, or type "s" to single
107 step or "n" to skip function calls. Tpye "help" for a summary
110 Use a preceeding bang("!") to do s51 simulator commands. So for
113 will send the "pc" command to ucSim and
114 give you the program counter and list the current line of assembly.
116 will give you the brief command line help listing of ucSim. But
117 this help will scroll of the screen. So to get a list, I redirect
118 stdout to a text file to examine like this:
119 sdcdb hi.ihx 2>&1 | tee sdcdb.log
121 Type '.' to toggle to a full time ucSim prompt.
125 ======================
127 Ok, so what are some of its problems? Lets try to itemize
128 them so we can fix them:
130 * It hangs sometimes when trying to do step or next.
132 This probably has something to do with the context
133 sdcdb tries to build dynamically. Sdcdb tries to
134 trace program operation by placing hidden breakpoints
135 and stepping threw the simulation between these.
137 * Does not print variables properly. Seems to use the
138 wrong address for the variable. (fixed)
140 * ASM listing not implemented.
141 This should be easy enough to add. This feature
142 really needs to be implemented before this is a useful
143 tool. That or addresses of code functions need to be
144 readily available for raw ucSim commands.
146 * No way to browse symbols, files names.
147 Preferably, it is easy to learn the addresses of variables
149 (working on this... see new ls,lm,lf commands)
151 * Does not allow listing, setting breakpoints or viewing variables
152 before starting the simulation.
153 (I am fixing now, partly fixed)
155 * p codestr - print on code char * broken, could be CDB info invalid.
159 ======================
161 Added a -z option. Any options after -z on sdcdb invocation line
162 are passed directly to ucSim.
164 Fixed print basic variable command(was not parsing or expecting
165 "0x" in data coming from ucSim). Dump bit command changed from
168 Add support for the following alternative ucSim binaries:
169 -mz80 - use "uz80" simulator.
170 -mavr - use "uavr" simulator.
171 -mxa - use "uxa" simulator.
173 Note that Z80(and probably avr/xa) does not produce enough
174 CDB debugging information to
175 make SDCDB useful. Hopefully CDB support will be
176 added to these other linkers and code generators.
178 Added lf,lm,ls commands(list functions, list modules, list symbols).
179 This allows browsing some the CDB information SDCDB pulls in
180 to do the wonderful things it does.
182 Added '.' prefix/command, used alone switches back and forth
183 from ucSim/SDCDB command mode). Also when at the (ucsim) prompt,
184 if a command is prefixed with '.' it will route the command to
185 the SDCDB command processor. (This could obsolete the '!' prefix).
188 ======================
190 Fix any remaining shortcomings above and make sdcdb integrate better with
193 Concerning the hanging on next/step instructions: This is critical
194 to fix. I beleive the problem is related to SDCDB's attempt to
195 dynamically track context. To do this, it sets many temporary break
196 points and uses these to progress step by step through the source code.
197 It does not seem reliable. It might be an idea to offer a simplified
198 mode of stepping and breakpoints. Need to study this more.
200 Make SDCDB integrate better with ucSim.
201 I think if sdcdb can act more transparently in regard to ucSim
202 it would be used more. So stress adding value and enhancing
203 ucSim operation, and not block or hide the functionality of ucSim.
205 * combine print "p" & "pt" together. We have room on the screen,
206 might as well print its type, address and value in one command.
208 * "fr" command prints the current position in the C code.
209 Should also print the raw code address for dumping ucSim code.
214 ======================
215 To debug, it might be helpful to turn on verbose debug dumps
216 by uncommenting #define SDCDB_DEBUG in sdcdb.h.
219 sdcdb.c - main shell of the program.
220 cmd.c - process user commands typed in.
221 simi.c - handle talking to the simulator via a socket connection.
222 symtab.c - Misc. functions to translate and process linked list
223 structures(modules, functions, symbols, etc) and CDB file
225 break.c - track and implement break points.
227 Understanding the structures and access mechanisms of SDCDB
228 is a bit of work. The structures include generic linked list
229 and function access. These lists are accessed in part by the
230 functions from ../../src/SDCCset.c and SDCChash.c. See the
231 cmd.c:infoSymbols() routine to gain some insight into these
232 main program structures. Or type "info symbols" to dump
233 out some of these. The new ls,lm,lf commands are also based
234 on showing information about these lists of structures.
236 Generic functions are used to act on these linked lists of
237 structures. For example, in cmd.c, DEFSETFUNC(funcWithName)
238 function will find a function structure with a given name.
239 So the linked list of function structures(with the head
240 "functions") is traversed and when one is found with a matching
241 name, a pointer to the function structure is returned.
243 The src/SDCCset.c,SDCCset.h contain much of the core helper
244 routines to allowed to implement these linked list access
247 The dynamic context tracking is difficult to understand.
248 It has some concept of stack use, as in
249 cmd.c:printSymValue(), where it can print variables relative
250 to the stack pointer.