[Lldb-commits] [PATCH] D157160: Surface error messages from the DebugSymbols DBGShellCommands external agent; add logging for LC_NOTEs in Mach-O corefiles

2023-08-08 Thread Jason Molenda via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1290869ef2f7: Show error messages from DebugSymbols 
DBGShellCommand agent (authored by jasonmolenda).

Changed prior to commit:
  https://reviews.llvm.org/D157160?vs=548015=548409#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157160

Files:
  lldb/source/Core/DynamicLoader.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Symbol/LocateSymbolFileMacOSX.cpp

Index: lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
===
--- lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
+++ lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
@@ -330,7 +330,8 @@
 
 static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
 ModuleSpec _spec,
-Status ) {
+Status ,
+const std::string ) {
   Log *log = GetLog(LLDBLog::Host);
   bool success = false;
   if (uuid_dict != NULL && CFGetTypeID(uuid_dict) == CFDictionaryGetTypeID()) {
@@ -342,7 +343,10 @@
CFSTR("DBGError"));
 if (cf_str && CFGetTypeID(cf_str) == CFStringGetTypeID()) {
   if (CFCString::FileSystemRepresentation(cf_str, str)) {
-error.SetErrorString(str);
+std::string errorstr = command;
+errorstr += ":\n";
+errorstr += str;
+error.SetErrorString(errorstr);
   }
 }
 
@@ -652,7 +656,8 @@
 CFCString uuid_cfstr(uuid_str.c_str());
 CFDictionaryRef uuid_dict =
 (CFDictionaryRef)CFDictionaryGetValue(plist.get(), uuid_cfstr.get());
-return GetModuleSpecInfoFromUUIDDictionary(uuid_dict, module_spec, error);
+return GetModuleSpecInfoFromUUIDDictionary(uuid_dict, module_spec, error,
+   command.GetData());
   }
 
   if (const CFIndex num_values = ::CFDictionaryGetCount(plist.get())) {
@@ -661,13 +666,14 @@
 ::CFDictionaryGetKeysAndValues(plist.get(), NULL,
(const void **)[0]);
 if (num_values == 1) {
-  return GetModuleSpecInfoFromUUIDDictionary(values[0], module_spec, error);
+  return GetModuleSpecInfoFromUUIDDictionary(values[0], module_spec, error,
+ command.GetData());
 }
 
 for (CFIndex i = 0; i < num_values; ++i) {
   ModuleSpec curr_module_spec;
   if (GetModuleSpecInfoFromUUIDDictionary(values[i], curr_module_spec,
-  error)) {
+  error, command.GetData())) {
 if (module_spec.GetArchitecture().IsCompatibleMatch(
 curr_module_spec.GetArchitecture())) {
   module_spec = curr_module_spec;
Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5414,6 +5414,8 @@
 
 std::string ObjectFileMachO::GetIdentifierString() {
   std::string result;
+  Log *log(
+  GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
   ModuleSP module_sp(GetModule());
   if (module_sp) {
 std::lock_guard guard(module_sp->GetMutex());
@@ -5449,6 +5451,8 @@
 result = buf;
 if (buf)
   free(buf);
+LLDB_LOGF(log, "LC_NOTE 'kern ver str' found with text '%s'",
+  result.c_str());
 return result;
   }
 }
@@ -5472,6 +5476,7 @@
   buf) == ident_command.cmdsize) {
   buf[ident_command.cmdsize - 1] = '\0';
   result = buf;
+  LLDB_LOGF(log, "LC_IDENT found with text '%s'", result.c_str());
 }
 if (buf)
   free(buf);
@@ -5484,6 +5489,7 @@
 
 addr_t ObjectFileMachO::GetAddressMask() {
   addr_t mask = 0;
+  Log *log(GetLog(LLDBLog::Process));
   ModuleSP module_sp(GetModule());
   if (module_sp) {
 std::lock_guard guard(module_sp->GetMutex());
@@ -5511,6 +5517,10 @@
   if (num_addr_bits != 0) {
 mask = ~((1ULL << num_addr_bits) - 1);
   }
+  LLDB_LOGF(log,
+"LC_NOTE 'addrable bits' found, value %d bits, "
+"mask 0x%" PRIx64,
+num_addr_bits, mask);
   break;
 }
   }
@@ -5526,6 +5536,8 @@
 bool _is_offset,

[Lldb-commits] [PATCH] D157160: Surface error messages from the DebugSymbols DBGShellCommands external agent; add logging for LC_NOTEs in Mach-O corefiles

2023-08-08 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: lldb/source/Core/DynamicLoader.cpp:241-242
+ error.AsCString("")[0] != '\0') {
+Stream  = target.GetDebugger().GetErrorStream();
+s << error.AsCString();
   }

If you don't need the Stream anymore you could do 

```
target.GetDebugger().GetErrorStream() << error.AsCString();
```



Comment at: lldb/source/Core/DynamicLoader.cpp:273-277
   LLDB_LOGF(log,
 "DynamicLoader::LoadBinaryWithUUIDAndAddress Loading "
-"binary UUID %s at %s 0x%" PRIx64,
-uuid.GetAsString().c_str(),
+"binary %s UUID %s at %s 0x%" PRIx64,
+name.str().c_str(), uuid.GetAsString().c_str(),
 value_is_offset ? "offset" : "address", value);

LLDB_LOG could simplify this a lot ;-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157160

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


[Lldb-commits] [PATCH] D157160: Surface error messages from the DebugSymbols DBGShellCommands external agent; add logging for LC_NOTEs in Mach-O corefiles

2023-08-07 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda updated this revision to Diff 548015.
jasonmolenda added a comment.

Update patch to send these error messages to the ErrorStream not OutputStream.  
Also change LocateSymbolFileMacOSX.cpp so the full command that was used to 
find the binary is included in the error message, to make it clearer exactly 
where the error message originated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157160

Files:
  lldb/source/Core/DynamicLoader.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Symbol/LocateSymbolFileMacOSX.cpp

Index: lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
===
--- lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
+++ lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
@@ -330,7 +330,8 @@
 
 static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
 ModuleSpec _spec,
-Status ) {
+Status ,
+const std::string ) {
   Log *log = GetLog(LLDBLog::Host);
   bool success = false;
   if (uuid_dict != NULL && CFGetTypeID(uuid_dict) == CFDictionaryGetTypeID()) {
@@ -342,7 +343,10 @@
CFSTR("DBGError"));
 if (cf_str && CFGetTypeID(cf_str) == CFStringGetTypeID()) {
   if (CFCString::FileSystemRepresentation(cf_str, str)) {
-error.SetErrorString(str);
+std::string errorstr = command;
+errorstr += ":\n";
+errorstr += str;
+error.SetErrorString(errorstr);
   }
 }
 
@@ -652,7 +656,8 @@
 CFCString uuid_cfstr(uuid_str.c_str());
 CFDictionaryRef uuid_dict =
 (CFDictionaryRef)CFDictionaryGetValue(plist.get(), uuid_cfstr.get());
-return GetModuleSpecInfoFromUUIDDictionary(uuid_dict, module_spec, error);
+return GetModuleSpecInfoFromUUIDDictionary(uuid_dict, module_spec, error,
+   command.GetData());
   }
 
   if (const CFIndex num_values = ::CFDictionaryGetCount(plist.get())) {
@@ -661,13 +666,14 @@
 ::CFDictionaryGetKeysAndValues(plist.get(), NULL,
(const void **)[0]);
 if (num_values == 1) {
-  return GetModuleSpecInfoFromUUIDDictionary(values[0], module_spec, error);
+  return GetModuleSpecInfoFromUUIDDictionary(values[0], module_spec, error,
+ command.GetData());
 }
 
 for (CFIndex i = 0; i < num_values; ++i) {
   ModuleSpec curr_module_spec;
   if (GetModuleSpecInfoFromUUIDDictionary(values[i], curr_module_spec,
-  error)) {
+  error, command.GetData())) {
 if (module_spec.GetArchitecture().IsCompatibleMatch(
 curr_module_spec.GetArchitecture())) {
   module_spec = curr_module_spec;
Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5414,6 +5414,8 @@
 
 std::string ObjectFileMachO::GetIdentifierString() {
   std::string result;
+  Log *log(
+  GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
   ModuleSP module_sp(GetModule());
   if (module_sp) {
 std::lock_guard guard(module_sp->GetMutex());
@@ -5449,6 +5451,8 @@
 result = buf;
 if (buf)
   free(buf);
+LLDB_LOGF(log, "LC_NOTE 'kern ver str' found with text '%s'",
+  result.c_str());
 return result;
   }
 }
@@ -5472,6 +5476,7 @@
   buf) == ident_command.cmdsize) {
   buf[ident_command.cmdsize - 1] = '\0';
   result = buf;
+  LLDB_LOGF(log, "LC_IDENT found with text '%s'", result.c_str());
 }
 if (buf)
   free(buf);
@@ -5484,6 +5489,7 @@
 
 addr_t ObjectFileMachO::GetAddressMask() {
   addr_t mask = 0;
+  Log *log(GetLog(LLDBLog::Process));
   ModuleSP module_sp(GetModule());
   if (module_sp) {
 std::lock_guard guard(module_sp->GetMutex());
@@ -5511,6 +5517,10 @@
   if (num_addr_bits != 0) {
 mask = ~((1ULL << num_addr_bits) - 1);
   }
+  LLDB_LOGF(log,
+"LC_NOTE 'addrable bits' found, value %d bits, "
+"mask 0x%" PRIx64,
+num_addr_bits, mask);
   break;
 }
   }
@@ -5526,6 +5536,8 @@
 

[Lldb-commits] [PATCH] D157160: Surface error messages from the DebugSymbols DBGShellCommands external agent; add logging for LC_NOTEs in Mach-O corefiles

2023-08-07 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added inline comments.



Comment at: lldb/source/Core/DynamicLoader.cpp:241-243
+Stream  = target.GetDebugger().GetOutputStream();
+s.Printf("Tried DBGShellCommands cmd, got error: %s\n",
+ error.AsCString());

JDevlieghere wrote:
> Shouldn't this be the error stream?
Ah good suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157160

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


[Lldb-commits] [PATCH] D157160: Surface error messages from the DebugSymbols DBGShellCommands external agent; add logging for LC_NOTEs in Mach-O corefiles

2023-08-07 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda updated this revision to Diff 548009.
jasonmolenda added a comment.

fix typeo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157160

Files:
  lldb/source/Core/DynamicLoader.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5414,6 +5414,8 @@
 
 std::string ObjectFileMachO::GetIdentifierString() {
   std::string result;
+  Log *log(
+  GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
   ModuleSP module_sp(GetModule());
   if (module_sp) {
 std::lock_guard guard(module_sp->GetMutex());
@@ -5449,6 +5451,8 @@
 result = buf;
 if (buf)
   free(buf);
+LLDB_LOGF(log, "LC_NOTE 'kern ver str' found with text '%s'",
+  result.c_str());
 return result;
   }
 }
@@ -5472,6 +5476,7 @@
   buf) == ident_command.cmdsize) {
   buf[ident_command.cmdsize - 1] = '\0';
   result = buf;
+  LLDB_LOGF(log, "LC_IDENT found with text '%s'", result.c_str());
 }
 if (buf)
   free(buf);
@@ -5484,6 +5489,7 @@
 
 addr_t ObjectFileMachO::GetAddressMask() {
   addr_t mask = 0;
+  Log *log(GetLog(LLDBLog::Process));
   ModuleSP module_sp(GetModule());
   if (module_sp) {
 std::lock_guard guard(module_sp->GetMutex());
@@ -5511,6 +5517,10 @@
   if (num_addr_bits != 0) {
 mask = ~((1ULL << num_addr_bits) - 1);
   }
+  LLDB_LOGF(log,
+"LC_NOTE 'addrable bits' found, value %d bits, "
+"mask 0x%" PRIx64,
+num_addr_bits, mask);
   break;
 }
   }
@@ -5526,6 +5536,8 @@
 bool _is_offset,
 UUID ,
 ObjectFile::BinaryType ) {
+  Log *log(
+  GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
   value = LLDB_INVALID_ADDRESS;
   value_is_offset = false;
   uuid.Clear();
@@ -5605,20 +5617,31 @@
   uuid = UUID(raw_uuid, sizeof(uuid_t));
   // convert the "main bin spec" type into our
   // ObjectFile::BinaryType enum
+  const char *typestr = "unrecognized type";
   switch (binspec_type) {
   case 0:
 type = eBinaryTypeUnknown;
+typestr = "uknown";
 break;
   case 1:
 type = eBinaryTypeKernel;
+typestr = "xnu kernel";
 break;
   case 2:
 type = eBinaryTypeUser;
+typestr = "userland dyld";
 break;
   case 3:
 type = eBinaryTypeStandalone;
+typestr = "standalone";
 break;
   }
+  LLDB_LOGF(log,
+"LC_NOTE 'main bin spec' found, version %d type %d "
+"(%s), value 0x%" PRIx64 " value-is-slide==%s uuid %s",
+version, type, typestr, value,
+value_is_offset ? "true" : "false",
+uuid.GetAsString().c_str());
   if (!m_data.GetU32(, _pagesize, 1))
 return false;
   if (version > 1 && !m_data.GetU32(, , 1))
@@ -6811,6 +6834,8 @@
 ObjectFileMachO::MachOCorefileAllImageInfos
 ObjectFileMachO::GetCorefileAllImageInfos() {
   MachOCorefileAllImageInfos image_infos;
+  Log *log(
+  GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
 
   // Look for an "all image infos" LC_NOTE.
   lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
@@ -6840,6 +6865,9 @@
 //  offset += 4; // uint32_t entries_size;
 //  offset += 4; // uint32_t unused;
 
+LLDB_LOGF(log,
+  "LC_NOTE 'all image infos' found version %d with %d images",
+  version, imgcount);
 offset = entries_fileoff;
 for (uint32_t i = 0; i < imgcount; i++) {
   // Read the struct image_entry.
@@ -6871,6 +6899,12 @@
 vmaddr};
 image_entry.segment_load_addresses.push_back(new_seg);
   }
+  LLDB_LOGF(
+  log, "  image entry: %s %s 0x%" PRIx64 " %s",
+  image_entry.filename.c_str(),
+  

[Lldb-commits] [PATCH] D157160: Surface error messages from the DebugSymbols DBGShellCommands external agent; add logging for LC_NOTEs in Mach-O corefiles

2023-08-07 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/source/Core/DynamicLoader.cpp:241-243
+Stream  = target.GetDebugger().GetOutputStream();
+s.Printf("Tried DBGShellCommands cmd, got error: %s\n",
+ error.AsCString());

Shouldn't this be the error stream?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157160

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


[Lldb-commits] [PATCH] D157160: Surface error messages from the DebugSymbols DBGShellCommands external agent; add logging for LC_NOTEs in Mach-O corefiles

2023-08-07 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda updated this revision to Diff 548001.
jasonmolenda added a comment.

Change calls to Log::Printf to use LLDB_LOGF().


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157160

Files:
  lldb/source/Core/DynamicLoader.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5414,6 +5414,8 @@
 
 std::string ObjectFileMachO::GetIdentifierString() {
   std::string result;
+  Log *log(
+  GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
   ModuleSP module_sp(GetModule());
   if (module_sp) {
 std::lock_guard guard(module_sp->GetMutex());
@@ -5449,6 +5451,8 @@
 result = buf;
 if (buf)
   free(buf);
+LLDB_LOGF("LC_NOTE 'kern ver str' found with text '%s'",
+  result.c_str());
 return result;
   }
 }
@@ -5472,6 +5476,7 @@
   buf) == ident_command.cmdsize) {
   buf[ident_command.cmdsize - 1] = '\0';
   result = buf;
+  LLDB_LOGF("LC_IDENT found with text '%s'", result.c_str());
 }
 if (buf)
   free(buf);
@@ -5484,6 +5489,7 @@
 
 addr_t ObjectFileMachO::GetAddressMask() {
   addr_t mask = 0;
+  Log *log(GetLog(LLDBLog::Process));
   ModuleSP module_sp(GetModule());
   if (module_sp) {
 std::lock_guard guard(module_sp->GetMutex());
@@ -5511,6 +5517,9 @@
   if (num_addr_bits != 0) {
 mask = ~((1ULL << num_addr_bits) - 1);
   }
+  LLDB_LOGF("LC_NOTE 'addrable bits' found, value %d bits, "
+"mask 0x%" PRIx64,
+num_addr_bits, mask);
   break;
 }
   }
@@ -5526,6 +5535,8 @@
 bool _is_offset,
 UUID ,
 ObjectFile::BinaryType ) {
+  Log *log(
+  GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
   value = LLDB_INVALID_ADDRESS;
   value_is_offset = false;
   uuid.Clear();
@@ -5605,20 +5616,30 @@
   uuid = UUID(raw_uuid, sizeof(uuid_t));
   // convert the "main bin spec" type into our
   // ObjectFile::BinaryType enum
+  const char *typestr = "unrecognized type";
   switch (binspec_type) {
   case 0:
 type = eBinaryTypeUnknown;
+typestr = "uknown";
 break;
   case 1:
 type = eBinaryTypeKernel;
+typestr = "xnu kernel";
 break;
   case 2:
 type = eBinaryTypeUser;
+typestr = "userland dyld";
 break;
   case 3:
 type = eBinaryTypeStandalone;
+typestr = "standalone";
 break;
   }
+  LLDB_LOGF("LC_NOTE 'main bin spec' found, version %d type %d "
+"(%s), value 0x%" PRIx64 " value-is-slide==%s uuid %s",
+version, type, typestr, value,
+value_is_offset ? "true" : "false",
+uuid.GetAsString().c_str());
   if (!m_data.GetU32(, _pagesize, 1))
 return false;
   if (version > 1 && !m_data.GetU32(, , 1))
@@ -6811,6 +6832,8 @@
 ObjectFileMachO::MachOCorefileAllImageInfos
 ObjectFileMachO::GetCorefileAllImageInfos() {
   MachOCorefileAllImageInfos image_infos;
+  Log *log(
+  GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
 
   // Look for an "all image infos" LC_NOTE.
   lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
@@ -6840,6 +6863,8 @@
 //  offset += 4; // uint32_t entries_size;
 //  offset += 4; // uint32_t unused;
 
+LLDB_LOGF("LC_NOTE 'all image infos' found version %d with %d images",
+  version, imgcount);
 offset = entries_fileoff;
 for (uint32_t i = 0; i < imgcount; i++) {
   // Read the struct image_entry.
@@ -6871,6 +6896,12 @@
 vmaddr};
 image_entry.segment_load_addresses.push_back(new_seg);
   }
+  LLDB_LOGF(
+  "  image entry: %s %s 0x%" PRIx64 " %s",
+  image_entry.filename.c_str(),
+  image_entry.uuid.GetAsString().c_str(), image_entry.load_address,
+  

[Lldb-commits] [PATCH] D157160: Surface error messages from the DebugSymbols DBGShellCommands external agent; add logging for LC_NOTEs in Mach-O corefiles

2023-08-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere requested changes to this revision.
JDevlieghere added inline comments.
This revision now requires changes to proceed.



Comment at: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:5454-5456
+if (log)
+  log->Printf("LC_NOTE 'kern ver str' found with text '%s'",
+  result.c_str());

Please use `LLDB_LOG(F)`:

```
LLDB_LOGF(log, "LC_NOTE 'kern ver str' found with text '%s'", result.c_str());
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157160

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


[Lldb-commits] [PATCH] D157160: Surface error messages from the DebugSymbols DBGShellCommands external agent; add logging for LC_NOTEs in Mach-O corefiles

2023-08-04 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda created this revision.
jasonmolenda added a reviewer: bulbazord.
jasonmolenda added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

On Darwin systems, lldb will call into the DebugSymbols framework to find the 
debug info (and/or binary) for a given UUID.  The user may have set a 
DBGShellCommands preference in com.apple.DebugSymbols to find that binary by 
UUID.  lldb will also try a binary that is set in the env var 
LLDB_APPLE_DSYMFORUUID_EXECUTABLE (mostly used by the testsuite) and for 
certain "force a binary load" binaries (e.g. the Darwin kernel binary/symbols, 
without which kernel debugging is largely useless), we have a special case in 
source/Symbol/LocateSymbolFileMacOSX.cpp that knows about a binary called 
/usr/local/bin/dsymForUUID that may be installed.

These DBGShellCommands programs return a plist (xml) output giving lldb the 
location of the dSYM and/or binary.  They can also return an error message in 
that xml response.  Today lldb does not print that error, making it difficult 
for users to understand why a binary was not successfully loaded.

I also added some simple logging as lldb processes LC_NOTEs in a mach-o 
corefile binary that can be enabled, to understand what lldb is seeing as it 
loads one of these.

I have another patch that I'll be uploading soon where I fix the DBGError 
return from a test case TestMultipleBinaryCorefile.py, although the error 
message is sent to the Debugger's Stdout channel so I'm not capturing/testing 
it in the API test right now.  (the dsym-for-uuid.sh that this test case 
creates DOES emit a DBGError right now on an unknown uuid, but it doesn't 
format it correctly and lldb ignores it).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157160

Files:
  lldb/source/Core/DynamicLoader.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5414,6 +5414,8 @@
 
 std::string ObjectFileMachO::GetIdentifierString() {
   std::string result;
+  Log *log(
+  GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
   ModuleSP module_sp(GetModule());
   if (module_sp) {
 std::lock_guard guard(module_sp->GetMutex());
@@ -5449,6 +5451,9 @@
 result = buf;
 if (buf)
   free(buf);
+if (log)
+  log->Printf("LC_NOTE 'kern ver str' found with text '%s'",
+  result.c_str());
 return result;
   }
 }
@@ -5472,6 +5477,8 @@
   buf) == ident_command.cmdsize) {
   buf[ident_command.cmdsize - 1] = '\0';
   result = buf;
+  if (log)
+log->Printf("LC_IDENT found with text '%s'", result.c_str());
 }
 if (buf)
   free(buf);
@@ -5484,6 +5491,7 @@
 
 addr_t ObjectFileMachO::GetAddressMask() {
   addr_t mask = 0;
+  Log *log(GetLog(LLDBLog::Process));
   ModuleSP module_sp(GetModule());
   if (module_sp) {
 std::lock_guard guard(module_sp->GetMutex());
@@ -5511,6 +5519,10 @@
   if (num_addr_bits != 0) {
 mask = ~((1ULL << num_addr_bits) - 1);
   }
+  if (log)
+log->Printf("LC_NOTE 'addrable bits' found, value %d bits, "
+"mask 0x%" PRIx64,
+num_addr_bits, mask);
   break;
 }
   }
@@ -5526,6 +5538,8 @@
 bool _is_offset,
 UUID ,
 ObjectFile::BinaryType ) {
+  Log *log(
+  GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
   value = LLDB_INVALID_ADDRESS;
   value_is_offset = false;
   uuid.Clear();
@@ -5605,20 +5619,32 @@
   uuid = UUID(raw_uuid, sizeof(uuid_t));
   // convert the "main bin spec" type into our
   // ObjectFile::BinaryType enum
+  const char *typestr = "unrecognized type";
   switch (binspec_type) {
   case 0:
 type = eBinaryTypeUnknown;
+typestr = "uknown";
 break;
   case 1:
 type = eBinaryTypeKernel;
+typestr = "xnu kernel";
 break;
   case 2:
 type = eBinaryTypeUser;
+typestr = "userland dyld";
 break;
   case 3: