[Lldb-commits] [PATCH] D98529: Strip pointer authentication codes from aarch64 pc.

2021-03-12 Thread Justin Cohen via Phabricator via lldb-commits
justincohen created this revision.
Herald added subscribers: omjavaid, danielkiss, kristof.beyls.
justincohen requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98529

Files:
  lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
  lldb/source/Plugins/ABI/AArch64/ABIAArch64.h


Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
===
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
@@ -24,6 +24,8 @@
 
   uint32_t GetGenericNum(llvm::StringRef name) override;
 
+  lldb::addr_t FixCodeAddress(lldb::addr_t pc) override;
+
   using lldb_private::MCBasedABI::MCBasedABI;
 };
 #endif
Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
===
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
@@ -56,3 +56,9 @@
   .Case("x7", LLDB_REGNUM_GENERIC_ARG8)
   .Default(LLDB_INVALID_REGNUM);
 }
+
+lldb::addr_t ABIAArch64::FixCodeAddress(lldb::addr_t pc) {
+  // Short term workaround to remove any pointer authentication codes. This
+  // should be removed once full PAC support is added.
+  return pc & 0x000F;
+}


Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
===
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
@@ -24,6 +24,8 @@
 
   uint32_t GetGenericNum(llvm::StringRef name) override;
 
+  lldb::addr_t FixCodeAddress(lldb::addr_t pc) override;
+
   using lldb_private::MCBasedABI::MCBasedABI;
 };
 #endif
Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
===
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
@@ -56,3 +56,9 @@
   .Case("x7", LLDB_REGNUM_GENERIC_ARG8)
   .Default(LLDB_INVALID_REGNUM);
 }
+
+lldb::addr_t ABIAArch64::FixCodeAddress(lldb::addr_t pc) {
+  // Short term workaround to remove any pointer authentication codes. This
+  // should be removed once full PAC support is added.
+  return pc & 0x000F;
+}
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D98529: [lldb] Strip pointer authentication codes from aarch64 pc.

2021-03-12 Thread Justin Cohen via Phabricator via lldb-commits
justincohen updated this revision to Diff 330331.
justincohen added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98529

Files:
  lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
  lldb/source/Plugins/ABI/AArch64/ABIAArch64.h


Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
===
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
@@ -24,6 +24,8 @@
 
   uint32_t GetGenericNum(llvm::StringRef name) override;
 
+  lldb::addr_t FixCodeAddress(lldb::addr_t pc) override;
+
   using lldb_private::MCBasedABI::MCBasedABI;
 };
 #endif
Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
===
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
@@ -56,3 +56,9 @@
   .Case("x7", LLDB_REGNUM_GENERIC_ARG8)
   .Default(LLDB_INVALID_REGNUM);
 }
+
+lldb::addr_t ABIAArch64::FixCodeAddress(lldb::addr_t pc) {
+  // Short term workaround to remove any pointer authentication codes. This
+  // should be removed once full PAC support is added.
+  return pc & 0x000F;
+}


Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
===
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
@@ -24,6 +24,8 @@
 
   uint32_t GetGenericNum(llvm::StringRef name) override;
 
+  lldb::addr_t FixCodeAddress(lldb::addr_t pc) override;
+
   using lldb_private::MCBasedABI::MCBasedABI;
 };
 #endif
Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
===
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
@@ -56,3 +56,9 @@
   .Case("x7", LLDB_REGNUM_GENERIC_ARG8)
   .Default(LLDB_INVALID_REGNUM);
 }
+
+lldb::addr_t ABIAArch64::FixCodeAddress(lldb::addr_t pc) {
+  // Short term workaround to remove any pointer authentication codes. This
+  // should be removed once full PAC support is added.
+  return pc & 0x000F;
+}
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D98529: [lldb] Strip pointer authentication codes from aarch64 pc.

2021-03-15 Thread Justin Cohen via Phabricator via lldb-commits
justincohen updated this revision to Diff 330665.
justincohen added a comment.

Move logic to ABIMacOSX_arm64.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98529

Files:
  lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
  lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h


Index: lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
===
--- lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
+++ lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
@@ -62,6 +62,12 @@
 return true;
   }
 
+  lldb::addr_t FixCodeAddress(lldb::addr_t pc) override {
+// Short term workaround to remove any pointer authentication codes. This
+// should be removed once full PAC support is added.
+return pc & 0x000F;
+  }
+
   // Static Functions
 
   static void Initialize();
Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
===
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
@@ -24,8 +24,6 @@
 
   uint32_t GetGenericNum(llvm::StringRef name) override;
 
