cvisual-studio-codelldbnim-lang

lldb in vscode: how to show string values on hover?


I'm debugging a C app in VS Code on Mac OS (arm64).

I can set breakpoints and see stacktraces. However, for variables, memory addresses are shown instead of values. The variable I want to inspect is msg. Whether I add a "watch", type its name in the lldb command prompt or hover the variable in the code editor, I always have to expand the p property in the result to see the value. Assuming p stands for pointer. A minor inconvenience, but can this be improved?

desired: when hovering msg, I see it's value, like "file not found" actual: I need to click "{...}" in the hover, then expand p to see the value

The source language I am coding in is Nim, which transpiles to C.

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "cppdbg",
            "request": "launch",
            "name": "Debug PDX",
            "program": "${env:PLAYDATE_SDK_PATH}/bin/Playdate Simulator",
            "args": [
                "${workspaceFolder}/${workspaceFolderBasename}.pdx"
            ],
            "cwd": "${workspaceFolder}",
            "osx": {
                "MIMode": "lldb",
                "program": "${env:PLAYDATE_SDK_PATH}/bin/Playdate Simulator.app"
            },
//[..]

enter image description here


Solution

  • lldb's "summary formatters" are probably what you want. They allow you to present a "one line summary" for a data type, which you can see without having to disclose the type.

    You can do what you want with a simple string summary like ${var.data%S}. You register that in your ~/.lldbinit using the type summary add command. There's lots more about how to use lldb summary formatters here:

    https://lldb.llvm.org/use/variable.html#type-summary