[Lldb-commits] [lldb] [lldb-dap] Updating VariableDescription to use GetDescription() as a fallback. (PR #77026)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue May 14 04:20:38 PDT 2024


labath wrote:

I'm currently optimizing our data formatters for some fairly complex data structures, and I've ran into something I don't understand. My DAP packet sequence for a hover request consists of two (mostly redundant) packets:

```
--> 
Content-Length: 114

{
  "arguments": {
    "context": "hover",
    "expression": "v",
    "frameId": 524288
  },
  "command": "evaluate",
  "seq": 21,
  "type": "request"
}
<-- 
Content-Length: 1830

{
  "body": {
    "result": "(std::vector<int>) v = size=121 {\n  [0] = 1\n  [1] = 2\n  [2] = 3\n  [3] = 4\n  [4] = 5\n  [5] = 6\n  [6] = 7\n  [7] = 77\n  [8] = 3\n  [9] = 33\n  [10] = 54\n  [11] = 5\n  [12] = 53\n  [13] = 523\n  [14] = 532\n  [15] = 53\n  [16] = 3535\n  [17] = 53\n  [18] = 2235\n  [19] = 352\n  [20] = 35\n  [21] = 352\n  [22] = 532\n  [23] = 532\n  [24] = 53\n  [25] = 35523\n  [26] = 523\n  [27] = 532\n  [28] = 523\n  [29] = 523\n  [30] = 523\n  [31] = 523\n  [32] = 235\n  [33] = 523\n  [34] = 532\n  [35] = 532\n  [36] = 523\n  [37] = 523\n  [38] = 53\n  [39] = 312\n  [40] = 5\n  [41] = 346\n  [42] = 4256\n  [43] = 346\n  [44] = 234\n  [45] = 632\n  [46] = 523\n  [47] = 6\n  [48] = 246\n  [49] = 54\n  [50] = 672\n  [51] = 67\n  [52] = 2457\n  [53] = 234\n  [54] = 7524\n  [55] = 7\n  [56] = 4376\n  [57] = 23467\n  [58] = 432\n  [59] = 6\n  [60] = 2347\n  [61] = 5435\n  [62] = 2\n  [63] = 346\n  [64] = 4536\n  [65] = 34\n  [66] = 53\n  [67] = 324\n  [68] = 645\n  [69] = 645\n  [70] = 456\n  [71] = 75\n  [72] = 343\n  [73] = 3\n  [74] = 4\n  [75] = 654\n  [76] = 3545\n  [77] = 5\n  [78] = 4\n  [79] = 435\n  [80] = 5\n  [81] = 345\n  [82] = 54\n  [83] = 435\n  [84] = 43\n  [85] = 245\n  [86] = 54\n  [87] = 32\n  [88] = 4565\n  [89] = 65\n  [90] = 54\n  [91] = 43\n  [92] = 54\n  [93] = 535\n  [94] = 3\n  [95] = 4\n  [96] = 5\n  [97] = 5\n  [98] = 65\n  [99] = 1342\n  [100] = 43657\n  [101] = 67856\n  [102] = 523\n  [103] = 4\n  [104] = 534\n  [105] = 576\n  [106] = 57\n  [107] = 46\n  [108] = 24\n  [109] = 6\n  [110] = 568\n  [111] = 5658\n  [112] = 76\n  [113] = 42\n  [114] = 634\n  [115] = 8\n  [116] = 54657\n  [117] = 6\n  [118] = 4\n  [119] = 8356\n  [120] = 75\n}",
    "type": "std::vector<int>",
    "variablesReference": 8
  },
  "command": "evaluate",
  "request_seq": 21,
  "seq": 0,
  "success": true,
  "type": "response"
}
--> 
Content-Length: 86

{
  "arguments": {
    "variablesReference": 8
  },
  "command": "variables",
  "seq": 22,
  "type": "request"
}
<-- 
Content-Length: 17549

{
  "body": {
    "variables": [
      {
        "$__lldb_extensions": {
          "value": "1"
        },
        "evaluateName": "v._M_impl._M_start->[0]",
        "name": "[0]",
        "type": "int",
        "value": "1",
        "variablesReference": 0
      },
// ...
      {
        "$__lldb_extensions": {
          "value": "75"
        },
        "evaluateName": "v._M_impl._M_start->[120]",
        "name": "[120]",
        "type": "int",
        "value": "75",
        "variablesReference": 0
      }
    ]
  },
  "command": "variables",
  "request_seq": 22,
  "seq": 0,
  "success": true,
  "type": "response"
}
```

The first response contains the contents of the formatted variable (a vector, in this example) as a string, while the second one contains the same data in a structured form. Looking at the history, I've found this PR, which seems to indicate that the first packet is necessary in order to provide the contents of data structure in the hover window. However, that does not appear to match what I'm seeing:

![sc-0](https://github.com/llvm/llvm-project/assets/3129331/9305bf38-314f-46a3-9c79-b3b08beadca1)

>From what I can tell by this screenshot, the only part that VSCode uses from the first response is the first line (which it uses as the "summary" of the value, while the rest of the data (the vector contents) comes from the second response.

The first response is problematic for me, because that output can contain a lot more information (if the vector contained structures rather than ints, those structures would get expanded recursively) than what's displayed on the screen, which makes the popups slower than necessary. From what I'm seeing, it would be ideal to remove the expansion in the first response completely (which would essentially amount to reverting this PR), given that the information is already contained in the second one. However, I am assuming there is a reason for why that code exists -- but then I don't understand why does my experience (and screenshots) differ so much from the screenshots on this PR. Could something have changed  (over the last 4 months)  in how VSCode behaves that would mean this PR is not necessary?

Can anyone shed any light on this?

https://github.com/llvm/llvm-project/pull/77026


More information about the lldb-commits mailing list