-  lldb::addr_t FixCodeAddress(lldb::addr_t pc) override;
-
   using lldb_private::MCBasedABI::MCBasedABI;
 };
 #endif
Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
===
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
@@ -56,9 +56,3 @@
   .Case("x7", LLDB_REGNUM_GENERIC_ARG8)
   .Default(LLDB_INVALID_REGNUM);
 }
-
-lldb::addr_t ABIAArch64::FixCodeAddress(lldb::addr_t pc) {
-  // Short term workaround to remove any pointer authentication codes. This
-  // should be removed once full PAC support is added.
-  return pc & 0x000F;
-}


Index: lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
===
--- lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
+++ lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
@@ -62,6 +62,12 @@
 return true;
   }
 
+  lldb::addr_t FixCodeAddress(lldb::addr_t pc) override {
+// Short term workaround to remove any pointer authentication codes. This
+// should be removed once full PAC support is added.
+return pc & 0x000F;
+  }
+
   // Static Functions
 
   static void Initialize();
Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
===
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
@@ -24,8 +24,6 @@
 
   uint32_t GetGenericNum(llvm::StringRef name) override;
 
-  lldb::addr_t FixCodeAddress(lldb::addr_t pc) override;
-
   using lldb_private::MCBasedABI::MCBasedABI;
 };
 #endif
Index: lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
===
--- lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
+++ lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
@@ -56,9 +56,3 @@
   .Case("x7", LLDB_REGNUM_GENERIC_ARG8)
   .Default(LLDB_INVALID_REGNUM);
 }
-
-lldb::addr_t ABIAArch64::FixCodeAddress(lldb::addr_t pc) {
-  // Short term workaround to remove any pointer authentication codes. This
-  // should be removed once full PAC support is added.
-  return pc & 0x000F;
-}
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D98529: [lldb] Strip pointer authentication codes from aarch64 pc.

2021-03-15 Thread Justin Cohen via Phabricator via lldb-commits
justincohen added inline comments.



Comment at: lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp:63
+  // should be removed once full PAC support is added.
+  return pc & 0x000F;
+}

DavidSpickett wrote:
> omjavaid wrote:
> > How did you come up with this 36bit mask for PC reg I think this mask is 
> > not appropriate for Linux virtual address space which is 52 or 48 bits in 
> > length.
> > 
> > 
> If it's any help I looked for this too and found 
> `aarch64/functions/pac/calcbottompacbit/CalculateBottomPACBit` pseudocode in 
> the armarm. This is used by the PAC strip instructions. (though it is a bit 
> mind bending to read)
I'll move this to `lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h` to not 
impact Linux.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98529

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


[Lldb-commits] [PATCH] D98529: [lldb] Strip pointer authentication codes from aarch64 pc.

2021-03-15 Thread Justin Cohen via Phabricator via lldb-commits
justincohen updated this revision to Diff 330667.
justincohen added a comment.

squash


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98529

Files:
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h


Index: lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
===
--- lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
+++ lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
@@ -62,6 +62,12 @@
 return true;
   }
 
+  lldb::addr_t FixCodeAddress(lldb::addr_t pc) override {
+// Short term workaround to remove any pointer authentication codes. This
+// should be removed once full PAC support is added.
+return pc & 0x000F;
+  }
+
   // Static Functions
 
   static void Initialize();


Index: lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
===
--- lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
+++ lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
@@ -62,6 +62,12 @@
 return true;
   }
 
+  lldb::addr_t FixCodeAddress(lldb::addr_t pc) override {
+// Short term workaround to remove any pointer authentication codes. This
+// should be removed once full PAC support is added.
+return pc & 0x000F;
+  }
+
   // Static Functions
 
   static void Initialize();
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D98529: [lldb] Strip pointer authentication codes from aarch64 pc.

2021-03-16 Thread Justin Cohen via Phabricator via lldb-commits
justincohen added a comment.

How does this work for a core dump?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98529

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


[Lldb-commits] [PATCH] D98529: [lldb] Strip pointer authentication codes from aarch64 pc.

2021-03-16 Thread Justin Cohen via Phabricator via lldb-commits
justincohen added a comment.

Breakpad/Crashpad are not transporting mach-o core files, they are using 
minidumps. minidumps don't contain any indication of the number of bits in the 
address. Apple Xcode lldb is still able to work with these minidumps correctly, 
while trunk lldb is not. How is it able to do this even when the dump file 
doesn't contain “addrable bits” or equivalent?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98529

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


[Lldb-commits] [PATCH] D98529: [lldb] Strip pointer authentication codes from aarch64 pc.

