[Lldb-commits] [lldb] [lldb] Use llvm::replace (NFC) (PR #140343)

2025-05-17 Thread Kazu Hirata via lldb-commits

https://github.com/kazutakahirata closed 
https://github.com/llvm/llvm-project/pull/140343
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 68e4f60 - [lldb] Use llvm::replace (NFC) (#140343)

2025-05-17 Thread via lldb-commits

Author: Kazu Hirata
Date: 2025-05-17T09:09:10-07:00
New Revision: 68e4f6090b369c14da8c6ef1f614664b9e0427e1

URL: 
https://github.com/llvm/llvm-project/commit/68e4f6090b369c14da8c6ef1f614664b9e0427e1
DIFF: 
https://github.com/llvm/llvm-project/commit/68e4f6090b369c14da8c6ef1f614664b9e0427e1.diff

LOG: [lldb] Use llvm::replace (NFC) (#140343)

Added: 


Modified: 
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/source/Utility/FileSpec.cpp
lldb/utils/TableGen/LLDBOptionDefEmitter.cpp
lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp

Removed: 




diff  --git a/lldb/source/Interpreter/CommandInterpreter.cpp 
b/lldb/source/Interpreter/CommandInterpreter.cpp
index eb4741feb0aa5..34749d890bf03 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -3346,9 +3346,9 @@ bool CommandInterpreter::SaveTranscript(
 CommandReturnObject &result, std::optional output_file) {
   if (output_file == std::nullopt || output_file->empty()) {
 std::string now = llvm::to_string(std::chrono::system_clock::now());
-std::replace(now.begin(), now.end(), ' ', '_');
+llvm::replace(now, ' ', '_');
 // Can't have file name with colons on Windows
-std::replace(now.begin(), now.end(), ':', '-');
+llvm::replace(now, ':', '-');
 const std::string file_name = "lldb_session_" + now + ".log";
 
 FileSpec save_location = GetSaveSessionDirectory();

diff  --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
index 3b601726388d6..1feeeb64aa9e5 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
@@ -251,8 +251,8 @@ TokenVerifier::TokenVerifier(std::string body) {
   // We only care about tokens and not their original source locations. If we
   // move the whole expression to only be in one line we can simplify the
   // following code that extracts the token contents.
-  std::replace(body.begin(), body.end(), '\n', ' ');
-  std::replace(body.begin(), body.end(), '\r', ' ');
+  llvm::replace(body, '\n', ' ');
+  llvm::replace(body, '\r', ' ');
 
   FileSystemOptions file_opts;
   FileManager file_mgr(file_opts,

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 3c3a0aa992d9c..262a7dc731713 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -237,12 +237,9 @@ FileSpecList 
PlatformDarwin::LocateExecutableScriptingResources(
   // ScriptInterpreter. For now, we just replace dots with
   // underscores, but if we ever support anything other than
   // Python we will need to rework this
-  std::replace(module_basename.begin(), module_basename.end(), '.',
-   '_');
-  std::replace(module_basename.begin(), module_basename.end(), ' ',
-   '_');
-  std::replace(module_basename.begin(), module_basename.end(), '-',
-   '_');
+  llvm::replace(module_basename, '.', '_');
+  llvm::replace(module_basename, ' ', '_');
+  llvm::replace(module_basename, '-', '_');
   ScriptInterpreter *script_interpreter =
   target->GetDebugger().GetScriptInterpreter();
   if (script_interpreter &&

diff  --git a/lldb/source/Utility/FileSpec.cpp 
b/lldb/source/Utility/FileSpec.cpp
index bb2b8647342b8..69d921643da2a 100644
--- a/lldb/source/Utility/FileSpec.cpp
+++ b/lldb/source/Utility/FileSpec.cpp
@@ -60,7 +60,7 @@ void Denormalize(llvm::SmallVectorImpl &path, 
FileSpec::Style style) {
   if (PathStyleIsPosix(style))
 return;
 
-  std::replace(path.begin(), path.end(), '/', '\\');
+  llvm::replace(path, '/', '\\');
 }
 
 } // end anonymous namespace
@@ -186,7 +186,7 @@ void FileSpec::SetFile(llvm::StringRef pathname, Style 
style) {
 
   // Normalize back slashes to forward slashes
   if (m_style == Style::windows)
-std::replace(resolved.begin(), resolved.end(), '\\', '/');
+llvm::replace(resolved, '\\', '/');
 
   if (resolved.empty()) {
 // If we have no path after normalization set the path to the current

diff  --git a/lldb/utils/TableGen/LLDBOptionDefEmitter.cpp 
b/lldb/utils/TableGen/LLDBOptionDefEmitter.cpp
index 735489c0e56a4..2507910d8a97a 100644
--- a/lldb/utils/TableGen/LLDBOptionDefEmitter.cpp
+++ b/lldb/utils/TableGen/LLDBOptionDefEmitter.cpp
@@ -150,7 +150,7 @@ static void emitOptions(std::string Command, ArrayRef Records,
   std::

[Lldb-commits] [lldb] [lldb] Use llvm::replace (NFC) (PR #140343)

2025-05-17 Thread Tim Gymnich via lldb-commits

https://github.com/tgymnich approved this pull request.


https://github.com/llvm/llvm-project/pull/140343
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Member variable cleanup in DAP.{cpp, h} (NFC) (PR #140390)

2025-05-17 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere created 
https://github.com/llvm/llvm-project/pull/140390

- Use in-class member initialization to simplify the constructor.
- Remove unimplemented SetConfigurationDone.
- Consistently use Doxygen-style comments.

>From c546c86ac849f316c9b31b881e92d8683aa5 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Sat, 17 May 2025 11:17:41 -0700
Subject: [PATCH] [lldb-dap] Member variable cleanup in DAP.{cpp,h} (NFC)

- Use in-class member initialization to simplify the constructor.
- Remove unimplemented SetConfigurationDone.
- Consistently use Doxygen-style comments.
---
 lldb/tools/lldb-dap/DAP.cpp |  6 +---
 lldb/tools/lldb-dap/DAP.h   | 60 -
 2 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 0d5eba6c40961..d813cdb0b9074 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -118,13 +118,9 @@ llvm::StringRef DAP::debug_adapter_path = "";
 DAP::DAP(Log *log, const ReplMode default_repl_mode,
  std::vector pre_init_commands, Transport &transport)
 : log(log), transport(transport), broadcaster("lldb-dap"),
-  exception_breakpoints(), focus_tid(LLDB_INVALID_THREAD_ID),
-  stop_at_entry(false), is_attach(false),
-  restarting_process_id(LLDB_INVALID_PROCESS_ID), 
configuration_done(false),
-  waiting_for_run_in_terminal(false),
   progress_event_reporter(
   [&](const ProgressEvent &event) { SendJSON(event.ToJSON()); }),
-  reverse_request_seq(0), repl_mode(default_repl_mode) {
+  repl_mode(default_repl_mode) {
   configuration.preInitCommands = std::move(pre_init_commands);
   RegisterRequests();
 }
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 8f24c6cf82924..975e2b290e1f9 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -162,10 +162,16 @@ struct DAP {
   lldb::SBFile in;
   OutputRedirector out;
   OutputRedirector err;
+
   /// Configuration specified by the launch or attach commands.
   protocol::Configuration configuration;
+
+  /// The debugger instance for this DAP session.
   lldb::SBDebugger debugger;
+
+  /// The target instance for this DAP session.
   lldb::SBTarget target;
+
   Variables variables;
   lldb::SBBroadcaster broadcaster;
   llvm::StringMap source_breakpoints;
@@ -173,39 +179,53 @@ struct DAP {
   InstructionBreakpointMap instruction_breakpoints;
   std::optional> exception_breakpoints;
   llvm::once_flag init_exception_breakpoints_flag;
-  // Map step in target id to list of function targets that user can choose.
+
+  /// Map step in target id to list of function targets that user can choose.
   llvm::DenseMap step_in_targets;
-  // A copy of the last LaunchRequest so we can reuse its arguments if we get a
-  // RestartRequest. Restarting an AttachRequest is not supported.
+
+  /// A copy of the last LaunchRequest so we can reuse its arguments if we get 
a
+  /// RestartRequest. Restarting an AttachRequest is not supported.
   std::optional last_launch_request;
-  lldb::tid_t focus_tid;
+
+  /// The focused thread for this DAP session.
+  lldb::tid_t focus_tid = LLDB_INVALID_THREAD_ID;
+
   bool disconnecting = false;
   llvm::once_flag terminated_event_flag;
-  bool stop_at_entry;
-  bool is_attach;
-  // The process event thread normally responds to process exited events by
-  // shutting down the entire adapter. When we're restarting, we keep the id of
-  // the old process here so we can detect this case and keep running.
-  lldb::pid_t restarting_process_id;
+  bool stop_at_entry = false;
+  bool is_attach = false;
+
+  /// The process event thread normally responds to process exited events by
+  /// shutting down the entire adapter. When we're restarting, we keep the id 
of
+  /// the old process here so we can detect this case and keep running.
+  lldb::pid_t restarting_process_id = LLDB_INVALID_PROCESS_ID;
+
+  /// Whether we have received the ConfigurationDone request, indicating that
+  /// the client has finished initialization of the debug adapter.
   bool configuration_done;
-  bool waiting_for_run_in_terminal;
+
+  bool waiting_for_run_in_terminal = false;
   ProgressEventReporter progress_event_reporter;
-  // Keep track of the last stop thread index IDs as threads won't go away
-  // unless we send a "thread" event to indicate the thread exited.
+
+  /// Keep track of the last stop thread index IDs as threads won't go away
+  /// unless we send a "thread" event to indicate the thread exited.
   llvm::DenseSet thread_ids;
-  uint32_t reverse_request_seq;
+
+  uint32_t reverse_request_seq = 0;
   std::mutex call_mutex;
   llvm::SmallDenseMap>
   inflight_reverse_requests;
   ReplMode repl_mode;
   lldb::SBFormat frame_format;
   lldb::SBFormat thread_format;
-  // This is used to allow request_evaluate to handle empty expressions
-  // (ie the user pressed 'return' and expects the previous express

[Lldb-commits] [lldb] [lldb-dap] Member variable cleanup in DAP.{cpp, h} (NFC) (PR #140390)

2025-05-17 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

- Use in-class member initialization to simplify the constructor.
- Remove unimplemented SetConfigurationDone.
- Consistently use Doxygen-style comments.

---
Full diff: https://github.com/llvm/llvm-project/pull/140390.diff


2 Files Affected:

- (modified) lldb/tools/lldb-dap/DAP.cpp (+1-5) 
- (modified) lldb/tools/lldb-dap/DAP.h (+39-21) 


``diff
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 0d5eba6c40961..d813cdb0b9074 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -118,13 +118,9 @@ llvm::StringRef DAP::debug_adapter_path = "";
 DAP::DAP(Log *log, const ReplMode default_repl_mode,
  std::vector pre_init_commands, Transport &transport)
 : log(log), transport(transport), broadcaster("lldb-dap"),
-  exception_breakpoints(), focus_tid(LLDB_INVALID_THREAD_ID),
-  stop_at_entry(false), is_attach(false),
-  restarting_process_id(LLDB_INVALID_PROCESS_ID), 
configuration_done(false),
-  waiting_for_run_in_terminal(false),
   progress_event_reporter(
   [&](const ProgressEvent &event) { SendJSON(event.ToJSON()); }),
-  reverse_request_seq(0), repl_mode(default_repl_mode) {
+  repl_mode(default_repl_mode) {
   configuration.preInitCommands = std::move(pre_init_commands);
   RegisterRequests();
 }
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 8f24c6cf82924..975e2b290e1f9 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -162,10 +162,16 @@ struct DAP {
   lldb::SBFile in;
   OutputRedirector out;
   OutputRedirector err;
+
   /// Configuration specified by the launch or attach commands.
   protocol::Configuration configuration;
+
+  /// The debugger instance for this DAP session.
   lldb::SBDebugger debugger;
+
+  /// The target instance for this DAP session.
   lldb::SBTarget target;
+
   Variables variables;
   lldb::SBBroadcaster broadcaster;
   llvm::StringMap source_breakpoints;
@@ -173,39 +179,53 @@ struct DAP {
   InstructionBreakpointMap instruction_breakpoints;
   std::optional> exception_breakpoints;
   llvm::once_flag init_exception_breakpoints_flag;
-  // Map step in target id to list of function targets that user can choose.
+
+  /// Map step in target id to list of function targets that user can choose.
   llvm::DenseMap step_in_targets;
-  // A copy of the last LaunchRequest so we can reuse its arguments if we get a
-  // RestartRequest. Restarting an AttachRequest is not supported.
+
+  /// A copy of the last LaunchRequest so we can reuse its arguments if we get 
a
+  /// RestartRequest. Restarting an AttachRequest is not supported.
   std::optional last_launch_request;
-  lldb::tid_t focus_tid;
+
+  /// The focused thread for this DAP session.
+  lldb::tid_t focus_tid = LLDB_INVALID_THREAD_ID;
+
   bool disconnecting = false;
   llvm::once_flag terminated_event_flag;
-  bool stop_at_entry;
-  bool is_attach;
-  // The process event thread normally responds to process exited events by
-  // shutting down the entire adapter. When we're restarting, we keep the id of
-  // the old process here so we can detect this case and keep running.
-  lldb::pid_t restarting_process_id;
+  bool stop_at_entry = false;
+  bool is_attach = false;
+
+  /// The process event thread normally responds to process exited events by
+  /// shutting down the entire adapter. When we're restarting, we keep the id 
of
+  /// the old process here so we can detect this case and keep running.
+  lldb::pid_t restarting_process_id = LLDB_INVALID_PROCESS_ID;
+
+  /// Whether we have received the ConfigurationDone request, indicating that
+  /// the client has finished initialization of the debug adapter.
   bool configuration_done;
-  bool waiting_for_run_in_terminal;
+
+  bool waiting_for_run_in_terminal = false;
   ProgressEventReporter progress_event_reporter;
-  // Keep track of the last stop thread index IDs as threads won't go away
-  // unless we send a "thread" event to indicate the thread exited.
+
+  /// Keep track of the last stop thread index IDs as threads won't go away
+  /// unless we send a "thread" event to indicate the thread exited.
   llvm::DenseSet thread_ids;
-  uint32_t reverse_request_seq;
+
+  uint32_t reverse_request_seq = 0;
   std::mutex call_mutex;
   llvm::SmallDenseMap>
   inflight_reverse_requests;
   ReplMode repl_mode;
   lldb::SBFormat frame_format;
   lldb::SBFormat thread_format;
-  // This is used to allow request_evaluate to handle empty expressions
-  // (ie the user pressed 'return' and expects the previous expression to
-  // repeat). If the previous expression was a command, this string will be
-  // empty; if the previous expression was a variable expression, this string
-  // will contain that expression.
+
+  /// This is used to allow request_evaluate to handle empty expressions
+  /// (ie the user pressed 'return' and exp

[Lldb-commits] [lldb] [lldb-dap] Move the Variables struct into its own file (NFC) (PR #140393)

2025-05-17 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Move the Variables struct out of DAP.h and into its own file to reduce the 
complexity of the latter. This PR also makes the members that are 
implementation details private.

---
Full diff: https://github.com/llvm/llvm-project/pull/140393.diff


5 Files Affected:

- (modified) lldb/tools/lldb-dap/CMakeLists.txt (+1) 
- (modified) lldb/tools/lldb-dap/DAP.cpp (-93) 
- (modified) lldb/tools/lldb-dap/DAP.h (+1-50) 
- (added) lldb/tools/lldb-dap/Variables.cpp (+105) 
- (added) lldb/tools/lldb-dap/Variables.h (+71) 


``diff
diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 5dedee8a87f41..f8e81eaff8606 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -23,6 +23,7 @@ add_lldb_library(lldbDAP
   RunInTerminal.cpp
   SourceBreakpoint.cpp
   Transport.cpp
+  Variables.cpp
   Watchpoint.cpp
 
   Handler/ResponseHandler.cpp
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 0d5eba6c40961..af46838f5671c 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1021,45 +1021,6 @@ lldb::SBError 
DAP::WaitForProcessToStop(std::chrono::seconds seconds) {
   return error;
 }
 
-void Variables::Clear() {
-  locals.Clear();
-  globals.Clear();
-  registers.Clear();
-  referenced_variables.clear();
-}
-
-int64_t Variables::GetNewVariableReference(bool is_permanent) {
-  if (is_permanent)
-return next_permanent_var_ref++;
-  return next_temporary_var_ref++;
-}
-
-bool Variables::IsPermanentVariableReference(int64_t var_ref) {
-  return var_ref >= PermanentVariableStartIndex;
-}
-
-lldb::SBValue Variables::GetVariable(int64_t var_ref) const {
-  if (IsPermanentVariableReference(var_ref)) {
-auto pos = referenced_permanent_variables.find(var_ref);
-if (pos != referenced_permanent_variables.end())
-  return pos->second;
-  } else {
-auto pos = referenced_variables.find(var_ref);
-if (pos != referenced_variables.end())
-  return pos->second;
-  }
-  return lldb::SBValue();
-}
-
-int64_t Variables::InsertVariable(lldb::SBValue variable, bool is_permanent) {
-  int64_t var_ref = GetNewVariableReference(is_permanent);
-  if (is_permanent)
-referenced_permanent_variables.insert(std::make_pair(var_ref, variable));
-  else
-referenced_variables.insert(std::make_pair(var_ref, variable));
-  return var_ref;
-}
-
 bool StartDebuggingRequestHandler::DoExecute(
 lldb::SBDebugger debugger, char **command,
 lldb::SBCommandReturnObject &result) {
@@ -1296,60 +1257,6 @@ DAP::GetInstructionBPFromStopReason(lldb::SBThread 
&thread) {
   return inst_bp;
 }
 
-lldb::SBValueList *Variables::GetTopLevelScope(int64_t variablesReference) {
-  switch (variablesReference) {
-  case VARREF_LOCALS:
-return &locals;
-  case VARREF_GLOBALS:
-return &globals;
-  case VARREF_REGS:
-return ®isters;
-  default:
-return nullptr;
-  }
-}
-
-lldb::SBValue Variables::FindVariable(uint64_t variablesReference,
-  llvm::StringRef name) {
-  lldb::SBValue variable;
-  if (lldb::SBValueList *top_scope = GetTopLevelScope(variablesReference)) {
-bool is_duplicated_variable_name = name.contains(" @");
-// variablesReference is one of our scopes, not an actual variable it is
-// asking for a variable in locals or globals or registers
-int64_t end_idx = top_scope->GetSize();
-// Searching backward so that we choose the variable in closest scope
-// among variables of the same name.
-for (int64_t i = end_idx - 1; i >= 0; --i) {
-  lldb::SBValue curr_variable = top_scope->GetValueAtIndex(i);
-  std::string variable_name = CreateUniqueVariableNameForDisplay(
-  curr_variable, is_duplicated_variable_name);
-  if (variable_name == name) {
-variable = curr_variable;
-break;
-  }
-}
-  } else {
-// This is not under the globals or locals scope, so there are no
-// duplicated names.
-
-// We have a named item within an actual variable so we need to find it
-// withing the container variable by name.
-lldb::SBValue container = GetVariable(variablesReference);
-variable = container.GetChildMemberWithName(name.data());
-if (!variable.IsValid()) {
-  if (name.starts_with("[")) {
-llvm::StringRef index_str(name.drop_front(1));
-uint64_t index = 0;
-if (!index_str.consumeInteger(0, index)) {
-  if (index_str == "]")
-variable = container.GetChildAtIndex(index);
-}
-  }
-}
-  }
-  return variable;
-}
-
 protocol::Capabilities DAP::GetCapabilities() {
   protocol::Capabilities capabilities;
 
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 8f24c6cf82924..033203309b4c6 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -20,6 +20,7 @@
 #include "Protocol/Prot

[Lldb-commits] [lldb] [lldb-dap] Move the Variables struct into its own file (NFC) (PR #140393)

2025-05-17 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere created 
https://github.com/llvm/llvm-project/pull/140393

Move the Variables struct out of DAP.h and into its own file to reduce the 
complexity of the latter. This PR also makes the members that are 
implementation details private.

>From 82cd419423f74777e248743534f2da48ae6b72c9 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Sat, 17 May 2025 11:34:48 -0700
Subject: [PATCH] [lldb-dap] Move the Variables struct into its own file (NFC)

Move the Variables struct out of DAP.h and into its own file to reduce
the complexity of the latter. This PR also makes the members that are
implementation details private.
---
 lldb/tools/lldb-dap/CMakeLists.txt |   1 +
 lldb/tools/lldb-dap/DAP.cpp|  93 -
 lldb/tools/lldb-dap/DAP.h  |  51 +-
 lldb/tools/lldb-dap/Variables.cpp  | 105 +
 lldb/tools/lldb-dap/Variables.h|  71 +++
 5 files changed, 178 insertions(+), 143 deletions(-)
 create mode 100644 lldb/tools/lldb-dap/Variables.cpp
 create mode 100644 lldb/tools/lldb-dap/Variables.h

diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 5dedee8a87f41..f8e81eaff8606 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -23,6 +23,7 @@ add_lldb_library(lldbDAP
   RunInTerminal.cpp
   SourceBreakpoint.cpp
   Transport.cpp
+  Variables.cpp
   Watchpoint.cpp
 
   Handler/ResponseHandler.cpp
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 0d5eba6c40961..af46838f5671c 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1021,45 +1021,6 @@ lldb::SBError 
DAP::WaitForProcessToStop(std::chrono::seconds seconds) {
   return error;
 }
 
-void Variables::Clear() {
-  locals.Clear();
-  globals.Clear();
-  registers.Clear();
-  referenced_variables.clear();
-}
-
-int64_t Variables::GetNewVariableReference(bool is_permanent) {
-  if (is_permanent)
-return next_permanent_var_ref++;
-  return next_temporary_var_ref++;
-}
-
-bool Variables::IsPermanentVariableReference(int64_t var_ref) {
-  return var_ref >= PermanentVariableStartIndex;
-}
-
-lldb::SBValue Variables::GetVariable(int64_t var_ref) const {
-  if (IsPermanentVariableReference(var_ref)) {
-auto pos = referenced_permanent_variables.find(var_ref);
-if (pos != referenced_permanent_variables.end())
-  return pos->second;
-  } else {
-auto pos = referenced_variables.find(var_ref);
-if (pos != referenced_variables.end())
-  return pos->second;
-  }
-  return lldb::SBValue();
-}
-
-int64_t Variables::InsertVariable(lldb::SBValue variable, bool is_permanent) {
-  int64_t var_ref = GetNewVariableReference(is_permanent);
-  if (is_permanent)
-referenced_permanent_variables.insert(std::make_pair(var_ref, variable));
-  else
-referenced_variables.insert(std::make_pair(var_ref, variable));
-  return var_ref;
-}
-
 bool StartDebuggingRequestHandler::DoExecute(
 lldb::SBDebugger debugger, char **command,
 lldb::SBCommandReturnObject &result) {
@@ -1296,60 +1257,6 @@ DAP::GetInstructionBPFromStopReason(lldb::SBThread 
&thread) {
   return inst_bp;
 }
 
-lldb::SBValueList *Variables::GetTopLevelScope(int64_t variablesReference) {
-  switch (variablesReference) {
-  case VARREF_LOCALS:
-return &locals;
-  case VARREF_GLOBALS:
-return &globals;
-  case VARREF_REGS:
-return ®isters;
-  default:
-return nullptr;
-  }
-}
-
-lldb::SBValue Variables::FindVariable(uint64_t variablesReference,
-  llvm::StringRef name) {
-  lldb::SBValue variable;
-  if (lldb::SBValueList *top_scope = GetTopLevelScope(variablesReference)) {
-bool is_duplicated_variable_name = name.contains(" @");
-// variablesReference is one of our scopes, not an actual variable it is
-// asking for a variable in locals or globals or registers
-int64_t end_idx = top_scope->GetSize();
-// Searching backward so that we choose the variable in closest scope
-// among variables of the same name.
-for (int64_t i = end_idx - 1; i >= 0; --i) {
-  lldb::SBValue curr_variable = top_scope->GetValueAtIndex(i);
-  std::string variable_name = CreateUniqueVariableNameForDisplay(
-  curr_variable, is_duplicated_variable_name);
-  if (variable_name == name) {
-variable = curr_variable;
-break;
-  }
-}
-  } else {
-// This is not under the globals or locals scope, so there are no
-// duplicated names.
-
-// We have a named item within an actual variable so we need to find it
-// withing the container variable by name.
-lldb::SBValue container = GetVariable(variablesReference);
-variable = container.GetChildMemberWithName(name.data());
-if (!variable.IsValid()) {
-  if (name.starts_with("[")) {
-llvm::StringRef index_str(name.drop_front(1));
-uint64_t index = 0;
-if (!in

[Lldb-commits] [lldb] [lldb-dap] Move the Variables struct into its own file (NFC) (PR #140393)

2025-05-17 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/140393

>From 82cd419423f74777e248743534f2da48ae6b72c9 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Sat, 17 May 2025 11:34:48 -0700
Subject: [PATCH 1/2] [lldb-dap] Move the Variables struct into its own file
 (NFC)

Move the Variables struct out of DAP.h and into its own file to reduce
the complexity of the latter. This PR also makes the members that are
implementation details private.
---
 lldb/tools/lldb-dap/CMakeLists.txt |   1 +
 lldb/tools/lldb-dap/DAP.cpp|  93 -
 lldb/tools/lldb-dap/DAP.h  |  51 +-
 lldb/tools/lldb-dap/Variables.cpp  | 105 +
 lldb/tools/lldb-dap/Variables.h|  71 +++
 5 files changed, 178 insertions(+), 143 deletions(-)
 create mode 100644 lldb/tools/lldb-dap/Variables.cpp
 create mode 100644 lldb/tools/lldb-dap/Variables.h

diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 5dedee8a87f41..f8e81eaff8606 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -23,6 +23,7 @@ add_lldb_library(lldbDAP
   RunInTerminal.cpp
   SourceBreakpoint.cpp
   Transport.cpp
+  Variables.cpp
   Watchpoint.cpp
 
   Handler/ResponseHandler.cpp
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 0d5eba6c40961..af46838f5671c 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1021,45 +1021,6 @@ lldb::SBError 
DAP::WaitForProcessToStop(std::chrono::seconds seconds) {
   return error;
 }
 
-void Variables::Clear() {
-  locals.Clear();
-  globals.Clear();
-  registers.Clear();
-  referenced_variables.clear();
-}
-
-int64_t Variables::GetNewVariableReference(bool is_permanent) {
-  if (is_permanent)
-return next_permanent_var_ref++;
-  return next_temporary_var_ref++;
-}
-
-bool Variables::IsPermanentVariableReference(int64_t var_ref) {
-  return var_ref >= PermanentVariableStartIndex;
-}
-
-lldb::SBValue Variables::GetVariable(int64_t var_ref) const {
-  if (IsPermanentVariableReference(var_ref)) {
-auto pos = referenced_permanent_variables.find(var_ref);
-if (pos != referenced_permanent_variables.end())
-  return pos->second;
-  } else {
-auto pos = referenced_variables.find(var_ref);
-if (pos != referenced_variables.end())
-  return pos->second;
-  }
-  return lldb::SBValue();
-}
-
-int64_t Variables::InsertVariable(lldb::SBValue variable, bool is_permanent) {
-  int64_t var_ref = GetNewVariableReference(is_permanent);
-  if (is_permanent)
-referenced_permanent_variables.insert(std::make_pair(var_ref, variable));
-  else
-referenced_variables.insert(std::make_pair(var_ref, variable));
-  return var_ref;
-}
-
 bool StartDebuggingRequestHandler::DoExecute(
 lldb::SBDebugger debugger, char **command,
 lldb::SBCommandReturnObject &result) {
@@ -1296,60 +1257,6 @@ DAP::GetInstructionBPFromStopReason(lldb::SBThread 
&thread) {
   return inst_bp;
 }
 
-lldb::SBValueList *Variables::GetTopLevelScope(int64_t variablesReference) {
-  switch (variablesReference) {
-  case VARREF_LOCALS:
-return &locals;
-  case VARREF_GLOBALS:
-return &globals;
-  case VARREF_REGS:
-return ®isters;
-  default:
-return nullptr;
-  }
-}
-
-lldb::SBValue Variables::FindVariable(uint64_t variablesReference,
-  llvm::StringRef name) {
-  lldb::SBValue variable;
-  if (lldb::SBValueList *top_scope = GetTopLevelScope(variablesReference)) {
-bool is_duplicated_variable_name = name.contains(" @");
-// variablesReference is one of our scopes, not an actual variable it is
-// asking for a variable in locals or globals or registers
-int64_t end_idx = top_scope->GetSize();
-// Searching backward so that we choose the variable in closest scope
-// among variables of the same name.
-for (int64_t i = end_idx - 1; i >= 0; --i) {
-  lldb::SBValue curr_variable = top_scope->GetValueAtIndex(i);
-  std::string variable_name = CreateUniqueVariableNameForDisplay(
-  curr_variable, is_duplicated_variable_name);
-  if (variable_name == name) {
-variable = curr_variable;
-break;
-  }
-}
-  } else {
-// This is not under the globals or locals scope, so there are no
-// duplicated names.
-
-// We have a named item within an actual variable so we need to find it
-// withing the container variable by name.
-lldb::SBValue container = GetVariable(variablesReference);
-variable = container.GetChildMemberWithName(name.data());
-if (!variable.IsValid()) {
-  if (name.starts_with("[")) {
-llvm::StringRef index_str(name.drop_front(1));
-uint64_t index = 0;
-if (!index_str.consumeInteger(0, index)) {
-  if (index_str == "]")
-variable = container.GetChildAtIndex(index);
-}
-  }
-}
-  }
-  return va

[Lldb-commits] [lldb] [lldb-dap] Move the Variables struct into its own file (PR #140393)

2025-05-17 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere edited 
https://github.com/llvm/llvm-project/pull/140393
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Move the Variables struct into its own file (PR #140393)

2025-05-17 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere edited 
https://github.com/llvm/llvm-project/pull/140393
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Move the Variables struct into its own file (PR #140393)

2025-05-17 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/140393

>From 82cd419423f74777e248743534f2da48ae6b72c9 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Sat, 17 May 2025 11:34:48 -0700
Subject: [PATCH 1/3] [lldb-dap] Move the Variables struct into its own file
 (NFC)

Move the Variables struct out of DAP.h and into its own file to reduce
the complexity of the latter. This PR also makes the members that are
implementation details private.
---
 lldb/tools/lldb-dap/CMakeLists.txt |   1 +
 lldb/tools/lldb-dap/DAP.cpp|  93 -
 lldb/tools/lldb-dap/DAP.h  |  51 +-
 lldb/tools/lldb-dap/Variables.cpp  | 105 +
 lldb/tools/lldb-dap/Variables.h|  71 +++
 5 files changed, 178 insertions(+), 143 deletions(-)
 create mode 100644 lldb/tools/lldb-dap/Variables.cpp
 create mode 100644 lldb/tools/lldb-dap/Variables.h

diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 5dedee8a87f41..f8e81eaff8606 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -23,6 +23,7 @@ add_lldb_library(lldbDAP
   RunInTerminal.cpp
   SourceBreakpoint.cpp
   Transport.cpp
+  Variables.cpp
   Watchpoint.cpp
 
   Handler/ResponseHandler.cpp
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 0d5eba6c40961..af46838f5671c 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1021,45 +1021,6 @@ lldb::SBError 
DAP::WaitForProcessToStop(std::chrono::seconds seconds) {
   return error;
 }
 
-void Variables::Clear() {
-  locals.Clear();
-  globals.Clear();
-  registers.Clear();
-  referenced_variables.clear();
-}
-
-int64_t Variables::GetNewVariableReference(bool is_permanent) {
-  if (is_permanent)
-return next_permanent_var_ref++;
-  return next_temporary_var_ref++;
-}
-
-bool Variables::IsPermanentVariableReference(int64_t var_ref) {
-  return var_ref >= PermanentVariableStartIndex;
-}
-
-lldb::SBValue Variables::GetVariable(int64_t var_ref) const {
-  if (IsPermanentVariableReference(var_ref)) {
-auto pos = referenced_permanent_variables.find(var_ref);
-if (pos != referenced_permanent_variables.end())
-  return pos->second;
-  } else {
-auto pos = referenced_variables.find(var_ref);
-if (pos != referenced_variables.end())
-  return pos->second;
-  }
-  return lldb::SBValue();
-}
-
-int64_t Variables::InsertVariable(lldb::SBValue variable, bool is_permanent) {
-  int64_t var_ref = GetNewVariableReference(is_permanent);
-  if (is_permanent)
-referenced_permanent_variables.insert(std::make_pair(var_ref, variable));
-  else
-referenced_variables.insert(std::make_pair(var_ref, variable));
-  return var_ref;
-}
-
 bool StartDebuggingRequestHandler::DoExecute(
 lldb::SBDebugger debugger, char **command,
 lldb::SBCommandReturnObject &result) {
@@ -1296,60 +1257,6 @@ DAP::GetInstructionBPFromStopReason(lldb::SBThread 
&thread) {
   return inst_bp;
 }
 
-lldb::SBValueList *Variables::GetTopLevelScope(int64_t variablesReference) {
-  switch (variablesReference) {
-  case VARREF_LOCALS:
-return &locals;
-  case VARREF_GLOBALS:
-return &globals;
-  case VARREF_REGS:
-return ®isters;
-  default:
-return nullptr;
-  }
-}
-
-lldb::SBValue Variables::FindVariable(uint64_t variablesReference,
-  llvm::StringRef name) {
-  lldb::SBValue variable;
-  if (lldb::SBValueList *top_scope = GetTopLevelScope(variablesReference)) {
-bool is_duplicated_variable_name = name.contains(" @");
-// variablesReference is one of our scopes, not an actual variable it is
-// asking for a variable in locals or globals or registers
-int64_t end_idx = top_scope->GetSize();
-// Searching backward so that we choose the variable in closest scope
-// among variables of the same name.
-for (int64_t i = end_idx - 1; i >= 0; --i) {
-  lldb::SBValue curr_variable = top_scope->GetValueAtIndex(i);
-  std::string variable_name = CreateUniqueVariableNameForDisplay(
-  curr_variable, is_duplicated_variable_name);
-  if (variable_name == name) {
-variable = curr_variable;
-break;
-  }
-}
-  } else {
-// This is not under the globals or locals scope, so there are no
-// duplicated names.
-
-// We have a named item within an actual variable so we need to find it
-// withing the container variable by name.
-lldb::SBValue container = GetVariable(variablesReference);
-variable = container.GetChildMemberWithName(name.data());
-if (!variable.IsValid()) {
-  if (name.starts_with("[")) {
-llvm::StringRef index_str(name.drop_front(1));
-uint64_t index = 0;
-if (!index_str.consumeInteger(0, index)) {
-  if (index_str == "]")
-variable = container.GetChildAtIndex(index);
-}
-  }
-}
-  }
-  return va

[Lldb-commits] [lldb] [lldb-dap] Move the command plugins out of the DAP header (PR #140396)

2025-05-17 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere created 
https://github.com/llvm/llvm-project/pull/140396

Move the command plugins out of the DAP header and into their file. This PR 
also renames the classes from "RequestHandler" to "Command". Although they are 
implemented in terms of sending requests, they are not "handlers".

>From 2b1f57010f2377a588867c509afb921cd0ccdd71 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Sat, 17 May 2025 12:20:15 -0700
Subject: [PATCH] [lldb-dap] Move the command plugins out of the DAP header

Move the command plugins out of the DAP header and into their file. This
PR also renames the classes from "RequestHandler" to "Command". Although
they are implemented in terms of sending requests, they are not
"handlers".
---
 lldb/tools/lldb-dap/CMakeLists.txt|   1 +
 lldb/tools/lldb-dap/CommandPlugins.cpp| 163 ++
 lldb/tools/lldb-dap/CommandPlugins.h  |  40 +
 lldb/tools/lldb-dap/DAP.cpp   | 153 
 lldb/tools/lldb-dap/DAP.h |  21 ---
 .../Handler/InitializeRequestHandler.cpp  |   7 +-
 6 files changed, 208 insertions(+), 177 deletions(-)
 create mode 100644 lldb/tools/lldb-dap/CommandPlugins.cpp
 create mode 100644 lldb/tools/lldb-dap/CommandPlugins.h

diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 5dedee8a87f41..97cdf23484ea0 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -8,6 +8,7 @@ add_public_tablegen_target(LLDBDAPOptionsTableGen)
 add_lldb_library(lldbDAP
   Breakpoint.cpp
   BreakpointBase.cpp
+  CommandPlugins.cpp
   DAP.cpp
   DAPError.cpp
   DAPLog.cpp
diff --git a/lldb/tools/lldb-dap/CommandPlugins.cpp 
b/lldb/tools/lldb-dap/CommandPlugins.cpp
new file mode 100644
index 0..4e7aa029e0f22
--- /dev/null
+++ b/lldb/tools/lldb-dap/CommandPlugins.cpp
@@ -0,0 +1,163 @@
+//===-- CommandPlugins.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CommandPlugins.h"
+#include "Handler/ResponseHandler.h"
+#include "JSONUtils.h"
+#include "lldb/API/SBStream.h"
+
+using namespace lldb_dap;
+
+bool StartDebuggingCommand::DoExecute(lldb::SBDebugger debugger, char 
**command,
+  lldb::SBCommandReturnObject &result) {
+  // Command format like: `start-debugging  `
+  if (!command) {
+result.SetError("Invalid use of start-debugging, expected format "
+"`start-debugging  `.");
+return false;
+  }
+
+  if (!command[0] || llvm::StringRef(command[0]).empty()) {
+result.SetError("start-debugging request type missing.");
+return false;
+  }
+
+  if (!command[1] || llvm::StringRef(command[1]).empty()) {
+result.SetError("start-debugging debug configuration missing.");
+return false;
+  }
+
+  llvm::StringRef request{command[0]};
+  std::string raw_configuration{command[1]};
+
+  llvm::Expected configuration =
+  llvm::json::parse(raw_configuration);
+
+  if (!configuration) {
+llvm::Error err = configuration.takeError();
+std::string msg = "Failed to parse json configuration: " +
+  llvm::toString(std::move(err)) + "\n\n" +
+  raw_configuration;
+result.SetError(msg.c_str());
+return false;
+  }
+
+  dap.SendReverseRequest(
+  "startDebugging",
+  llvm::json::Object{{"request", request},
+ {"configuration", std::move(*configuration)}});
+
+  result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
+
+  return true;
+}
+
+bool ReplModeCommand::DoExecute(lldb::SBDebugger debugger, char **command,
+lldb::SBCommandReturnObject &result) {
+  // Command format like: `repl-mode ?`
+  // If a new mode is not specified report the current mode.
+  if (!command || llvm::StringRef(command[0]).empty()) {
+std::string mode;
+switch (dap.repl_mode) {
+case ReplMode::Variable:
+  mode = "variable";
+  break;
+case ReplMode::Command:
+  mode = "command";
+  break;
+case ReplMode::Auto:
+  mode = "auto";
+  break;
+}
+
+result.Printf("lldb-dap repl-mode %s.\n", mode.c_str());
+result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
+
+return true;
+  }
+
+  llvm::StringRef new_mode{command[0]};
+
+  if (new_mode == "variable") {
+dap.repl_mode = ReplMode::Variable;
+  } else if (new_mode == "command") {
+dap.repl_mode = ReplMode::Command;
+  } else if (new_mode == "auto") {
+dap.repl_mode = ReplMode::Auto;
+  } else {
+lldb::SBStream error_message;
+error_message.Printf("Invalid repl-mode '%s'. Expected one of 'variable', "
+ 

[Lldb-commits] [lldb] [lldb-dap] Move the command plugins out of the DAP header (PR #140396)

2025-05-17 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Move the command plugins out of the DAP header and into their file. This PR 
also renames the classes from "RequestHandler" to "Command". Although they are 
implemented in terms of sending requests, they are not "handlers".

---
Full diff: https://github.com/llvm/llvm-project/pull/140396.diff


6 Files Affected:

- (modified) lldb/tools/lldb-dap/CMakeLists.txt (+1) 
- (added) lldb/tools/lldb-dap/CommandPlugins.cpp (+163) 
- (added) lldb/tools/lldb-dap/CommandPlugins.h (+40) 
- (modified) lldb/tools/lldb-dap/DAP.cpp (-153) 
- (modified) lldb/tools/lldb-dap/DAP.h (-21) 
- (modified) lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp (+4-3) 


``diff
diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 5dedee8a87f41..97cdf23484ea0 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -8,6 +8,7 @@ add_public_tablegen_target(LLDBDAPOptionsTableGen)
 add_lldb_library(lldbDAP
   Breakpoint.cpp
   BreakpointBase.cpp
+  CommandPlugins.cpp
   DAP.cpp
   DAPError.cpp
   DAPLog.cpp
diff --git a/lldb/tools/lldb-dap/CommandPlugins.cpp 
b/lldb/tools/lldb-dap/CommandPlugins.cpp
new file mode 100644
index 0..4e7aa029e0f22
--- /dev/null
+++ b/lldb/tools/lldb-dap/CommandPlugins.cpp
@@ -0,0 +1,163 @@
+//===-- CommandPlugins.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CommandPlugins.h"
+#include "Handler/ResponseHandler.h"
+#include "JSONUtils.h"
+#include "lldb/API/SBStream.h"
+
+using namespace lldb_dap;
+
+bool StartDebuggingCommand::DoExecute(lldb::SBDebugger debugger, char 
**command,
+  lldb::SBCommandReturnObject &result) {
+  // Command format like: `start-debugging  `
+  if (!command) {
+result.SetError("Invalid use of start-debugging, expected format "
+"`start-debugging  `.");
+return false;
+  }
+
+  if (!command[0] || llvm::StringRef(command[0]).empty()) {
+result.SetError("start-debugging request type missing.");
+return false;
+  }
+
+  if (!command[1] || llvm::StringRef(command[1]).empty()) {
+result.SetError("start-debugging debug configuration missing.");
+return false;
+  }
+
+  llvm::StringRef request{command[0]};
+  std::string raw_configuration{command[1]};
+
+  llvm::Expected configuration =
+  llvm::json::parse(raw_configuration);
+
+  if (!configuration) {
+llvm::Error err = configuration.takeError();
+std::string msg = "Failed to parse json configuration: " +
+  llvm::toString(std::move(err)) + "\n\n" +
+  raw_configuration;
+result.SetError(msg.c_str());
+return false;
+  }
+
+  dap.SendReverseRequest(
+  "startDebugging",
+  llvm::json::Object{{"request", request},
+ {"configuration", std::move(*configuration)}});
+
+  result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
+
+  return true;
+}
+
+bool ReplModeCommand::DoExecute(lldb::SBDebugger debugger, char **command,
+lldb::SBCommandReturnObject &result) {
+  // Command format like: `repl-mode ?`
+  // If a new mode is not specified report the current mode.
+  if (!command || llvm::StringRef(command[0]).empty()) {
+std::string mode;
+switch (dap.repl_mode) {
+case ReplMode::Variable:
+  mode = "variable";
+  break;
+case ReplMode::Command:
+  mode = "command";
+  break;
+case ReplMode::Auto:
+  mode = "auto";
+  break;
+}
+
+result.Printf("lldb-dap repl-mode %s.\n", mode.c_str());
+result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
+
+return true;
+  }
+
+  llvm::StringRef new_mode{command[0]};
+
+  if (new_mode == "variable") {
+dap.repl_mode = ReplMode::Variable;
+  } else if (new_mode == "command") {
+dap.repl_mode = ReplMode::Command;
+  } else if (new_mode == "auto") {
+dap.repl_mode = ReplMode::Auto;
+  } else {
+lldb::SBStream error_message;
+error_message.Printf("Invalid repl-mode '%s'. Expected one of 'variable', "
+ "'command' or 'auto'.\n",
+ new_mode.data());
+result.SetError(error_message.GetData());
+return false;
+  }
+
+  result.Printf("lldb-dap repl-mode %s set.\n", new_mode.data());
+  result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
+  return true;
+}
+
+/// Sends a DAP event with an optional body.
+///
+/// 
https://code.visualstudio.com/api/references/vscode-api#debug.onDidReceiveDebugSessionCustomEvent
+bool SendEventCommand::DoExecute(lldb::SBDebugger d

[Lldb-commits] [lldb] [LLDB] Add field member operators to DIL (PR #138093)

2025-05-17 Thread via lldb-commits

cmtice wrote:

I believe I have addressed all the review comments so far. Please take another 
look. Thanks!

https://github.com/llvm/llvm-project/pull/138093
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add field member operators to DIL (PR #138093)

2025-05-17 Thread via lldb-commits

https://github.com/cmtice updated 
https://github.com/llvm/llvm-project/pull/138093

>From fe9ac0fa05bb43ea718214746f0ea9b7eefc929a Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 1 May 2025 00:05:57 -0700
Subject: [PATCH 1/4] [LLDB] Add field member operators to DIL

Add the arrow and period operators, allowing DIL to find and access
member fields.
---
 lldb/docs/dil-expr-lang.ebnf  |  10 +-
 lldb/include/lldb/ValueObject/DILAST.h|  26 +++
 lldb/include/lldb/ValueObject/DILEval.h   |   8 +
 lldb/include/lldb/ValueObject/DILLexer.h  |   2 +
 lldb/include/lldb/ValueObject/DILParser.h |   1 +
 lldb/source/ValueObject/DILAST.cpp|   4 +
 lldb/source/ValueObject/DILEval.cpp   | 200 ++
 lldb/source/ValueObject/DILLexer.cpp  |   9 +-
 lldb/source/ValueObject/DILParser.cpp |  27 ++-
 .../frame/var-dil/basics/MemberOf/Makefile|   3 +
 .../MemberOf/TestFrameVarDILMemberOf.py   |  47 
 .../frame/var-dil/basics/MemberOf/main.cpp|  59 ++
 .../basics/MemberOfAnonymousMember/Makefile   |   3 +
 .../TestFrameVarDILMemberOfAnonymousMember.py |  62 ++
 .../basics/MemberOfAnonymousMember/main.cpp   |  74 +++
 .../basics/MemberOfInheritance/Makefile   |   3 +
 .../TestFrameVarDILMemberOfInheritance.py |  49 +
 .../basics/MemberOfInheritance/main.cpp   |  87 
 18 files changed, 666 insertions(+), 8 deletions(-)
 create mode 100644 
lldb/test/API/commands/frame/var-dil/basics/MemberOf/Makefile
 create mode 100644 
lldb/test/API/commands/frame/var-dil/basics/MemberOf/TestFrameVarDILMemberOf.py
 create mode 100644 
lldb/test/API/commands/frame/var-dil/basics/MemberOf/main.cpp
 create mode 100644 
lldb/test/API/commands/frame/var-dil/basics/MemberOfAnonymousMember/Makefile
 create mode 100644 
lldb/test/API/commands/frame/var-dil/basics/MemberOfAnonymousMember/TestFrameVarDILMemberOfAnonymousMember.py
 create mode 100644 
lldb/test/API/commands/frame/var-dil/basics/MemberOfAnonymousMember/main.cpp
 create mode 100644 
lldb/test/API/commands/frame/var-dil/basics/MemberOfInheritance/Makefile
 create mode 100644 
lldb/test/API/commands/frame/var-dil/basics/MemberOfInheritance/TestFrameVarDILMemberOfInheritance.py
 create mode 100644 
lldb/test/API/commands/frame/var-dil/basics/MemberOfInheritance/main.cpp

diff --git a/lldb/docs/dil-expr-lang.ebnf b/lldb/docs/dil-expr-lang.ebnf
index c8bf4231b3e4a..580626862c005 100644
--- a/lldb/docs/dil-expr-lang.ebnf
+++ b/lldb/docs/dil-expr-lang.ebnf
@@ -5,13 +5,17 @@
 
 expression = unary_expression ;
 
-unary_expression = unary_operator expression
- | primary_expression ;
+unary_expression = postfix_expression
+ | unary_operator expression ;
 
 unary_operator = "*" | "&" ;
 
+postfix_expresson = primary_expression
+  | postfix_expression "." id_expression
+  | postfix_expression "->" id_expression ;
+
 primary_expression = id_expression
-   | "(" expression ")";
+   | "(" expression ")"  ;
 
 id_expression = unqualified_id
   | qualified_id
diff --git a/lldb/include/lldb/ValueObject/DILAST.h 
b/lldb/include/lldb/ValueObject/DILAST.h
index fe3827ef0516a..a74a12bd8be9d 100644
--- a/lldb/include/lldb/ValueObject/DILAST.h
+++ b/lldb/include/lldb/ValueObject/DILAST.h
@@ -20,6 +20,7 @@ namespace lldb_private::dil {
 enum class NodeKind {
   eErrorNode,
   eIdentifierNode,
+  eMemberOfNode,
   eUnaryOpNode,
 };
 
@@ -88,6 +89,29 @@ class IdentifierNode : public ASTNode {
   std::string m_name;
 };
 
+class MemberOfNode : public ASTNode {
+public:
+  MemberOfNode(uint32_t location, ASTNodeUP base, bool is_arrow,
+   ConstString name)
+  : ASTNode(location, NodeKind::eMemberOfNode), m_base(std::move(base)),
+m_is_arrow(is_arrow), m_field_name(name) { }
+
+  llvm::Expected Accept(Visitor *v) const override;
+
+  ASTNode *base() const { return m_base.get(); }
+  bool IsArrow() const { return m_is_arrow; }
+  ConstString FieldName() const { return m_field_name; }
+
+  static bool classof(const ASTNode *node) {
+return node->GetKind() == NodeKind::eMemberOfNode;
+  }
+
+private:
+  ASTNodeUP m_base;
+  bool m_is_arrow;
+  ConstString m_field_name;
+};
+
 class UnaryOpNode : public ASTNode {
 public:
   UnaryOpNode(uint32_t location, UnaryOpKind kind, ASTNodeUP operand)
@@ -118,6 +142,8 @@ class Visitor {
   virtual llvm::Expected
   Visit(const IdentifierNode *node) = 0;
   virtual llvm::Expected
+  Visit(const MemberOfNode *node) = 0;
+  virtual llvm::Expected
   Visit(const UnaryOpNode *node) = 0;
 };
 
diff --git a/lldb/include/lldb/ValueObject/DILEval.h 
b/lldb/include/lldb/ValueObject/DILEval.h
index b1dd3fdb49739..053daffaa41f2 100644
--- a/lldb/include/lldb/ValueObject/DILEval.h
+++ b/lldb/include/lldb/ValueObject/DILEval.h
@@ -49,8 +49,16 @@ class Interpreter : Visitor {
 private:
   llvm::Expected
   Visit(const Ident

[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Ely Ronnen via lldb-commits

https://github.com/eronnen updated 
https://github.com/llvm/llvm-project/pull/139969

>From a705fec9e42d209ff64be3588ca74567d4319361 Mon Sep 17 00:00:00 2001
From: Ely Ronnen 
Date: Sat, 10 May 2025 20:45:17 +0200
Subject: [PATCH 1/5] support assembly in BreakpointLocationsRequestHandler

---
 .../breakpoint/TestDAP_setBreakpoints.py  |  1 -
 .../TestDAP_setExceptionBreakpoints.py|  1 -
 .../TestDAP_setFunctionBreakpoints.py |  1 -
 lldb/tools/lldb-dap/DAP.h |  3 +
 .../Handler/BreakpointLocationsHandler.cpp| 77 +++
 lldb/tools/lldb-dap/Handler/RequestHandler.h  | 11 +++
 .../lldb-dap/Handler/SourceRequestHandler.cpp |  4 +-
 7 files changed, 76 insertions(+), 22 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py
index aae1251b17c93..26df2573555df 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py
@@ -12,7 +12,6 @@
 import os
 
 
-@skip("Temporarily disable the breakpoint tests")
 class TestDAP_setBreakpoints(lldbdap_testcase.DAPTestCaseBase):
 def setUp(self):
 lldbdap_testcase.DAPTestCaseBase.setUp(self)
diff --git 
a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py
index 4dc8c5b3c7ded..92ac66cd44c5d 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py
@@ -10,7 +10,6 @@
 import lldbdap_testcase
 
 
-@skip("Temporarily disable the breakpoint tests")
 class TestDAP_setExceptionBreakpoints(lldbdap_testcase.DAPTestCaseBase):
 @skipIfWindows
 def test_functionality(self):
diff --git 
a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py
index baaca4d974d5d..946595f639edc 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py
@@ -10,7 +10,6 @@
 import lldbdap_testcase
 
 
-@skip("Temporarily disable the breakpoint tests")
 class TestDAP_setFunctionBreakpoints(lldbdap_testcase.DAPTestCaseBase):
 @skipIfWindows
 def test_set_and_clear(self):
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index c1a1130b1e59f..587d15891530e 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -219,6 +219,9 @@ struct DAP {
   llvm::StringSet<> modules;
   /// @}
 
+  /// Number of lines of assembly code to show when no debug info is available.
+  uint32_t number_of_assembly_lines_for_nodebug = 32;
+
   /// Creates a new DAP sessions.
   ///
   /// \param[in] log
diff --git a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp 
b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp
index 2ac886c3a5d2c..9eea549d72b00 100644
--- a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp
@@ -7,7 +7,7 @@
 
//===--===//
 
 #include "DAP.h"
-#include "JSONUtils.h"
+#include "LLDBUtils.h"
 #include "RequestHandler.h"
 #include 
 
@@ -19,19 +19,50 @@ namespace lldb_dap {
 llvm::Expected
 BreakpointLocationsRequestHandler::Run(
 const protocol::BreakpointLocationsArguments &args) const {
-  std::string path = args.source.path.value_or("");
   uint32_t start_line = args.line;
   uint32_t start_column = args.column.value_or(LLDB_INVALID_COLUMN_NUMBER);
   uint32_t end_line = args.endLine.value_or(start_line);
   uint32_t end_column =
   args.endColumn.value_or(std::numeric_limits::max());
 
+  // Find all relevant lines & columns
+  llvm::SmallVector, 8> locations;
+  if (args.source.sourceReference) {
+AddAssemblyBreakpointLocations(locations, *args.source.sourceReference,
+   start_line, end_line);
+  } else {
+std::string path = args.source.path.value_or("");
+AddSourceBreakpointLocations(locations, std::move(path), start_line,
+ start_column, end_line, end_column);
+  }
+
+  // The line entries are sorted by addresses, but we must return the list
+  // ordered by line / column position.
+  std::sort(locations.begin(), locations.end());
+  locations.erase(llvm::unique(locations), locations.end());
+
+  std::vector breakpoint_locations;
+  for (auto &l : locations) {
+protocol::BreakpointLocation lc;
+lc.line = l.first;
+lc.column = l.second;
+breakpoint_locations.push_back(std::move(lc));
+  }
+
+  return protocol::BreakpointLocationsResponseBody{
+  /*breakpoints=*/std::move(breakpoint_locations)};
+}
+
+template 
+void BreakpointLocat

[Lldb-commits] [lldb] [lldb] Add templated CompilerType::GetTypeSystem (NFC) (PR #140424)

2025-05-17 Thread Dave Lee via lldb-commits

https://github.com/kastiglione created 
https://github.com/llvm/llvm-project/pull/140424

None

>From f00b0d192a921c6cec369d2d674b617a9ca1f706 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Fri, 16 May 2025 11:47:08 -0700
Subject: [PATCH] [lldb] Add templated CompilerType::GetTypeSystem (NFC)

---
 lldb/include/lldb/Symbol/CompilerType.h   |  5 +++
 .../Clang/ClangASTImporter.cpp|  4 +--
 .../ExpressionParser/Clang/ClangASTSource.cpp |  3 +-
 .../Clang/ClangExpressionDeclMap.cpp  |  9 +++---
 .../ExpressionParser/Clang/ClangUtil.cpp  |  2 +-
 .../Clang/NameSearchContext.cpp   |  4 +--
 .../Language/CPlusPlus/BlockPointer.cpp   |  4 +--
 .../Plugins/Language/CPlusPlus/Coroutines.cpp |  3 +-
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  |  8 ++---
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  |  6 ++--
 .../NativePDB/SymbolFileNativePDB.cpp |  3 +-
 .../TypeSystem/Clang/TypeSystemClang.cpp  | 31 +++
 .../DynamicValueObjectLocalBuffer.cpp |  4 +--
 13 files changed, 36 insertions(+), 50 deletions(-)

diff --git a/lldb/include/lldb/Symbol/CompilerType.h 
b/lldb/include/lldb/Symbol/CompilerType.h
index b8badfda92cf3..df8489a7fe582 100644
--- a/lldb/include/lldb/Symbol/CompilerType.h
+++ b/lldb/include/lldb/Symbol/CompilerType.h
@@ -276,6 +276,11 @@ class CompilerType {
   /// TypeSystem::TypeSystemSPWrapper can be compared for equality.
   TypeSystemSPWrapper GetTypeSystem() const;
 
+  template 
+  std::shared_ptr GetTypeSystem() const {
+return GetTypeSystem().dyn_cast_or_null();
+  }
+
   ConstString GetTypeName(bool BaseOnly = false) const;
 
   ConstString GetDisplayTypeName() const;
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index db9a6dd197b3a..c8c8ba53e3bae 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -37,7 +37,7 @@ CompilerType ClangASTImporter::CopyType(TypeSystemClang 
&dst_ast,
 const CompilerType &src_type) {
   clang::ASTContext &dst_clang_ast = dst_ast.getASTContext();
 
-  auto src_ast = src_type.GetTypeSystem().dyn_cast_or_null();
+  auto src_ast = src_type.GetTypeSystem();
   if (!src_ast)
 return CompilerType();
 
@@ -307,7 +307,7 @@ CompilerType ClangASTImporter::DeportType(TypeSystemClang 
&dst,
   const CompilerType &src_type) {
   Log *log = GetLog(LLDBLog::Expressions);
 
-  auto src_ctxt = src_type.GetTypeSystem().dyn_cast_or_null();
+  auto src_ctxt = src_type.GetTypeSystem();
   if (!src_ctxt)
 return {};
 
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 34129807277d5..4b52f6aafcb75 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -1477,8 +1477,7 @@ ClangASTImporter::DeclOrigin 
ClangASTSource::GetDeclOrigin(const clang::Decl *de
 }
 
 CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) {
-  auto ts = src_type.GetTypeSystem();
-  auto src_ast = ts.dyn_cast_or_null();
+  auto src_ast = src_type.GetTypeSystem();
   if (!src_ast)
 return {};
 
diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 667cb8a900459..db4973b4a4d3e 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -219,7 +219,7 @@ bool ClangExpressionDeclMap::AddPersistentVariable(const 
NamedDecl *decl,
bool is_result,
bool is_lvalue) {
   assert(m_parser_vars.get());
-  auto ast = parser_type.GetTypeSystem().dyn_cast_or_null();
+  auto ast = parser_type.GetTypeSystem();
   if (ast == nullptr)
 return false;
 
@@ -1486,8 +1486,8 @@ bool ClangExpressionDeclMap::GetVariableValue(VariableSP 
&var,
 return false;
   }
 
-  auto ts = var_type->GetForwardCompilerType().GetTypeSystem();
-  auto clang_ast = ts.dyn_cast_or_null();
+  auto clang_ast =
+  var_type->GetForwardCompilerType().GetTypeSystem();
 
   if (!clang_ast) {
 LLDB_LOG(log, "Skipped a definition because it has no Clang AST");
@@ -1606,8 +1606,7 @@ void ClangExpressionDeclMap::AddOneVariable(
 
   TypeFromUser user_type = valobj->GetCompilerType();
 
-  auto clang_ast =
-  user_type.GetTypeSystem().dyn_cast_or_null();
+  auto clang_ast = user_type.GetTypeSystem();
 
   if (!clang_ast) {
 LLDB_LOG(log, "Skipped a definition because it has no Clang AST");
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.cpp 
b/lldb/s

[Lldb-commits] [lldb] [lldb] Add templated CompilerType::GetTypeSystem (NFC) (PR #140424)

2025-05-17 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Dave Lee (kastiglione)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/140424.diff


13 Files Affected:

- (modified) lldb/include/lldb/Symbol/CompilerType.h (+5) 
- (modified) lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp 
(+2-2) 
- (modified) lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
(+1-2) 
- (modified) 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp (+4-5) 
- (modified) lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.cpp (+1-1) 
- (modified) lldb/source/Plugins/ExpressionParser/Clang/NameSearchContext.cpp 
(+2-2) 
- (modified) lldb/source/Plugins/Language/CPlusPlus/BlockPointer.cpp (+2-2) 
- (modified) lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp (+1-2) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
(+3-5) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+2-4) 
- (modified) lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp 
(+1-2) 
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+11-20) 
- (modified) lldb/unittests/ValueObject/DynamicValueObjectLocalBuffer.cpp 
(+1-3) 


``diff
diff --git a/lldb/include/lldb/Symbol/CompilerType.h 
b/lldb/include/lldb/Symbol/CompilerType.h
index b8badfda92cf3..df8489a7fe582 100644
--- a/lldb/include/lldb/Symbol/CompilerType.h
+++ b/lldb/include/lldb/Symbol/CompilerType.h
@@ -276,6 +276,11 @@ class CompilerType {
   /// TypeSystem::TypeSystemSPWrapper can be compared for equality.
   TypeSystemSPWrapper GetTypeSystem() const;
 
+  template 
+  std::shared_ptr GetTypeSystem() const {
+return GetTypeSystem().dyn_cast_or_null();
+  }
+
   ConstString GetTypeName(bool BaseOnly = false) const;
 
   ConstString GetDisplayTypeName() const;
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index db9a6dd197b3a..c8c8ba53e3bae 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -37,7 +37,7 @@ CompilerType ClangASTImporter::CopyType(TypeSystemClang 
&dst_ast,
 const CompilerType &src_type) {
   clang::ASTContext &dst_clang_ast = dst_ast.getASTContext();
 
-  auto src_ast = src_type.GetTypeSystem().dyn_cast_or_null();
+  auto src_ast = src_type.GetTypeSystem();
   if (!src_ast)
 return CompilerType();
 
@@ -307,7 +307,7 @@ CompilerType ClangASTImporter::DeportType(TypeSystemClang 
&dst,
   const CompilerType &src_type) {
   Log *log = GetLog(LLDBLog::Expressions);
 
-  auto src_ctxt = src_type.GetTypeSystem().dyn_cast_or_null();
+  auto src_ctxt = src_type.GetTypeSystem();
   if (!src_ctxt)
 return {};
 
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 34129807277d5..4b52f6aafcb75 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -1477,8 +1477,7 @@ ClangASTImporter::DeclOrigin 
ClangASTSource::GetDeclOrigin(const clang::Decl *de
 }
 
 CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) {
-  auto ts = src_type.GetTypeSystem();
-  auto src_ast = ts.dyn_cast_or_null();
+  auto src_ast = src_type.GetTypeSystem();
   if (!src_ast)
 return {};
 
diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 667cb8a900459..db4973b4a4d3e 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -219,7 +219,7 @@ bool ClangExpressionDeclMap::AddPersistentVariable(const 
NamedDecl *decl,
bool is_result,
bool is_lvalue) {
   assert(m_parser_vars.get());
-  auto ast = parser_type.GetTypeSystem().dyn_cast_or_null();
+  auto ast = parser_type.GetTypeSystem();
   if (ast == nullptr)
 return false;
 
@@ -1486,8 +1486,8 @@ bool ClangExpressionDeclMap::GetVariableValue(VariableSP 
&var,
 return false;
   }
 
-  auto ts = var_type->GetForwardCompilerType().GetTypeSystem();
-  auto clang_ast = ts.dyn_cast_or_null();
+  auto clang_ast =
+  var_type->GetForwardCompilerType().GetTypeSystem();
 
   if (!clang_ast) {
 LLDB_LOG(log, "Skipped a definition because it has no Clang AST");
@@ -1606,8 +1606,7 @@ void ClangExpressionDeclMap::AddOneVariable(
 
   TypeFromUser user_type = valobj->GetCompilerType();
 
-  auto clang_ast =
-  user_type.GetTypeSystem().dyn_cast_or_null();
+  auto clang_ast = user_type.GetTypeSystem();
 
   if (!clang_ast) {
   

[Lldb-commits] [lldb] [lldb] Add templated CompilerType::GetTypeSystem (NFC) (PR #140424)

2025-05-17 Thread Dave Lee via lldb-commits

https://github.com/kastiglione edited 
https://github.com/llvm/llvm-project/pull/140424
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Jonas Devlieghere via lldb-commits


@@ -71,22 +101,26 @@ BreakpointLocationsRequestHandler::Run(
   locations.emplace_back(line, column);
 }
   }
+}
 
-  // The line entries are sorted by addresses, but we must return the list
-  // ordered by line / column position.
-  std::sort(locations.begin(), locations.end());
-  locations.erase(llvm::unique(locations), locations.end());
+template 
+void BreakpointLocationsRequestHandler::AddAssemblyBreakpointLocations(
+llvm::SmallVector, N> &locations,

JDevlieghere wrote:

You can avoid the template by taking a reference to a 
`SmallVectorImpl>`, which `SmallVector` inherits 
from. 

https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Jonas Devlieghere via lldb-commits


@@ -73,7 +87,64 @@ SetBreakpointsRequestHandler::Run(
 }
   }
 
-  return protocol::SetBreakpointsResponseBody{std::move(response_breakpoints)};
+  return response_breakpoints;
+}
+
+std::vector
+SetBreakpointsRequestHandler::SetAssemblyBreakpoints(
+const protocol::Source &source,
+const std::optional> &breakpoints)
+const {
+  std::vector response_breakpoints;
+  int64_t sourceReference = source.sourceReference.value_or(0);
+
+  lldb::SBAddress address(sourceReference, dap.target);
+  if (!address.IsValid())
+return response_breakpoints;
+
+  lldb::SBSymbol symbol = address.GetSymbol();
+  if (!symbol.IsValid())
+return response_breakpoints; // Not yet supporting breakpoints in assembly
+ // without a valid symbol
+
+  llvm::DenseMap request_bps;
+  if (breakpoints) {
+for (const auto &bp : *breakpoints) {
+  SourceBreakpoint src_bp(dap, bp);
+  request_bps.try_emplace(src_bp.GetLine(), src_bp);
+  const auto [iv, inserted] =
+  dap.assembly_breakpoints[sourceReference].try_emplace(

JDevlieghere wrote:

This together with the logic to either add or update a breakpoint seems like it 
could be abstracted away behind a function in the dap class. Something like 
`dap.SetAssemblyBreakpoint(uint32_t line, SourceBreakpoint& source_bp)`. Same 
thing with the delete below and then we can make `assembly_breakpoints` a 
member and provide some more abstraction.

https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Jonas Devlieghere via lldb-commits


@@ -73,7 +87,64 @@ SetBreakpointsRequestHandler::Run(
 }
   }
 
-  return protocol::SetBreakpointsResponseBody{std::move(response_breakpoints)};
+  return response_breakpoints;
+}
+
+std::vector
+SetBreakpointsRequestHandler::SetAssemblyBreakpoints(
+const protocol::Source &source,
+const std::optional> &breakpoints)
+const {
+  std::vector response_breakpoints;
+  int64_t sourceReference = source.sourceReference.value_or(0);
+
+  lldb::SBAddress address(sourceReference, dap.target);
+  if (!address.IsValid())
+return response_breakpoints;
+
+  lldb::SBSymbol symbol = address.GetSymbol();
+  if (!symbol.IsValid())
+return response_breakpoints; // Not yet supporting breakpoints in assembly
+ // without a valid symbol
+
+  llvm::DenseMap request_bps;
+  if (breakpoints) {
+for (const auto &bp : *breakpoints) {
+  SourceBreakpoint src_bp(dap, bp);
+  request_bps.try_emplace(src_bp.GetLine(), src_bp);
+  const auto [iv, inserted] =
+  dap.assembly_breakpoints[sourceReference].try_emplace(
+  src_bp.GetLine(), src_bp);
+  // We check if this breakpoint already exists to update it

JDevlieghere wrote:

```suggestion
  // We check if this breakpoint already exists to update it.
```

https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Jonas Devlieghere via lldb-commits


@@ -19,19 +18,50 @@ namespace lldb_dap {
 llvm::Expected
 BreakpointLocationsRequestHandler::Run(
 const protocol::BreakpointLocationsArguments &args) const {
-  std::string path = args.source.path.value_or("");
   uint32_t start_line = args.line;
   uint32_t start_column = args.column.value_or(LLDB_INVALID_COLUMN_NUMBER);
   uint32_t end_line = args.endLine.value_or(start_line);
   uint32_t end_column =
   args.endColumn.value_or(std::numeric_limits::max());
 
+  // Find all relevant lines & columns

JDevlieghere wrote:

```suggestion
  // Find all relevant lines & columns.
```

https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Jonas Devlieghere via lldb-commits


@@ -19,19 +18,50 @@ namespace lldb_dap {
 llvm::Expected
 BreakpointLocationsRequestHandler::Run(
 const protocol::BreakpointLocationsArguments &args) const {
-  std::string path = args.source.path.value_or("");
   uint32_t start_line = args.line;
   uint32_t start_column = args.column.value_or(LLDB_INVALID_COLUMN_NUMBER);
   uint32_t end_line = args.endLine.value_or(start_line);
   uint32_t end_column =
   args.endColumn.value_or(std::numeric_limits::max());
 
+  // Find all relevant lines & columns
+  llvm::SmallVector, 8> locations;
+  if (args.source.sourceReference) {
+AddAssemblyBreakpointLocations(locations, *args.source.sourceReference,
+   start_line, end_line);
+  } else {
+std::string path = args.source.path.value_or("");
+AddSourceBreakpointLocations(locations, std::move(path), start_line,
+ start_column, end_line, end_column);
+  }
+
+  // The line entries are sorted by addresses, but we must return the list
+  // ordered by line / column position.
+  std::sort(locations.begin(), locations.end());
+  locations.erase(llvm::unique(locations), locations.end());
+
+  std::vector breakpoint_locations;
+  for (auto &l : locations) {
+protocol::BreakpointLocation lc;
+lc.line = l.first;
+lc.column = l.second;
+breakpoint_locations.push_back(std::move(lc));
+  }

JDevlieghere wrote:

I think you should be able to create the locations in place like this:
```suggestion
  for (auto &l : locations) 
breakpoint_locations.emplace_back({l.first, l.second});
 ```

https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Jonas Devlieghere via lldb-commits


@@ -73,7 +87,64 @@ SetBreakpointsRequestHandler::Run(
 }
   }
 
-  return protocol::SetBreakpointsResponseBody{std::move(response_breakpoints)};
+  return response_breakpoints;
+}
+
+std::vector
+SetBreakpointsRequestHandler::SetAssemblyBreakpoints(
+const protocol::Source &source,
+const std::optional> &breakpoints)
+const {
+  std::vector response_breakpoints;
+  int64_t sourceReference = source.sourceReference.value_or(0);
+
+  lldb::SBAddress address(sourceReference, dap.target);
+  if (!address.IsValid())
+return response_breakpoints;
+
+  lldb::SBSymbol symbol = address.GetSymbol();
+  if (!symbol.IsValid())
+return response_breakpoints; // Not yet supporting breakpoints in assembly
+ // without a valid symbol
+
+  llvm::DenseMap request_bps;

JDevlieghere wrote:

Let's add a comment saying what the key is, or better change the variable name 
to make it obvious: `line_to_requested_source_bps` or something.

https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Jonas Devlieghere via lldb-commits


@@ -219,6 +221,9 @@ struct DAP {
   llvm::StringSet<> modules;
   /// @}
 
+  /// Number of lines of assembly code to show when no debug info is available.
+  uint32_t number_of_assembly_lines_for_nodebug = 32;

JDevlieghere wrote:

Is this a constant? 
```suggestion
  static constexpr uint32_t number_of_assembly_lines_for_nodebug = 32;
```

https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Jonas Devlieghere via lldb-commits


@@ -73,7 +87,64 @@ SetBreakpointsRequestHandler::Run(
 }
   }
 
-  return protocol::SetBreakpointsResponseBody{std::move(response_breakpoints)};
+  return response_breakpoints;
+}
+
+std::vector
+SetBreakpointsRequestHandler::SetAssemblyBreakpoints(
+const protocol::Source &source,
+const std::optional> &breakpoints)
+const {
+  std::vector response_breakpoints;
+  int64_t sourceReference = source.sourceReference.value_or(0);
+
+  lldb::SBAddress address(sourceReference, dap.target);
+  if (!address.IsValid())
+return response_breakpoints;
+
+  lldb::SBSymbol symbol = address.GetSymbol();
+  if (!symbol.IsValid())
+return response_breakpoints; // Not yet supporting breakpoints in assembly
+ // without a valid symbol

JDevlieghere wrote:

Don't worry about adding the braces when you have a comment.
```suggestion
  if (!symbol.IsValid()) {
// Not yet supporting breakpoints in assembly without a valid symbol.
return response_breakpoints; 
  }
```

https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Jonas Devlieghere via lldb-commits


@@ -71,22 +101,26 @@ BreakpointLocationsRequestHandler::Run(
   locations.emplace_back(line, column);
 }
   }
+}
 
-  // The line entries are sorted by addresses, but we must return the list
-  // ordered by line / column position.
-  std::sort(locations.begin(), locations.end());
-  locations.erase(llvm::unique(locations), locations.end());
+template 
+void BreakpointLocationsRequestHandler::AddAssemblyBreakpointLocations(
+llvm::SmallVector, N> &locations,

JDevlieghere wrote:

Looking at how this is called, maybe you don't even need to take this by 
reference, and you can have this return a 
`llvm::SmallVector, 8>`. Honestly I don't even 
know if the `SmallVector` optimization is worth it here, personally I would've 
just returned a regular `std::vector`. If you change the return type, you can 
also change the name of the method from `Add` to `Get`. Now it looks like 
there's potentially multiple calls adding values to the location list.

https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Jonas Devlieghere via lldb-commits


@@ -53,6 +54,8 @@ class LLDB_API SBFileSpec {
 
   uint32_t GetPath(char *dst_path, size_t dst_len) const;
 
+  bool GetPath(lldb::SBStream &dst_path) const;

JDevlieghere wrote:

I have mixed feelings about adding this API. Generally, we usually use streams 
when we have potentially multiline output which isn't the case. Here I'm also 
worried about setting a precedent that will lead to having more methods 
overloaded with streams. If this were private API I wouldn't mind, but since we 
guarantee ABI stability for the SB API, once an API has been added, we have to 
support it forever. 

How about adding a helper to LLDBUtils that takes a `SBFileSpec` and returns 
the path as a std::string? 

https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Ely Ronnen via lldb-commits

https://github.com/eronnen edited 
https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Ely Ronnen via lldb-commits

https://github.com/eronnen edited 
https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Ely Ronnen via lldb-commits

https://github.com/eronnen updated 
https://github.com/llvm/llvm-project/pull/139969

>From a705fec9e42d209ff64be3588ca74567d4319361 Mon Sep 17 00:00:00 2001
From: Ely Ronnen 
Date: Sat, 10 May 2025 20:45:17 +0200
Subject: [PATCH 1/6] support assembly in BreakpointLocationsRequestHandler

---
 .../breakpoint/TestDAP_setBreakpoints.py  |  1 -
 .../TestDAP_setExceptionBreakpoints.py|  1 -
 .../TestDAP_setFunctionBreakpoints.py |  1 -
 lldb/tools/lldb-dap/DAP.h |  3 +
 .../Handler/BreakpointLocationsHandler.cpp| 77 +++
 lldb/tools/lldb-dap/Handler/RequestHandler.h  | 11 +++
 .../lldb-dap/Handler/SourceRequestHandler.cpp |  4 +-
 7 files changed, 76 insertions(+), 22 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py
index aae1251b17c93..26df2573555df 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py
@@ -12,7 +12,6 @@
 import os
 
 
-@skip("Temporarily disable the breakpoint tests")
 class TestDAP_setBreakpoints(lldbdap_testcase.DAPTestCaseBase):
 def setUp(self):
 lldbdap_testcase.DAPTestCaseBase.setUp(self)
diff --git 
a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py
index 4dc8c5b3c7ded..92ac66cd44c5d 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py
@@ -10,7 +10,6 @@
 import lldbdap_testcase
 
 
-@skip("Temporarily disable the breakpoint tests")
 class TestDAP_setExceptionBreakpoints(lldbdap_testcase.DAPTestCaseBase):
 @skipIfWindows
 def test_functionality(self):
diff --git 
a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py
index baaca4d974d5d..946595f639edc 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py
@@ -10,7 +10,6 @@
 import lldbdap_testcase
 
 
-@skip("Temporarily disable the breakpoint tests")
 class TestDAP_setFunctionBreakpoints(lldbdap_testcase.DAPTestCaseBase):
 @skipIfWindows
 def test_set_and_clear(self):
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index c1a1130b1e59f..587d15891530e 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -219,6 +219,9 @@ struct DAP {
   llvm::StringSet<> modules;
   /// @}
 
+  /// Number of lines of assembly code to show when no debug info is available.
+  uint32_t number_of_assembly_lines_for_nodebug = 32;
+
   /// Creates a new DAP sessions.
   ///
   /// \param[in] log
diff --git a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp 
b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp
index 2ac886c3a5d2c..9eea549d72b00 100644
--- a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp
@@ -7,7 +7,7 @@
 
//===--===//
 
 #include "DAP.h"
-#include "JSONUtils.h"
+#include "LLDBUtils.h"
 #include "RequestHandler.h"
 #include 
 
@@ -19,19 +19,50 @@ namespace lldb_dap {
 llvm::Expected
 BreakpointLocationsRequestHandler::Run(
 const protocol::BreakpointLocationsArguments &args) const {
-  std::string path = args.source.path.value_or("");
   uint32_t start_line = args.line;
   uint32_t start_column = args.column.value_or(LLDB_INVALID_COLUMN_NUMBER);
   uint32_t end_line = args.endLine.value_or(start_line);
   uint32_t end_column =
   args.endColumn.value_or(std::numeric_limits::max());
 
+  // Find all relevant lines & columns
+  llvm::SmallVector, 8> locations;
+  if (args.source.sourceReference) {
+AddAssemblyBreakpointLocations(locations, *args.source.sourceReference,
+   start_line, end_line);
+  } else {
+std::string path = args.source.path.value_or("");
+AddSourceBreakpointLocations(locations, std::move(path), start_line,
+ start_column, end_line, end_column);
+  }
+
+  // The line entries are sorted by addresses, but we must return the list
+  // ordered by line / column position.
+  std::sort(locations.begin(), locations.end());
+  locations.erase(llvm::unique(locations), locations.end());
+
+  std::vector breakpoint_locations;
+  for (auto &l : locations) {
+protocol::BreakpointLocation lc;
+lc.line = l.first;
+lc.column = l.second;
+breakpoint_locations.push_back(std::move(lc));
+  }
+
+  return protocol::BreakpointLocationsResponseBody{
+  /*breakpoints=*/std::move(breakpoint_locations)};
+}
+
+template 
+void BreakpointLocat

[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Ely Ronnen via lldb-commits

https://github.com/eronnen updated 
https://github.com/llvm/llvm-project/pull/139969

>From d6325b3f6a8602fc96ad72acecfcccda1120614d Mon Sep 17 00:00:00 2001
From: Ely Ronnen 
Date: Sat, 10 May 2025 20:45:17 +0200
Subject: [PATCH 1/6] support assembly in BreakpointLocationsRequestHandler

---
 .../breakpoint/TestDAP_setBreakpoints.py  |  1 -
 .../TestDAP_setExceptionBreakpoints.py|  1 -
 .../TestDAP_setFunctionBreakpoints.py |  1 -
 lldb/tools/lldb-dap/DAP.h |  3 +
 .../Handler/BreakpointLocationsHandler.cpp| 77 +++
 lldb/tools/lldb-dap/Handler/RequestHandler.h  | 11 +++
 .../lldb-dap/Handler/SourceRequestHandler.cpp |  4 +-
 7 files changed, 76 insertions(+), 22 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py
index aae1251b17c93..26df2573555df 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py
@@ -12,7 +12,6 @@
 import os
 
 
-@skip("Temporarily disable the breakpoint tests")
 class TestDAP_setBreakpoints(lldbdap_testcase.DAPTestCaseBase):
 def setUp(self):
 lldbdap_testcase.DAPTestCaseBase.setUp(self)
diff --git 
a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py
index 4dc8c5b3c7ded..92ac66cd44c5d 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py
@@ -10,7 +10,6 @@
 import lldbdap_testcase
 
 
-@skip("Temporarily disable the breakpoint tests")
 class TestDAP_setExceptionBreakpoints(lldbdap_testcase.DAPTestCaseBase):
 @skipIfWindows
 def test_functionality(self):
diff --git 
a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py
index baaca4d974d5d..946595f639edc 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py
@@ -10,7 +10,6 @@
 import lldbdap_testcase
 
 
-@skip("Temporarily disable the breakpoint tests")
 class TestDAP_setFunctionBreakpoints(lldbdap_testcase.DAPTestCaseBase):
 @skipIfWindows
 def test_set_and_clear(self):
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 8f24c6cf82924..00aa4276852c5 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -219,6 +219,9 @@ struct DAP {
   llvm::StringSet<> modules;
   /// @}
 
+  /// Number of lines of assembly code to show when no debug info is available.
+  uint32_t number_of_assembly_lines_for_nodebug = 32;
+
   /// Creates a new DAP sessions.
   ///
   /// \param[in] log
diff --git a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp 
b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp
index 2ac886c3a5d2c..9eea549d72b00 100644
--- a/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp
@@ -7,7 +7,7 @@
 
//===--===//
 
 #include "DAP.h"
-#include "JSONUtils.h"
+#include "LLDBUtils.h"
 #include "RequestHandler.h"
 #include 
 
@@ -19,19 +19,50 @@ namespace lldb_dap {
 llvm::Expected
 BreakpointLocationsRequestHandler::Run(
 const protocol::BreakpointLocationsArguments &args) const {
-  std::string path = args.source.path.value_or("");
   uint32_t start_line = args.line;
   uint32_t start_column = args.column.value_or(LLDB_INVALID_COLUMN_NUMBER);
   uint32_t end_line = args.endLine.value_or(start_line);
   uint32_t end_column =
   args.endColumn.value_or(std::numeric_limits::max());
 
+  // Find all relevant lines & columns
+  llvm::SmallVector, 8> locations;
+  if (args.source.sourceReference) {
+AddAssemblyBreakpointLocations(locations, *args.source.sourceReference,
+   start_line, end_line);
+  } else {
+std::string path = args.source.path.value_or("");
+AddSourceBreakpointLocations(locations, std::move(path), start_line,
+ start_column, end_line, end_column);
+  }
+
+  // The line entries are sorted by addresses, but we must return the list
+  // ordered by line / column position.
+  std::sort(locations.begin(), locations.end());
+  locations.erase(llvm::unique(locations), locations.end());
+
+  std::vector breakpoint_locations;
+  for (auto &l : locations) {
+protocol::BreakpointLocation lc;
+lc.line = l.first;
+lc.column = l.second;
+breakpoint_locations.push_back(std::move(lc));
+  }
+
+  return protocol::BreakpointLocationsResponseBody{
+  /*breakpoints=*/std::move(breakpoint_locations)};
+}
+
+template 
+void BreakpointLocat

[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Ely Ronnen (eronnen)


Changes

* Support assembly source breakpoints
* Change `sourceReference` to be the load address for simplicity and 
consistency across threads/frames

[Screencast From 2025-05-17 
23-57-30.webm](https://github.com/user-attachments/assets/2e7c181d-42c1-4121-8f13-b180c19d0e33)



---

Patch is 29.52 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/139969.diff


19 Files Affected:

- (modified) lldb/include/lldb/API/SBFileSpec.h (+3) 
- (modified) lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
(+7) 
- (modified) 
lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py (+10) 
- (modified) lldb/source/API/SBFileSpec.cpp (+8) 
- (added) lldb/test/API/tools/lldb-dap/breakpoint-assembly/Makefile (+3) 
- (added) 
lldb/test/API/tools/lldb-dap/breakpoint-assembly/TestDAP_breakpointAssembly.py 
(+42) 
- (added) lldb/test/API/tools/lldb-dap/breakpoint-assembly/main.c (+14) 
- (modified) lldb/tools/lldb-dap/Breakpoint.cpp (+26-7) 
- (modified) lldb/tools/lldb-dap/DAP.h (+5) 
- (modified) lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp 
(+51-17) 
- (modified) lldb/tools/lldb-dap/Handler/RequestHandler.h (+20) 
- (modified) lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp 
(+75-4) 
- (modified) lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp (+9-11) 
- (modified) lldb/tools/lldb-dap/JSONUtils.cpp (+54-21) 
- (modified) lldb/tools/lldb-dap/JSONUtils.h (+14) 
- (modified) lldb/tools/lldb-dap/SourceBreakpoint.cpp (+22) 
- (modified) lldb/tools/lldb-dap/SourceBreakpoint.h (+1) 
- (modified) lldb/tools/lldb-dap/package-lock.json (+2-2) 
- (modified) lldb/tools/lldb-dap/package.json (+4-1) 


``diff
diff --git a/lldb/include/lldb/API/SBFileSpec.h 
b/lldb/include/lldb/API/SBFileSpec.h
index 36641843aabeb..303cb7d712cbf 100644
--- a/lldb/include/lldb/API/SBFileSpec.h
+++ b/lldb/include/lldb/API/SBFileSpec.h
@@ -10,6 +10,7 @@
 #define LLDB_API_SBFILESPEC_H
 
 #include "lldb/API/SBDefines.h"
+#include "lldb/API/SBStream.h"
 
 namespace lldb {
 
@@ -53,6 +54,8 @@ class LLDB_API SBFileSpec {
 
   uint32_t GetPath(char *dst_path, size_t dst_len) const;
 
+  bool GetPath(lldb::SBStream &dst_path) const;
+
   static int ResolvePath(const char *src_path, char *dst_path, size_t dst_len);
 
   bool GetDescription(lldb::SBStream &description) const;
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index 70fd0b0c419db..4a907a5e36901 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -955,6 +955,13 @@ def request_setBreakpoints(self, file_path, line_array, 
data=None):
 """
 (dir, base) = os.path.split(file_path)
 source_dict = {"name": base, "path": file_path}
+return self.request_setBreakpoints_with_source(source_dict, 
line_array, data)
+
+def request_setBreakpointsAssembly(self, sourceReference, line_array, 
data=None):
+source_dict = {"sourceReference": sourceReference}
+return self.request_setBreakpoints_with_source(source_dict, 
line_array, data)
+
+def request_setBreakpoints_with_source(self, source_dict, line_array, 
data=None):
 args_dict = {
 "source": source_dict,
 "sourceModified": False,
diff --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
index afdc746ed0d0d..427f66a7da0c8 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
@@ -63,6 +63,16 @@ def set_source_breakpoints(self, source_path, lines, 
data=None):
 for breakpoint in breakpoints:
 breakpoint_ids.append("%i" % (breakpoint["id"]))
 return breakpoint_ids
+
+def set_source_breakpoints_assembly(self, source_reference, lines, 
data=None):
+response = 
self.dap_server.request_setBreakpointsAssembly(source_reference, lines, data)
+if response is None:
+return []
+breakpoints = response["body"]["breakpoints"]
+breakpoint_ids = []
+for breakpoint in breakpoints:
+breakpoint_ids.append("%i" % (breakpoint["id"]))
+return breakpoint_ids
 
 def set_function_breakpoints(self, functions, condition=None, 
hitCondition=None):
 """Sets breakpoints by function name given an array of function names
diff --git a/lldb/source/API/SBFileSpec.cpp b/lldb/source/API/SBFileSpec.cpp
index a7df9afc4b8eb..cb44dac1d4fcc 100644
--- a/lldb/source/API/SBFileSpec.cpp
+++ b/lldb/source/API/SBFileSpec.cpp
@@ -19,6 +19,7 @@
 
 #include 
 #include 
+#include 
 
 using namespace lldb;
 using namespace lldb_privat

[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread Ely Ronnen via lldb-commits

https://github.com/eronnen ready_for_review 
https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] assembly breakpoints (PR #139969)

2025-05-17 Thread via lldb-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r HEAD~1...HEAD 
lldb/test/API/tools/lldb-dap/breakpoint-assembly/TestDAP_breakpointAssembly.py 
lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
``





View the diff from darker here.


``diff
--- packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py   
2025-05-18 00:26:37.00 +
+++ packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py   
2025-05-18 00:30:17.199504 +
@@ -61,13 +61,15 @@
 breakpoints = response["body"]["breakpoints"]
 breakpoint_ids = []
 for breakpoint in breakpoints:
 breakpoint_ids.append("%i" % (breakpoint["id"]))
 return breakpoint_ids
-
+
 def set_source_breakpoints_assembly(self, source_reference, lines, 
data=None):
-response = 
self.dap_server.request_setBreakpointsAssembly(source_reference, lines, data)
+response = self.dap_server.request_setBreakpointsAssembly(
+source_reference, lines, data
+)
 if response is None:
 return []
 breakpoints = response["body"]["breakpoints"]
 breakpoint_ids = []
 for breakpoint in breakpoints:

``




https://github.com/llvm/llvm-project/pull/139969
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Fix raciness in launch and attach tests (PR #137920)

2025-05-17 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere closed 
https://github.com/llvm/llvm-project/pull/137920
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits