[Lldb-commits] [PATCH] D115431: Set a default number of addressing bits for Darwin arm64 systems

2021-12-09 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda created this revision.
jasonmolenda added a reviewer: JDevlieghere.
jasonmolenda added a project: LLDB.
Herald added subscribers: omjavaid, kristof.beyls.
jasonmolenda requested review of this revision.

For ARMv8.3 pointer auth signing, lldb needs to know how many bits are valid 
for addressing, and strip the high bits off of addresses before looking them 
up.  During the initial bringup, we didn't have dynamic ways of getting these 
values so we hardcoded a default addressing mask in lldb, and there are still 
some cases where we need to support this, where we still don't have the value 
dynamically declared.

There are three parts to this patch, all needed to construct a test.  The most 
important part is that when I print ptrauth values, I always print the actual 
uint64_t with ptrauth bits included, then I strip the bits and see if it 
resolves to an address that lldb knows about.  If so, then I use the normal 
formatter.  For this test case, I needed this behavior in our function pointer 
formatter.  Our normal output might look like

(lldb) p fmain
(int (*)(...)) $0 = 0x00013f90 (a.out`main at main.c:3)

and with an ARMv8.3 ABI with ptrauth bits, you might see

(lldb) p fmain
(int (*)(...)) $0 = 0xe46bff013f8c (0xe46bff013f8c)

which is not helpful.  So this patch does

(lldb) p fmain
(int (*)(...)) $0 = 0xe46bff013f8c (actual=0x00013f8c a.out`main at 
main.c:3)

I never want to hide the ptrauth bit reality from the user - because they may 
be debugging a problem with ptrauth signing itself.  The three parts of the 
patch:

1. ABIMacOSX_arm64::FixAddress changed so if no mask is specified, uses the 
default mask.

2. ObjectFileMachO::GetAllArchSpecs when reading a Mach-O binary, we were 
previously clearing the Vendor from the Triple that we create for the binary 
(so it would be arm64e--).  This loses information - realistically, any binary 
in a Mach-O container is most likely following the Darwin ABIs and I want to 
retain the vendor so we can select the correct ABI instead of grabbing any 
random arm64 ABI.

3. ArchSpec::SetArchitecture - explicitly set the vendor to Apple when we have 
a Mach-O architecture.

4. formatters::CXXFunctionPointerSummaryProvider the formatter change above.

The test case for this is a main.c with main() and a function pointer global to 
main, fmain().  Then there is a standalone program that creates this specific 
corefile without any metadata about the addressing bits -- lldb itself always 
adds this metadata, so I couldn't use lldb's built-in process save-core 
functionality. It's a tiny corefile that only has 8 bytes of DATA memory where 
the function pointer is stored.  I have ideas for how I can use this test case 
for some upcoming changes I want to make, so I expect to get more use out of 
this test case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115431

Files:
  lldb/source/DataFormatters/CXXFunctionPointer.cpp
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Utility/ArchSpec.cpp
  lldb/test/API/macosx/corefile-default-ptrauth/Makefile
  lldb/test/API/macosx/corefile-default-ptrauth/TestCorefileDefaultPtrauth.py
  lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
  lldb/test/API/macosx/corefile-default-ptrauth/main.c

Index: lldb/test/API/macosx/corefile-default-ptrauth/main.c
===
--- /dev/null
+++ lldb/test/API/macosx/corefile-default-ptrauth/main.c
@@ -0,0 +1,6 @@
+int main();
+int (*fmain)() = main;
+int main () {
+  return fmain();
+}
+
Index: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
===
--- /dev/null
+++ lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
@@ -0,0 +1,105 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+// Given an executable binary with 
+//   "fmain" (a function pointer to main)
+//   "main"
+// symbols, create a fake arm64e corefile that
+// contains a memory segment for the fmain 
+// function pointer, with the value of the 
+// address of main() with ptrauth bits masked on.
+//
+// The corefile does not include the "addrable bits"
+// LC_NOTE, so lldb will need to fall back on its 
+// default value from the Darwin arm64 ABI.
+
+int main(int argc, char **argv)
+{
+  if (argc != 3) {
+fprintf (stderr, "usage: %s executable-binary output-file\n", argv[0]);
+exit(1);
+  }
+  FILE *exe = fopen(argv[1], "r");
+  if (!exe) {
+fprintf (stderr, "Unable to open executable %s for reading\n", argv[1]);
+  }
+  FILE *out = fopen(argv[2], "w");
+  if (!out) {
+fprintf (stderr, "Unable to open %s for writing\n", argv[2]);
+exit(1);
+  }
+
+  char buf[PATH_MAX + 6];
+  sprintf (buf, "nm '%s'", argv[1]);
+  FILE *nm = popen(buf, "r");
+  if (!nm) {
+fprintf (stderr,

[Lldb-commits] [PATCH] D115313: [lldb/Target] Slide source display for artificial locations at function start

2021-12-09 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

> Thanks for clarifying @DavidSpickett ! I'll change the warning accordingly.

Too many Davids :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115313

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


[Lldb-commits] [lldb] e04fc2d - [llvm][lldb] Remove unused SmallVectorMemoryBuffer.h includes

2021-12-09 Thread Jan Svoboda via lldb-commits

Author: Jan Svoboda
Date: 2021-12-09T11:32:13+01:00
New Revision: e04fc2d88efa60ed5527b90c15d8fc188739e989

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

LOG: [llvm][lldb] Remove unused SmallVectorMemoryBuffer.h includes

Added: 


Modified: 
lldb/unittests/Expression/CppModuleConfigurationTest.cpp
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Object/MachOUniversalWriter.cpp

Removed: 




diff  --git a/lldb/unittests/Expression/CppModuleConfigurationTest.cpp 
b/lldb/unittests/Expression/CppModuleConfigurationTest.cpp
index 3923f1215b340..017a0748c2243 100644
--- a/lldb/unittests/Expression/CppModuleConfigurationTest.cpp
+++ b/lldb/unittests/Expression/CppModuleConfigurationTest.cpp
@@ -11,7 +11,6 @@
 #include "TestingSupport/SubsystemRAII.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
-#include "llvm/Support/SmallVectorMemoryBuffer.h"
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"

diff  --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index be06556b0c3bf..15e20fec565f5 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -37,7 +37,6 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
-#include "llvm/Support/SmallVectorMemoryBuffer.h"
 #include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"

diff  --git a/llvm/lib/Object/MachOUniversalWriter.cpp 
b/llvm/lib/Object/MachOUniversalWriter.cpp
index 9673c97a10f01..ae1ff09a4f8f1 100644
--- a/llvm/lib/Object/MachOUniversalWriter.cpp
+++ b/llvm/lib/Object/MachOUniversalWriter.cpp
@@ -19,7 +19,6 @@
 #include "llvm/Object/IRObjectFile.h"
 #include "llvm/Object/MachO.h"
 #include "llvm/Object/MachOUniversal.h"
-#include "llvm/Support/SmallVectorMemoryBuffer.h"
 
 using namespace llvm;
 using namespace object;



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


[Lldb-commits] [PATCH] D115438: [lldb] Remove unused lldb.cpp

2021-12-09 Thread Haojian Wu via Phabricator via lldb-commits
hokein created this revision.
hokein added a reviewer: labath.
hokein requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

lldb.cpp is unused after 
https://github.com/llvm/llvm-project/commit/ccf1469a4cdb03cb2bc7868f76164e85d90ebee1


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115438

Files:
  lldb/source/lldb.cpp


Index: lldb/source/lldb.cpp
===
--- lldb/source/lldb.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-//===-- lldb.cpp 
--===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "VCSVersion.inc"
-#include "lldb/lldb-private.h"
-#include "clang/Basic/Version.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-// LLDB_VERSION_STRING is set through a define so unlike the other defines
-// expanded with CMake, it lacks the double quotes.
-#define QUOTE(str) #str
-#define EXPAND_AND_QUOTE(str) QUOTE(str)
-
-static const char *GetLLDBVersion() {
-#ifdef LLDB_VERSION_STRING
-  return EXPAND_AND_QUOTE(LLDB_VERSION_STRING);
-#else
-  return "lldb version " CLANG_VERSION_STRING;
-#endif
-}
-
-static const char *GetLLDBRevision() {
-#ifdef LLDB_REVISION
-  return LLDB_REVISION;
-#else
-  return NULL;
-#endif
-}
-
-static const char *GetLLDBRepository() {
-#ifdef LLDB_REPOSITORY
-  return LLDB_REPOSITORY;
-#else
-  return NULL;
-#endif
-}
-
-const char *lldb_private::GetVersion() {
-  static std::string g_version_str;
-  if (g_version_str.empty()) {
-const char *lldb_version = GetLLDBVersion();
-const char *lldb_repo = GetLLDBRepository();
-const char *lldb_rev = GetLLDBRevision();
-g_version_str += lldb_version;
-if (lldb_repo || lldb_rev) {
-  g_version_str += " (";
-  if (lldb_repo)
-g_version_str += lldb_repo;
-  if (lldb_repo && lldb_rev)
-g_version_str += " ";
-  if (lldb_rev) {
-g_version_str += "revision ";
-g_version_str += lldb_rev;
-  }
-  g_version_str += ")";
-}
-
-std::string clang_rev(clang::getClangRevision());
-if (clang_rev.length() > 0) {
-  g_version_str += "\n  clang revision ";
-  g_version_str += clang_rev;
-}
-std::string llvm_rev(clang::getLLVMRevision());
-if (llvm_rev.length() > 0) {
-  g_version_str += "\n  llvm revision ";
-  g_version_str += llvm_rev;
-}
-  }
-  return g_version_str.c_str();
-}


Index: lldb/source/lldb.cpp
===
--- lldb/source/lldb.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-//===-- lldb.cpp --===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "VCSVersion.inc"
-#include "lldb/lldb-private.h"
-#include "clang/Basic/Version.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-// LLDB_VERSION_STRING is set through a define so unlike the other defines
-// expanded with CMake, it lacks the double quotes.
-#define QUOTE(str) #str
-#define EXPAND_AND_QUOTE(str) QUOTE(str)
-
-static const char *GetLLDBVersion() {
-#ifdef LLDB_VERSION_STRING
-  return EXPAND_AND_QUOTE(LLDB_VERSION_STRING);
-#else
-  return "lldb version " CLANG_VERSION_STRING;
-#endif
-}
-
-static const char *GetLLDBRevision() {
-#ifdef LLDB_REVISION
-  return LLDB_REVISION;
-#else
-  return NULL;
-#endif
-}
-
-static const char *GetLLDBRepository() {
-#ifdef LLDB_REPOSITORY
-  return LLDB_REPOSITORY;
-#else
-  return NULL;
-#endif
-}
-
-const char *lldb_private::GetVersion() {
-  static std::string g_version_str;
-  if (g_version_str.empty()) {
-const char *lldb_version = GetLLDBVersion();
-const char *lldb_repo = GetLLDBRepository();
-const char *lldb_rev = GetLLDBRevision();
-g_version_str += lldb_version;
-if (lldb_repo || lldb_rev) {
-  g_version_str += " (";
-  if (lldb_repo)
-g_version_str += lldb_repo;
-  if (lldb_repo && lldb_rev)
-g_version_str += " ";
-  if (lldb_rev) {
-g_version_str += "revision ";
-g_version_str += lldb_rev;
-  }
-  g_version_str += ")";
-}
-
-std::string clang_rev(clang::getClangRevision());
-if (clang_rev.length() > 0) {
-  g_version_str += "\n  clang revision ";
-  g_version_str += clang_rev;
-}
-std::string llvm_rev(clang::getLLVMRevision());
-if (llvm_rev.length() > 0) {
-  g_version_str += "\n  llvm revision ";
-  g_v

[Lldb-commits] [PATCH] D115110: [lldb][nfc] clang-format some files as preperation for https://reviews.llvm.org/D114627

2021-12-09 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb2e2eece9aa8: [lldb][NFC] clang-format some files as 
preparation for https://reviews.llvm. (authored by lassefolger, committed by 
werat).

Changed prior to commit:
  https://reviews.llvm.org/D115110?vs=391895&id=393103#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115110

Files:
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Core/Module.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Symbol/SymbolFile.cpp

Index: lldb/source/Symbol/SymbolFile.cpp
===
--- lldb/source/Symbol/SymbolFile.cpp
+++ lldb/source/Symbol/SymbolFile.cpp
@@ -147,9 +147,11 @@
   // We assert that we have to module lock by trying to acquire the lock from a
   // different thread. Note that we must abort if the result is true to
   // guarantee correctness.
-  assert(std::async(std::launch::async,
-[this] { return this->GetModuleMutex().try_lock(); })
- .get() == false &&
+  assert(std::async(
+ std::launch::async,
+ [this] {
+   return this->GetModuleMutex().try_lock();
+ }).get() == false &&
  "Module is not locked");
 #endif
 }
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -253,8 +253,8 @@
   ExternalTypeModuleMap;
 
   /// Return the list of Clang modules imported by this SymbolFile.
-  const ExternalTypeModuleMap& getExternalTypeModules() const {
-  return m_external_type_modules;
+  const ExternalTypeModuleMap &getExternalTypeModules() const {
+return m_external_type_modules;
   }
 
   virtual DWARFDIE GetDIE(const DIERef &die_ref);
@@ -328,7 +328,6 @@
 return m_parse_time;
   }
 
-
 protected:
   typedef llvm::DenseMap
   DIEToTypePtr;
@@ -428,9 +427,10 @@
   virtual lldb::TypeSP
   FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
 
-  virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
-  const DWARFDIE &die, lldb_private::ConstString type_name,
-  bool must_be_implementation);
+  virtual lldb::TypeSP
+  FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die,
+   lldb_private::ConstString type_name,
+   bool must_be_implementation);
 
   lldb_private::Symbol *
   GetObjCClassSymbol(lldb_private::ConstString objc_class_name);
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1097,7 +1097,8 @@
   if (const char *include_path = module_die.GetAttributeValueAsString(
   DW_AT_LLVM_include_path, nullptr)) {
 FileSpec include_spec(include_path, dwarf_cu->GetPathStyle());
-MakeAbsoluteAndRemap(include_spec, *dwarf_cu, m_objfile_sp->GetModule());
+MakeAbsoluteAndRemap(include_spec, *dwarf_cu,
+ m_objfile_sp->GetModule());
 module.search_path = ConstString(include_spec.GetPath());
   }
   if (const char *sysroot = dwarf_cu->DIE().GetAttributeValueAsString(
@@ -1924,7 +1925,7 @@
   block_die = function_die.LookupDeepestBlock(file_vm_addr);
   }
 
-  if (!sc.function || ! lookup_block)
+  if (!sc.function || !lookup_block)
 return;
 
   Block &block = sc.function->GetBlock(true);
@@ -2319,7 +2320,8 @@
   if (log) {
 GetObjectFile()->GetModule()->LogMessage(
 log,
-"SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, sc_list)",
+"SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, "
+"sc_list)",
 name.GetCString(), name_type_mask);
   }
 
@@ -2352,8 +2354,7 @@
 log,
 "SymbolFileDWARF::FindFunctions (name=\"%s\", "
 "name_type_mask=0x%x, include_inlines=%d, sc_list) => %u",
-name.GetCString(), name_type_mask, include_inlines,
-num_matches);
+name.GetCString(), name_type_mask, include_inlines, num_matches);
   }
 }
 
Index: lldb/source/Core/Module.cpp
===
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -233,8 +233,8 @@
 Module::Module(const FileSpec &file_spec, const ArchSpec &arch,
const ConstString *object_name, lldb::offset_t object_offset,
const llvm::sys::TimePoint<> &object_mod_time)
-: m_mod_time(FileSystem::Instan

[Lldb-commits] [lldb] b2e2eec - [lldb][NFC] clang-format some files as preparation for https://reviews.llvm.org/D114627

2021-12-09 Thread Andy Yankovsky via lldb-commits

Author: Lasse Folger
Date: 2021-12-09T12:38:00+01:00
New Revision: b2e2eece9aa8db4bcc47c7fed0a9b999a3d96baf

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

LOG: [lldb][NFC] clang-format some files as preparation for 
https://reviews.llvm.org/D114627

Reviewed By: werat

Differential Revision: https://reviews.llvm.org/D115110

Added: 


Modified: 
lldb/include/lldb/Core/Module.h
lldb/include/lldb/Symbol/SymbolFile.h
lldb/source/Core/Module.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
lldb/source/Symbol/SymbolFile.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h
index b80f4fd9b85a7..acc11c777dbf3 100644
--- a/lldb/include/lldb/Core/Module.h
+++ b/lldb/include/lldb/Core/Module.h
@@ -21,8 +21,8 @@
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/Status.h"
-#include "lldb/Utility/XcodeSDK.h"
 #include "lldb/Utility/UUID.h"
+#include "lldb/Utility/XcodeSDK.h"
 #include "lldb/lldb-defines.h"
 #include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-forward.h"
@@ -128,7 +128,7 @@ class Module : public std::enable_shared_from_this,
   Module(const ModuleSpec &module_spec);
 
   template 
-  static lldb::ModuleSP CreateModuleFromObjectFile(Args &&... args) {
+  static lldb::ModuleSP CreateModuleFromObjectFile(Args &&...args) {
 // Must create a module and place it into a shared pointer before we can
 // create an object file since it has a std::weak_ptr back to the module,
 // so we need to control the creation carefully in this static function
@@ -255,8 +255,7 @@ class Module : public std::enable_shared_from_this,
   /// Returns a valid symbol pointer if a symbol was found,
   /// nullptr otherwise.
   const Symbol *FindFirstSymbolWithNameAndType(
-  ConstString name,
-  lldb::SymbolType symbol_type = lldb::eSymbolTypeAny);
+  ConstString name, lldb::SymbolType symbol_type = lldb::eSymbolTypeAny);
 
   void FindSymbolsWithNameAndType(ConstString name,
   lldb::SymbolType symbol_type,
@@ -439,12 +438,13 @@ class Module : public 
std::enable_shared_from_this,
   ///
   /// \param searched_symbol_files
   /// Prevents one file from being visited multiple times.
-  void FindTypes(llvm::ArrayRef pattern, LanguageSet 
languages,
- llvm::DenseSet 
&searched_symbol_files,
- TypeMap &types);
+  void
+  FindTypes(llvm::ArrayRef pattern, LanguageSet languages,
+llvm::DenseSet &searched_symbol_files,
+TypeMap &types);
 
-  lldb::TypeSP FindFirstType(const SymbolContext &sc,
- ConstString type_name, bool exact_match);
+  lldb::TypeSP FindFirstType(const SymbolContext &sc, ConstString type_name,
+ bool exact_match);
 
   /// Find types by name that are in a namespace. This function is used by the
   /// expression parser when searches need to happen in an exact namespace
@@ -788,8 +788,7 @@ class Module : public std::enable_shared_from_this,
   const FileSpec &file_spec, uint32_t line, bool check_inlines,
   lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list);
 
-  void SetFileSpecAndObjectName(const FileSpec &file,
-ConstString object_name);
+  void SetFileSpecAndObjectName(const FileSpec &file, ConstString object_name);
 
   bool GetIsDynamicLinkEditor();
 
@@ -876,7 +875,7 @@ class Module : public std::enable_shared_from_this,
   /// The value is returned as a reference to allow it to be updated by the
   /// ElapsedTime RAII object.
   StatsDuration &GetSymtabParseTime() { return m_symtab_parse_time; }
-  
+
   /// Accessor for the symbol table index time metric.
   ///
   /// The value is returned as a reference to allow it to be updated by the
@@ -949,27 +948,27 @@ class Module : public 
std::enable_shared_from_this,
 protected:
   // Member Variables
   mutable std::recursive_mutex m_mutex; ///< A mutex to keep this object happy
-///in multi-threaded environments.
+/// in multi-threaded environments.
 
   /// The modification time for this module when it was created.
   llvm::sys::TimePoint<> m_mod_time;
 
-  ArchSpec m_arch;  ///< The architecture for this module.
+  ArchSpec m_arch; ///< The architecture for this module.
   UUID m_uuid; ///< Each module is assumed to have a unique identifier to help
-   ///match it up to debug symbols.
+   /// match it up to debug symbols.
   FileSpec m_file; ///< The file representation on disk for this module (if
-

[Lldb-commits] [PATCH] D115431: Set a default number of addressing bits for Darwin arm64 systems

2021-12-09 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a reviewer: DavidSpickett.
DavidSpickett added a comment.

Glad to see this, it will be useful on AArch64 Linux as well.

General question, is yaml2obj not flexible enough to do this? I guess the issue 
would be even if it does do MachO the test could only work on a precompiled 
file, this way allows you to build `a.out` each time.

> I have ideas for how I can use this test case for some upcoming changes I 
> want to make, so I expect to get more use out of this test case.

And having this program to build the corefile allows you the flexibility to do 
these future things you reference here?




Comment at: lldb/source/DataFormatters/CXXFunctionPointer.cpp:53
+  Process *process = exe_ctx.GetProcessPtr();
+  if (process) {
+if (ABISP abi_sp = process->GetABI()) {

You could do `if (Process *process = ...`.



Comment at: lldb/source/DataFormatters/CXXFunctionPointer.cpp:55
+if (ABISP abi_sp = process->GetABI()) {
+  addr_t fixed_addr = abi_sp->FixCodeAddress (func_ptr_address);
+  if (fixed_addr != func_ptr_address) {

Remove space before the `(`. Unless this is a code style I'm missing.



Comment at: lldb/source/DataFormatters/CXXFunctionPointer.cpp:58
+Address test_address;
+test_address.SetLoadAddress (fixed_addr, target);
+if (test_address.GetSection() != nullptr) {

Stray space ` (` here too.



Comment at: lldb/source/DataFormatters/CXXFunctionPointer.cpp:61
+  int addrsize = 
target->GetArchitecture().GetAddressByteSize();
+  sstr.Printf("actual=0x%*.*" PRIx64 " ", addrsize * 2, 
addrsize * 2, fixed_addr);
+  so_addr = test_address;

Where does the closing ) come from, does the so_addr.Dump emit it?



Comment at: lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp:830
+  }
   return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
 }

Can you explain this logic? The "else" part I get, it's the sign extension 
check I'm not sure of.

I have to admit, we have this over in AArch64 Linux and it's been on my list to 
find out what it actually does and document it there too. My naive assumption 
is that removing signature bits would just be a mask but clearly I'm missing 
something.



Comment at: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:5161
 } else {
-  // We didn't find a LC_VERSION_MIN load command and this isn't a KEXT
-  // so lets not say our Vendor is Apple, leave it as an unspecified
-  // unknown.
-  base_triple.setVendor(llvm::Triple::UnknownVendor);
-  base_triple.setVendorName(llvm::StringRef());
   add_triple(base_triple);
 }

You could pull that out to after the if.

```
if (header.filetype == MH_KEXT_BUNDLE) {
base_triple.setVendor(llvm::Triple::Apple);
}
add_triple(base_triple);
```



Comment at: lldb/test/API/macosx/corefile-default-ptrauth/Makefile:9
+
+include Makefile.rules

Does a.out get built here because the default testing makefile does that? 
Please comment that if so, otherwise it looks like you forgot to check in the 
prebuilt a.out.



Comment at: 
lldb/test/API/macosx/corefile-default-ptrauth/TestCorefileDefaultPtrauth.py:50
+
+self.expect("ta v fmain", substrs=['fmain = 0x', 'actual=0x', 'main at 
main.c'])

I'd use the full commands here just for clarity.

Also given the brackets around the "actual" bit seem to be emitted by two 
different calls, include them in the match as well? Just in case one gets 
dropped at some point.



Comment at: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c:18
+//
+// The corefile does not include the "addrable bits"
+// LC_NOTE, so lldb will need to fall back on its 

Is the name spelled like that or should it be "addressable"?



Comment at: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c:30
+  if (!exe) {
+fprintf (stderr, "Unable to open executable %s for reading\n", argv[1]);
+  }

`exit(1)` here



Comment at: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c:55
+  }
+  fclose (nm);
+

Should you have some validity check here that the address of main and fmain is 
not still 0? Just in case you manage to read half way through an nm line and 
miss one of them.



Comment at: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c:57
+
+  int size_of_thread_cmd = 4 + 4 + 4 + 4 + sizeof (arm_thread_state64_t);
+

What are the 4s?



Comment at: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c:59
+
+  struct mach_header_64 mh;
+  mh

[Lldb-commits] [PATCH] D115431: Set a default number of addressing bits for Darwin arm64 systems

2021-12-09 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

> General question, is yaml2obj not flexible enough to do this? I guess the 
> issue would be even if it does do MachO the test could only work on a 
> precompiled file, this way allows you to build a.out each time.

Plus you get all the Mach specific constant values for free instead of writing 
umpteen magic numbers in a YAML file. So I think I just answered my own 
question here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115431

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


[Lldb-commits] [PATCH] D115438: [lldb] Remove unused lldb.cpp

2021-12-09 Thread Haojian Wu via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeaf4f60507fd: [lldb] Remove unused lldb.cpp (authored by 
hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115438

Files:
  lldb/source/lldb.cpp


Index: lldb/source/lldb.cpp
===
--- lldb/source/lldb.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-//===-- lldb.cpp 
--===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "VCSVersion.inc"
-#include "lldb/lldb-private.h"
-#include "clang/Basic/Version.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-// LLDB_VERSION_STRING is set through a define so unlike the other defines
-// expanded with CMake, it lacks the double quotes.
-#define QUOTE(str) #str
-#define EXPAND_AND_QUOTE(str) QUOTE(str)
-
-static const char *GetLLDBVersion() {
-#ifdef LLDB_VERSION_STRING
-  return EXPAND_AND_QUOTE(LLDB_VERSION_STRING);
-#else
-  return "lldb version " CLANG_VERSION_STRING;
-#endif
-}
-
-static const char *GetLLDBRevision() {
-#ifdef LLDB_REVISION
-  return LLDB_REVISION;
-#else
-  return NULL;
-#endif
-}
-
-static const char *GetLLDBRepository() {
-#ifdef LLDB_REPOSITORY
-  return LLDB_REPOSITORY;
-#else
-  return NULL;
-#endif
-}
-
-const char *lldb_private::GetVersion() {
-  static std::string g_version_str;
-  if (g_version_str.empty()) {
-const char *lldb_version = GetLLDBVersion();
-const char *lldb_repo = GetLLDBRepository();
-const char *lldb_rev = GetLLDBRevision();
-g_version_str += lldb_version;
-if (lldb_repo || lldb_rev) {
-  g_version_str += " (";
-  if (lldb_repo)
-g_version_str += lldb_repo;
-  if (lldb_repo && lldb_rev)
-g_version_str += " ";
-  if (lldb_rev) {
-g_version_str += "revision ";
-g_version_str += lldb_rev;
-  }
-  g_version_str += ")";
-}
-
-std::string clang_rev(clang::getClangRevision());
-if (clang_rev.length() > 0) {
-  g_version_str += "\n  clang revision ";
-  g_version_str += clang_rev;
-}
-std::string llvm_rev(clang::getLLVMRevision());
-if (llvm_rev.length() > 0) {
-  g_version_str += "\n  llvm revision ";
-  g_version_str += llvm_rev;
-}
-  }
-  return g_version_str.c_str();
-}


Index: lldb/source/lldb.cpp
===
--- lldb/source/lldb.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-//===-- lldb.cpp --===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "VCSVersion.inc"
-#include "lldb/lldb-private.h"
-#include "clang/Basic/Version.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-// LLDB_VERSION_STRING is set through a define so unlike the other defines
-// expanded with CMake, it lacks the double quotes.
-#define QUOTE(str) #str
-#define EXPAND_AND_QUOTE(str) QUOTE(str)
-
-static const char *GetLLDBVersion() {
-#ifdef LLDB_VERSION_STRING
-  return EXPAND_AND_QUOTE(LLDB_VERSION_STRING);
-#else
-  return "lldb version " CLANG_VERSION_STRING;
-#endif
-}
-
-static const char *GetLLDBRevision() {
-#ifdef LLDB_REVISION
-  return LLDB_REVISION;
-#else
-  return NULL;
-#endif
-}
-
-static const char *GetLLDBRepository() {
-#ifdef LLDB_REPOSITORY
-  return LLDB_REPOSITORY;
-#else
-  return NULL;
-#endif
-}
-
-const char *lldb_private::GetVersion() {
-  static std::string g_version_str;
-  if (g_version_str.empty()) {
-const char *lldb_version = GetLLDBVersion();
-const char *lldb_repo = GetLLDBRepository();
-const char *lldb_rev = GetLLDBRevision();
-g_version_str += lldb_version;
-if (lldb_repo || lldb_rev) {
-  g_version_str += " (";
-  if (lldb_repo)
-g_version_str += lldb_repo;
-  if (lldb_repo && lldb_rev)
-g_version_str += " ";
-  if (lldb_rev) {
-g_version_str += "revision ";
-g_version_str += lldb_rev;
-  }
-  g_version_str += ")";
-}
-
-std::string clang_rev(clang::getClangRevision());
-if (clang_rev.length() > 0) {
-  g_version_str += "\n  clang revision ";
-  g_version_str += clang_rev;
-}
-std::string llvm_rev(clang::getLLVMRevision());
-if (llvm_rev.length() > 0) {
-  g_version_str += "\n  llvm revision ";
-  g_version_str += llvm_rev;
-}
-  }
-  return g_version_str.c_

[Lldb-commits] [lldb] eaf4f60 - [lldb] Remove unused lldb.cpp

2021-12-09 Thread Haojian Wu via lldb-commits

Author: Haojian Wu
Date: 2021-12-09T17:54:27+01:00
New Revision: eaf4f60507fd7e5d20c5dcee711ca12f13f1acc1

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

LOG: [lldb] Remove unused lldb.cpp

lldb.cpp is unused after 
https://github.com/llvm/llvm-project/commit/ccf1469a4cdb03cb2bc7868f76164e85d90ebee1

Differential Revision: https://reviews.llvm.org/D115438

Added: 


Modified: 


Removed: 
lldb/source/lldb.cpp



diff  --git a/lldb/source/lldb.cpp b/lldb/source/lldb.cpp
deleted file mode 100644
index 371902f6c1b5d..0
--- a/lldb/source/lldb.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-//===-- lldb.cpp 
--===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "VCSVersion.inc"
-#include "lldb/lldb-private.h"
-#include "clang/Basic/Version.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-// LLDB_VERSION_STRING is set through a define so unlike the other defines
-// expanded with CMake, it lacks the double quotes.
-#define QUOTE(str) #str
-#define EXPAND_AND_QUOTE(str) QUOTE(str)
-
-static const char *GetLLDBVersion() {
-#ifdef LLDB_VERSION_STRING
-  return EXPAND_AND_QUOTE(LLDB_VERSION_STRING);
-#else
-  return "lldb version " CLANG_VERSION_STRING;
-#endif
-}
-
-static const char *GetLLDBRevision() {
-#ifdef LLDB_REVISION
-  return LLDB_REVISION;
-#else
-  return NULL;
-#endif
-}
-
-static const char *GetLLDBRepository() {
-#ifdef LLDB_REPOSITORY
-  return LLDB_REPOSITORY;
-#else
-  return NULL;
-#endif
-}
-
-const char *lldb_private::GetVersion() {
-  static std::string g_version_str;
-  if (g_version_str.empty()) {
-const char *lldb_version = GetLLDBVersion();
-const char *lldb_repo = GetLLDBRepository();
-const char *lldb_rev = GetLLDBRevision();
-g_version_str += lldb_version;
-if (lldb_repo || lldb_rev) {
-  g_version_str += " (";
-  if (lldb_repo)
-g_version_str += lldb_repo;
-  if (lldb_repo && lldb_rev)
-g_version_str += " ";
-  if (lldb_rev) {
-g_version_str += "revision ";
-g_version_str += lldb_rev;
-  }
-  g_version_str += ")";
-}
-
-std::string clang_rev(clang::getClangRevision());
-if (clang_rev.length() > 0) {
-  g_version_str += "\n  clang revision ";
-  g_version_str += clang_rev;
-}
-std::string llvm_rev(clang::getLLVMRevision());
-if (llvm_rev.length() > 0) {
-  g_version_str += "\n  llvm revision ";
-  g_version_str += llvm_rev;
-}
-  }
-  return g_version_str.c_str();
-}



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


[Lldb-commits] [PATCH] D115126: [LLDB] Add unit tests for Editline keyboard shortcuts

2021-12-09 Thread Neal via Phabricator via lldb-commits
nealsid updated this revision to Diff 393200.
nealsid added a comment.

Patch to address CR feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115126

Files:
  lldb/include/lldb/Host/Editline.h
  lldb/source/Host/common/Editline.cpp
  lldb/unittests/Editline/EditlineTest.cpp

Index: lldb/unittests/Editline/EditlineTest.cpp
===
--- lldb/unittests/Editline/EditlineTest.cpp
+++ lldb/unittests/Editline/EditlineTest.cpp
@@ -17,6 +17,7 @@
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 #include 
 #include 
 
@@ -28,7 +29,12 @@
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/StringList.h"
 
+using namespace std::chrono_literals;
+
+#define ESCAPE "\x1b"
+
 using namespace lldb_private;
+using namespace testing;
 
 namespace {
 const size_t TIMEOUT_MILLIS = 5000;
@@ -80,6 +86,8 @@
 
   void ConsumeAllOutput();
 
+  const std::string GetEditlineOutput();
+
 private:
   bool IsInputComplete(lldb_private::Editline *editline,
lldb_private::StringList &lines);
@@ -91,6 +99,7 @@
   int _pty_secondary_fd;
 
   std::unique_ptr _el_secondary_file;
+  std::stringstream testOutputBuffer;
 };
 
 EditlineAdapter::EditlineAdapter()
@@ -110,11 +119,21 @@
   EXPECT_THAT_ERROR(_pty.OpenSecondary(O_RDWR), llvm::Succeeded());
   _pty_secondary_fd = _pty.GetSecondaryFileDescriptor();
 
-  _el_secondary_file.reset(new FilePointer(fdopen(_pty_secondary_fd, "rw")));
+  _el_secondary_file.reset(new FilePointer(fdopen(_pty_secondary_fd, "w+")));
   EXPECT_FALSE(nullptr == *_el_secondary_file);
   if (*_el_secondary_file == nullptr)
 return;
 
+  // We have to set the output stream we pass to Editline as not using
+  // buffered I/O.  Otherwise we are missing editline's output when we
+  // close the stream in the keybinding test (i.e. the EOF comes
+  // before data previously written to the stream by editline).  This
+  // behavior isn't as I understand the spec becuse fclose should
+  // flush the stream, but my best guess is that it's some unexpected
+  // interaction with stream I/O and ptys.
+  EXPECT_EQ(setvbuf(*_el_secondary_file, nullptr, _IONBF, 0), 0)
+  << "Could not set editline output stream to use unbuffered I/O.";
+
   // Create an Editline instance.
   _editline_sp.reset(new lldb_private::Editline(
   "gtest editor", *_el_secondary_file, *_el_secondary_file,
@@ -204,6 +223,10 @@
   return (start_block_count > 0) && (brace_balance == 0);
 }
 
+const std::string EditlineAdapter::GetEditlineOutput() {
+  return testOutputBuffer.str();
+}
+
 void EditlineAdapter::ConsumeAllOutput() {
   FilePointer output_file(fdopen(_pty_primary_fd, "r"));
 
@@ -229,15 +252,15 @@
   break;
 }
 printf(" 0x%02x (%03d) (%s)\n", ch, ch, display_str);
-// putc(ch, stdout);
 #endif
+testOutputBuffer << (char)ch;
   }
 }
 
 class EditlineTestFixture : public ::testing::Test {
   SubsystemRAII subsystems;
   EditlineAdapter _el_adapter;
-  std::shared_ptr _sp_output_thread;
+  std::thread _sp_output_thread;
 
 public:
   static void SetUpTestCase() {
@@ -252,16 +275,17 @@
   return;
 
 // Dump output.
-_sp_output_thread =
-std::make_shared([&] { _el_adapter.ConsumeAllOutput(); });
+_sp_output_thread = std::thread([&] { _el_adapter.ConsumeAllOutput(); });
   }
 
-  void TearDown() override {
+  void EndOutputThread() {
 _el_adapter.CloseInput();
-if (_sp_output_thread)
-  _sp_output_thread->join();
+if (_sp_output_thread.joinable())
+  _sp_output_thread.join();
   }
 
+  void TearDown() override { EndOutputThread(); }
+
   EditlineAdapter &GetEditlineAdapter() { return _el_adapter; }
 };
 
@@ -309,4 +333,124 @@
   EXPECT_THAT(reported_lines, testing::ContainerEq(input_lines));
 }
 
+namespace lldb_private {
+
+// Parameter structure for parameterized tests.
+struct KeybindingTestValue {
+  // A number that is used to name the test, so test output can be
+  // mapped back to a specific input.
+  const std::string testNumber;
+  // Whether this keyboard shortcut is only bound in multi-line mode.
+  const bool multilineOnly;
+  // The actual key sequence.
+  const std::string keySequence;
+  // The command the key sequence is supposed to execute.
+  const std::string commandName;
+  // This is initialized to the keySequence by default, but gtest has
+  // some errors when the test name as created by the overloaded
+  // operator<< has embedded newlines.  This is even true when we
+  // specify a custom test name function, as we do below when we
+  // instantiate the test case.  In cases where the keyboard shortcut
+  // has a newline or carriage return, this field in the struct can be
+  // set to something that is printable.
+  const std::string &printableKeySequence = keySequence;
+};
+
+std::ostream &operator<<(std::ostream &os, const KeybindingTestValue &kbtv) {
+  return os

[Lldb-commits] [PATCH] D115438: [lldb] Remove unused lldb.cpp

2021-12-09 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115438

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


[Lldb-commits] [PATCH] D115313: [lldb/Target] Slide source display for artificial locations at function start

2021-12-09 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

Thanks! I have some late wording suggestions.




Comment at: lldb/source/Target/StackFrame.cpp:1904
+  strm.Printf("Warning: the current PC is an artificial location "
+  "in function %s.",
+  fn_name.AsCString());

This message might be confusing to developers. End-users won't know what "PC" 
and "artificial" means. What do you think about:
```
"Note: this address is compiler-generated code in function %s that has no 
source code associated with it."
```

?



Comment at: lldb/source/Target/StackFrame.cpp:1909
+  "Warning: the current PC is an artificial location "
+  "but lldb couldn't associate it with a function in %s.",
+  m_sc.line_entry.file.GetFilename().GetCString());

"Note: this address is compiler-generated code that has no source code 
associated with it."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115313

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


[Lldb-commits] [PATCH] D115431: Set a default number of addressing bits for Darwin arm64 systems

2021-12-09 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda marked 12 inline comments as done.
jasonmolenda added a comment.

Thanks so much for the thorough review Davide, I really appreciate the help and 
time you spent doing this.  I addressed the comments and will update the patch 
momentarily.

I have another small change I want to make soon where I add a new "load binary" 
LC_NOTE which will be a way for a corefile to tell lldb to load additional 
binaries for a corefile, and I'm planning to add this load binary command to 
the corefile and confirm that lldb loads the a.out correctly via that.

I didn't look at obj2yaml too hard, but the first thing I tried was running it 
on my created corefile, and it didn't include the memory contents 
(LC_SEGMENT_64), so I didn't pursue it much further. I knew I was going to add 
a custom LC_NOTE to this test corefile soon too and I don't think those are 
handled r.n.  It was pretty straightforward to create a simple corefile.




Comment at: lldb/source/DataFormatters/CXXFunctionPointer.cpp:61
+  int addrsize = 
target->GetArchitecture().GetAddressByteSize();
+  sstr.Printf("actual=0x%*.*" PRIx64 " ", addrsize * 2, 
addrsize * 2, fixed_addr);
+  so_addr = test_address;

DavidSpickett wrote:
> Where does the closing ) come from, does the so_addr.Dump emit it?
This method (and Address::Dump) are concatenating text into the Stream sstr 
which is a symbolic description of the address; we want to print

fmain = 0xPTRAUTH (actual=0xACTUAL )

so this is prepending the "actual=0xACTUAL " part, replacing the Address we're 
looking up with the ptrauth-stripped-off Address, and relying on Address::Dump 
to append its normal symbolication stuff.  Then just below in this method we 
have

  if (sstr.GetSize() > 0) {
stream.Printf("(%s)", sstr.GetData());

where the parens are added.



Comment at: lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp:830
+  }
   return (pc & pac_sign_extension) ? pc | mask : pc & (~mask);
 }

DavidSpickett wrote:
> Can you explain this logic? The "else" part I get, it's the sign extension 
> check I'm not sure of.
> 
> I have to admit, we have this over in AArch64 Linux and it's been on my list 
> to find out what it actually does and document it there too. My naive 
> assumption is that removing signature bits would just be a mask but clearly 
> I'm missing something.
I intend this to handle the case of code running in high memory, where bit 55 
is set, indicating that all of the high bits should be set to 1.  Unlike 
userland memory on Darwin which runs in low memory, where bit 55 is clear and 
so all the high bits should be cleared to 0 when removing the PAC bits.



Comment at: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:5161
 } else {
-  // We didn't find a LC_VERSION_MIN load command and this isn't a KEXT
-  // so lets not say our Vendor is Apple, leave it as an unspecified
-  // unknown.
-  base_triple.setVendor(llvm::Triple::UnknownVendor);
-  base_triple.setVendorName(llvm::StringRef());
   add_triple(base_triple);
 }

DavidSpickett wrote:
> You could pull that out to after the if.
> 
> ```
> if (header.filetype == MH_KEXT_BUNDLE) {
> base_triple.setVendor(llvm::Triple::Apple);
> }
> add_triple(base_triple);
> ```
Good point, altho looking at this bit of code my goal was to force Vendor to 
apple for any mach-o binary, not just kexts.  Whatever, the key part was not 
clearing the Vendor here.



Comment at: lldb/test/API/macosx/corefile-default-ptrauth/Makefile:9
+
+include Makefile.rules

DavidSpickett wrote:
> Does a.out get built here because the default testing makefile does that? 
> Please comment that if so, otherwise it looks like you forgot to check in the 
> prebuilt a.out.
OK.  I copied a Makefile I used in another test, where I have a helper program 
and the test binary, and didn't think about how it reads.



Comment at: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c:18
+//
+// The corefile does not include the "addrable bits"
+// LC_NOTE, so lldb will need to fall back on its 

DavidSpickett wrote:
> Is the name spelled like that or should it be "addressable"?
The LC_NOTE names are only 16 characters, so unfortunately, "addrable bits" it 
is. :) 



Comment at: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c:57
+
+  int size_of_thread_cmd = 4 + 4 + 4 + 4 + sizeof (arm_thread_state64_t);
+

DavidSpickett wrote:
> What are the 4s?
The LC_THREAD load command has four uint32_t's at the start, but you're right 
and I was even thinking of commenting in this last night & did not.  I added a 
comment with the format of LC_THREAD.



Comment at: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c:92
+  fwrite (&flavor, sizeof (fl

[Lldb-commits] [PATCH] D115431: Set a default number of addressing bits for Darwin arm64 systems

2021-12-09 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda updated this revision to Diff 393213.
jasonmolenda marked 3 inline comments as done.
jasonmolenda added a comment.

Update patchset to address David's feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115431

Files:
  lldb/source/DataFormatters/CXXFunctionPointer.cpp
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Utility/ArchSpec.cpp
  lldb/test/API/macosx/corefile-default-ptrauth/Makefile
  lldb/test/API/macosx/corefile-default-ptrauth/TestCorefileDefaultPtrauth.py
  lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
  lldb/test/API/macosx/corefile-default-ptrauth/main.c

Index: lldb/test/API/macosx/corefile-default-ptrauth/main.c
===
--- /dev/null
+++ lldb/test/API/macosx/corefile-default-ptrauth/main.c
@@ -0,0 +1,6 @@
+int main();
+int (*fmain)() = main;
+int main () {
+  return fmain();
+}
+
Index: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
===
--- /dev/null
+++ lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
@@ -0,0 +1,131 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+// Given an executable binary with 
+//   "fmain" (a function pointer to main)
+//   "main"
+// symbols, create a fake arm64e corefile that
+// contains a memory segment for the fmain 
+// function pointer, with the value of the 
+// address of main() with ptrauth bits masked on.
+//
+// The corefile does not include the "addrable bits"
+// LC_NOTE, so lldb will need to fall back on its 
+// default value from the Darwin arm64 ABI.
+
+int main(int argc, char **argv)
+{
+  if (argc != 3) {
+fprintf (stderr, "usage: %s executable-binary output-file\n", argv[0]);
+exit(1);
+  }
+  FILE *exe = fopen(argv[1], "r");
+  if (!exe) {
+fprintf (stderr, "Unable to open executable %s for reading\n", argv[1]);
+exit(1);
+  }
+  FILE *out = fopen(argv[2], "w");
+  if (!out) {
+fprintf (stderr, "Unable to open %s for writing\n", argv[2]);
+exit(1);
+  }
+
+  char buf[PATH_MAX + 6];
+  sprintf (buf, "nm '%s'", argv[1]);
+  FILE *nm = popen(buf, "r");
+  if (!nm) {
+fprintf (stderr, "Unable to run nm on '%s'", argv[1]);
+exit (1);
+  }
+  uint64_t main_addr = 0;
+  uint64_t fmain_addr = 0;
+  while (fgets (buf, sizeof(buf), nm)) {
+if (strstr (buf, "_fmain")) {
+  fmain_addr = strtoul (buf, NULL, 16);
+}
+if (strstr (buf, "_main")) {
+  main_addr = strtoul (buf, NULL, 16);
+}
+  }
+  pclose (nm);
+
+  if (main_addr == 0 || fmain_addr == 0) {
+fprintf(stderr, "Unable to find address of main or fmain in %s.\n",
+argv[1]);
+exit (1);
+  }
+
+  // Write out a corefile with contents in this order:
+  //1. mach header
+  //2. LC_THREAD load command
+  //3. LC_SEGMENT_64 load command
+  //4. memory segment contents
+
+  // struct thread_command {
+  //   uint32_tcmd;
+  //   uint32_tcmdsize;
+  //   uint32_t flavor  
+  //   uint32_t count   
+  //   struct XXX_thread_state state
+  int size_of_thread_cmd = 4 + 4 + 4 + 4 + sizeof (arm_thread_state64_t);
+
+  struct mach_header_64 mh;
+  mh.magic = 0xfeedfacf;
+  mh.cputype = CPU_TYPE_ARM64;
+  mh.cpusubtype = CPU_SUBTYPE_ARM64E;
+  mh.filetype = MH_CORE;
+  mh.ncmds = 2; // LC_THREAD, LC_SEGMENT_64
+  mh.sizeofcmds = size_of_thread_cmd + sizeof(struct segment_command_64);
+  mh.flags = 0;
+  mh.reserved = 0;
+
+  fwrite(&mh, sizeof (mh), 1, out);
+
+  struct segment_command_64 seg;
+  seg.cmd = LC_SEGMENT_64;
+  seg.cmdsize = sizeof(seg);
+  memset (&seg.segname, 0, 16);
+  seg.vmaddr = fmain_addr;
+  seg.vmsize = 8;
+  // Offset to segment contents
+  seg.fileoff = sizeof (mh) + size_of_thread_cmd + sizeof(seg);
+  seg.filesize = 8;
+  seg.maxprot = 3;
+  seg.initprot = 3;
+  seg.nsects = 0;
+  seg.flags = 0;
+
+  fwrite (&seg, sizeof (seg), 1, out);
+
+  uint32_t cmd = LC_THREAD;
+  fwrite (&cmd, sizeof (cmd), 1, out);
+  uint32_t cmdsize = size_of_thread_cmd;
+  fwrite (&cmdsize, sizeof (cmdsize), 1, out);
+  uint32_t flavor = ARM_THREAD_STATE64;
+  fwrite (&flavor, sizeof (flavor), 1, out);
+  // count is number of uint32_t's of the register context
+  uint32_t count = sizeof (arm_thread_state64_t) / 4;
+  fwrite (&count, sizeof (count), 1, out);
+  arm_thread_state64_t regstate;
+  memset (®state, 0, sizeof (regstate));
+  fwrite (®state, sizeof (regstate), 1, out);
+
+
+  // Or together a random PAC value from a system using 39 bits 
+  // of addressing with the address of main().  lldb will need
+  // to correctly strip off the high bits to find the address of
+  // main.
+  uint64_t segment_contents = 0xe46bff00 | main_addr;
+
+  fwrite (&segment_contents,

[Lldb-commits] [PATCH] D115126: [LLDB] Add unit tests for Editline keyboard shortcuts

2021-12-09 Thread Neal via Phabricator via lldb-commits
nealsid added a comment.

Thanks, Pavel.




Comment at: lldb/unittests/Editline/EditlineTest.cpp:133-139
+  // We have to set the output stream we pass to Editline as not using
+  // buffered I/O.  Otherwise we are missing editline's output when we
+  // close the stream in the keybinding test (i.e. the EOF comes
+  // before data previously written to the stream by editline).  This
+  // behavior isn't as I understand the spec becuse fclose should
+  // flush the stream, but my best guess is that it's some unexpected
+  // interaction with stream I/O and ptys.

labath wrote:
> I find this hard to believe. I think it's more likely that this is working 
> around some problem in the test itself. I can't say what is the precise 
> problem without more investigation, but for example the synchronization 
> around testOutputBuffer seems inadequate. `GetEditlineOutput` could deadlock 
> if the read thread reads the newline before it reaches the `wait` call. It 
> also does not handle spurious wakeups. And the accesses to testOutputBuffer 
> are completely thread-unsafe.
I spent a few hours on this before sending the initial patch; it may be some 
interaction with the file APIs and the Psuedoterminal class we have in LLVM.  I 
could not debug anything it was doing that was leading to this behavior, but 
reliably saw EOF being sent before data that had been written to the stream.  I 
also tried various things like flushing it manually, which did not work, but 
sleeping before closing the secondary FD enabled all data to be read on the 
test side.  If you have some time, I'd be happy to have a gchat or screen 
sharing session and see if we can brainstorm something.

Regarding the synchronization, good call; I built on top of the existing 
threading, which did not require synchronizing reading the output of editline, 
because the actual output was never used.  Now, I just call provide a method to 
call thread::join for tests that need to read the output to ensure it's all 
been written.  



Comment at: lldb/unittests/Editline/EditlineTest.cpp:235
 
-  int ch;
+  char ch;
   while ((ch = fgetc(output_file)) != EOF) {

labath wrote:
> This isn't right. The return type of fgetc is deliberately not `char` so that 
> `EOF` does not conflict with an actual character.
Ah, yeah, I changed it back.  For some reason I thought EOF was sent as an 
actual EOF character like CTRL-D, not a special platform-specific integer.



Comment at: lldb/unittests/Editline/EditlineTest.cpp:345
+  // mapped back to a specific input.
+  const std::string testNumber;
+  // Whether this keyboard shortcut is only bound in multi-line mode.

labath wrote:
> You already have a const on the variable declaration. You don't need to put 
> one on every member as well.
I like const on the struct fields since it expresses the intent (a compile-time 
data structure) better, and, without it, if the array variable decl type was 
changed to remove the const, modifying the fields would be permitted.



Comment at: lldb/unittests/Editline/EditlineTest.cpp:352-359
+  // This is initialized to the keySequence by default, but gtest has
+  // some errors when the test name as created by the overloaded
+  // operator<< has embedded newlines.  This is even true when we
+  // specify a custom test name function, as we do below when we
+  // instantiate the test case.  In cases where the keyboard shortcut
+  // has a newline or carriage return, this field in the struct can be
+  // set to something that is printable.

labath wrote:
> Why not just do the replacements in operator<< ?
I started that approach, but doing it at compile time seems easier because the 
output can be matched to the specific test by looking through the table, 
and...it's less code at runtime :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115126

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


[Lldb-commits] [PATCH] D115126: [LLDB] Add unit tests for Editline keyboard shortcuts

2021-12-09 Thread Neal via Phabricator via lldb-commits
nealsid updated this revision to Diff 393228.
nealsid added a comment.

Remove extra header and using decl


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115126

Files:
  lldb/include/lldb/Host/Editline.h
  lldb/source/Host/common/Editline.cpp
  lldb/unittests/Editline/EditlineTest.cpp

Index: lldb/unittests/Editline/EditlineTest.cpp
===
--- lldb/unittests/Editline/EditlineTest.cpp
+++ lldb/unittests/Editline/EditlineTest.cpp
@@ -28,7 +28,10 @@
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/StringList.h"
 
+#define ESCAPE "\x1b"
+
 using namespace lldb_private;
+using namespace testing;
 
 namespace {
 const size_t TIMEOUT_MILLIS = 5000;
@@ -80,6 +83,8 @@
 
   void ConsumeAllOutput();
 
+  const std::string GetEditlineOutput();
+
 private:
   bool IsInputComplete(lldb_private::Editline *editline,
lldb_private::StringList &lines);
@@ -91,6 +96,7 @@
   int _pty_secondary_fd;
 
   std::unique_ptr _el_secondary_file;
+  std::stringstream testOutputBuffer;
 };
 
 EditlineAdapter::EditlineAdapter()
@@ -110,11 +116,21 @@
   EXPECT_THAT_ERROR(_pty.OpenSecondary(O_RDWR), llvm::Succeeded());
   _pty_secondary_fd = _pty.GetSecondaryFileDescriptor();
 
-  _el_secondary_file.reset(new FilePointer(fdopen(_pty_secondary_fd, "rw")));
+  _el_secondary_file.reset(new FilePointer(fdopen(_pty_secondary_fd, "w+")));
   EXPECT_FALSE(nullptr == *_el_secondary_file);
   if (*_el_secondary_file == nullptr)
 return;
 
+  // We have to set the output stream we pass to Editline as not using
+  // buffered I/O.  Otherwise we are missing editline's output when we
+  // close the stream in the keybinding test (i.e. the EOF comes
+  // before data previously written to the stream by editline).  This
+  // behavior isn't as I understand the spec becuse fclose should
+  // flush the stream, but my best guess is that it's some unexpected
+  // interaction with stream I/O and ptys.
+  EXPECT_EQ(setvbuf(*_el_secondary_file, nullptr, _IONBF, 0), 0)
+  << "Could not set editline output stream to use unbuffered I/O.";
+
   // Create an Editline instance.
   _editline_sp.reset(new lldb_private::Editline(
   "gtest editor", *_el_secondary_file, *_el_secondary_file,
@@ -204,6 +220,10 @@
   return (start_block_count > 0) && (brace_balance == 0);
 }
 
+const std::string EditlineAdapter::GetEditlineOutput() {
+  return testOutputBuffer.str();
+}
+
 void EditlineAdapter::ConsumeAllOutput() {
   FilePointer output_file(fdopen(_pty_primary_fd, "r"));
 
@@ -229,15 +249,15 @@
   break;
 }
 printf(" 0x%02x (%03d) (%s)\n", ch, ch, display_str);
-// putc(ch, stdout);
 #endif
+testOutputBuffer << (char)ch;
   }
 }
 
 class EditlineTestFixture : public ::testing::Test {
   SubsystemRAII subsystems;
   EditlineAdapter _el_adapter;
-  std::shared_ptr _sp_output_thread;
+  std::thread _sp_output_thread;
 
 public:
   static void SetUpTestCase() {
@@ -252,16 +272,17 @@
   return;
 
 // Dump output.
-_sp_output_thread =
-std::make_shared([&] { _el_adapter.ConsumeAllOutput(); });
+_sp_output_thread = std::thread([&] { _el_adapter.ConsumeAllOutput(); });
   }
 
-  void TearDown() override {
+  void EndOutputThread() {
 _el_adapter.CloseInput();
-if (_sp_output_thread)
-  _sp_output_thread->join();
+if (_sp_output_thread.joinable())
+  _sp_output_thread.join();
   }
 
+  void TearDown() override { EndOutputThread(); }
+
   EditlineAdapter &GetEditlineAdapter() { return _el_adapter; }
 };
 
@@ -309,4 +330,124 @@
   EXPECT_THAT(reported_lines, testing::ContainerEq(input_lines));
 }
 
+namespace lldb_private {
+
+// Parameter structure for parameterized tests.
+struct KeybindingTestValue {
+  // A number that is used to name the test, so test output can be
+  // mapped back to a specific input.
+  const std::string testNumber;
+  // Whether this keyboard shortcut is only bound in multi-line mode.
+  const bool multilineOnly;
+  // The actual key sequence.
+  const std::string keySequence;
+  // The command the key sequence is supposed to execute.
+  const std::string commandName;
+  // This is initialized to the keySequence by default, but gtest has
+  // some errors when the test name as created by the overloaded
+  // operator<< has embedded newlines.  This is even true when we
+  // specify a custom test name function, as we do below when we
+  // instantiate the test case.  In cases where the keyboard shortcut
+  // has a newline or carriage return, this field in the struct can be
+  // set to something that is printable.
+  const std::string &printableKeySequence = keySequence;
+};
+
+std::ostream &operator<<(std::ostream &os, const KeybindingTestValue &kbtv) {
+  return os << "{" << kbtv.printableKeySequence << "  =>  " << kbtv.commandName
+<< " (multiline only: " << kbtv.multilineOnly << ")}";
+}
+
+

[Lldb-commits] [PATCH] D115461: [lldb/Target] Refine source display warning for artificial locations (NFC)

2021-12-09 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added a reviewer: aprantl.
mib added a project: LLDB.
Herald added a subscriber: JDevlieghere.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This is a post-review update for D115313 , to 
rephrase source display
warning messages for artificial locations, making them more
understandable for the end-user.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115461

Files:
  lldb/source/Target/StackFrame.cpp
  lldb/test/API/source-manager/TestSourceManager.py


Index: lldb/test/API/source-manager/TestSourceManager.py
===
--- lldb/test/API/source-manager/TestSourceManager.py
+++ lldb/test/API/source-manager/TestSourceManager.py
@@ -276,7 +276,7 @@
 
 self.expect("run", RUN_SUCCEEDED,
 substrs=['stop reason = breakpoint', '%s:%d' % 
(src_file,0),
- 'Warning: the current PC is an artificial ',
- 'location in function '
- ])
+ 'Note: this address is compiler-generated code in 
'
+ 'function', 'that has no source code associated '
+ 'with it.'])
 
Index: lldb/source/Target/StackFrame.cpp
===
--- lldb/source/Target/StackFrame.cpp
+++ lldb/source/Target/StackFrame.cpp
@@ -1900,14 +1900,13 @@
 ConstString fn_name = m_sc.GetFunctionName();
 
 if (!fn_name.IsEmpty())
-  strm.Printf("Warning: the current PC is an artificial location "
-  "in function %s.",
-  fn_name.AsCString());
-else
   strm.Printf(
-  "Warning: the current PC is an artificial location "
-  "but lldb couldn't associate it with a function in %s.",
-  m_sc.line_entry.file.GetFilename().GetCString());
+  "Note: this address is compiler-generated code in function "
+  "%s that has no source code associated with it.",
+  fn_name.AsCString());
+else
+  strm.Printf("Note: this address is compiler-generated code that "
+  "has no source code associated with it.");
 strm.EOL();
   }
 }


Index: lldb/test/API/source-manager/TestSourceManager.py
===
--- lldb/test/API/source-manager/TestSourceManager.py
+++ lldb/test/API/source-manager/TestSourceManager.py
@@ -276,7 +276,7 @@
 
 self.expect("run", RUN_SUCCEEDED,
 substrs=['stop reason = breakpoint', '%s:%d' % (src_file,0),
- 'Warning: the current PC is an artificial ',
- 'location in function '
- ])
+ 'Note: this address is compiler-generated code in '
+ 'function', 'that has no source code associated '
+ 'with it.'])
 
Index: lldb/source/Target/StackFrame.cpp
===
--- lldb/source/Target/StackFrame.cpp
+++ lldb/source/Target/StackFrame.cpp
@@ -1900,14 +1900,13 @@
 ConstString fn_name = m_sc.GetFunctionName();
 
 if (!fn_name.IsEmpty())
-  strm.Printf("Warning: the current PC is an artificial location "
-  "in function %s.",
-  fn_name.AsCString());
-else
   strm.Printf(
-  "Warning: the current PC is an artificial location "
-  "but lldb couldn't associate it with a function in %s.",
-  m_sc.line_entry.file.GetFilename().GetCString());
+  "Note: this address is compiler-generated code in function "
+  "%s that has no source code associated with it.",
+  fn_name.AsCString());
+else
+  strm.Printf("Note: this address is compiler-generated code that "
+  "has no source code associated with it.");
 strm.EOL();
   }
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D114008: [formatters] Add a deque formatter for libstdcpp and fix the libcxx one

2021-12-09 Thread walter erquinigo via Phabricator via lldb-commits
wallace closed this revision.
wallace added a comment.

committed as 2ea3c8a50add5436cf939d59c3235408ca0255c1 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114008

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


[Lldb-commits] [PATCH] D115178: Unify libstdcpp and libcxx formatters for `std::optional`