2021-03-17 Thread Justin Cohen via Phabricator via lldb-commits
justincohen added a comment.

In the meantime, I'll look into adding something to the Crashpad minidump 
format to store an `addrable bits` mask, although I'm not clear how to grab 
this in userspace.  Should `sysctl machdep.virtual_address_size` work on iOS?  
Can I grab TCR_ELx.T0SZ directly?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98529

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


[Lldb-commits] [PATCH] D98529: [lldb] Strip pointer authentication codes from aarch64 pc.

2021-03-17 Thread Justin Cohen via Phabricator via lldb-commits
justincohen added a comment.

  uint32_t addressing_bits;
  size_t len = sizeof (uint32_t);
  ret = sysctlbyname("machdep.virtual_address_size", &addressing_bits, &len, 
NULL, 0);

returns ret == -1 on an iOS 14.4 device.  I do see this work on an m1 mac.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98529

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


[Lldb-commits] [PATCH] D98886: Strip pointer authentication codes from MacOSX arc pc.

2021-03-18 Thread Justin Cohen via Phabricator via lldb-commits
justincohen created this revision.
justincohen requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98886

Files:
  lldb/include/lldb/Target/Process.h
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
  lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
  lldb/source/Plugins/Process/minidump/MinidumpParser.h
  lldb/source/Plugins/Process/minidump/MinidumpTypes.h
  lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
  lldb/source/Target/Process.cpp
  lldb/source/Target/TargetProperties.td
  llvm/include/llvm/BinaryFormat/MinidumpConstants.def

Index: llvm/include/llvm/BinaryFormat/MinidumpConstants.def
===
--- llvm/include/llvm/BinaryFormat/MinidumpConstants.def
+++ llvm/include/llvm/BinaryFormat/MinidumpConstants.def
@@ -56,6 +56,8 @@
 HANDLE_MDMP_STREAM_TYPE(0x0014, JavascriptData)
 HANDLE_MDMP_STREAM_TYPE(0x0015, SystemMemoryInfo)
 HANDLE_MDMP_STREAM_TYPE(0x0016, ProcessVMCounters)
+// Crashpad extension types.  0x4350 = "CP"
+HANDLE_MDMP_STREAM_TYPE(0x4351, CrashpadInfo)
 // Breakpad extension types.  0x4767 = "Gg"
 HANDLE_MDMP_STREAM_TYPE(0x47670001, BreakpadInfo)
 HANDLE_MDMP_STREAM_TYPE(0x47670002, AssertionInfo)
Index: lldb/source/Target/TargetProperties.td
===
--- lldb/source/Target/TargetProperties.td
+++ lldb/source/Target/TargetProperties.td
@@ -199,6 +199,9 @@
 Global,
 DefaultTrue,
 Desc<"If true, errors in expression evaluation will unwind the stack back to the state before the call.">;
+  def PointerAuthenticationAddressMask: Property<"pointer-authentication-address-mask", "UInt64">,
+DefaultUnsignedValue<0>,
+Desc<"The mask to strip pointer authentication codes. `AND` this mask with the pointer to recover an address. The default value of 0 means unspecified.">;
   def PythonOSPluginPath: Property<"python-os-plugin-path", "FileSpec">,
 DefaultUnsignedValue<1>,
 Desc<"A path to a python OS plug-in module file that contains a OperatingSystemPlugIn class.">;
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -195,6 +195,16 @@
   m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, args);
 }
 
+uint64_t ProcessProperties::GetPointerAuthenticationAddressMask() const {
+  const uint32_t idx = ePropertyPointerAuthenticationAddressMask;
+  return m_collection_sp->GetPropertyAtIndexAsUInt64(nullptr, idx, g_process_properties[idx].default_uint_value);
+}
+
+void ProcessProperties::SetPointerAuthenticationAddressMask(const uint64_t mask) {
+  const uint32_t idx = ePropertyPointerAuthenticationAddressMask;
+  m_collection_sp->SetPropertyAtIndexAsUInt64(nullptr, idx, mask);
+}
+
 FileSpec ProcessProperties::GetPythonOSPluginPath() const {
   const uint32_t idx = ePropertyPythonOSPluginPath;
   return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx);
Index: lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
===
--- lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -302,6 +302,11 @@
   }
   SetID(pid.getValue());
 
+  llvm::Optional mask = m_minidump_parser->GetPointerAuthenticationAddressMask();
+  if (mask) {
+SetPointerAuthenticationAddressMask(mask.getValue());
+  }
+
   return error;
 }
 
