@henols/c64-re-tools 2.6.0-rc.12 → 2.6.0-rc.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henols/c64-re-tools",
3
- "version": "2.6.0-rc.12",
3
+ "version": "2.6.0-rc.13",
4
4
  "description": "Agent-friendly Commodore 64 engineering toolkit for reverse engineering, debugging, development and testing.",
5
5
  "license": "MIT",
6
6
  "author": "Henrik Olsson",
@@ -251,7 +251,7 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
251
251
  - `body.lines` has `count` and `listed`. `listed` holds one line for each instruction of a code region, and one `!byte` line for other bytes.
252
252
  - Each line has `address`, `bytes`, `text`, `referencesIn` and `referencesOut`. It can also have `label`, `analyzerNames`, `lineComments` and `comment`. `lineComments` are the line comments before the line. `comment` is the side comment.
253
253
  - `text` is the instruction with the names of its target. An operand expression of the knowledge replaces the operand.
254
- - When the knowledge has coverage, `access` tells if a run executed (`x`), read (`r`) or wrote (`w`) the bytes of the line, or `-` for none. An `r` on code can come from a read of the 6502 that the program does not do, for example the byte after an RTS or the opcode at the PC when an interrupt starts.
254
+ - `access` is there when the knowledge has coverage. It tells if a run executed (`x`), read (`r`) or wrote (`w`) the bytes of the line. `-` tells that no run did. An `r` on code can come from a read of the 6502 that the program does not do. Examples are the byte after an RTS and the opcode after a branch that the CPU takes. Another example is the opcode at the PC when an interrupt starts.
255
255
  - With `--out`, the body has `lines` as a number, and `out`, `bytes` and `sha256` of the text file.
256
256
  - If the knowledge has no program in the space, the script refuses. Put the program in with `image` first.
257
257
  - Use `listing` in place of your own disassembler.
@@ -201,7 +201,7 @@ A leftover is a range of the program that nothing uses: unused code, old copies
201
201
  - `main.asm` builds a leftover file only when `LEFTOVERS` is 1. When it is 0, the build skips the bytes. Thus the addresses after the range do not change.
202
202
  - `config.asm` has `LEFTOVERS = 0`. Thus the default build is the clean program, without the leftovers.
203
203
  - Each release has `LEFTOVERS = 1`. Thus the build of a release gives the bytes of the release.
204
- - The loader program never has the leftovers. The plain form does not copy them, and the memory there keeps the bytes that were in it before. The packed form unpacks the build of `main.asm` in one piece, so the leftovers are $00.
204
+ - The loader program never has the leftovers. The plain form does not copy them, and the memory there keeps the bytes that were in it before. The packed form unpacks the build of `main.asm` in one piece, so the leftovers in it are $00. A leftover after the last byte of that build is not in it: the memory there keeps the bytes that were in it before.
205
205
  - Without coverage, no range is a leftover. Put the coverage of the runs into the project knowledge. Then generate again.
206
206
  - When `leftovers.changed` has ranges, the default build and the loader program now leave out other bytes. A test that observes the `added` bytes on the loader program gets other values there. Fill the `added` ranges in the test of the leftovers. In a test that compares them, exclude them with the reason that they are leftovers.
207
207
  - A leftover can be wrong when the coverage does not show a use. For example, the VIC-II reads a range, or the program reads a range before it writes it. Then a test of the loader program fails. Record the region in the project knowledge, or put the coverage of more runs into it. Do not change the source.
@@ -102,7 +102,7 @@ The script records only structure: code and data regions, analyzer names, and th
102
102
 
103
103
  `body` holds these fields for both analyzers:
104
104
 
105
- - `analyzer`: `dxa` or `ghidra`. `space` is in `body` only for a space that is not `c64`.
105
+ - `analyzer`: `dxa` or `ghidra`. `analyzerVersion` gives the version of the analyzer when the analyzer tells it. `space` is in `body` only for a space that is not `c64`.
106
106
  - `revision`: the revision of the findings, or `null` when the knowledge did not change.
