[Lldb-commits] [PATCH] D157667: Define qHostInfo and Mach-O LC_NOTE "addrable bits" methods to describe high and low memory addressing bits

2023-08-14 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda updated this revision to Diff 550148.
jasonmolenda added a comment.

Incorporate Jonas' suggestion of a AddressableBits class that 
GDBRemoteCommunicationClient and ObjectFileMachO could use to store the 
zero/one/two addressable bits values back to a Process, and centralizing the 
logic for how those 0-2 values are used to set the Process address masks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157667/new/

https://reviews.llvm.org/D157667

Files:
  lldb/docs/lldb-gdb-remote.txt
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/include/lldb/Utility/AddressableBits.h
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
  lldb/source/Utility/AddressableBits.cpp
  lldb/source/Utility/CMakeLists.txt

Index: lldb/source/Utility/CMakeLists.txt
===
--- lldb/source/Utility/CMakeLists.txt
+++ lldb/source/Utility/CMakeLists.txt
@@ -24,6 +24,7 @@
 endif()
 
 add_lldb_library(lldbUtility NO_INTERNAL_DEPENDENCIES
+  AddressableBits.cpp
   ArchSpec.cpp
   Args.cpp
   Baton.cpp
Index: lldb/source/Utility/AddressableBits.cpp
===
--- /dev/null
+++ lldb/source/Utility/AddressableBits.cpp
@@ -0,0 +1,50 @@
+//===-- AddressableBits.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Utility/AddressableBits.h"
+#include "lldb/Target/Process.h"
+#include "lldb/lldb-types.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+void AddressableBits::SetAddressableBits(uint32_t addressing_bits) {
+  m_low_memory_addr_bits = m_high_memory_addr_bits = addressing_bits;
+}
+
+void AddressableBits::SetAddressableBits(uint32_t lowmem_addressing_bits,
+ uint32_t highmem_addressing_bits) {
+  m_low_memory_addr_bits = lowmem_addressing_bits;
+  m_high_memory_addr_bits = highmem_addressing_bits;
+}
+
+void AddressableBits::Clear() {
+  m_low_memory_addr_bits = m_high_memory_addr_bits = 0;
+}
+
+void AddressableBits::SetProcessMasks(Process &process) {
+  // In case either value is set to 0, indicating it was not set, use the
+  // other value.
+  if (m_low_memory_addr_bits == 0)
+m_low_memory_addr_bits = m_high_memory_addr_bits;
+  if (m_high_memory_addr_bits == 0)
+m_high_memory_addr_bits = m_low_memory_addr_bits;
+
+  if (m_low_memory_addr_bits == 0)
+return;
+
+  addr_t address_mask = ~((1ULL << m_low_memory_addr_bits) - 1);
+  process.SetCodeAddressMask(address_mask);
+  process.SetDataAddressMask(address_mask);
+
+  if (m_low_memory_addr_bits != m_high_memory_addr_bits) {
+lldb::addr_t hi_address_mask = ~((1ULL << m_high_memory_addr_bits) - 1);
+process.SetHighmemCodeAddressMask(hi_address_mask);
+process.SetHighmemDataAddressMask(hi_address_mask);
+  }
+}
Index: lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
===
--- lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
+++ lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
@@ -509,10 +509,9 @@
 
   CleanupMemoryRegionPermissions();
 
-  addr_t address_mask = core_objfile->GetAddressMask();
-  if (address_mask != 0) {
-SetCodeAddressMask(address_mask);
-SetDataAddressMask(address_mask);
+  AddressableBits addressable_bits;
+  if (core_objfile->GetAddressableBits(addressable_bits)) {
+addressable_bits.SetProcessMasks(*this);
   }
   return error;
 }
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -899,10 +899,9 @@
  process_arch.GetTriple().getTriple());
   }
 