Index: lldb/source/Plugins/Process/minidump/MinidumpTypes.h
===
--- lldb/source/Plugins/Process/minidump/MinidumpTypes.h
+++ lldb/source/Plugins/Process/minidump/MinidumpTypes.h
@@ -102,6 +102,24 @@
   LinuxProcStatus() = default;
 };
 
+struct GUID {
+  llvm::support::ulittle32_t data1;
+  llvm::support::ulittle16_t data2;
+  llvm::support::ulittle16_t data3;
+  uint8_t data4[8];
+};
+static_assert(sizeof(GUID) == 16, "");
+
+struct CrashpadInfo {
+  uint32_t version;
+  GUID report_id;
+  GUID client_id;
+  LocationDescriptor simple_annotations;
+  LocationDescriptor module_list;
+  uint64_t pointer_authentication_address_mask;
+};
+static_assert(sizeof(CrashpadInfo) == 64, "");
+
 } // namespace minidump
 } // namespace lldb_private
 #endif // LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H
Index: lldb/source/Plugins/Process/minidump/MinidumpParser.h
===
--- lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -71,6 +71,7 @@
   const MinidumpMiscInfo *GetMiscInfo();
 
   llvm::Optional GetLinuxProcStatus();
+  llvm::Optional GetPointerAuthenticationAddressMask();
 
   llvm::Optional 

[Lldb-commits] [PATCH] D98886: Strip pointer authentication codes from MacOSX arc pc.

2021-03-22 Thread Justin Cohen via Phabricator via lldb-commits
justincohen updated this revision to Diff 332374.
justincohen edited the summary of this revision.
justincohen added a comment.

Fix length of crashpad structure / use ulittleXX


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98886

Files:
  lldb/include/lldb/Target/Process.h
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
  lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
  lldb/source/Plugins/Process/minidump/MinidumpParser.h
  lldb/source/Plugins/Process/minidump/MinidumpTypes.h
  lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
  lldb/source/Target/Process.cpp
  lldb/source/Target/TargetProperties.td
  llvm/include/llvm/BinaryFormat/MinidumpConstants.def

Index: llvm/include/llvm/BinaryFormat/MinidumpConstants.def
===
--- llvm/include/llvm/BinaryFormat/MinidumpConstants.def
+++ llvm/include/llvm/BinaryFormat/MinidumpConstants.def
@@ -56,6 +56,8 @@
 HANDLE_MDMP_STREAM_TYPE(0x0014, JavascriptData)
 HANDLE_MDMP_STREAM_TYPE(0x0015, SystemMemoryInfo)
 HANDLE_MDMP_STREAM_TYPE(0x0016, ProcessVMCounters)
+// Crashpad extension types.  0x4350 = "CP"
+HANDLE_MDMP_STREAM_TYPE(0x4351, CrashpadInfo)
 // Breakpad extension types.  0x4767 = "Gg"
 HANDLE_MDMP_STREAM_TYPE(0x47670001, BreakpadInfo)
 HANDLE_MDMP_STREAM_TYPE(0x47670002, AssertionInfo)
Index: lldb/source/Target/TargetProperties.td
===
--- lldb/source/Target/TargetProperties.td
+++ lldb/source/Target/TargetProperties.td
@@ -199,6 +199,9 @@
 Global,
 DefaultTrue,
 Desc<"If true, errors in expression evaluation will unwind the stack back to the state before the call.">;
+  def PointerAuthenticationAddressMask: Property<"pointer-authentication-address-mask", "UInt64">,
+DefaultUnsignedValue<0>,
+Desc<"The mask to strip pointer authentication codes. `AND` this mask with the pointer to recover an address. The default value of 0 means unspecified.">;
   def PythonOSPluginPath: Property<"python-os-plugin-path", "FileSpec">,
 DefaultUnsignedValue<1>,
 Desc<"A path to a python OS plug-in module file that contains a OperatingSystemPlugIn class.">;
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -195,6 +195,18 @@
   m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, args);
 }
 
+uint64_t ProcessProperties::GetPointerAuthenticationAddressMask() const {
+  const uint32_t idx = ePropertyPointerAuthenticationAddressMask;
+  return m_collection_sp->GetPropertyAtIndexAsUInt64(
+  nullptr, idx, g_process_properties[idx].default_uint_value);
+}
+
+void ProcessProperties::SetPointerAuthenticationAddressMask(
+const uint64_t mask) {
+  const uint32_t idx = ePropertyPointerAuthenticationAddressMask;
+  m_collection_sp->SetPropertyAtIndexAsUInt64(nullptr, idx, mask);
+}
+
 FileSpec ProcessProperties::GetPythonOSPluginPath() const {
   const uint32_t idx = ePropertyPythonOSPluginPath;
   return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx);
