microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.45k stars 1.53k forks source link

Disable pretty-printer while populating Locals UI? #9926

Open swarren opened 1 year ago

swarren commented 1 year ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary:

In my .gdbinit, I have a gdb pretty-printer function defined. In launch.json, pretty printing is enabled:

# (In Python mode)
gdb.pretty_printers.append(find_pp)
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },

This is fine because I see pretty prints if I dump variables via the gdb console within vscode. However, pretty printing also affects the Variables/Locals display, and this prevents me from expanding the relevant class/struct values to show the individual internal fields.

Request: vscode always disable pretty printing while it is retrieving the values to display in the Variables/Locals display, so that I can always expand values to see the actual member fields. Essentially, leave pretty printing for console commands only.

That request may make pretty printing less useful; some people may like seeing the pretty printed values in the Variables/Locals display. So perhaps:

Alternative request: vscode display the pretty printed values by default, just like it does today if pretty printing is enabled, but when the arrow that allows expanding/collapsing member fields is clicked, then temporarily disable pretty printing just while retrieving the member fields.

Debugger Configurations

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "binary_name config_name",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/_out-dev-ctr-usr-local/bin/binary_name",
            "args": [
                "a bunch of args"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/product_name/${input:app_dir}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Enable xxx's debug commands",
                    "text": "source ${workspaceFolder}/xxx/.gdbinit" 
                },
                {
                    "description": "Set local variables; required so Jinja can process UTF-8 chars in templates.",
                    "text": "set environment LC_CTYPE C.UTF-8" 
                }
            ],
            "miDebuggerPath": "${workspaceFolder}/product_name/vscode/mi_debugger.sh"
        }
    ],
    "inputs": [
        // This requires extension spadin.memento-inputs
        // You must manually type the sub-dir name, but it remembers it next time
        {
            "id": "app_dir",
            "type": "command",
            "description": "The product_name sub-directory",
            "command": "memento.promptString",
            "args": {
                "id": "app_dir",
                "description": "The product_name sub-directory",
                "default": "some/dir",
                "placeholder": "product_name sub-dir name e.g. some/dir"
            }
        }
    ]
}

Debugger Logs

NA

Other Extensions

No response

Additional Information

No response

WardenGnaw commented 1 year ago

Pretty print comes from GDB, if we were to support this feature, this would be 2 additional engine settings calls and n calls to all variables again.

e.g disable pretty printing, gather all the variables again, then re-enable pretty printing.

starball5 commented 7 months ago

Out of curiosity, did you implement the children, display_hint, num_children, and child API for your pretty printer? https://sourceware.org/gdb/current/onlinedocs/gdb.html/Pretty-Printing-API.html#Pretty-Printing-API Or have you considered doing so?

nvswarren commented 7 months ago

The pretty printer implementation in question is taken from a 3rd-party project. It looks like it implements children, but not the other APIs you mentioned. Here's a link to the relevant .gdbinit file containing the implementation: https://github.com/p4lang/p4c/blob/main/.gdbinit (I'm using an older commit from that repo, but it looks like at least the first pp implementation in the file hasn't changed vs. the copy we have.)

Do you think implementing those APIs would resolve this issue, or were you just curious?

starball5 commented 7 months ago

@nvswarren I was just curious... and now I'm really curious :D but I don't want to do the work to find out the answer :D