Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pretty printing for C++ debug in MacOS #574

Open
jiangtann opened this issue Nov 15, 2021 · 4 comments
Open

Support pretty printing for C++ debug in MacOS #574

jiangtann opened this issue Nov 15, 2021 · 4 comments
Labels
cause:Other The cause of this issue is outside of this project. enhancement Enchancement request

Comments

@jiangtann
Copy link

jiangtann commented Nov 15, 2021

I'm using macOS 12 Monterey and g++-11 installed by homebrew with latest VScode and CodeLLDB, the STL output is messy:
Xnip2021-11-16_05-25-06

And when I use Windows 11 and gcc/gdb with latest C/C++ extension provided by Microsoft, after I add the following configurations at launch.json (which is useless for CodeLLDB in MacOS):

"setupCommands": [
        { 
            "text": "-enable-pretty-printing",
            "description": "enable pretty printing", 
            "ignoreFailures": true 
        }
]

The STL output is delightful:
Xnip2021-11-16_05-33-33

Here is my configurations in MacOS:
launch.json

{
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "compile",
        }
    ]
} 

task.json

{
    "tasks": [
        {
            "type": "process",
            "label": "compile",
            "command": "/opt/homebrew/bin/g++-11",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
            ]
        }
    ],
    "version": "2.0.0"
}

Is there any way to make CodeLLDB support pretty printing in MacOS?

@jiangtann jiangtann added the enhancement Enchancement request label Nov 15, 2021
@vadimcn
Copy link
Owner

vadimcn commented Nov 15, 2021

Data structure visualization in LLDB is achieved via data formatters. I don't maintain LLDB's formatters for C++, I just include whatever upstream LLDB provides. As far as I know, LLDB has formatters for both gcc's libstdc++ and clang's libc++, however on macOS it probably assumes that libc++ is used since clang is the native compiler on that OS. Maybe ask on StackOverflow?

And when I use Windows 11 and gcc/gdb [...]

gcc and gdb are parts of the same toolchain, so this combination had better work...

@jiangtann
Copy link
Author

Clang does have better printing when debugging. And the reason why I use gcc instead of clang is that clang inlined more STL functions, which makes debug more difficult. For example:
GCC
Xnip2021-11-16_11-09-51

Clang
Xnip2021-11-16_11-10-35

It says:

expression failed to parse:
error: Couldn't lookup symbols:
  __ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6substrEmm

I have tried adding arguments like -O0 but it doesn't help.

Do you know how to prevent STL functions from being inlined when compiling?

@vadimcn vadimcn added the cause:Other The cause of this issue is outside of this project. label Nov 24, 2021
@vadimcn
Copy link
Owner

vadimcn commented Nov 24, 2021

Whatever this is is likely to be LLDB's built-in behavior. Not really under my control.

@conradsoon
Copy link

For anyone else still looking for a solution, adding -gdwarf-4 as a compilation option as suggested here while compiling works for me on macOS Monterey with gcc++-12 installed via homebrew.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cause:Other The cause of this issue is outside of this project. enhancement Enchancement request
Projects
None yet
Development

No branches or pull requests

3 participants