lldb-mi icon indicating copy to clipboard operation
lldb-mi copied to clipboard

lldb-mi hangs on M1 macOS when creating variable

Open LimingFang opened this issue 2 years ago • 14 comments

Environment

  • OS and version: macOS Monterey 12.4
  • VS Code: 1.68.0
  • C/C++ extension: 1.11.0
  • OS and version of remote machine (if applicable): no
  • GDB / LLDB version: 13.0.1

Bug Summary and Steps to Reproduce

Bug Summary: When debugging some code(for example, leveldb test code), sometimes the debug can't go on.

Steps to reproduce:

  1. Clone leveldb and add main.cpp image
  2. Debug this executable, when entering DB::Open: image then I was stuck in *dbptr = nullptr; where there's 4 lldb-mi process and in the right panel(variable),there is a circle spinning.

Debugger Configurations

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "cppdbg",
      "request": "launch",
      "name": "Debug main test",
      "program": "${workspaceFolder}/build/main_test",
      "args": [],
      "MIMode": "lldb",
      "cwd": "${workspaceFolder}",
      "MIMode": "lldb",
      "miDebuggerPath": "/Users/fangliming/Documents/GitHub/collections/lldb-mi/src/lldb-mi",
    }
  ]

lldb-mi version

image

Debugger Logs

log link

Additional Information

  • lldb-mi won't exit when stop debugging.
  • CodeLLDB extension works fine on my Mac.

outro

From the logs, it looks like the debugger is hanging on creating the variable edit.

-1034-var-create - - "edit" --thread 1 --frame 0

Why it is hanging on creating the VersionEdit edit variable.

  • microsoft/vscode-cpptools#9488

LimingFang avatar Jun 23 '22 05:06 LimingFang

I seem to have the same issue when I try to debug a Google Test UnitTest with the TestMate C++ extension.

There are more details here:

https://github.com/microsoft/vscode-cpptools/issues/9831

I hit the issue with a code like this. In this context it is reproducible 100%. In other context there is no issue.

    struct KeepAlive
    {
        /**
         * @brief `KeepAlive` subkeys.
         *
         */
        enum class Subkey
        {
            /// Subkey `AfterInitialDemand` - delaying the start.
            AfterInitialDemand,
            /// Subkey `Crashed` - depending on crashes.
            Crashed,
            /// Subkey `NetworkState` - depending on network availability.
            NetworkState,
            /// Subkey `OtherJobEnabled` - depending on other jobs.
            OtherJobEnabled,
            /// Subkey `PathState` - depending on the existence of a path.
            PathState,
            /// Subkey `SuccessfulExit` - depending on the last exit status.
            SuccessfulExit,
        };

        /**
         * @brief `KeepAlive` subkey value types.
         *
         */
        struct SubkeyValueType
        {
            /// Subkey `AfterInitialDemand` - delaying the start.
            using AfterInitialDemand = std::map<std::string, bool>;
            /// Subkey `Crashed` - depending on crashes.
            using Crashed = bool;
            /// Subkey `NetworkState` - depending on network availability.
            using NetworkState = bool;
            /// Subkey `OtherJobEnabled` - depending on other jobs.
            using OtherJobEnabled = std::map<std::string, bool>;
            /// Subkey `PathState` - depending on the existence of a path.
            using PathState = std::map<std::string, bool>;
            /// Subkey `SuccessfulExit` - depending on the last exit status.
            using SuccessfulExit = bool;
        };

        /**
         * @brief A `variant` of `KeepAlive` subkey value types.
         *
         */
        using SubkeyType = ::boost::variant2::variant<
            KeepAlive::SubkeyValueType::AfterInitialDemand,
            KeepAlive::SubkeyValueType::Crashed,
            KeepAlive::SubkeyValueType::NetworkState,
            KeepAlive::SubkeyValueType::OtherJobEnabled,
            KeepAlive::SubkeyValueType::PathState,
            KeepAlive::SubkeyValueType::SuccessfulExit>;
    };

tl::optional<
    ::boost::variant2::variant<bool, std::map<ILaunchdPlist::KeepAlive::Subkey, ILaunchdPlist::KeepAlive::SubkeyType>>>
LaunchdPlist::GetKeepAlive() const noexcept
{
...
}

TEST_F(LaunchdPlistTest, GetKeepAliveBool)
{
    // Binary plist

    auto valueOpt = LaunchdPlistTest::GetValidBinaryPlist()->GetKeepAlive();
    EXPECT_TRUE(valueOpt.has_value());

Here it hangs: Screenshot 2022-09-02 at 9 26 03

H-G-Hristov avatar Sep 02 '22 06:09 H-G-Hristov

If I stop debugging the lldb-mi process stays running at 100% CPU.

Screenshot 2022-09-02 at 9 28 12

H-G-Hristov avatar Sep 02 '22 06:09 H-G-Hristov

After several runs I have multiple lldb-mi instances:

Screenshot 2022-09-02 at 9 29 58

H-G-Hristov avatar Sep 02 '22 06:09 H-G-Hristov

Same here: https://github.com/lldb-tools/lldb-mi/issues/96 https://github.com/lldb-tools/lldb-mi/issues/89 VSCode is rendered useless because of this in a complex scenario of C++ templates, abstract classes and Google Test.

I can confirm now that this issue happened to me on Intel macOS BigSur but it is very, very common and reproducible on M1 in the above scenario.

H-G-Hristov avatar Sep 09 '22 07:09 H-G-Hristov

Same issue here.

donangel avatar Dec 13 '22 20:12 donangel

Any chance of this being looked at?

alexolog avatar Apr 05 '23 04:04 alexolog

Is this perhaps related to https://github.com/microsoft/vscode-cpptools/issues/7240#issuecomment-997954449? @shiretu posted his workaround there. Further comment:

This is truly a problem with the lldb. See my patch above. lldb is out-of-bounds-ing on walking uninitialized variables with garbage values on things like internal counters and sizes. My quick yet brutal fix is to limit these things to 64.

Unfortunately, VSCode tries to render all local variables in the current scope. And when it reaches one of those not-yet-initialized vars, it behaves like that.

garfieldnate avatar Aug 25 '23 03:08 garfieldnate

I can confirm this is also happening on Monterey on Intel Mac.

pangdaxing23 avatar Oct 16 '23 01:10 pangdaxing23

We need a programmer to solve this bug : )

sunshaoce avatar Oct 16 '23 10:10 sunshaoce

@sunshaoce This is getting a major issue. CodeLLDB also stopped working recently.

H-G-Hristov avatar Oct 17 '23 06:10 H-G-Hristov

https://github.com/microsoft/vscode-cpptools/issues/7240 Here seems to be a feasible solution, can any Mac users help test it out?

sunshaoce avatar Nov 30 '23 06:11 sunshaoce

Same thing to me after this much time, on vs code Screenshot 2024-05-29 alle 10 15 10

Ningen-jpg avatar May 29 '24 08:05 Ningen-jpg

Did you build the latest lldb-mi (a6c8c66d70b13209f3dabba5b6aefb2c58c3976c)?

sunshaoce avatar May 29 '24 10:05 sunshaoce