/* call stack can be 1024 deep */
STACK_DCL(callStack,function *,1024);
+#ifdef SDCDB_DEBUG
+char *debug_bp_type_strings[] =
+ {"ERR-0",
+ "DATA",
+ "CODE" ,
+ "A_CODE" ,
+ "USER" ,
+ "STEP" ,
+ "NEXT" ,
+ "FENTRY" ,
+ "FEXIT", "", ""};
+#endif
+
/*-----------------------------------------------------------------*/
/* setBreakPoint - creates an entry in the break point table */
/*-----------------------------------------------------------------*/
static long bpnum = 0;
char simbuf[50];
+ Dprintf(D_break, ("setBreakPoint: addr:%x atype:%s bpType:%s [%s:%d]\n",
+ addr,
+ debug_bp_type_strings[addrType],
+ debug_bp_type_strings[bpType],
+ fileName, lineno));
+
/* allocate & init a new bp */
bp = Safe_calloc(1,sizeof(breakp));
bp->addr = addr;
breakp *bp;
int k;
+ Dprintf(D_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"));
+
/* for break points delete if they are NEXT */
for ( bp = hTabFirstItem(bptable,&k); bp ;
bp = hTabNextItem(bptable,&k)) {
int k;
char simcmd[50];
+ Dprintf(D_break, ("deleteUSERbp %d\n", bpnum));
+
/* for break points delete if they are STEP */
for ( bp = hTabFirstItem(bptable,&k); bp ;
bp = hTabNextItem(bptable,&k)) {
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));
}
fprintf(stdout,"Deleted breakpoint %d\n",
breakp *bp;
int rv =0;
+ Dprintf(D_break, ("dispatchCB: addr:0x%x \n", addr));
+
/* if no break points set for this address
then use a simulator stop break point */
if ((bp = hTabFirstItemWK(bptable,addr)) == NULL) {
}
+ if (rv == 0) {
+ Dprintf(D_break, ("dispatchCB: WARNING rv==0\n", rv));
+ }
+
return rv;
}
/*-----------------------------------------------------------------*/
BP_CALLBACK(fentryCB)
{
+ Dprintf(D_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"));
+
/* pop the top most from the call stack */
STACK_POP(callStack);
return 0;
/*-----------------------------------------------------------------*/
BP_CALLBACK(userBpCB)
{
+ Dprintf(D_break, ("userBpCB: BP_CALLBACK entry\n"));
+
if (srcMode == SRC_CMODE) {
fprintf(stdout,"Breakpoint %d, %s() at %s:%d\n",
bpnum,
{
static function *lfunc = NULL;
+ Dprintf(D_break, ("stepBpCB: BP_CALLBACK entry\n"));
+
if (srcMode == SRC_CMODE) {
if ((lfunc && lfunc != ctxt->func) || !lfunc)
fprintf(stdout,"%s () at %s:%d\n",
{
static function *lfunc = NULL;
+ Dprintf(D_break, ("nextBpCB: BP_CALLBACK entry\n"));
+
if (srcMode == SRC_CMODE) {
if ((lfunc && lfunc != ctxt->func) || !lfunc)
fprintf(stdout,"%s () at %s:%d\n",
FENTRY ,
FEXIT};
-
typedef struct breakp
{
unsigned addr; /* address of break point */
int line = 0;
/* find the function we are in */
- if (!applyToSet(functions,funcInAddr,addr,&func))
- return NULL;
+ if (!applyToSet(functions,funcInAddr,addr,&func)) {
+ fprintf(stderr, "Error?:discoverContext: cannot apply to set!\n");
+ return NULL;
+ }
currCtxt->func = func;
currCtxt->addr = func->laddr = addr;
if not then we continue with the execution
of the program */
if (!rv) {
+ fprintf(stdout, "Stopping at non-user breakpoint\n");
+
+// notes: kpb
+// I took this out, after running "run" it would just keep re-running
+// even after a lot of break points hit. For some reason above code
+// not triggering(dispatchCB). This seems to be by design, startup adds
+// a bunch of breakpoints-but they are not USER breakpoints. Perhaps the
+// debugger changed with its implementation of "go"("run"). It seems we
+// need to add a "next" or "step" followed by a "run"...
+// I added a "step" in simi.c when we want a resume function, this seems
+// to work.
+
+// still there is question of how do we stop it initially, since
+// it must be started before it can get a context. If so, we would
+// want it to just run up to an initial entry point you'd think...
+// I don't see why we can't set breakpoints before an initial run,
+// this does not seem right to me.
+
+// line #'s are a bit off too.
+
+#if 0
gaddr = -1;
goto top ;
+#endif
}
}
/*-----------------------------------------------------------------*/
int cmdSimulator (char *s, context *cctxt)
{
- sendSim(s);
- sendSim("\n");
+ char tmpstr[82];
+
+ if (strlen(s) > 80) {
+ printf("error 3A\n");
+ exit(1);
+ }
+ strcpy(tmpstr, s);
+ strcat(tmpstr, "\n");
+ sendSim(tmpstr);
waitForSim();
fprintf(stdout,"%s",simResponse());
return 0;
sym = func->sym;
-#ifdef SDCDB_DEBUG
- printf("func '%s' has entry '%x' exit '%x'\n",
+ Dprintf(D_sdcdb, ("func '%s' has entry '%x' exit '%x'\n",
func->sym->name,
func->sym->addr,
- func->sym->eaddr);
-#endif
+ func->sym->eaddr));
+
if (!func->sym->addr && !func->sym->eaddr)
continue ;
}
#ifdef SDCDB_DEBUG
- printf("function '%s' has the following C exePoints\n",
- func->sym->name);
+ Dprintf(D_sdcdb, ("function '%s' has the following C exePoints\n",
+ func->sym->name));
{
exePoint *ep;
for (ep = setFirstItem(func->cfpoints); ep;
ep = setNextItem(func->cfpoints))
- fprintf (stdout,"{%x,%d} %s",ep->addr,ep->line,mod->cLines[ep->line]->src);
+ Dprintf(D_sdcdb, ("{%x,%d} %s",
+ ep->addr,ep->line,mod->cLines[ep->line]->src));
- fprintf(stdout," and the following ASM exePoints\n");
+ Dprintf(D_sdcdb, (" and the following ASM exePoints\n"));
for (ep = setFirstItem(func->afpoints); ep;
- ep = setNextItem(func->afpoints))
- fprintf (stdout,"{%x,%d} %s",ep->addr,ep->line,mod->asmLines[ep->line]->src);
-
+ ep = setNextItem(func->afpoints))
+ Dprintf (D_sdcdb, ("{%x,%d} %s",
+ ep->addr,ep->line,mod->asmLines[ep->line]->src));
}
#endif
}
/* #define SDCDB_DEBUG */
+#ifdef SDCDB_DEBUG
+// set D_x to 0 to turn off, 1 to turn on.
+#define D_break 1
+#define D_simi 1
+#define D_sdcdb 1
+#define D_symtab 1
+
+#define Dprintf(f, fs) {if (f) printf fs ; }
+#else
+#define Dprintf(f, fs) { }
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
if (resetp)
sbp = simibuff;
-#ifdef SDCDB_DEBUG
- fprintf(stderr,"stderr--> reading from sim\n");
-#endif
+ Dprintf(D_simi, ("readSim: reading from sim["));
while ((ch = fgetc(simin))) {
+
#ifdef SDCDB_DEBUG
- fputc(ch,stdout);
+ if (D_simi) {
+ fputc(ch,stdout);
+ }
#endif
+
*sbp++ = ch;
}
-#ifdef SDCDB_DEBUG
- fprintf(stderr,"stderr--> reading from sim done\n");
-#endif
+
+ Dprintf(D_simi, ("] end readSim\n"));
*sbp = '\0';
}
/* fork and start the simulator as a subprocess */
if ((simPid = fork())) {
-#ifdef SDCDB_DEBUG
- printf("simulator pid %d\n",(int) simPid);
-#endif
+ Dprintf(D_simi, ("simulator pid %d\n",(int) simPid));
}
else {
/*-----------------------------------------------------------------*/
void sendSim(char *s)
{
+ Dprintf(D_simi, ("sendSim-->%s", s)); // s has LF at end already
fputs(s,simout);
fflush(simout);
}
{
char buff[128];
- sprintf(buff,"l %s\n",s);
+ sprintf(buff,"l \"%s\"\n",s);
printf(buff);
sendSim(buff);
waitForSim();
unsigned addr ;
char *sfmt;
+ /* kpb: new code 8-03-01 */
+ if (gaddr == 0) {
+ /* initial start, start & stop from address 0 */
+ char buf[20];
+ // this program is setting up a bunch of breakpoints automatically
+ // at key places. Like at startup & main() and other function
+ // entry points. So we don't need to setup one here..
+ //sendSim("break 0x0\n");
+ //sleep(1);
+ //waitForSim();
+
+ sendSim("run 0x0\n");
+ sleep(1); /* do I need this? */
+ } else if (gaddr == -1) { /* resume */
+
+ // try adding this(kpb)
+ sendSim("step\n");
+ usleep(100000);
+ waitForSim();
+
+ sendSim ("run\n");
+ }
+ else {
+ printf("Error, simGoTillBp > 0!\n");
+ exit(1);
+ }
+
+#if 0
if (gaddr != -1) {
char buf[20];
sprintf(buf,"g 0x%x\n",gaddr);
sendSim(buf);
} else
sendSim ("g\n");
+#endif
waitForSim();
sr++;
}
- if (!*sr) return 0;
+ if (!*sr) {
+ fprintf(stderr, "Error?, simGoTillBp failed to Stop\n");
+ return 0;
+ }
while (isspace(*sr)) sr++ ;
- if (sscanf(sr,sfmt,&addr) != 1)
- return 0;
- else
+ if (sscanf(sr,sfmt,&addr) != 1) {
+ fprintf(stderr, "Error?, simGoTillBp failed to get Addr\n");
+ return 0;
+ }
return addr;
-
}
char *rb = regBuff;
int i;
- sendSim("dr\n");
+ sendSim("info registers\n");
+ //kpb(8-5-01) sendSim("dr\n");
+
waitForSim();
/* make it some more readable */
resp = simResponse();
/* the response is of the form
XXXXXX R0 R1 R2 R3 R4 R5 R6 R7 ........
XXXXXX XX . ACC=0xxx dd cc B=0xxx dd cc DPTR= 0xxxxx @DPTR= 0xxx dd cc
- XXXXXX XX . PSW= 0xxx CY=[1|0] AC=[0|1] OV=[0|1] P=[1|0] */
+ XXXXXX XX . PSW= 0xxx CY=[1|0] AC=[0|1] OV=[0|1] P=[1|0]
+
+Format as of 8-4-01:
+ 0x00 00 00 00 00 00 00 00 00 ........
+ 000000 00 . ACC= 0x00 0 . B= 0x00 DPTR= 0x0000 @DPTR= 0x00 0 .
+ 000000 00 . PSW= 0x00 CY=0 AC=0 OV=0 P=0
+F 0x006d 75 87 80 MOV PCON,#80
+*/
+
memset(regBuff,0,sizeof(regBuff));
/* skip the first numerics */
while (*resp && !isxdigit(*resp)) resp++;
+
+ if (strncmp(resp, "0x", 2)) {
+ fprintf(stderr, "Error: Format1A\n");
+ return regBuff;
+ }
+ resp += 2;
while (*resp && isxdigit(*resp)) resp++;
/* now get the eight registers */
s++;
sscanf(s,"%x",&func->sym->eaddr);
-#ifdef SDCDB_DEBUG
- printf("%s(eaddr%x)\n",func->sym->name,func->sym->eaddr);
-#endif
+
+ Dprintf(D_symtab, ("%s(eaddr%x)\n",func->sym->name,func->sym->eaddr));
}
/*-----------------------------------------------------------------*/
s++;
sscanf(s,"%x",&sym->addr);
-#ifdef SDCDB_DEBUG
- printf("%s(%x)\n",sym->name,sym->addr);
-#endif
+
+ Dprintf(D_symtab, ("%s(%x)\n",sym->name,sym->addr));
}
/*-----------------------------------------------------------------*/
line--;
if (line < mod->nasmLines) {
mod->asmLines[line]->addr = addr;
-#ifdef SDCDB_DEBUG
- printf("%s(%d:%x) %s",mod->asm_name,line,addr,mod->asmLines[line]->src);
-#endif
+ Dprintf(D_symtab, ("%s(%d:%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;
-#ifdef SDCDB_DEBUG
- printf("%s(%d:%x) %s",mod->c_name,
- line+1,addr,mod->cLines[line]->src);
-#endif
+ Dprintf(D_symtab, ("%s(%d:%x) %s",mod->c_name,
+ line+1,addr,mod->cLines[line]->src));
}
return;