MCPcopy Create free account
hub / github.com/Marus/cortex-debug / doWork

Method doWork

src/backend/disasm.ts:503–558  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

501 let iter = 0;
502 const maxTries = Math.ceil((this.maxInstrSize - this.minInstrSize) / this.instrMultiple);
503 const doWork = () => {
504 const old = this.findInCache(startAddress, endAddress);
505 if (old) {
506 const foundIx = old.findInstrIndex(validationAddr);
507 if (foundIx < 0) {
508 const msg = `Bad instruction cache. Could not find address ${validationAddr} that should have been found`;
509 this.handleMsg('log', msg + '\n');
510 resolve(new Error(msg));
511 } else {
512 resolve(new DisassemblyReturn(old.instructions, foundIx));
513 }
514 return;
515 }
516
517 const entireRangeGood = range.isKnownStart || this.isRangeInValidMem(startAddress, endAddress);
518 const end = endAddress;
519 // const end = range.isData ? endAddress : this.clipHigh(endAddress, endAddress + this.maxInstrSize); // Get a bit more for functions
520 let cmd: string;
521 cmd = `data-disassemble -s ${hexFormat(startAddress)} -e ${hexFormat(end)} -- 5`;
522 if (this.doTiming) {
523 const symName = range.symNode ? ` (${range.symNode.symbol.name})` : '';
524 const count = `${end - startAddress} bytes`.padStart(15);
525 this.handleMsg('log', `Debug: Gdb command: -${cmd}${count} ${symName}\n`);
526 }
527 this.miDebugger.sendCommand(cmd, false, false, true).then((result) => {
528 try {
529 const ret = this.parseDisassembleResults(result, validationAddr, entireRangeGood, cmd);
530 const foundIx = ret.foundAt;
531 if (foundIx < 0) {
532 if (GdbDisassembler.debug) {
533 const msg = `Could not disassemble at this address Looking for ${hexFormat(validationAddr)}: ${cmd} `;
534 console.log(msg, ret.instructions);
535 }
536 if ((startAddress >= this.instrMultiple) && (iter < maxTries)) {
537 iter++;
538 startAddress -= this.instrMultiple; // Try again with this address
539 doWork();
540 } else {
541 const msg = `Error: Could not disassemble at this address ${hexFormat(validationAddr)} ` + JSON.stringify(args);
542 this.handleMsg('log', msg + '\n');
543 resolve(new Error(msg));
544 }
545 } else {
546 const instrRange = new InstructionRange(ret.instructions);
547 this.addToCache(instrRange);
548 resolve(ret);
549 }
550 }
551 catch (e) {
552 resolve(e);
553 }
554 }, (e) => {
555 this.handleMsg('log', `Error: GDB failed: ${e.toString()}\n`);
556 resolve(e);
557 });
558 };
559 doWork();
560 });

Callers

nothing calls this directly

Calls 10

findInCacheMethod · 0.95
handleMsgMethod · 0.95
isRangeInValidMemMethod · 0.95
addToCacheMethod · 0.95
hexFormatFunction · 0.90
findInstrIndexMethod · 0.80
sendCommandMethod · 0.80
logMethod · 0.80
toStringMethod · 0.80

Tested by

no test coverage detected