warpo 3.0.0 → 3.1.0
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/dist/debug_server/debugSession.d.ts +17 -1
- package/dist/debug_server/debugSession.js +169 -7
- package/dist/debug_server/debugSession.js.map +1 -1
- package/dist/debug_server/debugger.d.ts +25 -0
- package/dist/debug_server/debugger.js +4 -0
- package/dist/debug_server/debugger.js.map +1 -0
- package/dist/debug_server/debuggerWasmModule.d.ts +28 -0
- package/dist/debug_server/debuggerWasmModule.js +75 -0
- package/dist/debug_server/debuggerWasmModule.js.map +1 -0
- package/dist/debug_server/nodeDebugger.d.ts +27 -0
- package/dist/debug_server/nodeDebugger.js +240 -0
- package/dist/debug_server/nodeDebugger.js.map +1 -0
- package/dist/debug_server/tests/debugSession.test.js +45 -1
- package/dist/debug_server/tests/debugSession.test.js.map +1 -1
- package/dist/debug_server/tests/testModule/debugger_basic.d.ts +1 -0
- package/dist/debug_server/tests/testModule/debugger_basic.js +6 -0
- package/dist/debug_server/tests/testModule/debugger_basic.js.map +1 -0
- package/dist/debug_server/wasmEntry.js +36 -0
- package/dist/debug_server/wasmEntry.js.map +1 -0
- package/dist/heap_analyzer/src/comparison.d.ts +2 -0
- package/dist/heap_analyzer/src/comparison.js +77 -0
- package/dist/heap_analyzer/src/comparison.js.map +1 -0
- package/dist/heap_analyzer/src/constants.d.ts +1 -1
- package/dist/heap_analyzer/src/constants.js +1 -1
- package/dist/heap_analyzer/src/debugInfoResolver.d.ts +30 -0
- package/dist/heap_analyzer/src/debugInfoResolver.js +334 -0
- package/dist/heap_analyzer/src/debugInfoResolver.js.map +1 -0
- package/dist/heap_analyzer/src/dumpReader.js +11 -2
- package/dist/heap_analyzer/src/dumpReader.js.map +1 -1
- package/dist/heap_analyzer/src/dwarfParser.d.ts +30 -9
- package/dist/heap_analyzer/src/dwarfParser.js +54 -20
- package/dist/heap_analyzer/src/dwarfParser.js.map +1 -1
- package/dist/heap_analyzer/src/index.d.ts +7 -0
- package/dist/heap_analyzer/src/index.js +16 -0
- package/dist/heap_analyzer/src/index.js.map +1 -0
- package/dist/heap_analyzer/src/referenceScanner.d.ts +4 -4
- package/dist/heap_analyzer/src/referenceScanner.js +52 -21
- package/dist/heap_analyzer/src/referenceScanner.js.map +1 -1
- package/dist/heap_analyzer/src/roots.d.ts +3 -6
- package/dist/heap_analyzer/src/roots.js +12 -5
- package/dist/heap_analyzer/src/roots.js.map +1 -1
- package/dist/heap_analyzer/src/snapshot.d.ts +2 -2
- package/dist/heap_analyzer/src/snapshot.js +36 -88
- package/dist/heap_analyzer/src/snapshot.js.map +1 -1
- package/dist/heap_analyzer/src/types.d.ts +54 -11
- package/dist/heap_analyzer/src/types.js +22 -1
- package/dist/heap_analyzer/src/types.js.map +1 -1
- package/dist/heap_analyzer/tests/comparison.test.d.ts +1 -0
- package/dist/heap_analyzer/tests/comparison.test.js +121 -0
- package/dist/heap_analyzer/tests/comparison.test.js.map +1 -0
- package/dist/heap_analyzer/tests/debugInfoResolver.test.d.ts +1 -0
- package/dist/heap_analyzer/tests/debugInfoResolver.test.js +205 -0
- package/dist/heap_analyzer/tests/debugInfoResolver.test.js.map +1 -0
- package/dist/heap_analyzer/tests/dumpReader.test.js +12 -2
- package/dist/heap_analyzer/tests/dumpReader.test.js.map +1 -1
- package/dist/heap_analyzer/tests/dwarfParser.test.js +40 -28
- package/dist/heap_analyzer/tests/dwarfParser.test.js.map +1 -1
- package/dist/heap_analyzer/tests/roots.test.js +21 -4
- package/dist/heap_analyzer/tests/roots.test.js.map +1 -1
- package/dist/heap_analyzer/tests/snapshot.test.js +58 -54
- package/dist/heap_analyzer/tests/snapshot.test.js.map +1 -1
- package/dist/heap_analyzer/tests/testHelper.js +1 -1
- package/dist/heap_analyzer/tests/testHelper.js.map +1 -1
- package/dist/heap_analyzer/tests/wasmExecutor.js +2 -1
- package/dist/heap_analyzer/tests/wasmExecutor.js.map +1 -1
- package/dist/scripts/lib.d.ts +5 -1
- package/dist/scripts/lib.js +171 -24
- package/dist/scripts/lib.js.map +1 -1
- package/dist/test_runner/core/compiler.js +0 -1
- package/dist/test_runner/core/compiler.js.map +1 -1
- package/dist/warpo.d.ts +12 -1
- package/dist/warpo.js +32 -7
- package/dist/warpo.js.map +1 -1
- package/dist/warpo_internal.d.ts +1 -1
- package/dist/warpo_internal.js +23 -14
- package/dist/warpo_internal.js.map +1 -1
- package/package.json +9 -1
- package/dist/heap_analyzer/src/classResolver.d.ts +0 -34
- package/dist/heap_analyzer/src/classResolver.js +0 -206
- package/dist/heap_analyzer/src/classResolver.js.map +0 -1
- package/dist/heap_analyzer/tests/classResolver.test.js +0 -110
- package/dist/heap_analyzer/tests/classResolver.test.js.map +0 -1
- /package/dist/{heap_analyzer/tests/classResolver.test.d.ts → debug_server/wasmEntry.d.ts} +0 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { it } from "node:test";
|
|
3
|
+
import { compareSnapshots } from "../src/comparison.js";
|
|
4
|
+
it("returns no constructor rows when two snapshots are identical", () => {
|
|
5
|
+
const snapshot = createSnapshot(1024, [createConstructor("Foo", [createInstance(100, 32, 64)])]);
|
|
6
|
+
assert.deepStrictEqual(compareSnapshots(snapshot, snapshot), {
|
|
7
|
+
beforeTotalHeapSize: 1024,
|
|
8
|
+
afterTotalHeapSize: 1024,
|
|
9
|
+
totalHeapSizeDelta: 0,
|
|
10
|
+
beforeTotalLiveSize: 32,
|
|
11
|
+
afterTotalLiveSize: 32,
|
|
12
|
+
totalLiveSizeDelta: 0,
|
|
13
|
+
constructors: [],
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
it("aggregates constructor diffs and keeps only changed instances", () => {
|
|
17
|
+
const before = createSnapshot(1024, [
|
|
18
|
+
createConstructor("Foo", [createInstance(100, 32, 64), createInstance(101, 16, 16)]),
|
|
19
|
+
createConstructor("Bar", [createInstance(200, 24, 24)]),
|
|
20
|
+
]);
|
|
21
|
+
const after = createSnapshot(1152, [
|
|
22
|
+
createConstructor("Foo", [createInstance(101, 16, 16), createInstance(102, 48, 80)]),
|
|
23
|
+
createConstructor("Baz", [createInstance(300, 40, 40)]),
|
|
24
|
+
]);
|
|
25
|
+
assert.deepStrictEqual(compareSnapshots(before, after), {
|
|
26
|
+
beforeTotalHeapSize: 1024,
|
|
27
|
+
afterTotalHeapSize: 1152,
|
|
28
|
+
totalHeapSizeDelta: 128,
|
|
29
|
+
beforeTotalLiveSize: 72,
|
|
30
|
+
afterTotalLiveSize: 104,
|
|
31
|
+
totalLiveSizeDelta: 32,
|
|
32
|
+
constructors: [
|
|
33
|
+
{
|
|
34
|
+
className: "Baz",
|
|
35
|
+
newCount: 1,
|
|
36
|
+
deletedCount: 0,
|
|
37
|
+
countDelta: 1,
|
|
38
|
+
allocatedSize: 40,
|
|
39
|
+
freedSize: 0,
|
|
40
|
+
sizeDelta: 40,
|
|
41
|
+
instances: [
|
|
42
|
+
{
|
|
43
|
+
address: 300,
|
|
44
|
+
shallowSize: 40,
|
|
45
|
+
retainedSize: 40,
|
|
46
|
+
changeKind: "new",
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
className: "Foo",
|
|
52
|
+
newCount: 1,
|
|
53
|
+
deletedCount: 1,
|
|
54
|
+
countDelta: 0,
|
|
55
|
+
allocatedSize: 48,
|
|
56
|
+
freedSize: 32,
|
|
57
|
+
sizeDelta: 16,
|
|
58
|
+
instances: [
|
|
59
|
+
{
|
|
60
|
+
address: 102,
|
|
61
|
+
shallowSize: 48,
|
|
62
|
+
retainedSize: 80,
|
|
63
|
+
changeKind: "new",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
address: 100,
|
|
67
|
+
shallowSize: 32,
|
|
68
|
+
retainedSize: 64,
|
|
69
|
+
changeKind: "delete",
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
className: "Bar",
|
|
75
|
+
newCount: 0,
|
|
76
|
+
deletedCount: 1,
|
|
77
|
+
countDelta: -1,
|
|
78
|
+
allocatedSize: 0,
|
|
79
|
+
freedSize: 24,
|
|
80
|
+
sizeDelta: -24,
|
|
81
|
+
instances: [
|
|
82
|
+
{
|
|
83
|
+
address: 200,
|
|
84
|
+
shallowSize: 24,
|
|
85
|
+
retainedSize: 24,
|
|
86
|
+
changeKind: "delete",
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
it("treats same-address instances as unchanged even if sizes differ", () => {
|
|
94
|
+
const before = createSnapshot(1024, [createConstructor("Foo", [createInstance(100, 32, 64)])]);
|
|
95
|
+
const after = createSnapshot(1024, [createConstructor("Foo", [createInstance(100, 64, 96)])]);
|
|
96
|
+
assert.deepStrictEqual(compareSnapshots(before, after).constructors, []);
|
|
97
|
+
});
|
|
98
|
+
function createSnapshot(totalHeapSize, constructors) {
|
|
99
|
+
return {
|
|
100
|
+
constructors,
|
|
101
|
+
totalHeapSize,
|
|
102
|
+
totalLiveSize: constructors.reduce((sum, entry) => sum + entry.totalShallowSize, 0),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function createConstructor(className, instances) {
|
|
106
|
+
return {
|
|
107
|
+
className,
|
|
108
|
+
count: instances.length,
|
|
109
|
+
totalShallowSize: instances.reduce((sum, instance) => sum + instance.shallowSize, 0),
|
|
110
|
+
totalRetainedSize: instances.reduce((sum, instance) => sum + instance.retainedSize, 0),
|
|
111
|
+
instances,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function createInstance(address, shallowSize, retainedSize) {
|
|
115
|
+
return {
|
|
116
|
+
address,
|
|
117
|
+
shallowSize,
|
|
118
|
+
retainedSize,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=comparison.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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AC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;QACpF,iBAAiB,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,GAAG,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC;QACtF,SAAS;KACV,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,OAAe,EAAE,WAAmB,EAAE,YAAoB;IAChF,OAAO;QACL,OAAO;QACP,WAAW;QACX,YAAY;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { before, describe, it } from "node:test";
|
|
3
|
+
import { attachBuiltinKind, DebugInfoResolver, resolveClassLayouts } from "../src/debugInfoResolver.js";
|
|
4
|
+
import { parseWasmDebugInfo, DW_AT, DW_TAG, getAttr } from "../src/dwarfParser.js";
|
|
5
|
+
import { BuiltinContainerKind } from "../src/types.js";
|
|
6
|
+
import { CLASS_PREFIX, describeIntegration } from "./testHelper.js";
|
|
7
|
+
function mustGetLayout(classMap, className) {
|
|
8
|
+
const classLayout = classMap.get(className);
|
|
9
|
+
if (!classLayout) {
|
|
10
|
+
throw new Error(`missing class layout ${className}`);
|
|
11
|
+
}
|
|
12
|
+
return classLayout;
|
|
13
|
+
}
|
|
14
|
+
function mustGetField(classLayout, fieldName) {
|
|
15
|
+
const field = classLayout.fields.find((candidate) => candidate.name === fieldName);
|
|
16
|
+
if (!field) {
|
|
17
|
+
throw new Error(`missing field ${fieldName} on ${classLayout.name}`);
|
|
18
|
+
}
|
|
19
|
+
return field;
|
|
20
|
+
}
|
|
21
|
+
describeIntegration("debug-info-resolver", (ctx) => {
|
|
22
|
+
let classes;
|
|
23
|
+
let classMap;
|
|
24
|
+
let debugInfoResolver;
|
|
25
|
+
let fixtureWasm;
|
|
26
|
+
before(() => {
|
|
27
|
+
ctx.compileFixture();
|
|
28
|
+
fixtureWasm = ctx.loadFixtureWasm();
|
|
29
|
+
debugInfoResolver = DebugInfoResolver.fromWasm(fixtureWasm);
|
|
30
|
+
classes = resolveClassLayouts(fixtureWasm);
|
|
31
|
+
classMap = new Map(classes.map((c) => [c.name, c]));
|
|
32
|
+
});
|
|
33
|
+
it("contains user-defined classes", () => {
|
|
34
|
+
const userClasses = ["Vector2", "Item", "Entity", "Character", "Player", "NPC", "TreeNode", "ListNode", "KVPair"];
|
|
35
|
+
for (const name of userClasses) {
|
|
36
|
+
assert.ok(classMap.has(CLASS_PREFIX + name), `missing class ${name}`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
it("contains stdlib classes with rtid", () => {
|
|
40
|
+
assert.ok(classMap.has("~lib/string/String"));
|
|
41
|
+
assert.ok(classMap.has("~lib/arraybuffer/ArrayBuffer"));
|
|
42
|
+
});
|
|
43
|
+
it("every class has a numeric rtid", () => {
|
|
44
|
+
for (const cls of classes) {
|
|
45
|
+
assert.strictEqual(typeof cls.rtid, "number");
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
it("non-zero rtIds are unique", () => {
|
|
49
|
+
const nonZeroRtIds = classes.filter((c) => c.rtid !== 0).map((c) => c.rtid);
|
|
50
|
+
assert.strictEqual(new Set(nonZeroRtIds).size, nonZeroRtIds.length);
|
|
51
|
+
});
|
|
52
|
+
it("keeps only ~lib/object/Object among zero-rtid layouts", () => {
|
|
53
|
+
const zeroRtIdNames = classes
|
|
54
|
+
.filter((c) => c.rtid === 0)
|
|
55
|
+
.map((c) => c.name)
|
|
56
|
+
.toSorted((left, right) => left.localeCompare(right));
|
|
57
|
+
assert.deepStrictEqual(zeroRtIdNames, ["~lib/object/Object"]);
|
|
58
|
+
});
|
|
59
|
+
describe("Vector2 layout", () => {
|
|
60
|
+
it("has two f32 fields at correct offsets", () => {
|
|
61
|
+
const vec2 = mustGetLayout(classMap, CLASS_PREFIX + "Vector2");
|
|
62
|
+
assert.strictEqual(vec2.fields.length, 2);
|
|
63
|
+
const x = mustGetField(vec2, "x");
|
|
64
|
+
assert.strictEqual(x.offset, 0);
|
|
65
|
+
assert.strictEqual(x.size, 4);
|
|
66
|
+
assert.strictEqual(x.isReference, false);
|
|
67
|
+
const y = mustGetField(vec2, "y");
|
|
68
|
+
assert.strictEqual(y.offset, 4);
|
|
69
|
+
assert.strictEqual(y.size, 4);
|
|
70
|
+
assert.strictEqual(y.isReference, false);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe("Character layout", () => {
|
|
74
|
+
it("has inherited fields from Entity and own fields", () => {
|
|
75
|
+
const character = mustGetLayout(classMap, CLASS_PREFIX + "Character");
|
|
76
|
+
const fieldNames = character.fields.map((f) => f.name);
|
|
77
|
+
assert.deepStrictEqual(fieldNames, ["id", "position", "name", "hp"]);
|
|
78
|
+
});
|
|
79
|
+
it("has base set to Entity", () => {
|
|
80
|
+
const character = mustGetLayout(classMap, CLASS_PREFIX + "Character");
|
|
81
|
+
assert.strictEqual(character.base, CLASS_PREFIX + "Entity");
|
|
82
|
+
});
|
|
83
|
+
it("name field is a reference", () => {
|
|
84
|
+
const character = mustGetLayout(classMap, CLASS_PREFIX + "Character");
|
|
85
|
+
const name = mustGetField(character, "name");
|
|
86
|
+
assert.strictEqual(name.isReference, true);
|
|
87
|
+
});
|
|
88
|
+
it("hp field is not a reference", () => {
|
|
89
|
+
const character = mustGetLayout(classMap, CLASS_PREFIX + "Character");
|
|
90
|
+
const hp = mustGetField(character, "hp");
|
|
91
|
+
assert.strictEqual(hp.isReference, false);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe("Player layout (deep inheritance)", () => {
|
|
95
|
+
it("has all inherited fields from Entity→Character plus own fields", () => {
|
|
96
|
+
const player = mustGetLayout(classMap, CLASS_PREFIX + "Player");
|
|
97
|
+
const fieldNames = player.fields.map((f) => f.name);
|
|
98
|
+
assert.deepStrictEqual(fieldNames, ["id", "position", "name", "hp", "inventory", "score"]);
|
|
99
|
+
});
|
|
100
|
+
it("has base set to Character", () => {
|
|
101
|
+
const player = mustGetLayout(classMap, CLASS_PREFIX + "Player");
|
|
102
|
+
assert.strictEqual(player.base, CLASS_PREFIX + "Character");
|
|
103
|
+
});
|
|
104
|
+
it("inherited fields have correct offsets", () => {
|
|
105
|
+
const player = mustGetLayout(classMap, CLASS_PREFIX + "Player");
|
|
106
|
+
assert.strictEqual(mustGetField(player, "id").offset, 0);
|
|
107
|
+
assert.strictEqual(mustGetField(player, "position").offset, 4);
|
|
108
|
+
assert.strictEqual(mustGetField(player, "name").offset, 8);
|
|
109
|
+
assert.strictEqual(mustGetField(player, "hp").offset, 12);
|
|
110
|
+
assert.strictEqual(mustGetField(player, "inventory").offset, 16);
|
|
111
|
+
assert.strictEqual(mustGetField(player, "score").offset, 20);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
describe("TreeNode layout", () => {
|
|
115
|
+
it("has self-referencing fields", () => {
|
|
116
|
+
const treeNode = mustGetLayout(classMap, CLASS_PREFIX + "TreeNode");
|
|
117
|
+
const left = mustGetField(treeNode, "left");
|
|
118
|
+
const right = mustGetField(treeNode, "right");
|
|
119
|
+
assert.strictEqual(left.isReference, true);
|
|
120
|
+
assert.strictEqual(right.isReference, true);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe("template types", () => {
|
|
124
|
+
it("resolves template type metadata for Array<Item>", () => {
|
|
125
|
+
const arrayItem = classes.find((c) => c.name === `~lib/array/Array<${CLASS_PREFIX}Item>`);
|
|
126
|
+
assert.ok(arrayItem);
|
|
127
|
+
assert.strictEqual(arrayItem.builtinKind, BuiltinContainerKind.Array);
|
|
128
|
+
assert.strictEqual(arrayItem.templateType, `${CLASS_PREFIX}Item`);
|
|
129
|
+
assert.strictEqual(arrayItem.templateTypeIsReference, true);
|
|
130
|
+
});
|
|
131
|
+
it("resolves builtin kinds for stdlib containers", () => {
|
|
132
|
+
const functionLayout = {
|
|
133
|
+
name: "~lib/function/Function<(i32)=>i32>",
|
|
134
|
+
};
|
|
135
|
+
attachBuiltinKind(functionLayout);
|
|
136
|
+
assert.strictEqual(classMap.get("~lib/staticarray/StaticArray<i32>")?.builtinKind, BuiltinContainerKind.StaticArray);
|
|
137
|
+
assert.strictEqual(classMap.get("~lib/set/Set<i32>")?.builtinKind, BuiltinContainerKind.MapOrSet);
|
|
138
|
+
assert.strictEqual(classMap.get("~lib/map/Map<i32,i32>")?.builtinKind, BuiltinContainerKind.MapOrSet);
|
|
139
|
+
assert.strictEqual(functionLayout.builtinKind, BuiltinContainerKind.Function);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
describe("entry layouts", () => {
|
|
143
|
+
it("resolves Set entry layouts", () => {
|
|
144
|
+
assert.deepStrictEqual(classMap.get("~lib/set/Set<i32>")?.entryLayout, {
|
|
145
|
+
size: 8,
|
|
146
|
+
referenceOffsets: [],
|
|
147
|
+
});
|
|
148
|
+
assert.deepStrictEqual(classMap.get(`~lib/set/Set<${CLASS_PREFIX}Item>`)?.entryLayout, {
|
|
149
|
+
size: 8,
|
|
150
|
+
referenceOffsets: [0],
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
it("resolves Map entry layouts", () => {
|
|
154
|
+
assert.deepStrictEqual(classMap.get("~lib/map/Map<i32,i32>")?.entryLayout, {
|
|
155
|
+
size: 12,
|
|
156
|
+
referenceOffsets: [],
|
|
157
|
+
});
|
|
158
|
+
assert.deepStrictEqual(classMap.get(`~lib/map/Map<~lib/string/String,${CLASS_PREFIX}Player>`)?.entryLayout, {
|
|
159
|
+
size: 12,
|
|
160
|
+
referenceOffsets: [0, 4],
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
it("excludes classes without rtid", () => {
|
|
165
|
+
for (const cls of classes) {
|
|
166
|
+
assert.notStrictEqual(cls.rtid, undefined);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
describe("global roots", () => {
|
|
170
|
+
it("maps mutable i32 runtime globals back to their wasm global indices", () => {
|
|
171
|
+
const wasmDebugInfo = parseWasmDebugInfo(fixtureWasm);
|
|
172
|
+
const wasmGlobalEntries = wasmDebugInfo.globals;
|
|
173
|
+
const mutableI32GlobalValues = new Array(wasmGlobalEntries.filter((entry) => entry.mutable && entry.type.kind === -1 /* TypeKind.i32 */).length).fill(0);
|
|
174
|
+
const topLevelGlobalVariableDIEs = wasmDebugInfo.compilationUnits[0].rootDIE.children.filter((child) => child.tag === DW_TAG.variable);
|
|
175
|
+
const maybeGlobalTreeDie = topLevelGlobalVariableDIEs.find((die) => String(getAttr(die, DW_AT.name)?.value).endsWith("/globalTree"));
|
|
176
|
+
if (!maybeGlobalTreeDie) {
|
|
177
|
+
throw new Error("missing globalTree DIE");
|
|
178
|
+
}
|
|
179
|
+
const globalTreeDie = maybeGlobalTreeDie;
|
|
180
|
+
const globalTreeIndex = getAttr(globalTreeDie, DW_AT.location)?.value;
|
|
181
|
+
let expectedSlot = -1;
|
|
182
|
+
let mutableI32Slot = 0;
|
|
183
|
+
for (const wasmGlobalEntry of wasmGlobalEntries) {
|
|
184
|
+
if (wasmGlobalEntry.type.kind !== -1 /* TypeKind.i32 */) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (wasmGlobalEntry.mutable) {
|
|
188
|
+
if (wasmGlobalEntry.index === globalTreeIndex) {
|
|
189
|
+
expectedSlot = mutableI32Slot;
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
mutableI32Slot++;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
assert.ok(expectedSlot >= 0);
|
|
196
|
+
const expectedValue = 0x12345678;
|
|
197
|
+
mutableI32GlobalValues[expectedSlot] = expectedValue;
|
|
198
|
+
const rootMap = new Map(debugInfoResolver.getGlobalRoots(mutableI32GlobalValues).map((root) => [root.name, root]));
|
|
199
|
+
assert.strictEqual(rootMap.get(`${CLASS_PREFIX}globalTree`)?.value, expectedValue);
|
|
200
|
+
assert.strictEqual(rootMap.get(`${CLASS_PREFIX}globalTree`)?.globalIndex, globalTreeIndex);
|
|
201
|
+
assert.strictEqual(rootMap.get(`${CLASS_PREFIX}globalTree`)?.className, `${CLASS_PREFIX}TreeNode`);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
//# sourceMappingURL=debugInfoResolver.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debugInfoResolver.test.js","sourceRoot":"","sources":["../../../tools/heap_analyzer/tests/debugInfoResolver.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACxG,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAqC,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEpE,SAAS,aAAa,CAAC,QAAkC,EAAE,SAAiB;IAC1E,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC5C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,wBAAwB,SAAS,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,YAAY,CAAC,WAAwB,EAAE,SAAiB;IAC/D,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAA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HEADER_SIZE } from "../src/constants.js";
|
|
|
5
5
|
import { describeIntegration } from "./testHelper.js";
|
|
6
6
|
describeIntegration("parseDumpFile", (ctx) => {
|
|
7
7
|
let buffer;
|
|
8
|
+
let header;
|
|
8
9
|
before(() => {
|
|
9
10
|
ctx.compileFixture();
|
|
10
11
|
ctx.generateFixtureDump();
|
|
11
12
|
buffer = ctx.loadFixtureDumpBuffer();
|
|
13
|
+
header = new DataView(buffer);
|
|
12
14
|
});
|
|
13
15
|
it("parses metadata from generated dump", () => {
|
|
14
16
|
const result = parseDumpFile(buffer);
|
|
15
|
-
const header = new DataView(buffer);
|
|
16
17
|
assert.strictEqual(result.rtGlobals.dataEnd, header.getUint32(8, true));
|
|
17
18
|
assert.strictEqual(result.rtGlobals.heapBase, header.getUint32(12, true));
|
|
18
19
|
assert.strictEqual(result.rtGlobals.stackPointer, header.getUint32(16, true));
|
|
@@ -20,13 +21,22 @@ describeIntegration("parseDumpFile", (ctx) => {
|
|
|
20
21
|
assert.ok(result.rtGlobals.heapBase > result.rtGlobals.dataEnd);
|
|
21
22
|
assert.ok(result.rtGlobals.stackPointer <= result.rtGlobals.heapBase);
|
|
22
23
|
});
|
|
24
|
+
it("parses mutable i32 globals from the variable-length header", () => {
|
|
25
|
+
const result = parseDumpFile(buffer);
|
|
26
|
+
const numMutableI32GlobalValues = header.getUint32(20, true);
|
|
27
|
+
assert.strictEqual(result.rtGlobals.mutableI32GlobalValues.length, numMutableI32GlobalValues);
|
|
28
|
+
for (let index = 0; index < numMutableI32GlobalValues; index++) {
|
|
29
|
+
assert.strictEqual(result.rtGlobals.mutableI32GlobalValues[index], header.getUint32(DUMP_HEADER_SIZE + index * 4, true));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
23
32
|
it("returns a DataView over the memory region", () => {
|
|
24
33
|
const result = parseDumpFile(buffer);
|
|
25
34
|
assert.ok(result.memory instanceof DataView);
|
|
26
35
|
});
|
|
27
36
|
it("memory size equals file size minus header", () => {
|
|
28
37
|
const result = parseDumpFile(buffer);
|
|
29
|
-
|
|
38
|
+
const memoryOffset = DUMP_HEADER_SIZE + header.getUint32(20, true) * 4;
|
|
39
|
+
assert.strictEqual(result.memory.byteLength, buffer.byteLength - memoryOffset);
|
|
30
40
|
assert.strictEqual(result.memory.byteLength, 65536);
|
|
31
41
|
});
|
|
32
42
|
it("memory content is readable at address 0", () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dumpReader.test.js","sourceRoot":"","sources":["../../../tools/heap_analyzer/tests/dumpReader.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,mBAAmB,CAAC,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE;IAC3C,IAAI,MAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"dumpReader.test.js","sourceRoot":"","sources":["../../../tools/heap_analyzer/tests/dumpReader.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,mBAAmB,CAAC,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE;IAC3C,IAAI,MAAmB,CAAC;IACxB,IAAI,MAAgB,CAAC;IAErB,MAAM,CAAC,GAAG,EAAE;QACV,GAAG,CAAC,cAAc,EAAE,CAAC;QACrB,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AM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACtC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,WAAW,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACnC,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;QAChD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,0BAA0B,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,37 +1,43 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { before, describe, it } from "node:test";
|
|
3
|
-
import { DW_AT, DW_FORM, DW_TAG,
|
|
3
|
+
import { DW_AT, DW_FORM, DW_TAG, extractWasmSections, parseAbbrevTable, parseWasmDebugInfo, tagName, attrName, getAttr, walkDIEs, findDIEsByTag, buildOffsetMap, } from "../src/dwarfParser.js";
|
|
4
4
|
import { CLASS_PREFIX, describeIntegration } from "./testHelper.js";
|
|
5
5
|
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
6
6
|
// ── Tests ────────────────────────────────────────────────────────────────────
|
|
7
7
|
describeIntegration("dwarfParser", (ctx) => {
|
|
8
|
-
let
|
|
8
|
+
let debugInfo;
|
|
9
9
|
let root;
|
|
10
10
|
before(() => {
|
|
11
11
|
ctx.compileFixture();
|
|
12
|
-
|
|
13
|
-
root =
|
|
12
|
+
debugInfo = parseWasmDebugInfo(ctx.loadFixtureWasm());
|
|
13
|
+
root = debugInfo.compilationUnits[0].rootDIE;
|
|
14
14
|
});
|
|
15
|
-
describe("
|
|
15
|
+
describe("extractWasmSections", () => {
|
|
16
16
|
it("finds DWARF custom sections in wasm binary", () => {
|
|
17
|
-
const sections =
|
|
18
|
-
const names = new Set(sections.map((s) => s.name));
|
|
17
|
+
const sections = extractWasmSections(ctx.loadFixtureWasm());
|
|
18
|
+
const names = new Set(sections.customSections.map((s) => s.name));
|
|
19
19
|
assert.ok(names.has("debug_info"));
|
|
20
20
|
assert.ok(names.has("debug_abbrev"));
|
|
21
21
|
assert.ok(names.has("debug_str"));
|
|
22
22
|
});
|
|
23
23
|
it("returns non-empty payloads for DWARF sections", () => {
|
|
24
|
-
const sections =
|
|
25
|
-
const debugInfo = sections.find((s) => s.name === "debug_info");
|
|
26
|
-
const debugAbbrev = sections.find((s) => s.name === "debug_abbrev");
|
|
24
|
+
const sections = extractWasmSections(ctx.loadFixtureWasm());
|
|
25
|
+
const debugInfo = sections.customSections.find((s) => s.name === "debug_info");
|
|
26
|
+
const debugAbbrev = sections.customSections.find((s) => s.name === "debug_abbrev");
|
|
27
27
|
assert.ok(debugInfo.payload.length > 0);
|
|
28
28
|
assert.ok(debugAbbrev.payload.length > 0);
|
|
29
29
|
});
|
|
30
|
+
it("returns the fixture's global entries with the expected mutability split", () => {
|
|
31
|
+
const sections = extractWasmSections(ctx.loadFixtureWasm());
|
|
32
|
+
const mutableGlobals = sections.globals.filter((entry) => entry.mutable);
|
|
33
|
+
assert.strictEqual(sections.globals.length, 18);
|
|
34
|
+
assert.strictEqual(mutableGlobals.length, 15);
|
|
35
|
+
});
|
|
30
36
|
});
|
|
31
37
|
describe("parseAbbrevTable", () => {
|
|
32
38
|
it("parses abbreviation entries from debug_abbrev", () => {
|
|
33
|
-
const sections =
|
|
34
|
-
const abbrevSection = sections.find((s) => s.name === "debug_abbrev");
|
|
39
|
+
const sections = extractWasmSections(ctx.loadFixtureWasm());
|
|
40
|
+
const abbrevSection = sections.customSections.find((s) => s.name === "debug_abbrev");
|
|
35
41
|
const table = parseAbbrevTable(abbrevSection.payload);
|
|
36
42
|
assert.ok(table.size > 0);
|
|
37
43
|
const entry1 = table.get(1);
|
|
@@ -40,16 +46,16 @@ describeIntegration("dwarfParser", (ctx) => {
|
|
|
40
46
|
assert.ok(entry1.attributes.some((a) => a.name === DW_AT.producer && a.form === DW_FORM.strp));
|
|
41
47
|
});
|
|
42
48
|
it("parses class_type abbreviation", () => {
|
|
43
|
-
const sections =
|
|
44
|
-
const table = parseAbbrevTable(sections.find((s) => s.name === "debug_abbrev").payload);
|
|
49
|
+
const sections = extractWasmSections(ctx.loadFixtureWasm());
|
|
50
|
+
const table = parseAbbrevTable(sections.customSections.find((s) => s.name === "debug_abbrev").payload);
|
|
45
51
|
const classAbbrev = [...table.values()].find((e) => e.tag === DW_TAG.class_type);
|
|
46
52
|
assert.notStrictEqual(classAbbrev, undefined);
|
|
47
53
|
assert.strictEqual(classAbbrev.hasChildren, true);
|
|
48
54
|
assert.ok(classAbbrev.attributes.some((a) => a.name === DW_AT.name));
|
|
49
55
|
});
|
|
50
56
|
it("parses member abbreviation", () => {
|
|
51
|
-
const sections =
|
|
52
|
-
const table = parseAbbrevTable(sections.find((s) => s.name === "debug_abbrev").payload);
|
|
57
|
+
const sections = extractWasmSections(ctx.loadFixtureWasm());
|
|
58
|
+
const table = parseAbbrevTable(sections.customSections.find((s) => s.name === "debug_abbrev").payload);
|
|
53
59
|
const memberAbbrev = [...table.values()].find((e) => e.tag === DW_TAG.member);
|
|
54
60
|
assert.notStrictEqual(memberAbbrev, undefined);
|
|
55
61
|
assert.strictEqual(memberAbbrev.hasChildren, false);
|
|
@@ -59,42 +65,48 @@ describeIntegration("dwarfParser", (ctx) => {
|
|
|
59
65
|
assert.ok(attrNames.has(DW_AT.data_member_location));
|
|
60
66
|
});
|
|
61
67
|
});
|
|
62
|
-
describe("
|
|
68
|
+
describe("parseWasmDebugInfo", () => {
|
|
63
69
|
it("parses a single DWARF4 compilation unit", () => {
|
|
64
|
-
assert.strictEqual(
|
|
65
|
-
const unit =
|
|
70
|
+
assert.strictEqual(debugInfo.compilationUnits.length, 1);
|
|
71
|
+
const unit = debugInfo.compilationUnits[0];
|
|
66
72
|
assert.strictEqual(unit.version, 4);
|
|
67
73
|
assert.strictEqual(unit.addressSize, 4);
|
|
68
74
|
});
|
|
75
|
+
it("returns wasm globals alongside DWARF units", () => {
|
|
76
|
+
const mutableGlobals = debugInfo.globals.filter((entry) => entry.mutable);
|
|
77
|
+
assert.strictEqual(debugInfo.globals.length, 18);
|
|
78
|
+
assert.strictEqual(mutableGlobals.length, 15);
|
|
79
|
+
});
|
|
69
80
|
it("accepts ArrayBuffer input", () => {
|
|
70
|
-
const result =
|
|
81
|
+
const result = parseWasmDebugInfo(ctx.loadFixtureWasm().buffer);
|
|
71
82
|
assert.strictEqual(result.compilationUnits.length, 1);
|
|
83
|
+
assert.strictEqual(result.globals.length, debugInfo.globals.length);
|
|
72
84
|
});
|
|
73
85
|
it("has warpo as producer", () => {
|
|
74
86
|
assert.strictEqual(getAttr(root, DW_AT.producer)?.value, "warpo");
|
|
75
87
|
});
|
|
76
88
|
it("throws when debug_abbrev is missing", () => {
|
|
77
89
|
const minimalWasm = new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
|
|
78
|
-
assert.throws(() =>
|
|
90
|
+
assert.throws(() => parseWasmDebugInfo(minimalWasm), /Missing .debug_abbrev section/);
|
|
79
91
|
});
|
|
80
92
|
it("has non-empty abbreviations table", () => {
|
|
81
|
-
assert.ok(
|
|
93
|
+
assert.ok(debugInfo.abbreviations.size > 0);
|
|
82
94
|
});
|
|
83
95
|
it("has abbrevOffset of 0", () => {
|
|
84
|
-
assert.strictEqual(
|
|
96
|
+
assert.strictEqual(debugInfo.compilationUnits[0].abbrevOffset, 0);
|
|
85
97
|
});
|
|
86
98
|
});
|
|
87
99
|
describe("stringTable", () => {
|
|
88
100
|
it("is a non-empty Map", () => {
|
|
89
|
-
assert.ok(
|
|
90
|
-
assert.ok(
|
|
101
|
+
assert.ok(debugInfo.stringTable instanceof Map);
|
|
102
|
+
assert.ok(debugInfo.stringTable.size > 0);
|
|
91
103
|
});
|
|
92
104
|
it("contains producer string 'warpo'", () => {
|
|
93
|
-
const values = [...
|
|
105
|
+
const values = [...debugInfo.stringTable.values()];
|
|
94
106
|
assert.ok(values.includes("warpo"));
|
|
95
107
|
});
|
|
96
108
|
it("all values are non-empty strings", () => {
|
|
97
|
-
for (const str of
|
|
109
|
+
for (const str of debugInfo.stringTable.values()) {
|
|
98
110
|
assert.strictEqual(typeof str, "string");
|
|
99
111
|
assert.ok(str.length > 0);
|
|
100
112
|
}
|
|
@@ -104,7 +116,7 @@ describeIntegration("dwarfParser", (ctx) => {
|
|
|
104
116
|
assert.notStrictEqual(producer, undefined);
|
|
105
117
|
assert.strictEqual(producer.form, DW_FORM.strp);
|
|
106
118
|
assert.strictEqual(typeof producer.value, "string");
|
|
107
|
-
assert.strictEqual(
|
|
119
|
+
assert.strictEqual(debugInfo.stringTable.get(0), producer.value);
|
|
108
120
|
});
|
|
109
121
|
});
|
|
110
122
|
describe("tagName", () => {
|