[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

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

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


[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

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

kovdan01 wrote:

Merging this previously approved PR since prerequisites are now met

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


[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

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

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/84387

>From 728f5644aebfafd2114e7e47a9b83ef057423997 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 20 Feb 2024 10:57:54 -0800
Subject: [PATCH 1/6] Upstream ptrauth changes to DWARFASTParserClang

---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 57 +++
 1 file changed, 57 insertions(+)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 54d06b1115a229..67fe830e1aa70d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -495,6 +495,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const 
SymbolContext ,
   case DW_TAG_const_type:
   case DW_TAG_restrict_type:
   case DW_TAG_volatile_type:
+  case DW_TAG_LLVM_ptrauth_type:
   case DW_TAG_atomic_type:
   case DW_TAG_unspecified_type: {
 type_sp = ParseTypeModifier(sc, die, attrs);
@@ -676,6 +677,62 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext 
,
   case DW_TAG_volatile_type:
 encoding_data_type = Type::eEncodingIsVolatileUID;
 break;
+  case DW_TAG_LLVM_ptrauth_type: {
+DWARFDIE ptr_die = die.GetReferencedDIE(DW_AT_type);
+// FIXME: Fully resolving the type here may affect performance.
+Type *res_type = dwarf->ResolveType(ptr_die);
+if (!res_type)
+  break;
+attrs.type.Clear();
+encoding_data_type = Type::eEncodingIsUID;
+resolve_state = Type::ResolveState::Full;
+
+// Apply the ptrauth qualifier to the resolved type.
+auto *ptr_type =
+(clang::Type *)res_type->GetForwardCompilerType().GetOpaqueQualType();
+auto getAttr = [&](llvm::dwarf::Attribute Attr, unsigned defaultValue = 0) 
{
+  return die.GetAttributeValueAsUnsigned(Attr, defaultValue);
+};
+const unsigned key = getAttr(DW_AT_LLVM_ptrauth_key);
+const bool addr_disc = getAttr(DW_AT_LLVM_ptrauth_address_discriminated);
+const unsigned extra = getAttr(DW_AT_LLVM_ptrauth_extra_discriminator);
+const bool isapointer = getAttr(DW_AT_LLVM_ptrauth_isa_pointer);
+const bool authenticates_null_values =
+getAttr(DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
+const bool is_restricted_integral = !ptr_type->isPointerType();
+const unsigned authentication_mode_int = getAttr(
+DW_AT_LLVM_ptrauth_authentication_mode,
+static_cast(clang::PointerAuthenticationMode::SignAndAuth));
+clang::PointerAuthenticationMode authentication_mode =
+clang::PointerAuthenticationMode::SignAndAuth;
+if (authentication_mode_int >=
+static_cast(clang::PointerAuthenticationMode::None) &&
+authentication_mode_int <=
+static_cast(
+clang::PointerAuthenticationMode::SignAndAuth)) {
+  authentication_mode = static_cast(
+  authentication_mode_int);
+} else {
+  dwarf->GetObjectFile()->GetModule()->ReportError(
+  "[{0:x16}]: invalid pointer authentication mode method {1:x4}",
+  die.GetOffset(), authentication_mode_int);
+}
+
+// FIXME: Use these variables when PointerAuthQualifier is more complete
+// upstream.
+(void)is_restricted_integral;
+
+clang::Qualifiers qualifiers;
+auto ptr_auth = clang::PointerAuthQualifier::Create(
+key, addr_disc, extra, authentication_mode, isapointer,
+authenticates_null_values);
+qualifiers.setPointerAuth(ptr_auth);
+auto  = m_ast.getASTContext();
+auto qual_type = ctx.getQualifiedType(ptr_type, qualifiers);
+clang_type =
+CompilerType(m_ast.weak_from_this(), qual_type.getAsOpaquePtr());
+break;
+  }
   case DW_TAG_atomic_type:
 encoding_data_type = Type::eEncodingIsAtomicUID;
 break;

>From 8aa1ba0b05362b8960faac1945bb25c68ecb4b98 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Thu, 7 Mar 2024 16:34:09 +0300
Subject: [PATCH 2/6] [PAC][lldb] Use `eEncodingIsLLVMPtrAuthUID` for
 `__ptrauth`-qualified types

---
 lldb/include/lldb/Symbol/Type.h   | 4 +++-
 .../Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp  | 2 +-
 lldb/source/Symbol/Type.cpp   | 8 +++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index acd1a769f13cd6..d55280b58bc4f7 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -401,7 +401,9 @@ class Type : public std::enable_shared_from_this, 
public UserID {
 /// This type is the type whose UID is m_encoding_uid as an atomic type.
 eEncodingIsAtomicUID,
 /// This type is the synthetic type whose UID is m_encoding_uid.
-eEncodingIsSyntheticUID
+eEncodingIsSyntheticUID,
+/// This type is a signed pointer.
+eEncodingIsLLVMPtrAuthUID
   };
 
   enum class ResolveState : unsigned char 

[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

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

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


[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

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

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/84387

>From 728f5644aebfafd2114e7e47a9b83ef057423997 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 20 Feb 2024 10:57:54 -0800
Subject: [PATCH 1/6] Upstream ptrauth changes to DWARFASTParserClang

---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 57 +++
 1 file changed, 57 insertions(+)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 54d06b1115a229..67fe830e1aa70d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -495,6 +495,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const 
SymbolContext ,
   case DW_TAG_const_type:
   case DW_TAG_restrict_type:
   case DW_TAG_volatile_type:
+  case DW_TAG_LLVM_ptrauth_type:
   case DW_TAG_atomic_type:
   case DW_TAG_unspecified_type: {
 type_sp = ParseTypeModifier(sc, die, attrs);
@@ -676,6 +677,62 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext 
,
   case DW_TAG_volatile_type:
 encoding_data_type = Type::eEncodingIsVolatileUID;
 break;
+  case DW_TAG_LLVM_ptrauth_type: {
+DWARFDIE ptr_die = die.GetReferencedDIE(DW_AT_type);
+// FIXME: Fully resolving the type here may affect performance.
+Type *res_type = dwarf->ResolveType(ptr_die);
+if (!res_type)
+  break;
+attrs.type.Clear();
+encoding_data_type = Type::eEncodingIsUID;
+resolve_state = Type::ResolveState::Full;
+
+// Apply the ptrauth qualifier to the resolved type.
+auto *ptr_type =
+(clang::Type *)res_type->GetForwardCompilerType().GetOpaqueQualType();
+auto getAttr = [&](llvm::dwarf::Attribute Attr, unsigned defaultValue = 0) 
{
+  return die.GetAttributeValueAsUnsigned(Attr, defaultValue);
+};
+const unsigned key = getAttr(DW_AT_LLVM_ptrauth_key);
+const bool addr_disc = getAttr(DW_AT_LLVM_ptrauth_address_discriminated);
+const unsigned extra = getAttr(DW_AT_LLVM_ptrauth_extra_discriminator);
+const bool isapointer = getAttr(DW_AT_LLVM_ptrauth_isa_pointer);
+const bool authenticates_null_values =
+getAttr(DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
+const bool is_restricted_integral = !ptr_type->isPointerType();
+const unsigned authentication_mode_int = getAttr(
+DW_AT_LLVM_ptrauth_authentication_mode,
+static_cast(clang::PointerAuthenticationMode::SignAndAuth));
+clang::PointerAuthenticationMode authentication_mode =
+clang::PointerAuthenticationMode::SignAndAuth;
+if (authentication_mode_int >=
+static_cast(clang::PointerAuthenticationMode::None) &&
+authentication_mode_int <=
+static_cast(
+clang::PointerAuthenticationMode::SignAndAuth)) {
+  authentication_mode = static_cast(
+  authentication_mode_int);
+} else {
+  dwarf->GetObjectFile()->GetModule()->ReportError(
+  "[{0:x16}]: invalid pointer authentication mode method {1:x4}",
+  die.GetOffset(), authentication_mode_int);
+}
+
+// FIXME: Use these variables when PointerAuthQualifier is more complete
+// upstream.
+(void)is_restricted_integral;
+
+clang::Qualifiers qualifiers;
+auto ptr_auth = clang::PointerAuthQualifier::Create(
+key, addr_disc, extra, authentication_mode, isapointer,
+authenticates_null_values);
+qualifiers.setPointerAuth(ptr_auth);
+auto  = m_ast.getASTContext();
+auto qual_type = ctx.getQualifiedType(ptr_type, qualifiers);
+clang_type =
+CompilerType(m_ast.weak_from_this(), qual_type.getAsOpaquePtr());
+break;
+  }
   case DW_TAG_atomic_type:
 encoding_data_type = Type::eEncodingIsAtomicUID;
 break;

>From 8aa1ba0b05362b8960faac1945bb25c68ecb4b98 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Thu, 7 Mar 2024 16:34:09 +0300
Subject: [PATCH 2/6] [PAC][lldb] Use `eEncodingIsLLVMPtrAuthUID` for
 `__ptrauth`-qualified types

---
 lldb/include/lldb/Symbol/Type.h   | 4 +++-
 .../Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp  | 2 +-
 lldb/source/Symbol/Type.cpp   | 8 +++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index acd1a769f13cd6..d55280b58bc4f7 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -401,7 +401,9 @@ class Type : public std::enable_shared_from_this, 
public UserID {
 /// This type is the type whose UID is m_encoding_uid as an atomic type.
 eEncodingIsAtomicUID,
 /// This type is the synthetic type whose UID is m_encoding_uid.
-eEncodingIsSyntheticUID
+eEncodingIsSyntheticUID,
+/// This type is a signed pointer.
+eEncodingIsLLVMPtrAuthUID
   };
 
   enum class ResolveState : unsigned char 

[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


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

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

kovdan01 wrote:

Thanks @jasonmolenda for your feedback and suggestion! See 
f96989dd1f832284b74d07d1e457a15a0b16c199 - I've deleted the test with corefile 
and added the test you've mentioned. Basically, I've just left the most simple 
test from "normal" `Testx86AssemblyInspectionEngine` and checked the 
`GetNonCallSiteUnwindPlanFromAssembly` call result against false. I've also 
ensured that w/o the patch applied, we just fail with nullptr dereference - so 
the test actually covers the case it's designed for.

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


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

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

kovdan01 wrote:

@jasonmolenda A kind reminder regarding the PR - see answers to your previous 
comments above

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


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

2024-03-28 Thread Daniil Kovalev via lldb-commits

kovdan01 wrote:

@jasonmolenda Would be glad to see your feedback - see answers to your previous 
comments above

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


[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

2024-03-28 Thread Daniil Kovalev via lldb-commits


@@ -676,6 +677,62 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext 
,
   case DW_TAG_volatile_type:
 encoding_data_type = Type::eEncodingIsVolatileUID;
 break;
+  case DW_TAG_LLVM_ptrauth_type: {
+DWARFDIE ptr_die = die.GetReferencedDIE(DW_AT_type);

kovdan01 wrote:

Done, thanks, see eecbb370d3d0257a5a4ffb68219d41aa5426

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


[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

2024-03-28 Thread Daniil Kovalev via lldb-commits


@@ -216,6 +216,16 @@ class TypeSystem : public PluginInterface,
 
   virtual uint32_t GetPointerByteSize() = 0;
 
+  // TODO: are we allowed to insert virtual functions in the middle of the 
class
+  // interface and break ABI?

kovdan01 wrote:

Thanks, deleted TODOs in ced59fd6d4fcaa1a4158708fde3a4b0e9af2e5c2

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


[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

2024-03-28 Thread Daniil Kovalev via lldb-commits


@@ -664,6 +685,17 @@ CompilerType CompilerType::GetPointerType() const {
   return CompilerType();
 }
 
+CompilerType
+CompilerType::AddPtrAuthModifier(unsigned key, bool isAddressDiscriminated,

kovdan01 wrote:

> Also, whose this user of this API?

I've updated this PR with eecbb370d3d0257a5a4ffb68219d41aa5426 which 
implements lazy resolve of ptrauth types. Since then, 
`CompilerType::AddPtrAuthModifier` is used in `Type::ResolveCompilerType`. So, 
this API is "indirectly" tested in DWARFASTParserClangTests.TestPtrAuthParsing 
unit test.

> Can we add an API test that tests this API? E.g., running `frame var`/`expr` 
> on ptrauth types?

Probably later, when `__ptrauth` qualifier support in upstream llvm is more 
complete. As far as I see from existing API tests (e.g. 
API/lang/c/const_variables/TestConstVariables.py), we need to compile code with 
desired features first, and then run it under debugger and test stuff that we 
want to. Since the compiler does not seem to fully support `__ptrauth`-related 
features yet, implementing the corresponding API test does not currently seem 
viable.

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


[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

2024-03-28 Thread Daniil Kovalev via lldb-commits

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/84387

>From 728f5644aebfafd2114e7e47a9b83ef057423997 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 20 Feb 2024 10:57:54 -0800
Subject: [PATCH 1/6] Upstream ptrauth changes to DWARFASTParserClang

---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 57 +++
 1 file changed, 57 insertions(+)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 54d06b1115a229..67fe830e1aa70d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -495,6 +495,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const 
SymbolContext ,
   case DW_TAG_const_type:
   case DW_TAG_restrict_type:
   case DW_TAG_volatile_type:
+  case DW_TAG_LLVM_ptrauth_type:
   case DW_TAG_atomic_type:
   case DW_TAG_unspecified_type: {
 type_sp = ParseTypeModifier(sc, die, attrs);
@@ -676,6 +677,62 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext 
,
   case DW_TAG_volatile_type:
 encoding_data_type = Type::eEncodingIsVolatileUID;
 break;
+  case DW_TAG_LLVM_ptrauth_type: {
+DWARFDIE ptr_die = die.GetReferencedDIE(DW_AT_type);
+// FIXME: Fully resolving the type here may affect performance.
+Type *res_type = dwarf->ResolveType(ptr_die);
+if (!res_type)
+  break;
+attrs.type.Clear();
+encoding_data_type = Type::eEncodingIsUID;
+resolve_state = Type::ResolveState::Full;
+
+// Apply the ptrauth qualifier to the resolved type.
+auto *ptr_type =
+(clang::Type *)res_type->GetForwardCompilerType().GetOpaqueQualType();
+auto getAttr = [&](llvm::dwarf::Attribute Attr, unsigned defaultValue = 0) 
{
+  return die.GetAttributeValueAsUnsigned(Attr, defaultValue);
+};
+const unsigned key = getAttr(DW_AT_LLVM_ptrauth_key);
+const bool addr_disc = getAttr(DW_AT_LLVM_ptrauth_address_discriminated);
+const unsigned extra = getAttr(DW_AT_LLVM_ptrauth_extra_discriminator);
+const bool isapointer = getAttr(DW_AT_LLVM_ptrauth_isa_pointer);
+const bool authenticates_null_values =
+getAttr(DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
+const bool is_restricted_integral = !ptr_type->isPointerType();
+const unsigned authentication_mode_int = getAttr(
+DW_AT_LLVM_ptrauth_authentication_mode,
+static_cast(clang::PointerAuthenticationMode::SignAndAuth));
+clang::PointerAuthenticationMode authentication_mode =
+clang::PointerAuthenticationMode::SignAndAuth;
+if (authentication_mode_int >=
+static_cast(clang::PointerAuthenticationMode::None) &&
+authentication_mode_int <=
+static_cast(
+clang::PointerAuthenticationMode::SignAndAuth)) {
+  authentication_mode = static_cast(
+  authentication_mode_int);
+} else {
+  dwarf->GetObjectFile()->GetModule()->ReportError(
+  "[{0:x16}]: invalid pointer authentication mode method {1:x4}",
+  die.GetOffset(), authentication_mode_int);
+}
+
+// FIXME: Use these variables when PointerAuthQualifier is more complete
+// upstream.
+(void)is_restricted_integral;
+
+clang::Qualifiers qualifiers;
+auto ptr_auth = clang::PointerAuthQualifier::Create(
+key, addr_disc, extra, authentication_mode, isapointer,
+authenticates_null_values);
+qualifiers.setPointerAuth(ptr_auth);
+auto  = m_ast.getASTContext();
+auto qual_type = ctx.getQualifiedType(ptr_type, qualifiers);
+clang_type =
+CompilerType(m_ast.weak_from_this(), qual_type.getAsOpaquePtr());
+break;
+  }
   case DW_TAG_atomic_type:
 encoding_data_type = Type::eEncodingIsAtomicUID;
 break;

>From 8aa1ba0b05362b8960faac1945bb25c68ecb4b98 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Thu, 7 Mar 2024 16:34:09 +0300
Subject: [PATCH 2/6] [PAC][lldb] Use `eEncodingIsLLVMPtrAuthUID` for
 `__ptrauth`-qualified types

---
 lldb/include/lldb/Symbol/Type.h   | 4 +++-
 .../Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp  | 2 +-
 lldb/source/Symbol/Type.cpp   | 8 +++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index acd1a769f13cd6..d55280b58bc4f7 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -401,7 +401,9 @@ class Type : public std::enable_shared_from_this, 
public UserID {
 /// This type is the type whose UID is m_encoding_uid as an atomic type.
 eEncodingIsAtomicUID,
 /// This type is the synthetic type whose UID is m_encoding_uid.
-eEncodingIsSyntheticUID
+eEncodingIsSyntheticUID,
+/// This type is a signed pointer.
+eEncodingIsLLVMPtrAuthUID
   };
 
   enum class ResolveState : unsigned char 

[Lldb-commits] [clang] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

2024-03-28 Thread Daniil Kovalev via lldb-commits

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/84387

>From 728f5644aebfafd2114e7e47a9b83ef057423997 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 20 Feb 2024 10:57:54 -0800
Subject: [PATCH 01/10] Upstream ptrauth changes to DWARFASTParserClang

---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 57 +++
 1 file changed, 57 insertions(+)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 54d06b1115a229..67fe830e1aa70d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -495,6 +495,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const 
SymbolContext ,
   case DW_TAG_const_type:
   case DW_TAG_restrict_type:
   case DW_TAG_volatile_type:
+  case DW_TAG_LLVM_ptrauth_type:
   case DW_TAG_atomic_type:
   case DW_TAG_unspecified_type: {
 type_sp = ParseTypeModifier(sc, die, attrs);
@@ -676,6 +677,62 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext 
,
   case DW_TAG_volatile_type:
 encoding_data_type = Type::eEncodingIsVolatileUID;
 break;
+  case DW_TAG_LLVM_ptrauth_type: {
+DWARFDIE ptr_die = die.GetReferencedDIE(DW_AT_type);
+// FIXME: Fully resolving the type here may affect performance.
+Type *res_type = dwarf->ResolveType(ptr_die);
+if (!res_type)
+  break;
+attrs.type.Clear();
+encoding_data_type = Type::eEncodingIsUID;
+resolve_state = Type::ResolveState::Full;
+
+// Apply the ptrauth qualifier to the resolved type.
+auto *ptr_type =
+(clang::Type *)res_type->GetForwardCompilerType().GetOpaqueQualType();
+auto getAttr = [&](llvm::dwarf::Attribute Attr, unsigned defaultValue = 0) 
{
+  return die.GetAttributeValueAsUnsigned(Attr, defaultValue);
+};
+const unsigned key = getAttr(DW_AT_LLVM_ptrauth_key);
+const bool addr_disc = getAttr(DW_AT_LLVM_ptrauth_address_discriminated);
+const unsigned extra = getAttr(DW_AT_LLVM_ptrauth_extra_discriminator);
+const bool isapointer = getAttr(DW_AT_LLVM_ptrauth_isa_pointer);
+const bool authenticates_null_values =
+getAttr(DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
+const bool is_restricted_integral = !ptr_type->isPointerType();
+const unsigned authentication_mode_int = getAttr(
+DW_AT_LLVM_ptrauth_authentication_mode,
+static_cast(clang::PointerAuthenticationMode::SignAndAuth));
+clang::PointerAuthenticationMode authentication_mode =
+clang::PointerAuthenticationMode::SignAndAuth;
+if (authentication_mode_int >=
+static_cast(clang::PointerAuthenticationMode::None) &&
+authentication_mode_int <=
+static_cast(
+clang::PointerAuthenticationMode::SignAndAuth)) {
+  authentication_mode = static_cast(
+  authentication_mode_int);
+} else {
+  dwarf->GetObjectFile()->GetModule()->ReportError(
+  "[{0:x16}]: invalid pointer authentication mode method {1:x4}",
+  die.GetOffset(), authentication_mode_int);
+}
+
+// FIXME: Use these variables when PointerAuthQualifier is more complete
+// upstream.
+(void)is_restricted_integral;
+
+clang::Qualifiers qualifiers;
+auto ptr_auth = clang::PointerAuthQualifier::Create(
+key, addr_disc, extra, authentication_mode, isapointer,
+authenticates_null_values);
+qualifiers.setPointerAuth(ptr_auth);
+auto  = m_ast.getASTContext();
+auto qual_type = ctx.getQualifiedType(ptr_type, qualifiers);
+clang_type =
+CompilerType(m_ast.weak_from_this(), qual_type.getAsOpaquePtr());
+break;
+  }
   case DW_TAG_atomic_type:
 encoding_data_type = Type::eEncodingIsAtomicUID;
 break;

>From 8aa1ba0b05362b8960faac1945bb25c68ecb4b98 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Thu, 7 Mar 2024 16:34:09 +0300
Subject: [PATCH 02/10] [PAC][lldb] Use `eEncodingIsLLVMPtrAuthUID` for
 `__ptrauth`-qualified types

---
 lldb/include/lldb/Symbol/Type.h   | 4 +++-
 .../Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp  | 2 +-
 lldb/source/Symbol/Type.cpp   | 8 +++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index acd1a769f13cd6..d55280b58bc4f7 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -401,7 +401,9 @@ class Type : public std::enable_shared_from_this, 
public UserID {
 /// This type is the type whose UID is m_encoding_uid as an atomic type.
 eEncodingIsAtomicUID,
 /// This type is the synthetic type whose UID is m_encoding_uid.
-eEncodingIsSyntheticUID
+eEncodingIsSyntheticUID,
+/// This type is a signed pointer.
+eEncodingIsLLVMPtrAuthUID
   };
 
   enum class ResolveState : unsigned 

[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

2024-03-20 Thread Daniil Kovalev via lldb-commits

kovdan01 wrote:

A kind reminder regarding the PR - would be glad to see feedback from everyone 
interested.

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


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

2024-03-14 Thread Daniil Kovalev via lldb-commits

kovdan01 wrote:

@jasonmolenda Just in case you've missed - I've provided the use case 
description leading to the issue (as you requested) above 
https://github.com/llvm/llvm-project/pull/82603#issuecomment-1970019956. Would 
be glad if you let me know if it gives you enough info & if this particular PR 
is OK or the issue should be fixed in another way.

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


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

2024-03-11 Thread Daniil Kovalev via lldb-commits

kovdan01 wrote:

> As this plugin seems related to backtrace perhaps the test should at least 
> run `bt` and check for the first line of the output.

I had similar thoughts, but I'm not sure if placing the test in 
`lldb/test/Shell/Commands` as `command-backtrace-missing-x86.test` is a nice 
idea. The issue occurs during loading the core dump (or, when debugging an 
executable, when executing "run" command). So, running `bt` might be misleading 
- a one might think that we test an absence of nullptr dereference during `bt`, 
but we want to test that the core dump is at least loaded properly since with 
the issue present we don't even get to the point where we can run `bt`.

I would be glad to here other people's thoughts on that - I'm personally not 
sure which testing approach is less evil here.

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


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

2024-03-11 Thread Daniil Kovalev via lldb-commits


@@ -0,0 +1,10 @@
+# UNSUPPORTED: x86

kovdan01 wrote:

Yes, I've checked that with `X86` in `LLVM_TARGETS_TO_BUILD`, the test becomes 
unsupported. So, it looks like it's currently OK

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


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

2024-03-11 Thread Daniil Kovalev via lldb-commits

kovdan01 wrote:

> Can this code be hit when using an x86 core file? Then you could write a 
> shell test thatis `UNSUPPORTED: x86-registered-target` (whatever the proper 
> syntax is) and assert that it does not crash.

@DavidSpickett The issue is present when loading an x86 core files via `lldb 
--core core` (nothing else, just running this command). I've implemented shell 
test and put that into a new directory Core - see 
bd9bb0a5d73d7532f885222df900c6f6406c7473. If there is a more applicable place 
for that - would be glad to see suggestions

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


[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

2024-03-07 Thread Daniil Kovalev via lldb-commits

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


[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

2024-03-07 Thread Daniil Kovalev via lldb-commits

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/84387

>From 728f5644aebfafd2114e7e47a9b83ef057423997 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 20 Feb 2024 10:57:54 -0800
Subject: [PATCH 1/4] Upstream ptrauth changes to DWARFASTParserClang

---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 57 +++
 1 file changed, 57 insertions(+)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 54d06b1115a229..67fe830e1aa70d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -495,6 +495,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const 
SymbolContext ,
   case DW_TAG_const_type:
   case DW_TAG_restrict_type:
   case DW_TAG_volatile_type:
+  case DW_TAG_LLVM_ptrauth_type:
   case DW_TAG_atomic_type:
   case DW_TAG_unspecified_type: {
 type_sp = ParseTypeModifier(sc, die, attrs);
@@ -676,6 +677,62 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext 
,
   case DW_TAG_volatile_type:
 encoding_data_type = Type::eEncodingIsVolatileUID;
 break;
+  case DW_TAG_LLVM_ptrauth_type: {
+DWARFDIE ptr_die = die.GetReferencedDIE(DW_AT_type);
+// FIXME: Fully resolving the type here may affect performance.
+Type *res_type = dwarf->ResolveType(ptr_die);
+if (!res_type)
+  break;
+attrs.type.Clear();
+encoding_data_type = Type::eEncodingIsUID;
+resolve_state = Type::ResolveState::Full;
+
+// Apply the ptrauth qualifier to the resolved type.
+auto *ptr_type =
+(clang::Type *)res_type->GetForwardCompilerType().GetOpaqueQualType();
+auto getAttr = [&](llvm::dwarf::Attribute Attr, unsigned defaultValue = 0) 
{
+  return die.GetAttributeValueAsUnsigned(Attr, defaultValue);
+};
+const unsigned key = getAttr(DW_AT_LLVM_ptrauth_key);
+const bool addr_disc = getAttr(DW_AT_LLVM_ptrauth_address_discriminated);
+const unsigned extra = getAttr(DW_AT_LLVM_ptrauth_extra_discriminator);
+const bool isapointer = getAttr(DW_AT_LLVM_ptrauth_isa_pointer);
+const bool authenticates_null_values =
+getAttr(DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
+const bool is_restricted_integral = !ptr_type->isPointerType();
+const unsigned authentication_mode_int = getAttr(
+DW_AT_LLVM_ptrauth_authentication_mode,
+static_cast(clang::PointerAuthenticationMode::SignAndAuth));
+clang::PointerAuthenticationMode authentication_mode =
+clang::PointerAuthenticationMode::SignAndAuth;
+if (authentication_mode_int >=
+static_cast(clang::PointerAuthenticationMode::None) &&
+authentication_mode_int <=
+static_cast(
+clang::PointerAuthenticationMode::SignAndAuth)) {
+  authentication_mode = static_cast(
+  authentication_mode_int);
+} else {
+  dwarf->GetObjectFile()->GetModule()->ReportError(
+  "[{0:x16}]: invalid pointer authentication mode method {1:x4}",
+  die.GetOffset(), authentication_mode_int);
+}
+
+// FIXME: Use these variables when PointerAuthQualifier is more complete
+// upstream.
+(void)is_restricted_integral;
+
+clang::Qualifiers qualifiers;
+auto ptr_auth = clang::PointerAuthQualifier::Create(
+key, addr_disc, extra, authentication_mode, isapointer,
+authenticates_null_values);
+qualifiers.setPointerAuth(ptr_auth);
+auto  = m_ast.getASTContext();
+auto qual_type = ctx.getQualifiedType(ptr_type, qualifiers);
+clang_type =
+CompilerType(m_ast.weak_from_this(), qual_type.getAsOpaquePtr());
+break;
+  }
   case DW_TAG_atomic_type:
 encoding_data_type = Type::eEncodingIsAtomicUID;
 break;

>From 8aa1ba0b05362b8960faac1945bb25c68ecb4b98 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Thu, 7 Mar 2024 16:34:09 +0300
Subject: [PATCH 2/4] [PAC][lldb] Use `eEncodingIsLLVMPtrAuthUID` for
 `__ptrauth`-qualified types

---
 lldb/include/lldb/Symbol/Type.h   | 4 +++-
 .../Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp  | 2 +-
 lldb/source/Symbol/Type.cpp   | 8 +++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index acd1a769f13cd6..d55280b58bc4f7 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -401,7 +401,9 @@ class Type : public std::enable_shared_from_this, 
public UserID {
 /// This type is the type whose UID is m_encoding_uid as an atomic type.
 eEncodingIsAtomicUID,
 /// This type is the synthetic type whose UID is m_encoding_uid.
-eEncodingIsSyntheticUID
+eEncodingIsSyntheticUID,
+/// This type is a signed pointer.
+eEncodingIsLLVMPtrAuthUID
   };
 
   enum class ResolveState : unsigned char 

[Lldb-commits] [lldb] [PAC][lldb][Dwarf] Support `__ptrauth`-qualified types in user expressions (PR #84387)

2024-03-07 Thread Daniil Kovalev via lldb-commits

https://github.com/kovdan01 created 
https://github.com/llvm/llvm-project/pull/84387

Depends on #84384 

This adds support for `DW_TAG_LLVM_ptrauth_type` entries corresponding
to explicitly signed types (e.g. free function pointers) in lldb user
expressions. Applies PR https://github.com/apple/llvm-project/pull/8239 from
Apple's downstream and also adds tests and related code.

Co-authored-by: Jonas Devlieghere 


>From 728f5644aebfafd2114e7e47a9b83ef057423997 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 20 Feb 2024 10:57:54 -0800
Subject: [PATCH 1/4] Upstream ptrauth changes to DWARFASTParserClang

---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 57 +++
 1 file changed, 57 insertions(+)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 54d06b1115a229..67fe830e1aa70d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -495,6 +495,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const 
SymbolContext ,
   case DW_TAG_const_type:
   case DW_TAG_restrict_type:
   case DW_TAG_volatile_type:
+  case DW_TAG_LLVM_ptrauth_type:
   case DW_TAG_atomic_type:
   case DW_TAG_unspecified_type: {
 type_sp = ParseTypeModifier(sc, die, attrs);
@@ -676,6 +677,62 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext 
,
   case DW_TAG_volatile_type:
 encoding_data_type = Type::eEncodingIsVolatileUID;
 break;
+  case DW_TAG_LLVM_ptrauth_type: {
+DWARFDIE ptr_die = die.GetReferencedDIE(DW_AT_type);
+// FIXME: Fully resolving the type here may affect performance.
+Type *res_type = dwarf->ResolveType(ptr_die);
+if (!res_type)
+  break;
+attrs.type.Clear();
+encoding_data_type = Type::eEncodingIsUID;
+resolve_state = Type::ResolveState::Full;
+
+// Apply the ptrauth qualifier to the resolved type.
+auto *ptr_type =
+(clang::Type *)res_type->GetForwardCompilerType().GetOpaqueQualType();
+auto getAttr = [&](llvm::dwarf::Attribute Attr, unsigned defaultValue = 0) 
{
+  return die.GetAttributeValueAsUnsigned(Attr, defaultValue);
+};
+const unsigned key = getAttr(DW_AT_LLVM_ptrauth_key);
+const bool addr_disc = getAttr(DW_AT_LLVM_ptrauth_address_discriminated);
+const unsigned extra = getAttr(DW_AT_LLVM_ptrauth_extra_discriminator);
+const bool isapointer = getAttr(DW_AT_LLVM_ptrauth_isa_pointer);
+const bool authenticates_null_values =
+getAttr(DW_AT_LLVM_ptrauth_authenticates_null_values, 0);
+const bool is_restricted_integral = !ptr_type->isPointerType();
+const unsigned authentication_mode_int = getAttr(
+DW_AT_LLVM_ptrauth_authentication_mode,
+static_cast(clang::PointerAuthenticationMode::SignAndAuth));
+clang::PointerAuthenticationMode authentication_mode =
+clang::PointerAuthenticationMode::SignAndAuth;
+if (authentication_mode_int >=
+static_cast(clang::PointerAuthenticationMode::None) &&
+authentication_mode_int <=
+static_cast(
+clang::PointerAuthenticationMode::SignAndAuth)) {
+  authentication_mode = static_cast(
+  authentication_mode_int);
+} else {
+  dwarf->GetObjectFile()->GetModule()->ReportError(
+  "[{0:x16}]: invalid pointer authentication mode method {1:x4}",
+  die.GetOffset(), authentication_mode_int);
+}
+
+// FIXME: Use these variables when PointerAuthQualifier is more complete
+// upstream.
+(void)is_restricted_integral;
+
+clang::Qualifiers qualifiers;
+auto ptr_auth = clang::PointerAuthQualifier::Create(
+key, addr_disc, extra, authentication_mode, isapointer,
+authenticates_null_values);
+qualifiers.setPointerAuth(ptr_auth);
+auto  = m_ast.getASTContext();
+auto qual_type = ctx.getQualifiedType(ptr_type, qualifiers);
+clang_type =
+CompilerType(m_ast.weak_from_this(), qual_type.getAsOpaquePtr());
+break;
+  }
   case DW_TAG_atomic_type:
 encoding_data_type = Type::eEncodingIsAtomicUID;
 break;

>From f2a2cdc1ef3d4722a0b336ec484ef0200a0f1ee9 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Thu, 7 Mar 2024 16:34:09 +0300
Subject: [PATCH 2/4] [PAC][lldb] Use `eEncodingIsLLVMPtrAuthUID` for
 `__ptrauth`-qualified types

---
 lldb/include/lldb/Symbol/Type.h|  4 +++-
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp   |  2 +-
 lldb/source/Symbol/Type.cpp| 18 --
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index acd1a769f13cd6..d55280b58bc4f7 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -401,7 +401,9 @@ class Type : public std::enable_shared_from_this, 
public UserID {
 /// This type is the type whose UID 

[Lldb-commits] [lldb] [lldb][X86] Fix setting target features in ClangExpressionParser (PR #82364)

2024-03-02 Thread Daniil Kovalev via lldb-commits

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


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

2024-02-28 Thread Daniil Kovalev via lldb-commits

kovdan01 wrote:

> Can this code be hit when using an x86 core file?

Thanks for suggestion! I'll try that and notify here if such approach succeeded.

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


[Lldb-commits] [lldb] [lldb][X86] Fix setting target features in ClangExpressionParser (PR #82364)

2024-02-28 Thread Daniil Kovalev via lldb-commits

kovdan01 wrote:

> Would this change be observable by a test?

@adrian-prantl Theoretically, it should be: in 
`ClangExpressionParser::ClangExpressionParser`, we try to hardcode sse and sse2 
for both x86 and x86_64, while in `X86TargetInfo::initFeatureMap`, sse2 
(implying sse) is only hardcoded for x86_64. So, for x86 the observable 
behavior should change.

Unfortunately, I'm not sure where and how this could be tested. I suppose the 
proper place for such a test is somewhere in lldb/unittests/Expression, but I 
don't see existing tests which check similar stuff. Please let me know if I 
miss something. 

@Michael137 would be glad to see your thoughts on this.

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


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

2024-02-28 Thread Daniil Kovalev via lldb-commits

kovdan01 wrote:

> tbh I have no problems with the patch, but I think it's fixing something that 
> I think should be reconsidered altogether, I'm interested to hear more about 
> what the use case looks like that led to this being a problem.

@jasonmolenda The use case is very simple, describing it "as is". I was working 
on AArch64-specific stuff in lldb in downstream and revealed an x86-related 
issue while reading the code (see 
https://github.com/llvm/llvm-project/pull/82364). When working on the latter 
issue, I tried to run a random x86-64 executable inside lldb and got this 
error. It occurs literally on the simplest use case:

1. run `lldb /usr/bin/ls`
2. inside lldb, hit `r` to run
3. get the nullptr dereference described

Yes, it's *that* simple.

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


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

2024-02-22 Thread Daniil Kovalev via lldb-commits

https://github.com/kovdan01 ready_for_review 
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


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

2024-02-22 Thread Daniil Kovalev via lldb-commits

kovdan01 wrote:

Please suggest ideas how this could be tested. It looks like that 
UnwindAssembly unittests is the right place for it - but UnwindAssemblyx86Tests 
cmake target is not built without X86 in `LLVM_TARGETS_TO_BUILD`, which is the 
pre-condition of the issue this PR is fixing.

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


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

2024-02-22 Thread Daniil Kovalev via lldb-commits

https://github.com/kovdan01 created 
https://github.com/llvm/llvm-project/pull/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.

>From 5c9ac5382958d88cbe2b89128957b3a0908c9d88 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Thu, 22 Feb 2024 11:42:44 +0300
Subject: [PATCH] [lldb] Fix nullptr dereference on running x86 binary with
 x86-disabled llvm

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.
---
 .../UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp  | 6 ++
 1 file changed, 6 insertions(+)

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;

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


[Lldb-commits] [lldb] [lldb][X86] Fix setting target features in ClangExpressionParser (PR #82364)

2024-02-20 Thread Daniil Kovalev via lldb-commits

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


[Lldb-commits] [lldb] [lldb][X86] Fix setting target features in ClangExpressionParser (PR #82364)

2024-02-20 Thread Daniil Kovalev via lldb-commits

https://github.com/kovdan01 created 
https://github.com/llvm/llvm-project/pull/82364

Currently, for x86 and x86_64 triples, "+sse" and "+sse2" are appended to 
`Features` vector of `TargetOptions` unconditionally. This vector is later 
reset in `TargetInfo::CreateTargetInfo` and filled using info from 
`FeaturesAsWritten` vector, so previous modifications of the `Features` vector 
have no effect. For x86_64 triple, we append "sse2" unconditionally in 
`X86TargetInfo::initFeatureMap`, so despite the `Features` vector reset, we 
still have the desired sse features enabled. The corresponding code in 
`X86TargetInfo::initFeatureMap` is marked as FIXME, so we should not probably 
rely on it and should set desired features properly in `ClangExpressionParser`.

This patch changes the vector the features are appended to from `Features` to 
`FeaturesAsWritten`. It's not reset later and is used to compute resulting 
`Features` vector.

>From 0b7e2f905687995a710dad6fc8da5bea602e39f1 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Mon, 19 Feb 2024 17:19:36 +0300
Subject: [PATCH] [lldb][X86] Fix settings target features in
 ClangExpressionParser

Currently, for x86 and x86_64 triples, "+sse" and "+sse2" are appended
to `Features` vector of `TargetOptions` unconditionally. This vector is
later reset in `TargetInfo::CreateTargetInfo` and filled using info from
`FeaturesAsWritten` vector, so previous modifications of the `Features`
vector have no effect. For x86_64 triple, we append "sse2"
unconditionally in `X86TargetInfo::initFeatureMap`, so despite the
`Features` vector reset, we still have the desired sse features enabled.
The corresponding code in `X86TargetInfo::initFeatureMap` is marked as
FIXME, so we should not probably rely on it and should set desired
features properly in `ClangExpressionParser`.

This patch changes the vector the features are appended to from
`Features` to `FeaturesAsWritten`. It's not reset later and is used to
compute resulting `Features` vector.
---
 .../Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 574d661e2a215e..822d286cd6c3c4 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -445,8 +445,8 @@ ClangExpressionParser::ClangExpressionParser(
   // Supported subsets of x86
   if (target_machine == llvm::Triple::x86 ||
   target_machine == llvm::Triple::x86_64) {
-m_compiler->getTargetOpts().Features.push_back("+sse");
-m_compiler->getTargetOpts().Features.push_back("+sse2");
+m_compiler->getTargetOpts().FeaturesAsWritten.push_back("+sse");
+m_compiler->getTargetOpts().FeaturesAsWritten.push_back("+sse2");
   }
 
   // Set the target CPU to generate code for. This will be empty for any CPU

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