Skip to content

GDB 12.1: -var-create: unable to create variable object #437

@kmARC

Description

@kmARC

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 object error displayed next to variables when selecting a different stack frame from the Call stack list (see screenshot)
Screenshot 2024-08-14 at 11 17 11

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 N with N being the stack frame number
  • Or apply the following patch on v0.27.0 of 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)
    • cwd and target are properly set

Other mentions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions