[Lldb-commits] [lldb] [lldb][AArch64] Do not crash if NT_ARM_TLS is missing (PR #106478)

Igor Kudrin via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 29 12:22:05 PDT 2024


https://github.com/igorkudrin updated https://github.com/llvm/llvm-project/pull/106478

>From 6854730d45a2c119d2b8f71df6e22ead1c7ad5a8 Mon Sep 17 00:00:00 2001
From: Igor Kudrin <ikudrin at accesssoftek.com>
Date: Wed, 28 Aug 2024 17:57:38 -0700
Subject: [PATCH 1/2] [lldb][AArch64] Do not crash if NT_ARM_TLS is missing

[D156118](https://reviews.llvm.org/D156118) states that this note is
always present, but it is better to check it explicitly, as otherwise
`lldb` may crash when trying to read registers.
---
 .../Utility/RegisterInfoPOSIX_arm64.cpp       |  7 ++--
 .../elf-core/aarch64-no-NT_ARM_TLS.yaml       | 34 +++++++++++++++++++
 .../test/Shell/Process/elf-core/lit.local.cfg |  1 +
 3 files changed, 39 insertions(+), 3 deletions(-)
 create mode 100644 lldb/test/Shell/Process/elf-core/aarch64-no-NT_ARM_TLS.yaml
 create mode 100644 lldb/test/Shell/Process/elf-core/lit.local.cfg

diff --git a/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp b/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
index 054b7d9b2ec575..8ebdd214458c45 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
@@ -254,9 +254,10 @@ RegisterInfoPOSIX_arm64::RegisterInfoPOSIX_arm64(
       if (m_opt_regsets.AllSet(eRegsetMaskMTE))
         AddRegSetMTE();
 
-      // The TLS set always contains tpidr but only has tpidr2 when SME is
-      // present.
-      AddRegSetTLS(m_opt_regsets.AllSet(eRegsetMaskSSVE));
+      if (m_opt_regsets.AllSet(eRegsetMaskTLS))
+        // The TLS set always contains tpidr but only has tpidr2 when SME is
+        // present.
+        AddRegSetTLS(m_opt_regsets.AllSet(eRegsetMaskSSVE));
 
       if (m_opt_regsets.AnySet(eRegsetMaskSSVE))
         AddRegSetSME(m_opt_regsets.AnySet(eRegsetMaskZT));
diff --git a/lldb/test/Shell/Process/elf-core/aarch64-no-NT_ARM_TLS.yaml b/lldb/test/Shell/Process/elf-core/aarch64-no-NT_ARM_TLS.yaml
new file mode 100644
index 00000000000000..bd8ce225c9e071
--- /dev/null
+++ b/lldb/test/Shell/Process/elf-core/aarch64-no-NT_ARM_TLS.yaml
@@ -0,0 +1,34 @@
+# REQUIRES: aarch64
+
+## Check that lldb does not crash if a core file does not contain an NT_ARM_TLS
+## note while there are notes for other dynamic register sets.
+
+# RUN: yaml2obj %s -o %t
+# RUN: %lldb -c %t -o "re r -a" | FileCheck %s
+
+# CHECK:      Pointer Authentication Registers:
+# CHECK-NEXT:   data_mask =
+# CHECK-NEXT:   code_mask =
+# CHECK-NOT:  Thread Local Storage Registers:
+
+--- !ELF
+FileHeader:
+  Class:        ELFCLASS64
+  Data:         ELFDATA2LSB
+  Type:         ET_CORE
+  Machine:      EM_AARCH64
+ProgramHeaders:
+  - Type:       PT_NOTE
+    FirstSec:   .note
+    LastSec:    .note
+Sections:
+  - Name:       .note
+    Type:       SHT_NOTE
+    Notes:
+      - Name:   CORE
+        Desc:   0b00000000000000000000000b00000000000000000000000000000000000000389300001b930000389300001b930000000000000000000000000000000000000000000000000000e02e0000000000000000000000000000119100000000000000000000000000005ee100000000000000000000000000002f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400162e2ffff00005801400000000000200162e2ffff0000240140000000000000000000000000000100000000000000
+        Type:   NT_PRSTATUS
+      - Name:   LINUX
+        Desc:   0000000000007f000000000000007f00
+        Type:   NT_ARM_PAC_MASK
+...
diff --git a/lldb/test/Shell/Process/elf-core/lit.local.cfg b/lldb/test/Shell/Process/elf-core/lit.local.cfg
new file mode 100644
index 00000000000000..8169b9f95e118c
--- /dev/null
+++ b/lldb/test/Shell/Process/elf-core/lit.local.cfg
@@ -0,0 +1 @@
+config.suffixes = ['.yaml']

>From 90366705c6bce931a279940c5f9ee43f232f00f2 Mon Sep 17 00:00:00 2001
From: Igor Kudrin <ikudrin at accesssoftek.com>
Date: Thu, 29 Aug 2024 12:20:42 -0700
Subject: [PATCH 2/2] fixup: add braces

---
 .../source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp b/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
index 8ebdd214458c45..9f5872e5de7e9f 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
@@ -254,10 +254,11 @@ RegisterInfoPOSIX_arm64::RegisterInfoPOSIX_arm64(
       if (m_opt_regsets.AllSet(eRegsetMaskMTE))
         AddRegSetMTE();
 
-      if (m_opt_regsets.AllSet(eRegsetMaskTLS))
+      if (m_opt_regsets.AllSet(eRegsetMaskTLS)) {
         // The TLS set always contains tpidr but only has tpidr2 when SME is
         // present.
         AddRegSetTLS(m_opt_regsets.AllSet(eRegsetMaskSSVE));
+      }
 
       if (m_opt_regsets.AnySet(eRegsetMaskSSVE))
         AddRegSetSME(m_opt_regsets.AnySet(eRegsetMaskZT));



More information about the lldb-commits mailing list