Skip to content

Commit a7b5cb5

Browse files
committed
fix: 'dump node to stdout' works with codelldb
When adding support for codelldb this command was not updated, but only TODO added.
1 parent 81f7b9a commit a7b5cb5

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/extension.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as utils from './utils';
33
import { Features } from './utils';
44
import * as vars from './variables';
55
import * as dbg from './debugger';
6+
import * as dap from './dap';
67
import path from 'path';
78

89

@@ -148,35 +149,29 @@ export async function dumpVariableToLogCommand(args: any, log: utils.ILogger,
148149
return;
149150
}
150151

151-
const variable = args.variable;
152-
if (!variable?.value) {
153-
log.warn('Variable info not present in args');
154-
return;
155-
}
152+
const variable: dap.DebugVariable = args.variable;
156153

157-
console.assert(typeof variable.value === 'string');
158-
159-
if (!(debug.isValidPointerType(variable.value))) {
160-
vscode.window.showWarningMessage(`Variable ${variable.name} is not valid pointer`);
154+
const frameId = await debug.getCurrentFrameId();
155+
if (frameId === undefined) {
156+
vscode.window.showWarningMessage(`Could not get current stack frame id in order to invoke 'pprint'`);
161157
return;
162158
}
163159

164-
const stackFrame = await debug.getCurrentFrameId();
165-
if (stackFrame === undefined) {
166-
log.error('could not obtain current frameId');
160+
if (!(debug.isValidPointerType(variable))) {
161+
vscode.window.showWarningMessage(`Variable ${variable.value} is not valid pointer`);
167162
return;
168163
}
169-
170-
/* TODO: tested only for CppDbg */
171-
/* Simple `pprint(Node*)' function call */
172-
const expression = `-exec call pprint((const void *) ${variable.value})`;
173164

165+
const expression = `pprint((const void *) ${debug.getPointer(variable)})`;
174166
try {
175-
await debug.evaluate(expression, stackFrame);
167+
await debug.evaluate(expression,
168+
frameId,
169+
undefined /* context */,
170+
true /* no return */);
176171
} catch (err: any) {
177172
log.error('could not dump variable %s to log', variable.name, err);
178173
vscode.window.showErrorMessage(`Could not dump variable ${variable.name}. `
179-
+ `See errors in Output log`)
174+
+ 'See errors in Output log');
180175
}
181176
}
182177

0 commit comments

Comments
 (0)