| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/TADS2/DBGRUN.C,v 1.3 1999/07/11 00:46:29 MJRoberts Exp $"; |
| 4 |
#endif |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include <stdlib.h> |
| 29 |
#include <string.h> |
| 30 |
#include <stdio.h> |
| 31 |
#include <ctype.h> |
| 32 |
#include "os.h" |
| 33 |
#include "dbg.h" |
| 34 |
#include "tio.h" |
| 35 |
#include "obj.h" |
| 36 |
#include "prp.h" |
| 37 |
#include "tok.h" |
| 38 |
#include "run.h" |
| 39 |
#include "tok.h" |
| 40 |
#include "prs.h" |
| 41 |
#include "linf.h" |
| 42 |
#include "bif.h" |
| 43 |
#include "lst.h" |
| 44 |
|
| 45 |
|
| 46 |
int dbgpresent() |
| 47 |
{ |
| 48 |
return TRUE; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
void dbgwhere(dbgcxdef *ctx, char *p) |
| 53 |
{ |
| 54 |
dbgfdef *f; |
| 55 |
|
| 56 |
f = &ctx->dbgcxfrm[ctx->dbgcxfcn - 1]; |
| 57 |
if (f->dbgftarg == MCMONINV) |
| 58 |
p += dbgnam(ctx, p, TOKSTBIFN, f->dbgfbif); |
| 59 |
else |
| 60 |
p += dbgnam(ctx, p, |
| 61 |
(f->dbgfself == MCMONINV ? TOKSTFUNC : TOKSTOBJ), |
| 62 |
(int)f->dbgftarg); |
| 63 |
|
| 64 |
if (f->dbgfself != MCMONINV && f->dbgfself != f->dbgftarg) |
| 65 |
{ |
| 66 |
memcpy(p, "<self=", (size_t)6); |
| 67 |
p += 6; |
| 68 |
p += dbgnam(ctx, p, TOKSTOBJ, (int)f->dbgfself); |
| 69 |
*p++ = '>'; |
| 70 |
} |
| 71 |
if (f->dbgfprop) |
| 72 |
{ |
| 73 |
*p++ = '.'; |
| 74 |
p += dbgnam(ctx, p, TOKSTPROP, (int)f->dbgfprop); |
| 75 |
} |
| 76 |
if (f->dbgfself == MCMONINV || f->dbgfbif) |
| 77 |
{ |
| 78 |
*p++ = '('; |
| 79 |
*p++ = ')'; |
| 80 |
} |
| 81 |
*p = '\0'; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
static int dbgbpeval(dbgcxdef *ctx, dbgbpdef *bp, dbgfdef *fr) |
| 89 |
{ |
| 90 |
uchar *objptr; |
| 91 |
runsdef *oldsp; |
| 92 |
runsdef val; |
| 93 |
int err; |
| 94 |
|
| 95 |
objptr = mcmlck(ctx->dbgcxmem, bp->dbgbpcond); |
| 96 |
|
| 97 |
ERRBEGIN(ctx->dbgcxerr) |
| 98 |
|
| 99 |
oldsp = ctx->dbgcxrun->runcxsp; |
| 100 |
runexe(ctx->dbgcxrun, objptr, fr->dbgfself, bp->dbgbpcond, |
| 101 |
(prpnum)0, 0); |
| 102 |
|
| 103 |
ERRCATCH(ctx->dbgcxerr, err) |
| 104 |
|
| 105 |
; |
| 106 |
ERREND(ctx->dbgcxerr) |
| 107 |
|
| 108 |
|
| 109 |
mcmunlck(ctx->dbgcxmem, bp->dbgbpcond); |
| 110 |
|
| 111 |
|
| 112 |
if (ctx->dbgcxrun->runcxsp != oldsp) |
| 113 |
{ |
| 114 |
runpop(ctx->dbgcxrun, &val); |
| 115 |
if (val.runstyp == DAT_NIL) |
| 116 |
return FALSE; |
| 117 |
else |
| 118 |
return TRUE; |
| 119 |
} |
| 120 |
else |
| 121 |
return FALSE; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
void dbgss(dbgcxdef *ctx, uint ofs, int instr, int err, |
| 126 |
uchar *noreg *instrp) |
| 127 |
{ |
| 128 |
dbgbpdef *bp; |
| 129 |
int i; |
| 130 |
dbgfdef *fr; |
| 131 |
int bphit = 0; |
| 132 |
voccxdef *vcx = ctx->dbgcxrun->runcxvoc; |
| 133 |
unsigned int exec_ofs; |
| 134 |
errdef *inner_frame; |
| 135 |
int stepping; |
| 136 |
|
| 137 |
|
| 138 |
if (ctx->dbgcxflg & DBGCXFIND) |
| 139 |
return; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
if (dbgu_err_resume(ctx)) |
| 151 |
{ |
| 152 |
|
| 153 |
while (ctx->dbgcxfcn > 1 |
| 154 |
&& ctx->dbgcxfrm[ctx->dbgcxfcn-1].dbgftarg == MCMONINV) |
| 155 |
ctx->dbgcxfcn--; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
fr = (ctx->dbgcxfcn == 0 ? 0 : &ctx->dbgcxfrm[ctx->dbgcxfcn - 1]); |
| 160 |
|
| 161 |
|
| 162 |
stepping = FALSE; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
if ((ctx->dbgcxflg & DBGCXFSS) != 0) |
| 169 |
{ |
| 170 |
|
| 171 |
if ((ctx->dbgcxflg & DBGCXFSO) != 0) |
| 172 |
{ |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
stepping = (ctx->dbgcxdep <= ctx->dbgcxsof); |
| 179 |
} |
| 180 |
else |
| 181 |
{ |
| 182 |
|
| 183 |
stepping = TRUE; |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
if (!stepping && err == 0) |
| 192 |
{ |
| 193 |
|
| 194 |
if (instr == OPCBP) |
| 195 |
{ |
| 196 |
|
| 197 |
for (i = 0, bp = ctx->dbgcxbp ; i < DBGBPMAX ; ++bp, ++i) |
| 198 |
{ |
| 199 |
if (fr != 0 |
| 200 |
&& (bp->dbgbpflg & DBGBPFUSED) |
| 201 |
&& !(bp->dbgbpflg & DBGBPFDISA) |
| 202 |
&& (bp->dbgbpself == fr->dbgfself |
| 203 |
|| bp->dbgbpself == MCMONINV |
| 204 |
|| bifinh(vcx, vocinh(vcx, fr->dbgfself), |
| 205 |
bp->dbgbpself)) |
| 206 |
&& bp->dbgbptarg == fr->dbgftarg |
| 207 |
&& bp->dbgbpofs + 3 == ofs) |
| 208 |
break; |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
if (i == DBGBPMAX) |
| 213 |
return; |
| 214 |
|
| 215 |
|
| 216 |
if (!(ctx->dbgcxflg & DBGCXFSS) && (bp->dbgbpflg & DBGBPFCOND) |
| 217 |
&& !dbgbpeval(ctx, bp, fr)) |
| 218 |
return; |
| 219 |
|
| 220 |
|
| 221 |
bphit = i + 1; |
| 222 |
} |
| 223 |
else |
| 224 |
{ |
| 225 |
int brk; |
| 226 |
|
| 227 |
|
| 228 |
if (fr != 0 && (ctx->dbgcxflg & DBGCXFGBP) != 0) |
| 229 |
{ |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
for (brk = FALSE, i = 0, bp = ctx->dbgcxbp ; |
| 237 |
i < DBGBPMAX ; ++bp, ++i) |
| 238 |
{ |
| 239 |
if ((bp->dbgbpflg & DBGBPFUSED) |
| 240 |
&& !(bp->dbgbpflg & DBGBPFDISA) |
| 241 |
&& bp->dbgbptarg == MCMONINV |
| 242 |
&& dbgbpeval(ctx, bp, fr)) |
| 243 |
{ |
| 244 |
brk = TRUE; |
| 245 |
bp->dbgbpflg |= DBGBPFDISA; |
| 246 |
bphit = i + 1; |
| 247 |
break; |
| 248 |
} |
| 249 |
} |
| 250 |
} |
| 251 |
else |
| 252 |
{ |
| 253 |
|
| 254 |
brk = FALSE; |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
if (!brk) |
| 259 |
return; |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
ctx->dbgcxflg |= DBGCXFIND; |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
if (instrp != 0 && fr != 0 && fr->dbgftarg != MCMONINV) |
| 273 |
{ |
| 274 |
exec_ofs = *instrp - mcmobjptr(ctx->dbgcxmem, (mcmon)fr->dbgftarg); |
| 275 |
mcmunlck(ctx->dbgcxmem, (mcmon)fr->dbgftarg); |
| 276 |
} |
| 277 |
else |
| 278 |
exec_ofs = 0; |
| 279 |
|
| 280 |
|
| 281 |
inner_frame = ctx->dbgcxerr->errcxptr; |
| 282 |
|
| 283 |
ERRBEGIN(ctx->dbgcxerr) |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
if (err != 0) |
| 290 |
errcopyargs(ctx->dbgcxerr, inner_frame); |
| 291 |
|
| 292 |
|
| 293 |
dbgucmd(ctx, bphit, err, &exec_ofs); |
| 294 |
ERRCLEAN(ctx->dbgcxerr) |
| 295 |
|
| 296 |
ctx->dbgcxflg &= ~DBGCXFIND; |
| 297 |
ERRENDCLN(ctx->dbgcxerr); |
| 298 |
|
| 299 |
|
| 300 |
if (instrp != 0 && fr != 0 && fr->dbgftarg != MCMONINV) |
| 301 |
*instrp = mcmlck(ctx->dbgcxmem, (mcmon)fr->dbgftarg) + exec_ofs; |
| 302 |
|
| 303 |
|
| 304 |
ctx->dbgcxflg &= ~DBGCXFIND; |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
int dbgstart(dbgcxdef *ctx) |
| 309 |
{ |
| 310 |
if (!ctx || !(ctx->dbgcxflg & DBGCXFOK)) return TRUE; |
| 311 |
ctx->dbgcxflg |= DBGCXFSS; |
| 312 |
return FALSE; |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
static int dbgnamsav(dbgcxdef *ctx, char *nam, uint *ofsp) |
| 317 |
{ |
| 318 |
size_t len = strlen(nam) + 1; |
| 319 |
|
| 320 |
if (ctx->dbgcxnam |
| 321 |
&& ctx->dbgcxnamf + len < ctx->dbgcxnams) |
| 322 |
{ |
| 323 |
memcpy(ctx->dbgcxnam + ctx->dbgcxnamf, nam, len); |
| 324 |
*ofsp = ctx->dbgcxnamf; |
| 325 |
ctx->dbgcxnamf += len; |
| 326 |
return FALSE; |
| 327 |
} |
| 328 |
else |
| 329 |
return TRUE; |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
static void dbgnamdel(dbgcxdef *ctx, uint ofs) |
| 334 |
{ |
| 335 |
int i; |
| 336 |
dbgbpdef *bp; |
| 337 |
dbgwxdef *wx; |
| 338 |
uint delsiz; |
| 339 |
|
| 340 |
|
| 341 |
if (!ctx->dbgcxnam) return; |
| 342 |
|
| 343 |
|
| 344 |
delsiz = strlen(ctx->dbgcxnam + ofs) + 1; |
| 345 |
|
| 346 |
|
| 347 |
for (i = DBGBPMAX, bp = ctx->dbgcxbp ; i ; ++bp, --i) |
| 348 |
{ |
| 349 |
if ((bp->dbgbpflg & DBGBPFUSED) && (bp->dbgbpflg & DBGBPFNAME) |
| 350 |
&& bp->dbgbpnam > ofs) |
| 351 |
bp->dbgbpnam -= delsiz; |
| 352 |
if ((bp->dbgbpflg & DBGBPFUSED) && (bp->dbgbpflg & DBGBPFCONDNAME) |
| 353 |
&& bp->dbgbpcondnam > ofs) |
| 354 |
bp->dbgbpcondnam -= delsiz; |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
for (i = DBGWXMAX, wx = ctx->dbgcxwx ; i ; ++wx, --i) |
| 359 |
{ |
| 360 |
if ((wx->dbgwxflg & DBGWXFUSED) && (wx->dbgwxflg & DBGWXFNAME) |
| 361 |
&& wx->dbgwxnam > ofs) |
| 362 |
wx->dbgwxnam -= delsiz; |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
if (ctx->dbgcxnamf - ofs - delsiz) |
| 367 |
memmove(ctx->dbgcxnam + ofs, ctx->dbgcxnam + ofs + delsiz, |
| 368 |
(size_t)(ctx->dbgcxnamf - ofs - delsiz)); |
| 369 |
ctx->dbgcxnamf -= delsiz; |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
int dbgbpat(dbgcxdef *ctx, objnum target, objnum self, |
| 377 |
uint ofs, int *bpnum, char *bpname, int toggle, char *cond, |
| 378 |
int *did_set) |
| 379 |
{ |
| 380 |
int i; |
| 381 |
dbgbpdef *bp; |
| 382 |
|
| 383 |
|
| 384 |
for (i = 0, bp = ctx->dbgcxbp ; i < DBGBPMAX ; ++bp, ++i) |
| 385 |
{ |
| 386 |
|
| 387 |
if (!(bp->dbgbpflg & DBGBPFUSED)) |
| 388 |
break; |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
*bpnum = i + 1; |
| 398 |
|
| 399 |
|
| 400 |
return dbgbpatid(ctx, *bpnum, target, self, ofs, |
| 401 |
bpname, toggle, cond, did_set); |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
int dbgbpatid(dbgcxdef *ctx, int bpnum, objnum target, objnum self, |
| 410 |
uint ofs, char *bpname, int toggle, char *cond, |
| 411 |
int *did_set) |
| 412 |
{ |
| 413 |
uchar *objp; |
| 414 |
int done; |
| 415 |
dbgbpdef *bp; |
| 416 |
int err; |
| 417 |
objnum condobj = MCMONINV; |
| 418 |
|
| 419 |
|
| 420 |
--bpnum; |
| 421 |
bp = &ctx->dbgcxbp[bpnum]; |
| 422 |
|
| 423 |
|
| 424 |
if (target == MCMONINV) |
| 425 |
{ |
| 426 |
|
| 427 |
dbgfdef fr; |
| 428 |
|
| 429 |
|
| 430 |
if (bpnum == DBGBPMAX) |
| 431 |
return ERR_MANYBP; |
| 432 |
else if ((bp->dbgbpflg & DBGBPFUSED) != 0) |
| 433 |
return ERR_BPINUSE; |
| 434 |
|
| 435 |
fr.dbgffr = 0; |
| 436 |
fr.dbgftarg = MCMONINV; |
| 437 |
if ((err = dbgcompile(ctx, cond, &fr, &condobj, FALSE)) != 0) |
| 438 |
return err; |
| 439 |
|
| 440 |
|
| 441 |
bp->dbgbpflg = DBGBPFUSED | DBGBPFCOND; |
| 442 |
bp->dbgbpself = |
| 443 |
bp->dbgbptarg = MCMONINV; |
| 444 |
bp->dbgbpofs = 0; |
| 445 |
bp->dbgbpcond = condobj; |
| 446 |
|
| 447 |
|
| 448 |
if (!dbgnamsav(ctx, bpname, &bp->dbgbpnam)) |
| 449 |
bp->dbgbpflg |= DBGBPFNAME; |
| 450 |
|
| 451 |
|
| 452 |
if (!dbgnamsav(ctx, cond, &bp->dbgbpcondnam)) |
| 453 |
bp->dbgbpflg |= DBGBPFCONDNAME; |
| 454 |
|
| 455 |
|
| 456 |
ctx->dbgcxflg |= DBGCXFGBP; |
| 457 |
|
| 458 |
|
| 459 |
return 0; |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
objp = mcmlck(ctx->dbgcxmem, (mcmon)target); |
| 464 |
|
| 465 |
|
| 466 |
for (done = FALSE ; !done ; ) |
| 467 |
{ |
| 468 |
switch(*(objp + ofs)) |
| 469 |
{ |
| 470 |
case OPCENTER: |
| 471 |
ofs += 3; |
| 472 |
break; |
| 473 |
case OPCCHKARGC: |
| 474 |
ofs += 2; |
| 475 |
break; |
| 476 |
case OPCFRAME: |
| 477 |
ofs += 1 + osrp2(objp + ofs + 1); |
| 478 |
break; |
| 479 |
default: |
| 480 |
done = TRUE; |
| 481 |
break; |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
if (did_set != 0) |
| 487 |
*did_set = TRUE; |
| 488 |
|
| 489 |
|
| 490 |
if (*(objp + ofs) == OPCBP) |
| 491 |
{ |
| 492 |
|
| 493 |
if (toggle && (cond == 0 || *cond == '\0')) |
| 494 |
{ |
| 495 |
int i; |
| 496 |
|
| 497 |
|
| 498 |
if (did_set != 0) |
| 499 |
*did_set = FALSE; |
| 500 |
|
| 501 |
|
| 502 |
for (i = 0, bp = ctx->dbgcxbp ; i < DBGBPMAX ; ++bp, ++i) |
| 503 |
{ |
| 504 |
if ((bp->dbgbpflg & DBGBPFUSED) != 0 |
| 505 |
&& bp->dbgbptarg == target |
| 506 |
&& bp->dbgbpofs == ofs |
| 507 |
&& bp->dbgbpself == self) |
| 508 |
{ |
| 509 |
err = dbgbpdel(ctx, i+1); |
| 510 |
goto return_error; |
| 511 |
} |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
err = 0; |
| 517 |
} |
| 518 |
else if (*(objp + ofs) != OPCLINE) |
| 519 |
{ |
| 520 |
|
| 521 |
err = ERR_BPNOTLN; |
| 522 |
} |
| 523 |
else if (bpnum == DBGBPMAX) |
| 524 |
{ |
| 525 |
|
| 526 |
err = ERR_MANYBP; |
| 527 |
} |
| 528 |
else if ((bp->dbgbpflg & DBGBPFUSED) != 0) |
| 529 |
{ |
| 530 |
|
| 531 |
return ERR_BPINUSE; |
| 532 |
} |
| 533 |
else |
| 534 |
{ |
| 535 |
|
| 536 |
err = 0; |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
if (cond && *cond) |
| 541 |
{ |
| 542 |
dbgfdef fr; |
| 543 |
|
| 544 |
fr.dbgffr = osrp2(objp + ofs + 2); |
| 545 |
fr.dbgftarg = target; |
| 546 |
err = dbgcompile(ctx, cond, &fr, &condobj, FALSE); |
| 547 |
} |
| 548 |
|
| 549 |
if (err == 0) |
| 550 |
{ |
| 551 |
|
| 552 |
bp->dbgbpflg = DBGBPFUSED; |
| 553 |
bp->dbgbpself = self; |
| 554 |
bp->dbgbptarg = target; |
| 555 |
bp->dbgbpofs = ofs; |
| 556 |
|
| 557 |
if (cond && *cond) |
| 558 |
{ |
| 559 |
|
| 560 |
bp->dbgbpcond = condobj; |
| 561 |
bp->dbgbpflg |= DBGBPFCOND; |
| 562 |
if (!dbgnamsav(ctx, cond, &bp->dbgbpcondnam)) |
| 563 |
bp->dbgbpflg |= DBGBPFCONDNAME; |
| 564 |
} |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
*(objp + ofs) = OPCBP; |
| 572 |
mcmtch(ctx->dbgcxmem, (mcmon)target); |
| 573 |
} |
| 574 |
|
| 575 |
return_error: |
| 576 |
mcmunlck(ctx->dbgcxmem, (mcmon)target); |
| 577 |
|
| 578 |
|
| 579 |
if (err && condobj != MCMONINV) |
| 580 |
mcmfre(ctx->dbgcxmem, condobj); |
| 581 |
|
| 582 |
|
| 583 |
if (!err && !dbgnamsav(ctx, bpname, &bp->dbgbpnam)) |
| 584 |
bp->dbgbpflg |= DBGBPFNAME; |
| 585 |
|
| 586 |
return err; |
| 587 |
} |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
int dbgbpsetcond(dbgcxdef *ctx, int bpnum, char *cond) |
| 593 |
{ |
| 594 |
dbgbpdef *bp; |
| 595 |
int err; |
| 596 |
objnum condobj; |
| 597 |
dbgfdef fr; |
| 598 |
|
| 599 |
|
| 600 |
--bpnum; |
| 601 |
bp = &ctx->dbgcxbp[bpnum]; |
| 602 |
if (bpnum < 0 || bpnum >= DBGBPMAX || !(bp->dbgbpflg & DBGBPFUSED)) |
| 603 |
return ERR_BPNSET; |
| 604 |
|
| 605 |
|
| 606 |
if (bp->dbgbptarg == MCMONINV) |
| 607 |
{ |
| 608 |
|
| 609 |
fr.dbgffr = 0; |
| 610 |
fr.dbgftarg = MCMONINV; |
| 611 |
err = dbgcompile(ctx, cond, &fr, &condobj, FALSE); |
| 612 |
} |
| 613 |
else |
| 614 |
{ |
| 615 |
uchar *objp; |
| 616 |
|
| 617 |
|
| 618 |
objp = mcmlck(ctx->dbgcxmem, (mcmon)bp->dbgbptarg); |
| 619 |
|
| 620 |
|
| 621 |
fr.dbgffr = osrp2(objp + bp->dbgbpofs + 2); |
| 622 |
fr.dbgftarg = bp->dbgbptarg; |
| 623 |
err = dbgcompile(ctx, cond, &fr, &condobj, FALSE); |
| 624 |
|
| 625 |
|
| 626 |
mcmunlck(ctx->dbgcxmem, (mcmon)bp->dbgbptarg); |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
if (err != 0) |
| 631 |
return err; |
| 632 |
|
| 633 |
|
| 634 |
if (bp->dbgbpflg & DBGBPFCOND) |
| 635 |
mcmfre(ctx->dbgcxmem, bp->dbgbpcond); |
| 636 |
|
| 637 |
|
| 638 |
if (bp->dbgbpflg & DBGBPFCONDNAME) |
| 639 |
{ |
| 640 |
dbgnamdel(ctx, bp->dbgbpcondnam); |
| 641 |
bp->dbgbpflg &= ~DBGBPFCONDNAME; |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
bp->dbgbpcond = condobj; |
| 646 |
|
| 647 |
|
| 648 |
if (!dbgnamsav(ctx, cond, &bp->dbgbpcondnam)) |
| 649 |
bp->dbgbpflg |= DBGBPFCONDNAME; |
| 650 |
|
| 651 |
|
| 652 |
return 0; |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
int dbgisbp(dbgcxdef *ctx, objnum target, objnum self, uint ofs, int *bpnum) |
| 661 |
{ |
| 662 |
dbgbpdef *bp; |
| 663 |
int i; |
| 664 |
|
| 665 |
|
| 666 |
for (i = 0, bp = ctx->dbgcxbp ; i < DBGBPMAX ; ++bp, ++i) |
| 667 |
{ |
| 668 |
|
| 669 |
if ((bp->dbgbpflg & DBGBPFUSED) != 0 |
| 670 |
&& bp->dbgbptarg == target |
| 671 |
&& bp->dbgbpself == self |
| 672 |
&& bp->dbgbpofs == ofs) |
| 673 |
{ |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
if (bpnum != 0) |
| 679 |
*bpnum = i+1; |
| 680 |
return TRUE; |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
|
| 685 |
return FALSE; |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
int dbgisbpena(dbgcxdef *ctx, int bpnum) |
| 692 |
{ |
| 693 |
dbgbpdef *bp; |
| 694 |
|
| 695 |
|
| 696 |
--bpnum; |
| 697 |
if (bpnum < 0 || bpnum >= DBGBPMAX) |
| 698 |
return FALSE; |
| 699 |
|
| 700 |
|
| 701 |
bp = &ctx->dbgcxbp[bpnum]; |
| 702 |
|
| 703 |
|
| 704 |
return ((bp->dbgbpflg & DBGBPFUSED) != 0 |
| 705 |
&& (bp->dbgbpflg & DBGBPFDISA) == 0); |
| 706 |
} |
| 707 |
|
| 708 |
|
| 709 |
int dbgbpset(dbgcxdef *ctx, char *addr, int *bpnum) |
| 710 |
{ |
| 711 |
char *p; |
| 712 |
char psav; |
| 713 |
char *tok1; |
| 714 |
char tok1sav; |
| 715 |
char *tok1end; |
| 716 |
char *tok2; |
| 717 |
toksdef sym1; |
| 718 |
toksdef sym2; |
| 719 |
toktdef *tab; |
| 720 |
uint hsh1; |
| 721 |
uint hsh2; |
| 722 |
objnum objn; |
| 723 |
uint ofs; |
| 724 |
uchar *objp; |
| 725 |
prpdef *prp; |
| 726 |
dattyp typ; |
| 727 |
objnum target; |
| 728 |
char *end; |
| 729 |
char buf1[40]; |
| 730 |
char buf2[40]; |
| 731 |
|
| 732 |
|
| 733 |
for (p = addr ; *p && t_isspace(*p) ; ++p) ; |
| 734 |
for (tok1 = addr = p ; *p && TOKISSYM(*p) ; ++p) ; |
| 735 |
|
| 736 |
|
| 737 |
if (!strnicmp(tok1, "when ", (size_t)5)) |
| 738 |
{ |
| 739 |
for (end = tok1 + 5 ; t_isspace(*end) ; ++end) ; |
| 740 |
return(dbgbpat(ctx, MCMONINV, MCMONINV, 0, bpnum, |
| 741 |
addr, FALSE, end, 0)); |
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
for (tok1end = p ; t_isspace(*p) ; ++p) ; |
| 746 |
if (*p == '.') |
| 747 |
{ |
| 748 |
for (++p ; t_isspace(*p) ; ++p) ; |
| 749 |
for (tok2 = p ; TOKISSYM(*p) ; ++p) ; |
| 750 |
psav = *p; |
| 751 |
*p = '\0'; |
| 752 |
end = (psav ? p + 1 : p); |
| 753 |
} |
| 754 |
else |
| 755 |
{ |
| 756 |
tok2 = (char *)0; |
| 757 |
end = tok1end; |
| 758 |
if (*end) ++end; |
| 759 |
p = (char *)0; |
| 760 |
} |
| 761 |
|
| 762 |
tok1sav = *tok1end; |
| 763 |
*tok1end = '\0'; |
| 764 |
|
| 765 |
|
| 766 |
tab = (toktdef *)ctx->dbgcxtab; |
| 767 |
if (ctx->dbgcxprs->prscxtok->tokcxflg & TOKCXCASEFOLD) |
| 768 |
{ |
| 769 |
strcpy(buf1, tok1); |
| 770 |
os_strlwr(buf1); |
| 771 |
tok1 = buf1; |
| 772 |
} |
| 773 |
hsh1 = tokhsh(tok1); |
| 774 |
if (!(*tab->toktfsea)(tab, tok1, (int)strlen(tok1), hsh1, &sym1)) |
| 775 |
return ERR_BPSYM; |
| 776 |
objn = sym1.toksval; |
| 777 |
|
| 778 |
if (tok2) |
| 779 |
{ |
| 780 |
|
| 781 |
if (ctx->dbgcxprs->prscxtok->tokcxflg & TOKCXCASEFOLD) |
| 782 |
{ |
| 783 |
strcpy(buf2, tok2); |
| 784 |
os_strlwr(buf2); |
| 785 |
tok2 = buf2; |
| 786 |
} |
| 787 |
hsh2 = tokhsh(tok2); |
| 788 |
if (!(*tab->toktfsea)(tab, tok2, (int)strlen(tok2), hsh2, &sym2)) |
| 789 |
return ERR_BPSYM; |
| 790 |
if (sym1.tokstyp != TOKSTOBJ) return ERR_BPOBJ; |
| 791 |
|
| 792 |
|
| 793 |
ofs = objgetap(ctx->dbgcxmem, objn, (prpnum)sym2.toksval, |
| 794 |
&target, FALSE); |
| 795 |
if (!ofs) return ERR_BPNOPRP; |
| 796 |
|
| 797 |
|
| 798 |
objp = mcmlck(ctx->dbgcxmem, (mcmon)target); |
| 799 |
prp = objofsp((objdef *)objp, ofs); |
| 800 |
typ = prptype(prp); |
| 801 |
ofs = ((uchar *)prpvalp(prp)) - objp; |
| 802 |
mcmunlck(ctx->dbgcxmem, (mcmon)target); |
| 803 |
|
| 804 |
if (typ != DAT_CODE) return ERR_BPPRPNC; |
| 805 |
} |
| 806 |
else |
| 807 |
{ |
| 808 |
|
| 809 |
if (sym1.tokstyp != TOKSTFUNC) return ERR_BPFUNC; |
| 810 |
ofs = 0; |
| 811 |
target = objn; |
| 812 |
objn = MCMONINV; |
| 813 |
} |
| 814 |
|
| 815 |
|
| 816 |
if (p) *p = psav; |
| 817 |
*tok1end = tok1sav; |
| 818 |
|
| 819 |
|
| 820 |
if (*end) |
| 821 |
{ |
| 822 |
while (t_isspace(*end)) ++end; |
| 823 |
if (*end) |
| 824 |
{ |
| 825 |
if (strnicmp(end, "when ", (size_t)5)) |
| 826 |
return ERR_EXTRTXT; |
| 827 |
for (end += 5 ; t_isspace(*end) ; ++end) ; |
| 828 |
} |
| 829 |
} |
| 830 |
|
| 831 |
|
| 832 |
return(dbgbpat(ctx, target, objn, ofs, bpnum, addr, FALSE, end, 0)); |
| 833 |
} |
| 834 |
|
| 835 |
|
| 836 |
int dbgbpdel(dbgcxdef *ctx, int bpnum) |
| 837 |
{ |
| 838 |
dbgbpdef *bp = &ctx->dbgcxbp[--bpnum]; |
| 839 |
dbgbpdef *bp2; |
| 840 |
uchar *objp; |
| 841 |
int i; |
| 842 |
int bpset; |
| 843 |
|
| 844 |
|
| 845 |
if (bpnum < 0 || bpnum >= DBGBPMAX || !(bp->dbgbpflg & DBGBPFUSED)) |
| 846 |
return ERR_BPNSET; |
| 847 |
|
| 848 |
|
| 849 |
for (bpset = FALSE, i = DBGBPMAX, bp2 = ctx->dbgcxbp ; i ; ++bp2, --i) |
| 850 |
{ |
| 851 |
if (bp != bp2 && (bp2->dbgbpflg & DBGBPFUSED) |
| 852 |
&& bp2->dbgbptarg == bp->dbgbptarg |
| 853 |
&& bp2->dbgbpofs == bp->dbgbpofs) |
| 854 |
{ |
| 855 |
bpset = TRUE; |
| 856 |
break; |
| 857 |
} |
| 858 |
} |
| 859 |
|
| 860 |
|
| 861 |
if (!bpset) |
| 862 |
{ |
| 863 |
if (bp->dbgbptarg == MCMONINV) |
| 864 |
{ |
| 865 |
|
| 866 |
ctx->dbgcxflg &= ~DBGCXFGBP; |
| 867 |
} |
| 868 |
else |
| 869 |
{ |
| 870 |
|
| 871 |
objp = mcmlck(ctx->dbgcxmem, (mcmon)bp->dbgbptarg); |
| 872 |
*(objp + bp->dbgbpofs) = OPCLINE; |
| 873 |
mcmtch(ctx->dbgcxmem, (mcmon)bp->dbgbptarg); |
| 874 |
mcmunlck(ctx->dbgcxmem, (mcmon)bp->dbgbptarg); |
| 875 |
} |
| 876 |
} |
| 877 |
|
| 878 |
|
| 879 |
if (bp->dbgbpflg & DBGBPFNAME) |
| 880 |
dbgnamdel(ctx, bp->dbgbpnam); |
| 881 |
if (bp->dbgbpflg & DBGBPFCONDNAME) |
| 882 |
dbgnamdel(ctx, bp->dbgbpcondnam); |
| 883 |
|
| 884 |
|
| 885 |
bp->dbgbpflg &= ~DBGBPFUSED; |
| 886 |
|
| 887 |
|
| 888 |
if (bp->dbgbpflg & DBGBPFCOND) |
| 889 |
{ |
| 890 |
mcmfre(ctx->dbgcxmem, bp->dbgbpcond); |
| 891 |
bp->dbgbpflg &= ~DBGBPFCOND; |
| 892 |
} |
| 893 |
|
| 894 |
return 0; |
| 895 |
} |
| 896 |
|
| 897 |
|
| 898 |
void dbgbplist(dbgcxdef *ctx, |
| 899 |
void (*dispfn)(void *ctx, const char *str, int len), |
| 900 |
void *dispctx) |
| 901 |
{ |
| 902 |
dbgbpdef *bp = ctx->dbgcxbp; |
| 903 |
int i; |
| 904 |
char *p; |
| 905 |
char buf[10]; |
| 906 |
|
| 907 |
|
| 908 |
if (!ctx->dbgcxnam) return; |
| 909 |
|
| 910 |
for (i = 0 ; i < DBGBPMAX ; ++bp, ++i) |
| 911 |
{ |
| 912 |
if ((bp->dbgbpflg & DBGBPFUSED) && (bp->dbgbpflg & DBGBPFNAME)) |
| 913 |
{ |
| 914 |
p = ctx->dbgcxnam + bp->dbgbpnam; |
| 915 |
sprintf(buf, "%d: ", i + 1); |
| 916 |
(*dispfn)(dispctx, buf, (int)strlen(buf)); |
| 917 |
(*dispfn)(dispctx, p, (int)strlen(p)); |
| 918 |
|
| 919 |
if (bp->dbgbpflg & DBGBPFDISA) |
| 920 |
(*dispfn)(dispctx, " [disabled]", 11); |
| 921 |
|
| 922 |
(*dispfn)(dispctx, "\n", 1); |
| 923 |
} |
| 924 |
} |
| 925 |
} |
| 926 |
|
| 927 |
|
| 928 |
void dbgbpenum(dbgcxdef *ctx, |
| 929 |
void (*cbfunc)(void *cbctx, int bpnum, const char *desc, |
| 930 |
const char *cond, int disabled), void *cbctx) |
| 931 |
{ |
| 932 |
dbgbpdef *bp = ctx->dbgcxbp; |
| 933 |
int i; |
| 934 |
char *bpname; |
| 935 |
char *cond; |
| 936 |
|
| 937 |
|
| 938 |
if (ctx->dbgcxnam == 0) |
| 939 |
return; |
| 940 |
|
| 941 |
|
| 942 |
for (i = 0 ; i < DBGBPMAX ; ++bp, ++i) |
| 943 |
{ |
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
if ((bp->dbgbpflg & DBGBPFUSED) && (bp->dbgbpflg & DBGBPFNAME)) |
| 949 |
{ |
| 950 |
|
| 951 |
bpname = ctx->dbgcxnam + bp->dbgbpnam; |
| 952 |
|
| 953 |
|
| 954 |
cond = ((bp->dbgbpflg & DBGBPFCONDNAME) != 0 |
| 955 |
? ctx->dbgcxnam + bp->dbgbpcondnam : 0); |
| 956 |
|
| 957 |
|
| 958 |
(*cbfunc)(cbctx, i + 1, bpname, cond, |
| 959 |
(bp->dbgbpflg & DBGBPFDISA) != 0); |
| 960 |
} |
| 961 |
} |
| 962 |
} |
| 963 |
|
| 964 |
|
| 965 |
int dbgbpdis(dbgcxdef *ctx, int bpnum, int disable) |
| 966 |
{ |
| 967 |
dbgbpdef *bp = &ctx->dbgcxbp[--bpnum]; |
| 968 |
|
| 969 |
|
| 970 |
if (bpnum < 0 || bpnum >= DBGBPMAX || !(bp->dbgbpflg & DBGBPFUSED)) |
| 971 |
return ERR_BPNSET; |
| 972 |
|
| 973 |
if (disable) bp->dbgbpflg |= DBGBPFDISA; |
| 974 |
else bp->dbgbpflg &= ~DBGBPFDISA; |
| 975 |
return 0; |
| 976 |
} |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
void dbgbpeach(dbgcxdef *ctx, void (*fn)(void *, int, uchar *, uint), |
| 984 |
void *fnctx) |
| 985 |
{ |
| 986 |
int i; |
| 987 |
dbgbpdef *bp = ctx->dbgcxbp; |
| 988 |
uchar *p; |
| 989 |
uint len; |
| 990 |
|
| 991 |
for (i = 0 ; i < DBGBPMAX ; ++bp, ++i) |
| 992 |
{ |
| 993 |
if ((bp->dbgbpflg & DBGBPFUSED) |
| 994 |
&& bp->dbgbptarg != MCMONINV) |
| 995 |
{ |
| 996 |
p = mcmlck(ctx->dbgcxmem, (mcmon)bp->dbgbptarg); |
| 997 |
p += bp->dbgbpofs + 1; |
| 998 |
len = *p - 4; |
| 999 |
p += 3; |
| 1000 |
(*fn)(fnctx, (int)(*p), p + 1, len); |
| 1001 |
mcmunlck(ctx->dbgcxmem, (mcmon)bp->dbgbptarg); |
| 1002 |
} |
| 1003 |
} |
| 1004 |
} |
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
int dbgbpgetinfo(dbgcxdef *ctx, int bpnum, char *descbuf, size_t descbuflen, |
| 1011 |
char *condbuf, size_t condbuflen) |
| 1012 |
{ |
| 1013 |
dbgbpdef *bp = &ctx->dbgcxbp[--bpnum]; |
| 1014 |
|
| 1015 |
|
| 1016 |
if (bpnum < 0 || bpnum >= DBGBPMAX || !(bp->dbgbpflg & DBGBPFUSED)) |
| 1017 |
return ERR_BPNSET; |
| 1018 |
|
| 1019 |
|
| 1020 |
if (descbuf != 0 && descbuflen != 0) |
| 1021 |
{ |
| 1022 |
|
| 1023 |
if ((bp->dbgbpflg & DBGBPFNAME) != 0) |
| 1024 |
{ |
| 1025 |
size_t outlen; |
| 1026 |
char *bpname; |
| 1027 |
|
| 1028 |
|
| 1029 |
bpname = ctx->dbgcxnam + bp->dbgbpnam; |
| 1030 |
|
| 1031 |
|
| 1032 |
outlen = strlen(bpname); |
| 1033 |
if (outlen > descbuflen - 1) |
| 1034 |
outlen = descbuflen - 1; |
| 1035 |
|
| 1036 |
|
| 1037 |
memcpy(descbuf, bpname, outlen); |
| 1038 |
descbuf[outlen] = '\0'; |
| 1039 |
} |
| 1040 |
else |
| 1041 |
{ |
| 1042 |
|
| 1043 |
descbuf[0] = '\0'; |
| 1044 |
} |
| 1045 |
} |
| 1046 |
|
| 1047 |
|
| 1048 |
if (condbuf != 0 && condbuflen != 0) |
| 1049 |
{ |
| 1050 |
|
| 1051 |
if ((bp->dbgbpflg & DBGBPFCONDNAME) != 0) |
| 1052 |
{ |
| 1053 |
size_t outlen; |
| 1054 |
char *condname; |
| 1055 |
|
| 1056 |
|
| 1057 |
condname = ctx->dbgcxnam + bp->dbgbpcondnam; |
| 1058 |
|
| 1059 |
|
| 1060 |
outlen = strlen(condname); |
| 1061 |
if (outlen > condbuflen - 1) |
| 1062 |
outlen = condbuflen - 1; |
| 1063 |
|
| 1064 |
|
| 1065 |
memcpy(condbuf, condname, outlen); |
| 1066 |
condbuf[outlen] = '\0'; |
| 1067 |
} |
| 1068 |
else |
| 1069 |
{ |
| 1070 |
|
| 1071 |
condbuf[0] = '\0'; |
| 1072 |
} |
| 1073 |
} |
| 1074 |
|
| 1075 |
|
| 1076 |
return 0; |
| 1077 |
} |
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
static int dbglinget(lindef *lin) |
| 1082 |
{ |
| 1083 |
if (lin->linflg & LINFEOF) |
| 1084 |
return TRUE; |
| 1085 |
else |
| 1086 |
{ |
| 1087 |
lin->linflg |= LINFEOF; |
| 1088 |
return FALSE; |
| 1089 |
} |
| 1090 |
} |
| 1091 |
|
| 1092 |
static void dbglincls(lindef *lin) |
| 1093 |
{ |
| 1094 |
VARUSED(lin); |
| 1095 |
} |
| 1096 |
|
| 1097 |
|
| 1098 |
static void dbglinpos(lindef *lin, char *buf, uint bufl) |
| 1099 |
{ |
| 1100 |
VARUSED(lin); |
| 1101 |
VARUSED(buf); |
| 1102 |
VARUSED(bufl); |
| 1103 |
} |
| 1104 |
|
| 1105 |
|
| 1106 |
static void dbglinglo(lindef *lin, uchar *buf) |
| 1107 |
{ |
| 1108 |
VARUSED(lin); |
| 1109 |
VARUSED(buf); |
| 1110 |
} |
| 1111 |
|
| 1112 |
|
| 1113 |
static int dbglinwrt(lindef *lin, osfildef *fp) |
| 1114 |
{ |
| 1115 |
VARUSED(lin); |
| 1116 |
VARUSED(fp); |
| 1117 |
return TRUE; |
| 1118 |
} |
| 1119 |
|
| 1120 |
|
| 1121 |
static void dbglincmp(lindef *lin, uchar *buf) |
| 1122 |
{ |
| 1123 |
VARUSED(lin); |
| 1124 |
VARUSED(buf); |
| 1125 |
} |
| 1126 |
|
| 1127 |
|
| 1128 |
#define DBGMAXSYM 30 |
| 1129 |
|
| 1130 |
struct toktfdef |
| 1131 |
{ |
| 1132 |
toktdef toktfsc; |
| 1133 |
mcmcxdef *toktfmem; |
| 1134 |
dbgcxdef *toktfdbg; |
| 1135 |
dbgfdef *toktffr; |
| 1136 |
}; |
| 1137 |
typedef struct toktfdef toktfdef; |
| 1138 |
|
| 1139 |
|
| 1140 |
int dbgtabsea(toktdef *tab, char *name, int namel, int hash, toksdef *ret) |
| 1141 |
{ |
| 1142 |
dbgfdef *fr; |
| 1143 |
uchar *objp; |
| 1144 |
toktfdef *ftab = (toktfdef *)tab; |
| 1145 |
mcmcxdef *mctx = ftab->toktfmem; |
| 1146 |
uint len; |
| 1147 |
uint symlen; |
| 1148 |
uint symval; |
| 1149 |
uint ofs; |
| 1150 |
uint encofs; |
| 1151 |
uchar *framep; |
| 1152 |
|
| 1153 |
fr = ftab->toktffr; |
| 1154 |
|
| 1155 |
|
| 1156 |
if (fr->dbgftarg == MCMONINV) |
| 1157 |
return FALSE; |
| 1158 |
|
| 1159 |
|
| 1160 |
objp = mcmlck(mctx, fr->dbgftarg); |
| 1161 |
|
| 1162 |
for (ofs = fr->dbgffr ; ofs ; ofs = encofs) |
| 1163 |
{ |
| 1164 |
|
| 1165 |
framep = objp + ofs; |
| 1166 |
len = osrp2(framep) - 4; |
| 1167 |
encofs = osrp2(framep + 2); |
| 1168 |
framep += 4; |
| 1169 |
|
| 1170 |
while (len) |
| 1171 |
{ |
| 1172 |
symval = osrp2(framep); |
| 1173 |
framep += 2; |
| 1174 |
symlen = *framep++; |
| 1175 |
len -= 3 + symlen; |
| 1176 |
|
| 1177 |
if (symlen == (uint)namel && !memcmp(name, framep, (size_t)namel)) |
| 1178 |
{ |
| 1179 |
|
| 1180 |
mcmunlck(mctx, fr->dbgftarg); |
| 1181 |
ret->toksval = symval; |
| 1182 |
ret->tokstyp = TOKSTLOCAL; |
| 1183 |
ret->tokslen = namel; |
| 1184 |
ret->toksfr = ofs; |
| 1185 |
return TRUE; |
| 1186 |
} |
| 1187 |
|
| 1188 |
|
| 1189 |
framep += symlen; |
| 1190 |
} |
| 1191 |
} |
| 1192 |
|
| 1193 |
|
| 1194 |
mcmunlck(mctx, fr->dbgftarg); |
| 1195 |
return FALSE; |
| 1196 |
} |
| 1197 |
|
| 1198 |
|
| 1199 |
int dbgcompile(dbgcxdef *ctx, char *expr, dbgfdef *fr, objnum *objnp, |
| 1200 |
int speculative) |
| 1201 |
{ |
| 1202 |
lindef lin; |
| 1203 |
ushort oldflg = 0; |
| 1204 |
int err; |
| 1205 |
prscxdef *prs = ctx->dbgcxprs; |
| 1206 |
toktfdef tab; |
| 1207 |
mcmon objn; |
| 1208 |
|
| 1209 |
|
| 1210 |
prs->prscxtok->tokcxlin = &lin; |
| 1211 |
lin.lingetp = dbglinget; |
| 1212 |
lin.linclsp = dbglincls; |
| 1213 |
lin.linppos = dbglinpos; |
| 1214 |
lin.linglop = dbglinglo; |
| 1215 |
lin.linwrtp = dbglinwrt; |
| 1216 |
lin.lincmpp = dbglincmp; |
| 1217 |
lin.linpar = (lindef *)0; |
| 1218 |
lin.linnxt = (lindef *)0; |
| 1219 |
lin.linid = 0; |
| 1220 |
lin.linbuf = expr; |
| 1221 |
lin.linflg = LINFNOINC; |
| 1222 |
lin.linlen = strlen(expr); |
| 1223 |
lin.linlln = 0; |
| 1224 |
|
| 1225 |
|
| 1226 |
prs->prscxemt->emtcxfrob = fr->dbgftarg; |
| 1227 |
|
| 1228 |
|
| 1229 |
tab.toktfsc.toktfadd = 0; |
| 1230 |
tab.toktfsc.toktfsea = dbgtabsea; |
| 1231 |
tab.toktfsc.toktnxt = prs->prscxtok->tokcxstab; |
| 1232 |
tab.toktfsc.tokterr = prs->prscxerr; |
| 1233 |
tab.toktfmem = ctx->dbgcxrun->runcxmem; |
| 1234 |
tab.toktfdbg = ctx; |
| 1235 |
tab.toktffr = fr; |
| 1236 |
|
| 1237 |
|
| 1238 |
err = 0; |
| 1239 |
|
| 1240 |
|
| 1241 |
prs->prscxemt->emtcxptr = mcmalo(prs->prscxmem, (ushort)512, &objn); |
| 1242 |
prs->prscxemt->emtcxobj = objn; |
| 1243 |
prs->prscxemt->emtcxofs = 0; |
| 1244 |
|
| 1245 |
ERRBEGIN(ctx->dbgcxerr) |
| 1246 |
|
| 1247 |
|
| 1248 |
oldflg = prs->prscxflg; |
| 1249 |
prs->prscxflg &= ~(PRSCXFLIN + PRSCXFLCL); |
| 1250 |
|
| 1251 |
|
| 1252 |
prs->prscxtok->tokcxstab = &tab.toktfsc; |
| 1253 |
|
| 1254 |
|
| 1255 |
prsrstn(prs); |
| 1256 |
prs->prscxtok->tokcxlen = 0; |
| 1257 |
toknext(prs->prscxtok); |
| 1258 |
|
| 1259 |
|
| 1260 |
if (speculative) |
| 1261 |
prsxgen_spec(prs); |
| 1262 |
else |
| 1263 |
prsxgen(prs); |
| 1264 |
|
| 1265 |
|
| 1266 |
emtop(prs->prscxemt, OPCDBGRET); |
| 1267 |
|
| 1268 |
ERRCATCH(ctx->dbgcxerr, err) |
| 1269 |
|
| 1270 |
mcmunlck(prs->prscxmem, objn); |
| 1271 |
mcmfre(prs->prscxmem, objn); |
| 1272 |
|
| 1273 |
|
| 1274 |
prs->prscxflg = oldflg; |
| 1275 |
prs->prscxtok->tokcxstab = tab.toktfsc.toktnxt; |
| 1276 |
|
| 1277 |
return err; |
| 1278 |
ERREND(ctx->dbgcxerr) |
| 1279 |
|
| 1280 |
|
| 1281 |
prs->prscxflg = oldflg; |
| 1282 |
prs->prscxtok->tokcxstab = tab.toktfsc.toktnxt; |
| 1283 |
|
| 1284 |
mcmunlck(prs->prscxmem, objn); |
| 1285 |
*objnp = objn; |
| 1286 |
return 0; |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
int dbgeval(dbgcxdef *ctx, char *expr, |
| 1291 |
void (*dispfn)(void *, const char *, int), |
| 1292 |
void *dispctx, int level, |
| 1293 |
int showtype) |
| 1294 |
{ |
| 1295 |
|
| 1296 |
return dbgevalext(ctx, expr, dispfn, dispctx, level, showtype, 0, 0, 0, |
| 1297 |
FALSE); |
| 1298 |
} |
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
static void dbgenumprop(dbgcxdef *ctx, objnum objn, objnum self, |
| 1304 |
void (*func)(void *ctx, const char *propname, |
| 1305 |
int propnamelen, |
| 1306 |
const char *relationship), |
| 1307 |
void *cbctx) |
| 1308 |
{ |
| 1309 |
objdef *objptr; |
| 1310 |
int cnt; |
| 1311 |
prpdef *p; |
| 1312 |
int sccnt; |
| 1313 |
uchar *sc; |
| 1314 |
|
| 1315 |
|
| 1316 |
if (objn == MCMONINV) |
| 1317 |
return; |
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
if (vocinh(ctx->dbgcxrun->runcxvoc, objn) == 0) |
| 1324 |
return; |
| 1325 |
|
| 1326 |
|
| 1327 |
objptr = (objdef *)mcmlck(ctx->dbgcxmem, objn); |
| 1328 |
|
| 1329 |
|
| 1330 |
cnt = objnprop(objptr); |
| 1331 |
|
| 1332 |
|
| 1333 |
for (p = objprp(objptr) ; cnt != 0 ; p = objpnxt(p), --cnt) |
| 1334 |
{ |
| 1335 |
prpnum prpn; |
| 1336 |
char prpname[TOKNAMMAX + 1]; |
| 1337 |
int len; |
| 1338 |
objnum srcobj; |
| 1339 |
|
| 1340 |
|
| 1341 |
prpn = prpprop(p); |
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
switch(prptype(p)) |
| 1348 |
{ |
| 1349 |
case DAT_BASEPTR: |
| 1350 |
case DAT_CODE: |
| 1351 |
case DAT_DSTRING: |
| 1352 |
case DAT_TPL: |
| 1353 |
case DAT_DEMAND: |
| 1354 |
case DAT_SYN: |
| 1355 |
case DAT_REDIR: |
| 1356 |
case DAT_TPL2: |
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
continue; |
| 1362 |
} |
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
if (objn != self |
| 1371 |
&& (objgetap(ctx->dbgcxmem, self, prpn, &srcobj, FALSE) == 0 |
| 1372 |
|| srcobj != objn)) |
| 1373 |
continue; |
| 1374 |
|
| 1375 |
|
| 1376 |
len = dbgnam(ctx, prpname, TOKSTPROP, prpn); |
| 1377 |
|
| 1378 |
|
| 1379 |
(*func)(cbctx, prpname, len, "."); |
| 1380 |
} |
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
sccnt = objnsc(objptr); |
| 1387 |
for (sc = objsc(objptr) ; sccnt != 0 ; sc += 2, --sccnt) |
| 1388 |
{ |
| 1389 |
|
| 1390 |
dbgenumprop(ctx, (objnum)osrp2(sc), self, func, cbctx); |
| 1391 |
} |
| 1392 |
|
| 1393 |
|
| 1394 |
mcmunlck(ctx->dbgcxmem, objn); |
| 1395 |
} |
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
int dbgevalext(dbgcxdef *ctx, char *expr, |
| 1403 |
void (*dispfn)(void *, const char *, int), void *dispctx, |
| 1404 |
int level, int showtype, dattyp *dat, |
| 1405 |
void (*aggcb)(void *, const char *, int, const char *), |
| 1406 |
void *aggctx, int speculative) |
| 1407 |
{ |
| 1408 |
runsdef *oldsp; |
| 1409 |
runsdef val; |
| 1410 |
objnum objn; |
| 1411 |
uchar *objptr; |
| 1412 |
int err; |
| 1413 |
int oldfcn; |
| 1414 |
int olddep; |
| 1415 |
|
| 1416 |
|
| 1417 |
if ((err = dbgcompile(ctx, expr, &ctx->dbgcxfrm[level], &objn, |
| 1418 |
speculative)) != 0) |
| 1419 |
return err; |
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
oldfcn = ctx->dbgcxfcn; |
| 1427 |
olddep = ctx->dbgcxdep; |
| 1428 |
|
| 1429 |
ERRBEGIN(ctx->dbgcxerr) |
| 1430 |
|
| 1431 |
objptr = mcmlck(ctx->dbgcxmem, objn); |
| 1432 |
|
| 1433 |
|
| 1434 |
oldsp = ctx->dbgcxrun->runcxsp; |
| 1435 |
runexe(ctx->dbgcxrun, objptr, ctx->dbgcxfrm[level].dbgfself, |
| 1436 |
objn, (prpnum)0, 0); |
| 1437 |
|
| 1438 |
|
| 1439 |
if (ctx->dbgcxrun->runcxsp != oldsp) |
| 1440 |
{ |
| 1441 |
|
| 1442 |
runpop(ctx->dbgcxrun, &val); |
| 1443 |
|
| 1444 |
|
| 1445 |
dbgpval(ctx, &val, dispfn, dispctx, showtype); |
| 1446 |
(*dispfn)(dispctx, "\n", 1); |
| 1447 |
|
| 1448 |
|
| 1449 |
if (dat != 0) |
| 1450 |
*dat = val.runstyp; |
| 1451 |
} |
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
if (aggcb != 0) |
| 1459 |
{ |
| 1460 |
switch(val.runstyp) |
| 1461 |
{ |
| 1462 |
case DAT_OBJECT: |
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
dbgenumprop(ctx, val.runsv.runsvobj, val.runsv.runsvobj, |
| 1468 |
aggcb, aggctx); |
| 1469 |
break; |
| 1470 |
|
| 1471 |
case DAT_LIST: |
| 1472 |
{ |
| 1473 |
uchar *p; |
| 1474 |
uint rem; |
| 1475 |
uint idxcnt; |
| 1476 |
uint idx; |
| 1477 |
|
| 1478 |
|
| 1479 |
p = val.runsv.runsvstr; |
| 1480 |
rem = osrp2(p) - 2; |
| 1481 |
p += 2; |
| 1482 |
for (idxcnt = 0 ; rem != 0 ; ++idxcnt, lstadv(&p, &rem)) ; |
| 1483 |
|
| 1484 |
|
| 1485 |
for (idx = 1 ; idx <= idxcnt ; ++idx) |
| 1486 |
{ |
| 1487 |
char idxbuf[30]; |
| 1488 |
|
| 1489 |
|
| 1490 |
sprintf(idxbuf, "[%u]", idx); |
| 1491 |
|
| 1492 |
|
| 1493 |
(*aggcb)(aggctx, idxbuf, strlen(idxbuf), ""); |
| 1494 |
} |
| 1495 |
} |
| 1496 |
break; |
| 1497 |
} |
| 1498 |
} |
| 1499 |
|
| 1500 |
ERRCATCH(ctx->dbgcxerr, err) |
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
ctx->dbgcxfcn = oldfcn; |
| 1508 |
ctx->dbgcxdep = olddep; |
| 1509 |
|
| 1510 |
ERREND(ctx->dbgcxerr) |
| 1511 |
|
| 1512 |
|
| 1513 |
mcmunlck(ctx->dbgcxmem, objn); |
| 1514 |
mcmfre(ctx->dbgcxmem, objn); |
| 1515 |
|
| 1516 |
|
| 1517 |
return err; |
| 1518 |
} |
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
void dbgenumlcl(dbgcxdef *ctx, int level, |
| 1525 |
void (*func)(void *ctx, const char *lclnam, size_t lclnamlen), |
| 1526 |
void *cbctx) |
| 1527 |
{ |
| 1528 |
dbgfdef *fr; |
| 1529 |
mcmcxdef *mctx = ctx->dbgcxmem; |
| 1530 |
uchar *objp; |
| 1531 |
uint ofs; |
| 1532 |
uint encofs; |
| 1533 |
int err; |
| 1534 |
|
| 1535 |
|
| 1536 |
fr = &ctx->dbgcxfrm[level]; |
| 1537 |
|
| 1538 |
|
| 1539 |
if (fr->dbgftarg == MCMONINV) |
| 1540 |
return; |
| 1541 |
|
| 1542 |
ERRBEGIN(ctx->dbgcxerr) |
| 1543 |
|
| 1544 |
objp = mcmlck(mctx, fr->dbgftarg); |
| 1545 |
ERRCATCH(ctx->dbgcxerr, err) |
| 1546 |
|
| 1547 |
return; |
| 1548 |
ERREND(ctx->dbgcxerr) |
| 1549 |
|
| 1550 |
ERRBEGIN(ctx->dbgcxerr) |
| 1551 |
|
| 1552 |
for (ofs = fr->dbgffr ; ofs != 0 ; ofs = encofs) |
| 1553 |
{ |
| 1554 |
uchar *framep; |
| 1555 |
uint len; |
| 1556 |
|
| 1557 |
|
| 1558 |
framep = objp + ofs; |
| 1559 |
len = osrp2(framep) - 4; |
| 1560 |
encofs = osrp2(framep + 2); |
| 1561 |
framep += 4; |
| 1562 |
|
| 1563 |
|
| 1564 |
while (len != 0) |
| 1565 |
{ |
| 1566 |
uint symlen; |
| 1567 |
|
| 1568 |
|
| 1569 |
framep += 2; |
| 1570 |
symlen = *framep++; |
| 1571 |
len -= 3 + symlen; |
| 1572 |
|
| 1573 |
|
| 1574 |
(*func)(cbctx, (char *)framep, (size_t)symlen); |
| 1575 |
|
| 1576 |
|
| 1577 |
framep += symlen; |
| 1578 |
} |
| 1579 |
} |
| 1580 |
|
| 1581 |
ERRCATCH(ctx->dbgcxerr, err) |
| 1582 |
|
| 1583 |
ERREND(ctx->dbgcxerr) |
| 1584 |
|
| 1585 |
|
| 1586 |
mcmunlck(mctx, fr->dbgftarg); |
| 1587 |
} |
| 1588 |
|
| 1589 |
|
| 1590 |
int dbgwxset(dbgcxdef *ctx, char *expr, int *wxnum, int level) |
| 1591 |
{ |
| 1592 |
dbgwxdef *wx; |
| 1593 |
int i; |
| 1594 |
objnum objn; |
| 1595 |
int err; |
| 1596 |
uint oldflg; |
| 1597 |
|
| 1598 |
|
| 1599 |
while (t_isspace(*expr)) ++expr; |
| 1600 |
|
| 1601 |
|
| 1602 |
for (i = 0, wx = ctx->dbgcxwx ; i < DBGWXMAX ; ++wx, ++i) |
| 1603 |
if (!(wx->dbgwxflg & DBGWXFUSED)) break; |
| 1604 |
|
| 1605 |
if (i == DBGWXMAX) return ERR_MANYWX; |
| 1606 |
*wxnum = i + 1; |
| 1607 |
|
| 1608 |
|
| 1609 |
oldflg = ctx->dbgcxprs->prscxflg; |
| 1610 |
ctx->dbgcxprs->prscxflg |= PRSCXFWTCH; |
| 1611 |
err = dbgcompile(ctx, expr, &ctx->dbgcxfrm[level], &objn, FALSE); |
| 1612 |
ctx->dbgcxprs->prscxflg = oldflg; |
| 1613 |
if (err) |
| 1614 |
return err; |
| 1615 |
|
| 1616 |
|
| 1617 |
wx->dbgwxobj = objn; |
| 1618 |
wx->dbgwxflg = DBGWXFUSED; |
| 1619 |
wx->dbgwxself = ctx->dbgcxfrm[level].dbgfself; |
| 1620 |
if (!dbgnamsav(ctx, expr, &wx->dbgwxnam)) wx->dbgwxflg |= DBGWXFNAME; |
| 1621 |
|
| 1622 |
return 0; |
| 1623 |
} |
| 1624 |
|
| 1625 |
|
| 1626 |
int dbgwxdel(dbgcxdef *ctx, int wxnum) |
| 1627 |
{ |
| 1628 |
dbgwxdef *wx = &ctx->dbgcxwx[--wxnum]; |
| 1629 |
|
| 1630 |
|
| 1631 |
if (wxnum < 0 || wxnum > DBGWXMAX || !(wx->dbgwxflg & DBGWXFUSED)) |
| 1632 |
return ERR_WXNSET; |
| 1633 |
|
| 1634 |
mcmfre(ctx->dbgcxmem, wx->dbgwxobj); |
| 1635 |
wx->dbgwxflg &= ~DBGWXFUSED; |
| 1636 |
if (wx->dbgwxflg & DBGWXFNAME) |
| 1637 |
dbgnamdel(ctx, wx->dbgwxnam); |
| 1638 |
|
| 1639 |
return 0; |
| 1640 |
} |
| 1641 |
|
| 1642 |
|
| 1643 |
void dbgwxupd(dbgcxdef *ctx, void (*dispfn)(void *, const char *, int), |
| 1644 |
void *dispctx) |
| 1645 |
{ |
| 1646 |
int i; |
| 1647 |
dbgwxdef *wx; |
| 1648 |
int err; |
| 1649 |
uchar *objptr; |
| 1650 |
runsdef *oldsp; |
| 1651 |
runsdef val; |
| 1652 |
char buf[50]; |
| 1653 |
int first = TRUE; |
| 1654 |
|
| 1655 |
|
| 1656 |
outwx(1); |
| 1657 |
|
| 1658 |
for (i = 0, wx = ctx->dbgcxwx ; i < DBGWXMAX ; ++wx, ++i) |
| 1659 |
{ |
| 1660 |
if (!(wx->dbgwxflg & DBGWXFUSED)) continue; |
| 1661 |
|
| 1662 |
|
| 1663 |
if (!first) (*dispfn)(dispctx, "\n", 1); |
| 1664 |
else first = FALSE; |
| 1665 |
|
| 1666 |
sprintf(buf, "[%d] %s = ", i + 1, ctx->dbgcxnam + wx->dbgwxnam); |
| 1667 |
(*dispfn)(dispctx, buf, (int)strlen(buf)); |
| 1668 |
|
| 1669 |
|
| 1670 |
objptr = mcmlck(ctx->dbgcxmem, wx->dbgwxobj); |
| 1671 |
|
| 1672 |
ERRBEGIN(ctx->dbgcxerr) |
| 1673 |
|
| 1674 |
oldsp = ctx->dbgcxrun->runcxsp; |
| 1675 |
runexe(ctx->dbgcxrun, objptr, wx->dbgwxself, wx->dbgwxobj, |
| 1676 |
(prpnum)0, 0); |
| 1677 |
|
| 1678 |
if (ctx->dbgcxrun->runcxsp != oldsp) |
| 1679 |
{ |
| 1680 |
runpop(ctx->dbgcxrun, &val); |
| 1681 |
dbgpval(ctx, &val, dispfn, dispctx, FALSE); |
| 1682 |
} |
| 1683 |
else |
| 1684 |
(*dispfn)(dispctx, "<no value>", 10); |
| 1685 |
|
| 1686 |
ERRCATCH(ctx->dbgcxerr, err) |
| 1687 |
if (err == ERR_INACTFR) |
| 1688 |
(*dispfn)(dispctx, "<not available>", 15); |
| 1689 |
else |
| 1690 |
{ |
| 1691 |
sprintf(buf, "<error %d>", err); |
| 1692 |
(*dispfn)(dispctx, buf, (int)strlen(buf)); |
| 1693 |
} |
| 1694 |
ERREND(ctx->dbgcxerr) |
| 1695 |
|
| 1696 |
mcmunlck(ctx->dbgcxmem, wx->dbgwxobj); |
| 1697 |
} |
| 1698 |
|
| 1699 |
|
| 1700 |
outwx(0); |
| 1701 |
} |
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
runsdef *dbgfrfind(dbgcxdef *ctx, objnum frobj, uint frofs) |
| 1710 |
{ |
| 1711 |
int i; |
| 1712 |
dbgfdef *f; |
| 1713 |
mcmon objn; |
| 1714 |
uchar *objptr; |
| 1715 |
uint ofs; |
| 1716 |
|
| 1717 |
|
| 1718 |
for (i = ctx->dbgcxfcn, f = &ctx->dbgcxfrm[i-1] ; i ; --f, --i) |
| 1719 |
{ |
| 1720 |
|
| 1721 |
objn = f->dbgftarg; |
| 1722 |
if (frobj != objn) continue; |
| 1723 |
|
| 1724 |
|
| 1725 |
objptr = mcmlck(ctx->dbgcxmem, objn); |
| 1726 |
|
| 1727 |
for (ofs = f->dbgffr ; ofs ; ) |
| 1728 |
{ |
| 1729 |
if (ofs == frofs) |
| 1730 |
{ |
| 1731 |
|
| 1732 |
mcmunlck(ctx->dbgcxmem, objn); |
| 1733 |
return f->dbgfbp; |
| 1734 |
} |
| 1735 |
|
| 1736 |
|
| 1737 |
ofs = osrp2(objptr + ofs + 2); |
| 1738 |
} |
| 1739 |
|
| 1740 |
|
| 1741 |
mcmunlck(ctx->dbgcxmem, objn); |
| 1742 |
} |
| 1743 |
|
| 1744 |
|
| 1745 |
errsig(ctx->dbgcxerr, ERR_INACTFR); |
| 1746 |
NOTREACHEDV(runsdef *); |
| 1747 |
return 0; |
| 1748 |
} |
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
void dbgswitch(lindef **linp, lindef *newlin) |
| 1757 |
{ |
| 1758 |
if (*linp) lindisact(*linp); |
| 1759 |
if (newlin) linactiv(newlin); |
| 1760 |
*linp = newlin; |
| 1761 |
} |
| 1762 |
|