2021-12-09 Thread Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcfb075089128: Unify libstdcpp and libcxx formatters for 
`std::optional` (authored by zrthxn, committed by Walter Erquinigo 
).

Changed prior to commit:
  https://reviews.llvm.org/D115178?vs=392308&id=393267#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115178

Files:
  lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/source/Plugins/Language/CPlusPlus/Generic.h
  lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
  lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.h

Index: lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.h
===
--- lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.h
+++ lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.h
@@ -45,6 +45,10 @@
 LibStdcppBitsetSyntheticFrontEndCreator(CXXSyntheticChildren *,
 lldb::ValueObjectSP);
 
+SyntheticChildrenFrontEnd *
+LibStdcppOptionalSyntheticFrontEndCreator(CXXSyntheticChildren *,
+  lldb::ValueObjectSP);
+
 SyntheticChildrenFrontEnd *
 LibStdcppVectorIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *,
 lldb::ValueObjectSP);
Index: lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp
===
--- lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-//===-- LibCxxOptional.cpp ===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "LibCxx.h"
-#include "lldb/DataFormatters/FormattersHelpers.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-namespace {
-
-class OptionalFrontEnd : public SyntheticChildrenFrontEnd {
-public:
-  OptionalFrontEnd(ValueObject &valobj) : SyntheticChildrenFrontEnd(valobj) {
-Update();
-  }
-
-  size_t GetIndexOfChildWithName(ConstString name) override {
-return formatters::ExtractIndexFromString(name.GetCString());
-  }
-
-  bool MightHaveChildren() override { return true; }
-  bool Update() override;
-  size_t CalculateNumChildren() override { return m_has_value ? 1U : 0U; }
-  ValueObjectSP GetChildAtIndex(size_t idx) override;
-
-private:
-  /// True iff the option contains a value.
-  bool m_has_value = false;
-};
-} // namespace
-
-bool OptionalFrontEnd::Update() {
-  ValueObjectSP engaged_sp(
-  m_backend.GetChildMemberWithName(ConstString("__engaged_"), true));
-
-  if (!engaged_sp)
-return false;
-
-  // __engaged_ is a bool flag and is true if the optional contains a value.
-  // Converting it to unsigned gives us a size of 1 if it contains a value
-  // and 0 if not.
-  m_has_value = engaged_sp->GetValueAsUnsigned(0) != 0;
-
-  return false;
-}
-
-ValueObjectSP OptionalFrontEnd::GetChildAtIndex(size_t idx) {
-  if (!m_has_value)
-return ValueObjectSP();
-
-  // __val_ contains the underlying value of an optional if it has one.
-  // Currently because it is part of an anonymous union GetChildMemberWithName()
-  // does not peer through and find it unless we are at the parent itself.
-  // We can obtain the parent through __engaged_.
-  ValueObjectSP val_sp(
-  m_backend.GetChildMemberWithName(ConstString("__engaged_"), true)
-  ->GetParent()
-  ->GetChildAtIndex(0, true)
-  ->GetChildMemberWithName(ConstString("__val_"), true));
-
-  if (!val_sp)
-return ValueObjectSP();
-
-  CompilerType holder_type = val_sp->GetCompilerType();
-
-  if (!holder_type)
-return ValueObjectSP();
-
-  return val_sp->Clone(ConstString("Value"));
-}
-
-SyntheticChildrenFrontEnd *
-formatters::LibcxxOptionalFrontEndCreator(CXXSyntheticChildren *,
-  lldb::ValueObjectSP valobj_sp) {
-  if (valobj_sp)
-return new OptionalFrontEnd(*valobj_sp);
-  return nullptr;
-}
Index: lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
===
--- lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -170,8 +170,8 @@
   lldb::ValueObjectSP);
 
 SyntheticChildrenFrontEnd *
-LibcxxOptionalFrontEndCreator(CXXSyntheticChildren *,
-  lldb::ValueObjectSP valobj_sp);
+LibcxxOptionalSyntheticFrontE

[Lldb-commits] [lldb] cfb0750 - Unify libstdcpp and libcxx formatters for `std::optional`

2021-12-09 Thread Walter Erquinigo via lldb-commits

Author: Alisamar Husain
Date: 2021-12-09T13:10:43-08:00
New Revision: cfb075089128b2e5918afd0ce21ec10bf455e5ab

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

LOG: Unify libstdcpp and libcxx formatters for `std::optional`

Reviewed By: wallace

Differential Revision: https://reviews.llvm.org/D115178

Added: 
lldb/source/Plugins/Language/CPlusPlus/Generic.h
lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp

Modified: 
lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.h

Removed: 
lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp



diff  --git a/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt 
b/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
index eb53649ab0ff9..125c12cfe4a56 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
+++ b/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
@@ -4,12 +4,12 @@ add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN
   CPlusPlusNameParser.cpp
   CxxStringTypes.cpp
   GenericBitset.cpp
+  GenericOptional.cpp
   LibCxx.cpp
   LibCxxAtomic.cpp
   LibCxxInitializerList.cpp
   LibCxxList.cpp
   LibCxxMap.cpp
