[Lldb-commits] [lldb] b712061 - [lldb] Remove unused forward declaration RecordingMemoryManager

2023-06-14 Thread Kazu Hirata via lldb-commits

Author: Kazu Hirata
Date: 2023-06-14T22:04:43-07:00
New Revision: b712061441b4990c8195b940912d2a4ac0bdbee0

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

LOG: [lldb] Remove unused forward declaration RecordingMemoryManager

The corresponding class definition was removed by:

  commit 8dfb68e0398ef48d41dc8ea058e9aa750b5fc85f
  Author: Sean Callanan 
  Date:   Tue Mar 19 00:10:07 2013 +

Added: 


Modified: 
lldb/include/lldb/Expression/Expression.h
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h

Removed: 




diff  --git a/lldb/include/lldb/Expression/Expression.h 
b/lldb/include/lldb/Expression/Expression.h
index b4207de958e98..3e61d78828bbb 100644
--- a/lldb/include/lldb/Expression/Expression.h
+++ b/lldb/include/lldb/Expression/Expression.h
@@ -20,8 +20,6 @@
 
 namespace lldb_private {
 
-class RecordingMemoryManager;
-
 /// \class Expression Expression.h "lldb/Expression/Expression.h" Encapsulates
 /// a single expression for use in lldb
 ///

diff  --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h
index 41e62ae72f6ca..e66d46c21ddfa 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h
@@ -24,7 +24,6 @@ class ASTConsumer;
 namespace lldb_private {
 
 class ClangExpressionDeclMap;
-class RecordingMemoryManager;
 
 // ClangExpressionHelper
 class ClangExpressionHelper



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


[Lldb-commits] [PATCH] D152886: [lldb] Make it easier to spot if sources were resolved in crashlog output

2023-06-14 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7371ec76299d: [lldb] Have crashlog warn when remapped paths 
are inaccessible. (authored by JDevlieghere).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152886

Files:
  lldb/examples/python/crashlog.py


Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -306,6 +306,8 @@
 if self.show_symbol_progress():
 with print_lock:
 print("Getting symbols for %s %s..." % (uuid_str, 
self.path))
+# Keep track of unresolved source paths.
+unavailable_source_paths = set()
 if os.path.exists(self.dsymForUUIDBinary):
 dsym_for_uuid_command = "%s %s" % (self.dsymForUUIDBinary, 
uuid_str)
 s = subprocess.check_output(dsym_for_uuid_command, shell=True)
@@ -335,6 +337,12 @@
 plist["DBGSymbolRichExecutable"]
 )
 self.resolved_path = self.path
+if "DBGSourcePathRemapping" in plist:
+path_remapping = 
plist["DBGSourcePathRemapping"]
+for _, value in path_remapping.items():
+source_path = os.path.expanduser(value)
+if not os.path.exists(source_path):
+
unavailable_source_paths.add(source_path)
 if not self.resolved_path and os.path.exists(self.path):
 if not self.find_matching_slice():
 return False
@@ -373,6 +381,12 @@
 ):
 with print_lock:
 print("Resolved symbols for %s %s..." % (uuid_str, 
self.path))
+if len(unavailable_source_paths):
+for source_path in unavailable_source_paths:
+print(
+"Could not access remapped source path for %s 
%s"
+% (uuid_str, source_path)
+)
 return True
 else:
 self.unavailable = True


Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -306,6 +306,8 @@
 if self.show_symbol_progress():
 with print_lock:
 print("Getting symbols for %s %s..." % (uuid_str, self.path))
+# Keep track of unresolved source paths.
+unavailable_source_paths = set()
 if os.path.exists(self.dsymForUUIDBinary):
 dsym_for_uuid_command = "%s %s" % (self.dsymForUUIDBinary, uuid_str)
 s = subprocess.check_output(dsym_for_uuid_command, shell=True)
@@ -335,6 +337,12 @@
 plist["DBGSymbolRichExecutable"]
 )
 self.resolved_path = self.path
+if "DBGSourcePathRemapping" in plist:
+path_remapping = plist["DBGSourcePathRemapping"]
+for _, value in path_remapping.items():
+source_path = os.path.expanduser(value)
+if not os.path.exists(source_path):
+unavailable_source_paths.add(source_path)
 if not self.resolved_path and os.path.exists(self.path):
 if not self.find_matching_slice():
 return False
@@ -373,6 +381,12 @@
 ):
 with print_lock:
 print("Resolved symbols for %s %s..." % (uuid_str, self.path))
+if len(unavailable_source_paths):
+for source_path in unavailable_source_paths:
+print(
+"Could not access remapped source path for %s %s"
+% (uuid_str, source_path)
+)
 return True
 else:
 self.unavailable = True
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 7371ec7 - [lldb] Have crashlog warn when remapped paths are inaccessible.

2023-06-14 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2023-06-14T17:15:28-07:00
New Revision: 7371ec76299df6922911233bd6ee07d7629d09b6

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

LOG: [lldb] Have crashlog warn when remapped paths are inaccessible.

It can be tricky to troubleshoot why the crashlog script can't show
inline sources. The two most common causes are that we couldn't find the
dSYM or, if we find the dSYM, that the path remapping included in the
dSYMForUUID output isn't accessible. The former is already easy to
diagnose, but the latter is harder because you'd have to manually invoke
dsymForUUID on the UUID and check the remapped path. This patch
automates that process and prints a warning if the remapped path doesn't
exist or is not accessible.

Differential revision: https://reviews.llvm.org/D152886

Added: 


Modified: 
lldb/examples/python/crashlog.py

Removed: 




diff  --git a/lldb/examples/python/crashlog.py 
b/lldb/examples/python/crashlog.py
index 6f69ef5bff7fc..709dda714eb34 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -306,6 +306,8 @@ def locate_module_and_debug_symbols(self):
 if self.show_symbol_progress():
 with print_lock:
 print("Getting symbols for %s %s..." % (uuid_str, 
self.path))
+# Keep track of unresolved source paths.
+unavailable_source_paths = set()
 if os.path.exists(self.dsymForUUIDBinary):
 dsym_for_uuid_command = "%s %s" % (self.dsymForUUIDBinary, 
uuid_str)
 s = subprocess.check_output(dsym_for_uuid_command, shell=True)
@@ -335,6 +337,12 @@ def locate_module_and_debug_symbols(self):
 plist["DBGSymbolRichExecutable"]
 )
 self.resolved_path = self.path
+if "DBGSourcePathRemapping" in plist:
+path_remapping = 
plist["DBGSourcePathRemapping"]
+for _, value in path_remapping.items():
+source_path = os.path.expanduser(value)
+if not os.path.exists(source_path):
+
unavailable_source_paths.add(source_path)
 if not self.resolved_path and os.path.exists(self.path):
 if not self.find_matching_slice():
 return False
@@ -373,6 +381,12 @@ def locate_module_and_debug_symbols(self):
 ):
 with print_lock:
 print("Resolved symbols for %s %s..." % (uuid_str, 
self.path))
+if len(unavailable_source_paths):
+for source_path in unavailable_source_paths:
+print(
+"Could not access remapped source path for %s 
%s"
+% (uuid_str, source_path)
+)
 return True
 else:
 self.unavailable = True



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


[Lldb-commits] [lldb] 048204d - [lldb] Remove lldbassert from DebugNamesDWARFIndex::GetGlobalVariables

2023-06-14 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2023-06-14T17:15:20-07:00
New Revision: 048204d6102ab984c067c1a1c9889edb7f58d419

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

LOG: [lldb] Remove lldbassert from DebugNamesDWARFIndex::GetGlobalVariables

34a8e6eee666 changed SymbolFileDWARF::GetDwoNum to
SymbolFileDWARF::GetFileIndex but changed the meaning from just DWO to
DWO and OSO which changed the meaning of the assert. The assert was
therefore removed from ManualDWARFIndex::GetGlobalVariables and
ManualDWARFIndex::GetGlobalVariables but was still present in
DebugNamesDWARFIndex::GetGlobalVariables. If we want to reintroduce the
assert, we need something with the old semantics for all 3.

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
index c72d5ccabd1dc..d09e233441de6 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
@@ -126,7 +126,6 @@ void DebugNamesDWARFIndex::GetGlobalVariables(
 
 void DebugNamesDWARFIndex::GetGlobalVariables(
 DWARFUnit , llvm::function_ref callback) {
-  lldbassert(!cu.GetSymbolFileDWARF().GetFileIndex());
   uint64_t cu_offset = cu.GetOffset();
   bool found_entry_for_cu = false;
   for (const DebugNames::NameIndex : *m_debug_names_up) {



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


[Lldb-commits] [PATCH] D152933: [lldb][Android] Add platform.plugin.remote-android.run-as

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531579.
splhack added a comment.

Fixed diff dependencies in order to fix CI
https://reviews.llvm.org/B238946


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152933

Files:
  lldb/source/Plugins/Platform/Android/CMakeLists.txt
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.h
  lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
  lldb/unittests/Platform/Android/PlatformAndroidTest.cpp

Index: lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
===
--- lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
+++ lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
@@ -52,6 +52,7 @@
   }
 
   MOCK_METHOD0(GetAdbClient, AdbClientSP());
+  MOCK_METHOD0(GetPropertyRunAs, llvm::StringRef());
 };
 
 } // namespace
@@ -100,6 +101,32 @@
   .Success());
 }
 
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithZipFileAndRunAs) {
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client,
+  ShellToFile(StrEq("run-as 'com.example.test' "
+"dd if='/system/app/Test/Test.apk' "
+"iflag=skip_bytes,count_bytes "
+"skip=4096 count=3600 status=none"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetPropertyRunAs())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.test")));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(
+  FileSpec("/system/app/Test/Test.apk!/lib/arm64-v8a/libtest.so"), 4096,
+  3600, FileSpec())
+  .Success());
+}
+
 TEST_F(PlatformAndroidTest, GetFileWithNormalFile) {
   auto sync_service = new MockSyncService();
   EXPECT_CALL(*sync_service, Stat(FileSpec("/data/local/tmp/test"), _, _, _))
@@ -152,3 +179,40 @@
   FileSpec())
   .Success());
 }
+
+TEST_F(PlatformAndroidTest, GetFileWithCatFallbackAndRunAs) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(
+  *sync_service,
+  Stat(FileSpec("/data/data/com.example.app/lib-main/libtest.so"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(0), Return(Status(;
+
+  auto adb_client0 = new MockAdbClient();
+  EXPECT_CALL(*adb_client0, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  auto adb_client1 = new MockAdbClient();
+  EXPECT_CALL(
+  *adb_client1,
+  ShellToFile(StrEq("run-as 'com.example.app' "
+"cat '/data/data/com.example.app/lib-main/libtest.so'"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetPropertyRunAs())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.app")));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(2)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client0)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client1);
+
+  EXPECT_TRUE(
+  GetFile(FileSpec("/data/data/com.example.app/lib-main/libtest.so"),
+  FileSpec())
+  .Success());
+}
Index: lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
===
--- /dev/null
+++ lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
@@ -0,0 +1,9 @@
+include "../../../../include/lldb/Core/PropertiesBase.td"
+
+let Definition = "android" in {
+  def PlatformRunAs: Property<"run-as", "String">,
+Global,
+DefaultStringValue<"">,
+Desc<"Specify package name to run adb shell command with 'run-as' as the "
+ "package user when necessary (e.g. to get file with 'cat' and 'dd').">;
+}
Index: lldb/source/Plugins/Platform/Android/PlatformAndroid.h
===
--- lldb/source/Plugins/Platform/Android/PlatformAndroid.h
+++ lldb/source/Plugins/Platform/Android/PlatformAndroid.h
@@ -30,6 +30,8 @@
   // lldb_private::PluginInterface functions
   static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
 
+  static void DebuggerInitialize(lldb_private::Debugger );
+
   static llvm::StringRef GetPluginNameStatic(bool is_host) {
 return is_host ? Platform::GetHostPlatformName() : "remote-android";
   }
@@ -73,6 +75,10 @@
   typedef std::unique_ptr AdbClientSP;
   virtual AdbClientSP GetAdbClient();
 
+  virtual llvm::StringRef GetPropertyRunAs();
+
+  std::string GetRunAs();
+
 private:
   AdbClient::SyncService *GetSyncService(Status );
 
@@ -81,7 +87,7 @@
   uint32_t m_sdk_version;
 };
 
-} // namespace 

[Lldb-commits] [PATCH] D152855: [lldb][Android] Add PlatformAndroidTest

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531578.
splhack added a comment.

Fixed diff dependencies in order to fix CI
https://reviews.llvm.org/B238938


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152855

Files:
  lldb/source/Plugins/Platform/Android/AdbClient.h
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.h
  lldb/unittests/Platform/Android/CMakeLists.txt
  lldb/unittests/Platform/Android/PlatformAndroidTest.cpp

Index: lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
===
--- /dev/null
+++ lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
@@ -0,0 +1,154 @@
+//===-- PlatformAndroidTest.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 "Plugins/Platform/Android/PlatformAndroid.h"
+#include "Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Utility/Connection.h"
+#include "gmock/gmock.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_android;
+using namespace testing;
+
+namespace {
+
+class MockSyncService : public AdbClient::SyncService {
+public:
+  MockSyncService() : SyncService(std::move(m_mock_conn)) {}
+
+  MOCK_METHOD2(PullFile,
+   Status(const FileSpec _file, const FileSpec _file));
+  MOCK_METHOD4(Stat, Status(const FileSpec _file, uint32_t ,
+uint32_t , uint32_t ));
+
+private:
+  std::unique_ptr m_mock_conn;
+};
+
+typedef std::unique_ptr SyncServiceSP;
+
+class MockAdbClient : public AdbClient {
+public:
+  explicit MockAdbClient() : AdbClient("mock") {}
+
+  MOCK_METHOD3(ShellToFile,
+   Status(const char *command, std::chrono::milliseconds timeout,
+  const FileSpec _file_spec));
+  MOCK_METHOD1(GetSyncService, SyncServiceSP(Status ));
+};
+
+class PlatformAndroidTest : public PlatformAndroid, public ::testing::Test {
+public:
+  PlatformAndroidTest() : PlatformAndroid(false) {
+m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
+  }
+
+  MOCK_METHOD0(GetAdbClient, AdbClientSP());
+};
+
+} // namespace
+
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithNormalFile) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(*sync_service, Stat(FileSpec("/system/lib64/libc.so"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(1), Return(Status(;
+  EXPECT_CALL(*sync_service, PullFile(FileSpec("/system/lib64/libc.so"), _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(FileSpec("/system/lib64/libc.so"), 0, 0, FileSpec())
+  .Success());
+}
+
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithZipFile) {
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client,
+  ShellToFile(StrEq("dd if='/system/app/Test/Test.apk' "
+"iflag=skip_bytes,count_bytes "
+"skip=4096 count=3600 status=none"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(
+  FileSpec("/system/app/Test/Test.apk!/lib/arm64-v8a/libtest.so"), 4096,
+  3600, FileSpec())
+  .Success());
+}
+
+TEST_F(PlatformAndroidTest, GetFileWithNormalFile) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(*sync_service, Stat(FileSpec("/data/local/tmp/test"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(1), Return(Status(;
+  EXPECT_CALL(*sync_service, PullFile(FileSpec("/data/local/tmp/test"), _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(GetFile(FileSpec("/data/local/tmp/test"), 

[Lldb-commits] [PATCH] D152759: [lldb][Android] Support zip .so file

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531576.
splhack added a comment.

Fixed diff dependencies in order to fix CI
https://reviews.llvm.org/B238937


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152759

Files:
  lldb/include/lldb/Host/common/ZipFileResolver.h
  lldb/include/lldb/Utility/ZipFile.h
  lldb/source/Host/CMakeLists.txt
  lldb/source/Host/common/ZipFileResolver.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/ZipFile.cpp
  lldb/unittests/Host/CMakeLists.txt
  lldb/unittests/Host/common/CMakeLists.txt
  lldb/unittests/Host/common/Inputs/zip-test.zip
  lldb/unittests/Host/common/ZipFileResolverTest.cpp

Index: lldb/unittests/Host/common/ZipFileResolverTest.cpp
===
--- /dev/null
+++ lldb/unittests/Host/common/ZipFileResolverTest.cpp
@@ -0,0 +1,72 @@
+//===-- ZipFileResolverTest.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/Host/common/ZipFileResolver.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace llvm;
+
+namespace {
+class ZipFileResolverTest : public ::testing::Test {
+  SubsystemRAII subsystems;
+};
+
+std::string TestZipPath() {
+  FileSpec zip_spec(GetInputFilePath("zip-test.zip"));
+  FileSystem::Instance().Resolve(zip_spec);
+  return zip_spec.GetPath();
+}
+} // namespace
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithNormalFile) {
+  const FileSpec file_spec("/system/lib64/libtest.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_TRUE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+
+  EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindNormal);
+  EXPECT_EQ(file_path, file_spec.GetPath());
+  EXPECT_EQ(file_offset, 0UL);
+  EXPECT_EQ(file_size, 0UL);
+}
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithZipMissing) {
+  const std::string zip_path = TestZipPath();
+  const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libmissing.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_FALSE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+}
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithZipExisting) {
+  const std::string zip_path = TestZipPath();
+  const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libzip-test.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_TRUE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+
+  EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindZip);
+  EXPECT_EQ(file_path, zip_path);
+  EXPECT_EQ(file_offset, 4096UL);
+  EXPECT_EQ(file_size, 3600UL);
+}
Index: lldb/unittests/Host/common/CMakeLists.txt
===
--- /dev/null
+++ lldb/unittests/Host/common/CMakeLists.txt
@@ -0,0 +1,15 @@
+set (FILES
+  ZipFileResolverTest.cpp
+)
+
+add_lldb_unittest(HostCommonTests
+  ${FILES}
+  LINK_LIBS
+lldbHost
+lldbUtilityHelpers
+  )
+
+set(test_inputs
+  zip-test.zip
+  )
+add_unittest_inputs(HostCommonTests "${test_inputs}")
Index: lldb/unittests/Host/CMakeLists.txt
===
--- lldb/unittests/Host/CMakeLists.txt
+++ lldb/unittests/Host/CMakeLists.txt
@@ -38,3 +38,5 @@
 LLVMTestingSupport
 LLVMTargetParser
   )
+
+add_subdirectory(common)
Index: lldb/source/Utility/ZipFile.cpp
===
--- /dev/null
+++ lldb/source/Utility/ZipFile.cpp
@@ -0,0 +1,180 @@
+//===-- ZipFile.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/ZipFile.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/FileSpec.h"
+#include "llvm/Support/Endian.h"
+
+using namespace lldb_private;
+using 

[Lldb-commits] [PATCH] D152712: [lldb][Android] Use a lambda for calls to ::open in RetryAfterSignal

2023-06-14 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

Nice. LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152712

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


[Lldb-commits] [PATCH] D152886: [lldb] Make it easier to spot if sources were resolved in crashlog output

2023-06-14 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib accepted this revision.
mib added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!


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

https://reviews.llvm.org/D152886

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


[Lldb-commits] [PATCH] D152886: [lldb] Make it easier to spot if sources were resolved in crashlog output

2023-06-14 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 531562.
JDevlieghere marked 2 inline comments as done.
JDevlieghere added a comment.

Make the warning its own line


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

https://reviews.llvm.org/D152886

Files:
  lldb/examples/python/crashlog.py


Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -306,6 +306,8 @@
 if self.show_symbol_progress():
 with print_lock:
 print("Getting symbols for %s %s..." % (uuid_str, 
self.path))
+# Keep track of unresolved source paths.
+unavailable_source_paths = set()
 if os.path.exists(self.dsymForUUIDBinary):
 dsym_for_uuid_command = "%s %s" % (self.dsymForUUIDBinary, 
uuid_str)
 s = subprocess.check_output(dsym_for_uuid_command, shell=True)
@@ -335,6 +337,12 @@
 plist["DBGSymbolRichExecutable"]
 )
 self.resolved_path = self.path
+if "DBGSourcePathRemapping" in plist:
+path_remapping = 
plist["DBGSourcePathRemapping"]
+for _, value in path_remapping.items():
+source_path = os.path.expanduser(value)
+if not os.path.exists(source_path):
+
unavailable_source_paths.add(source_path)
 if not self.resolved_path and os.path.exists(self.path):
 if not self.find_matching_slice():
 return False
@@ -373,6 +381,12 @@
 ):
 with print_lock:
 print("Resolved symbols for %s %s..." % (uuid_str, 
self.path))
+if len(unavailable_source_paths):
+for source_path in unavailable_source_paths:
+print(
+"Could not access remapped source path for %s 
%s"
+% (uuid_str, source_path)
+)
 return True
 else:
 self.unavailable = True


Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -306,6 +306,8 @@
 if self.show_symbol_progress():
 with print_lock:
 print("Getting symbols for %s %s..." % (uuid_str, self.path))
+# Keep track of unresolved source paths.
+unavailable_source_paths = set()
 if os.path.exists(self.dsymForUUIDBinary):
 dsym_for_uuid_command = "%s %s" % (self.dsymForUUIDBinary, uuid_str)
 s = subprocess.check_output(dsym_for_uuid_command, shell=True)
@@ -335,6 +337,12 @@
 plist["DBGSymbolRichExecutable"]
 )
 self.resolved_path = self.path
+if "DBGSourcePathRemapping" in plist:
+path_remapping = plist["DBGSourcePathRemapping"]
+for _, value in path_remapping.items():
+source_path = os.path.expanduser(value)
+if not os.path.exists(source_path):
+unavailable_source_paths.add(source_path)
 if not self.resolved_path and os.path.exists(self.path):
 if not self.find_matching_slice():
 return False
@@ -373,6 +381,12 @@
 ):
 with print_lock:
 print("Resolved symbols for %s %s..." % (uuid_str, self.path))
+if len(unavailable_source_paths):
+for source_path in unavailable_source_paths:
+print(
+"Could not access remapped source path for %s %s"
+% (uuid_str, source_path)
+)
 return True
 else:
 self.unavailable = True
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D152962: [lldb] Fix SBPlatform after f4be9ff6458f

2023-06-14 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG623ad8a8ddc9: [lldb] Fix SBPlatform after f4be9ff6458f 
(authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152962

Files:
  lldb/source/API/SBPlatform.cpp


Index: lldb/source/API/SBPlatform.cpp
===
--- lldb/source/API/SBPlatform.cpp
+++ lldb/source/API/SBPlatform.cpp
@@ -488,7 +488,7 @@
 void SBPlatform::SetSDKRoot(const char *sysroot) {
   LLDB_INSTRUMENT_VA(this, sysroot);
   if (PlatformSP platform_sp = GetSP())
-platform_sp->SetSDKRootDirectory(sysroot);
+platform_sp->SetSDKRootDirectory(llvm::StringRef(sysroot).str());
 }
 
 SBError SBPlatform::Get(SBFileSpec , SBFileSpec ) {


Index: lldb/source/API/SBPlatform.cpp
===
--- lldb/source/API/SBPlatform.cpp
+++ lldb/source/API/SBPlatform.cpp
@@ -488,7 +488,7 @@
 void SBPlatform::SetSDKRoot(const char *sysroot) {
   LLDB_INSTRUMENT_VA(this, sysroot);
   if (PlatformSP platform_sp = GetSP())
-platform_sp->SetSDKRootDirectory(sysroot);
+platform_sp->SetSDKRootDirectory(llvm::StringRef(sysroot).str());
 }
 
 SBError SBPlatform::Get(SBFileSpec , SBFileSpec ) {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 623ad8a - [lldb] Fix SBPlatform after f4be9ff6458f

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

Author: Alex Langford
Date: 2023-06-14T15:46:00-07:00
New Revision: 623ad8a8ddc96e9dee4f354ee4e7b3e7c11b119f

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

LOG: [lldb] Fix SBPlatform after f4be9ff6458f

If you pass `nullptr` (or `None` from python) to SBPlatform::SetSDKRoot,
LLDB crashes. Let's be more resilient to `nullptr` here.

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

Added: 


Modified: 
lldb/source/API/SBPlatform.cpp

Removed: 




diff  --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index 12461f3713eca..ed55e93ffc9de 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -488,7 +488,7 @@ uint32_t SBPlatform::GetOSUpdateVersion() {
 void SBPlatform::SetSDKRoot(const char *sysroot) {
   LLDB_INSTRUMENT_VA(this, sysroot);
   if (PlatformSP platform_sp = GetSP())
-platform_sp->SetSDKRootDirectory(sysroot);
+platform_sp->SetSDKRootDirectory(llvm::StringRef(sysroot).str());
 }
 
 SBError SBPlatform::Get(SBFileSpec , SBFileSpec ) {



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


[Lldb-commits] [PATCH] D152870: [lldb][NFCI] Remove StructuredData::Array::GetItemAtIndexAsString overloads with ConstString

2023-06-14 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added inline comments.



Comment at: lldb/source/Target/DynamicRegisterInfo.cpp:204
+m_sets.push_back(
+{ConstString(set_name).AsCString(), nullptr, 0, nullptr});
   } else {

I guess `m_sets` is a vector of `char*` ... Should we change it to 
`lldb::StringList` or `llvm::StringSet` so we don't have to create a 
`ConstString` here ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152870

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


[Lldb-commits] [PATCH] D152968: [lldb][NFCI] Remove use of ConstString in ProcessStructReader

2023-06-14 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, jingham, mib.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

std::map is naturally replaced with
`llvm::StringMap` here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152968

Files:
  lldb/include/lldb/Target/ProcessStructReader.h
  lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp


Index: lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
===
--- lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
+++ lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
@@ -442,13 +442,13 @@
 dispatch_tsd_indexes_s);
 
   m_libdispatch_tsd_indexes.dti_version =
-  struct_reader.GetField(ConstString("dti_version"));
+  struct_reader.GetField("dti_version");
   m_libdispatch_tsd_indexes.dti_queue_index =
-  struct_reader.GetField(ConstString("dti_queue_index"));
+  struct_reader.GetField("dti_queue_index");
   m_libdispatch_tsd_indexes.dti_voucher_index =
-  struct_reader.GetField(ConstString("dti_voucher_index"));
+  struct_reader.GetField("dti_voucher_index");
   m_libdispatch_tsd_indexes.dti_qos_class_index =
-  struct_reader.GetField(ConstString("dti_qos_class_index"));
+  struct_reader.GetField("dti_qos_class_index");
 }
   }
 }
Index: lldb/include/lldb/Target/ProcessStructReader.h
===
--- lldb/include/lldb/Target/ProcessStructReader.h
+++ lldb/include/lldb/Target/ProcessStructReader.h
@@ -14,11 +14,12 @@
 
 #include "lldb/Symbol/CompilerType.h"
 #include "lldb/Target/Process.h"
-#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/DataBufferHeap.h"
 #include "lldb/Utility/DataExtractor.h"
 #include "lldb/Utility/Status.h"
 
+#include "llvm/ADT/StringMap.h"
+
 #include 
 #include 
 #include 
@@ -32,7 +33,7 @@
 size_t size;
   };
 
-  std::map m_fields;
+  llvm::StringMap m_fields;
   DataExtractor m_data;
   lldb::ByteOrder m_byte_order;
   size_t m_addr_byte_size;
@@ -62,10 +63,9 @@
   // no support for things larger than a uint64_t (yet)
   if (!size || *size > 8)
 return;
-  ConstString const_name = ConstString(name.c_str());
   size_t byte_index = static_cast(bit_offset / 8);
-  m_fields[const_name] =
-  FieldImpl{field_type, byte_index, static_cast(*size)};
+  m_fields.insert({name, FieldImpl{field_type, byte_index,
+   static_cast(*size)}});
 }
 auto total_size = struct_type.GetByteSize(nullptr);
 if (!total_size)
@@ -80,7 +80,7 @@
   }
 
   template 
-  RetType GetField(ConstString name, RetType fail_value = RetType()) {
+  RetType GetField(llvm::StringRef name, RetType fail_value = RetType()) {
 auto iter = m_fields.find(name), end = m_fields.end();
 if (iter == end)
   return fail_value;


Index: lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
===
--- lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
+++ lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
@@ -442,13 +442,13 @@
 dispatch_tsd_indexes_s);
 
   m_libdispatch_tsd_indexes.dti_version =
-  struct_reader.GetField(ConstString("dti_version"));
+  struct_reader.GetField("dti_version");
   m_libdispatch_tsd_indexes.dti_queue_index =
-  struct_reader.GetField(ConstString("dti_queue_index"));
+  struct_reader.GetField("dti_queue_index");
   m_libdispatch_tsd_indexes.dti_voucher_index =
-  struct_reader.GetField(ConstString("dti_voucher_index"));
+  struct_reader.GetField("dti_voucher_index");
   m_libdispatch_tsd_indexes.dti_qos_class_index =
-  struct_reader.GetField(ConstString("dti_qos_class_index"));
+  struct_reader.GetField("dti_qos_class_index");
 }
   }
 }
Index: lldb/include/lldb/Target/ProcessStructReader.h
===
--- lldb/include/lldb/Target/ProcessStructReader.h
+++ lldb/include/lldb/Target/ProcessStructReader.h
@@ -14,11 +14,12 @@
 
 #include "lldb/Symbol/CompilerType.h"
 #include "lldb/Target/Process.h"
-#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/DataBufferHeap.h"
 #include "lldb/Utility/DataExtractor.h"
 #include "lldb/Utility/Status.h"
 
+#include "llvm/ADT/StringMap.h"
+
 #include 
 #include 
 #include 
@@ -32,7 +33,7 @@
 size_t size;
   };
 
-  std::map m_fields;
+  llvm::StringMap m_fields;
   DataExtractor m_data;
   lldb::ByteOrder m_byte_order;
   size_t m_addr_byte_size;
@@ -62,10 +63,9 @@
   // no support for things 

[Lldb-commits] [lldb] f6ca15c - [lldb][NFCI] Remove unused method ProcessStructReader::GetOffsetOf

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

Author: Alex Langford
Date: 2023-06-14T14:45:21-07:00
New Revision: f6ca15cfb20983e2a966efad663a25bd61826c07

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

LOG: [lldb][NFCI] Remove unused method ProcessStructReader::GetOffsetOf

Completely unused here, AFAICT. It's also not used in the swift
downstream forks.

Added: 


Modified: 
lldb/include/lldb/Target/ProcessStructReader.h

Removed: 




diff  --git a/lldb/include/lldb/Target/ProcessStructReader.h 
b/lldb/include/lldb/Target/ProcessStructReader.h
index 4af51cac32890..ceb70528cf2d1 100644
--- a/lldb/include/lldb/Target/ProcessStructReader.h
+++ b/lldb/include/lldb/Target/ProcessStructReader.h
@@ -92,13 +92,6 @@ class ProcessStructReader {
   return fail_value;
 return (RetType)(m_data.GetMaxU64(, size));
   }
-
-  size_t GetOffsetOf(ConstString name, size_t fail_value = SIZE_MAX) {
-auto iter = m_fields.find(name), end = m_fields.end();
-if (iter == end)
-  return fail_value;
-return iter->second.offset;
-  }
 };
 }
 



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


[Lldb-commits] [lldb] a9ddf45 - [lldb][NFCI] Remove ProcessStructReader header where unused

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

Author: Alex Langford
Date: 2023-06-14T14:38:18-07:00
New Revision: a9ddf45b8ace943b637837b63e38f297ac811442

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

LOG: [lldb][NFCI] Remove ProcessStructReader header where unused

Added: 


Modified: 
lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
lldb/source/Plugins/Language/ObjC/Cocoa.cpp
lldb/source/Plugins/Language/ObjC/NSError.cpp
lldb/source/Plugins/Language/ObjC/NSException.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
index bbd1e52ebaaf1..6781c96210a42 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp
@@ -17,7 +17,6 @@
 #include "lldb/DataFormatters/StringPrinter.h"
 #include "lldb/DataFormatters/TypeSummary.h"
 #include "lldb/Host/Time.h"
-#include "lldb/Target/ProcessStructReader.h"
 #include "lldb/Target/SectionLoadList.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"

diff  --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index efd14501bcf75..666b467a88813 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -16,7 +16,6 @@
 #include "lldb/DataFormatters/StringPrinter.h"
 #include "lldb/DataFormatters/TypeSummary.h"
 #include "lldb/DataFormatters/VectorIterator.h"
-#include "lldb/Target/ProcessStructReader.h"
 #include "lldb/Target/SectionLoadList.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Utility/ConstString.h"

diff  --git a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp 
b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
index e85781d919ed9..374ac763ab183 100644
--- a/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
+++ b/lldb/source/Plugins/Language/ObjC/Cocoa.cpp
@@ -21,7 +21,6 @@
 #include "lldb/Host/Time.h"
 #include "lldb/Target/Language.h"
 #include "lldb/Target/Process.h"
-#include "lldb/Target/ProcessStructReader.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Utility/DataBufferHeap.h"
 #include "lldb/Utility/Endian.h"

diff  --git a/lldb/source/Plugins/Language/ObjC/NSError.cpp 
b/lldb/source/Plugins/Language/ObjC/NSError.cpp
index c267089f763db..99eeb2d5092f2 100644
--- a/lldb/source/Plugins/Language/ObjC/NSError.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSError.cpp
@@ -14,7 +14,6 @@
 #include "lldb/Core/ValueObject.h"
 #include "lldb/Core/ValueObjectConstResult.h"
 #include "lldb/DataFormatters/FormattersHelpers.h"
-#include "lldb/Target/ProcessStructReader.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Utility/DataBufferHeap.h"
 #include "lldb/Utility/Endian.h"

diff  --git a/lldb/source/Plugins/Language/ObjC/NSException.cpp 
b/lldb/source/Plugins/Language/ObjC/NSException.cpp
index 875a30c118776..29805bb2d5fe8 100644
--- a/lldb/source/Plugins/Language/ObjC/NSException.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSException.cpp
@@ -13,7 +13,6 @@
 #include "lldb/Core/ValueObject.h"
 #include "lldb/Core/ValueObjectConstResult.h"
 #include "lldb/DataFormatters/FormattersHelpers.h"
-#include "lldb/Target/ProcessStructReader.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Utility/DataBufferHeap.h"
 #include "lldb/Utility/Endian.h"



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


[Lldb-commits] [PATCH] D152331: [lldb][NFCI] Platforms should own their SDKBuild and SDKRootDirectory strings

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

Looks like this actually causes TestDebuggerAPI.py to segfault because 
SBPlatform::SetSDKRoot can take `nullptr` for its argument, and the conversion 
from `nullptr -> std::string` blows up. I'm fixing that in 
https://reviews.llvm.org/D152962.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152331

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


[Lldb-commits] [PATCH] D152962: [lldb] Fix SBPlatform after f4be9ff6458f

2023-06-14 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added a reviewer: jingham.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

If you pass `nullptr` (or `None` from python) to SBPlatform::SetSDKRoot,
LLDB crashes. Let's be more resilient to `nullptr` here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152962

Files:
  lldb/source/API/SBPlatform.cpp


Index: lldb/source/API/SBPlatform.cpp
===
--- lldb/source/API/SBPlatform.cpp
+++ lldb/source/API/SBPlatform.cpp
@@ -488,7 +488,7 @@
 void SBPlatform::SetSDKRoot(const char *sysroot) {
   LLDB_INSTRUMENT_VA(this, sysroot);
   if (PlatformSP platform_sp = GetSP())
-platform_sp->SetSDKRootDirectory(sysroot);
+platform_sp->SetSDKRootDirectory(llvm::StringRef(sysroot).str());
 }
 
 SBError SBPlatform::Get(SBFileSpec , SBFileSpec ) {


Index: lldb/source/API/SBPlatform.cpp
===
--- lldb/source/API/SBPlatform.cpp
+++ lldb/source/API/SBPlatform.cpp
@@ -488,7 +488,7 @@
 void SBPlatform::SetSDKRoot(const char *sysroot) {
   LLDB_INSTRUMENT_VA(this, sysroot);
   if (PlatformSP platform_sp = GetSP())
-platform_sp->SetSDKRootDirectory(sysroot);
+platform_sp->SetSDKRootDirectory(llvm::StringRef(sysroot).str());
 }
 
 SBError SBPlatform::Get(SBFileSpec , SBFileSpec ) {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D152933: [lldb][Android] Add platform.plugin.remote-android.run-as

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531509.
splhack added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152933

Files:
  lldb/source/Plugins/Platform/Android/CMakeLists.txt
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.h
  lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
  lldb/unittests/Platform/Android/PlatformAndroidTest.cpp

Index: lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
===
--- lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
+++ lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
@@ -52,6 +52,7 @@
   }
 
   MOCK_METHOD0(GetAdbClient, AdbClientSP());
+  MOCK_METHOD0(GetPropertyRunAs, llvm::StringRef());
 };
 
 } // namespace
@@ -100,6 +101,32 @@
   .Success());
 }
 
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithZipFileAndRunAs) {
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client,
+  ShellToFile(StrEq("run-as 'com.example.test' "
+"dd if='/system/app/Test/Test.apk' "
+"iflag=skip_bytes,count_bytes "
+"skip=4096 count=3600 status=none"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetPropertyRunAs())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.test")));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(
+  FileSpec("/system/app/Test/Test.apk!/lib/arm64-v8a/libtest.so"), 4096,
+  3600, FileSpec())
+  .Success());
+}
+
 TEST_F(PlatformAndroidTest, GetFileWithNormalFile) {
   auto sync_service = new MockSyncService();
   EXPECT_CALL(*sync_service, Stat(FileSpec("/data/local/tmp/test"), _, _, _))
@@ -152,3 +179,40 @@
   FileSpec())
   .Success());
 }
+
+TEST_F(PlatformAndroidTest, GetFileWithCatFallbackAndRunAs) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(
+  *sync_service,
+  Stat(FileSpec("/data/data/com.example.app/lib-main/libtest.so"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(0), Return(Status(;
+
+  auto adb_client0 = new MockAdbClient();
+  EXPECT_CALL(*adb_client0, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  auto adb_client1 = new MockAdbClient();
+  EXPECT_CALL(
+  *adb_client1,
+  ShellToFile(StrEq("run-as 'com.example.app' "
+"cat '/data/data/com.example.app/lib-main/libtest.so'"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetPropertyRunAs())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.app")));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(2)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client0)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client1);
+
+  EXPECT_TRUE(
+  GetFile(FileSpec("/data/data/com.example.app/lib-main/libtest.so"),
+  FileSpec())
+  .Success());
+}
Index: lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
===
--- /dev/null
+++ lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
@@ -0,0 +1,9 @@
+include "../../../../include/lldb/Core/PropertiesBase.td"
+
+let Definition = "android" in {
+  def PlatformRunAs: Property<"run-as", "String">,
+Global,
+DefaultStringValue<"">,
+Desc<"Specify package name to run adb shell command with 'run-as' as the "
+ "package user when necessary (e.g. to get file with 'cat' and 'dd').">;
+}
Index: lldb/source/Plugins/Platform/Android/PlatformAndroid.h
===
--- lldb/source/Plugins/Platform/Android/PlatformAndroid.h
+++ lldb/source/Plugins/Platform/Android/PlatformAndroid.h
@@ -30,6 +30,8 @@
   // lldb_private::PluginInterface functions
   static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
 
+  static void DebuggerInitialize(lldb_private::Debugger );
+
   static llvm::StringRef GetPluginNameStatic(bool is_host) {
 return is_host ? Platform::GetHostPlatformName() : "remote-android";
   }
@@ -73,6 +75,10 @@
   typedef std::unique_ptr AdbClientSP;
   virtual AdbClientSP GetAdbClient();
 
+  virtual llvm::StringRef GetPropertyRunAs();
+
+  std::string GetRunAs();
+
 private:
   AdbClient::SyncService *GetSyncService(Status );
 
@@ -81,7 +87,7 @@
   uint32_t m_sdk_version;
 };
 
-} // namespace platofor_android
+} // namespace platform_android
 } // namespace lldb_private
 
 

[Lldb-commits] [PATCH] D152855: [lldb][Android] Add PlatformAndroidTest

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531500.
splhack added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152855

Files:
  lldb/source/Plugins/Platform/Android/AdbClient.h
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.h
  lldb/unittests/Platform/Android/CMakeLists.txt
  lldb/unittests/Platform/Android/PlatformAndroidTest.cpp

Index: lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
===
--- /dev/null
+++ lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
@@ -0,0 +1,154 @@
+//===-- PlatformAndroidTest.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 "Plugins/Platform/Android/PlatformAndroid.h"
+#include "Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Utility/Connection.h"
+#include "gmock/gmock.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_android;
+using namespace testing;
+
+namespace {
+
+class MockSyncService : public AdbClient::SyncService {
+public:
+  MockSyncService() : SyncService(std::move(m_mock_conn)) {}
+
+  MOCK_METHOD2(PullFile,
+   Status(const FileSpec _file, const FileSpec _file));
+  MOCK_METHOD4(Stat, Status(const FileSpec _file, uint32_t ,
+uint32_t , uint32_t ));
+
+private:
+  std::unique_ptr m_mock_conn;
+};
+
+typedef std::unique_ptr SyncServiceSP;
+
+class MockAdbClient : public AdbClient {
+public:
+  explicit MockAdbClient() : AdbClient("mock") {}
+
+  MOCK_METHOD3(ShellToFile,
+   Status(const char *command, std::chrono::milliseconds timeout,
+  const FileSpec _file_spec));
+  MOCK_METHOD1(GetSyncService, SyncServiceSP(Status ));
+};
+
+class PlatformAndroidTest : public PlatformAndroid, public ::testing::Test {
+public:
+  PlatformAndroidTest() : PlatformAndroid(false) {
+m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
+  }
+
+  MOCK_METHOD0(GetAdbClient, AdbClientSP());
+};
+
+} // namespace
+
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithNormalFile) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(*sync_service, Stat(FileSpec("/system/lib64/libc.so"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(1), Return(Status(;
+  EXPECT_CALL(*sync_service, PullFile(FileSpec("/system/lib64/libc.so"), _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(FileSpec("/system/lib64/libc.so"), 0, 0, FileSpec())
+  .Success());
+}
+
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithZipFile) {
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client,
+  ShellToFile(StrEq("dd if='/system/app/Test/Test.apk' "
+"iflag=skip_bytes,count_bytes "
+"skip=4096 count=3600 status=none"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(
+  FileSpec("/system/app/Test/Test.apk!/lib/arm64-v8a/libtest.so"), 4096,
+  3600, FileSpec())
+  .Success());
+}
+
+TEST_F(PlatformAndroidTest, GetFileWithNormalFile) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(*sync_service, Stat(FileSpec("/data/local/tmp/test"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(1), Return(Status(;
+  EXPECT_CALL(*sync_service, PullFile(FileSpec("/data/local/tmp/test"), _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(GetFile(FileSpec("/data/local/tmp/test"), FileSpec()).Success());
+}
+
+TEST_F(PlatformAndroidTest, GetFileWithCatFallback) 

[Lldb-commits] [PATCH] D152759: [lldb][Android] Support zip .so file

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531499.
splhack added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152759

Files:
  lldb/include/lldb/Host/common/ZipFileResolver.h
  lldb/include/lldb/Utility/ZipFile.h
  lldb/source/Host/CMakeLists.txt
  lldb/source/Host/common/ZipFileResolver.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/ZipFile.cpp
  lldb/unittests/Host/CMakeLists.txt
  lldb/unittests/Host/common/CMakeLists.txt
  lldb/unittests/Host/common/Inputs/zip-test.zip
  lldb/unittests/Host/common/ZipFileResolverTest.cpp

Index: lldb/unittests/Host/common/ZipFileResolverTest.cpp
===
--- /dev/null
+++ lldb/unittests/Host/common/ZipFileResolverTest.cpp
@@ -0,0 +1,72 @@
+//===-- ZipFileResolverTest.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/Host/common/ZipFileResolver.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace llvm;
+
+namespace {
+class ZipFileResolverTest : public ::testing::Test {
+  SubsystemRAII subsystems;
+};
+
+std::string TestZipPath() {
+  FileSpec zip_spec(GetInputFilePath("zip-test.zip"));
+  FileSystem::Instance().Resolve(zip_spec);
+  return zip_spec.GetPath();
+}
+} // namespace
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithNormalFile) {
+  const FileSpec file_spec("/system/lib64/libtest.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_TRUE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+
+  EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindNormal);
+  EXPECT_EQ(file_path, file_spec.GetPath());
+  EXPECT_EQ(file_offset, 0UL);
+  EXPECT_EQ(file_size, 0UL);
+}
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithZipMissing) {
+  const std::string zip_path = TestZipPath();
+  const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libmissing.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_FALSE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+}
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithZipExisting) {
+  const std::string zip_path = TestZipPath();
+  const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libzip-test.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_TRUE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+
+  EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindZip);
+  EXPECT_EQ(file_path, zip_path);
+  EXPECT_EQ(file_offset, 4096UL);
+  EXPECT_EQ(file_size, 3600UL);
+}
Index: lldb/unittests/Host/common/CMakeLists.txt
===
--- /dev/null
+++ lldb/unittests/Host/common/CMakeLists.txt
@@ -0,0 +1,15 @@
+set (FILES
+  ZipFileResolverTest.cpp
+)
+
+add_lldb_unittest(HostCommonTests
+  ${FILES}
+  LINK_LIBS
+lldbHost
+lldbUtilityHelpers
+  )
+
+set(test_inputs
+  zip-test.zip
+  )
+add_unittest_inputs(HostCommonTests "${test_inputs}")
Index: lldb/unittests/Host/CMakeLists.txt
===
--- lldb/unittests/Host/CMakeLists.txt
+++ lldb/unittests/Host/CMakeLists.txt
@@ -38,3 +38,5 @@
 LLVMTestingSupport
 LLVMTargetParser
   )
+
+add_subdirectory(common)
Index: lldb/source/Utility/ZipFile.cpp
===
--- /dev/null
+++ lldb/source/Utility/ZipFile.cpp
@@ -0,0 +1,180 @@
+//===-- ZipFile.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/ZipFile.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/FileSpec.h"
+#include "llvm/Support/Endian.h"
+
+using namespace lldb_private;
+using namespace llvm::support;
+
+namespace {
+
+// Zip headers.
+// 

[Lldb-commits] [PATCH] D152757: [lldb][ObjectFileELF] Set ModuleSpec file offset and size

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531498.
splhack added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152757

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/CMakeLists.txt
  lldb/unittests/ObjectFile/ELF/Inputs/liboffset-test.so
  lldb/unittests/ObjectFile/ELF/Inputs/offset-test.bin
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp


Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -156,6 +156,35 @@
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
 
+TEST_F(ObjectFileELFTest, GetModuleSpecifications_OffsetSizeWithNormalFile) {
+  std::string SO = GetInputFilePath("liboffset-test.so");
+  ModuleSpecList Specs;
+  ASSERT_EQ(1u, ObjectFile::GetModuleSpecifications(FileSpec(SO), 0, 0, 
Specs));
+  ModuleSpec Spec;
+  ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ;
+  UUID Uuid;
+  Uuid.SetFromStringRef("7D6E4738");
+  EXPECT_EQ(Spec.GetUUID(), Uuid);
+  EXPECT_EQ(Spec.GetObjectOffset(), 0UL);
+  EXPECT_EQ(Spec.GetObjectSize(), 3600UL);
+  EXPECT_EQ(FileSystem::Instance().GetByteSize(FileSpec(SO)), 3600UL);
+}
+
+TEST_F(ObjectFileELFTest, GetModuleSpecifications_OffsetSizeWithOffsetFile) {
+  std::string SO = GetInputFilePath("offset-test.bin");
+  ModuleSpecList Specs;
+  ASSERT_EQ(
+  1u, ObjectFile::GetModuleSpecifications(FileSpec(SO), 1024, 3600, 
Specs));
+  ModuleSpec Spec;
+  ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ;
+  UUID Uuid;
+  Uuid.SetFromStringRef("7D6E4738");
+  EXPECT_EQ(Spec.GetUUID(), Uuid);
+  EXPECT_EQ(Spec.GetObjectOffset(), 1024UL);
+  EXPECT_EQ(Spec.GetObjectSize(), 3600UL);
+  EXPECT_EQ(FileSystem::Instance().GetByteSize(FileSpec(SO)), 4640UL);
+}
+
 TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
   /*
   // nosym-entrypoint-arm-thumb.s
Index: lldb/unittests/ObjectFile/ELF/CMakeLists.txt
===
--- lldb/unittests/ObjectFile/ELF/CMakeLists.txt
+++ lldb/unittests/ObjectFile/ELF/CMakeLists.txt
@@ -11,5 +11,7 @@
 
 set(test_inputs
   early-section-headers.so
+  liboffset-test.so
+  offset-test.bin
   )
 add_unittest_inputs(ObjectFileELFTests "${test_inputs}")
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -555,6 +555,8 @@
 if (header.Parse(data, _offset)) {
   if (data_sp) {
 ModuleSpec spec(file);
+spec.SetObjectOffset(file_offset);
+spec.SetObjectSize(length);
 
 const uint32_t sub_type = subTypeFromElfHeader(header);
 spec.GetArchitecture().SetArchitecture(
@@ -587,7 +589,7 @@
   }
 
   if (data_sp->GetByteSize() < length)
-data_sp = MapFileData(file, -1, file_offset);
+data_sp = MapFileData(file, length, file_offset);
   if (data_sp)
 data.SetData(data_sp);
   // In case there is header extension in the section #0, the header we


Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -156,6 +156,35 @@
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
 
+TEST_F(ObjectFileELFTest, GetModuleSpecifications_OffsetSizeWithNormalFile) {
+  std::string SO = GetInputFilePath("liboffset-test.so");
+  ModuleSpecList Specs;
+  ASSERT_EQ(1u, ObjectFile::GetModuleSpecifications(FileSpec(SO), 0, 0, Specs));
+  ModuleSpec Spec;
+  ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ;
+  UUID Uuid;
+  Uuid.SetFromStringRef("7D6E4738");
+  EXPECT_EQ(Spec.GetUUID(), Uuid);
+  EXPECT_EQ(Spec.GetObjectOffset(), 0UL);
+  EXPECT_EQ(Spec.GetObjectSize(), 3600UL);
+  EXPECT_EQ(FileSystem::Instance().GetByteSize(FileSpec(SO)), 3600UL);
+}
+
+TEST_F(ObjectFileELFTest, GetModuleSpecifications_OffsetSizeWithOffsetFile) {
+  std::string SO = GetInputFilePath("offset-test.bin");
+  ModuleSpecList Specs;
+  ASSERT_EQ(
+  1u, ObjectFile::GetModuleSpecifications(FileSpec(SO), 1024, 3600, Specs));
+  ModuleSpec Spec;
+  ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ;
+  UUID Uuid;
+  Uuid.SetFromStringRef("7D6E4738");
+  EXPECT_EQ(Spec.GetUUID(), Uuid);
+  EXPECT_EQ(Spec.GetObjectOffset(), 1024UL);
+  EXPECT_EQ(Spec.GetObjectSize(), 3600UL);
+  EXPECT_EQ(FileSystem::Instance().GetByteSize(FileSpec(SO)), 4640UL);
+}
+
 TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
   /*
   // nosym-entrypoint-arm-thumb.s
Index: lldb/unittests/ObjectFile/ELF/CMakeLists.txt

[Lldb-commits] [PATCH] D152861: Clear non-addressable bits from fp/sp/lr/pc values in RegisterContextUnwind

2023-06-14 Thread Jason Molenda via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0ce7037b5edd: Clear non-addressable bits from pc/fp/sp in 
unwinds (authored by jasonmolenda).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152861

Files:
  lldb/source/Target/RegisterContextUnwind.cpp

Index: lldb/source/Target/RegisterContextUnwind.cpp
===
--- lldb/source/Target/RegisterContextUnwind.cpp
+++ lldb/source/Target/RegisterContextUnwind.cpp
@@ -137,9 +137,8 @@
   // (which would be a no-op in frame 0 where we get it from the register set,
   // but still a good idea to make the call here for other ABIs that may
   // exist.)
-  ABI *abi = process->GetABI().get();
-  if (abi)
-current_pc = abi->FixCodeAddress(current_pc);
+  if (ABISP abi_sp = process->GetABI())
+current_pc = abi_sp->FixCodeAddress(current_pc);
 
   UnwindPlanSP lang_runtime_plan_sp = LanguageRuntime::GetRuntimeUnwindPlan(
   m_thread, this, m_behaves_like_zeroth_frame);
@@ -355,17 +354,23 @@
 
   // Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
   // this will strip bit zero in case we read a PC from memory or from the LR.
-  ABI *abi = process->GetABI().get();
-  if (abi)
-pc = abi->FixCodeAddress(pc);
+  ABISP abi_sp = process->GetABI();
+  if (abi_sp)
+pc = abi_sp->FixCodeAddress(pc);
 
   if (log) {
 UnwindLogMsg("pc = 0x%" PRIx64, pc);
 addr_t reg_val;
-if (ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FP, reg_val))
+if (ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FP, reg_val)) {
+  if (abi_sp)
+reg_val = abi_sp->FixDataAddress(reg_val);
   UnwindLogMsg("fp = 0x%" PRIx64, reg_val);
-if (ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, reg_val))
+}
+if (ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, reg_val)) {
+  if (abi_sp)
+reg_val = abi_sp->FixDataAddress(reg_val);
   UnwindLogMsg("sp = 0x%" PRIx64, reg_val);
+}
   }
 
   // A pc of 0x0 means it's the end of the stack crawl unless we're above a trap
@@ -424,11 +429,11 @@
   }
 }
 
-if (abi) {
+if (abi_sp) {
   m_fast_unwind_plan_sp.reset();
   m_full_unwind_plan_sp =
   std::make_shared(lldb::eRegisterKindGeneric);
-  abi->CreateDefaultUnwindPlan(*m_full_unwind_plan_sp);
+  abi_sp->CreateDefaultUnwindPlan(*m_full_unwind_plan_sp);
   if (m_frame_type != eSkipFrame) // don't override eSkipFrame
   {
 m_frame_type = eNormalFrame;
@@ -1751,8 +1756,8 @@
   if (ReadRegisterValueFromRegisterLocation(regloc, reg_info, reg_value)) {
 old_caller_pc_value = reg_value.GetAsUInt64();
 if (ProcessSP process_sp = m_thread.GetProcess()) {
-  if (ABISP abi = process_sp->GetABI())
-old_caller_pc_value = abi->FixCodeAddress(old_caller_pc_value);
+  if (ABISP abi_sp = process_sp->GetABI())
+old_caller_pc_value = abi_sp->FixCodeAddress(old_caller_pc_value);
 }
   }
 }
@@ -1811,8 +1816,8 @@
   reg_value)) {
   new_caller_pc_value = reg_value.GetAsUInt64();
   if (ProcessSP process_sp = m_thread.GetProcess()) {
-if (ABISP abi = process_sp->GetABI())
-  new_caller_pc_value = abi->FixCodeAddress(new_caller_pc_value);
+if (ABISP abi_sp = process_sp->GetABI())
+  new_caller_pc_value = abi_sp->FixCodeAddress(new_caller_pc_value);
   }
 }
   }
@@ -1953,6 +1958,7 @@
 
   address = LLDB_INVALID_ADDRESS;
   addr_t cfa_reg_contents;
+  ABISP abi_sp = m_thread.GetProcess()->GetABI();
 
   switch (fa.GetValueType()) {
   case UnwindPlan::Row::FAValue::isRegisterDereferenced: {
@@ -1963,11 +1969,13 @@
   GetRegisterInfoAtIndex(cfa_reg.GetAsKind(eRegisterKindLLDB));
   RegisterValue reg_value;
   if (reg_info) {
+if (abi_sp)
+  cfa_reg_contents = abi_sp->FixDataAddress(cfa_reg_contents);
 Status error = ReadRegisterValueFromMemory(
 reg_info, cfa_reg_contents, reg_info->byte_size, reg_value);
 if (error.Success()) {
   address = reg_value.GetAsUInt64();
-  if (ABISP abi_sp = m_thread.GetProcess()->GetABI())
+  if (abi_sp)
 address = abi_sp->FixCodeAddress(address);
   UnwindLogMsg(
   "CFA value via dereferencing reg %s (%d): reg has val 0x%" PRIx64
@@ -1989,6 +1997,8 @@
 RegisterNumber cfa_reg(m_thread, row_register_kind,
fa.GetRegisterNumber());
 if (ReadGPRValue(cfa_reg, cfa_reg_contents)) {
+  if (abi_sp)
+cfa_reg_contents = abi_sp->FixDataAddress(cfa_reg_contents);
   if (cfa_reg_contents == LLDB_INVALID_ADDRESS || cfa_reg_contents == 0 ||
   cfa_reg_contents == 1) {
 

[Lldb-commits] [PATCH] D152863: [lldb] NFC Add Process methods to Fix.*Address, to simplify this bit clearing across the codebase

2023-06-14 Thread Jason Molenda via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG90d9f88f19a1: Add Fix*Address methods to Process, call into 
ABI (authored by jasonmolenda).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152863

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
@@ -5688,6 +5688,24 @@
   return GetDataAddressMask();
 }
 
+addr_t Process::FixCodeAddress(addr_t addr) {
+  if (ABISP abi_sp = GetABI())
+addr = abi_sp->FixCodeAddress(addr);
+  return addr;
+}
+
+addr_t Process::FixDataAddress(addr_t addr) {
+  if (ABISP abi_sp = GetABI())
+addr = abi_sp->FixDataAddress(addr);
+  return addr;
+}
+
+addr_t Process::FixAnyAddress(addr_t addr) {
+  if (ABISP abi_sp = GetABI())
+addr = abi_sp->FixAnyAddress(addr);
+  return addr;
+}
+
 void Process::DidExec() {
   Log *log = GetLog(LLDBLog::Process);
   LLDB_LOGF(log, "Process::%s()", __FUNCTION__);
Index: lldb/include/lldb/Target/Process.h
===
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -1392,6 +1392,22 @@
 m_highmem_data_address_mask = data_address_mask;
   }
 
+  /// Some targets might use bits in a code address to indicate a mode switch,
+  /// ARM uses bit zero to signify a code address is thumb, so any ARM ABI
+  /// plug-ins would strip those bits.
+  /// Or use the high bits to authenticate a pointer value.
+  lldb::addr_t FixCodeAddress(lldb::addr_t pc);
+  lldb::addr_t FixDataAddress(lldb::addr_t pc);
+
+  /// Use this method when you do not know, or do not care what kind of address
+  /// you are fixing. On platforms where there would be a difference between 
the
+  /// two types, it will pick the safest option.
+  ///
+  /// Its purpose is to signal that no specific choice was made and provide an
+  /// alternative to randomly picking FixCode/FixData address. Which could 
break
+  /// platforms where there is a difference (only Arm Thumb at this time).
+  lldb::addr_t FixAnyAddress(lldb::addr_t pc);
+
   /// Get the Modification ID of the process.
   ///
   /// \return


Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -5688,6 +5688,24 @@
   return GetDataAddressMask();
 }
 
+addr_t Process::FixCodeAddress(addr_t addr) {
+  if (ABISP abi_sp = GetABI())
+addr = abi_sp->FixCodeAddress(addr);
+  return addr;
+}
+
+addr_t Process::FixDataAddress(addr_t addr) {
+  if (ABISP abi_sp = GetABI())
+addr = abi_sp->FixDataAddress(addr);
+  return addr;
+}
+
+addr_t Process::FixAnyAddress(addr_t addr) {
+  if (ABISP abi_sp = GetABI())
+addr = abi_sp->FixAnyAddress(addr);
+  return addr;
+}
+
 void Process::DidExec() {
   Log *log = GetLog(LLDBLog::Process);
   LLDB_LOGF(log, "Process::%s()", __FUNCTION__);
Index: lldb/include/lldb/Target/Process.h
===
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -1392,6 +1392,22 @@
 m_highmem_data_address_mask = data_address_mask;
   }
 
+  /// Some targets might use bits in a code address to indicate a mode switch,
+  /// ARM uses bit zero to signify a code address is thumb, so any ARM ABI
+  /// plug-ins would strip those bits.
+  /// Or use the high bits to authenticate a pointer value.
+  lldb::addr_t FixCodeAddress(lldb::addr_t pc);
+  lldb::addr_t FixDataAddress(lldb::addr_t pc);
+
+  /// Use this method when you do not know, or do not care what kind of address
+  /// you are fixing. On platforms where there would be a difference between the
+  /// two types, it will pick the safest option.
+  ///
+  /// Its purpose is to signal that no specific choice was made and provide an
+  /// alternative to randomly picking FixCode/FixData address. Which could break
+  /// platforms where there is a difference (only Arm Thumb at this time).
+  lldb::addr_t FixAnyAddress(lldb::addr_t pc);
+
   /// Get the Modification ID of the process.
   ///
   /// \return
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 0ce7037 - Clear non-addressable bits from pc/fp/sp in unwinds

2023-06-14 Thread Jason Molenda via lldb-commits

Author: Jason Molenda
Date: 2023-06-14T13:49:26-07:00
New Revision: 0ce7037b5edd0f1937c9d9572ab12528d26091ed

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

LOG: Clear non-addressable bits from pc/fp/sp in unwinds

Some Darwin corefiles can have the pc/fp/sp/lr in the
live register context signed with pointer authentication;
this patch changes RegisterContextUnwind to strip those
bits off of those values as we try to walk the stack.

Differential Revision: https://reviews.llvm.org/D152861
rdar://109185291

Added: 


Modified: 
lldb/source/Target/RegisterContextUnwind.cpp

Removed: 




diff  --git a/lldb/source/Target/RegisterContextUnwind.cpp 
b/lldb/source/Target/RegisterContextUnwind.cpp
index bf31ebbd858ae..242c7d3f6b945 100644
--- a/lldb/source/Target/RegisterContextUnwind.cpp
+++ b/lldb/source/Target/RegisterContextUnwind.cpp
@@ -137,9 +137,8 @@ void RegisterContextUnwind::InitializeZerothFrame() {
   // (which would be a no-op in frame 0 where we get it from the register set,
   // but still a good idea to make the call here for other ABIs that may
   // exist.)
-  ABI *abi = process->GetABI().get();
-  if (abi)
-current_pc = abi->FixCodeAddress(current_pc);
+  if (ABISP abi_sp = process->GetABI())
+current_pc = abi_sp->FixCodeAddress(current_pc);
 
   UnwindPlanSP lang_runtime_plan_sp = LanguageRuntime::GetRuntimeUnwindPlan(
   m_thread, this, m_behaves_like_zeroth_frame);
@@ -355,17 +354,23 @@ void RegisterContextUnwind::InitializeNonZerothFrame() {
 
   // Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
   // this will strip bit zero in case we read a PC from memory or from the LR.
-  ABI *abi = process->GetABI().get();
-  if (abi)
-pc = abi->FixCodeAddress(pc);
+  ABISP abi_sp = process->GetABI();
+  if (abi_sp)
+pc = abi_sp->FixCodeAddress(pc);
 
   if (log) {
 UnwindLogMsg("pc = 0x%" PRIx64, pc);
 addr_t reg_val;
-if (ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FP, reg_val))
+if (ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FP, reg_val)) {
+  if (abi_sp)
+reg_val = abi_sp->FixDataAddress(reg_val);
   UnwindLogMsg("fp = 0x%" PRIx64, reg_val);
-if (ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, reg_val))
+}
+if (ReadGPRValue(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, reg_val)) {
+  if (abi_sp)
+reg_val = abi_sp->FixDataAddress(reg_val);
   UnwindLogMsg("sp = 0x%" PRIx64, reg_val);
+}
   }
 
   // A pc of 0x0 means it's the end of the stack crawl unless we're above a 
trap
@@ -424,11 +429,11 @@ void RegisterContextUnwind::InitializeNonZerothFrame() {
   }
 }
 
-if (abi) {
+if (abi_sp) {
   m_fast_unwind_plan_sp.reset();
   m_full_unwind_plan_sp =
   std::make_shared(lldb::eRegisterKindGeneric);
-  abi->CreateDefaultUnwindPlan(*m_full_unwind_plan_sp);
+  abi_sp->CreateDefaultUnwindPlan(*m_full_unwind_plan_sp);
   if (m_frame_type != eSkipFrame) // don't override eSkipFrame
   {
 m_frame_type = eNormalFrame;
@@ -1751,8 +1756,8 @@ bool RegisterContextUnwind::TryFallbackUnwindPlan() {
   if (ReadRegisterValueFromRegisterLocation(regloc, reg_info, reg_value)) {
 old_caller_pc_value = reg_value.GetAsUInt64();
 if (ProcessSP process_sp = m_thread.GetProcess()) {
-  if (ABISP abi = process_sp->GetABI())
-old_caller_pc_value = abi->FixCodeAddress(old_caller_pc_value);
+  if (ABISP abi_sp = process_sp->GetABI())
+old_caller_pc_value = abi_sp->FixCodeAddress(old_caller_pc_value);
 }
   }
 }
@@ -1811,8 +1816,8 @@ bool RegisterContextUnwind::TryFallbackUnwindPlan() {
   reg_value)) {
   new_caller_pc_value = reg_value.GetAsUInt64();
   if (ProcessSP process_sp = m_thread.GetProcess()) {
-if (ABISP abi = process_sp->GetABI())
-  new_caller_pc_value = abi->FixCodeAddress(new_caller_pc_value);
+if (ABISP abi_sp = process_sp->GetABI())
+  new_caller_pc_value = 
abi_sp->FixCodeAddress(new_caller_pc_value);
   }
 }
   }
@@ -1953,6 +1958,7 @@ bool RegisterContextUnwind::ReadFrameAddress(
 
   address = LLDB_INVALID_ADDRESS;
   addr_t cfa_reg_contents;
+  ABISP abi_sp = m_thread.GetProcess()->GetABI();
 
   switch (fa.GetValueType()) {
   case UnwindPlan::Row::FAValue::isRegisterDereferenced: {
@@ -1963,11 +1969,13 @@ bool RegisterContextUnwind::ReadFrameAddress(
   GetRegisterInfoAtIndex(cfa_reg.GetAsKind(eRegisterKindLLDB));
   RegisterValue reg_value;
   if (reg_info) {
+if (abi_sp)
+  cfa_reg_contents = abi_sp->FixDataAddress(cfa_reg_contents);
   

[Lldb-commits] [lldb] 90d9f88 - Add Fix*Address methods to Process, call into ABI

2023-06-14 Thread Jason Molenda via lldb-commits

Author: Jason Molenda
Date: 2023-06-14T13:49:26-07:00
New Revision: 90d9f88f19a128a6bacd7c8db594feb96047cded

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

LOG: Add Fix*Address methods to Process, call into ABI

We need to clear non-addressable bits from addresses across
the lldb sources.  Currently these need to use an ABI method
to clear those bits from addresses, which you do by taking a
Process, getting the current ABI, then calling the method.

Simplify this by providing methods in Process which call into
the ABI methods themselves.

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

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 b27fd212ad1f9..3b9de13206ac8 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1392,6 +1392,22 @@ class Process : public 
std::enable_shared_from_this,
 m_highmem_data_address_mask = data_address_mask;
   }
 
+  /// Some targets might use bits in a code address to indicate a mode switch,
+  /// ARM uses bit zero to signify a code address is thumb, so any ARM ABI
+  /// plug-ins would strip those bits.
+  /// Or use the high bits to authenticate a pointer value.
+  lldb::addr_t FixCodeAddress(lldb::addr_t pc);
+  lldb::addr_t FixDataAddress(lldb::addr_t pc);
+
+  /// Use this method when you do not know, or do not care what kind of address
+  /// you are fixing. On platforms where there would be a 
diff erence between the
+  /// two types, it will pick the safest option.
+  ///
+  /// Its purpose is to signal that no specific choice was made and provide an
+  /// alternative to randomly picking FixCode/FixData address. Which could 
break
+  /// platforms where there is a 
diff erence (only Arm Thumb at this time).
+  lldb::addr_t FixAnyAddress(lldb::addr_t pc);
+
   /// Get the Modification ID of the process.
   ///
   /// \return

diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 3dd807aa83632..9730d7217eda3 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -5688,6 +5688,24 @@ lldb::addr_t Process::GetHighmemDataAddressMask() {
   return GetDataAddressMask();
 }
 
+addr_t Process::FixCodeAddress(addr_t addr) {
+  if (ABISP abi_sp = GetABI())
+addr = abi_sp->FixCodeAddress(addr);
+  return addr;
+}
+
+addr_t Process::FixDataAddress(addr_t addr) {
+  if (ABISP abi_sp = GetABI())
+addr = abi_sp->FixDataAddress(addr);
+  return addr;
+}
+
+addr_t Process::FixAnyAddress(addr_t addr) {
+  if (ABISP abi_sp = GetABI())
+addr = abi_sp->FixAnyAddress(addr);
+  return addr;
+}
+
 void Process::DidExec() {
   Log *log = GetLog(LLDBLog::Process);
   LLDB_LOGF(log, "Process::%s()", __FUNCTION__);



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


[Lldb-commits] [PATCH] D152916: [lldb] Add "register info" command

2023-06-14 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda accepted this revision.
jasonmolenda added a comment.
This revision is now accepted and ready to land.

Looks good!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152916

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


[Lldb-commits] [PATCH] D152918: [lldb] Add register field tables to the "register info" command

2023-06-14 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda accepted this revision.
jasonmolenda added a comment.
This revision is now accepted and ready to land.

LGTM.  Putting this in `register info` is good, it's not too easily 
discoverable (to be honest I didn't know this command existed today), but as 
you say, the number of people who want to see this are relatively small so 
putting it in a more mainstream command like register read may not be the best 
choice.  We can start with only in `register info`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152918

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


[Lldb-commits] [PATCH] D152917: [LLDB] Add table formatting for register fields

2023-06-14 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda accepted this revision.
jasonmolenda added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: lldb/include/lldb/Target/RegisterFlags.h:96
 
+  /// Produce a text table showing the layout of all the fields. Unamed/padding
+  /// fields will be included, with only their positions shown.

"Unnamed"



Comment at: lldb/source/Target/RegisterFlags.cpp:149
+// column, just let it overflow and we'll wrap next time around. There's 
not
+// mich we can do with a very small terminal.
+if (current_width && ((current_width + column_width + 1) >= max_width)) {

"much"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152917

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


[Lldb-commits] [PATCH] D152712: [lldb][Android] Use a lambda for calls to ::open in RetryAfterSignal

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531483.
splhack added a comment.

Replace `llvm::sys::RetryAfterSignal(-1, ::open)` with
`FileSystem::Instance().Open`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152712

Files:
  lldb/include/lldb/Host/FileSystem.h
  lldb/source/Host/common/PseudoTerminal.cpp
  lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
  lldb/source/Host/posix/FileSystemPosix.cpp
  lldb/source/Host/posix/PipePosix.cpp
  lldb/source/Host/posix/ProcessLauncherPosixFork.cpp

Index: lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
===
--- lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
+++ lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostProcess.h"
 #include "lldb/Host/Pipe.h"
@@ -14,7 +15,6 @@
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/Log.h"
 #include "llvm/Support/Errno.h"
-#include "llvm/Support/FileSystem.h"
 
 #include 
 #include 
@@ -71,7 +71,7 @@
 }
 
 static void DupDescriptor(int error_fd, const char *file, int fd, int flags) {
-  int target_fd = llvm::sys::RetryAfterSignal(-1, ::open, file, flags, 0666);
+  int target_fd = FileSystem::Instance().Open(file, flags, 0666);
 
   if (target_fd == -1)
 ExitWithError(error_fd, "DupDescriptor-open");
Index: lldb/source/Host/posix/PipePosix.cpp
===
--- lldb/source/Host/posix/PipePosix.cpp
+++ lldb/source/Host/posix/PipePosix.cpp
@@ -7,11 +7,11 @@
 //===--===//
 
 #include "lldb/Host/posix/PipePosix.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Utility/SelectHelper.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Errno.h"
-#include "llvm/Support/FileSystem.h"
 #include 
 #include 
 
@@ -148,7 +148,7 @@
 flags |= O_CLOEXEC;
 
   Status error;
-  int fd = llvm::sys::RetryAfterSignal(-1, ::open, name.str().c_str(), flags);
+  int fd = FileSystem::Instance().Open(name.str().c_str(), flags);
   if (fd != -1)
 m_fds[READ] = fd;
   else
Index: lldb/source/Host/posix/FileSystemPosix.cpp
===
--- lldb/source/Host/posix/FileSystemPosix.cpp
+++ lldb/source/Host/posix/FileSystemPosix.cpp
@@ -77,5 +77,8 @@
 }
 
 int FileSystem::Open(const char *path, int flags, int mode) {
-  return llvm::sys::RetryAfterSignal(-1, ::open, path, flags, mode);
+  // Call ::open in a lambda to avoid overload resolution in RetryAfterSignal
+  // when open is overloaded, such as in Bionic.
+  auto lambda = [&]() { return ::open(path, flags, mode); };
+  return llvm::sys::RetryAfterSignal(-1, lambda);
 }
Index: lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
===
--- lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
+++ lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
@@ -15,6 +15,7 @@
 
 #include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
 #include "lldb/Host/Config.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Socket.h"
 #include "lldb/Host/SocketAddress.h"
 #include "lldb/Utility/LLDBLog.h"
@@ -726,7 +727,7 @@
 #if LLDB_ENABLE_POSIX
   std::string addr_str = s.str();
   // file:///PATH
-  int fd = llvm::sys::RetryAfterSignal(-1, ::open, addr_str.c_str(), O_RDWR);
+  int fd = FileSystem::Instance().Open(addr_str.c_str(), O_RDWR);
   if (fd == -1) {
 if (error_ptr)
   error_ptr->SetErrorToErrno();
@@ -776,7 +777,7 @@
 return eConnectionStatusError;
   }
 
-  int fd = llvm::sys::RetryAfterSignal(-1, ::open, path.str().c_str(), O_RDWR);
+  int fd = FileSystem::Instance().Open(path.str().c_str(), O_RDWR);
   if (fd == -1) {
 if (error_ptr)
   error_ptr->SetErrorToErrno();
Index: lldb/source/Host/common/PseudoTerminal.cpp
===
--- lldb/source/Host/common/PseudoTerminal.cpp
+++ lldb/source/Host/common/PseudoTerminal.cpp
@@ -8,6 +8,7 @@
 
 #include "lldb/Host/PseudoTerminal.h"
 #include "lldb/Host/Config.h"
+#include "lldb/Host/FileSystem.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Errno.h"
 #include 
@@ -95,7 +96,7 @@
   CloseSecondaryFileDescriptor();
 
   std::string name = GetSecondaryName();
-  m_secondary_fd = llvm::sys::RetryAfterSignal(-1, ::open, name.c_str(), oflag);
+  m_secondary_fd = FileSystem::Instance().Open(name.c_str(), oflag);
   if (m_secondary_fd >= 0)
 return llvm::Error::success();
 
Index: lldb/include/lldb/Host/FileSystem.h

[Lldb-commits] [PATCH] D152861: Clear non-addressable bits from fp/sp/lr/pc values in RegisterContextUnwind

2023-06-14 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added a comment.

In D152861#4420223 , @DavidSpickett 
wrote:

> I'm curious how you would end up with a signed PC value, but given this is 
> unwind it could be a value from a previous frame that was signed when stored 
> to the stack.

The darwin kernel signs sp/pc (and maybe fp too) when they're at rest inside 
the kernel, I think.  When we fetch the values for these with thread_get_state, 
they need to be run through and auth-and-clear before the values are sent to 
lldb (in debugserver aka lldb-server).   gcore isn't stripping the auth bits 
when it fetches the register contexts from the kernel, and is putting those 
values as-is in corefiles.

You're right that this shouldn't happen in a real process.  We already strip 
auth bits from $lr and spilled $lr's on the stack, where the code actually does 
sign it.  This is purely addressing an artifact of how the darwin kernel 
represents these internally.  gcore should really be clearing the auth bits 
from these register before putting them in a core file, but we need to work on 
core files that have already been created like this, so I'm starting with an 
lldb patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152861

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


[Lldb-commits] [PATCH] D152712: [lldb][Android] Use a lambda for calls to ::open in RetryAfterSignal

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack added a comment.

oh wait, `FileSystem::Open` is already `RetryAfterSignal::Open` in this diff.
will replace `RetryAfterSignal::Open` with `FileSystem::Open`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152712

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


[Lldb-commits] [PATCH] D152712: [lldb][Android] Use a lambda for calls to ::open in RetryAfterSignal

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack added a comment.

@JDevlieghere does `FileSystem::RetryAfterSignal::Open` sound good to you?
Or `FileSystem::RetryAfterSignalOpen`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152712

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


[Lldb-commits] [PATCH] D152712: [lldb][Android] Use a lambda for calls to ::open in RetryAfterSignal

2023-06-14 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere requested changes to this revision.
JDevlieghere added a comment.
This revision now requires changes to proceed.

Should we make this the default behavior in `FileSystem`? Either way I think 
this belongs there rather than in Host.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152712

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


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

2023-06-14 Thread Kazu Hirata via lldb-commits

Author: Kazu Hirata
Date: 2023-06-14T10:56:22-07:00
New Revision: 7d21f5714e5a040f121fa08648c748073467db82

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

LOG: [lldb] Fix a warning

This patch fixes:

  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4843:13:
  error: 225 enumeration values not handled in switch: 'RvvInt8mf8x2',
  'RvvInt8mf8x3', 'RvvInt8mf8x4'... [-Werror,-Wswitch]

Added: 


Modified: 
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 




diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 6506f118f8c65..15c9729c22cfb 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -5107,7 +5107,232 @@ lldb::Encoding 
TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,
 case clang::BuiltinType::RvvBool16:
 case clang::BuiltinType::RvvBool32:
 case clang::BuiltinType::RvvBool64:
+case clang::BuiltinType::RvvInt8mf8x2:
+case clang::BuiltinType::RvvInt8mf8x3:
+case clang::BuiltinType::RvvInt8mf8x4:
+case clang::BuiltinType::RvvInt8mf8x5:
+case clang::BuiltinType::RvvInt8mf8x6:
+case clang::BuiltinType::RvvInt8mf8x7:
+case clang::BuiltinType::RvvInt8mf8x8:
+case clang::BuiltinType::RvvInt8mf4x2:
+case clang::BuiltinType::RvvInt8mf4x3:
+case clang::BuiltinType::RvvInt8mf4x4:
+case clang::BuiltinType::RvvInt8mf4x5:
+case clang::BuiltinType::RvvInt8mf4x6:
+case clang::BuiltinType::RvvInt8mf4x7:
+case clang::BuiltinType::RvvInt8mf4x8:
+case clang::BuiltinType::RvvInt8mf2x2:
+case clang::BuiltinType::RvvInt8mf2x3:
+case clang::BuiltinType::RvvInt8mf2x4:
+case clang::BuiltinType::RvvInt8mf2x5:
+case clang::BuiltinType::RvvInt8mf2x6:
+case clang::BuiltinType::RvvInt8mf2x7:
+case clang::BuiltinType::RvvInt8mf2x8:
+case clang::BuiltinType::RvvInt8m1x2:
+case clang::BuiltinType::RvvInt8m1x3:
+case clang::BuiltinType::RvvInt8m1x4:
+case clang::BuiltinType::RvvInt8m1x5:
+case clang::BuiltinType::RvvInt8m1x6:
+case clang::BuiltinType::RvvInt8m1x7:
+case clang::BuiltinType::RvvInt8m1x8:
+case clang::BuiltinType::RvvInt8m2x2:
+case clang::BuiltinType::RvvInt8m2x3:
+case clang::BuiltinType::RvvInt8m2x4:
+case clang::BuiltinType::RvvInt8m4x2:
+case clang::BuiltinType::RvvUint8mf8x2:
+case clang::BuiltinType::RvvUint8mf8x3:
+case clang::BuiltinType::RvvUint8mf8x4:
+case clang::BuiltinType::RvvUint8mf8x5:
+case clang::BuiltinType::RvvUint8mf8x6:
+case clang::BuiltinType::RvvUint8mf8x7:
+case clang::BuiltinType::RvvUint8mf8x8:
+case clang::BuiltinType::RvvUint8mf4x2:
+case clang::BuiltinType::RvvUint8mf4x3:
+case clang::BuiltinType::RvvUint8mf4x4:
+case clang::BuiltinType::RvvUint8mf4x5:
+case clang::BuiltinType::RvvUint8mf4x6:
+case clang::BuiltinType::RvvUint8mf4x7:
+case clang::BuiltinType::RvvUint8mf4x8:
+case clang::BuiltinType::RvvUint8mf2x2:
+case clang::BuiltinType::RvvUint8mf2x3:
+case clang::BuiltinType::RvvUint8mf2x4:
+case clang::BuiltinType::RvvUint8mf2x5:
+case clang::BuiltinType::RvvUint8mf2x6:
+case clang::BuiltinType::RvvUint8mf2x7:
+case clang::BuiltinType::RvvUint8mf2x8:
+case clang::BuiltinType::RvvUint8m1x2:
+case clang::BuiltinType::RvvUint8m1x3:
+case clang::BuiltinType::RvvUint8m1x4:
+case clang::BuiltinType::RvvUint8m1x5:
+case clang::BuiltinType::RvvUint8m1x6:
+case clang::BuiltinType::RvvUint8m1x7:
+case clang::BuiltinType::RvvUint8m1x8:
+case clang::BuiltinType::RvvUint8m2x2:
+case clang::BuiltinType::RvvUint8m2x3:
+case clang::BuiltinType::RvvUint8m2x4:
+case clang::BuiltinType::RvvUint8m4x2:
+case clang::BuiltinType::RvvInt16mf4x2:
+case clang::BuiltinType::RvvInt16mf4x3:
+case clang::BuiltinType::RvvInt16mf4x4:
+case clang::BuiltinType::RvvInt16mf4x5:
+case clang::BuiltinType::RvvInt16mf4x6:
+case clang::BuiltinType::RvvInt16mf4x7:
+case clang::BuiltinType::RvvInt16mf4x8:
+case clang::BuiltinType::RvvInt16mf2x2:
+case clang::BuiltinType::RvvInt16mf2x3:
+case clang::BuiltinType::RvvInt16mf2x4:
+case clang::BuiltinType::RvvInt16mf2x5:
+case clang::BuiltinType::RvvInt16mf2x6:
+case clang::BuiltinType::RvvInt16mf2x7:
+case clang::BuiltinType::RvvInt16mf2x8:
+case clang::BuiltinType::RvvInt16m1x2:
+case clang::BuiltinType::RvvInt16m1x3:
+case clang::BuiltinType::RvvInt16m1x4:
+case clang::BuiltinType::RvvInt16m1x5:
+case clang::BuiltinType::RvvInt16m1x6:
+case clang::BuiltinType::RvvInt16m1x7:
+case 

[Lldb-commits] [PATCH] D152886: [lldb] Make it easier to spot if sources were resolved in crashlog output

2023-06-14 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added inline comments.



Comment at: lldb/examples/python/crashlog.py:344
+)
+if os.path.exists(source_path):
+self.resolved_source = True

JDevlieghere wrote:
> mib wrote:
> > I guess that checks that the user have access to the remapped path, is that 
> > right ?
> > 
> > If that's not the case, I think we should let the user know
> Yeah, that's exactly right. We do let the user know by including or emitting 
> "and sources" in the symbol resolution print. Currently we print the "and 
> sources" when at least one of the remapped paths is accessible. We could 
> change this to only print it when all the paths are accessible. We could also 
> change the message the say "and could not find sources" when a path remapping 
> is present but the paths are not accessible. 
It think it would be clearer for the user if we said something like "couldn't 
access remapped source path (path/to/source)"


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

https://reviews.llvm.org/D152886

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


[Lldb-commits] [PATCH] D152846: [lldb][NFCI] Remove custom matcher classes in Listener in favor of lambdas

2023-06-14 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 531407.
bulbazord added a comment.

Use STLExtras where appropriate


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152846

Files:
  lldb/source/Utility/Listener.cpp

Index: lldb/source/Utility/Listener.cpp
===
--- lldb/source/Utility/Listener.cpp
+++ lldb/source/Utility/Listener.cpp
@@ -18,20 +18,6 @@
 using namespace lldb;
 using namespace lldb_private;
 
-namespace {
-class BroadcasterManagerWPMatcher {
-public:
-  BroadcasterManagerWPMatcher(BroadcasterManagerSP manager_sp)
-  : m_manager_sp(std::move(manager_sp)) {}
-  bool operator()(const BroadcasterManagerWP _wp) const {
-BroadcasterManagerSP input_sp = input_wp.lock();
-return (input_sp && input_sp == m_manager_sp);
-  }
-
-  BroadcasterManagerSP m_manager_sp;
-};
-} // anonymous namespace
-
 Listener::Listener(const char *name)
 : m_name(name), m_broadcasters(), m_broadcasters_mutex(), m_events(),
   m_events_mutex(), m_is_shadow() {
@@ -181,17 +167,12 @@
 }
 
 void Listener::BroadcasterManagerWillDestruct(BroadcasterManagerSP manager_sp) {
-  // Just need to remove this broadcast manager from the list of managers:
-  broadcaster_manager_collection::iterator iter,
-  end_iter = m_broadcaster_managers.end();
-  BroadcasterManagerWP manager_wp;
-
-  BroadcasterManagerWPMatcher matcher(std::move(manager_sp));
-  iter = std::find_if(
-  m_broadcaster_managers.begin(), end_iter, matcher);
-  if (iter != end_iter)
-m_broadcaster_managers.erase(iter);
+  const auto manager_matcher =
+  [_sp](const BroadcasterManagerWP _wp) -> bool {
+BroadcasterManagerSP input_sp = input_wp.lock();
+return (input_sp && input_sp == manager_sp);
+  };
+  llvm::erase_if(m_broadcaster_managers, manager_matcher);
 }
 
 void Listener::AddEvent(EventSP _sp) {
@@ -206,36 +187,6 @@
   m_events_condition.notify_all();
 }
 
-class EventBroadcasterMatches {
-public:
-  EventBroadcasterMatches(Broadcaster *broadcaster)
-  : m_broadcaster(broadcaster) {}
-
-  bool operator()(const EventSP _sp) const {
-return event_sp->BroadcasterIs(m_broadcaster);
-  }
-
-private:
-  Broadcaster *m_broadcaster;
-};
-
-class EventMatcher {
-public:
-  EventMatcher(Broadcaster *broadcaster, uint32_t event_type_mask)
-  : m_broadcaster(broadcaster), m_event_type_mask(event_type_mask) {}
-
-  bool operator()(const EventSP _sp) const {
-if (m_broadcaster && !event_sp->BroadcasterIs(m_broadcaster))
-  return false;
-
-return m_event_type_mask == 0 || m_event_type_mask & event_sp->GetType();
-  }
-
-private:
-  Broadcaster *m_broadcaster;
-  const uint32_t m_event_type_mask;
-};
-
 bool Listener::FindNextEventInternal(
 std::unique_lock ,
 Broadcaster *broadcaster, // nullptr for any broadcaster
@@ -249,14 +200,18 @@
   if (m_events.empty())
 return false;
 
+  const auto event_matcher =
+  [broadcaster, event_type_mask](const EventSP _sp) -> bool {
+if (broadcaster && !event_sp->BroadcasterIs(broadcaster))
+  return false;
+return event_type_mask == 0 || event_type_mask & event_sp->GetType();
+  };
   Listener::event_collection::iterator pos = m_events.end();
 
-  if (broadcaster == nullptr && event_type_mask == 0) {
+  if (broadcaster == nullptr && event_type_mask == 0)
 pos = m_events.begin();
-  } else {
-pos = std::find_if(m_events.begin(), m_events.end(),
-   EventMatcher(broadcaster, event_type_mask));
-  }
+  else
+pos = llvm::find_if(m_events, event_matcher);
 
   if (pos != m_events.end()) {
 event_sp = *pos;
@@ -395,6 +350,11 @@
   if (!manager_sp)
 return 0;
 
+  const auto manager_matcher =
+  [_sp](const BroadcasterManagerWP _wp) -> bool {
+BroadcasterManagerSP input_sp = input_wp.lock();
+return (input_sp && input_sp == manager_sp);
+  };
   // The BroadcasterManager mutex must be locked before m_broadcasters_mutex to
   // avoid violating the lock hierarchy (manager before broadcasters).
   std::lock_guard manager_guard(
@@ -404,14 +364,9 @@
   uint32_t bits_acquired = manager_sp->RegisterListenerForEvents(
   this->shared_from_this(), event_spec);
   if (bits_acquired) {
-broadcaster_manager_collection::iterator iter,
-end_iter = m_broadcaster_managers.end();
 BroadcasterManagerWP manager_wp(manager_sp);
-BroadcasterManagerWPMatcher matcher(manager_sp);
-iter = std::find_if(
-m_broadcaster_managers.begin(), end_iter, matcher);
-if (iter == end_iter)
+auto iter = llvm::find_if(m_broadcaster_managers, manager_matcher);
+if (iter == m_broadcaster_managers.end())
   m_broadcaster_managers.push_back(manager_wp);
   }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D152331: [lldb][NFCI] Platforms should own their SDKBuild and SDKRootDirectory strings

2023-06-14 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf4be9ff6458f: [lldb][NFCI] Platforms should own their 
SDKBuild and SDKRootDirectory strings (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152331

Files:
  lldb/include/lldb/Interpreter/OptionGroupPlatform.h
  lldb/include/lldb/Target/Platform.h
  lldb/source/API/SBPlatform.cpp
  lldb/source/Interpreter/OptionGroupPlatform.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
  lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
  lldb/source/Target/Platform.cpp

Index: lldb/source/Target/Platform.cpp
===
--- lldb/source/Target/Platform.cpp
+++ lldb/source/Target/Platform.cpp
@@ -210,11 +210,10 @@
 Status error(eErrorTypeGeneric);
 ModuleSpec resolved_spec;
 // Check if we have sysroot set.
-if (m_sdk_sysroot) {
+if (!m_sdk_sysroot.empty()) {
   // Prepend sysroot to module spec.
   resolved_spec = spec;
-  resolved_spec.GetFileSpec().PrependPathComponent(
-  m_sdk_sysroot.GetStringRef());
+  resolved_spec.GetFileSpec().PrependPathComponent(m_sdk_sysroot);
   // Try to get shared module with resolved spec.
   error = ModuleList::GetSharedModule(resolved_spec, module_sp,
   module_search_paths_ptr, old_modules,
@@ -312,9 +311,9 @@
 strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no");
   }
 
-  if (GetSDKRootDirectory()) {
-strm.Format("   Sysroot: {0}\n", GetSDKRootDirectory());
-  }
+  if (const std::string _root = GetSDKRootDirectory(); !sdk_root.empty())
+strm.Format("   Sysroot: {0}\n", sdk_root);
+
   if (GetWorkingDirectory()) {
 strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetPath().c_str());
   }
Index: lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
===
--- lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
+++ lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
@@ -191,8 +191,8 @@
   launch_info.SetArguments(args, true);
 
   Environment emulator_env = Host::GetEnvironment();
-  if (ConstString sysroot = GetSDKRootDirectory())
-emulator_env["QEMU_LD_PREFIX"] = sysroot.GetStringRef().str();
+  if (const std::string  = GetSDKRootDirectory(); !sysroot.empty())
+emulator_env["QEMU_LD_PREFIX"] = sysroot;
   for (const auto  : GetGlobalProperties().GetEmulatorEnvVars())
 emulator_env[KV.first()] = KV.second;
   launch_info.GetEnvironment() = ComputeLaunchEnvironment(
Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
===
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
@@ -34,8 +34,8 @@
   std::lock_guard guard(m_sdk_dir_mutex);
   if (m_sdk_directory_infos.empty()) {
 // A --sysroot option was supplied - add it to our list of SDKs to check
-if (m_sdk_sysroot) {
-  FileSpec sdk_sysroot_fspec(m_sdk_sysroot.GetCString());
+if (!m_sdk_sysroot.empty()) {
+  FileSpec sdk_sysroot_fspec(m_sdk_sysroot.c_str());
   FileSystem::Instance().Resolve(sdk_sysroot_fspec);
   const SDKDirectoryInfo sdk_sysroot_directory_info(sdk_sysroot_fspec);
   m_sdk_directory_infos.push_back(sdk_sysroot_directory_info);
@@ -43,7 +43,7 @@
 LLDB_LOGF(log,
   "PlatformDarwinDevice::UpdateSDKDirectoryInfosIfNeeded added "
   "--sysroot SDK directory %s",
-  m_sdk_sysroot.GetCString());
+  m_sdk_sysroot.c_str());
   }
   return true;
 }
@@ -152,20 +152,20 @@
 std::vector check_sdk_info(num_sdk_infos, true);
 
 // Prefer the user SDK build string.
-ConstString build = GetSDKBuild();
+std::string build = GetSDKBuild();
 
 // Fall back to the platform's build string.
-if (!build) {
-  if (std::optional os_build_str = GetOSBuildString()) {
-build = ConstString(*os_build_str);
-  }
+if (build.empty()) {
+  if (std::optional os_build_str = GetOSBuildString())
+build.assign(*os_build_str);
 }
 
 // If we have a build string, only check platforms for which the build
 // string matches.
-if (build) {
+if (!build.empty()) {
   for (i = 0; i < num_sdk_infos; ++i)
-check_sdk_info[i] = m_sdk_directory_infos[i].build == build;
+check_sdk_info[i] = m_sdk_directory_infos[i].build.GetStringRef() ==
+llvm::StringRef(build);
 }
 
 // If we are connected we can find the version of the OS the platform us
@@ -201,7 +201,7 @@
   }
 }
   }
-} else if (build) {
+} else if (!build.empty()) {
   // No version, just a build 

[Lldb-commits] [lldb] f4be9ff - [lldb][NFCI] Platforms should own their SDKBuild and SDKRootDirectory strings

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

Author: Alex Langford
Date: 2023-06-14T09:59:58-07:00
New Revision: f4be9ff6458fe6401acaf9239865e077141dd8bc

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

LOG: [lldb][NFCI] Platforms should own their SDKBuild and SDKRootDirectory 
strings

These don't need to be ConstStrings. They don't really benefit much from
deduplication and comparing them isn't on a hot path, so they don't
really benefit much from quick comparisons.

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

Added: 


Modified: 
lldb/include/lldb/Interpreter/OptionGroupPlatform.h
lldb/include/lldb/Target/Platform.h
lldb/source/API/SBPlatform.cpp
lldb/source/Interpreter/OptionGroupPlatform.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
lldb/source/Target/Platform.cpp

Removed: 




diff  --git a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h 
b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h
index fed2791a61309..2ffd44f0035de 100644
--- a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h
+++ b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h
@@ -47,22 +47,24 @@ class OptionGroupPlatform : public OptionGroup {
   m_platform_name.clear();
   }
 
-  ConstString GetSDKRootDirectory() const { return m_sdk_sysroot; }
+  const std::string () const { return m_sdk_sysroot; }
 
-  void SetSDKRootDirectory(ConstString sdk_root_directory) {
-m_sdk_sysroot = sdk_root_directory;
+  void SetSDKRootDirectory(std::string sdk_root_directory) {
+m_sdk_sysroot = std::move(sdk_root_directory);
   }
 
-  ConstString GetSDKBuild() const { return m_sdk_build; }
+  const std::string () const { return m_sdk_build; }
 
-  void SetSDKBuild(ConstString sdk_build) { m_sdk_build = sdk_build; }
+  void SetSDKBuild(std::string sdk_build) {
+m_sdk_build = std::move(sdk_build);
+  }
 
   bool PlatformMatches(const lldb::PlatformSP _sp) const;
 
 protected:
   std::string m_platform_name;
-  ConstString m_sdk_sysroot;
-  ConstString m_sdk_build;
+  std::string m_sdk_sysroot;
+  std::string m_sdk_build;
   llvm::VersionTuple m_os_version;
   bool m_include_platform_option;
 };

diff  --git a/lldb/include/lldb/Target/Platform.h 
b/lldb/include/lldb/Target/Platform.h
index 08e47cc132473..b556e1aa3dd2e 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -448,13 +448,15 @@ class Platform : public PluginInterface {
   // Used for column widths
   size_t GetMaxGroupIDNameLength() const { return m_max_gid_name_len; }
 
-  ConstString GetSDKRootDirectory() const { return m_sdk_sysroot; }
+  const std::string () const { return m_sdk_sysroot; }
 
-  void SetSDKRootDirectory(ConstString dir) { m_sdk_sysroot = dir; }
+  void SetSDKRootDirectory(std::string dir) { m_sdk_sysroot = std::move(dir); }
 
-  ConstString GetSDKBuild() const { return m_sdk_build; }
+  const std::string () const { return m_sdk_build; }
 
-  void SetSDKBuild(ConstString sdk_build) { m_sdk_build = sdk_build; }
+  void SetSDKBuild(std::string sdk_build) {
+m_sdk_build = std::move(sdk_build);
+  }
 
   // Override this to return true if your platform supports Clang modules. You
   // may also need to override AddClangModuleCompilationOptions to pass the
@@ -900,9 +902,9 @@ class Platform : public PluginInterface {
   // the once we call HostInfo::GetOSVersion().
   bool m_os_version_set_while_connected;
   bool m_system_arch_set_while_connected;
-  ConstString
+  std::string
   m_sdk_sysroot; // the root location of where the SDK files are all 
located
-  ConstString m_sdk_build;
+  std::string m_sdk_build;
   FileSpec m_working_dir; // The working directory which is used when 
installing
   // modules that have no install path set
   std::string m_remote_url;

diff  --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index c678edcd810da..12461f3713eca 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -488,7 +488,7 @@ uint32_t SBPlatform::GetOSUpdateVersion() {
 void SBPlatform::SetSDKRoot(const char *sysroot) {
   LLDB_INSTRUMENT_VA(this, sysroot);
   if (PlatformSP platform_sp = GetSP())
-platform_sp->SetSDKRootDirectory(ConstString(sysroot));
+platform_sp->SetSDKRootDirectory(sysroot);
 }
 
 SBError SBPlatform::Get(SBFileSpec , SBFileSpec ) {

diff  --git a/lldb/source/Interpreter/OptionGroupPlatform.cpp 
b/lldb/source/Interpreter/OptionGroupPlatform.cpp
index 60107eb288069..9928a5cda03e2 100644
--- a/lldb/source/Interpreter/OptionGroupPlatform.cpp
+++ b/lldb/source/Interpreter/OptionGroupPlatform.cpp
@@ -50,10 +50,10 @@ PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(
 if (!m_os_version.empty())
   

[Lldb-commits] [PATCH] D152933: [lldb][Android] Add platform.plugin.remote-android.run-as

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531398.
splhack added a comment.

remove 'Depends on' from commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152933

Files:
  lldb/source/Plugins/Platform/Android/CMakeLists.txt
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.h
  lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
  lldb/unittests/Platform/Android/PlatformAndroidTest.cpp

Index: lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
===
--- lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
+++ lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
@@ -52,6 +52,7 @@
   }
 
   MOCK_METHOD0(GetAdbClient, AdbClientSP());
+  MOCK_METHOD0(GetPropertyRunAs, llvm::StringRef());
 };
 
 } // namespace
@@ -100,6 +101,32 @@
   .Success());
 }
 
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithZipFileAndRunAs) {
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client,
+  ShellToFile(StrEq("run-as 'com.example.test' "
+"dd if='/system/app/Test/Test.apk' "
+"iflag=skip_bytes,count_bytes "
+"skip=4096 count=3600 status=none"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetPropertyRunAs())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.test")));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(
+  FileSpec("/system/app/Test/Test.apk!/lib/arm64-v8a/libtest.so"), 4096,
+  3600, FileSpec())
+  .Success());
+}
+
 TEST_F(PlatformAndroidTest, GetFileWithNormalFile) {
   auto sync_service = new MockSyncService();
   EXPECT_CALL(*sync_service, Stat(FileSpec("/data/local/tmp/test"), _, _, _))
@@ -152,3 +179,40 @@
   FileSpec())
   .Success());
 }
+
+TEST_F(PlatformAndroidTest, GetFileWithCatFallbackAndRunAs) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(
+  *sync_service,
+  Stat(FileSpec("/data/data/com.example.app/lib-main/libtest.so"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(0), Return(Status(;
+
+  auto adb_client0 = new MockAdbClient();
+  EXPECT_CALL(*adb_client0, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  auto adb_client1 = new MockAdbClient();
+  EXPECT_CALL(
+  *adb_client1,
+  ShellToFile(StrEq("run-as 'com.example.app' "
+"cat '/data/data/com.example.app/lib-main/libtest.so'"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetPropertyRunAs())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.app")));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(2)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client0)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client1);
+
+  EXPECT_TRUE(
+  GetFile(FileSpec("/data/data/com.example.app/lib-main/libtest.so"),
+  FileSpec())
+  .Success());
+}
Index: lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
===
--- /dev/null
+++ lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
@@ -0,0 +1,9 @@
+include "../../../../include/lldb/Core/PropertiesBase.td"
+
+let Definition = "android" in {
+  def PlatformRunAs: Property<"run-as", "String">,
+Global,
+DefaultStringValue<"">,
+Desc<"Specify package name to run adb shell command with 'run-as' as the "
+ "package user when necessary (e.g. to get file with 'cat' and 'dd').">;
+}
Index: lldb/source/Plugins/Platform/Android/PlatformAndroid.h
===
--- lldb/source/Plugins/Platform/Android/PlatformAndroid.h
+++ lldb/source/Plugins/Platform/Android/PlatformAndroid.h
@@ -30,6 +30,8 @@
   // lldb_private::PluginInterface functions
   static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
 
+  static void DebuggerInitialize(lldb_private::Debugger );
+
   static llvm::StringRef GetPluginNameStatic(bool is_host) {
 return is_host ? Platform::GetHostPlatformName() : "remote-android";
   }
@@ -73,6 +75,10 @@
   typedef std::unique_ptr AdbClientSP;
   virtual AdbClientSP GetAdbClient();
 
+  virtual llvm::StringRef GetPropertyRunAs();
+
+  std::string GetRunAs();
+
 private:
   AdbClient::SyncService *GetSyncService(Status );
 
@@ -81,7 +87,7 @@
   uint32_t m_sdk_version;
 };
 
-} // namespace platofor_android
+} // namespace platform_android

[Lldb-commits] [PATCH] D152855: [lldb][Android] Add PlatformAndroidTest

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531396.
splhack added a comment.

remove 'Depend on' from commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152855

Files:
  lldb/source/Plugins/Platform/Android/AdbClient.h
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.h
  lldb/unittests/Platform/Android/CMakeLists.txt
  lldb/unittests/Platform/Android/PlatformAndroidTest.cpp

Index: lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
===
--- /dev/null
+++ lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
@@ -0,0 +1,154 @@
+//===-- PlatformAndroidTest.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 "Plugins/Platform/Android/PlatformAndroid.h"
+#include "Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Utility/Connection.h"
+#include "gmock/gmock.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_android;
+using namespace testing;
+
+namespace {
+
+class MockSyncService : public AdbClient::SyncService {
+public:
+  MockSyncService() : SyncService(std::move(m_mock_conn)) {}
+
+  MOCK_METHOD2(PullFile,
+   Status(const FileSpec _file, const FileSpec _file));
+  MOCK_METHOD4(Stat, Status(const FileSpec _file, uint32_t ,
+uint32_t , uint32_t ));
+
+private:
+  std::unique_ptr m_mock_conn;
+};
+
+typedef std::unique_ptr SyncServiceSP;
+
+class MockAdbClient : public AdbClient {
+public:
+  explicit MockAdbClient() : AdbClient("mock") {}
+
+  MOCK_METHOD3(ShellToFile,
+   Status(const char *command, std::chrono::milliseconds timeout,
+  const FileSpec _file_spec));
+  MOCK_METHOD1(GetSyncService, SyncServiceSP(Status ));
+};
+
+class PlatformAndroidTest : public PlatformAndroid, public ::testing::Test {
+public:
+  PlatformAndroidTest() : PlatformAndroid(false) {
+m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
+  }
+
+  MOCK_METHOD0(GetAdbClient, AdbClientSP());
+};
+
+} // namespace
+
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithNormalFile) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(*sync_service, Stat(FileSpec("/system/lib64/libc.so"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(1), Return(Status(;
+  EXPECT_CALL(*sync_service, PullFile(FileSpec("/system/lib64/libc.so"), _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(FileSpec("/system/lib64/libc.so"), 0, 0, FileSpec())
+  .Success());
+}
+
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithZipFile) {
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client,
+  ShellToFile(StrEq("dd if='/system/app/Test/Test.apk' "
+"iflag=skip_bytes,count_bytes "
+"skip=4096 count=3600 status=none"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(
+  FileSpec("/system/app/Test/Test.apk!/lib/arm64-v8a/libtest.so"), 4096,
+  3600, FileSpec())
+  .Success());
+}
+
+TEST_F(PlatformAndroidTest, GetFileWithNormalFile) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(*sync_service, Stat(FileSpec("/data/local/tmp/test"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(1), Return(Status(;
+  EXPECT_CALL(*sync_service, PullFile(FileSpec("/data/local/tmp/test"), _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(GetFile(FileSpec("/data/local/tmp/test"), FileSpec()).Success());
+}
+

[Lldb-commits] [PATCH] D152759: [lldb][Android] Support zip .so file

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531394.
splhack added a comment.

remove 'Depends on' from commit message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152759

Files:
  lldb/include/lldb/Host/common/ZipFileResolver.h
  lldb/include/lldb/Utility/ZipFile.h
  lldb/source/Host/CMakeLists.txt
  lldb/source/Host/common/ZipFileResolver.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/ZipFile.cpp
  lldb/unittests/Host/CMakeLists.txt
  lldb/unittests/Host/common/CMakeLists.txt
  lldb/unittests/Host/common/Inputs/zip-test.zip
  lldb/unittests/Host/common/ZipFileResolverTest.cpp

Index: lldb/unittests/Host/common/ZipFileResolverTest.cpp
===
--- /dev/null
+++ lldb/unittests/Host/common/ZipFileResolverTest.cpp
@@ -0,0 +1,72 @@
+//===-- ZipFileResolverTest.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/Host/common/ZipFileResolver.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace llvm;
+
+namespace {
+class ZipFileResolverTest : public ::testing::Test {
+  SubsystemRAII subsystems;
+};
+
+std::string TestZipPath() {
+  FileSpec zip_spec(GetInputFilePath("zip-test.zip"));
+  FileSystem::Instance().Resolve(zip_spec);
+  return zip_spec.GetPath();
+}
+} // namespace
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithNormalFile) {
+  const FileSpec file_spec("/system/lib64/libtest.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_TRUE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+
+  EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindNormal);
+  EXPECT_EQ(file_path, file_spec.GetPath());
+  EXPECT_EQ(file_offset, 0UL);
+  EXPECT_EQ(file_size, 0UL);
+}
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithZipMissing) {
+  const std::string zip_path = TestZipPath();
+  const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libmissing.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_FALSE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+}
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithZipExisting) {
+  const std::string zip_path = TestZipPath();
+  const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libzip-test.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_TRUE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+
+  EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindZip);
+  EXPECT_EQ(file_path, zip_path);
+  EXPECT_EQ(file_offset, 4096UL);
+  EXPECT_EQ(file_size, 3600UL);
+}
Index: lldb/unittests/Host/common/CMakeLists.txt
===
--- /dev/null
+++ lldb/unittests/Host/common/CMakeLists.txt
@@ -0,0 +1,15 @@
+set (FILES
+  ZipFileResolverTest.cpp
+)
+
+add_lldb_unittest(HostCommonTests
+  ${FILES}
+  LINK_LIBS
+lldbHost
+lldbUtilityHelpers
+  )
+
+set(test_inputs
+  zip-test.zip
+  )
+add_unittest_inputs(HostCommonTests "${test_inputs}")
Index: lldb/unittests/Host/CMakeLists.txt
===
--- lldb/unittests/Host/CMakeLists.txt
+++ lldb/unittests/Host/CMakeLists.txt
@@ -38,3 +38,5 @@
 LLVMTestingSupport
 LLVMTargetParser
   )
+
+add_subdirectory(common)
Index: lldb/source/Utility/ZipFile.cpp
===
--- /dev/null
+++ lldb/source/Utility/ZipFile.cpp
@@ -0,0 +1,180 @@
+//===-- ZipFile.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/ZipFile.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/FileSpec.h"
+#include "llvm/Support/Endian.h"
+
+using namespace lldb_private;
+using namespace llvm::support;
+
+namespace 

[Lldb-commits] [PATCH] D152933: [lldb][Android] Add platform.plugin.remote-android.run-as

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531392.
splhack added a comment.
Herald added a subscriber: JDevlieghere.

rebase onto D152855 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152933

Files:
  lldb/source/Plugins/Platform/Android/CMakeLists.txt
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.h
  lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
  lldb/unittests/Platform/Android/PlatformAndroidTest.cpp

Index: lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
===
--- lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
+++ lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
@@ -52,6 +52,7 @@
   }
 
   MOCK_METHOD0(GetAdbClient, AdbClientSP());
+  MOCK_METHOD0(GetPropertyRunAs, llvm::StringRef());
 };
 
 } // namespace
@@ -100,6 +101,32 @@
   .Success());
 }
 
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithZipFileAndRunAs) {
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client,
+  ShellToFile(StrEq("run-as 'com.example.test' "
+"dd if='/system/app/Test/Test.apk' "
+"iflag=skip_bytes,count_bytes "
+"skip=4096 count=3600 status=none"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetPropertyRunAs())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.test")));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(
+  FileSpec("/system/app/Test/Test.apk!/lib/arm64-v8a/libtest.so"), 4096,
+  3600, FileSpec())
+  .Success());
+}
+
 TEST_F(PlatformAndroidTest, GetFileWithNormalFile) {
   auto sync_service = new MockSyncService();
   EXPECT_CALL(*sync_service, Stat(FileSpec("/data/local/tmp/test"), _, _, _))
@@ -152,3 +179,40 @@
   FileSpec())
   .Success());
 }
+
+TEST_F(PlatformAndroidTest, GetFileWithCatFallbackAndRunAs) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(
+  *sync_service,
+  Stat(FileSpec("/data/data/com.example.app/lib-main/libtest.so"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(0), Return(Status(;
+
+  auto adb_client0 = new MockAdbClient();
+  EXPECT_CALL(*adb_client0, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  auto adb_client1 = new MockAdbClient();
+  EXPECT_CALL(
+  *adb_client1,
+  ShellToFile(StrEq("run-as 'com.example.app' "
+"cat '/data/data/com.example.app/lib-main/libtest.so'"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetPropertyRunAs())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.app")));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(2)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client0)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client1);
+
+  EXPECT_TRUE(
+  GetFile(FileSpec("/data/data/com.example.app/lib-main/libtest.so"),
+  FileSpec())
+  .Success());
+}
Index: lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
===
--- /dev/null
+++ lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
@@ -0,0 +1,9 @@
+include "../../../../include/lldb/Core/PropertiesBase.td"
+
+let Definition = "android" in {
+  def PlatformRunAs: Property<"run-as", "String">,
+Global,
+DefaultStringValue<"">,
+Desc<"Specify package name to run adb shell command with 'run-as' as the "
+ "package user when necessary (e.g. to get file with 'cat' and 'dd').">;
+}
Index: lldb/source/Plugins/Platform/Android/PlatformAndroid.h
===
--- lldb/source/Plugins/Platform/Android/PlatformAndroid.h
+++ lldb/source/Plugins/Platform/Android/PlatformAndroid.h
@@ -30,6 +30,8 @@
   // lldb_private::PluginInterface functions
   static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
 
+  static void DebuggerInitialize(lldb_private::Debugger );
+
   static llvm::StringRef GetPluginNameStatic(bool is_host) {
 return is_host ? Platform::GetHostPlatformName() : "remote-android";
   }
@@ -73,6 +75,10 @@
   typedef std::unique_ptr AdbClientSP;
   virtual AdbClientSP GetAdbClient();
 
+  virtual llvm::StringRef GetPropertyRunAs();
+
+  std::string GetRunAs();
+
 private:
   AdbClient::SyncService *GetSyncService(Status );
 
@@ -81,7 +87,7 @@
   uint32_t m_sdk_version;
 };
 
-} // 

[Lldb-commits] [PATCH] D152855: [lldb][Android] Add PlatformAndroidTest

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531389.
splhack added a comment.

rebase onto D152759 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152855

Files:
  lldb/source/Plugins/Platform/Android/AdbClient.h
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.h
  lldb/unittests/Platform/Android/CMakeLists.txt
  lldb/unittests/Platform/Android/PlatformAndroidTest.cpp

Index: lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
===
--- /dev/null
+++ lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
@@ -0,0 +1,154 @@
+//===-- PlatformAndroidTest.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 "Plugins/Platform/Android/PlatformAndroid.h"
+#include "Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Utility/Connection.h"
+#include "gmock/gmock.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_android;
+using namespace testing;
+
+namespace {
+
+class MockSyncService : public AdbClient::SyncService {
+public:
+  MockSyncService() : SyncService(std::move(m_mock_conn)) {}
+
+  MOCK_METHOD2(PullFile,
+   Status(const FileSpec _file, const FileSpec _file));
+  MOCK_METHOD4(Stat, Status(const FileSpec _file, uint32_t ,
+uint32_t , uint32_t ));
+
+private:
+  std::unique_ptr m_mock_conn;
+};
+
+typedef std::unique_ptr SyncServiceSP;
+
+class MockAdbClient : public AdbClient {
+public:
+  explicit MockAdbClient() : AdbClient("mock") {}
+
+  MOCK_METHOD3(ShellToFile,
+   Status(const char *command, std::chrono::milliseconds timeout,
+  const FileSpec _file_spec));
+  MOCK_METHOD1(GetSyncService, SyncServiceSP(Status ));
+};
+
+class PlatformAndroidTest : public PlatformAndroid, public ::testing::Test {
+public:
+  PlatformAndroidTest() : PlatformAndroid(false) {
+m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
+  }
+
+  MOCK_METHOD0(GetAdbClient, AdbClientSP());
+};
+
+} // namespace
+
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithNormalFile) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(*sync_service, Stat(FileSpec("/system/lib64/libc.so"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(1), Return(Status(;
+  EXPECT_CALL(*sync_service, PullFile(FileSpec("/system/lib64/libc.so"), _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(FileSpec("/system/lib64/libc.so"), 0, 0, FileSpec())
+  .Success());
+}
+
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithZipFile) {
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client,
+  ShellToFile(StrEq("dd if='/system/app/Test/Test.apk' "
+"iflag=skip_bytes,count_bytes "
+"skip=4096 count=3600 status=none"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(
+  FileSpec("/system/app/Test/Test.apk!/lib/arm64-v8a/libtest.so"), 4096,
+  3600, FileSpec())
+  .Success());
+}
+
+TEST_F(PlatformAndroidTest, GetFileWithNormalFile) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(*sync_service, Stat(FileSpec("/data/local/tmp/test"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(1), Return(Status(;
+  EXPECT_CALL(*sync_service, PullFile(FileSpec("/data/local/tmp/test"), _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(GetFile(FileSpec("/data/local/tmp/test"), FileSpec()).Success());
+}
+

[Lldb-commits] [PATCH] D152759: [lldb][Android] Support zip .so file

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack added inline comments.



Comment at: lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp:261-264
+  if (const char *run_as = std::getenv("ANDROID_PLATFORM_RUN_AS"))
+snprintf(run_as_cmd, sizeof(run_as_cmd), "run-as '%s' ", run_as);
+  else
+run_as_cmd[0] = '\0';

splhack wrote:
> bulbazord wrote:
> > Maybe it would be a good idea to centralize the `run-as` logic somewhere, 
> > right now it's pretty ad-hoc.
> Will look into these run-as things with D152494 centralize and if 
> plugin.platform.android.platform-run-as possible.
run-as is centralized in D152933


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152759

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


[Lldb-commits] [PATCH] D152759: [lldb][Android] Support zip .so file

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531384.
splhack added a comment.

rebase onto D152757 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152759

Files:
  lldb/include/lldb/Host/common/ZipFileResolver.h
  lldb/include/lldb/Utility/ZipFile.h
  lldb/source/Host/CMakeLists.txt
  lldb/source/Host/common/ZipFileResolver.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/ZipFile.cpp
  lldb/unittests/Host/CMakeLists.txt
  lldb/unittests/Host/common/CMakeLists.txt
  lldb/unittests/Host/common/Inputs/zip-test.zip
  lldb/unittests/Host/common/ZipFileResolverTest.cpp

Index: lldb/unittests/Host/common/ZipFileResolverTest.cpp
===
--- /dev/null
+++ lldb/unittests/Host/common/ZipFileResolverTest.cpp
@@ -0,0 +1,72 @@
+//===-- ZipFileResolverTest.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/Host/common/ZipFileResolver.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace llvm;
+
+namespace {
+class ZipFileResolverTest : public ::testing::Test {
+  SubsystemRAII subsystems;
+};
+
+std::string TestZipPath() {
+  FileSpec zip_spec(GetInputFilePath("zip-test.zip"));
+  FileSystem::Instance().Resolve(zip_spec);
+  return zip_spec.GetPath();
+}
+} // namespace
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithNormalFile) {
+  const FileSpec file_spec("/system/lib64/libtest.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_TRUE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+
+  EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindNormal);
+  EXPECT_EQ(file_path, file_spec.GetPath());
+  EXPECT_EQ(file_offset, 0UL);
+  EXPECT_EQ(file_size, 0UL);
+}
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithZipMissing) {
+  const std::string zip_path = TestZipPath();
+  const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libmissing.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_FALSE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+}
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithZipExisting) {
+  const std::string zip_path = TestZipPath();
+  const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libzip-test.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_TRUE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+
+  EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindZip);
+  EXPECT_EQ(file_path, zip_path);
+  EXPECT_EQ(file_offset, 4096UL);
+  EXPECT_EQ(file_size, 3600UL);
+}
Index: lldb/unittests/Host/common/CMakeLists.txt
===
--- /dev/null
+++ lldb/unittests/Host/common/CMakeLists.txt
@@ -0,0 +1,15 @@
+set (FILES
+  ZipFileResolverTest.cpp
+)
+
+add_lldb_unittest(HostCommonTests
+  ${FILES}
+  LINK_LIBS
+lldbHost
+lldbUtilityHelpers
+  )
+
+set(test_inputs
+  zip-test.zip
+  )
+add_unittest_inputs(HostCommonTests "${test_inputs}")
Index: lldb/unittests/Host/CMakeLists.txt
===
--- lldb/unittests/Host/CMakeLists.txt
+++ lldb/unittests/Host/CMakeLists.txt
@@ -38,3 +38,5 @@
 LLVMTestingSupport
 LLVMTargetParser
   )
+
+add_subdirectory(common)
Index: lldb/source/Utility/ZipFile.cpp
===
--- /dev/null
+++ lldb/source/Utility/ZipFile.cpp
@@ -0,0 +1,180 @@
+//===-- ZipFile.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/ZipFile.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/FileSpec.h"
+#include "llvm/Support/Endian.h"
+
+using namespace lldb_private;
+using namespace 

[Lldb-commits] [PATCH] D152757: [lldb][ObjectFileELF] Set ModuleSpec file offset and size

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531383.
splhack added a comment.

rebase onto D152712 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152757

Files:
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/unittests/ObjectFile/ELF/CMakeLists.txt
  lldb/unittests/ObjectFile/ELF/Inputs/liboffset-test.so
  lldb/unittests/ObjectFile/ELF/Inputs/offset-test.bin
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp


Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -156,6 +156,35 @@
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
 
+TEST_F(ObjectFileELFTest, GetModuleSpecifications_OffsetSizeWithNormalFile) {
+  std::string SO = GetInputFilePath("liboffset-test.so");
+  ModuleSpecList Specs;
+  ASSERT_EQ(1u, ObjectFile::GetModuleSpecifications(FileSpec(SO), 0, 0, 
Specs));
+  ModuleSpec Spec;
+  ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ;
+  UUID Uuid;
+  Uuid.SetFromStringRef("7D6E4738");
+  EXPECT_EQ(Spec.GetUUID(), Uuid);
+  EXPECT_EQ(Spec.GetObjectOffset(), 0UL);
+  EXPECT_EQ(Spec.GetObjectSize(), 3600UL);
+  EXPECT_EQ(FileSystem::Instance().GetByteSize(FileSpec(SO)), 3600UL);
+}
+
+TEST_F(ObjectFileELFTest, GetModuleSpecifications_OffsetSizeWithOffsetFile) {
+  std::string SO = GetInputFilePath("offset-test.bin");
+  ModuleSpecList Specs;
+  ASSERT_EQ(
+  1u, ObjectFile::GetModuleSpecifications(FileSpec(SO), 1024, 3600, 
Specs));
+  ModuleSpec Spec;
+  ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ;
+  UUID Uuid;
+  Uuid.SetFromStringRef("7D6E4738");
+  EXPECT_EQ(Spec.GetUUID(), Uuid);
+  EXPECT_EQ(Spec.GetObjectOffset(), 1024UL);
+  EXPECT_EQ(Spec.GetObjectSize(), 3600UL);
+  EXPECT_EQ(FileSystem::Instance().GetByteSize(FileSpec(SO)), 4640UL);
+}
+
 TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
   /*
   // nosym-entrypoint-arm-thumb.s
Index: lldb/unittests/ObjectFile/ELF/CMakeLists.txt
===
--- lldb/unittests/ObjectFile/ELF/CMakeLists.txt
+++ lldb/unittests/ObjectFile/ELF/CMakeLists.txt
@@ -11,5 +11,7 @@
 
 set(test_inputs
   early-section-headers.so
+  liboffset-test.so
+  offset-test.bin
   )
 add_unittest_inputs(ObjectFileELFTests "${test_inputs}")
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -555,6 +555,8 @@
 if (header.Parse(data, _offset)) {
   if (data_sp) {
 ModuleSpec spec(file);
+spec.SetObjectOffset(file_offset);
+spec.SetObjectSize(length);
 
 const uint32_t sub_type = subTypeFromElfHeader(header);
 spec.GetArchitecture().SetArchitecture(
@@ -587,7 +589,7 @@
   }
 
   if (data_sp->GetByteSize() < length)
-data_sp = MapFileData(file, -1, file_offset);
+data_sp = MapFileData(file, length, file_offset);
   if (data_sp)
 data.SetData(data_sp);
   // In case there is header extension in the section #0, the header we


Index: lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
===
--- lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -156,6 +156,35 @@
   EXPECT_EQ(Spec.GetUUID(), Uuid);
 }
 
+TEST_F(ObjectFileELFTest, GetModuleSpecifications_OffsetSizeWithNormalFile) {
+  std::string SO = GetInputFilePath("liboffset-test.so");
+  ModuleSpecList Specs;
+  ASSERT_EQ(1u, ObjectFile::GetModuleSpecifications(FileSpec(SO), 0, 0, Specs));
+  ModuleSpec Spec;
+  ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ;
+  UUID Uuid;
+  Uuid.SetFromStringRef("7D6E4738");
+  EXPECT_EQ(Spec.GetUUID(), Uuid);
+  EXPECT_EQ(Spec.GetObjectOffset(), 0UL);
+  EXPECT_EQ(Spec.GetObjectSize(), 3600UL);
+  EXPECT_EQ(FileSystem::Instance().GetByteSize(FileSpec(SO)), 3600UL);
+}
+
+TEST_F(ObjectFileELFTest, GetModuleSpecifications_OffsetSizeWithOffsetFile) {
+  std::string SO = GetInputFilePath("offset-test.bin");
+  ModuleSpecList Specs;
+  ASSERT_EQ(
+  1u, ObjectFile::GetModuleSpecifications(FileSpec(SO), 1024, 3600, Specs));
+  ModuleSpec Spec;
+  ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ;
+  UUID Uuid;
+  Uuid.SetFromStringRef("7D6E4738");
+  EXPECT_EQ(Spec.GetUUID(), Uuid);
+  EXPECT_EQ(Spec.GetObjectOffset(), 1024UL);
+  EXPECT_EQ(Spec.GetObjectSize(), 3600UL);
+  EXPECT_EQ(FileSystem::Instance().GetByteSize(FileSpec(SO)), 4640UL);
+}
+
 TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
   /*
   // nosym-entrypoint-arm-thumb.s
Index: 

[Lldb-commits] [PATCH] D152712: [lldb][Android] Use a lambda for calls to ::open in RetryAfterSignal

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531381.
splhack added a comment.

rebase onto main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152712

Files:
  lldb/include/lldb/Host/common/RetryAfterSignal.h
  lldb/source/Host/common/PseudoTerminal.cpp
  lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
  lldb/source/Host/posix/FileSystemPosix.cpp
  lldb/source/Host/posix/PipePosix.cpp
  lldb/source/Host/posix/ProcessLauncherPosixFork.cpp

Index: lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
===
--- lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
+++ lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
@@ -11,6 +11,7 @@
 #include "lldb/Host/HostProcess.h"
 #include "lldb/Host/Pipe.h"
 #include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/common/RetryAfterSignal.h"
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/Log.h"
 #include "llvm/Support/Errno.h"
@@ -71,7 +72,7 @@
 }
 
 static void DupDescriptor(int error_fd, const char *file, int fd, int flags) {
-  int target_fd = llvm::sys::RetryAfterSignal(-1, ::open, file, flags, 0666);
+  int target_fd = RetryAfterSignal::Open(file, flags, 0666);
 
   if (target_fd == -1)
 ExitWithError(error_fd, "DupDescriptor-open");
Index: lldb/source/Host/posix/PipePosix.cpp
===
--- lldb/source/Host/posix/PipePosix.cpp
+++ lldb/source/Host/posix/PipePosix.cpp
@@ -8,6 +8,7 @@
 
 #include "lldb/Host/posix/PipePosix.h"
 #include "lldb/Host/HostInfo.h"
+#include "lldb/Host/common/RetryAfterSignal.h"
 #include "lldb/Utility/SelectHelper.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Errno.h"
@@ -148,7 +149,7 @@
 flags |= O_CLOEXEC;
 
   Status error;
-  int fd = llvm::sys::RetryAfterSignal(-1, ::open, name.str().c_str(), flags);
+  int fd = RetryAfterSignal::Open(name.str().c_str(), flags);
   if (fd != -1)
 m_fds[READ] = fd;
   else
Index: lldb/source/Host/posix/FileSystemPosix.cpp
===
--- lldb/source/Host/posix/FileSystemPosix.cpp
+++ lldb/source/Host/posix/FileSystemPosix.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "lldb/Host/FileSystem.h"
+#include "lldb/Host/common/RetryAfterSignal.h"
 
 // C includes
 #include 
@@ -77,5 +78,5 @@
 }
 
 int FileSystem::Open(const char *path, int flags, int mode) {
-  return llvm::sys::RetryAfterSignal(-1, ::open, path, flags, mode);
+  return RetryAfterSignal::Open(path, flags, mode);
 }
Index: lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
===
--- lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
+++ lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
@@ -13,6 +13,7 @@
 #define _DARWIN_UNLIMITED_SELECT
 #endif
 
+#include "lldb/Host/common/RetryAfterSignal.h"
 #include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
 #include "lldb/Host/Config.h"
 #include "lldb/Host/Socket.h"
@@ -726,7 +727,7 @@
 #if LLDB_ENABLE_POSIX
   std::string addr_str = s.str();
   // file:///PATH
-  int fd = llvm::sys::RetryAfterSignal(-1, ::open, addr_str.c_str(), O_RDWR);
+  int fd = RetryAfterSignal::Open(addr_str.c_str(), O_RDWR);
   if (fd == -1) {
 if (error_ptr)
   error_ptr->SetErrorToErrno();
@@ -776,7 +777,7 @@
 return eConnectionStatusError;
   }
 
-  int fd = llvm::sys::RetryAfterSignal(-1, ::open, path.str().c_str(), O_RDWR);
+  int fd = RetryAfterSignal::Open(path.str().c_str(), O_RDWR);
   if (fd == -1) {
 if (error_ptr)
   error_ptr->SetErrorToErrno();
Index: lldb/source/Host/common/PseudoTerminal.cpp
===
--- lldb/source/Host/common/PseudoTerminal.cpp
+++ lldb/source/Host/common/PseudoTerminal.cpp
@@ -8,6 +8,7 @@
 
 #include "lldb/Host/PseudoTerminal.h"
 #include "lldb/Host/Config.h"
+#include "lldb/Host/common/RetryAfterSignal.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Errno.h"
 #include 
@@ -95,7 +96,7 @@
   CloseSecondaryFileDescriptor();
 
   std::string name = GetSecondaryName();
-  m_secondary_fd = llvm::sys::RetryAfterSignal(-1, ::open, name.c_str(), oflag);
+  m_secondary_fd = RetryAfterSignal::Open(name.c_str(), oflag);
   if (m_secondary_fd >= 0)
 return llvm::Error::success();
 
Index: lldb/include/lldb/Host/common/RetryAfterSignal.h
===
--- /dev/null
+++ lldb/include/lldb/Host/common/RetryAfterSignal.h
@@ -0,0 +1,35 @@
+//===-- RetryAfterSignal.h --*- C++ -*-===//
+//
+// 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 

[Lldb-commits] [PATCH] D152886: [lldb] Make it easier to spot if sources were resolved in crashlog output

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



Comment at: lldb/examples/python/crashlog.py:344
+)
+if os.path.exists(source_path):
+self.resolved_source = True

mib wrote:
> I guess that checks that the user have access to the remapped path, is that 
> right ?
> 
> If that's not the case, I think we should let the user know
Yeah, that's exactly right. We do let the user know by including or emitting 
"and sources" in the symbol resolution print. Currently we print the "and 
sources" when at least one of the remapped paths is accessible. We could change 
this to only print it when all the paths are accessible. We could also change 
the message the say "and could not find sources" when a path remapping is 
present but the paths are not accessible. 


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

https://reviews.llvm.org/D152886

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


[Lldb-commits] [PATCH] D152494: [lldb][Android] Fix adb shell cat

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack abandoned this revision.
splhack added a comment.

@bulbazord thanks for the suggestion! property works well. D152933 
 supersedes this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152494

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


[Lldb-commits] [PATCH] D152933: [lldb][Android] Add platform.plugin.remote-android.run-as

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack created this revision.
Herald added a subscriber: danielkiss.
Herald added a project: All.
splhack added reviewers: clayborg, bulbazord, labath, lanza.
splhack published this revision for review.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

When LLDB fails to pull file from a package directory due to security
constraint, user needs to set the package name to
'platform.plugin.remote-android.run-as' property to run shell commands
as the package user. (e.g. to get file with 'cat' and 'dd').

https://cs.android.com/android/platform/superproject/+/master:
system/core/run-as/run-as.cpp;l=39-61;
drc=4a77a84a55522a3b122f9c63ef0d0b8a6a131627

This supersedes D152494 
Depends on D152855 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152933

Files:
  lldb/source/Plugins/Platform/Android/CMakeLists.txt
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.h
  lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
  lldb/unittests/Platform/Android/PlatformAndroidTest.cpp

Index: lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
===
--- lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
+++ lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
@@ -52,6 +52,7 @@
   }
 
   MOCK_METHOD0(GetAdbClient, AdbClientSP());
+  MOCK_METHOD0(GetPropertyRunAs, llvm::StringRef());
 };
 
 } // namespace
@@ -100,6 +101,32 @@
   .Success());
 }
 
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithZipFileAndRunAs) {
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client,
+  ShellToFile(StrEq("run-as 'com.example.test' "
+"dd if='/system/app/Test/Test.apk' "
+"iflag=skip_bytes,count_bytes "
+"skip=4096 count=3600 status=none"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetPropertyRunAs())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.test")));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(
+  FileSpec("/system/app/Test/Test.apk!/lib/arm64-v8a/libtest.so"), 4096,
+  3600, FileSpec())
+  .Success());
+}
+
 TEST_F(PlatformAndroidTest, GetFileWithNormalFile) {
   auto sync_service = new MockSyncService();
   EXPECT_CALL(*sync_service, Stat(FileSpec("/data/local/tmp/test"), _, _, _))
@@ -152,3 +179,40 @@
   FileSpec())
   .Success());
 }
+
+TEST_F(PlatformAndroidTest, GetFileWithCatFallbackAndRunAs) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(
+  *sync_service,
+  Stat(FileSpec("/data/data/com.example.app/lib-main/libtest.so"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(0), Return(Status(;
+
+  auto adb_client0 = new MockAdbClient();
+  EXPECT_CALL(*adb_client0, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  auto adb_client1 = new MockAdbClient();
+  EXPECT_CALL(
+  *adb_client1,
+  ShellToFile(StrEq("run-as 'com.example.app' "
+"cat '/data/data/com.example.app/lib-main/libtest.so'"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetPropertyRunAs())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.app")));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(2)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client0)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client1);
+
+  EXPECT_TRUE(
+  GetFile(FileSpec("/data/data/com.example.app/lib-main/libtest.so"),
+  FileSpec())
+  .Success());
+}
Index: lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
===
--- /dev/null
+++ lldb/source/Plugins/Platform/Android/PlatformAndroidProperties.td
@@ -0,0 +1,9 @@
+include "../../../../include/lldb/Core/PropertiesBase.td"
+
+let Definition = "android" in {
+  def PlatformRunAs: Property<"run-as", "String">,
+Global,
+DefaultStringValue<"">,
+Desc<"Specify package name to run adb shell command with 'run-as' as the "
+ "package user when necessary (e.g. to get file with 'cat' and 'dd').">;
+}
Index: lldb/source/Plugins/Platform/Android/PlatformAndroid.h
===
--- lldb/source/Plugins/Platform/Android/PlatformAndroid.h
+++ lldb/source/Plugins/Platform/Android/PlatformAndroid.h
@@ -30,6 +30,8 @@
   // lldb_private::PluginInterface functions
   static lldb::PlatformSP 

[Lldb-commits] [PATCH] D152872: Add support for __debug_line_str in Mach-O

2023-06-14 Thread Adrian Prantl via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG27fac4a72ae5: Add support for __debug_line_str in Mach-O 
(authored by aprantl).
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152872

Files:
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/test/Shell/SymbolFile/DWARF/x86/dwarf5-macho.c


Index: lldb/test/Shell/SymbolFile/DWARF/x86/dwarf5-macho.c
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/x86/dwarf5-macho.c
@@ -0,0 +1,15 @@
+// Test that the file names in the __debug_line_str section can be decoded.
+
+// REQUIRES: system-darwin
+
+// RUN: %clang -target x86_64-apple-darwin %s -c -o %t.o -gdwarf-5
+// RUN: llvm-readobj --sections %t.o | FileCheck %s --check-prefix NAMES
+// RUN: xcrun %clang -target x86_64-apple-darwin -o %t.exe %t.o
+// RUN: %lldb %t.exe -b -o "target modules dump line-table %s" | FileCheck %s
+
+// NAMES: Name: __debug_line_str
+
+int main(int argc, char **argv) {
+  // CHECK: dwarf5-macho.c:[[@LINE+1]]
+  return 0;
+}
Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1443,6 +1443,7 @@
   static ConstString g_sect_name_dwarf_debug_frame("__debug_frame");
   static ConstString g_sect_name_dwarf_debug_info("__debug_info");
   static ConstString g_sect_name_dwarf_debug_line("__debug_line");
+  static ConstString g_sect_name_dwarf_debug_line_str("__debug_line_str");
   static ConstString g_sect_name_dwarf_debug_loc("__debug_loc");
   static ConstString g_sect_name_dwarf_debug_loclists("__debug_loclists");
   static ConstString g_sect_name_dwarf_debug_macinfo("__debug_macinfo");
@@ -1472,6 +1473,8 @@
 return eSectionTypeDWARFDebugInfo;
   if (section_name == g_sect_name_dwarf_debug_line)
 return eSectionTypeDWARFDebugLine;
+  if (section_name == g_sect_name_dwarf_debug_line_str)
+return eSectionTypeDWARFDebugLineStr;
   if (section_name == g_sect_name_dwarf_debug_loc)
 return eSectionTypeDWARFDebugLoc;
   if (section_name == g_sect_name_dwarf_debug_loclists)


Index: lldb/test/Shell/SymbolFile/DWARF/x86/dwarf5-macho.c
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/x86/dwarf5-macho.c
@@ -0,0 +1,15 @@
+// Test that the file names in the __debug_line_str section can be decoded.
+
+// REQUIRES: system-darwin
+
+// RUN: %clang -target x86_64-apple-darwin %s -c -o %t.o -gdwarf-5
+// RUN: llvm-readobj --sections %t.o | FileCheck %s --check-prefix NAMES
+// RUN: xcrun %clang -target x86_64-apple-darwin -o %t.exe %t.o
+// RUN: %lldb %t.exe -b -o "target modules dump line-table %s" | FileCheck %s
+
+// NAMES: Name: __debug_line_str
+
+int main(int argc, char **argv) {
+  // CHECK: dwarf5-macho.c:[[@LINE+1]]
+  return 0;
+}
Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1443,6 +1443,7 @@
   static ConstString g_sect_name_dwarf_debug_frame("__debug_frame");
   static ConstString g_sect_name_dwarf_debug_info("__debug_info");
   static ConstString g_sect_name_dwarf_debug_line("__debug_line");
+  static ConstString g_sect_name_dwarf_debug_line_str("__debug_line_str");
   static ConstString g_sect_name_dwarf_debug_loc("__debug_loc");
   static ConstString g_sect_name_dwarf_debug_loclists("__debug_loclists");
   static ConstString g_sect_name_dwarf_debug_macinfo("__debug_macinfo");
@@ -1472,6 +1473,8 @@
 return eSectionTypeDWARFDebugInfo;
   if (section_name == g_sect_name_dwarf_debug_line)
 return eSectionTypeDWARFDebugLine;
+  if (section_name == g_sect_name_dwarf_debug_line_str)
+return eSectionTypeDWARFDebugLineStr;
   if (section_name == g_sect_name_dwarf_debug_loc)
 return eSectionTypeDWARFDebugLoc;
   if (section_name == g_sect_name_dwarf_debug_loclists)
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 27fac4a - Add support for __debug_line_str in Mach-O

2023-06-14 Thread Adrian Prantl via lldb-commits

Author: Adrian Prantl
Date: 2023-06-14T08:37:08-07:00
New Revision: 27fac4a72ae54a471471a69c0ad999585ccbb026

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

LOG: Add support for __debug_line_str in Mach-O

This patch resolves an issue that currently accounts for the vast
majority of failures on the matrix bot.

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

Added: 
lldb/test/Shell/SymbolFile/DWARF/x86/dwarf5-macho.c

Modified: 
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 887c0b64c2c62..5fddb4e6eadd0 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1443,6 +1443,7 @@ static lldb::SectionType GetSectionType(uint32_t flags,
   static ConstString g_sect_name_dwarf_debug_frame("__debug_frame");
   static ConstString g_sect_name_dwarf_debug_info("__debug_info");
   static ConstString g_sect_name_dwarf_debug_line("__debug_line");
+  static ConstString g_sect_name_dwarf_debug_line_str("__debug_line_str");
   static ConstString g_sect_name_dwarf_debug_loc("__debug_loc");
   static ConstString g_sect_name_dwarf_debug_loclists("__debug_loclists");
   static ConstString g_sect_name_dwarf_debug_macinfo("__debug_macinfo");
@@ -1472,6 +1473,8 @@ static lldb::SectionType GetSectionType(uint32_t flags,
 return eSectionTypeDWARFDebugInfo;
   if (section_name == g_sect_name_dwarf_debug_line)
 return eSectionTypeDWARFDebugLine;
+  if (section_name == g_sect_name_dwarf_debug_line_str)
+return eSectionTypeDWARFDebugLineStr;
   if (section_name == g_sect_name_dwarf_debug_loc)
 return eSectionTypeDWARFDebugLoc;
   if (section_name == g_sect_name_dwarf_debug_loclists)

diff  --git a/lldb/test/Shell/SymbolFile/DWARF/x86/dwarf5-macho.c 
b/lldb/test/Shell/SymbolFile/DWARF/x86/dwarf5-macho.c
new file mode 100644
index 0..cc7305677f6e7
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/dwarf5-macho.c
@@ -0,0 +1,15 @@
+// Test that the file names in the __debug_line_str section can be decoded.
+
+// REQUIRES: system-darwin
+
+// RUN: %clang -target x86_64-apple-darwin %s -c -o %t.o -gdwarf-5
+// RUN: llvm-readobj --sections %t.o | FileCheck %s --check-prefix NAMES
+// RUN: xcrun %clang -target x86_64-apple-darwin -o %t.exe %t.o
+// RUN: %lldb %t.exe -b -o "target modules dump line-table %s" | FileCheck %s
+
+// NAMES: Name: __debug_line_str
+
+int main(int argc, char **argv) {
+  // CHECK: dwarf5-macho.c:[[@LINE+1]]
+  return 0;
+}



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


[Lldb-commits] [PATCH] D152922: [lldb][RISCV] Replace enumeration of RVV builtin types with inclusion to RISCVVTypes.def

2023-06-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett accepted this revision.
DavidSpickett added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: JDevlieghere.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152922

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


[Lldb-commits] [PATCH] D152922: [lldb][RISCV] Replace enumeration of RVV builtin types with inclusion to RISCVVTypes.def

2023-06-14 Thread Yueh-Ting (eop) Chen via Phabricator via lldb-commits
eopXD created this revision.
eopXD added a reviewer: DavidSpickett.
Herald added subscribers: jobnoorman, VincentWu, vkmr, luismarques, 
sameer.abuasal, s.egerton, Jim, benna, psnobl, rogfer01, shiva0217, kito-cheng, 
simoncook, asb, arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: lldb-commits, pcwang-thead.
Herald added a project: LLDB.

This approach prevents us from adding new lines into the switch case when new 
types are introduced.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152922

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp


Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -5041,73 +5041,8 @@
   break;
 
 // RISC-V V builtin types.
-case clang::BuiltinType::RvvInt8mf8:
-case clang::BuiltinType::RvvInt8mf4:
-case clang::BuiltinType::RvvInt8mf2:
-case clang::BuiltinType::RvvInt8m1:
-case clang::BuiltinType::RvvInt8m2:
-case clang::BuiltinType::RvvInt8m4:
-case clang::BuiltinType::RvvInt8m8:
-case clang::BuiltinType::RvvUint8mf8:
-case clang::BuiltinType::RvvUint8mf4:
-case clang::BuiltinType::RvvUint8mf2:
-case clang::BuiltinType::RvvUint8m1:
-case clang::BuiltinType::RvvUint8m2:
-case clang::BuiltinType::RvvUint8m4:
-case clang::BuiltinType::RvvUint8m8:
-case clang::BuiltinType::RvvInt16mf4:
-case clang::BuiltinType::RvvInt16mf2:
-case clang::BuiltinType::RvvInt16m1:
-case clang::BuiltinType::RvvInt16m2:
-case clang::BuiltinType::RvvInt16m4:
-case clang::BuiltinType::RvvInt16m8:
-case clang::BuiltinType::RvvUint16mf4:
-case clang::BuiltinType::RvvUint16mf2:
-case clang::BuiltinType::RvvUint16m1:
-case clang::BuiltinType::RvvUint16m2:
-case clang::BuiltinType::RvvUint16m4:
-case clang::BuiltinType::RvvUint16m8:
-case clang::BuiltinType::RvvInt32mf2:
-case clang::BuiltinType::RvvInt32m1:
-case clang::BuiltinType::RvvInt32m2:
-case clang::BuiltinType::RvvInt32m4:
-case clang::BuiltinType::RvvInt32m8:
-case clang::BuiltinType::RvvUint32mf2:
-case clang::BuiltinType::RvvUint32m1:
-case clang::BuiltinType::RvvUint32m2:
-case clang::BuiltinType::RvvUint32m4:
-case clang::BuiltinType::RvvUint32m8:
-case clang::BuiltinType::RvvInt64m1:
-case clang::BuiltinType::RvvInt64m2:
-case clang::BuiltinType::RvvInt64m4:
-case clang::BuiltinType::RvvInt64m8:
-case clang::BuiltinType::RvvUint64m1:
-case clang::BuiltinType::RvvUint64m2:
-case clang::BuiltinType::RvvUint64m4:
-case clang::BuiltinType::RvvUint64m8:
-case clang::BuiltinType::RvvFloat16mf4:
-case clang::BuiltinType::RvvFloat16mf2:
-case clang::BuiltinType::RvvFloat16m1:
-case clang::BuiltinType::RvvFloat16m2:
-case clang::BuiltinType::RvvFloat16m4:
-case clang::BuiltinType::RvvFloat16m8:
-case clang::BuiltinType::RvvFloat32mf2:
-case clang::BuiltinType::RvvFloat32m1:
-case clang::BuiltinType::RvvFloat32m2:
-case clang::BuiltinType::RvvFloat32m4:
-case clang::BuiltinType::RvvFloat32m8:
-case clang::BuiltinType::RvvFloat64m1:
-case clang::BuiltinType::RvvFloat64m2:
-case clang::BuiltinType::RvvFloat64m4:
-case clang::BuiltinType::RvvFloat64m8:
-case clang::BuiltinType::RvvBool1:
-case clang::BuiltinType::RvvBool2:
-case clang::BuiltinType::RvvBool4:
-case clang::BuiltinType::RvvBool8:
-case clang::BuiltinType::RvvBool16:
-case clang::BuiltinType::RvvBool32:
-case clang::BuiltinType::RvvBool64:
-case clang::BuiltinType::RvvInt32m1x2:
+#define RVV_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id:
+#include "clang/Basic/RISCVVTypes.def"
   break;
 
 // WebAssembly builtin types.


Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -5041,73 +5041,8 @@
   break;
 
 // RISC-V V builtin types.
-case clang::BuiltinType::RvvInt8mf8:
-case clang::BuiltinType::RvvInt8mf4:
-case clang::BuiltinType::RvvInt8mf2:
-case clang::BuiltinType::RvvInt8m1:
-case clang::BuiltinType::RvvInt8m2:
-case clang::BuiltinType::RvvInt8m4:
-case clang::BuiltinType::RvvInt8m8:
-case clang::BuiltinType::RvvUint8mf8:
-case clang::BuiltinType::RvvUint8mf4:
-case clang::BuiltinType::RvvUint8mf2:
-case clang::BuiltinType::RvvUint8m1:
-case clang::BuiltinType::RvvUint8m2:
-case clang::BuiltinType::RvvUint8m4:
-case clang::BuiltinType::RvvUint8m8:
-case clang::BuiltinType::RvvInt16mf4:
-case clang::BuiltinType::RvvInt16mf2:

[Lldb-commits] [PATCH] D152918: [lldb] Add register field tables to the "register info" command

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

This is the major use case for the command. With these diagrams matching the 
architecture manual (mostly) you can use them to work out what mask/shift you 
need. You'll be able to print a register, see that the field isn't the right 
value, then "register info" and realise what you did wrong. The audience for it 
is small but when I was one of that audience (different debugger though) I 
really appreciated not having to leave the debugger to do this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152918

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


[Lldb-commits] [PATCH] D152916: [lldb] Add "register info" command

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

I think "info" is a fairly safe name for this command. I thought about 
"register help" but then you could do "help register help" and while that's 
amusing it's also pretty silly.

You might think at a glance "info" does something like check the register's 
value for symbols, but we have other things in lldb to do that so I don't think 
it's confusing once you look at the help or see the command output.

It could do multiple registers but my use case is one off cases where you are 
sanity checking an assumption, perhaps learning a new extension or 
architecture. Not throwing a list of registers at it like you might "register 
read".  Easy to add later if needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152916

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


[Lldb-commits] [PATCH] D152916: [lldb] Add "register info" command

2023-06-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added reviewers: jasonmolenda, labath, JDevlieghere.
DavidSpickett added inline comments.



Comment at: lldb/source/Core/DumpRegisterInfo.cpp:84
+
+void lldb_private::DoDumpRegisterInfo(
+Stream , const char *name, const char *alt_name, uint32_t byte_size,

This is split out to make testing easier.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152916

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


[Lldb-commits] [PATCH] D152918: [lldb] Add register field tables to the "register info" command

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

This teaches DumpRegisterInfo to generate a table from the register
flags type. It just calls a method on RegisterFlags.

As such, the extra tests are minimal and only show that the intergration
works. Exhaustive formatting tests are done with RegisterFlags itself.

Example:

  (lldb) register info cpsr
 Name: cpsr
 Size: 4 bytes (32 bits)
  In sets: general (index 0)
  
  | 31 | 30 | 29 | 28 | 27-26 | 25  | 24  | 23  | 22  | 21 | 20 | 19-13 |  12  
| 11-10 | 9 | 8 | 7 | 6 | 5 |  4  | 3-2 | 1 | 0  |
  
|||||---|-|-|-|-|||---|--|---|---|---|---|---|---|-|-|---||
  | N  | Z  | C  | V  |   | TCO | DIT | UAO | PAN | SS | IL |   | SSBS 
|   | D | A | I | F |   | nRW | EL  |   | SP |

LLDB limits the max terminal width to 80 chars by default.
So to get that full width output you will need to change the "term-width"
setting to something higher.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152918

Files:
  lldb/include/lldb/Core/DumpRegisterInfo.h
  lldb/source/Commands/CommandObjectRegister.cpp
  lldb/source/Core/DumpRegisterInfo.cpp
  lldb/test/API/commands/register/register/register_command/TestRegisters.py
  lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py
  lldb/unittests/Core/DumpRegisterInfoTest.cpp

Index: lldb/unittests/Core/DumpRegisterInfoTest.cpp
===
--- lldb/unittests/Core/DumpRegisterInfoTest.cpp
+++ lldb/unittests/Core/DumpRegisterInfoTest.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "lldb/Core/DumpRegisterInfo.h"
+#include "lldb/Target/RegisterFlags.h"
 #include "lldb/Utility/StreamString.h"
 #include "gtest/gtest.h"
 
@@ -14,27 +15,28 @@
 
 TEST(DoDumpRegisterInfoTest, MinimumInfo) {
   StreamString strm;
-  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {});
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {}, nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)");
 }
 
 TEST(DoDumpRegisterInfoTest, AltName) {
   StreamString strm;
-  DoDumpRegisterInfo(strm, "foo", "bar", 4, {}, {}, {});
+  DoDumpRegisterInfo(strm, "foo", "bar", 4, {}, {}, {}, nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo (bar)\n"
   "   Size: 4 bytes (32 bits)");
 }
 
 TEST(DoDumpRegisterInfoTest, Invalidates) {
   StreamString strm;
-  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2"}, {}, {});
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2"}, {}, {}, nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)\n"
   "Invalidates: foo2");
 
   strm.Clear();
-  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3", "foo4"}, {}, {});
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3", "foo4"}, {}, {},
+ nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)\n"
   "Invalidates: foo2, foo3, foo4");
@@ -42,13 +44,14 @@
 
 TEST(DoDumpRegisterInfoTest, ReadFrom) {
   StreamString strm;
-  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1"}, {});
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1"}, {}, nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)\n"
   "  Read from: foo1");
 
   strm.Clear();
-  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1", "foo2", "foo3"}, {});
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1", "foo2", "foo3"}, {},
+ nullptr, 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)\n"
   "  Read from: foo1, foo2, foo3");
@@ -56,14 +59,15 @@
 
 TEST(DoDumpRegisterInfoTest, InSets) {
   StreamString strm;
-  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {{"set1", 101}});
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {{"set1", 101}}, nullptr,
+ 0);
   ASSERT_EQ(strm.GetString(), "   Name: foo\n"
   "   Size: 4 bytes (32 bits)\n"
   "In sets: set1 (index 101)");
 
   strm.Clear();
   DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {},
- {{"set1", 0}, {"set2", 1}, {"set3", 2}});
+ {{"set1", 0}, {"set2", 1}, {"set3", 2}}, nullptr, 0);
   ASSERT_EQ(strm.GetString(),
 "   Name: foo\n"

[Lldb-commits] [PATCH] D152917: [LLDB] Add table formatting for register fields

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

I'm  aware we likely have 10s of adhoc table printing functions across llvm and 
I'm surprised someone hasn't unified them yet. Which is to say, today I am not 
that person though I would like to collect a list of places that could benefit 
from it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152917

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


[Lldb-commits] [PATCH] D152917: [LLDB] Add table formatting for register fields

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

This will be used by the "register info" command to show
the layout of register contents. For example if we have
these fields coming in from XML:

  
  
  
  

We get:

  | 31-24 | 23-16 | 15-8 | 7-0 |
  |---|---|--|-|
  |   A   |   B   |  C   |  D  |

Note that this is only the layout, not the values.
For values, use "register read".

The tables' columns are center padded (left bias
if there's an odd padding) and will wrap if the terminal width
is too low.

  | 31-24 | 23-16 |
  |---|---|
  |   A   |   B   |
  
  | 15-8 | 7-0 |
  |--|-|
  |  C   |  D  |

This means we match the horizontal format seen in many architecture
manuals but don't spam the user with lots of misaligned text when the
output gets very long.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152917

Files:
  lldb/include/lldb/Target/RegisterFlags.h
  lldb/source/Target/RegisterFlags.cpp
  lldb/unittests/Target/RegisterFlagsTest.cpp

Index: lldb/unittests/Target/RegisterFlagsTest.cpp
===
--- lldb/unittests/Target/RegisterFlagsTest.cpp
+++ lldb/unittests/Target/RegisterFlagsTest.cpp
@@ -137,3 +137,121 @@
  make_field(28, 28)});
   ASSERT_EQ(0x0005ULL, rf3.ReverseFieldOrder(0xA000));
 }
+
+TEST(RegisterFlagsTest, AsTable) {
+  // Anonymous fields are shown with an empty name cell,
+  // whether they are known up front or added during construction.
+  RegisterFlags anon_field("", 4, {make_field(0, 31)});
+  ASSERT_EQ("| 31-0 |\n"
+"|--|\n"
+"|  |",
+anon_field.AsTable(100));
+
+  RegisterFlags anon_with_pad("", 4, {make_field(16, 31)});
+  ASSERT_EQ("| 31-16 | 15-0 |\n"
+"|---|--|\n"
+"|   |  |",
+anon_with_pad.AsTable(100));
+
+  // Use the wider of position and name to set the column width.
+  RegisterFlags name_wider("", 4, {RegisterFlags::Field("aardvark", 0, 31)});
+  ASSERT_EQ("|   31-0   |\n"
+"|--|\n"
+"| aardvark |",
+name_wider.AsTable(100));
+  // When the padding is an odd number, put the remaining 1 on the right.
+  RegisterFlags pos_wider("", 4, {RegisterFlags::Field("?", 0, 31)});
+  ASSERT_EQ("| 31-0 |\n"
+"|--|\n"
+"|  ?   |",
+pos_wider.AsTable(100));
+
+  // Single bit fields don't need to show start and end, just one of them.
+  RegisterFlags single_bit("", 4, {make_field(31, 31)});
+  ASSERT_EQ("| 31 | 30-0 |\n"
+"||--|\n"
+"||  |",
+single_bit.AsTable(100));
+
+  // Columns are printed horizontally if max width allows.
+  RegisterFlags many_fields("", 4,
+{RegisterFlags::Field("cat", 28, 31),
+ RegisterFlags::Field("pigeon", 20, 23),
+ RegisterFlags::Field("wolf", 12, 12),
+ RegisterFlags::Field("x", 0, 4)});
+  ASSERT_EQ("| 31-28 | 27-24 | 23-20  | 19-13 |  12  | 11-5 | 4-0 |\n"
+"|---|---||---|--|--|-|\n"
+"|  cat  |   | pigeon |   | wolf |  |  x  |",
+many_fields.AsTable(100));
+
+  // max_width tells us when we need to split into further tables.
+  // Here no split is needed.
+  RegisterFlags exact_max_single_col("", 4, {RegisterFlags::Field("?", 0, 31)});
+  ASSERT_EQ("| 31-0 |\n"
+"|--|\n"
+"|  ?   |",
+exact_max_single_col.AsTable(9));
+  RegisterFlags exact_max_two_col(
+  "", 4,
+  {RegisterFlags::Field("?", 16, 31), RegisterFlags::Field("#", 0, 15)});
+  ASSERT_EQ("| 31-16 | 15-0 |\n"
+"|---|--|\n"
+"|   ?   |  #   |",
+exact_max_two_col.AsTable(16));
+
+  // If max is less than a single column, just print the single column. The user
+  // will have to put up with some wrapping in this niche case.
+  RegisterFlags zero_max_single_col("", 4, {RegisterFlags::Field("?", 0, 31)});
+  ASSERT_EQ("| 31-0 |\n"
+"|--|\n"
+"|  ?   |",
+zero_max_single_col.AsTable(0));
+  // Same logic for any following columns. Effectively making a "vertical"
+  // table, just with more grid lines.
+  RegisterFlags zero_max_two_col(
+  "", 4,
+  {RegisterFlags::Field("?", 16, 31), RegisterFlags::Field("#", 0, 15)});
+  ASSERT_EQ("| 31-16 |\n"
+"|---|\n"
+"|   ?   |\n"
+"\n"
+"| 15-0 |\n"
+"|--|\n"
+"|  #   |",
+zero_max_two_col.AsTable(0));
+
+  RegisterFlags max_less_than_single_col("", 4,
+ {RegisterFlags::Field("?", 0, 31)});

[Lldb-commits] [PATCH] D152916: [lldb] Add "register info" command

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

This adds a new command that will show all the information lldb
knows about a register.

  (lldb) register info s0
 Name: s0
 Size: 4 bytes (32 bits)
  Invalidates: v0, d0
Read from: v0
  In sets: Floating Point Registers (index 1)

Currently it only allows a single register, and we get the
information from the RegisterInfo structure.

For those of us who know the architecture well, this information
is all pretty obvious. For those who don't, it's nice to have it
at a glance without leaving the debugger.

I hope to have more in depth information to show here in the future,
which will be of wider use.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152916

Files:
  lldb/include/lldb/Core/DumpRegisterInfo.h
  lldb/source/Commands/CommandObjectRegister.cpp
  lldb/source/Core/CMakeLists.txt
  lldb/source/Core/DumpRegisterInfo.cpp
  lldb/test/API/commands/register/register/register_command/TestRegisters.py
  lldb/unittests/Core/CMakeLists.txt
  lldb/unittests/Core/DumpRegisterInfoTest.cpp

Index: lldb/unittests/Core/DumpRegisterInfoTest.cpp
===
--- /dev/null
+++ lldb/unittests/Core/DumpRegisterInfoTest.cpp
@@ -0,0 +1,82 @@
+//===-- DumpRegisterInfoTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Core/DumpRegisterInfo.h"
+#include "lldb/Utility/StreamString.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+
+TEST(DoDumpRegisterInfoTest, MinimumInfo) {
+  StreamString strm;
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)");
+}
+
+TEST(DoDumpRegisterInfoTest, AltName) {
+  StreamString strm;
+  DoDumpRegisterInfo(strm, "foo", "bar", 4, {}, {}, {});
+  ASSERT_EQ(strm.GetString(), "   Name: foo (bar)\n"
+  "   Size: 4 bytes (32 bits)");
+}
+
+TEST(DoDumpRegisterInfoTest, Invalidates) {
+  StreamString strm;
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2"}, {}, {});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)\n"
+  "Invalidates: foo2");
+
+  strm.Clear();
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3", "foo4"}, {}, {});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)\n"
+  "Invalidates: foo2, foo3, foo4");
+}
+
+TEST(DoDumpRegisterInfoTest, ReadFrom) {
+  StreamString strm;
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1"}, {});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)\n"
+  "  Read from: foo1");
+
+  strm.Clear();
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {"foo1", "foo2", "foo3"}, {});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)\n"
+  "  Read from: foo1, foo2, foo3");
+}
+
+TEST(DoDumpRegisterInfoTest, InSets) {
+  StreamString strm;
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {}, {{"set1", 101}});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)\n"
+  "In sets: set1 (index 101)");
+
+  strm.Clear();
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {}, {},
+ {{"set1", 0}, {"set2", 1}, {"set3", 2}});
+  ASSERT_EQ(strm.GetString(),
+"   Name: foo\n"
+"   Size: 4 bytes (32 bits)\n"
+"In sets: set1 (index 0), set2 (index 1), set3 (index 2)");
+}
+
+TEST(DoDumpRegisterInfoTest, MaxInfo) {
+  StreamString strm;
+  DoDumpRegisterInfo(strm, "foo", nullptr, 4, {"foo2", "foo3"},
+ {"foo3", "foo4"}, {{"set1", 1}, {"set2", 2}});
+  ASSERT_EQ(strm.GetString(), "   Name: foo\n"
+  "   Size: 4 bytes (32 bits)\n"
+  "Invalidates: foo2, foo3\n"
+  "  Read from: foo3, foo4\n"
+  "In sets: set1 (index 1), set2 (index 2)");
+}
Index: lldb/unittests/Core/CMakeLists.txt
===
--- lldb/unittests/Core/CMakeLists.txt
+++ lldb/unittests/Core/CMakeLists.txt
@@ -2,6 

[Lldb-commits] [PATCH] D152846: [lldb][NFCI] Remove custom matcher classes in Listener in favor of lambdas

2023-06-14 Thread Felipe de Azevedo Piovezan via Phabricator via lldb-commits
fdeazeve accepted this revision.
fdeazeve added a comment.
This revision is now accepted and ready to land.

Nice catch! Also agree with the suggestion of using the STLExtras wrapper


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152846

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


[Lldb-commits] [PATCH] D152519: [lldb][AArch64] Add Scalable Matrix Extension option to QEMU launch script

2023-06-14 Thread David Spickett via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG01e30b30d09a: [lldb][AArch64] Add Scalable Matrix Extension 
option to QEMU launch script (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152519

Files:
  lldb/docs/use/qemu-testing.rst
  lldb/scripts/lldb-test-qemu/run-qemu.sh


Index: lldb/scripts/lldb-test-qemu/run-qemu.sh
===
--- lldb/scripts/lldb-test-qemu/run-qemu.sh
+++ lldb/scripts/lldb-test-qemu/run-qemu.sh
@@ -6,7 +6,8 @@
   echo -e "  --help\t\t\tDisplay this information."
   echo -e "  --arch {arm|arm64}\t\tSelects architecture QEMU system emulation."
   echo -e "  --sve\t\t\t\tEnables AArch64 SVE mode."
-  echo -e "  --mte\t\t\t\tEnables AArch64 MTE mode.\n"
+  echo -e "  --mte\t\t\t\tEnables AArch64 MTE mode."
+  echo -e "  --sme\t\t\t\tEnables AArch64 SME mode."
   echo -e "  --rootfs {path}\t\tPath of root file system image."
   echo -e "  --qemu {path}\t\t\tPath of pre-installed qemu-system-* 
executable."
   echo -e "  --kernel {path}\t\tPath of Linux kernel prebuilt image.\n"
@@ -50,6 +51,7 @@
 --qemu) QEMU_BIN=$2; shift;;
 --sve)  SVE=1;;
 --mte)  MTE=1;;
+--sme)  SME=1;;
 --help) print_usage 0 ;;
 *)  invalid_arg "$1" ;;
   esac
@@ -104,16 +106,19 @@
   if [[ $MTE ]]; then
 echo "warning: --mte is supported by AArch64 targets only"
   fi
+  if [[ $SME ]]; then
+echo "warning: --sme is supported by AArch64 targets only"
+  fi
 elif [[ "$ARCH" == "arm64" ]]; then
   QEMU_MACHINE=virt
   QEMU_SVE_MAX_VQ=4
   QEMU_CPU="cortex-a53"
 
-  if [[ $SVE ]] || [[ $MTE ]]; then
+  if [[ $SVE ]] || [[ $MTE ]] || [[ $SME ]]; then
 QEMU_CPU="max"
   fi
 
-  if [[ $SVE ]]; then
+  if [[ $SVE ]] || [[ $SME ]]; then
 QEMU_CPU="$QEMU_CPU,sve-max-vq=$QEMU_SVE_MAX_VQ"
   fi
   if [[ $MTE ]]; then
Index: lldb/docs/use/qemu-testing.rst
===
--- lldb/docs/use/qemu-testing.rst
+++ lldb/docs/use/qemu-testing.rst
@@ -93,8 +93,11 @@
 
 * --sve option will enable AArch64 SVE mode.
 
-* --mte option will enable AArch64 MTE (memory tagging) mode.
-  (can be used on its own or in addition to --sve)
+* --sme option will enable AArch64 SME mode (SME requires SVE, so this will 
also
+  be enabled).
+
+* --mte option will enable AArch64 MTE (memory tagging) mode
+  (can be used on its own or in addition to --sve).
 
 
 **Example:** Run QEMU Arm or AArch64 system emulation using run-qemu.sh


Index: lldb/scripts/lldb-test-qemu/run-qemu.sh
===
--- lldb/scripts/lldb-test-qemu/run-qemu.sh
+++ lldb/scripts/lldb-test-qemu/run-qemu.sh
@@ -6,7 +6,8 @@
   echo -e "  --help\t\t\tDisplay this information."
   echo -e "  --arch {arm|arm64}\t\tSelects architecture QEMU system emulation."
   echo -e "  --sve\t\t\t\tEnables AArch64 SVE mode."
-  echo -e "  --mte\t\t\t\tEnables AArch64 MTE mode.\n"
+  echo -e "  --mte\t\t\t\tEnables AArch64 MTE mode."
+  echo -e "  --sme\t\t\t\tEnables AArch64 SME mode."
   echo -e "  --rootfs {path}\t\tPath of root file system image."
   echo -e "  --qemu {path}\t\t\tPath of pre-installed qemu-system-* executable."
   echo -e "  --kernel {path}\t\tPath of Linux kernel prebuilt image.\n"
@@ -50,6 +51,7 @@
 --qemu) QEMU_BIN=$2; shift;;
 --sve)  SVE=1;;
 --mte)  MTE=1;;
+--sme)  SME=1;;
 --help) print_usage 0 ;;
 *)  invalid_arg "$1" ;;
   esac
@@ -104,16 +106,19 @@
   if [[ $MTE ]]; then
 echo "warning: --mte is supported by AArch64 targets only"
   fi
+  if [[ $SME ]]; then
+echo "warning: --sme is supported by AArch64 targets only"
+  fi
 elif [[ "$ARCH" == "arm64" ]]; then
   QEMU_MACHINE=virt
   QEMU_SVE_MAX_VQ=4
   QEMU_CPU="cortex-a53"
 
-  if [[ $SVE ]] || [[ $MTE ]]; then
+  if [[ $SVE ]] || [[ $MTE ]] || [[ $SME ]]; then
 QEMU_CPU="max"
   fi
 
-  if [[ $SVE ]]; then
+  if [[ $SVE ]] || [[ $SME ]]; then
 QEMU_CPU="$QEMU_CPU,sve-max-vq=$QEMU_SVE_MAX_VQ"
   fi
   if [[ $MTE ]]; then
Index: lldb/docs/use/qemu-testing.rst
===
--- lldb/docs/use/qemu-testing.rst
+++ lldb/docs/use/qemu-testing.rst
@@ -93,8 +93,11 @@
 
 * --sve option will enable AArch64 SVE mode.
 
-* --mte option will enable AArch64 MTE (memory tagging) mode.
-  (can be used on its own or in addition to --sve)
+* --sme option will enable AArch64 SME mode (SME requires SVE, so this will also
+  be enabled).
+
+* --mte option will enable AArch64 MTE (memory tagging) mode
+  (can be used on its own or in addition to --sve).
 
 
 **Example:** Run QEMU Arm or AArch64 system emulation using run-qemu.sh
___
lldb-commits mailing list
lldb-commits@lists.llvm.org

[Lldb-commits] [lldb] 01e30b3 - [lldb][AArch64] Add Scalable Matrix Extension option to QEMU launch script

2023-06-14 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2023-06-14T14:33:47+01:00
New Revision: 01e30b30d09aca13819b40bfeff634e776e2b564

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

LOG: [lldb][AArch64] Add Scalable Matrix Extension option to QEMU launch script

The Scalable Matrix Extension (SME) does not require extra options
beyond setting the cpu to "max".

https://qemu-project.gitlab.io/qemu/system/arm/cpu-features.html#sme-cpu-property-examples

SME depends on SVE, so that will be enabled too even if you don't ask
for it by name.

--sve --sme -> SVE and SME
--sme   -> SVE and SME
--sve   -> Only SVE

Reviewed By: omjavaid

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

Added: 


Modified: 
lldb/docs/use/qemu-testing.rst
lldb/scripts/lldb-test-qemu/run-qemu.sh

Removed: 




diff  --git a/lldb/docs/use/qemu-testing.rst b/lldb/docs/use/qemu-testing.rst
index a523137c8710b..f765d5ca9600b 100644
--- a/lldb/docs/use/qemu-testing.rst
+++ b/lldb/docs/use/qemu-testing.rst
@@ -93,8 +93,11 @@ run-qemu.sh has following dependencies:
 
 * --sve option will enable AArch64 SVE mode.
 
-* --mte option will enable AArch64 MTE (memory tagging) mode.
-  (can be used on its own or in addition to --sve)
+* --sme option will enable AArch64 SME mode (SME requires SVE, so this will 
also
+  be enabled).
+
+* --mte option will enable AArch64 MTE (memory tagging) mode
+  (can be used on its own or in addition to --sve).
 
 
 **Example:** Run QEMU Arm or AArch64 system emulation using run-qemu.sh

diff  --git a/lldb/scripts/lldb-test-qemu/run-qemu.sh 
b/lldb/scripts/lldb-test-qemu/run-qemu.sh
index d11711c10e772..6dca03aab28e2 100755
--- a/lldb/scripts/lldb-test-qemu/run-qemu.sh
+++ b/lldb/scripts/lldb-test-qemu/run-qemu.sh
@@ -6,7 +6,8 @@ print_usage() {
   echo -e "  --help\t\t\tDisplay this information."
   echo -e "  --arch {arm|arm64}\t\tSelects architecture QEMU system emulation."
   echo -e "  --sve\t\t\t\tEnables AArch64 SVE mode."
-  echo -e "  --mte\t\t\t\tEnables AArch64 MTE mode.\n"
+  echo -e "  --mte\t\t\t\tEnables AArch64 MTE mode."
+  echo -e "  --sme\t\t\t\tEnables AArch64 SME mode."
   echo -e "  --rootfs {path}\t\tPath of root file system image."
   echo -e "  --qemu {path}\t\t\tPath of pre-installed qemu-system-* 
executable."
   echo -e "  --kernel {path}\t\tPath of Linux kernel prebuilt image.\n"
@@ -50,6 +51,7 @@ while [[ $# -gt 0 ]]; do
 --qemu) QEMU_BIN=$2; shift;;
 --sve)  SVE=1;;
 --mte)  MTE=1;;
+--sme)  SME=1;;
 --help) print_usage 0 ;;
 *)  invalid_arg "$1" ;;
   esac
@@ -104,16 +106,19 @@ if [[ "$ARCH" == "arm" ]]; then
   if [[ $MTE ]]; then
 echo "warning: --mte is supported by AArch64 targets only"
   fi
+  if [[ $SME ]]; then
+echo "warning: --sme is supported by AArch64 targets only"
+  fi
 elif [[ "$ARCH" == "arm64" ]]; then
   QEMU_MACHINE=virt
   QEMU_SVE_MAX_VQ=4
   QEMU_CPU="cortex-a53"
 
-  if [[ $SVE ]] || [[ $MTE ]]; then
+  if [[ $SVE ]] || [[ $MTE ]] || [[ $SME ]]; then
 QEMU_CPU="max"
   fi
 
-  if [[ $SVE ]]; then
+  if [[ $SVE ]] || [[ $SME ]]; then
 QEMU_CPU="$QEMU_CPU,sve-max-vq=$QEMU_SVE_MAX_VQ"
   fi
   if [[ $MTE ]]; then



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


[Lldb-commits] [PATCH] D152872: Add support for __debug_line_str in Mach-O

2023-06-14 Thread Felipe de Azevedo Piovezan via Phabricator via lldb-commits
fdeazeve accepted this revision.
fdeazeve added a comment.

Nice and subtle fix! :)


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

https://reviews.llvm.org/D152872

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


[Lldb-commits] [PATCH] D152519: [lldb][AArch64] Add Scalable Matrix Extension option to QEMU launch script

2023-06-14 Thread Muhammad Omair Javaid via Phabricator via lldb-commits
omjavaid accepted this revision.
omjavaid added a comment.
This revision is now accepted and ready to land.

This looks good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152519

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


[Lldb-commits] [PATCH] D152863: [lldb] NFC Add Process methods to Fix.*Address, to simplify this bit clearing across the codebase

2023-06-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett accepted this revision.
DavidSpickett added a comment.
This revision is now accepted and ready to land.

LGTM. Sinking the whole `if abi` dance into these methods will clean up a lot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152863

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


[Lldb-commits] [PATCH] D152861: Clear non-addressable bits from fp/sp/lr/pc values in RegisterContextUnwind

2023-06-14 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett accepted this revision.
DavidSpickett added a comment.
This revision is now accepted and ready to land.

I'm curious how you would end up with a signed PC value, but given this is 
unwind it could be a value from a previous frame that was signed when stored to 
the stack.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152861

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


[Lldb-commits] [PATCH] D152855: [lldb][Android] Add PlatformAndroidTest

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531198.
splhack added a comment.
Herald added a subscriber: JDevlieghere.

sync with D152759  new version


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152855

Files:
  lldb/source/Plugins/Platform/Android/AdbClient.h
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.h
  lldb/unittests/Platform/Android/CMakeLists.txt
  lldb/unittests/Platform/Android/PlatformAndroidTest.cpp

Index: lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
===
--- /dev/null
+++ lldb/unittests/Platform/Android/PlatformAndroidTest.cpp
@@ -0,0 +1,154 @@
+//===-- PlatformAndroidTest.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 "Plugins/Platform/Android/PlatformAndroid.h"
+#include "Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Utility/Connection.h"
+#include "gmock/gmock.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_android;
+using namespace testing;
+
+namespace {
+
+class MockSyncService : public AdbClient::SyncService {
+public:
+  MockSyncService() : SyncService(std::move(m_mock_conn)) {}
+
+  MOCK_METHOD2(PullFile,
+   Status(const FileSpec _file, const FileSpec _file));
+  MOCK_METHOD4(Stat, Status(const FileSpec _file, uint32_t ,
+uint32_t , uint32_t ));
+
+private:
+  std::unique_ptr m_mock_conn;
+};
+
+typedef std::unique_ptr SyncServiceSP;
+
+class MockAdbClient : public AdbClient {
+public:
+  explicit MockAdbClient() : AdbClient("mock") {}
+
+  MOCK_METHOD3(ShellToFile,
+   Status(const char *command, std::chrono::milliseconds timeout,
+  const FileSpec _file_spec));
+  MOCK_METHOD1(GetSyncService, SyncServiceSP(Status ));
+};
+
+class PlatformAndroidTest : public PlatformAndroid, public ::testing::Test {
+public:
+  PlatformAndroidTest() : PlatformAndroid(false) {
+m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
+  }
+
+  MOCK_METHOD0(GetAdbClient, AdbClientSP());
+};
+
+} // namespace
+
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithNormalFile) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(*sync_service, Stat(FileSpec("/system/lib64/libc.so"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(1), Return(Status(;
+  EXPECT_CALL(*sync_service, PullFile(FileSpec("/system/lib64/libc.so"), _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(FileSpec("/system/lib64/libc.so"), 0, 0, FileSpec())
+  .Success());
+}
+
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithZipFile) {
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client,
+  ShellToFile(StrEq("dd if='/system/app/Test/Test.apk' "
+"iflag=skip_bytes,count_bytes "
+"skip=4096 count=3600 status=none"),
+  _, _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(
+  FileSpec("/system/app/Test/Test.apk!/lib/arm64-v8a/libtest.so"), 4096,
+  3600, FileSpec())
+  .Success());
+}
+
+TEST_F(PlatformAndroidTest, GetFileWithNormalFile) {
+  auto sync_service = new MockSyncService();
+  EXPECT_CALL(*sync_service, Stat(FileSpec("/data/local/tmp/test"), _, _, _))
+  .Times(1)
+  .WillOnce(DoAll(SetArgReferee<1>(1), Return(Status(;
+  EXPECT_CALL(*sync_service, PullFile(FileSpec("/data/local/tmp/test"), _))
+  .Times(1)
+  .WillOnce(Return(Status()));
+
+  auto adb_client = new MockAdbClient();
+  EXPECT_CALL(*adb_client, GetSyncService(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(SyncServiceSP(sync_service);
+
+  EXPECT_CALL(*this, GetAdbClient())
+  .Times(1)
+  .WillOnce(Return(ByMove(std::move(AdbClientSP(adb_client);
+
+  

[Lldb-commits] [PATCH] D152759: [lldb][Android] Support zip .so file

2023-06-14 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531195.
splhack added a comment.

- ZipFile: zip file parser in Utility
  - include/lldb/Utility/ZipFile.h
  - source/Utility/ZipFile.cpp

- ZipFileResolver: bionic zip .so file resolver, depends on Host::FileSystem
  - include/lldb/Host/common/ZipFileResolver.h
  - source/Host/common/ZipFileResolver.cpp

- ZipFileResolverTest
  - unittests/Host/common


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152759

Files:
  lldb/include/lldb/Host/common/ZipFileResolver.h
  lldb/include/lldb/Utility/ZipFile.h
  lldb/source/Host/CMakeLists.txt
  lldb/source/Host/common/ZipFileResolver.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/ZipFile.cpp
  lldb/unittests/Host/CMakeLists.txt
  lldb/unittests/Host/common/CMakeLists.txt
  lldb/unittests/Host/common/Inputs/zip-test.zip
  lldb/unittests/Host/common/ZipFileResolverTest.cpp

Index: lldb/unittests/Host/common/ZipFileResolverTest.cpp
===
--- /dev/null
+++ lldb/unittests/Host/common/ZipFileResolverTest.cpp
@@ -0,0 +1,72 @@
+//===-- ZipFileResolverTest.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/Host/common/ZipFileResolver.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace llvm;
+
+namespace {
+class ZipFileResolverTest : public ::testing::Test {
+  SubsystemRAII subsystems;
+};
+
+std::string TestZipPath() {
+  FileSpec zip_spec(GetInputFilePath("zip-test.zip"));
+  FileSystem::Instance().Resolve(zip_spec);
+  return zip_spec.GetPath();
+}
+} // namespace
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithNormalFile) {
+  const FileSpec file_spec("/system/lib64/libtest.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_TRUE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+
+  EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindNormal);
+  EXPECT_EQ(file_path, file_spec.GetPath());
+  EXPECT_EQ(file_offset, 0UL);
+  EXPECT_EQ(file_size, 0UL);
+}
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithZipMissing) {
+  const std::string zip_path = TestZipPath();
+  const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libmissing.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_FALSE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+}
+
+TEST_F(ZipFileResolverTest, ResolveBionicPathWithZipExisting) {
+  const std::string zip_path = TestZipPath();
+  const FileSpec file_spec(zip_path + "!/lib/arm64-v8a/libzip-test.so");
+
+  ZipFileResolver::FileKind file_kind;
+  std::string file_path;
+  lldb::offset_t file_offset;
+  lldb::offset_t file_size;
+  ASSERT_TRUE(ZipFileResolver::ResolveBionicPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+
+  EXPECT_EQ(file_kind, ZipFileResolver::FileKind::eFileKindZip);
+  EXPECT_EQ(file_path, zip_path);
+  EXPECT_EQ(file_offset, 4096UL);
+  EXPECT_EQ(file_size, 3600UL);
+}
Index: lldb/unittests/Host/common/CMakeLists.txt
===
--- /dev/null
+++ lldb/unittests/Host/common/CMakeLists.txt
@@ -0,0 +1,15 @@
+set (FILES
+  ZipFileResolverTest.cpp
+)
+
+add_lldb_unittest(HostCommonTests
+  ${FILES}
+  LINK_LIBS
+lldbHost
+lldbUtilityHelpers
+  )
+
+set(test_inputs
+  zip-test.zip
+  )
+add_unittest_inputs(HostCommonTests "${test_inputs}")
Index: lldb/unittests/Host/CMakeLists.txt
===
--- lldb/unittests/Host/CMakeLists.txt
+++ lldb/unittests/Host/CMakeLists.txt
@@ -38,3 +38,5 @@
 LLVMTestingSupport
 LLVMTargetParser
   )
+
+add_subdirectory(common)
Index: lldb/source/Utility/ZipFile.cpp
===
--- /dev/null
+++ lldb/source/Utility/ZipFile.cpp
@@ -0,0 +1,180 @@
+//===-- ZipFile.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
+//