Skip to content

[lldb-dap] Invalid variable reference ids #119784

@Anthony-Eid

Description

@Anthony-Eid

Summary

It seems like lldb-dap reuses variable reference numbers across scopes during the same suspended state. For example, if a client sends two scope requests with different frame_ids, lldb-dap uses the same variable reference numbers for different variables across scopes.

This goes against the DAP specifications in regard to the lifetime of object references and variableReference's definition, because references become invalid before the program exits its suspended state thus making variables request respond with invalid data.

   /**
   * If `variablesReference` is > 0, the variable is structured and its children
   * can be retrieved by passing `variablesReference` to the `variables` request
   * as long as execution remains suspended. See 'Lifetime of Object References'
   * in the Overview section for details.
   */
  variablesReference: number;

Example

{
  "type": "request",
  "seq": 11,
  "command": "scopes",
  "arguments": {
    "frameId": 524289
  }
}
{
  "type": "request",
  "seq": 10,
  "command": "scopes",
  "arguments": {
    "frameId": 524290
  }
}
{
  "body": {
    "scopes": [
      {
        "expensive": false,
        "name": "Locals",
        "namedVariables": 1,
        "presentationHint": "locals",
        "variablesReference": 1
      },
      {
        "expensive": false,
        "name": "Globals",
        "namedVariables": 0,
        "variablesReference": 2
      },
      {
        "expensive": false,
        "name": "Registers",
        "namedVariables": 3,
        "presentationHint": "registers",
        "variablesReference": 3
      }
    ]
  },
  "command": "scopes",
  "request_seq": 9,
  "seq": 0,
  "success": true,
  "type": "response"
},
{
  "body": {
    "scopes": [
      {
        "expensive": false,
        "name": "Locals",
        "namedVariables": 0,
        "presentationHint": "locals",
        "variablesReference": 1
      },
      {
        "expensive": false,
        "name": "Globals",
        "namedVariables": 0,
        "variablesReference": 2
      },
      {
        "expensive": false,
        "name": "Registers",
        "namedVariables": 3,
        "presentationHint": "registers",
        "variablesReference": 3
      }
    ]
  },
  "command": "scopes",
  "request_seq": 12,
  "seq": 0,
  "success": true,
  "type": "response"
}

Additional Information

I’m one of the people working on creating a client-side debug adapter implementation for the Zed code editor and noticed this bug occurring when requesting variable information. This is preventing Zed from getting valid variable information during debugging. I used the below simple program to get the above log message

While we could fix the order of our requests to mimic VSCode or Neo Vim to fix this issue, it wouldn't solve this bug during Zed's collaborative debugging sessions where multiple users could be looking at different scopes at the same time. So changing the order of Zed's requests isn't an adequate solution.

compiled with gcc -g3 -o main.out

int main() {

    int x = 1;

    return x; // Breakpoint on this line to trigger a stop event
}

I installed lldb-dap through Pacman on Arch Linux and am using lldb version 18.1.18.

Log files

vscode-lldb-dap-logs.txt
zed-lldb-dap-logs.txt

Please let me know if there's additional information I could provide to help fix this. I'll also be willing to collaborate with someone to come up with a patch, but I don't have any exposure to the code base so I would really appreciate help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions