[Lldb-commits] [PATCH] D153177: [lldb][NFCI] Remove ConstString from GDBRemoteCommunicationClient::ConfigureRemoteStructuredData

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

ConstString's benefits are not being utilized here, StringRef is
sufficient.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153177

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


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -492,7 +492,7 @@
   ///
   /// \see \b Process::ConfigureStructuredData(...) for details.
   Status
-  ConfigureRemoteStructuredData(ConstString type_name,
+  ConfigureRemoteStructuredData(llvm::StringRef type_name,
 const StructuredData::ObjectSP _sp);
 
   llvm::Expected
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -4171,10 +4171,10 @@
 }
 
 Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
-ConstString type_name, const StructuredData::ObjectSP _sp) {
+llvm::StringRef type_name, const StructuredData::ObjectSP _sp) {
   Status error;
 
-  if (type_name.GetLength() == 0) {
+  if (type_name.empty()) {
 error.SetErrorString("invalid type_name argument");
 return error;
   }
@@ -4182,7 +4182,7 @@
   // Build command: Configure{type_name}: serialized config data.
   StreamGDBRemote stream;
   stream.PutCString("QConfigure");
-  stream.PutCString(type_name.GetStringRef());
+  stream.PutCString(type_name);
   stream.PutChar(':');
   if (config_sp) {
 // Gather the plain-text version of the configuration data.
@@ -4201,21 +4201,20 @@
   auto result = SendPacketAndWaitForResponse(stream.GetString(), response);
   if (result == PacketResult::Success) {
 // We failed if the config result comes back other than OK.
-if (strcmp(response.GetStringRef().data(), "OK") == 0) {
+if (response.GetStringRef() == "OK") {
   // Okay!
   error.Clear();
 } else {
-  error.SetErrorStringWithFormat("configuring StructuredData feature "
- "%s failed with error %s",
- type_name.AsCString(),
- response.GetStringRef().data());
+  error.SetErrorStringWithFormatv(
+  "configuring StructuredData feature {0} failed with error {1}",
+  type_name, response.GetStringRef());
 }
   } else {
 // Can we get more data here on the failure?
-error.SetErrorStringWithFormat("configuring StructuredData feature %s "
-   "failed when sending packet: "
-   "PacketResult=%d",
-   type_name.AsCString(), (int)result);
+error.SetErrorStringWithFormatv(
+"configuring StructuredData feature {0} failed when sending packet: "
+"PacketResult={1}",
+type_name, (int)result);
   }
   return error;
 }


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -492,7 +492,7 @@
   ///
   /// \see \b Process::ConfigureStructuredData(...) for details.
   Status
-  ConfigureRemoteStructuredData(ConstString type_name,
+  ConfigureRemoteStructuredData(llvm::StringRef type_name,
 const StructuredData::ObjectSP _sp);
 
   llvm::Expected
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -4171,10 +4171,10 @@
 }
 
 Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
-ConstString type_name, const StructuredData::ObjectSP _sp) {
+llvm::StringRef type_name, const StructuredData::ObjectSP _sp) {
   Status error;
 
-  if (type_name.GetLength() == 0) {
+  if (type_name.empty()) {
 error.SetErrorString("invalid type_name argument");
 return error;
   }
@@ -4182,7 +4182,7 @@
   // Build command: Configure{type_name}: serialized config data.
   StreamGDBRemote stream;
   stream.PutCString("QConfigure");
-  

[Lldb-commits] [lldb] ab85553 - [lldb] Fix Python test formatting (NFC)

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

Author: Jonas Devlieghere
Date: 2023-06-16T14:51:14-07:00
New Revision: ab855530f797bbc113f75f833a4ca5711749d7c8

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

LOG: [lldb] Fix Python test formatting (NFC)

All Python files in the LLVM repository were reformatted with Black [1].
Files inside the LLDB subproject were reformatted in 2238dcc39358. This
patch updates a handful of tests that were added or modified since then
and weren't formatted with Black.

[1] 
https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style/68257

Added: 


Modified: 
lldb/test/API/commands/dwim-print/TestDWIMPrint.py
lldb/test/API/functionalities/inline-stepping/TestInlineStepping.py
lldb/test/API/functionalities/step-avoids-no-debug/TestStepNoDebug.py
lldb/test/API/functionalities/var_path/TestVarPath.py
lldb/test/API/lang/cpp/class_static/TestStaticVariables.py

lldb/test/API/lang/cpp/frame-var-depth-and-elem-count/TestFrameVarDepthAndElemCount.py
lldb/test/API/python_api/function_symbol/TestDisasmAPI.py
lldb/test/API/python_api/function_symbol/TestSymbolAPI.py
lldb/test/API/python_api/target/TestTargetAPI.py

Removed: 




diff  --git a/lldb/test/API/commands/dwim-print/TestDWIMPrint.py 
b/lldb/test/API/commands/dwim-print/TestDWIMPrint.py
index 9cb99a2a817d6..040632096c70e 100644
--- a/lldb/test/API/commands/dwim-print/TestDWIMPrint.py
+++ b/lldb/test/API/commands/dwim-print/TestDWIMPrint.py
@@ -142,5 +142,7 @@ def test_summary_strings(self):
 def test_void_result(self):
 """Test dwim-print does not surface an error message for void 
expressions."""
 self.build()
-lldbutil.run_to_source_breakpoint(self, "// break here", 
lldb.SBFileSpec("main.c"))
+lldbutil.run_to_source_breakpoint(
+self, "// break here", lldb.SBFileSpec("main.c")
+)
 self.expect("dwim-print (void)15", matching=False, 
patterns=["(?i)error"])

diff  --git 
a/lldb/test/API/functionalities/inline-stepping/TestInlineStepping.py 
b/lldb/test/API/functionalities/inline-stepping/TestInlineStepping.py
index 49a72c2863e74..752c3a9cbd286 100644
--- a/lldb/test/API/functionalities/inline-stepping/TestInlineStepping.py
+++ b/lldb/test/API/functionalities/inline-stepping/TestInlineStepping.py
@@ -25,7 +25,7 @@ def test_step_over_with_python_api(self):
 self.build()
 self.inline_stepping_step_over()
 
-@add_test_categories(['pyapi'])
+@add_test_categories(["pyapi"])
 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr32343")
 def test_step_in_template_with_python_api(self):
 """Test stepping in to templated functions."""

diff  --git 
a/lldb/test/API/functionalities/step-avoids-no-debug/TestStepNoDebug.py 
b/lldb/test/API/functionalities/step-avoids-no-debug/TestStepNoDebug.py
index 6c399b8a0a1b2..ad59c5ccb1a4f 100644
--- a/lldb/test/API/functionalities/step-avoids-no-debug/TestStepNoDebug.py
+++ b/lldb/test/API/functionalities/step-avoids-no-debug/TestStepNoDebug.py
@@ -10,9 +10,10 @@
 
 
 class StepAvoidsNoDebugTestCase(TestBase):
-
-@add_test_categories(['pyapi'])
-@expectedFailureAll(archs=["aarch64"], oslist=["windows"], 
bugnumber="llvm.org/pr56292")
+@add_test_categories(["pyapi"])
+@expectedFailureAll(
+archs=["aarch64"], oslist=["windows"], bugnumber="llvm.org/pr56292"
+)
 def test_step_out_with_python(self):
 """Test stepping out using avoid-no-debug with dsyms."""
 self.build()
@@ -26,8 +27,11 @@ def test_step_out_with_python(self):
 compiler_version=[">=", "3.9"],
 archs=["i386"],
 oslist=no_match(["freebsd"]),
-bugnumber="llvm.org/pr28549")
-@expectedFailureAll(archs=["aarch64"], oslist=["windows"], 
bugnumber="llvm.org/pr56292")
+bugnumber="llvm.org/pr28549",
+)
+@expectedFailureAll(
+archs=["aarch64"], oslist=["windows"], bugnumber="llvm.org/pr56292"
+)
 def test_step_over_with_python(self):
 """Test stepping over using avoid-no-debug with dwarf."""
 self.build()
@@ -41,8 +45,11 @@ def test_step_over_with_python(self):
 compiler_version=[">=", "3.9"],
 archs=["i386"],
 oslist=no_match(["freebsd"]),
-bugnumber="llvm.org/pr28549")
-@expectedFailureAll(archs=["aarch64"], oslist=["windows"], 
bugnumber="llvm.org/pr56292")
+bugnumber="llvm.org/pr28549",
+)
+@expectedFailureAll(
+archs=["aarch64"], oslist=["windows"], bugnumber="llvm.org/pr56292"
+)
 def test_step_in_with_python(self):
 """Test stepping in using avoid-no-debug with dwarf."""
 self.build()

diff  --git a/lldb/test/API/functionalities/var_path/TestVarPath.py 

[Lldb-commits] [lldb] f1bb534 - [lldb] Simplify logging in Process settings (NFC)

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

Author: Jonas Devlieghere
Date: 2023-06-16T14:46:46-07:00
New Revision: f1bb534b0ab53fab501fa92c4ef0f5eaf75c6bd6

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

LOG: [lldb] Simplify logging in Process settings (NFC)

Added: 


Modified: 
lldb/source/Target/Process.cpp

Removed: 




diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 7ad62976d968d..8542ffe91b56c 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -5689,30 +5689,28 @@ lldb::addr_t Process::GetHighmemDataAddressMask() {
 }
 
 void Process::SetCodeAddressMask(lldb::addr_t code_address_mask) {
-  Log *log = GetLog(LLDBLog::Process);
-  LLDB_LOGF(log, "Setting Process code address mask to 0x%" PRIx64,
-code_address_mask);
+  LLDB_LOG(GetLog(LLDBLog::Process),
+   "Setting Process code address mask to {0:x}", code_address_mask);
   m_code_address_mask = code_address_mask;
 }
 
 void Process::SetDataAddressMask(lldb::addr_t data_address_mask) {
-  Log *log = GetLog(LLDBLog::Process);
-  LLDB_LOGF(log, "Setting Process data address mask to 0x%" PRIx64,
-data_address_mask);
+  LLDB_LOG(GetLog(LLDBLog::Process),
+   "Setting Process data address mask to {0:x}", data_address_mask);
   m_data_address_mask = data_address_mask;
 }
 
 void Process::SetHighmemCodeAddressMask(lldb::addr_t code_address_mask) {
-  Log *log = GetLog(LLDBLog::Process);
-  LLDB_LOGF(log, "Setting Process highmem code address mask to 0x%" PRIx64,
-code_address_mask);
+  LLDB_LOG(GetLog(LLDBLog::Process),
+   "Setting Process highmem code address mask to {0:x}",
+   code_address_mask);
   m_highmem_code_address_mask = code_address_mask;
 }
 
 void Process::SetHighmemDataAddressMask(lldb::addr_t data_address_mask) {
-  Log *log = GetLog(LLDBLog::Process);
-  LLDB_LOGF(log, "Setting Process highmem data address mask to 0x%" PRIx64,
-data_address_mask);
+  LLDB_LOG(GetLog(LLDBLog::Process),
+   "Setting Process highmem data address mask to {0:x}",
+   data_address_mask);
   m_highmem_data_address_mask = data_address_mask;
 }
 



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


[Lldb-commits] [lldb] 7d30878 - [lldb][NFCI] Avoid a few unnecessary ConstString constructions in StructuredDataDarwinLog

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

Author: Alex Langford
Date: 2023-06-16T14:19:13-07:00
New Revision: 7d30878bf8586a991264c5ca9095a7b5a5234a42

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

LOG: [lldb][NFCI] Avoid a few unnecessary ConstString constructions in 
StructuredDataDarwinLog

Process::GetStructuredDataPlugin takes a StringRef directly, no need to
convert them to ConstString first.

Added: 


Modified: 
lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp 
b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
index a9f88233d9463..611e1506d8581 100644
--- a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
+++ b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
@@ -799,8 +799,8 @@ class EnableCommand : public CommandObjectParsed {
 }
 
 // Get the plugin for the process.