107
107
  - `coverage`: the ranges that the analyzer examined.
108
108
  - `changes`: for analyzer names (`names`), `regions` and `references`, the counts `added`, `changed`, `retired`, `unchanged` and `suppressed`. `suppressed` counts the findings that the script did not record, because the user or the LLM removed a fact at that place. `references.inData` counts the references that the script did not record, because they start in a data region of the user, the LLM or a heuristic. The analyzer decoded these data bytes as code. `symbols.retired` counts the old symbols of the analyzer that became analyzer names.
@@ -130,6 +130,7 @@ The `hint` gives each of these cases:
130
130
  - `conflicts` is not empty. Find the correct answer in the emulator. Then correct the project knowledge.
131
131
  - `coverageConflicts` is not empty. Classify each range as code in the project knowledge, or as `dual-use` when its bytes are also data. For many ranges, write all classifications in one batch of changes.
132
132
  - `idioms.candidates.macros` has candidates, and the run had no `--apply-macros`. Examine the candidates. To write the correct candidates to the project knowledge, run the analysis again with `--apply-macros`. Give `--skip` with the start of each candidate that is not correct. Then generate the source again.
133
+ - The last analysis of the same program bytes used another analyzer version. Thus a change in `revision` can come from the new analyzer, and not from the program or the project knowledge.
133
134
  - A list is cut. Give a larger `--max-listed`. The project knowledge has all `labels` and `functions` as analyzer names.
134
135
 
135
136
  There is no `nextAction`.
@@ -15,7 +15,7 @@ import { GHIDRA_LIMITS } from "#src/native/types.ts";
15
15
  import { openForRead, withWrite } from "#src/knowledge/database.ts";
16
16
  import { analyzedBytes, operandImages, programCoverage, requireProgram } from "#src/knowledge/program.ts";
17
17
  import { applyBatch, type BatchOperation } from "#src/knowledge/write.ts";
18
- import { importFindings, runProvenance, type ImportConflict, type ImportContext, type ImportResult, type NormalizedFindings } from "#src/knowledge/import.ts";
18
+ import { importFindings, lastToolVersion, runProvenance, type ImportConflict, type ImportContext, type ImportResult, type NormalizedFindings } from "#src/knowledge/import.ts";
19
19
  import { currentRevision, listMacros, listMacroUses, listPatches, listReferences, listRegions, listSymbols } from "#src/knowledge/read.ts";
20
20
  import { DEFAULT_SPACE, SEMANTIC_ORIGINS, type Analyzer } from "#src/knowledge/schema.ts";
21
21
  import { platformNames, platformNamesFor, romUseOfProgram, type RomUse } from "#src/platform.ts";
@@ -36,8 +36,11 @@ const ALL_NAMES = "a larger --max-listed. The project knowledge has all of them
36
36
  * analyzer data over executed code to classify, and macro candidates to write.
37
37
  * The envelope adds the sentence for a cut list.
38
38
  */
