()
| 285 | } |
| 286 | |
| 287 | private async getMemoryRegions() { |
| 288 | if (this.memoryRegions) { |
| 289 | return; |
| 290 | } |
| 291 | try { |
| 292 | await this.setArchitecture(); |
| 293 | this.memoryRegions = []; |
| 294 | const miNode = await this.miDebugger.sendCommand('interpreter-exec console "info mem"', false, true); |
| 295 | const str = miNode.output; |
| 296 | let match: RegExpExecArray; |
| 297 | const regex = RegExp(/^[0-9]+\s+([^\s])\s+(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+)\s+([^\r\n]*)/mgi); |
| 298 | // Num Enb Low Addr High Addr Attrs |
| 299 | // 1 y 0x10000000 0x10100000 flash blocksize 0x200 nocache |
| 300 | while (match = regex.exec(str)) { |
| 301 | const [flag, lowAddr, highAddr, attrsStr] = match.slice(1, 5); |
| 302 | if (flag === 'y') { |
| 303 | const nHighAddr = parseInt(highAddr); |
| 304 | const nlowAddr = parseInt(lowAddr); |
| 305 | const attrs = attrsStr.split(/\s+/g); |
| 306 | const name = `GdbInfo${this.memoryRegions.length}`; |
| 307 | this.memoryRegions.push(new MemoryRegion({ |
| 308 | name: match[1], |
| 309 | size: nHighAddr - nlowAddr, // size |
| 310 | vmaStart: nlowAddr, // vma |
| 311 | lmaStart: nlowAddr, // lma |
| 312 | vmaStartOrig: nlowAddr, |
| 313 | attrs: attrs |
| 314 | })); |
| 315 | } |
| 316 | } |
| 317 | } catch (e) { |
| 318 | this.handleMsg('log', `Error: ${e.toString()}`); |
| 319 | } |
| 320 | const fromGdb = this.memoryRegions.length; |
| 321 | // There is a caveat here. Adding regions from executables is not reliable when you have PIC |
| 322 | // (Position Independent Code) -- so far have not seen such a thing but it is possible |
| 323 | this.memoryRegions = this.memoryRegions.concat(this.gdbSession.symbolTable.memoryRegions); |
| 324 | |
| 325 | if (this.memoryRegions.length > 0) { |
| 326 | this.handleMsg('log', 'Note: We detected the following memory regions as valid using gdb "info mem" and "objdump -h"\n'); |
| 327 | this.handleMsg('log', ' This information is used to adjust bounds only when normal disassembly fails.\n'); |
| 328 | const hdrs = ['Size', 'VMA Beg', 'VMA End', 'LMA Beg', 'LMA End'].map((x: string) => x.padStart(10)); |
| 329 | const line = ''.padEnd(80, '=') + '\n'; |
| 330 | this.handleMsg('stdout', line); |
| 331 | this.handleMsg('stdout', ' Using following memory regions for disassembly\n'); |
| 332 | this.handleMsg('stdout', line); |
| 333 | this.handleMsg('stdout', hdrs.join('') + ' Attributes\n'); |
| 334 | this.handleMsg('stdout', line); |
| 335 | let count = 0; |
| 336 | for (const r of this.memoryRegions) { |
| 337 | if (count++ === fromGdb) { |
| 338 | if (fromGdb === 0) { |
| 339 | this.handleMsg('stdout', ' Unfortunately, No memory information from gdb (or gdb-server). Will try to manage without\n'); |
| 340 | } |
| 341 | this.handleMsg('stdout', ' '.padEnd(80, '-') + '\n'); |
| 342 | } |
| 343 | const vals = [r.size, r.vmaStart, r.vmaEnd - 1, r.lmaStart, r.lmaEnd - 1].map((v) => hexFormat(v, 8, false).padStart(10)); |
| 344 | if (r.vmaStart === r.lmaStart) { |
no test coverage detected