-auto plugin_sp = process_sp->GetStructuredDataPlugin(
-ConstString(GetDarwinLogTypeName()));
+auto plugin_sp =
+process_sp->GetStructuredDataPlugin(GetDarwinLogTypeName());
 if (!plugin_sp || (plugin_sp->GetPluginName() !=
StructuredDataDarwinLog::GetStaticPluginName())) {
   result.AppendError("failed to get StructuredDataPlugin for "
@@ -871,8 +871,8 @@ class StatusCommand : public CommandObjectParsed {
   stream.PutCString("Enabled: not applicable "
 "(requires process)\n");
 } else {
-  auto plugin_sp = process_sp->GetStructuredDataPlugin(
-  ConstString(GetDarwinLogTypeName()));
+  auto plugin_sp =
+  process_sp->GetStructuredDataPlugin(GetDarwinLogTypeName());
   stream.Printf("Availability: %s\n",
 plugin_sp ? "available" : "unavailable");
   llvm::StringRef plugin_name = 
StructuredDataDarwinLog::GetStaticPluginName();
@@ -1490,8 +1490,7 @@ bool StructuredDataDarwinLog::InitCompletionHookCallback(
   LLDB_LOGF(log, "StructuredDataDarwinLog::%s() call is for process uid %d",
 __FUNCTION__, process_sp->GetUniqueID());
 
-  auto plugin_sp =
-  process_sp->GetStructuredDataPlugin(ConstString(GetDarwinLogTypeName()));
+  auto plugin_sp = process_sp->GetStructuredDataPlugin(GetDarwinLogTypeName());
   if (!plugin_sp) {
 LLDB_LOG(log, "warning: no plugin for feature {0} in process uid {1}",
  GetDarwinLogTypeName(), process_sp->GetUniqueID());



___
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.package-name

2023-06-16 Thread Greg Clayton via Phabricator via lldb-commits
clayborg accepted this revision.
clayborg added a comment.
This revision is now accepted and ready to land.

lgtm now!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152933

___
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.package-name

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

update 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
@@ -49,6 +49,7 @@
   }
 
   MOCK_METHOD1(GetAdbClient, AdbClientUP(Status ));
+  MOCK_METHOD0(GetPropertyPackageName, llvm::StringRef());
 };
 
 } // namespace
@@ -112,6 +113,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, GetPropertyPackageName())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.test")));
+
+  EXPECT_CALL(*this, GetAdbClient(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(AdbClientUP(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"), _, _, _))
@@ -164,3 +191,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(SyncServiceUP(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, GetPropertyPackageName())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.app")));
+
+  EXPECT_CALL(*this, GetAdbClient(_))
+  .Times(2)
+  .WillOnce(Return(ByMove(AdbClientUP(adb_client0
+  .WillOnce(Return(ByMove(AdbClientUP(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 PlatformPackageName: Property<"package-name", "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 AdbClientUP;
   virtual AdbClientUP GetAdbClient(Status );
 
+  virtual llvm::StringRef GetPropertyPackageName();
+
+  std::string GetRunAs();
+
 private:
   AdbClient::SyncService *GetSyncService(Status );
 
Index: lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp

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

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

Rename it to platform.plugin.remote-android.package-name


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
@@ -49,6 +49,7 @@
   }
 
   MOCK_METHOD1(GetAdbClient, AdbClientUP(Status ));
+  MOCK_METHOD0(GetPropertyPackageName, llvm::StringRef());
 };
 
 } // namespace
@@ -112,6 +113,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, GetPropertyPackageName())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.test")));
+
+  EXPECT_CALL(*this, GetAdbClient(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(AdbClientUP(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"), _, _, _))
@@ -164,3 +191,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(SyncServiceUP(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, GetPropertyPackageName())
+  .Times(1)
+  .WillOnce(Return(llvm::StringRef("com.example.app")));
+
+  EXPECT_CALL(*this, GetAdbClient(_))
+  .Times(2)
+  .WillOnce(Return(ByMove(AdbClientUP(adb_client0
+  .WillOnce(Return(ByMove(AdbClientUP(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 PlatformPackageName: Property<"package-name", "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 AdbClientUP;
   virtual AdbClientUP GetAdbClient(Status );
 
+  virtual llvm::StringRef GetPropertyPackageName();
+
+  std::string GetRunAs();
+
 private:
   AdbClient::SyncService *GetSyncService(Status );
 
Index: lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp

[Lldb-commits] [PATCH] D153088: [lldb] De-virtualize applicable functions in ValueObject (NFC)

2023-06-16 Thread Dave Lee via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf2a1320c2ff5: [lldb] De-virtualize applicable functions in 
ValueObject (NFC) (authored by kastiglione).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153088

Files:
  lldb/include/lldb/Core/ValueObject.h


Index: lldb/include/lldb/Core/ValueObject.h
===
--- lldb/include/lldb/Core/ValueObject.h
+++ lldb/include/lldb/Core/ValueObject.h
@@ -370,26 +370,26 @@
 return GetCompilerType().GetTypeName();
   }
 
-  virtual lldb::LanguageType GetObjectRuntimeLanguage() {
+  lldb::LanguageType GetObjectRuntimeLanguage() {
 return GetCompilerType().GetMinimumLanguage();
   }
 
-  virtual uint32_t
+  uint32_t
   GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr) {
 return GetCompilerType().GetTypeInfo(pointee_or_element_compiler_type);
   }
 
-  virtual bool IsPointerType() { return GetCompilerType().IsPointerType(); }
+  bool IsPointerType() { return GetCompilerType().IsPointerType(); }
 
-  virtual bool IsArrayType() { return GetCompilerType().IsArrayType(); }
+  bool IsArrayType() { return GetCompilerType().IsArrayType(); }
 
-  virtual bool IsScalarType() { return GetCompilerType().IsScalarType(); }
+  bool IsScalarType() { return GetCompilerType().IsScalarType(); }
 
-  virtual bool IsPointerOrReferenceType() {
+  bool IsPointerOrReferenceType() {
 return GetCompilerType().IsPointerOrReferenceType();
   }
 
-  virtual bool IsPossibleDynamicType();
+  bool IsPossibleDynamicType();
 
   bool IsNilReference();
 
@@ -429,10 +429,6 @@
 return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0);
   }
 
-  virtual bool IsArrayItemForPointer() {
-return m_flags.m_is_array_item_for_pointer;
-  }
-
   virtual const char *GetValueAsCString();
 
   virtual bool GetValueAsCString(const lldb_private::TypeFormatImpl ,
@@ -628,7 +624,7 @@
 
   // The backing bits of this value object were updated, clear any descriptive
   // string, so we know we have to refetch them.
-  virtual void ValueUpdated() {
+  void ValueUpdated() {
 ClearUserVisibleData(eClearUserVisibleDataItemsValue |
  eClearUserVisibleDataItemsSummary |
  eClearUserVisibleDataItemsDescription);


Index: lldb/include/lldb/Core/ValueObject.h
===
--- lldb/include/lldb/Core/ValueObject.h
+++ lldb/include/lldb/Core/ValueObject.h
@@ -370,26 +370,26 @@
 return GetCompilerType().GetTypeName();
   }
 
-  virtual lldb::LanguageType GetObjectRuntimeLanguage() {
+  lldb::LanguageType GetObjectRuntimeLanguage() {
 return GetCompilerType().GetMinimumLanguage();
   }
 
-  virtual uint32_t
+  uint32_t
   GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr) {
 return GetCompilerType().GetTypeInfo(pointee_or_element_compiler_type);
   }
 
-  virtual bool IsPointerType() { return GetCompilerType().IsPointerType(); }
+  bool IsPointerType() { return GetCompilerType().IsPointerType(); }
 
-  virtual bool IsArrayType() { return GetCompilerType().IsArrayType(); }
+  bool IsArrayType() { return GetCompilerType().IsArrayType(); }
 
-  virtual bool IsScalarType() { return GetCompilerType().IsScalarType(); }
+  bool IsScalarType() { return GetCompilerType().IsScalarType(); }
 
-  virtual bool IsPointerOrReferenceType() {
+  bool IsPointerOrReferenceType() {
 return GetCompilerType().IsPointerOrReferenceType();
   }
 
-  virtual bool IsPossibleDynamicType();
+  bool IsPossibleDynamicType();
 
   bool IsNilReference();
 
@@ -429,10 +429,6 @@
 return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0);
   }
 
-  virtual bool IsArrayItemForPointer() {
-return m_flags.m_is_array_item_for_pointer;
-  }
-
   virtual const char *GetValueAsCString();
 
   virtual bool GetValueAsCString(const lldb_private::TypeFormatImpl ,
@@ -628,7 +624,7 @@
 
   // The backing bits of this value object were updated, clear any descriptive
   // string, so we know we have to refetch them.
-  virtual void ValueUpdated() {
+  void ValueUpdated() {
 ClearUserVisibleData(eClearUserVisibleDataItemsValue |
  eClearUserVisibleDataItemsSummary |
  eClearUserVisibleDataItemsDescription);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] f2a1320 - [lldb] De-virtualize applicable functions in ValueObject (NFC)

2023-06-16 Thread Dave Lee via lldb-commits

Author: Dave Lee
Date: 2023-06-16T11:12:15-07:00
New Revision: f2a1320c2ff5be9b3280eb926d3f10dc86f56d7f

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

LOG: [lldb] De-virtualize applicable functions in ValueObject (NFC)

Remove `virtual` from `ValueObject` functions that aren't overridden.

One such function, `IsArrayItemForPointer`, is not called and so is instead 
deleted.

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

Added: 


Modified: 
lldb/include/lldb/Core/ValueObject.h

Removed: 




diff  --git a/lldb/include/lldb/Core/ValueObject.h 
b/lldb/include/lldb/Core/ValueObject.h
index 2edd1e019d922..2f2b212e238ca 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -370,26 +370,26 @@ class ValueObject {
 return GetCompilerType().GetTypeName();
   }
 
-  virtual lldb::LanguageType GetObjectRuntimeLanguage() {
+  lldb::LanguageType GetObjectRuntimeLanguage() {
 return GetCompilerType().GetMinimumLanguage();
   }
 
-  virtual uint32_t
+  uint32_t
   GetTypeInfo(CompilerType *pointee_or_element_compiler_type = nullptr) {
 return GetCompilerType().GetTypeInfo(pointee_or_element_compiler_type);
   }
 
-  virtual bool IsPointerType() { return GetCompilerType().IsPointerType(); }
+  bool IsPointerType() { return GetCompilerType().IsPointerType(); }
 
-  virtual bool IsArrayType() { return GetCompilerType().IsArrayType(); }
+  bool IsArrayType() { return GetCompilerType().IsArrayType(); }
 
-  virtual bool IsScalarType() { return GetCompilerType().IsScalarType(); }
+  bool IsScalarType() { return GetCompilerType().IsScalarType(); }
 
-  virtual bool IsPointerOrReferenceType() {
+  bool IsPointerOrReferenceType() {
 return GetCompilerType().IsPointerOrReferenceType();
   }
 
-  virtual bool IsPossibleDynamicType();
+  bool IsPossibleDynamicType();
 
   bool IsNilReference();
 
@@ -429,10 +429,6 @@ class ValueObject {
 return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0);
   }
 
-  virtual bool IsArrayItemForPointer() {
-return m_flags.m_is_array_item_for_pointer;
-  }
-
   virtual const char *GetValueAsCString();
 
   virtual bool GetValueAsCString(const lldb_private::TypeFormatImpl ,
@@ -628,7 +624,7 @@ class ValueObject {
 
   // The backing bits of this value object were updated, clear any descriptive
   // string, so we know we have to refetch them.
-  virtual void ValueUpdated() {
+  void ValueUpdated() {
 ClearUserVisibleData(eClearUserVisibleDataItemsValue |
  eClearUserVisibleDataItemsSummary |
  eClearUserVisibleDataItemsDescription);



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


[Lldb-commits] [lldb] 4493049 - [lldb][NFCI] Remove unused method Properties::GetSubProperty

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

Author: Alex Langford
Date: 2023-06-16T10:55:01-07:00
New Revision: 44930490124d29c07b9538fb08fc6c7713cd74dc

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

LOG: [lldb][NFCI] Remove unused method Properties::GetSubProperty

Added: 


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

Removed: 




diff  --git a/lldb/include/lldb/Core/UserSettingsController.h 
b/lldb/include/lldb/Core/UserSettingsController.h
index 26d5d37383ade..ea60467c9afe5 100644
--- a/lldb/include/lldb/Core/UserSettingsController.h
+++ b/lldb/include/lldb/Core/UserSettingsController.h
@@ -23,7 +23,6 @@
 
 namespace lldb_private {
 class CommandInterpreter;
-class ConstString;
 class ExecutionContext;
 class Property;
 class Stream;
@@ -69,9 +68,6 @@ class Properties {
   size_t Apropos(llvm::StringRef keyword,
  std::vector _properties) const;
 
-  lldb::OptionValuePropertiesSP GetSubProperty(const ExecutionContext *exe_ctx,
-   ConstString name);
-
   // We sometimes need to introduce a setting to enable experimental features,
   // but then we don't want the setting for these to cause errors when the
   // setting goes away.  Add a sub-topic of the settings using this

diff  --git a/lldb/source/Core/UserSettingsController.cpp 
b/lldb/source/Core/UserSettingsController.cpp
index 30bb468357443..f5dd926cf0500 100644
--- a/lldb/source/Core/UserSettingsController.cpp
+++ b/lldb/source/Core/UserSettingsController.cpp
@@ -98,15 +98,6 @@ Properties::Apropos(llvm::StringRef keyword,
   return matching_properties.size();
 }
 
-lldb::OptionValuePropertiesSP
-Properties::GetSubProperty(const ExecutionContext *exe_ctx,
-   ConstString name) {
-  OptionValuePropertiesSP properties_sp(GetValueProperties());
-  if (properties_sp)
-return properties_sp->GetSubProperty(exe_ctx, name);
-  return lldb::OptionValuePropertiesSP();
-}
-
 llvm::StringRef Properties::GetExperimentalSettingsName() {
   static constexpr llvm::StringLiteral g_experimental("experimental");
   return g_experimental;



___
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-16 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0b90d09898ca: [lldb][NFCI] Remove use of ConstString in 
ProcessStructReader (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

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 larger than a uint64_t (yet)

[Lldb-commits] [lldb] 0b90d09 - [lldb][NFCI] Remove use of ConstString in ProcessStructReader

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

Author: Alex Langford
Date: 2023-06-16T10:53:24-07:00
New Revision: 0b90d09898cadc89105c3caf0d01f09e66c49993

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

LOG: [lldb][NFCI] Remove use of ConstString in ProcessStructReader

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

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

Added: 


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

Removed: 




diff  --git a/lldb/include/lldb/Target/ProcessStructReader.h 
b/lldb/include/lldb/Target/ProcessStructReader.h
index ceb70528cf2d1..0f0b3f69d5509 100644
--- a/lldb/include/lldb/Target/ProcessStructReader.h
+++ b/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 @@ class ProcessStructReader {
 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 @@ class ProcessStructReader {
   // 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 @@ class ProcessStructReader {
   }
 
   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;

diff  --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp 
b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
index ae5e1b7baed57..f4ddc9e869148 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
@@ -442,13 +442,13 @@ void SystemRuntimeMacOSX::ReadLibdispatchTSDIndexes() {
 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");
 }
   }
 }



___
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-16 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG193c7d10cb30: [lldb][NFCI] Remove custom matcher classes in 
Listener in favor of lambdas (authored by bulbazord).

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] [lldb] 193c7d1 - [lldb][NFCI] Remove custom matcher classes in Listener in favor of lambdas

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

Author: Alex Langford
Date: 2023-06-16T10:50:15-07:00
New Revision: 193c7d10cb30d846d35085a462f8a6c8ad226f1f

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

LOG: [lldb][NFCI] Remove custom matcher classes in Listener in favor of lambdas

Instead of writing boilerplate classes to serve as matchers for things
like `find_if` and `erase_if`, we can use lambdas. I believe this
simplifies the Listener class.

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

Added: 


Modified: 
lldb/source/Utility/Listener.cpp

Removed: 




diff  --git a/lldb/source/Utility/Listener.cpp 
b/lldb/source/Utility/Listener.cpp
index 34bfde401f586..48ea5fca899e3 100644
--- a/lldb/source/Utility/Listener.cpp
+++ b/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::BroadcasterWillDestruct(Broadcaster 
*broadcaster) {
 }
 
 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 @@ void Listener::AddEvent(EventSP _sp) {
   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 @@ bool Listener::FindNextEventInternal(
   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 @@ Listener::StartListeningForEventSpec(const 
BroadcasterManagerSP _sp,
   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 @@ Listener::StartListeningForEventSpec(const 
BroadcasterManagerSP _sp,
   uint32_t bits_acquired = 

[Lldb-commits] [PATCH] D153060: lldb: do more than 1 kilobyte at a time to vastly increase binary sync speed

2023-06-16 Thread Russell Greene via Phabricator via lldb-commits
russelltg added a comment.

Name: Russell Greene
Email: russellgree...@gmail.com

Thank you :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153060

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


[Lldb-commits] [PATCH] D153054: [lldb][NFCI] TypeSystemClang::GetTypeForIdentifier should take a StringRef

2023-06-16 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4c8b6fae4437: [lldb][NFCI] 
TypeSystemClang::GetTypeForIdentifier should take a StringRef (authored by 
bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153054

Files:
  lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
  lldb/source/Plugins/RegisterTypeBuilder/RegisterTypeBuilderClang.cpp
  lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -252,31 +252,29 @@
 
   template 
   CompilerType
-  GetTypeForIdentifier(ConstString type_name,
+  GetTypeForIdentifier(llvm::StringRef type_name,
clang::DeclContext *decl_context = nullptr) {
 CompilerType compiler_type;
-
-if (type_name.GetLength()) {
-  clang::ASTContext  = getASTContext();
-  if (!decl_context)
-decl_context = ast.getTranslationUnitDecl();
-
-  clang::IdentifierInfo  = ast.Idents.get(type_name.GetCString());
-  clang::DeclarationName myName =
-  ast.DeclarationNames.getIdentifier();
-
-  clang::DeclContext::lookup_result result = decl_context->lookup(myName);
-
-  if (!result.empty()) {
-clang::NamedDecl *named_decl = *result.begin();
-if (const RecordDeclType *record_decl =
-llvm::dyn_cast(named_decl))
-  compiler_type =
-  CompilerType(weak_from_this(),
-   clang::QualType(record_decl->getTypeForDecl(), 0)
-   .getAsOpaquePtr());
-  }
-}
+if (type_name.empty())
+  return compiler_type;
+
+clang::ASTContext  = getASTContext();
+if (!decl_context)
+  decl_context = ast.getTranslationUnitDecl();
+
+clang::IdentifierInfo  = ast.Idents.get(type_name);
+clang::DeclarationName myName =
+ast.DeclarationNames.getIdentifier();
+clang::DeclContext::lookup_result result = decl_context->lookup(myName);
+if (result.empty())
+  return compiler_type;
+
+clang::NamedDecl *named_decl = *result.begin();
+if (const RecordDeclType *record_decl =
+llvm::dyn_cast(named_decl))
+  compiler_type = CompilerType(
+  weak_from_this(),
+  clang::QualType(record_decl->getTypeForDecl(), 0).getAsOpaquePtr());
 
 return compiler_type;
   }
Index: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
===
--- lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -407,8 +407,8 @@
 // symbols in PDB for types with const or volatile modifiers, but we need
 // to create only one declaration for them all.
 Type::ResolveState type_resolve_state;
-CompilerType clang_type = m_ast.GetTypeForIdentifier(
-ConstString(name), decl_context);
+CompilerType clang_type =
+m_ast.GetTypeForIdentifier(name, decl_context);
 if (!clang_type.IsValid()) {
   auto access = GetAccessibilityForUdt(*udt);
 
@@ -479,8 +479,8 @@
 uint64_t bytes = enum_type->getLength();
 
 // Check if such an enum already exists in the current context
-CompilerType ast_enum = m_ast.GetTypeForIdentifier(
-ConstString(name), decl_context);
+CompilerType ast_enum =
+m_ast.GetTypeForIdentifier(name, decl_context);
 if (!ast_enum.IsValid()) {
   auto underlying_type_up = enum_type->getUnderlyingType();
   if (!underlying_type_up)
@@ -557,8 +557,7 @@
 
 // Check if such a typedef already exists in the current context
 CompilerType ast_typedef =
-m_ast.GetTypeForIdentifier(ConstString(name),
-   decl_ctx);
+m_ast.GetTypeForIdentifier(name, decl_ctx);
 if (!ast_typedef.IsValid()) {
   CompilerType target_ast_type = target_type->GetFullCompilerType();
 
Index: lldb/source/Plugins/RegisterTypeBuilder/RegisterTypeBuilderClang.cpp
===
--- lldb/source/Plugins/RegisterTypeBuilder/RegisterTypeBuilderClang.cpp
+++ lldb/source/Plugins/RegisterTypeBuilder/RegisterTypeBuilderClang.cpp
@@ -48,7 +48,7 @@
   // See if we have made this type before and can reuse it.
   CompilerType fields_type =
   type_system->GetTypeForIdentifier(
-  ConstString(register_type_name.c_str()));
+  register_type_name);
 
   if (!fields_type) {
 // In most ABI, a change of field type means a change in storage unit.
Index: lldb/source/Plugins/Language/ObjC/NSDictionary.cpp

[Lldb-commits] [lldb] 4c8b6fa - [lldb][NFCI] TypeSystemClang::GetTypeForIdentifier should take a StringRef

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

Author: Alex Langford
Date: 2023-06-16T10:44:55-07:00
New Revision: 4c8b6fae4437f9a5b17ddc146592aec0e4c78e02

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

LOG: [lldb][NFCI] TypeSystemClang::GetTypeForIdentifier should take a StringRef

This method just takes its ConstString parameter and gets a StringRef
out of it. Let's just pass in a StringRef directly.

This also cleans up some logic in the callers to be a little easier to
read and to avoid unnecessary ConstString creation.

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

Added: 


Modified: 
lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
lldb/source/Plugins/RegisterTypeBuilder/RegisterTypeBuilderClang.cpp
lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

Removed: 




diff  --git a/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp 
b/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
index 702d196a7dda9..2e927eb8d8569 100644
--- a/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
+++ b/lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
@@ -65,32 +65,30 @@ NSDictionary_Additionals::GetAdditionalSynthetics() {
 
 static CompilerType GetLLDBNSPairType(TargetSP target_sp) {
   CompilerType compiler_type;
-
   TypeSystemClangSP scratch_ts_sp =
   ScratchTypeSystemClang::GetForTarget(*target_sp);
 
-  if (scratch_ts_sp) {
-ConstString g_lldb_autogen_nspair("__lldb_autogen_nspair");
-
-compiler_type = scratch_ts_sp->GetTypeForIdentifier(
-g_lldb_autogen_nspair);
-
-if (!compiler_type) {
-  compiler_type = scratch_ts_sp->CreateRecordType(
-  nullptr, OptionalClangModuleID(), lldb::eAccessPublic,
-  g_lldb_autogen_nspair.GetCString(), clang::TTK_Struct,
-  lldb::eLanguageTypeC);
-
-  if (compiler_type) {
-TypeSystemClang::StartTagDeclarationDefinition(compiler_type);
-CompilerType id_compiler_type =
-scratch_ts_sp->GetBasicType(eBasicTypeObjCID);
-TypeSystemClang::AddFieldToRecordType(
-compiler_type, "key", id_compiler_type, lldb::eAccessPublic, 0);
-TypeSystemClang::AddFieldToRecordType(
-compiler_type, "value", id_compiler_type, lldb::eAccessPublic, 0);
-TypeSystemClang::CompleteTagDeclarationDefinition(compiler_type);
-  }
+  if (!scratch_ts_sp)
+return compiler_type;
+
+  static constexpr llvm::StringLiteral 
g_lldb_autogen_nspair("__lldb_autogen_nspair");
+
+  compiler_type = 
scratch_ts_sp->GetTypeForIdentifier(g_lldb_autogen_nspair);
+
+  if (!compiler_type) {
+compiler_type = scratch_ts_sp->CreateRecordType(
+nullptr, OptionalClangModuleID(), lldb::eAccessPublic,
+g_lldb_autogen_nspair, clang::TTK_Struct, lldb::eLanguageTypeC);
+
+if (compiler_type) {
+  TypeSystemClang::StartTagDeclarationDefinition(compiler_type);
+  CompilerType id_compiler_type =
+  scratch_ts_sp->GetBasicType(eBasicTypeObjCID);
+  TypeSystemClang::AddFieldToRecordType(
+  compiler_type, "key", id_compiler_type, lldb::eAccessPublic, 0);
+  TypeSystemClang::AddFieldToRecordType(
+  compiler_type, "value", id_compiler_type, lldb::eAccessPublic, 0);
+  TypeSystemClang::CompleteTagDeclarationDefinition(compiler_type);
 }
   }
   return compiler_type;

diff  --git 
a/lldb/source/Plugins/RegisterTypeBuilder/RegisterTypeBuilderClang.cpp 
b/lldb/source/Plugins/RegisterTypeBuilder/RegisterTypeBuilderClang.cpp
index 49348ed697014..aeb54ef9ee24b 100644
--- a/lldb/source/Plugins/RegisterTypeBuilder/RegisterTypeBuilderClang.cpp
+++ b/lldb/source/Plugins/RegisterTypeBuilder/RegisterTypeBuilderClang.cpp
@@ -48,7 +48,7 @@ CompilerType RegisterTypeBuilderClang::GetRegisterType(
   // See if we have made this type before and can reuse it.
   CompilerType fields_type =
   type_system->GetTypeForIdentifier(
-  ConstString(register_type_name.c_str()));
+  register_type_name);
 
   if (!fields_type) {
 // In most ABI, a change of field type means a change in storage unit.

diff  --git a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp 
b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
index b1a882465c404..5efa5bccb85f5 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -407,8 +407,8 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const 
PDBSymbol ) {
 // symbols in PDB for types with const or volatile modifiers, but we need
 // to create only one declaration for them all.
 Type::ResolveState type_resolve_state;
-CompilerType clang_type = m_ast.GetTypeForIdentifier(
-ConstString(name), decl_context);
+CompilerType clang_type =
+

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

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

- s/AdbClientSP/AdbClientUP/g
- Updated `Status ` arg to `GetAdbClient`
- Added error checks in AndroidPlatform for `GetAdbClient`
- Added DownloadModuleSliceWithAdbClientError test for the GetAdbClient error


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,166 @@
+//===-- 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::unique_ptr()) {}
+
+  MOCK_METHOD2(PullFile,
+   Status(const FileSpec _file, const FileSpec _file));
+  MOCK_METHOD4(Stat, Status(const FileSpec _file, uint32_t ,
+uint32_t , uint32_t ));
+};
+
+typedef std::unique_ptr SyncServiceUP;
+
+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, SyncServiceUP(Status ));
+};
+
+class PlatformAndroidTest : public PlatformAndroid, public ::testing::Test {
+public:
+  PlatformAndroidTest() : PlatformAndroid(false) {
+m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
+  }
+
+  MOCK_METHOD1(GetAdbClient, AdbClientUP(Status ));
+};
+
+} // namespace
+
+TEST_F(PlatformAndroidTest, DownloadModuleSliceWithAdbClientError) {
+  EXPECT_CALL(*this, GetAdbClient(_))
+  .Times(1)
+  .WillOnce(DoAll(WithArg<0>([](auto ) {
+arg = Status("Failed to create AdbClient");
+  }),
+  Return(ByMove(AdbClientUP();
+
+  EXPECT_TRUE(
+  DownloadModuleSlice(
+  FileSpec("/system/app/Test/Test.apk!/lib/arm64-v8a/libtest.so"), 4096,
+  3600, FileSpec())
+  .Fail());
+}
+
+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(SyncServiceUP(sync_service;
+
+  EXPECT_CALL(*this, GetAdbClient(_))
+  .Times(1)
+  .WillOnce(Return(ByMove(AdbClientUP(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(AdbClientUP(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)
+  

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

2023-06-16 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 532165.
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, ResolveSharedLibraryPathWithNormalFile) {
+  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::ResolveSharedLibraryPath(
+  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, ResolveSharedLibraryPathWithZipMissing) {
+  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::ResolveSharedLibraryPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+}
+
+TEST_F(ZipFileResolverTest, ResolveSharedLibraryPathWithZipExisting) {
+  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::ResolveSharedLibraryPath(
+  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;
+

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

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

removed abandoned dependency


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,39 @@
   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) {
+  // The contents of offset-test.bin are
+  // -0-1023: \0
+  // - 1024-4623: liboffset-test.so (offset: 1024, size: 3600, CRC32: 7D6E4738)
+  // - 4624-4639: \0
+  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,14 @@
 if (header.Parse(data, _offset)) {
   if (data_sp) {
 ModuleSpec spec(file);
+// In Android API level 23 and above, bionic dynamic linker is able to
+// load .so file directly from zip file. In that case, .so file is
+// page aligned and uncompressed, and this module spec should retain 
the
+// .so file offset and file size to pass through the information from
+// lldb-server to LLDB. For normal file, file_offset should be 0,
+// length should be the size of the file.
+spec.SetObjectOffset(file_offset);
+spec.SetObjectSize(length);
 
 const uint32_t sub_type = subTypeFromElfHeader(header);
 spec.GetArchitecture().SetArchitecture(
@@ -586,8 +594,12 @@
   __FUNCTION__, file.GetPath().c_str());
   }
 
+  // When ELF file does not contain GNU build ID, the later code will
+  // calculate CRC32 with this data_sp file_offset and length. It is
+  // important for Android zip .so file, which is a slice of a file,
+  // to not access the outside of the file slice range.
   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,39 @@
   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;
+  

[Lldb-commits] [PATCH] D152516: [lldb][AArch64] Add thread local storage tpidr register

2023-06-16 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett planned changes to this revision.
DavidSpickett added a comment.

Also found that clang at -00 will only read tpidr once vs. the gcc I had that 
would read it fresh each time. I can't rely on either of those to happen, so 
will change the test to use assembly to directly read and write tpidr instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152516

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


[Lldb-commits] [PATCH] D152516: [lldb][AArch64] Add thread local storage tpidr register

2023-06-16 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 532156.
DavidSpickett added a comment.

Always add the TLS regset mask value. It worked on my QEMU setup because
it also had the other extensions, but an armv8-a machine didn't.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152516

Files:
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
  lldb/test/API/linux/aarch64/tls_register/Makefile
  lldb/test/API/linux/aarch64/tls_register/TestAArch64LinuxTLSRegister.py
  lldb/test/API/linux/aarch64/tls_register/main.c

Index: lldb/test/API/linux/aarch64/tls_register/main.c
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tls_register/main.c
@@ -0,0 +1,25 @@
+#include 
+#include 
+
+struct __attribute__((__packed__)) TestStruct {
+  uint64_t one;
+  uint64_t two;
+};
+
+int main() {
+  static __thread struct TestStruct test_data;
+  test_data.one = 0xABABABABCDCDCDCD;
+#define TWO_VALUE 0xEFEFEFEF01010101
+  test_data.two = TWO_VALUE;
+
+  // Barrier to ensure the above writes are done first.
+  __asm__ volatile("" ::: "memory"); // Set break point at this line.
+
+  // Here lldb moves the TLS pointer 8 bytes forward.
+  // So this actually reads test_data.two instead of test_data.one.
+  volatile bool tls_has_moved = test_data.one == TWO_VALUE;
+
+  return 0; // Set break point 2 at this line.
+  // lldb will reset the thread pointer here so we don't potentially confuse
+  // libc.
+}
Index: lldb/test/API/linux/aarch64/tls_register/TestAArch64LinuxTLSRegister.py
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tls_register/TestAArch64LinuxTLSRegister.py
@@ -0,0 +1,77 @@
+"""
+Test lldb's ability to read and write the AArch64 TLS register tpidr.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class AArch64LinuxTLSRegister(TestBase):
+NO_DEBUG_INFO_TESTCASE = True
+
+@skipUnlessArch("aarch64")
+@skipUnlessPlatform(["linux"])
+def test_tls(self):
+self.build()
+self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
+
+lldbutil.run_break_set_by_file_and_line(
+self,
+"main.c",
+line_number("main.c", "// Set break point at this line."),
+num_expected_locations=1,
+)
+
+lldbutil.run_break_set_by_file_and_line(
+self,
+"main.c",
+line_number("main.c", "// Set break point 2 at this line."),
+num_expected_locations=1,
+)
+
+self.runCmd("run", RUN_SUCCEEDED)
+
+if self.process().GetState() == lldb.eStateExited:
+self.fail("Test program failed to run.")
+
+self.expect(
+"thread list",
+STOPPED_DUE_TO_BREAKPOINT,
+substrs=["stopped", "stop reason = breakpoint"],
+)
+
+# We can't know what the value should be since it moves about between
+# runs. So we'll check that we can read it, and by modifying it, see
+# changes in the program.
+
+regs = self.thread().GetSelectedFrame().GetRegisters()
+tls_regs = regs.GetFirstValueByName("Thread Local Storage Registers")
+self.assertTrue(tls_regs.IsValid(), "No TLS registers found.")
+tpidr = tls_regs.GetChildMemberWithName("tpidr")
+self.assertTrue(tpidr.IsValid(), "No tpidr register found.")
+tpidr = tpidr.GetValueAsUnsigned()
+
+# We should be able to find a known value in the TLS area it points to.
+# test_data should be very soon after the header, 64 bytes seems to work fine.
+self.expect("memory find -e 0xABABABABCDCDCDCD $tpidr $tpidr+64",
+substrs=["data found at location: 0x"])
+
+# Now modify the TLS pointer so that anyone reading test_data.one actually
+# reads test_data.two.
+self.expect("register write tpidr 0x{:x}".format(tpidr+8))
+
+# Let the program read test_data.one.
+self.expect("continue")
+
+self.expect(
+"thread list",
+STOPPED_DUE_TO_BREAKPOINT,
+substrs=["stopped", "stop reason = breakpoint"],
+)
+
+self.expect("p tls_has_moved", substrs=["true"])
+
+# Reset TLS so we don't potentially confuse the libc.
+self.expect("register write tpidr 0x{:x}".format(tpidr))
\ No newline at end of file
Index: lldb/test/API/linux/aarch64/tls_register/Makefile
===
--- /dev/null
+++ 

[Lldb-commits] [PATCH] D152516: [lldb][AArch64] Add thread local storage tpidr register

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

Move if up to before SVE registers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152516

Files:
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
  lldb/test/API/linux/aarch64/tls_register/Makefile
  lldb/test/API/linux/aarch64/tls_register/TestAArch64LinuxTLSRegister.py
  lldb/test/API/linux/aarch64/tls_register/main.c

Index: lldb/test/API/linux/aarch64/tls_register/main.c
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tls_register/main.c
@@ -0,0 +1,25 @@
+#include 
+#include 
+
+struct __attribute__((__packed__)) TestStruct {
+  uint64_t one;
+  uint64_t two;
+};
+
+int main() {
+  static __thread struct TestStruct test_data;
+  test_data.one = 0xABABABABCDCDCDCD;
+#define TWO_VALUE 0xEFEFEFEF01010101
+  test_data.two = TWO_VALUE;
+
+  // Barrier to ensure the above writes are done first.
+  __asm__ volatile("" ::: "memory"); // Set break point at this line.
+
+  // Here lldb moves the TLS pointer 8 bytes forward.
+  // So this actually reads test_data.two instead of test_data.one.
+  volatile bool tls_has_moved = test_data.one == TWO_VALUE;
+
+  return 0; // Set break point 2 at this line.
+  // lldb will reset the thread pointer here so we don't potentially confuse
+  // libc.
+}
Index: lldb/test/API/linux/aarch64/tls_register/TestAArch64LinuxTLSRegister.py
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tls_register/TestAArch64LinuxTLSRegister.py
@@ -0,0 +1,77 @@
+"""
+Test lldb's ability to read and write the AArch64 TLS register tpidr.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class AArch64LinuxTLSRegister(TestBase):
+NO_DEBUG_INFO_TESTCASE = True
+
+@skipUnlessArch("aarch64")
+@skipUnlessPlatform(["linux"])
+def test_tls(self):
+self.build()
+self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
+
+lldbutil.run_break_set_by_file_and_line(
+self,
+"main.c",
+line_number("main.c", "// Set break point at this line."),
+num_expected_locations=1,
+)
+
+lldbutil.run_break_set_by_file_and_line(
+self,
+"main.c",
+line_number("main.c", "// Set break point 2 at this line."),
+num_expected_locations=1,
+)
+
+self.runCmd("run", RUN_SUCCEEDED)
+
+if self.process().GetState() == lldb.eStateExited:
+self.fail("Test program failed to run.")
+
+self.expect(
+"thread list",
+STOPPED_DUE_TO_BREAKPOINT,
+substrs=["stopped", "stop reason = breakpoint"],
+)
+
+# We can't know what the value should be since it moves about between
+# runs. So we'll check that we can read it, and by modifying it, see
+# changes in the program.
+
+regs = self.thread().GetSelectedFrame().GetRegisters()
+tls_regs = regs.GetFirstValueByName("Thread Local Storage Registers")
+self.assertTrue(tls_regs.IsValid(), "No TLS registers found.")
+tpidr = tls_regs.GetChildMemberWithName("tpidr")
+self.assertTrue(tpidr.IsValid(), "No tpidr register found.")
+tpidr = tpidr.GetValueAsUnsigned()
+
+# We should be able to find a known value in the TLS area it points to.
+# test_data should be very soon after the header, 64 bytes seems to work fine.
+self.expect("memory find -e 0xABABABABCDCDCDCD $tpidr $tpidr+64",
+substrs=["data found at location: 0x"])
+
+# Now modify the TLS pointer so that anyone reading test_data.one actually
+# reads test_data.two.
+self.expect("register write tpidr 0x{:x}".format(tpidr+8))
+
+# Let the program read test_data.one.
+self.expect("continue")
+
+self.expect(
+"thread list",
+STOPPED_DUE_TO_BREAKPOINT,
+substrs=["stopped", "stop reason = breakpoint"],
+)
+
+self.expect("p tls_has_moved", substrs=["true"])
+
+# Reset TLS so we don't potentially confuse the libc.
+self.expect("register write tpidr 0x{:x}".format(tpidr))
\ No newline at end of file
Index: lldb/test/API/linux/aarch64/tls_register/Makefile
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tls_register/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := 

[Lldb-commits] [PATCH] D153043: [lldb] Fix handling of cfi_restore in the unwinder

2023-06-16 Thread Jaroslav Sevcik via Phabricator via lldb-commits
jarin added a comment.

In D153043#4427660 , @Michael137 
wrote:

> Looks like this is failing on the Darwin x86_64 buildbots: 
> https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/56510/execution/node/74/log/
>
>   Exit Code: 1
>   
>   Command Output (stderr):
>   --
>   clang: warning: argument unused during compilation: 
> '-fmodules-cache-path=/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lldb-test-build.noindex/module-cache-clang/lldb-shell'
>  [-Wunused-command-line-argument]
>   
> /Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s:25:2:
>  error: unknown directive
>.size g_hard_abort, 1
>^
>   
>   
>   Failed Tests (1):
> lldb-shell :: Unwind/eh-frame-dwarf-unwind-abort.test

I removed the offending directive. Feel free to revert all this if there are 
still problems.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153043

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


[Lldb-commits] [lldb] af35be5 - [lldb] Remove unused directive from test for D153043

2023-06-16 Thread Jaroslav Sevcik via lldb-commits

Author: Jaroslav Sevcik
Date: 2023-06-16T12:46:21+02:00
New Revision: af35be55c032a5af93e235ca8347fffeb68b788e

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

LOG: [lldb] Remove unused directive from test for D153043

Added: 


Modified: 
lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s

Removed: 




diff  --git a/lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s 
b/lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s
index e03a69f67f8f9..660bb14395e8d 100644
--- a/lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s
+++ b/lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s
@@ -22,4 +22,3 @@ asm_main:
.globl  g_hard_abort
 g_hard_abort:
.byte   1
-   .size   g_hard_abort, 1
\ No newline at end of file



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


[Lldb-commits] [PATCH] D153043: [lldb] Fix handling of cfi_restore in the unwinder

2023-06-16 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

Looks like this is failing on the Darwin x86_64 buildbots: 
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/56510/execution/node/74/log/

  Exit Code: 1
  
  Command Output (stderr):
  --
  clang: warning: argument unused during compilation: 
'-fmodules-cache-path=/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lldb-test-build.noindex/module-cache-clang/lldb-shell'
 [-Wunused-command-line-argument]
  
/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s:25:2:
 error: unknown directive
   .size g_hard_abort, 1
   ^
  
  
  Failed Tests (1):
lldb-shell :: Unwind/eh-frame-dwarf-unwind-abort.test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153043

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


[Lldb-commits] [PATCH] D153102: [lldb][MainLoopTest] Fix assertion failure on arm Linux

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

@DavidSpickett thanks for the heads up, and thanks @labath to the commit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153102

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


[Lldb-commits] [PATCH] D153060: lldb: do more than 1 kilobyte at a time to vastly increase binary sync speed

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

Sure, what name and email address should go on the commit?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153060

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


[Lldb-commits] [PATCH] D153102: [lldb][MainLoopTest] Fix assertion failure on arm Linux

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

I assume 
https://github.com/llvm/llvm-project/commit/244fcecb90fa7a3fb710ca5768d3bae9af5868cc
 already fixed this. It fixed the bot and there's no failures currently.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153102

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


[Lldb-commits] [PATCH] D152364: [lldb] Rate limit progress reports -- different approach [WIP-ish]

2023-06-16 Thread Pavel Labath via Phabricator via lldb-commits
labath reopened this revision.
labath added a comment.

:(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152364

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


[Lldb-commits] [lldb] afe8f20 - Revert "[lldb] Rate limit progress reports -- different approach [WIP-ish]"

2023-06-16 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2023-06-16T09:09:56+02:00
New Revision: afe8f20bb8dd1808cae542eb7ba0fc11a7886918

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

LOG: Revert "[lldb] Rate limit progress reports -- different approach [WIP-ish]"

This reverts commit c30853460da7446f92bc1e516f9cbe2c5df6e136, which I
pushed accidentally -- sorry.

Added: 


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

Removed: 




diff  --git a/lldb/include/lldb/Core/Progress.h 
b/lldb/include/lldb/Core/Progress.h
index 3bafd3d4b34ea..b2b8781a43b05 100644
--- a/lldb/include/lldb/Core/Progress.h
+++ b/lldb/include/lldb/Core/Progress.h
@@ -9,11 +9,9 @@
 #ifndef LLDB_CORE_PROGRESS_H
 #define LLDB_CORE_PROGRESS_H
 
-#include "lldb/Host/HostThread.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/lldb-types.h"
 #include 
-#include 
 #include 
 #include 
 
@@ -94,26 +92,24 @@ class Progress {
   void Increment(uint64_t amount = 1, std::string update = {});
 
 private:
-  void SendPeriodicReports(std::shared_future done);
-  void ReportProgress(std::string update);
+  void ReportProgress(std::string update = {});
   static std::atomic g_id;
   /// The title of the progress activity.
   std::string m_title;
+  std::mutex m_mutex;
   /// A unique integer identifier for progress reporting.
   const uint64_t m_id;
   /// How much work ([0...m_total]) that has been completed.
-  std::atomic m_completed;
+  uint64_t m_completed;
   /// Total amount of work, UINT64_MAX for non deterministic progress.
   const uint64_t m_total;
   /// The optional debugger ID to report progress to. If this has no value then
   /// all debuggers will receive this event.
   std::optional m_debugger_id;
-
-  std::mutex m_update_mutex;
-  std::string m_update;
-
-  std::promise m_stop_reporting_thread;
-  HostThread m_reporting_thread;
+  /// Set to true when progress has been reported where m_completed == m_total
+  /// to ensure that we don't send progress updates after progress has
+  /// completed.
+  bool m_complete = false;
 };
 
 } // namespace lldb_private

diff  --git a/lldb/source/Core/Progress.cpp b/lldb/source/Core/Progress.cpp
index a531b9b70437e..08be73f1470f3 100644
--- a/lldb/source/Core/Progress.cpp
+++ b/lldb/source/Core/Progress.cpp
@@ -9,8 +9,6 @@
 #include "lldb/Core/Progress.h"
 
 #include "lldb/Core/Debugger.h"
-#include "lldb/Host/ThreadLauncher.h"
-#include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/StreamString.h"
 
 using namespace lldb;
@@ -24,67 +22,39 @@ Progress::Progress(std::string title, uint64_t total,
   assert(total > 0);
   if (debugger)
 m_debugger_id = debugger->GetID();
-
-  // Using a shared_future because std::function needs to be copyable.
-  if (llvm::Expected reporting_thread =
-  ThreadLauncher::LaunchThread(
-  "",
-  [this, future = std::shared_future(
- m_stop_reporting_thread.get_future())]() {
-SendPeriodicReports(future);
-return lldb::thread_result_t();
-  })) {
-m_reporting_thread = std::move(*reporting_thread);
-  } else {
-LLDB_LOG_ERROR(GetLog(LLDBLog::Host), reporting_thread.takeError(),
-   "failed to launch host thread: {}");
-  }
+  std::lock_guard guard(m_mutex);
+  ReportProgress();
 }
 
 Progress::~Progress() {
-  m_stop_reporting_thread.set_value();
-  if (m_reporting_thread.IsJoinable()) {
-m_reporting_thread.Join(nullptr);
+  // Make sure to always report progress completed when this object is
+  // destructed so it indicates the progress dialog/activity should go away.
+  std::lock_guard guard(m_mutex);
+  if (!m_completed) {
+m_completed = m_total;
+ReportProgress();
   }
 }
 
-void Progress::SendPeriodicReports(std::shared_future done) {
-  uint64_t last_completed = 0;
-  Debugger::ReportProgress(m_id, m_title, "", last_completed, m_total,
-   m_debugger_id);
-
-  while (last_completed != m_total &&
- done.wait_for(std::chrono::milliseconds(100)) ==
- std::future_status::timeout) {
-uint64_t current_completed = m_completed.load();
-if (current_completed == last_completed)
-  continue;
-
-if (current_completed == m_total ||
-current_completed < last_completed /*overflow*/) {
-  break;
-}
-
-std::string current_update;
-{
-  std::lock_guard guard(m_update_mutex);
-  current_update = std::move(m_update);
-  m_update.clear();
-}
-Debugger::ReportProgress(m_id, m_title, std::move(current_update),
- current_completed, m_total, m_debugger_id);
-last_completed = current_completed;
+void Progress::Increment(uint64_t amount, std::string update) {
+  if 

[Lldb-commits] [PATCH] D152364: [lldb] Rate limit progress reports -- different approach [WIP-ish]

2023-06-16 Thread Pavel Labath via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc30853460da7: [lldb] Rate limit progress reports -- 
different approach [WIP-ish] (authored by labath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152364

Files:
  lldb/include/lldb/Core/Progress.h
  lldb/source/Core/Progress.cpp

Index: lldb/source/Core/Progress.cpp
===
--- lldb/source/Core/Progress.cpp
+++ lldb/source/Core/Progress.cpp
@@ -9,6 +9,8 @@
 #include "lldb/Core/Progress.h"
 
 #include "lldb/Core/Debugger.h"
+#include "lldb/Host/ThreadLauncher.h"
+#include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/StreamString.h"
 
 using namespace lldb;
@@ -22,39 +24,67 @@
   assert(total > 0);
   if (debugger)
 m_debugger_id = debugger->GetID();
-  std::lock_guard guard(m_mutex);
-  ReportProgress();
+
+  // Using a shared_future because std::function needs to be copyable.
+  if (llvm::Expected reporting_thread =
+  ThreadLauncher::LaunchThread(
+  "",
+  [this, future = std::shared_future(
+ m_stop_reporting_thread.get_future())]() {
+SendPeriodicReports(future);
+return lldb::thread_result_t();
+  })) {
+m_reporting_thread = std::move(*reporting_thread);
+  } else {
+LLDB_LOG_ERROR(GetLog(LLDBLog::Host), reporting_thread.takeError(),
+   "failed to launch host thread: {}");
+  }
 }
 
 Progress::~Progress() {
-  // Make sure to always report progress completed when this object is
-  // destructed so it indicates the progress dialog/activity should go away.
-  std::lock_guard guard(m_mutex);
-  if (!m_completed) {
-m_completed = m_total;
-ReportProgress();
+  m_stop_reporting_thread.set_value();
+  if (m_reporting_thread.IsJoinable()) {
+m_reporting_thread.Join(nullptr);
   }
 }
 
-void Progress::Increment(uint64_t amount, std::string update) {
-  if (amount > 0) {
-std::lock_guard guard(m_mutex);
-// Watch out for unsigned overflow and make sure we don't increment too
-// much and exceed m_total.
-if (amount > (m_total - m_completed))
-  m_completed = m_total;
-else
-  m_completed += amount;
-ReportProgress(update);
+void Progress::SendPeriodicReports(std::shared_future done) {
+  uint64_t last_completed = 0;
+  Debugger::ReportProgress(m_id, m_title, "", last_completed, m_total,
+   m_debugger_id);
+
+  while (last_completed != m_total &&
+ done.wait_for(std::chrono::milliseconds(100)) ==
+ std::future_status::timeout) {
+uint64_t current_completed = m_completed.load();
+if (current_completed == last_completed)
+  continue;
+
+if (current_completed == m_total ||
+current_completed < last_completed /*overflow*/) {
+  break;
+}
+
+std::string current_update;
+{
+  std::lock_guard guard(m_update_mutex);
+  current_update = std::move(m_update);
+  m_update.clear();
+}
+Debugger::ReportProgress(m_id, m_title, std::move(current_update),
+ current_completed, m_total, m_debugger_id);
+last_completed = current_completed;
   }
+
+  Debugger::ReportProgress(m_id, m_title, "", m_total, m_total, m_debugger_id);
 }
 
-void Progress::ReportProgress(std::string update) {
-  if (!m_complete) {
-// Make sure we only send one notification that indicates the progress is
-// complete.
-m_complete = m_completed == m_total;
-Debugger::ReportProgress(m_id, m_title, std::move(update), m_completed,
- m_total, m_debugger_id);
+void Progress::Increment(uint64_t amount, std::string update) {
+  if (amount == 0)
+return;
+  if (!update.empty()) {
+std::lock_guard guard(m_update_mutex);
+m_update = std::move(update);
   }
+  m_completed += amount;
 }
Index: lldb/include/lldb/Core/Progress.h
===
--- lldb/include/lldb/Core/Progress.h
+++ lldb/include/lldb/Core/Progress.h
@@ -9,9 +9,11 @@
 #ifndef LLDB_CORE_PROGRESS_H
 #define LLDB_CORE_PROGRESS_H
 
+#include "lldb/Host/HostThread.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/lldb-types.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -92,24 +94,26 @@
   void Increment(uint64_t amount = 1, std::string update = {});
 
 private:
-  void ReportProgress(std::string update = {});
+  void SendPeriodicReports(std::shared_future done);
+  void ReportProgress(std::string update);
   static std::atomic g_id;
   /// The title of the progress activity.
   std::string m_title;
-  std::mutex m_mutex;
   /// A unique integer identifier for progress reporting.
   const uint64_t m_id;
   /// How much work ([0...m_total]) that has been 

[Lldb-commits] [lldb] 244fcec - [lldb] Fix MainLoopTest for changes in D152712

2023-06-16 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2023-06-16T09:05:27+02:00
New Revision: 244fcecb90fa7a3fb710ca5768d3bae9af5868cc

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

LOG: [lldb] Fix MainLoopTest for changes in D152712

Added: 


Modified: 
lldb/unittests/Host/MainLoopTest.cpp

Removed: 




diff  --git a/lldb/unittests/Host/MainLoopTest.cpp 
b/lldb/unittests/Host/MainLoopTest.cpp
index b1857fec3c49e..4084e90782fd5 100644
--- a/lldb/unittests/Host/MainLoopTest.cpp
+++ b/lldb/unittests/Host/MainLoopTest.cpp
@@ -9,6 +9,7 @@
 #include "lldb/Host/MainLoop.h"
 #include "TestingSupport/SubsystemRAII.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/PseudoTerminal.h"
 #include "lldb/Host/common/TCPSocket.h"
 #include "llvm/Testing/Support/Error.h"
@@ -20,7 +21,7 @@ using namespace lldb_private;
 namespace {
 class MainLoopTest : public testing::Test {
 public:
-  SubsystemRAII subsystems;
+  SubsystemRAII subsystems;
 
   void SetUp() override {
 bool child_processes_inherit = false;



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


[Lldb-commits] [lldb] c308534 - [lldb] Rate limit progress reports -- different approach [WIP-ish]

2023-06-16 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2023-06-16T08:28:29+02:00
New Revision: c30853460da7446f92bc1e516f9cbe2c5df6e136

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

LOG: [lldb] Rate limit progress reports -- different approach [WIP-ish]

Have the Progress class spawn a thread to periodically send progress
reports.

The reporting period could be made configurable, but for now I've
hardcoded it to 100ms. (This is the main WIP part)

It could be argued that creating a thread for progress reporting adds
overhead, but I would counter that by saying "If the task is so fast
that creating a thread noticably slows it down, then it really doesn't
need progress reporting".

For me, this speeds up DWARF indexing by about 1.5% (which is only
slightly above the error bars), but I expect it will have a much bigger
impact in situations where printing a single progress update takes a
nontrivial amount of time.

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

Added: 


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

Removed: 




diff  --git a/lldb/include/lldb/Core/Progress.h 
b/lldb/include/lldb/Core/Progress.h
index b2b8781a43b05..3bafd3d4b34ea 100644
--- a/lldb/include/lldb/Core/Progress.h
+++ b/lldb/include/lldb/Core/Progress.h
@@ -9,9 +9,11 @@
 #ifndef LLDB_CORE_PROGRESS_H
 #define LLDB_CORE_PROGRESS_H
 
+#include "lldb/Host/HostThread.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/lldb-types.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -92,24 +94,26 @@ class Progress {
   void Increment(uint64_t amount = 1, std::string update = {});
 
 private:
-  void ReportProgress(std::string update = {});
+  void SendPeriodicReports(std::shared_future done);
+  void ReportProgress(std::string update);
   static std::atomic g_id;
   /// The title of the progress activity.
   std::string m_title;
-  std::mutex m_mutex;
   /// A unique integer identifier for progress reporting.
   const uint64_t m_id;
   /// How much work ([0...m_total]) that has been completed.
-  uint64_t m_completed;
+  std::atomic m_completed;
   /// Total amount of work, UINT64_MAX for non deterministic progress.
   const uint64_t m_total;
   /// The optional debugger ID to report progress to. If this has no value then
   /// all debuggers will receive this event.
   std::optional m_debugger_id;
-  /// Set to true when progress has been reported where m_completed == m_total
-  /// to ensure that we don't send progress updates after progress has
-  /// completed.
-  bool m_complete = false;
+
+  std::mutex m_update_mutex;
+  std::string m_update;
+
+  std::promise m_stop_reporting_thread;
+  HostThread m_reporting_thread;
 };
 
 } // namespace lldb_private

diff  --git a/lldb/source/Core/Progress.cpp b/lldb/source/Core/Progress.cpp
index 08be73f1470f3..a531b9b70437e 100644
--- a/lldb/source/Core/Progress.cpp
+++ b/lldb/source/Core/Progress.cpp
@@ -9,6 +9,8 @@
 #include "lldb/Core/Progress.h"
 
 #include "lldb/Core/Debugger.h"
+#include "lldb/Host/ThreadLauncher.h"
+#include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/StreamString.h"
 
 using namespace lldb;
@@ -22,39 +24,67 @@ Progress::Progress(std::string title, uint64_t total,
   assert(total > 0);
   if (debugger)
 m_debugger_id = debugger->GetID();
-  std::lock_guard guard(m_mutex);
-  ReportProgress();
+
+  // Using a shared_future because std::function needs to be copyable.
+  if (llvm::Expected reporting_thread =
+  ThreadLauncher::LaunchThread(
+  "",
+  [this, future = std::shared_future(
+ m_stop_reporting_thread.get_future())]() {
+SendPeriodicReports(future);
+return lldb::thread_result_t();
+  })) {
+m_reporting_thread = std::move(*reporting_thread);
+  } else {
+LLDB_LOG_ERROR(GetLog(LLDBLog::Host), reporting_thread.takeError(),
+   "failed to launch host thread: {}");
+  }
 }
 
 Progress::~Progress() {
-  // Make sure to always report progress completed when this object is
-  // destructed so it indicates the progress dialog/activity should go away.
-  std::lock_guard guard(m_mutex);
-  if (!m_completed) {
-m_completed = m_total;
-ReportProgress();
+  m_stop_reporting_thread.set_value();
+  if (m_reporting_thread.IsJoinable()) {
+m_reporting_thread.Join(nullptr);
   }
 }
 
-void Progress::Increment(uint64_t amount, std::string update) {
-  if (amount > 0) {
-std::lock_guard guard(m_mutex);
-// Watch out for unsigned overflow and make sure we don't increment too
-// much and exceed m_total.
-if (amount > (m_total - m_completed))
-  m_completed = m_total;
-else
-  m_completed += amount;
-ReportProgress(update);
+void 

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

2023-06-16 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 531992.
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, ResolveSharedLibraryPathWithNormalFile) {
+  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::ResolveSharedLibraryPath(
+  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, ResolveSharedLibraryPathWithZipMissing) {
+  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::ResolveSharedLibraryPath(
+  file_spec, file_kind, file_path, file_offset, file_size));
+}
+
+TEST_F(ZipFileResolverTest, ResolveSharedLibraryPathWithZipExisting) {
+  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::ResolveSharedLibraryPath(
+  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;
+

[Lldb-commits] [PATCH] D153043: [lldb] Fix handling of cfi_restore in the unwinder

2023-06-16 Thread Jaroslav Sevcik via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG07b9e6ed0db2: [lldb] Fix handling of cfi_restore in the 
unwinder (authored by jarin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153043

Files:
  lldb/source/Symbol/DWARFCallFrameInfo.cpp
  lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s
  lldb/test/Shell/Unwind/eh-frame-dwarf-unwind-abort.test


Index: lldb/test/Shell/Unwind/eh-frame-dwarf-unwind-abort.test
===
--- /dev/null
+++ lldb/test/Shell/Unwind/eh-frame-dwarf-unwind-abort.test
@@ -0,0 +1,21 @@
+# Test restoring of register values.
+
+# UNSUPPORTED: system-windows
+# REQUIRES: target-x86_64, native
+
+# RUN: %clang_host %p/Inputs/call-asm.c 
%p/Inputs/eh-frame-dwarf-unwind-abort.s -o %t
+# RUN: %lldb %t -s %s -o exit | FileCheck %s
+
+process launch
+# CHECK: stop reason = signal SIGTRAP
+
+thread backtrace
+# CHECK: frame #0: {{.*}}`asm_main + 23
+# CHECK: frame #1: {{.*}}`main + {{.*}}
+
+target modules show-unwind -n asm_main
+# CHECK: eh_frame UnwindPlan:
+# CHECK: row[0]:0: CFA=rsp +8 => rip=[CFA-8]
+# CHECK: row[1]:   14: CFA=rsp+16 => rbp=[CFA-16] rip=[CFA-8]
+# CHECK: row[2]:   17: CFA=rbp+16 => rbp=[CFA-16] rip=[CFA-8]
+# CHECK: row[3]:   22: CFA=rsp +8 => rip=[CFA-8]
Index: lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s
===
--- /dev/null
+++ lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s
@@ -0,0 +1,25 @@
+.text
+.globl  asm_main
+asm_main:
+.cfi_startproc
+cmpb $0x0, g_hard_abort(%rip)
+jne .L
+
+pushq   %rbp
+.cfi_def_cfa_offset 16
+.cfi_offset 6, -16
+movq%rsp, %rbp
+.cfi_def_cfa_register 6
+callq   abort
+.L:
+.cfi_def_cfa 7, 8
+.cfi_restore 6
+int3
+ud2
+.cfi_endproc
+
+   .data
+   .globl  g_hard_abort
+g_hard_abort:
+   .byte   1
+   .size   g_hard_abort, 1
\ No newline at end of file
Index: lldb/source/Symbol/DWARFCallFrameInfo.cpp
===
--- lldb/source/Symbol/DWARFCallFrameInfo.cpp
+++ lldb/source/Symbol/DWARFCallFrameInfo.cpp
@@ -674,6 +674,11 @@
   unwind_plan.GetRowAtIndex(0)->GetRegisterInfo(reg_num,
 reg_location))
 row->SetRegisterInfo(reg_num, reg_location);
+  else {
+// If the register was not set in the first row, remove the
+// register info to keep the unmodified value from the caller.
+row->RemoveRegisterInfo(reg_num);
+  }
   break;
 }
 }


Index: lldb/test/Shell/Unwind/eh-frame-dwarf-unwind-abort.test
===
--- /dev/null
+++ lldb/test/Shell/Unwind/eh-frame-dwarf-unwind-abort.test
@@ -0,0 +1,21 @@
+# Test restoring of register values.
+
+# UNSUPPORTED: system-windows
+# REQUIRES: target-x86_64, native
+
+# RUN: %clang_host %p/Inputs/call-asm.c %p/Inputs/eh-frame-dwarf-unwind-abort.s -o %t
+# RUN: %lldb %t -s %s -o exit | FileCheck %s
+
+process launch
+# CHECK: stop reason = signal SIGTRAP
+
+thread backtrace
+# CHECK: frame #0: {{.*}}`asm_main + 23
+# CHECK: frame #1: {{.*}}`main + {{.*}}
+
+target modules show-unwind -n asm_main
+# CHECK: eh_frame UnwindPlan:
+# CHECK: row[0]:0: CFA=rsp +8 => rip=[CFA-8]
+# CHECK: row[1]:   14: CFA=rsp+16 => rbp=[CFA-16] rip=[CFA-8]
+# CHECK: row[2]:   17: CFA=rbp+16 => rbp=[CFA-16] rip=[CFA-8]
+# CHECK: row[3]:   22: CFA=rsp +8 => rip=[CFA-8]
Index: lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s
===
--- /dev/null
+++ lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s
@@ -0,0 +1,25 @@
+.text
+.globl  asm_main
+asm_main:
+.cfi_startproc
+cmpb $0x0, g_hard_abort(%rip)
+jne .L
+
+pushq   %rbp
+.cfi_def_cfa_offset 16
+.cfi_offset 6, -16
+movq%rsp, %rbp
+.cfi_def_cfa_register 6
+callq   abort
+.L:
+.cfi_def_cfa 7, 8
+.cfi_restore 6
+int3
+ud2
+.cfi_endproc
+
+	.data
+	.globl  g_hard_abort
+g_hard_abort:
+	.byte   1
+	.size   g_hard_abort, 1
\ No newline at end of file
Index: lldb/source/Symbol/DWARFCallFrameInfo.cpp
===
--- lldb/source/Symbol/DWARFCallFrameInfo.cpp
+++ lldb/source/Symbol/DWARFCallFrameInfo.cpp
@@ -674,6 +674,11 @@
   unwind_plan.GetRowAtIndex(0)->GetRegisterInfo(reg_num,
 reg_location))
 row->SetRegisterInfo(reg_num, reg_location);
+

[Lldb-commits] [lldb] 07b9e6e - [lldb] Fix handling of cfi_restore in the unwinder

2023-06-16 Thread Jaroslav Sevcik via lldb-commits

Author: Jaroslav Sevcik
Date: 2023-06-16T08:01:29+02:00
New Revision: 07b9e6ed0db206912b99c153a6bcfcb41f792cc5

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

LOG: [lldb] Fix handling of cfi_restore in the unwinder

Currently, lldb's unwinder ignores cfi_restore opcodes for registers
that are not set in the first row of the unwinding info. This prevents
unwinding of failed assertion in Chrome/v8 (https://github.com/v8/v8).
The attached test is an x64 copy of v8's function that failed to unwind
correctly (V8_Fatal).

This patch changes handling of cfi_restore to reset the location if
the first unwind table row does not map the restored register.

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

Added: 
lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s
lldb/test/Shell/Unwind/eh-frame-dwarf-unwind-abort.test

Modified: 
lldb/source/Symbol/DWARFCallFrameInfo.cpp

Removed: 




diff  --git a/lldb/source/Symbol/DWARFCallFrameInfo.cpp 
b/lldb/source/Symbol/DWARFCallFrameInfo.cpp
index be9f64356b4e0..dc54d13ae23cb 100644
--- a/lldb/source/Symbol/DWARFCallFrameInfo.cpp
+++ b/lldb/source/Symbol/DWARFCallFrameInfo.cpp
@@ -674,6 +674,11 @@ bool DWARFCallFrameInfo::FDEToUnwindPlan(dw_offset_t 
dwarf_offset,
   unwind_plan.GetRowAtIndex(0)->GetRegisterInfo(reg_num,
 reg_location))
 row->SetRegisterInfo(reg_num, reg_location);
+  else {
+// If the register was not set in the first row, remove the
+// register info to keep the unmodified value from the caller.
+row->RemoveRegisterInfo(reg_num);
+  }
   break;
 }
 }

diff  --git a/lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s 
b/lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s
new file mode 100644
index 0..e03a69f67f8f9
--- /dev/null
+++ b/lldb/test/Shell/Unwind/Inputs/eh-frame-dwarf-unwind-abort.s
@@ -0,0 +1,25 @@
+.text
+.globl  asm_main
+asm_main:
+.cfi_startproc
+cmpb $0x0, g_hard_abort(%rip)
+jne .L
+
+pushq   %rbp
+.cfi_def_cfa_offset 16
+.cfi_offset 6, -16
+movq%rsp, %rbp
+.cfi_def_cfa_register 6
+callq   abort
+.L:
+.cfi_def_cfa 7, 8
+.cfi_restore 6
+int3
+ud2
+.cfi_endproc
+
+   .data
+   .globl  g_hard_abort
+g_hard_abort:
+   .byte   1
+   .size   g_hard_abort, 1
\ No newline at end of file

diff  --git a/lldb/test/Shell/Unwind/eh-frame-dwarf-unwind-abort.test 
b/lldb/test/Shell/Unwind/eh-frame-dwarf-unwind-abort.test
new file mode 100644
index 0..ccf973d9313c2
--- /dev/null
+++ b/lldb/test/Shell/Unwind/eh-frame-dwarf-unwind-abort.test
@@ -0,0 +1,21 @@
+# Test restoring of register values.
+
+# UNSUPPORTED: system-windows
+# REQUIRES: target-x86_64, native
+
+# RUN: %clang_host %p/Inputs/call-asm.c 
%p/Inputs/eh-frame-dwarf-unwind-abort.s -o %t
+# RUN: %lldb %t -s %s -o exit | FileCheck %s
+
+process launch
+# CHECK: stop reason = signal SIGTRAP
+
+thread backtrace
+# CHECK: frame #0: {{.*}}`asm_main + 23
+# CHECK: frame #1: {{.*}}`main + {{.*}}
+
+target modules show-unwind -n asm_main
+# CHECK: eh_frame UnwindPlan:
+# CHECK: row[0]:0: CFA=rsp +8 => rip=[CFA-8]
+# CHECK: row[1]:   14: CFA=rsp+16 => rbp=[CFA-16] rip=[CFA-8]
+# CHECK: row[2]:   17: CFA=rbp+16 => rbp=[CFA-16] rip=[CFA-8]
+# CHECK: row[3]:   22: CFA=rsp +8 => rip=[CFA-8]



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