39
- function withHint(body: Record<string, unknown>, conflicts: number, coverageConflicts: number, macros: { candidates: number; applied: boolean; revision: string | null | undefined }) {
39
+ function withHint(body: Record<string, unknown>, conflicts: number, coverageConflicts: number, macros: { candidates: number; applied: boolean; revision: string | null | undefined }, version: { now: string | undefined; last: string | undefined; revision: string | null }) {
40
40
  const hints: string[] = [];
41
+ if (version.revision !== null && version.now !== undefined && version.last !== undefined && version.now !== version.last) {
42
+ hints.push(`The last analysis of this program used ${version.last}. Thus a change in revision ${version.revision} can come from the new analyzer version, and not from the program or the project knowledge.`);
43
+ }
41
44
  if (conflicts > 0) hints.push("The analysis and the project knowledge disagree at each place in conflicts. Find the correct answer in the emulator. Then correct the project knowledge.");
42
45
  if (coverageConflicts > 0) hints.push("The coverage shows executed code in each range of coverageConflicts. Classify each range as code, or as dual-use when its bytes are also data, in the project knowledge.");
43
46
  if (typeof macros.revision === "string") hints.push("The project knowledge has the macro candidates now. Generate the source again.");
@@ -222,6 +225,8 @@ async function analyze(call: Call): Promise<unknown> {
222
225
  const coverageUsed = fromCoverage.filter((entry) => seeds.entryPoints.includes(entry) || codeStarts.includes(entry)).length;
223
226
  // Platform names are C64 names: drive code and banks get none.
224
227
  const platform = space === DEFAULT_SPACE ? platformNames() : [];
228
+ /** The analyzer version of the last analysis of these bytes: a new version can change the findings by itself. */
229
+ const lastVersion = reader === undefined ? undefined : lastToolVersion(reader, analyzer, bytes);
225
230
  reader?.close();
226
231
  /** Imports the idioms as their own revision, after the analyzer's, and gives their part of the result. */
227
232
  const idiomsResult = () => {
@@ -298,6 +303,7 @@ async function analyze(call: Call): Promise<unknown> {
298
303
  const found = idiomsResult();
299
304
  const body = {
300
305
  analyzer: "dxa",
306
+ ...(result.toolVersion === undefined ? {} : { analyzerVersion: result.toolVersion }),
301
307
  ...(space === DEFAULT_SPACE ? {} : { space }),
302
308
  ...found,
303
309
  ...coverageResult(),
@@ -307,7 +313,7 @@ async function analyze(call: Call): Promise<unknown> {
307
313
  labels: listed(result.labels, max, (label) => ({ address: formatC64Address(label.address), name: label.name }), ALL_NAMES),
308
314
  ...(written === undefined ? {} : { listing: written }),
309
315
  };
310
- return withHint(body, imported.conflicts.length + found.idioms.conflicts.length, body.coverageConflicts?.length ?? 0, { candidates: found.idioms.candidates.macros.count, applied: applyMacros, revision: found.idioms.candidates.macros.revision });
316
+ return withHint(body, imported.conflicts.length + found.idioms.conflicts.length, body.coverageConflicts?.length ?? 0, { candidates: found.idioms.candidates.macros.count, applied: applyMacros, revision: found.idioms.candidates.macros.revision }, { now: result.toolVersion, last: lastVersion, revision: imported.revision });
311
317
  }
312
318
 
313
319
  const { result } = await analyzeWithGhidra({ imageKind, ...seeds, codeStarts, decompile }, bytes, localToolContext());
@@ -328,6 +334,7 @@ async function analyze(call: Call): Promise<unknown> {
328
334
  }
329
335
  const body = {
330
336
  analyzer: "ghidra",
337
+ ...(result.toolVersion === undefined ? {} : { analyzerVersion: result.toolVersion }),
331
338
  ...(space === DEFAULT_SPACE ? {} : { space }),
332
339
  ...(instructions === undefined ? {} : { instructions }),
333
340
  ...found,
@@ -341,7 +348,7 @@ async function analyze(call: Call): Promise<unknown> {
341
348
  ? {}
342
349
  : { notDecompiled: result.notDecompiled!.map((item) => ({ entry: formatC64Address(item.entry), reason: item.reason })) }),
343
350
  };
344
- return withHint(body, imported.conflicts.length + found.idioms.conflicts.length, body.coverageConflicts?.length ?? 0, { candidates: found.idioms.candidates.macros.count, applied: applyMacros, revision: found.idioms.candidates.macros.revision });
351
+ return withHint(body, imported.conflicts.length + found.idioms.conflicts.length, body.coverageConflicts?.length ?? 0, { candidates: found.idioms.candidates.macros.count, applied: applyMacros, revision: found.idioms.candidates.macros.revision }, { now: result.toolVersion, last: lastVersion, revision: imported.revision });
345
352
  }
346
353
 
347
354
  await runScript({
@@ -207,7 +207,7 @@ The script does the steps of the record file on the original program. Then it wr
207
207
 
208
208
  Do this for each result:
209
209
 
210
- - `PASS`: `hint` tells you to commit the folder and to add its `coverage.bin` to the project knowledge as coverage. `nextAction` replays the recording on the original. Run it to make sure that the recording replays.
210
+ - `PASS`: for a folder in `tests/recordings/`, `hint` tells you to commit the folder and to add its `coverage.bin` to the project knowledge as coverage. Git ignores `.c64-re-tools/local/`, thus the project knowledge must not name a file in it. For a folder there, `hint` tells you to record again with `--out tests/recordings/<name>`. `nextAction` replays the recording on the original. Run it to make sure that the recording replays.
211
211
  - `FAIL` after a cancel on the page: `hint` tells you to ask the user what to do. Do not record a session from steps in place of the session of the user.
212
212
  - Another `FAIL`: `reason` names the step that did not complete. Examples are a `runUntil` step that did not get to its target, and a `type` step with too many keys. Change the step, then run `record` again.
213
213
  - `coverageFrom` is `null` and `executed` is 0: the coverage did not start, so the coverage map is empty. The recording can still replay.
@@ -107,11 +107,11 @@ async function recordCommand(call: Call): Promise<Reply> {
107
107
  ];
108
108
  // A recording in the local folder is a work file: git ignores it, so it is no test.
109
109
  const keep = projectRelative(out).startsWith(`${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/`)
110
- ? `Git ignores ${out}. To keep the recording as a test, record again with --out tests/recordings/<name>.`
111
- : `Commit ${out} with the scenarios.`;
110
+ ? `Git ignores ${out}. To keep the recording as a test and to add its coverage to the project knowledge, record again with --out tests/recordings/<name>.`
111
+ : `Commit ${out} with the scenarios. Add ${out}/${RECORDING_FILES.coverage} to the project knowledge as coverage.`;
112
112
  return reply(
113
113
  { result: "PASS", recorded: true, out, ...summary, files },
114
- { hint: `${keep} Add ${out}/${RECORDING_FILES.coverage} to the project knowledge as coverage. ${summary.coverageFrom === null ? "The coverage did not start: the map is empty." : "The map has no marks for the code that ran before coverageFrom."} To make sure that the recording replays, run nextAction.`, nextAction: call.next("replay", out) },
114
+ { hint: `${keep} ${summary.coverageFrom === null ? "The coverage did not start: the map is empty." : "The map has no marks for the code that ran before coverageFrom."} To make sure that the recording replays, run nextAction.`, nextAction: call.next("replay", out) },
115
115
  );
116
116
  } finally {
117
117
  await core.close();
@@ -69,6 +69,13 @@ export function runProvenance(image: Uint8Array, toolVersion: string | undefined
69
69
  return toolVersion === undefined ? { inputHash } : { inputHash, toolVersion };
70
70
  }
71
71
 
72
+ /** The version of the analyzer in its last revision of these image bytes: undefined when it has none, or when that revision does not tell it. */
73
+ export function lastToolVersion(db: DatabaseSync, analyzer: Analyzer, image: Uint8Array): string | undefined {
74
+ const { inputHash } = runProvenance(image, undefined);
75
+ const row = db.prepare("SELECT tool_version FROM revisions WHERE origin = ? AND input_hash = ? ORDER BY id DESC LIMIT 1").get(analyzer, inputHash!) as { tool_version: string | null } | undefined;
76
+ return row?.tool_version ?? undefined;
77
+ }
78
+
72
79
  export type ImportConflict =
73
80
  | {
74
81
  category: "symbol";