-  LibCxxOptional.cpp
   LibCxxQueue.cpp
   LibCxxTuple.cpp
   LibCxxUnorderedMap.cpp

diff  --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 55b3af8123073..df61cc3853ebc 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -35,6 +35,7 @@
 #include "BlockPointer.h"
 #include "CPlusPlusNameParser.h"
 #include "CxxStringTypes.h"
+#include "Generic.h"
 #include "LibCxx.h"
 #include "LibCxxAtomic.h"
 #include "LibCxxVariant.h"
@@ -655,7 +656,7 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP 
cpp_category_sp) {
   "libc++ std::tuple synthetic children",
   ConstString("^std::__[[:alnum:]]+::tuple<.*>(( )?&)?$"),
   stl_synth_flags, true);
-  AddCXXSynthetic(cpp_category_sp, LibcxxOptionalFrontEndCreator,
+  AddCXXSynthetic(cpp_category_sp, LibcxxOptionalSyntheticFrontEndCreator,
   "libc++ std::optional synthetic children",
   ConstString("^std::__[[:alnum:]]+::optional<.+>(( )?&)?$"),
   stl_synth_flags, true);
@@ -772,7 +773,7 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP 
cpp_category_sp) {
 ConstString("^std::__[[:alnum:]]+::atomic<.+>$"),
 stl_summary_flags, true);
   AddCXXSummary(cpp_category_sp,
-lldb_private::formatters::LibcxxOptionalSummaryProvider,
+lldb_private::formatters::GenericOptionalSummaryProvider,
 "libc++ std::optional summary provider",
 ConstString("^std::__[[:alnum:]]+::optional<.+>(( )?&)?$"),
 stl_summary_flags, true);