Index: lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
===
--- lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -302,6 +302,12 @@
   }
   SetID(pid.getValue());
 
+  llvm::Optional mask =
+  m_minidump_parser->GetPointerAuthenticationAddressMask();
+  if (mask) {
+SetPointerAuthenticationAddressMask(mask.getValue());
+  }
+
   return error;
 }
 
Index: lldb/source/Plugins/Process/minidump/MinidumpTypes.h
===
--- lldb/source/Plugins/Process/minidump/MinidumpTypes.h
+++ lldb/source/Plugins/Process/minidump/MinidumpTypes.h
@@ -102,6 +102,24 @@
   LinuxProcStatus() = default;
 };
 
+struct GUID {
+  llvm::support::ulittle32_t data1;
+  llvm::support::ulittle16_t data2;
+  llvm::support::ulittle16_t data3;
+  uint8_t data4[8];
+};
+static_assert(sizeof(GUID) == 16, "");
+
+struct CrashpadInfo {
+  llvm::support::ulittle32_t version;
+  GUID report_id;
+  GUID client_id;
+  LocationDescriptor simple_annotations;
+  LocationDescriptor module_list;
+  llvm::support::ulittle64_t pointer_authentication_address_mask;
+};
+static_assert(sizeof(CrashpadInfo) == 60, "");
+
 } // namespace minidump
 } // namespace lldb_private
 #endif // LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H
Index: lldb/source/Plugins/Process/minidump/MinidumpParser.h
===
--- lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -71,6 +71,7 @@
   const MinidumpMiscInfo *Get

[Lldb-commits] [PATCH] D98529: [lldb] Strip pointer authentication codes from aarch64 pc.

2021-03-25 Thread Justin Cohen via Phabricator via lldb-commits
justincohen added a comment.

> OK we may need to retain the manual setting when I upstream this, instead of 
> going with the pure Process-maintained value determined dynamically by gdb 
> packet or corefile metadata.  If this is something you need for your own 
> FixCodeAddress prelim patch, I can upstream the 
> target.process.virtual-addressable-bits setting (I think the name is fine, 
> even once Process can determine this dynamically).  We'll need to decide at 
> some point what the correct behavior is when they conflict, but if only one 
> is set the choice is straightforward.

Were you able to confirm if sysctlbyname "machdep.virtual_address_size" works 
on iOS? I'm currently hard coding this information in minidump creation, as 
it's failing for me.

