[Lldb-commits] [lldb] Fix flake in TestZerothFrame.py (PR #96685)

2024-07-02 Thread Pavel Labath via lldb-commits

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


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


[Lldb-commits] [lldb] Fix flake in TestZerothFrame.py (PR #96685)

2024-07-02 Thread via lldb-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
darker --check --diff -r 
7c83b7ef1796210451b839f4c58f2815f4aedfe5...e3d44a2fed3d4129e245d5695c3af0c21bb7b329
 lldb/test/API/functionalities/unwind/zeroth_frame/TestZerothFrame.py
``





View the diff from darker here.


``diff
--- TestZerothFrame.py  2024-07-01 21:17:03.00 +
+++ TestZerothFrame.py  2024-07-02 07:24:38.100392 +
@@ -39,12 +39,16 @@
 exe = self.getBuildArtifact("a.out")
 target = self.dbg.CreateTarget(exe)
 self.assertTrue(target, VALID_TARGET)
 
 main_dot_c = lldb.SBFileSpec("main.c")
-bp1 = target.BreakpointCreateBySourceRegex("// Set breakpoint 1 here", 
main_dot_c)
-bp2 = target.BreakpointCreateBySourceRegex("// Set breakpoint 2 here", 
main_dot_c)
+bp1 = target.BreakpointCreateBySourceRegex(
+"// Set breakpoint 1 here", main_dot_c
+)
+bp2 = target.BreakpointCreateBySourceRegex(
+"// Set breakpoint 2 here", main_dot_c
+)
 
 process = target.LaunchSimple(None, None, 
self.get_process_working_directory())
 self.assertTrue(process, VALID_PROCESS)
 
 thread = self.thread()

``




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


[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/97262

>From e08689b3e2482305755b56e4029f201fcf7af05b Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Tue, 2 Jul 2024 00:26:41 -0700
Subject: [PATCH] [lldb/docs] Add scripting extensions documentation to the
 website

This patch adds the documentation for a subset of scripting extensions
such as scripted process, scripted thread, operating system threads &
scritped thread plans to the lldb website.

Signed-off-by: Med Ismail Bennani 
---
 lldb/docs/CMakeLists.txt  |  9 ++-
 lldb/docs/index.rst   |  1 +
 lldb/docs/python_extensions.rst   | 36 ++
 .../python/templates/operating_system.py  | 20 +++---
 .../python/templates/scripted_platform.py | 25 ---
 .../python/templates/scripted_process.py  | 42 +--
 .../python/templates/scripted_thread_plan.py  | 70 +++
 7 files changed, 156 insertions(+), 47 deletions(-)
 create mode 100644 lldb/docs/python_extensions.rst
 create mode 100644 lldb/examples/python/templates/scripted_thread_plan.py

diff --git a/lldb/docs/CMakeLists.txt b/lldb/docs/CMakeLists.txt
index f482e91d1b10c..f327596f3ef31 100644
--- a/lldb/docs/CMakeLists.txt
+++ b/lldb/docs/CMakeLists.txt
@@ -25,10 +25,17 @@ if (LLDB_ENABLE_PYTHON AND SPHINX_FOUND)
 # Pretend that the SWIG generated API is a Python package.
 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lldb)
 get_target_property(lldb_bindings_dir swig_wrapper_python BINARY_DIR)
+
 add_custom_target(lldb-python-doc-package
   COMMAND "${CMAKE_COMMAND}" -E copy "${lldb_bindings_dir}/lldb.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/__init__.py"
+  COMMAND "${CMAKE_COMMAND}" -E make_directory 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_thread_plan.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
   COMMENT "Copying lldb.py to pretend its a Python package.")
-add_dependencies(lldb-python-doc-package swig_wrapper_python)
+
+add_dependencies(lldb-python-doc-package swig_wrapper_python lldb-python)
 
 # FIXME: Don't treat Sphinx warnings as errors. The files generated by
 # automodapi are full of warnings (partly caused by SWIG, our documentation
diff --git a/lldb/docs/index.rst b/lldb/docs/index.rst
index 1e7d69002dd3e..3ce23beec2a5e 100644
--- a/lldb/docs/index.rst
+++ b/lldb/docs/index.rst
@@ -141,6 +141,7 @@ interesting areas to contribute to lldb.
use/python
use/python-reference
Python API 
+   Python Extensions 
 
 
 .. toctree::
diff --git a/lldb/docs/python_extensions.rst b/lldb/docs/python_extensions.rst
new file mode 100644
index 0..716e3b066c36f
--- /dev/null
+++ b/lldb/docs/python_extensions.rst
@@ -0,0 +1,36 @@
+Python Extensions
+=
+
+LLDB provides many scriptable extensions to augment the debugger capabilities
+and give the ability to the user to tailor their experience to their own needs.
+
+This page describes some of these scripting extension:
+
+Operating System Thread Plugins
+---
+
+.. automodapi:: lldb.plugins.operating_system
+:no-heading:
+:no-inheritance-diagram:
+
+Scripted Process Plugins
+---
+
+.. automodapi:: lldb.plugins.scripted_process
+:no-heading:
+:no-inheritance-diagram:
+
+Scripted Platform Plugins
+---
+
+.. automodapi:: lldb.plugins.scripted_platform
+:no-heading:
+:no-inheritance-diagram:
+
+Scripted Thread Plan Plugins
+---
+
+.. automodapi:: lldb.plugins.scripted_thread_plan
+:no-heading:
+:no-inheritance-diagram:
+
diff --git a/lldb/examples/python/templates/operating_system.py 
b/lldb/examples/python/templates/operating_system.py
index a8053bcaa21af..d83019079ee90 100644
--- a/lldb/examples/python/templates/operating_system.py
+++ b/lldb/examples/python/templates/operating_system.py
@@ -10,16 +10,16 @@ class OperatingSystem(ScriptedThread):
 """
 Class that provides data for an instance of a LLDB 'OperatingSystemPython' 
plug-in class.
 
-```
-thread_info = {
-"tid": tid,
-"name": "four",
-"queue": "queue4",
-"state": "stopped",
-"stop_reason": "none",
-"core" : 2
-}
-```
+.. code-block:: python
+
+thread_info = {
+"tid": tid,
+"name": 

[Lldb-commits] [lldb] Fix flake in TestZerothFrame.py (PR #96685)

2024-07-02 Thread Pavel Labath via lldb-commits

labath wrote:

> > Looks good. Are you able to merge this on your own?
> 
> Nope, I'll need someone with write access to do it.

Sounds good. Can you just patch the formatter changes in, and then I'll submit 
it.

@bulbazord, if you don't respond, I'm going to assume that new version 
addresses your comments as well.

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


[Lldb-commits] [lldb] [lldb] Don't unregister a listener that's being destroyed (PR #97300)

2024-07-02 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Don't unregister a listener that's being destroyed (PR #97300)

2024-07-02 Thread Pavel Labath via lldb-commits

labath wrote:

Thanks for the explanation. I believe I understand the purpose of the primary 
listener. While I'm not sure that a "shared pointer" is the best way to express 
the "someone must exist on the other end to pull the events" notion, I'm not 
interested in revisiting that decision, so I'll remove that part of the commit 
message.

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


[Lldb-commits] [lldb] 01e96c8 - [lldb] Don't unregister a listener that's being destroyed (#97300)

2024-07-02 Thread via lldb-commits

Author: Pavel Labath
Date: 2024-07-02T10:08:03+02:00
New Revision: 01e96c86497ac9670e1168134870beb99cbd4d8f

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

LOG: [lldb] Don't unregister a listener that's being destroyed (#97300)

It's not necessary because the broadcasters hold a weak_ptr (*) to it,
and will delete the weak_ptr next time they try to lock it. Doing this
prevents recursion in RemoveListener, where the function can end up
holding the only shared_ptr to a listener, and its destruction can
trigger another call to RemoveListener -- which will mess up the state
of the first instance.

This is the same bug that we've have fixed in
https://reviews.llvm.org/D23406, but it was effectively undone in
https://reviews.llvm.org/D157556. With the addition of a primary
listener, a fix like D23406 becomes unwieldy (and it has already shown
itself to be fragile), which is why this patch attempts a different
approach.

Like in 2016, I don't know a good way to unit test this bug, since it
depends on precise timing, but the thing I like about this approach is
that it enables us to change the broadcaster mutex into a non-recursive
one. While that doesn't prevent the bug from happening again, it will
make it much easier to spot in the future, as the code will hang with a
smoking gun (instead of crashing a little while later). I'm going to
attempt that in a separate patch to minimize disruption.

(*) Technically a broadcaster holds the *primary* listener as a
shared_ptr, but that's still ok as it means that listener will not get
destroyed until it is explicitly removed.

Added: 


Modified: 
lldb/source/Utility/Listener.cpp

Removed: 




diff  --git a/lldb/source/Utility/Listener.cpp 
b/lldb/source/Utility/Listener.cpp
index 6a74c530ad257..5aacb4104e1cf 100644
--- a/lldb/source/Utility/Listener.cpp
+++ b/lldb/source/Utility/Listener.cpp
@@ -30,7 +30,7 @@ Listener::Listener(const char *name)
 Listener::~Listener() {
   Log *log = GetLog(LLDBLog::Object);
 
-  Clear();
+  // Don't call Clear() from here as that can cause races. See #96750.
 
   LLDB_LOGF(log, "%p Listener::%s('%s')", static_cast(this),
 __FUNCTION__, m_name.c_str());



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


[Lldb-commits] [lldb] [lldb] Don't unregister a listener that's being destroyed (PR #97300)

2024-07-02 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] Fix type error when calling random.randrange with 'float' arg (PR #97328)

2024-07-02 Thread David Spickett via lldb-commits


@@ -75,7 +75,7 @@ def __init__(self):
 class Pipe(object):
 def __init__(self, prefix):
 while True:
-self.name = "lldb-" + str(random.randrange(1e10))
+self.name = "lldb-" + str(random.randrange(int(1e10)))

DavidSpickett wrote:

FWIW I find it easier to read `e10` than `00`, so I'd also keep the 
style as is.

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


[Lldb-commits] [lldb] [lldb][test] Fix type error when calling random.randrange with 'float' arg (PR #97328)

2024-07-02 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb][test] Fix type error when calling random.randrange with 'float' arg (PR #97328)

2024-07-02 Thread David Spickett via lldb-commits

DavidSpickett wrote:

I'm confused, I don't see this random call in `TestGdbRemoteConnection.py`, but 
I do in 
`lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py`.

Is your branch based off something other than the current `main`?

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


[Lldb-commits] [lldb] [lldb][test] Disable TestUseSourceCache on Windows (PR #97324)

2024-07-02 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb][test] Disable TestUseSourceCache on Windows (PR #97324)

2024-07-02 Thread David Spickett via lldb-commits

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

For a while now our only Windows bot is Linaro's Windows on Arm, so there's 
probably a few of these skips hanging around.

Thanks for finding this one.

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


[Lldb-commits] [lldb] [lldb] Make Broadcaster mutexes non-recursive (PR #97400)

2024-07-02 Thread Pavel Labath via lldb-commits

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

Non-recursive mutexes encourage better locking discipline and avoid bugs like 
#96750, where one can unexpectedly re-enter the critical section on the same 
thread, and interrupt a presumed-indivisible operation.

In this case, the only needed fix was to remove locking from some 
BroadcastManager functions, which were only called from the Listener class (and 
the listener already locked those mutexes to preserve lock ordering).

While doing that, I noticed we don't have unit tests for these functions, so I 
added one.

>From e9de8bde8e2e75e2558f1f14df31f796aa97069d Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Tue, 2 Jul 2024 08:11:38 +
Subject: [PATCH] [lldb] Make Broadcaster mutexes non-recursive

Non-recursive mutexes encourage better locking discipline and avoid bugs
like #96750, where one can unexpectedly re-enter the critical section on
the same thread, and interrupt a presumed-indivisible operation.

In this case, the only needed fix was to remove locking from some
BroadcastManager functions, which were only called from the Listener
class (and the listener already locked those mutexes to preserve lock
ordering).
---
 lldb/include/lldb/Utility/Broadcaster.h | 17 ++-
 lldb/source/Utility/Broadcaster.cpp | 33 ++---
 lldb/source/Utility/Listener.cpp| 12 
 lldb/unittests/Utility/ListenerTest.cpp | 39 +
 4 files changed, 70 insertions(+), 31 deletions(-)

diff --git a/lldb/include/lldb/Utility/Broadcaster.h 
b/lldb/include/lldb/Utility/Broadcaster.h
index 58436ddb9f26d..c6f63f1916573 100644
--- a/lldb/include/lldb/Utility/Broadcaster.h
+++ b/lldb/include/lldb/Utility/Broadcaster.h
@@ -87,12 +87,6 @@ class BroadcasterManager
 
   ~BroadcasterManager() = default;
 
-  uint32_t RegisterListenerForEvents(const lldb::ListenerSP &listener_sp,
- const BroadcastEventSpec &event_spec);
-
-  bool UnregisterListenerForEvents(const lldb::ListenerSP &listener_sp,
-   const BroadcastEventSpec &event_spec);
-
   lldb::ListenerSP
   GetListenerForEventSpec(const BroadcastEventSpec &event_spec) const;
 
@@ -105,13 +99,20 @@ class BroadcasterManager
   void Clear();
 
 private:
+  uint32_t
+  RegisterListenerForEventsNoLock(const lldb::ListenerSP &listener_sp,
+  const BroadcastEventSpec &event_spec);
+
+  bool UnregisterListenerForEventsNoLock(const lldb::ListenerSP &listener_sp,
+ const BroadcastEventSpec &event_spec);
+
   typedef std::pair event_listener_key;
   typedef std::map collection;
   typedef std::set listener_collection;
   collection m_event_map;
   listener_collection m_listeners;
 
-  mutable std::recursive_mutex m_manager_mutex;
+  mutable std::mutex m_manager_mutex;
 };
 
 /// \class Broadcaster Broadcaster.h "lldb/Utility/Broadcaster.h" An event
@@ -441,7 +442,7 @@ class Broadcaster {
 collection m_listeners;
 
 /// A mutex that protects \a m_listeners.
-std::recursive_mutex m_listeners_mutex;
+std::mutex m_listeners_mutex;
 
 /// See the discussion of Broadcasters and Listeners above.
 lldb::ListenerSP m_primary_listener_sp;
diff --git a/lldb/source/Utility/Broadcaster.cpp 
b/lldb/source/Utility/Broadcaster.cpp
index b6d8ae39325d3..c6b2606afe0c8 100644
--- a/lldb/source/Utility/Broadcaster.cpp
+++ b/lldb/source/Utility/Broadcaster.cpp
@@ -87,7 +87,7 @@ bool Broadcaster::BroadcasterImpl::HasListeners(uint32_t 
event_mask) {
 }
 
 void Broadcaster::BroadcasterImpl::Clear() {
-  std::lock_guard guard(m_listeners_mutex);
+  std::lock_guard guard(m_listeners_mutex);
 
   // Make sure the listener forgets about this broadcaster. We do this in the
   // broadcaster in case the broadcaster object initiates the removal.
@@ -137,7 +137,7 @@ Broadcaster::BroadcasterImpl::AddListener(const 
lldb::ListenerSP &listener_sp,
   if (!listener_sp)
 return 0;
 
-  std::lock_guard guard(m_listeners_mutex);
+  std::lock_guard guard(m_listeners_mutex);
 
   // See if we already have this listener, and if so, update its mask
 
@@ -171,7 +171,7 @@ Broadcaster::BroadcasterImpl::AddListener(const 
lldb::ListenerSP &listener_sp,
 }
 
 bool Broadcaster::BroadcasterImpl::EventTypeHasListeners(uint32_t event_type) {
-  std::lock_guard guard(m_listeners_mutex);
+  std::lock_guard guard(m_listeners_mutex);
 
   if (!m_hijacking_listeners.empty() && event_type & m_hijacking_masks.back())
 return true;
@@ -195,7 +195,7 @@ bool Broadcaster::BroadcasterImpl::RemoveListener(
 return true;
   }
 
-  std::lock_guard guard(m_listeners_mutex);
+  std::lock_guard guard(m_listeners_mutex);
   for (auto it = m_listeners.begin(); it != m_listeners.end();) {
 lldb::ListenerSP curr_listener_sp(it->first.lock());
 
@@ -243,7 +243,7 @@ void 
Broadcaster::BroadcasterImpl::PrivateBroadcastEvent(EventSP &event_sp,
 
 

[Lldb-commits] [lldb] [lldb] Make Broadcaster mutexes non-recursive (PR #97400)

2024-07-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

Non-recursive mutexes encourage better locking discipline and avoid bugs like 
#96750, where one can unexpectedly re-enter the critical section on the 
same thread, and interrupt a presumed-indivisible operation.

In this case, the only needed fix was to remove locking from some 
BroadcastManager functions, which were only called from the Listener class (and 
the listener already locked those mutexes to preserve lock ordering).

While doing that, I noticed we don't have unit tests for these functions, so I 
added one.

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


4 Files Affected:

- (modified) lldb/include/lldb/Utility/Broadcaster.h (+9-8) 
- (modified) lldb/source/Utility/Broadcaster.cpp (+15-18) 
- (modified) lldb/source/Utility/Listener.cpp (+7-5) 
- (modified) lldb/unittests/Utility/ListenerTest.cpp (+39) 


``diff
diff --git a/lldb/include/lldb/Utility/Broadcaster.h 
b/lldb/include/lldb/Utility/Broadcaster.h
index 58436ddb9f26d..c6f63f1916573 100644
--- a/lldb/include/lldb/Utility/Broadcaster.h
+++ b/lldb/include/lldb/Utility/Broadcaster.h
@@ -87,12 +87,6 @@ class BroadcasterManager
 
   ~BroadcasterManager() = default;
 
-  uint32_t RegisterListenerForEvents(const lldb::ListenerSP &listener_sp,
- const BroadcastEventSpec &event_spec);
-
-  bool UnregisterListenerForEvents(const lldb::ListenerSP &listener_sp,
-   const BroadcastEventSpec &event_spec);
-
   lldb::ListenerSP
   GetListenerForEventSpec(const BroadcastEventSpec &event_spec) const;
 
@@ -105,13 +99,20 @@ class BroadcasterManager
   void Clear();
 
 private:
+  uint32_t
+  RegisterListenerForEventsNoLock(const lldb::ListenerSP &listener_sp,
+  const BroadcastEventSpec &event_spec);
+
+  bool UnregisterListenerForEventsNoLock(const lldb::ListenerSP &listener_sp,
+ const BroadcastEventSpec &event_spec);
+
   typedef std::pair event_listener_key;
   typedef std::map collection;
   typedef std::set listener_collection;
   collection m_event_map;
   listener_collection m_listeners;
 
-  mutable std::recursive_mutex m_manager_mutex;
+  mutable std::mutex m_manager_mutex;
 };
 
 /// \class Broadcaster Broadcaster.h "lldb/Utility/Broadcaster.h" An event
@@ -441,7 +442,7 @@ class Broadcaster {
 collection m_listeners;
 
 /// A mutex that protects \a m_listeners.
-std::recursive_mutex m_listeners_mutex;
+std::mutex m_listeners_mutex;
 
 /// See the discussion of Broadcasters and Listeners above.
 lldb::ListenerSP m_primary_listener_sp;
diff --git a/lldb/source/Utility/Broadcaster.cpp 
b/lldb/source/Utility/Broadcaster.cpp
index b6d8ae39325d3..c6b2606afe0c8 100644
--- a/lldb/source/Utility/Broadcaster.cpp
+++ b/lldb/source/Utility/Broadcaster.cpp
@@ -87,7 +87,7 @@ bool Broadcaster::BroadcasterImpl::HasListeners(uint32_t 
event_mask) {
 }
 
 void Broadcaster::BroadcasterImpl::Clear() {
-  std::lock_guard guard(m_listeners_mutex);
+  std::lock_guard guard(m_listeners_mutex);
 
   // Make sure the listener forgets about this broadcaster. We do this in the
   // broadcaster in case the broadcaster object initiates the removal.
@@ -137,7 +137,7 @@ Broadcaster::BroadcasterImpl::AddListener(const 
lldb::ListenerSP &listener_sp,
   if (!listener_sp)
 return 0;
 
-  std::lock_guard guard(m_listeners_mutex);
+  std::lock_guard guard(m_listeners_mutex);
 
   // See if we already have this listener, and if so, update its mask
 
@@ -171,7 +171,7 @@ Broadcaster::BroadcasterImpl::AddListener(const 
lldb::ListenerSP &listener_sp,
 }
 
 bool Broadcaster::BroadcasterImpl::EventTypeHasListeners(uint32_t event_type) {
-  std::lock_guard guard(m_listeners_mutex);
+  std::lock_guard guard(m_listeners_mutex);
 
   if (!m_hijacking_listeners.empty() && event_type & m_hijacking_masks.back())
 return true;
@@ -195,7 +195,7 @@ bool Broadcaster::BroadcasterImpl::RemoveListener(
 return true;
   }
 
-  std::lock_guard guard(m_listeners_mutex);
+  std::lock_guard guard(m_listeners_mutex);
   for (auto it = m_listeners.begin(); it != m_listeners.end();) {
 lldb::ListenerSP curr_listener_sp(it->first.lock());
 
@@ -243,7 +243,7 @@ void 
Broadcaster::BroadcasterImpl::PrivateBroadcastEvent(EventSP &event_sp,
 
   const uint32_t event_type = event_sp->GetType();
 
-  std::lock_guard guard(m_listeners_mutex);
+  std::lock_guard guard(m_listeners_mutex);
 
   ListenerSP hijacking_listener_sp;
 
@@ -327,7 +327,7 @@ void 
Broadcaster::BroadcasterImpl::SetPrimaryListener(lldb::ListenerSP
 
 bool Broadcaster::BroadcasterImpl::HijackBroadcaster(
 const lldb::ListenerSP &listener_sp, uint32_t event_mask) {
-  std::lock_guard guard(m_listeners_mutex);
+  std::lock_guard guard(m_listeners_mutex);
 
   Log *log = GetLog(LLDBLog::Events);
   LLDB_LOG(
@@ -341,7 +341,7 @@ bool Broadcaster::Broadcas

[Lldb-commits] [lldb] 54811a9 - [lldb][test] Mark dwp foreign type units test unsupported on Windows

2024-07-02 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2024-07-02T09:19:59Z
New Revision: 54811a9b1194d8239cc28c2a974228ffadf80100

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

LOG: [lldb][test] Mark dwp foreign type units test unsupported on Windows

This test has been flaky on Linaro's Windows on Arm bot:
https://lab.llvm.org/buildbot/#/builders/141/builds/425

Added: 


Modified: 
lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp

Removed: 




diff  --git a/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
index 4df1b33dd7d91..ef15d418b4cfe 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp
@@ -1,4 +1,6 @@
 // REQUIRES: lld
+// Is flaky on Windows.
+// UNSUPPORTED: system-windows
 
 // This test will make a type that will be compiled 
diff erently into two
 // 
diff erent .dwo files in a type unit with the same type hash, but with



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


[Lldb-commits] [lldb] [lldb/Commands] Alias `script` command to `scripting run` (PR #97263)

2024-07-02 Thread David Spickett via lldb-commits

DavidSpickett wrote:

I've 
[disabled](https://github.com/llvm/llvm-project/commit/54811a9b1194d8239cc28c2a974228ffadf80100)
 the test on Windows and Linaro will look into it.

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


[Lldb-commits] [lldb] Fix the test to deal with non-deterministic output. (PR #96800)

2024-07-02 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Linaro has also seen it failing on our Windows on Arm bot: 
https://lab.llvm.org/buildbot/#/builders/141/builds/425

I've disabled the test 
(https://github.com/llvm/llvm-project/commit/54811a9b1194d8239cc28c2a974228ffadf80100)
 and one of my colleagues is going to look into it.

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


[Lldb-commits] [lldb] [lldb][test] Disable TestUseSourceCache on Windows (PR #97324)

2024-07-02 Thread David Spickett via lldb-commits

DavidSpickett wrote:

There is a skipIfWindows decorator that could be used instead but it's the same 
thing anyway, going to merge this as is.

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


[Lldb-commits] [lldb] 2da1095 - [lldb][test] Disable TestUseSourceCache on Windows (#97324)

2024-07-02 Thread via lldb-commits

Author: Kendal Harland
Date: 2024-07-02T11:06:12+01:00
New Revision: 2da10959e00a81b983a0ea6d5c1ba9e0f2e1f192

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

LOG: [lldb][test] Disable TestUseSourceCache on Windows (#97324)

This test also fails on Windows amd64, although it is only disabled for
aarch64.

Co-authored-by: kendal 

Added: 


Modified: 
lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py

Removed: 




diff  --git 
a/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py 
b/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py
index c54345af4994c..421599080a9e5 100644
--- a/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py
+++ b/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py
@@ -18,7 +18,7 @@ def test_set_use_source_cache_false(self):
 self.set_use_source_cache_and_test(False)
 
 @skipIf(hostoslist=no_match(["windows"]))
-@skipIf(oslist=["windows"], archs=["aarch64"])  # Fails on windows 11
+@skipIf(oslist=["windows"])  # Fails on windows 11
 def test_set_use_source_cache_true(self):
 """Test that after 'set use-source-cache false', files are locked."""
 self.set_use_source_cache_and_test(True)



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


[Lldb-commits] [lldb] [lldb][test] Disable TestUseSourceCache on Windows (PR #97324)

2024-07-02 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb][test] Disable TestUseSourceCache on Windows (PR #97324)

2024-07-02 Thread via lldb-commits

github-actions[bot] wrote:



@kendalharland Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[Lldb-commits] [lldb] [lldb][AArch64] Add register field enum information (PR #96887)

2024-07-02 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett updated 
https://github.com/llvm/llvm-project/pull/96887

>From 3bb90e95fcefa986a0b375487072b775cb45ce69 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Mon, 11 Mar 2024 10:56:50 +
Subject: [PATCH] [lldb][AArch64] Add register field enum information

This enables XML output for enums and adds enums for 2 fields
on AArch64:
* mte_ctrl.tcf, which controls how tag faults are delivered.
* fpcr.rmode, which sets the rounding mode for floating point operations.

The other one we could do is cpsr.btype, but it is not
clear what would be useful here so I'm not including it
in this change.
---
 .../Process/Utility/RegisterFlagsDetector_arm64.cpp | 12 +---
 .../gdb-remote/GDBRemoteCommunicationServerLLGS.cpp |  2 ++
 .../register/register_command/TestRegisters.py  |  8 +++-
 .../postmortem/elf-core/TestLinuxCore.py|  7 ++-
 .../TestAArch64LinuxMTEMemoryTagCoreFile.py | 13 ++---
 .../Core/aarch64-freebsd-register-fields.test   |  2 +-
 6 files changed, 35 insertions(+), 9 deletions(-)

diff --git 
a/lldb/source/Plugins/Process/Utility/RegisterFlagsDetector_arm64.cpp 
b/lldb/source/Plugins/Process/Utility/RegisterFlagsDetector_arm64.cpp
index 024c6ad208689..7c8dba3680938 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterFlagsDetector_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterFlagsDetector_arm64.cpp
@@ -53,16 +53,22 @@ Arm64RegisterFlagsDetector::DetectMTECtrlFields(uint64_t 
hwcap,
   // Represents the contents of NT_ARM_TAGGED_ADDR_CTRL and the value passed
   // to prctl(PR_TAGGED_ADDR_CTRL...). Fields are derived from the defines
   // used to build the value.
+
+  static const FieldEnum tcf_enum(
+  "tcf_enum",
+  {{0, "TCF_NONE"}, {1, "TCF_SYNC"}, {2, "TCF_ASYNC"}, {3, "TCF_ASYMM"}});
   return {{"TAGS", 3, 18}, // 16 bit bitfield shifted up by PR_MTE_TAG_SHIFT.
-  {"TCF_ASYNC", 2},
-  {"TCF_SYNC", 1},
+  {"TCF", 1, 2, &tcf_enum},
   {"TAGGED_ADDR_ENABLE", 0}};
 }
 
 Arm64RegisterFlagsDetector::Fields
 Arm64RegisterFlagsDetector::DetectFPCRFields(uint64_t hwcap, uint64_t hwcap2) {
+  static const FieldEnum rmode_enum(
+  "rmode_enum", {{0, "RN"}, {1, "RP"}, {2, "RM"}, {3, "RZ"}});
+
   std::vector fpcr_fields{
-  {"AHP", 26}, {"DN", 25}, {"FZ", 24}, {"RMode", 22, 23},
+  {"AHP", 26}, {"DN", 25}, {"FZ", 24}, {"RMode", 22, 23, &rmode_enum},
   // Bits 21-20 are "Stride" which is unused in AArch64 state.
   };
 
diff --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index ae1a77e5be832..08d5f5039d516 100644
--- 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -3083,6 +3083,7 @@ GDBRemoteCommunicationServerLLGS::BuildTargetXml() {
   if (registers_count)
 response.IndentMore();
 
+  llvm::StringSet<> field_enums_seen;
   for (int reg_index = 0; reg_index < registers_count; reg_index++) {
 const RegisterInfo *reg_info =
 reg_context.GetRegisterInfoAtIndex(reg_index);
@@ -3096,6 +3097,7 @@ GDBRemoteCommunicationServerLLGS::BuildTargetXml() {
 
 if (reg_info->flags_type) {
   response.IndentMore();
+  reg_info->flags_type->EnumsToXML(response, field_enums_seen);
   reg_info->flags_type->ToXML(response);
   response.IndentLess();
 }
diff --git 
a/lldb/test/API/commands/register/register/register_command/TestRegisters.py 
b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
index dd887740c3c12..d1fc3e100af33 100644
--- a/lldb/test/API/commands/register/register/register_command/TestRegisters.py
+++ b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
@@ -632,7 +632,13 @@ def test_register_read_fields(self):
 self.expect("register read fpsr", substrs=["= (QC = 0, IDC = 0, IXC = 
0"])
 # AHP/DN/FZ/RMode always present, others may vary.
 self.expect(
-"register read fpcr", substrs=["= (AHP = 0, DN = 0, FZ = 0, RMode 
= 0"]
+"register read fpcr", substrs=["= (AHP = 0, DN = 0, FZ = 0, RMode 
= RN"]
+)
+
+# Should get enumerator descriptions for RMode.
+self.expect(
+"register info fpcr",
+substrs=["RMode: 0 = RN, 1 = RP, 2 = RM, 3 = RZ"],
 )
 
 @skipUnlessPlatform(["linux"])
diff --git a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py 
b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
index 1eaaa87d3b87d..0afac26367de0 100644
--- a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
+++ b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
@@ -583,7 +583,12 @@ def test_aarch64_sve_regs_full(self):
 self.expect("register read fpsr", substrs=["= (QC = 0, IDC = 0, 

[Lldb-commits] [lldb] [lldb][AArch64] Add register field enum information (PR #96887)

2024-07-02 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Rebased as FreeBSD support went in yesterday and moved some files about.

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


[Lldb-commits] [lldb] [lldb][test] Fix type error when calling random.randrange with 'float' arg (PR #97328)

2024-07-02 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

Looks good, but note that this file was moved (to 
`packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py`) 
recently, so you'll need to rebase this PR to HEAD.

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


[Lldb-commits] [lldb] [lldb][test] Fix type error when calling random.randrange with 'float' arg (PR #97328)

2024-07-02 Thread Pavel Labath via lldb-commits


@@ -75,7 +75,7 @@ def __init__(self):
 class Pipe(object):
 def __init__(self, prefix):
 while True:
-self.name = "lldb-" + str(random.randrange(1e10))
+self.name = "lldb-" + str(random.randrange(int(1e10)))

labath wrote:

How about `10**10` ?

(As the "original author" ;), I'm not really sure what happened here. I'm 
pretty sure I did not write a huge blob of windows-specific code without 
testing it. It could be that newer python versions got more string about typing 
or sth...)

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


[Lldb-commits] [lldb] [lldb][test] Fix type error when calling random.randrange with 'float' arg (PR #97328)

2024-07-02 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] Fix test assertions in TestDAP_stepInTargets.py (PR #96687)

2024-07-02 Thread Pavel Labath via lldb-commits

labath wrote:

This looks fine to me. @jeffreytan81  ?

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


[Lldb-commits] [lldb] [lldb/Commands] Alias `script` command to `scripting run` (PR #97263)

2024-07-02 Thread Dave Lee via lldb-commits

kastiglione wrote:

> The problem with this command is that it either executes a script given to it 
> on the command line, or it runs the embedded script interpreter...

I don't see the problem. The original `script` does both of those things, and 
`run` works fits those two use case as well or better than `execute`, in my 
opinion.

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


[Lldb-commits] [lldb] [lldb/Commands] Alias `script` command to `scripting run` (PR #97263)

2024-07-02 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

> > The problem with this command is that it either executes a script given to 
> > it on the command line, or it runs the embedded script interpreter...
> 
> 
> 
> I don't see the problem. The original `script` does both of those things, and 
> `run` fits those two use case as well or better than `execute`, in my opinion.

I don't know if you saw but I actually changed the command to be `scripting 
run` before landing this 😅

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


[Lldb-commits] [lldb] [lldb/Commands] Alias `script` command to `scripting run` (PR #97263)

2024-07-02 Thread Dave Lee via lldb-commits

kastiglione wrote:

@medismailben 👍 I saw, and also wanted to reply to Jim.

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


[Lldb-commits] [lldb] [LLDB] DebugInfoD tests: attempt to fix Fuchsia build (PR #96802)

2024-07-02 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei updated 
https://github.com/llvm/llvm-project/pull/96802

>From 95832768ffb3b115e95df19ae5ef14231cad32cc Mon Sep 17 00:00:00 2001
From: Kevin Frei 
Date: Mon, 25 Mar 2024 08:23:47 -0700
Subject: [PATCH 01/13] Trying to deal with Linux AArch64 test failures :/

---
 .../SymbolVendor/ELF/SymbolVendorELF.cpp  |  18 ++
 .../API/debuginfod/Normal/TestDebuginfod.py   | 187 +
 .../SplitDWARF/TestDebuginfodDWP.py   | 196 ++
 3 files changed, 401 insertions(+)
 create mode 100644 lldb/test/API/debuginfod/Normal/TestDebuginfod.py
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py

diff --git a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp 
b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
index b5fe35d71032a..a881218a56cef 100644
--- a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
+++ b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
@@ -44,6 +44,24 @@ llvm::StringRef 
SymbolVendorELF::GetPluginDescriptionStatic() {
  "executables.";
 }
 
+// If this is needed elsewhere, it can be exported/moved.
+static bool IsDwpSymbolFile(const lldb::ModuleSP &module_sp,
+const FileSpec &file_spec) {
+  DataBufferSP dwp_file_data_sp;
+  lldb::offset_t dwp_file_data_offset = 0;
+  // Try to create an ObjectFile from the file_spec.
+  ObjectFileSP dwp_obj_file = ObjectFile::FindPlugin(
+  module_sp, &file_spec, 0, FileSystem::Instance().GetByteSize(file_spec),
+  dwp_file_data_sp, dwp_file_data_offset);
+  // The presence of a debug_cu_index section is the key identifying feature of
+  // a DWP file. Make sure we don't fill in the section list on dwp_obj_file
+  // (by calling GetSectionList(false)) as this is invoked before we may have
+  // all the symbol files collected and available.
+  return dwp_obj_file && ObjectFileELF::classof(dwp_obj_file.get()) &&
+ dwp_obj_file->GetSectionList(false)->FindSectionByType(
+ eSectionTypeDWARFDebugCuIndex, false);
+}
+
 // CreateInstance
 //
 // Platforms can register a callback to use when creating symbol vendors to
diff --git a/lldb/test/API/debuginfod/Normal/TestDebuginfod.py 
b/lldb/test/API/debuginfod/Normal/TestDebuginfod.py
new file mode 100644
index 0..a662fb9fc6e68
--- /dev/null
+++ b/lldb/test/API/debuginfod/Normal/TestDebuginfod.py
@@ -0,0 +1,187 @@
+import os
+import shutil
+import tempfile
+import struct
+
+import lldb
+from lldbsuite.test.decorators import *
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+def getUUID(aoutuuid):
+"""
+Pull the 20 byte UUID out of the .note.gnu.build-id section that was dumped
+to a file already, as part of the build.
+"""
+with open(aoutuuid, "rb") as f:
+data = f.read(36)
+if len(data) != 36:
+return None
+header = struct.unpack_from("<4I", data)
+if len(header) != 4:
+return None
+# 4 element 'prefix', 20 bytes of uuid, 3 byte long string: 'GNU':
+if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 
0x554E47:
+return None
+return data[16:].hex()
+
+
+"""
+Test support for the DebugInfoD network symbol acquisition protocol.
+This one is for simple / no split-dwarf scenarios.
+
+For no-split-dwarf scenarios, there are 2 variations:
+1 - A stripped binary with it's corresponding unstripped binary:
+2 - A stripped binary with a corresponding --only-keep-debug symbols file
+"""
+
+
+@skipUnlessPlatform(["linux", "freebsd"])
+class DebugInfodTests(TestBase):
+# No need to try every flavor of debug inf.
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_normal_no_symbols(self):
+"""
+Validate behavior with no symbols or symbol locator.
+('baseline negative' behavior)
+"""
+test_root = self.config_test(["a.out"])
+self.try_breakpoint(False)
+
+def test_normal_default(self):
+"""
+Validate behavior with symbols, but no symbol locator.
+('baseline positive' behavior)
+"""
+test_root = self.config_test(["a.out", "a.out.debug"])
+self.try_breakpoint(True)
+
+def test_debuginfod_symbols(self):
+"""
+Test behavior with the full binary available from Debuginfod as
+'debuginfo' from the plug-in.
+"""
+test_root = self.config_test(["a.out"], "a.out.full")
+self.try_breakpoint(True)
+
+def test_debuginfod_executable(self):
+"""
+Test behavior with the full binary available from Debuginfod as
+'executable' from the plug-in.
+"""
+test_root = self.config_test(["a.out"], None, "a.out.full")
+self.try_breakpoint(True)
+
+def test_debuginfod_okd_symbols(self):
+"""
+Test behavior with the 'only-keep-debug' symbols available from 
Debuginfod.
+"""
+  

[Lldb-commits] [lldb] fix issue with debug-types-dwo-cross-reference.cpp.tmp test (PR #97381)

2024-07-02 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere requested changes to this pull request.

https://github.com/llvm/llvm-project/issues/97380#issuecomment-2203028709

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-02 Thread via lldb-commits

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

>From c703c473147e3e554a98014319294668a0ec790d Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Sun, 16 Jun 2024 16:32:47 -0700
Subject: [PATCH 1/3] [LLDB] Add AST node classes, functions, etc. for Data
 Inspection Language (DIL).

The Data Inspection Language (DIL), described in
https://discourse.llvm.org/t/rfc-data-inspection-language/69893 includes
its own parser and expression evaluator.

This change defines the AST nodes, classes and functions which are used by the
DIL parser and expression evaluator. It also adds the .ebnf file documenting
the (current) expression language handled by the DIL parser and expression
evaluator.
---
 lldb/docs/dil-expr-lang.ebnf| 165 
 lldb/include/lldb/Core/DILAST.h | 690 
 lldb/source/Core/CMakeLists.txt |   1 +
 lldb/source/Core/DILAST.cpp | 568 ++
 4 files changed, 1424 insertions(+)
 create mode 100644 lldb/docs/dil-expr-lang.ebnf
 create mode 100644 lldb/include/lldb/Core/DILAST.h
 create mode 100644 lldb/source/Core/DILAST.cpp

diff --git a/lldb/docs/dil-expr-lang.ebnf b/lldb/docs/dil-expr-lang.ebnf
new file mode 100644
index 0..40c678c25cda5
--- /dev/null
+++ b/lldb/docs/dil-expr-lang.ebnf
@@ -0,0 +1,165 @@
+(* LLDB Debug Expressions, a subset of C++ *)
+(* Insired by https://www.nongnu.org/hcb *)
+
+expression = assignment_expression ;
+
+assignment_expression = conditional_expression
+logical_or_expression assignment_operator 
assignment_expression ;
+
+assignment_operator = "="
+| "*="
+| "/="
+| "%="
+| "+="
+| "-="
+| ">>="
+| "<<="
+| "&="
+| "^="
+| "|=" ;
+
+conditional_expression = logical_or_expression
+   | logical_or_expression "?" expression ":" 
assignment_expression ;
+
+logical_or_expression = logical_and_expression {"||" logical_and_expression} ;
+
+logical_and_expression = inclusive_or_expression {"&&" 
inclusive_or_expression} ;
+
+inclusive_or_expression = exclusive_or_expression {"|" 
exclusive_or_expression} ;
+
+exclusive_or_expression = and_expression {"^" and_expression} ;
+
+and_expression = equality_expression {"&" equality_expression} ;
+
+equality_expression = relational_expression {"==" relational_expression}
+| relational_expression {"!=" relational_expression} ;
+
+relational_expression = shift_expression {"<" shift_expression}
+  | shift_expression {">" shift_expression}
+  | shift_expression {"<=" shift_expression}
+  | shift_expression {">=" shift_expression} ;
+
+shift_expression = additive_expression {"<<" additive_expression}
+ | additive_expression {">>" additive_expression} ;
+
+additive_expression = multiplicative_expression {"+" multiplicative_expression}
+| multiplicative_expression {"-" 
multiplicative_expression} ;
+
+multiplicative_expression = cast_expression {"*" cast_expression}
+  | cast_expression {"/" cast_expression}
+  | cast_expression {"%" cast_expression} ;
+
+cast_expression = unary_expression
+| "(" type_id ")" cast_expression ;
+
+unary_expression = postfix_expression
+ | "++" cast_expression
+ | "--" cast_expression
+ | unary_operator cast_expression
+ | "sizeof" unary_expression
+ | "sizeof" "(" type_id ")" ;
+
+unary_operator = "*" | "&" | "+" | "-" | "!" | "~" ;
+
+postfix_expression = primary_expression
+   | postfix_expression "[" expression "]"
+   | postfix_expression "." id_expression
+   | postfix_expression "->" id_expression
+   | postfix_expression "++"
+   | postfix_expression "--"
+   | static_cast "<" type_id ">" "(" expression ")" ;
+   | dynamic_cast "<" type_id ">" "(" expression ")" ;
+   | reinterpret_cast "<" type_id ">" "(" expression ")" ;
+
+primary_expression = numeric_literal
+   | boolean_literal
+   | pointer_literal
+   | id_expression
+   | "this"
+   | "(" expression ")"
+   | builtin_func ;
+
+type_id = type_specifier_seq [abstract_declarator] ;
+
+type_specifier_seq = type_specifier [type_specifier_seq] ;
+
+type_specifier = simple_type_specifier
+   | cv_qualifier ;
+
+simple_type_specifier = ["::"] [nested_name_specifier] type_name
+  | "char"
+  | "char16_t"
+  | "char32_t"
+  | "wchar_t"
+  

[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-02 Thread via lldb-commits

cmtice wrote:

As requested, I have updated this PR to only include the pieces needed to 
reproduce current (default) 'frame variable' behavior with DIL.  I have also 
updated the BNF file accordingly. 

I agree with Jim re the DIL language: We should only have a single language 
definition, and it can be a superset of the languages  it supports. So there 
may be parts of it that belong to particular languages, but that does not mean 
it supports those languages exclusively.

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-02 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 436872693a8a57487bf4510437183878d1e35cfb 
c230c2844814b0edcf90c0b62dd8030cd6a5a0a8 -- lldb/include/lldb/Core/DILAST.h 
lldb/source/Core/DILAST.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/include/lldb/Core/DILAST.h b/lldb/include/lldb/Core/DILAST.h
index 6b61157201..0bc4309826 100644
--- a/lldb/include/lldb/Core/DILAST.h
+++ b/lldb/include/lldb/Core/DILAST.h
@@ -91,9 +91,9 @@ enum class CStyleCastKind {
 
 /// The Unary operators recognized by DIL.
 enum class UnaryOpKind {
-  AddrOf,  // "&"
-  Deref,   // "*"
-  Minus,   // "-"
+  AddrOf, // "&"
+  Deref,  // "*"
+  Minus,  // "-"
 };
 
 /// Given a string representing a type, returns the CompilerType corresponding

``




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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

2024-07-02 Thread via lldb-commits

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

>From c703c473147e3e554a98014319294668a0ec790d Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Sun, 16 Jun 2024 16:32:47 -0700
Subject: [PATCH 1/4] [LLDB] Add AST node classes, functions, etc. for Data
 Inspection Language (DIL).

The Data Inspection Language (DIL), described in
https://discourse.llvm.org/t/rfc-data-inspection-language/69893 includes
its own parser and expression evaluator.

This change defines the AST nodes, classes and functions which are used by the
DIL parser and expression evaluator. It also adds the .ebnf file documenting
the (current) expression language handled by the DIL parser and expression
evaluator.
---
 lldb/docs/dil-expr-lang.ebnf| 165 
 lldb/include/lldb/Core/DILAST.h | 690 
 lldb/source/Core/CMakeLists.txt |   1 +
 lldb/source/Core/DILAST.cpp | 568 ++
 4 files changed, 1424 insertions(+)
 create mode 100644 lldb/docs/dil-expr-lang.ebnf
 create mode 100644 lldb/include/lldb/Core/DILAST.h
 create mode 100644 lldb/source/Core/DILAST.cpp

diff --git a/lldb/docs/dil-expr-lang.ebnf b/lldb/docs/dil-expr-lang.ebnf
new file mode 100644
index 0..40c678c25cda5
--- /dev/null
+++ b/lldb/docs/dil-expr-lang.ebnf
@@ -0,0 +1,165 @@
+(* LLDB Debug Expressions, a subset of C++ *)
+(* Insired by https://www.nongnu.org/hcb *)
+
+expression = assignment_expression ;
+
+assignment_expression = conditional_expression
+logical_or_expression assignment_operator 
assignment_expression ;
+
+assignment_operator = "="
+| "*="
+| "/="
+| "%="
+| "+="
+| "-="
+| ">>="
+| "<<="
+| "&="
+| "^="
+| "|=" ;
+
+conditional_expression = logical_or_expression
+   | logical_or_expression "?" expression ":" 
assignment_expression ;
+
+logical_or_expression = logical_and_expression {"||" logical_and_expression} ;
+
+logical_and_expression = inclusive_or_expression {"&&" 
inclusive_or_expression} ;
+
+inclusive_or_expression = exclusive_or_expression {"|" 
exclusive_or_expression} ;
+
+exclusive_or_expression = and_expression {"^" and_expression} ;
+
+and_expression = equality_expression {"&" equality_expression} ;
+
+equality_expression = relational_expression {"==" relational_expression}
+| relational_expression {"!=" relational_expression} ;
+
+relational_expression = shift_expression {"<" shift_expression}
+  | shift_expression {">" shift_expression}
+  | shift_expression {"<=" shift_expression}
+  | shift_expression {">=" shift_expression} ;
+
+shift_expression = additive_expression {"<<" additive_expression}
+ | additive_expression {">>" additive_expression} ;
+
+additive_expression = multiplicative_expression {"+" multiplicative_expression}
+| multiplicative_expression {"-" 
multiplicative_expression} ;
+
+multiplicative_expression = cast_expression {"*" cast_expression}
+  | cast_expression {"/" cast_expression}
+  | cast_expression {"%" cast_expression} ;
+
+cast_expression = unary_expression
+| "(" type_id ")" cast_expression ;
+
+unary_expression = postfix_expression
+ | "++" cast_expression
+ | "--" cast_expression
+ | unary_operator cast_expression
+ | "sizeof" unary_expression
+ | "sizeof" "(" type_id ")" ;
+
+unary_operator = "*" | "&" | "+" | "-" | "!" | "~" ;
+
+postfix_expression = primary_expression
+   | postfix_expression "[" expression "]"
+   | postfix_expression "." id_expression
+   | postfix_expression "->" id_expression
+   | postfix_expression "++"
+   | postfix_expression "--"
+   | static_cast "<" type_id ">" "(" expression ")" ;
+   | dynamic_cast "<" type_id ">" "(" expression ")" ;
+   | reinterpret_cast "<" type_id ">" "(" expression ")" ;
+
+primary_expression = numeric_literal
+   | boolean_literal
+   | pointer_literal
+   | id_expression
+   | "this"
+   | "(" expression ")"
+   | builtin_func ;
+
+type_id = type_specifier_seq [abstract_declarator] ;
+
+type_specifier_seq = type_specifier [type_specifier_seq] ;
+
+type_specifier = simple_type_specifier
+   | cv_qualifier ;
+
+simple_type_specifier = ["::"] [nested_name_specifier] type_name
+  | "char"
+  | "char16_t"
+  | "char32_t"
+  | "wchar_t"
+  

[Lldb-commits] [lldb] Fix test assertions in TestDAP_stepInTargets.py (PR #96687)

2024-07-02 Thread via lldb-commits

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

Sorry, was in the middle of review then got interrupted/distracted by other 
stuff yesterday.

Looks good.

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


[Lldb-commits] [lldb] [lldb] [ObjectFileELF] Detect QNX Neutrino RTOS targets (PR #97439)

2024-07-02 Thread Ayush Sahay via lldb-commits

https://github.com/ayushsahay1837 created 
https://github.com/llvm/llvm-project/pull/97439

This change detects _QNX Neutrino Real-Time Operating System_ targets, and is 
the second in a series of changes that look to facilitate remote debug of 
_AArch64_ targets on _QNX_.

_QNX Neutrino Real-Time Operating System_ is a commercial Unix-like real-time 
operating system primarily targeting the embedded systems market including 
automotive, medical devices, robotics, transportation, and industrial embedded 
systems.

The series of changes in question looks to provision support for –

- Launching a debuggee
- Attaching to a debuggee
- Having the debuggee come up stopped at the entry point
- Setting breakpoints
- Stopping at breakpoints
- Reading/writing contents of/to the debuggee's memory
- Reading/writing contents of/to the debuggee's registers
- Reading/writing contents of/to the debuggee's variables
- Resuming the debuggee's execution
- Single-stepping the debuggee's execution
- Interrupting the debuggee's execution
- Dumping information pertaining to the debuggee's stack trace

Kindly note that _ptrace_ isn't available on _QNX_. Instead, _devctl_ can be 
leveraged to observe and control the execution of a process under debug on 
_QNX_.

Any additional support (including the facilitation of execution of tests) will 
be the subject of future work.

>From f28581bb6897395adf4b2202db4a3e772ecacff9 Mon Sep 17 00:00:00 2001
From: Ted Woodward 
Date: Fri, 18 Aug 2023 17:56:00 -0500
Subject: [PATCH] [lldb] [ObjectFileELF] Detect QNX Neutrino RTOS targets

Detect QNX Neutrino Real-Time Operating System targets and duly set the
operating system component of the triple.
---
 lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 5c6b475044be5..c9918cfc0f57e 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -66,6 +66,7 @@ static const char *const LLDB_NT_OWNER_OPENBSD = "OpenBSD";
 static const char *const LLDB_NT_OWNER_ANDROID = "Android";
 static const char *const LLDB_NT_OWNER_CORE = "CORE";
 static const char *const LLDB_NT_OWNER_LINUX = "LINUX";
+static const char *const LLDB_NT_OWNER_QNX = "QNX";
 
 // ELF note type definitions
 static const elf_word LLDB_NT_FREEBSD_ABI_TAG = 0x01;
@@ -1284,6 +1285,8 @@ 
ObjectFileELF::RefineModuleDetailsFromNote(lldb_private::DataExtractor &data,
   // cases (e.g. compile with -nostdlib) Hence set OS to Linux
   arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
   }
+} else if (note.n_name == LLDB_NT_OWNER_QNX) {
+  arch_spec.GetTriple().setOS(llvm::Triple::OSType::QNX);
 }
 
 // Calculate the offset of the next note just in case "offset" has been

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


[Lldb-commits] [lldb] [lldb] [ObjectFileELF] Detect QNX Neutrino RTOS targets (PR #97439)

2024-07-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Ayush Sahay (ayushsahay1837)


Changes

This change detects _QNX Neutrino Real-Time Operating System_ targets, and is 
the second in a series of changes that look to facilitate remote debug of 
_AArch64_ targets on _QNX_.

_QNX Neutrino Real-Time Operating System_ is a commercial Unix-like real-time 
operating system primarily targeting the embedded systems market including 
automotive, medical devices, robotics, transportation, and industrial embedded 
systems.

The series of changes in question looks to provision support for –

- Launching a debuggee
- Attaching to a debuggee
- Having the debuggee come up stopped at the entry point
- Setting breakpoints
- Stopping at breakpoints
- Reading/writing contents of/to the debuggee's memory
- Reading/writing contents of/to the debuggee's registers
- Reading/writing contents of/to the debuggee's variables
- Resuming the debuggee's execution
- Single-stepping the debuggee's execution
- Interrupting the debuggee's execution
- Dumping information pertaining to the debuggee's stack trace

Kindly note that _ptrace_ isn't available on _QNX_. Instead, _devctl_ can be 
leveraged to observe and control the execution of a process under debug on 
_QNX_.

Any additional support (including the facilitation of execution of tests) will 
be the subject of future work.

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


1 Files Affected:

- (modified) lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (+3) 


``diff
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 5c6b475044be5..c9918cfc0f57e 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -66,6 +66,7 @@ static const char *const LLDB_NT_OWNER_OPENBSD = "OpenBSD";
 static const char *const LLDB_NT_OWNER_ANDROID = "Android";
 static const char *const LLDB_NT_OWNER_CORE = "CORE";
 static const char *const LLDB_NT_OWNER_LINUX = "LINUX";
+static const char *const LLDB_NT_OWNER_QNX = "QNX";
 
 // ELF note type definitions
 static const elf_word LLDB_NT_FREEBSD_ABI_TAG = 0x01;
@@ -1284,6 +1285,8 @@ 
ObjectFileELF::RefineModuleDetailsFromNote(lldb_private::DataExtractor &data,
   // cases (e.g. compile with -nostdlib) Hence set OS to Linux
   arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
   }
+} else if (note.n_name == LLDB_NT_OWNER_QNX) {
+  arch_spec.GetTriple().setOS(llvm::Triple::OSType::QNX);
 }
 
 // Calculate the offset of the next note just in case "offset" has been

``




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


[Lldb-commits] [clang] [lldb] [clang][RecordLayoutBuilder] Be stricter about inferring packed-ness in ExternalLayouts (PR #97443)

2024-07-02 Thread Michael Buch via lldb-commits

https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/97443

This patch is motivated by the LLDB support required for: 
https://github.com/llvm/llvm-project/issues/93069

In the presence of `[[no_unique_address]]`, LLDB may ask Clang to lay out types 
with overlapping field offsets. Because we don't have attributes such as 
`packed` or `no_unique_address` in the LLDB AST, the `RecordLayoutBuilder` 
supports an `InferAlignment` mode, which, in the past, attempted to detect 
layouts which came from packed structures in order to provide a conservative 
estimate of alignment for it (since `DW_AT_alignment` isn't emitted unless 
explicitly changed with `alignas`, etc.).

However, in the presence of overlapping fields due to `no_unique_address`, 
`InferAlignment` would set the alignment of structures to `1` for which that's 
incorrect. This poses issues in some LLDB formatters that synthesize new Clang 
types and rely on the layout builder to get the `FieldOffset` of structures 
right that we did have DWARF offsets for. The result of this is that if we get 
the alignment wrong, LLDB reads out garbage data from the wrong field offsets.

There are a couple of solutions to this that we considered:
1. Make LLDB formatters not do the above, and make them more robust to 
inaccurate alignment.
2. Remove `InferAlignment` entirely and rely on Clang emitting 
`DW_AT_alignment` for packed structures.
3. Remove `InferAlignment` and detect packedness from within LLDB.
4. Make the `InferAlignment` logic account for overlapping fields.

Option (1) turned out quite hairy and it's not clear we can achieve this with 
the tools available for certain STL formatters (particularly `std::map`). But I 
would still very much like to simplify this if we can.

Option (2) wouldn't help with GCC-compiled binaries, and if we can get away 
with LLDB not needing the alignment, then we wouldn't need to increase 
debug-info size.

Option (3), AFAICT, would require us to reimplement some of the layout logic in 
the layout builder. Would be great if we can avoid this added complexity.

Option (4) seemed like the best option in the interim. As part of this change I 
also removed one of the `InferAlignment` blocks. The test-cases associated with 
this code-path pass regardless, and from the description of the change that 
introduced it it's not clear why specifically the base offsets would influence 
the `Alignment` field, and how it would imply packedness. But happy to be 
proven wrong. Ultimately it would be great if we can get rid of the 
`InferAlignment` infrastructure and support our use-cases in LLDB or DWARF 
instead.

>From 3a718c75d0458b7aece72f2ba8e5aa5a68815237 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 2 Jul 2024 18:43:34 +0200
Subject: [PATCH] [clang][RecordLayoutBuilder] Be stricter about inferring
 packed-ness in ExternalLayouts

This patch is motivated by the LLDB support required for:
https://github.com/llvm/llvm-project/issues/93069

In the presence of `[[no_unique_address]]`, LLDB may ask Clang
to lay out types with overlapping field offsets. Because we don't
have attributes such as `packed` or `no_unique_address` in the LLDB
AST, the `RecordLayoutBuilder` supports an `InferAlignment` mode, which,
in the past, attempted to detect layouts which came from packed
structures in order to provide a conservative estimate of alignment for
it (since `DW_AT_alignment` isn't emitted unless explicitly changed with
`alignas`, etc.).

However, in the presence of overlapping fields due to `no_unique_address`,
`InferAlignment` would set the alignment of structures to `1` for which
that's incorrect. This poses issues in some LLDB formatters that
synthesize new Clang types and rely on the layout builder to get the
`FieldOffset` of structures right that we did have DWARF offsets for.
The result of this is that if we get the alignment wrong, LLDB reads
out garbage data from the wrong field offsets.

There are a couple of solutions to this that we considered:
1. Make LLDB formatters not do the above, and make them more robust
   to inaccurate alignment.
2. Remove `InferAlignment` entirely and rely on Clang emitting
   `DW_AT_alignment` for packed structures.
3. Remove `InferAlignment` and detect packedness from within LLDB.
4. Make the `InferAlignment` logic account for overlapping fields.

Option (1) turned out quite hairy and it's not clear we can achieve
this with the tools available for certain STL formatters (particularly
`std::map`). But I would still very much like to simplify this if we
can.

Option (2) wouldn't help with GCC-compiled binaries, and if we can
get away with LLDB not needing the alignment, then we wouldn't need
to increase debug-info size.

Option (3), AFAICT, would require us to reimplement some of the layout
logic in the layout builder. Would be great if we can avoid this added
complexity.

Option (4) seemed like the best option in the interim. As part of this
change I also removed one o

[Lldb-commits] [clang] [lldb] [clang][RecordLayoutBuilder] Be stricter about inferring packed-ness in ExternalLayouts (PR #97443)

2024-07-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Michael Buch (Michael137)


Changes

This patch is motivated by the LLDB support required for: 
https://github.com/llvm/llvm-project/issues/93069

In the presence of `[[no_unique_address]]`, LLDB may ask Clang to lay out types 
with overlapping field offsets. Because we don't have attributes such as 
`packed` or `no_unique_address` in the LLDB AST, the `RecordLayoutBuilder` 
supports an `InferAlignment` mode, which, in the past, attempted to detect 
layouts which came from packed structures in order to provide a conservative 
estimate of alignment for it (since `DW_AT_alignment` isn't emitted unless 
explicitly changed with `alignas`, etc.).

However, in the presence of overlapping fields due to `no_unique_address`, 
`InferAlignment` would set the alignment of structures to `1` for which that's 
incorrect. This poses issues in some LLDB formatters that synthesize new Clang 
types and rely on the layout builder to get the `FieldOffset` of structures 
right that we did have DWARF offsets for. The result of this is that if we get 
the alignment wrong, LLDB reads out garbage data from the wrong field offsets.

There are a couple of solutions to this that we considered:
1. Make LLDB formatters not do the above, and make them more robust to 
inaccurate alignment.
2. Remove `InferAlignment` entirely and rely on Clang emitting 
`DW_AT_alignment` for packed structures.
3. Remove `InferAlignment` and detect packedness from within LLDB.
4. Make the `InferAlignment` logic account for overlapping fields.

Option (1) turned out quite hairy and it's not clear we can achieve this with 
the tools available for certain STL formatters (particularly `std::map`). But I 
would still very much like to simplify this if we can.

Option (2) wouldn't help with GCC-compiled binaries, and if we can get away 
with LLDB not needing the alignment, then we wouldn't need to increase 
debug-info size.

Option (3), AFAICT, would require us to reimplement some of the layout logic in 
the layout builder. Would be great if we can avoid this added complexity.

Option (4) seemed like the best option in the interim. As part of this change I 
also removed one of the `InferAlignment` blocks. The test-cases associated with 
this code-path pass regardless, and from the description of the change that 
introduced it it's not clear why specifically the base offsets would influence 
the `Alignment` field, and how it would imply packedness. But happy to be 
proven wrong. Ultimately it would be great if we can get rid of the 
`InferAlignment` infrastructure and support our use-cases in LLDB or DWARF 
instead.

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


3 Files Affected:

- (modified) clang/lib/AST/RecordLayoutBuilder.cpp (+17-17) 
- (modified) lldb/test/Shell/SymbolFile/DWARF/no_unique_address-alignment.cpp 
(-2) 
- (modified) 
lldb/test/Shell/SymbolFile/DWARF/no_unique_address-base-alignment.cpp (-2) 


``diff
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index d9bf62c2bbb04..8dbf69c310cbb 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -802,7 +802,8 @@ class ItaniumRecordLayoutBuilder {
   /// \param Field The field whose offset is being queried.
   /// \param ComputedOffset The offset that we've computed for this field.
   uint64_t updateExternalFieldOffset(const FieldDecl *Field,
- uint64_t ComputedOffset);
+ uint64_t ComputedOffset,
+ uint64_t PreviousOffset);
 
   void CheckFieldPadding(uint64_t Offset, uint64_t UnpaddedOffset,
   uint64_t UnpackedOffset, unsigned UnpackedAlign,
@@ -1296,13 +1297,6 @@ ItaniumRecordLayoutBuilder::LayoutBase(const 
BaseSubobjectInfo *Base) {
 bool Allowed = EmptySubobjects->CanPlaceBaseAtOffset(Base, Offset);
 (void)Allowed;
 assert(Allowed && "Base subobject externally placed at overlapping 
offset");
-
-if (InferAlignment && Offset < getDataSize().alignTo(AlignTo)) {
-  // The externally-supplied base offset is before the base offset we
-  // computed. Assume that the structure is packed.
-  Alignment = CharUnits::One();
-  InferAlignment = false;
-}
   }
 
   if (!Base->Class->isEmpty()) {
@@ -1770,7 +1764,8 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const 
FieldDecl *D) {
   // If we're using external layout, give the external layout a chance
   // to override this information.
   if (UseExternalLayout)
-FieldOffset = updateExternalFieldOffset(D, FieldOffset);
+FieldOffset = updateExternalFieldOffset(
+D, FieldOffset, FieldOffsets.empty() ? 0 : FieldOffsets.back());
 
   // Okay, place the bitfield at the calculated offset.
   FieldOffsets.push_back(FieldOffset);
@@ -2063,8 +2058,9 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDec

[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Alex Langford via lldb-commits

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


[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Alex Langford via lldb-commits


@@ -0,0 +1,70 @@
+from abc import abstractmethod

bulbazord wrote:

This is an entire scripting interface. Maybe a separate PR would be more 
appropriate? Seems like you're doing multiple things here.

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


[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Alex Langford via lldb-commits


@@ -25,10 +25,17 @@ if (LLDB_ENABLE_PYTHON AND SPHINX_FOUND)
 # Pretend that the SWIG generated API is a Python package.
 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lldb)
 get_target_property(lldb_bindings_dir swig_wrapper_python BINARY_DIR)
+

bulbazord wrote:

nit: stray space?

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


[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Alex Langford via lldb-commits

https://github.com/bulbazord commented:

I know you've been thinking about and working on this for a while, so glad to 
see it come together like this! 😃 

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


[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Alex Langford via lldb-commits


@@ -0,0 +1,36 @@
+Python Extensions
+=
+
+LLDB provides many scriptable extensions to augment the debugger capabilities
+and give the ability to the user to tailor their experience to their own needs.
+
+This page describes some of these scripting extension:

bulbazord wrote:

`extension` -> `extensions`

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


[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Alex Langford via lldb-commits


@@ -0,0 +1,36 @@
+Python Extensions
+=
+
+LLDB provides many scriptable extensions to augment the debugger capabilities
+and give the ability to the user to tailor their experience to their own needs.

bulbazord wrote:

Suggestion: `LLDB provides scriptable extensions to augment the debugger's 
capabilities. This gives users the ability to tailor their debugging experience 
to their own needs.`

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


[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Alex Langford via lldb-commits


@@ -10,9 +10,6 @@ class ScriptedPlatform(metaclass=ABCMeta):
 
 Most of the base class methods are `@abstractmethod` that need to be
 overwritten by the inheriting class.
-
-DISCLAIMER: THIS INTERFACE IS STILL UNDER DEVELOPMENT AND NOT STABLE.
-THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE.

bulbazord wrote:

Why remove the disclaimer? Is this no longer true?

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


[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Alex Langford via lldb-commits


@@ -0,0 +1,36 @@
+Python Extensions
+=
+
+LLDB provides many scriptable extensions to augment the debugger capabilities
+and give the ability to the user to tailor their experience to their own needs.
+
+This page describes some of these scripting extension:
+
+Operating System Thread Plugins
+---
+

bulbazord wrote:

A short blurb explaining what each of these are for would be useful. It may not 
be obvious what "Operating System Thread Plugins" are for, as an example.

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


[Lldb-commits] [lldb] [lldb] Don't unregister a listener that's being destroyed (PR #97300)

2024-07-02 Thread via lldb-commits

jimingham wrote:

> Thanks for the explanation. I believe I understand the purpose of the primary 
> listener. While I'm not sure that a "shared pointer" is the best way to 
> express the "someone must exist on the other end to pull the events" notion, 
> I'm not interested in revisiting that decision, so I'll remove that part of 
> the commit message.

Holding a shared pointer isn't really about making sure the client that 
provides the Listener is doing the right thing with it.  Rather, the 
shared-pointer-ness coupled with the fact that you have to provide a Listener 
to make a Process mean that the Process event code never has to reason about 
what to do if it didn't have a Listener, which would be a pointless 
complication.

I didn't try hard to come up with a way to enforce correct behavior on the 
client side because the fact that the debug session produced thereby wouldn't 
work seems a sufficient enforcement mechanism.

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


[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Med Ismail Bennani via lldb-commits


@@ -10,9 +10,6 @@ class ScriptedPlatform(metaclass=ABCMeta):
 
 Most of the base class methods are `@abstractmethod` that need to be
 overwritten by the inheriting class.
-
-DISCLAIMER: THIS INTERFACE IS STILL UNDER DEVELOPMENT AND NOT STABLE.
-THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE.

medismailben wrote:

I'd expect at this point the extension to be stable.

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


[Lldb-commits] [lldb] [lldb] Make Broadcaster mutexes non-recursive (PR #97400)

2024-07-02 Thread via lldb-commits

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

LGTM, non-recursive mutex's are much easier to reason about for sure.  Thanks 
for the unit test!

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


[Lldb-commits] [lldb] [lldb/Commands] Alias `script` command to `scripting run` (PR #97263)

2024-07-02 Thread Alex Langford via lldb-commits


@@ -518,6 +518,15 @@ void CommandInterpreter::Initialize() {
 AddAlias("re", cmd_obj_sp);
   }
 
+  cmd_obj_sp = GetCommandSPExact("scripting execute");
+  if (cmd_obj_sp) {
+AddAlias("sc", cmd_obj_sp);
+AddAlias("scr", cmd_obj_sp);
+AddAlias("scri", cmd_obj_sp);
+AddAlias("scrip", cmd_obj_sp);
+AddAlias("script", cmd_obj_sp);

bulbazord wrote:

Might be a good idea to write a comment explaining the constraint here? If I 
came across this code snippet I'd definitely want to know why we do this.

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


[Lldb-commits] [clang] [lldb] [clang][RecordLayoutBuilder] Be stricter about inferring packed-ness in ExternalLayouts (PR #97443)

2024-07-02 Thread Michael Buch via lldb-commits


@@ -2250,14 +2246,18 @@ void ItaniumRecordLayoutBuilder::UpdateAlignment(
   }
 }
 
-uint64_t
-ItaniumRecordLayoutBuilder::updateExternalFieldOffset(const FieldDecl *Field,
-  uint64_t ComputedOffset) 
{
+uint64_t ItaniumRecordLayoutBuilder::updateExternalFieldOffset(
+const FieldDecl *Field, uint64_t ComputedOffset, uint64_t PreviousOffset) {
   uint64_t ExternalFieldOffset = External.getExternalFieldOffset(Field);
 
-  if (InferAlignment && ExternalFieldOffset < ComputedOffset) {
-// The externally-supplied field offset is before the field offset we
-// computed. Assume that the structure is packed.
+  // If the externally-supplied field offset is before the field offset we
+  // computed. Check against the previous field offset to make sure we don't
+  // misinterpret overlapping fields as packedness of the structure.
+  const bool assume_packed = ExternalFieldOffset > 0 &&
+ ExternalFieldOffset < ComputedOffset &&
+ ExternalFieldOffset > PreviousOffset;

Michael137 wrote:

Technically "overlapping" would have to account for size of the previous field

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


[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Med Ismail Bennani via lldb-commits


@@ -0,0 +1,36 @@
+Python Extensions
+=
+
+LLDB provides many scriptable extensions to augment the debugger capabilities
+and give the ability to the user to tailor their experience to their own needs.
+
+This page describes some of these scripting extension:
+
+Operating System Thread Plugins
+---
+

medismailben wrote:

![image](https://github.com/llvm/llvm-project/assets/10001166/0dec76ec-ae53-4ea1-b5f5-b96e64cfb7de)

We get the blurb from the docstrings.

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


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-02 Thread Alex Langford via lldb-commits


@@ -127,6 +130,171 @@ class CommandObjectScriptingRun : public CommandObjectRaw 
{
   CommandOptions m_options;
 };
 
+#pragma mark CommandObjectScriptingTemplateList
+
+#define LLDB_OPTIONS_scripting_template_list
+#include "CommandOptions.inc"
+
+class CommandObjectScriptingTemplateList : public CommandObjectParsed {
+public:
+  CommandObjectScriptingTemplateList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "scripting template list",
+"List all the available scripting affordances templates. ",
+"scripting template list [--language  --]") {}
+
+  ~CommandObjectScriptingTemplateList() override = default;
+
+  Options *GetOptions() override { return &m_options; }
+
+  class CommandOptions : public Options {
+  public:
+CommandOptions() = default;
+~CommandOptions() override = default;
+Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+  ExecutionContext *execution_context) override {
+  Status error;
+  const int short_option = m_getopt_table[option_idx].val;
+
+  switch (short_option) {
+  case 'l':
+language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
+option_arg, GetDefinitions()[option_idx].enum_values,
+eScriptLanguageNone, error);
+if (!error.Success())
+  error.SetErrorStringWithFormat("unrecognized value for language 
'%s'",
+ option_arg.str().c_str());
+break;
+  default:
+llvm_unreachable("Unimplemented option");
+  }
+
+  return error;
+}
+
+void OptionParsingStarting(ExecutionContext *execution_context) override {
+  language = lldb::eScriptLanguageNone;
+}
+
+llvm::ArrayRef GetDefinitions() override {
+  return llvm::ArrayRef(g_scripting_template_list_options);
+}
+
+lldb::ScriptLanguage language = lldb::eScriptLanguageNone;
+  };
+
+protected:
+  void DoExecute(Args &command, CommandReturnObject &result) override {
+lldb::ScriptLanguage language =
+(m_options.language == lldb::eScriptLanguageNone)
+? m_interpreter.GetDebugger().GetScriptLanguage()
+: m_options.language;
+
+if (language == lldb::eScriptLanguageNone) {
+  result.AppendError(
+  "the script-lang setting is set to none - scripting not available");
+  return;
+}
+
+ScriptInterpreter *script_interpreter =
+GetDebugger().GetScriptInterpreter(true, language);
+
+if (script_interpreter == nullptr) {
+  result.AppendError("no script interpreter");
+  return;
+}
+
+Stream &s = result.GetOutputStream();
+s.Printf("Available scripted affordances:\n");

bulbazord wrote:

Suggestion: `Available scripting templates`. My reason is that the command is 
`scripting template list` so I would expect it to tell me what the available 
scripting templates are.

Additionally, it might be useful to specify the language. So something like 
`Available scripting templates (Python)` or something like that. This would let 
you drop the `print_field("Language", "Python")` below.

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


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-02 Thread Alex Langford via lldb-commits


@@ -127,6 +130,171 @@ class CommandObjectScriptingRun : public CommandObjectRaw 
{
   CommandOptions m_options;
 };
 
+#pragma mark CommandObjectScriptingTemplateList
+
+#define LLDB_OPTIONS_scripting_template_list
+#include "CommandOptions.inc"
+
+class CommandObjectScriptingTemplateList : public CommandObjectParsed {
+public:
+  CommandObjectScriptingTemplateList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "scripting template list",
+"List all the available scripting affordances templates. ",
+"scripting template list [--language  --]") {}
+
+  ~CommandObjectScriptingTemplateList() override = default;
+
+  Options *GetOptions() override { return &m_options; }
+
+  class CommandOptions : public Options {
+  public:
+CommandOptions() = default;
+~CommandOptions() override = default;
+Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+  ExecutionContext *execution_context) override {
+  Status error;
+  const int short_option = m_getopt_table[option_idx].val;
+
+  switch (short_option) {
+  case 'l':
+language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
+option_arg, GetDefinitions()[option_idx].enum_values,
+eScriptLanguageNone, error);
+if (!error.Success())
+  error.SetErrorStringWithFormat("unrecognized value for language 
'%s'",
+ option_arg.str().c_str());
+break;
+  default:
+llvm_unreachable("Unimplemented option");
+  }
+
+  return error;
+}
+
+void OptionParsingStarting(ExecutionContext *execution_context) override {
+  language = lldb::eScriptLanguageNone;
+}
+
+llvm::ArrayRef GetDefinitions() override {
+  return llvm::ArrayRef(g_scripting_template_list_options);
+}
+
+lldb::ScriptLanguage language = lldb::eScriptLanguageNone;
+  };
+
+protected:
+  void DoExecute(Args &command, CommandReturnObject &result) override {
+lldb::ScriptLanguage language =
+(m_options.language == lldb::eScriptLanguageNone)
+? m_interpreter.GetDebugger().GetScriptLanguage()
+: m_options.language;
+
+if (language == lldb::eScriptLanguageNone) {
+  result.AppendError(
+  "the script-lang setting is set to none - scripting not available");
+  return;
+}
+
+ScriptInterpreter *script_interpreter =
+GetDebugger().GetScriptInterpreter(true, language);
+
+if (script_interpreter == nullptr) {
+  result.AppendError("no script interpreter");
+  return;
+}
+
+Stream &s = result.GetOutputStream();
+s.Printf("Available scripted affordances:\n");
+
+auto print_field = [&s](llvm::StringRef key, llvm::StringRef value,
+bool check_validy = false) {
+  if (!check_validy || !value.empty()) {
+s.IndentMore();
+s.Indent();
+s << key << ": " << value << '\n';
+s.IndentLess();
+  }
+};
+auto print_usages = [&s](llvm::StringRef usage_kind,
+ std::vector &usages) {
+  s.IndentMore();
+  s.Indent();
+  s << usage_kind << " Usages:";
+  if (usages.empty())
+s << " No usages.\n";
+  else if (usages.size() == 1)
+s << " " << usages.front() << '\n';
+  else {
+s << '\n';
+for (llvm::StringRef usage : usages) {
+  s.IndentMore();
+  s.Indent();
+  s << usage << '\n';
+  s.IndentLess();
+}
+  }
+  s.IndentLess();
+};
+
+size_t i = 0;
+for (llvm::StringRef plugin_name =
+ PluginManager::GetScriptedInterfaceNameAtIndex(i);
+ !plugin_name.empty();) {

bulbazord wrote:

Increment `i` here instead of below? It would be more resilient to making 
mistakes when modifying this loop for any reason.

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


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-02 Thread Alex Langford via lldb-commits


@@ -127,6 +130,171 @@ class CommandObjectScriptingRun : public CommandObjectRaw 
{
   CommandOptions m_options;
 };
 
+#pragma mark CommandObjectScriptingTemplateList
+
+#define LLDB_OPTIONS_scripting_template_list
+#include "CommandOptions.inc"
+
+class CommandObjectScriptingTemplateList : public CommandObjectParsed {
+public:
+  CommandObjectScriptingTemplateList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "scripting template list",
+"List all the available scripting affordances templates. ",
+"scripting template list [--language  --]") {}
+
+  ~CommandObjectScriptingTemplateList() override = default;
+
+  Options *GetOptions() override { return &m_options; }
+
+  class CommandOptions : public Options {
+  public:
+CommandOptions() = default;
+~CommandOptions() override = default;
+Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+  ExecutionContext *execution_context) override {
+  Status error;
+  const int short_option = m_getopt_table[option_idx].val;
+
+  switch (short_option) {
+  case 'l':
+language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
+option_arg, GetDefinitions()[option_idx].enum_values,
+eScriptLanguageNone, error);
+if (!error.Success())
+  error.SetErrorStringWithFormat("unrecognized value for language 
'%s'",
+ option_arg.str().c_str());
+break;
+  default:
+llvm_unreachable("Unimplemented option");
+  }
+
+  return error;
+}
+
+void OptionParsingStarting(ExecutionContext *execution_context) override {
+  language = lldb::eScriptLanguageNone;
+}
+
+llvm::ArrayRef GetDefinitions() override {
+  return llvm::ArrayRef(g_scripting_template_list_options);
+}
+
+lldb::ScriptLanguage language = lldb::eScriptLanguageNone;
+  };
+
+protected:
+  void DoExecute(Args &command, CommandReturnObject &result) override {
+lldb::ScriptLanguage language =
+(m_options.language == lldb::eScriptLanguageNone)
+? m_interpreter.GetDebugger().GetScriptLanguage()
+: m_options.language;
+
+if (language == lldb::eScriptLanguageNone) {
+  result.AppendError(
+  "the script-lang setting is set to none - scripting not available");
+  return;
+}
+
+ScriptInterpreter *script_interpreter =
+GetDebugger().GetScriptInterpreter(true, language);
+
+if (script_interpreter == nullptr) {
+  result.AppendError("no script interpreter");
+  return;
+}
+
+Stream &s = result.GetOutputStream();
+s.Printf("Available scripted affordances:\n");
+
+auto print_field = [&s](llvm::StringRef key, llvm::StringRef value,
+bool check_validy = false) {

bulbazord wrote:

typo: `validy` -> `validity`?


Also, what's the use case for the check? I don't see you use it.

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


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-02 Thread Alex Langford via lldb-commits


@@ -29,6 +29,9 @@ add_subdirectory(UnwindAssembly)
 
 set(LLDB_STRIPPED_PLUGINS)
 get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
+get_property(LLDB_EXTRA_PLUGINS GLOBAL PROPERTY LLDB_EXTRA_SCRIPT_PLUGINS)
+list(APPEND LLDB_ALL_PLUGINS ${LLDB_EXTRA_PLUGINS})

bulbazord wrote:

I don't think there's a benefit to splitting the plugins into two different 
global properties. Is there a reason why we should treat these script plugins 
differently? 

Also I see you doing that for the python plugins below, how about the Lua ones?

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


[Lldb-commits] [lldb] Fix flake in TestZerothFrame.py (PR #96685)

2024-07-02 Thread Alex Langford via lldb-commits

bulbazord wrote:

Yes, looks good to me. Thanks for taking the time! :)

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


[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/97262

>From 06a79c19a169fa6b8bed30bde37b7ee56ade5cef Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Tue, 2 Jul 2024 12:47:50 -0700
Subject: [PATCH] [lldb/docs] Add scripting extensions documentation to the
 website

This patch adds the documentation for a subset of scripting extensions
such as scripted process, scripted thread, operating system threads &
scritped thread plans to the lldb website.

Signed-off-by: Med Ismail Bennani 
---
 lldb/docs/CMakeLists.txt  |  7 +++-
 lldb/docs/index.rst   |  1 +
 .../python/templates/operating_system.py  | 20 -
 .../python/templates/scripted_platform.py | 25 ++-
 .../python/templates/scripted_process.py  | 42 +--
 5 files changed, 48 insertions(+), 47 deletions(-)

diff --git a/lldb/docs/CMakeLists.txt b/lldb/docs/CMakeLists.txt
index f482e91d1b10c..ed4296bbf03a4 100644
--- a/lldb/docs/CMakeLists.txt
+++ b/lldb/docs/CMakeLists.txt
@@ -27,8 +27,13 @@ if (LLDB_ENABLE_PYTHON AND SPHINX_FOUND)
 get_target_property(lldb_bindings_dir swig_wrapper_python BINARY_DIR)
 add_custom_target(lldb-python-doc-package
   COMMAND "${CMAKE_COMMAND}" -E copy "${lldb_bindings_dir}/lldb.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/__init__.py"
+  COMMAND "${CMAKE_COMMAND}" -E make_directory 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
   COMMENT "Copying lldb.py to pretend its a Python package.")
-add_dependencies(lldb-python-doc-package swig_wrapper_python)
+
+add_dependencies(lldb-python-doc-package swig_wrapper_python lldb-python)
 
 # FIXME: Don't treat Sphinx warnings as errors. The files generated by
 # automodapi are full of warnings (partly caused by SWIG, our documentation
diff --git a/lldb/docs/index.rst b/lldb/docs/index.rst
index 1e7d69002dd3e..3ce23beec2a5e 100644
--- a/lldb/docs/index.rst
+++ b/lldb/docs/index.rst
@@ -141,6 +141,7 @@ interesting areas to contribute to lldb.
use/python
use/python-reference
Python API 
+   Python Extensions 
 
 
 .. toctree::
diff --git a/lldb/examples/python/templates/operating_system.py 
b/lldb/examples/python/templates/operating_system.py
index a8053bcaa21af..d83019079ee90 100644
--- a/lldb/examples/python/templates/operating_system.py
+++ b/lldb/examples/python/templates/operating_system.py
@@ -10,16 +10,16 @@ class OperatingSystem(ScriptedThread):
 """
 Class that provides data for an instance of a LLDB 'OperatingSystemPython' 
plug-in class.
 
-```
-thread_info = {
-"tid": tid,
-"name": "four",
-"queue": "queue4",
-"state": "stopped",
-"stop_reason": "none",
-"core" : 2
-}
-```
+.. code-block:: python
+
+thread_info = {
+"tid": tid,
+"name": "four",
+"queue": "queue4",
+"state": "stopped",
+"stop_reason": "none",
+"core" : 2
+}
 
 - tid : thread ID (mandatory)
 - name : thread name (optional key/value pair)
diff --git a/lldb/examples/python/templates/scripted_platform.py 
b/lldb/examples/python/templates/scripted_platform.py
index fb1bde8fd4cb7..5805f99dea4ca 100644
--- a/lldb/examples/python/templates/scripted_platform.py
+++ b/lldb/examples/python/templates/scripted_platform.py
@@ -10,9 +10,6 @@ class ScriptedPlatform(metaclass=ABCMeta):
 
 Most of the base class methods are `@abstractmethod` that need to be
 overwritten by the inheriting class.
-
-DISCLAIMER: THIS INTERFACE IS STILL UNDER DEVELOPMENT AND NOT STABLE.
-THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE.
 """
 
 processes = None
@@ -32,16 +29,18 @@ def __init__(self, exe_ctx, args):
 def list_processes(self):
 """Get a list of processes that are running or that can be attached to 
on the platform.
 
-processes = {
-420: {
-name: a.out,
-arch: aarch64,
-pid: 420,
-parent_pid: 42 (optional),
-uid: 0 (optional),
-gid: 0 (optional),
-},
-}
+.. code-block:: python
+
+processes = {
+420: {
+name: a.out,
+arch: aarch64,
+pid: 420,
+parent_pid: 42 (optional),
+uid: 0 (optional),
+

[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Alex Langford via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Alex Langford via lldb-commits


@@ -0,0 +1,36 @@
+Python Extensions
+=
+
+LLDB provides many scriptable extensions to augment the debugger capabilities
+and give the ability to the user to tailor their experience to their own needs.
+
+This page describes some of these scripting extension:
+
+Operating System Thread Plugins
+---
+

bulbazord wrote:

Ah, this looks great! Thanks for showing me what it will look like :)

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


[Lldb-commits] [lldb] 59f4267 - [lldb/docs] Add scripting extensions documentation to the website (#97262)

2024-07-02 Thread via lldb-commits

Author: Med Ismail Bennani
Date: 2024-07-02T12:52:50-07:00
New Revision: 59f4267c8e0625c6583327be2db1608930f2d796

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

LOG: [lldb/docs] Add scripting extensions documentation to the website (#97262)

This patch adds the documentation for a subset of scripting extensions
such as scripted process, scripted thread, operating system threads &
scritped thread plans to the lldb website.

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/docs/CMakeLists.txt
lldb/docs/index.rst
lldb/examples/python/templates/operating_system.py
lldb/examples/python/templates/scripted_platform.py
lldb/examples/python/templates/scripted_process.py

Removed: 




diff  --git a/lldb/docs/CMakeLists.txt b/lldb/docs/CMakeLists.txt
index f482e91d1b10c..ed4296bbf03a4 100644
--- a/lldb/docs/CMakeLists.txt
+++ b/lldb/docs/CMakeLists.txt
@@ -27,8 +27,13 @@ if (LLDB_ENABLE_PYTHON AND SPHINX_FOUND)
 get_target_property(lldb_bindings_dir swig_wrapper_python BINARY_DIR)
 add_custom_target(lldb-python-doc-package
   COMMAND "${CMAKE_COMMAND}" -E copy "${lldb_bindings_dir}/lldb.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/__init__.py"
+  COMMAND "${CMAKE_COMMAND}" -E make_directory 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
   COMMENT "Copying lldb.py to pretend its a Python package.")
-add_dependencies(lldb-python-doc-package swig_wrapper_python)
+
+add_dependencies(lldb-python-doc-package swig_wrapper_python lldb-python)
 
 # FIXME: Don't treat Sphinx warnings as errors. The files generated by
 # automodapi are full of warnings (partly caused by SWIG, our documentation

diff  --git a/lldb/docs/index.rst b/lldb/docs/index.rst
index 1e7d69002dd3e..3ce23beec2a5e 100644
--- a/lldb/docs/index.rst
+++ b/lldb/docs/index.rst
@@ -141,6 +141,7 @@ interesting areas to contribute to lldb.
use/python
use/python-reference
Python API 
+   Python Extensions 
 
 
 .. toctree::

diff  --git a/lldb/examples/python/templates/operating_system.py 
b/lldb/examples/python/templates/operating_system.py
index a8053bcaa21af..d83019079ee90 100644
--- a/lldb/examples/python/templates/operating_system.py
+++ b/lldb/examples/python/templates/operating_system.py
@@ -10,16 +10,16 @@ class OperatingSystem(ScriptedThread):
 """
 Class that provides data for an instance of a LLDB 'OperatingSystemPython' 
plug-in class.
 
-```
-thread_info = {
-"tid": tid,
-"name": "four",
-"queue": "queue4",
-"state": "stopped",
-"stop_reason": "none",
-"core" : 2
-}
-```
+.. code-block:: python
+
+thread_info = {
+"tid": tid,
+"name": "four",
+"queue": "queue4",
+"state": "stopped",
+"stop_reason": "none",
+"core" : 2
+}
 
 - tid : thread ID (mandatory)
 - name : thread name (optional key/value pair)

diff  --git a/lldb/examples/python/templates/scripted_platform.py 
b/lldb/examples/python/templates/scripted_platform.py
index fb1bde8fd4cb7..5805f99dea4ca 100644
--- a/lldb/examples/python/templates/scripted_platform.py
+++ b/lldb/examples/python/templates/scripted_platform.py
@@ -10,9 +10,6 @@ class ScriptedPlatform(metaclass=ABCMeta):
 
 Most of the base class methods are `@abstractmethod` that need to be
 overwritten by the inheriting class.
-
-DISCLAIMER: THIS INTERFACE IS STILL UNDER DEVELOPMENT AND NOT STABLE.
-THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE.
 """
 
 processes = None
@@ -32,16 +29,18 @@ def __init__(self, exe_ctx, args):
 def list_processes(self):
 """Get a list of processes that are running or that can be attached to 
on the platform.
 
-processes = {
-420: {
-name: a.out,
-arch: aarch64,
-pid: 420,
-parent_pid: 42 (optional),
-uid: 0 (optional),
-gid: 0 (optional),
-},
-}
+.. code-block:: python
+
+processes = {
+420: {
+name: a.out,
+arch: aarch64,
+pid: 420,
+parent_pid: 

[Lldb-commits] [lldb] [lldb/docs] Add scripting extensions documentation to the website (PR #97262)

2024-07-02 Thread Med Ismail Bennani via lldb-commits

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


[Lldb-commits] [lldb] [lldb][AArch64] Add register field enum information (PR #96887)

2024-07-02 Thread Alex Langford via lldb-commits

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

LGTM, seems like the natural progression of this work. :)

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


[Lldb-commits] [lldb] [llvm] [DRAFT][LLDB][Minidump] Support minidumps where there are multiple exception streams (PR #97470)

2024-07-02 Thread Jacob Lalonde via lldb-commits

https://github.com/Jlalond created 
https://github.com/llvm/llvm-project/pull/97470

Currently, LLDB assumes all minidumps will have unique sections. This is 
intuitive because almost all of the minidump sections are themselves lists. 
Exceptions including Signals are unique in that they are all individual 
sections with their own directory. 

This means LLDB fails to load minidumps with multiple exceptions due to them 
not being unique. This behavior is erroneous and this PR introduces support for 
an arbitrary number of exception streams. Additionally, stop info was 
calculated on for a single thread before, and now we properly support mapping 
exceptions to threads.

This PR is starting in DRAFT because implementing testing is still required.

>From 7e41ca79a09d67ff7bb76a9d95dda4e7ccfdba8b Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 2 Jul 2024 12:41:02 -0700
Subject: [PATCH 1/2] Add support to read multiple exception streams in
 minidumps

---
 .../Process/minidump/MinidumpParser.cpp   |  11 +-
 .../Plugins/Process/minidump/MinidumpParser.h |   2 +-
 .../Process/minidump/ProcessMinidump.cpp  | 122 ++
 .../Process/minidump/ProcessMinidump.h|   2 +-
 .../Process/minidump/ThreadMinidump.cpp   |  14 +-
 .../Plugins/Process/minidump/ThreadMinidump.h |   3 +-
 .../Process/minidump/MinidumpParserTest.cpp   |  11 +-
 llvm/include/llvm/Object/Minidump.h   |  34 -
 llvm/lib/Object/Minidump.cpp  |  37 ++
 llvm/lib/ObjectYAML/MinidumpYAML.cpp  |   4 +-
 10 files changed, 162 insertions(+), 78 deletions(-)

diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
index be9fae938e227..ac487a5ed0c0a 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
@@ -408,7 +408,7 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
 continue;
   }
   // This module has been seen. Modules are sometimes mentioned multiple
-  // times when they are mapped discontiguously, so find the module with
+  // times when they are mapped discontiguously, so find the module with 
   // the lowest "base_of_image" and use that as the filtered module.
   if (module.BaseOfImage < dup_module->BaseOfImage)
 filtered_modules[iter->second] = &module;
@@ -417,14 +417,15 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
   return filtered_modules;
 }
 
-const minidump::ExceptionStream *MinidumpParser::GetExceptionStream() {
-  auto ExpectedStream = GetMinidumpFile().getExceptionStream();
+const std::vector 
MinidumpParser::GetExceptionStreams() {
+  auto ExpectedStream = GetMinidumpFile().getExceptionStreams();
   if (ExpectedStream)
-return &*ExpectedStream;
+return ExpectedStream.get();
 
   LLDB_LOG_ERROR(GetLog(LLDBLog::Process), ExpectedStream.takeError(),
  "Failed to read minidump exception stream: {0}");
-  return nullptr;
+  // return empty on failure.
+  return std::vector();
 }
 
 std::optional
diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.h 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
index 050ba086f46f5..e552c7210e330 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -82,7 +82,7 @@ class MinidumpParser {
   // have the same name, it keeps the copy with the lowest load address.
   std::vector GetFilteredModuleList();
 
-  const llvm::minidump::ExceptionStream *GetExceptionStream();
+  const std::vector GetExceptionStreams();
 
   std::optional FindMemoryRange(lldb::addr_t addr);
 
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp 
b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
index 13599f4a1553f..9f707c0d8a7a7 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -39,6 +39,7 @@
 
 #include 
 #include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
@@ -157,7 +158,7 @@ ProcessMinidump::ProcessMinidump(lldb::TargetSP target_sp,
  const FileSpec &core_file,
  DataBufferSP core_data)
 : PostMortemProcess(target_sp, listener_sp, core_file),
-  m_core_data(std::move(core_data)), m_active_exception(nullptr),
+  m_core_data(std::move(core_data)),
   m_is_wow64(false) {}
 
 ProcessMinidump::~ProcessMinidump() {
@@ -209,7 +210,19 @@ Status ProcessMinidump::DoLoadCore() {
   GetTarget().SetArchitecture(arch, true /*set_platform*/);
 
   m_thread_list = m_minidump_parser->GetThreads();
-  m_active_exception = m_minidump_parser->GetExceptionStream();
+  std::vector exception_streams = 
m_minidump_parser->GetExceptionStreams();
+  for (const auto &exception_stream : exception_streams) {
+if (m_exceptions_by_tid.count(excep

[Lldb-commits] [lldb] [LLDB] DebugInfoD tests: attempt to fix Fuchsia build (PR #96802)

2024-07-02 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei updated 
https://github.com/llvm/llvm-project/pull/96802

>From a7894b87df9afa9f22263e4d8ddec955978dea45 Mon Sep 17 00:00:00 2001
From: Kevin Frei 
Date: Mon, 25 Mar 2024 08:23:47 -0700
Subject: [PATCH 01/13] Trying to deal with Linux AArch64 test failures :/

---
 .../SymbolVendor/ELF/SymbolVendorELF.cpp  |  18 ++
 .../API/debuginfod/Normal/TestDebuginfod.py   | 187 +
 .../SplitDWARF/TestDebuginfodDWP.py   | 196 ++
 3 files changed, 401 insertions(+)
 create mode 100644 lldb/test/API/debuginfod/Normal/TestDebuginfod.py
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py

diff --git a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp 
b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
index b5fe35d71032a..a881218a56cef 100644
--- a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
+++ b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
@@ -44,6 +44,24 @@ llvm::StringRef 
SymbolVendorELF::GetPluginDescriptionStatic() {
  "executables.";
 }
 
+// If this is needed elsewhere, it can be exported/moved.
+static bool IsDwpSymbolFile(const lldb::ModuleSP &module_sp,
+const FileSpec &file_spec) {
+  DataBufferSP dwp_file_data_sp;
+  lldb::offset_t dwp_file_data_offset = 0;
+  // Try to create an ObjectFile from the file_spec.
+  ObjectFileSP dwp_obj_file = ObjectFile::FindPlugin(
+  module_sp, &file_spec, 0, FileSystem::Instance().GetByteSize(file_spec),
+  dwp_file_data_sp, dwp_file_data_offset);
+  // The presence of a debug_cu_index section is the key identifying feature of
+  // a DWP file. Make sure we don't fill in the section list on dwp_obj_file
+  // (by calling GetSectionList(false)) as this is invoked before we may have
+  // all the symbol files collected and available.
+  return dwp_obj_file && ObjectFileELF::classof(dwp_obj_file.get()) &&
+ dwp_obj_file->GetSectionList(false)->FindSectionByType(
+ eSectionTypeDWARFDebugCuIndex, false);
+}
+
 // CreateInstance
 //
 // Platforms can register a callback to use when creating symbol vendors to
diff --git a/lldb/test/API/debuginfod/Normal/TestDebuginfod.py 
b/lldb/test/API/debuginfod/Normal/TestDebuginfod.py
new file mode 100644
index 0..a662fb9fc6e68
--- /dev/null
+++ b/lldb/test/API/debuginfod/Normal/TestDebuginfod.py
@@ -0,0 +1,187 @@
+import os
+import shutil
+import tempfile
+import struct
+
+import lldb
+from lldbsuite.test.decorators import *
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+def getUUID(aoutuuid):
+"""
+Pull the 20 byte UUID out of the .note.gnu.build-id section that was dumped
+to a file already, as part of the build.
+"""
+with open(aoutuuid, "rb") as f:
+data = f.read(36)
+if len(data) != 36:
+return None
+header = struct.unpack_from("<4I", data)
+if len(header) != 4:
+return None
+# 4 element 'prefix', 20 bytes of uuid, 3 byte long string: 'GNU':
+if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 
0x554E47:
+return None
+return data[16:].hex()
+
+
+"""
+Test support for the DebugInfoD network symbol acquisition protocol.
+This one is for simple / no split-dwarf scenarios.
+
+For no-split-dwarf scenarios, there are 2 variations:
+1 - A stripped binary with it's corresponding unstripped binary:
+2 - A stripped binary with a corresponding --only-keep-debug symbols file
+"""
+
+
+@skipUnlessPlatform(["linux", "freebsd"])
+class DebugInfodTests(TestBase):
+# No need to try every flavor of debug inf.
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_normal_no_symbols(self):
+"""
+Validate behavior with no symbols or symbol locator.
+('baseline negative' behavior)
+"""
+test_root = self.config_test(["a.out"])
+self.try_breakpoint(False)
+
+def test_normal_default(self):
+"""
+Validate behavior with symbols, but no symbol locator.
+('baseline positive' behavior)
+"""
+test_root = self.config_test(["a.out", "a.out.debug"])
+self.try_breakpoint(True)
+
+def test_debuginfod_symbols(self):
+"""
+Test behavior with the full binary available from Debuginfod as
+'debuginfo' from the plug-in.
+"""
+test_root = self.config_test(["a.out"], "a.out.full")
+self.try_breakpoint(True)
+
+def test_debuginfod_executable(self):
+"""
+Test behavior with the full binary available from Debuginfod as
+'executable' from the plug-in.
+"""
+test_root = self.config_test(["a.out"], None, "a.out.full")
+self.try_breakpoint(True)
+
+def test_debuginfod_okd_symbols(self):
+"""
+Test behavior with the 'only-keep-debug' symbols available from 
Debuginfod.
+"""
+  

[Lldb-commits] [lldb] [lldb] Add scripted thread plan python base class to lldb & website (PR #97481)

2024-07-02 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben created 
https://github.com/llvm/llvm-project/pull/97481

Following a feedback request in #97262, I took out the scripted thread plan 
python base class from it and make a separate PR for it.

This patch adds the scripted thread plan base python class to the lldb python 
module as well as the lldb documentation website.

>From bf26ddefb822636d07c383ecf695876acd8e2a93 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Tue, 2 Jul 2024 14:06:16 -0700
Subject: [PATCH] [lldb] Add scripted thread plan python base class to lldb &
 website

Following a feedback request in #97262, I took out the scripted thread
plan python base class from it and make a separate PR for it.

This patch adds the scripted thread plan base python class to the lldb
python module as well as the lldb documentation website.

Signed-off-by: Med Ismail Bennani 
---
 lldb/bindings/python/CMakeLists.txt   |  4 +-
 lldb/docs/CMakeLists.txt  |  1 +
 lldb/docs/python_extensions.rst   | 39 +++
 .../python/templates/scripted_thread_plan.py  | 70 +++
 4 files changed, 113 insertions(+), 1 deletion(-)
 create mode 100644 lldb/docs/python_extensions.rst
 create mode 100644 lldb/examples/python/templates/scripted_thread_plan.py

diff --git a/lldb/bindings/python/CMakeLists.txt 
b/lldb/bindings/python/CMakeLists.txt
index def6941e802bb..69306a384e0b1 100644
--- a/lldb/bindings/python/CMakeLists.txt
+++ b/lldb/bindings/python/CMakeLists.txt
@@ -108,7 +108,9 @@ function(finish_swig_python swig_target 
lldb_python_bindings_dir lldb_python_tar
 "${LLDB_SOURCE_DIR}/examples/python/templates/parsed_cmd.py"
 "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py"
 "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py"
-"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py")
+"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py"
+"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_thread_plan.py"
+)
 
   if(APPLE)
 create_python_package(
diff --git a/lldb/docs/CMakeLists.txt b/lldb/docs/CMakeLists.txt
index ed4296bbf03a4..f1664a6965332 100644
--- a/lldb/docs/CMakeLists.txt
+++ b/lldb/docs/CMakeLists.txt
@@ -31,6 +31,7 @@ if (LLDB_ENABLE_PYTHON AND SPHINX_FOUND)
   COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
   COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
   COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_thread_plan.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
   COMMENT "Copying lldb.py to pretend its a Python package.")
 
 add_dependencies(lldb-python-doc-package swig_wrapper_python lldb-python)
diff --git a/lldb/docs/python_extensions.rst b/lldb/docs/python_extensions.rst
new file mode 100644
index 0..7e5f1ba6879db
--- /dev/null
+++ b/lldb/docs/python_extensions.rst
@@ -0,0 +1,39 @@
+Python Extensions
+=
+
+LLDB provides scriptable extensions to augment the debugger's capabilities.
+This gives users the ability to tailor their debugging experience to their own 
needs.
+
+This page describes some of these scripting extensions:
+
+Operating System Thread Plugins
+---
+
+.. automodapi:: lldb.plugins.operating_system
+:no-heading:
+:skip: ScriptedThread
+:no-inheritance-diagram:
+
+Scripted Process Plugins
+---
+
+.. automodapi:: lldb.plugins.scripted_process
+:no-heading:
+:skip: ABCMeta
+:no-inheritance-diagram:
+
+Scripted Platform Plugins
+---
+
+.. automodapi:: lldb.plugins.scripted_platform
+:no-heading:
+:skip: ABCMeta
+:no-inheritance-diagram:
+
+Scripted Thread Plan Plugins
+---
+
+.. automodapi:: lldb.plugins.scripted_thread_plan
+:no-heading:
+:no-inheritance-diagram:
+
diff --git a/lldb/examples/python/templates/scripted_thread_plan.py 
b/lldb/examples/python/templates/scripted_thread_plan.py
new file mode 100644
index 0..67396cdfc53a2
--- /dev/null
+++ b/lldb/examples/python/templates/scripted_thread_plan.py
@@ -0,0 +1,70 @@
+from abc import abstractmethod
+
+import lldb
+
+
+class ScriptedThreadPlan:
+"""
+Class that provides data for an instance of a LLDB 'ScriptedThreadPlan' 
plug-in class used to construct custom stepping logic.
+
+"""
+
+def __init__(self, thread_plan: lldb.SBThreadPlan):
+"""Initialization needs a valid lldb.SBThreadPlan object. This plug-in 
will get created after a live process is valid and has stopped.
+

[Lldb-commits] [lldb] [LLDB] DebugInfoD tests: attempt to fix Fuchsia build (PR #96802)

2024-07-02 Thread Kevin Frei via lldb-commits

https://github.com/kevinfrei updated 
https://github.com/llvm/llvm-project/pull/96802

>From 790db0c3dece1699a6cc6e670ddd0f7099840386 Mon Sep 17 00:00:00 2001
From: Kevin Frei 
Date: Mon, 25 Mar 2024 08:23:47 -0700
Subject: [PATCH 01/13] Trying to deal with Linux AArch64 test failures :/

---
 .../SymbolVendor/ELF/SymbolVendorELF.cpp  |  18 ++
 .../API/debuginfod/Normal/TestDebuginfod.py   | 187 +
 .../SplitDWARF/TestDebuginfodDWP.py   | 196 ++
 3 files changed, 401 insertions(+)
 create mode 100644 lldb/test/API/debuginfod/Normal/TestDebuginfod.py
 create mode 100644 lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py

diff --git a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp 
b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
index b5fe35d71032a..a881218a56cef 100644
--- a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
+++ b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
@@ -44,6 +44,24 @@ llvm::StringRef 
SymbolVendorELF::GetPluginDescriptionStatic() {
  "executables.";
 }
 
+// If this is needed elsewhere, it can be exported/moved.
+static bool IsDwpSymbolFile(const lldb::ModuleSP &module_sp,
+const FileSpec &file_spec) {
+  DataBufferSP dwp_file_data_sp;
+  lldb::offset_t dwp_file_data_offset = 0;
+  // Try to create an ObjectFile from the file_spec.
+  ObjectFileSP dwp_obj_file = ObjectFile::FindPlugin(
+  module_sp, &file_spec, 0, FileSystem::Instance().GetByteSize(file_spec),
+  dwp_file_data_sp, dwp_file_data_offset);
+  // The presence of a debug_cu_index section is the key identifying feature of
+  // a DWP file. Make sure we don't fill in the section list on dwp_obj_file
+  // (by calling GetSectionList(false)) as this is invoked before we may have
+  // all the symbol files collected and available.
+  return dwp_obj_file && ObjectFileELF::classof(dwp_obj_file.get()) &&
+ dwp_obj_file->GetSectionList(false)->FindSectionByType(
+ eSectionTypeDWARFDebugCuIndex, false);
+}
+
 // CreateInstance
 //
 // Platforms can register a callback to use when creating symbol vendors to
diff --git a/lldb/test/API/debuginfod/Normal/TestDebuginfod.py 
b/lldb/test/API/debuginfod/Normal/TestDebuginfod.py
new file mode 100644
index 0..a662fb9fc6e68
--- /dev/null
+++ b/lldb/test/API/debuginfod/Normal/TestDebuginfod.py
@@ -0,0 +1,187 @@
+import os
+import shutil
+import tempfile
+import struct
+
+import lldb
+from lldbsuite.test.decorators import *
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+def getUUID(aoutuuid):
+"""
+Pull the 20 byte UUID out of the .note.gnu.build-id section that was dumped
+to a file already, as part of the build.
+"""
+with open(aoutuuid, "rb") as f:
+data = f.read(36)
+if len(data) != 36:
+return None
+header = struct.unpack_from("<4I", data)
+if len(header) != 4:
+return None
+# 4 element 'prefix', 20 bytes of uuid, 3 byte long string: 'GNU':
+if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 
0x554E47:
+return None
+return data[16:].hex()
+
+
+"""
+Test support for the DebugInfoD network symbol acquisition protocol.
+This one is for simple / no split-dwarf scenarios.
+
+For no-split-dwarf scenarios, there are 2 variations:
+1 - A stripped binary with it's corresponding unstripped binary:
+2 - A stripped binary with a corresponding --only-keep-debug symbols file
+"""
+
+
+@skipUnlessPlatform(["linux", "freebsd"])
+class DebugInfodTests(TestBase):
+# No need to try every flavor of debug inf.
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_normal_no_symbols(self):
+"""
+Validate behavior with no symbols or symbol locator.
+('baseline negative' behavior)
+"""
+test_root = self.config_test(["a.out"])
+self.try_breakpoint(False)
+
+def test_normal_default(self):
+"""
+Validate behavior with symbols, but no symbol locator.
+('baseline positive' behavior)
+"""
+test_root = self.config_test(["a.out", "a.out.debug"])
+self.try_breakpoint(True)
+
+def test_debuginfod_symbols(self):
+"""
+Test behavior with the full binary available from Debuginfod as
+'debuginfo' from the plug-in.
+"""
+test_root = self.config_test(["a.out"], "a.out.full")
+self.try_breakpoint(True)
+
+def test_debuginfod_executable(self):
+"""
+Test behavior with the full binary available from Debuginfod as
+'executable' from the plug-in.
+"""
+test_root = self.config_test(["a.out"], None, "a.out.full")
+self.try_breakpoint(True)
+
+def test_debuginfod_okd_symbols(self):
+"""
+Test behavior with the 'only-keep-debug' symbols available from 
Debuginfod.
+"""
+  

[Lldb-commits] [lldb] [lldb] Add scripted thread plan python base class to lldb & website (PR #97481)

2024-07-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Med Ismail Bennani (medismailben)


Changes

Following a feedback request in #97262, I took out the scripted thread 
plan python base class from it and make a separate PR for it.

This patch adds the scripted thread plan base python class to the lldb python 
module as well as the lldb documentation website.

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


4 Files Affected:

- (modified) lldb/bindings/python/CMakeLists.txt (+3-1) 
- (modified) lldb/docs/CMakeLists.txt (+1) 
- (added) lldb/docs/python_extensions.rst (+39) 
- (added) lldb/examples/python/templates/scripted_thread_plan.py (+70) 


``diff
diff --git a/lldb/bindings/python/CMakeLists.txt 
b/lldb/bindings/python/CMakeLists.txt
index def6941e802bb..69306a384e0b1 100644
--- a/lldb/bindings/python/CMakeLists.txt
+++ b/lldb/bindings/python/CMakeLists.txt
@@ -108,7 +108,9 @@ function(finish_swig_python swig_target 
lldb_python_bindings_dir lldb_python_tar
 "${LLDB_SOURCE_DIR}/examples/python/templates/parsed_cmd.py"
 "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py"
 "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py"
-"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py")
+"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py"
+"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_thread_plan.py"
+)
 
   if(APPLE)
 create_python_package(
diff --git a/lldb/docs/CMakeLists.txt b/lldb/docs/CMakeLists.txt
index ed4296bbf03a4..f1664a6965332 100644
--- a/lldb/docs/CMakeLists.txt
+++ b/lldb/docs/CMakeLists.txt
@@ -31,6 +31,7 @@ if (LLDB_ENABLE_PYTHON AND SPHINX_FOUND)
   COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
   COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
   COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_thread_plan.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
   COMMENT "Copying lldb.py to pretend its a Python package.")
 
 add_dependencies(lldb-python-doc-package swig_wrapper_python lldb-python)
diff --git a/lldb/docs/python_extensions.rst b/lldb/docs/python_extensions.rst
new file mode 100644
index 0..7e5f1ba6879db
--- /dev/null
+++ b/lldb/docs/python_extensions.rst
@@ -0,0 +1,39 @@
+Python Extensions
+=
+
+LLDB provides scriptable extensions to augment the debugger's capabilities.
+This gives users the ability to tailor their debugging experience to their own 
needs.
+
+This page describes some of these scripting extensions:
+
+Operating System Thread Plugins
+---
+
+.. automodapi:: lldb.plugins.operating_system
+:no-heading:
+:skip: ScriptedThread
+:no-inheritance-diagram:
+
+Scripted Process Plugins
+---
+
+.. automodapi:: lldb.plugins.scripted_process
+:no-heading:
+:skip: ABCMeta
+:no-inheritance-diagram:
+
+Scripted Platform Plugins
+---
+
+.. automodapi:: lldb.plugins.scripted_platform
+:no-heading:
+:skip: ABCMeta
+:no-inheritance-diagram:
+
+Scripted Thread Plan Plugins
+---
+
+.. automodapi:: lldb.plugins.scripted_thread_plan
+:no-heading:
+:no-inheritance-diagram:
+
diff --git a/lldb/examples/python/templates/scripted_thread_plan.py 
b/lldb/examples/python/templates/scripted_thread_plan.py
new file mode 100644
index 0..67396cdfc53a2
--- /dev/null
+++ b/lldb/examples/python/templates/scripted_thread_plan.py
@@ -0,0 +1,70 @@
+from abc import abstractmethod
+
+import lldb
+
+
+class ScriptedThreadPlan:
+"""
+Class that provides data for an instance of a LLDB 'ScriptedThreadPlan' 
plug-in class used to construct custom stepping logic.
+
+"""
+
+def __init__(self, thread_plan: lldb.SBThreadPlan):
+"""Initialization needs a valid lldb.SBThreadPlan object. This plug-in 
will get created after a live process is valid and has stopped.
+
+Args:
+thread_plan (lldb.SBThreadPlan): The underlying `ThreadPlan` that 
is pushed onto the plan stack.
+"""
+self.thread_plan = thread_plan
+
+def explains_stop(self, event: lldb.SBEvent) -> bool:
+"""Each plan is asked from youngest to oldest if it "explains" the 
stop. The first plan to claim the stop wins.
+
+Args:
+event (lldb.SBEvent): The process stop event.
+
+Returns:
+bool: `True` if this stop could be claimed by this thread plan, 
`False` otherwise.
+Defaults to `True`.
+"""
+

[Lldb-commits] [lldb] [LLDB] DebugInfoD tests: attempt to fix Fuchsia build (PR #96802)

2024-07-02 Thread Kevin Frei via lldb-commits

kevinfrei wrote:

@JDevlieghere could you stamp this so I can see if I've managed to make the 
tests work on the Fuchsia build (which I can't reproduce locally)

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


[Lldb-commits] [lldb] Add the ability for Script based commands to specify their "repeat command" (PR #94823)

2024-07-02 Thread via lldb-commits

https://github.com/jimingham updated 
https://github.com/llvm/llvm-project/pull/94823

>From c2fea75364a0017be5e59020467d661bd00122ba Mon Sep 17 00:00:00 2001
From: Jim Ingham 
Date: Fri, 7 Jun 2024 17:36:34 -0700
Subject: [PATCH 1/4] Add the ability for Script based commands to specify
 their "repeat command".

Among other things, returning an empty string as the repeat command disables
auto-repeat, which can be useful for state-changing commands.
---
 lldb/bindings/python/python-wrapper.swig  | 23 
 lldb/examples/python/cmdtemplate.py   |  6 +-
 lldb/include/lldb/Interpreter/CommandObject.h |  4 ++
 .../lldb/Interpreter/ScriptInterpreter.h  |  5 ++
 .../source/Commands/CommandObjectCommands.cpp | 26 -
 lldb/source/Commands/CommandObjectThread.cpp  |  2 +-
 .../Python/SWIGPythonBridge.h |  4 ++
 .../Python/ScriptInterpreterPython.cpp| 27 +
 .../Python/ScriptInterpreterPythonImpl.h  | 14 +++--
 .../script/add/TestAddParsedCommand.py| 55 +++
 .../command/script/add/test_commands.py   | 25 -
 .../Python/PythonTestSuite.cpp|  6 ++
 12 files changed, 187 insertions(+), 10 deletions(-)

diff --git a/lldb/bindings/python/python-wrapper.swig 
b/lldb/bindings/python/python-wrapper.swig
index 1370afc885d43..bb3c9433e2032 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -831,6 +831,29 @@ bool 
lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject(
   return true;
 }
 
+std::optional
+lldb_private::python::SWIGBridge::LLDBSwigPythonGetRepeatCommandForScriptedCommand(PyObject
 *implementor,
+   std::string &command) {
+  PyErr_Cleaner py_err_cleaner(true);
+
+  PythonObject self(PyRefType::Borrowed, implementor);
+  auto pfunc = self.ResolveName("get_repeat_command");
+  // If not implemented, repeat the exact command.
+  if (!pfunc.IsAllocated())
+return std::nullopt;
+
+  PythonObject result;
+  PythonString command_str(command);
+  result = pfunc(command_str);
+
+  // A return of None is the equivalent of nullopt - means repeat
+  // the command as is:
+  if (result.IsNone())
+return std::nullopt;
+
+  return result.Str().GetString().str();
+}
+
 #include "lldb/Interpreter/CommandReturnObject.h"
 
 bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallParsedCommandObject(
diff --git a/lldb/examples/python/cmdtemplate.py 
b/lldb/examples/python/cmdtemplate.py
index 49a08365268f8..9a96888508b6f 100644
--- a/lldb/examples/python/cmdtemplate.py
+++ b/lldb/examples/python/cmdtemplate.py
@@ -19,7 +19,7 @@ class FrameStatCommand(ParsedCommand):
 
 @classmethod
 def register_lldb_command(cls, debugger, module_name):
-ParsedCommandBase.do_register_cmd(cls, debugger, module_name)
+ParsedCommand.do_register_cmd(cls, debugger, module_name)
 print(
 'The "{0}" command has been installed, type "help {0}" or "{0} '
 '--help" for detailed help.'.format(cls.program)
@@ -72,6 +72,10 @@ def setup_command_definition(self):
 default = True,
 )
 
+def get_repeat_command(self, args):
+"""As an example, make the command not auto-repeat:"""
+return ""
+
 def get_short_help(self):
 return "Example command for use in debugging"
 
diff --git a/lldb/include/lldb/Interpreter/CommandObject.h 
b/lldb/include/lldb/Interpreter/CommandObject.h
index a641a468b49d2..727ea0d963734 100644
--- a/lldb/include/lldb/Interpreter/CommandObject.h
+++ b/lldb/include/lldb/Interpreter/CommandObject.h
@@ -296,6 +296,10 @@ class CommandObject : public 
std::enable_shared_from_this {
   ///
   /// \param[in] current_command_args
   ///The command arguments.
+  ///
+  /// \param[in] index
+  ///This is for internal use - it is how the completion request is tracked
+  ///in CommandObjectMultiword, and should otherwise be ignored.
   ///
   /// \return
   /// std::nullopt if there is no special repeat command - it will use the
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index 932eaa8b8a4a2..934fd1837fcc0 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -480,6 +480,11 @@ class ScriptInterpreter : public PluginInterface {
   const lldb_private::ExecutionContext &exe_ctx) {
 return false;
   }
+  
+  virtual std::optional GetRepeatCommandForScriptedCommand(
+  StructuredData::GenericSP impl_obj_sp, Args &args) {
+return std::nullopt;
+  }
 
   virtual bool RunScriptFormatKeyword(const char *impl_function,
   Process *process, std::string &output,
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp 
b/lldb/source/Commands/CommandObjectCommands.cpp
index f4903e373b086..4144876c0751f 100644
--- a/lldb/source/C

[Lldb-commits] [lldb] [lldb] Add scripted thread plan python base class to lldb & website (PR #97481)

2024-07-02 Thread Alex Langford via lldb-commits

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


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


[Lldb-commits] [lldb] [llvm] [DRAFT][LLDB][Minidump] Support minidumps where there are multiple exception streams (PR #97470)

2024-07-02 Thread Jacob Lalonde via lldb-commits

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

>From 7e41ca79a09d67ff7bb76a9d95dda4e7ccfdba8b Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 2 Jul 2024 12:41:02 -0700
Subject: [PATCH 1/3] Add support to read multiple exception streams in
 minidumps

---
 .../Process/minidump/MinidumpParser.cpp   |  11 +-
 .../Plugins/Process/minidump/MinidumpParser.h |   2 +-
 .../Process/minidump/ProcessMinidump.cpp  | 122 ++
 .../Process/minidump/ProcessMinidump.h|   2 +-
 .../Process/minidump/ThreadMinidump.cpp   |  14 +-
 .../Plugins/Process/minidump/ThreadMinidump.h |   3 +-
 .../Process/minidump/MinidumpParserTest.cpp   |  11 +-
 llvm/include/llvm/Object/Minidump.h   |  34 -
 llvm/lib/Object/Minidump.cpp  |  37 ++
 llvm/lib/ObjectYAML/MinidumpYAML.cpp  |   4 +-
 10 files changed, 162 insertions(+), 78 deletions(-)

diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
index be9fae938e227..ac487a5ed0c0a 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
@@ -408,7 +408,7 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
 continue;
   }
   // This module has been seen. Modules are sometimes mentioned multiple
-  // times when they are mapped discontiguously, so find the module with
+  // times when they are mapped discontiguously, so find the module with 
   // the lowest "base_of_image" and use that as the filtered module.
   if (module.BaseOfImage < dup_module->BaseOfImage)
 filtered_modules[iter->second] = &module;
@@ -417,14 +417,15 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
   return filtered_modules;
 }
 
-const minidump::ExceptionStream *MinidumpParser::GetExceptionStream() {
-  auto ExpectedStream = GetMinidumpFile().getExceptionStream();
+const std::vector 
MinidumpParser::GetExceptionStreams() {
+  auto ExpectedStream = GetMinidumpFile().getExceptionStreams();
   if (ExpectedStream)
-return &*ExpectedStream;
+return ExpectedStream.get();
 
   LLDB_LOG_ERROR(GetLog(LLDBLog::Process), ExpectedStream.takeError(),
  "Failed to read minidump exception stream: {0}");
-  return nullptr;
+  // return empty on failure.
+  return std::vector();
 }
 
 std::optional
diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.h 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
index 050ba086f46f5..e552c7210e330 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -82,7 +82,7 @@ class MinidumpParser {
   // have the same name, it keeps the copy with the lowest load address.
   std::vector GetFilteredModuleList();
 
-  const llvm::minidump::ExceptionStream *GetExceptionStream();
+  const std::vector GetExceptionStreams();
 
   std::optional FindMemoryRange(lldb::addr_t addr);
 
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp 
b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
index 13599f4a1553f..9f707c0d8a7a7 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -39,6 +39,7 @@
 
 #include 
 #include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
@@ -157,7 +158,7 @@ ProcessMinidump::ProcessMinidump(lldb::TargetSP target_sp,
  const FileSpec &core_file,
  DataBufferSP core_data)
 : PostMortemProcess(target_sp, listener_sp, core_file),
-  m_core_data(std::move(core_data)), m_active_exception(nullptr),
+  m_core_data(std::move(core_data)),
   m_is_wow64(false) {}
 
 ProcessMinidump::~ProcessMinidump() {
@@ -209,7 +210,19 @@ Status ProcessMinidump::DoLoadCore() {
   GetTarget().SetArchitecture(arch, true /*set_platform*/);
 
   m_thread_list = m_minidump_parser->GetThreads();
-  m_active_exception = m_minidump_parser->GetExceptionStream();
+  std::vector exception_streams = 
m_minidump_parser->GetExceptionStreams();
+  for (const auto &exception_stream : exception_streams) {
+if (m_exceptions_by_tid.count(exception_stream.ThreadId) > 0) {
+  // We only cast to avoid the warning around converting little endian in 
printf.
+  error.SetErrorStringWithFormat("duplicate exception stream for tid %" 
PRIu32, (uint32_t)exception_stream.ThreadId);
+  return error;
+} else 
+  m_exceptions_by_tid[exception_stream.ThreadId] = exception_stream;
+
+
+std::cout << "Adding Exception Stream # " << 
(uint32_t)exception_stream.ThreadId << std::endl;
+std::cout << "Added index " << 
(uint32_t)m_exceptions_by_tid[exception_stream.ThreadId].ExceptionRecord.ExceptionCode
 << std::endl;
+  }
 
   SetUnixSignals(UnixSignals::Create(GetArchitecture()));
 
@@ -232,60 

[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Support minidumps where there are multiple exception streams (PR #97470)

2024-07-02 Thread Jacob Lalonde via lldb-commits

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Support minidumps where there are multiple exception streams (PR #97470)

2024-07-02 Thread Jacob Lalonde via lldb-commits

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

>From e8d1f3a7f978bd3c5767f0b0cacea60146a257f7 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 2 Jul 2024 12:41:02 -0700
Subject: [PATCH 1/4] Add support to read multiple exception streams in
 minidumps

---
 .../Process/minidump/MinidumpParser.cpp   |  11 +-
 .../Plugins/Process/minidump/MinidumpParser.h |   2 +-
 .../Process/minidump/ProcessMinidump.cpp  | 122 ++
 .../Process/minidump/ProcessMinidump.h|   2 +-
 .../Process/minidump/ThreadMinidump.cpp   |  14 +-
 .../Plugins/Process/minidump/ThreadMinidump.h |   3 +-
 .../Process/minidump/MinidumpParserTest.cpp   |  11 +-
 llvm/include/llvm/Object/Minidump.h   |  34 -
 llvm/lib/Object/Minidump.cpp  |  37 ++
 llvm/lib/ObjectYAML/MinidumpYAML.cpp  |   4 +-
 10 files changed, 162 insertions(+), 78 deletions(-)

diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
index be9fae938e227..ac487a5ed0c0a 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
@@ -408,7 +408,7 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
 continue;
   }
   // This module has been seen. Modules are sometimes mentioned multiple
-  // times when they are mapped discontiguously, so find the module with
+  // times when they are mapped discontiguously, so find the module with 
   // the lowest "base_of_image" and use that as the filtered module.
   if (module.BaseOfImage < dup_module->BaseOfImage)
 filtered_modules[iter->second] = &module;
@@ -417,14 +417,15 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
   return filtered_modules;
 }
 
-const minidump::ExceptionStream *MinidumpParser::GetExceptionStream() {
-  auto ExpectedStream = GetMinidumpFile().getExceptionStream();
+const std::vector 
MinidumpParser::GetExceptionStreams() {
+  auto ExpectedStream = GetMinidumpFile().getExceptionStreams();
   if (ExpectedStream)
-return &*ExpectedStream;
+return ExpectedStream.get();
 
   LLDB_LOG_ERROR(GetLog(LLDBLog::Process), ExpectedStream.takeError(),
  "Failed to read minidump exception stream: {0}");
-  return nullptr;
+  // return empty on failure.
+  return std::vector();
 }
 
 std::optional
diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.h 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
index 050ba086f46f5..e552c7210e330 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -82,7 +82,7 @@ class MinidumpParser {
   // have the same name, it keeps the copy with the lowest load address.
   std::vector GetFilteredModuleList();
 
-  const llvm::minidump::ExceptionStream *GetExceptionStream();
+  const std::vector GetExceptionStreams();
 
   std::optional FindMemoryRange(lldb::addr_t addr);
 
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp 
b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
index 13599f4a1553f..9f707c0d8a7a7 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -39,6 +39,7 @@
 
 #include 
 #include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
@@ -157,7 +158,7 @@ ProcessMinidump::ProcessMinidump(lldb::TargetSP target_sp,
  const FileSpec &core_file,
  DataBufferSP core_data)
 : PostMortemProcess(target_sp, listener_sp, core_file),
-  m_core_data(std::move(core_data)), m_active_exception(nullptr),
+  m_core_data(std::move(core_data)),
   m_is_wow64(false) {}
 
 ProcessMinidump::~ProcessMinidump() {
@@ -209,7 +210,19 @@ Status ProcessMinidump::DoLoadCore() {
   GetTarget().SetArchitecture(arch, true /*set_platform*/);
 
   m_thread_list = m_minidump_parser->GetThreads();
-  m_active_exception = m_minidump_parser->GetExceptionStream();
+  std::vector exception_streams = 
m_minidump_parser->GetExceptionStreams();
+  for (const auto &exception_stream : exception_streams) {
+if (m_exceptions_by_tid.count(exception_stream.ThreadId) > 0) {
+  // We only cast to avoid the warning around converting little endian in 
printf.
+  error.SetErrorStringWithFormat("duplicate exception stream for tid %" 
PRIu32, (uint32_t)exception_stream.ThreadId);
+  return error;
+} else 
+  m_exceptions_by_tid[exception_stream.ThreadId] = exception_stream;
+
+
+std::cout << "Adding Exception Stream # " << 
(uint32_t)exception_stream.ThreadId << std::endl;
+std::cout << "Added index " << 
(uint32_t)m_exceptions_by_tid[exception_stream.ThreadId].ExceptionRecord.ExceptionCode
 << std::endl;
+  }
 
   SetUnixSignals(UnixSignals::Create(GetArchitecture()));
 
@@ -232,60 

[Lldb-commits] [lldb] [lldb] [Platform] Introduce PlatformQNX (PR #97487)

2024-07-02 Thread Ayush Sahay via lldb-commits

https://github.com/ayushsahay1837 created 
https://github.com/llvm/llvm-project/pull/97487

This change provisions the _QNX_ platform plugin, and is the third in a series 
of changes that look to facilitate remote debug of _AArch64_ targets on _QNX_.

_QNX Neutrino Real-Time Operating System_ is a commercial Unix-like real-time 
operating system primarily targeting the embedded systems market including 
automotive, medical devices, robotics, transportation, and industrial embedded 
systems.

The series of changes in question looks to provision support for –

- Launching a debuggee
- Attaching to a debuggee
- Having the debuggee come up stopped at the entry point
- Setting breakpoints
- Stopping at breakpoints
- Reading/writing contents of/to the debuggee's memory
- Reading/writing contents of/to the debuggee's registers
- Reading/writing contents of/to the debuggee's variables
- Resuming the debuggee's execution
- Single-stepping the debuggee's execution
- Interrupting the debuggee's execution
- Dumping information pertaining to the debuggee's stack trace

Kindly note that _ptrace_ isn't available on _QNX_. Instead, _devctl_ can be 
leveraged to observe and control the execution of a process under debug on 
_QNX_.

Any additional support (including the facilitation of execution of tests) will 
be the subject of future work.

>From 30b13cd6d0f13ba41a3f40a602c6c066dceda9d6 Mon Sep 17 00:00:00 2001
From: Ted Woodward 
Date: Thu, 24 Aug 2023 11:36:32 -0500
Subject: [PATCH] [lldb] [Platform] Introduce PlatformQNX

Provision the QNX platform plugin.
---
 lldb/source/Plugins/Platform/CMakeLists.txt   |   1 +
 .../Plugins/Platform/QNX/CMakeLists.txt   |  11 +
 .../Plugins/Platform/QNX/PlatformQNX.cpp  | 313 ++
 .../source/Plugins/Platform/QNX/PlatformQNX.h |  72 
 4 files changed, 397 insertions(+)
 create mode 100644 lldb/source/Plugins/Platform/QNX/CMakeLists.txt
 create mode 100644 lldb/source/Plugins/Platform/QNX/PlatformQNX.cpp
 create mode 100644 lldb/source/Plugins/Platform/QNX/PlatformQNX.h

diff --git a/lldb/source/Plugins/Platform/CMakeLists.txt 
b/lldb/source/Plugins/Platform/CMakeLists.txt
index 6869587f917eb..d4e8669ed944b 100644
--- a/lldb/source/Plugins/Platform/CMakeLists.txt
+++ b/lldb/source/Plugins/Platform/CMakeLists.txt
@@ -7,4 +7,5 @@ add_subdirectory(NetBSD)
 add_subdirectory(OpenBSD)
 add_subdirectory(POSIX)
 add_subdirectory(QemuUser)
+add_subdirectory(QNX)
 add_subdirectory(Windows)
diff --git a/lldb/source/Plugins/Platform/QNX/CMakeLists.txt 
b/lldb/source/Plugins/Platform/QNX/CMakeLists.txt
new file mode 100644
index 0..04e5b0f864d98
--- /dev/null
+++ b/lldb/source/Plugins/Platform/QNX/CMakeLists.txt
@@ -0,0 +1,11 @@
+add_lldb_library(lldbPluginPlatformQNX PLUGIN
+  PlatformQNX.cpp
+
+   LINK_LIBS
+lldbBreakpoint
+lldbCore
+lldbHost
+lldbInterpreter
+lldbTarget
+lldbPluginPlatformPOSIX
+  )
diff --git a/lldb/source/Plugins/Platform/QNX/PlatformQNX.cpp 
b/lldb/source/Plugins/Platform/QNX/PlatformQNX.cpp
new file mode 100644
index 0..028aaf5f412a2
--- /dev/null
+++ b/lldb/source/Plugins/Platform/QNX/PlatformQNX.cpp
@@ -0,0 +1,313 @@
+//===-- PlatformQNX.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 "PlatformQNX.h"
+#include "lldb/Host/Config.h"
+
+#include 
+#if LLDB_ENABLE_POSIX
+#include 
+#endif
+
+#include "Utility/ARM64_DWARF_Registers.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+
+// Define these constants from QNX mman.h for use when targeting remote QNX
+// systems even when host has different values.
+#define MAP_PRIVATE 0x0002
+#define MAP_ANON 0x0008
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_qnx;
+
+LLDB_PLUGIN_DEFINE(PlatformQNX)
+
+static uint32_t g_initialize_count = 0;
+
+PlatformSP PlatformQNX::CreateInstance(bool force, const ArchSpec *arch) {
+  Log *log = GetLog(LLDBLog::Platform);
+  LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
+   arch ? arch->GetArchitectureName() : "",
+   arch ? arch->GetTriple().getTriple() : "");
+
+  bool create = force;
+  if (!create && arch && arch->IsValid()) {
+const llvm::Triple &triple = arch->GetTriple();
+switch (triple.getOS()) {
+case llvm::Triple::QNX:
+  create = true;
+ 

[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Support minidumps where there are multiple exception streams (PR #97470)

2024-07-02 Thread Jacob Lalonde via lldb-commits

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


[Lldb-commits] [lldb] [lldb] [Platform] Introduce PlatformQNX (PR #97487)

2024-07-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Ayush Sahay (ayushsahay1837)


Changes

This change provisions the _QNX_ platform plugin, and is the third in a series 
of changes that look to facilitate remote debug of _AArch64_ targets on _QNX_.

_QNX Neutrino Real-Time Operating System_ is a commercial Unix-like real-time 
operating system primarily targeting the embedded systems market including 
automotive, medical devices, robotics, transportation, and industrial embedded 
systems.

The series of changes in question looks to provision support for –

- Launching a debuggee
- Attaching to a debuggee
- Having the debuggee come up stopped at the entry point
- Setting breakpoints
- Stopping at breakpoints
- Reading/writing contents of/to the debuggee's memory
- Reading/writing contents of/to the debuggee's registers
- Reading/writing contents of/to the debuggee's variables
- Resuming the debuggee's execution
- Single-stepping the debuggee's execution
- Interrupting the debuggee's execution
- Dumping information pertaining to the debuggee's stack trace

Kindly note that _ptrace_ isn't available on _QNX_. Instead, _devctl_ can be 
leveraged to observe and control the execution of a process under debug on 
_QNX_.

Any additional support (including the facilitation of execution of tests) will 
be the subject of future work.

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


4 Files Affected:

- (modified) lldb/source/Plugins/Platform/CMakeLists.txt (+1) 
- (added) lldb/source/Plugins/Platform/QNX/CMakeLists.txt (+11) 
- (added) lldb/source/Plugins/Platform/QNX/PlatformQNX.cpp (+313) 
- (added) lldb/source/Plugins/Platform/QNX/PlatformQNX.h (+72) 


``diff
diff --git a/lldb/source/Plugins/Platform/CMakeLists.txt 
b/lldb/source/Plugins/Platform/CMakeLists.txt
index 6869587f917eb..d4e8669ed944b 100644
--- a/lldb/source/Plugins/Platform/CMakeLists.txt
+++ b/lldb/source/Plugins/Platform/CMakeLists.txt
@@ -7,4 +7,5 @@ add_subdirectory(NetBSD)
 add_subdirectory(OpenBSD)
 add_subdirectory(POSIX)
 add_subdirectory(QemuUser)
+add_subdirectory(QNX)
 add_subdirectory(Windows)
diff --git a/lldb/source/Plugins/Platform/QNX/CMakeLists.txt 
b/lldb/source/Plugins/Platform/QNX/CMakeLists.txt
new file mode 100644
index 0..04e5b0f864d98
--- /dev/null
+++ b/lldb/source/Plugins/Platform/QNX/CMakeLists.txt
@@ -0,0 +1,11 @@
+add_lldb_library(lldbPluginPlatformQNX PLUGIN
+  PlatformQNX.cpp
+
+   LINK_LIBS
+lldbBreakpoint
+lldbCore
+lldbHost
+lldbInterpreter
+lldbTarget
+lldbPluginPlatformPOSIX
+  )
diff --git a/lldb/source/Plugins/Platform/QNX/PlatformQNX.cpp 
b/lldb/source/Plugins/Platform/QNX/PlatformQNX.cpp
new file mode 100644
index 0..028aaf5f412a2
--- /dev/null
+++ b/lldb/source/Plugins/Platform/QNX/PlatformQNX.cpp
@@ -0,0 +1,313 @@
+//===-- PlatformQNX.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 "PlatformQNX.h"
+#include "lldb/Host/Config.h"
+
+#include 
+#if LLDB_ENABLE_POSIX
+#include 
+#endif
+
+#include "Utility/ARM64_DWARF_Registers.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+
+// Define these constants from QNX mman.h for use when targeting remote QNX
+// systems even when host has different values.
+#define MAP_PRIVATE 0x0002
+#define MAP_ANON 0x0008
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_qnx;
+
+LLDB_PLUGIN_DEFINE(PlatformQNX)
+
+static uint32_t g_initialize_count = 0;
+
+PlatformSP PlatformQNX::CreateInstance(bool force, const ArchSpec *arch) {
+  Log *log = GetLog(LLDBLog::Platform);
+  LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
+   arch ? arch->GetArchitectureName() : "",
+   arch ? arch->GetTriple().getTriple() : "");
+
+  bool create = force;
+  if (!create && arch && arch->IsValid()) {
+const llvm::Triple &triple = arch->GetTriple();
+switch (triple.getOS()) {
+case llvm::Triple::QNX:
+  create = true;
+  break;
+default:
+  break;
+}
+  }
+
+  LLDB_LOG(log, "create = {0}", create);
+  if (create) {
+return PlatformSP(new PlatformQNX(false));
+  }
+  return PlatformSP();
+}
+
+llvm::StringRef PlatformQNX::GetPluginDescriptionStatic(bool is_host) {
+  if (is_host)
+return "Local QNX user platform plug-in.";
+  return

[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Support minidumps where there are multiple exception streams (PR #97470)

2024-07-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-binary-utilities

Author: Jacob Lalonde (Jlalond)


Changes

Currently, LLDB assumes all minidumps will have unique sections. This is 
intuitive because almost all of the minidump sections are themselves lists. 
Exceptions including Signals are unique in that they are all individual 
sections with their own directory. 

This means LLDB fails to load minidumps with multiple exceptions due to them 
not being unique. This behavior is erroneous and this PR introduces support for 
an arbitrary number of exception streams. Additionally, stop info was 
calculated on for a single thread before, and now we properly support mapping 
exceptions to threads.

This PR is starting in DRAFT because implementing testing is still required.

---

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


12 Files Affected:

- (modified) lldb/source/Plugins/Process/minidump/MinidumpParser.cpp (+6-4) 
- (modified) lldb/source/Plugins/Process/minidump/MinidumpParser.h (+1-1) 
- (modified) lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp (+66-55) 
- (modified) lldb/source/Plugins/Process/minidump/ProcessMinidump.h (+1-1) 
- (modified) lldb/source/Plugins/Process/minidump/ThreadMinidump.cpp (+15-3) 
- (modified) lldb/source/Plugins/Process/minidump/ThreadMinidump.h (+3-1) 
- (modified) 
lldb/test/API/functionalities/postmortem/minidump-new/TestMiniDumpNew.py (+14) 
- (added) 
lldb/test/API/functionalities/postmortem/minidump-new/multiple-sigsev.yaml 
(+39) 
- (modified) lldb/unittests/Process/minidump/MinidumpParserTest.cpp (+7-4) 
- (modified) llvm/include/llvm/Object/Minidump.h (+31-7) 
- (modified) llvm/lib/Object/Minidump.cpp (+36) 
- (modified) llvm/lib/ObjectYAML/MinidumpYAML.cpp (+2-2) 


``diff
diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
index be9fae938e227..c51fed8d91b07 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
@@ -417,14 +417,16 @@ std::vector 
MinidumpParser::GetFilteredModuleList() {
   return filtered_modules;
 }
 
-const minidump::ExceptionStream *MinidumpParser::GetExceptionStream() {
-  auto ExpectedStream = GetMinidumpFile().getExceptionStream();
+const std::vector
+MinidumpParser::GetExceptionStreams() {
+  auto ExpectedStream = GetMinidumpFile().getExceptionStreams();
   if (ExpectedStream)
-return &*ExpectedStream;
+return ExpectedStream.get();
 
   LLDB_LOG_ERROR(GetLog(LLDBLog::Process), ExpectedStream.takeError(),
  "Failed to read minidump exception stream: {0}");
-  return nullptr;
+  // return empty on failure.
+  return std::vector();
 }
 
 std::optional
diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.h 
b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
index 050ba086f46f5..e552c7210e330 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -82,7 +82,7 @@ class MinidumpParser {
   // have the same name, it keeps the copy with the lowest load address.
   std::vector GetFilteredModuleList();
 
-  const llvm::minidump::ExceptionStream *GetExceptionStream();
+  const std::vector GetExceptionStreams();
 
   std::optional FindMemoryRange(lldb::addr_t addr);
 
diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp 
b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
index 13599f4a1553f..9a7e481b92796 100644
--- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -157,8 +157,7 @@ ProcessMinidump::ProcessMinidump(lldb::TargetSP target_sp,
  const FileSpec &core_file,
  DataBufferSP core_data)
 : PostMortemProcess(target_sp, listener_sp, core_file),
-  m_core_data(std::move(core_data)), m_active_exception(nullptr),
-  m_is_wow64(false) {}
+  m_core_data(std::move(core_data)), m_is_wow64(false) {}
 
 ProcessMinidump::~ProcessMinidump() {
   Clear();
@@ -209,7 +208,20 @@ Status ProcessMinidump::DoLoadCore() {
   GetTarget().SetArchitecture(arch, true /*set_platform*/);
 
   m_thread_list = m_minidump_parser->GetThreads();
-  m_active_exception = m_minidump_parser->GetExceptionStream();
+  std::vector exception_streams =
+  m_minidump_parser->GetExceptionStreams();
+  for (const auto &exception_stream : exception_streams) {
+if (!m_exceptions_by_tid
+ .try_emplace(exception_stream.ThreadId, exception_stream)
+ .second) {
+  // We only cast to avoid the warning around converting little endian in
+  // printf.
+  error.SetErrorStringWithFormat(
+  "duplicate exception stream for tid %" PRIu32,
+  (uint32_t)exception_stream.ThreadId);
+  return error;
+}
+  }
 
   SetU

[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Support minidumps where there are multiple exception streams (PR #97470)

2024-07-02 Thread Jacob Lalonde via lldb-commits


@@ -0,0 +1,39 @@
+--- !minidump
+Streams:
+  - Type:ThreadList
+Threads:
+  - Thread Id:   0x1B4F23
+Context: 
0B001000330006020100100010A234EBFC7F10A234EBFC7FF09C34EBFC7FC0A91ABCE97FA0163FBCE97F4602921C400030A434EBFC7FC61D40007F03801F0000FF00252525252525252525252525252525250000FF00FF00
+Stack:
+  Start of Memory Range: 0x7FFFD348
+  Content: ''
+  - Thread Id:   0x1B6D22
+Context: 
0B001000330006020100100010A234EBFC7F10A234EBFC7FF09C34EBFC7FC0A91ABCE97FA0163FBCE97F4602921C400030A434EBFC7FC61D40007F03801F0000FF00252525252525252525252525252525250000FF00FF0

[Lldb-commits] [lldb] Fix test assertions in TestDAP_stepInTargets.py (PR #96687)

2024-07-02 Thread Kendal Harland via lldb-commits

kendalharland wrote:

> Sorry, was in the middle of review then got interrupted/distracted by other 
> stuff yesterday.
> 
> Looks good.

No problem at all. Thanks for the reviews! I'll look into the build failures.

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


[Lldb-commits] [lldb] Fix flake in TestZerothFrame.py (PR #96685)

2024-07-02 Thread Kendal Harland via lldb-commits

kendalharland wrote:

Sure thing, I hadn't hooked up the formatter yet so I'll run it and reupload. 
Thanks for the reviews! 

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


[Lldb-commits] [lldb] 622df0e - [lldb] Add scripted thread plan python base class to lldb & website (#97481)

2024-07-02 Thread via lldb-commits

Author: Med Ismail Bennani
Date: 2024-07-02T15:20:18-07:00
New Revision: 622df0ee9226b90e924538909337d55333d5d2fa

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

LOG: [lldb] Add scripted thread plan python base class to lldb & website 
(#97481)

Following a feedback request in #97262, I took out the scripted thread
plan python base class from it and make a separate PR for it.

This patch adds the scripted thread plan base python class to the lldb
python module as well as the lldb documentation website.

Signed-off-by: Med Ismail Bennani 

Added: 
lldb/docs/python_extensions.rst
lldb/examples/python/templates/scripted_thread_plan.py

Modified: 
lldb/bindings/python/CMakeLists.txt
lldb/docs/CMakeLists.txt

Removed: 




diff  --git a/lldb/bindings/python/CMakeLists.txt 
b/lldb/bindings/python/CMakeLists.txt
index def6941e802bb..69306a384e0b1 100644
--- a/lldb/bindings/python/CMakeLists.txt
+++ b/lldb/bindings/python/CMakeLists.txt
@@ -108,7 +108,9 @@ function(finish_swig_python swig_target 
lldb_python_bindings_dir lldb_python_tar
 "${LLDB_SOURCE_DIR}/examples/python/templates/parsed_cmd.py"
 "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py"
 "${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py"
-"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py")
+"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py"
+"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_thread_plan.py"
+)
 
   if(APPLE)
 create_python_package(

diff  --git a/lldb/docs/CMakeLists.txt b/lldb/docs/CMakeLists.txt
index ed4296bbf03a4..f1664a6965332 100644
--- a/lldb/docs/CMakeLists.txt
+++ b/lldb/docs/CMakeLists.txt
@@ -31,6 +31,7 @@ if (LLDB_ENABLE_PYTHON AND SPHINX_FOUND)
   COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_process.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
   COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_platform.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
   COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/operating_system.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
+  COMMAND "${CMAKE_COMMAND}" -E copy 
"${LLDB_SOURCE_DIR}/examples/python/templates/scripted_thread_plan.py" 
"${CMAKE_CURRENT_BINARY_DIR}/lldb/plugins/"
   COMMENT "Copying lldb.py to pretend its a Python package.")
 
 add_dependencies(lldb-python-doc-package swig_wrapper_python lldb-python)

diff  --git a/lldb/docs/python_extensions.rst b/lldb/docs/python_extensions.rst
new file mode 100644
index 0..7e5f1ba6879db
--- /dev/null
+++ b/lldb/docs/python_extensions.rst
@@ -0,0 +1,39 @@
+Python Extensions
+=
+
+LLDB provides scriptable extensions to augment the debugger's capabilities.
+This gives users the ability to tailor their debugging experience to their own 
needs.
+
+This page describes some of these scripting extensions:
+
+Operating System Thread Plugins
+---
+
+.. automodapi:: lldb.plugins.operating_system
+:no-heading:
+:skip: ScriptedThread
+:no-inheritance-diagram:
+
+Scripted Process Plugins
+---
+
+.. automodapi:: lldb.plugins.scripted_process
+:no-heading:
+:skip: ABCMeta
+:no-inheritance-diagram:
+
+Scripted Platform Plugins
+---
+
+.. automodapi:: lldb.plugins.scripted_platform
+:no-heading:
+:skip: ABCMeta
+:no-inheritance-diagram:
+
+Scripted Thread Plan Plugins
+---
+
+.. automodapi:: lldb.plugins.scripted_thread_plan
+:no-heading:
+:no-inheritance-diagram:
+

diff  --git a/lldb/examples/python/templates/scripted_thread_plan.py 
b/lldb/examples/python/templates/scripted_thread_plan.py
new file mode 100644
index 0..67396cdfc53a2
--- /dev/null
+++ b/lldb/examples/python/templates/scripted_thread_plan.py
@@ -0,0 +1,70 @@
+from abc import abstractmethod
+
+import lldb
+
+
+class ScriptedThreadPlan:
+"""
+Class that provides data for an instance of a LLDB 'ScriptedThreadPlan' 
plug-in class used to construct custom stepping logic.
+
+"""
+
+def __init__(self, thread_plan: lldb.SBThreadPlan):
+"""Initialization needs a valid lldb.SBThreadPlan object. This plug-in 
will get created after a live process is valid and has stopped.
+
+Args:
+thread_plan (lldb.SBThreadPlan): The underlying `ThreadPlan` that 
is pushed onto the plan stack.
+"""
+self.thread_plan = thread_plan
+
+def explains_stop(self, event: lldb.SBEvent) -> bool:
+"""Each plan is asked from youngest to oldest if it "explains" the 
stop. Th

[Lldb-commits] [lldb] [lldb] Add scripted thread plan python base class to lldb & website (PR #97481)

2024-07-02 Thread Med Ismail Bennani via lldb-commits

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


[Lldb-commits] [clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-02 Thread Helena Kotas via lldb-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/97362

>From a07ea8d187cbba5717b89f5c54138f12993b3ee8 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Thu, 6 Jun 2024 11:44:56 -0700
Subject: [PATCH 1/5] wip: Stub out adding an HLSLResource builtin type

There are a couple of things that may be wrong here:

- Adding the PREDEF_TYPE to ASTBitCodes seems sketchy, but matches
  prior art.
- I skipped name mangling for now - can it come up?
- We use an unspellable name in a few places
- The type info matches `void *`. Does that make sense?
---
 clang/include/clang-c/Index.h   |  4 +++-
 clang/include/clang/AST/ASTContext.h|  1 +
 clang/include/clang/AST/BuiltinTypes.def|  3 +++
 clang/include/clang/AST/Type.h  | 12 
 clang/include/clang/Serialization/ASTBitCodes.h |  5 -
 clang/lib/AST/ASTContext.cpp|  8 
 clang/lib/AST/ExprConstant.cpp  |  1 +
 clang/lib/AST/ItaniumMangle.cpp |  4 
 clang/lib/AST/MicrosoftMangle.cpp   |  5 +
 clang/lib/AST/NSAPI.cpp |  1 +
 clang/lib/AST/Type.cpp  |  3 +++
 clang/lib/AST/TypeLoc.cpp   |  1 +
 clang/lib/CodeGen/CGDebugInfo.cpp   |  5 +
 clang/lib/CodeGen/CGDebugInfo.h |  1 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp | 13 +
 clang/lib/CodeGen/CGHLSLRuntime.h   |  2 ++
 clang/lib/CodeGen/CodeGenTypes.cpp  |  4 
 clang/lib/CodeGen/ItaniumCXXABI.cpp |  1 +
 clang/lib/Index/USRGeneration.cpp   |  2 ++
 clang/lib/Serialization/ASTCommon.cpp   |  3 +++
 clang/lib/Serialization/ASTReader.cpp   |  3 +++
 clang/tools/libclang/CIndex.cpp |  1 +
 clang/tools/libclang/CXType.cpp |  2 ++
 .../Plugins/TypeSystem/Clang/TypeSystemClang.cpp|  2 ++
 24 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index ce2282937f86c..b47407f571dfe 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2966,7 +2966,9 @@ enum CXTypeKind {
 
   CXType_ExtVector = 176,
   CXType_Atomic = 177,
-  CXType_BTFTagAttributed = 178
+  CXType_BTFTagAttributed = 178,
+
+  CXType_HLSLResource = 179
 };
 
 /**
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index de86cb5e9d7fc..57e4d7c7c6d33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1130,6 +1130,7 @@ class ASTContext : public RefCountedBase {
 #include "clang/Basic/OpenCLImageTypes.def"
   CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
   CanQualType OCLQueueTy, OCLReserveIDTy;
+  CanQualType HLSLResourceTy;
   CanQualType IncompleteMatrixIdxTy;
   CanQualType ArraySectionTy;
   CanQualType OMPArrayShapingTy, OMPIteratorTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a743..74c6585688a71 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -257,6 +257,9 @@ BUILTIN_TYPE(OCLQueue, OCLQueueTy)
 // OpenCL reserve_id_t.
 BUILTIN_TYPE(OCLReserveID, OCLReserveIDTy)
 
+// HLSL resource type
+BUILTIN_TYPE(HLSLResource, HLSLResourceTy)
+
 // This represents the type of an expression whose type is
 // totally unknown, e.g. 'T::foo'.  It is permitted for this to
 // appear in situations where the structure of the type is
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 61246479188e9..720ce7715903c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2626,6 +2626,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isBitIntType() const;// Bit-precise integer type
   bool isOpenCLSpecificType() const;// Any OpenCL specific type
 
+  bool isHLSLResourceType() const;// HLSL resource type
+  bool isHLSLSpecificType() const;  // Any HLSL specific type
+
+
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
   /// than implicitly __strong.
@@ -7887,6 +7891,14 @@ inline bool Type::isOpenCLSpecificType() const {
  isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
 }
 
+inline bool Type::isHLSLResourceType() const {
+  return isSpecificBuiltinType(BuiltinType::HLSLResource);
+}
+
+inline bool Type::isHLSLSpecificType() const {
+  return isHLSLResourceType();
+}
+
 inline bool Type::isTemplateTypeParmType() const {
   return isa(CanonicalType);
 }
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization

[Lldb-commits] [lldb] [lldb][AArch64] Add register field enum information (PR #96887)

2024-07-02 Thread Jason Molenda via lldb-commits

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

LGTM.

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


[Lldb-commits] [clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-02 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 60d4a3517610494e5b2ef6bf347cdc71a6a979e5 
6c6f17ca827feb8384441cbd6d44493954ba726f -- clang/include/clang-c/Index.h 
clang/include/clang/AST/ASTContext.h clang/include/clang/AST/Type.h 
clang/include/clang/Basic/Specifiers.h clang/include/clang/Sema/DeclSpec.h 
clang/include/clang/Serialization/ASTBitCodes.h clang/lib/AST/ASTContext.cpp 
clang/lib/AST/ASTImporter.cpp clang/lib/AST/ExprConstant.cpp 
clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/MicrosoftMangle.cpp 
clang/lib/AST/NSAPI.cpp clang/lib/AST/PrintfFormatString.cpp 
clang/lib/AST/Type.cpp clang/lib/AST/TypeLoc.cpp 
clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGDebugInfo.h 
clang/lib/CodeGen/CGHLSLRuntime.cpp clang/lib/CodeGen/CGHLSLRuntime.h 
clang/lib/CodeGen/CodeGenTypes.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp 
clang/lib/CodeGen/TargetInfo.h clang/lib/Index/USRGeneration.cpp 
clang/lib/Parse/ParseDecl.cpp clang/lib/Parse/ParseExpr.cpp 
clang/lib/Parse/ParseExprCXX.cpp clang/lib/Parse/ParseTentative.cpp 
clang/lib/Sema/DeclSpec.cpp clang/lib/Sema/SemaDecl.cpp 
clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaTemplateVariadic.cpp 
clang/lib/Sema/SemaType.cpp clang/lib/Serialization/ASTCommon.cpp 
clang/lib/Serialization/ASTReader.cpp clang/tools/libclang/CIndex.cpp 
clang/tools/libclang/CXType.cpp 
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 07f8e54b5b..34aac8d453 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2968,8 +2968,7 @@ enum CXTypeKind {
   CXType_Atomic = 177,
   CXType_BTFTagAttributed = 178,
 
-#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)   \
-  CXType_##Id,
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) CXType_##Id,
 #include "clang/Basic/HLSLIntangibleTypes.def"
 };
 
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 930b98b46c..4713e50386 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2630,7 +2630,7 @@ public:
 
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) bool is##Id##Type() const;
 #include "clang/Basic/HLSLIntangibleTypes.def"
-  bool isHLSLSpecificType() const;  // Any HLSL specific type
+  bool isHLSLSpecificType() const; // Any HLSL specific type
 
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5f6233376f..790587501a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1386,7 +1386,7 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
 
   if (LangOpts.HLSL) {
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)
\
-InitBuiltinType(SingletonId, BuiltinType::Id);
+  InitBuiltinType(SingletonId, BuiltinType::Id);
 #include "clang/Basic/HLSLIntangibleTypes.def"
   }
 
diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp
index ed6477d0a5..f5d1fbf30c 100644
--- a/clang/tools/libclang/CXType.cpp
+++ b/clang/tools/libclang/CXType.cpp
@@ -79,9 +79,9 @@ static CXTypeKind GetBuiltinTypeKind(const BuiltinType *BT) {
 BTCASE(OCLReserveID);
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) BTCASE(Id);
 #include "clang/Basic/HLSLIntangibleTypes.def"
-  default:
-return CXType_Unexposed;
-  }
+default:
+  return CXType_Unexposed;
+}
 #undef BTCASE
 }
 

``




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


[Lldb-commits] [clang] [lldb] [clang][RecordLayoutBuilder] Be stricter about inferring packed-ness in ExternalLayouts (PR #97443)

2024-07-02 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-02 Thread Helena Kotas via lldb-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/97362

>From a07ea8d187cbba5717b89f5c54138f12993b3ee8 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Thu, 6 Jun 2024 11:44:56 -0700
Subject: [PATCH 1/6] wip: Stub out adding an HLSLResource builtin type

There are a couple of things that may be wrong here:

- Adding the PREDEF_TYPE to ASTBitCodes seems sketchy, but matches
  prior art.
- I skipped name mangling for now - can it come up?
- We use an unspellable name in a few places
- The type info matches `void *`. Does that make sense?
---
 clang/include/clang-c/Index.h   |  4 +++-
 clang/include/clang/AST/ASTContext.h|  1 +
 clang/include/clang/AST/BuiltinTypes.def|  3 +++
 clang/include/clang/AST/Type.h  | 12 
 clang/include/clang/Serialization/ASTBitCodes.h |  5 -
 clang/lib/AST/ASTContext.cpp|  8 
 clang/lib/AST/ExprConstant.cpp  |  1 +
 clang/lib/AST/ItaniumMangle.cpp |  4 
 clang/lib/AST/MicrosoftMangle.cpp   |  5 +
 clang/lib/AST/NSAPI.cpp |  1 +
 clang/lib/AST/Type.cpp  |  3 +++
 clang/lib/AST/TypeLoc.cpp   |  1 +
 clang/lib/CodeGen/CGDebugInfo.cpp   |  5 +
 clang/lib/CodeGen/CGDebugInfo.h |  1 +
 clang/lib/CodeGen/CGHLSLRuntime.cpp | 13 +
 clang/lib/CodeGen/CGHLSLRuntime.h   |  2 ++
 clang/lib/CodeGen/CodeGenTypes.cpp  |  4 
 clang/lib/CodeGen/ItaniumCXXABI.cpp |  1 +
 clang/lib/Index/USRGeneration.cpp   |  2 ++
 clang/lib/Serialization/ASTCommon.cpp   |  3 +++
 clang/lib/Serialization/ASTReader.cpp   |  3 +++
 clang/tools/libclang/CIndex.cpp |  1 +
 clang/tools/libclang/CXType.cpp |  2 ++
 .../Plugins/TypeSystem/Clang/TypeSystemClang.cpp|  2 ++
 24 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index ce2282937f86c..b47407f571dfe 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2966,7 +2966,9 @@ enum CXTypeKind {
 
   CXType_ExtVector = 176,
   CXType_Atomic = 177,
-  CXType_BTFTagAttributed = 178
+  CXType_BTFTagAttributed = 178,
+
+  CXType_HLSLResource = 179
 };
 
 /**
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index de86cb5e9d7fc..57e4d7c7c6d33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1130,6 +1130,7 @@ class ASTContext : public RefCountedBase {
 #include "clang/Basic/OpenCLImageTypes.def"
   CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy;
   CanQualType OCLQueueTy, OCLReserveIDTy;
+  CanQualType HLSLResourceTy;
   CanQualType IncompleteMatrixIdxTy;
   CanQualType ArraySectionTy;
   CanQualType OMPArrayShapingTy, OMPIteratorTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a743..74c6585688a71 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -257,6 +257,9 @@ BUILTIN_TYPE(OCLQueue, OCLQueueTy)
 // OpenCL reserve_id_t.
 BUILTIN_TYPE(OCLReserveID, OCLReserveIDTy)
 
+// HLSL resource type
+BUILTIN_TYPE(HLSLResource, HLSLResourceTy)
+
 // This represents the type of an expression whose type is
 // totally unknown, e.g. 'T::foo'.  It is permitted for this to
 // appear in situations where the structure of the type is
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 61246479188e9..720ce7715903c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2626,6 +2626,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isBitIntType() const;// Bit-precise integer type
   bool isOpenCLSpecificType() const;// Any OpenCL specific type
 
+  bool isHLSLResourceType() const;// HLSL resource type
+  bool isHLSLSpecificType() const;  // Any HLSL specific type
+
+
   /// Determines if this type, which must satisfy
   /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
   /// than implicitly __strong.
@@ -7887,6 +7891,14 @@ inline bool Type::isOpenCLSpecificType() const {
  isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
 }
 
+inline bool Type::isHLSLResourceType() const {
+  return isSpecificBuiltinType(BuiltinType::HLSLResource);
+}
+
+inline bool Type::isHLSLSpecificType() const {
+  return isHLSLResourceType();
+}
+
 inline bool Type::isTemplateTypeParmType() const {
   return isa(CanonicalType);
 }
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization

[Lldb-commits] [lldb] [lldb] Improve error message for unrecognized executables (PR #97490)

2024-07-02 Thread Jonas Devlieghere via lldb-commits

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

Currently, LLDB prints out a rather unhelpful error message when passed a file 
that it doesn't recognize as an executable.

> error: '/path/to/file' doesn't contain any 'host' platform
> architectures: arm64, armv7, armv7f, armv7k, armv7s, armv7m, armv7em,
> armv6m, armv6, armv5, armv4, arm, thumbv7, thumbv7k, thumbv7s,
> thumbv7f, thumbv7m, thumbv7em, thumbv6m, thumbv6, thumbv5, thumbv4t,
> thumb, x86_64, x86_64, arm64, arm64e

I did a quick search internally and found at least 24 instances of users being 
confused by this. This patch improves the error message when it doesn't 
recognize the file as an executable, but keeps the existing error message 
otherwise, i.e. when it's an object file we understand, but the current 
platform doesn't support.

>From a4e291994cc1f2357829292d043fa05edf9f04af Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 2 Jul 2024 16:22:34 -0700
Subject: [PATCH] [lldb] Improve error message for unrecognized executables

Currently, LLDB prints out a rather unhelpful error message when passed
a file that it doesn't recognize as an executable.

  error: '/path/to/file' doesn't contain any 'host' platform
  architectures: arm64, armv7, armv7f, armv7k, armv7s, armv7m, armv7em,
  armv6m, armv6, armv5, armv4, arm, thumbv7, thumbv7k, thumbv7s,
  thumbv7f, thumbv7m, thumbv7em, thumbv6m, thumbv6, thumbv5, thumbv4t,
  thumb, x86_64, x86_64, arm64, arm64e, arm64, arm64e

I did a quick search internally and found at least 24 instances of users
being confused by this. This patch improves the error message when it
doesn't recognize the file as an executable, but keeps the existing
error message otherwise, i.e. when it's an object file we understand,
but the current platform doesn't support.
---
 lldb/include/lldb/Symbol/ObjectFile.h |  1 +
 lldb/source/Symbol/ObjectFile.cpp |  9 ++
 lldb/source/Target/Platform.cpp   | 87 ++-
 .../PECOFF/invalid-export-table.yaml  |  2 +-
 4 files changed, 55 insertions(+), 44 deletions(-)

diff --git a/lldb/include/lldb/Symbol/ObjectFile.h 
b/lldb/include/lldb/Symbol/ObjectFile.h
index 6348d8103f85d..8592323322e38 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -178,6 +178,7 @@ class ObjectFile : public 
std::enable_shared_from_this,
 lldb::offset_t file_offset,
 lldb::offset_t file_size,
 lldb_private::ModuleSpecList &specs);
+  static bool IsObjectFile(lldb_private::FileSpec file_spec);
   /// Split a path into a file path with object name.
   ///
   /// For paths like "/tmp/foo.a(bar.o)" we often need to split a path up into
diff --git a/lldb/source/Symbol/ObjectFile.cpp 
b/lldb/source/Symbol/ObjectFile.cpp
index d890ad92e8312..2608a9c5fb79a 100644
--- a/lldb/source/Symbol/ObjectFile.cpp
+++ b/lldb/source/Symbol/ObjectFile.cpp
@@ -184,6 +184,15 @@ ObjectFileSP ObjectFile::FindPlugin(const lldb::ModuleSP 
&module_sp,
   return object_file_sp;
 }
 
+bool ObjectFile::IsObjectFile(lldb_private::FileSpec file_spec) {
+  DataBufferSP data_sp;
+  offset_t data_offset = 0;
+  ModuleSP module_sp = std::make_shared(file_spec);
+  return static_cast(ObjectFile::FindPlugin(
+  module_sp, &file_spec, 0, FileSystem::Instance().GetByteSize(file_spec),
+  data_sp, data_offset));
+}
+
 size_t ObjectFile::GetModuleSpecifications(const FileSpec &file,
lldb::offset_t file_offset,
lldb::offset_t file_size,
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index b3116545b91d1..d57f644be5611 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -766,7 +766,6 @@ Status
 Platform::ResolveExecutable(const ModuleSpec &module_spec,
 lldb::ModuleSP &exe_module_sp,
 const FileSpecList *module_search_paths_ptr) {
-  Status error;
 
   // We may connect to a process and use the provided executable (Don't use
   // local $PATH).
@@ -775,55 +774,57 @@ Platform::ResolveExecutable(const ModuleSpec &module_spec,
   // Resolve any executable within a bundle on MacOSX
   Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
 
-  if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()) ||
-  module_spec.GetUUID().IsValid()) {
-if (resolved_module_spec.GetArchitecture().IsValid() ||
-resolved_module_spec.GetUUID().IsValid()) {
-  error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
-  module_search_paths_ptr, nullptr,
-  nullptr);
+  if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()) &&
+  !module_s

[Lldb-commits] [lldb] [lldb] Improve error message for unrecognized executables (PR #97490)

2024-07-02 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Currently, LLDB prints out a rather unhelpful error message when passed a file 
that it doesn't recognize as an executable.

> error: '/path/to/file' doesn't contain any 'host' platform
> architectures: arm64, armv7, armv7f, armv7k, armv7s, armv7m, armv7em,
> armv6m, armv6, armv5, armv4, arm, thumbv7, thumbv7k, thumbv7s,
> thumbv7f, thumbv7m, thumbv7em, thumbv6m, thumbv6, thumbv5, thumbv4t,
> thumb, x86_64, x86_64, arm64, arm64e

I did a quick search internally and found at least 24 instances of users being 
confused by this. This patch improves the error message when it doesn't 
recognize the file as an executable, but keeps the existing error message 
otherwise, i.e. when it's an object file we understand, but the current 
platform doesn't support.

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


4 Files Affected:

- (modified) lldb/include/lldb/Symbol/ObjectFile.h (+1) 
- (modified) lldb/source/Symbol/ObjectFile.cpp (+9) 
- (modified) lldb/source/Target/Platform.cpp (+44-43) 
- (modified) lldb/test/Shell/ObjectFile/PECOFF/invalid-export-table.yaml (+1-1) 


``diff
diff --git a/lldb/include/lldb/Symbol/ObjectFile.h 
b/lldb/include/lldb/Symbol/ObjectFile.h
index 6348d8103f85d..8592323322e38 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -178,6 +178,7 @@ class ObjectFile : public 
std::enable_shared_from_this,
 lldb::offset_t file_offset,
 lldb::offset_t file_size,
 lldb_private::ModuleSpecList &specs);
+  static bool IsObjectFile(lldb_private::FileSpec file_spec);
   /// Split a path into a file path with object name.
   ///
   /// For paths like "/tmp/foo.a(bar.o)" we often need to split a path up into
diff --git a/lldb/source/Symbol/ObjectFile.cpp 
b/lldb/source/Symbol/ObjectFile.cpp
index d890ad92e8312..2608a9c5fb79a 100644
--- a/lldb/source/Symbol/ObjectFile.cpp
+++ b/lldb/source/Symbol/ObjectFile.cpp
@@ -184,6 +184,15 @@ ObjectFileSP ObjectFile::FindPlugin(const lldb::ModuleSP 
&module_sp,
   return object_file_sp;
 }
 
+bool ObjectFile::IsObjectFile(lldb_private::FileSpec file_spec) {
+  DataBufferSP data_sp;
+  offset_t data_offset = 0;
+  ModuleSP module_sp = std::make_shared(file_spec);
+  return static_cast(ObjectFile::FindPlugin(
+  module_sp, &file_spec, 0, FileSystem::Instance().GetByteSize(file_spec),
+  data_sp, data_offset));
+}
+
 size_t ObjectFile::GetModuleSpecifications(const FileSpec &file,
lldb::offset_t file_offset,
lldb::offset_t file_size,
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index b3116545b91d1..d57f644be5611 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -766,7 +766,6 @@ Status
 Platform::ResolveExecutable(const ModuleSpec &module_spec,
 lldb::ModuleSP &exe_module_sp,
 const FileSpecList *module_search_paths_ptr) {
-  Status error;
 
   // We may connect to a process and use the provided executable (Don't use
   // local $PATH).
@@ -775,55 +774,57 @@ Platform::ResolveExecutable(const ModuleSpec &module_spec,
   // Resolve any executable within a bundle on MacOSX
   Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
 
-  if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()) ||
-  module_spec.GetUUID().IsValid()) {
-if (resolved_module_spec.GetArchitecture().IsValid() ||
-resolved_module_spec.GetUUID().IsValid()) {
-  error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
-  module_search_paths_ptr, nullptr,
-  nullptr);
+  if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()) &&
+  !module_spec.GetUUID().IsValid())
+return Status::createWithFormat("'{0}' does not exist",
+resolved_module_spec.GetFileSpec());
+
+  if (resolved_module_spec.GetArchitecture().IsValid() ||
+  resolved_module_spec.GetUUID().IsValid()) {
+Status error =
+ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
+module_search_paths_ptr, nullptr, nullptr);
 
+if (exe_module_sp && exe_module_sp->GetObjectFile())
+  return error;
+exe_module_sp.reset();
+  }
+  // No valid architecture was specified or the exact arch wasn't found.
+  // Ask the platform for the architectures that we should be using (in the
+  // correct order) and see if we can find a match that way.
+  StreamString arch_names;
+  llvm::ListSeparator LS;
+  ArchSpec process_host_arch;
+  Status error;
+  for (const ArchSpec &arch : GetSup

[Lldb-commits] [lldb] Add the ability for Script based commands to specify their "repeat command" (PR #94823)

2024-07-02 Thread Med Ismail Bennani via lldb-commits

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

LGTM!

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


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-02 Thread Med Ismail Bennani via lldb-commits


@@ -127,6 +130,171 @@ class CommandObjectScriptingRun : public CommandObjectRaw 
{
   CommandOptions m_options;
 };
 
+#pragma mark CommandObjectScriptingTemplateList
+
+#define LLDB_OPTIONS_scripting_template_list
+#include "CommandOptions.inc"
+
+class CommandObjectScriptingTemplateList : public CommandObjectParsed {
+public:
+  CommandObjectScriptingTemplateList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "scripting template list",
+"List all the available scripting affordances templates. ",
+"scripting template list [--language  --]") {}
+
+  ~CommandObjectScriptingTemplateList() override = default;
+
+  Options *GetOptions() override { return &m_options; }
+
+  class CommandOptions : public Options {
+  public:
+CommandOptions() = default;
+~CommandOptions() override = default;
+Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+  ExecutionContext *execution_context) override {
+  Status error;
+  const int short_option = m_getopt_table[option_idx].val;
+
+  switch (short_option) {
+  case 'l':
+language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
+option_arg, GetDefinitions()[option_idx].enum_values,
+eScriptLanguageNone, error);
+if (!error.Success())
+  error.SetErrorStringWithFormat("unrecognized value for language 
'%s'",
+ option_arg.str().c_str());
+break;
+  default:
+llvm_unreachable("Unimplemented option");
+  }
+
+  return error;
+}
+
+void OptionParsingStarting(ExecutionContext *execution_context) override {
+  language = lldb::eScriptLanguageNone;
+}
+
+llvm::ArrayRef GetDefinitions() override {
+  return llvm::ArrayRef(g_scripting_template_list_options);
+}
+
+lldb::ScriptLanguage language = lldb::eScriptLanguageNone;
+  };
+
+protected:
+  void DoExecute(Args &command, CommandReturnObject &result) override {
+lldb::ScriptLanguage language =
+(m_options.language == lldb::eScriptLanguageNone)
+? m_interpreter.GetDebugger().GetScriptLanguage()
+: m_options.language;
+
+if (language == lldb::eScriptLanguageNone) {
+  result.AppendError(
+  "the script-lang setting is set to none - scripting not available");
+  return;
+}
+
+ScriptInterpreter *script_interpreter =
+GetDebugger().GetScriptInterpreter(true, language);
+
+if (script_interpreter == nullptr) {
+  result.AppendError("no script interpreter");
+  return;
+}
+
+Stream &s = result.GetOutputStream();
+s.Printf("Available scripted affordances:\n");
+
+auto print_field = [&s](llvm::StringRef key, llvm::StringRef value,
+bool check_validy = false) {

medismailben wrote:

It's used in the next line. If set, it will check that the value argument isn't 
empty.

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


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-02 Thread Med Ismail Bennani via lldb-commits


@@ -127,6 +130,171 @@ class CommandObjectScriptingRun : public CommandObjectRaw 
{
   CommandOptions m_options;
 };
 
+#pragma mark CommandObjectScriptingTemplateList
+
+#define LLDB_OPTIONS_scripting_template_list
+#include "CommandOptions.inc"
+
+class CommandObjectScriptingTemplateList : public CommandObjectParsed {
+public:
+  CommandObjectScriptingTemplateList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "scripting template list",
+"List all the available scripting affordances templates. ",
+"scripting template list [--language  --]") {}
+
+  ~CommandObjectScriptingTemplateList() override = default;
+
+  Options *GetOptions() override { return &m_options; }
+
+  class CommandOptions : public Options {
+  public:
+CommandOptions() = default;
+~CommandOptions() override = default;
+Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+  ExecutionContext *execution_context) override {
+  Status error;
+  const int short_option = m_getopt_table[option_idx].val;
+
+  switch (short_option) {
+  case 'l':
+language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
+option_arg, GetDefinitions()[option_idx].enum_values,
+eScriptLanguageNone, error);
+if (!error.Success())
+  error.SetErrorStringWithFormat("unrecognized value for language 
'%s'",
+ option_arg.str().c_str());
+break;
+  default:
+llvm_unreachable("Unimplemented option");
+  }
+
+  return error;
+}
+
+void OptionParsingStarting(ExecutionContext *execution_context) override {
+  language = lldb::eScriptLanguageNone;
+}
+
+llvm::ArrayRef GetDefinitions() override {
+  return llvm::ArrayRef(g_scripting_template_list_options);
+}
+
+lldb::ScriptLanguage language = lldb::eScriptLanguageNone;
+  };
+
+protected:
+  void DoExecute(Args &command, CommandReturnObject &result) override {
+lldb::ScriptLanguage language =
+(m_options.language == lldb::eScriptLanguageNone)
+? m_interpreter.GetDebugger().GetScriptLanguage()
+: m_options.language;
+
+if (language == lldb::eScriptLanguageNone) {
+  result.AppendError(
+  "the script-lang setting is set to none - scripting not available");
+  return;
+}
+
+ScriptInterpreter *script_interpreter =
+GetDebugger().GetScriptInterpreter(true, language);
+
+if (script_interpreter == nullptr) {
+  result.AppendError("no script interpreter");
+  return;
+}
+
+Stream &s = result.GetOutputStream();
+s.Printf("Available scripted affordances:\n");

medismailben wrote:

I was thinking `scripting extensions` rather than `scripting templates` may be 
we can do both `scripting extension templates` here ?

For the second suggestion, the command has an optional `-l|--language  
` option to only print extension information for that specific 
language.

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


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-02 Thread via lldb-commits


@@ -127,6 +130,171 @@ class CommandObjectScriptingRun : public CommandObjectRaw 
{
   CommandOptions m_options;
 };
 
+#pragma mark CommandObjectScriptingTemplateList
+
+#define LLDB_OPTIONS_scripting_template_list
+#include "CommandOptions.inc"
+
+class CommandObjectScriptingTemplateList : public CommandObjectParsed {
+public:
+  CommandObjectScriptingTemplateList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "scripting template list",
+"List all the available scripting affordances templates. ",
+"scripting template list [--language  --]") {}
+
+  ~CommandObjectScriptingTemplateList() override = default;
+
+  Options *GetOptions() override { return &m_options; }
+
+  class CommandOptions : public Options {
+  public:
+CommandOptions() = default;
+~CommandOptions() override = default;
+Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+  ExecutionContext *execution_context) override {
+  Status error;
+  const int short_option = m_getopt_table[option_idx].val;
+
+  switch (short_option) {
+  case 'l':
+language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
+option_arg, GetDefinitions()[option_idx].enum_values,
+eScriptLanguageNone, error);
+if (!error.Success())
+  error.SetErrorStringWithFormat("unrecognized value for language 
'%s'",
+ option_arg.str().c_str());
+break;
+  default:
+llvm_unreachable("Unimplemented option");
+  }
+
+  return error;
+}
+
+void OptionParsingStarting(ExecutionContext *execution_context) override {
+  language = lldb::eScriptLanguageNone;
+}
+
+llvm::ArrayRef GetDefinitions() override {
+  return llvm::ArrayRef(g_scripting_template_list_options);
+}
+
+lldb::ScriptLanguage language = lldb::eScriptLanguageNone;

jimingham wrote:

should be m_language, right?

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


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-02 Thread Med Ismail Bennani via lldb-commits


@@ -127,6 +130,171 @@ class CommandObjectScriptingRun : public CommandObjectRaw 
{
   CommandOptions m_options;
 };
 
+#pragma mark CommandObjectScriptingTemplateList
+
+#define LLDB_OPTIONS_scripting_template_list
+#include "CommandOptions.inc"
+
+class CommandObjectScriptingTemplateList : public CommandObjectParsed {
+public:
+  CommandObjectScriptingTemplateList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "scripting template list",
+"List all the available scripting affordances templates. ",
+"scripting template list [--language  --]") {}
+
+  ~CommandObjectScriptingTemplateList() override = default;
+
+  Options *GetOptions() override { return &m_options; }
+
+  class CommandOptions : public Options {
+  public:
+CommandOptions() = default;
+~CommandOptions() override = default;
+Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+  ExecutionContext *execution_context) override {
+  Status error;
+  const int short_option = m_getopt_table[option_idx].val;
+
+  switch (short_option) {
+  case 'l':
+language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
+option_arg, GetDefinitions()[option_idx].enum_values,
+eScriptLanguageNone, error);
+if (!error.Success())
+  error.SetErrorStringWithFormat("unrecognized value for language 
'%s'",
+ option_arg.str().c_str());
+break;
+  default:
+llvm_unreachable("Unimplemented option");
+  }
+
+  return error;
+}
+
+void OptionParsingStarting(ExecutionContext *execution_context) override {
+  language = lldb::eScriptLanguageNone;
+}
+
+llvm::ArrayRef GetDefinitions() override {
+  return llvm::ArrayRef(g_scripting_template_list_options);
+}
+
+lldb::ScriptLanguage language = lldb::eScriptLanguageNone;

medismailben wrote:

Correct

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


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-02 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

FWIW, this is the output it's producing for now:
```
(lldb) scripting template list 
Available scripted affordances:
  Name: ScriptedProcessPythonInterface
  Language: Python
  Description: Mock process state
  Command Interpreter Usages:
process attach -C  [-k key -v value ...]
process launch -C  [-k key -v value ...]
  API Usages:
SBAttachInfo.SetScriptedProcessClassName
SBAttachInfo.SetScriptedProcessDictionary
SBTarget.Attach
SBLaunchInfo.SetScriptedProcessClassName
SBLaunchInfo.SetScriptedProcessDictionary
SBTarget.Launch

  Name: ScriptedThreadPlanPythonInterface
  Language: Python
  Description: Alter thread stepping logic and stop reason
  Command Interpreter Usages: thread step-scripted -C  [-k key -v 
value ...]
  API Usages: SBThread.StepUsingScriptedThreadPlan
```

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


  1   2   >