Download tools/dbg3.mjs from HelloSun/esp32emu: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/HelloSun/esp32emu/resolve/main/tools/dbg3.mjs
- Command line
-
hf download hf://spaces/HelloSun/esp32emu/tools/dbg3.mjs
-
curl -L -o dbg3.mjs https://huggingface.co/spaces/HelloSun/esp32emu/resolve/main/tools/dbg3.mjs
1.6 kB
| import fs from 'fs'; | |
| import { ESP32 } from '../web/js/soc.js'; | |
| const [,, flash, disFile, n = '80'] = process.argv; | |
| const romDir = new URL('../web/rom/', import.meta.url).pathname; | |
| const soc = new ESP32({}); | |
| soc.loadRoms(fs.readFileSync(romDir + 'esp32-v3-rom.bin'), fs.readFileSync(romDir + 'esp32-v3-rom-app.bin')); | |
| soc.setFlash(fs.readFileSync(flash)); | |
| soc.enablePsram(process.argv.includes('--psram')); | |
| soc.onUart = (n, b) => process.stdout.write(String.fromCharCode(b)); | |
| soc.reset('power'); | |
| const c = soc.cpus[0]; | |
| const map = new Map(); const lab = new Map(); | |
| for (const f of [disFile, '/tmp/opencode/rom_pro.dis']) { let cur = ''; for (const l of fs.readFileSync(f, 'utf8').split('\n')) { const lm = l.match(/^([0-9a-f]{8}) <(.*)>:/); if (lm) { cur = lm[2]; continue; } const m = l.match(/^\s*([0-9a-f]{8}):\s*(.*)$/); if (m && !map.has(parseInt(m[1], 16))) { map.set(parseInt(m[1], 16), m[2]); lab.set(parseInt(m[1], 16), f.includes('rom_pro') ? 'ROM' : cur); } } } | |
| c.trace = []; | |
| soc.requestReset = function(k){ throw new Error('RESET '+k); }; | |
| c.exception = function (pc, cause, va) { throw new Error('EXC ' + pc.toString(16) + ' cause ' + cause + ' va ' + (va >>> 0).toString(16)); }; | |
| try { for (let k = 0; k < 4000000; k++) { soc.run(100); if (c.trace.length > 5e6) c.trace = c.trace.slice(-1000); } } catch (e) { console.log(e.message); } | |
| const tr = c.trace.slice(-parseInt(n)); | |
| let lastL=''; console.log(tr.map(p => { const L = lab.get(p>>>0)||''; const pre = L!==lastL ? ' <'+L+'>\n' : ''; lastL=L; return pre + (p >>> 0).toString(16) + ': ' + (map.get(p >>> 0) || '?'); }).join('\n')); | |