[Lldb-commits] [lldb] [lldb] Synchronize the debugger's stdout and stderr streams (PR #126630)

2025-02-18 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 8b284dc31070b9d1d99c593146da6248a5ca545d 
4c7990f8e2424a6dbb9954df071f4fc91c93d067 --extensions cpp,h -- 
lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Core/IOHandler.h 
lldb/include/lldb/Host/Editline.h lldb/include/lldb/Host/File.h 
lldb/include/lldb/Host/StreamFile.h 
lldb/include/lldb/Interpreter/ScriptInterpreter.h 
lldb/include/lldb/Target/ThreadPlanTracer.h lldb/include/lldb/lldb-forward.h 
lldb/source/API/SBDebugger.cpp 
lldb/source/Commands/CommandObjectBreakpointCommand.cpp 
lldb/source/Commands/CommandObjectCommands.cpp 
lldb/source/Commands/CommandObjectExpression.cpp 
lldb/source/Commands/CommandObjectGUI.cpp 
lldb/source/Commands/CommandObjectLog.cpp 
lldb/source/Commands/CommandObjectTarget.cpp 
lldb/source/Commands/CommandObjectType.cpp 
lldb/source/Commands/CommandObjectWatchpointCommand.cpp 
lldb/source/Core/Debugger.cpp lldb/source/Core/IOHandler.cpp 
lldb/source/Core/IOHandlerCursesGUI.cpp lldb/source/Expression/REPL.cpp 
lldb/source/Host/common/Editline.cpp 
lldb/source/Interpreter/CommandInterpreter.cpp 
lldb/source/Interpreter/ScriptInterpreter.cpp 
lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp 
lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
 lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp 
lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
lldb/source/Target/ThreadPlanTracer.cpp lldb/unittests/Editline/EditlineTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/include/lldb/Core/Debugger.h 
b/lldb/include/lldb/Core/Debugger.h
index bbb06cb9c5..9c8a9623fe 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -134,9 +134,13 @@ public:
   lldb::FileSP GetInputFileSP() { return m_input_file_sp; }
   File &GetInputFile() { return *m_input_file_sp; }
 
-  lldb::FileSP GetOutputFileSP() { return 
m_output_stream_sp->GetUnlockedFileSP(); }
+  lldb::FileSP GetOutputFileSP() {
+return m_output_stream_sp->GetUnlockedFileSP();
+  }
 
-  lldb::FileSP GetErrorFileSP() { return 
m_error_stream_sp->GetUnlockedFileSP(); }
+  lldb::FileSP GetErrorFileSP() {
+return m_error_stream_sp->GetUnlockedFileSP();
+  }
 
   repro::DataRecorder *GetInputRecorder();
 

``




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


[Lldb-commits] [lldb] [lldb] Synchronize the debugger's stdout and stderr streams (PR #126630)

2025-02-18 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

Rebased on top of #127682

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


[Lldb-commits] [lldb] [lldb] Synchronize the debugger's stdout and stderr streams (PR #126630)

2025-02-18 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

As I had hoped, all the remaining uses of `LockableStreamFile` are now coming 
from the IOHandler. 

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


