Skip to content

[lldb][dap] Avoid concurrent HandleCommand calls #83162

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

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import os
import unittest

import dap_server
import lldbdap_testcase
from lldbsuite.test import lldbtest, lldbutil
from lldbsuite.test.decorators import *


@unittest.skip("https://llvm.org/PR81686")
class TestDAP_commands(lldbdap_testcase.DAPTestCaseBase):
def test_command_directive_quiet_on_success(self):
program = self.getBuildArtifact("a.out")
Expand Down
12 changes: 11 additions & 1 deletion lldb/tools/lldb-dap/LLDBUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "LLDBUtils.h"
#include "DAP.h"

#include <mutex>

namespace lldb_dap {

bool RunLLDBCommands(llvm::StringRef prefix,
Expand Down Expand Up @@ -37,7 +39,15 @@ bool RunLLDBCommands(llvm::StringRef prefix,
}
}

interp.HandleCommand(command.str().c_str(), result);
{
// Prevent simultaneous calls to HandleCommand, e.g. EventThreadFunction
// may asynchronously call RunExitCommands when we are already calling
// RunTerminateCommands.
static std::mutex handle_command_mutex;
std::lock_guard<std::mutex> locker(handle_command_mutex);
interp.HandleCommand(command.str().c_str(), result);
}

const bool got_error = !result.Succeeded();
// The if statement below is assuming we always print out `!` prefixed
// lines. The only time we don't print is when we have `quiet_on_success ==
Expand Down