I uploaded https://reviews.llvm.org/D98886 which reads a mask from a minidump 
and sets target.process.pointer-authentication-address-mask.  Would you 
consider that (as I assume this is going to be converted into a mask 
regardless, and I if there's a possibility for future non-contiguous bits)

What do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98529

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


[Lldb-commits] [PATCH] D98529: [lldb] Strip pointer authentication codes from aarch64 pc.

2021-03-25 Thread Justin Cohen via Phabricator via lldb-commits
justincohen added a comment.



> Clearing PAC bits is a little more complicated than just clearing the bits, 
> though.  Bit 55 tells us whether the high bits are all 0's or all 1's (on 
> Darwin, in EL0 processes they're all 0's, in EL1, all 1's).  If we had a 
> setting to provide a mask instead of the number of bits that are valid in 
> addressing, that might lead someone to try to use it for a different purpose. 
>  Trying to imagine a scenario like this, maybe someone could know that a 
> certain range of the address space isn't used for a certain type of pointer, 
> and that they could reuse those bits as a Top Byte Ignore kind of thing, but 
> the generated code would need to clear/set those bits before dereferencing, 
> or we'd need a CPU with that kind of capability.  Maybe there could be 
> examples of this today like the thumb bit on armv7, where the 0th bit on 
> something with alignment restrictions can be used to carry metadata, although 
> I can't think of anything like that on AArch/x86_64 (the only two targets I 
> can really remember well these days).

Copying over a comment from pcc@ on the minidump change here: 
https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2773358/5//COMMIT_MSG#15
 :
 > On Linux, the mask that you get from NT_ARM_PAC_MASK specifies which bits 
 > need to be cleared from the pointer. So to use the mask, you AND with the 
 > inverse.
 > This also has the advantage that 0 is not a special case, since you can AND 
 > with its inverse and get the same pointer back.

What if we invert the mask, and do something like instead?
`(ptr & (1ULL << 55)) ? (ptr | mask) : (ptr & ~mask);`

This should be very similar to the pseudocode here: 
https://webcache.googleusercontent.com/search?q=cache:3fCUm601caMJ:https://developer.arm.com/ja/docs/ddi0596/latest/shared-pseudocode-functions/aarch64-functionspac-pseudocode+&cd=2&hl=en&ct=clnk&gl=us


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98529

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


[Lldb-commits] [PATCH] D98886: Pass pointer authentication code mask from minidump and use to strip pac from pc.

2021-03-26 Thread Justin Cohen via Phabricator via lldb-commits
justincohen updated this revision to Diff 333601.
justincohen added a comment.

Inverted mask.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98886

Files:
  lldb/include/lldb/Target/Process.h
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
  lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
  lldb/source/Plugins/Process/minidump/MinidumpParser.h
  lldb/source/Plugins/Process/minidump/MinidumpTypes.h
  lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
  lldb/source/Target/Process.cpp
  lldb/source/Target/TargetProperties.td
  llvm/include/llvm/BinaryFormat/MinidumpConstants.def

Index: llvm/include/llvm/BinaryFormat/MinidumpConstants.def
===
--- llvm/include/llvm/BinaryFormat/MinidumpConstants.def
+++ llvm/include/llvm/BinaryFormat/MinidumpConstants.def
@@ -56,6 +56,8 @@
 HANDLE_MDMP_STREAM_TYPE(0x0014, JavascriptData)
 HANDLE_MDMP_STREAM_TYPE(0x0015, SystemMemoryInfo)
 HANDLE_MDMP_STREAM_TYPE(0x0016, ProcessVMCounters)
+// Crashpad extension types.  0x4350 = "CP"
+HANDLE_MDMP_STREAM_TYPE(0x4351, CrashpadInfo)
 // Breakpad extension types.  0x4767 = "Gg"
 HANDLE_MDMP_STREAM_TYPE(0x47670001, BreakpadInfo)
 HANDLE_MDMP_STREAM_TYPE(0x47670002, AssertionInfo)
Index: lldb/source/Target/TargetProperties.td
===
--- lldb/source/Target/TargetProperties.td
+++ lldb/source/Target/TargetProperties.td
@@ -199,6 +199,9 @@
 Global,
 DefaultTrue,
 Desc<"If true, errors in expression evaluation will unwind the stack back to the state before the call.">;
+  def PointerAuthenticationAddressMask: Property<"pointer-authentication-address-mask", "UInt64">,
+DefaultUnsignedValue<0>,
+Desc<"Specifies which bits need to be cleared from the pointer.  To use the mask, AND with the inverse.">;
   def PythonOSPluginPath: Property<"python-os-plugin-path", "FileSpec">,
 DefaultUnsignedValue<1>,
 Desc<"A path to a python OS plug-in module file that contains a OperatingSystemPlugIn class.">;
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -195,6 +195,18 @@
   m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, args);
 }
 
+uint64_t ProcessProperties::GetPointerAuthenticationAddressMask() const {
+  const uint32_t idx = ePropertyPointerAuthenticationAddressMask;
+  return m_collection_sp->GetPropertyAtIndexAsUInt64(
+  nullptr, idx, g_process_properties[idx].default_uint_value);
+}
+
+void ProcessProperties::SetPointerAuthenticationAddressMask(
+const uint64_t mask) {
+  const uint32_t idx = ePropertyPointerAuthenticationAddressMask;
+  m_collection_sp->SetPropertyAtIndexAsUInt64(nullptr, idx, mask);
+}
+
 FileSpec ProcessProperties::GetPythonOSPluginPath() const {
   const uint32_t idx = ePropertyPythonOSPluginPath;
   return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx);
Index: lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
===
--- lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -302,6 +302,12 @@
   }
   SetID(pid.getValue());
 
+  llvm::Optional mask =
+  m_minidump_parser->GetPointerAuthenticationAddressMask();
+  if (mask) {
+SetPointerAuthenticationAddressMask(mask.getValue());
+  }
+
   return error;
 }
 
Index: lldb/source/Plugins/Process/minidump/MinidumpTypes.h
===
--- lldb/source/Plugins/Process/minidump/MinidumpTypes.h
+++ lldb/source/Plugins/Process/minidump/MinidumpTypes.h
@@ -102,6 +102,24 @@
   LinuxProcStatus() = default;
 };
 