[Lldb-commits] [lldb] [lldb] Add terminfo dependency for ncurses support (PR #126810)

2025-02-18 Thread Jordan R AW via lldb-commits

ajordanr-google wrote:

This apparently broke a downstream edge case with fuschia: 
https://issues.fuchsia.dev/397455029, where they set all but the 
`TINFO_LIBRARIES` variable.

I have given them a downstream fix, but wondering if I can rework the patch so 
that this isn't an issue. I don't think we need to revert, given this only 
happens with edge-case defines and it's easily fixed downstream by setting 
`TINFO_LIBRARIES = CURSES_LIBRARIES`.

I'm thinking we could make it easier for folks who hit similar errors by doing 
one of the following:

1. Checking that when `CURSES_LIBRARIES`, see if it has the symbols. If not, 
then check if `TINFO_LIBRARIES` is set. Error out if not.
2. Don't check for the existence of `TINFO_LIBRARIES` at all, assume 
`CURSES_LIBRARIES` is set "correctly" for their use case.

I don't really have a preference here.

I also notice with this commit that we're changing `CURSES_LIBRARIES` to be a 
path to a list of paths. Not sure if anyone depends on that fact? Do we care?

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

2025-02-18 Thread Vy Nguyen via lldb-commits


@@ -56,13 +60,83 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes the exit status of a debugger.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct DebuggerTelemetryInfo : public LLDBBaseTelemetryInfo {
+  std::string username;
+  std::string lldb_git_sha;

oontvoo wrote:

Right - that's the general idea. But for our specific use-case, (as far as I 
remember) we need the git-sha to figure out which release it was (the info will 
be supplied at build time). I don't remember the exact detail, though.

will make this a generic "lldb_version" for now.

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

2025-02-18 Thread Vy Nguyen via lldb-commits

https://github.com/oontvoo updated 
https://github.com/llvm/llvm-project/pull/127696

>From 24e9f78744f98ecf3ac01f1f719f1eac9b3479f0 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Tue, 18 Feb 2025 15:58:08 -0500
Subject: [PATCH 1/2] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related
 methods

- This type of entry is used to collect data about the debugger startup/exit
- Tests will be added (They may need to be shell test with a "test-only" 
TelemetryManager plugin defined. I'm trying to figure out how to get that 
linked only when tests are running and not to the LLDB binary all the time.
---
 lldb/include/lldb/Core/Telemetry.h |  78 +++
 lldb/source/Core/Debugger.cpp  |  40 ++
 lldb/source/Core/Telemetry.cpp | 115 +
 3 files changed, 220 insertions(+), 13 deletions(-)

diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index b72556ecaf3c9..d6eec5dc687be 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -13,6 +13,7 @@
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Utility/StructuredData.h"
 #include "lldb/lldb-forward.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/JSON.h"
@@ -29,6 +30,9 @@ namespace telemetry {
 
 struct LLDBEntryKind : public ::llvm::telemetry::EntryKind {
   static const llvm::telemetry::KindType BaseInfo = 0b11000;
+  static const llvm::telemetry::KindType DebuggerInfo = 0b11001;
+  // There are other entries in between (added in separate PRs)
+  static const llvm::telemetry::KindType MiscInfo = 0b0;
 };
 
 /// Defines a convenient type for timestamp of various events.
@@ -56,6 +60,71 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes the exit status of a debugger.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct DebuggerTelemetryInfo : public LLDBBaseTelemetryInfo {
+  std::string username;
+  std::string lldb_git_sha;
+  std::string lldb_path;
+  std::string cwd;
+  std::optional exit_desc;
+
+  DebuggerTelemetryInfo() = default;
+
+  // Provide a copy ctor because we may need to make a copy before
+  // sanitizing the data.
+  // (The sanitization might differ between different Destination classes).
+  DebuggerTelemetryInfo(const DebuggerTelemetryInfo &other) {
+username = other.username;
+lldb_git_sha = other.lldb_git_sha;
+lldb_path = other.lldb_path;
+cwd = other.cwd;
+  };
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::DebuggerInfo;
+  }
+
+  static bool classof(const llvm::telemetry::TelemetryInfo *T) {
+return T->getKind() == LLDBEntryKind::DebuggerInfo;
+  }
+
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
+/// The "catch-all" entry to store a set of non-standard data, such as
+/// error-messages, etc.
+struct MiscTelemetryInfo : public LLDBBaseTelemetryInfo {
+  /// If the event is/can be associated with a target entry,
+  /// this field contains that target's UUID.
+  ///  otherwise.
+  std::string target_uuid;
+
+  /// Set of key-value pairs for any optional (or impl-specific) data
+  std::map meta_data;
+
+  MiscTelemetryInfo() = default;
+
+  MiscTelemetryInfo(const MiscTelemetryInfo &other) {
+target_uuid = other.target_uuid;
+meta_data = other.meta_data;
+  }
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::MiscInfo;
+  }
+
+  static bool classof(const llvm::telemetry::TelemetryInfo *T) {
+return T->getKind() == LLDBEntryKind::MiscInfo;
+  }
+
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
 /// The base Telemetry manager instance in LLDB.
 /// This class declares additional instrumentation points
 /// applicable to LLDB.
@@ -63,6 +132,11 @@ class TelemetryManager : public llvm::telemetry::Manager {
 public:
   llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override;
 
+  const llvm::telemetry::Config *getConfig();
+
+  void atDebuggerStartup(DebuggerTelemetryInfo *entry);
+  void atDebuggerExit(DebuggerTelemetryInfo *entry);
+
   virtual llvm::StringRef GetInstanceName() const = 0;
   static TelemetryManager *getInstance();
 
@@ -73,6 +147,10 @@ class TelemetryManager : public llvm::telemetry::Manager {
 
 private:
   std::unique_ptr m_config;
+  // Each debugger is assigned a unique ID (session_id).
+  // All TelemetryInfo entries emitted for the same debugger instance
+  // will get the same session_id.
+  llvm::DenseMap session_ids;
   static std::unique_ptr g_instance;
 };
 
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 18569e155b517..b458abc798a9e 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -62,6 +62,7 @@
 

[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

2025-02-18 Thread Vy Nguyen via lldb-commits

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

2025-02-18 Thread Vy Nguyen via lldb-commits


@@ -56,13 +60,83 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes the exit status of a debugger.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct DebuggerTelemetryInfo : public LLDBBaseTelemetryInfo {
+  std::string username;
+  std::string lldb_git_sha;
+  std::string lldb_path;
+  std::string cwd;
+  std::optional exit_desc;
+
+  DebuggerTelemetryInfo() = default;
+
+  // Provide a copy ctor because we may need to make a copy before
+  // sanitizing the data.
+  // (The sanitization might differ between different Destination classes).

oontvoo wrote:

> What's this sanitization. 
This goes back to your previous privacy question.  It's where the 
Destination::receiveEntry() decides  whether to delete sensitive fields before 
sending the entry to some custom storage. If it does want to delete the fields, 
it'd do so by copying the original entry, then modifying the copy. Otherwise, 
it'd just send the original w/o copying,


> Does that exist yet?
No, it's up to the vendors to decide which fields to sanitize (because I bet 
we'd all disagree on this). 

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

2025-02-18 Thread Vy Nguyen via lldb-commits


@@ -73,6 +147,10 @@ class TelemetryManager : public llvm::telemetry::Manager {
 
 private:
   std::unique_ptr m_config;
+  // Each debugger is assigned a unique ID (session_id).
+  // All TelemetryInfo entries emitted for the same debugger instance
+  // will get the same session_id.
+  llvm::DenseMap session_ids;

oontvoo wrote:

When the debugger is destroyed, we'd remove it from the map. When does a 
Debugger object get destroyed? Is it when the process dies?

(Unless you're saying there could be multiple different Debugger objects for 
the same entity?  )

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

2025-02-18 Thread Vy Nguyen via lldb-commits


@@ -761,12 +767,29 @@ void Debugger::InstanceInitialize() {
 
 DebuggerSP Debugger::CreateInstance(lldb::LogOutputCallback log_callback,
 void *baton) {
+#ifdef LLVM_BUILD_TELEMETRY
+  lldb_private::telemetry::SteadyTimePoint start_time =
+  std::chrono::steady_clock::now();
+#endif
   DebuggerSP debugger_sp(new Debugger(log_callback, baton));
   if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
 std::lock_guard guard(*g_debugger_list_mutex_ptr);
 g_debugger_list_ptr->push_back(debugger_sp);
   }
   debugger_sp->InstanceInitialize();
+
+#ifdef LLVM_BUILD_TELEMETRY
+  if (auto *telemetry_manager = telemetry::TelemetryManager::getInstance()) {
+if (telemetry_manager->getConfig()->EnableTelemetry) {
+  lldb_private::telemetry::DebuggerTelemetryInfo entry;
+  entry.start_time = start_time;
+  entry.end_time = std::chrono::steady_clock::now();
+  entry.debugger = debugger_sp.get();
+  telemetry_manager->atDebuggerStartup(&entry);
+}
+  }
+#endif

oontvoo wrote:

Can we convince the person that asked for this to accept the solution of 
setting `telemetry::Config::EnableTelemetry=false` and trusting that it'd do 
the right thign?

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

2025-02-18 Thread Vy Nguyen via lldb-commits

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


[Lldb-commits] [lldb] 7a78152 - [lldb] Fix a warning

2025-02-18 Thread Kazu Hirata via lldb-commits

Author: Kazu Hirata
Date: 2025-02-18T08:10:38-08:00
New Revision: 7a781527682ebe90616b05fb2311b1d0d6fc997e

URL: 
https://github.com/llvm/llvm-project/commit/7a781527682ebe90616b05fb2311b1d0d6fc997e
DIFF: 
https://github.com/llvm/llvm-project/commit/7a781527682ebe90616b05fb2311b1d0d6fc997e.diff

LOG: [lldb] Fix a warning

This patch fixes:

  third-party/unittest/googletest/include/gtest/gtest.h:1379:11:
  error: comparison of integers of different signs: 'const int' and
  'const unsigned long' [-Werror,-Wsign-compare]

Added: 


Modified: 
lldb/unittests/Core/TelemetryTest.cpp

Removed: 




diff  --git a/lldb/unittests/Core/TelemetryTest.cpp 
b/lldb/unittests/Core/TelemetryTest.cpp
index 03bd8a59ba7dc..0f2eaccb21a2c 100644
--- a/lldb/unittests/Core/TelemetryTest.cpp
+++ b/lldb/unittests/Core/TelemetryTest.cpp
@@ -87,7 +87,7 @@ TEST(TelemetryTest, PluginTest) {
   entry.msg = "";
 
   ASSERT_THAT_ERROR(ins->dispatch(&entry), ::llvm::Succeeded());
-  ASSERT_EQ(1, expected_entries.size());
+  ASSERT_EQ(1U, expected_entries.size());
   EXPECT_EQ("In FakePlugin",
 
llvm::dyn_cast(expected_entries[0])
 ->msg);



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Prepare UnwindPlans for discontinuous functions (PR #127661)

2025-02-18 Thread Pavel Labath via lldb-commits


@@ -477,19 +474,15 @@ class UnwindPlan {
   uint32_t GetReturnAddressRegister() { return m_return_addr_register; }
 
   uint32_t GetInitialCFARegister() const {
-if (m_row_list.empty())
-  return LLDB_INVALID_REGNUM;
-return m_row_list.front()->GetCFAValue().GetRegisterNumber();
+if (auto it = m_rows.find(0); it != m_rows.end())
+  return it->second->GetCFAValue().GetRegisterNumber();
+return LLDB_INVALID_REGNUM;
   }
 
   // This UnwindPlan may not be valid at every address of the function span.
   // For instance, a FastUnwindPlan will not be valid at the prologue setup
   // instructions - only in the body of the function.
-  void SetPlanValidAddressRange(const AddressRange &range);
-
-  const AddressRange &GetAddressRange() const {

labath wrote:

Unused fn.

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


[Lldb-commits] [lldb] [lldb] Add LineTable::{upper, lower}_bound (PR #127519)

2025-02-18 Thread Jonas Devlieghere via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] [lldb][Mach-O] Read dyld_all_image_infos addr from `main bin spec` LC_NOTE (PR #127156)

2025-02-18 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 3c2ba68915b268fd3b7d39bf62e19199b2cb8995 
11384154451c75afc99a272e61c4e869d605a11e --extensions h,cpp -- 
lldb/include/lldb/Symbol/ObjectFile.h 
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp 
lldb/source/Plugins/Process/mach-core/ProcessMachCore.h
``





View the diff from clang-format here.


``diff
diff --git a/lldb/include/lldb/Symbol/ObjectFile.h 
b/lldb/include/lldb/Symbol/ObjectFile.h
index a91590ad47..874926da2c 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -82,13 +82,13 @@ public:
 eBinaryTypeInvalid = 0,
 eBinaryTypeUnknown,
 /// kernel binary
-eBinaryTypeKernel, 
+eBinaryTypeKernel,
 /// user process binary, dyld addr
-eBinaryTypeUser,
+eBinaryTypeUser,
 /// user process binary, dyld_all_image_infos addr
-eBinaryTypeUserAllImageInfos, 
+eBinaryTypeUserAllImageInfos,
 /// standalone binary / firmware
-eBinaryTypeStandalone 
+eBinaryTypeStandalone
   };
 
   struct LoadableData {

``




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


[Lldb-commits] [lldb] [lldb][Mach-O] Read dyld_all_image_infos addr from `main bin spec` LC_NOTE (PR #127156)

2025-02-18 Thread Jason Molenda via lldb-commits

https://github.com/jasonmolenda updated 
https://github.com/llvm/llvm-project/pull/127156

>From 0a6558940403814ffa2bf6c265bc0e9267eef855 Mon Sep 17 00:00:00 2001
From: Jason Molenda 
Date: Thu, 13 Feb 2025 18:20:28 -0800
Subject: [PATCH 1/2] [lldb][Mach-O] Read dyld_all_image_infos addr from `main
 bin spec` LC_NOTE

Mach-O corefiles have LC_NOTE metadata, one LC_NOTE that lldb
recognizes is `main bin spec` which can specify that this is a
kernel corefile, userland corefile, or firmware/standalone corefile.
With a userland corefile, the LC_NOTE would specify the virtual
address of the dyld binary's Mach-O header.  lldb would create a
Module from that in-memory binary, find the `dyld_all_image_infos`
object in dyld's DATA segment, and use that object to find all of
the binaries present in the corefile.

ProcessMachCore takes the metadata from this LC_NOTE and passes the
address to the DynamicLoader plugin via its `GetImageInfoAddress()`
method, so the DynamicLoader can find all of the binaries and load
them in the Target at their correct virtual addresses.

We have a corefile creator who would prefer to specify the address
of `dyld_all_image_infos` directly, instead of specifying the address
of dyld and parsing that to find the object.  DynamicLoaderMacOSX,
the DynamicLoader plugin being used here, will accept either a
dyld virtual address or a `dyld_all_image_infos` virtual address
from ProcessMachCore, and do the correct thing with either value.

lldb's process save-core mach-o corefile reader will continue to
specify the virtual address of the dyld binary.

rdar://144322688
---
 lldb/include/lldb/Symbol/ObjectFile.h |  9 ++--
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 10 -
 .../Process/mach-core/ProcessMachCore.cpp | 45 +++
 .../Process/mach-core/ProcessMachCore.h   |  1 +
 4 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/lldb/include/lldb/Symbol/ObjectFile.h 
b/lldb/include/lldb/Symbol/ObjectFile.h
index d89314d44bf67..8873209eeece6 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -81,9 +81,12 @@ class ObjectFile : public 
std::enable_shared_from_this,
   enum BinaryType {
 eBinaryTypeInvalid = 0,
 eBinaryTypeUnknown,
-eBinaryTypeKernel,/// kernel binary
-eBinaryTypeUser,  /// user process binary
-eBinaryTypeStandalone /// standalone binary / firmware
+eBinaryTypeKernel,/// kernel binary
+eBinaryTypeUser,  /// user process binary,
+  /// dyld addr
+eBinaryTypeUserAllImageInfos, /// user process binary,
+  /// dyld_all_image_infos addr
+eBinaryTypeStandalone /// standalone binary / firmware
   };
 
   struct LoadableData {
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 4e356a7c8f5d9..8cf6ed268f3b8 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5599,9 +5599,13 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t 
&value,
   // struct main_bin_spec
   // {
   // uint32_t version;   // currently 2
-  // uint32_t type;  // 0 == unspecified, 1 == kernel,
+  // uint32_t type;  // 0 == unspecified,
+  // // 1 == kernel
   // // 2 == user process,
+  // dyld mach-o binary addr
   // // 3 == standalone binary
+  // // 4 == user process,
+  // //  dyld_all_image_infos addr
   // uint64_t address;   // UINT64_MAX if address not specified
   // uint64_t slide; // slide, UINT64_MAX if unspecified
   // // 0 if no slide needs to be applied to
@@ -5669,6 +5673,10 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t 
&value,
 type = eBinaryTypeStandalone;
 typestr = "standalone";
 break;
+  case 4:
+type = eBinaryTypeUserAllImageInfos;
+typestr = "userland dyld_all_image_infos";
+break;
   }
   LLDB_LOGF(log,
 "LC_NOTE 'main bin spec' found, version %d type %d "
diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp 
b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
index eef9bd4a175ec..281f3a0db8f69 100644
--- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
+++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
@@ -114,6 +114,7 @@ ProcessMachCore::ProcessMachCore(lldb::TargetSP target_sp,
 : PostMortemProcess(target_sp, listener_sp, core_file), m_core_aranges(),
   m_core_range_infos(), m_core_module_sp(),
 

[Lldb-commits] [lldb] [lldb] Store the return SBValueList in the CommandReturnObject (PR #127566)

2025-02-18 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Prepare UnwindPlans for discontinuous functions (PR #127661)

2025-02-18 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-hexagon

Author: Pavel Labath (labath)


Changes

The main changes are:
- changing the internal row representation from vector to a map. This
  wasn't strictly necessary, but I'm doing it because due the functions
  not starting at the lowest address, the Row for the function entry
  point (offset zero) may no longer be the first (zeroth) entry in the
  vector, so we will need to (binary) search for it. This would have
  been possible with a (sorted) vector representation as well, but that's
  somewhat tricky because the unwind plans are constructed in place, so
  there isn't a good place to insert a sort operations (the plans are
  currently implicitly sorted due to the sequential nature of their
  construction, but that will be harder to ensure when jumping between
  multiple regions).
- changing the valid address range from singular to plural

The changes to other files are due to the address range pluralization
and due to the removal of `AppendRow` (as there isn't really an "append"
operation in a map).

---

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


35 Files Affected:

- (modified) lldb/include/lldb/Symbol/UnwindPlan.h (+12-20) 
- (modified) lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp (+1-1) 
- (modified) lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/Hexagon/ABISysV_hexagon.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp (+1-1) 
- (modified) lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp (+2-2) 
- (modified) lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp 
(+1-1) 
- (modified) lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp 
(+1-1) 
- (modified) lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp 
(+1-1) 
- (modified) 
lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp (+1-1) 
- (modified) lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp 
(+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp (+3-3) 
- (modified) lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp (+1-1) 
- (modified) lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp 
(+9-9) 
- (modified) 
lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp (+5-5) 
- (modified) lldb/source/Symbol/ArmUnwindInfo.cpp (+1-1) 
- (modified) lldb/source/Symbol/CompactUnwindInfo.cpp (+8-8) 
- (modified) lldb/source/Symbol/DWARFCallFrameInfo.cpp (+7-7) 
- (modified) lldb/source/Symbol/UnwindPlan.cpp (+41-73) 
- (modified) lldb/unittests/Symbol/CMakeLists.txt (+1) 
- (added) lldb/unittests/Symbol/UnwindPlanTest.cpp (+76) 
- (modified) 
lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp (+12-12) 


``diff
diff --git a/lldb/include/lldb/Symbol/UnwindPlan.h 
b/lldb/include/lldb/Symbol/UnwindPlan.h
index 48c9bef76857c..1585fb69172a5 100644
--- a/lldb/include/lldb/Symbol/UnwindPlan.h
+++ b/lldb/include/lldb/Symbol/UnwindPlan.h
@@ -436,7 +436,7 @@ class UnwindPlan {
 
   // Performs a deep copy of the plan, including all the rows (expensive).
   UnwindPlan(const UnwindPlan &rhs)
-  : m_plan_valid_address_range(rhs.m_plan_valid_address_range),
+  : m_plan_valid_ranges(rhs.m_plan_valid_ranges),
 m_register_kind(rhs.m_register_kind),
 m_return_addr_register(rhs.m_return_addr_register),
 m_source_name(rhs.m_source_name),
@@ -446,18 +446,15 @@ class UnwindPlan {
 m_plan_is_for_signal_trap(rhs.m_plan_is_for_signal_trap),
 m_lsda_address(rhs.m_lsda_address),
 m_personality_func_addr(rhs.m_personality_func_addr) {
-m_row_list.reserve(rhs.m_row_list.size());
-for (const RowSP &row_sp : rhs.m_row_list)
-  m_row_list.emplace_back(new Row(*row_sp));
+for (const auto &[offset, row_sp] : rhs.m_rows)
+  m_rows.emplace(offset, std::make_shared(*row_sp));
   }
 
   ~UnwindPlan() = default;
 
   void Dump(Stream &s, Thread *thread, lldb::addr_t base_addr) const;
 
-

[Lldb-commits] [lldb] [lldb] Prepare UnwindPlans for discontinuous functions (PR #127661)

2025-02-18 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

The main changes are:
- changing the internal row representation from vector to a map. This
  wasn't strictly necessary, but I'm doing it because due the functions
  not starting at the lowest address, the Row for the function entry
  point (offset zero) may no longer be the first (zeroth) entry in the
  vector, so we will need to (binary) search for it. This would have
  been possible with a (sorted) vector representation as well, but that's
  somewhat tricky because the unwind plans are constructed in place, so
  there isn't a good place to insert a sort operations (the plans are
  currently implicitly sorted due to the sequential nature of their
  construction, but that will be harder to ensure when jumping between
  multiple regions).
- changing the valid address range from singular to plural

The changes to other files are due to the address range pluralization
and due to the removal of `AppendRow` (as there isn't really an "append"
operation in a map).

---

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


35 Files Affected:

- (modified) lldb/include/lldb/Symbol/UnwindPlan.h (+12-20) 
- (modified) lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp (+1-1) 
- (modified) lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/Hexagon/ABISysV_hexagon.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp (+1-1) 
- (modified) lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp (+2-2) 
- (modified) lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp (+2-2) 
- (modified) lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp 
(+1-1) 
- (modified) lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp 
(+1-1) 
- (modified) lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp 
(+1-1) 
- (modified) 
lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp (+1-1) 
- (modified) lldb/source/Plugins/Instruction/PPC64/EmulateInstructionPPC64.cpp 
(+1-1) 
- (modified) lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp (+3-3) 
- (modified) lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp (+1-1) 
- (modified) lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp 
(+9-9) 
- (modified) 
lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp (+5-5) 
- (modified) lldb/source/Symbol/ArmUnwindInfo.cpp (+1-1) 
- (modified) lldb/source/Symbol/CompactUnwindInfo.cpp (+8-8) 
- (modified) lldb/source/Symbol/DWARFCallFrameInfo.cpp (+7-7) 
- (modified) lldb/source/Symbol/UnwindPlan.cpp (+41-73) 
- (modified) lldb/unittests/Symbol/CMakeLists.txt (+1) 
- (added) lldb/unittests/Symbol/UnwindPlanTest.cpp (+76) 
- (modified) 
lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp (+12-12) 


``diff
diff --git a/lldb/include/lldb/Symbol/UnwindPlan.h 
b/lldb/include/lldb/Symbol/UnwindPlan.h
index 48c9bef76857c..1585fb69172a5 100644
--- a/lldb/include/lldb/Symbol/UnwindPlan.h
+++ b/lldb/include/lldb/Symbol/UnwindPlan.h
@@ -436,7 +436,7 @@ class UnwindPlan {
 
   // Performs a deep copy of the plan, including all the rows (expensive).
   UnwindPlan(const UnwindPlan &rhs)
-  : m_plan_valid_address_range(rhs.m_plan_valid_address_range),
+  : m_plan_valid_ranges(rhs.m_plan_valid_ranges),
 m_register_kind(rhs.m_register_kind),
 m_return_addr_register(rhs.m_return_addr_register),
 m_source_name(rhs.m_source_name),
@@ -446,18 +446,15 @@ class UnwindPlan {
 m_plan_is_for_signal_trap(rhs.m_plan_is_for_signal_trap),
 m_lsda_address(rhs.m_lsda_address),
 m_personality_func_addr(rhs.m_personality_func_addr) {
-m_row_list.reserve(rhs.m_row_list.size());
-for (const RowSP &row_sp : rhs.m_row_list)
-  m_row_list.emplace_back(new Row(*row_sp));
+for (const auto &[offset, row_sp] : rhs.m_rows)
+  m_rows.emplace(offset, std::make_shared(*row_sp));
   }
 
   ~UnwindPlan() = default;
 
   void Dump(Stream &s, Thread *thread, lldb::addr_t base_addr) const;
 
-  void Appe

[Lldb-commits] [lldb] Addressed additional review comments from PR/119716. (PR #126757)

2025-02-18 Thread Vy Nguyen via lldb-commits

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


[Lldb-commits] [lldb] 55dba06 - Addressed additional review comments from PR/119716. (#126757)

2025-02-18 Thread via lldb-commits

Author: Vy Nguyen
Date: 2025-02-18T11:13:55-05:00
New Revision: 55dba06540d17cb9abf2fca094a3805b4eef3be3

URL: 
https://github.com/llvm/llvm-project/commit/55dba06540d17cb9abf2fca094a3805b4eef3be3
DIFF: 
https://github.com/llvm/llvm-project/commit/55dba06540d17cb9abf2fca094a3805b4eef3be3.diff

LOG: Addressed additional review comments from PR/119716. (#126757)

Added: 


Modified: 
lldb/include/lldb/Core/Telemetry.h
lldb/source/Core/Telemetry.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index 7923b208e3b48..b72556ecaf3c9 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -56,7 +56,7 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
-/// The base Telemetry manager instance in LLDB
+/// The base Telemetry manager instance in LLDB.
 /// This class declares additional instrumentation points
 /// applicable to LLDB.
 class TelemetryManager : public llvm::telemetry::Manager {

diff  --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index f2a9d4bd00dad..5222f76704f91 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -29,10 +29,7 @@
 namespace lldb_private {
 namespace telemetry {
 
-using ::llvm::Error;
-using ::llvm::telemetry::Destination;
-using ::llvm::telemetry::Serializer;
-using ::llvm::telemetry::TelemetryInfo;
+using namespace llvm::telemetry;
 
 static uint64_t ToNanosec(const SteadyTimePoint Point) {
   return std::chrono::nanoseconds(Point.time_since_epoch()).count();
@@ -46,28 +43,27 @@ void LLDBBaseTelemetryInfo::serialize(Serializer 
&serializer) const {
 serializer.write("end_time", ToNanosec(end_time.value()));
 }
 
-[[maybe_unused]] static std::string MakeUUID(lldb_private::Debugger *debugger) 
{
+[[maybe_unused]] static std::string MakeUUID(Debugger *debugger) {
   uint8_t random_bytes[16];
   if (auto ec = llvm::getRandomBytes(random_bytes, 16)) {
 LLDB_LOG(GetLog(LLDBLog::Object),
  "Failed to generate random bytes for UUID: {0}", ec.message());
-// fallback to using timestamp + debugger ID.
+// Fallback to using timestamp + debugger ID.
 return llvm::formatv(
 "{0}_{1}", std::chrono::steady_clock::now().time_since_epoch().count(),
 debugger->GetID());
   }
-  return lldb_private::UUID(random_bytes).GetAsString();
+  return UUID(random_bytes).GetAsString();
 }
 
-TelemetryManager::TelemetryManager(
-std::unique_ptr config)
+TelemetryManager::TelemetryManager(std::unique_ptr config)
 : m_config(std::move(config)) {}
 
 llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) {
   // Do nothing for now.
   // In up-coming patch, this would be where the manager
   // attach the session_uuid to the entry.
-  return Error::success();
+  return llvm::Error::success();
 }
 
 std::unique_ptr TelemetryManager::g_instance = nullptr;



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Prepare UnwindPlans for discontinuous functions (PR #127661)

2025-02-18 Thread Pavel Labath via lldb-commits

https://github.com/labath created 
https://github.com/llvm/llvm-project/pull/127661

The main changes are:
- changing the internal row representation from vector to a map. This
  wasn't strictly necessary, but I'm doing it because due the functions
  not starting at the lowest address, the Row for the function entry
  point (offset zero) may no longer be the first (zeroth) entry in the
  vector, so we will need to (binary) search for it. This would have
  been possible with a (sorted) vector representation as well, but that's
  somewhat tricky because the unwind plans are constructed in place, so
  there isn't a good place to insert a sort operations (the plans are
  currently implicitly sorted due to the sequential nature of their
  construction, but that will be harder to ensure when jumping between
  multiple regions).
- changing the valid address range from singular to plural

The changes to other files are due to the address range pluralization
and due to the removal of `AppendRow` (as there isn't really an "append"
operation in a map).

>From 431345f9d7b6da285a36620d5862ceffd93c10ec Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Tue, 18 Feb 2025 16:14:30 +0100
Subject: [PATCH] [lldb] Prepare UnwindPlans for discontinuous functions

The main changes are:
- changing the internal row representation from vector to a map. This
  wasn't strictly necessary, but I'm doing it because due the functions
  not starting at the lowest address, the Row for the function entry
  point (offset zero) may no longer be the first (zeroth) entry in the
  vector, so we will need to (binary) search for it. This would have
  been possible with a (sorted) vector representation as well, but that's
  somewhat tricky because the unwind plans are constructed in place, so
  there isn't a good place to insert a sort operations (the plans are
  currently implicitly sorted due to the sequential nature of their
  construction, but that will be harder to ensure when jumping between
  multiple regions.
- changing the valid address range from singular to plural

The changes to other files are due to the address range pluralization
and due to the removal of `AppendRow` (as there isn't really an "append"
operation in a map).
---
 lldb/include/lldb/Symbol/UnwindPlan.h |  32 ++---
 .../Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp   |   4 +-
 .../Plugins/ABI/AArch64/ABISysV_arm64.cpp |   4 +-
 lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp   |   2 +-
 lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp |   4 +-
 lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp   |   4 +-
 .../Plugins/ABI/Hexagon/ABISysV_hexagon.cpp   |   4 +-
 .../ABI/LoongArch/ABISysV_loongarch.cpp   |   4 +-
 .../Plugins/ABI/MSP430/ABISysV_msp430.cpp |   4 +-
 lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp |   4 +-
 .../Plugins/ABI/Mips/ABISysV_mips64.cpp   |   4 +-
 .../Plugins/ABI/PowerPC/ABISysV_ppc.cpp   |   4 +-
 .../Plugins/ABI/PowerPC/ABISysV_ppc64.cpp |   4 +-
 .../Plugins/ABI/RISCV/ABISysV_riscv.cpp   |   4 +-
 .../Plugins/ABI/SystemZ/ABISysV_s390x.cpp |   2 +-
 .../source/Plugins/ABI/X86/ABIMacOSX_i386.cpp |   4 +-
 lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp  |   4 +-
 .../source/Plugins/ABI/X86/ABISysV_x86_64.cpp |   4 +-
 .../Plugins/ABI/X86/ABIWindows_x86_64.cpp |   4 +-
 .../Instruction/ARM/EmulateInstructionARM.cpp |   2 +-
 .../ARM64/EmulateInstructionARM64.cpp |   2 +-
 .../MIPS/EmulateInstructionMIPS.cpp   |   2 +-
 .../MIPS64/EmulateInstructionMIPS64.cpp   |   2 +-
 .../PPC64/EmulateInstructionPPC64.cpp |   2 +-
 .../ObjectFile/PECOFF/PECallFrameInfo.cpp |   6 +-
 .../Plugins/Platform/Linux/PlatformLinux.cpp  |   2 +-
 .../Breakpad/SymbolFileBreakpad.cpp   |  18 +--
 .../x86/x86AssemblyInspectionEngine.cpp   |  10 +-
 lldb/source/Symbol/ArmUnwindInfo.cpp  |   2 +-
 lldb/source/Symbol/CompactUnwindInfo.cpp  |  16 +--
 lldb/source/Symbol/DWARFCallFrameInfo.cpp |  14 +--
 lldb/source/Symbol/UnwindPlan.cpp | 114 +++---
 lldb/unittests/Symbol/CMakeLists.txt  |   1 +
 lldb/unittests/Symbol/UnwindPlanTest.cpp  |  76 
 .../x86/Testx86AssemblyInspectionEngine.cpp   |  24 ++--
 35 files changed, 215 insertions(+), 178 deletions(-)
 create mode 100644 lldb/unittests/Symbol/UnwindPlanTest.cpp

diff --git a/lldb/include/lldb/Symbol/UnwindPlan.h 
b/lldb/include/lldb/Symbol/UnwindPlan.h
index 48c9bef76857c..1585fb69172a5 100644
--- a/lldb/include/lldb/Symbol/UnwindPlan.h
+++ b/lldb/include/lldb/Symbol/UnwindPlan.h
@@ -436,7 +436,7 @@ class UnwindPlan {
 
   // Performs a deep copy of the plan, including all the rows (expensive).
   UnwindPlan(const UnwindPlan &rhs)
-  : m_plan_valid_address_range(rhs.m_plan_valid_address_range),
+  : m_plan_valid_ranges(rhs.m_plan_valid_ranges),
 m_register_kind(rhs.m_register_kind),
 m_return_addr_register(rhs.m_return_addr_register),
 m_source_name(rhs.m_source_name),

[Lldb-commits] [lldb] [lldb] Prepare UnwindPlans for discontinuous functions (PR #127661)

2025-02-18 Thread Pavel Labath via lldb-commits


@@ -486,9 +459,9 @@ bool UnwindPlan::PlanValidAtAddress(Address addr) {
   // If the 0th Row of unwind instructions is missing, or if it doesn't provide
   // a register to use to find the Canonical Frame Address, this is not a valid
   // UnwindPlan.
-  if (GetRowAtIndex(0).get() == nullptr ||
-  GetRowAtIndex(0)->GetCFAValue().GetValueType() ==
-  Row::FAValue::unspecified) {
+  RowSP row0_sp = GetRowForFunctionOffset(0);
+  if (!row0_sp ||
+  row0_sp->GetCFAValue().GetValueType() == Row::FAValue::unspecified) {

labath wrote:

This is potentially too strict. We could say we check for the CFA value of the 
first row -- even if that row doesn't start at offset zero (that's what the 
code was doing before). Or, we could say we check for the CFA value of the row 
matching the provided address...

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


[Lldb-commits] [lldb] [lldb] Prepare UnwindPlans for discontinuous functions (PR #127661)

2025-02-18 Thread Pavel Labath via lldb-commits


@@ -446,18 +446,15 @@ class UnwindPlan {
 m_plan_is_for_signal_trap(rhs.m_plan_is_for_signal_trap),
 m_lsda_address(rhs.m_lsda_address),
 m_personality_func_addr(rhs.m_personality_func_addr) {
-m_row_list.reserve(rhs.m_row_list.size());
-for (const RowSP &row_sp : rhs.m_row_list)
-  m_row_list.emplace_back(new Row(*row_sp));
+for (const auto &[offset, row_sp] : rhs.m_rows)
+  m_rows.emplace(offset, std::make_shared(*row_sp));
   }
 
   ~UnwindPlan() = default;
 
   void Dump(Stream &s, Thread *thread, lldb::addr_t base_addr) const;
 
-  void AppendRow(const RowSP &row_sp);
-
-  void InsertRow(const RowSP &row_sp, bool replace_existing = false);
+  void InsertRow(const RowSP &row_sp, bool replace_existing = true);

labath wrote:

Changed the default because that's how AppendRow worked (InsertRow was only 
called from test code until now)

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


[Lldb-commits] [lldb] [lldb] Synchronize the debugger's stdout and stderr streams (PR #126630)

2025-02-18 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

> Yesterday, I wasn't sure if we need the async stream mechanism. Today, I 
> think we do (because of the prompt redrawing thingy). I think the two 
> questions (async print and stream protection), but are separate in a way (the 
> iohandlers still need, and the editline iohandler actually uses a mutex), but 
> they are also kind of related in that they have to work together to achieve 
> desired outcome ("nice" console output?) -- which may impact how they're 
> implemented.

I think so too. When I started writing that message yesterday I was under the 
impression that we could get rid of the asynchronous streams altogether, but 
the prompt redrawing makes me doubt that. 

> At this point, I think the main question I am trying to answer is about a 
> some guideline/rule about the usage of the various printing mechanism. 
> Imagine I'm writing (or reviewing) a piece of code trying to print something. 
> How do I know which method to use. If I can get a hold of a Debugger, I have 
> the choice between GetOutputStreamSP, GetOutputFile and GetAsyncOutputStream. 
> This patch doesn't really change that (which is why I think you say it's a 
> net benefit), but it might make it seem like using GetOutputStreamSP (after 
> locking it) is safe/okay -- which I think is the part that's bothering me.
>
> So to try to propose an answer to this question: would it be correct to say 
> that (even after this patch, as it is right now), one should approximately 
> always use GetAsyncOutputStream for printing stuff out (at least in cases 
> where one doesn't have the CommandReturnObject around), and that the other 
> methods exist as implementation details of that (supporting locking in 
> iohandlers, which is necessary to produce output correctly), or due legacy 
> code we don't know how to get rid of?

Yes. I now think that everyone should use the asynchronous streams by default. 
The lockable streams should only be used if the buffering poses a problem or 
you need the underlying stream for legacy reasons (e.g. the SB API). Let me try 
to confirm that assumption by converting all the uses that don't fall in the 
exception categories in a separate PR. If that works out, we can think about a 
way to enforce this at the API level (e.g. making the getters for the lockable 
stream private and relying on friends) and rebase this PR on top.  


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


[Lldb-commits] [lldb] e1a393e - Define Telemetry plugin for LLDB. (#126588)

2025-02-18 Thread via lldb-commits

Author: Vy Nguyen
Date: 2025-02-18T10:44:16-05:00
New Revision: e1a393e39275ca0fea4bb19fa08c88bae3178cf8

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

LOG: Define Telemetry plugin for LLDB. (#126588)

Details:

Make LLDB's TelemetryManager a "plugin" so that vendor can supply
appropriate implementation.
The rest of LLDB code will simply call `TelemetryManager::getInstance`

-

Co-authored-by: Pavel Labath 

Added: 
lldb/unittests/Core/TelemetryTest.cpp

Modified: 
lldb/include/lldb/Core/Telemetry.h
lldb/source/Core/Telemetry.cpp
lldb/unittests/Core/CMakeLists.txt

Removed: 




diff  --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index 60a7097de5eee..7923b208e3b48 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -61,12 +61,19 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
 /// applicable to LLDB.
 class TelemetryManager : public llvm::telemetry::Manager {
 public:
+  llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override;
+
+  virtual llvm::StringRef GetInstanceName() const = 0;
+  static TelemetryManager *getInstance();
+
+protected:
   TelemetryManager(std::unique_ptr config);
 
-  llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override;
+  static void setInstance(std::unique_ptr manger);
 
 private:
   std::unique_ptr m_config;
+  static std::unique_ptr g_instance;
 };
 
 } // namespace telemetry

diff  --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index 0d0d7c1df3bb9..f2a9d4bd00dad 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -70,6 +70,13 @@ llvm::Error TelemetryManager::preDispatch(TelemetryInfo 
*entry) {
   return Error::success();
 }
 
+std::unique_ptr TelemetryManager::g_instance = nullptr;
+TelemetryManager *TelemetryManager::getInstance() { return g_instance.get(); }
+
+void TelemetryManager::setInstance(std::unique_ptr manager) {
+  g_instance = std::move(manager);
+}
+
 } // namespace telemetry
 } // namespace lldb_private
 

diff  --git a/lldb/unittests/Core/CMakeLists.txt 
b/lldb/unittests/Core/CMakeLists.txt
index 949963fd40346..d4d3764b67ae3 100644
--- a/lldb/unittests/Core/CMakeLists.txt
+++ b/lldb/unittests/Core/CMakeLists.txt
@@ -1,3 +1,7 @@
+if (LLVM_BUILD_TELEMETRY)
+  set(TELEMETRY_DEPS Telemetry)
+endif()
+
 add_lldb_unittest(LLDBCoreTests
   CommunicationTest.cpp
   DiagnosticEventTest.cpp
@@ -10,6 +14,7 @@ add_lldb_unittest(LLDBCoreTests
   RichManglingContextTest.cpp
   SourceLocationSpecTest.cpp
   SourceManagerTest.cpp
+  TelemetryTest.cpp
   UniqueCStringMapTest.cpp
 
   LINK_LIBS
@@ -26,4 +31,5 @@ add_lldb_unittest(LLDBCoreTests
 LLVMTestingSupport
   LINK_COMPONENTS
 Support
+${TELEMETRY_DEPS}
   )

diff  --git a/lldb/unittests/Core/TelemetryTest.cpp 
b/lldb/unittests/Core/TelemetryTest.cpp
new file mode 100644
index 0..03bd8a59ba7dc
--- /dev/null
+++ b/lldb/unittests/Core/TelemetryTest.cpp
@@ -0,0 +1,98 @@
+//===-- TelemetryTest.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 "llvm/Config/llvm-config.h"
+
+#ifdef LLVM_BUILD_TELEMETRY
+
+#include "lldb/Core/PluginInterface.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Telemetry.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Telemetry/Telemetry.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+namespace lldb_private {
+
+struct FakeTelemetryInfo : public llvm::telemetry::TelemetryInfo {
+  std::string msg;
+};
+
+class TestDestination : public llvm::telemetry::Destination {
+public:
+  TestDestination(std::vector *entries)
+  : received_entries(entries) {}
+
+  llvm::Error
+  receiveEntry(const llvm::telemetry::TelemetryInfo *entry) override {
+received_entries->push_back(entry);
+return llvm::Error::success();
+  }
+
+  llvm::StringLiteral name() const override { return "TestDestination"; }
+
+private:
+  std::vector *received_entries;
+};
+
+class FakePlugin : public telemetry::TelemetryManager {
+public:
+  FakePlugin()
+  : telemetry::TelemetryManager(
+std::make_unique(true)) {}
+
+  // TelemetryManager interface
+  llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override {
+if (auto *fake_entry = llvm::dyn_cast(entry))
+  fake_entry->msg = "In FakePlugin";
+
+return llvm::Error::success(

[Lldb-commits] [lldb] Define Telemetry plugin for LLDB. (PR #126588)

2025-02-18 Thread Vy Nguyen via lldb-commits

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


[Lldb-commits] [lldb] [lldb][RISCV] fix LR/SC handling in lldb-server (PR #127505)

2025-02-18 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

CC @SEmmmer 

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


[Lldb-commits] [lldb] [lldb] Store the return ValueObject in the CommandReturnObject (PR #127566)

2025-02-18 Thread via lldb-commits

jimingham wrote:

> Two questions:
> 
> * what about commands (like frame/target variable) which can return more than 
> variable. I guess I'm wondering if this should be a SBValueList instead?

That makes sense.

> * what about commands (I don't know if we have any) whose output consists of 
> more than formatting a single value (which, I guess would be lost if the IDE 
> decides to ignore the output). Are we fine with not supporting that? (we 
> could say that if a command wants to print some extra output, it should use 
> the error stream for that)

 In the longer term, we can also add an optional SBStructuredData for commands 
that return structured data, like `image lists` or `image lookup` so the UI can 
print these as tables or something else nice.  So if we end up having fancier 
commands that have both a ValueObject return plus extra annotation, we could 
add an SBValue type to what an SBStructured data can hold, and have it emit 
`before` and `after` entries for the extra text.

I think that would be better than trying to dump some of the output to stderr. 


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


[Lldb-commits] [lldb] [lldb] Store the return ValueObject in the CommandReturnObject (PR #127566)

2025-02-18 Thread via lldb-commits

jimingham wrote:

I think Pavel is right, having this be an SBValueList would allow us to support 
more commands.  That should be just as easy to implement and use, and more 
flexible.

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


[Lldb-commits] [lldb] [lldb][NFC] remove AdaptedConstIterator and AdaptedIterable (PR #127507)

2025-02-18 Thread via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Add LineTable::{upper, lower}_bound (PR #127519)

2025-02-18 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] Define Telemetry plugin for LLDB. (PR #126588)

2025-02-18 Thread Vy Nguyen via lldb-commits

oontvoo wrote:

Thanks, all. Just to wrap up, the only change required here is to remove the 
PluginInterface inheritance (and renaming the current 
`Manager::getPluginName()` to `Manager::getInstanceName()` to avoid confusion.



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


[Lldb-commits] [lldb] [lldb][Mach-O] Read dyld_all_image_infos addr from `main bin spec` LC_NOTE (PR #127156)

2025-02-18 Thread Jason Molenda via lldb-commits


@@ -5669,6 +5673,10 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t 
&value,
 type = eBinaryTypeStandalone;
 typestr = "standalone";
 break;
+  case 4:
+type = eBinaryTypeUserAllImageInfos;
+typestr = "userland dyld_all_image_infos";
+break;

jasonmolenda wrote:

The `typestr` is set to `"unrecognized type"` and will be printed if logging is 
enabled, but the `type` enum is uninitialized and will also be printed, which 
could be confusing.  I'll add an initialization.  This method doesn't currently 
take a Target or Process pointer so I can't print a message to the user 
asynchronously, it'll require them to enable logging when something is going 
wrong to find it.

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


[Lldb-commits] [lldb] 1f5edb1 - [lldb][Mach-O] Read dyld_all_image_infos addr from `main bin spec` LC_NOTE (#127156)

2025-02-18 Thread via lldb-commits

Author: Jason Molenda
Date: 2025-02-18T12:40:54-08:00
New Revision: 1f5edb17b23f5ac0576f83a6c122ce38bd5ec18e

URL: 
https://github.com/llvm/llvm-project/commit/1f5edb17b23f5ac0576f83a6c122ce38bd5ec18e
DIFF: 
https://github.com/llvm/llvm-project/commit/1f5edb17b23f5ac0576f83a6c122ce38bd5ec18e.diff

LOG: [lldb][Mach-O] Read dyld_all_image_infos addr from `main bin spec` LC_NOTE 
(#127156)

Mach-O corefiles have LC_NOTE metadata, one LC_NOTE that lldb recognizes
is `main bin spec` which can specify that this is a kernel corefile,
userland corefile, or firmware/standalone corefile. With a userland
corefile, the LC_NOTE would specify the virtual address of the dyld
binary's Mach-O header. lldb would create a Module from that in-memory
binary, find the `dyld_all_image_infos` object in dyld's DATA segment,
and use that object to find all of the binaries present in the corefile.

ProcessMachCore takes the metadata from this LC_NOTE and passes the
address to the DynamicLoader plugin via its `GetImageInfoAddress()`
method, so the DynamicLoader can find all of the binaries and load them
in the Target at their correct virtual addresses.

We have a corefile creator who would prefer to specify the address of
`dyld_all_image_infos` directly, instead of specifying the address of
dyld and parsing that to find the object. DynamicLoaderMacOSX, the
DynamicLoader plugin being used here, will accept either a dyld virtual
address or a `dyld_all_image_infos` virtual address from
ProcessMachCore, and do the correct thing with either value.

lldb's process save-core mach-o corefile reader will continue to specify
the virtual address of the dyld binary.

rdar://144322688

Added: 


Modified: 
lldb/include/lldb/Symbol/ObjectFile.h
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
lldb/source/Plugins/Process/mach-core/ProcessMachCore.h

Removed: 




diff  --git a/lldb/include/lldb/Symbol/ObjectFile.h 
b/lldb/include/lldb/Symbol/ObjectFile.h
index d89314d44bf67..874926da2ceb7 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -81,9 +81,14 @@ class ObjectFile : public 
std::enable_shared_from_this,
   enum BinaryType {
 eBinaryTypeInvalid = 0,
 eBinaryTypeUnknown,
-eBinaryTypeKernel,/// kernel binary
-eBinaryTypeUser,  /// user process binary
-eBinaryTypeStandalone /// standalone binary / firmware
+/// kernel binary
+eBinaryTypeKernel,
+/// user process binary, dyld addr
+eBinaryTypeUser,
+/// user process binary, dyld_all_image_infos addr
+eBinaryTypeUserAllImageInfos,
+/// standalone binary / firmware
+eBinaryTypeStandalone
   };
 
   struct LoadableData {

diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 4e356a7c8f5d9..a19322ff1e263 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5599,9 +5599,13 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t 
&value,
   // struct main_bin_spec
   // {
   // uint32_t version;   // currently 2
-  // uint32_t type;  // 0 == unspecified, 1 == kernel,
+  // uint32_t type;  // 0 == unspecified,
+  // // 1 == kernel
   // // 2 == user process,
+  // dyld mach-o binary addr
   // // 3 == standalone binary
+  // // 4 == user process,
+  // //  dyld_all_image_infos addr
   // uint64_t address;   // UINT64_MAX if address not specified
   // uint64_t slide; // slide, UINT64_MAX if unspecified
   // // 0 if no slide needs to be applied to
@@ -5652,6 +5656,7 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t 
&value,
   // convert the "main bin spec" type into our
   // ObjectFile::BinaryType enum
   const char *typestr = "unrecognized type";
+  type = eBinaryTypeInvalid;
   switch (binspec_type) {
   case 0:
 type = eBinaryTypeUnknown;
@@ -5669,6 +5674,10 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t 
&value,
 type = eBinaryTypeStandalone;
 typestr = "standalone";
 break;
+  case 4:
+type = eBinaryTypeUserAllImageInfos;
+typestr = "userland dyld_all_image_infos";
+break;
   }
   LLDB_LOGF(log,
 "LC_NOTE 'main bin spec' found, version %d type %d "

diff  --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp 
b/lldb/source/Plugins/Process/m

[Lldb-commits] [lldb] [lldb][Mach-O] Read dyld_all_image_infos addr from `main bin spec` LC_NOTE (PR #127156)

2025-02-18 Thread Jason Molenda via lldb-commits

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


[Lldb-commits] [lldb] Allow option to ignore module load errors in ScriptedProcess (PR #127153)

2025-02-18 Thread via lldb-commits

jimingham wrote:

So it seems like if we ignore module loading errors for these cases, the 
generic code in lldb does the right thing and produces an "as good as it can 
do" module entry.  So why would we ever want to elide a library if the scripted 
side can't find a physical file for it?  Whatever is producing the module after 
errors should always be allowed to do that, shouldn't it?

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


[Lldb-commits] [lldb] [LLDB-DAP] SBDebugger don't prefix title on progress updates (PR #124648)

2025-02-18 Thread Jacob Lalonde via lldb-commits

https://github.com/Jlalond updated 
https://github.com/llvm/llvm-project/pull/124648

>From 12ff645735c1dbf51e58b9f80d4e3e13a0babdf5 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Mon, 27 Jan 2025 13:41:58 -0800
Subject: [PATCH 1/4] Only include title on the first message

---
 lldb/include/lldb/Core/DebuggerEvents.h | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lldb/include/lldb/Core/DebuggerEvents.h 
b/lldb/include/lldb/Core/DebuggerEvents.h
index 49a4ecf8e537e..52e4f77d7637d 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -44,12 +44,15 @@ class ProgressEventData : public EventData {
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
-std::string message = m_title;
-if (!m_details.empty()) {
-  message.append(": ");
-  message.append(m_details);
-}
-return message;
+if (m_completed == 0) {
+  std::string message = m_title;
+  if (!m_details.empty()) {
+message.append(": ");
+message.append(m_details);
+  }
+  return message;
+} else
+  return !m_details.empty() ? m_details : std::string();
   }
   const std::string &GetTitle() const { return m_title; }
   const std::string &GetDetails() const { return m_details; }

>From 82ed76ae3b6bef176bf54dd1031f0cb9c95081c1 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Mon, 27 Jan 2025 14:48:01 -0800
Subject: [PATCH 2/4] Add comment explaining if and add a test

---
 lldb/include/lldb/Core/DebuggerEvents.h   | 1 +
 lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py | 5 +
 2 files changed, 6 insertions(+)

diff --git a/lldb/include/lldb/Core/DebuggerEvents.h 
b/lldb/include/lldb/Core/DebuggerEvents.h
index 52e4f77d7637d..ca06ee835fde3 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -44,6 +44,7 @@ class ProgressEventData : public EventData {
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
+// Only put the title in the message of the progress create event.
 if (m_completed == 0) {
   std::string message = m_title;
   if (!m_details.empty()) {
diff --git a/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py 
b/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py
index 36c0cef9c4714..945c3f7633364 100755
--- a/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py
+++ b/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py
@@ -41,8 +41,13 @@ def test_output(self):
 for event in self.dap_server.progress_events:
 event_type = event["event"]
 if "progressStart" in event_type:
+title = event["body"]["title"]
+self.assertIn("Progress tester", title)
 start_found = True
 if "progressUpdate" in event_type:
+message = event["body"]["message"]
+print(f"Progress update: {message}")
+self.assertNotIn("Progres tester", message)
 update_found = True
 
 self.assertTrue(start_found)

>From e15090782a93e07e8a260a0594ca02430e68e09f Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Thu, 30 Jan 2025 10:04:04 -0800
Subject: [PATCH 3/4] Migrate to structured data

Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:


Differential Revision: https://phabricator.intern.facebook.com/D68927453
---
 lldb/include/lldb/Core/DebuggerEvents.h | 16 +++-
 lldb/tools/lldb-dap/lldb-dap.cpp| 54 +
 2 files changed, 52 insertions(+), 18 deletions(-)

diff --git a/lldb/include/lldb/Core/DebuggerEvents.h 
b/lldb/include/lldb/Core/DebuggerEvents.h
index ca06ee835fde3..49a4ecf8e537e 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -44,16 +44,12 @@ class ProgressEventData : public EventData {
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
-// Only put the title in the message of the progress create event.
-if (m_completed == 0) {
-  std::string message = m_title;
-  if (!m_details.empty()) {
-message.append(": ");
-message.append(m_details);
-  }
-  return message;
-} else
-  return !m_details.empty() ? m_details : std::string();
+std::string message = m_title;
+if (!m_details.empty()) {
+  message.append(": ");
+  message.append(m_details);
+}
+return message;
   }
   const std::string &GetTitle() const { return m_title; }
   const std::string &GetDetails() const { return m_details; }
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index e323990d8b6ed..4b3460190a7c9 100644
--- a/lldb/tools/lldb

[Lldb-commits] [lldb] 49453bf - [lldb][NFC] remove AdaptedConstIterator and AdaptedIterable (#127507)

2025-02-18 Thread via lldb-commits

Author: dlav-sc
Date: 2025-02-18T21:06:48+03:00
New Revision: 49453bf18e1877a3bd4d1cef40bb52c209b9c1e3

URL: 
https://github.com/llvm/llvm-project/commit/49453bf18e1877a3bd4d1cef40bb52c209b9c1e3
DIFF: 
https://github.com/llvm/llvm-project/commit/49453bf18e1877a3bd4d1cef40bb52c209b9c1e3.diff

LOG: [lldb][NFC] remove AdaptedConstIterator and AdaptedIterable (#127507)

AdaptedConstIterator currently doesn't have iterator traits, so I can't
use STL algorithms with containers like WatchpointList.

This patch replaces AdaptedConstIterator and AdaptedIterable with
llvm::iterator_adaped_base and llvm::iterator_range respectively.

Added: 


Modified: 
lldb/include/lldb/Breakpoint/BreakpointList.h
lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h
lldb/include/lldb/Breakpoint/BreakpointLocationList.h
lldb/include/lldb/Breakpoint/WatchpointList.h
lldb/include/lldb/Breakpoint/WatchpointResource.h
lldb/include/lldb/Core/ModuleList.h
lldb/include/lldb/Core/ModuleSpec.h
lldb/include/lldb/Host/common/NativeProcessProtocol.h
lldb/include/lldb/Symbol/SymbolContext.h
lldb/include/lldb/Symbol/TypeList.h
lldb/include/lldb/Symbol/TypeMap.h
lldb/include/lldb/Target/QueueList.h
lldb/include/lldb/Target/TargetList.h
lldb/include/lldb/Target/ThreadCollection.h
lldb/include/lldb/Utility/Iterable.h

Removed: 




diff  --git a/lldb/include/lldb/Breakpoint/BreakpointList.h 
b/lldb/include/lldb/Breakpoint/BreakpointList.h
index a7399d385f6f0..4a921fadfc066 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointList.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointList.h
@@ -163,8 +163,7 @@ class BreakpointList {
   bool m_is_internal;
 
 public:
-  typedef LockingAdaptedIterable
+  typedef LockingAdaptedIterable
   BreakpointIterable;
   BreakpointIterable Breakpoints() {
 return BreakpointIterable(m_breakpoints, GetMutex());

diff  --git a/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h 
b/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h
index 34bd309864871..3aef1d658c0e5 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h
@@ -165,8 +165,7 @@ class BreakpointLocationCollection {
   mutable std::mutex m_collection_mutex;
 
 public:
-  typedef AdaptedIterable
+  typedef llvm::iterator_range
   BreakpointLocationCollectionIterable;
   BreakpointLocationCollectionIterable BreakpointLocations() {
 return BreakpointLocationCollectionIterable(m_break_loc_collection);

diff  --git a/lldb/include/lldb/Breakpoint/BreakpointLocationList.h 
b/lldb/include/lldb/Breakpoint/BreakpointLocationList.h
index f76a8fcfdd7e7..17dc0bfe03148 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointLocationList.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointLocationList.h
@@ -204,8 +204,7 @@ class BreakpointLocationList {
   BreakpointLocationCollection *m_new_location_recorder;
 
 public:
-  typedef AdaptedIterable
+  typedef llvm::iterator_range
   BreakpointLocationIterable;
 
   BreakpointLocationIterable BreakpointLocations() {

diff  --git a/lldb/include/lldb/Breakpoint/WatchpointList.h 
b/lldb/include/lldb/Breakpoint/WatchpointList.h
index bf87495d79dba..d037d36e64290 100644
--- a/lldb/include/lldb/Breakpoint/WatchpointList.h
+++ b/lldb/include/lldb/Breakpoint/WatchpointList.h
@@ -39,8 +39,7 @@ class WatchpointList {
   ~WatchpointList();
 
   typedef std::list wp_collection;
-  typedef LockingAdaptedIterable
+  typedef LockingAdaptedIterable
   WatchpointIterable;
 
   /// Add a Watchpoint to the list.

diff  --git a/lldb/include/lldb/Breakpoint/WatchpointResource.h 
b/lldb/include/lldb/Breakpoint/WatchpointResource.h
index 070d84cff8f26..c1a81fc486eb6 100644
--- a/lldb/include/lldb/Breakpoint/WatchpointResource.h
+++ b/lldb/include/lldb/Breakpoint/WatchpointResource.h
@@ -39,8 +39,7 @@ class WatchpointResource
   void SetType(bool read, bool write);
 
   typedef std::vector WatchpointCollection;
-  typedef LockingAdaptedIterable
+  typedef LockingAdaptedIterable
   WatchpointIterable;
 
   /// Iterate over the watchpoint constituents for this resource

diff  --git a/lldb/include/lldb/Core/ModuleList.h 
b/lldb/include/lldb/Core/ModuleList.h
index 43d931a844740..29b87de88520d 100644
--- a/lldb/include/lldb/Core/ModuleList.h
+++ b/lldb/include/lldb/Core/ModuleList.h
@@ -521,14 +521,13 @@ class ModuleList {
   Notifier *m_notifier = nullptr;
 
 public:
-  typedef LockingAdaptedIterable
+  typedef LockingAdaptedIterable
   ModuleIterable;
   ModuleIterable Modules() const {
 return ModuleIterable(m_modules, GetMutex());
   }
 
-  typedef AdaptedIterable
+  typedef llvm::iterator_range
   ModuleIterableNoLocking;
   ModuleIterableNoLocking ModulesNoLocking() const {
 return ModuleIterableNoLocking(m_modules);

diff  --git a/lldb/include/lldb/Core/ModuleSpec.h

[Lldb-commits] [lldb] [lldb][Mach-O] Read dyld_all_image_infos addr from `main bin spec` LC_NOTE (PR #127156)

2025-02-18 Thread Jason Molenda via lldb-commits

https://github.com/jasonmolenda updated 
https://github.com/llvm/llvm-project/pull/127156

>From 0a6558940403814ffa2bf6c265bc0e9267eef855 Mon Sep 17 00:00:00 2001
From: Jason Molenda 
Date: Thu, 13 Feb 2025 18:20:28 -0800
Subject: [PATCH 1/3] [lldb][Mach-O] Read dyld_all_image_infos addr from `main
 bin spec` LC_NOTE

Mach-O corefiles have LC_NOTE metadata, one LC_NOTE that lldb
recognizes is `main bin spec` which can specify that this is a
kernel corefile, userland corefile, or firmware/standalone corefile.
With a userland corefile, the LC_NOTE would specify the virtual
address of the dyld binary's Mach-O header.  lldb would create a
Module from that in-memory binary, find the `dyld_all_image_infos`
object in dyld's DATA segment, and use that object to find all of
the binaries present in the corefile.

ProcessMachCore takes the metadata from this LC_NOTE and passes the
address to the DynamicLoader plugin via its `GetImageInfoAddress()`
method, so the DynamicLoader can find all of the binaries and load
them in the Target at their correct virtual addresses.

We have a corefile creator who would prefer to specify the address
of `dyld_all_image_infos` directly, instead of specifying the address
of dyld and parsing that to find the object.  DynamicLoaderMacOSX,
the DynamicLoader plugin being used here, will accept either a
dyld virtual address or a `dyld_all_image_infos` virtual address
from ProcessMachCore, and do the correct thing with either value.

lldb's process save-core mach-o corefile reader will continue to
specify the virtual address of the dyld binary.

rdar://144322688
---
 lldb/include/lldb/Symbol/ObjectFile.h |  9 ++--
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 10 -
 .../Process/mach-core/ProcessMachCore.cpp | 45 +++
 .../Process/mach-core/ProcessMachCore.h   |  1 +
 4 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/lldb/include/lldb/Symbol/ObjectFile.h 
b/lldb/include/lldb/Symbol/ObjectFile.h
index d89314d44bf67..8873209eeece6 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -81,9 +81,12 @@ class ObjectFile : public 
std::enable_shared_from_this,
   enum BinaryType {
 eBinaryTypeInvalid = 0,
 eBinaryTypeUnknown,
-eBinaryTypeKernel,/// kernel binary
-eBinaryTypeUser,  /// user process binary
-eBinaryTypeStandalone /// standalone binary / firmware
+eBinaryTypeKernel,/// kernel binary
+eBinaryTypeUser,  /// user process binary,
+  /// dyld addr
+eBinaryTypeUserAllImageInfos, /// user process binary,
+  /// dyld_all_image_infos addr
+eBinaryTypeStandalone /// standalone binary / firmware
   };
 
   struct LoadableData {
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 4e356a7c8f5d9..8cf6ed268f3b8 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5599,9 +5599,13 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t 
&value,
   // struct main_bin_spec
   // {
   // uint32_t version;   // currently 2
-  // uint32_t type;  // 0 == unspecified, 1 == kernel,
+  // uint32_t type;  // 0 == unspecified,
+  // // 1 == kernel
   // // 2 == user process,
+  // dyld mach-o binary addr
   // // 3 == standalone binary
+  // // 4 == user process,
+  // //  dyld_all_image_infos addr
   // uint64_t address;   // UINT64_MAX if address not specified
   // uint64_t slide; // slide, UINT64_MAX if unspecified
   // // 0 if no slide needs to be applied to
@@ -5669,6 +5673,10 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t 
&value,
 type = eBinaryTypeStandalone;
 typestr = "standalone";
 break;
+  case 4:
+type = eBinaryTypeUserAllImageInfos;
+typestr = "userland dyld_all_image_infos";
+break;
   }
   LLDB_LOGF(log,
 "LC_NOTE 'main bin spec' found, version %d type %d "
diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp 
b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
index eef9bd4a175ec..281f3a0db8f69 100644
--- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
+++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
@@ -114,6 +114,7 @@ ProcessMachCore::ProcessMachCore(lldb::TargetSP target_sp,
 : PostMortemProcess(target_sp, listener_sp, core_file), m_core_aranges(),
   m_core_range_infos(), m_core_module_sp(),
 

[Lldb-commits] [lldb] [LLDB-DAP] SBDebugger don't prefix title on progress updates (PR #124648)

2025-02-18 Thread Jonas Devlieghere via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb][Mach-O] Read dyld_all_image_infos addr from `main bin spec` LC_NOTE (PR #127156)

2025-02-18 Thread Jason Molenda via lldb-commits

https://github.com/jasonmolenda updated 
https://github.com/llvm/llvm-project/pull/127156

>From 0a6558940403814ffa2bf6c265bc0e9267eef855 Mon Sep 17 00:00:00 2001
From: Jason Molenda 
Date: Thu, 13 Feb 2025 18:20:28 -0800
Subject: [PATCH 1/4] [lldb][Mach-O] Read dyld_all_image_infos addr from `main
 bin spec` LC_NOTE

Mach-O corefiles have LC_NOTE metadata, one LC_NOTE that lldb
recognizes is `main bin spec` which can specify that this is a
kernel corefile, userland corefile, or firmware/standalone corefile.
With a userland corefile, the LC_NOTE would specify the virtual
address of the dyld binary's Mach-O header.  lldb would create a
Module from that in-memory binary, find the `dyld_all_image_infos`
object in dyld's DATA segment, and use that object to find all of
the binaries present in the corefile.

ProcessMachCore takes the metadata from this LC_NOTE and passes the
address to the DynamicLoader plugin via its `GetImageInfoAddress()`
method, so the DynamicLoader can find all of the binaries and load
them in the Target at their correct virtual addresses.

We have a corefile creator who would prefer to specify the address
of `dyld_all_image_infos` directly, instead of specifying the address
of dyld and parsing that to find the object.  DynamicLoaderMacOSX,
the DynamicLoader plugin being used here, will accept either a
dyld virtual address or a `dyld_all_image_infos` virtual address
from ProcessMachCore, and do the correct thing with either value.

lldb's process save-core mach-o corefile reader will continue to
specify the virtual address of the dyld binary.

rdar://144322688
---
 lldb/include/lldb/Symbol/ObjectFile.h |  9 ++--
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 10 -
 .../Process/mach-core/ProcessMachCore.cpp | 45 +++
 .../Process/mach-core/ProcessMachCore.h   |  1 +
 4 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/lldb/include/lldb/Symbol/ObjectFile.h 
b/lldb/include/lldb/Symbol/ObjectFile.h
index d89314d44bf67..8873209eeece6 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -81,9 +81,12 @@ class ObjectFile : public 
std::enable_shared_from_this,
   enum BinaryType {
 eBinaryTypeInvalid = 0,
 eBinaryTypeUnknown,
-eBinaryTypeKernel,/// kernel binary
-eBinaryTypeUser,  /// user process binary
-eBinaryTypeStandalone /// standalone binary / firmware
+eBinaryTypeKernel,/// kernel binary
+eBinaryTypeUser,  /// user process binary,
+  /// dyld addr
+eBinaryTypeUserAllImageInfos, /// user process binary,
+  /// dyld_all_image_infos addr
+eBinaryTypeStandalone /// standalone binary / firmware
   };
 
   struct LoadableData {
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 4e356a7c8f5d9..8cf6ed268f3b8 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5599,9 +5599,13 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t 
&value,
   // struct main_bin_spec
   // {
   // uint32_t version;   // currently 2
-  // uint32_t type;  // 0 == unspecified, 1 == kernel,
+  // uint32_t type;  // 0 == unspecified,
+  // // 1 == kernel
   // // 2 == user process,
+  // dyld mach-o binary addr
   // // 3 == standalone binary
+  // // 4 == user process,
+  // //  dyld_all_image_infos addr
   // uint64_t address;   // UINT64_MAX if address not specified
   // uint64_t slide; // slide, UINT64_MAX if unspecified
   // // 0 if no slide needs to be applied to
@@ -5669,6 +5673,10 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t 
&value,
 type = eBinaryTypeStandalone;
 typestr = "standalone";
 break;
+  case 4:
+type = eBinaryTypeUserAllImageInfos;
+typestr = "userland dyld_all_image_infos";
+break;
   }
   LLDB_LOGF(log,
 "LC_NOTE 'main bin spec' found, version %d type %d "
diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp 
b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
index eef9bd4a175ec..281f3a0db8f69 100644
--- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
+++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
@@ -114,6 +114,7 @@ ProcessMachCore::ProcessMachCore(lldb::TargetSP target_sp,
 : PostMortemProcess(target_sp, listener_sp, core_file), m_core_aranges(),
   m_core_range_infos(), m_core_module_sp(),
 

[Lldb-commits] [lldb] [lldb] Store the return SBValueList in the CommandReturnObject (PR #127566)

2025-02-18 Thread via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

2025-02-18 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Vy Nguyen (oontvoo)


Changes

- This type of entry is used to collect data about the debugger startup/exit
- Tests will be added (They may need to be shell test with a "test-only" 
TelemetryManager plugin defined. I'm trying to figure out how to get that 
linked only when tests are running and not to the LLDB binary all the time.

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


3 Files Affected:

- (modified) lldb/include/lldb/Core/Telemetry.h (+78) 
- (modified) lldb/source/Core/Debugger.cpp (+40) 
- (modified) lldb/source/Core/Telemetry.cpp (+102-13) 


``diff
diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index b72556ecaf3c9..d6eec5dc687be 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -13,6 +13,7 @@
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Utility/StructuredData.h"
 #include "lldb/lldb-forward.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/JSON.h"
@@ -29,6 +30,9 @@ namespace telemetry {
 
 struct LLDBEntryKind : public ::llvm::telemetry::EntryKind {
   static const llvm::telemetry::KindType BaseInfo = 0b11000;
+  static const llvm::telemetry::KindType DebuggerInfo = 0b11001;
+  // There are other entries in between (added in separate PRs)
+  static const llvm::telemetry::KindType MiscInfo = 0b0;
 };
 
 /// Defines a convenient type for timestamp of various events.
@@ -56,6 +60,71 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes the exit status of a debugger.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct DebuggerTelemetryInfo : public LLDBBaseTelemetryInfo {
+  std::string username;
+  std::string lldb_git_sha;
+  std::string lldb_path;
+  std::string cwd;
+  std::optional exit_desc;
+
+  DebuggerTelemetryInfo() = default;
+
+  // Provide a copy ctor because we may need to make a copy before
+  // sanitizing the data.
+  // (The sanitization might differ between different Destination classes).
+  DebuggerTelemetryInfo(const DebuggerTelemetryInfo &other) {
+username = other.username;
+lldb_git_sha = other.lldb_git_sha;
+lldb_path = other.lldb_path;
+cwd = other.cwd;
+  };
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::DebuggerInfo;
+  }
+
+  static bool classof(const llvm::telemetry::TelemetryInfo *T) {
+return T->getKind() == LLDBEntryKind::DebuggerInfo;
+  }
+
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
+/// The "catch-all" entry to store a set of non-standard data, such as
+/// error-messages, etc.
+struct MiscTelemetryInfo : public LLDBBaseTelemetryInfo {
+  /// If the event is/can be associated with a target entry,
+  /// this field contains that target's UUID.
+  ///  otherwise.
+  std::string target_uuid;
+
+  /// Set of key-value pairs for any optional (or impl-specific) data
+  std::map meta_data;
+
+  MiscTelemetryInfo() = default;
+
+  MiscTelemetryInfo(const MiscTelemetryInfo &other) {
+target_uuid = other.target_uuid;
+meta_data = other.meta_data;
+  }
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::MiscInfo;
+  }
+
+  static bool classof(const llvm::telemetry::TelemetryInfo *T) {
+return T->getKind() == LLDBEntryKind::MiscInfo;
+  }
+
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
 /// The base Telemetry manager instance in LLDB.
 /// This class declares additional instrumentation points
 /// applicable to LLDB.
@@ -63,6 +132,11 @@ class TelemetryManager : public llvm::telemetry::Manager {
 public:
   llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override;
 
+  const llvm::telemetry::Config *getConfig();
+
+  void atDebuggerStartup(DebuggerTelemetryInfo *entry);
+  void atDebuggerExit(DebuggerTelemetryInfo *entry);
+
   virtual llvm::StringRef GetInstanceName() const = 0;
   static TelemetryManager *getInstance();
 
@@ -73,6 +147,10 @@ class TelemetryManager : public llvm::telemetry::Manager {
 
 private:
   std::unique_ptr m_config;
+  // Each debugger is assigned a unique ID (session_id).
+  // All TelemetryInfo entries emitted for the same debugger instance
+  // will get the same session_id.
+  llvm::DenseMap session_ids;
   static std::unique_ptr g_instance;
 };
 
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 18569e155b517..b458abc798a9e 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -62,6 +62,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator.h"
+#include "llvm/Config/llvm-config.h"
 #include "llvm/Support/DynamicLibrary.h"
 #include "llvm/S

[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

2025-02-18 Thread Vy Nguyen via lldb-commits

https://github.com/oontvoo created 
https://github.com/llvm/llvm-project/pull/127696

- This type of entry is used to collect data about the debugger startup/exit
- Tests will be added (They may need to be shell test with a "test-only" 
TelemetryManager plugin defined. I'm trying to figure out how to get that 
linked only when tests are running and not to the LLDB binary all the time.

>From 24e9f78744f98ecf3ac01f1f719f1eac9b3479f0 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Tue, 18 Feb 2025 15:58:08 -0500
Subject: [PATCH] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related
 methods

- This type of entry is used to collect data about the debugger startup/exit
- Tests will be added (They may need to be shell test with a "test-only" 
TelemetryManager plugin defined. I'm trying to figure out how to get that 
linked only when tests are running and not to the LLDB binary all the time.
---
 lldb/include/lldb/Core/Telemetry.h |  78 +++
 lldb/source/Core/Debugger.cpp  |  40 ++
 lldb/source/Core/Telemetry.cpp | 115 +
 3 files changed, 220 insertions(+), 13 deletions(-)

diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index b72556ecaf3c9..d6eec5dc687be 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -13,6 +13,7 @@
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Utility/StructuredData.h"
 #include "lldb/lldb-forward.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/JSON.h"
@@ -29,6 +30,9 @@ namespace telemetry {
 
 struct LLDBEntryKind : public ::llvm::telemetry::EntryKind {
   static const llvm::telemetry::KindType BaseInfo = 0b11000;
+  static const llvm::telemetry::KindType DebuggerInfo = 0b11001;
+  // There are other entries in between (added in separate PRs)
+  static const llvm::telemetry::KindType MiscInfo = 0b0;
 };
 
 /// Defines a convenient type for timestamp of various events.
@@ -56,6 +60,71 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes the exit status of a debugger.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct DebuggerTelemetryInfo : public LLDBBaseTelemetryInfo {
+  std::string username;
+  std::string lldb_git_sha;
+  std::string lldb_path;
+  std::string cwd;
+  std::optional exit_desc;
+
+  DebuggerTelemetryInfo() = default;
+
+  // Provide a copy ctor because we may need to make a copy before
+  // sanitizing the data.
+  // (The sanitization might differ between different Destination classes).
+  DebuggerTelemetryInfo(const DebuggerTelemetryInfo &other) {
+username = other.username;
+lldb_git_sha = other.lldb_git_sha;
+lldb_path = other.lldb_path;
+cwd = other.cwd;
+  };
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::DebuggerInfo;
+  }
+
+  static bool classof(const llvm::telemetry::TelemetryInfo *T) {
+return T->getKind() == LLDBEntryKind::DebuggerInfo;
+  }
+
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
+/// The "catch-all" entry to store a set of non-standard data, such as
+/// error-messages, etc.
+struct MiscTelemetryInfo : public LLDBBaseTelemetryInfo {
+  /// If the event is/can be associated with a target entry,
+  /// this field contains that target's UUID.
+  ///  otherwise.
+  std::string target_uuid;
+
+  /// Set of key-value pairs for any optional (or impl-specific) data
+  std::map meta_data;
+
+  MiscTelemetryInfo() = default;
+
+  MiscTelemetryInfo(const MiscTelemetryInfo &other) {
+target_uuid = other.target_uuid;
+meta_data = other.meta_data;
+  }
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::MiscInfo;
+  }
+
+  static bool classof(const llvm::telemetry::TelemetryInfo *T) {
+return T->getKind() == LLDBEntryKind::MiscInfo;
+  }
+
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
 /// The base Telemetry manager instance in LLDB.
 /// This class declares additional instrumentation points
 /// applicable to LLDB.
@@ -63,6 +132,11 @@ class TelemetryManager : public llvm::telemetry::Manager {
 public:
   llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override;
 
+  const llvm::telemetry::Config *getConfig();
+
+  void atDebuggerStartup(DebuggerTelemetryInfo *entry);
+  void atDebuggerExit(DebuggerTelemetryInfo *entry);
+
   virtual llvm::StringRef GetInstanceName() const = 0;
   static TelemetryManager *getInstance();
 
@@ -73,6 +147,10 @@ class TelemetryManager : public llvm::telemetry::Manager {
 
 private:
   std::unique_ptr m_config;
+  // Each debugger is assigned a unique ID (session_id).
+  // All TelemetryInfo entries emitted for the same debugger instance
+  // will get the s

[Lldb-commits] [lldb] [lldb][Mach-O] Read dyld_all_image_infos addr from `main bin spec` LC_NOTE (PR #127156)

2025-02-18 Thread LLVM Continuous Integration via lldb-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-arm-ubuntu` running 
on `linaro-lldb-arm-ubuntu` while building `lldb` at step 6 "test".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/18/builds/11664


Here is the relevant piece of the build log for the reference

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: terminal/TestSTTYBeforeAndAfter.py (1128 of 2905)
PASS: lldb-api :: test_utils/TestDecorators.py (1129 of 2905)
PASS: lldb-api :: test_utils/TestInlineTest.py (1130 of 2905)
PASS: lldb-api :: test_utils/TestPExpectTest.py (1131 of 2905)
PASS: lldb-api :: test_utils/base/TestBaseTest.py (1132 of 2905)
PASS: lldb-api :: python_api/watchpoint/watchlocation/TestTargetWatchAddress.py 
(1133 of 2905)
PASS: lldb-api :: terminal/TestEditline.py (1134 of 2905)
UNSUPPORTED: lldb-api :: 
tools/lldb-dap/breakpoint-events/TestDAP_breakpointEvents.py (1135 of 2905)
PASS: lldb-api :: tools/lldb-dap/attach/TestDAP_attachByPortNum.py (1136 of 
2905)
PASS: lldb-api :: tools/lldb-dap/breakpoint/TestDAP_breakpointLocations.py 
(1137 of 2905)
FAIL: lldb-api :: tools/lldb-dap/attach/TestDAP_attach.py (1138 of 2905)
 TEST 'lldb-api :: tools/lldb-dap/attach/TestDAP_attach.py' 
FAILED 
Script:
--
/usr/bin/python3.10 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py 
-u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env 
LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env 
LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch 
armv8l --build-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb 
--compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang 
--dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil 
--make /usr/bin/gmake --llvm-tools-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --lldb-obj-root 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb --lldb-libs-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/attach
 -p TestDAP_attach.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 
1f5edb17b23f5ac0576f83a6c122ce38bd5ec18e)
  clang revision 1f5edb17b23f5ac0576f83a6c122ce38bd5ec18e
  llvm revision 1f5edb17b23f5ac0576f83a6c122ce38bd5ec18e
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 
'debugserver', 'objc']
= DEBUG ADAPTER PROTOCOL LOGS =
1739912216.176085234 --> 
Content-Length: 344

{
  "arguments": {
"adapterID": "lldb-native",
"clientID": "vscode",
"columnsStartAt1": true,
"linesStartAt1": true,
"locale": "en-us",
"pathFormat": "path",
"sourceInitFile": false,
"supportsRunInTerminalRequest": true,
"supportsStartDebuggingRequest": true,
"supportsVariablePaging": true,
"supportsVariableType": true
  },
  "command": "initialize",
  "seq": 1,
  "type": "request"
}
1739912216.180476904 <-- 
Content-Length: 1631


```



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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

2025-02-18 Thread Vy Nguyen via lldb-commits


@@ -73,6 +147,10 @@ class TelemetryManager : public llvm::telemetry::Manager {
 
 private:
   std::unique_ptr m_config;
+  // Each debugger is assigned a unique ID (session_id).
+  // All TelemetryInfo entries emitted for the same debugger instance
+  // will get the same session_id.
+  llvm::DenseMap session_ids;

oontvoo wrote:

This is a lazily-populated map. We are not associating the TelemetryManager 
with any Debugger. Rather, each TelemetryInfo entry may carry a pointer to a 
debugger. We compute some unique-ID for each debugger and put it in this map to 
re-use rather than having to re-compute everytime

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


[Lldb-commits] [lldb] [lldb] Store the return SBValueList in the CommandReturnObject (PR #127566)

2025-02-18 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Store the return ValueObject in the CommandReturnObject (PR #127566)

2025-02-18 Thread Jonas Devlieghere via lldb-commits

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

>From 6f59b1116dd83b9cce526103cca98a5d2056720f Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 17 Feb 2025 20:58:30 -0800
Subject: [PATCH 1/2] [lldb] Store the return ValueObject in the
 CommandReturnObject

There are a lot of lldb commands whose result is really a ValueObject
that we then print with the ValueObjectPrinter. Now that we have the
ability to access the SBCommandReturnObject through a callback
(#125006), we can store the resultant ValueObject in the return object,
allowing an IDE  to access the SBValue and do its own rich formatting.

rdar://143965453
---
 lldb/include/lldb/API/SBCommandReturnObject.h   |  2 ++
 lldb/include/lldb/API/SBValue.h |  1 +
 lldb/include/lldb/Interpreter/CommandReturnObject.h |  9 +
 lldb/source/API/SBCommandReturnObject.cpp   | 10 ++
 lldb/source/Commands/CommandObjectDWIMPrint.cpp |  3 +++
 lldb/source/Commands/CommandObjectExpression.cpp|  2 ++
 lldb/source/Commands/CommandObjectFrame.cpp |  1 +
 .../TestSBCommandReturnObject.py| 13 +
 8 files changed, 41 insertions(+)

diff --git a/lldb/include/lldb/API/SBCommandReturnObject.h 
b/lldb/include/lldb/API/SBCommandReturnObject.h
index 9a63c1f96aa70..96dda239d3c97 100644
--- a/lldb/include/lldb/API/SBCommandReturnObject.h
+++ b/lldb/include/lldb/API/SBCommandReturnObject.h
@@ -136,6 +136,8 @@ class LLDB_API SBCommandReturnObject {
 
   void SetError(const char *error_cstr);
 
+  lldb::SBValue GetReturnValue(lldb::DynamicValueType use_dynamic);
+
 protected:
   friend class SBCommandInterpreter;
   friend class SBOptions;
diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h
index 46ef6daa95264..75d20a4378f09 100644
--- a/lldb/include/lldb/API/SBValue.h
+++ b/lldb/include/lldb/API/SBValue.h
@@ -442,6 +442,7 @@ class LLDB_API SBValue {
 
 protected:
   friend class SBBlock;
+  friend class SBCommandReturnObject;
   friend class SBFrame;
   friend class SBModule;
   friend class SBTarget;
diff --git a/lldb/include/lldb/Interpreter/CommandReturnObject.h 
b/lldb/include/lldb/Interpreter/CommandReturnObject.h
index 803bcd76995ed..1a6cc5c6de060 100644
--- a/lldb/include/lldb/Interpreter/CommandReturnObject.h
+++ b/lldb/include/lldb/Interpreter/CommandReturnObject.h
@@ -165,6 +165,12 @@ class CommandReturnObject {
 return m_diagnostic_indent;
   }
 
+  lldb::ValueObjectSP GetValueObjectSP() const { return m_value_object_sp; }
+
+  void SetValueObjectSP(lldb::ValueObjectSP value_object_sp) {
+m_value_object_sp = value_object_sp;
+  }
+
   lldb::ReturnStatus GetStatus() const;
 
   void SetStatus(lldb::ReturnStatus status);
@@ -197,6 +203,9 @@ class CommandReturnObject {
 
   lldb::ReturnStatus m_status = lldb::eReturnStatusStarted;
 
+  /// An optional return ValueObjectSP.
+  lldb::ValueObjectSP m_value_object_sp;
+
   bool m_did_change_process_state = false;
   bool m_suppress_immediate_output = false;
 
diff --git a/lldb/source/API/SBCommandReturnObject.cpp 
b/lldb/source/API/SBCommandReturnObject.cpp
index 6f54581e64ef4..085bfac57c0a8 100644
--- a/lldb/source/API/SBCommandReturnObject.cpp
+++ b/lldb/source/API/SBCommandReturnObject.cpp
@@ -12,6 +12,7 @@
 #include "lldb/API/SBFile.h"
 #include "lldb/API/SBStream.h"
 #include "lldb/API/SBStructuredData.h"
+#include "lldb/API/SBValue.h"
 #include "lldb/Core/StructuredDataImpl.h"
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Utility/ConstString.h"
@@ -356,3 +357,12 @@ void SBCommandReturnObject::SetError(const char 
*error_cstr) {
   if (error_cstr)
 ref().AppendError(error_cstr);
 }
+
+SBValue
+SBCommandReturnObject::GetReturnValue(lldb::DynamicValueType use_dynamic) {
+  LLDB_INSTRUMENT_VA(this, use_dynamic);
+
+  SBValue sb_value;
+  sb_value.SetSP(ref().GetValueObjectSP(), use_dynamic);
+  return sb_value;
+}
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index d4d038d28f675..aab99441c63a3 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -205,6 +205,9 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
 ExpressionResults expr_result = target.EvaluateExpression(
 expr, exe_scope, valobj_sp, eval_options, &fixed_expression);
 
+if (valobj_sp)
+  result.SetValueObjectSP(valobj_sp);
+
 // Record the position of the expression in the command.
 std::optional indent;
 if (fixed_expression.empty()) {
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp 
b/lldb/source/Commands/CommandObjectExpression.cpp
index 7e26381c92405..b0c92d9391b13 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -434,6 +434,8 @@ bool 
CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
   

[Lldb-commits] [lldb] [lldb] Store the return SBValueList in the CommandReturnObject (PR #127566)

2025-02-18 Thread Jonas Devlieghere via lldb-commits


@@ -22,8 +22,6 @@ class ValueObject;
 /// A collection of ValueObject values that.
 class ValueObjectList {
 public:
-  const ValueObjectList &operator=(const ValueObjectList &rhs);

JDevlieghere wrote:

Essentially a no-op, but necessary to silence:
```
warning: definition of implicit copy constructor for 'ValueObjectList' is 
deprecated because it has a user-provided copy assignment operator 
[-Wdeprecated-copy-with-user-provided-copy]
```

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


[Lldb-commits] [lldb] [LLDB-DAP] SBDebugger don't prefix title on progress updates (PR #124648)

2025-02-18 Thread Jacob Lalonde via lldb-commits

https://github.com/Jlalond updated 
https://github.com/llvm/llvm-project/pull/124648

>From 12ff645735c1dbf51e58b9f80d4e3e13a0babdf5 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Mon, 27 Jan 2025 13:41:58 -0800
Subject: [PATCH 1/4] Only include title on the first message

---
 lldb/include/lldb/Core/DebuggerEvents.h | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lldb/include/lldb/Core/DebuggerEvents.h 
b/lldb/include/lldb/Core/DebuggerEvents.h
index 49a4ecf8e537e..52e4f77d7637d 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -44,12 +44,15 @@ class ProgressEventData : public EventData {
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
-std::string message = m_title;
-if (!m_details.empty()) {
-  message.append(": ");
-  message.append(m_details);
-}
-return message;
+if (m_completed == 0) {
+  std::string message = m_title;
+  if (!m_details.empty()) {
+message.append(": ");
+message.append(m_details);
+  }
+  return message;
+} else
+  return !m_details.empty() ? m_details : std::string();
   }
   const std::string &GetTitle() const { return m_title; }
   const std::string &GetDetails() const { return m_details; }

>From 82ed76ae3b6bef176bf54dd1031f0cb9c95081c1 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Mon, 27 Jan 2025 14:48:01 -0800
Subject: [PATCH 2/4] Add comment explaining if and add a test

---
 lldb/include/lldb/Core/DebuggerEvents.h   | 1 +
 lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py | 5 +
 2 files changed, 6 insertions(+)

diff --git a/lldb/include/lldb/Core/DebuggerEvents.h 
b/lldb/include/lldb/Core/DebuggerEvents.h
index 52e4f77d7637d..ca06ee835fde3 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -44,6 +44,7 @@ class ProgressEventData : public EventData {
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
+// Only put the title in the message of the progress create event.
 if (m_completed == 0) {
   std::string message = m_title;
   if (!m_details.empty()) {
diff --git a/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py 
b/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py
index 36c0cef9c4714..945c3f7633364 100755
--- a/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py
+++ b/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py
@@ -41,8 +41,13 @@ def test_output(self):
 for event in self.dap_server.progress_events:
 event_type = event["event"]
 if "progressStart" in event_type:
+title = event["body"]["title"]
+self.assertIn("Progress tester", title)
 start_found = True
 if "progressUpdate" in event_type:
+message = event["body"]["message"]
+print(f"Progress update: {message}")
+self.assertNotIn("Progres tester", message)
 update_found = True
 
 self.assertTrue(start_found)

>From e15090782a93e07e8a260a0594ca02430e68e09f Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Thu, 30 Jan 2025 10:04:04 -0800
Subject: [PATCH 3/4] Migrate to structured data

Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:


Differential Revision: https://phabricator.intern.facebook.com/D68927453
---
 lldb/include/lldb/Core/DebuggerEvents.h | 16 +++-
 lldb/tools/lldb-dap/lldb-dap.cpp| 54 +
 2 files changed, 52 insertions(+), 18 deletions(-)

diff --git a/lldb/include/lldb/Core/DebuggerEvents.h 
b/lldb/include/lldb/Core/DebuggerEvents.h
index ca06ee835fde3..49a4ecf8e537e 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -44,16 +44,12 @@ class ProgressEventData : public EventData {
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
-// Only put the title in the message of the progress create event.
-if (m_completed == 0) {
-  std::string message = m_title;
-  if (!m_details.empty()) {
-message.append(": ");
-message.append(m_details);
-  }
-  return message;
-} else
-  return !m_details.empty() ? m_details : std::string();
+std::string message = m_title;
+if (!m_details.empty()) {
+  message.append(": ");
+  message.append(m_details);
+}
+return message;
   }
   const std::string &GetTitle() const { return m_title; }
   const std::string &GetDetails() const { return m_details; }
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index e323990d8b6ed..4b3460190a7c9 100644
--- a/lldb/tools/lldb

[Lldb-commits] [lldb] [LLDB-DAP] SBDebugger don't prefix title on progress updates (PR #124648)

2025-02-18 Thread Jacob Lalonde via lldb-commits

Jlalond wrote:

@JDevlieghere Cleaned up as you suggested, sorry about the initial rough state 
but I mostly wanted a sanity check if I was overlooking anything.

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


[Lldb-commits] [lldb] [LLDB-DAP] SBDebugger don't prefix title on progress updates (PR #124648)

2025-02-18 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 5ecce45ea2980aff35d1283d4dd3feb8f74de16c 
19a03d8c40103298f0cb51af173f7be086eefd62 --extensions cpp -- 
lldb/tools/lldb-dap/lldb-dap.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 9635a683d2..2f72518160 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -452,10 +452,12 @@ void ProgressEventThreadFunction(DAP &dap) {
 lldb::SBStructuredData data =
 lldb::SBDebugger::GetProgressDataFromEvent(event);
 
-const uint64_t progress_id = GetUintFromStructuredData(data, 
"progress_id");
+const uint64_t progress_id =
+GetUintFromStructuredData(data, "progress_id");
 const uint64_t completed = GetUintFromStructuredData(data, 
"completed");
 const uint64_t total = GetUintFromStructuredData(data, "total");
-const std::string details = GetStringFromStructuredData(data, 
"details");
+const std::string details =
+GetStringFromStructuredData(data, "details");
 std::string message;
 // Include the title on the first event.
 if (completed == 0) {
@@ -464,7 +466,6 @@ void ProgressEventThreadFunction(DAP &dap) {
   message += ": ";
 }
 
-
 message += details;
 // Verbose check, but we get -1 for the uint64 on failure to read
 // so we check everything before broadcasting an event.

``




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


[Lldb-commits] [lldb] Allow option to ignore module load errors in ScriptedProcess (PR #127153)

2025-02-18 Thread via lldb-commits

rchamala wrote:

In my case, for non-scripted process of coredump, I see the module information 
even when symbol is not found and I see a placeholder object being created for 
the module. For scripted process, it shows only the main module due to the 
limitation I pointed in this PR

Target 1 is child elf-core process target. Target 2 is scripted process target

1. **Current State (without my change)**

Target list
```
Current targets:
  target #0:  ( platform=host )
  target #1: [vdso] ( arch=aarch64-*-linux, platform=remote-android, pid=1234, 
state=stopped )
* target #2: /path/to/coredump ( arch=aarch64-*-*, platform=remote-android, 
pid=3456, state=stopped )
```

2. Sample Image List of child elf-core target. Note the `*` at the end, which 
indicates placeholder object
```
[0]  0x1234455 [vdso]   /path/to/a.out
[1] 0x1234566  /path/to/libc.so(*)
[2] ...
```

3. Sample Image list of scripted process target. Only one module is shown

```
[0]  0x1234445 [vdso]   /path/to/a.out
```

**With my PR to ignore load module errors:**

1. Sample image list of scripted process target. All modules are shown, for the 
ones whose symbols are not found, place holder objects are created similar to 
non-scripted process targets


```
[0]  0x1234455 [vdso]   /path/to/a.out
[1]  0x1234566  /path/to/libc.so(*)
[2]  0x1245666 /path/to/libb.so
[3]  ...
```





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


[Lldb-commits] [lldb] [LLDB-DAP] SBDebugger don't prefix title on progress updates (PR #124648)

2025-02-18 Thread Jacob Lalonde via lldb-commits

https://github.com/Jlalond updated 
https://github.com/llvm/llvm-project/pull/124648

>From 12ff645735c1dbf51e58b9f80d4e3e13a0babdf5 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Mon, 27 Jan 2025 13:41:58 -0800
Subject: [PATCH 1/4] Only include title on the first message

---
 lldb/include/lldb/Core/DebuggerEvents.h | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lldb/include/lldb/Core/DebuggerEvents.h 
b/lldb/include/lldb/Core/DebuggerEvents.h
index 49a4ecf8e537e..52e4f77d7637d 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -44,12 +44,15 @@ class ProgressEventData : public EventData {
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
-std::string message = m_title;
-if (!m_details.empty()) {
-  message.append(": ");
-  message.append(m_details);
-}
-return message;
+if (m_completed == 0) {
+  std::string message = m_title;
+  if (!m_details.empty()) {
+message.append(": ");
+message.append(m_details);
+  }
+  return message;
+} else
+  return !m_details.empty() ? m_details : std::string();
   }
   const std::string &GetTitle() const { return m_title; }
   const std::string &GetDetails() const { return m_details; }

>From 82ed76ae3b6bef176bf54dd1031f0cb9c95081c1 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Mon, 27 Jan 2025 14:48:01 -0800
Subject: [PATCH 2/4] Add comment explaining if and add a test

---
 lldb/include/lldb/Core/DebuggerEvents.h   | 1 +
 lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py | 5 +
 2 files changed, 6 insertions(+)

diff --git a/lldb/include/lldb/Core/DebuggerEvents.h 
b/lldb/include/lldb/Core/DebuggerEvents.h
index 52e4f77d7637d..ca06ee835fde3 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -44,6 +44,7 @@ class ProgressEventData : public EventData {
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
+// Only put the title in the message of the progress create event.
 if (m_completed == 0) {
   std::string message = m_title;
   if (!m_details.empty()) {
diff --git a/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py 
b/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py
index 36c0cef9c4714..945c3f7633364 100755
--- a/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py
+++ b/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py
@@ -41,8 +41,13 @@ def test_output(self):
 for event in self.dap_server.progress_events:
 event_type = event["event"]
 if "progressStart" in event_type:
+title = event["body"]["title"]
+self.assertIn("Progress tester", title)
 start_found = True
 if "progressUpdate" in event_type:
+message = event["body"]["message"]
+print(f"Progress update: {message}")
+self.assertNotIn("Progres tester", message)
 update_found = True
 
 self.assertTrue(start_found)

>From e15090782a93e07e8a260a0594ca02430e68e09f Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Thu, 30 Jan 2025 10:04:04 -0800
Subject: [PATCH 3/4] Migrate to structured data

Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:


Differential Revision: https://phabricator.intern.facebook.com/D68927453
---
 lldb/include/lldb/Core/DebuggerEvents.h | 16 +++-
 lldb/tools/lldb-dap/lldb-dap.cpp| 54 +
 2 files changed, 52 insertions(+), 18 deletions(-)

diff --git a/lldb/include/lldb/Core/DebuggerEvents.h 
b/lldb/include/lldb/Core/DebuggerEvents.h
index ca06ee835fde3..49a4ecf8e537e 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -44,16 +44,12 @@ class ProgressEventData : public EventData {
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
-// Only put the title in the message of the progress create event.
-if (m_completed == 0) {
-  std::string message = m_title;
-  if (!m_details.empty()) {
-message.append(": ");
-message.append(m_details);
-  }
-  return message;
-} else
-  return !m_details.empty() ? m_details : std::string();
+std::string message = m_title;
+if (!m_details.empty()) {
+  message.append(": ");
+  message.append(m_details);
+}
+return message;
   }
   const std::string &GetTitle() const { return m_title; }
   const std::string &GetDetails() const { return m_details; }
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index e323990d8b6ed..4b3460190a7c9 100644
--- a/lldb/tools/lldb

[Lldb-commits] [lldb] [lldb] Fix RangeDataVector::CombineConsecutiveEntriesWithEqualData (PR #127059)

2025-02-18 Thread Jacob Lalonde via lldb-commits


@@ -493,36 +493,27 @@ class RangeDataVector {
 #ifdef ASSERT_RANGEMAP_ARE_SORTED
 assert(IsSorted());
 #endif
-typename Collection::iterator pos;
-typename Collection::iterator end;
-typename Collection::iterator prev;
-bool can_combine = false;
-// First we determine if we can combine any of the Entry objects so we
-// don't end up allocating and making a new collection for no reason
-for (pos = m_entries.begin(), end = m_entries.end(), prev = end; pos != 
end;
- prev = pos++) {
-  if (prev != end && prev->data == pos->data) {
-can_combine = true;
-break;
-  }
-}
+auto first_intersect = std::adjacent_find(
+m_entries.begin(), m_entries.end(), [](const Entry &a, const Entry &b) 
{
+  return a.DoesAdjoinOrIntersect(b) && a.data == b.data;
+});
+if (first_intersect == m_entries.end())
+  return;
 
-// We can combine at least one entry, then we make a new collection and
-// populate it accordingly, and then swap it into place.
-if (can_combine) {
-  Collection minimal_ranges;
-  for (pos = m_entries.begin(), end = m_entries.end(), prev = end;
-   pos != end; prev = pos++) {
-if (prev != end && prev->data == pos->data)
-  minimal_ranges.back().SetRangeEnd(pos->GetRangeEnd());
-else
-  minimal_ranges.push_back(*pos);
-  }
-  // Use the swap technique in case our new vector is much smaller. We must
-  // swap when using the STL because std::vector objects never release or
-  // reduce the memory once it has been allocated/reserved.
-  m_entries.swap(minimal_ranges);
+// We can combine at least one entry. Make a new collection and populate it
+// accordingly, and then swap it into place.
+auto pos = std::next(first_intersect);
+Collection minimal_ranges(m_entries.begin(), pos);
+for (; pos != m_entries.end(); ++pos) {
+  Entry &back = minimal_ranges.back();
+  if (back.DoesAdjoinOrIntersect(*pos) && back.data == pos->data)
+back.SetRangeEnd(std::max(back.GetRangeEnd(), pos->GetRangeEnd()));
+  else
+minimal_ranges.push_back(*pos);
 }
+m_entries.swap(minimal_ranges);
+if (!m_entries.empty())

Jlalond wrote:

Is it possible for this to be empty? We would have at least one entry to pass 
the intersection check, and I don't see how we would empty the collection via 
merging ranges

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


[Lldb-commits] [lldb] [lldb] Fix RangeDataVector::CombineConsecutiveEntriesWithEqualData (PR #127059)

2025-02-18 Thread Jacob Lalonde via lldb-commits


@@ -493,36 +493,27 @@ class RangeDataVector {
 #ifdef ASSERT_RANGEMAP_ARE_SORTED
 assert(IsSorted());
 #endif
-typename Collection::iterator pos;
-typename Collection::iterator end;
-typename Collection::iterator prev;
-bool can_combine = false;
-// First we determine if we can combine any of the Entry objects so we
-// don't end up allocating and making a new collection for no reason
-for (pos = m_entries.begin(), end = m_entries.end(), prev = end; pos != 
end;
- prev = pos++) {
-  if (prev != end && prev->data == pos->data) {
-can_combine = true;
-break;
-  }
-}
+auto first_intersect = std::adjacent_find(
+m_entries.begin(), m_entries.end(), [](const Entry &a, const Entry &b) 
{
+  return a.DoesAdjoinOrIntersect(b) && a.data == b.data;

Jlalond wrote:

Is the equal check cheaper than the Intersect or Adjacency check? If so we 
should short circuit on equality before checking for an intersection

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


[Lldb-commits] [lldb] [lldb] Fix RangeDataVector::CombineConsecutiveEntriesWithEqualData (PR #127059)

2025-02-18 Thread Jacob Lalonde via lldb-commits


@@ -493,36 +493,27 @@ class RangeDataVector {
 #ifdef ASSERT_RANGEMAP_ARE_SORTED
 assert(IsSorted());
 #endif
-typename Collection::iterator pos;
-typename Collection::iterator end;
-typename Collection::iterator prev;
-bool can_combine = false;
-// First we determine if we can combine any of the Entry objects so we
-// don't end up allocating and making a new collection for no reason
-for (pos = m_entries.begin(), end = m_entries.end(), prev = end; pos != 
end;
- prev = pos++) {
-  if (prev != end && prev->data == pos->data) {
-can_combine = true;
-break;
-  }
-}
+auto first_intersect = std::adjacent_find(
+m_entries.begin(), m_entries.end(), [](const Entry &a, const Entry &b) 
{
+  return a.DoesAdjoinOrIntersect(b) && a.data == b.data;
+});

Jlalond wrote:

nit: an empty line before the if is in my opinion nicer to read

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


[Lldb-commits] [lldb] Allow option to ignore module load errors in ScriptedProcess (PR #127153)

2025-02-18 Thread via lldb-commits

jimingham wrote:

It's never the case on Darwin that you know nothing about a loaded shared 
library.  You will always know at least its name, UUID, and load addresses.  It 
doesn't matter whether the binary exists on disk or not, we will always be able 
to reconstruct at least a skeleton form from the loader's information.

So thinking just about Darwin, I'd opine that you should never totally omit 
information about a loaded library.  If the loader tells you about it, you 
should at least make its presence available even if you can't reconstruct much 
information from it.

The ELF behavior surprises me, I would have definitely though it was a bug that 
the absence of the library on disk would cause the library to totally disappear 
from a debug session that was clearly using it.  That seems to me like 
information we really should try to surface the user.

I really haven't played around with ELF much so I'm not up on how lossy it can 
be.  In the case where you've deleted the library on disk is there really 
NOTHING that lldb can tell you about that loaded library?

Jim
 


> On Feb 18, 2025, at 12:15 AM, Pavel Labath ***@***.***> wrote:
> 
> 
> labath
>  left a comment 
> (llvm/llvm-project#127153)
> I'm not convinced of that this change needs to be happen in ScriptedProcess 
> ... May be we could have a setting to not discard all modules loaded in case 
> 1 of them failed to load that would also work with other Process plugins. 
> @jimingham what do you think ?
> 
> I'm confused. Isn't that already what happens for non-scripted processes?
> 
> $ lldb -n a.out -o "image list" -b
> (lldb) process attach --name "a.out"
> Process 11191 stopped
> * thread #1, name = 'a.out', stop reason = signal SIGSTOP
> frame #0: 0x7f7083e088e4 libc.so.6`pause + 20
> libc.so.6`pause:
> ->  0x7f7083e088e4 <+20>: cmpq   $-0x1000, %rax ; imm = 0xF000 
> 0x7f7083e088ea <+26>: ja 0x7f7083e08920 ; <+80>
> 0x7f7083e088ec <+28>: retq   
> 0x7f7083e088ed <+29>: nopl   (%rax)
> Executable module set to "/tmp/X/a.out".
> Architecture set to: x86_64-pc-linux-gnu.
> (lldb) image list
> [  0] 171A52C4 0x56532dec /tmp/X/a.out 
> [  1] 421DCFD2-138A-B321-D6F1-7AFD7B7FC999-F79CA445 0x7ffdeb3a5000 [vdso] 
> (0x7ffdeb3a5000)
> [  2] 838926F7 0x7f7083f45000 libb.so  <== LIBB.SO HERE
> [  3] C88DE6C8 0x7f7083d1f000 /lib64/libc.so.6 
>   /usr/lib/debug/lib64/libc.so.6.debug
> [  4] D626A570 0x7f7083f4c000 /lib64/ld-linux-x86-64.so.2 
> $ rm libb.so <= FILE DELETED
> $ lldb -n a.out -o "image list" -b
> (lldb) process attach --name "a.out"
> Process 11191 stopped
> * thread #1, name = 'a.out', stop reason = signal SIGSTOP
> frame #0: 0x7f7083e088e4 libc.so.6`pause + 20
> libc.so.6`pause:
> ->  0x7f7083e088e4 <+20>: cmpq   $-0x1000, %rax ; imm = 0xF000 
> 0x7f7083e088ea <+26>: ja 0x7f7083e08920 ; <+80>
> 0x7f7083e088ec <+28>: retq   
> 0x7f7083e088ed <+29>: nopl   (%rax)
> Executable module set to "/tmp/X/a.out".
> Architecture set to: x86_64-pc-linux-gnu.
> (lldb) image list<= LIBB.SO MISSING (BUT OTHER MODULES STILL THERE)
> [  0] 171A52C4 0x56532dec /tmp/X/a.out 
> [  1] 421DCFD2-138A-B321-D6F1-7AFD7B7FC999-F79CA445 0x7ffdeb3a5000 [vdso] 
> (0x7ffdeb3a5000)
> [  2] C88DE6C8 0x7f7083d1f000 /lib64/libc.so.6 
>   /usr/lib/debug/lib64/libc.so.6.debug
> [  3] D626A570 0x7f7083f4c000 /lib64/ld-linux-x86-64.so.2 
> I got this on linux. On darwin, the module might still be present because it 
> might be read from process memory directly. Still, if that failed for some 
> reason (perhaps because instead of a live process we were dealing with a core 
> file -- one which does not include the module contents in the dump), I would 
> expect other modules to be present.
> 
> Rejecting all of them because one couldn't be found seems to go against our 
> "do our best to keep going with limited info" philosophy.
> 
> —
> Reply to this email directly, view it on GitHub, or unsubscribe.
> You are receiving this because you were mentioned.
> 
>   
>  
> 
> 
> labath
>  left a comment 
> (llvm/llvm-project#127153)
>  
> I'm not convinced of that this change needs to be happen in ScriptedProcess 
> ... May be we could have a setting to not discard all modules loaded in case 
> 1 of them failed to load that would also work with other Process plugins. 
> @jimingham  what do you think ?
> 
> I'm confused. Isn't that already what happens for non-scripted processes?
> 
> $ lldb -n a.out -o "image list" -b
> (lldb) process attach --name "a.out"
> Process 11191 stopped
> * 

[Lldb-commits] [lldb] [lldb] Make GetOutputStreamSP and GetErrorStreamSP protected (PR #127682)

2025-02-18 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

More context/background in #126630. 

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


[Lldb-commits] [lldb] [lldb] Make GetOutputStreamSP and GetErrorStreamSP protected (PR #127682)

2025-02-18 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

This makes GetOutputStreamSP and GetErrorStreamSP protected members of 
Debugger. Users who want to print to the debugger's stream should use 
GetAsyncOutputStreamSP and GetAsyncErrorStreamSP instead and the few remaining 
stragglers have been migrated.

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


13 Files Affected:

- (modified) lldb/include/lldb/Core/Debugger.h (+12-8) 
- (modified) lldb/include/lldb/Target/ThreadPlanTracer.h (+1-1) 
- (modified) lldb/source/API/SBDebugger.cpp (+6-6) 
- (modified) lldb/source/Commands/CommandObjectGUI.cpp (+4-4) 
- (modified) lldb/source/Commands/CommandObjectLog.cpp (+2-1) 
- (modified) lldb/source/Core/Debugger.cpp (+4-4) 
- (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+2-2) 
- (modified) lldb/source/Interpreter/ScriptInterpreter.cpp (+2-2) 
- (modified) 
lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp 
(+5-4) 
- (modified) 
lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
 (-2) 
- (modified) 
lldb/source/Plugins/InstrumentationRuntime/Utility/ReportRetriever.cpp (+2-2) 
- (modified) lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp 
(+2-2) 
- (modified) lldb/source/Target/ThreadPlanTracer.cpp (+20-19) 


``diff
diff --git a/lldb/include/lldb/Core/Debugger.h 
b/lldb/include/lldb/Core/Debugger.h
index d7751ca045bb2..7f08f3dd26106 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -131,17 +131,13 @@ class Debugger : public 
std::enable_shared_from_this,
 
   void SetAsyncExecution(bool async);
 
-  lldb::FileSP GetInputFileSP() { return m_input_file_sp; }
-
-  lldb::StreamFileSP GetOutputStreamSP() { return m_output_stream_sp; }
-
-  lldb::StreamFileSP GetErrorStreamSP() { return m_error_stream_sp; }
-
   File &GetInputFile() { return *m_input_file_sp; }
 
-  File &GetOutputFile() { return m_output_stream_sp->GetFile(); }
+  lldb::FileSP GetInputFileSP() { return m_input_file_sp; }
+
+  lldb::FileSP GetOutputFileSP() { return m_output_stream_sp->GetFileSP(); }
 
-  File &GetErrorFile() { return m_error_stream_sp->GetFile(); }
+  lldb::FileSP GetErrorFileSP() { return m_error_stream_sp->GetFileSP(); }
 
   repro::DataRecorder *GetInputRecorder();
 
@@ -649,6 +645,14 @@ class Debugger : public 
std::enable_shared_from_this,
 
   void PrintProgress(const ProgressEventData &data);
 
+  /// Except for Debugger and IOHandler, GetOutputStreamSP and GetErrorStreamSP
+  /// should not be used directly. Use GetAsyncOutputStream and
+  /// GetAsyncErrorStream instead.
+  /// @{
+  lldb::StreamFileSP GetOutputStreamSP() { return m_output_stream_sp; }
+  lldb::StreamFileSP GetErrorStreamSP() { return m_error_stream_sp; }
+  /// @}
+
   void PushIOHandler(const lldb::IOHandlerSP &reader_sp,
  bool cancel_top_handler = true);
 
diff --git a/lldb/include/lldb/Target/ThreadPlanTracer.h 
b/lldb/include/lldb/Target/ThreadPlanTracer.h
index a6fd2f031dc22..7c45e213f94f1 100644
--- a/lldb/include/lldb/Target/ThreadPlanTracer.h
+++ b/lldb/include/lldb/Target/ThreadPlanTracer.h
@@ -56,7 +56,7 @@ class ThreadPlanTracer {
   Process &m_process;
   lldb::tid_t m_tid;
 
-  Stream *GetLogStream();
+  lldb::StreamSP GetLogStreamSP();
 
   virtual void Log();
 
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index bf19d2ff8333c..e646b09e05852 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -509,14 +509,14 @@ SBFile SBDebugger::GetInputFile() {
 FILE *SBDebugger::GetOutputFileHandle() {
   LLDB_INSTRUMENT_VA(this);
   if (m_opaque_sp)
-return m_opaque_sp->GetOutputStreamSP()->GetFile().GetStream();
+return m_opaque_sp->GetOutputFileSP()->GetStream();
   return nullptr;
 }
 
 SBFile SBDebugger::GetOutputFile() {
   LLDB_INSTRUMENT_VA(this);
   if (m_opaque_sp)
-return SBFile(m_opaque_sp->GetOutputStreamSP()->GetFileSP());
+return SBFile(m_opaque_sp->GetOutputFileSP());
   return SBFile();
 }
 
@@ -524,7 +524,7 @@ FILE *SBDebugger::GetErrorFileHandle() {
   LLDB_INSTRUMENT_VA(this);
 
   if (m_opaque_sp)
-return m_opaque_sp->GetErrorStreamSP()->GetFile().GetStream();
+return m_opaque_sp->GetErrorFileSP()->GetStream();
   return nullptr;
 }
 
@@ -532,7 +532,7 @@ SBFile SBDebugger::GetErrorFile() {
   LLDB_INSTRUMENT_VA(this);
   SBFile file;
   if (m_opaque_sp)
-return SBFile(m_opaque_sp->GetErrorStreamSP()->GetFileSP());
+return SBFile(m_opaque_sp->GetErrorFileSP());
   return SBFile();
 }
 
@@ -573,8 +573,8 @@ void SBDebugger::HandleCommand(const char *command) {
 
 sb_interpreter.HandleCommand(command, result, false);
 
-result.PutError(m_opaque_sp->GetErrorStreamSP()->GetFileSP());
-result.PutOutput(m_opaque_sp->GetOutputStreamSP()->GetFileSP());
+result.PutError(m_opaque_sp->GetErrorFileSP());
+result.Put

[Lldb-commits] [lldb] [lldb] Make GetOutputStreamSP and GetErrorStreamSP protected (PR #127682)

2025-02-18 Thread Jonas Devlieghere via lldb-commits

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

This makes GetOutputStreamSP and GetErrorStreamSP protected members of 
Debugger. Users who want to print to the debugger's stream should use 
GetAsyncOutputStreamSP and GetAsyncErrorStreamSP instead and the few remaining 
stragglers have been migrated.

>From 02b0a9e9a69e138aac87ed693c4e97c58e20acfc Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 18 Feb 2025 10:34:05 -0800
Subject: [PATCH] [lldb] Make GetOutputStreamSP and GetErrorStreamSP protected

This makes GetOutputStreamSP and GetErrorStreamSP protected members of
Debugger. Users who want to print to the debugger's stream should use
GetAsyncOutputStreamSP and GetAsyncErrorStreamSP instead and the few
remaining stragglers have been migrated.
---
 lldb/include/lldb/Core/Debugger.h | 20 ++
 lldb/include/lldb/Target/ThreadPlanTracer.h   |  2 +-
 lldb/source/API/SBDebugger.cpp| 12 +++---
 lldb/source/Commands/CommandObjectGUI.cpp |  8 ++--
 lldb/source/Commands/CommandObjectLog.cpp |  3 +-
 lldb/source/Core/Debugger.cpp |  8 ++--
 .../source/Interpreter/CommandInterpreter.cpp |  4 +-
 lldb/source/Interpreter/ScriptInterpreter.cpp |  4 +-
 .../DynamicLoaderDarwinKernel.cpp |  9 +++--
 .../UBSan/InstrumentationRuntimeUBSan.cpp |  2 -
 .../Utility/ReportRetriever.cpp   |  4 +-
 .../Lua/ScriptInterpreterLua.cpp  |  4 +-
 lldb/source/Target/ThreadPlanTracer.cpp   | 39 ++-
 13 files changed, 62 insertions(+), 57 deletions(-)

diff --git a/lldb/include/lldb/Core/Debugger.h 
b/lldb/include/lldb/Core/Debugger.h
index d7751ca045bb2..7f08f3dd26106 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -131,17 +131,13 @@ class Debugger : public 
std::enable_shared_from_this,
 
   void SetAsyncExecution(bool async);
 
-  lldb::FileSP GetInputFileSP() { return m_input_file_sp; }
-
-  lldb::StreamFileSP GetOutputStreamSP() { return m_output_stream_sp; }
-
-  lldb::StreamFileSP GetErrorStreamSP() { return m_error_stream_sp; }
-
   File &GetInputFile() { return *m_input_file_sp; }
 
-  File &GetOutputFile() { return m_output_stream_sp->GetFile(); }
+  lldb::FileSP GetInputFileSP() { return m_input_file_sp; }
+
+  lldb::FileSP GetOutputFileSP() { return m_output_stream_sp->GetFileSP(); }
 
-  File &GetErrorFile() { return m_error_stream_sp->GetFile(); }
+  lldb::FileSP GetErrorFileSP() { return m_error_stream_sp->GetFileSP(); }
 
   repro::DataRecorder *GetInputRecorder();
 
@@ -649,6 +645,14 @@ class Debugger : public 
std::enable_shared_from_this,
 
   void PrintProgress(const ProgressEventData &data);
 
+  /// Except for Debugger and IOHandler, GetOutputStreamSP and GetErrorStreamSP
+  /// should not be used directly. Use GetAsyncOutputStream and
+  /// GetAsyncErrorStream instead.
+  /// @{
+  lldb::StreamFileSP GetOutputStreamSP() { return m_output_stream_sp; }
+  lldb::StreamFileSP GetErrorStreamSP() { return m_error_stream_sp; }
+  /// @}
+
   void PushIOHandler(const lldb::IOHandlerSP &reader_sp,
  bool cancel_top_handler = true);
 
diff --git a/lldb/include/lldb/Target/ThreadPlanTracer.h 
b/lldb/include/lldb/Target/ThreadPlanTracer.h
index a6fd2f031dc22..7c45e213f94f1 100644
--- a/lldb/include/lldb/Target/ThreadPlanTracer.h
+++ b/lldb/include/lldb/Target/ThreadPlanTracer.h
@@ -56,7 +56,7 @@ class ThreadPlanTracer {
   Process &m_process;
   lldb::tid_t m_tid;
 
-  Stream *GetLogStream();
+  lldb::StreamSP GetLogStreamSP();
 
   virtual void Log();
 
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index bf19d2ff8333c..e646b09e05852 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -509,14 +509,14 @@ SBFile SBDebugger::GetInputFile() {
 FILE *SBDebugger::GetOutputFileHandle() {
   LLDB_INSTRUMENT_VA(this);
   if (m_opaque_sp)
-return m_opaque_sp->GetOutputStreamSP()->GetFile().GetStream();
+return m_opaque_sp->GetOutputFileSP()->GetStream();
   return nullptr;
 }
 
 SBFile SBDebugger::GetOutputFile() {
   LLDB_INSTRUMENT_VA(this);
   if (m_opaque_sp)
-return SBFile(m_opaque_sp->GetOutputStreamSP()->GetFileSP());
+return SBFile(m_opaque_sp->GetOutputFileSP());
   return SBFile();
 }
 
@@ -524,7 +524,7 @@ FILE *SBDebugger::GetErrorFileHandle() {
   LLDB_INSTRUMENT_VA(this);
 
   if (m_opaque_sp)
-return m_opaque_sp->GetErrorStreamSP()->GetFile().GetStream();
+return m_opaque_sp->GetErrorFileSP()->GetStream();
   return nullptr;
 }
 
@@ -532,7 +532,7 @@ SBFile SBDebugger::GetErrorFile() {
   LLDB_INSTRUMENT_VA(this);
   SBFile file;
   if (m_opaque_sp)
-return SBFile(m_opaque_sp->GetErrorStreamSP()->GetFileSP());
+return SBFile(m_opaque_sp->GetErrorFileSP());
   return SBFile();
 }
 
@@ -573,8 +573,8 @@ void SBDebugger::HandleCommand(const char *command) {
 
 sb_interpreter.HandleCommand(command,

[Lldb-commits] [lldb] [LLDB-DAP] SBDebugger don't prefix title on progress updates (PR #124648)

2025-02-18 Thread Jacob Lalonde via lldb-commits

https://github.com/Jlalond updated 
https://github.com/llvm/llvm-project/pull/124648

>From 12ff645735c1dbf51e58b9f80d4e3e13a0babdf5 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Mon, 27 Jan 2025 13:41:58 -0800
Subject: [PATCH 1/5] Only include title on the first message

---
 lldb/include/lldb/Core/DebuggerEvents.h | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lldb/include/lldb/Core/DebuggerEvents.h 
b/lldb/include/lldb/Core/DebuggerEvents.h
index 49a4ecf8e537e..52e4f77d7637d 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -44,12 +44,15 @@ class ProgressEventData : public EventData {
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
-std::string message = m_title;
-if (!m_details.empty()) {
-  message.append(": ");
-  message.append(m_details);
-}
-return message;
+if (m_completed == 0) {
+  std::string message = m_title;
+  if (!m_details.empty()) {
+message.append(": ");
+message.append(m_details);
+  }
+  return message;
+} else
+  return !m_details.empty() ? m_details : std::string();
   }
   const std::string &GetTitle() const { return m_title; }
   const std::string &GetDetails() const { return m_details; }

>From 82ed76ae3b6bef176bf54dd1031f0cb9c95081c1 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Mon, 27 Jan 2025 14:48:01 -0800
Subject: [PATCH 2/5] Add comment explaining if and add a test

---
 lldb/include/lldb/Core/DebuggerEvents.h   | 1 +
 lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py | 5 +
 2 files changed, 6 insertions(+)

diff --git a/lldb/include/lldb/Core/DebuggerEvents.h 
b/lldb/include/lldb/Core/DebuggerEvents.h
index 52e4f77d7637d..ca06ee835fde3 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -44,6 +44,7 @@ class ProgressEventData : public EventData {
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
+// Only put the title in the message of the progress create event.
 if (m_completed == 0) {
   std::string message = m_title;
   if (!m_details.empty()) {
diff --git a/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py 
b/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py
index 36c0cef9c4714..945c3f7633364 100755
--- a/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py
+++ b/lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py
@@ -41,8 +41,13 @@ def test_output(self):
 for event in self.dap_server.progress_events:
 event_type = event["event"]
 if "progressStart" in event_type:
+title = event["body"]["title"]
+self.assertIn("Progress tester", title)
 start_found = True
 if "progressUpdate" in event_type:
+message = event["body"]["message"]
+print(f"Progress update: {message}")
+self.assertNotIn("Progres tester", message)
 update_found = True
 
 self.assertTrue(start_found)

>From e15090782a93e07e8a260a0594ca02430e68e09f Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Thu, 30 Jan 2025 10:04:04 -0800
Subject: [PATCH 3/5] Migrate to structured data

Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:


Differential Revision: https://phabricator.intern.facebook.com/D68927453
---
 lldb/include/lldb/Core/DebuggerEvents.h | 16 +++-
 lldb/tools/lldb-dap/lldb-dap.cpp| 54 +
 2 files changed, 52 insertions(+), 18 deletions(-)

diff --git a/lldb/include/lldb/Core/DebuggerEvents.h 
b/lldb/include/lldb/Core/DebuggerEvents.h
index ca06ee835fde3..49a4ecf8e537e 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -44,16 +44,12 @@ class ProgressEventData : public EventData {
   uint64_t GetCompleted() const { return m_completed; }
   uint64_t GetTotal() const { return m_total; }
   std::string GetMessage() const {
-// Only put the title in the message of the progress create event.
-if (m_completed == 0) {
-  std::string message = m_title;
-  if (!m_details.empty()) {
-message.append(": ");
-message.append(m_details);
-  }
-  return message;
-} else
-  return !m_details.empty() ? m_details : std::string();
+std::string message = m_title;
+if (!m_details.empty()) {
+  message.append(": ");
+  message.append(m_details);
+}
+return message;
   }
   const std::string &GetTitle() const { return m_title; }
   const std::string &GetDetails() const { return m_details; }
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index e323990d8b6ed..4b3460190a7c9 100644
--- a/lldb/tools/lldb

[Lldb-commits] [lldb] [lldb] Add LineTable::{upper, lower}_bound (PR #127519)

2025-02-18 Thread Pavel Labath via lldb-commits

https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/127519

>From 627bb23342ee22dd263f0142ea43f644afd6faae Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 17 Feb 2025 17:29:40 +0100
Subject: [PATCH 1/2] [lldb] Add LineTable::{upper,lower}_bound

The motivation is #123622 and the fact that is hard to fine the last
line entry in a given range. `FindLineEntryByAddress(range_end-1)` is
the best we have, but it's not ideal because it has a magic -1 and that
it relies on there existing a line entry at that address (generally, it
should be there, but if for some case it isn't, we might end up ignoring
the entries that are there (or -- like my incorrect fix in #123622 did
-- iterating through the entire line table).

What we really want is to get the last entry that exists in the given
range. Or, equivalently (and more STL-like) the first entry after that
range. This is what these functions do. I've used the STL names since
they do pretty much exactly what the standard functions do (the main
head-scratcher comes from the fact that our entries represent ranges
rather than single values).

The functions can also be used to simplify the maze of `if` statements
in `FindLineEntryByAddress`, but I'm keeping that as a separate patch.
For now, I'm just adding some unit testing for that function to gain
more confidence that the patch does not change the function behavior.
---
 lldb/include/lldb/Symbol/LineTable.h|  13 ++
 lldb/source/Symbol/LineTable.cpp|  46 +++-
 lldb/unittests/Symbol/CMakeLists.txt|   1 +
 lldb/unittests/Symbol/LineTableTest.cpp | 285 
 4 files changed, 343 insertions(+), 2 deletions(-)
 create mode 100644 lldb/unittests/Symbol/LineTableTest.cpp

diff --git a/lldb/include/lldb/Symbol/LineTable.h 
b/lldb/include/lldb/Symbol/LineTable.h
index 6d158ab518879..f66081b6ee110 100644
--- a/lldb/include/lldb/Symbol/LineTable.h
+++ b/lldb/include/lldb/Symbol/LineTable.h
@@ -102,6 +102,19 @@ class LineTable {
 
   void GetDescription(Stream *s, Target *target, lldb::DescriptionLevel level);
 
+  /// Helper function for line table iteration. \c lower_bound returns the 
index
+  /// of the first line entry which ends after the given address (i.e., the
+  /// first entry which contains the given address or it comes after it).
+  /// \c upper_bound returns the index of the first line entry which begins on
+  /// or after the given address (i.e., the entry which would come after the
+  /// entry containing the given address, if such an entry exists). Functions
+  /// return GetSize() if there is no such entry. The functions are
+  /// most useful in combination: iterating from lower_bound(a) to
+  /// upper_bound(b) returns all line tables which intersect the half-open
+  /// range [a,b).
+  uint32_t lower_bound(const Address &so_addr) const;
+  uint32_t upper_bound(const Address &so_addr) const;
+
   /// Find a line entry that contains the section offset address \a so_addr.
   ///
   /// \param[in] so_addr
diff --git a/lldb/source/Symbol/LineTable.cpp b/lldb/source/Symbol/LineTable.cpp
index 3d2afcdd11997..aae4ab59ff156 100644
--- a/lldb/source/Symbol/LineTable.cpp
+++ b/lldb/source/Symbol/LineTable.cpp
@@ -123,7 +123,7 @@ void LineTable::InsertSequence(LineSequence *sequence) {
   entry_collection::iterator end_pos = m_entries.end();
   LineTable::Entry::LessThanBinaryPredicate less_than_bp(this);
   entry_collection::iterator pos =
-  upper_bound(begin_pos, end_pos, entry, less_than_bp);
+  std::upper_bound(begin_pos, end_pos, entry, less_than_bp);
 
   // We should never insert a sequence in the middle of another sequence
   if (pos != begin_pos) {
@@ -185,6 +185,48 @@ bool LineTable::GetLineEntryAtIndex(uint32_t idx, 
LineEntry &line_entry) {
   return false;
 }
 
+uint32_t LineTable::lower_bound(const Address &so_addr) const {
+  if (so_addr.GetModule() != m_comp_unit->GetModule())
+return GetSize();
+
+  Entry search_entry;
+  search_entry.file_addr = so_addr.GetFileAddress();
+  if (search_entry.file_addr == LLDB_INVALID_ADDRESS)
+return GetSize();
+
+  // This is not a typo. upper_bound returns the first entry which definitely
+  // does not contain this address, which means the entry before it *might*
+  // contain it -- if it is not a termination entry.
+  auto pos =
+  llvm::upper_bound(m_entries, search_entry, Entry::EntryAddressLessThan);
+
+  if (pos != m_entries.begin() && !std::prev(pos)->is_terminal_entry)
+--pos;
+
+  return std::distance(m_entries.begin(), pos);
+}
+
+uint32_t LineTable::upper_bound(const Address &so_addr) const {
+  if (so_addr.GetModule() != m_comp_unit->GetModule())
+return GetSize();
+
+  Entry search_entry;
+  search_entry.file_addr = so_addr.GetFileAddress();
+  if (search_entry.file_addr == LLDB_INVALID_ADDRESS)
+return GetSize();
+
+  // This is not a typo. lower_bound returns the first entry which starts on or
+  // after the given address, which is exactly what we want

[Lldb-commits] [lldb] [lldb] Store the return ValueObject in the CommandReturnObject (PR #127566)

2025-02-18 Thread Adrian Vogelsgesang via lldb-commits

vogelsgesang wrote:

Would be great if we could integrate this with `lldb-dap` right away, then we 
could see how this works in practice in at least one GUI.

Note that lldb-dap already exposes SBValues via the protocol when evaluating an 
expression. Afaict, the same logic only could also be wired with 
`GetReturnValue` now

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


[Lldb-commits] [lldb] [lldb] Add LineTable::{upper, lower}_bound (PR #127519)

2025-02-18 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 153dd19e3057169e6935027ffbc84b62b392aa35 
bfe8f5c7338a24420223b794559d4c842d14d190 --extensions cpp,h -- 
lldb/unittests/Symbol/LineTableTest.cpp lldb/include/lldb/Symbol/LineTable.h 
lldb/source/Symbol/LineTable.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/unittests/Symbol/LineTableTest.cpp 
b/lldb/unittests/Symbol/LineTableTest.cpp
index 314fc09b73..2749d0d413 100644
--- a/lldb/unittests/Symbol/LineTableTest.cpp
+++ b/lldb/unittests/Symbol/LineTableTest.cpp
@@ -132,9 +132,7 @@ public:
   std::vector> Build() {
 return std::move(m_sequences);
   }
-  enum Terminal : bool {
-Terminal = true;
-  };
+  enum Terminal : bool { Terminal = true; };
   void Entry(addr_t addr, bool terminal = false) {
 LineTable::AppendLineEntryToSequence(
 m_seq_up.get(), addr, /*line=*/1, /*column=*/0,

``




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


[Lldb-commits] [lldb] [lldb] Add LineTable::{upper, lower}_bound (PR #127519)

2025-02-18 Thread Pavel Labath via lldb-commits

https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/127519

>From 627bb23342ee22dd263f0142ea43f644afd6faae Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 17 Feb 2025 17:29:40 +0100
Subject: [PATCH 1/3] [lldb] Add LineTable::{upper,lower}_bound

The motivation is #123622 and the fact that is hard to fine the last
line entry in a given range. `FindLineEntryByAddress(range_end-1)` is
the best we have, but it's not ideal because it has a magic -1 and that
it relies on there existing a line entry at that address (generally, it
should be there, but if for some case it isn't, we might end up ignoring
the entries that are there (or -- like my incorrect fix in #123622 did
-- iterating through the entire line table).

What we really want is to get the last entry that exists in the given
range. Or, equivalently (and more STL-like) the first entry after that
range. This is what these functions do. I've used the STL names since
they do pretty much exactly what the standard functions do (the main
head-scratcher comes from the fact that our entries represent ranges
rather than single values).

The functions can also be used to simplify the maze of `if` statements
in `FindLineEntryByAddress`, but I'm keeping that as a separate patch.
For now, I'm just adding some unit testing for that function to gain
more confidence that the patch does not change the function behavior.
---
 lldb/include/lldb/Symbol/LineTable.h|  13 ++
 lldb/source/Symbol/LineTable.cpp|  46 +++-
 lldb/unittests/Symbol/CMakeLists.txt|   1 +
 lldb/unittests/Symbol/LineTableTest.cpp | 285 
 4 files changed, 343 insertions(+), 2 deletions(-)
 create mode 100644 lldb/unittests/Symbol/LineTableTest.cpp

diff --git a/lldb/include/lldb/Symbol/LineTable.h 
b/lldb/include/lldb/Symbol/LineTable.h
index 6d158ab518879..f66081b6ee110 100644
--- a/lldb/include/lldb/Symbol/LineTable.h
+++ b/lldb/include/lldb/Symbol/LineTable.h
@@ -102,6 +102,19 @@ class LineTable {
 
   void GetDescription(Stream *s, Target *target, lldb::DescriptionLevel level);
 
+  /// Helper function for line table iteration. \c lower_bound returns the 
index
+  /// of the first line entry which ends after the given address (i.e., the
+  /// first entry which contains the given address or it comes after it).
+  /// \c upper_bound returns the index of the first line entry which begins on
+  /// or after the given address (i.e., the entry which would come after the
+  /// entry containing the given address, if such an entry exists). Functions
+  /// return GetSize() if there is no such entry. The functions are
+  /// most useful in combination: iterating from lower_bound(a) to
+  /// upper_bound(b) returns all line tables which intersect the half-open
+  /// range [a,b).
+  uint32_t lower_bound(const Address &so_addr) const;
+  uint32_t upper_bound(const Address &so_addr) const;
+
   /// Find a line entry that contains the section offset address \a so_addr.
   ///
   /// \param[in] so_addr
diff --git a/lldb/source/Symbol/LineTable.cpp b/lldb/source/Symbol/LineTable.cpp
index 3d2afcdd11997..aae4ab59ff156 100644
--- a/lldb/source/Symbol/LineTable.cpp
+++ b/lldb/source/Symbol/LineTable.cpp
@@ -123,7 +123,7 @@ void LineTable::InsertSequence(LineSequence *sequence) {
   entry_collection::iterator end_pos = m_entries.end();
   LineTable::Entry::LessThanBinaryPredicate less_than_bp(this);
   entry_collection::iterator pos =
-  upper_bound(begin_pos, end_pos, entry, less_than_bp);
+  std::upper_bound(begin_pos, end_pos, entry, less_than_bp);
 
   // We should never insert a sequence in the middle of another sequence
   if (pos != begin_pos) {
@@ -185,6 +185,48 @@ bool LineTable::GetLineEntryAtIndex(uint32_t idx, 
LineEntry &line_entry) {
   return false;
 }
 
+uint32_t LineTable::lower_bound(const Address &so_addr) const {
+  if (so_addr.GetModule() != m_comp_unit->GetModule())
+return GetSize();
+
+  Entry search_entry;
+  search_entry.file_addr = so_addr.GetFileAddress();
+  if (search_entry.file_addr == LLDB_INVALID_ADDRESS)
+return GetSize();
+
+  // This is not a typo. upper_bound returns the first entry which definitely
+  // does not contain this address, which means the entry before it *might*
+  // contain it -- if it is not a termination entry.
+  auto pos =
+  llvm::upper_bound(m_entries, search_entry, Entry::EntryAddressLessThan);
+
+  if (pos != m_entries.begin() && !std::prev(pos)->is_terminal_entry)
+--pos;
+
+  return std::distance(m_entries.begin(), pos);
+}
+
+uint32_t LineTable::upper_bound(const Address &so_addr) const {
+  if (so_addr.GetModule() != m_comp_unit->GetModule())
+return GetSize();
+
+  Entry search_entry;
+  search_entry.file_addr = so_addr.GetFileAddress();
+  if (search_entry.file_addr == LLDB_INVALID_ADDRESS)
+return GetSize();
+
+  // This is not a typo. lower_bound returns the first entry which starts on or
+  // after the given address, which is exactly what we want

[Lldb-commits] [lldb] [lldb] Add LineTable::{upper, lower}_bound (PR #127519)

2025-02-18 Thread Pavel Labath via lldb-commits


@@ -185,6 +185,48 @@ bool LineTable::GetLineEntryAtIndex(uint32_t idx, 
LineEntry &line_entry) {
   return false;
 }
 
+uint32_t LineTable::lower_bound(const Address &so_addr) const {
+  if (so_addr.GetModule() != m_comp_unit->GetModule())
+return GetSize();
+
+  Entry search_entry;
+  search_entry.file_addr = so_addr.GetFileAddress();
+  if (search_entry.file_addr == LLDB_INVALID_ADDRESS)
+return GetSize();
+
+  // This is not a typo. upper_bound returns the first entry which definitely
+  // does not contain this address, which means the entry before it *might*
+  // contain it -- if it is not a termination entry.
+  auto pos =
+  llvm::upper_bound(m_entries, search_entry, Entry::EntryAddressLessThan);
+
+  if (pos != m_entries.begin() && !std::prev(pos)->is_terminal_entry)
+--pos;
+
+  return std::distance(m_entries.begin(), pos);

labath wrote:

Mainly because all of the other LineTable API work with indexes. So like, I 
wouldn't actually have a way with the returned iterator. Part of the reason for 
that is that the internal LineTable representation does not match what gets 
returned by functions like `FindLineEntryByAddress`. That could be dealt with 
by building a fancy iterator class which converts the values on the fly, but 
that's a much larger change..

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


[Lldb-commits] [lldb] [lldb] Store the return ValueObject in the CommandReturnObject (PR #127566)

2025-02-18 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

Two questions:
- what about commands (like frame/target variable) which can return more than 
variable. I guess I'm wondering if this should be a SBValueList instead?
- what about commands (I don't know if we have any) whose output consists of 
more than formatting a single value (which, I guess would be lost if the IDE 
decides to ignore the output). Are we fine with not supporting that? (we could 
say that if a command wants to print some extra output, it should use the error 
stream for that)

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


[Lldb-commits] [lldb] Define Telemetry plugin for LLDB. (PR #126588)

2025-02-18 Thread Vy Nguyen via lldb-commits

https://github.com/oontvoo updated 
https://github.com/llvm/llvm-project/pull/126588

>From c7734011094995c64137de6f8122033d2a981610 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Mon, 10 Feb 2025 14:44:11 -0500
Subject: [PATCH 01/26] Define TelemetryVendor plugin.

Details:

Upstream in LLDB, we will have a default TelemetryVendor plugin will provide a 
default Config and NULL TelemetryManager.
Downstream vendors can extend this to provide a vendor-specific Config along 
with a functional TelemetryManager instance.
---
 lldb/include/lldb/Core/TelemetryVendor.h | 39 +
 lldb/source/Core/TelemetryVendor.cpp | 43 
 2 files changed, 82 insertions(+)
 create mode 100644 lldb/include/lldb/Core/TelemetryVendor.h
 create mode 100644 lldb/source/Core/TelemetryVendor.cpp

diff --git a/lldb/include/lldb/Core/TelemetryVendor.h 
b/lldb/include/lldb/Core/TelemetryVendor.h
new file mode 100644
index 0..a2ab3b69fde42
--- /dev/null
+++ b/lldb/include/lldb/Core/TelemetryVendor.h
@@ -0,0 +1,39 @@
+//===-- TelemetryVendor.h 
-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef LLDB_CORE_TELEMETRYVENDOR_H
+#define LLDB_CORE_TELEMETRYVENDOR_H
+
+#include "lldb/Core/PluginInterface.h"
+#include "lldb/Core/Telemetry.h"
+#include "llvm/Telemetry/Telemetry.h"
+
+#include 
+
+namespace lldb_private {
+
+class TelemetryVendor : public PluginInterface {
+public:
+  TelemetryVendor() = default;
+
+  llvm::StringRef GetPluginName() override;
+
+  static void Initialize();
+
+  static void Terminate();
+
+  static std::unique_ptr GetTelemetryConfig();
+  static void
+  SetTelemetryConfig(std::unique_ptr config);
+
+  static lldb::TelemetryManagerSP GetTelemetryManager();
+  static void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp);
+};
+
+} // namespace lldb_private
+#endif // LLDB_CORE_TELEMETRYVENDOR_H
diff --git a/lldb/source/Core/TelemetryVendor.cpp 
b/lldb/source/Core/TelemetryVendor.cpp
new file mode 100644
index 0..520a01b9b1c7a
--- /dev/null
+++ b/lldb/source/Core/TelemetryVendor.cpp
@@ -0,0 +1,43 @@
+//===-- TelemetryVendor.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 "lldb/Core/TelemetryVendor.h"
+
+namespace lldb_private {
+
+llvm::StringRef TelemetryVendor::GetPluginName() {
+  return "UpstreamTelemetryVendor";
+}
+
+void TelemetryVendor::Initialize() {
+  // The default (upstream) impl will have telemetry disabled by default.
+  SetTelemetryConfig(
+  std::make_unique(/*enable_telemetry*/ false));
+  SetTelemetryManager(nullptr);
+}
+
+static std::unique_ptr current_config;
+std::unique_ptr TelemetryVendor::GetTelemetryConfig() 
{
+  return current_config;
+}
+
+void TelemetryVendor::SetTelemetryConfig(
+std::unique_ptr config) {
+  current_config = std::move(config);
+}
+
+lldb::TelemetryManagerSP TelemetryVendor::GetTelemetryManager() {
+  static TelemteryManagerSP g_telemetry_manager_sp;
+  return g_telemetry_manager_sp;
+}
+
+void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp) {
+  GetTelemetryManager() = manager_sp;
+}
+
+} // namespace lldb_private

>From 5f6a04de76a5bf633ca9d14d9907d535301c5c59 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Tue, 11 Feb 2025 10:31:00 -0500
Subject: [PATCH 02/26] use shared ptr

---
 lldb/include/lldb/Core/TelemetryVendor.h |  7 ---
 lldb/include/lldb/lldb-forward.h |  5 +
 lldb/source/Core/TelemetryVendor.cpp | 14 +++---
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/lldb/include/lldb/Core/TelemetryVendor.h 
b/lldb/include/lldb/Core/TelemetryVendor.h
index a2ab3b69fde42..a55f06fb9141f 100644
--- a/lldb/include/lldb/Core/TelemetryVendor.h
+++ b/lldb/include/lldb/Core/TelemetryVendor.h
@@ -27,11 +27,12 @@ class TelemetryVendor : public PluginInterface {
 
   static void Terminate();
 
-  static std::unique_ptr GetTelemetryConfig();
-  static void
-  SetTelemetryConfig(std::unique_ptr config);
+  static lldb::TelemetryConfig GetTelemetryConfig();
+
+  static void SetTelemetryConfig(const lldb::TelemetryConfigSP &config);
 
   static lldb::TelemetryManagerSP GetTelemetryManager();
+
   static void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp);
 };
 
diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h
index fc7456a4b9a32..2f2a4ec86a1fb 100644
--- a/lldb/include/lldb/

[Lldb-commits] [lldb] Define Telemetry plugin for LLDB. (PR #126588)

2025-02-18 Thread Vy Nguyen via lldb-commits

https://github.com/oontvoo updated 
https://github.com/llvm/llvm-project/pull/126588

>From c7734011094995c64137de6f8122033d2a981610 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Mon, 10 Feb 2025 14:44:11 -0500
Subject: [PATCH 01/27] Define TelemetryVendor plugin.

Details:

Upstream in LLDB, we will have a default TelemetryVendor plugin will provide a 
default Config and NULL TelemetryManager.
Downstream vendors can extend this to provide a vendor-specific Config along 
with a functional TelemetryManager instance.
---
 lldb/include/lldb/Core/TelemetryVendor.h | 39 +
 lldb/source/Core/TelemetryVendor.cpp | 43 
 2 files changed, 82 insertions(+)
 create mode 100644 lldb/include/lldb/Core/TelemetryVendor.h
 create mode 100644 lldb/source/Core/TelemetryVendor.cpp

diff --git a/lldb/include/lldb/Core/TelemetryVendor.h 
b/lldb/include/lldb/Core/TelemetryVendor.h
new file mode 100644
index 0..a2ab3b69fde42
--- /dev/null
+++ b/lldb/include/lldb/Core/TelemetryVendor.h
@@ -0,0 +1,39 @@
+//===-- TelemetryVendor.h 
-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef LLDB_CORE_TELEMETRYVENDOR_H
+#define LLDB_CORE_TELEMETRYVENDOR_H
+
+#include "lldb/Core/PluginInterface.h"
+#include "lldb/Core/Telemetry.h"
+#include "llvm/Telemetry/Telemetry.h"
+
+#include 
+
+namespace lldb_private {
+
+class TelemetryVendor : public PluginInterface {
+public:
+  TelemetryVendor() = default;
+
+  llvm::StringRef GetPluginName() override;
+
+  static void Initialize();
+
+  static void Terminate();
+
+  static std::unique_ptr GetTelemetryConfig();
+  static void
+  SetTelemetryConfig(std::unique_ptr config);
+
+  static lldb::TelemetryManagerSP GetTelemetryManager();
+  static void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp);
+};
+
+} // namespace lldb_private
+#endif // LLDB_CORE_TELEMETRYVENDOR_H
diff --git a/lldb/source/Core/TelemetryVendor.cpp 
b/lldb/source/Core/TelemetryVendor.cpp
new file mode 100644
index 0..520a01b9b1c7a
--- /dev/null
+++ b/lldb/source/Core/TelemetryVendor.cpp
@@ -0,0 +1,43 @@
+//===-- TelemetryVendor.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 "lldb/Core/TelemetryVendor.h"
+
+namespace lldb_private {
+
+llvm::StringRef TelemetryVendor::GetPluginName() {
+  return "UpstreamTelemetryVendor";
+}
+
+void TelemetryVendor::Initialize() {
+  // The default (upstream) impl will have telemetry disabled by default.
+  SetTelemetryConfig(
+  std::make_unique(/*enable_telemetry*/ false));
+  SetTelemetryManager(nullptr);
+}
+
+static std::unique_ptr current_config;
+std::unique_ptr TelemetryVendor::GetTelemetryConfig() 
{
+  return current_config;
+}
+
+void TelemetryVendor::SetTelemetryConfig(
+std::unique_ptr config) {
+  current_config = std::move(config);
+}
+
+lldb::TelemetryManagerSP TelemetryVendor::GetTelemetryManager() {
+  static TelemteryManagerSP g_telemetry_manager_sp;
+  return g_telemetry_manager_sp;
+}
+
+void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp) {
+  GetTelemetryManager() = manager_sp;
+}
+
+} // namespace lldb_private

>From 5f6a04de76a5bf633ca9d14d9907d535301c5c59 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Tue, 11 Feb 2025 10:31:00 -0500
Subject: [PATCH 02/27] use shared ptr

---
 lldb/include/lldb/Core/TelemetryVendor.h |  7 ---
 lldb/include/lldb/lldb-forward.h |  5 +
 lldb/source/Core/TelemetryVendor.cpp | 14 +++---
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/lldb/include/lldb/Core/TelemetryVendor.h 
b/lldb/include/lldb/Core/TelemetryVendor.h
index a2ab3b69fde42..a55f06fb9141f 100644
--- a/lldb/include/lldb/Core/TelemetryVendor.h
+++ b/lldb/include/lldb/Core/TelemetryVendor.h
@@ -27,11 +27,12 @@ class TelemetryVendor : public PluginInterface {
 
   static void Terminate();
 
-  static std::unique_ptr GetTelemetryConfig();
-  static void
-  SetTelemetryConfig(std::unique_ptr config);
+  static lldb::TelemetryConfig GetTelemetryConfig();
+
+  static void SetTelemetryConfig(const lldb::TelemetryConfigSP &config);
 
   static lldb::TelemetryManagerSP GetTelemetryManager();
+
   static void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp);
 };
 
diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h
index fc7456a4b9a32..2f2a4ec86a1fb 100644
--- a/lldb/include/lldb/

[Lldb-commits] [lldb] Define Telemetry plugin for LLDB. (PR #126588)

2025-02-18 Thread Vy Nguyen via lldb-commits

https://github.com/oontvoo updated 
https://github.com/llvm/llvm-project/pull/126588

>From c7734011094995c64137de6f8122033d2a981610 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Mon, 10 Feb 2025 14:44:11 -0500
Subject: [PATCH 01/27] Define TelemetryVendor plugin.

Details:

Upstream in LLDB, we will have a default TelemetryVendor plugin will provide a 
default Config and NULL TelemetryManager.
Downstream vendors can extend this to provide a vendor-specific Config along 
with a functional TelemetryManager instance.
---
 lldb/include/lldb/Core/TelemetryVendor.h | 39 +
 lldb/source/Core/TelemetryVendor.cpp | 43 
 2 files changed, 82 insertions(+)
 create mode 100644 lldb/include/lldb/Core/TelemetryVendor.h
 create mode 100644 lldb/source/Core/TelemetryVendor.cpp

diff --git a/lldb/include/lldb/Core/TelemetryVendor.h 
b/lldb/include/lldb/Core/TelemetryVendor.h
new file mode 100644
index 0..a2ab3b69fde42
--- /dev/null
+++ b/lldb/include/lldb/Core/TelemetryVendor.h
@@ -0,0 +1,39 @@
+//===-- TelemetryVendor.h 
-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef LLDB_CORE_TELEMETRYVENDOR_H
+#define LLDB_CORE_TELEMETRYVENDOR_H
+
+#include "lldb/Core/PluginInterface.h"
+#include "lldb/Core/Telemetry.h"
+#include "llvm/Telemetry/Telemetry.h"
+
+#include 
+
+namespace lldb_private {
+
+class TelemetryVendor : public PluginInterface {
+public:
+  TelemetryVendor() = default;
+
+  llvm::StringRef GetPluginName() override;
+
+  static void Initialize();
+
+  static void Terminate();
+
+  static std::unique_ptr GetTelemetryConfig();
+  static void
+  SetTelemetryConfig(std::unique_ptr config);
+
+  static lldb::TelemetryManagerSP GetTelemetryManager();
+  static void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp);
+};
+
+} // namespace lldb_private
+#endif // LLDB_CORE_TELEMETRYVENDOR_H
diff --git a/lldb/source/Core/TelemetryVendor.cpp 
b/lldb/source/Core/TelemetryVendor.cpp
new file mode 100644
index 0..520a01b9b1c7a
--- /dev/null
+++ b/lldb/source/Core/TelemetryVendor.cpp
@@ -0,0 +1,43 @@
+//===-- TelemetryVendor.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 "lldb/Core/TelemetryVendor.h"
+
+namespace lldb_private {
+
+llvm::StringRef TelemetryVendor::GetPluginName() {
+  return "UpstreamTelemetryVendor";
+}
+
+void TelemetryVendor::Initialize() {
+  // The default (upstream) impl will have telemetry disabled by default.
+  SetTelemetryConfig(
+  std::make_unique(/*enable_telemetry*/ false));
+  SetTelemetryManager(nullptr);
+}
+
+static std::unique_ptr current_config;
+std::unique_ptr TelemetryVendor::GetTelemetryConfig() 
{
+  return current_config;
+}
+
+void TelemetryVendor::SetTelemetryConfig(
+std::unique_ptr config) {
+  current_config = std::move(config);
+}
+
+lldb::TelemetryManagerSP TelemetryVendor::GetTelemetryManager() {
+  static TelemteryManagerSP g_telemetry_manager_sp;
+  return g_telemetry_manager_sp;
+}
+
+void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp) {
+  GetTelemetryManager() = manager_sp;
+}
+
+} // namespace lldb_private

>From 5f6a04de76a5bf633ca9d14d9907d535301c5c59 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Tue, 11 Feb 2025 10:31:00 -0500
Subject: [PATCH 02/27] use shared ptr

---
 lldb/include/lldb/Core/TelemetryVendor.h |  7 ---
 lldb/include/lldb/lldb-forward.h |  5 +
 lldb/source/Core/TelemetryVendor.cpp | 14 +++---
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/lldb/include/lldb/Core/TelemetryVendor.h 
b/lldb/include/lldb/Core/TelemetryVendor.h
index a2ab3b69fde42..a55f06fb9141f 100644
--- a/lldb/include/lldb/Core/TelemetryVendor.h
+++ b/lldb/include/lldb/Core/TelemetryVendor.h
@@ -27,11 +27,12 @@ class TelemetryVendor : public PluginInterface {
 
   static void Terminate();
 
-  static std::unique_ptr GetTelemetryConfig();
-  static void
-  SetTelemetryConfig(std::unique_ptr config);
+  static lldb::TelemetryConfig GetTelemetryConfig();
+
+  static void SetTelemetryConfig(const lldb::TelemetryConfigSP &config);
 
   static lldb::TelemetryManagerSP GetTelemetryManager();
+
   static void SetTelemetryManager(const lldb::TelemetryManagerSP &manager_sp);
 };
 
diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h
index fc7456a4b9a32..2f2a4ec86a1fb 100644
--- a/lldb/include/lldb/

[Lldb-commits] [lldb] Allow option to ignore module load errors in ScriptedProcess (PR #127153)

2025-02-18 Thread Pavel Labath via lldb-commits

labath wrote:

> I'm not convinced of that this change needs to be happen in ScriptedProcess 
> ... May be we could have a setting to not discard all modules loaded in case 
> 1 of them failed to load that would also work with other Process plugins. 
> @jimingham what do you think ?

I'm confused. Isn't that already what happens for non-scripted processes?

```
$ lldb -n a.out -o "image list" -b
(lldb) process attach --name "a.out"
Process 11191 stopped
* thread #1, name = 'a.out', stop reason = signal SIGSTOP
frame #0: 0x7f7083e088e4 libc.so.6`pause + 20
libc.so.6`pause:
->  0x7f7083e088e4 <+20>: cmpq   $-0x1000, %rax ; imm = 0xF000 
0x7f7083e088ea <+26>: ja 0x7f7083e08920 ; <+80>
0x7f7083e088ec <+28>: retq   
0x7f7083e088ed <+29>: nopl   (%rax)
Executable module set to "/tmp/X/a.out".
Architecture set to: x86_64-pc-linux-gnu.
(lldb) image list
[  0] 171A52C4 0x56532dec /tmp/X/a.out 
[  1] 421DCFD2-138A-B321-D6F1-7AFD7B7FC999-F79CA445 0x7ffdeb3a5000 [vdso] 
(0x7ffdeb3a5000)
[  2] 838926F7 0x7f7083f45000 libb.so  <== LIBB.SO HERE
[  3] C88DE6C8 0x7f7083d1f000 /lib64/libc.so.6 
  /usr/lib/debug/lib64/libc.so.6.debug
[  4] D626A570 0x7f7083f4c000 /lib64/ld-linux-x86-64.so.2 
$ rm libb.so <= FILE DELETED
$ lldb -n a.out -o "image list" -b
(lldb) process attach --name "a.out"
Process 11191 stopped
* thread #1, name = 'a.out', stop reason = signal SIGSTOP
frame #0: 0x7f7083e088e4 libc.so.6`pause + 20
libc.so.6`pause:
->  0x7f7083e088e4 <+20>: cmpq   $-0x1000, %rax ; imm = 0xF000 
0x7f7083e088ea <+26>: ja 0x7f7083e08920 ; <+80>
0x7f7083e088ec <+28>: retq   
0x7f7083e088ed <+29>: nopl   (%rax)
Executable module set to "/tmp/X/a.out".
Architecture set to: x86_64-pc-linux-gnu.
(lldb) image list<= LIBB.SO MISSING (BUT OTHER MODULES STILL THERE)
[  0] 171A52C4 0x56532dec /tmp/X/a.out 
[  1] 421DCFD2-138A-B321-D6F1-7AFD7B7FC999-F79CA445 0x7ffdeb3a5000 [vdso] 
(0x7ffdeb3a5000)
[  2] C88DE6C8 0x7f7083d1f000 /lib64/libc.so.6 
  /usr/lib/debug/lib64/libc.so.6.debug
[  3] D626A570 0x7f7083f4c000 /lib64/ld-linux-x86-64.so.2 
```

I got this on linux. On darwin, the module might still be present because it 
might be read from process memory directly. Still, if that failed for some 
reason (perhaps because instead of a live process we were dealing with a core 
file -- one which does not include the module contents in the dump), I would 
expect other modules to be present. 

Rejecting all of them because one couldn't be found seems to go against our "do 
our best to keep going with limited info" philosophy.

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


[Lldb-commits] [lldb] [lldb] Synchronize the debugger's stdout and stderr streams (PR #126630)

2025-02-18 Thread Pavel Labath via lldb-commits

labath wrote:

> > That said, not needing to replicate the locking logic in every IOHandler 
> > would definitely be nice. However, I'm not certain about the feasibility of 
> > that. In a way, I think that the PrintAsync approach is better because it 
> > lets the IOHandler know that some async printing is happening, and it can 
> > choose how to deal with it. For example, the ProcessIOHandler (forwarding 
> > stdout of the debugger proces) can end up in a state where the debugged 
> > process has written only a half a line. If async printing is plumbed 
> > through it, it will know that is happening, and it can choose to do 
> > something about (print an extra newline to delimit process output, or maybe 
> > erase the last output line, and then redraw it after the async output -- I 
> > don't know).
> 
> Are you saying this is how it _could_ work? Looking at 
> `IOHandlerProcessSTDIO`, it doesn't implement `PrintAsync` so it's just using 
> the default implementation which prints to the debugger output stream.

Correct. This is not how IOHandlerProcessSTDIO works right now (but 
[IOHandlerEditline](https://github.com/llvm/llvm-project/blob/e235fcb582eec5f58c905b66f96d0732d17b875e/lldb/source/Host/common/Editline.cpp#L1660)
 does). I'm using that as an example of something that would not be possible if 
one relied solely on the locking mechanism. The curses gui iohandler might be 
an even better example of that (although I'd much rather see it burn than 
improve it), as there the output might need to go to some particular curses 
window in order to avoid completely corrupting the curses window layout.

> 
> > I'm not a mind reader nor a time traveller, but I have a feeling this is 
> > the reason why the async functionality is implemented the way it is. Maybe 
> > that's something we don't need? I think I could live without it. But if 
> > that is the case, I would like to see it dismantled, at least partially. 
> > For example, do you think it would be possible to change 
> > Debugger::PrintAsync to print the output directly (after locking the stream 
> > and such) -- without going through the IOHandlers and stuff?
> 
> I ran the test suite with this change:
> 
> ```
> diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
> index 65f0502143bc..7e306fd7dcf4 100644
> --- a/lldb/source/Core/Debugger.cpp
> +++ b/lldb/source/Core/Debugger.cpp
> @@ -1200,13 +1200,10 @@ bool Debugger::CheckTopIOHandlerTypes(IOHandler::Type 
> top_type,
>  }
>  
>  void Debugger::PrintAsync(const char *s, size_t len, bool is_stdout) {
> -  bool printed = m_io_handler_stack.PrintAsync(s, len, is_stdout);
> -  if (!printed) {
> -LockableStreamFileSP stream_sp =
> -is_stdout ? m_output_stream_sp : m_error_stream_sp;
> -LockedStreamFile locked_stream = stream_sp->Lock();
> -locked_stream.Write(s, len);
> -  }
> +  LockableStreamFileSP stream_sp =
> +  is_stdout ? m_output_stream_sp : m_error_stream_sp;
> +  LockedStreamFile locked_stream = stream_sp->Lock();
> +  locked_stream.Write(s, len);
>  }
>  
>  llvm::StringRef Debugger::GetTopIOHandlerControlSequence(char ch) {
> ```
> 
> I'm not sure how representative it is to rely on the test suite for something 
> like this, but I got one failure (`TestBreakpointCallbackCommandSource.py`) 
> because we don't redraw the prompt.

Thanks for trying it out. You're right, it probably isn't representative, but 
this test failure probably is a symptom of the problem -- this implementation 
would not trigger the prompt redrawing code I linked to above.

> @labath After reading your last message I'm not sure where you want to take 
> this. I understand the desire to not have two ways of doing things, but I 
> don't necessarily see how they have to be tied together.

I'm sorry about the confusion. I think that's a reflection of my ambiguity. I 
wouldn't really say I want to take this in a specific direction. I'm more of in 
the "asking questions" stage, where I'm turning the problem over in order to 
understand it.

Yesterday, I wasn't sure if we need the async stream mechanism. Today, I think 
we do (because of the prompt redrawing thingy). I think the two questions 
(async print and stream protection), but are separate in a way (the iohandlers 
still need, and the editline iohandler actually uses a mutex), but they are 
also kind of related in that they have to work together to achieve desired 
outcome ("nice" console output?) -- which may impact how they're implemented. 

At this point, I think the main question I am trying to answer is about a some 
guideline/rule about the usage of the various printing mechanism. Imagine I'm 
writing (or reviewing) a piece of code trying to print something. How do I know 
which method to use. If I can get a hold of a Debugger, I have the choice 
between GetOutputStreamSP, GetOutputFile and GetAsyncOutputStream. This patch 
doesn't really change that (which is why I think you say it's a net benefit), 
but it might