dsh-stm32 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -29
- package/README_EN.md +125 -29
- package/client/client.js +682 -0
- package/docs/development-notes.md +1385 -5
- package/docs/logic-audit.md +607 -0
- package/docs/reading-guide.md +738 -0
- package/lib/client.js +682 -0
- package/lib/commands/register.js +214 -12
- package/lib/data/chips.js +134 -4
- package/lib/data/clock-f1.js +158 -0
- package/lib/data/cmsis-sources.js +316 -0
- package/lib/data/f1-ram.generated.js +34 -0
- package/lib/data/firmware-packages.js +352 -0
- package/lib/data/install-guides.js +190 -0
- package/lib/data/search-roots.js +135 -15
- package/lib/data/stm32f1.js +186 -0
- package/lib/data/toolchain-config.js +310 -0
- package/lib/engine/build.js +121 -16
- package/lib/engine/cache.js +336 -0
- package/lib/engine/clock-plan.js +608 -0
- package/lib/engine/cmake-sources.js +428 -0
- package/lib/engine/code-patch.js +18 -6
- package/lib/engine/debug-session.js +163 -4
- package/lib/engine/debug.js +84 -19
- package/lib/engine/doctor.js +395 -4
- package/lib/engine/fetch.js +287 -0
- package/lib/engine/firmware-install.js +668 -0
- package/lib/engine/flash.js +145 -15
- package/lib/engine/fs-longpath.js +107 -0
- package/lib/engine/generate-cache.js +118 -0
- package/lib/engine/generate-script.js +30 -8
- package/lib/engine/generate.js +296 -14
- package/lib/engine/hal-chip.js +230 -0
- package/lib/engine/ioc-plan.js +47 -8
- package/lib/engine/msys2-install.js +1870 -0
- package/lib/engine/probe.js +57 -6
- package/lib/engine/project-export.js +129 -0
- package/lib/engine/register-clock.js +132 -0
- package/lib/engine/register-linker.js +129 -0
- package/lib/engine/register-template.js +449 -0
- package/lib/engine/regs.js +18 -4
- package/lib/engine/route-plan.js +553 -0
- package/lib/engine/scaffold.js +303 -72
- package/lib/engine/subprocess-runner.js +2 -0
- package/lib/engine/tar.js +250 -0
- package/lib/engine/text-file.js +150 -0
- package/lib/engine/thirdparty.js +243 -0
- package/lib/engine/tool-env.js +51 -0
- package/lib/engine/toolchain-gate.js +386 -0
- package/lib/engine/vscode-config.js +99 -0
- package/lib/engine/web-api.js +375 -0
- package/lib/engine/web-routes.js +100 -0
- package/lib/engine/xcube-catalog.js +102 -0
- package/lib/engine/xcube.js +254 -0
- package/lib/engine/zip.js +142 -0
- package/lib/index.js +44 -2
- package/lib/skill/stm32-workflow.js +3 -3
- package/lib/tools/build.js +55 -3
- package/lib/tools/cache.js +250 -0
- package/lib/tools/code-patch.js +29 -2
- package/lib/tools/debug-session.js +56 -14
- package/lib/tools/debug.js +43 -2
- package/lib/tools/doctor.js +16 -3
- package/lib/tools/env-install.js +472 -0
- package/lib/tools/env-probe.js +6 -2
- package/lib/tools/firmware-install.js +255 -0
- package/lib/tools/flash.js +41 -2
- package/lib/tools/generate.js +96 -10
- package/lib/tools/ioc-apply.js +27 -11
- package/lib/tools/ioc-inspect.js +4 -2
- package/lib/tools/ioc-plan.js +209 -11
- package/lib/tools/project-create.js +229 -21
- package/lib/tools/project-dir.js +95 -0
- package/lib/tools/project-export.js +100 -0
- package/lib/tools/regs.js +82 -7
- package/lib/tools/route-plan.js +467 -0
- package/package.json +11 -4
- package/templates/register/CMakeLists.txt +52 -0
- package/templates/register/Core/Src/main.c +72 -0
- package/templates/scaffold/openocd.cfg +8 -0
- package/templates/scaffold/vscode/launch.json +8 -6
- package/templates/scaffold/vscode/settings.json +5 -11
|
@@ -14,13 +14,70 @@ import { existsSync } from "node:fs";
|
|
|
14
14
|
import { resolveSearchConfig } from "../data/search-roots.js";
|
|
15
15
|
import { pickPort, resolveElfPath } from "./debug.js";
|
|
16
16
|
import { defaultConfigs, findProjectConfig, toOpenOcdPath } from "./flash.js";
|
|
17
|
-
import {
|
|
17
|
+
import { resolveToolIn } from "./probe.js";
|
|
18
18
|
import { runCapture } from "./subprocess-runner.js";
|
|
19
19
|
import { waitForListening } from "./debug.js";
|
|
20
20
|
const DEFAULT_IDLE_TTL_MS = 90_000;
|
|
21
21
|
const DEFAULT_HARD_TTL_MS = 10 * 60_000;
|
|
22
22
|
const SWEEP_MS = 5_000;
|
|
23
23
|
const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
24
|
+
/** 把 "0x4001100c" / "4001100C" 统一成 8 位小写 0x 形式;解析不了返回 null。 */
|
|
25
|
+
export function normalizeHexAddress(text) {
|
|
26
|
+
const body = text.trim().replace(/^0x/iu, "");
|
|
27
|
+
if (!/^[0-9a-f]{1,8}$/iu.test(body))
|
|
28
|
+
return null;
|
|
29
|
+
return "0x" + body.toLowerCase().padStart(8, "0");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 从 gdb 输出里按出现顺序取 print/x 打印的十六进制值(形如 $1 = 0x4001100c)。
|
|
33
|
+
*
|
|
34
|
+
* gdb 只在成功打印时输出 `$N = 0x...`,被拒绝的表达式留一行 Cannot access memory,
|
|
35
|
+
* 所以"少了一个"正好表示那个地址没读到。
|
|
36
|
+
*/
|
|
37
|
+
export function parseGdbPrintedHex(output) {
|
|
38
|
+
const values = [];
|
|
39
|
+
for (const match of output.matchAll(/\$\d+\s*=\s*(0x[0-9a-fA-F]+)/gu)) {
|
|
40
|
+
const value = match[1];
|
|
41
|
+
if (value !== undefined)
|
|
42
|
+
values.push(value.toLowerCase());
|
|
43
|
+
}
|
|
44
|
+
return values;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 按 gdb 的 echo 分段标记取回每个地址的值(审计 A7)。
|
|
48
|
+
*
|
|
49
|
+
* 老做法是按 `$N = 0x...` 的出现顺序对齐地址,但失败的命令只打一行
|
|
50
|
+
* "Cannot access memory at address ..."、不产生 `$N`,于是中间有一个地址读失败,
|
|
51
|
+
* 后面所有值就整体前移、张冠李戴,报告里还标着 ok=true。
|
|
52
|
+
* 现在每个地址前面先 echo 一个 ===DSH:<address>=== 标记,值只在它自己那一段里找。
|
|
53
|
+
*/
|
|
54
|
+
export function parseMarkedWords(output, addresses) {
|
|
55
|
+
const values = new Map();
|
|
56
|
+
let pc = "";
|
|
57
|
+
const marks = [];
|
|
58
|
+
for (const match of output.matchAll(/===DSH:([A-Za-z0-9_.]+)===/gu)) {
|
|
59
|
+
const tag = match[1];
|
|
60
|
+
if (tag === undefined)
|
|
61
|
+
continue;
|
|
62
|
+
const start = match.index ?? 0;
|
|
63
|
+
marks.push({ tag, start, end: start + match[0].length });
|
|
64
|
+
}
|
|
65
|
+
for (let index = 0; index < marks.length; index += 1) {
|
|
66
|
+
const mark = marks[index];
|
|
67
|
+
const next = marks[index + 1];
|
|
68
|
+
const segment = output.slice(mark.end, next === undefined ? output.length : next.start);
|
|
69
|
+
const printed = /\$\d+\s*=\s*(0x[0-9a-fA-F]+)/u.exec(segment);
|
|
70
|
+
const value = printed === null ? "" : printed[1].toLowerCase();
|
|
71
|
+
if (mark.tag === "PC") {
|
|
72
|
+
if (pc === "" && value !== "")
|
|
73
|
+
pc = value;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (value !== "" && !values.has(mark.tag))
|
|
77
|
+
values.set(mark.tag, value);
|
|
78
|
+
}
|
|
79
|
+
return { pc, values };
|
|
80
|
+
}
|
|
24
81
|
function emptyReport(errors, message) {
|
|
25
82
|
return {
|
|
26
83
|
ok: false, active: false, sessionId: "", port: 0, projectDir: "", elfPath: "",
|
|
@@ -93,7 +150,7 @@ export class DebugSessionManager {
|
|
|
93
150
|
}
|
|
94
151
|
const projectDir = request.projectDir;
|
|
95
152
|
const config = resolveSearchConfig(process.env, request.binDirs === undefined ? {} : { binDirs: request.binDirs });
|
|
96
|
-
const openOcd =
|
|
153
|
+
const openOcd = await resolveToolIn(subprocess, ["openocd"], config.binDirs);
|
|
97
154
|
if (openOcd === null)
|
|
98
155
|
return emptyReport(["找不到 openocd(先跑 stm32_env_probe)"], "没开会话:找不到 openocd");
|
|
99
156
|
// 符号表在这里解析:调用方(工具层、e2e、以后可能的 CLI)都不用自己找 .elf。
|
|
@@ -131,6 +188,7 @@ export class DebugSessionManager {
|
|
|
131
188
|
hardTtlMs: request.hardTtlMs ?? DEFAULT_HARD_TTL_MS,
|
|
132
189
|
logText: "",
|
|
133
190
|
binDirs: config.binDirs,
|
|
191
|
+
owner: request.owner ?? "",
|
|
134
192
|
};
|
|
135
193
|
const listening = await waitForListening(handle, 15_000, (text) => {
|
|
136
194
|
session.logText += text + "\n";
|
|
@@ -175,7 +233,7 @@ export class DebugSessionManager {
|
|
|
175
233
|
for (const dirs of searchDirs) {
|
|
176
234
|
if (dirs.length === 0)
|
|
177
235
|
continue;
|
|
178
|
-
gdb =
|
|
236
|
+
gdb = await resolveToolIn(this.subprocess, ["gdb-multiarch", "arm-none-eabi-gdb"], dirs);
|
|
179
237
|
if (gdb !== null)
|
|
180
238
|
break;
|
|
181
239
|
}
|
|
@@ -230,8 +288,109 @@ export class DebugSessionManager {
|
|
|
230
288
|
message: errors.length === 0 ? "执行完成(" + String(this.now() - startedAt) + " ms)" : "执行有问题:" + errors[0],
|
|
231
289
|
};
|
|
232
290
|
}
|
|
233
|
-
|
|
291
|
+
/**
|
|
292
|
+
* 借正在跑的调试会话(它已经占着 openocd + CMSIS-DAP)读 32 位字。
|
|
293
|
+
*
|
|
294
|
+
* 为什么要借:再起一个 openocd 会抢同一块探针,实测报
|
|
295
|
+
* "CMSIS-DAP transfer count mismatch: expected 3, got 2"。所以有会话时一律走 gdb 表达式
|
|
296
|
+
* (print/x $pc + 每地址 print/x *(unsigned int *)0x...),halt 之后 resume,芯片照原样继续跑。
|
|
297
|
+
*/
|
|
298
|
+
async readWords(request) {
|
|
299
|
+
const startedAt = this.now();
|
|
234
300
|
const session = this.current;
|
|
301
|
+
if (session === null) {
|
|
302
|
+
return {
|
|
303
|
+
ok: false, sessionId: "", port: 0, projectDir: "", command: "", pc: "", samples: [],
|
|
304
|
+
durationMs: 0, output: "",
|
|
305
|
+
errors: ["没有调试会话(先 stm32_debug_session,或短任务用 stm32_debug_run)"],
|
|
306
|
+
message: "没读:没有调试会话",
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
const addresses = [];
|
|
310
|
+
const bad = [];
|
|
311
|
+
for (const raw of request.addresses) {
|
|
312
|
+
const normalized = normalizeHexAddress(raw);
|
|
313
|
+
if (normalized === null)
|
|
314
|
+
bad.push(raw);
|
|
315
|
+
else
|
|
316
|
+
addresses.push(normalized);
|
|
317
|
+
}
|
|
318
|
+
if (addresses.length === 0) {
|
|
319
|
+
return {
|
|
320
|
+
ok: false, sessionId: session.id, port: session.port, projectDir: session.projectDir,
|
|
321
|
+
command: "", pc: "", samples: [], durationMs: this.now() - startedAt, output: "",
|
|
322
|
+
errors: ["没有可读的地址" + (bad.length === 0 ? "" : "(解析不了:" + bad.join("、") + ")")],
|
|
323
|
+
message: "没读:地址不合法",
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
const commands = ["echo ===DSH:PC===", "print/x $pc"];
|
|
327
|
+
for (const address of addresses) {
|
|
328
|
+
commands.push("echo ===DSH:" + address + "===");
|
|
329
|
+
commands.push("print/x *(unsigned int *)" + address);
|
|
330
|
+
}
|
|
331
|
+
const evaluated = await this.eval({
|
|
332
|
+
commands,
|
|
333
|
+
...(request.timeoutMs === undefined ? {} : { timeoutMs: request.timeoutMs }),
|
|
334
|
+
...(request.signal === undefined ? {} : { signal: request.signal }),
|
|
335
|
+
});
|
|
336
|
+
const marked = parseMarkedWords(evaluated.output, addresses);
|
|
337
|
+
const values = new Map(marked.values);
|
|
338
|
+
let pc = marked.pc;
|
|
339
|
+
if (marked.pc === "" && marked.values.size === 0) {
|
|
340
|
+
// 极老的 gdb 可能不认 echo:退回按顺序对齐(老行为,可能错位),至少不让工具整体失败。
|
|
341
|
+
const printed = parseGdbPrintedHex(evaluated.output);
|
|
342
|
+
pc = printed[0] ?? "";
|
|
343
|
+
addresses.forEach((address, index) => {
|
|
344
|
+
const value = printed[index + 1];
|
|
345
|
+
if (value !== undefined)
|
|
346
|
+
values.set(address, value);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
const samples = addresses.map((address) => {
|
|
350
|
+
const value = values.get(address);
|
|
351
|
+
return value === undefined || value === "" ? { address, value: "", ok: false } : { address, value, ok: true };
|
|
352
|
+
});
|
|
353
|
+
const missing = samples.filter((sample) => !sample.ok).length;
|
|
354
|
+
const errors = [...evaluated.errors];
|
|
355
|
+
for (const raw of bad)
|
|
356
|
+
errors.push("地址解析不了:" + raw);
|
|
357
|
+
if (missing > 0)
|
|
358
|
+
errors.push("有 " + String(missing) + " 个地址没读到值(地址没映射或没对齐)");
|
|
359
|
+
if (pc === "")
|
|
360
|
+
errors.push("没读到 pc");
|
|
361
|
+
const ok = evaluated.ok && missing === 0 && pc !== "";
|
|
362
|
+
return {
|
|
363
|
+
ok,
|
|
364
|
+
sessionId: session.id,
|
|
365
|
+
port: session.port,
|
|
366
|
+
projectDir: session.projectDir,
|
|
367
|
+
command: evaluated.command,
|
|
368
|
+
pc,
|
|
369
|
+
samples,
|
|
370
|
+
durationMs: this.now() - startedAt,
|
|
371
|
+
output: evaluated.output,
|
|
372
|
+
errors,
|
|
373
|
+
message: ok
|
|
374
|
+
? "从调试会话(端口 " + String(session.port) + ")读了 " + String(samples.length) + " 个值"
|
|
375
|
+
: "读失败:" + (errors[0] ?? "未知原因"),
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* 关会话。options.requireOwner 给定时,只有 owner 对得上才关(审计 A9)。
|
|
380
|
+
*
|
|
381
|
+
* 原来 turn/end 一到就无条件关,多 agent 并行时会把别人正在用的探针收走;
|
|
382
|
+
* 现在监听方带上自己的 agent id,不属于自己的会话就不动。owner 未知(空串)时按老行为处理。
|
|
383
|
+
*/
|
|
384
|
+
async stop(reason, options = {}) {
|
|
385
|
+
const session = this.current;
|
|
386
|
+
const required = options.requireOwner ?? "";
|
|
387
|
+
if (session !== null && required !== "" && session.owner !== "" && session.owner !== required) {
|
|
388
|
+
return {
|
|
389
|
+
ok: true,
|
|
390
|
+
stopped: false,
|
|
391
|
+
message: "没关:这个会话是另一个调用方起的(" + session.owner + "),不动它(" + reason + ")",
|
|
392
|
+
};
|
|
393
|
+
}
|
|
235
394
|
this.current = null;
|
|
236
395
|
this.stopSweeper();
|
|
237
396
|
if (session === null)
|
package/lib/engine/debug.js
CHANGED
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { existsSync, statSync } from "node:fs";
|
|
9
9
|
import { createConnection } from "node:net";
|
|
10
|
-
import { isAbsolute, resolve } from "node:path";
|
|
10
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
11
11
|
import { resolveSearchConfig } from "../data/search-roots.js";
|
|
12
|
-
import { detectBuildDir, findElf } from "./build.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
12
|
+
import { detectBuildDir, elfSelectionNote, findElf } from "./build.js";
|
|
13
|
+
import { usbDiagnosis } from "./doctor.js";
|
|
14
|
+
import { HINT_BUSY, HINT_DP, HINT_PROBE, defaultConfigs, errorCodeOfLines, findProjectConfig, probeMissingLines, quoteForDisplay, toOpenOcdPath, usbNoteFor, } from "./flash.js";
|
|
15
|
+
import { resolveToolIn } from "./probe.js";
|
|
15
16
|
import { runStreaming } from "./subprocess-runner.js";
|
|
16
17
|
const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
17
18
|
/** 端口是否被占用(openocd 默认 3333 常被用户自己的调试会话占着)。 */
|
|
@@ -37,7 +38,6 @@ export async function pickPort(preferred = 3333) {
|
|
|
37
38
|
}
|
|
38
39
|
return preferred;
|
|
39
40
|
}
|
|
40
|
-
const REGISTER_NAMES = ["pc", "sp", "lr", "xpsr"];
|
|
41
41
|
/** 从 gdb -batch 输出里抠出断点位置、寄存器、调用栈。 */
|
|
42
42
|
export function parseGdbOutput(text) {
|
|
43
43
|
const errors = [];
|
|
@@ -76,10 +76,6 @@ export function parseGdbOutput(text) {
|
|
|
76
76
|
if (/^(Remote communication error|Cannot access memory|No symbol|error:|\.gdbinit)/iu.test(line))
|
|
77
77
|
errors.push(line);
|
|
78
78
|
}
|
|
79
|
-
for (const name of REGISTER_NAMES) {
|
|
80
|
-
if (!registers.some((item) => item.name === name))
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
79
|
return { hitBreakpoint, location, registers, backtrace, locals, errors };
|
|
84
80
|
}
|
|
85
81
|
/** 等 openocd 打出 "Listening on port"(或超时)。 */
|
|
@@ -120,6 +116,38 @@ export async function waitForListening(handle, timeoutMs, onText) {
|
|
|
120
116
|
drain();
|
|
121
117
|
return { ok: false, text };
|
|
122
118
|
}
|
|
119
|
+
/** 失败时 log tail 的优先级:Error/adapter 那几行比"最后 15 行"有用得多。 */
|
|
120
|
+
function keyLogTail(lines, maxLines) {
|
|
121
|
+
const important = /error|unable to find|no device found|adapter|cmsis-dap|listening|couldn't bind|jtag|cannot/i;
|
|
122
|
+
const kept = new Set();
|
|
123
|
+
for (let index = lines.length - 1; index >= 0 && kept.size < maxLines; index -= 1) {
|
|
124
|
+
const line = lines[index];
|
|
125
|
+
if (line === undefined)
|
|
126
|
+
continue;
|
|
127
|
+
if (important.test(line))
|
|
128
|
+
kept.add(index);
|
|
129
|
+
}
|
|
130
|
+
for (let index = lines.length - 1; index >= 0 && kept.size < maxLines; index -= 1)
|
|
131
|
+
kept.add(index);
|
|
132
|
+
return [...kept].sort((left, right) => left - right).map((index) => lines[index]).join("\n");
|
|
133
|
+
}
|
|
134
|
+
/** errorCode → 一句给人看的下一步。 */
|
|
135
|
+
function debugHintFor(code) {
|
|
136
|
+
if (code === "no-probe")
|
|
137
|
+
return HINT_PROBE;
|
|
138
|
+
if (code === "probe-busy")
|
|
139
|
+
return HINT_BUSY;
|
|
140
|
+
if (code === "swd-locked")
|
|
141
|
+
return HINT_DP;
|
|
142
|
+
if (code === "no-power")
|
|
143
|
+
return "目标板可能没供电:检查 3V3/GND 与 BOOT 跳线。";
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
/** 日志里第一条真正说明问题的行(给 message 用,避免只报"起不来")。 */
|
|
147
|
+
function firstProblemLine(lines) {
|
|
148
|
+
const hit = lines.find((line) => /^Error|unable to find|no device found|couldn't bind|cannot open|invalid/i.test(line));
|
|
149
|
+
return (hit ?? lines[lines.length - 1] ?? "").trim();
|
|
150
|
+
}
|
|
123
151
|
export async function runDebugRun(subprocess, request) {
|
|
124
152
|
const projectDir = resolve(request.projectDir);
|
|
125
153
|
const config = resolveSearchConfig(process.env, request.binDirs === undefined ? {} : { binDirs: request.binDirs });
|
|
@@ -136,10 +164,13 @@ export async function runDebugRun(subprocess, request) {
|
|
|
136
164
|
errors.push("找不到 .elf(先跑 stm32_build)");
|
|
137
165
|
return { ...empty, message: "没调试:找不到 .elf", durationMs: Date.now() - startedAt };
|
|
138
166
|
}
|
|
167
|
+
const selectionNote = elfSelectionNote(dirname(elfPath));
|
|
168
|
+
if (selectionNote !== "")
|
|
169
|
+
notes.push(selectionNote);
|
|
139
170
|
const openOcd = request.openOcdPath !== undefined && request.openOcdPath !== ""
|
|
140
171
|
? request.openOcdPath
|
|
141
|
-
:
|
|
142
|
-
const gdb =
|
|
172
|
+
: await resolveToolIn(subprocess, ["openocd"], config.binDirs);
|
|
173
|
+
const gdb = await resolveToolIn(subprocess, ["gdb-multiarch", "arm-none-eabi-gdb"], config.binDirs);
|
|
143
174
|
if (openOcd === null || gdb === null) {
|
|
144
175
|
errors.push(openOcd === null ? "找不到 openocd" : "找不到 gdb(gdb-multiarch 或 arm-none-eabi-gdb)");
|
|
145
176
|
return { ...empty, elfPath, message: "没调试:缺工具链(先跑 stm32_env_probe)", durationMs: Date.now() - startedAt };
|
|
@@ -174,13 +205,26 @@ export async function runDebugRun(subprocess, request) {
|
|
|
174
205
|
request.onProgress?.(text);
|
|
175
206
|
});
|
|
176
207
|
if (!listening.ok) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
208
|
+
// F2:旧版只回"openocd 起不来"+15 行尾巴,真正的 adapter init 失败常被挤掉。
|
|
209
|
+
// 现在先归类(与 flash 同一套规则),再把有信息量的行留下,并顺手做一次 USB 形态诊断。
|
|
210
|
+
const lines = listening.text.split(/\r?\n/u).filter((line) => line.trim() !== "");
|
|
211
|
+
const errorCode = errorCodeOfLines(lines);
|
|
212
|
+
const hint = debugHintFor(errorCode);
|
|
213
|
+
if (hint !== null)
|
|
214
|
+
notes.push(hint);
|
|
215
|
+
if (probeMissingLines(lines).length > 0) {
|
|
216
|
+
const usb = await usbDiagnosis(subprocess, request.signal);
|
|
217
|
+
const extra = usbNoteFor(usb.kind, usb.detail);
|
|
218
|
+
if (extra !== null)
|
|
219
|
+
notes.push(extra);
|
|
220
|
+
}
|
|
221
|
+
const problem = firstProblemLine(lines);
|
|
222
|
+
errors.push("openocd 起不来(errorCode=" + (errorCode === "" ? "unknown" : errorCode) + "):" +
|
|
223
|
+
(problem === "" ? "15 s 内没开始监听 " + String(port) : problem));
|
|
181
224
|
return {
|
|
182
|
-
...empty, elfPath, port, openOcdLogTail:
|
|
183
|
-
message: "没调试:openocd 起不来"
|
|
225
|
+
...empty, elfPath, port, openOcdLogTail: keyLogTail(lines, 40), errorCode,
|
|
226
|
+
message: "没调试:openocd 起不来" + (errorCode === "" ? "" : "(" + errorCode + ")"),
|
|
227
|
+
durationMs: Date.now() - startedAt,
|
|
184
228
|
};
|
|
185
229
|
}
|
|
186
230
|
const breakAt = request.breakAt ?? "main";
|
|
@@ -227,7 +271,13 @@ export async function runDebugRun(subprocess, request) {
|
|
|
227
271
|
errors.push("gdb 超时(" + String(request.timeoutMs ?? 45_000) + " ms):断点没命中或目标没在跑");
|
|
228
272
|
if (gdbOutcome.exitCode !== 0)
|
|
229
273
|
errors.push("gdb 退出码 " + String(gdbOutcome.exitCode));
|
|
230
|
-
const
|
|
274
|
+
const allLines = [...openOcdText.split(/\r?\n/u), ...gdbText.split(/\r?\n/u)].filter((line) => line.trim() !== "");
|
|
275
|
+
// A26:ok 必须和 errors 一致 —— 退出码非 0、gdb 报的错(Cannot access memory 之类)都不算成功。
|
|
276
|
+
const ok = gdbOutcome.spawnError === null
|
|
277
|
+
&& !gdbOutcome.timedOut
|
|
278
|
+
&& gdbOutcome.exitCode === 0
|
|
279
|
+
&& probe.errors.length === 0
|
|
280
|
+
&& (breakAt === "none" || probe.hitBreakpoint);
|
|
231
281
|
if (ok)
|
|
232
282
|
notes.push("已在 " + (probe.location === "" ? breakAt : probe.location) + " 停住并抓过快照;收尾是 monitor reset run + detach,芯片现在自由运行,探针已释放");
|
|
233
283
|
if (!ok && probe.hitBreakpoint)
|
|
@@ -235,6 +285,20 @@ export async function runDebugRun(subprocess, request) {
|
|
|
235
285
|
if (breakAt !== "none" && !probe.hitBreakpoint && errors.length === 0) {
|
|
236
286
|
errors.push("没有停在 " + breakAt + ":可能是复位后没跑到这里,或符号对不上(.elf 与板上的固件不一致)");
|
|
237
287
|
}
|
|
288
|
+
// F2:失败时给结构化错误码 + 可执行提示(成功时留空,报告不带噪音)。
|
|
289
|
+
let errorCode = "";
|
|
290
|
+
if (!ok) {
|
|
291
|
+
errorCode = errorCodeOfLines(allLines);
|
|
292
|
+
const hint = debugHintFor(errorCode);
|
|
293
|
+
if (hint !== null)
|
|
294
|
+
notes.push(hint);
|
|
295
|
+
if (errorCode === "no-probe" && probeMissingLines(allLines).length > 0) {
|
|
296
|
+
const usb = await usbDiagnosis(subprocess, request.signal);
|
|
297
|
+
const extra = usbNoteFor(usb.kind, usb.detail);
|
|
298
|
+
if (extra !== null)
|
|
299
|
+
notes.push(extra);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
238
302
|
return {
|
|
239
303
|
ok,
|
|
240
304
|
projectDir,
|
|
@@ -248,7 +312,8 @@ export async function runDebugRun(subprocess, request) {
|
|
|
248
312
|
locals: probe.locals,
|
|
249
313
|
gdbCommand,
|
|
250
314
|
gdbOutput: gdbText,
|
|
251
|
-
openOcdLogTail:
|
|
315
|
+
openOcdLogTail: keyLogTail(allLines, 40),
|
|
316
|
+
...(errorCode === "" ? {} : { errorCode }),
|
|
252
317
|
durationMs: Date.now() - startedAt,
|
|
253
318
|
errors,
|
|
254
319
|
message: ok
|