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

Method disassembleProtocolRequest2

src/backend/disasm.ts:667–805  ·  view source on GitHub ↗
(
        response: DebugProtocol.DisassembleResponse,
        args: DebugProtocol.DisassembleArguments,
        request?: DebugProtocol.Request)

Source from the content-addressed store, hash-verified

665 }
666
667 private disassembleProtocolRequest2(
668 response: DebugProtocol.DisassembleResponse,
669 args: DebugProtocol.DisassembleArguments,
670 request?: DebugProtocol.Request): Promise<void>
671 {
672 return new Promise(async (resolve, reject) => {
673 try {
674 await this.getMemoryRegions();
675 const seq = request?.seq;
676 if (GdbDisassembler.debug) {
677 this.handleMsg('log', `Debug-${seq}: Dequeuing...\n`);
678 console.log('disassembleRequest: ', args);
679 }
680
681 const baseAddress = parseInt(args.memoryReference);
682 const offset = args.offset || 0;
683 const instrOffset = args.instructionOffset || 0;
684 const timer = this.doTiming ? new HrTimer() : undefined;
685
686 if (offset !== 0) {
687 throw (new Error('VSCode using non-zero disassembly offset? Don\'t know how to handle this yet. Please report this problem'));
688 }
689 const startAddr = Math.max(0, Math.min(baseAddress, baseAddress + (instrOffset * this.maxInstrSize)));
690 const endAddr = baseAddress + (args.instructionCount + instrOffset) * this.maxInstrSize;
691 // this.handleMsg('log', 'Start: ' + ([startAddr, baseAddress, baseAddress - startAddr].map((x) => hexFormat(x))).join(',') + '\n');
692 // this.handleMsg('log', 'End : ' + ([baseAddress, endAddr, endAddr - baseAddress].map((x) => hexFormat(x))).join(',') + '\n');
693
694 const ranges = this.findDisasmRanges(startAddr, endAddr, baseAddress);
695 const promises = ranges.map((r) => this.getProtocolDisassembly(r, args));
696 const instrRanges = await Promise.all(promises);
697 const orig = Array.from(instrRanges);
698 // Remove all Error items from front and back
699 while ((instrRanges.length > 0) && !(instrRanges[0] instanceof DisassemblyReturn)) {
700 instrRanges.shift();
701 ranges.shift();
702 }
703 while ((instrRanges.length > 0) && !(instrRanges[instrRanges.length - 1] instanceof DisassemblyReturn)) {
704 instrRanges.pop();
705 ranges.pop();
706 }
707 if (instrRanges.length === 0) {
708 throw new Error(`Disassembly failed completely for ${hexFormat(startAddr)} - ${hexFormat(endAddr)}`);
709 }
710 let all: InstructionRange;
711 for (const r of instrRanges) {
712 const range = ranges.shift();
713 if (!(r instanceof DisassemblyReturn)) {
714 throw new Error(`Disassembly failed completely for ${hexFormat(range.qStart)} - ${hexFormat(range.qEnd)}`);
715 }
716 const tmp = new InstructionRange((r as DisassemblyReturn).instructions);
717 if (!all) {
718 all = tmp;
719 } else {
720 all.forceMerge(tmp);
721 }
722 }
723
724 let instrs = all.instructions;

Callers 1

runDisasmRequestMethod · 0.95

Calls 12

getMemoryRegionsMethod · 0.95
handleMsgMethod · 0.95
findDisasmRangesMethod · 0.95
hexFormatFunction · 0.90
logMethod · 0.80
forceMergeMethod · 0.80
findInstrIndexMethod · 0.80
createPaddedMsMethod · 0.80
toStringMethod · 0.80
sendErrorResponsePubMethod · 0.80

Tested by

no test coverage detected