[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread Anthony Ha via lldb-commits

Awfa wrote:

> MD5 is insufficient for claiming that files are identical; how do we migrate 
> this to a secure hash?

Is there an attack vector you're concerned about?

Or are you wary of workflow friction when a file won't upload to the remote 
platform because the hashes accidently collide?

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


[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread Ed Maste via lldb-commits

emaste wrote:

MD5 is insufficient for claiming that files are identical; how do we migrate 
this to a secure hash?

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


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-16 Thread Ed Maste via lldb-commits

emaste wrote:

> is there not a Posix way to get these

Not really. On FreeBSD these generally come from sysctl(s).

Of the ones added in this pull request SetParentProcessID is already handled on 
FreeBSD, while SetProcessGroupID, SetProcessSessionID, SetUserTime, 
SetSystemTime, SetCumulativeUserTime, SetCumulativeSystemTime are not

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


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-16 Thread via lldb-commits

jimingham wrote:


> On Apr 16, 2024, at 5:17 PM, Fred Grim ***@***.***> wrote:
> 
> 
> These seem like fairly POSIX-y bits of data, is there not a Posix way to get 
> these (so other posix systems will also get this info?)
> 
> Not that I know of for arbitrary processes in linux. fwiw the original code 
> without these values got similar bits out of the proc filesystem
> 
That's sad, but not your doing...

> Also, it looks like you added user time and system time information, but you 
> didn't test that those get valid values.
> 
> I did not. My concern here is that this would make for flaky tests. The issue 
> is that these times are going to be very dependent on the cpus they are 
> scheduled to, what else is running on that same machine and so on. I guess we 
> could do a bunch of stuff to pin the unit test process in place and make it 
> more controllable but that tends to imply permissions for the host executing 
> the unit test. Or maybe you were thinking of another way? I am all ears if so.
> 

The user and system times should be monotonically increasing.  So you could 
stop at a breakpoint, fetch the times, then run your program through a little 
spin loop to burn some CPU before hitting a second breakpoint.   Then get the 
times again and assert that they are > the first set. You could also set a 
timer in the test between the first and second stop and assert that the 
difference in system and user time is less than or equal to the timer 
difference.  A single threaded program can only run on one core at a time, so 
that should always be true.

Jim


> —
> Reply to this email directly, view it on GitHub 
> , or 
> unsubscribe 
> .
> You are receiving this because you are on a team that was mentioned.
> 



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


[Lldb-commits] [lldb] [lldb] Have lldb-server assign ports to children in platform mode (PR #88845)

2024-04-16 Thread Anthony Ha via lldb-commits


@@ -324,6 +335,10 @@ int main_platform(int argc, char *argv[]) {
   // connections while a connection is active.
   acceptor_up.reset();
 }
+
+GDBRemoteCommunicationServerPlatform::PortMap portmap_for_child;
+portmap_for_child.AllowPort(*port);

Awfa wrote:

I removed the optional port and changed it - so reading the code should be more 
straightforward, and we shouldn't have to think about this.

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


[Lldb-commits] [lldb] [lldb] Have lldb-server assign ports to children in platform mode (PR #88845)

2024-04-16 Thread Anthony Ha via lldb-commits


@@ -301,13 +294,31 @@ int main_platform(int argc, char *argv[]) {
   exit(socket_error);
 }
 printf("Connection established.\n");
+
+std::optional port = 0;

Awfa wrote:

I removed the optional port here, and just set the portmap within the 
availablePort branch.

I also realized I forgot to take into account the non-server mode, so I put 
`platform.SetPortMap(std::move(gdbserver_portmap));` for the else branch where 
`lldb-server` isn't running with the `--server` flag.

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


[Lldb-commits] [lldb] [lldb] Have lldb-server assign ports to children in platform mode (PR #88845)

2024-04-16 Thread Anthony Ha via lldb-commits


@@ -301,13 +294,31 @@ int main_platform(int argc, char *argv[]) {
   exit(socket_error);
 }
 printf("Connection established.\n");
+
+std::optional port = 0;
 if (g_server) {
   // Collect child zombie processes.
 #if !defined(_WIN32)
-  while (waitpid(-1, nullptr, WNOHANG) > 0)
-;
+  auto waitResult = waitpid(-1, nullptr, WNOHANG);
+  while (waitResult > 0) {

Awfa wrote:

Updated

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


[Lldb-commits] [lldb] [lldb] Have lldb-server assign ports to children in platform mode (PR #88845)

2024-04-16 Thread Anthony Ha via lldb-commits


@@ -301,13 +294,31 @@ int main_platform(int argc, char *argv[]) {
   exit(socket_error);
 }
 printf("Connection established.\n");
+
+std::optional port = 0;
 if (g_server) {
   // Collect child zombie processes.
 #if !defined(_WIN32)
-  while (waitpid(-1, nullptr, WNOHANG) > 0)
-;
+  auto waitResult = waitpid(-1, nullptr, WNOHANG);
+  while (waitResult > 0) {
+// waitResult is the child pid
+gdbserver_portmap.FreePortForProcess(waitResult);
+waitResult = waitpid(-1, nullptr, WNOHANG);
+  }
 #endif
-  if (fork()) {
+  llvm::Expected available_port =
+  gdbserver_portmap.GetNextAvailablePort();
+  if (available_port)
+port = *available_port;
+
+  else {

Awfa wrote:

In the else branch, the connection to the platform will just be dropped, and an 
error printed to stderr.

This is a recoverable error in the sense that when a child platform process 
dies, a port will become available again - so it's desirable not to crash 
`lldb-server`.

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


[Lldb-commits] [lldb] [lldb] Have lldb-server assign ports to children in platform mode (PR #88845)

2024-04-16 Thread Anthony Ha via lldb-commits

https://github.com/Awfa updated https://github.com/llvm/llvm-project/pull/88845

>From 3d75f42b5f61ea126001919491aa09ebd15ba9f8 Mon Sep 17 00:00:00 2001
From: Anthony Ha 
Date: Mon, 15 Apr 2024 19:36:34 +
Subject: [PATCH 1/2] [lldb] Have lldb-server assign ports to children in
 platform mode

---
 lldb/tools/lldb-server/lldb-platform.cpp | 41 
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/lldb/tools/lldb-server/lldb-platform.cpp 
b/lldb/tools/lldb-server/lldb-platform.cpp
index 3e126584eb25b4..384709ba79b656 100644
--- a/lldb/tools/lldb-server/lldb-platform.cpp
+++ b/lldb/tools/lldb-server/lldb-platform.cpp
@@ -282,17 +282,10 @@ int main_platform(int argc, char *argv[]) {
 }
   }
 
-  do {
-GDBRemoteCommunicationServerPlatform platform(
-acceptor_up->GetSocketProtocol(), acceptor_up->GetSocketScheme());
-
-if (port_offset > 0)
-  platform.SetPortOffset(port_offset);
-
-if (!gdbserver_portmap.empty()) {
-  platform.SetPortMap(std::move(gdbserver_portmap));
-}
+  GDBRemoteCommunicationServerPlatform platform(
+  acceptor_up->GetSocketProtocol(), acceptor_up->GetSocketScheme());
 
+  do {
 const bool children_inherit_accept_socket = true;
 Connection *conn = nullptr;
 error = acceptor_up->Accept(children_inherit_accept_socket, conn);
@@ -301,13 +294,31 @@ int main_platform(int argc, char *argv[]) {
   exit(socket_error);
 }
 printf("Connection established.\n");
+
+std::optional port = 0;
 if (g_server) {
   // Collect child zombie processes.
 #if !defined(_WIN32)
-  while (waitpid(-1, nullptr, WNOHANG) > 0)
-;
+  auto waitResult = waitpid(-1, nullptr, WNOHANG);
+  while (waitResult > 0) {
+// waitResult is the child pid
+gdbserver_portmap.FreePortForProcess(waitResult);
+waitResult = waitpid(-1, nullptr, WNOHANG);
+  }
 #endif
-  if (fork()) {
+  llvm::Expected available_port =
+  gdbserver_portmap.GetNextAvailablePort();
+  if (available_port)
+port = *available_port;
+
+  else {
+fprintf(stderr, "no available port for connection - dropping...\n");
+delete conn;
+continue;
+  }
+  auto childPid = fork();
+  if (childPid) {
+gdbserver_portmap.AssociatePortWithProcess(*available_port, childPid);
 // Parent doesn't need a connection to the lldb client
 delete conn;
 
@@ -324,6 +335,10 @@ int main_platform(int argc, char *argv[]) {
   // connections while a connection is active.
   acceptor_up.reset();
 }
+
+GDBRemoteCommunicationServerPlatform::PortMap portmap_for_child;
+portmap_for_child.AllowPort(*port);
+platform.SetPortMap(std::move(portmap_for_child));
 platform.SetConnection(std::unique_ptr(conn));
 
 if (platform.IsConnected()) {

>From 27782fb03b3705e9ff4a5b3cc0d17c8448919be9 Mon Sep 17 00:00:00 2001
From: Anthony Ha 
Date: Wed, 17 Apr 2024 00:46:58 +
Subject: [PATCH 2/2] amend! [lldb] Have lldb-server assign ports to children
 in platform mode

[lldb] Have lldb-server assign ports to children in platform mode
---
 lldb/tools/lldb-server/lldb-platform.cpp | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/lldb/tools/lldb-server/lldb-platform.cpp 
b/lldb/tools/lldb-server/lldb-platform.cpp
index 384709ba79b656..ff91a3318cf0d5 100644
--- a/lldb/tools/lldb-server/lldb-platform.cpp
+++ b/lldb/tools/lldb-server/lldb-platform.cpp
@@ -295,27 +295,31 @@ int main_platform(int argc, char *argv[]) {
 }
 printf("Connection established.\n");
 
-std::optional port = 0;
 if (g_server) {
   // Collect child zombie processes.
 #if !defined(_WIN32)
-  auto waitResult = waitpid(-1, nullptr, WNOHANG);
-  while (waitResult > 0) {
+  ::pid_t waitResult;
+  while ((waitResult = waitpid(-1, nullptr, WNOHANG)) > 0) {
 // waitResult is the child pid
 gdbserver_portmap.FreePortForProcess(waitResult);
-waitResult = waitpid(-1, nullptr, WNOHANG);
   }
 #endif
+  // TODO: Clean up portmap for Windows when children die
+
+  // After collecting zombie ports, get the next available
+  GDBRemoteCommunicationServerPlatform::PortMap portmap_for_child;
   llvm::Expected available_port =
   gdbserver_portmap.GetNextAvailablePort();
   if (available_port)
-port = *available_port;
-
+portmap_for_child.AllowPort(*available_port);
   else {
-fprintf(stderr, "no available port for connection - dropping...\n");
+fprintf(stderr,
+"no available gdbserver port for connection - dropping...\n");
 delete conn;
 continue;
   }
+  platform.SetPortMap(std::move(portmap_for_child));
+
   auto childPid = fork();
   if (childPid) {
 gdbserver_portmap.AssociatePortWithProcess(*available_port, childPid);
@@ -334,11 +338,11 @@ int 

[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread Anthony Ha via lldb-commits


@@ -1197,6 +1197,34 @@ Status Platform::PutFile(const FileSpec , const 
FileSpec ,
   if (!source_file)
 return Status(source_file.takeError());
   Status error;
+
+  bool requires_upload = true;
+  {

Awfa wrote:

Just removed the scoping - so the md5 vars are part of the main scope.

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


[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread Anthony Ha via lldb-commits


@@ -1184,7 +1184,7 @@ bool Platform::IsCompatibleArchitecture(const ArchSpec 
,
 Status Platform::PutFile(const FileSpec , const FileSpec ,
  uint32_t uid, uint32_t gid) {
   Log *log = GetLog(LLDBLog::Platform);
-  LLDB_LOGF(log, "[PutFile] Using block by block transfer\n");
+  LLDB_LOGF(log, "[PutFile] Using block by block transfer");

Awfa wrote:

I decided to leave it out of this PR

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


[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread Anthony Ha via lldb-commits

https://github.com/Awfa updated https://github.com/llvm/llvm-project/pull/88812

>From 095696411172034f80233f1722e293c1f458d67f Mon Sep 17 00:00:00 2001
From: Anthony Ha 
Date: Mon, 15 Apr 2024 19:34:19 +
Subject: [PATCH 1/3] [lldb] Skip remote PutFile when MD5 hashes equal

---
 .../gdb-server/PlatformRemoteGDBServer.cpp|  9 +
 .../gdb-server/PlatformRemoteGDBServer.h  |  3 ++
 .../GDBRemoteCommunicationClient.cpp  | 36 +--
 lldb/source/Target/Platform.cpp   | 30 +++-
 .../GDBRemoteCommunicationClientTest.cpp  | 23 
 5 files changed, 98 insertions(+), 3 deletions(-)

diff --git 
a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp 
b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 88f1ad15b6b485..d9f3e40019cf29 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -684,6 +684,15 @@ Status PlatformRemoteGDBServer::RunShellCommand(
   signo_ptr, command_output, timeout);
 }
 
+bool PlatformRemoteGDBServer::CalculateMD5(const FileSpec _spec,
+   uint64_t , uint64_t ) {
+  if (IsConnected()) {
+// Note that high/low are switched in the gdb remote communication client
+return m_gdb_client_up->CalculateMD5(file_spec, high, low);
+  }
+  return false;
+}
+
 void PlatformRemoteGDBServer::CalculateTrapHandlerSymbolNames() {
   m_trap_handlers.push_back(ConstString("_sigtramp"));
 }
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h 
b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
index 638f7db5ef800c..d83fc386f59427 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
@@ -146,6 +146,9 @@ class PlatformRemoteGDBServer : public Platform, private 
UserIDResolver {
 
   void CalculateTrapHandlerSymbolNames() override;
 
+  bool CalculateMD5(const FileSpec _spec, uint64_t ,
+uint64_t ) override;
+
   const lldb::UnixSignalsSP () override;
 
   size_t ConnectToWaitingProcesses(lldb_private::Debugger ,
diff --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 1f6116967a4f64..8c79d5fecf12fe 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -3433,8 +3433,40 @@ bool GDBRemoteCommunicationClient::CalculateMD5(
   return false;
 if (response.Peek() && *response.Peek() == 'x')
   return false;
-low = response.GetHexMaxU64(false, UINT64_MAX);
-high = response.GetHexMaxU64(false, UINT64_MAX);
+
+// GDBRemoteCommunicationServerCommon::Handle_vFile_MD5 concatenates low 
and
+// high hex strings. We can't use response.GetHexMaxU64 because that can't
+// handle the concatenated hex string. What would happen is parsing the low
+// would consume the whole response packet - which is a bug. Instead, we 
get
+// the byte string for each low and high hex separately, and parse them.
+//
+// An alternate way to handle this is to change the server to put a
+// delimiter between the low/high parts, and change the client to parse the
+// delimiter. However, we choose not to do this so existing lldb-servers
+// don't have to be patched
+
+// Get low part
+auto part = response.GetStringRef().substr(response.GetFilePos(),
+   sizeof(uint64_t) * 2);
+if (part.size() != sizeof(uint64_t) * 2)
+  return false;
+response.SetFilePos(response.GetFilePos() + part.size());
+
+bool conversionErrored = part.getAsInteger(16, low);
+if (conversionErrored)
+  return false;
+
+// Get high part
+part = response.GetStringRef().substr(response.GetFilePos(),
+  sizeof(uint64_t) * 2);
+if (part.size() != sizeof(uint64_t) * 2)
+  return false;
+response.SetFilePos(response.GetFilePos() + part.size());
+
+conversionErrored = part.getAsInteger(16, high);
+if (conversionErrored)
+  return false;
+
 return true;
   }
   return false;
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 4ce290dfbe035f..cdbafb17a5df4d 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -1184,7 +1184,7 @@ bool Platform::IsCompatibleArchitecture(const ArchSpec 
,
 Status Platform::PutFile(const FileSpec , const FileSpec ,
  uint32_t uid, uint32_t gid) {
   Log *log = GetLog(LLDBLog::Platform);
-  LLDB_LOGF(log, "[PutFile] Using block by block transfer\n");
+  LLDB_LOGF(log, "[PutFile] Using block 

[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-16 Thread Fred Grim via lldb-commits

feg208 wrote:

> These seem like fairly POSIX-y bits of data, is there not a Posix way to get 
> these (so other posix systems will also get this info?)

Not that I know of for arbitrary processes in linux. fwiw the original code 
without these values got similar bits out of the proc filesystem

> 
> Also, it looks like you added user time and system time information, but you 
> didn't test that those get valid values.

I did not. My concern here is that this would make for flaky tests. The issue 
is that these times are going to be very dependent on the cpus they are 
scheduled to, what else is running on that same machine and so on. I guess we 
could do a bunch of stuff to pin the unit test process in place and make it 
more controllable but that tends to imply permissions for the host executing 
the unit test. Or maybe you were thinking of another way? I am all ears if so.  

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


[Lldb-commits] [lldb] Add asan tests for libsanitizers. (#88349) (PR #88962)

2024-04-16 Thread Usama Hameed via lldb-commits

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


[Lldb-commits] [lldb] 988ffd0 - Add asan tests for libsanitizers. (#88349) (#88962)

2024-04-16 Thread via lldb-commits

Author: Usama Hameed
Date: 2024-04-16T16:00:14-07:00
New Revision: 988ffd06722e7e056b239efe497345ac97be33db

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

LOG: Add asan tests for libsanitizers. (#88349) (#88962)

The previous patch was reverted because the test fails to build when
libsanitizers is not present. This patch catches the BuildError
exception and skips the test appropriately.

This patch tests LLDB integration with libsanitizers for ASan.

rdar://111856681

Added: 


Modified: 
lldb/test/API/functionalities/asan/Makefile
lldb/test/API/functionalities/asan/TestMemoryHistory.py
lldb/test/API/functionalities/asan/TestReportData.py

Removed: 




diff  --git a/lldb/test/API/functionalities/asan/Makefile 
b/lldb/test/API/functionalities/asan/Makefile
index 4913a18d8cc6f9..d66696fed7078f 100644
--- a/lldb/test/API/functionalities/asan/Makefile
+++ b/lldb/test/API/functionalities/asan/Makefile
@@ -1,4 +1,8 @@
 C_SOURCES := main.c
-CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info
+asan: CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info
+asan: all
+
+libsanitizers: CFLAGS_EXTRAS := -fsanitize=address -fsanitize-stable-abi -g 
-gcolumn-info
+libsanitizers: all
 
 include Makefile.rules

diff  --git a/lldb/test/API/functionalities/asan/TestMemoryHistory.py 
b/lldb/test/API/functionalities/asan/TestMemoryHistory.py
index 00162ae8822c74..41ab25823f5cc6 100644
--- a/lldb/test/API/functionalities/asan/TestMemoryHistory.py
+++ b/lldb/test/API/functionalities/asan/TestMemoryHistory.py
@@ -8,16 +8,24 @@
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbplatform
 from lldbsuite.test import lldbutil
-
+from lldbsuite.test_event.build_exception import BuildError
 
 class AsanTestCase(TestBase):
 @skipIfFreeBSD  # llvm.org/pr21136 runtimes not yet available by default
 @expectedFailureNetBSD
 @skipUnlessAddressSanitizer
 def test(self):
-self.build()
+self.build(make_targets=["asan"])
 self.asan_tests()
 
+@skipIf(oslist=no_match(["macosx"]))
+def test_libsanitizers_asan(self):
+try:
+self.build(make_targets=["libsanitizers"])
+except BuildError as e:
+self.skipTest("failed to build with libsanitizers")
+self.libsanitizer_tests()
+
 def setUp(self):
 # Call super's setUp().
 TestBase.setUp(self)
@@ -26,6 +34,68 @@ def setUp(self):
 self.line_free = line_number("main.c", "// free line")
 self.line_breakpoint = line_number("main.c", "// break line")
 
+# Test line numbers: rdar://126237493
+def libsanitizer_tests(self):
+target = self.createTestTarget()
+
+self.runCmd(
+"env SanitizersAddress=1 MallocSanitizerZone=1 
MallocSecureAllocator=0"
+)
+
+self.runCmd("run")
+
+# In libsanitizers, memory history is not supported until a report has 
been generated
+self.expect(
+"thread list",
+"Process should be stopped due to ASan report",
+substrs=["stopped", "stop reason = Use of deallocated memory"],
+)
+
+# test the 'memory history' command
+self.expect(
+"memory history 'pointer'",
+substrs=[
+"Memory deallocated by Thread",
+"a.out`f2",
+"main.c",
+"Memory allocated by Thread",
+"a.out`f1",
+"main.c",
+],
+)
+
+# do the same using SB API
+process = self.dbg.GetSelectedTarget().process
+val = (
+
process.GetSelectedThread().GetSelectedFrame().EvaluateExpression("pointer")
+)
+addr = val.GetValueAsUnsigned()
+threads = process.GetHistoryThreads(addr)
+self.assertEqual(threads.GetSize(), 2)
+
+history_thread = threads.GetThreadAtIndex(0)
+self.assertTrue(history_thread.num_frames >= 2)
+self.assertEqual(
+
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
+"main.c",
+)
+
+history_thread = threads.GetThreadAtIndex(1)
+self.assertTrue(history_thread.num_frames >= 2)
+self.assertEqual(
+
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
+"main.c",
+)
+
+# let's free the container (SBThreadCollection) and see if the
+# SBThreads still live
+threads = None
+self.assertTrue(history_thread.num_frames >= 2)
+self.assertEqual(
+
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
+"main.c",
+)
+
 def asan_tests(self):
 target = self.createTestTarget()
 

diff  

[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-16 Thread via lldb-commits

jimingham wrote:

These seem like fairly POSIX-y bits of data, is there not a Posix way to get 
these (so other posix systems will also get this info?)

Also, it looks like you added user time and system time information, but you 
didn't test that those get valid values.

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


[Lldb-commits] [lldb] [llvm] Add support for using foreign type units in .debug_names. (PR #87740)

2024-04-16 Thread Alexander Yermolovich via lldb-commits

ayermolo wrote:

@clayborg 
Figured I reply here to your comment:
https://github.com/llvm/llvm-project/pull/88092#issuecomment-2059961175
This was regarding merging .debug_names in linker (although types are not 
implemented yet there), but FYI BOLT output is similar.
All the CUs are in one module.
Entry for type unit will have two indexes.
One for CU to which it belongs and another for type unit. Which can either be 
local or foreign.
example:
```
  Compilation Unit offsets [
CU[0]: 0x
CU[1]: 0x0029
  ]
  Foreign Type Unit signatures [
ForeignTU[0]: 0x49dc260088be7e56
ForeignTU[1]: 0x104ec427d2ebea6f
ForeignTU[2]: 0xca1e65a66d92b970
ForeignTU[3]: 0x104ec427d2ebea6f
  ]
  
  ...
  Bucket 1 [
Name 1 {
  Hash: 0x7C96E4DB
  String: 0x0027 "Foo2"
  Entry @ 0x117 {
Abbrev: 0x1
Tag: DW_TAG_structure_type
DW_IDX_type_unit: 0x00
DW_IDX_compile_unit: 0x00
DW_IDX_die_offset: 0x0021
DW_IDX_parent: 
  }
}
```




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


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-16 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Fred Grim (feg208)


Changes

This adds some additional bits into a ProcessInfo structure that will be of use 
in filling structs in an elf core file. This is a demand for implementing 
process save-core

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


3 Files Affected:

- (modified) lldb/include/lldb/Utility/ProcessInfo.h (+71) 
- (modified) lldb/source/Host/linux/Host.cpp (+105-20) 
- (modified) lldb/unittests/Host/linux/HostTest.cpp (+6) 


``diff
diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 7fb5b37be0f48f..e9fe71e1b851d1 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -139,6 +139,11 @@ class ProcessInfo {
 // to that process.
 class ProcessInstanceInfo : public ProcessInfo {
 public:
+  struct timespec {
+time_t tv_sec = 0;
+long int tv_usec = 0;
+  };
+
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
@@ -172,6 +177,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_parent_pid != LLDB_INVALID_PROCESS_ID;
   }
 
+  lldb::pid_t GetProcessGroupID() const { return m_process_group_id; }
+
+  void SetProcessGroupID(lldb::pid_t pgrp) { m_process_group_id = pgrp; }
+
+  bool ProcessGroupIDIsValid() const {
+return m_process_group_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  lldb::pid_t GetProcessSessionID() const { return m_process_session_id; }
+
+  void SetProcessSessionID(lldb::pid_t session) {
+m_process_session_id = session;
+  }
+
+  bool ProcessSessionIDIsValid() const {
+return m_process_session_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  struct timespec GetUserTime() const { return m_user_time; }
+
+  void SetUserTime(struct timespec utime) { m_user_time = utime; }
+
+  bool UserTimeIsValid() const {
+return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetSystemTime() const { return m_system_time; }
+
+  void SetSystemTime(struct timespec stime) { m_system_time = stime; }
+
+  bool SystemTimeIsValid() const {
+return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeUserTime() const {
+return m_cumulative_user_time;
+  }
+
+  void SetCumulativeUserTime(struct timespec cutime) {
+m_cumulative_user_time = cutime;
+  }
+
+  bool CumulativeUserTimeIsValid() const {
+return m_cumulative_user_time.tv_sec > 0 ||
+   m_cumulative_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeSystemTime() const {
+return m_cumulative_system_time;
+  }
+
+  void SetCumulativeSystemTime(struct timespec cstime) {
+m_cumulative_system_time = cstime;
+  }
+
+  bool CumulativeSystemTimeIsValid() const {
+return m_cumulative_system_time.tv_sec > 0 ||
+   m_cumulative_system_time.tv_sec > 0;
+  }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -183,6 +248,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   uint32_t m_euid = UINT32_MAX;
   uint32_t m_egid = UINT32_MAX;
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
+  struct timespec m_user_time {};
+  struct timespec m_system_time {};
+  struct timespec m_cumulative_user_time {};
+  struct timespec m_cumulative_system_time {};
 };
 
 typedef std::vector ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 6c57384aa38a13..c6490f2fc9e2f5 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -49,6 +49,29 @@ enum class ProcessState {
   TracedOrStopped,
   Zombie,
 };
+
+constexpr int task_comm_len = 16;
+
+struct StatFields {
+  ::pid_t pid = LLDB_INVALID_PROCESS_ID;
+  char comm[task_comm_len];
+  char state;
+  ::pid_t ppid = LLDB_INVALID_PROCESS_ID;
+  ::pid_t pgrp = LLDB_INVALID_PROCESS_ID;
+  ::pid_t session = LLDB_INVALID_PROCESS_ID;
+  int tty_nr;
+  int tpgid;
+  unsigned flags;
+  long unsigned minflt;
+  long unsigned cminflt;
+  long unsigned majflt;
+  long unsigned cmajflt;
+  long unsigned utime;
+  long unsigned stime;
+  long cutime;
+  long cstime;
+  //  other things. We don't need them below
+};
 }
 
 namespace lldb_private {
@@ -60,11 +83,92 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   ::pid_t ) {
   Log *log = GetLog(LLDBLog::Host);
 
-  auto BufferOrError = getProcFile(Pid, "status");
+  auto BufferOrError = getProcFile(Pid, "stat");
   if (!BufferOrError)
 return false;
 
   llvm::StringRef Rest = BufferOrError.get()->getBuffer();
+  if (Rest.empty())
+return false;
+  StatFields stat_fields;
+  if (sscanf(Rest.data(),
+ "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu 

[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-16 Thread Fred Grim via lldb-commits

https://github.com/feg208 created 
https://github.com/llvm/llvm-project/pull/88995

This adds some additional bits into a ProcessInfo structure that will be of use 
in filling structs in an elf core file. This is a demand for implementing 
process save-core

>From 9b8ec4d0c31ad1b228add56bc27cd79457e515c7 Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Tue, 16 Apr 2024 14:46:37 -0700
Subject: [PATCH] adds additional information to the ProcessInfo object for elf
 processes

---
 lldb/include/lldb/Utility/ProcessInfo.h |  71 ++
 lldb/source/Host/linux/Host.cpp | 125 
 lldb/unittests/Host/linux/HostTest.cpp  |   6 ++
 3 files changed, 182 insertions(+), 20 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 7fb5b37be0f48f..e9fe71e1b851d1 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -139,6 +139,11 @@ class ProcessInfo {
 // to that process.
 class ProcessInstanceInfo : public ProcessInfo {
 public:
+  struct timespec {
+time_t tv_sec = 0;
+long int tv_usec = 0;
+  };
+
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
@@ -172,6 +177,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_parent_pid != LLDB_INVALID_PROCESS_ID;
   }
 
+  lldb::pid_t GetProcessGroupID() const { return m_process_group_id; }
+
+  void SetProcessGroupID(lldb::pid_t pgrp) { m_process_group_id = pgrp; }
+
+  bool ProcessGroupIDIsValid() const {
+return m_process_group_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  lldb::pid_t GetProcessSessionID() const { return m_process_session_id; }
+
+  void SetProcessSessionID(lldb::pid_t session) {
+m_process_session_id = session;
+  }
+
+  bool ProcessSessionIDIsValid() const {
+return m_process_session_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  struct timespec GetUserTime() const { return m_user_time; }
+
+  void SetUserTime(struct timespec utime) { m_user_time = utime; }
+
+  bool UserTimeIsValid() const {
+return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetSystemTime() const { return m_system_time; }
+
+  void SetSystemTime(struct timespec stime) { m_system_time = stime; }
+
+  bool SystemTimeIsValid() const {
+return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeUserTime() const {
+return m_cumulative_user_time;
+  }
+
+  void SetCumulativeUserTime(struct timespec cutime) {
+m_cumulative_user_time = cutime;
+  }
+
+  bool CumulativeUserTimeIsValid() const {
+return m_cumulative_user_time.tv_sec > 0 ||
+   m_cumulative_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeSystemTime() const {
+return m_cumulative_system_time;
+  }
+
+  void SetCumulativeSystemTime(struct timespec cstime) {
+m_cumulative_system_time = cstime;
+  }
+
+  bool CumulativeSystemTimeIsValid() const {
+return m_cumulative_system_time.tv_sec > 0 ||
+   m_cumulative_system_time.tv_sec > 0;
+  }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -183,6 +248,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   uint32_t m_euid = UINT32_MAX;
   uint32_t m_egid = UINT32_MAX;
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
+  struct timespec m_user_time {};
+  struct timespec m_system_time {};
+  struct timespec m_cumulative_user_time {};
+  struct timespec m_cumulative_system_time {};
 };
 
 typedef std::vector ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 6c57384aa38a13..c6490f2fc9e2f5 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -49,6 +49,29 @@ enum class ProcessState {
   TracedOrStopped,
   Zombie,
 };
+
+constexpr int task_comm_len = 16;
+
+struct StatFields {
+  ::pid_t pid = LLDB_INVALID_PROCESS_ID;
+  char comm[task_comm_len];
+  char state;
+  ::pid_t ppid = LLDB_INVALID_PROCESS_ID;
+  ::pid_t pgrp = LLDB_INVALID_PROCESS_ID;
+  ::pid_t session = LLDB_INVALID_PROCESS_ID;
+  int tty_nr;
+  int tpgid;
+  unsigned flags;
+  long unsigned minflt;
+  long unsigned cminflt;
+  long unsigned majflt;
+  long unsigned cmajflt;
+  long unsigned utime;
+  long unsigned stime;
+  long cutime;
+  long cstime;
+  //  other things. We don't need them below
+};
 }
 
 namespace lldb_private {
@@ -60,11 +83,92 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   ::pid_t ) {
   Log *log = GetLog(LLDBLog::Host);
 
-  auto BufferOrError = getProcFile(Pid, "status");
+  auto BufferOrError = getProcFile(Pid, "stat");
   if (!BufferOrError)
 return false;
 
   llvm::StringRef Rest = 

[Lldb-commits] [lldb] [lldb][DynamicLoader] Fix lldb unable to stop at _dl_debug_state if user set it before the process launched. (PR #88792)

2024-04-16 Thread Jason Molenda via lldb-commits

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

This looks good, thanks for the revisions.

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


[Lldb-commits] [lldb] Add asan tests for libsanitizers. (#88349) (PR #88962)

2024-04-16 Thread Usama Hameed via lldb-commits

usama54321 wrote:


> The only change here was catching the build errors, right? lldbtest.build 
> only throws exceptions, it doesn't return any value, so this seems the right 
> way to do it.
> 
> Letting the build system fail to find this library seems easier than trying 
> to check ourselves.
> 
> LGTM

Yes I verified that the build system throws an exception when the make command 
fails


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


[Lldb-commits] [libcxx] [lldb] [libc++][CI] Tests LLDB libc++ data formatters. (PR #88312)

2024-04-16 Thread Mark de Wever via lldb-commits

mordante wrote:

Thanks for the fix!

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


[Lldb-commits] [lldb] Add asan tests for libsanitizers. (#88349) (PR #88962)

2024-04-16 Thread via lldb-commits

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

The only change here was catching the build errors, right?  lldbtest.build only 
throws exceptions, it doesn't return any value, so this seems the right way to 
do it.

Letting the build system fail to find this library seems easier than trying to 
check ourselves.

LGTM

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


[Lldb-commits] [lldb] Add asan tests for libsanitizers. (#88349) (PR #88962)

2024-04-16 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Usama Hameed (usama54321)


Changes

The previous patch was reverted because the test fails to build when 
libsanitizers is not present. This patch catches the BuildError exception and 
skips the test appropriately.

This patch tests LLDB integration with libsanitizers for ASan.

rdar://111856681

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


3 Files Affected:

- (modified) lldb/test/API/functionalities/asan/Makefile (+5-1) 
- (modified) lldb/test/API/functionalities/asan/TestMemoryHistory.py (+72-2) 
- (modified) lldb/test/API/functionalities/asan/TestReportData.py (+17-4) 


``diff
diff --git a/lldb/test/API/functionalities/asan/Makefile 
b/lldb/test/API/functionalities/asan/Makefile
index 4913a18d8cc6f9..d66696fed7078f 100644
--- a/lldb/test/API/functionalities/asan/Makefile
+++ b/lldb/test/API/functionalities/asan/Makefile
@@ -1,4 +1,8 @@
 C_SOURCES := main.c
-CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info
+asan: CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info
+asan: all
+
+libsanitizers: CFLAGS_EXTRAS := -fsanitize=address -fsanitize-stable-abi -g 
-gcolumn-info
+libsanitizers: all
 
 include Makefile.rules
diff --git a/lldb/test/API/functionalities/asan/TestMemoryHistory.py 
b/lldb/test/API/functionalities/asan/TestMemoryHistory.py
index 00162ae8822c74..41ab25823f5cc6 100644
--- a/lldb/test/API/functionalities/asan/TestMemoryHistory.py
+++ b/lldb/test/API/functionalities/asan/TestMemoryHistory.py
@@ -8,16 +8,24 @@
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbplatform
 from lldbsuite.test import lldbutil
-
+from lldbsuite.test_event.build_exception import BuildError
 
 class AsanTestCase(TestBase):
 @skipIfFreeBSD  # llvm.org/pr21136 runtimes not yet available by default
 @expectedFailureNetBSD
 @skipUnlessAddressSanitizer
 def test(self):
-self.build()
+self.build(make_targets=["asan"])
 self.asan_tests()
 
+@skipIf(oslist=no_match(["macosx"]))
+def test_libsanitizers_asan(self):
+try:
+self.build(make_targets=["libsanitizers"])
+except BuildError as e:
+self.skipTest("failed to build with libsanitizers")
+self.libsanitizer_tests()
+
 def setUp(self):
 # Call super's setUp().
 TestBase.setUp(self)
@@ -26,6 +34,68 @@ def setUp(self):
 self.line_free = line_number("main.c", "// free line")
 self.line_breakpoint = line_number("main.c", "// break line")
 
+# Test line numbers: rdar://126237493
+def libsanitizer_tests(self):
+target = self.createTestTarget()
+
+self.runCmd(
+"env SanitizersAddress=1 MallocSanitizerZone=1 
MallocSecureAllocator=0"
+)
+
+self.runCmd("run")
+
+# In libsanitizers, memory history is not supported until a report has 
been generated
+self.expect(
+"thread list",
+"Process should be stopped due to ASan report",
+substrs=["stopped", "stop reason = Use of deallocated memory"],
+)
+
+# test the 'memory history' command
+self.expect(
+"memory history 'pointer'",
+substrs=[
+"Memory deallocated by Thread",
+"a.out`f2",
+"main.c",
+"Memory allocated by Thread",
+"a.out`f1",
+"main.c",
+],
+)
+
+# do the same using SB API
+process = self.dbg.GetSelectedTarget().process
+val = (
+
process.GetSelectedThread().GetSelectedFrame().EvaluateExpression("pointer")
+)
+addr = val.GetValueAsUnsigned()
+threads = process.GetHistoryThreads(addr)
+self.assertEqual(threads.GetSize(), 2)
+
+history_thread = threads.GetThreadAtIndex(0)
+self.assertTrue(history_thread.num_frames >= 2)
+self.assertEqual(
+
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
+"main.c",
+)
+
+history_thread = threads.GetThreadAtIndex(1)
+self.assertTrue(history_thread.num_frames >= 2)
+self.assertEqual(
+
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
+"main.c",
+)
+
+# let's free the container (SBThreadCollection) and see if the
+# SBThreads still live
+threads = None
+self.assertTrue(history_thread.num_frames >= 2)
+self.assertEqual(
+
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
+"main.c",
+)
+
 def asan_tests(self):
 target = self.createTestTarget()
 
diff --git a/lldb/test/API/functionalities/asan/TestReportData.py 
b/lldb/test/API/functionalities/asan/TestReportData.py
index 543c5fe66a208d..5e4c179e2a4819 100644
--- a/lldb/test/API/functionalities/asan/TestReportData.py
+++ 

[Lldb-commits] [lldb] Add asan tests for libsanitizers. (#88349) (PR #88962)

2024-04-16 Thread Usama Hameed via lldb-commits

https://github.com/usama54321 created 
https://github.com/llvm/llvm-project/pull/88962

The previous patch was reverted because the test fails to build when 
libsanitizers is not present. This patch catches the BuildError exception and 
skips the test appropriately.

This patch tests LLDB integration with libsanitizers for ASan.

rdar://111856681

>From 48adfe5abe7655c6e933e12f05e17ea4bd2e5692 Mon Sep 17 00:00:00 2001
From: Usama Hameed 
Date: Mon, 15 Apr 2024 19:42:45 -0700
Subject: [PATCH] Add asan tests for libsanitizers. (#88349)

This patch tests LLDB integration with libsanitizers for ASan.

rdar://111856681
---
 lldb/test/API/functionalities/asan/Makefile   |  6 +-
 .../functionalities/asan/TestMemoryHistory.py | 74 ++-
 .../functionalities/asan/TestReportData.py| 21 +-
 3 files changed, 94 insertions(+), 7 deletions(-)

diff --git a/lldb/test/API/functionalities/asan/Makefile 
b/lldb/test/API/functionalities/asan/Makefile
index 4913a18d8cc6f9..d66696fed7078f 100644
--- a/lldb/test/API/functionalities/asan/Makefile
+++ b/lldb/test/API/functionalities/asan/Makefile
@@ -1,4 +1,8 @@
 C_SOURCES := main.c
-CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info
+asan: CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info
+asan: all
+
+libsanitizers: CFLAGS_EXTRAS := -fsanitize=address -fsanitize-stable-abi -g 
-gcolumn-info
+libsanitizers: all
 
 include Makefile.rules
diff --git a/lldb/test/API/functionalities/asan/TestMemoryHistory.py 
b/lldb/test/API/functionalities/asan/TestMemoryHistory.py
index 00162ae8822c74..41ab25823f5cc6 100644
--- a/lldb/test/API/functionalities/asan/TestMemoryHistory.py
+++ b/lldb/test/API/functionalities/asan/TestMemoryHistory.py
@@ -8,16 +8,24 @@
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbplatform
 from lldbsuite.test import lldbutil
-
+from lldbsuite.test_event.build_exception import BuildError
 
 class AsanTestCase(TestBase):
 @skipIfFreeBSD  # llvm.org/pr21136 runtimes not yet available by default
 @expectedFailureNetBSD
 @skipUnlessAddressSanitizer
 def test(self):
-self.build()
+self.build(make_targets=["asan"])
 self.asan_tests()
 
+@skipIf(oslist=no_match(["macosx"]))
+def test_libsanitizers_asan(self):
+try:
+self.build(make_targets=["libsanitizers"])
+except BuildError as e:
+self.skipTest("failed to build with libsanitizers")
+self.libsanitizer_tests()
+
 def setUp(self):
 # Call super's setUp().
 TestBase.setUp(self)
@@ -26,6 +34,68 @@ def setUp(self):
 self.line_free = line_number("main.c", "// free line")
 self.line_breakpoint = line_number("main.c", "// break line")
 
+# Test line numbers: rdar://126237493
+def libsanitizer_tests(self):
+target = self.createTestTarget()
+
+self.runCmd(
+"env SanitizersAddress=1 MallocSanitizerZone=1 
MallocSecureAllocator=0"
+)
+
+self.runCmd("run")
+
+# In libsanitizers, memory history is not supported until a report has 
been generated
+self.expect(
+"thread list",
+"Process should be stopped due to ASan report",
+substrs=["stopped", "stop reason = Use of deallocated memory"],
+)
+
+# test the 'memory history' command
+self.expect(
+"memory history 'pointer'",
+substrs=[
+"Memory deallocated by Thread",
+"a.out`f2",
+"main.c",
+"Memory allocated by Thread",
+"a.out`f1",
+"main.c",
+],
+)
+
+# do the same using SB API
+process = self.dbg.GetSelectedTarget().process
+val = (
+
process.GetSelectedThread().GetSelectedFrame().EvaluateExpression("pointer")
+)
+addr = val.GetValueAsUnsigned()
+threads = process.GetHistoryThreads(addr)
+self.assertEqual(threads.GetSize(), 2)
+
+history_thread = threads.GetThreadAtIndex(0)
+self.assertTrue(history_thread.num_frames >= 2)
+self.assertEqual(
+
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
+"main.c",
+)
+
+history_thread = threads.GetThreadAtIndex(1)
+self.assertTrue(history_thread.num_frames >= 2)
+self.assertEqual(
+
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
+"main.c",
+)
+
+# let's free the container (SBThreadCollection) and see if the
+# SBThreads still live
+threads = None
+self.assertTrue(history_thread.num_frames >= 2)
+self.assertEqual(
+
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
+"main.c",
+)
+
 def asan_tests(self):
 target = self.createTestTarget()
 
diff --git 

[Lldb-commits] [lldb] [lldb][DynamicLoader] Fix lldb unable to stop at _dl_debug_state if user set it before the process launched. (PR #88792)

2024-04-16 Thread Zequan Wu via lldb-commits

ZequanWu wrote:

> > > why not just call ModulesDidLoad and delegate this (and possibly other 
> > > binary-just-loaded) behaviors to it?
> > 
> > 
> > That's what I did first, but it breaks the test 
> > `TestModuleLoadedNotifys.ModuleLoadedNotifysTestCase.test_launch_notifications`
> >  because of extra broadcaster event. So, I moved out the part just updating 
> > breakpoints.
> 
> The point of the test is to ensure you don't get a hundred notifications, one 
> for each module. Having one notification for ld.so, and 99 for the rest of 
> the modules is ok. It should be fine to just update the test to match new 
> reality.

Updated to use `Target::ModulesDisLoad` and the test.

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


[Lldb-commits] [lldb] [lldb][DynamicLoader] Fix lldb unable to stop at _dl_debug_state if user set it before the process launched. (PR #88792)

2024-04-16 Thread Zequan Wu via lldb-commits

https://github.com/ZequanWu updated 
https://github.com/llvm/llvm-project/pull/88792

>From 26528cd679478448edf446e0e82e5f207ffd6113 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Mon, 15 Apr 2024 16:30:38 -0400
Subject: [PATCH 1/3] [lldb][DynamicLoader] Fix lldb unable to stop at
 _dl_debug_state if user set it before the process launched.

---
 lldb/include/lldb/Target/Target.h   |  3 +++
 .../POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp   |  5 +
 lldb/source/Target/Target.cpp   | 17 ++---
 .../breakpoint_command/TestBreakpointCommand.py | 17 +
 4 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index 2c2e6b2831ccee..3554ef0ea5a140 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -878,6 +878,9 @@ class Target : public std::enable_shared_from_this,
   // the address of its previous instruction and return that address.
   lldb::addr_t GetBreakableLoadAddress(lldb::addr_t addr);
 
+  void UpdateBreakpoints(ModuleList _list, bool added,
+ bool delete_locations);
+
   void ModulesDidLoad(ModuleList _list);
 
   void ModulesDidUnload(ModuleList _list, bool delete_locations);
diff --git 
a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp 
b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
index 9baf86da4dc799..901fa53682da8e 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -576,6 +576,11 @@ ModuleSP DynamicLoaderPOSIXDYLD::LoadInterpreterModule() {
 UpdateLoadedSections(module_sp, LLDB_INVALID_ADDRESS, m_interpreter_base,
  false);
 m_interpreter_module = module_sp;
+// Manually update breakpoints after updating loaded sections, because they
+// cannot be resolve at the time when creating this module.
+ModuleList module_list;
+module_list.Append(module_sp);
+m_process->GetTarget().UpdateBreakpoints(module_list, true, false);
 return module_sp;
   }
   return nullptr;
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 09b0ac42631d1a..ec2dea5cc238d3 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -1687,6 +1687,13 @@ void 
Target::NotifyModulesRemoved(lldb_private::ModuleList _list) {
   ModulesDidUnload(module_list, false);
 }
 
+void Target::UpdateBreakpoints(ModuleList _list, bool added,
+   bool delete_locations) {
+  m_breakpoint_list.UpdateBreakpoints(module_list, added, delete_locations);
+  m_internal_breakpoint_list.UpdateBreakpoints(module_list, added,
+   delete_locations);
+}
+
 void Target::ModulesDidLoad(ModuleList _list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
@@ -1694,8 +1701,7 @@ void Target::ModulesDidLoad(ModuleList _list) {
   ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
   LoadScriptingResourceForModule(module_sp, this);
 }
-m_breakpoint_list.UpdateBreakpoints(module_list, true, false);
-m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false);
+UpdateBreakpoints(module_list, true, false);
 if (m_process_sp) {
   m_process_sp->ModulesDidLoad(module_list);
 }
@@ -1713,8 +1719,7 @@ void Target::SymbolsDidLoad(ModuleList _list) {
   }
 }
 
-m_breakpoint_list.UpdateBreakpoints(module_list, true, false);
-m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false);
+UpdateBreakpoints(module_list, true, false);
 auto data_sp =
 std::make_shared(shared_from_this(), module_list);
 BroadcastEvent(eBroadcastBitSymbolsLoaded, data_sp);
@@ -1727,9 +1732,7 @@ void Target::ModulesDidUnload(ModuleList _list, 
bool delete_locations) {
 auto data_sp =
 std::make_shared(shared_from_this(), module_list);
 BroadcastEvent(eBroadcastBitModulesUnloaded, data_sp);
-m_breakpoint_list.UpdateBreakpoints(module_list, false, delete_locations);
-m_internal_breakpoint_list.UpdateBreakpoints(module_list, false,
- delete_locations);
+UpdateBreakpoints(module_list, false, delete_locations);
 
 // If a module was torn down it will have torn down the 'TypeSystemClang's
 // that we used as source 'ASTContext's for the persistent variables in
diff --git 
a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
 
b/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
index ea242952e409ec..a7e23fae14a21f 100644
--- 
a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
+++ 

[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread Alex Langford via lldb-commits

https://github.com/bulbazord commented:

Looking better! Let's get the comments and style sorted out, but I think this 
is looking good :)

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


[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread Alex Langford via lldb-commits


@@ -684,6 +684,14 @@ Status PlatformRemoteGDBServer::RunShellCommand(
   signo_ptr, command_output, timeout);
 }
 
+bool PlatformRemoteGDBServer::CalculateMD5(const FileSpec _spec,
+   uint64_t , uint64_t ) {
+  if (!IsConnected()) {
+return false;
+  }

bulbazord wrote:

The LLVM coding standards suggest not having curly braces for 1 line bodies: 
https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements

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


[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread Alex Langford via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread Alex Langford via lldb-commits


@@ -1197,6 +1197,34 @@ Status Platform::PutFile(const FileSpec , const 
FileSpec ,
   if (!source_file)
 return Status(source_file.takeError());
   Status error;
+
+  bool requires_upload = true;
+  {

bulbazord wrote:

I see. I wouldn't say it's a bad thing to create a new scope if you want to 
contain the lifetime of these variables to their own scope, but in LLDB (and 
more broadly LLVM) this is mostly used for RAII. The most common instance of 
this is when one wants to acquire a lock but does not want the lock to span the 
lifetime of the method body.

For consistency I would say either put this code in the main body, put it in a 
small static function, or put it in a lambda.

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


[Lldb-commits] [lldb] [lldb/linux] Make sure the process continues running after a detach (PR #88494)

2024-04-16 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,48 @@
+#include "pseudo_barrier.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+pseudo_barrier_t barrier;
+
+constexpr size_t nthreads = 5;
+volatile bool wait_for_debugger_flag = true;
+
+void break_here() {}
+
+void tfunc() {
+  pseudo_barrier_wait(barrier);
+
+  break_here();
+}
+
+int main(int argc, char const *argv[]) {
+  lldb_enable_attach();

labath wrote:

Yes, but it's not really a "special" OS. Most linux systems are configured like 
that by default, where you're only allowed to debug your own children (unless 
they explicitly allow that, or you're root, etc.). Check out 
https://www.kernel.org/doc/html/v4.15/admin-guide/LSM/Yama.html. 
lldb_enable_attach is our own invention, which calls the appropriate os 
interface to enable attaching if necessary. Currently, it's only implemented on 
linux.

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


[Lldb-commits] [lldb] [lldb/linux] Make sure the process continues running after a detach (PR #88494)

2024-04-16 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,59 @@
+"""
+Test that the process continues running after we detach from it.
+"""
+
+import lldb
+import time
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class DetachResumesTestCase(TestBase):
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_detach_resumes(self):
+self.build()
+exe = self.getBuildArtifact()
+
+# The inferior will use this file to let us know it is ready to be
+# attached.
+sync_file_path = lldbutil.append_to_process_working_directory(
+self, "sync_file_%d" % (int(time.time()))
+)
+
+# And this one to let us know it is running after we've detached from
+# it.
+exit_file_path = lldbutil.append_to_process_working_directory(
+self, "exit_file_%d" % (int(time.time()))
+)
+
+popen = self.spawnSubprocess(
+self.getBuildArtifact(exe), [sync_file_path, exit_file_path]
+)
+lldbutil.wait_for_file_on_target(self, sync_file_path)
+
+self.runCmd("process attach -p " + str(popen.pid))
+
+# Set a breakpoint at a place that will be called by multiple threads
+# simultaneously. On systems (e.g. linux) where the debugger needs to
+# send signals to suspend threads, these signals will race with threads
+# hitting the breakpoint (and stopping on their own).
+bpno = lldbutil.run_break_set_by_symbol(self, "break_here")
+
+# And let the inferior know it can call the function.
+self.runCmd("expr -- wait_for_debugger_flag = false")
+
+self.runCmd("continue")
+
+self.expect(
+"thread list",
+STOPPED_DUE_TO_BREAKPOINT,
+substrs=["stopped", "stop reason = breakpoint"],
+)
+
+# Detach, the process should keep running after this, and not be 
stopped
+# by the signals that the debugger may have used to suspend the 
threads.
+self.runCmd("detach")
+
+lldbutil.wait_for_file_on_target(self, exit_file_path)

labath wrote:

Yes, and just in case it does not, the file name has an embedded time stamp 
(mainly a remnant of the time where we were not automatically cleaning up the 
test dir :) )

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


[Lldb-commits] [lldb] [lldb/linux] Make sure the process continues running after a detach (PR #88494)

2024-04-16 Thread via lldb-commits

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


[Lldb-commits] [lldb] [lldb/linux] Make sure the process continues running after a detach (PR #88494)

2024-04-16 Thread via lldb-commits


@@ -0,0 +1,48 @@
+#include "pseudo_barrier.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+pseudo_barrier_t barrier;
+
+constexpr size_t nthreads = 5;
+volatile bool wait_for_debugger_flag = true;
+
+void break_here() {}
+
+void tfunc() {
+  pseudo_barrier_wait(barrier);
+
+  break_here();
+}
+
+int main(int argc, char const *argv[]) {
+  lldb_enable_attach();

jeffreytan81 wrote:

Just curious, why this is needed? 
Is it that some special OS may restrict the default attaching behavior for 
security reason unless lldb_enable_attach() is explicitly called?  

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


[Lldb-commits] [lldb] [lldb/linux] Make sure the process continues running after a detach (PR #88494)

2024-04-16 Thread via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb][DynamicLoader] Fix lldb unable to stop at _dl_debug_state if user set it before the process launched. (PR #88792)

2024-04-16 Thread Zequan Wu via lldb-commits

https://github.com/ZequanWu updated 
https://github.com/llvm/llvm-project/pull/88792

>From 26528cd679478448edf446e0e82e5f207ffd6113 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Mon, 15 Apr 2024 16:30:38 -0400
Subject: [PATCH 1/2] [lldb][DynamicLoader] Fix lldb unable to stop at
 _dl_debug_state if user set it before the process launched.

---
 lldb/include/lldb/Target/Target.h   |  3 +++
 .../POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp   |  5 +
 lldb/source/Target/Target.cpp   | 17 ++---
 .../breakpoint_command/TestBreakpointCommand.py | 17 +
 4 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index 2c2e6b2831ccee..3554ef0ea5a140 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -878,6 +878,9 @@ class Target : public std::enable_shared_from_this,
   // the address of its previous instruction and return that address.
   lldb::addr_t GetBreakableLoadAddress(lldb::addr_t addr);
 
+  void UpdateBreakpoints(ModuleList _list, bool added,
+ bool delete_locations);
+
   void ModulesDidLoad(ModuleList _list);
 
   void ModulesDidUnload(ModuleList _list, bool delete_locations);
diff --git 
a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp 
b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
index 9baf86da4dc799..901fa53682da8e 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -576,6 +576,11 @@ ModuleSP DynamicLoaderPOSIXDYLD::LoadInterpreterModule() {
 UpdateLoadedSections(module_sp, LLDB_INVALID_ADDRESS, m_interpreter_base,
  false);
 m_interpreter_module = module_sp;
+// Manually update breakpoints after updating loaded sections, because they
+// cannot be resolve at the time when creating this module.
+ModuleList module_list;
+module_list.Append(module_sp);
+m_process->GetTarget().UpdateBreakpoints(module_list, true, false);
 return module_sp;
   }
   return nullptr;
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 09b0ac42631d1a..ec2dea5cc238d3 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -1687,6 +1687,13 @@ void 
Target::NotifyModulesRemoved(lldb_private::ModuleList _list) {
   ModulesDidUnload(module_list, false);
 }
 
+void Target::UpdateBreakpoints(ModuleList _list, bool added,
+   bool delete_locations) {
+  m_breakpoint_list.UpdateBreakpoints(module_list, added, delete_locations);
+  m_internal_breakpoint_list.UpdateBreakpoints(module_list, added,
+   delete_locations);
+}
+
 void Target::ModulesDidLoad(ModuleList _list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
@@ -1694,8 +1701,7 @@ void Target::ModulesDidLoad(ModuleList _list) {
   ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
   LoadScriptingResourceForModule(module_sp, this);
 }
-m_breakpoint_list.UpdateBreakpoints(module_list, true, false);
-m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false);
+UpdateBreakpoints(module_list, true, false);
 if (m_process_sp) {
   m_process_sp->ModulesDidLoad(module_list);
 }
@@ -1713,8 +1719,7 @@ void Target::SymbolsDidLoad(ModuleList _list) {
   }
 }
 
-m_breakpoint_list.UpdateBreakpoints(module_list, true, false);
-m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false);
+UpdateBreakpoints(module_list, true, false);
 auto data_sp =
 std::make_shared(shared_from_this(), module_list);
 BroadcastEvent(eBroadcastBitSymbolsLoaded, data_sp);
@@ -1727,9 +1732,7 @@ void Target::ModulesDidUnload(ModuleList _list, 
bool delete_locations) {
 auto data_sp =
 std::make_shared(shared_from_this(), module_list);
 BroadcastEvent(eBroadcastBitModulesUnloaded, data_sp);
-m_breakpoint_list.UpdateBreakpoints(module_list, false, delete_locations);
-m_internal_breakpoint_list.UpdateBreakpoints(module_list, false,
- delete_locations);
+UpdateBreakpoints(module_list, false, delete_locations);
 
 // If a module was torn down it will have torn down the 'TypeSystemClang's
 // that we used as source 'ASTContext's for the persistent variables in
diff --git 
a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
 
b/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
index ea242952e409ec..a7e23fae14a21f 100644
--- 
a/lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
+++ 

[Lldb-commits] [lldb] [lldb][DynamicLoader] Fix lldb unable to stop at _dl_debug_state if user set it before the process launched. (PR #88792)

2024-04-16 Thread Pavel Labath via lldb-commits

labath wrote:

> > why not just call ModulesDidLoad and delegate this (and possibly other 
> > binary-just-loaded) behaviors to it?
> 
> That's what I did first, but it breaks the test 
> `TestModuleLoadedNotifys.ModuleLoadedNotifysTestCase.test_launch_notifications`
>  because of extra broadcaster event. So, I moved out the part just updating 
> breakpoints.

The point of the test is to ensure you don't get a hundred notifications, one 
for each module. Having one notification for ld.so, and 99 for the rest of the 
modules is ok. It should be fine to just update the test to match new reality.

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


[Lldb-commits] [lldb] Add asan tests for libsanitizers. (PR #88349)

2024-04-16 Thread Adrian Prantl via lldb-commits

adrian-prantl wrote:

@usama54321 I had to revert this because it broke both the arm64 and x86 bots: 
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/1078/

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


[Lldb-commits] [lldb] f8e2ec1 - Revert "Add asan tests for libsanitizers. (#88349)"

2024-04-16 Thread Adrian Prantl via lldb-commits

Author: Adrian Prantl
Date: 2024-04-16T08:29:09-07:00
New Revision: f8e2ec13a8c6d33cb7b4f37869b4429ddcf43f01

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

LOG: Revert "Add asan tests for libsanitizers. (#88349)"

This reverts commit 82f479ba315a417b6cd01a8c2efdc15c26689f2e due to bot 
breakage.

Added: 


Modified: 
lldb/test/API/functionalities/asan/Makefile
lldb/test/API/functionalities/asan/TestMemoryHistory.py
lldb/test/API/functionalities/asan/TestReportData.py

Removed: 
lldb/test/API/functionalities/libsanitizers/util.py



diff  --git a/lldb/test/API/functionalities/asan/Makefile 
b/lldb/test/API/functionalities/asan/Makefile
index d66696fed7078f..4913a18d8cc6f9 100644
--- a/lldb/test/API/functionalities/asan/Makefile
+++ b/lldb/test/API/functionalities/asan/Makefile
@@ -1,8 +1,4 @@
 C_SOURCES := main.c
-asan: CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info
-asan: all
-
-libsanitizers: CFLAGS_EXTRAS := -fsanitize=address -fsanitize-stable-abi -g 
-gcolumn-info
-libsanitizers: all
+CFLAGS_EXTRAS := -fsanitize=address -g -gcolumn-info
 
 include Makefile.rules

diff  --git a/lldb/test/API/functionalities/asan/TestMemoryHistory.py 
b/lldb/test/API/functionalities/asan/TestMemoryHistory.py
index ee7939203ead18..00162ae8822c74 100644
--- a/lldb/test/API/functionalities/asan/TestMemoryHistory.py
+++ b/lldb/test/API/functionalities/asan/TestMemoryHistory.py
@@ -9,21 +9,15 @@
 from lldbsuite.test import lldbplatform
 from lldbsuite.test import lldbutil
 
-from functionalities.libsanitizers.util import no_libsanitizers
 
 class AsanTestCase(TestBase):
 @skipIfFreeBSD  # llvm.org/pr21136 runtimes not yet available by default
 @expectedFailureNetBSD
 @skipUnlessAddressSanitizer
 def test(self):
-self.build(make_targets=["asan"])
+self.build()
 self.asan_tests()
 
-@skipIf(oslist=no_match(["macosx"]))
-def test_libsanitizers_asan(self):
-self.build(make_targets=["libsanitizers"])
-self.libsanitizer_tests()
-
 def setUp(self):
 # Call super's setUp().
 TestBase.setUp(self)
@@ -32,71 +26,6 @@ def setUp(self):
 self.line_free = line_number("main.c", "// free line")
 self.line_breakpoint = line_number("main.c", "// break line")
 
-# Test line numbers: rdar://126237493
-def libsanitizer_tests(self):
-target = self.createTestTarget()
-
-if no_libsanitizers(self):
-self.skipTest("libsanitizers not found")
-
-self.runCmd(
-"env SanitizersAddress=1 MallocSanitizerZone=1 
MallocSecureAllocator=0"
-)
-
-self.runCmd("run")
-
-# In libsanitizers, memory history is not supported until a report has 
been generated
-self.expect(
-"thread list",
-"Process should be stopped due to ASan report",
-substrs=["stopped", "stop reason = Use of deallocated memory"],
-)
-
-# test the 'memory history' command
-self.expect(
-"memory history 'pointer'",
-substrs=[
-"Memory deallocated by Thread",
-"a.out`f2",
-"main.c",
-"Memory allocated by Thread",
-"a.out`f1",
-"main.c",
-],
-)
-
-# do the same using SB API
-process = self.dbg.GetSelectedTarget().process
-val = (
-
process.GetSelectedThread().GetSelectedFrame().EvaluateExpression("pointer")
-)
-addr = val.GetValueAsUnsigned()
-threads = process.GetHistoryThreads(addr)
-self.assertEqual(threads.GetSize(), 2)
-
-history_thread = threads.GetThreadAtIndex(0)
-self.assertTrue(history_thread.num_frames >= 2)
-self.assertEqual(
-
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
-"main.c",
-)
-
-history_thread = threads.GetThreadAtIndex(1)
-self.assertTrue(history_thread.num_frames >= 2)
-self.assertEqual(
-
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
-"main.c",
-)
-
-# let's free the container (SBThreadCollection) and see if the
-# SBThreads still live
-threads = None
-self.assertTrue(history_thread.num_frames >= 2)
-self.assertEqual(
-
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
-"main.c",
-)
-
 def asan_tests(self):
 target = self.createTestTarget()
 

diff  --git a/lldb/test/API/functionalities/asan/TestReportData.py 
b/lldb/test/API/functionalities/asan/TestReportData.py
index de0c1206a57ad6..543c5fe66a208d 100644
--- 

[Lldb-commits] [lldb] [lldb][DynamicLoader] Fix lldb unable to stop at _dl_debug_state if user set it before the process launched. (PR #88792)

2024-04-16 Thread Zequan Wu via lldb-commits

ZequanWu wrote:

> I'm missing why the _dl_debug_state breakpoint is special here, such that it 
> requires a force load of the section info? How does that happen?

Jason's comment explains it well. It's because ld.so's loading is special here. 
Normal binaries are loaded via `DynamicLoaderPOSIXDYLD::RefreshModules` which 
updates loaded section addresses.

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


[Lldb-commits] [lldb] [lldb][DynamicLoader] Fix lldb unable to stop at _dl_debug_state if user set it before the process launched. (PR #88792)

2024-04-16 Thread Zequan Wu via lldb-commits

ZequanWu wrote:

> why not just call ModulesDidLoad and delegate this (and possibly other 
> binary-just-loaded) behaviors to it?

That's what I did first, but it breaks the test 
`TestModuleLoadedNotifys.ModuleLoadedNotifysTestCase.test_launch_notifications` 
because of extra broadcaster event. So, I moved out the part of the part just 
updating breakpoints.

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


[Lldb-commits] [lldb] [lldb/linux] Make sure the process continues running after a detach (PR #88494)

2024-04-16 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Thanks for looking into this. I had no idea what it might be but your 
explanation makes a lot of sense.

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


[Lldb-commits] [lldb] [lldb/linux] Make sure the process continues running after a detach (PR #88494)

2024-04-16 Thread David Spickett via lldb-commits


@@ -0,0 +1,59 @@
+"""
+Test that the process continues running after we detach from it.
+"""
+
+import lldb
+import time
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class DetachResumesTestCase(TestBase):
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_detach_resumes(self):
+self.build()
+exe = self.getBuildArtifact()
+
+# The inferior will use this file to let us know it is ready to be
+# attached.
+sync_file_path = lldbutil.append_to_process_working_directory(
+self, "sync_file_%d" % (int(time.time()))
+)
+
+# And this one to let us know it is running after we've detached from
+# it.
+exit_file_path = lldbutil.append_to_process_working_directory(
+self, "exit_file_%d" % (int(time.time()))
+)
+
+popen = self.spawnSubprocess(
+self.getBuildArtifact(exe), [sync_file_path, exit_file_path]
+)
+lldbutil.wait_for_file_on_target(self, sync_file_path)
+
+self.runCmd("process attach -p " + str(popen.pid))
+
+# Set a breakpoint at a place that will be called by multiple threads
+# simultaneously. On systems (e.g. linux) where the debugger needs to
+# send signals to suspend threads, these signals will race with threads
+# hitting the breakpoint (and stopping on their own).
+bpno = lldbutil.run_break_set_by_symbol(self, "break_here")
+
+# And let the inferior know it can call the function.
+self.runCmd("expr -- wait_for_debugger_flag = false")
+
+self.runCmd("continue")
+
+self.expect(
+"thread list",
+STOPPED_DUE_TO_BREAKPOINT,
+substrs=["stopped", "stop reason = breakpoint"],
+)
+
+# Detach, the process should keep running after this, and not be 
stopped
+# by the signals that the debugger may have used to suspend the 
threads.
+self.runCmd("detach")
+
+lldbutil.wait_for_file_on_target(self, exit_file_path)

DavidSpickett wrote:

I presume the test working dir gets cleaned up automatically between runs?

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


[Lldb-commits] [lldb] [lldb/linux] Make sure the process continues running after a detach (PR #88494)

2024-04-16 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Will fix https://github.com/llvm/llvm-project/issues/85084.

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


[Lldb-commits] [lldb] [lldb] Have lldb-server assign ports to children in platform mode (PR #88845)

2024-04-16 Thread David Spickett via lldb-commits


@@ -301,13 +294,31 @@ int main_platform(int argc, char *argv[]) {
   exit(socket_error);
 }
 printf("Connection established.\n");
+
+std::optional port = 0;

DavidSpickett wrote:

If we're going to use optional then this should be left to default construct to 
std::nullopt (https://en.cppreference.com/w/cpp/utility/optional/nullopt_t) 
(the equivalent of Haskell Maybe's "Nothing" state).

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


[Lldb-commits] [lldb] [lldb] Have lldb-server assign ports to children in platform mode (PR #88845)

2024-04-16 Thread David Spickett via lldb-commits


@@ -301,13 +294,31 @@ int main_platform(int argc, char *argv[]) {
   exit(socket_error);
 }
 printf("Connection established.\n");
+
+std::optional port = 0;
 if (g_server) {
   // Collect child zombie processes.
 #if !defined(_WIN32)
-  while (waitpid(-1, nullptr, WNOHANG) > 0)
-;
+  auto waitResult = waitpid(-1, nullptr, WNOHANG);
+  while (waitResult > 0) {

DavidSpickett wrote:

Could be `while (int waitResult = waitpid( ) {`.

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


[Lldb-commits] [lldb] [lldb] Have lldb-server assign ports to children in platform mode (PR #88845)

2024-04-16 Thread David Spickett via lldb-commits


@@ -324,6 +335,10 @@ int main_platform(int argc, char *argv[]) {
   // connections while a connection is active.
   acceptor_up.reset();
 }
+
+GDBRemoteCommunicationServerPlatform::PortMap portmap_for_child;
+portmap_for_child.AllowPort(*port);

DavidSpickett wrote:

This will fail at runtime if the optional is empty. Are we 100% sure there is 
no path to get here that leaves the optional empty?

If it is expected that we get here with port empty, the code should be:
```
if (port) // Which means "is the optional empty?", not "is the value in the 
optional true in a boolean sense
  portmap_for_child.AllowPort(*port);
```

Given that we're setting a port for a child I assume we'll always have some 
valid port by this point. Though the code is quite complex, so the free assert 
given by `operator*` on the optional does add some safety.

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


[Lldb-commits] [lldb] [lldb] Have lldb-server assign ports to children in platform mode (PR #88845)

2024-04-16 Thread David Spickett via lldb-commits


@@ -301,13 +294,31 @@ int main_platform(int argc, char *argv[]) {
   exit(socket_error);
 }
 printf("Connection established.\n");
+
+std::optional port = 0;
 if (g_server) {
   // Collect child zombie processes.
 #if !defined(_WIN32)
-  while (waitpid(-1, nullptr, WNOHANG) > 0)
-;
+  auto waitResult = waitpid(-1, nullptr, WNOHANG);
+  while (waitResult > 0) {
+// waitResult is the child pid
+gdbserver_portmap.FreePortForProcess(waitResult);
+waitResult = waitpid(-1, nullptr, WNOHANG);
+  }
 #endif
-  if (fork()) {
+  llvm::Expected available_port =
+  gdbserver_portmap.GetNextAvailablePort();
+  if (available_port)
+port = *available_port;
+
+  else {

DavidSpickett wrote:

This needs to do something with the failed expected otherwise there'll be an 
error at runtime. See `GDBRemoteCommunicationServerPlatform::LaunchGDBServer`. 
I think you can just do `llvm::consumeError(port.takeError())` here.

That runtime error may need asserts to be enabled, pass 
`-DLLVM_ENABLE_ASSERTIONS=True` to cmake.

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


[Lldb-commits] [lldb] [lldb] Have lldb-server assign ports to children in platform mode (PR #88845)

2024-04-16 Thread David Spickett via lldb-commits

DavidSpickett wrote:

I think this will fix https://github.com/llvm/llvm-project/issues/47549. And 
make the note at the end of `lldb/docs/use/qemu-testing.rst` outdated.

For testing we might be able to send the platform the gdbserver spawn packets 
and check that it doesn't return the same port each time. There are tests in 
`lldb/test/API/tools/lldb-server` that expect certain responses. Problem with 
that is we won't know what port range is available on the test host so what 
would we pass to the min and max?

Given the only existing tests are for the command line validation, I'd be ok 
not adding tests for this.

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


[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread David Spickett via lldb-commits

DavidSpickett wrote:

@weliveindetail I think this might fix the problems you were having remote 
debugging clang-repl (I can't seem to find the actual Discourse thread).

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


[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread David Spickett via lldb-commits


@@ -1197,6 +1197,34 @@ Status Platform::PutFile(const FileSpec , const 
FileSpec ,
   if (!source_file)
 return Status(source_file.takeError());
   Status error;
+
+  bool requires_upload = true;
+  {

DavidSpickett wrote:

If you really need a new scope, a small static function in the same file is the 
usual way. In this case it's fine to have them in the scope of the main 
function I think, I don't think they overlap with any existing var.

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


[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread David Spickett via lldb-commits


@@ -1184,7 +1184,7 @@ bool Platform::IsCompatibleArchitecture(const ArchSpec 
,
 Status Platform::PutFile(const FileSpec , const FileSpec ,
  uint32_t uid, uint32_t gid) {
   Log *log = GetLog(LLDBLog::Platform);
-  LLDB_LOGF(log, "[PutFile] Using block by block transfer\n");
+  LLDB_LOGF(log, "[PutFile] Using block by block transfer");

DavidSpickett wrote:

Since (I assume) you can't push directly, I suggest leaving this out of this PR 
and once this PR lands immediately put up a PR just to change that \n.

It's maybe a bit strict but PRs are free :)

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


[Lldb-commits] [lldb] [lldb] Skip remote PutFile when MD5 hashes equal (PR #88812)

2024-04-16 Thread David Spickett via lldb-commits


@@ -3433,8 +3433,40 @@ bool GDBRemoteCommunicationClient::CalculateMD5(
   return false;
 if (response.Peek() && *response.Peek() == 'x')
   return false;
-low = response.GetHexMaxU64(false, UINT64_MAX);
-high = response.GetHexMaxU64(false, UINT64_MAX);
+
+// GDBRemoteCommunicationServerCommon::Handle_vFile_MD5 concatenates low 
and
+// high hex strings. We can't use response.GetHexMaxU64 because that can't
+// handle the concatenated hex string. What would happen is parsing the low
+// would consume the whole response packet - which is a bug. Instead, we 
get

DavidSpickett wrote:

Maybe a small wording change then "which is a bug" could be "which would give 
incorrect results".

"is a bug" sounds a lot like we have a bug still.

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


[Lldb-commits] [lldb] 7e49b0d - [lldb] Fix nullptr dereference on running x86 binary with x86-disabled llvm (#82603)

2024-04-16 Thread via lldb-commits

Author: Daniil Kovalev
Date: 2024-04-16T09:53:33+03:00
New Revision: 7e49b0d5a67f212e84f8ec0ec2e39a6a8673bfaf

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

LOG: [lldb] Fix nullptr dereference on running x86 binary with x86-disabled 
llvm (#82603)

If `LLVM_TARGETS_TO_BUILD` does not contain `X86` and we try to run an
x86 binary in lldb, we get a `nullptr` dereference in
`LLVMDisasmInstruction(...)`. We try to call `getDisAsm()` method on a
`LLVMDisasmContext *DC` which is null. The pointer is passed from
`x86AssemblyInspectionEngine::instruction_length(...)` and is originally
`m_disasm_context` member of `x86AssemblyInspectionEngine`. This should
be filled by `LLVMCreateDisasm(...)` in the class constructor, but not
having X86 target enabled in llvm makes
`TargetRegistry::lookupTarget(...)` call return `nullptr`, which results
in `m_disasm_context` initialized with `nullptr` as well.

This patch adds if statements against `m_disasm_context` in
`x86AssemblyInspectionEngine::GetNonCallSiteUnwindPlanFromAssembly(...)`
and `x86AssemblyInspectionEngine::FindFirstNonPrologueInstruction(...)`
so subsequent calls to
`x86AssemblyInspectionEngine::instruction_length(...)` do not cause a
null pointer dereference.

Added: 
lldb/unittests/UnwindAssembly/x86-but-no-x86-target/CMakeLists.txt

lldb/unittests/UnwindAssembly/x86-but-no-x86-target/Testx86AssemblyInspectionEngine.cpp

Modified: 
lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
lldb/unittests/UnwindAssembly/CMakeLists.txt

Removed: 




diff  --git 
a/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp 
b/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
index 2032c5a68d054c..6bfaa54135a959 100644
--- a/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
+++ b/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
@@ -909,6 +909,9 @@ bool 
x86AssemblyInspectionEngine::GetNonCallSiteUnwindPlanFromAssembly(
   if (!m_register_map_initialized)
 return false;
 
+  if (m_disasm_context == nullptr)
+return false;
+
   addr_t current_func_text_offset = 0;
   int current_sp_bytes_offset_from_fa = 0;
   bool is_aligned = false;
@@ -1570,6 +1573,9 @@ bool 
x86AssemblyInspectionEngine::FindFirstNonPrologueInstruction(
   if (!m_register_map_initialized)
 return false;
 
+  if (m_disasm_context == nullptr)
+return false;
+
   while (offset < size) {
 int regno;
 int insn_len;

diff  --git a/lldb/unittests/UnwindAssembly/CMakeLists.txt 
b/lldb/unittests/UnwindAssembly/CMakeLists.txt
index 136fcd9ae97981..d6e4471af4ecb3 100644
--- a/lldb/unittests/UnwindAssembly/CMakeLists.txt
+++ b/lldb/unittests/UnwindAssembly/CMakeLists.txt
@@ -9,3 +9,7 @@ endif()
 if ("X86" IN_LIST LLVM_TARGETS_TO_BUILD)
   add_subdirectory(x86)
 endif()
+
+if (NOT "X86" IN_LIST LLVM_TARGETS_TO_BUILD)
+  add_subdirectory(x86-but-no-x86-target)
+endif()

diff  --git 
a/lldb/unittests/UnwindAssembly/x86-but-no-x86-target/CMakeLists.txt 
b/lldb/unittests/UnwindAssembly/x86-but-no-x86-target/CMakeLists.txt
new file mode 100644
index 00..d28e9629a64cfc
--- /dev/null
+++ b/lldb/unittests/UnwindAssembly/x86-but-no-x86-target/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_lldb_unittest(UnwindAssemblyX86ButNoX86TargetTests
+Testx86AssemblyInspectionEngine.cpp
+LINK_LIBS
+  lldbCore
+  lldbSymbol
+  lldbPluginUnwindAssemblyX86
+LINK_COMPONENTS
+  Support
+  ${LLVM_TARGETS_TO_BUILD}
+  )

diff  --git 
a/lldb/unittests/UnwindAssembly/x86-but-no-x86-target/Testx86AssemblyInspectionEngine.cpp
 
b/lldb/unittests/UnwindAssembly/x86-but-no-x86-target/Testx86AssemblyInspectionEngine.cpp
new file mode 100644
index 00..ed093d146440e3
--- /dev/null
+++ 
b/lldb/unittests/UnwindAssembly/x86-but-no-x86-target/Testx86AssemblyInspectionEngine.cpp
@@ -0,0 +1,103 @@
+//===-- Testx86AssemblyInspectionEngine.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 "gtest/gtest.h"
+
+#include "Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.h"
+#include "lldb/Core/AddressRange.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Utility/ArchSpec.h"
+
+#include "llvm/Support/TargetSelect.h"
+
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+class Testx86AssemblyInspectionEngine : public testing::Test {
+public:
+  static void SetUpTestCase();
+};
+
+void 

[Lldb-commits] [lldb] [lldb] Fix nullptr dereference on running x86 binary with x86-disabled llvm (PR #82603)

2024-04-16 Thread Daniil Kovalev via lldb-commits

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