+struct GUID {
+  llvm::support::ulittle32_t data1;
+  llvm::support::ulittle16_t data2;
+  llvm::support::ulittle16_t data3;
+  uint8_t data4[8];
+};
+static_assert(sizeof(GUID) == 16, "");
+
+struct CrashpadInfo {
+  llvm::support::ulittle32_t version;
+  GUID report_id;
+  GUID client_id;
+  LocationDescriptor simple_annotations;
+  LocationDescriptor module_list;
+  llvm::support::ulittle64_t pointer_authentication_address_mask;
+};
+static_assert(sizeof(CrashpadInfo) == 60, "");
+
 } // namespace minidump
 } // namespace lldb_private
 #endif // LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H
Index: lldb/source/Plugins/Process/minidump/MinidumpParser.h
===
--- lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -71,6 +71,7 @@
   const MinidumpMiscInfo *GetMiscInfo();
 
   llvm::Optional GetLinuxProcStatus();
+  llvm::Optional GetPointerAuthenticationAddressMask();
 
   llvm::Optional 

[Lldb-commits] [PATCH] D98886: Pass pointer authentication code mask from minidump and use to strip pac from pc.

2021-03-26 Thread Justin Cohen via Phabricator via lldb-commits
justincohen updated this revision to Diff 333608.
justincohen added a comment.

Check CrashpadInfo version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98886

Files:
  lldb/include/lldb/Target/Process.h
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.h
  lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
  lldb/source/Plugins/Process/minidump/MinidumpParser.h
  lldb/source/Plugins/Process/minidump/MinidumpTypes.h
  lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
  lldb/source/Target/Process.cpp
  lldb/source/Target/TargetProperties.td
  llvm/include/llvm/BinaryFormat/MinidumpConstants.def

Index: llvm/include/llvm/BinaryFormat/MinidumpConstants.def
===
--- llvm/include/llvm/BinaryFormat/MinidumpConstants.def
+++ llvm/include/llvm/BinaryFormat/MinidumpConstants.def
@@ -56,6 +56,8 @@
 HANDLE_MDMP_STREAM_TYPE(0x0014, JavascriptData)
 HANDLE_MDMP_STREAM_TYPE(0x0015, SystemMemoryInfo)
 HANDLE_MDMP_STREAM_TYPE(0x0016, ProcessVMCounters)
+// Crashpad extension types.  0x4350 = "CP"
+HANDLE_MDMP_STREAM_TYPE(0x4351, CrashpadInfo)
 // Breakpad extension types.  0x4767 = "Gg"
 HANDLE_MDMP_STREAM_TYPE(0x47670001, BreakpadInfo)
 HANDLE_MDMP_STREAM_TYPE(0x47670002, AssertionInfo)
Index: lldb/source/Target/TargetProperties.td
===
--- lldb/source/Target/TargetProperties.td
+++ lldb/source/Target/TargetProperties.td
@@ -199,6 +199,9 @@
 Global,
 DefaultTrue,
 Desc<"If true, errors in expression evaluation will unwind the stack back to the state before the call.">;
+  def PointerAuthenticationAddressMask: Property<"pointer-authentication-address-mask", "UInt64">,
+DefaultUnsignedValue<0>,
+Desc<"Specifies which bits need to be cleared from the pointer.  To use the mask, AND with the inverse.">;
   def PythonOSPluginPath: Property<"python-os-plugin-path", "FileSpec">,
 DefaultUnsignedValue<1>,
 Desc<"A path to a python OS plug-in module file that contains a OperatingSystemPlugIn class.">;
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -195,6 +195,18 @@
   m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, args);
 }
 
+uint64_t ProcessProperties::GetPointerAuthenticationAddressMask() const {
+  const uint32_t idx = ePropertyPointerAuthenticationAddressMask;
+  return m_collection_sp->GetPropertyAtIndexAsUInt64(
+  nullptr, idx, g_process_properties[idx].default_uint_value);
+}
+
+void ProcessProperties::SetPointerAuthenticationAddressMask(
+const uint64_t mask) {
+  const uint32_t idx = ePropertyPointerAuthenticationAddressMask;
+  m_collection_sp->SetPropertyAtIndexAsUInt64(nullptr, idx, mask);
+}
+
 FileSpec ProcessProperties::GetPythonOSPluginPath() const {
   const uint32_t idx = ePropertyPythonOSPluginPath;
   return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx);
Index: lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
===
--- lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
+++ lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
@@ -302,6 +302,12 @@
   }
   SetID(pid.getValue());
 
+  llvm::Optional mask =
+  m_minidump_parser->GetPointerAuthenticationAddressMask();
+  if (mask) {
+SetPointerAuthenticationAddressMask(mask.getValue());
+  }
+
   return error;
 }
 