@@ -918,11 +919,6 @@ static void 
LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
   SyntheticChildrenSP(new ScriptedSyntheticChildren(
   stl_deref_flags,
   "lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
-  cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
-  RegularExpression("^std::optional<.+>(( )?&)?$"),
-  SyntheticChildrenSP(new ScriptedSyntheticChildren(
-  stl_synth_flags,
-  "lldb.formatters.cpp.gnu_libstdcpp.StdOptionalSynthProvider")));
   cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
   RegularExpression("^std::multiset<.+> >(( )?&)?$"),
   SyntheticChildrenSP(new ScriptedSyntheticChildren(
@@ -946,11 +942,6 @@ static void 
LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
 
   stl_summary_flags.SetDontShowChildren(false);
   stl_summary_flags.SetSkipPointers(false);
-  cpp_category_sp->GetRegexTypeSummariesContainer()->Add(
-  RegularExpression("^std::optional<.+>(( )?&)?$"),
-  TypeSummaryImplSP(new ScriptSummaryFormat(
-  stl_summary_flags,
-  "lldb.formatters.cpp.gnu_libstdcpp.StdOptionalSummaryProvider")));
   cpp_category_sp->GetRegexTypeSummariesContainer()->Add(
   RegularExpression("^std::bitset<.+>(( )?&)?$"),
   TypeSummaryImplSP(
@@ -1031,6 +1022,12 @@ static void 
LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
   "std::bitset synthetic child", ConstString("^std::bitset<.+>(( )?&)?$"),
   stl_deref_flags, true);
 
+  AddCXXSynthetic(
+  cpp_category_sp,
+  lldb_private::formatters::LibStdcppOptionalSyntheticFrontEndCreator,
+  "std::optional synthetic chil

[Lldb-commits] [PATCH] D115178: Unify libstdcpp and libcxx formatters for `std::optional`

2021-12-09 Thread walter erquinigo via Phabricator via lldb-commits
wallace added a comment.

committed as cfb075089128b2e5918afd0ce21ec10bf455e5ab 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115178

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


[Lldb-commits] [PATCH] D114911: [lldb] Introduce a FreeBSDKernel plugin for vmcores

2021-12-09 Thread Michał Górny via Phabricator via lldb-commits
mgorny updated this revision to Diff 393276.
mgorny added a comment.

Add tests for other vmcores. Fix assert in arm64, and turn it into 
static_assert.


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

https://reviews.llvm.org/D114911

Files:
  lldb/cmake/modules/LLDBConfig.cmake
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/source/Plugins/Process/CMakeLists.txt
  lldb/source/Plugins/Process/FreeBSDKernel/CMakeLists.txt
  lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.cpp
  lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.h
  
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.cpp
  lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_arm64.h
  
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_i386.cpp
  lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_i386.h
  
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_x86_64.cpp
  
lldb/source/Plugins/Process/FreeBSDKernel/RegisterContextFreeBSDKernel_x86_64.h
  lldb/source/Plugins/Process/FreeBSDKernel/ThreadFreeBSDKernel.cpp
  lldb/source/Plugins/Process/FreeBSDKernel/ThreadFreeBSDKernel.h
  
lldb/test/API/functionalities/postmortem/FreeBSDKernel/TestFreeBSDKernelVMCore.py
  lldb/test/API/functionalities/postmortem/FreeBSDKernel/kernel-amd64.yaml
  lldb/test/API/functionalities/postmortem/FreeBSDKernel/kernel-arm64.yaml
  lldb/test/API/functionalities/postmortem/FreeBSDKernel/kernel-i386.yaml
  lldb/test/API/functionalities/postmortem/FreeBSDKernel/tools/README.rst
  lldb/test/API/functionalities/postmortem/FreeBSDKernel/tools/copy-sparse.py
  
lldb/test/API/functionalities/postmortem/FreeBSDKernel/tools/libfbsdvmcore-print-offsets.patch
  lldb/test/API/functionalities/postmortem/FreeBSDKernel/tools/test.script
  lldb/test/API/functionalities/postmortem/FreeBSDKernel/vmcore-amd64-full.bz2
  
lldb/test/API/functionalities/postmortem/FreeBSDKernel/vmcore-amd64-minidump.bz2
  
lldb/test/API/functionalities/postmortem/FreeBSDKernel/vmcore-arm64-minidump.bz2
  
lldb/test/API/functionalities/postmortem/FreeBSDKernel/vmcore-i386-minidump.bz2

Index: lldb/test/API/functionalities/postmortem/FreeBSDKernel/tools/test.script
===
--- /dev/null
+++ lldb/test/API/functionalities/postmortem/FreeBSDKernel/tools/test.script
@@ -0,0 +1,5 @@
+thread list
+register read pc
+bt
+p *(int*)&hz
+memory read &hz
Index: lldb/test/API/functionalities/postmortem/FreeBSDKernel/tools/libfbsdvmcore-print-offsets.patch
===
--- /dev/null
+++ lldb/test/API/functionalities/postmortem/FreeBSDKernel/tools/libfbsdvmcore-print-offsets.patch
@@ -0,0 +1,166 @@
+diff --git a/lib/fvc.c b/lib/fvc.c
+index e6b96c1..4033f78 100644
+--- a/lib/fvc.c
 b/lib/fvc.c
+@@ -297,6 +297,7 @@ fvc_read(fvc_t *kd, fvc_addr_t kva, void *buf, size_t len)
+ 			_fvc_syserr(kd, kd->program, "fvc_read");
+ 			break;
+ 		}
++		printf("%% RD: %zu %d\n", pa, cc);
+ 		/*
+ 		 * If ka_kvatop returns a bogus value or our core file is
+ 		 * truncated, we might wind up seeking beyond the end of the
+@@ -331,3 +332,8 @@ fvc_kerndisp(fvc_t *kd)
+ 
+ 	return (kd->arch->ka_kerndisp(kd));
+ }
++
++ssize_t xpread(int fd, void *buf, size_t count, off_t offset) {
++	printf("%% RD: %zu %zu\n", offset, count);
++	return pread(fd, buf, count, offset);
++}
+diff --git a/lib/fvc.h b/lib/fvc.h
+index 8680079..ff1e0f0 100644
+--- a/lib/fvc.h
 b/lib/fvc.h
+@@ -54,6 +54,8 @@ typedef unsigned char fvc_vm_prot_t;
+ #define	FVC_VM_PROT_WRITE		((fvc_vm_prot_t) 0x02)
+ #define	FVC_VM_PROT_EXECUTE		((fvc_vm_prot_t) 0x04)
+ 
++ssize_t xpread(int fd, void *buf, size_t count, off_t offset);
++
+ struct fvc_page {
+ 	unsigned int	kp_version;
+ 	fvc_addr_t	kp_paddr;
+diff --git a/lib/fvc_amd64.c b/lib/fvc_amd64.c
+index 4d27998..69f1807 100644
+--- a/lib/fvc_amd64.c
 b/lib/fvc_amd64.c
+@@ -205,7 +205,7 @@ _amd64_vatop(fvc_t *kd, fvc_addr_t va, off_t *pa)
+ 		_fvc_err(kd, kd->program, "_amd64_vatop: pdpe_pa not found");
+ 		goto invalid;
+ 	}
+-	if (pread(kd->pmfd, &pdpe, sizeof(pdpe), ofs) != sizeof(pdpe)) {
++	if (xpread(kd->pmfd, &pdpe, sizeof(pdpe), ofs) != sizeof(pdpe)) {
+ 		_fvc_syserr(kd, kd->program, "_amd64_vatop: read pdpe");
+ 		goto invalid;
+ 	}
+@@ -237,7 +237,7 @@ _amd64_vatop(fvc_t *kd, fvc_addr_t va, off_t *pa)
+ 		_fvc_syserr(kd, kd->program, "_amd64_vatop: pde_pa not found");
+ 		goto invalid;
+ 	}
+-	if (pread(kd->pmfd, &pde, sizeof(pde), ofs) != sizeof(pde)) {
++	if (xpread(kd->pmfd, &pde, sizeof(pde), ofs) != sizeof(pde)) {
+ 		_fvc_syserr(kd, kd->program, "_amd64_vatop: read pde");
+ 		goto invalid;
+ 	}
+@@ -269,7 +269,7 @@ _amd64_vatop(fvc_t *kd, fvc_addr_t va, off_t *pa)
+ 		_fvc_err(kd, kd->program, "_amd64_vatop: pte_pa not found");
+ 		goto invalid;
+ 	}
+-	if (pread(kd->pmfd, &pte, sizeof(pte), ofs) != sizeof(pte)) {
++	if (xp

[Lldb-commits] [PATCH] D115461: [lldb/Target] Refine source display warning for artificial locations (NFC)

2021-12-09 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

Thanks, I think this is much easier to understand!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115461

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


[Lldb-commits] [lldb] 20db8e0 - [lldb/Target] Refine source display warning for artificial locations (NFC)

2021-12-09 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2021-12-09T14:38:14-08:00
New Revision: 20db8e07f9d5e4378839602752099e0ff2f703a9

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

LOG: [lldb/Target] Refine source display warning for artificial locations (NFC)

This is a post-review update for D115313, to rephrase source display
warning messages for artificial locations, making them more
understandable for the end-user.

Differential Revision: https://reviews.llvm.org/D115461

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/source/Target/StackFrame.cpp
lldb/test/API/source-manager/TestSourceManager.py

Removed: 




diff  --git a/lldb/source/Target/StackFrame.cpp 
b/lldb/source/Target/StackFrame.cpp
index 8208288e15ef7..7b4295158425e 100644
--- a/lldb/source/Target/StackFrame.cpp
+++ b/lldb/source/Target/StackFrame.cpp
@@ -1900,14 +1900,13 @@ bool StackFrame::GetStatus(Stream &strm, bool 
show_frame_info, bool show_source,
 ConstString fn_name = m_sc.GetFunctionName();
 
 if (!fn_name.IsEmpty())
-  strm.Printf("Warning: the current PC is an artificial location "
-  "in function %s.",
-  fn_name.AsCString());
-else
   strm.Printf(
-  "Warning: the current PC is an artificial location "
-  "but lldb couldn't associate it with a function in %s.",
-  m_sc.line_entry.file.GetFilename().GetCString());
+  "Note: this address is compiler-generated code in function "
+  "%s that has no source code associated with it.",
+  fn_name.AsCString());
+else
+  strm.Printf("Note: this address is compiler-generated code that "
+  "has no source code associated with it.");
 strm.EOL();
   }
 }

diff  --git a/lldb/test/API/source-manager/TestSourceManager.py 
b/lldb/test/API/source-manager/TestSourceManager.py
index 15af2e46c29af..888174a62f19b 100644
--- a/lldb/test/API/source-manager/TestSourceManager.py
+++ b/lldb/test/API/source-manager/TestSourceManager.py
@@ -276,7 +276,7 @@ def test_artificial_source_location(self):
 
 self.expect("run", RUN_SUCCEEDED,
 substrs=['stop reason = breakpoint', '%s:%d' % 
(src_file,0),
- 'Warning: the current PC is an artificial ',
- 'location in function '
- ])
+ 'Note: this address is compiler-generated code in 
'
+ 'function', 'that has no source code associated '
+ 'with it.'])
 



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


[Lldb-commits] [PATCH] D115461: [lldb/Target] Refine source display warning for artificial locations (NFC)

2021-12-09 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG20db8e07f9d5: [lldb/Target] Refine source display warning 
for artificial locations (NFC) (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115461

Files:
  lldb/source/Target/StackFrame.cpp
  lldb/test/API/source-manager/TestSourceManager.py


Index: lldb/test/API/source-manager/TestSourceManager.py
===
--- lldb/test/API/source-manager/TestSourceManager.py
+++ lldb/test/API/source-manager/TestSourceManager.py
@@ -276,7 +276,7 @@
 
 self.expect("run", RUN_SUCCEEDED,
 substrs=['stop reason = breakpoint', '%s:%d' % 
(src_file,0),
- 'Warning: the current PC is an artificial ',
- 'location in function '
- ])
+ 'Note: this address is compiler-generated code in 
'
+ 'function', 'that has no source code associated '
+ 'with it.'])
 
Index: lldb/source/Target/StackFrame.cpp
===
--- lldb/source/Target/StackFrame.cpp
+++ lldb/source/Target/StackFrame.cpp
@@ -1900,14 +1900,13 @@
 ConstString fn_name = m_sc.GetFunctionName();
 
 if (!fn_name.IsEmpty())
-  strm.Printf("Warning: the current PC is an artificial location "
-  "in function %s.",
-  fn_name.AsCString());
-else
   strm.Printf(
-  "Warning: the current PC is an artificial location "
-  "but lldb couldn't associate it with a function in %s.",
-  m_sc.line_entry.file.GetFilename().GetCString());
+  "Note: this address is compiler-generated code in function "
+  "%s that has no source code associated with it.",
+  fn_name.AsCString());
+else
+  strm.Printf("Note: this address is compiler-generated code that "
+  "has no source code associated with it.");
 strm.EOL();
   }
 }


Index: lldb/test/API/source-manager/TestSourceManager.py
===
--- lldb/test/API/source-manager/TestSourceManager.py
+++ lldb/test/API/source-manager/TestSourceManager.py
@@ -276,7 +276,7 @@
 
 self.expect("run", RUN_SUCCEEDED,
 substrs=['stop reason = breakpoint', '%s:%d' % (src_file,0),
- 'Warning: the current PC is an artificial ',
- 'location in function '
- ])
+ 'Note: this address is compiler-generated code in '
+ 'function', 'that has no source code associated '
+ 'with it.'])
 
Index: lldb/source/Target/StackFrame.cpp
===
--- lldb/source/Target/StackFrame.cpp
+++ lldb/source/Target/StackFrame.cpp
@@ -1900,14 +1900,13 @@
 ConstString fn_name = m_sc.GetFunctionName();
 
 if (!fn_name.IsEmpty())
-  strm.Printf("Warning: the current PC is an artificial location "
-  "in function %s.",
-  fn_name.AsCString());
-else
   strm.Printf(
-  "Warning: the current PC is an artificial location "
-  "but lldb couldn't associate it with a function in %s.",
-  m_sc.line_entry.file.GetFilename().GetCString());
+  "Note: this address is compiler-generated code in function "
+  "%s that has no source code associated with it.",
+  fn_name.AsCString());
+else
+  strm.Printf("Note: this address is compiler-generated code that "
+  "has no source code associated with it.");
 strm.EOL();
   }
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D115313: [lldb/Target] Slide source display for artificial locations at function start

2021-12-09 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

In D115313#3182258 , @DavidSpickett 
wrote:

>> Thanks for clarifying @DavidSpickett ! I'll change the warning accordingly.
>
> Too many Davids :)

😅😅


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115313

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


[Lldb-commits] [PATCH] D115474: [lldb] Refactor & update of EditlineTest

2021-12-09 Thread Neal via Phabricator via lldb-commits
nealsid created this revision.
Herald added a subscriber: kristof.beyls.
nealsid requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This patch has a few minor cleanups and a restructuring of the
EditlineTest class:

Cleanups:

- Adds some comments to member variables
- Renames _editline_sp to _editline_up to reflect that it's a unique_ptr
- Create a debug macro for ConsumeAllOutput when EDITLINE_DUMP_OUTPUT is 1
- Rename _sp_output_thread to output_read_thread since it's no longer a shared 
pointer.

Restructuring:

- Merge EditlineAdapter and EditlineTestFixture.  EditLineAdapter is a

useful separation, but is only used by EditlineTestFixture.  It's a
perfectly fine pattern to put test state & helper methods in the test
fixture class, which is what this patch does.

- Remove FilePointer, which is an RAII class for FILE* pointers.  We

used it in two locations, which are to store FILE* variables for the
pty file handles.  In the primary case, the Pseudoterminal class already
closes the handle in it's destructor, so we don't need to (and were
actually causing a harmless double close of the handle), and in the
second case, we need to manage the handle close ourselves anyway,
because some tests need to close the handle manually as part of their
test case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115474

Files:
  lldb/unittests/Editline/EditlineTest.cpp

Index: lldb/unittests/Editline/EditlineTest.cpp
===
--- lldb/unittests/Editline/EditlineTest.cpp
+++ lldb/unittests/Editline/EditlineTest.cpp
@@ -12,6 +12,12 @@
 
 #define EDITLINE_TEST_DUMP_OUTPUT 0
 
+#if EDITLINE_TEST_DUMP_OUTPUT
+#define DEBUG_PRINT_EDITLINE_OUTPUT(ch) PrintEditlineOutput(ch)
+#else
+#define DEBUG_PRINT_EDITLINE_OUTPUT(...)
+#endif
+
 #include 
 #include 
 
@@ -37,40 +43,40 @@
 const size_t TIMEOUT_MILLIS = 5000;
 }
 
-class FilePointer {
+class EditlineTestFixture : public ::testing::Test {
 public:
-  FilePointer() = delete;
-
-  FilePointer(const FilePointer &) = delete;
+  static void SetUpTestCase() {
+// We need a TERM set properly for editline to work as expected.
+setenv("TERM", "vt100", 1);
+  }
 
-  FilePointer(FILE *file_p) : _file_p(file_p) {}
+  void SetUp() override;
 
-  ~FilePointer() {
-if (_file_p != nullptr) {
-  const int close_result = fclose(_file_p);
-  EXPECT_EQ(0, close_result);
-}
-  }
+protected:
+  // EditLine callback for us to tell whether input is complete or
+  // not.
+  bool IsInputComplete(lldb_private::Editline *editline,
+   lldb_private::StringList &lines);
 
-  operator FILE *() { return _file_p; }
+  // Helper debug method to escape & print libedit's output.
+  void PrintEditlineOutput(char ch);
 
-private:
-  FILE *_file_p;
-};
+  // This is normally executed during test case teardown, but some
+  // cases call it explicitly to ensure that all libeditoutput is read
+  // before verifying it.
+  void EndOutputThread() {
+CloseInput();
+if (output_read_thread.joinable())
+  output_read_thread.join();
+  }
 
-/**
- Wraps an Editline class, providing a simple way to feed
- input (as if from the keyboard) and receive output from Editline.
- */
-class EditlineAdapter {
-public:
-  EditlineAdapter();
+  void TearDown() override { EndOutputThread(); }
 
+  // Close the file pointer that libedit outputs to (which is our
+  // input).
   void CloseInput();
 
-  bool IsValid() const { return _editline_sp != nullptr; }
-
-  lldb_private::Editline &GetEditline() { return *_editline_sp; }
+  lldb_private::Editline &GetEditline() { return *_editline_up; }
 
   bool SendLine(const std::string &line);
 
@@ -86,216 +92,36 @@
   const std::string GetEditlineOutput();
 
 private:
-  bool IsInputComplete(lldb_private::Editline *editline,
-   lldb_private::StringList &lines);
+  // EditLine needs a filesystem for reading the history file.
+  SubsystemRAII subsystems;
 
-  std::unique_ptr _editline_sp;
+  // A thread to read libedit's stdout.
+  std::thread output_read_thread;
+  // The EditLine instance under test.
+  std::unique_ptr _editline_up;
 
+  // Pseudoterminal for libedit's stdout.
   PseudoTerminal _pty;
+  // Primary/secondary file descriptors for the pty.
   int _pty_primary_fd;
   int _pty_secondary_fd;
 
-  std::unique_ptr _el_secondary_file;
+  // A FILE* stream that is passed to libedit for stdout.
+  FILE *_el_secondary_file;
+  // The buffer the thread above stores libedit's output into.
   std::stringstream testOutputBuffer;
 };
 
-EditlineAdapter::EditlineAdapter()
-: _editline_sp(), _pty(), _pty_primary_fd(-1), _pty_secondary_fd(-1),
-  _el_secondary_file() {
-  lldb_private::Status error;
-
-  // Open the first primary pty available.
-  EXPECT_THAT_ERROR(_pty.OpenFirstAvailablePrimary(O_RDWR), llvm::Succeeded());
-
-  // Grab the primary fd.  This is a file descriptor we 

[Lldb-commits] [PATCH] D115482: [lldb] Update the PDB tests to pass with the VS2019 toolset

2021-12-09 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova created this revision.
stella.stamenova requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The pdb lldb tests do not work correctly with both the VS2019 and VS2017 
toolsets at the moment. This change updates several of the tests to work with 
both toolsets. Unfortunately, this makes the tests suboptimal for both 
toolsets, but we can update them to be better for VS2019 once we officially 
drop VS2017. This change is meant to bridge the gap until the update happens, 
so that the buildbots can work with either toolset.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115482

Files:
  lldb/test/Shell/SymbolFile/PDB/ast-restore.test
  lldb/test/Shell/SymbolFile/PDB/class-layout.test
  lldb/test/Shell/SymbolFile/PDB/enums-layout.test
  lldb/test/Shell/SymbolFile/PDB/typedefs.test
  lldb/test/Shell/SymbolFile/PDB/variables.test

Index: lldb/test/Shell/SymbolFile/PDB/variables.test
===
--- lldb/test/Shell/SymbolFile/PDB/variables.test
+++ lldb/test/Shell/SymbolFile/PDB/variables.test
@@ -51,7 +51,7 @@
 FUNC-MAIN-NEXT: Variable{{.*}}, name = "a"
 FUNC-MAIN-SAME: scope = local
 
-FUNC-CONSTRUCTOR:  Function{{.*}}, mangled = ??0Class@@QEAA@H@Z
+FUNC-CONSTRUCTOR:  Function{{.*}}, {{(de)?}}mangled = {{.*}}{{(Class::)?}}Class{{.*}}
 FUNC-CONSTRUCTOR-NEXT:   Block
 FUNC-CONSTRUCTOR-NEXT: Variable{{.*}}, name = "this"
 FUNC-CONSTRUCTOR-SAME: scope = parameter
@@ -59,7 +59,7 @@
 FUNC-CONSTRUCTOR-NEXT: Variable{{.*}}, name = "a"
 FUNC-CONSTRUCTOR-SAME: scope = parameter
 
-FUNC-MEMBER:  Function{{.*}}, mangled = ?Func@Class@@QEAAXXZ
+FUNC-MEMBER:  Function{{.*}}, {{(de)?}}mangled = {{.*}}{{(Class::)?}}Func{{.*}}
 FUNC-MEMBER-NEXT:   Block
 FUNC-MEMBER-NEXT: Variable{{.*}}, name = "this"
 FUNC-MEMBER-SAME: scope = parameter
Index: lldb/test/Shell/SymbolFile/PDB/typedefs.test
===
--- lldb/test/Shell/SymbolFile/PDB/typedefs.test
+++ lldb/test/Shell/SymbolFile/PDB/typedefs.test
@@ -17,7 +17,6 @@
 CHECK-DAG: name = "char16_t", size = 2, compiler_type = {{.*}} char16_t
 CHECK-DAG: Type{{.*}} , name = "unsigned long", size = 4, compiler_type = {{.*}} unsigned long
 CHECK-DAG: Type{{.*}} , size = 40, compiler_type = {{.*}} unsigned long[10]
-CHECK-DAG: Type{{.*}} , name = "ULongArrayTypedef", compiler_type = {{.*}} typedef ULongArrayTypedef
 
 ; Note: compiler_type of `long double` is represented by the one for `double`
 CHECK-DAG: Type{{.*}} , name = "double", size = 8, compiler_type = {{.*}} double
Index: lldb/test/Shell/SymbolFile/PDB/enums-layout.test
===
--- lldb/test/Shell/SymbolFile/PDB/enums-layout.test
+++ lldb/test/Shell/SymbolFile/PDB/enums-layout.test
@@ -10,35 +10,35 @@
 ; FIXME: PDB does not have information about scoped enumeration (Enum class) so the  
 ; compiler type used is the same as the one for unscoped enumeration.
 
-ENUM:  Type{{.*}} , name = "Enum", size = 4, decl = simpletypestest.cpp:19, compiler_type = {{.*}} enum Enum {
+ENUM:  Type{{.*}} , name = "Enum", size = 4, decl = {{[Ss]}}imple{{[Tt]}}ypes{{[Tt]}}est.cpp:19, compiler_type = {{.*}} enum Enum {
 ENUM_NEXT:RED,
 ENUM_NEXT:GREEN,
 ENUM_NEXT:BLUE
 ENUM_NEXT:}
 
-ENUM_CONST:  Type{{.*}} , name = "EnumConst", size = 4,  decl = simpletypestest.cpp:22, compiler_type = {{.*}} enum EnumConst {
+ENUM_CONST:  Type{{.*}} , name = "EnumConst", size = 4,  decl = {{[Ss]}}imple{{[Tt]}}ypes{{[Tt]}}est.cpp:22, compiler_type = {{.*}} enum EnumConst {
 ENUM_CONST-NEXT:LOW,
 ENUM_CONST-NEXT:NORMAL,
 ENUM_CONST-NEXT:HIGH
 ENUM_CONST-NEXT:}
 
-ENUM_EMPTY:  Type{{.*}} , name = "EnumEmpty", size = 4,  decl = simpletypestest.cpp:25, compiler_type = {{.*}} enum EnumEmpty {
+ENUM_EMPTY:  Type{{.*}} , name = "EnumEmpty", size = 4,  decl = {{[Ss]}}imple{{[Tt]}}ypes{{[Tt]}}est.cpp:25, compiler_type = {{.*}} enum EnumEmpty {
 ENUM_EMPTY-NEXT:}
 
-ENUM_UCHAR:  Type{{.*}} , name = "EnumUChar", size = 1,  decl = simpletypestest.cpp:28, compiler_type = {{.*}} enum EnumUChar {
+ENUM_UCHAR:  Type{{.*}} , name = "EnumUChar", size = 1,  decl = {{[Ss]}}imple{{[Tt]}}ypes{{[Tt]}}est.cpp:28, compiler_type = {{.*}} enum EnumUChar {
 ENUM_UCHAR-NEXT:ON,
 ENUM_UCHAR-NEXT:OFF,
 ENUM_UCHAR-NEXT:AUTO
 ENUM_UCHAR-NEXT:}
 
 ; Note that `enum EnumClass` is tested instead of `enum class EnumClass`
-ENUM_CLASS:  Type{{.*}} , name = "EnumClass", size = 4,  decl = simpletypestest.cpp:32, compiler_type = {{.*}} enum EnumClass {
+ENUM_CLASS:  Type{{.*}} , name = "EnumClass", size = 4,  decl = {{[Ss]}}imple{{[Tt]}}ypes{{[Tt]}}est.cpp:32, compiler_type = {{.*}} enum EnumClass {
 ENUM_CLASS-NEXT:YES,
 ENUM_CLASS-NEXT:NO,
 ENUM_CLASS-NE

[Lldb-commits] [PATCH] D115482: [lldb] Update the PDB tests to pass with the VS2019 toolset

2021-12-09 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added inline comments.
Herald added a subscriber: JDevlieghere.



Comment at: lldb/test/Shell/SymbolFile/PDB/enums-layout.test:13
 
-ENUM:  Type{{.*}} , name = "Enum", size = 4, decl = 
simpletypestest.cpp:19, compiler_type = {{.*}} enum Enum {
+ENUM:  Type{{.*}} , name = "Enum", size = 4, decl = 
{{[Ss]}}imple{{[Tt]}}ypes{{[Tt]}}est.cpp:19, compiler_type = {{.*}} enum Enum {
 ENUM_NEXT:RED,

This is particularly absurd. VS2017 toolset does not capitalize the name of the 
file, but VS2019 toolset does.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115482

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


[Lldb-commits] [PATCH] D115308: [LLDB] Uniquify Type in type list.

2021-12-09 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik added a comment.

I would also like to know where this duplicate insertion is happening. Can you 
walk us through the steps that lead to the duplicate entries? thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115308

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


[Lldb-commits] [lldb] 223e8ca - Set a default number of address bits on Darwin arm64 systems

2021-12-09 Thread Jason Molenda via lldb-commits

Author: Jason Molenda
Date: 2021-12-09T22:53:01-08:00
New Revision: 223e8ca02616dd9353da230d95589954927025c9

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

LOG: Set a default number of address bits on Darwin arm64 systems

With arm64e ARMv8.3 pointer authentication, lldb needs to know how
many bits are used for addressing and how many are used for pointer
auth signing.  This should be determined dynamically from the inferior
system / corefile, but there are some workflows where it still isn't
recorded and we fall back on a default value that is correct on some
Darwin environments.

This patch also explicitly sets the vendor of mach-o binaries to
Apple, so we select an Apple ABI instead of a random other ABI.

It adds a function pointer formatter for systems where pointer
authentication is in use, and we can strip the ptrauth bits off
of the function pointer address and get a different value that
points to an actual symbol.

Differential Revision: https://reviews.llvm.org/D115431
rdar://84644661

Added: 
lldb/test/API/macosx/corefile-default-ptrauth/Makefile
lldb/test/API/macosx/corefile-default-ptrauth/TestCorefileDefaultPtrauth.py
lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
lldb/test/API/macosx/corefile-default-ptrauth/main.c

Modified: 
lldb/source/DataFormatters/CXXFunctionPointer.cpp
lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Utility/ArchSpec.cpp

Removed: 




diff  --git a/lldb/source/DataFormatters/CXXFunctionPointer.cpp 
b/lldb/source/DataFormatters/CXXFunctionPointer.cpp
index 3b7b0bc27cf81..d7df280e56efb 100644
--- a/lldb/source/DataFormatters/CXXFunctionPointer.cpp
+++ b/lldb/source/DataFormatters/CXXFunctionPointer.cpp
@@ -9,6 +9,7 @@
 #include "lldb/DataFormatters/CXXFunctionPointer.h"
 
 #include "lldb/Core/ValueObject.h"
+#include "lldb/Target/ABI.h"
 #include "lldb/Target/SectionLoadList.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Utility/Stream.h"
@@ -38,8 +39,34 @@ bool 
lldb_private::formatters::CXXFunctionPointerSummaryProvider(
   Address so_addr;
   Target *target = exe_ctx.GetTargetPtr();
   if (target && !target->GetSectionLoadList().IsEmpty()) {
-if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address,
-so_addr)) {
+target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address,
+so_addr);
+if (so_addr.GetSection() == nullptr) {
+  // If we have an address that doesn't correspond to any symbol,
+  // it might have authentication bits.  Strip them & see if it
+  // now points to a symbol -- if so, do the SymbolContext lookup
+  // based on the stripped address.
+  // If we find a symbol with the ptrauth bits stripped, print the
+  // raw value into the stream, and replace the Address with the
+  // one that points to a symbol for a fuller description.
+  if (Process *process = exe_ctx.GetProcessPtr()) {
+if (ABISP abi_sp = process->GetABI()) {
+  addr_t fixed_addr = abi_sp->FixCodeAddress(func_ptr_address);
+  if (fixed_addr != func_ptr_address) {
+Address test_address;
+test_address.SetLoadAddress(fixed_addr, target);
+if (test_address.GetSection() != nullptr) {
+  int addrsize = 
target->GetArchitecture().GetAddressByteSize();
+  sstr.Printf("actual=0x%*.*" PRIx64 " ", addrsize * 2,
+  addrsize * 2, fixed_addr);
+  so_addr = test_address;
+}
+  }
+}
+  }
+}
+
+if (so_addr.IsValid()) {
   so_addr.Dump(&sstr, exe_ctx.GetBestExecutionContextScope(),
Address::DumpStyleResolvedDescription,
Address::DumpStyleSectionNameOffset);

diff  --git a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp 
b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
index ccfbeec3d5891..804532acf9f7d 100644
--- a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
+++ b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
@@ -817,6 +817,16 @@ ValueObjectSP ABIMacOSX_arm64::GetReturnValueObjectImpl(
 
 lldb::addr_t ABIMacOSX_arm64::FixAddress(addr_t pc, addr_t mask) {
   lldb::addr_t pac_sign_extension = 0x0080ULL;
+  // Darwin systems originally couldn't determine the proper value
+  // dynamically, so the most common value was hardcoded.  This has
+  // largely been cleaned up, but there are still a handful of
+  // environments tha

[Lldb-commits] [PATCH] D115431: Set a default number of addressing bits for Darwin arm64 systems

2021-12-09 Thread Jason Molenda via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG223e8ca02616: Set a default number of address bits on Darwin 
arm64 systems (authored by jasonmolenda).

Changed prior to commit:
  https://reviews.llvm.org/D115431?vs=393213&id=393378#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115431

Files:
  lldb/source/DataFormatters/CXXFunctionPointer.cpp
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Utility/ArchSpec.cpp
  lldb/test/API/macosx/corefile-default-ptrauth/Makefile
  lldb/test/API/macosx/corefile-default-ptrauth/TestCorefileDefaultPtrauth.py
  lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
  lldb/test/API/macosx/corefile-default-ptrauth/main.c

Index: lldb/test/API/macosx/corefile-default-ptrauth/main.c
===
--- /dev/null
+++ lldb/test/API/macosx/corefile-default-ptrauth/main.c
@@ -0,0 +1,6 @@
+int main();
+int (*fmain)() = main;
+int main () {
+  return fmain();
+}
+
Index: lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
===
--- /dev/null
+++ lldb/test/API/macosx/corefile-default-ptrauth/create-corefile.c
@@ -0,0 +1,131 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+// Given an executable binary with 
+//   "fmain" (a function pointer to main)
+//   "main"
+// symbols, create a fake arm64e corefile that
+// contains a memory segment for the fmain 
+// function pointer, with the value of the 
+// address of main() with ptrauth bits masked on.
+//
+// The corefile does not include the "addrable bits"
+// LC_NOTE, so lldb will need to fall back on its 
+// default value from the Darwin arm64 ABI.
+
+int main(int argc, char **argv)
+{
+  if (argc != 3) {
+fprintf (stderr, "usage: %s executable-binary output-file\n", argv[0]);
+exit(1);
+  }
+  FILE *exe = fopen(argv[1], "r");
+  if (!exe) {
+fprintf (stderr, "Unable to open executable %s for reading\n", argv[1]);
+exit(1);
+  }
+  FILE *out = fopen(argv[2], "w");
+  if (!out) {
+fprintf (stderr, "Unable to open %s for writing\n", argv[2]);
+exit(1);
+  }
+
+  char buf[PATH_MAX + 6];
+  sprintf (buf, "nm '%s'", argv[1]);
+  FILE *nm = popen(buf, "r");
+  if (!nm) {
+fprintf (stderr, "Unable to run nm on '%s'", argv[1]);
+exit (1);
+  }
+  uint64_t main_addr = 0;
+  uint64_t fmain_addr = 0;
+  while (fgets (buf, sizeof(buf), nm)) {
+if (strstr (buf, "_fmain")) {
+  fmain_addr = strtoul (buf, NULL, 16);
+}
+if (strstr (buf, "_main")) {
+  main_addr = strtoul (buf, NULL, 16);
+}
+  }
+  pclose (nm);
+
+  if (main_addr == 0 || fmain_addr == 0) {
+fprintf(stderr, "Unable to find address of main or fmain in %s.\n",
+argv[1]);
+exit (1);
+  }
+
+  // Write out a corefile with contents in this order:
+  //1. mach header
+  //2. LC_THREAD load command
+  //3. LC_SEGMENT_64 load command
+  //4. memory segment contents
+
+  // struct thread_command {
+  //   uint32_tcmd;
+  //   uint32_tcmdsize;
+  //   uint32_t flavor  
+  //   uint32_t count   
+  //   struct XXX_thread_state state
+  int size_of_thread_cmd = 4 + 4 + 4 + 4 + sizeof (arm_thread_state64_t);
+
+  struct mach_header_64 mh;
+  mh.magic = 0xfeedfacf;
+  mh.cputype = CPU_TYPE_ARM64;
+  mh.cpusubtype = CPU_SUBTYPE_ARM64E;
+  mh.filetype = MH_CORE;
+  mh.ncmds = 2; // LC_THREAD, LC_SEGMENT_64
+  mh.sizeofcmds = size_of_thread_cmd + sizeof(struct segment_command_64);
+  mh.flags = 0;
+  mh.reserved = 0;
+
+  fwrite(&mh, sizeof (mh), 1, out);
+
+  struct segment_command_64 seg;
+  seg.cmd = LC_SEGMENT_64;
+  seg.cmdsize = sizeof(seg);
+  memset (&seg.segname, 0, 16);
+  seg.vmaddr = fmain_addr;
+  seg.vmsize = 8;
+  // Offset to segment contents
+  seg.fileoff = sizeof (mh) + size_of_thread_cmd + sizeof(seg);
+  seg.filesize = 8;
+  seg.maxprot = 3;
+  seg.initprot = 3;
+  seg.nsects = 0;
+  seg.flags = 0;
+
+  fwrite (&seg, sizeof (seg), 1, out);
+
+  uint32_t cmd = LC_THREAD;
+  fwrite (&cmd, sizeof (cmd), 1, out);
+  uint32_t cmdsize = size_of_thread_cmd;
+  fwrite (&cmdsize, sizeof (cmdsize), 1, out);
+  uint32_t flavor = ARM_THREAD_STATE64;
+  fwrite (&flavor, sizeof (flavor), 1, out);
+  // count is number of uint32_t's of the register context
+  uint32_t count = sizeof (arm_thread_state64_t) / 4;
+  fwrite (&count, sizeof (count), 1, out);
+  arm_thread_state64_t regstate;
+  memset (®state, 0, sizeof (regstate));
+  fwrite (®state, sizeof (regstate), 1, out);
+
+
+  // Or together a random PAC value from a system using 39 bits 
+  // of addressing with the address of main()