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