Skip to content

Commit 04f0a42

Browse files
committed
[lldb-dap] Refactoring IO handling for the SBDebugger.
This refactors the IO handling of lldb-dap and its SBDebugger. This adjusts the SBDebugger instance to have a pty associated with in/out/err. Using a pty allows us to handle commands with raw input modes, such as `script` or `breakpoint command add`. Additionally, to better handle output produced by the debugger and evaluate command I added a print helper. This new print helper will inspect the SBCommandReturnObject and store any associated variables in the variable store. This lets users more easily inspect variables directly in the Debug Console in VSCode.
1 parent e05fffb commit 04f0a42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1182
-744
lines changed

lldb/include/lldb/Utility/LLDBLog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ enum class LLDBLog : Log::MaskType {
5757
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
5858

5959
void InitializeLldbChannel();
60+
void TerminateLldbChannel();
6061

6162
template <> Log::Channel &LogChannelFor<LLDBLog>();
6263
} // namespace lldb_private

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -995,15 +995,15 @@ def request_writeMemory(self, memoryReference, data, offset=0, allowPartial=Fals
995995

996996
def request_evaluate(
997997
self,
998-
expression,
998+
expression: str,
999999
frameIndex=0,
1000-
threadId=None,
1001-
context=None,
1000+
threadId: Optional[int] = None,
1001+
context: Optional[
1002+
Literal["watch", "repl", "hover", "clipboard", "variables"]
1003+
] = None,
10021004
is_hex: Optional[bool] = None,
1003-
):
1005+
) -> Optional[Response]:
10041006
stackFrame = self.get_stackFrame(frameIndex=frameIndex, threadId=threadId)
1005-
if stackFrame is None:
1006-
return []
10071007
args_dict = {
10081008
"expression": expression,
10091009
"frameId": stackFrame["id"],
@@ -1012,7 +1012,7 @@ def request_evaluate(
10121012
args_dict["context"] = context
10131013
if is_hex is not None:
10141014
args_dict["format"] = {"hex": is_hex}
1015-
command_dict = {
1015+
command_dict: Request = {
10161016
"command": "evaluate",
10171017
"type": "request",
10181018
"arguments": args_dict,

lldb/source/Core/Debugger.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,11 @@ void Debugger::Terminate() {
743743
debugger->Clear();
744744
g_debugger_list_ptr->clear();
745745
}
746+
747+
delete g_debugger_list_ptr;
748+
delete g_debugger_list_mutex_ptr;
749+
g_debugger_list_ptr = nullptr;
750+
g_debugger_list_mutex_ptr = nullptr;
746751
}
747752
}
748753

lldb/source/Initialization/SystemInitializerCommon.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,5 @@ void SystemInitializerCommon::Terminate() {
101101
Log::DisableAllLogChannels();
102102
FileSystem::Terminate();
103103
Diagnostics::Terminate();
104+
TerminateLldbChannel();
104105
}

lldb/source/Utility/LLDBLog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,5 @@ template <> Log::Channel &lldb_private::LogChannelFor<LLDBLog>() {
8787
void lldb_private::InitializeLldbChannel() {
8888
Log::Register("lldb", g_log_channel);
8989
}
90+
91+
void lldb_private::TerminateLldbChannel() { Log::Unregister("lldb"); }

lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Test lldb-dap cancel request
33
"""
44

5-
import time
6-
75
from lldbsuite.test.decorators import *
86
from lldbsuite.test.lldbtest import *
97
import lldbdap_testcase

lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def run_test_evaluate_expressions(
128128
self.assertEvaluate("var1", "20", want_type="int")
129129
# Empty expression should equate to the previous expression.
130130
if context == "repl":
131+
self.assertEvaluate("p var1", "20")
131132
self.assertEvaluate("", "20")
132133
else:
133134
self.assertEvaluateFailure("")

0 commit comments

Comments
 (0)