static void printTypeInfo(link *);
static void printValAggregates (symbol *,link *,char,unsigned int,int);
-static void printOrSetSymValue (symbol *sym, context *cctxt,
- int flg, int dnum, int fmt, char *rs, char *val);
+static int printOrSetSymValue (symbol *sym, context *cctxt,
+ int flg, int dnum, int fmt,
+ char *rs, char *val, char cmp);
int srcMode = SRC_CMODE ;
static set *dispsymbols = NULL ; /* set of displayable symbols */
/*-----------------------------------------------------------------*/
static void setBPatModLine (module *mod, int line, char bpType )
{
- int next_line;
+ int next_line;
/* look for the first executable line after the line
- specified & get the break point there */
+ specified & get the break point there */
+
+ if ( line < 0 )
+ return;
+
if (srcMode == SRC_CMODE && line > mod->ncLines) {
- fprintf(stderr,"No line %d in file \"%s\".\n",
- line,mod->c_name);
- return ;
+ fprintf(stderr,"No line %d in file \"%s\".\n",
+ line,mod->c_name);
+ return ;
}
if (srcMode == SRC_AMODE && line > mod->nasmLines) {
- fprintf(stderr,"No line %d in file \"%s\".\n",
- line,mod->asm_name);
- return ;
+ fprintf(stderr,"No line %d in file \"%s\".\n",
+ line,mod->asm_name);
+ return ;
}
next_line = line;
for ( ; next_line < (srcMode == SRC_CMODE ? mod->ncLines : mod->nasmLines ) ;
next_line++ ) {
if (srcMode == SRC_CMODE) {
- if (mod->cLines[next_line]->addr) {
+ if (mod->cLines[next_line]->addr != INT_MAX) {
setBreakPoint (mod->cLines[next_line]->addr, CODE, bpType,
userBpCB, mod->c_name, next_line);
return;
}
}
else {
- if (mod->asmLines[next_line]->addr) {
+ if (mod->asmLines[next_line]->addr != INT_MAX) {
setBreakPoint (mod->asmLines[next_line]->addr, CODE, bpType,
userBpCB, mod->asm_name, next_line);
return;
/* find the function we are in */
if (!func && !applyToSet(functions,funcInAddr,addr,&func)) {
- if (!applyToSet(functions,funcWithName,"main",&func) ||
+ if (!applyToSet(functions,funcWithName,"_main",&func) ||
!applyToSet(modules,moduleLineWithAddr,addr,&mod,NULL))
{
- fprintf(stderr, "Error?:discoverContext: cannot apply addr 0x%x\n",addr);
+ fprintf(stderr, "addr 0x%x in no module/function (runtime env?)\n",addr);
return NULL;
}
currCtxt->func = func;
&line,&currCtxt->block,&currCtxt->level))
currCtxt->cline = func->lline = line;
else
- currCtxt->cline = func->exitline;
+ currCtxt->cline = -1;
}
/* find the asm line number */
line = 0;
if (applyToSet(func->afpoints,lineAtAddr,addr,
&line,NULL,NULL))
- currCtxt->asmline = line;
+ currCtxt->asmline = line;
else
- currCtxt->asmline = -1;
+ currCtxt->asmline = -1;
return currCtxt ;
}
unsigned int addr ;
context *ctxt;
int rv;
-
+ stopCommandList();
top:
if ( userinterrupt )
{
userinterrupt = 0;
return;
}
+ if ( gaddr == 0 )
+ {
+ function *func = NULL;;
+ if (applyToSet(functions,funcInAddr,gaddr,&func))
+ STACK_PUSH(callStack,func);
+ }
addr = simGoTillBp (gaddr);
/* got the pc for the break point now first
}
/*-----------------------------------------------------------------*/
-/* preparePrint - common parse function for */
+/* preparePrint - common parse function for set variable, */
/* output, print and display */
/*-----------------------------------------------------------------*/
static char *preparePrint(char *s, context *cctxt, int *fmt, symbol **sym)
s++;
while (isspace(*s)) s++;
}
- for ( bp = s; *bp && ( isalnum( *bp ) || *bp == '_'); bp++ );
+ for ( bp = s; *bp && ( isalnum( *bp ) || *bp == '_' || *bp == '$'); bp++ );
save_ch = *bp;
if ( *bp )
*bp = '\0';
- *sym = symLookup(s,cctxt);
+ if ( *s )
+ *sym = symLookup(s,cctxt);
*bp = save_ch;
if ( ! *sym )
}
fprintf(stderr,"No function contains specified address.\n");
+ if( saddr >= 0 )
+ {
+ char lbuf[64];
+ sprintf(lbuf,"dis 0x%lx 0 %ld\n",saddr,( eaddr == -1 )?1L:eaddr-saddr);
+ sendSim(lbuf);
+ waitForSim(1000, NULL);
+ fputs(simResponse(),stdout);
+ }
return 0;
}
/*-----------------------------------------------------------------*/
/* if current context is known */
if (cctxt->func) {
+ Dprintf(D_break, ("commonSetUserBp: a) cctxtaddr:%x \n",cctxt->addr));
if (srcMode == SRC_CMODE)
/* set the break point */
setBreakPoint ( cctxt->addr , CODE , bpType , userBpCB ,
}
else
{
+ Dprintf(D_break, ("commonSetUserBp: g) addr:%x \n",braddr));
setBreakPoint ( braddr , CODE , bpType , userBpCB ,
modul->c_name,line);
}
}
/* case b) lineno */
/* check if line number */
- if (isdigit(*s)) {
+ if ( !strchr(s,':') && isdigit(*s)) {
/* get the lineno */
int line = atoi(s) -1;
-
+ Dprintf(D_break, ("commonSetUserBp: b) line:%d \n",line));
+ if ( line < 0 )
+ {
+ fprintf(stdout,"linenumber <= 0\n");
+ goto ret;
+ }
/* if current context not present then we must get the module
which has main & set the break point @ line number provided
of that module : if current context known then set the bp
}
/* case c) filename:lineno */
- if (isdigit(*(bp +1))) {
-
+ if (isdigit(*(bp +1))) {
+ Dprintf(D_break, ("commonSetUserBp: c) line:%d \n",atoi(bp+1)));
setBPatModLine (mod,atoi(bp+1)-1,bpType);
goto ret;
if (!applyToSet(functions,funcWithNameModule,bp+1,s,&func))
fprintf(stderr,"Function \"%s\" not defined.\n",bp+1);
else
+ Dprintf(D_break, ("commonSetUserBp: d) \n"));
setBPatModLine (mod,
(srcMode == SRC_CMODE ?
func->entryline :
}
/* case e) function */
+ Dprintf(D_break, ("commonSetUserBp: e) \n"));
if (!applyToSet(functions,funcWithName,s,&func))
fprintf(stderr,"Function \"%s\" not defined.\n",s);
else
if ( cctxt && cctxt->func)
{
/* actual line */
- if (printAsmLine(cctxt->func,cctxt->func->mod,
+ if ( cctxt->addr != INT_MAX )
+ {
+ if (printAsmLine(cctxt->func,cctxt->func->mod,
(long)cctxt->addr,(long)cctxt->addr))
return 0;
+ }
}
return 0;
}
while (*s && *s != '=') s++;
*s++ = '\0';
while (isspace(*s)) *s++ = '\0';
- if (*s)
+ if (*s && sym)
{
- printOrSetSymValue(sym,cctxt,0,0,0,rs,s);
- return 0;
+ printOrSetSymValue(sym,cctxt,0,0,0,rs,s,'\0');
+ return 0;
}
else
fprintf(stdout,"No new value for \"%s\".\n",s);
return 0;
}
+/*-----------------------------------------------------------------*/
+/* cmdIgnore - set ignorecount for breakpoint */
+/*-----------------------------------------------------------------*/
+int cmdIgnore (char *s, context *cctxt)
+{
+ int bpnum, cnt ;
+ while (isspace(*s)) s++;
+ if (!*s )
+ {
+ fprintf(stdout,"Argument required (breakpoint number).\n");
+ return 0;
+ }
+ bpnum = strtol(s,&s,10);
+ while (isspace(*s)) s++;
+ if (!*s )
+ {
+ fprintf(stdout,"Second argument (specified ignore-count) is missing.");
+ return 0;
+ }
+ cnt = strtol(s,0,10);
+ setUserbpIgnCount(bpnum,cnt);
+ return 0;
+}
+
+/*-----------------------------------------------------------------*/
+/* cmdCondition - set condition for breakpoint */
+/*-----------------------------------------------------------------*/
+int cmdCondition (char *s, context *cctxt)
+{
+ int bpnum ;
+ while (isspace(*s)) s++;
+ if (!*s )
+ {
+ fprintf(stdout,"Argument required (breakpoint number).\n");
+ return 0;
+ }
+ bpnum = strtol(s,&s,10);
+ while (isspace(*s)) s++;
+ if (*s)
+ s = Safe_strdup(s);
+ else
+ s = NULL;
+ setUserbpCondition(bpnum,s);
+ return 0;
+}
+
/*-----------------------------------------------------------------*/
/* cmdCommands - set commands for breakpoint */
/*-----------------------------------------------------------------*/
int cmdStepi (char *s, context *cctxt)
{
- if (STACK_EMPTY(callStack))
+ if (0 /*STACK_EMPTY(callStack)*/)
fprintf(stdout,"The program is not being run.\n");
else
{
fprintf(stdout,"No executable file specified.\nUse the \"file\" command.\n");
return 0;
}
+ resetHitCount();
simGo(0);
} else {
fgets(buff,sizeof(buff),stdin);
if (toupper(buff[0]) == 'Y') {
simReset();
+ resetHitCount();
simGo(0);
}
}
/*-----------------------------------------------------------------*/
static void infoRegisters( int all, context *ctxt)
{
- static unsigned int regaddrs[] = {0x81,0x82,0x83,0xd0,0xe0,0xf0,0};
+ static unsigned int regaddrs[] = {0x81,0x82,0x83,0xb8,0xd0,0xe0,0xf0,0};
unsigned long val;
int i,j,*r;
i = simGetValue (0xd0,'I',1);
- fprintf(stdout,"PC : 0x%04X RegisterBank %d:\nR0-7:",ctxt->addr,(i>>3)&3);
+ fprintf(stdout,"IP : 0x%04X RegisterBank %d:\nR0-7:",ctxt->addr,(i>>3)&3);
for ( j = 0; j < 8 ; j++ )
{
val = simGetValue (j ,'R',1);
func ? func->sym->name : "?",
func ? lastaddr -func->sym->addr : 0);
llines = pline +1;
- while ( pline < list_mod->ncLines )
+ for ( ; pline < list_mod->ncLines; pline++ )
{
- pline++;
if ( list_mod->cLines[pline]->addr > lastaddr )
{
lastaddr = list_mod->cLines[pline]->addr -1;
return 0;
}
-static void setValBasic(symbol *sym, link *type,
- char mem, unsigned addr,int size, char *val)
+static unsigned long getValBasic(symbol *sym, link *type, char *val)
{
char *s;
union
}v;
if (IS_FLOAT(type))
- v.f = strtof(val,NULL);
+ v.f = strtod(val,NULL);
else
if (IS_PTR(type))
v.val = strtol(val,NULL,0);
else
v.val = strtol(val,NULL,0);
}
- simSetValue(addr,mem,size,v.val);
+ return v.val;
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/* printOrSetSymValue - print or set value of a symbol */
/*-----------------------------------------------------------------*/
-static void printOrSetSymValue (symbol *sym, context *cctxt,
- int flg, int dnum, int fmt, char *rs, char *val)
+static int printOrSetSymValue (symbol *sym, context *cctxt,
+ int flg, int dnum, int fmt, char *rs,
+ char *val, char cmp )
{
static char fmtChar[] = " todx ";
static int stack = 1;
if (!bp)
{
fprintf(stdout,"cannot determine stack frame\n");
- return ;
+ return 1;
}
sym->addr = simGetValue(bp->addr,bp->addrspace,bp->size)
*s2 = save_ch2;
if ( ! fields )
{
- fprintf(stdout,"Unkown variable \"%s\" for index.\n", s);
- return;
+ fprintf(stdout,"Unknown variable \"%s\" for index.\n", s);
+ return 1;
}
/* arrays & structures first */
if (! IS_INTEGRAL(fields->type))
{
fprintf(stdout,"Wrong type of variable \"%s\" for index \n", s);
- return;
+ return 1;
}
n = simGetValue(fields->addr,fields->addrspace,getSize(fields->type));
}
if ( n < 0 || n >= DCL_ELEM(type))
{
fprintf(stdout,"Wrong index %d.\n", n);
- return;
+ return 1;
}
type = type->next;
size = getSize(type);
if ( ! fields )
{
fprintf(stdout,"Unknown field \"%s\" of structure\n", s);
- return;
+ return 1;
}
type = fields->type;
size = getSize(type);
if (IS_AGGREGATE(type))
{
if ( val )
- fprintf(stdout,"Cannot set aggregate variable\n");
+ {
+ fprintf(stdout,"Cannot set/compare aggregate variable\n");
+ return 1;
+ }
else
printValAggregates(sym,type,sym->addrspace,addr,fmt);
}
{
if ( !val )
printValFunc(sym,fmt);
+ else
+ return 1;
}
else
{
if ( val )
- setValBasic (sym,type,sym->addrspace,addr,size,val);
+ {
+ unsigned long newval;
+ newval = getValBasic(sym,type,val);
+
+ if ( cmp )
+ {
+ unsigned long lval;
+ lval = simGetValue(addr,sym->addrspace,size);
+ switch ( cmp )
+ {
+ case '<' : return ( lval < newval ? 1:0 ); break;
+ case '>' : return ( lval > newval ? 1:0 ); break;
+ case 'l' : return ( lval <= newval ? 1:0 ); break;
+ case 'g' : return ( lval >= newval ? 1:0 ); break;
+ case '=' : return ( lval == newval ? 1:0 ); break;
+ case '!' : return ( lval != newval ? 1:0 ); break;
+ }
+ }
+ else
+ {
+ if ( sym->addrspace == 'I' && addr == 0xb8 )
+ {
+ /* Symbol with address of IP */
+ if ( cctxt ) cctxt->addr = newval;
+ simSetPC(cctxt->addr);
+ }
+ else
+ simSetValue(addr,sym->addrspace,size,newval);
+ return 1;
+ }
+ }
else
printValBasic(sym,type,sym->addrspace,addr,size,fmt);
}
if ( flg > 0 ) fprintf(stdout,"\n");
-
+ return 0;
}
/*-----------------------------------------------------------------*/
}
}
+/*-----------------------------------------------------------------*/
+/* conditionIsTrue - compare variable with constant value */
+/*-----------------------------------------------------------------*/
+int conditionIsTrue( char *s, context *cctxt)
+{
+ symbol *sym = NULL;
+ int fmt;
+ char *rs, *dup, cmp_char;
+ dup = s = Safe_strdup(s);
+ if ( !( rs = preparePrint(s, cctxt, &fmt, &sym )) || !sym)
+ fmt = 1;
+ else if (!( s = strpbrk(rs,"<>=!")))
+ fmt = 1;
+ else
+ {
+ cmp_char = *s;
+ *s++ = '\0';
+ if ( *s == '=' )
+ {
+ /* if <= or >= an other char is used
+ * == or != not checked in switch
+ */
+ switch( cmp_char )
+ {
+ case '>': cmp_char = 'g' ; break;
+ case '<': cmp_char = 'l' ; break;
+ }
+ s++ ;
+ }
+ while (isspace(*s)) *s++ = '\0';
+ fmt = printOrSetSymValue(sym,cctxt,0,0,0,rs,s,cmp_char);
+ }
+ Safe_free(dup);
+ return fmt;
+}
+
/*-----------------------------------------------------------------*/
/* cmdPrint - print value of variable */
/*-----------------------------------------------------------------*/
if ( sym )
{
- printOrSetSymValue(sym,cctxt,1,0,fmt,rs,NULL);
+ printOrSetSymValue(sym,cctxt,1,0,fmt,rs,NULL,'\0');
}
return 0;
}
if ( sym )
{
- printOrSetSymValue(sym,cctxt,0,0,fmt,rs,NULL);
+ printOrSetSymValue(sym,cctxt,0,0,fmt,rs,NULL,'\0');
}
return 0;
}
dsym = setNextItem(dispsymbols))
{
if ( (sym = symLookup(dsym->name,cctxt)))
- printOrSetSymValue(sym,cctxt,2,dsym->dnum,dsym->fmt,dsym->rs,NULL);
+ printOrSetSymValue(sym,cctxt,2,dsym->dnum,dsym->fmt,
+ dsym->rs,NULL,'\0');
}
}
{
function *func = NULL;
currentFrame = 0;
- if (!applyToSet(functions,funcWithName,"main",&func) &&
- !applyToSet(functions,funcWithName,"_main",&func))
- return;
+ if (!applyToSet(functions,funcWithName,"_main",&func) &&
+ !applyToSet(functions,funcWithName,"main",&func))
+ return;
discoverContext (func->sym->addr, func);
}
+
+function *needExtraMainFunction()
+{
+ function *func = NULL;
+ if (!applyToSet(functions,funcWithName,"_main",&func))
+ {
+ if (applyToSet(functions,funcWithName,"main",&func))
+ {
+ return func;
+ }
+ }
+ return NULL;
+}
static void printFrame()
{