sdcc/debugger
-SDCDB debugger
+SDCDB debugger - Development notes.
======================
-Notes April 23, 2003
+
+Notes April 23, 2003
+========================
Martin Helmling added support for ddd GUI debugger.
Code added to display assembly, set variables, and other commands
to interface to ddd.
Also sometimes not the correct breakpoints for stepping found in sdcdb.
I try to fix this tomorrow.
+Additional patches and notes from Martin(4-24-03):
+in the attachment you found three patches:
+debugpatch: Only for debugging, you can switch on and off the 4 different
+ debug and you can grep the debug by the prefix.
+signalpatch:Now the simulator stops if the user sends an interrupt
+ ( or 'ddd' ) and also the simulator does not die by another
+ user signal.
+
+sympatch: This is not a feature, THIS is the fix of a BUG !!!
+ In some circumstances in the *.cdb file the Symbol record
+ comes before the function record. So the symbol was
+ generated TWO TIMES in the symbol list. The L:G and L:XG
+
+ records then insert entry and exit address to the wrong
+ symbol. So before a new symbol is generated for the
+ function, a lookup in the symboltable is done.
+
+Example of a *.cdb:
+
+S:G$ZpuInitialize$0$0({2}DF,SV:S),C,0,0
+S:G$ZpuInitialize$0$0({2}DF,SV:S),C,0,0
+F:G$ZpuInitialize$0$0({2}DF,SV:S),Z,0,0,0,0,0
+S:LZpuInitialize$i$1$1({2}SI:S),R,0,0,[]
+L:G$ZpuInitialize$0$0:ADF
+L:XG$ZpuInitialize$0$0:BBB
Notes Feb 10, 2002 - Karl Bongers
+========================
SDCDB is a debugger for SDCC compiler. It works as a front
end to the ucSim simulator/disassembler program.
breakp *bp;
int k;
- Dprintf(D_break, ("Deleting all STEP BPs\n"));
+ Dprintf(D_break, ("break: Deleting all STEP BPs\n"));
/* for break points delete if they are STEP */
for ( bp = hTabFirstItem(bptable,&k); bp ;
bp = hTabNextItem(bptable,&k)) {
int k;
char simcmd[50];
- Dprintf(D_break, ("Deleting all NEXT BPs\n"));
+ Dprintf(D_break, ("break: Deleting all NEXT BPs\n"));
/* for break points delete if they are NEXT */
for ( bp = hTabFirstItem(bptable,&k); bp ;
int k;
char simcmd[50];
- Dprintf(D_break, ("deleteUSERbp %d\n", bpnum));
+ Dprintf(D_break, ("break: deleteUSERbp %d\n", bpnum));
/* for break points delete if they are STEP */
for ( bp = hTabFirstItem(bptable,&k); bp ;
send command to simulator to delete bp from this addr */
if (hTabSearch(bptable,bp->addr) == NULL) {
simClearBP (bp->addr);
- Dprintf(D_break, ("deleteUSERbp:simClearBP 0x%x\n", bp->addr));
+ Dprintf(D_break, ("break: deleteUSERbp:simClearBP 0x%x\n", bp->addr));
}
fprintf(stdout,"Deleted breakpoint %d\n",
breakp *bp;
int rv =0;
- Dprintf(D_break, ("dispatchCB: addr:0x%x \n", addr));
+ Dprintf(D_break, ("break: dispatchCB: addr:0x%x \n", addr));
/* if no break points set for this address
then use a simulator stop break point */
}
if (rv == 0) {
- Dprintf(D_break, ("dispatchCB: WARNING rv==0\n", rv));
+ Dprintf(D_break, ("break: dispatchCB: WARNING rv==0\n", rv));
}
return rv;
/*-----------------------------------------------------------------*/
BP_CALLBACK(fentryCB)
{
- Dprintf(D_break, ("fentryCB: BP_CALLBACK entry\n"));
+ Dprintf(D_break, ("break: fentryCB: BP_CALLBACK entry\n"));
/* add the current function into the call stack */
STACK_PUSH(callStack,ctxt->func);
/*-----------------------------------------------------------------*/
BP_CALLBACK(fexitCB)
{
- Dprintf(D_break, ("fexitCB: BP_CALLBACK entry\n"));
+ Dprintf(D_break, ("break: fexitCB: BP_CALLBACK entry\n"));
/* pop the top most from the call stack */
STACK_POP(callStack);
/*-----------------------------------------------------------------*/
BP_CALLBACK(userBpCB)
{
- Dprintf(D_break, ("userBpCB: BP_CALLBACK entry\n"));
+ Dprintf(D_break, ("break: userBpCB: BP_CALLBACK entry\n"));
if (srcMode == SRC_CMODE) {
fprintf(stdout,"Breakpoint %d, %s() at %s:%d\n",
{
static function *lfunc = NULL;
- Dprintf(D_break, ("stepBpCB: BP_CALLBACK entry\n"));
+ Dprintf(D_break, ("break: stepBpCB: BP_CALLBACK entry\n"));
if (srcMode == SRC_CMODE) {
if ((lfunc && lfunc != ctxt->func) || !lfunc)
{
static function *lfunc = NULL;
- Dprintf(D_break, ("nextBpCB: BP_CALLBACK entry\n"));
+ Dprintf(D_break, ("break: nextBpCB: BP_CALLBACK entry\n"));
if (srcMode == SRC_CMODE) {
if ((lfunc && lfunc != ctxt->func) || !lfunc)
#include "cmd.h"
#include "newalloc.h"
+#ifdef SDCDB_DEBUG
+int sdcdbDebug = 0;
+#endif
+
char *currModName = NULL;
cdbrecs *recsRoot = NULL ;
set *modules = NULL; /* set of all modules */
sym = func->sym;
- Dprintf(D_sdcdb, ("func '%s' has entry '%x' exit '%x'\n",
+ Dprintf(D_sdcdb, ("sdcdb: func '%s' has entry '0x%x' exit '0x%x'\n",
func->sym->name,
func->sym->addr,
func->sym->eaddr));
}
#ifdef SDCDB_DEBUG
- Dprintf(D_sdcdb, ("function '%s' has the following C exePoints\n",
+ if (!( D_sdcdb & sdcdbDebug))
+ return;
+
+ Dprintf(D_sdcdb, ("sdcdb: function '%s' has the following C exePoints\n",
func->sym->name));
{
exePoint *ep;
for (ep = setFirstItem(func->cfpoints); ep;
ep = setNextItem(func->cfpoints))
- Dprintf(D_sdcdb, ("{%x,%d} %s",
+ Dprintf(D_sdcdb, ("sdcdb: {0x%x,%d} %s",
ep->addr,ep->line,mod->cLines[ep->line]->src));
- Dprintf(D_sdcdb, (" and the following ASM exePoints\n"));
+ Dprintf(D_sdcdb, ("sdcdb: and the following ASM exePoints\n"));
for (ep = setFirstItem(func->afpoints); ep;
ep = setNextItem(func->afpoints))
- Dprintf (D_sdcdb, ("{%x,%d} %s",
+ Dprintf (D_sdcdb, ("sdcdb: {0x%x,%d} %s",
ep->addr,ep->line,mod->asmLines[ep->line]->src));
}
#endif
char *filename = NULL;
int passon_args_flag = 0; /* if true, pass on args to simulator */
- Dprintf(D_sdcdb, ("parseCmdLine\n"));
+ Dprintf(D_sdcdb, ("sdcdb: parseCmdLine\n"));
for ( i = 1; i < argc ; i++) {
//fprintf(stdout,"%s\n",argv[i]);
continue;
}
+#ifdef SDCDB_DEBUG
+ if (strncmp(argv[i],"-d=",3) == 0) {
+ sdcdbDebug = strtol(&argv[i][3],0,0);
+ continue;
+ }
+#endif
+
/* model string */
if (strncmp(argv[i],"-m",2) == 0) {
strncpy(model_str, &argv[i][2], 15);
static void
sigintr(int sig)
{
- /* may be interrupt from user: stop debugger ( also simulator ??) */
+ /* may be interrupt from user: stop debugger and also simulator */
userinterrupt = 1;
+ sendSim("\n");
}
/* the only child can be the simulator */
signal(SIGTERM, bad_signal);
signal(SIGCHLD, sigchld );
- signal(SIGPIPE, SIG_IGN);
signal(SIGABRT, bad_signal);
signal(SIGALRM, bad_signal);
signal(SIGFPE, bad_signal);
int main ( int argc, char **argv)
{
printVersionInfo();
- printf("WARNING: SDCDB is EXPERIMENTAL and NOT A FULLY FUNCTIONING TOOL.\n");
+ printf("WARNING: SDCDB is EXPERIMENTAL.\n");
simArgs[nsimArgs++] = "s51";
simArgs[nsimArgs++] = "-P";
#ifndef SDCDB_H
#define SDCDB_H
-// #define SDCDB_DEBUG
+#define SDCDB_DEBUG
#ifdef SDCDB_DEBUG
// set D_x to 0 to turn off, 1 to turn on.
-#define D_break 0
-#define D_simi 1
-#define D_sdcdb 1
-#define D_symtab 0
+#define D_break 0x01
+#define D_simi 0x02
+#define D_sdcdb 0x04
+#define D_symtab 0x08
-#define Dprintf(f, fs) {if (f) printf fs ; }
+extern int sdcdbDebug;
+
+#define Dprintf(f, fs) {if (f & sdcdbDebug) printf fs ; }
#else
#define Dprintf(f, fs) { }
#endif
extern char **environ;
char simactive = 0;
-
-#if 0
-#define MS_SLEEP(_ms) usleep(_ms * 1000)
-#endif
-
/*-----------------------------------------------------------------*/
/* waitForSim - wait till simulator is done its job */
/*-----------------------------------------------------------------*/
int i=0;
int ch;
-Dprintf(D_simi, ("waitForSim start(%d)\n", timeout_ms));
+Dprintf(D_simi, ("simi: waitForSim start(%d)\n", timeout_ms));
sbp = simibuff;
- // MS_SLEEP(timeout_ms); dont need, in blocking mode.
-
while ((ch = fgetc(simin)) > 0 ) {
*sbp++ = ch;
}
*sbp = 0;
Dprintf(D_simi, ("waitForSim(%d) got[%s]\n", timeout_ms, simibuff));
-#if 0
- hmmmm, I guess we are not running non-blocking, we may still
- need this code...Im not sure how the above works, it must block
- until something gets into the buffer, then fgetc() reads down the
- buffer...
- do {
- while ((ch = fgetc(simin))) {
- *sbp++ = ch;
- }
- *sbp = 0;
-printf("got1[%s]\n", simibuff);
- MS_SLEEP(20);
- timeout_ms -= 20;
-printf("..\n");
-
- if (expect) {
- if (strstr(expect, sbp)) {
- timeout_ms = 0;
- }
- } else if (sbp != simibuff) {
- timeout_ms = 0;
- }
-
- /* pull in data one more time after delay to try and
- guarentee we pull in complete responce line */
- if (timeout_ms <= 0) {
-printf(",,\n");
- while ((ch = fgetc(simin))) {
- *sbp++ = ch;
- }
- *sbp = 0;
-printf("got2[%s]\n", simibuff);
- }
- }
- while (timeout_ms > 0);
-printf("...\n");
-#endif
-
}
/*-----------------------------------------------------------------*/
struct sockaddr_in sin;
int retry = 0;
int i ;
- Dprintf(D_simi, ("openSimulator\n"));
+ Dprintf(D_simi, ("simi: openSimulator\n"));
/* fork and start the simulator as a subprocess */
if ((simPid = fork())) {
- Dprintf(D_simi, ("simulator pid %d\n",(int) simPid));
+ Dprintf(D_simi, ("simi: simulator pid %d\n",(int) simPid));
}
else {
/* we are in the child process : start the simulator */
+ signal(SIGHUP , SIG_IGN );
+ signal(SIGINT , SIG_IGN );
+ signal(SIGABRT, SIG_IGN );
+ signal(SIGCHLD, SIG_IGN );
+
if (execvp(args[0],args) < 0) {
perror("cannot exec simulator");
exit(1);
if ( ! simout )
return;
- Dprintf(D_simi, ("sendSim-->%s", s)); // s has LF at end already
+ Dprintf(D_simi, ("simi: sendSim-->%s", s)); // s has LF at end already
fputs(s,simout);
fflush(simout);
}
#include "newalloc.h"
structdef *structWithName (char *);
+DEFSETFUNC(symWithRName);
/*------------------------------------------------------------------*/
/* getSize - returns size of a type chain in bits */
void parseFunc (char *line)
{
function *func ;
- char *rs;
+ char *rs = line ;
int i;
+
+ while (*rs && *rs != '(') rs++ ;
+ *--rs = '\0';
+
func = Safe_calloc(1,sizeof(function));
- func->sym = parseSymbol(line,&rs);
+ func->sym = NULL;
+ applyToSet(symbols,symWithRName,line,&func->sym);
+ *rs++ = '0';
+ if (! func->sym)
+ func->sym = parseSymbol(line,&rs);
func->sym->isfunc = 1;
func->modName = currModName ;
- while(*rs != ',') rs++;
+ while(*rs && *rs != ',') rs++;
rs++;
sscanf(rs,"%d,%d,%d",&i,
&(SPEC_INTN(func->sym->etype)),
s++;
sscanf(s,"%x",&func->sym->eaddr);
- Dprintf(D_symtab, ("%s(eaddr%x)\n",func->sym->name,func->sym->eaddr));
+ Dprintf(D_symtab, ("symtab: %s(eaddr 0x%x)\n",func->sym->name,func->sym->eaddr));
}
/*-----------------------------------------------------------------*/
s++;
sscanf(s,"%x",&sym->addr);
- Dprintf(D_symtab, ("%s(%x)\n",sym->name,sym->addr));
+ Dprintf(D_symtab, ("symtab: %s(0x%x)\n",sym->name,sym->addr));
}
/*-----------------------------------------------------------------*/
line--;
if (line < mod->nasmLines) {
mod->asmLines[line]->addr = addr;
- Dprintf(D_symtab, ("%s(%d:%x) %s",mod->asm_name,line,addr,mod->asmLines[line]->src));
+ Dprintf(D_symtab, ("symtab: %s(%d:0x%x) %s",mod->asm_name,line,addr,mod->asmLines[line]->src));
}
}
mod->cLines[line]->addr = addr;
mod->cLines[line]->block = block;
mod->cLines[line]->level = level;
- Dprintf(D_symtab, ("%s(%d:%x) %s",mod->c_name,
+ Dprintf(D_symtab, ("symtab: %s(%d:0x%x) %s",mod->c_name,
line+1,addr,mod->cLines[line]->src));
}
return;