3 SDCDB debugger - Development notes.
7 ddd - Notes from Martin Helmling, April 28, 2003
8 ========================
10 To fullfill the requirements of 'ddd' ( Data Display Debugger ) to use it at
11 graphical frontend to 'sdcdb' some new commands must be implemented.
13 Now you can run the ddd with the commandline
15 ddd -debugger 'sdcdb -cpu 8032 <file>'
17 Following commands are additional implemented:
21 stepi - Step one instruction exactly using simulator 'step' command.
22 nexti - Step one instruction, but proceed through subroutine calls using simulator 'next' command.
23 break *<addr> - Set breakpoint at program address
27 <- "Simulator stopped at Address 0x0051\n"
28 "\032\032x.c:31:1:beg:0x00000051\n"
31 <- "Simulator stopped at Address 0x0055\n"
32 "\032\032x.c:33:1:beg:0x00000055\n"
35 2. show machine code window:
37 x /i - disassemble one asm command
38 x disassemble asm commands
41 -> "x /i 0x00000055\n"
42 <- "0x00000055 <main+6>:\t\tmov\tr0,#_l\n"
44 -> "disassemble 0x00000055\n"
45 <- "Dump of assembler code for function main:\n"
46 "0x0000004f <main>:\t\tmov\tr0,#_ttt\n"
47 "0x00000051 <main+2>:\t\tmov\t@r0,#0x01\n"
48 <- "0x00000053 <main+4>:\t\tmov\tr2,#0x09\n"
49 "0x00000055 <main+6>:\t\tmov\tr0,#_l\n"
51 "0x000000c1 <main+114>:\t\tret\n"
52 "End of assembler dump.\n"
54 -> "disassemble 0x40 0x45\n"
55 <- "Dump of assembler code from 0x00000040 to 0x00000045:\n"
56 "0x00000040 <subfunc1+8>:\t\tinc\tr0\n"
57 "0x00000041 <subfunc1+9>:\t\tmov\t@r0,ar3\n"
58 "0x00000043 <subfunc1+11>:\t\tmov\ta,r3\n"
59 "0x00000044 <subfunc1+12>:\t\trlc\ta\n"
60 "0x00000045 <subfunc1+13>:\t\tsubb\ta,acc\n"
61 "End of assembler dump.\n"
64 <- "Breakpoint 1 at 0x4b: file x.c, line 23.\n"
66 -> "info breakpoints\n"
67 <- "Num Type Disp Enb Address What\n"
68 "1 breakpoint keep y 0x0000004b at x.c:23\n"
72 3. show registers and stack
74 frame - print information about the current Stack
76 up - Select and print stack frame that called this one
77 down - Select and print stack frame that called this one
78 info registers - show registers
79 info all-registers - show also special these function registers,
80 which are symbolical defined.
81 help <cmd> show short help for ddd tooltip info
85 <- "#0 0x0000004b in subfunc1 () at x.c:23\n"
86 "#1 0x0000004f in main () at x.c:31\n"
89 <- "#0 0x0000004b in subfunc1 () at x.c:23\n"
90 "\032\032x.c:23:1:beg:0x0000004b\n"
93 <- "#1 0x0000004f in main () at x.c:31\n"
94 "\032\032x.c:31:1:beg:0x0000004f\n"
97 <- "#1 0x0000004f in main () at x.c:31\n"
98 "\032\032x.c:31:1:beg:0x0000004f\n"
101 <- "#0 0x0000004b in subfunc1 () at x.c:23\n"
102 "\032\032x.c:23:1:beg:0x0000004b\n"
105 <- "#0 0x0000004b in subfunc1 () at x.c:23\n"
106 "\032\032x.c:23:1:beg:0x0000004b\n"
108 -> "info registers\n"
109 <- "R0 : 0x87 135 .\n"
120 "PSW : 0x00 | CY : 0 | AC : 0 | OV : 0 | P : 0\n"
122 # Showing all registers.
123 -> "info all-registers\n"
124 <- "R0 : 0x87 135 .\n"
135 "PSW : 0x00 | CY : 0 | AC : 0 | OV : 0 | P : 0\n"
136 "Special Function Registers:\n"
137 <- "P0=0xff P0_0=1 P0_1=1 P0_2=1 P0_3=1\n"
141 <- "Step program until it reaches a different source line.\n"
144 <- "Step one instruction exactly.\n"
147 4. show and set variables:
148 output [/<fmt>] <expr1> print value of <expr1> without newline for tooltip of ddd
149 print [/<fmt>] <expr1> print value of <expr1> with newline
150 display [/<fmt>] <expr1> print value of <expr1> every time the program is stopped
151 or 'display' command without args is used.
153 set variable <expr1> = <value>
156 <fmt> is the format for the basic type which is print out.
157 If no format is set the default format is used.
158 format is set by ddd 'x' as hex 'o' as octal, 'd' as dezimal and 't' as binary.
160 <expr1> can by a variable , a array element , a structure element ( [] and . is parsed ).
161 indices of arrays may be constants or variables.
162 ( dereference of pointers and casting today not implemented !! )
167 typedef unsigned char uchar;
169 typedef struct _txstate
175 xdata txstate_t txstates[8];
184 <- "2: /x l = 0x00000005\n"
190 <- "3: /o l = 00000000005\n"
191 "2: /x l = 0x00000005\n"
198 "3: /o l = 00000000005\n"
199 "2: /x l = 0x00000005\n"
205 <- "5: /t l = 00000000000000000000000000000101\n"
207 "3: /o l = 00000000005\n"
208 "2: /x l = 0x00000005\n"
213 -> "print txstates\n"
214 <- "$2 = { { dstatus = {\'\\1\',\'\\0\',\'\\0\',\'\\0\'},
215 avalue = {\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\'}},
216 { dstatus = {\'\\0\',\'\\2\',\'\\0\',\'\\0\'},
217 avalue = {\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\'}},
218 { dstatus = {\'\\0\',\'\\0\',\'\\375\',\'\\0\'},
219 avalue = {\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\'}},
220 { dstatus = {\'\\0\',\'\\0\',\'\\0\',\'\\0\'},
221 avalue = {\'\\0\',\'\\0\',\'\\0\',\'\\4\',\'\\0\',\'\\0\',\'\\0\',\
222 '\\0\'}}, { dstatus = {\'\\0\',\'\\0\',\'\\0\',\'\\0\'},
223 avalue = {\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\'}},
224 { dstatus = {\'\\0\',\'\\0\',\'\\0\',\'\\0\'},
225 avalue = {\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\'}},
226 { dstatus = {\'\\0\',\'\\0\',\'\\0\',\'\\0\'},
227 avalue = {\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\'}},
228 { dstatus = {\'\\0\',\'\\0\',\'\\0\',\'\\0\'},
229 avalue = {\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\0\',\'\\
232 -> "print txstates[1].dstatus[1]\n"
235 -> "print /x txstates[1].dstatus[1]\n"
237 -> "output txstates[1].dstatus[1]\n"
239 -> "set variable txstates[1].dstatus[1] = 0x10\n"
241 -> "print /t txstates[1].dstatus[1]\n"
243 -> "print /x txstates[1].dstatus[1]\n"
248 -> "set variable l = 2\n"
252 -> "print /x txstates[l].dstatus[2]\n"
256 ---------------------------------------------------
258 Implementation Notes:
260 IMEM and XMEM are cached to optimize the printaut of structures and arrays
265 ========================
266 Martin Helmling added support for ddd GUI debugger.
267 Code added to display assembly, set variables, and other commands
272 in the attachment is my actual patch.
274 The 'up' and 'down' stack commands are not implemented.
275 But the features for 'ddd' to see bopth the c source and the assembler
277 also the display of variables.
278 Set variables are only implemented for basic types.
279 Register variables can also displayed, but here I think a problem in the
281 Sometimes the register name not exists:
283 S:LcacheTxAnalogValue$offset$1$1({1}SC:U),E,0,0
284 S:LcacheTxAnalogValue$i$1$1({1}SC:S),R,0,0,[]
285 S:LcacheTxAnalogValue$val$1$1({4}ST__00020000:S),E,0,0
286 S:LcacheTxAnalogValue$value$1$1({1}SC:U),R,0,0,[]
287 S:LcacheTxAnalogValue$sloc0$1$0({4}SL:U),E,0,0
288 S:LsetRelays$addr$1$1({1}SC:U),R,0,0,[r2]
289 S:LsetRelays$state$1$1({1}SC:U),R,0,0,[r3]
290 S:LsetRelays$value$1$1({1}SC:U),R,0,0,[r5]
291 S:L_main$i$1$1({1}SC:U),R,0,0,[]
292 S:L_main$j$1$1({1}SC:U),R,0,0,[r3]
293 S:L_main$ok$1$1({1}SC:U),R,0,0,[r3]
295 the empty [] I mean !!
297 Is this a known bug in sdcc ?
299 Also sometimes not the correct breakpoints for stepping found in sdcdb.
300 I try to fix this tomorrow.
302 Additional patches and notes from Martin(4-24-03):
303 in the attachment you found three patches:
304 debugpatch: Only for debugging, you can switch on and off the 4 different
305 debug and you can grep the debug by the prefix.
306 signalpatch:Now the simulator stops if the user sends an interrupt
307 ( or 'ddd' ) and also the simulator does not die by another
310 sympatch: This is not a feature, THIS is the fix of a BUG !!!
311 In some circumstances in the *.cdb file the Symbol record
312 comes before the function record. So the symbol was
313 generated TWO TIMES in the symbol list. The L:G and L:XG
315 records then insert entry and exit address to the wrong
316 symbol. So before a new symbol is generated for the
317 function, a lookup in the symboltable is done.
321 S:G$ZpuInitialize$0$0({2}DF,SV:S),C,0,0
322 S:G$ZpuInitialize$0$0({2}DF,SV:S),C,0,0
323 F:G$ZpuInitialize$0$0({2}DF,SV:S),Z,0,0,0,0,0
324 S:LZpuInitialize$i$1$1({2}SI:S),R,0,0,[]
325 L:G$ZpuInitialize$0$0:ADF
326 L:XG$ZpuInitialize$0$0:BBB
329 Notes Feb 10, 2002 - Karl Bongers
330 ========================
332 SDCDB is a debugger for SDCC compiler. It works as a front
333 end to the ucSim simulator/disassembler program.
335 WARNING: SDCDB is EXPERIMENTAL and NOT A FULLY FUNCTIONING TOOL.
337 SDCDB does hold out promise for a nice debugger tool that
338 could integrate well with ucSim and other SDCC tools. It has
339 some nice functionality that could augment ucSim nicely.
340 It reads in a lot of symbolic information from the .CDB
341 debug files as well as the source code and assembly
342 listings referred to in these CDB files.
343 This can be used to display your program data, list
344 c or asm source code and set breakpoints.
346 Unfortunately, SDCDB is not quite finished and does not
347 function well enough yet to recommend for general use.
351 ======================
352 Compile with --debug option:
354 This should generate .cdb symbolic debug files.
356 Load sdcdb, like this:
359 Then you need to do an initial "run" command. It should hopefully
360 stop somewhere at the main() entrypoint.
362 Now you should be able to list code, and set breakpoints. Type
363 "c" to continue running to a breakpoint, or type "s" to single
364 step or "n" to skip function calls. Tpye "help" for a summary
367 Use a preceeding bang("!") to do s51 simulator commands. So for
370 will send the "pc" command to ucSim and
371 give you the program counter and list the current line of assembly.
373 will give you the brief command line help listing of ucSim. But
374 this help will scroll of the screen. So to get a list, I redirect
375 stdout to a text file to examine like this:
376 sdcdb hi.ihx 2>&1 | tee sdcdb.log
378 Type '.' to toggle to a full time ucSim prompt.
382 ======================
384 Ok, so what are some of its problems? Lets try to itemize
385 them so we can fix them:
387 * It hangs sometimes when trying to do step or next.
389 This probably has something to do with the context
390 sdcdb tries to build dynamically. Sdcdb tries to
391 trace program operation by placing hidden breakpoints
392 and stepping threw the simulation between these.
394 * Does not print variables properly. Seems to use the
395 wrong address for the variable. (fixed)
397 * ASM listing not implemented.
398 This should be easy enough to add. This feature
399 really needs to be implemented before this is a useful
400 tool. That or addresses of code functions need to be
401 readily available for raw ucSim commands.
403 * No way to browse symbols, files names.
404 Preferably, it is easy to learn the addresses of variables
406 (working on this... see new ls,lm,lf commands)
408 * Does not allow listing, setting breakpoints or viewing variables
409 before starting the simulation.
410 (I am fixing now, partly fixed)
412 * p codestr - print on code char * broken, could be CDB info invalid.
416 ======================
418 Added a -z option. Any options after -z on sdcdb invocation line
419 are passed directly to ucSim.
421 Fixed print basic variable command(was not parsing or expecting
422 "0x" in data coming from ucSim). Dump bit command changed from
425 Add support for the following alternative ucSim binaries:
426 -mz80 - use "uz80" simulator.
427 -mavr - use "uavr" simulator.
428 -mxa - use "uxa" simulator.
430 Note that Z80(and probably avr/xa) does not produce enough
431 CDB debugging information to
432 make SDCDB useful. Hopefully CDB support will be
433 added to these other linkers and code generators.
435 Added lf,lm,ls commands(list functions, list modules, list symbols).
436 This allows browsing some the CDB information SDCDB pulls in
437 to do the wonderful things it does.
439 Added '.' prefix/command, used alone switches back and forth
440 from ucSim/SDCDB command mode). Also when at the (ucsim) prompt,
441 if a command is prefixed with '.' it will route the command to
442 the SDCDB command processor. (This could obsolete the '!' prefix).
445 ======================
447 Fix any remaining shortcomings above and make sdcdb integrate better with
450 Concerning the hanging on next/step instructions: This is critical
451 to fix. I beleive the problem is related to SDCDB's attempt to
452 dynamically track context. To do this, it sets many temporary break
453 points and uses these to progress step by step through the source code.
454 It does not seem reliable. It might be an idea to offer a simplified
455 mode of stepping and breakpoints. Need to study this more.
457 Make SDCDB integrate better with ucSim.
458 I think if sdcdb can act more transparently in regard to ucSim
459 it would be used more. So stress adding value and enhancing
460 ucSim operation, and not block or hide the functionality of ucSim.
462 * combine print "p" & "pt" together. We have room on the screen,
463 might as well print its type, address and value in one command.
465 * "fr" command prints the current position in the C code.
466 Should also print the raw code address for dumping ucSim code.
471 ======================
472 To debug, it might be helpful to turn on verbose debug dumps
473 by uncommenting #define SDCDB_DEBUG in sdcdb.h.
476 sdcdb.c - main shell of the program.
477 cmd.c - process user commands typed in.
478 simi.c - handle talking to the simulator via a socket connection.
479 symtab.c - Misc. functions to translate and process linked list
480 structures(modules, functions, symbols, etc) and CDB file
482 break.c - track and implement break points.
484 Understanding the structures and access mechanisms of SDCDB
485 is a bit of work. The structures include generic linked list
486 and function access. These lists are accessed in part by the
487 functions from ../../src/SDCCset.c and SDCChash.c. See the
488 cmd.c:infoSymbols() routine to gain some insight into these
489 main program structures. Or type "info symbols" to dump
490 out some of these. The new ls,lm,lf commands are also based
491 on showing information about these lists of structures.
493 Generic functions are used to act on these linked lists of
494 structures. For example, in cmd.c, DEFSETFUNC(funcWithName)
495 function will find a function structure with a given name.
496 So the linked list of function structures(with the head
497 "functions") is traversed and when one is found with a matching
498 name, a pointer to the function structure is returned.
500 The src/SDCCset.c,SDCCset.h contain much of the core helper
501 routines to allowed to implement these linked list access
504 The dynamic context tracking is difficult to understand.
505 It has some concept of stack use, as in
506 cmd.c:printSymValue(), where it can print variables relative
507 to the stack pointer.