@@ -62,7 +62,15 @@ export class GdbHeapTraceManager {
6262 / \\ / g,
6363 "/"
6464 ) } /htrace_${ new Date ( ) . getTime ( ) } .svdat`;
65- await this . createGdbinitFile ( fileName , workspace . fsPath ) ;
65+ const buildDirPath = readParameter (
66+ "idf.buildPath" ,
67+ workspace
68+ ) as string ;
69+ const buildExists = await pathExists ( buildDirPath ) ;
70+ if ( ! buildExists ) {
71+ throw new Error ( `${ buildDirPath } doesn't exist. Build first.` ) ;
72+ }
73+ await this . createGdbinitFile ( fileName , buildDirPath ) ;
6674 const modifiedEnv = await appendIdfAndToolsToPath ( workspace ) ;
6775 const idfTarget = modifiedEnv . IDF_TARGET || "esp32" ;
6876 const gdbTool = getToolchainToolName ( idfTarget , "gdb" ) ;
@@ -73,14 +81,6 @@ export class GdbHeapTraceManager {
7381 if ( ! isGdbToolInPath ) {
7482 throw new Error ( `${ gdbTool } is not available in PATH.` ) ;
7583 }
76- const buildDirPath = readParameter (
77- "idf.buildPath" ,
78- workspace
79- ) as string ;
80- const buildExists = await pathExists ( buildDirPath ) ;
81- if ( ! buildExists ) {
82- throw new Error ( `${ buildDirPath } doesn't exist. Build first.` ) ;
83- }
8484 const projectName = await getProjectName ( buildDirPath ) ;
8585 const elfFilePath = join ( buildDirPath , `${ projectName } .elf` ) ;
8686 const elfFileExists = await pathExists ( elfFilePath ) ;
@@ -132,16 +132,20 @@ export class GdbHeapTraceManager {
132132 public async stop ( ) {
133133 try {
134134 if ( this . childProcess ) {
135- this . childProcess . stdin . end ( ) ;
136- this . childProcess . kill ( "SIGKILL" ) ;
135+ this . childProcess . stdin . write ( "quit\n" ) ;
136+ // Give GDB some time to process the quit command
137+ await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
138+ if ( ! this . childProcess . killed ) {
139+ this . childProcess . kill ( "SIGKILL" ) ;
140+ }
137141 this . childProcess = null ;
138142 }
139143 this . archiveDataProvider . populateArchiveTree ( ) ;
140144 this . showStartButton ( ) ;
141145 } catch ( error ) {
142146 const msg = error . message
143147 ? error . message
144- : "Error stoping GDB Heap Tracing" ;
148+ : "Error stopping GDB Heap Tracing" ;
145149 Logger . errorNotify ( msg , error , "GdbHeapTraceManager stop" ) ;
146150 }
147151 }
@@ -170,9 +174,9 @@ export class GdbHeapTraceManager {
170174 traceFilePath : string ,
171175 workspaceFolder : string
172176 ) {
173- let content = `set pagination off\ntarget remote :3333\n\nmon reset halt\nflushregs\n\n` ;
174- content += `tb heap_trace_start\ncommands\nmon esp sysview start ${ traceFilePath } \n` ;
175- content += `c\nend\n\ntb heap_trace_stop\ncommands\nmon esp sysview stop\nend\n\nc` ;
177+ let content = `set pagination off\nset confirm off\ ntarget remote :3333\n\nmon reset halt\nflushregs\n\n` ;
178+ content += `tb heap_trace_start\ncommands\nmon esp sysview_mcore start ${ traceFilePath } \n` ;
179+ content += `c\nend\n\ntb heap_trace_stop\ncommands\nmon esp sysview_mcore stop\nend\n\nc` ;
176180 const filePath = join ( workspaceFolder , this . gdbinitFileName ) ;
177181 await writeFile ( filePath , content ) ;
178182 }
0 commit comments