@@ -175,17 +175,17 @@ export async function dumpVariableToLogCommand(args: any, log: utils.ILogger,
175175 }
176176}
177177
178- export async function dumpVariableToDocumentCommand ( variable : dap . DebugVariable , log : utils . ILogger ,
178+ export async function dumpVariableToDocumentCommand ( variable : dap . DebugVariable ,
179+ log : utils . ILogger ,
179180 debug : dbg . IDebuggerFacade ) {
180181 const session = vscode . debug . activeDebugSession ;
181182 if ( ! session ) {
182- vscode . window . showWarningMessage ( 'Can not dump variable - no active debug session!' ) ;
183183 return ;
184184 }
185185
186186 const frameId = await debug . getCurrentFrameId ( ) ;
187187 if ( frameId === undefined ) {
188- vscode . window . showWarningMessage ( `Could not get current stack frame id in order to invoke 'pprint' ` ) ;
188+ vscode . window . showWarningMessage ( `Could not get current stack frame id to invoke functions ` ) ;
189189 return ;
190190 }
191191
@@ -194,7 +194,16 @@ export async function dumpVariableToDocumentCommand(variable: dap.DebugVariable,
194194 return ;
195195 }
196196
197- const nodeToStringExpr = `nodeToString((const void *) ${ debug . getPointer ( variable ) } )` ;
197+ /*
198+ * In order to make node dump we use 2 functions:
199+ *
200+ * 1. 'nodeToStringWithLocations' - dump arbitrary node object into string form
201+ * 2. 'pretty_format_node_dump' - prettify dump returned from 'nodeToString'
202+ *
203+ * This sequence is well known and also used in 'pprint' itself, so feel
204+ * free to use it.
205+ */
206+ const nodeToStringExpr = `nodeToStringWithLocations((const void *) ${ debug . getPointer ( variable ) } )` ;
198207 let response ;
199208 try {
200209 response = await debug . evaluate ( nodeToStringExpr , frameId ) ;
@@ -226,6 +235,10 @@ export async function dumpVariableToDocumentCommand(variable: dap.DebugVariable,
226235 const ptr = debug . extractPtrFromString ( debugVariable ) ;
227236 const node = await debug . extractLongString ( debugVariable , frameId ) ;
228237
238+ /*
239+ * Perform pfree'ing ONLY after extracting string, otherwise there will
240+ * be garbage '\\177' in string buffer.
241+ */
229242 try {
230243 await debug . evaluate ( `pfree((const void *) ${ ptr } )` , frameId ,
231244 undefined , true ) ;
@@ -241,6 +254,10 @@ export async function dumpVariableToDocumentCommand(variable: dap.DebugVariable,
241254 return ;
242255 }
243256
257+ /*
258+ * Finally, show document with node dump. It would be nice to also set
259+ * appropriate title, but I don't known how to do it without saving file.
260+ */
244261 const document = await vscode . workspace . openTextDocument ( { content : node } ) ;
245262 vscode . window . showTextDocument ( document ) ;
246263}
0 commit comments