From 6e84ab9a14e63c58e1facdbf9a695c093882b37b Mon Sep 17 00:00:00 2001 From: jeffreytan81 Date: Mon, 19 Aug 2024 10:57:35 -0700 Subject: [PATCH 1/5] Fix StartDebuggingRequestHandler/ReplModeRequestHandler in lldb-dap --- lldb/tools/lldb-dap/DAP.h | 2 -- lldb/tools/lldb-dap/lldb-dap.cpp | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h index 57562a1498351..7828272aa15a7 100644 --- a/lldb/tools/lldb-dap/DAP.h +++ b/lldb/tools/lldb-dap/DAP.h @@ -192,8 +192,6 @@ struct DAP { std::mutex call_mutex; std::map inflight_reverse_requests; - StartDebuggingRequestHandler start_debugging_request_handler; - ReplModeRequestHandler repl_mode_request_handler; ReplMode repl_mode; std::string command_escape_prefix = "`"; lldb::SBFormat frame_format; diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index ea84f31aec3a6..f50a6c1731073 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -1627,12 +1627,12 @@ void request_initialize(const llvm::json::Object &request) { "lldb-dap", "Commands for managing lldb-dap."); if (GetBoolean(arguments, "supportsStartDebuggingRequest", false)) { cmd.AddCommand( - "startDebugging", &g_dap.start_debugging_request_handler, + "startDebugging", new StartDebuggingRequestHandler(), "Sends a startDebugging request from the debug adapter to the client " "to start a child debug session of the same type as the caller."); } cmd.AddCommand( - "repl-mode", &g_dap.repl_mode_request_handler, + "repl-mode", new ReplModeRequestHandler(), "Get or set the repl behavior of lldb-dap evaluation requests."); g_dap.progress_event_thread = std::thread(ProgressEventThreadFunction); From d56c9b32f46e2c08ca134834b670bf3b1dad6c53 Mon Sep 17 00:00:00 2001 From: jeffreytan81 Date: Thu, 12 Sep 2024 09:05:33 -0700 Subject: [PATCH 2/5] Add CreateBoolValue API --- lldb/examples/synthetic/gnu_libstdcpp.py | 6 +----- lldb/include/lldb/API/SBValue.h | 2 ++ lldb/source/API/SBValue.cpp | 27 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lldb/examples/synthetic/gnu_libstdcpp.py b/lldb/examples/synthetic/gnu_libstdcpp.py index d98495b8a9df3..597298dfce36b 100644 --- a/lldb/examples/synthetic/gnu_libstdcpp.py +++ b/lldb/examples/synthetic/gnu_libstdcpp.py @@ -473,11 +473,7 @@ def get_child_at_index(self, index): "[" + str(index) + "]", element_offset, element_type ) bit = element.GetValueAsUnsigned(0) & (1 << bit_offset) - if bit != 0: - value_expr = "(bool)true" - else: - value_expr = "(bool)false" - return self.valobj.CreateValueFromExpression("[%d]" % index, value_expr) + return self.valobj.CreateBooleanValue("[%d]" % index, bool(bit)) def update(self): try: diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h index bec816fb45184..aeda26cb6dd79 100644 --- a/lldb/include/lldb/API/SBValue.h +++ b/lldb/include/lldb/API/SBValue.h @@ -146,6 +146,8 @@ class LLDB_API SBValue { lldb::SBValue CreateValueFromData(const char *name, lldb::SBData data, lldb::SBType type); + lldb::SBValue CreateBoolValue(const char *name, bool value); + /// Get a child value by index from a value. /// /// Structs, unions, classes, arrays and pointers have child diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index 273aac5ad4798..eb54213f4e60b 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -645,6 +645,33 @@ lldb::SBValue SBValue::CreateValueFromData(const char *name, SBData data, return sb_value; } +lldb::SBValue SBValue::CreateBoolValue(const char *name, bool value) { + LLDB_INSTRUMENT_VA(this, name); + + lldb::SBValue sb_value; + lldb::ValueObjectSP new_value_sp; + ValueLocker locker; + lldb::ValueObjectSP value_sp(GetSP(locker)); + ProcessSP process_sp = m_opaque_sp->GetProcessSP(); + lldb::SBTarget target = GetTarget(); + if (!target.IsValid()) + return sb_value; + lldb::SBType boolean_type = target.GetBasicType(lldb::eBasicTypeBool); + lldb::TypeImplSP type_impl_sp(boolean_type.GetSP()); + if (value_sp && process_sp && type_impl_sp) { + int data_buf[1] = {value ? 1 : 0}; + lldb::SBData data = lldb::SBData::CreateDataFromSInt32Array( + process_sp->GetByteOrder(), sizeof(data_buf[0]), data_buf, + sizeof(data_buf) / sizeof(data_buf[0])); + ExecutionContext exe_ctx(value_sp->GetExecutionContextRef()); + new_value_sp = ValueObject::CreateValueObjectFromData( + name, **data, exe_ctx, type_impl_sp->GetCompilerType(true)); + new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); + } + sb_value.SetSP(new_value_sp); + return sb_value; +} + SBValue SBValue::GetChildAtIndex(uint32_t idx) { LLDB_INSTRUMENT_VA(this, idx); From 37a5ffac3d7cb50713be3fb6d6c46c6b527f2aa5 Mon Sep 17 00:00:00 2001 From: jeffreytan81 Date: Thu, 12 Sep 2024 10:08:39 -0700 Subject: [PATCH 3/5] Fix typo --- lldb/examples/synthetic/gnu_libstdcpp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/examples/synthetic/gnu_libstdcpp.py b/lldb/examples/synthetic/gnu_libstdcpp.py index 597298dfce36b..a6605a7a7eb5b 100644 --- a/lldb/examples/synthetic/gnu_libstdcpp.py +++ b/lldb/examples/synthetic/gnu_libstdcpp.py @@ -473,7 +473,7 @@ def get_child_at_index(self, index): "[" + str(index) + "]", element_offset, element_type ) bit = element.GetValueAsUnsigned(0) & (1 << bit_offset) - return self.valobj.CreateBooleanValue("[%d]" % index, bool(bit)) + return self.valobj.CreateBoolValue("[%d]" % index, bool(bit)) def update(self): try: From 257cd0d0ac95c975ba280ce929eeba15bbe29a39 Mon Sep 17 00:00:00 2001 From: jeffreytan81 Date: Thu, 12 Sep 2024 14:56:53 -0700 Subject: [PATCH 4/5] Use ValueObject::CreateValueObjectFromBool() API --- lldb/include/lldb/API/SBValue.h | 2 +- lldb/source/API/SBValue.cpp | 18 ++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h index aeda26cb6dd79..9090cece80f7c 100644 --- a/lldb/include/lldb/API/SBValue.h +++ b/lldb/include/lldb/API/SBValue.h @@ -145,7 +145,7 @@ class LLDB_API SBValue { // AddressOf() on the return of this call all return invalid lldb::SBValue CreateValueFromData(const char *name, lldb::SBData data, lldb::SBType type); - + // Returned value has no address. lldb::SBValue CreateBoolValue(const char *name, bool value); /// Get a child value by index from a value. diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index eb54213f4e60b..8ac32858e4313 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -652,20 +652,10 @@ lldb::SBValue SBValue::CreateBoolValue(const char *name, bool value) { lldb::ValueObjectSP new_value_sp; ValueLocker locker; lldb::ValueObjectSP value_sp(GetSP(locker)); - ProcessSP process_sp = m_opaque_sp->GetProcessSP(); - lldb::SBTarget target = GetTarget(); - if (!target.IsValid()) - return sb_value; - lldb::SBType boolean_type = target.GetBasicType(lldb::eBasicTypeBool); - lldb::TypeImplSP type_impl_sp(boolean_type.GetSP()); - if (value_sp && process_sp && type_impl_sp) { - int data_buf[1] = {value ? 1 : 0}; - lldb::SBData data = lldb::SBData::CreateDataFromSInt32Array( - process_sp->GetByteOrder(), sizeof(data_buf[0]), data_buf, - sizeof(data_buf) / sizeof(data_buf[0])); - ExecutionContext exe_ctx(value_sp->GetExecutionContextRef()); - new_value_sp = ValueObject::CreateValueObjectFromData( - name, **data, exe_ctx, type_impl_sp->GetCompilerType(true)); + lldb::TargetSP target_sp = m_opaque_sp->GetTargetSP(); + if (value_sp && target_sp) { + new_value_sp = + ValueObject::CreateValueObjectFromBool(target_sp, value, name); new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); } sb_value.SetSP(new_value_sp); From 713242a86edfe4e7636cef152606b6f99191fd4b Mon Sep 17 00:00:00 2001 From: jeffreytan81 Date: Thu, 12 Sep 2024 17:19:37 -0700 Subject: [PATCH 5/5] Remove SetAddressTypeOfChildren() call --- lldb/source/API/SBValue.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index 8ac32858e4313..e1a31708d46ff 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -656,7 +656,6 @@ lldb::SBValue SBValue::CreateBoolValue(const char *name, bool value) { if (value_sp && target_sp) { new_value_sp = ValueObject::CreateValueObjectFromBool(target_sp, value, name); - new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); } sb_value.SetSP(new_value_sp); return sb_value;