-  if (int addressable_bits = m_gdb_comm.GetAddressingBits()) {
-lldb::addr_t address_mask = ~((1ULL << addressable_bits) - 1);
-SetCodeAddressMask(address_mask);
-SetDataAddressMask(address_mask);
+  AddressableBits addressable_bits;
+  if (m_gdb_comm.GetAddressableBits(addressable_bits)) {
+addressable_bits.SetProcessMasks(*this);
   }
 
   if (process_arch.IsValid()) {
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h

[Lldb-commits] [PATCH] D157609: [lldb] Search debug file paths when looking for split DWARF files

2023-08-14 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

We are also looking for a way to locate .dwo files at Meta. One idea we came up 
with is to add a setting that can be set:

  (lldb) settings set symbols.locate-dwo-script /path/to/locate-dwo.py

Any specified scripts would be expect to contain a python function:

  def locate_dwo(exe_path: lldb.SBFileSpec, dwo_path: lldb.SBFileSpec, dwo_id: 
str):
# Add code to locate the .dwo file here...

All of our binaries are built in a "buck-out" directory and the .dwo file paths 
are relative this to folder regardless of the DW_AT_comp_dir value. If we pass 
the executable into this function, we can search for "/buck-out/" in the path, 
and then use the first part of the path as a prefix and return a valid path.

This kind of solution might allow distributed build systems to not have to 
download all of the .dwo files until they are requested and the script could 
download them and return a path.

The current solution in this patch is nice and simple and would also work, but 
it would require us to know up front where these directories are so that we can 
set the setting correctly which is what we are trying to avoid as if someone 
tries to debug and doesn't see variables due to not being able to find a .dwo 
file, then some turn the "printf pro".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157609/new/

https://reviews.llvm.org/D157609

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


[Lldb-commits] [PATCH] D157609: [lldb] Search debug file paths when looking for split DWARF files

2023-08-14 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:1737
+  if (!dwo_file.IsRelative()) {
+found = FileSystem::Instance().Exists(dwo_file);
+  } else {

Maybe we can also check the debug info search paths to see if they contain just 
the basename in case someone sends you a binary and any needed .dwo files?

So if we have a DWO path of "/users/someone/build/foo.dwo", we would check each 
of the debug info search paths for:
```
path + dwo_file.GetFilename()
```
This would allow someone to send a binary to someone else and allow them to 
load it up.

But any such search might belong down below this entire if/else statement when 
the file isn't found:

```
if (!found) {
  // Search for debug info path + basename...
}
```



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp:1795
 
-  if (!FileSystem::Instance().Exists(dwo_file)) {
+  if (!found) {
 unit.SetDwoError(Status::createWithFormat(

Here is where we might think about doing the debug info search path + basename 
searches since it doesn't matter if the .dwo file original path was relative or 
not.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157609/new/

https://reviews.llvm.org/D157609

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


[Lldb-commits] [PATCH] D157662: [lldb][NFCI] Change parameter type in Process::SetExitStatus

2023-08-14 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5a25f97e6950: [lldb][NFCI] Change parameter type in 
Process::SetExitStatus (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157662/new/

https://reviews.llvm.org/D157662

Files:
  lldb/include/lldb/Target/Process.h
  lldb/source/Target/Process.cpp


Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -1053,27 +1053,27 @@
   return nullptr;
 }
 
-bool Process::SetExitStatus(int status, const char *cstr) {
+bool Process::SetExitStatus(int status, llvm::StringRef exit_string) {
   // Use a mutex to protect setting the exit status.
   std::lock_guard guard(m_exit_status_mutex);
 
   Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
-  LLDB_LOGF(log, "(plugin = %s status=%i (0x%8.8x), description=%s%s%s)",
-   GetPluginName().data(), status, status, cstr ? "\"" : "",
-   cstr ? cstr : "NULL", cstr ? "\"" : "");
+  LLDB_LOG(log, "(plugin = {0} status = {1} ({1:x8}), description=\"{2}\")",
+   GetPluginName(), status, exit_string);
 
   // We were already in the exited state
   if (m_private_state.GetValue() == eStateExited) {
-LLDB_LOGF(log,
- "(plugin = %s) ignoring exit status because state was already set 
"
- "to eStateExited",
- GetPluginName().data());
+LLDB_LOG(
+log,
+"(plugin = {0}) ignoring exit status because state was already set "
+"to eStateExited",
+GetPluginName());
 return false;
   }
 
   m_exit_status = status;
-  if (cstr)
-m_exit_string = cstr;
+  if (!exit_string.empty())
+m_exit_string = exit_string.str();
   else
 m_exit_string.clear();
 
Index: lldb/include/lldb/Target/Process.h
===
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -1439,8 +1439,13 @@
   /// \param[in] exit_status
   /// The value for the process's return code.
   ///
-  /// \see lldb::StateType
-  virtual bool SetExitStatus(int exit_status, const char *cstr);
+  /// \param[in] exit_string
+  /// A StringRef containing the reason for exiting. May be empty.
+  ///
+  /// \return
+  /// Returns \b false if the process was already in an exited state, \b
+  /// true otherwise.
+  virtual bool SetExitStatus(int exit_status, llvm::StringRef exit_string);
 
   /// Check if a process is still alive.
   ///


Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -1053,27 +1053,27 @@
   return nullptr;
 }
 
-bool Process::SetExitStatus(int status, const char *cstr) {
+bool Process::SetExitStatus(int status, llvm::StringRef exit_string) {
   // Use a mutex to protect setting the exit status.
   std::lock_guard guard(m_exit_status_mutex);
 
   Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
-  LLDB_LOGF(log, "(plugin = %s status=%i (0x%8.8x), description=%s%s%s)",
-   GetPluginName().data(), status, status, cstr ? "\"" : "",
-   cstr ? cstr : "NULL", cstr ? "\"" : "");
+  LLDB_LOG(log, "(plugin = {0} status = {1} ({1:x8}), description=\"{2}\")",
+   GetPluginName(), status, exit_string);
 
   // We were already in the exited state
   if (m_private_state.GetValue() == eStateExited) {
-LLDB_LOGF(log,
- "(plugin = %s) ignoring exit status because state was already set "
- "to eStateExited",
- GetPluginName().data());
+LLDB_LOG(
+log,
+"(plugin = {0}) ignoring exit status because state was already set "
+"to eStateExited",
+GetPluginName());
 return false;
   }
 
   m_exit_status = status;
-  if (cstr)
-m_exit_string = cstr;
+  if (!exit_string.empty())
+m_exit_string = exit_string.str();
   else
 m_exit_string.clear();
 
Index: lldb/include/lldb/Target/Process.h
===
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -1439,8 +1439,13 @@
   /// \param[in] exit_status
   /// The value for the process's return code.
   ///
-  /// \see lldb::StateType
-  virtual bool SetExitStatus(int exit_status, const char *cstr);
+  /// \param[in] exit_string
+  /// A StringRef containing the reason for exiting. May be empty.
+  ///
+  /// \return
+  /// Returns \b false if the process was already in an exited state, \b
+  /// true otherwise.
+  virtual bool SetExitStatus(int exit_status, llvm::StringRef exit_string);
 
   /// Check if a process is still alive.
   ///
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi

[Lldb-commits] [lldb] 5a25f97 - [lldb][NFCI] Change parameter type in Process::SetExitStatus

2023-08-14 Thread Alex Langford via lldb-commits

Author: Alex Langford
Date: 2023-08-14T15:49:03-07:00
New Revision: 5a25f97e69500d4f65ce0e56027787752c7aab61

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

LOG: [lldb][NFCI] Change parameter type in Process::SetExitStatus

My primary motivation here is actually to change something in
UnixSignals, but this change is a necesary precondition.

I've also updated the documentation and rewritten the log statements to
use `formatv` instead of `printf` (printf-style formatting and
llvm::StringRef don't mix well).

Differential Revision: https://reviews.llvm.org/D157662

Added: 


Modified: 
lldb/include/lldb/Target/Process.h
lldb/source/Target/Process.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index affd3fbc37b07a..6ea6f82548aaf8 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1439,8 +1439,13 @@ class Process : public 
std::enable_shared_from_this,
   /// \param[in] exit_status
   /// The value for the process's return code.
   ///
-  /// \see lldb::StateType
-  virtual bool SetExitStatus(int exit_status, const char *cstr);
+  /// \param[in] exit_string
+  /// A StringRef containing the reason for exiting. May be empty.
+  ///
+  /// \return
+  /// Returns \b false if the process was already in an exited state, \b
+  /// true otherwise.
+  virtual bool SetExitStatus(int exit_status, llvm::StringRef exit_string);
 
   /// Check if a process is still alive.
   ///

diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 447d03b1cb288e..ea08ddb6bfedaa 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -1053,27 +1053,27 @@ const char *Process::GetExitDescription() {
   return nullptr;
 }
 
-bool Process::SetExitStatus(int status, const char *cstr) {
+bool Process::SetExitStatus(int status, llvm::StringRef exit_string) {
   // Use a mutex to protect setting the exit status.
   std::lock_guard guard(m_exit_status_mutex);
 
   Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
-  LLDB_LOGF(log, "(plugin = %s status=%i (0x%8.8x), description=%s%s%s)",
-   GetPluginName().data(), status, status, cstr ? "\"" : "",
-   cstr ? cstr : "NULL", cstr ? "\"" : "");
+  LLDB_LOG(log, "(plugin = {0} status = {1} ({1:x8}), description=\"{2}\")",
+   GetPluginName(), status, exit_string);
 
   // We were already in the exited state
   if (m_private_state.GetValue() == eStateExited) {
-LLDB_LOGF(log,
- "(plugin = %s) ignoring exit status because state was already set 
"
- "to eStateExited",
- GetPluginName().data());
+LLDB_LOG(
+log,
+"(plugin = {0}) ignoring exit status because state was already set "
+"to eStateExited",
+GetPluginName());
 return false;
   }
 
   m_exit_status = status;
-  if (cstr)
-m_exit_string = cstr;
+  if (!exit_string.empty())
+m_exit_string = exit_string.str();
   else
 m_exit_string.clear();
 



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


[Lldb-commits] [PATCH] D157122: [lldb] Remove support for SBHostOS threading functionality

2023-08-14 Thread Alex Langford via Phabricator via lldb-commits
bulbazord abandoned this revision.
bulbazord added a comment.

Landed as 69fdbdc4493aacf4d418a063930b39b02b5e18c5 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157122/new/

https://reviews.llvm.org/D157122

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


[Lldb-commits] [lldb] 69fdbdc - [lldb] Remove support for SBHostOS threading functionality

2023-08-14 Thread Alex Langford via lldb-commits

Author: Alex Langford
Date: 2023-08-14T14:33:08-07:00
New Revision: 69fdbdc4493aacf4d418a063930b39b02b5e18c5

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

LOG: [lldb] Remove support for SBHostOS threading functionality

As stated on Discourse*, these methods have been deprecated. I am
removing their implementation. They will now do nothing and return a
value indicating failure (where appropriate).
Due to the LLDB project's commitment to ABI stability at the SB API
layer, we cannot remove these symbols completely.

Discourse link: 
https://discourse.llvm.org/t/do-you-use-the-threading-functionality-in-sbhostos/71973

Added: 


Modified: 
lldb/source/API/SBHostOS.cpp
llvm/docs/ReleaseNotes.rst

Removed: 




diff  --git a/lldb/source/API/SBHostOS.cpp b/lldb/source/API/SBHostOS.cpp
index cb026fd9203b9b..a77a703bba37b5 100644
--- a/lldb/source/API/SBHostOS.cpp
+++ b/lldb/source/API/SBHostOS.cpp
@@ -101,61 +101,23 @@ lldb::thread_t SBHostOS::ThreadCreate(const char *name,
   lldb::thread_func_t thread_function,
   void *thread_arg, SBError *error_ptr) {
   LLDB_INSTRUMENT_VA(name, thread_function, thread_arg, error_ptr);
-  llvm::Expected thread =
-  ThreadLauncher::LaunchThread(name, [thread_function, thread_arg] {
-return thread_function(thread_arg);
-  });
-  if (!thread) {
-if (error_ptr)
-  error_ptr->SetError(Status(thread.takeError()));
-else
-  llvm::consumeError(thread.takeError());
-return LLDB_INVALID_HOST_THREAD;
-  }
-
-  return thread->Release();
+  return LLDB_INVALID_HOST_THREAD;
 }
 
 void SBHostOS::ThreadCreated(const char *name) { LLDB_INSTRUMENT_VA(name); }
 
 bool SBHostOS::ThreadCancel(lldb::thread_t thread, SBError *error_ptr) {
   LLDB_INSTRUMENT_VA(thread, error_ptr);
-
-  Status error;
-  HostThread host_thread(thread);
-  error = host_thread.Cancel();
-  if (error_ptr)
-error_ptr->SetError(error);
-  host_thread.Release();
-  return error.Success();
+  return false;
 }
 
 bool SBHostOS::ThreadDetach(lldb::thread_t thread, SBError *error_ptr) {
   LLDB_INSTRUMENT_VA(thread, error_ptr);
-
-  Status error;
-#if defined(_WIN32)
-  if (error_ptr)
-error_ptr->SetErrorString("ThreadDetach is not supported on this 
platform");
-#else
-  HostThread host_thread(thread);
-  error = host_thread.GetNativeThread().Detach();
-  if (error_ptr)
-error_ptr->SetError(error);
-  host_thread.Release();
-#endif
-  return error.Success();
+  return false;
 }
 
 bool SBHostOS::ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result,
   SBError *error_ptr) {
   LLDB_INSTRUMENT_VA(thread, result, error_ptr);
-
-  Status error;
-  HostThread host_thread(thread);
-  error = host_thread.Join(result);
-  if (error_ptr)
-error_ptr->SetError(error);
-  host_thread.Release();
-  return error.Success();
+  return false;
 }

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 3d50c3f6fd8f95..4d0d531485051c 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -151,6 +151,9 @@ Changes to the LLVM tools
 Changes to LLDB
 -
 
+* Methods in SBHostOS related to threads have had their implementations
+  removed. These methods will return a value indicating failure.
+
 Changes to Sanitizers
 -
 * HWASan now defaults to detecting use-after-scope bugs.



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


[Lldb-commits] [PATCH] D157760: [lldb] Properly protect the Communication class with reader/writer lock

2023-08-14 Thread Augusto Noronha via Phabricator via lldb-commits
augusto2112 added inline comments.



Comment at: lldb/include/lldb/Core/Communication.h:86-89
+  lldb_private::Connection *GetConnection() {
+std::shared_lock guard(m_connection_mutex);
+return m_connection_sp.get();
+  }

bulbazord wrote:
> This isn't necessarily introduced by your patch, but I don't think this lock 
> does much other than make sure nobody can change `m_connection_sp` in between 
> you calling `GetConnection` and you actually receiving the `Connection` 
> pointer. It still comes with all the pitfalls of handing out a raw pointer 
> (instead of a `shared_ptr`).
> 
> As a follow-up or maybe even precursor, we should probably stop handing out 
> the raw connection pointer...
I agree. I think we should do it after this patch though.



Comment at: lldb/include/lldb/Core/Communication.h:172-174
   std::mutex
   m_write_mutex; ///< Don't let multiple threads write at the same time...
+  mutable std::shared_mutex m_connection_mutex;

JDevlieghere wrote:
> Why do we need both? Can't we use `m_connection_mutex` in write mode instead 
> of `m_write_mutex`?
If we use `m_connection_mutex` in write mode instead of m_write_mutex then we 
can't have concurrent reads and writes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157760/new/

https://reviews.llvm.org/D157760

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


[Lldb-commits] [PATCH] D157756: Support corefiles that put the uuid of their binary in a fixed address in low memory; load that binary

2023-08-14 Thread Jim Ingham via Phabricator via lldb-commits
jingham accepted this revision.
jingham added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157756/new/

https://reviews.llvm.org/D157756

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


[Lldb-commits] [PATCH] D157759: [lldb] Remove use of __future__ in python

2023-08-14 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe634c2f71493: [lldb] Remove use of __future__ in python 
(authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157759/new/

https://reviews.llvm.org/D157759

Files:
  lldb/docs/conf.py
  lldb/packages/Python/lldbsuite/support/gmodules.py
  lldb/packages/Python/lldbsuite/test/__init__.py
  lldb/packages/Python/lldbsuite/test/bench.py
  lldb/packages/Python/lldbsuite/test/configuration.py
  lldb/packages/Python/lldbsuite/test/decorators.py
  lldb/packages/Python/lldbsuite/test/dotest.py
  lldb/packages/Python/lldbsuite/test/dotest_args.py
  lldb/packages/Python/lldbsuite/test/lldb_pylint_helper.py
  lldb/packages/Python/lldbsuite/test/lldbbench.py
  lldb/packages/Python/lldbsuite/test/lldbinline.py
  lldb/packages/Python/lldbsuite/test/lldbpexpect.py
  lldb/packages/Python/lldbsuite/test/lldbplatform.py
  lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/packages/Python/lldbsuite/test/lldbutil.py
  lldb/packages/Python/lldbsuite/test/test_categories.py
  lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
  lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
  lldb/scripts/android/host_art_bt.py
  lldb/third_party/Python/module/progress/progress.py
  lldb/third_party/Python/module/unittest2/unittest2/test/test_result.py
  lldb/third_party/Python/module/unittest2/unittest2/test/test_unittest2_with.py
  lldb/tools/intel-features/intel-mpx/test/TestMPXTable.py
  lldb/utils/lui/lldbutil.py

Index: lldb/utils/lui/lldbutil.py
===
--- lldb/utils/lui/lldbutil.py
+++ lldb/utils/lui/lldbutil.py
@@ -12,8 +12,6 @@
 They can also be useful for general purpose lldb scripting.
 """
 
-from __future__ import print_function
-
 import lldb
 import os
 import sys
Index: lldb/tools/intel-features/intel-mpx/test/TestMPXTable.py
===
--- lldb/tools/intel-features/intel-mpx/test/TestMPXTable.py
+++ lldb/tools/intel-features/intel-mpx/test/TestMPXTable.py
@@ -2,9 +2,6 @@
 Test mpx-table command.
 """
 
-from __future__ import print_function
-
-
 import os
 import time
 import re
Index: lldb/third_party/Python/module/unittest2/unittest2/test/test_unittest2_with.py
===
--- lldb/third_party/Python/module/unittest2/unittest2/test/test_unittest2_with.py
+++ lldb/third_party/Python/module/unittest2/unittest2/test/test_unittest2_with.py
@@ -1,5 +1,3 @@
-from __future__ import with_statement
-
 import unittest2
 from unittest2.test.support import OldTestResult, catch_warnings
 
Index: lldb/third_party/Python/module/unittest2/unittest2/test/test_result.py
===
--- lldb/third_party/Python/module/unittest2/unittest2/test/test_result.py
+++ lldb/third_party/Python/module/unittest2/unittest2/test/test_result.py
@@ -1,5 +1,3 @@
-from __future__ import print_function
-
 import sys
 import textwrap
 from StringIO import StringIO
Index: lldb/third_party/Python/module/progress/progress.py
===
--- lldb/third_party/Python/module/progress/progress.py
+++ lldb/third_party/Python/module/progress/progress.py
@@ -1,7 +1,5 @@
 #!/usr/bin/env python
 
-from __future__ import print_function
-
 import use_lldb_suite
 
 import sys
Index: lldb/scripts/android/host_art_bt.py
===
--- lldb/scripts/android/host_art_bt.py
+++ lldb/scripts/android/host_art_bt.py
@@ -5,8 +5,6 @@
 #   'command script import host_art_bt.py'
 #   'host_art_bt'
 
-from __future__ import print_function
-
 import sys
 import re
 
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
===
--- lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
@@ -1,8 +1,6 @@
 """Module for supporting unit testing of the lldb-server debug monitor exe.
 """
 
-from __future__ import division, print_function
-
 import binascii
 import os
 import os.path
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
===
--- lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
@@ -2,9 +2,6 @@
 Base class for gdb-remote test cases.
 """
 
-from __future__ import division, print_function
-
-
 import errno
 import os
 import os.path
Index: lldb/packages/Python/lldbsuite/test/test_categories.py

[Lldb-commits] [lldb] e634c2f - [lldb] Remove use of __future__ in python

2023-08-14 Thread Alex Langford via lldb-commits

Author: Alex Langford
Date: 2023-08-14T14:14:48-07:00
New Revision: e634c2f7149392b62e93c1b2b75701a12bc06721

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

LOG: [lldb] Remove use of __future__ in python

These were useful primarily for the Python 2 to 3 transition. Python 2
is no longer supported so these are no longer necessary.

Differential Revision: https://reviews.llvm.org/D157759

Added: 


Modified: 
lldb/docs/conf.py
lldb/packages/Python/lldbsuite/support/gmodules.py
lldb/packages/Python/lldbsuite/test/__init__.py
lldb/packages/Python/lldbsuite/test/bench.py
lldb/packages/Python/lldbsuite/test/configuration.py
lldb/packages/Python/lldbsuite/test/decorators.py
lldb/packages/Python/lldbsuite/test/dotest.py
lldb/packages/Python/lldbsuite/test/dotest_args.py
lldb/packages/Python/lldbsuite/test/lldb_pylint_helper.py
lldb/packages/Python/lldbsuite/test/lldbbench.py
lldb/packages/Python/lldbsuite/test/lldbinline.py
lldb/packages/Python/lldbsuite/test/lldbpexpect.py
lldb/packages/Python/lldbsuite/test/lldbplatform.py
lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
lldb/packages/Python/lldbsuite/test/lldbtest.py
lldb/packages/Python/lldbsuite/test/lldbutil.py
lldb/packages/Python/lldbsuite/test/test_categories.py
lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
lldb/scripts/android/host_art_bt.py
lldb/third_party/Python/module/progress/progress.py
lldb/third_party/Python/module/unittest2/unittest2/test/test_result.py

lldb/third_party/Python/module/unittest2/unittest2/test/test_unittest2_with.py
lldb/tools/intel-features/intel-mpx/test/TestMPXTable.py
lldb/utils/lui/lldbutil.py

Removed: 




diff  --git a/lldb/docs/conf.py b/lldb/docs/conf.py
index 50d45f2971f550..7c4c945f25babe 100644
--- a/lldb/docs/conf.py
+++ b/lldb/docs/conf.py
@@ -10,8 +10,6 @@
 #
 # All configuration values have a default; values that are commented out
 # serve to show the default.
-from __future__ import print_function
-
 import sys, os, re, shutil
 from datetime import date
 

diff  --git a/lldb/packages/Python/lldbsuite/support/gmodules.py 
b/lldb/packages/Python/lldbsuite/support/gmodules.py
index 80213092e67fb5..81185a56422667 100644
--- a/lldb/packages/Python/lldbsuite/support/gmodules.py
+++ b/lldb/packages/Python/lldbsuite/support/gmodules.py
@@ -1,6 +1,3 @@
-from __future__ import absolute_import
-from __future__ import print_function
-
 # System modules
 import os
 import re

diff  --git a/lldb/packages/Python/lldbsuite/test/__init__.py 
b/lldb/packages/Python/lldbsuite/test/__init__.py
index 93971c2f2364be..b7390580876b7e 100644
--- a/lldb/packages/Python/lldbsuite/test/__init__.py
+++ b/lldb/packages/Python/lldbsuite/test/__init__.py
@@ -1,7 +1,5 @@
 # Module level initialization for the `lldbsuite.test` module.
 
-from __future__ import absolute_import
-
 from . import dotest
 
 run_suite = dotest.run_suite

diff  --git a/lldb/packages/Python/lldbsuite/test/bench.py 
b/lldb/packages/Python/lldbsuite/test/bench.py
index 3fe301f36d1a7e..1a11b3ef4f0e64 100644
--- a/lldb/packages/Python/lldbsuite/test/bench.py
+++ b/lldb/packages/Python/lldbsuite/test/bench.py
@@ -12,9 +12,6 @@
 ./bench.py -e /Volumes/data/lldb/svn/regression/build/Debug/lldb -x '-F 
Driver::MainLoop()' 2>&1 | grep -P '^lldb.*benchmark:'
 """
 
-from __future__ import print_function
-from __future__ import absolute_import
-
 import os
 from optparse import OptionParser
 

diff  --git a/lldb/packages/Python/lldbsuite/test/configuration.py 
b/lldb/packages/Python/lldbsuite/test/configuration.py
index 0085117b954202..2a4b9b3c070c7f 100644
--- a/lldb/packages/Python/lldbsuite/test/configuration.py
+++ b/lldb/packages/Python/lldbsuite/test/configuration.py
@@ -7,9 +7,6 @@
 how this invocation of the test suite should be run.
 """
 
-from __future__ import absolute_import
-from __future__ import print_function
-
 # System modules
 import os
 

diff  --git a/lldb/packages/Python/lldbsuite/test/decorators.py 
b/lldb/packages/Python/lldbsuite/test/decorators.py
index b9ac170b84df9b..5562130aa34079 100644
--- a/lldb/packages/Python/lldbsuite/test/decorators.py
+++ b/lldb/packages/Python/lldbsuite/test/decorators.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import
-
 # System modules
 from distutils.version import LooseVersion
 from functools import wraps

diff  --git a/lldb/packages/Python/lldbsuite/test/dotest.py 
b/lldb/packages/Python/lldbsuite/test/dotest.py
index 1b2076f593932d..a27d8cf321f829 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -18,9 +18,6

[Lldb-commits] [PATCH] D157759: [lldb] Remove use of __future__ in python

2023-08-14 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.

In D157759#4581673 , @mib wrote:

> LGTM! Although we should make sure no one is still using Python 2 downstream

Python 2 has been deprecated for a while and we've removed other stuff that 
makes it no longer possible to use Python 2.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157759/new/

https://reviews.llvm.org/D157759

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


[Lldb-commits] [PATCH] D157760: [lldb] Properly protect the Communication class with reader/writer lock

2023-08-14 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/include/lldb/Core/Communication.h:172-174
   std::mutex
   m_write_mutex; ///< Don't let multiple threads write at the same time...
+  mutable std::shared_mutex m_connection_mutex;

Why do we need both? Can't we use `m_connection_mutex` in write mode instead of 
`m_write_mutex`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157760/new/

https://reviews.llvm.org/D157760

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


[Lldb-commits] [PATCH] D157497: feat: Migrate isArch16Bit

2023-08-14 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

In D157497#4586165 , @MaskRay wrote:

> In D157497#4584621 , @Pivnoy wrote:
>
>> This discussion was the main motivation for this change.
>> https://discourse.llvm.org/t/rfc-refactor-triple-related-classes/70410/11
>> As a result, Triple should become a data class, and its dependencies such as 
>> Architecture, Operating System etc. represent in the form of interfaces that 
>> can be implemented for the necessary instances.
>
> FWIW I still don't see advantages by switching to the new 
> `llvm::TripleUtils::isArch32Bit` style. How is it better than the current way?

+1
What advantages does this approach bring? I re-read the RFC in the discourse 
link you posted and I'm still not sure why this approach is desirable. Happy to 
discuss further either on this PR or in the discourse thread.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157497/new/

https://reviews.llvm.org/D157497

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


[Lldb-commits] [PATCH] D157667: Define qHostInfo and Mach-O LC_NOTE "addrable bits" methods to describe high and low memory addressing bits

2023-08-14 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h:125-126
 
-  lldb::addr_t GetAddressMask() override;
+  bool GetAddressMask(lldb::addr_t &lowmem_mask,
+  lldb::addr_t &highmem_mask) override;
 

I would prefer this to return a struct with the two masks, possibly living in 
Utility. The struct would centralize default values, which values are 
meaningful, etc and could be stored as a member in 
`GDBRemoteCommunicationClient`. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157667/new/

https://reviews.llvm.org/D157667

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


[Lldb-commits] [PATCH] D157497: feat: Migrate isArch16Bit

2023-08-14 Thread Fangrui Song via Phabricator via lldb-commits
MaskRay added a comment.

In D157497#4584621 , @Pivnoy wrote:

> This discussion was the main motivation for this change.
> https://discourse.llvm.org/t/rfc-refactor-triple-related-classes/70410/11
> As a result, Triple should become a data class, and its dependencies such as 
> Architecture, Operating System etc. represent in the form of interfaces that 
> can be implemented for the necessary instances.

FWIW I still don't see advantages by switching to the new 
`llvm::TripleUtils::isArch32Bit` style. How is it better than the current way?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157497/new/

https://reviews.llvm.org/D157497

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


[Lldb-commits] [PATCH] D157849: [lldb/crashlog] Replace deprecated optparse by argparse (NFC)

2023-08-14 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

Makes sense to me. `optparse` has been deprecated since Python 3.2 in favor of 
`argparse`. It's good to get ahead of the curve here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157849/new/

https://reviews.llvm.org/D157849

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


[Lldb-commits] [PATCH] D157760: [lldb] Properly protect the Communication class with reader/writer lock

2023-08-14 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/include/lldb/Core/Communication.h:86-89
+  lldb_private::Connection *GetConnection() {
+std::shared_lock guard(m_connection_mutex);
+return m_connection_sp.get();
+  }

This isn't necessarily introduced by your patch, but I don't think this lock 
does much other than make sure nobody can change `m_connection_sp` in between 
you calling `GetConnection` and you actually receiving the `Connection` 
pointer. It still comes with all the pitfalls of handing out a raw pointer 
(instead of a `shared_ptr`).

As a follow-up or maybe even precursor, we should probably stop handing out the 
raw connection pointer...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157760/new/

https://reviews.llvm.org/D157760

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


[Lldb-commits] [PATCH] D157512: [lldb][PlatformDarwin] Only parse SDK from debug-info if target language is Objective-C

2023-08-14 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

Apart from Jim's comment (does this still work?) this seems like a reasonable 
heuristic.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157512/new/

https://reviews.llvm.org/D157512

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


[Lldb-commits] [PATCH] D157883: [lldb][AArch64] Add SME's Array Storage (ZA) and streaming vector length (SVG) registers

2023-08-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

I realise this is a giant patch, so if you see a way to split it, great. 
However, SVG is read from the ZA header and we need SVG to implement the 
resizing of ZA. So at least those are tied to each other.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157883/new/

https://reviews.llvm.org/D157883

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


[Lldb-commits] [PATCH] D154927: [lldb][AArch64] Add SME's streaming vector control register

2023-08-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 549951.
DavidSpickett added a comment.

Rebase and reimplement this on top of ZA/SVG.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154927/new/

https://reviews.llvm.org/D154927

Files:
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
  
lldb/test/API/commands/register/register/aarch64_dynamic_regset/TestArm64DynamicRegsets.py
  
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/TestSVERegisters.py
  
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/main.c
  
lldb/test/API/commands/register/register/aarch64_za_reg/za_save_restore/TestZARegisterSaveRestore.py

Index: lldb/test/API/commands/register/register/aarch64_za_reg/za_save_restore/TestZARegisterSaveRestore.py
===
--- lldb/test/API/commands/register/register/aarch64_za_reg/za_save_restore/TestZARegisterSaveRestore.py
+++ lldb/test/API/commands/register/register/aarch64_za_reg/za_save_restore/TestZARegisterSaveRestore.py
@@ -149,6 +149,10 @@
 self.runCmd("register read " + sve_reg_names)
 sve_values = self.res.GetOutput()
 
+svcr_value = 1 if sve_mode == Mode.SSVE else 0
+if za_state == ZA.Enabled:
+svcr_value += 2
+
 def check_regs():
 if za_state == ZA.Enabled:
 self.check_za(start_vl)
@@ -160,6 +164,7 @@
 self.assertEqual(start_vg, self.read_vg())
 
 self.expect("register read " + sve_reg_names, substrs=[sve_values])
+self.expect("register read svcr", substrs=["0x{:016x}".format(svcr_value)])
 
 for expr in exprs:
 expr_cmd = "expression {}()".format(expr)
Index: lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/main.c
===
--- lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/main.c
+++ lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/main.c
@@ -5,7 +5,7 @@
 #define PR_SME_SET_VL 63
 #endif
 
-#define SMSTART() asm volatile("msr  s0_3_c4_c7_3, xzr" /*smstart*/)
+#define SMSTART_SM() asm volatile("msr  s0_3_c4_c3_3, xzr" /*smstart sm*/)
 
 void write_sve_regs() {
   // We assume the smefa64 feature is present, which allows ffr access
@@ -126,18 +126,18 @@
   // Note that doing a syscall brings you back to non-streaming mode, so we
   // don't need to SMSTOP here.
   if (streaming)
-SMSTART();
+SMSTART_SM();
   write_sve_regs_expr();
   prctl(SET_VL_OPT, 8 * 4);
   if (streaming)
-SMSTART();
+SMSTART_SM();
   write_sve_regs_expr();
   return 1;
 }
 
 int main() {
 #ifdef START_SSVE
-  SMSTART();
+  SMSTART_SM();
 #endif
   write_sve_regs();
 
Index: lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/TestSVERegisters.py
===
--- lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/TestSVERegisters.py
+++ lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/TestSVERegisters.py
@@ -24,7 +24,14 @@
 reg_value.GetByteSize(), expected, 'Verify "%s" == %i' % (name, expected)
 )
 
-def check_sve_regs_read(self, z_reg_size):
+def check_sve_regs_read(self, z_reg_size, expected_mode):
+if self.isAArch64SME():
+# This test uses SMSTART SM, which only enables streaming mode,
+# leaving ZA disabled.
+expected_value = "1" if expected_mode == Mode.SSVE else "0"
+self.expect("register read svcr", substrs=[
+"0x000" + expected_value])
+
 p_reg_size = int(z_reg_size / 8)
 
 for i in range(32):
@@ -168,7 +175,7 @@
 
 vg_reg_value = sve_registers.GetChildMemberWithName("vg").GetValueAsUnsigned()
 z_reg_size = vg_reg_value * 8
-self.check_sve_regs_read(z_reg_size)
+self.check_sve_regs_read(z_reg_size, start_mode)
 
 # Evaluate simple expression and print function expr_eval_func address.
 self.expect("expression expr_eval_func", substrs=["= 0x"])
@@ -184,7 +191,7 @@
 
 # We called a jitted function above which must not have changed SVE
 # vector length or register values.
-self.check_sve_regs_read(z_reg_size)
+self.check_sve_regs_read(z_reg_size, start_mode)
 
 self.check_sve_regs_read_after_write(z_reg_size)
 
Index: lldb/test/API/commands/register/register/aarch64_dynamic_regset/TestArm64DynamicRegsets.py
===
--- lldb/test/API/

[Lldb-commits] [PATCH] D157883: [lldb][AArch64] Add SME's Array Storage (ZA) and streaming vector length (SVG) registers

2023-08-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added subscribers: ctetreau, kristof.beyls.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added subscribers: lldb-commits, alextsao1999.
Herald added a project: LLDB.

The "Matrix" part of the Scalable Matrix Extension is a new register
"ZA". You can think of this as a square matrix made up of scalable rows,
where each row is one scalable vector long. However it is not made
of the existing scalable vector registers, it is its own register.
Meaning that the size of ZA is the vector length in bytes * the vector
length in bytes.

https://developer.arm.com/documentation/ddi0616/latest/

It uses the streaming vector length, even when streaming mode itself
is not active. For this reason, it's register data heeader always includes
the streaming vector length and I've added a pseudo register "SVG"
for users to be able to see this. Since they may be interacting
with ZA outside of streaming mode, where "VG" would be the non-streaming
vector length.

Due to it's size I've changed kMaxRegisterByteSize to the maximum
possible ZA size and kTypicalRegisterByteSize will be the maximum
possible scalable vector size. Therefore ZA transactions will cause heap
allocations, and non ZA registers will perform exactly as before.

ZA can be enabled and disabled independently of streaming mode. The way
this works in ptrace is different to SVE versus streaming SVE. Writing
NT_ARM_ZA without register data disables ZA, writing NT_ARM_ZA with
register data enables ZA (LLDB will only support the latter, and only
because it's convenient for us to do so).

https://kernel.org/doc/html/v6.2/arm64/sme.html

LLDB does not handle registers that can appear and dissappear at
runtime. Rather than add complexity to implement that, LLDB will
show a block of 0s when ZA is disabled.

The alternative is not only updating the vector lengths every stop,
but every register definition. It's possible but I'm not sure it's worth
pursuing.

Users should refer to the SVCR register (added in the next patch)
for the final word on whether ZA is active or not.

Writing to "VG" during streaming mode will change the size of the
streaming sve registers and ZA. LLDB will not attempt to preserve
register values in this case, we'll just read back the undefined
content the kernel shows. This is in line with, as stated, the
kernel ABIs and the prospective software ABIs look like.

ZA is defined as a vector of size SVL*SVL, so the display in lldb
is very basic. A giant block of values. This is no worse than SVE,
just larger. There is scope to improve this but that can wait
until we see some use cases.

Testing:

- TestSVEThreadedDynamic now checks for correct SVG values.
- New test TestZAThreadedDynamic creates 3 threads with different ZA sizes and 
states and switches between them verifying the register value (derived from the 
existing threaded SVE test).
- New test TestZARegisterSaveRestore starts in a given SME state, runs a set of 
expressions in various orders, then checks that the original state has been 
restored.
- TestArm64DynamicRegsets has ZA and SVG checks added, including writing to ZA 
to enable it.

An SME enabled program has the following extra state:

- Streaming mode or non-streaming mode.
- ZA enabled or disabled.
- The active vector length.

Covering the transition between all possible states and all other
possible states is not viable, therefore the testing is a cross
section of that, all of which found real bugs in LLDB and the Linux
Kernel during development.

Many of those transitions will not be possible via LLDB
(e.g. disabling ZA) and many more are possible but unlikely to be
used in normal use.

Running these tests will as usual require QEMU as there is no
real SME hardware available at this time, and a very recent
kernel.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157883

Files:
  lldb/include/lldb/Utility/RegisterValue.h
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
  lldb/source/Plugins/Process/Utility/LinuxPTraceDefines_arm64sve.h
  lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
  lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Target/DynamicRegisterInfo.cpp
  
lldb/test/API/commands/register/register/aarch64_dynamic_regset/TestArm64DynamicRegsets.py
  
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/TestSVEThreadedDynamic.py
  
lldb/test/API/commands/register/registe

[Lldb-commits] [PATCH] D157497: feat: Migrate isArch16Bit

2023-08-14 Thread Evgeniy Makarev via Phabricator via lldb-commits
Pivnoy added a comment.

This discussion was the main motivation for this change.
https://discourse.llvm.org/t/rfc-refactor-triple-related-classes/70410/11
As a result, Triple should become a data class, and its dependencies such as 
Architecture, Operating System etc. represent in the form of interfaces that 
can be implemented for the necessary instances.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157497/new/

https://reviews.llvm.org/D157497

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


[Lldb-commits] [PATCH] D157609: [lldb] Search debug file paths when looking for split DWARF files

2023-08-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added reviewers: aprantl, clayborg, lenary.
DavidSpickett added a subscriber: lenary.
DavidSpickett added a comment.

https://github.com/llvm/llvm-project/issues/28667 is the github issue.

@lenary This fixes your reproducer, if you have any more ways to confuse lldb 
please try them with this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157609/new/

https://reviews.llvm.org/D157609

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


[Lldb-commits] [PATCH] D157609: WIP: [lldb] Search debug file paths when looking for split DWARF files

2023-08-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 549872.
DavidSpickett added a comment.

Cleanup, add testing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157609/new/

https://reviews.llvm.org/D157609

Files:
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths.c

Index: lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths.c
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/dwo-debug-file-search-paths.c
@@ -0,0 +1,28 @@
+/// Check that LLDB uses the paths in target.debug-file-search-paths to find
+/// split DWARF files with DW_AT_comp_dir set, when the program file has been
+/// moved and/or we're executing it from another directory.
+// RUN: rm -rf %t.compdir/ %t.e/
+// RUN: mkdir -p %t.compdir/a/b/c/d/
+// RUN: cp %s %t.compdir/a/b/c/d/main.c
+// RUN: cd %t.compdir/a/b/
+/// The produced DWO is named c/d/main-main.dwo, with a DW_AT_comp_dir of a/b.
+// RUN: %clang_host -g -gsplit-dwarf -fdebug-prefix-map=%t.compdir=. c/d/main.c -o c/d/main
+// RUN: cd ../../..
+/// Move only the program, leaving the DWO file in place.
+// RUN: mv %t.compdir/a/b/c/d/main %t.compdir/a/
+/// Debug it from yet another path.
+// RUN: mkdir -p %t.e/
+// RUN: cd %t.e
+/// LLDB won't find the DWO next to the binary or in the current dir, so it
+/// should find the DWO file by doing %t.compdir/ + a/b/ + c/d/main-main.dwo.
+// RUN: %lldb --no-lldbinit %t.compdir/a/main \
+// RUN:   -O "settings append target.debug-file-search-paths %t.compdir" \
+// RUN:   -o "b main.c:27" -o "run" -o "frame variable" --batch 2>&1 | FileCheck %s
+
+// CHECK-NOT: warning: {{.*}}main unable to locate separate debug file (dwo, dwp). Debugging will be degraded.
+// CHECK: (int) num = 5
+
+int main(void) {
+  int num = 5;
+  return 0;
+}
\ No newline at end of file
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1731,7 +1731,11 @@
   const char *comp_dir = nullptr;
   FileSpec dwo_file(dwo_name);
   FileSystem::Instance().Resolve(dwo_file);
-  if (dwo_file.IsRelative()) {
+  bool found = false;
+
+  if (!dwo_file.IsRelative()) {
+found = FileSystem::Instance().Exists(dwo_file);
+  } else {
 comp_dir = cu_die.GetAttributeValueAsString(dwarf_cu, DW_AT_comp_dir,
 nullptr);
 if (!comp_dir) {
@@ -1744,18 +1748,51 @@
 }
 
 dwo_file.SetFile(comp_dir, FileSpec::Style::native);
-if (dwo_file.IsRelative()) {
+
+if (!dwo_file.IsRelative()) {
+  FileSystem::Instance().Resolve(dwo_file);
+  dwo_file.AppendPathComponent(dwo_name);
+  found = FileSystem::Instance().Exists(dwo_file);
+} else {
+  FileSpecList dwo_paths;
+
   // if DW_AT_comp_dir is relative, it should be relative to the location
   // of the executable, not to the location from which the debugger was
   // launched.
-  dwo_file.PrependPathComponent(
+  FileSpec relative_to_binary = dwo_file;
+  relative_to_binary.PrependPathComponent(
   m_objfile_sp->GetFileSpec().GetDirectory().GetStringRef());
+  FileSystem::Instance().Resolve(relative_to_binary);
+  relative_to_binary.AppendPathComponent(dwo_name);
+  dwo_paths.Append(relative_to_binary);
+
+  // Or it's relative to one of the user specified debug directories.
+  const FileSpecList &debug_file_search_paths =
+  Target::GetDefaultDebugFileSearchPaths();
+  size_t num_directories = debug_file_search_paths.GetSize();
+  for (size_t idx = 0; idx < num_directories; ++idx) {
+FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx);
+dirspec.AppendPathComponent(comp_dir);
+FileSystem::Instance().Resolve(dirspec);
+if (!FileSystem::Instance().IsDirectory(dirspec))
+  continue;
+
+dirspec.AppendPathComponent(dwo_name);
+dwo_paths.Append(dirspec);
+  }
+
+  size_t num_possible = dwo_paths.GetSize();
+  for (size_t idx = 0; idx < num_possible && !found; ++idx) {
+FileSpec dwo_spec = dwo_paths.GetFileSpecAtIndex(idx);
+if (FileSystem::Instance().Exists(dwo_spec)) {
+  dwo_file = dwo_spec;
+  found = true;
+}
+  }
 }
-FileSystem::Instance().Resolve(dwo_file);
-dwo_file.AppendPathComponent(dwo_name);
   }
 
-  if (!FileSystem::Instance().Exists(dwo_file)) {
+  if (!found) {
 unit.SetDwoError(Status::createWithFormat(
 "unable to locate .dwo debug file \"{0}\" for skeleton DIE "
 "{1:x16}",
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D157043: [lldb/crashlog] Make TextCrashLogParser more resilient to new lines

2023-08-14 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

In D157043#4582385 , @JDevlieghere 
wrote:

> Test?

I'll do it in a follow-up.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157043/new/

https://reviews.llvm.org/D157043

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


[Lldb-commits] [PATCH] D157852: [lldb/crashlog] Skip non-crashed threads in batch mode

2023-08-14 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added reviewers: bulbazord, JDevlieghere.
mib added a project: LLDB.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

When using the `crashlog` command in batch mode, most users only care
about the crashed thread and end up having to scroll past all the
non-crashed threads, which is not a good user experience.

Now that `-c|--crashed-only` is set by default, we should also apply
that behavior for batch mode: Only the crashed thread and "Application
Specific Backtrace" threads will be shown to the user in batch mode.

The user will still have the ability to show all the threads if they use
`--no-crashed-only` which will parse the symbols from the report, or
with `-a|--load-all-images` which will fetch binaries and debug info
from the build record and symbolicate every thread.

rdar://106329893

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157852

Files:
  lldb/examples/python/crashlog.py


Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -1436,6 +1436,10 @@
 print()
 
 for thread in crash_log.threads:
+if options.crashed_only and not (
+thread.crashed or thread.app_specific_backtrace
+):
+continue
 thread.dump_symbolicated(crash_log, options)
 print()
 


Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -1436,6 +1436,10 @@
 print()
 
 for thread in crash_log.threads:
+if options.crashed_only and not (
+thread.crashed or thread.app_specific_backtrace
+):
+continue
 thread.dump_symbolicated(crash_log, options)
 print()
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D157851: [lldb/crashlog] Add support for Last Exception Backtrace

2023-08-14 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added reviewers: bulbazord, JDevlieghere.
mib added a project: LLDB.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch adds support to the "Last Exception Backtrace" to the
`crashlog` command.

This metadata is homologous to the "Application Specific Backtrace",
however the format is closer to a regular stack frame.

Since the thread that "contains" the "Last Exception Backtrace" doesn't
really exist, this information is displayed when requesting an extended
backtrace of the crashed thread, similarly to the "Application Specific
Backtrace".

To achieve that, this patch includes some refactors and fixes to the
existing "Application Specific Backtrace" handling.

rdar://113046509

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157851

Files:
  lldb/examples/python/crashlog.py
  lldb/examples/python/scripted_process/crashlog_scripted_process.py


Index: lldb/examples/python/scripted_process/crashlog_scripted_process.py
===
--- lldb/examples/python/scripted_process/crashlog_scripted_process.py
+++ lldb/examples/python/scripted_process/crashlog_scripted_process.py
@@ -178,7 +178,7 @@
 self.idx = self.backing_thread.index
 self.tid = self.backing_thread.id
 if self.backing_thread.app_specific_backtrace:
-self.name = "Application Specific Backtrace - " + str(self.idx)
+self.name = "Application Specific Backtrace"
 else:
 self.name = self.backing_thread.name
 self.queue = self.backing_thread.queue
Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -586,10 +586,15 @@
 self.parse_threads(self.data["threads"])
 if "asi" in self.data:
 self.crashlog.asi = self.data["asi"]
+# FIXME: With the current design, we can either show the ASI or 
Last
+# Exception Backtrace, not both. Is there a situation where we 
would
+# like to show both ?
 if "asiBacktraces" in self.data:
 self.parse_app_specific_backtraces(self.data["asiBacktraces"])
 if "lastExceptionBacktrace" in self.data:
-self.crashlog.asb = self.data["lastExceptionBacktrace"]
+self.parse_last_exception_backtraces(
+self.data["lastExceptionBacktrace"]
+)
 self.parse_errors(self.data)
 thread = self.crashlog.threads[self.crashlog.crashed_thread_idx]
 reason = self.parse_crash_reason(self.data["exception"])
@@ -792,12 +797,22 @@
 return True
 
 def parse_app_specific_backtraces(self, json_app_specific_bts):
-for idx, backtrace in enumerate(json_app_specific_bts):
-thread = self.crashlog.Thread(idx, True, 
self.crashlog.process_arch)
-thread.queue = "Application Specific Backtrace"
+thread = self.crashlog.Thread(
+len(self.crashlog.threads), True, self.crashlog.process_arch
+)
+thread.queue = "Application Specific Backtrace"
+for backtrace in json_app_specific_bts:
 if self.parse_asi_backtrace(thread, backtrace):
 self.crashlog.threads.append(thread)
 
+def parse_last_exception_backtraces(self, json_last_exc_bts):
+thread = self.crashlog.Thread(
+len(self.crashlog.threads), True, self.crashlog.process_arch
+)
+thread.queue = "Last Exception Backtrace"
+self.parse_frames(thread, json_last_exc_bts)
+self.crashlog.threads.append(thread)
+
 def parse_thread_registers(self, json_thread_state, prefix=None):
 registers = dict()
 for key, state in json_thread_state.items():


Index: lldb/examples/python/scripted_process/crashlog_scripted_process.py
===
--- lldb/examples/python/scripted_process/crashlog_scripted_process.py
+++ lldb/examples/python/scripted_process/crashlog_scripted_process.py
@@ -178,7 +178,7 @@
 self.idx = self.backing_thread.index
 self.tid = self.backing_thread.id
 if self.backing_thread.app_specific_backtrace:
-self.name = "Application Specific Backtrace - " + str(self.idx)
+self.name = "Application Specific Backtrace"
 else:
 self.name = self.backing_thread.name
 self.queue = self.backing_thread.queue
Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -586,10 +586,15 @@
 self.parse_threads(self.data["threads"])
 if "asi" in self.data:
   

[Lldb-commits] [PATCH] D157850: [lldb/crashlog] Fix module loading for crashed thread behaviour

2023-08-14 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added a reviewer: JDevlieghere.
mib added a project: LLDB.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

Before 27f27d15f 
, the 
`crashlog` command would always load images even
if `-a` or `-c` was not set by the user.

Since that change, images are loaded only when one of these 2 flags are
set, otherwise, we fallback to parsing the symbols from the report and
load them into a `SymbolFileJSON`.

Although that makes it way faster than pulling binaries and debug
symbols from build records, that cause a degraded experience since none
of our users are used to set these 2 flags. For instance, that would
symbolicate the backtraces, however the users wouldn't see sources.

To address that change of behavior, this patch changes the default value
for the `-c|--crash-only` flag to `true`. On the other hand, thanks to
the move to `argparse`, we introduced a new `--no-only-crashed` flag
that will let the user force skipping loading any images, relying only
on the `SymbolFileJSON`.

This gives the users a good compromise since they would be able to see
sources for the crashed thread if they're available, otherwise, they'll
only get a symbolicated backtrace.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157850

Files:
  lldb/examples/python/crashlog.py


Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -1590,10 +1590,10 @@
 arg_parser.add_argument(
 "--crashed-only",
 "-c",
-action="store_true",
+action=argparse.BooleanOptionalAction,
 dest="crashed_only",
 help="only symbolicate the crashed thread",
-default=False,
+default=True,
 )
 arg_parser.add_argument(
 "--disasm-depth",


Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -1590,10 +1590,10 @@
 arg_parser.add_argument(
 "--crashed-only",
 "-c",
-action="store_true",
+action=argparse.BooleanOptionalAction,
 dest="crashed_only",
 help="only symbolicate the crashed thread",
-default=False,
+default=True,
 )
 arg_parser.add_argument(
 "--disasm-depth",
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D157849: [lldb/crashlog] Replace deprecated optparse by argparse (NFC)

2023-08-14 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added reviewers: JDevlieghere, bulbazord.
mib added a project: LLDB.
Herald added a project: All.
mib requested review of this revision.
Herald added subscribers: lldb-commits, wangpc.

This patch replace the deprecated `optparse` module used for the
`crashlog`& `save_crashlog` commands with the new `argparse` from the
python standard library. This provides many benefits such as showing the
default values for each option in the help description, but also greatly
improve the handling of position arguments.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157849

Files:
  lldb/examples/python/crashlog.py
  lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no-args.test

Index: lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no-args.test
===
--- lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no-args.test
+++ lldb/test/Shell/ScriptInterpreter/Python/Crashlog/no-args.test
@@ -2,8 +2,10 @@
 
 # CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands
 
-# CHECK: Usage: crashlog [options]  [FILE ...]
+# CHECK: usage: crashlog [options]  [FILE ...]
 # CHECK: Symbolicate one or more darwin crash log files to provide source file and line
-# CHECK: Options:
+# CHECK: positional arguments:
+# CHECK-NEXT: FILE  crash report(s) to symbolicate (default: None)
+# CHECK: options:
 # CHECK:  -h, --helpshow this help message and exit
 
Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -27,11 +27,11 @@
 # --
 
 import abc
+import argparse
 import concurrent.futures
 import contextlib
 import datetime
 import json
-import optparse
 import os
 import platform
 import plistlib
@@ -1234,12 +1234,20 @@
 
 
 def save_crashlog(debugger, command, exe_ctx, result, dict):
-usage = "usage: %prog [options] "
+usage = "save_crashlog [options] "
 description = """Export the state of current target into a crashlog file"""
-parser = optparse.OptionParser(
-description=description, prog="save_crashlog", usage=usage
+parser = argparse.ArgumentParser(
+description=description,
+prog="save_crashlog",
+formatter_class=argparse.ArgumentDefaultsHelpFormatter,
 )
-parser.add_option(
+parser.add_argument(
+"output",
+metavar="output-file",
+type=argparse.FileType("w", encoding="utf-8"),
+nargs=1,
+)
+parser.add_argument(
 "-v",
 "--verbose",
 action="store_true",
@@ -1248,21 +1256,13 @@
 default=False,
 )
 try:
-(options, args) = parser.parse_args(shlex.split(command))
-except:
-result.PutCString("error: invalid options")
-return
-if len(args) != 1:
-result.PutCString(
-"error: invalid arguments, a single output file is the only valid argument"
-)
-return
-out_file = open(args[0], "w", encoding="utf-8")
-if not out_file:
-result.PutCString("error: failed to open file '%s' for writing...", args[0])
+options = parser.parse_args(shlex.split(command))
+except Exception as e:
+result.SetError(str(e))
 return
 target = exe_ctx.target
 if target:
+out_file = options.output
 identifier = target.executable.basename
 process = exe_ctx.process
 if process:
@@ -1352,7 +1352,7 @@
 )
 out_file.close()
 else:
-result.PutCString("error: invalid target")
+result.SetError("invalid target")
 
 
 class Symbolicate:
@@ -1366,8 +1366,8 @@
 return "Symbolicate one or more darwin crash log files."
 
 def get_long_help(self):
-option_parser = CrashLogOptionParser()
-return option_parser.format_help()
+arg_parser = CrashLogOptionParser()
+return arg_parser.format_help()
 
 
 def SymbolicateCrashLog(crash_log, options):
@@ -1523,11 +1523,22 @@
 def CreateSymbolicateCrashLogOptions(
 command_name, description, add_interactive_options
 ):
-usage = "usage: %prog [options]  [FILE ...]"
-option_parser = optparse.OptionParser(
-description=description, prog="crashlog", usage=usage
+usage = "crashlog [options]  [FILE ...]"
+arg_parser = argparse.ArgumentParser(
+description=description,
+prog="crashlog",
+usage=usage,
+formatter_class=argparse.ArgumentDefaultsHelpFormatter,
+)
+arg_parser.add_argument(
+"reports",
+metavar="FILE",
+type=str,
+nargs="*",
+help="crash report(s) to symbolicate",
 )
-option_parser.add_option(
+
+arg_parser.add_argument(
 "--version

[Lldb-commits] [PATCH] D157497: feat: Migrate isArch16Bit

2023-08-14 Thread Alex Bradbury via Phabricator via lldb-commits
asb added a comment.

Is there some separate discussion thread or proposal about this refactoring and 
its motivations?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157497/new/

https://reviews.llvm.org/D157497

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


[Lldb-commits] [PATCH] D157846: [lldb][AArch64] Add SME's SVE register state to TestArm64DynamicRegsets

2023-08-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added subscribers: ctetreau, kristof.beyls.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Since we need to switch modes, this is its own test. I will be adding
ZA, SVG and SVCR checks here later.

Prior to this we didn't have any testing of writing streaming mode
SVE registers from lldb.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157846

Files:
  
lldb/test/API/commands/register/register/aarch64_dynamic_regset/TestArm64DynamicRegsets.py
  lldb/test/API/commands/register/register/aarch64_dynamic_regset/main.c


Index: lldb/test/API/commands/register/register/aarch64_dynamic_regset/main.c
===
--- lldb/test/API/commands/register/register/aarch64_dynamic_regset/main.c
+++ lldb/test/API/commands/register/register/aarch64_dynamic_regset/main.c
@@ -1,5 +1,9 @@
 #include 
 
+#ifndef HWCAP2_SME
+#define HWCAP2_SME (1 << 23)
+#endif
+
 void set_sve_registers() {
   // AArch64 SVE extension ISA adds a new set of vector and predicate 
registers:
   // 32 Z registers, 16 P registers, and 1 FFR register.
@@ -64,8 +68,14 @@
   asm volatile("cpy  z31.b, p15/z, #32\n\t");
 }
 
-int main() {
-  if (getauxval(AT_HWCAP) & HWCAP_SVE) // check if SVE is present
+int main(int argc, char *argv[]) {
+  if (argc > 1) {
+// Enable streaming mode SVE and the ZA array storage.
+asm volatile("msr  s0_3_c4_c7_3, xzr" /*smstart*/);
+  }
+
+  // If we have SVE or SME, set the SVE registers.
+  if ((getauxval(AT_HWCAP) & HWCAP_SVE) || (getauxval(AT_HWCAP2) & HWCAP2_SME))
 set_sve_registers();
 
   return 0; // Set a break point here.
Index: 
lldb/test/API/commands/register/register/aarch64_dynamic_regset/TestArm64DynamicRegsets.py
===
--- 
lldb/test/API/commands/register/register/aarch64_dynamic_regset/TestArm64DynamicRegsets.py
+++ 
lldb/test/API/commands/register/register/aarch64_dynamic_regset/TestArm64DynamicRegsets.py
@@ -120,3 +120,42 @@
 )
 self.expect("register read data_mask", substrs=["data_mask = 
0x"])
 self.expect("register read code_mask", substrs=["code_mask = 
0x"])
+
+@no_debug_info_test
+@skipIf(archs=no_match(["aarch64"]))
+@skipIf(oslist=no_match(["linux"]))
+def test_aarch64_dynamic_regset_config_sme(self):
+"""Test AArch64 Dynamic Register sets configuration, but only SME
+   registers."""
+if not self.isAArch64SME():
+self.skipTest("SME must be present.")
+
+self.build()
+self.line = line_number("main.c", "// Set a break point here.")
+
+exe = self.getBuildArtifact("a.out")
+self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+lldbutil.run_break_set_by_file_and_line(
+self, "main.c", self.line, num_expected_locations=1
+)
+self.runCmd("settings set target.run-args sme")
+self.runCmd("run", RUN_SUCCEEDED)
+
+self.expect(
+"thread backtrace",
+STOPPED_DUE_TO_BREAKPOINT,
+substrs=["stop reason = breakpoint 1."],
+)
+
+target = self.dbg.GetSelectedTarget()
+process = target.GetProcess()
+thread = process.GetThreadAtIndex(0)
+currentFrame = thread.GetFrameAtIndex(0)
+
+register_sets = currentFrame.GetRegisters()
+
+ssve_registers = register_sets.GetFirstValueByName(
+"Scalable Vector Extension Registers")
+self.assertTrue(ssve_registers.IsValid())
+self.sve_regs_read_dynamic(ssve_registers)


Index: lldb/test/API/commands/register/register/aarch64_dynamic_regset/main.c
===
--- lldb/test/API/commands/register/register/aarch64_dynamic_regset/main.c
+++ lldb/test/API/commands/register/register/aarch64_dynamic_regset/main.c
@@ -1,5 +1,9 @@
 #include 
 
+#ifndef HWCAP2_SME
+#define HWCAP2_SME (1 << 23)
+#endif
+
 void set_sve_registers() {
   // AArch64 SVE extension ISA adds a new set of vector and predicate registers:
   // 32 Z registers, 16 P registers, and 1 FFR register.
@@ -64,8 +68,14 @@
   asm volatile("cpy  z31.b, p15/z, #32\n\t");
 }
 
-int main() {
-  if (getauxval(AT_HWCAP) & HWCAP_SVE) // check if SVE is present
+int main(int argc, char *argv[]) {
+  if (argc > 1) {
+// Enable streaming mode SVE and the ZA array storage.
+asm volatile("msr  s0_3_c4_c7_3, xzr" /*smstart*/);
+  }
+
+  // If we have SVE or SME, set the SVE registers.
+  if ((getauxval(AT_HWCAP) & HWCAP_SVE) || (getauxval(AT_HWCAP2) & HWCAP2_SME))
 set_sve_registers();
 
   return 0; // Set a break point here.
Index: lldb/test/API/commands/register/register/aarch64_dynamic_regset/TestArm64DynamicRegsets.py
=

[Lldb-commits] [PATCH] D157845: [lldb][AArch64] Remove bool return from UpdateARM64SVERegistersInfos

2023-08-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This always succeeds. While I'm here, document why we check the size
of p0 against the value of VG.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157845

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
@@ -38,7 +38,7 @@
 
   ~GDBRemoteDynamicRegisterInfo() override = default;
 
-  bool UpdateARM64SVERegistersInfos(uint64_t vg);
+  void UpdateARM64SVERegistersInfos(uint64_t vg);
 };
 
 class GDBRemoteRegisterContext : public RegisterContext {
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -772,27 +772,28 @@
   uint32_t vg_reg_num = reg_info->kinds[eRegisterKindLLDB];
   uint64_t vg_reg_value = ReadRegisterAsUnsigned(vg_reg_num, fail_value);
 
-  if (vg_reg_value != fail_value && vg_reg_value <= 32) {
-const RegisterInfo *reg_info = m_reg_info_sp->GetRegisterInfo("p0");
-if (!reg_info || vg_reg_value == reg_info->byte_size)
-  return false;
+  if (vg_reg_value == fail_value || vg_reg_value > 32)
+return false;
 
-if (m_reg_info_sp->UpdateARM64SVERegistersInfos(vg_reg_value)) {
-  // Make a heap based buffer that is big enough to store all registers
-  m_reg_data.SetData(std::make_shared(
-  m_reg_info_sp->GetRegisterDataByteSize(), 0));
-  m_reg_data.SetByteOrder(GetByteOrder());
+  reg_info = m_reg_info_sp->GetRegisterInfo("p0");
+  // Predicate registers have 1 bit per byte in the vector so their size is
+  // VL / 8. VG is in units of 8 bytes already, so if the size of p0 == VG
+  // already, we do not have to reconfigure.
+  if (!reg_info || vg_reg_value == reg_info->byte_size)
+return false;
 
-  InvalidateAllRegisters();
+  m_reg_info_sp->UpdateARM64SVERegistersInfos(vg_reg_value);
+  // Make a heap based buffer that is big enough to store all registers
+  m_reg_data.SetData(std::make_shared(
+  m_reg_info_sp->GetRegisterDataByteSize(), 0));
+  m_reg_data.SetByteOrder(GetByteOrder());
 
-  return true;
-}
-  }
+  InvalidateAllRegisters();
 
-  return false;
+  return true;
 }
 
-bool GDBRemoteDynamicRegisterInfo::UpdateARM64SVERegistersInfos(uint64_t vg) {
+void GDBRemoteDynamicRegisterInfo::UpdateARM64SVERegistersInfos(uint64_t vg) {
   // SVE Z register size is vg x 8 bytes.
   uint32_t z_reg_byte_size = vg * 8;
 
@@ -813,5 +814,4 @@
 
   // Re-calculate register offsets
   ConfigureOffsets();
-  return true;
 }


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
@@ -38,7 +38,7 @@
 
   ~GDBRemoteDynamicRegisterInfo() override = default;
 
-  bool UpdateARM64SVERegistersInfos(uint64_t vg);
+  void UpdateARM64SVERegistersInfos(uint64_t vg);
 };
 
 class GDBRemoteRegisterContext : public RegisterContext {
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -772,27 +772,28 @@
   uint32_t vg_reg_num = reg_info->kinds[eRegisterKindLLDB];
   uint64_t vg_reg_value = ReadRegisterAsUnsigned(vg_reg_num, fail_value);
 
-  if (vg_reg_value != fail_value && vg_reg_value <= 32) {
-const RegisterInfo *reg_info = m_reg_info_sp->GetRegisterInfo("p0");
-if (!reg_info || vg_reg_value == reg_info->byte_size)
-  return false;
+  if (vg_reg_value == fail_value || vg_reg_value > 32)
+return false;
 
-if (m_reg_info_sp->UpdateARM64SVERegistersInfos(vg_reg_value)) {
-  // Make a heap based buffer that is big enough to store all registers
-  m_reg_data.SetData(std::make_shared(
-  m_reg_info_sp->GetRegisterDataByteSize(), 0));
-  m_reg_data.SetByteOrder(GetByteOrder());
+  reg_info = m_reg_info_sp->GetRegisterInfo("p0");
+  // Predicate registers have 1 bit per byte in the vector so their size is
+  // VL / 8. VG is in units of 8 bytes already, so if the size of p0 == VG
+  // already, we do not have to reconfigu

[Lldb-commits] [PATCH] D156687: [lldb][AArch64] Add kind marker to ReadAll/WriteALLRegisterValues data

2023-08-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 549836.
DavidSpickett added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156687/new/

https://reviews.llvm.org/D156687

Files:
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp

Index: lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
@@ -499,6 +499,30 @@
   return Status("Failed to write register value");
 }
 
+enum SavedRegistersKind : uint32_t {
+  GPR,
+  SVE, // Used for SVE and SSVE.
+  FPR, // When there is no SVE, or SVE in FPSIMD mode.
+  MTE,
+  TLS,
+};
+
+static uint8_t *AddSavedRegistersKind(uint8_t *dst, SavedRegistersKind kind) {
+  *(reinterpret_cast(dst)) = kind;
+  return dst + sizeof(uint32_t);
+}
+
+static uint8_t *AddSavedRegistersData(uint8_t *dst, void *src, size_t size) {
+  ::memcpy(dst, src, size);
+  return dst + size;
+}
+
+static uint8_t *AddSavedRegisters(uint8_t *dst, enum SavedRegistersKind kind,
+  void *src, size_t size) {
+  dst = AddSavedRegistersKind(dst, kind);
+  return AddSavedRegistersData(dst, src, size);
+}
+
 Status NativeRegisterContextLinux_arm64::ReadAllRegisterValues(
 lldb::WritableDataBufferSP &data_sp) {
   // AArch64 register data must contain GPRs and either FPR or SVE registers.
@@ -512,33 +536,33 @@
   // corresponds to register sets enabled by current register context.
 
   Status error;
-  uint32_t reg_data_byte_size = GetGPRBufferSize();
+  uint32_t reg_data_byte_size = sizeof(SavedRegistersKind) + GetGPRBufferSize();
   error = ReadGPR();
   if (error.Fail())
 return error;
 
   // If SVE is enabled we need not copy FPR separately.
   if (GetRegisterInfo().IsSVEEnabled() || GetRegisterInfo().IsSSVEEnabled()) {
-reg_data_byte_size += GetSVEBufferSize();
-// Also store the current SVE mode.
-reg_data_byte_size += sizeof(uint32_t);
+// Store mode and register data.
+reg_data_byte_size +=
+sizeof(SavedRegistersKind) + sizeof(m_sve_state) + GetSVEBufferSize();
 error = ReadAllSVE();
   } else {
-reg_data_byte_size += GetFPRSize();
+reg_data_byte_size += sizeof(SavedRegistersKind) + GetFPRSize();
 error = ReadFPR();
   }
   if (error.Fail())
 return error;
 
   if (GetRegisterInfo().IsMTEEnabled()) {
-reg_data_byte_size += GetMTEControlSize();
+reg_data_byte_size += sizeof(SavedRegistersKind) + GetMTEControlSize();
 error = ReadMTEControl();
 if (error.Fail())
   return error;
   }
 
   // tpidr is always present but tpidr2 depends on SME.
-  reg_data_byte_size += GetTLSBufferSize();
+  reg_data_byte_size += sizeof(SavedRegistersKind) + GetTLSBufferSize();
   error = ReadTLS();
   if (error.Fail())
 return error;
@@ -546,25 +570,26 @@
   data_sp.reset(new DataBufferHeap(reg_data_byte_size, 0));
   uint8_t *dst = data_sp->GetBytes();
 
-  ::memcpy(dst, GetGPRBuffer(), GetGPRBufferSize());
-  dst += GetGPRBufferSize();
+  dst = AddSavedRegisters(dst, SavedRegistersKind::GPR, GetGPRBuffer(),
+  GetGPRBufferSize());
 
   if (GetRegisterInfo().IsSVEEnabled() || GetRegisterInfo().IsSSVEEnabled()) {
-*dst = static_cast(m_sve_state);
+dst = AddSavedRegistersKind(dst, SavedRegistersKind::SVE);
+*(reinterpret_cast(dst)) = m_sve_state;
 dst += sizeof(m_sve_state);
-::memcpy(dst, GetSVEBuffer(), GetSVEBufferSize());
-dst += GetSVEBufferSize();
+dst = AddSavedRegistersData(dst, GetSVEBuffer(), GetSVEBufferSize());
   } else {
-::memcpy(dst, GetFPRBuffer(), GetFPRSize());
-dst += GetFPRSize();
+dst = AddSavedRegisters(dst, SavedRegistersKind::FPR, GetFPRBuffer(),
+GetFPRSize());
   }
 
   if (GetRegisterInfo().IsMTEEnabled()) {
-::memcpy(dst, GetMTEControl(), GetMTEControlSize());
-dst += GetMTEControlSize();
+dst = AddSavedRegisters(dst, SavedRegistersKind::MTE, GetMTEControl(),
+GetMTEControlSize());
   }
 
-  ::memcpy(dst, GetTLSBuffer(), GetTLSBufferSize());
+  dst = AddSavedRegisters(dst, SavedRegistersKind::TLS, GetTLSBuffer(),
+  GetTLSBufferSize());
 
   return error;
 }
@@ -599,7 +624,8 @@
 return error;
   }
 
-  uint64_t reg_data_min_size = GetGPRBufferSize() + GetFPRSize();
+  uint64_t reg_data_min_size =
+  GetGPRBufferSize() + GetFPRSize() + 2 * (sizeof(SavedRegistersKind));
   if (data_sp->GetByteSize() < reg_data_min_size) {
 error.SetErrorStringWithFormat(
 "NativeRegisterContextLinux_arm64::%s data_sp contained insufficient "
@@ -608,81 +634,84 @@
 return error;
   }
 
-  // Register data starts with GPRs
-  ::memcpy(GetGPRBuffer(), src, GetGPRBufferSize());
-  m_gpr_is_valid = true;
+  const uin

[Lldb-commits] [PATCH] D157488: [lldb][AArch64] Add testing of save/restore for Linux MTE control register

2023-08-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 549835.
DavidSpickett added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157488/new/

https://reviews.llvm.org/D157488

Files:
  lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/Makefile
  
lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py
  lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/main.c


Index: lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/main.c
===
--- /dev/null
+++ lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/main.c
@@ -0,0 +1,21 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int setup_mte() {
+  return prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE | 
PR_MTE_TCF_SYNC,
+   0, 0, 0);
+}
+
+int main(int argc, char const *argv[]) {
+  if (!(getauxval(AT_HWCAP2) & HWCAP2_MTE))
+return 1;
+
+  if (setup_mte())
+return 1;
+
+  return 0; // Set a break point here.
+}
Index: 
lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py
===
--- /dev/null
+++ 
lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py
@@ -0,0 +1,50 @@
+"""
+Test that LLDB correctly reads, writes and restores the MTE control register on
+AArch64 Linux.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class MTECtrlRegisterTestCase(TestBase):
+@no_debug_info_test
+@skipIf(archs=no_match(["aarch64"]))
+@skipIf(oslist=no_match(["linux"]))
+def test_mte_ctrl_register(self):
+if not self.isAArch64MTE():
+self.skipTest("Target must support MTE.")
+
+self.build()
+self.line = line_number("main.c", "// Set a break point here.")
+
+exe = self.getBuildArtifact("a.out")
+self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+lldbutil.run_break_set_by_file_and_line(
+self, "main.c", self.line, num_expected_locations=1
+)
+self.runCmd("run", RUN_SUCCEEDED)
+
+self.expect(
+"process status",
+STOPPED_DUE_TO_BREAKPOINT,
+substrs=["stop reason = breakpoint 1."],
+)
+
+# Bit 0 = tagged addressing enabled
+# Bit 1 = synchronous faults
+# Bit 2 = asynchronous faults
+# We start enabled with synchronous faults.
+self.expect("register read mte_ctrl", substrs=["0x0003"])
+
+# Change to asynchronous faults.
+self.runCmd("register write mte_ctrl 5")
+self.expect("register read mte_ctrl", substrs=["0x0005"])
+
+# This would return to synchronous faults if we did not restore the
+# previous value.
+self.expect("expression setup_mte()", substrs=["= 0"])
+self.expect("register read mte_ctrl", substrs=["0x0005"])
\ No newline at end of file
Index: 
lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/Makefile
===
--- /dev/null
+++ lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules


Index: lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/main.c
===
--- /dev/null
+++ lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/main.c
@@ -0,0 +1,21 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int setup_mte() {
+  return prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC,
+   0, 0, 0);
+}
+
+int main(int argc, char const *argv[]) {
+  if (!(getauxval(AT_HWCAP2) & HWCAP2_MTE))
+return 1;
+
+  if (setup_mte())
+return 1;
+
+  return 0; // Set a break point here.
+}
Index: lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py
===
--- /dev/null
+++ lldb/test/API/commands/register/register/aarch64_mte_ctrl_register/TestMTECtrlRegister.py
@@ -0,0 +1,50 @@
+"""
+Test that LLDB correctly reads, writes and restores the MTE control register on
+AArch64 Linux.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class MTECtrlRegisterTestCase(TestBase):
+@no_debug_info_test
+@skipIf(archs=no_match(["aarch64"]))
+@skipIf(oslist=no_match(["linux"]))
+def test_mte_ctrl_register(self):
+if not self.isAArch64MTE():
+self.skipTest("Target must support MTE.")
+
+self.build()
+self.line

[Lldb-commits] [PATCH] D157000: [lldb][AArch64] Check SIMD save/restore in SVE SIMD test

2023-08-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 549834.
DavidSpickett added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157000/new/

https://reviews.llvm.org/D157000

Files:
  
lldb/test/API/commands/register/register/aarch64_sve_simd_registers/TestSVESIMDRegisters.py
  lldb/test/API/commands/register/register/aarch64_sve_simd_registers/main.c

Index: lldb/test/API/commands/register/register/aarch64_sve_simd_registers/main.c
===
--- lldb/test/API/commands/register/register/aarch64_sve_simd_registers/main.c
+++ lldb/test/API/commands/register/register/aarch64_sve_simd_registers/main.c
@@ -40,6 +40,45 @@
   WRITE_SIMD(31);
 }
 
+void write_simd_regs_expr() {
+#define WRITE_SIMD(NUM)\
+  asm volatile("MOV v" #NUM ".d[0], %0\n\t"\
+   "MOV v" #NUM ".d[1], %0\n\t" ::"r"(NUM + 1))
+
+  WRITE_SIMD(0);
+  WRITE_SIMD(1);
+  WRITE_SIMD(2);
+  WRITE_SIMD(3);
+  WRITE_SIMD(4);
+  WRITE_SIMD(5);
+  WRITE_SIMD(6);
+  WRITE_SIMD(7);
+  WRITE_SIMD(8);
+  WRITE_SIMD(9);
+  WRITE_SIMD(10);
+  WRITE_SIMD(11);
+  WRITE_SIMD(12);
+  WRITE_SIMD(13);
+  WRITE_SIMD(14);
+  WRITE_SIMD(15);
+  WRITE_SIMD(16);
+  WRITE_SIMD(17);
+  WRITE_SIMD(18);
+  WRITE_SIMD(19);
+  WRITE_SIMD(20);
+  WRITE_SIMD(21);
+  WRITE_SIMD(22);
+  WRITE_SIMD(23);
+  WRITE_SIMD(24);
+  WRITE_SIMD(25);
+  WRITE_SIMD(26);
+  WRITE_SIMD(27);
+  WRITE_SIMD(28);
+  WRITE_SIMD(29);
+  WRITE_SIMD(30);
+  WRITE_SIMD(31);
+}
+
 unsigned verify_simd_regs() {
   uint64_t got_low = 0;
   uint64_t got_high = 0;
Index: lldb/test/API/commands/register/register/aarch64_sve_simd_registers/TestSVESIMDRegisters.py
===
--- lldb/test/API/commands/register/register/aarch64_sve_simd_registers/TestSVESIMDRegisters.py
+++ lldb/test/API/commands/register/register/aarch64_sve_simd_registers/TestSVESIMDRegisters.py
@@ -1,6 +1,6 @@
 """
-Test that LLDB correctly reads and writes AArch64 SIMD registers in SVE,
-streaming SVE and normal SIMD modes.
+Test that LLDB correctly reads and writes and restores AArch64 SIMD registers
+in SVE, streaming SVE and normal SIMD modes.
 
 There are a few operating modes and we use different strategies for each:
 * Without SVE, in SIMD mode - read the SIMD regset.
@@ -48,6 +48,13 @@
 pad = " ".join(["0x00"] * 7)
 return "{{0x{:02x} {} 0x{:02x} {}}}".format(n, pad, n, pad)
 
+def check_simd_values(self, value_offset):
+# These are 128 bit registers, so getting them from the API as unsigned
+# values doesn't work. Check the command output instead.
+for i in range(32):
+self.expect("register read v{}".format(i),
+substrs=[self.make_simd_value(i+value_offset)])
+
 def sve_simd_registers_impl(self, mode):
 self.skip_if_needed(mode)
 
@@ -68,12 +75,9 @@
 substrs=["stop reason = breakpoint 1."],
 )
 
-# These are 128 bit registers, so getting them from the API as unsigned
-# values doesn't work. Check the command output instead.
-for i in range(32):
-self.expect(
-"register read v{}".format(i), substrs=[self.make_simd_value(i)]
-)
+self.check_simd_values(0)
+self.runCmd("expression write_simd_regs_expr()")
+self.check_simd_values(0)
 
 # Write a new set of values. The kernel will move the program back to
 # non-streaming mode here.
@@ -83,10 +87,7 @@
 )
 
 # Should be visible within lldb.
-for i in range(32):
-self.expect(
-"register read v{}".format(i), substrs=[self.make_simd_value(i + 1)]
-)
+self.check_simd_values(1)
 
 # The program should agree with lldb.
 self.expect("continue", substrs=["exited with status = 0"])
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits