-
Notifications
You must be signed in to change notification settings - Fork 124
Description
Symptom
When using a recent version of gdb (anything after 2022 March 08), the thread context is not selected by the extension anymore, and therefore (multi-threaded?) binaries cannot be properly debugged. Our team encountered two issues:
- Debugging a multi-threaded binary resulted in never stopping at a breakpoint
-var-create: unable to create variable objecterror displayed next to variables when selecting a different stack frame from the Call stack list (see screenshot)
Cause
I git-bisected the offending commit in gdb: bminor/binutils-gdb@a9c82bc changed how the thread / stack frame context is selected. From the commit message:
With this change, there are only two GDB/MI commands
that can change user selected context: -thread-select and -stack-select-frame.
This allows us to remove all and rather complicated logic of notifying
about user selected context change from mi_execute_command (), leaving it
to these two commands themselves to notify.
Workaround
- Either after selecting the stack frame, manually invoke
-stack-select-frame Nwith N being the stack frame number - Or apply the following patch on
v0.27.0of the extension
diff --git a/src/backend/mi2/mi2.ts b/src/backend/mi2/mi2.ts
index e641160..fcef83b 100644
--- a/src/backend/mi2/mi2.ts
+++ b/src/backend/mi2/mi2.ts
@@ -741,6 +741,7 @@ export class MI2 extends EventEmitter implements IBackend {
if (trace)
this.log("stderr", "getStackVariables");
+ await this.sendCommand(`stack-select-frame ${frame}`);
const result = await this.sendCommand(`stack-list-variables --thread ${thread} --frame ${frame} --simple-values`);
const variables = result.result("variables");
const ret: Variable[] = [];Note that I'm not sure if this is the right spot to invoke -stack-select-frame. It seems to be performant and does its job.
System
- If you are using gdb
-
gdb --version>= 12.1 (compiled from source, broken after bminor/binutils-gdb@a9c82bc) - it works on the command line with
gdb(when invoking-stack-select-frame) -
cwdandtargetare properly set
-
Other mentions
- Call stack window - selecting entry not actually changing frame in the debugger platformio/platform-espressif32#1330 seems to be caused by the same issue