[Lldb-commits] [lldb] [lldb][AArch64] Fix arm64 hardware breakpoint/watchpoint to arm32 process. (PR #147198)

2025-07-06 Thread via lldb-commits

https://github.com/b10902118 created 
https://github.com/llvm/llvm-project/pull/147198

This bug skips the test because the wrong ptrace call to detect avaliable 
hardware/breakpoint number that resuls in 0.

After tracing linux's compat_ptrace in arch/arm64/kernel/ptrace.c, found that 
arm64 lldb-server should just keep using the ptrace commands for 64bit tracees. 
See: 
https://github.com/torvalds/linux/commit/5d220ff9420f8b1689805ba2d938bedf9e0860a4

So the solution is copying the implementation in 
NativeRegisterContextLinux_arm64.cpp.

>From 102a2f59c07dfb63cc2aabae66a0afcf60388602 Mon Sep 17 00:00:00 2001
From: b10902118 
Date: Sun, 6 Jul 2025 23:50:54 +0800
Subject: [PATCH] [lldb][AArch64] Fix arm64 hardware breakpoint/watchpoint to
 arm32 process.

This bug skips the test because the wrong ptrace call to detect avaliable 
hardware/breakpoint number that resuls in 0.

After tracing linux's compat_ptrace in arch/arm64/kernel/ptrace.c, found that 
arm64 lldb-server should just keep using the ptrace commands for 64bit tracees. 
See:
https://github.com/torvalds/linux/commit/5d220ff9420f8b1689805ba2d938bedf9e0860a4

So the solution is copying the implementation in 
NativeRegisterContextLinux_arm64.cpp.
---
 .../Linux/NativeRegisterContextLinux_arm.cpp  | 75 ++-
 .../Linux/NativeRegisterContextLinux_arm.h|  2 +-
 2 files changed, 74 insertions(+), 3 deletions(-)

diff --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
index dc7fb103e87c0..9123a577008bd 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
@@ -23,13 +23,18 @@
 #include 
 #include 
 
+#if defined(__arm64__) || defined(__aarch64__)
+#include "lldb/Host/linux/Ptrace.h"
+#include 
+#endif
+
 #define REG_CONTEXT_SIZE (GetGPRSize() + sizeof(m_fpr))
 
 #ifndef PTRACE_GETVFPREGS
 #define PTRACE_GETVFPREGS 27
 #define PTRACE_SETVFPREGS 28
 #endif
-#ifndef PTRACE_GETHBPREGS
+#if defined(__arm__) && !defined(PTRACE_GETHBPREGS)
 #define PTRACE_GETHBPREGS 29
 #define PTRACE_SETHBPREGS 30
 #endif
@@ -723,6 +728,7 @@ Status 
NativeRegisterContextLinux_arm::ReadHardwareDebugInfo() {
 return Status();
   }
 
+#ifdef __arm__
   unsigned int cap_val;
 
   error = NativeProcessLinux::PtraceWrapper(PTRACE_GETHBPREGS, 
m_thread.GetID(),
@@ -737,12 +743,43 @@ Status 
NativeRegisterContextLinux_arm::ReadHardwareDebugInfo() {
   m_refresh_hwdebug_info = false;
 
   return error;
+#else  // __aarch64__
+  ::pid_t tid = m_thread.GetID();
+
+  int regset = NT_ARM_HW_WATCH;
+  struct iovec ioVec;
+  struct user_hwdebug_state dreg_state;
+
+  ioVec.iov_base = &dreg_state;
+  ioVec.iov_len = sizeof(dreg_state);
+
+  error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set,
+&ioVec, ioVec.iov_len);
+
+  if (error.Fail())
+return error;
+
+  m_max_hwp_supported = dreg_state.dbg_info & 0xff;
+
+  regset = NT_ARM_HW_BREAK;
+  error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set,
+&ioVec, ioVec.iov_len);
+
+  if (error.Fail())
+return error;
+
+  m_max_hbp_supported = dreg_state.dbg_info & 0xff;
+  m_refresh_hwdebug_info = false;
+
+  return error;
+#endif // __arm__
 }
 
-Status NativeRegisterContextLinux_arm::WriteHardwareDebugRegs(int hwbType,
+Status NativeRegisterContextLinux_arm::WriteHardwareDebugRegs(DREGType hwbType,
   int hwb_index) {
   Status error;
 
+#ifdef __arm__
   lldb::addr_t *addr_buf;
   uint32_t *ctrl_buf;
 
@@ -781,6 +818,40 @@ Status 
NativeRegisterContextLinux_arm::WriteHardwareDebugRegs(int hwbType,
   }
 
   return error;
+#else  // __aarch64__
+  struct iovec ioVec;
+  struct user_hwdebug_state dreg_state;
+  int regset;
+
+  memset(&dreg_state, 0, sizeof(dreg_state));
+  ioVec.iov_base = &dreg_state;
+
+  switch (hwbType) {
+  case eDREGTypeWATCH:
+regset = NT_ARM_HW_WATCH;
+ioVec.iov_len = sizeof(dreg_state.dbg_info) + sizeof(dreg_state.pad) +
+(sizeof(dreg_state.dbg_regs[0]) * m_max_hwp_supported);
+
+for (uint32_t i = 0; i < m_max_hwp_supported; i++) {
+  dreg_state.dbg_regs[i].addr = m_hwp_regs[i].address;
+  dreg_state.dbg_regs[i].ctrl = m_hwp_regs[i].control;
+}
+break;
+  case eDREGTypeBREAK:
+regset = NT_ARM_HW_BREAK;
+ioVec.iov_len = sizeof(dreg_state.dbg_info) + sizeof(dreg_state.pad) +
+(sizeof(dreg_state.dbg_regs[0]) * m_max_hbp_supported);
+
+for (uint32_t i = 0; i < m_max_hbp_supported; i++) {
+  dreg_state.dbg_regs[i].addr = m_hbr_regs[i].address;
+  dreg_state.dbg_regs[i].ctrl = m_hbr_regs[i].control;
+}
+break;
+  }
+
+  return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(),
+

[Lldb-commits] [lldb] [lldb][AArch64] Fix arm64 hardware breakpoint/watchpoint to arm32 process. (PR #147198)

2025-07-06 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: None (b10902118)


Changes

This bug skips the test because the wrong ptrace call to detect avaliable 
hardware/breakpoint number that resuls in 0.

After tracing linux's compat_ptrace in arch/arm64/kernel/ptrace.c, found that 
arm64 lldb-server should just keep using the ptrace commands for 64bit tracees. 
See: 
https://github.com/torvalds/linux/commit/5d220ff9420f8b1689805ba2d938bedf9e0860a4

So the solution is copying the implementation in 
NativeRegisterContextLinux_arm64.cpp.

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


2 Files Affected:

- (modified) 
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp (+73-2) 
- (modified) lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h 
(+1-1) 


``diff
diff --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
index dc7fb103e87c0..9123a577008bd 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
@@ -23,13 +23,18 @@
 #include 
 #include 
 
+#if defined(__arm64__) || defined(__aarch64__)
+#include "lldb/Host/linux/Ptrace.h"
+#include 
+#endif
+
 #define REG_CONTEXT_SIZE (GetGPRSize() + sizeof(m_fpr))
 
 #ifndef PTRACE_GETVFPREGS
 #define PTRACE_GETVFPREGS 27
 #define PTRACE_SETVFPREGS 28
 #endif
-#ifndef PTRACE_GETHBPREGS
+#if defined(__arm__) && !defined(PTRACE_GETHBPREGS)
 #define PTRACE_GETHBPREGS 29
 #define PTRACE_SETHBPREGS 30
 #endif
@@ -723,6 +728,7 @@ Status 
NativeRegisterContextLinux_arm::ReadHardwareDebugInfo() {
 return Status();
   }
 
+#ifdef __arm__
   unsigned int cap_val;
 
   error = NativeProcessLinux::PtraceWrapper(PTRACE_GETHBPREGS, 
m_thread.GetID(),
@@ -737,12 +743,43 @@ Status 
NativeRegisterContextLinux_arm::ReadHardwareDebugInfo() {
   m_refresh_hwdebug_info = false;
 
   return error;
+#else  // __aarch64__
+  ::pid_t tid = m_thread.GetID();
+
+  int regset = NT_ARM_HW_WATCH;
+  struct iovec ioVec;
+  struct user_hwdebug_state dreg_state;
+
+  ioVec.iov_base = &dreg_state;
+  ioVec.iov_len = sizeof(dreg_state);
+
+  error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set,
+&ioVec, ioVec.iov_len);
+
+  if (error.Fail())
+return error;
+
+  m_max_hwp_supported = dreg_state.dbg_info & 0xff;
+
+  regset = NT_ARM_HW_BREAK;
+  error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set,
+&ioVec, ioVec.iov_len);
+
+  if (error.Fail())
+return error;
+
+  m_max_hbp_supported = dreg_state.dbg_info & 0xff;
+  m_refresh_hwdebug_info = false;
+
+  return error;
+#endif // __arm__
 }
 
-Status NativeRegisterContextLinux_arm::WriteHardwareDebugRegs(int hwbType,
+Status NativeRegisterContextLinux_arm::WriteHardwareDebugRegs(DREGType hwbType,
   int hwb_index) {
   Status error;
 
+#ifdef __arm__
   lldb::addr_t *addr_buf;
   uint32_t *ctrl_buf;
 
@@ -781,6 +818,40 @@ Status 
NativeRegisterContextLinux_arm::WriteHardwareDebugRegs(int hwbType,
   }
 
   return error;
+#else  // __aarch64__
+  struct iovec ioVec;
+  struct user_hwdebug_state dreg_state;
+  int regset;
+
+  memset(&dreg_state, 0, sizeof(dreg_state));
+  ioVec.iov_base = &dreg_state;
+
+  switch (hwbType) {
+  case eDREGTypeWATCH:
+regset = NT_ARM_HW_WATCH;
+ioVec.iov_len = sizeof(dreg_state.dbg_info) + sizeof(dreg_state.pad) +
+(sizeof(dreg_state.dbg_regs[0]) * m_max_hwp_supported);
+
+for (uint32_t i = 0; i < m_max_hwp_supported; i++) {
+  dreg_state.dbg_regs[i].addr = m_hwp_regs[i].address;
+  dreg_state.dbg_regs[i].ctrl = m_hwp_regs[i].control;
+}
+break;
+  case eDREGTypeBREAK:
+regset = NT_ARM_HW_BREAK;
+ioVec.iov_len = sizeof(dreg_state.dbg_info) + sizeof(dreg_state.pad) +
+(sizeof(dreg_state.dbg_regs[0]) * m_max_hbp_supported);
+
+for (uint32_t i = 0; i < m_max_hbp_supported; i++) {
+  dreg_state.dbg_regs[i].addr = m_hbr_regs[i].address;
+  dreg_state.dbg_regs[i].ctrl = m_hbr_regs[i].control;
+}
+break;
+  }
+
+  return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(),
+   ®set, &ioVec, ioVec.iov_len);
+#endif // __arm__
 }
 
 uint32_t NativeRegisterContextLinux_arm::CalculateFprOffset(
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h
index 15b46609c286b..6d0ad38d7eb75 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h
@@ -125,7 +125,7 @@ class NativeRegisterContextLinux_arm : public 
NativeRegisterContextLinux {
 
   Status ReadH

[Lldb-commits] [lldb] [lldb][AArch64] Fix arm64 hardware breakpoint/watchpoint to arm32 process. (PR #147198)

2025-07-06 Thread via lldb-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[Lldb-commits] [lldb] [lldb][test] Combine libstdc++ and libc++ std::map tests into generic test (PR #147174)

2025-07-06 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/147174

>From afaebb5e6a16bbf91f3de26ae69050e503d55158 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Sun, 6 Jul 2025 07:37:17 +0100
Subject: [PATCH 1/4] [lldb][test] Combine libstdc++ and libc++ std::map tests
 into generic test

This combines the libc++ and libstdc++ test cases. The libstdcpp tests were a 
subset of the libc++ test, so this patch moves the libcxx test into generic and 
removes the libstdcpp test entirely.

Split out from https://github.com/llvm/llvm-project/pull/146740
---
 .../{libstdcpp => generic}/map/Makefile   |   2 -
 .../map/TestDataFormatterStdMap.py}   |  22 +-
 .../{libcxx => generic}/map/main.cpp  |   0
 .../data-formatter-stl/libcxx/map/Makefile|   6 -
 .../libstdcpp/map/TestDataFormatterStdMap.py  | 301 --
 .../data-formatter-stl/libstdcpp/map/main.cpp |  55 
 6 files changed, 18 insertions(+), 368 deletions(-)
 rename 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/{libstdcpp => 
generic}/map/Makefile (70%)
 rename 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/{libcxx/map/TestDataFormatterLibccMap.py
 => generic/map/TestDataFormatterStdMap.py} (95%)
 rename lldb/test/API/functionalities/data-formatter/data-formatter-stl/{libcxx 
=> generic}/map/main.cpp (100%)
 delete mode 100644 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/Makefile
 delete mode 100644 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/TestDataFormatterStdMap.py
 delete mode 100644 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/main.cpp

diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/Makefile
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/map/Makefile
similarity index 70%
rename from 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/Makefile
rename to 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/map/Makefile
index bf8e6b8703f36..8b20bcb05 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/map/Makefile
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/map/Makefile
@@ -1,5 +1,3 @@
 CXX_SOURCES := main.cpp
 
-USE_LIBSTDCPP := 1
-
 include Makefile.rules
diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/map/TestDataFormatterStdMap.py
similarity index 95%
rename from 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
rename to 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/map/TestDataFormatterStdMap.py
index b2b83a3b46114..b039db8123bbf 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/TestDataFormatterLibccMap.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/map/TestDataFormatterStdMap.py
@@ -9,7 +9,7 @@
 from lldbsuite.test import lldbutil
 
 
-class LibcxxMapDataFormatterTestCase(TestBase):
+class StdMapDataFormatterTestCase(TestBase):
 def setUp(self):
 TestBase.setUp(self)
 ns = "ndk" if lldbplatformutil.target_is_android() else ""
@@ -22,10 +22,8 @@ def check_pair(self, first_value, second_value):
 ]
 return ValueCheck(children=pair_children)
 
-@add_test_categories(["libc++"])
-def test_with_run_command(self):
+def do_test(self):
 """Test that that file and class static variables display correctly."""
-self.build()
 self.runCmd("file " + self.getBuildArtifact("a.out"), 
CURRENT_EXECUTABLE_SET)
 
 bkpt = self.target().FindBreakpointByID(
@@ -326,3 +324,19 @@ def cleanup():
 lldbutil.continue_to_breakpoint(self.process(), bkpt)
 
 self.expect("frame variable ss", substrs=["%s::map" % ns, "size=0", 
"{}"])
+
+@add_test_categories(["libc++"])
+def test_libcxx(self):
+self.build(dictionary={"USE_LIBCPP" : 1})
+self.do_test()
+
+@add_test_categories(["libstdcxx"])
+def test_libstdcxx(self):
+self.build(dictionary={"USE_LIBSTDCPP" : 1})
+self.do_test()
+
+@add_test_categories(["libstdcxx"])
+def test_libstdcxx_debug(self):
+self.build(dictionary={"USE_LIBSTDCPP" : 1,
+   "CXXFLAGS_EXTRAS": "-D_GLIBCXX_DEBUG"})
+self.do_test()
diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/map/main.cpp
similarity index 100%
rename from 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/map/main.cpp
rename to 
lldb/test/API/functionalities/data-formatte

[Lldb-commits] [lldb] [lldb] Pass address expression command args through FixAnyAddress (PR #147011)

2025-07-06 Thread Jason Molenda via lldb-commits

https://github.com/jasonmolenda updated 
https://github.com/llvm/llvm-project/pull/147011

>From bf1838f4676bab0f7c998d3dbb03b6b593103335 Mon Sep 17 00:00:00 2001
From: Jason Molenda 
Date: Fri, 4 Jul 2025 00:11:30 -0700
Subject: [PATCH 1/2] [lldb] Pass address expression command args through
 FixAnyAddress

Commands that take an address expression/address through the
OptionArgParser::ToAddress method, which has filtered this
user-specified address through one of the Process Fix methods to
clear non-addressable bits (MTE, PAC, top byte ignore, etc).  We
don't know what class of address this is, IMEM or DMEM, but this
method is passing the addresses through Process::FixCodeAddress,
and on at least one target, FixCodeAddress clears low bits which
are invalid for instructions.

Correct this to use FixAnyAddress, which doesn't make alignment
assumptions.

The actual issue found was by people debugging on a 32-bit ARM
Cortex-M part, who tried to do a memory read from an odd address,
and lldb returned results starting at the next lower even address.

rdar://154885727
---
 lldb/source/Interpreter/OptionArgParser.cpp   |  3 +-
 .../TestArmMachoCorefileRegctx.py |  3 +-
 .../create-arm-corefiles.cpp  | 63 ---
 3 files changed, 58 insertions(+), 11 deletions(-)

diff --git a/lldb/source/Interpreter/OptionArgParser.cpp 
b/lldb/source/Interpreter/OptionArgParser.cpp
index 2d393a57452ee..616f6e3dc8820 100644
--- a/lldb/source/Interpreter/OptionArgParser.cpp
+++ b/lldb/source/Interpreter/OptionArgParser.cpp
@@ -175,8 +175,7 @@ lldb::addr_t OptionArgParser::ToAddress(const 
ExecutionContext *exe_ctx,
   lldb::addr_t addr = *maybe_addr;
 
   if (Process *process = exe_ctx->GetProcessPtr())
-if (ABISP abi_sp = process->GetABI())
-  addr = abi_sp->FixCodeAddress(addr);
+addr = process->FixAnyAddress(addr);
 
   return addr;
 }
diff --git 
a/lldb/test/API/macosx/arm-corefile-regctx/TestArmMachoCorefileRegctx.py 
b/lldb/test/API/macosx/arm-corefile-regctx/TestArmMachoCorefileRegctx.py
index 4190ea3ac3318..8e34a292e4d5e 100644
--- a/lldb/test/API/macosx/arm-corefile-regctx/TestArmMachoCorefileRegctx.py
+++ b/lldb/test/API/macosx/arm-corefile-regctx/TestArmMachoCorefileRegctx.py
@@ -1,6 +1,5 @@
 """Test that Mach-O armv7/arm64 corefile register contexts are read by lldb."""
 
-
 import os
 import re
 import subprocess
@@ -44,6 +43,8 @@ def test_armv7_corefile(self):
 self.assertTrue(exception.IsValid())
 self.assertEqual(exception.GetValueAsUnsigned(), 0x3F5C)
 
+self.expect("x/4bx $sp-1", substrs=["0x000d", "0xff 0x00 0x01 
0x02"])
+
 def test_arm64_corefile(self):
 ### Create corefile
 retcode = call(self.create_corefile + " arm64 " + self.corefile, 
shell=True)
diff --git a/lldb/test/API/macosx/arm-corefile-regctx/create-arm-corefiles.cpp 
b/lldb/test/API/macosx/arm-corefile-regctx/create-arm-corefiles.cpp
index 5517a2397ae52..2bcc48497bdc4 100644
--- a/lldb/test/API/macosx/arm-corefile-regctx/create-arm-corefiles.cpp
+++ b/lldb/test/API/macosx/arm-corefile-regctx/create-arm-corefiles.cpp
@@ -10,15 +10,30 @@
 // only defines the ARM register context constants when building on
 // an arm system.  We're creating fake corefiles, and might be
 // creating them on an intel system.
+#ifndef ARM_THREAD_STATE
 #define ARM_THREAD_STATE 1
+#endif
+#ifndef ARM_THREAD_STATE_COUNT
 #define ARM_THREAD_STATE_COUNT 17
+#endif
+#ifndef ARM_EXCEPTION_STATE
 #define ARM_EXCEPTION_STATE 3
+#endif
+#ifndef ARM_EXCEPTION_STATE_COUNT
 #define ARM_EXCEPTION_STATE_COUNT 3
+#endif
+#ifndef ARM_THREAD_STATE64
 #define ARM_THREAD_STATE64 6
+#endif
+#ifndef ARM_THREAD_STATE64_COUNT
 #define ARM_THREAD_STATE64_COUNT 68
+#endif
+#ifndef ARM_EXCEPTION_STATE64
 #define ARM_EXCEPTION_STATE64 7
+#endif
+#ifndef ARM_EXCEPTION_STATE64_COUNT
 #define ARM_EXCEPTION_STATE64_COUNT 4
-
+#endif
 
 union uint32_buf {
   uint8_t bytebuf[4];
@@ -129,6 +144,24 @@ std::vector arm64_lc_thread_load_command() {
   return data;
 }
 
+std::vector lc_segment(uint32_t fileoff) {
+  std::vector data;
+  add_uint32(data, LC_SEGMENT); // segment_command.cmd
+  add_uint32(data, sizeof(struct segment_command)); // segment_command.cmdsize
+  for (int i = 0; i < 16; i++)
+data.push_back(0);// segment_command.segname[16]
+  add_uint32(data, 0x000e - 512); // segment_command.vmaddr
+  add_uint32(data, 1024); // segment_command.vmsize
+  add_uint32(data, fileoff);  // segment_command.fileoff
+  add_uint32(data, 1024); // segment_command.filesize
+  add_uint32(data, 3);// segment_command.maxprot
+  add_uint32(data, 3);// segment_command.initprot
+  add_uint32(data, 0);// segment_command.nsects
+  add_uint32(data, 0);// segment_command.flags
+
+  return data;
+}
+
 enum arch { unspecified, armv7, arm64 };
 
 int main(int argc, char **argv) {
@@ -

[Lldb-commits] [clang] [clang-tools-extra] [libcxx] [lldb] [Clang] Make the SizeType, SignedSizeType and PtrdiffType be named sugar types instead of built-in types (PR #143653)

2025-07-06 Thread via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)

2025-07-06 Thread Dmitry Vasilyev via lldb-commits


@@ -31,6 +34,122 @@ static DWORD 
ToTimeout(std::optional point) {
   return ceil(dur).count();
 }
 
+namespace {
+
+class PipeEvent : public MainLoopWindows::IOEvent {
+public:
+  explicit PipeEvent(HANDLE handle)
+  : IOEvent((IOObject::WaitableHandle)CreateEventW(
+NULL, /*bManualReset=*/FALSE,
+/*bInitialState=*/FALSE, NULL)),
+m_handle(handle), m_ready(CreateEventW(NULL, /*bManualReset=*/FALSE,
+   /*bInitialState=*/FALSE, NULL)) 
{
+assert(m_event && m_ready);
+  }
+
+  ~PipeEvent() override {
+if (m_monitor_thread.joinable()) {
+  m_stopped = true;
+  SetEvent(m_ready);
+  // Keep trying to cancel ReadFile() until the thread exits.
+  do {
+CancelIoEx((HANDLE)m_handle, /*lpOverlapped=*/NULL);
+  } while (WaitForSingleObject(m_monitor_thread.native_handle(), 1) ==
+   WAIT_TIMEOUT);
+  m_monitor_thread.join();
+}
+CloseHandle((HANDLE)m_event);
+CloseHandle(m_ready);
+  }
+
+  void WillPoll() override {
+if (!m_monitor_thread.joinable())
+  m_monitor_thread = std::thread(&PipeEvent::Monitor, this);
+  }
+
+  void Disarm() override { SetEvent(m_ready); }
+
+  /// Monitors the handle performing a zero byte read to determine when data is
+  /// avaiable.
+  void Monitor() {
+do {
+  char buf[1];
+  DWORD bytes_read = 0;
+  OVERLAPPED ov = {0};
+  // Block on a 0-byte read; this will only resume when data is
+  // available in the pipe. The pipe must be PIPE_WAIT or this thread
+  // will spin.
+  BOOL success =
+  ReadFile(m_handle, buf, /*nNumberOfBytesToRead=*/0, &bytes_read, 
&ov);
+  DWORD bytes_available = 0;
+  DWORD err = GetLastError();

slydiman wrote:

Don't call GetLastError() if ReadFile returned TRUE! 

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


[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)

2025-07-06 Thread Dmitry Vasilyev via lldb-commits


@@ -44,26 +163,20 @@ MainLoopWindows::~MainLoopWindows() {
 }
 
 llvm::Expected MainLoopWindows::Poll() {
-  std::vector events;
+  std::vector events;
   events.reserve(m_read_fds.size() + 1);
-  for (auto &[fd, info] : m_read_fds) {
-int result = WSAEventSelect(fd, info.event, FD_READ | FD_ACCEPT | 
FD_CLOSE);
-assert(result == 0);
-UNUSED_IF_ASSERT_DISABLED(result);
-
-events.push_back(info.event);
+  for (auto &[_, fd_info] : m_read_fds) {
+fd_info.event->WillPoll();
+events.push_back((HANDLE)fd_info.event->GetHandle());
   }
   events.push_back(m_interrupt_event);
 
   DWORD result =
   WSAWaitForMultipleEvents(events.size(), events.data(), FALSE,

slydiman wrote:

Why you still call WSAWaitForMultipleEvents instead of WaitForMultipleObjects 
for non-socket handles?

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


[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)

2025-07-06 Thread Dmitry Vasilyev via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)

2025-07-06 Thread Dmitry Vasilyev via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Update the String table offset based on the DWARF format (PR #147054)

2025-07-06 Thread Hemang Gadhavi via lldb-commits

HemangGadhavi wrote:

> I suggest you look in lldb's source for any uses of the DWARF32 symbol, I bet 
> we've done this elsewhere too.

Yes I already found it and its in my list to fix, there are few places where 
`DWARF32` parsing but I was planing to do in separate PR. or you want me to do 
it here only ?

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