Index: lldb/source/Plugins/Process/minidump/MinidumpTypes.h
===
--- lldb/source/Plugins/Process/minidump/MinidumpTypes.h
+++ lldb/source/Plugins/Process/minidump/MinidumpTypes.h
@@ -102,6 +102,24 @@
   LinuxProcStatus() = default;
 };
 
+struct GUID {
+  llvm::support::ulittle32_t data1;
+  llvm::support::ulittle16_t data2;
+  llvm::support::ulittle16_t data3;
+  uint8_t data4[8];
+};
+static_assert(sizeof(GUID) == 16, "");
+
+struct CrashpadInfo {
+  llvm::support::ulittle32_t version;
+  GUID report_id;
+  GUID client_id;
+  LocationDescriptor simple_annotations;
+  LocationDescriptor module_list;
+  llvm::support::ulittle64_t pointer_authentication_address_mask;
+};
+static_assert(sizeof(CrashpadInfo) == 60, "");
+
 } // namespace minidump
 } // namespace lldb_private
 #endif // LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_MINIDUMPTYPES_H
Index: lldb/source/Plugins/Process/minidump/MinidumpParser.h
===
--- lldb/source/Plugins/Process/minidump/MinidumpParser.h
+++ lldb/source/Plugins/Process/minidump/MinidumpParser.h
@@ -71,6 +71,7 @@
   const MinidumpMiscInfo *GetMiscInfo();
 
   llvm::Optional GetLinuxProcStatus();
+  llvm::Optional GetPointerAuthenticationAddressMask();
 
   ll

[Lldb-commits] [PATCH] D98886: Pass pointer authentication code mask from minidump and use to strip pac from pc.

2021-03-26 Thread Justin Cohen via Phabricator via lldb-commits
justincohen marked 2 inline comments as done.
justincohen added inline comments.



Comment at: lldb/source/Plugins/Process/minidump/MinidumpTypes.h:113
+
+struct CrashpadInfo {
+  llvm::support::ulittle32_t version;

markmentovai wrote:
> Ensure alignment is compatible with what Crashpad uses.
Confirmed manually.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98886

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


[Lldb-commits] [PATCH] D98529: [lldb] Strip pointer authentication codes from aarch64 pc.

2021-03-29 Thread Justin Cohen via Phabricator via lldb-commits
justincohen added a comment.

Can we move comments over to --> https://reviews.llvm.org/D98886, which has 
these changes implemented?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98529

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


[Lldb-commits] [PATCH] D99944: [LLDB] AArch64 PAC elf-core stack unwinder support

2021-04-12 Thread Justin Cohen via Phabricator via lldb-commits
justincohen added a comment.

In D99944#2684280 , @jasonmolenda 
wrote:

> Omair, Justin, what do you think here?  I don't think it's especially hard to 
> accept this in terms of # of bits OR a mask, and we should use the more 
> general internal rep in lldb.  Another alternative would be "the mask should 
> be converted to the # of bits in addressing and stored in Process in those 
> terms".

From a minidump/crashpad perspective, we are fine with either approach.  We 
plan to a use a mask within the minidump format, but we can convert it to # of 
bits as necessary.


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

https://reviews.llvm.org/D99944

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


[Lldb-commits] [PATCH] D100515: [lldb] Add GetCodeAddressMask and GetDataAddressMask to Process

2021-04-15 Thread Justin Cohen via Phabricator via lldb-commits
justincohen accepted this revision.
justincohen added a comment.
This revision is now accepted and ready to land.

> On Darwin, we use the same number of bits for both code and data, but given 
> the way ptrace() behaves on Linux, I'm guessing this may not be the case 
> everywhere.  Should we store both masks, and add FixCodeAddress + 
> FixDataAddress methods in the ABI's, Justin?  What do you think?

This all LGTM!  I don't have a strong opinion on naming.  My understanding is 
both code and data will be necessary in case TBID0 is set on Linux.


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

https://reviews.llvm.org/D100515

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


[Lldb-commits] [PATCH] D100515: [lldb] Add GetCodeAddressMask and GetDataAddressMask to Process

2021-04-16 Thread Justin Cohen via Phabricator via lldb-commits
justincohen added a comment.

Out of curiosity: Typically should one be able to set 
target.process.virtual-addressable-bits after the target has been created?  Or 
is it expected that users will need to run in the following order only:

  settings set target.process.virtual-addressable-bits ...
  target create -c 

Setting virtual-addressable-bits won't do anythin after the target has been 
created (and perhaps that is working as intended?)


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

https://reviews.llvm.org/D100515

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