|
|
|
|
@@ -0,0 +1,638 @@
|
|
|
|
|
import {
|
|
|
|
|
DataExtractionResult,
|
|
|
|
|
VisualizationData,
|
|
|
|
|
} from "@hediet/debug-visualizer-data-extraction";
|
|
|
|
|
import { hotClass, registerUpdateReconciler } from "@hediet/node-reload";
|
|
|
|
|
import { Config, DebugAdapterConfig } from "../Config";
|
|
|
|
|
import { DebugSessionProxy } from "../proxies/DebugSessionProxy";
|
|
|
|
|
import { DebuggerViewProxy } from "../proxies/DebuggerViewProxy";
|
|
|
|
|
import { FormattedMessage } from "../webviewContract";
|
|
|
|
|
import {
|
|
|
|
|
DebugSessionVisualizationSupport,
|
|
|
|
|
GetVisualizationDataArgs,
|
|
|
|
|
VisualizationBackend,
|
|
|
|
|
VisualizationBackendBase,
|
|
|
|
|
} from "./VisualizationBackend";
|
|
|
|
|
|
|
|
|
|
registerUpdateReconciler(module);
|
|
|
|
|
|
|
|
|
|
// A generic, DAP-only replacement for the old gdb_debug_graph.py/
|
|
|
|
|
// py_debug_graph.py debuggee-side scripts: walks whatever the debug adapter
|
|
|
|
|
// already exposes via the standard "evaluate"/"variables"/"scopes" requests
|
|
|
|
|
// and produces the same { kind: { nodeTable: true }, nodes, edges, roots }
|
|
|
|
|
// shape the node-table-graph webview visualizer expects (see
|
|
|
|
|
// webview/src/visualizers/nodeTableGraphVisualizer.ts) -- no script needs to
|
|
|
|
|
// be sourced into gdb or imported into the debuggee's Python process.
|
|
|
|
|
|
|
|
|
|
interface NodeField {
|
|
|
|
|
name: string;
|
|
|
|
|
value: string;
|
|
|
|
|
isPointer?: boolean;
|
|
|
|
|
typeHint?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ArrayTableColumn {
|
|
|
|
|
id: string;
|
|
|
|
|
// Aligned by index with the owning ArrayTable's memberNames -- a member
|
|
|
|
|
// this particular element doesn't have gets an empty-value placeholder
|
|
|
|
|
// rather than shifting the columns out of alignment.
|
|
|
|
|
values: NodeField[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ArrayTable {
|
|
|
|
|
memberNames: string[];
|
|
|
|
|
columns: ArrayTableColumn[];
|
|
|
|
|
// The real element count and whether `columns` was capped at
|
|
|
|
|
// MAX_ARRAY_ELEMENTS -- lets the webview show "N of M" instead of
|
|
|
|
|
// silently hiding that the rest of a very large array wasn't fetched.
|
|
|
|
|
totalCount: number;
|
|
|
|
|
truncated: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface GraphNodeData {
|
|
|
|
|
id: string;
|
|
|
|
|
fields: NodeField[];
|
|
|
|
|
type?: string;
|
|
|
|
|
// Present instead of a meaningful `fields` (left []) when this node is an
|
|
|
|
|
// array/slice/vector of struct-shaped elements -- rendered as a compact
|
|
|
|
|
// table (one row per member, one column per element) instead of a chain
|
|
|
|
|
// of per-element boxes. See looksLikeArrayOfStructs/buildArrayTableNode.
|
|
|
|
|
arrayTable?: ArrayTable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface GraphEdge {
|
|
|
|
|
from: string;
|
|
|
|
|
to: string;
|
|
|
|
|
label?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface GraphRoot {
|
|
|
|
|
name: string;
|
|
|
|
|
value: string;
|
|
|
|
|
kind?: "local" | "watched" | "global";
|
|
|
|
|
type?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface NodeTableVisualizationData extends VisualizationData {
|
|
|
|
|
kind: { nodeTable: true };
|
|
|
|
|
lang: string;
|
|
|
|
|
nodes: GraphNodeData[];
|
|
|
|
|
edges: GraphEdge[];
|
|
|
|
|
roots: GraphRoot[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface DapVariable {
|
|
|
|
|
name: string;
|
|
|
|
|
value: string;
|
|
|
|
|
variablesReference: number;
|
|
|
|
|
type?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A field only becomes its own graph node (and edge) when it looks like a
|
|
|
|
|
// genuine pointer with an independent address -- everything else (by-value
|
|
|
|
|
// nested structs, Option/std::optional wrappers, ...) is flattened inline as
|
|
|
|
|
// dotted sub-fields instead, up to this depth. Once `-enable-pretty-printing`
|
|
|
|
|
// is on (see Config.ts's built-in cppdbg setupExpression), a wrapper's DAP
|
|
|
|
|
// children already reflect gdb's own pretty-printer output, so this stays a
|
|
|
|
|
// shallow structural rule rather than needing to special-case any container
|
|
|
|
|
// type by name.
|
|
|
|
|
const INLINE_FLATTEN_MAX_DEPTH = 3;
|
|
|
|
|
const ADDRESS_RE = /0x[0-9a-f]+/i;
|
|
|
|
|
|
|
|
|
|
// Fetching (and walking the members of) every element of a very large
|
|
|
|
|
// array/slice/vector is both slow (one DAP round trip per element) and
|
|
|
|
|
// produces an unusably wide table -- cap it and let the webview page
|
|
|
|
|
// through what's fetched instead of hanging or rendering thousands of
|
|
|
|
|
// columns at once.
|
|
|
|
|
const MAX_ARRAY_ELEMENTS = 500;
|
|
|
|
|
|
|
|
|
|
// pydevd/debugpy (Python) injects these as synthetic pseudo-children into
|
|
|
|
|
// *every* object's variable listing, grouping dunder attributes and bound
|
|
|
|
|
// methods for the Variables view -- they aren't real fields. Left
|
|
|
|
|
// unfiltered, the inline-flatten path in addField() (which has no notion of
|
|
|
|
|
// "this isn't a real field, don't recurse") walks straight into them: each
|
|
|
|
|
// one is itself an object with its own nested "special variables", so it
|
|
|
|
|
// recurses into Python's dict/type/method-wrapper internals. Measured on a
|
|
|
|
|
// 3-node linked list: ~126 DAP round trips and 400+ flattened junk fields,
|
|
|
|
|
// several seconds, on every single refresh -- the "Debug Visualizer
|
|
|
|
|
// freezes" symptom reported against a Python (debugpy) session. gdb/delve
|
|
|
|
|
// have no equivalent synthetic grouping, so this is debugpy-specific.
|
|
|
|
|
const PSEUDO_SCOPE_NAMES = new Set([
|
|
|
|
|
"special variables",
|
|
|
|
|
"function variables",
|
|
|
|
|
"class variables",
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
@hotClass(module)
|
|
|
|
|
export class NodeTableGraphEngine implements DebugSessionVisualizationSupport {
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly debuggerView: DebuggerViewProxy,
|
|
|
|
|
private readonly config: Config
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
createBackend(
|
|
|
|
|
session: DebugSessionProxy
|
|
|
|
|
): VisualizationBackend | undefined {
|
|
|
|
|
const config = this.config.getDebugAdapterConfig(session.session.type);
|
|
|
|
|
if (!config || !config.nodeTableGraph) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
return new NodeTableGraphVisualizationBackend(
|
|
|
|
|
session,
|
|
|
|
|
this.debuggerView,
|
|
|
|
|
config
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class NodeTableGraphVisualizationBackend extends VisualizationBackendBase {
|
|
|
|
|
public readonly expressionLanguageId = "text";
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
debugSession: DebugSessionProxy,
|
|
|
|
|
debuggerView: DebuggerViewProxy,
|
|
|
|
|
private readonly config: DebugAdapterConfig
|
|
|
|
|
) {
|
|
|
|
|
super(debugSession, debuggerView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private detectLang(): string {
|
|
|
|
|
const type = this.debugSession.session.type;
|
|
|
|
|
if (type === "debugpy" || type === "python") {
|
|
|
|
|
return "python";
|
|
|
|
|
}
|
|
|
|
|
if (type === "go") {
|
|
|
|
|
return "go";
|
|
|
|
|
}
|
|
|
|
|
const miDebuggerPath = String(
|
|
|
|
|
(this.debugSession.session.configuration as { miDebuggerPath?: string })
|
|
|
|
|
.miDebuggerPath || ""
|
|
|
|
|
);
|
|
|
|
|
if (miDebuggerPath.includes("rust-gdb")) {
|
|
|
|
|
return "rust";
|
|
|
|
|
}
|
|
|
|
|
return "cpp";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async getVisualizationData({
|
|
|
|
|
expression,
|
|
|
|
|
sessionStore,
|
|
|
|
|
}: GetVisualizationDataArgs): Promise<
|
|
|
|
|
| { kind: "data"; result: DataExtractionResult }
|
|
|
|
|
| { kind: "error"; message: FormattedMessage }
|
|
|
|
|
> {
|
|
|
|
|
const frameId = this.debuggerView.getActiveStackFrameId(
|
|
|
|
|
this.debugSession
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await this.runSetupOnce(sessionStore, frameId);
|
|
|
|
|
|
|
|
|
|
const nodes = new Map<string, GraphNodeData>();
|
|
|
|
|
const edges: GraphEdge[] = [];
|
|
|
|
|
const visited = new Set<string>();
|
|
|
|
|
const roots: GraphRoot[] = [];
|
|
|
|
|
|
|
|
|
|
const primary = await this.debugSession.evaluate({
|
|
|
|
|
expression,
|
|
|
|
|
frameId,
|
|
|
|
|
context: this.config.context,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let primaryId: string | undefined;
|
|
|
|
|
if (primary.variablesReference > 0) {
|
|
|
|
|
primaryId = await this.walkNodeOrArrayTable(
|
|
|
|
|
primary.variablesReference,
|
|
|
|
|
primary.result,
|
|
|
|
|
nodes,
|
|
|
|
|
edges,
|
|
|
|
|
visited
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
nodes.set("root", {
|
|
|
|
|
id: "root",
|
|
|
|
|
fields: [{ name: "value", value: primary.result }],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await this.discoverLocals(frameId, primaryId, nodes, edges, visited, roots);
|
|
|
|
|
|
|
|
|
|
const data: NodeTableVisualizationData = {
|
|
|
|
|
kind: { nodeTable: true },
|
|
|
|
|
lang: this.detectLang(),
|
|
|
|
|
nodes: [...nodes.values()],
|
|
|
|
|
edges,
|
|
|
|
|
roots,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
kind: "data",
|
|
|
|
|
result: {
|
|
|
|
|
availableExtractors: [],
|
|
|
|
|
usedExtractor: {
|
|
|
|
|
id: "node-table-graph" as any,
|
|
|
|
|
name: "Node Table Graph",
|
|
|
|
|
priority: 2000,
|
|
|
|
|
},
|
|
|
|
|
data,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
return {
|
|
|
|
|
kind: "error",
|
|
|
|
|
message: {
|
|
|
|
|
kind: "list",
|
|
|
|
|
items: [
|
|
|
|
|
"An error occurred while building the node table graph:",
|
|
|
|
|
error.message,
|
|
|
|
|
`Used debug adapter: ${this.debugSession.session.configuration.type}`,
|
|
|
|
|
{
|
|
|
|
|
kind: "inlineList",
|
|
|
|
|
items: [
|
|
|
|
|
"Evaluated expression is",
|
|
|
|
|
{ kind: "code", content: expression },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Runs the adapter's setup commands (e.g. gdb's pretty-printing/
|
|
|
|
|
// print-elements/print-characters options) once per debug session
|
|
|
|
|
// instead of on every refresh -- sessionStore.data is a per-session slot
|
|
|
|
|
// VisualizationWatchModel already keeps around for exactly this purpose.
|
|
|
|
|
private async runSetupOnce(
|
|
|
|
|
sessionStore: { data: unknown },
|
|
|
|
|
frameId: number | undefined
|
|
|
|
|
) {
|
|
|
|
|
const store = sessionStore.data as
|
|
|
|
|
| { nodeTableGraphSetupDone?: boolean }
|
|
|
|
|
| undefined;
|
|
|
|
|
if (store && store.nodeTableGraphSetupDone) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const commands = this.config.getSetupExpression();
|
|
|
|
|
if (commands) {
|
|
|
|
|
for (const cmd of commands) {
|
|
|
|
|
try {
|
|
|
|
|
await this.debugSession.evaluate({
|
|
|
|
|
expression: cmd,
|
|
|
|
|
frameId,
|
|
|
|
|
context: "repl",
|
|
|
|
|
});
|
|
|
|
|
} catch {
|
|
|
|
|
// best-effort -- fall through, the real walk below will
|
|
|
|
|
// still surface a clear error if something's actually wrong
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sessionStore.data = { ...(store || {}), nodeTableGraphSetupDone: true };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async discoverLocals(
|
|
|
|
|
frameId: number | undefined,
|
|
|
|
|
primaryId: string | undefined,
|
|
|
|
|
nodes: Map<string, GraphNodeData>,
|
|
|
|
|
edges: GraphEdge[],
|
|
|
|
|
visited: Set<string>,
|
|
|
|
|
roots: GraphRoot[]
|
|
|
|
|
) {
|
|
|
|
|
if (frameId === undefined) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const scopes = await this.debugSession.getScopes({ frameId });
|
|
|
|
|
const localsScope = scopes.find((s) => /local/i.test(s.name));
|
|
|
|
|
if (!localsScope) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const localVars = await this.debugSession.getVariables({
|
|
|
|
|
variablesReference: localsScope.variablesReference,
|
|
|
|
|
});
|
|
|
|
|
for (const v of localVars as DapVariable[]) {
|
|
|
|
|
const addr = this.extractAddress(v.value);
|
|
|
|
|
if (primaryId !== undefined && addr === primaryId) {
|
|
|
|
|
continue; // already covered by the primary root
|
|
|
|
|
}
|
|
|
|
|
if (v.variablesReference > 0) {
|
|
|
|
|
const id = await this.walkNodeOrArrayTable(
|
|
|
|
|
v.variablesReference,
|
|
|
|
|
v.value,
|
|
|
|
|
nodes,
|
|
|
|
|
edges,
|
|
|
|
|
visited
|
|
|
|
|
);
|
|
|
|
|
roots.push({ name: v.name, value: id, kind: "local", type: v.type });
|
|
|
|
|
} else {
|
|
|
|
|
roots.push({
|
|
|
|
|
name: v.name,
|
|
|
|
|
value: v.value,
|
|
|
|
|
kind: "local",
|
|
|
|
|
type: v.type,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finds an address that plausibly belongs to `value` *itself*, not to
|
|
|
|
|
// something nested inside its own summary text. Some adapters (delve,
|
|
|
|
|
// with dlvLoadConfig's followPointers on) inline a pointer's entire
|
|
|
|
|
// pointee summary -- including further nested pointers' addresses --
|
|
|
|
|
// into the value string without ever printing the pointer's own
|
|
|
|
|
// address anywhere; naively taking the first "0x..." match there would
|
|
|
|
|
// silently misattribute some nested field's address as this value's own
|
|
|
|
|
// identity. Rejecting a match that only appears after the value's own
|
|
|
|
|
// summary has already opened a nested struct/array (a "{" or "[")
|
|
|
|
|
// filters those out, while still matching the common bare-address
|
|
|
|
|
// ("0x1234") and gdb-style ("0x1234 <Node>") and Python-repr
|
|
|
|
|
// ("<Foo object at 0x1234>") shapes, none of which have that.
|
|
|
|
|
private extractAddress(value: string): string | undefined {
|
|
|
|
|
const m = ADDRESS_RE.exec(value);
|
|
|
|
|
if (!m) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
if (/[{[]/.test(value.slice(0, m.index))) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
return m[0].toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Some debug adapters (delve/Go, at least) represent a pointer's
|
|
|
|
|
// dereference as a single transparent child with an empty name, rather
|
|
|
|
|
// than exposing the pointee's fields/elements directly -- unwrap through
|
|
|
|
|
// it (recursively, in case of multiple indirections, e.g. `**T`) so
|
|
|
|
|
// field names and array detection see the real members, not one
|
|
|
|
|
// anonymous wrapper hop away from them.
|
|
|
|
|
private async getResolvedChildren(
|
|
|
|
|
variablesReference: number
|
|
|
|
|
): Promise<DapVariable[]> {
|
|
|
|
|
let children = await this.fetchRealChildren(variablesReference);
|
|
|
|
|
while (
|
|
|
|
|
children.length === 1 &&
|
|
|
|
|
children[0].name === "" &&
|
|
|
|
|
children[0].variablesReference > 0
|
|
|
|
|
) {
|
|
|
|
|
children = await this.fetchRealChildren(children[0].variablesReference);
|
|
|
|
|
}
|
|
|
|
|
return children;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filters out pydevd/debugpy's synthetic "special variables"/"function
|
|
|
|
|
// variables" pseudo-children (see PSEUDO_SCOPE_NAMES) right at the
|
|
|
|
|
// source, so nothing downstream -- array-of-structs detection, the
|
|
|
|
|
// inline-flatten walk, array table columns -- ever has to know they
|
|
|
|
|
// exist.
|
|
|
|
|
private async fetchRealChildren(
|
|
|
|
|
variablesReference: number
|
|
|
|
|
): Promise<DapVariable[]> {
|
|
|
|
|
const children = (await this.debugSession.getVariables({
|
|
|
|
|
variablesReference,
|
|
|
|
|
})) as DapVariable[];
|
|
|
|
|
return children.filter((c) => !PSEUDO_SCOPE_NAMES.has(c.name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private looksLikePointer(v: { type?: string; value: string }): boolean {
|
|
|
|
|
if (v.type) {
|
|
|
|
|
// C/C++ (rust-gdb prints Rust pointers/references the same way
|
|
|
|
|
// gdb's own C type-printer would): trailing sigil, e.g. "Node *".
|
|
|
|
|
if (/\*\s*$/.test(v.type)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// Go (delve) and Rust's own `*mut T`/`*const T`/`&T` syntax put
|
|
|
|
|
// the sigil in front instead, e.g. "*main.Node", "&Node<i32>".
|
|
|
|
|
if (/^\s*[*&]/.test(v.type)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (/<.*object at 0x[0-9a-f]+>/i.test(v.value)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A value counts as "array of classes" when every child's name is a bare
|
|
|
|
|
// or bracketed index (0,1,2,... or [0],[1],[2],...) -- the DAP naming
|
|
|
|
|
// convention arrays/slices/vectors already use across gdb/MIEngine,
|
|
|
|
|
// debugpy, and delve -- and the first element is itself struct-shaped
|
|
|
|
|
// (has its own children), not a scalar leaf. Only the first element is
|
|
|
|
|
// checked, on the assumption the array is homogeneous (true for every
|
|
|
|
|
// language this targets); a scalar array (e.g. `int[5]`) intentionally
|
|
|
|
|
// falls through to the ordinary inline-flatten path instead.
|
|
|
|
|
private looksLikeArrayOfStructs(children: DapVariable[]): boolean {
|
|
|
|
|
if (children.length === 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!children.every((c) => /^\[?\d+\]?$/.test(c.name))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return children[0].variablesReference > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Recursively walks a DAP variablesReference into `nodes`/`edges`,
|
|
|
|
|
// returning the id (a real address when one is present in the variable's
|
|
|
|
|
// own printed value, else a synthesized id) of the node it produced --
|
|
|
|
|
// mirrors the old scripts' hex(ptr_int)/id(obj)-derived node ids, giving
|
|
|
|
|
// the same cross-reference cycle dedup via `visited`. Routes to either a
|
|
|
|
|
// regular struct node or an array-table node depending on shape, so an
|
|
|
|
|
// array of structs gets the compact table rendering everywhere it
|
|
|
|
|
// appears -- as the primary root, a struct's own field, a local, or a
|
|
|
|
|
// pointer's target -- not just in one specific position.
|
|
|
|
|
private async walkNodeOrArrayTable(
|
|
|
|
|
variablesReference: number,
|
|
|
|
|
ownValue: string,
|
|
|
|
|
nodes: Map<string, GraphNodeData>,
|
|
|
|
|
edges: GraphEdge[],
|
|
|
|
|
visited: Set<string>,
|
|
|
|
|
prefetchedChildren?: DapVariable[]
|
|
|
|
|
): Promise<string> {
|
|
|
|
|
const id = this.extractAddress(ownValue) || `synthetic:${nodes.size}`;
|
|
|
|
|
if (visited.has(id)) {
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
visited.add(id);
|
|
|
|
|
|
|
|
|
|
const children =
|
|
|
|
|
prefetchedChildren ?? (await this.getResolvedChildren(variablesReference));
|
|
|
|
|
|
|
|
|
|
if (this.looksLikeArrayOfStructs(children)) {
|
|
|
|
|
await this.buildArrayTableNode(id, children, nodes, edges, visited);
|
|
|
|
|
} else {
|
|
|
|
|
await this.buildStructFields(id, children, nodes, edges, visited);
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async buildStructFields(
|
|
|
|
|
id: string,
|
|
|
|
|
children: DapVariable[],
|
|
|
|
|
nodes: Map<string, GraphNodeData>,
|
|
|
|
|
edges: GraphEdge[],
|
|
|
|
|
visited: Set<string>
|
|
|
|
|
) {
|
|
|
|
|
const fields: NodeField[] = [];
|
|
|
|
|
for (const child of children) {
|
|
|
|
|
await this.addField(child, fields, edges, nodes, visited, id, 0);
|
|
|
|
|
}
|
|
|
|
|
nodes.set(id, { id, fields });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Builds a single node holding every element's members as columns
|
|
|
|
|
// (memberNames is the union of member names across elements, in
|
|
|
|
|
// first-seen order, so a ragged/heterogeneous array still lines up
|
|
|
|
|
// sensibly). A pointer member is still a real edge out of this same
|
|
|
|
|
// node for each element that has one, labeled "[i].member" -- pointers
|
|
|
|
|
// stay navigable everywhere, they just fan out from one box instead of
|
|
|
|
|
// each element getting its own.
|
|
|
|
|
private async buildArrayTableNode(
|
|
|
|
|
id: string,
|
|
|
|
|
allElements: DapVariable[],
|
|
|
|
|
nodes: Map<string, GraphNodeData>,
|
|
|
|
|
edges: GraphEdge[],
|
|
|
|
|
visited: Set<string>
|
|
|
|
|
) {
|
|
|
|
|
const totalCount = allElements.length;
|
|
|
|
|
const truncated = totalCount > MAX_ARRAY_ELEMENTS;
|
|
|
|
|
const elements = truncated
|
|
|
|
|
? allElements.slice(0, MAX_ARRAY_ELEMENTS)
|
|
|
|
|
: allElements;
|
|
|
|
|
|
|
|
|
|
const memberNames: string[] = [];
|
|
|
|
|
const seenMembers = new Set<string>();
|
|
|
|
|
const columnCells: Map<string, NodeField>[] = [];
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < elements.length; i++) {
|
|
|
|
|
const cells = new Map<string, NodeField>();
|
|
|
|
|
const el = elements[i];
|
|
|
|
|
if (el.variablesReference > 0) {
|
|
|
|
|
const members = await this.getResolvedChildren(el.variablesReference);
|
|
|
|
|
for (const m of members) {
|
|
|
|
|
if (!seenMembers.has(m.name)) {
|
|
|
|
|
seenMembers.add(m.name);
|
|
|
|
|
memberNames.push(m.name);
|
|
|
|
|
}
|
|
|
|
|
const addr = this.extractAddress(m.value);
|
|
|
|
|
if (addr && this.looksLikePointer(m)) {
|
|
|
|
|
if (m.variablesReference > 0) {
|
|
|
|
|
const targetId = await this.walkNodeOrArrayTable(
|
|
|
|
|
m.variablesReference,
|
|
|
|
|
m.value,
|
|
|
|
|
nodes,
|
|
|
|
|
edges,
|
|
|
|
|
visited
|
|
|
|
|
);
|
|
|
|
|
edges.push({
|
|
|
|
|
from: id,
|
|
|
|
|
to: targetId,
|
|
|
|
|
label: `[${i}].${m.name}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
cells.set(m.name, {
|
|
|
|
|
name: m.name,
|
|
|
|
|
value: addr,
|
|
|
|
|
isPointer: true,
|
|
|
|
|
typeHint: m.type,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
cells.set(m.name, {
|
|
|
|
|
name: m.name,
|
|
|
|
|
value: m.value,
|
|
|
|
|
typeHint: m.type,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
columnCells.push(cells);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const columns: ArrayTableColumn[] = elements.map((el, i) => ({
|
|
|
|
|
id: /^\[\d+\]$/.test(el.name) ? el.name : `[${el.name}]`,
|
|
|
|
|
values: memberNames.map(
|
|
|
|
|
(m) => columnCells[i].get(m) || { name: m, value: "" }
|
|
|
|
|
),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
nodes.set(id, {
|
|
|
|
|
id,
|
|
|
|
|
fields: [],
|
|
|
|
|
arrayTable: { memberNames, columns, totalCount, truncated },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async addField(
|
|
|
|
|
child: DapVariable,
|
|
|
|
|
fields: NodeField[],
|
|
|
|
|
edges: GraphEdge[],
|
|
|
|
|
nodes: Map<string, GraphNodeData>,
|
|
|
|
|
visited: Set<string>,
|
|
|
|
|
ownerId: string,
|
|
|
|
|
depth: number
|
|
|
|
|
) {
|
|
|
|
|
const addr = this.extractAddress(child.value);
|
|
|
|
|
if (addr && this.looksLikePointer(child)) {
|
|
|
|
|
fields.push({
|
|
|
|
|
name: child.name,
|
|
|
|
|
value: addr,
|
|
|
|
|
isPointer: true,
|
|
|
|
|
typeHint: child.type,
|
|
|
|
|
});
|
|
|
|
|
if (child.variablesReference > 0) {
|
|
|
|
|
const targetId = await this.walkNodeOrArrayTable(
|
|
|
|
|
child.variablesReference,
|
|
|
|
|
child.value,
|
|
|
|
|
nodes,
|
|
|
|
|
edges,
|
|
|
|
|
visited
|
|
|
|
|
);
|
|
|
|
|
edges.push({ from: ownerId, to: targetId, label: child.name });
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (child.variablesReference > 0) {
|
|
|
|
|
const grandchildren = await this.getResolvedChildren(
|
|
|
|
|
child.variablesReference
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (this.looksLikeArrayOfStructs(grandchildren)) {
|
|
|
|
|
const targetId = await this.walkNodeOrArrayTable(
|
|
|
|
|
child.variablesReference,
|
|
|
|
|
child.value,
|
|
|
|
|
nodes,
|
|
|
|
|
edges,
|
|
|
|
|
visited,
|
|
|
|
|
grandchildren
|
|
|
|
|
);
|
|
|
|
|
edges.push({ from: ownerId, to: targetId, label: child.name });
|
|
|
|
|
fields.push({
|
|
|
|
|
name: child.name,
|
|
|
|
|
value: targetId,
|
|
|
|
|
isPointer: true,
|
|
|
|
|
typeHint: child.type,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (depth < INLINE_FLATTEN_MAX_DEPTH) {
|
|
|
|
|
if (grandchildren.length === 0) {
|
|
|
|
|
fields.push({ name: child.name, value: child.value, typeHint: child.type });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (const gc of grandchildren) {
|
|
|
|
|
await this.addField(
|
|
|
|
|
{ ...gc, name: `${child.name}.${gc.name}` },
|
|
|
|
|
fields,
|
|
|
|
|
edges,
|
|
|
|
|
nodes,
|
|
|
|
|
visited,
|
|
|
|
|
ownerId,
|
|
|
|
|
depth + 1
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fields.push({ name: child.name, value: child.value, typeHint: child.type });
|
|
|
|
|
}
|
|
|
|
|
}
|