[Lldb-commits] [lldb] 447c920 - [lldb] Remove unused imports from crashlog.py

2022-05-14 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-05-14T08:58:55-07:00
New Revision: 447c920a8adfc07f46f61b2a5099ea5b50628645

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

LOG: [lldb] Remove unused imports from crashlog.py

Added: 


Modified: 
lldb/examples/python/crashlog.py

Removed: 




diff  --git a/lldb/examples/python/crashlog.py 
b/lldb/examples/python/crashlog.py
index 0bcdcd0a9fe68..33a64559d4821 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -26,11 +26,9 @@
 #   PYTHONPATH=/path/to/LLDB.framework/Resources/Python ./crashlog.py 
~/Library/Logs/DiagnosticReports/a.crash
 #--
 
-import cmd
 import concurrent.futures
 import contextlib
 import datetime
-import glob
 import json
 import optparse
 import os
@@ -526,10 +524,10 @@ def parse_frames(self, thread, json_frames):
 thread.frames.append(self.crashlog.Frame(idx, pc, frame_offset))
 
 # on arm64 systems, if it jump through a null function pointer,
-# we end up at address 0 and the crash reporter unwinder 
-# misses the frame that actually faulted.  
-# But $lr can tell us where the last BL/BLR instruction used 
-# was at, so insert that address as the caller stack frame.  
+# we end up at address 0 and the crash reporter unwinder
+# misses the frame that actually faulted.
+# But $lr can tell us where the last BL/BLR instruction used
+# was at, so insert that address as the caller stack frame.
 if idx == 0 and pc == 0 and "lr" in thread.registers:
 pc = thread.registers["lr"]
 for image in self.data['usedImages']:



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


[Lldb-commits] [lldb] ae016e4 - [lldb] Don't swallow crashlog exceptions

2022-05-14 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-05-14T08:58:56-07:00
New Revision: ae016e4f7c856983420544794c48c4a2feb6c79a

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

LOG: [lldb] Don't swallow crashlog exceptions

crashlog.py catches every exception in order to format them. This
results in both the exception name as well as the backtrace getting
swallowed.

Here's an example of the current output:

  error: python exception: in method 'SBTarget_ResolveLoadAddress', argument 2 
of type 'lldb::addr_t'

Compare this to the output without the custom exception handling:

  Traceback (most recent call last):
File "[...]/site-packages/lldb/macosx/crashlog.py", line 929, in __call__
  SymbolicateCrashLogs(debugger, shlex.split(command))
File "[...]/site-packages/lldb/macosx/crashlog.py", line 1239, in 
SymbolicateCrashLogs
  SymbolicateCrashLog(crash_log, options)
File "[...]/site-packages/lldb/macosx/crashlog.py", line 1006, in 
SymbolicateCrashLog
  thread.dump_symbolicated(crash_log, options)
File "[...]/site-packages/lldb/macosx/crashlog.py", line 124, in 
dump_symbolicated
  symbolicated_frame_addresses = crash_log.symbolicate(
File "[...]/site-packages/lldb/utils/symbolication.py", line 540, in 
symbolicate
  if symbolicated_address.symbolicate(verbose):
File "[...]/site-packages/lldb/utils/symbolication.py", line 98, in 
symbolicate
  sym_ctx = self.get_symbol_context()
File "[...]/site-packages/lldb/utils/symbolication.py", line 77, in 
get_symbol_context
  sb_addr = self.resolve_addr()
File "[...]/site-packages/lldb/utils/symbolication.py", line 69, in 
resolve_addr
  self.so_addr = self.target.ResolveLoadAddress(self.load_addr)
File "[...]/site-packages/lldb/__init__.py", line 10675, in 
ResolveLoadAddress
  return _lldb.SBTarget_ResolveLoadAddress(self, vm_addr)
  OverflowError: in method 'SBTarget_ResolveLoadAddress', argument 2 of type 
'lldb::addr_t'

This patch removes the custom exception handling and lets LLDB or the
default exception handler deal with it instead.

Differential revision: https://reviews.llvm.org/D125589

Added: 


Modified: 
lldb/examples/python/crashlog.py

Removed: 




diff  --git a/lldb/examples/python/crashlog.py 
b/lldb/examples/python/crashlog.py
index 33a64559d482..49c9a92497eb 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -925,10 +925,7 @@ def __init__(self, debugger, internal_dict):
 pass
 
 def __call__(self, debugger, command, exe_ctx, result):
-try:
-SymbolicateCrashLogs(debugger, shlex.split(command))
-except Exception as e:
-result.PutCString("error: python exception: %s" % e)
+SymbolicateCrashLogs(debugger, shlex.split(command))
 
 def get_short_help(self):
 return "Symbolicate one or more darwin crash log files."
@@ -1020,11 +1017,7 @@ def load_crashlog_in_scripted_process(debugger, 
crash_log_file, options):
 if not os.path.exists(crashlog_path):
 result.PutCString("error: crashlog file %s does not exist" % 
crashlog_path)
 
-try:
-crashlog = CrashLogParser().parse(debugger, crashlog_path, False)
-except Exception as e:
-result.PutCString("error: python exception: %s" % e)
-return
+crashlog = CrashLogParser().parse(debugger, crashlog_path, False)
 
 if debugger.GetNumTargets() > 0:
 target = debugger.GetTargetAtIndex(0)



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


[Lldb-commits] [PATCH] D125589: [lldb] Don't swallow crashlog exceptions

2022-05-14 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
JDevlieghere marked an inline comment as done.
Closed by commit rGae016e4f7c85: [lldb] Don't swallow crashlog exceptions 
(authored by JDevlieghere).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125589

Files:
  lldb/examples/python/crashlog.py


Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -925,10 +925,7 @@
 pass
 
 def __call__(self, debugger, command, exe_ctx, result):
-try:
-SymbolicateCrashLogs(debugger, shlex.split(command))
-except Exception as e:
-result.PutCString("error: python exception: %s" % e)
+SymbolicateCrashLogs(debugger, shlex.split(command))
 
 def get_short_help(self):
 return "Symbolicate one or more darwin crash log files."
@@ -1020,11 +1017,7 @@
 if not os.path.exists(crashlog_path):
 result.PutCString("error: crashlog file %s does not exist" % 
crashlog_path)
 
-try:
-crashlog = CrashLogParser().parse(debugger, crashlog_path, False)
-except Exception as e:
-result.PutCString("error: python exception: %s" % e)
-return
+crashlog = CrashLogParser().parse(debugger, crashlog_path, False)
 
 if debugger.GetNumTargets() > 0:
 target = debugger.GetTargetAtIndex(0)


Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -925,10 +925,7 @@
 pass
 
 def __call__(self, debugger, command, exe_ctx, result):
-try:
-SymbolicateCrashLogs(debugger, shlex.split(command))
-except Exception as e:
-result.PutCString("error: python exception: %s" % e)
+SymbolicateCrashLogs(debugger, shlex.split(command))
 
 def get_short_help(self):
 return "Symbolicate one or more darwin crash log files."
@@ -1020,11 +1017,7 @@
 if not os.path.exists(crashlog_path):
 result.PutCString("error: crashlog file %s does not exist" % crashlog_path)
 
-try:
-crashlog = CrashLogParser().parse(debugger, crashlog_path, False)
-except Exception as e:
-result.PutCString("error: python exception: %s" % e)
-return
+crashlog = CrashLogParser().parse(debugger, crashlog_path, False)
 
 if debugger.GetNumTargets() > 0:
 target = debugger.GetTargetAtIndex(0)
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D125616: [NFC] two small perf fixes for when using a DebugSymbols DBGShellCommands to find a dSYM

2022-05-14 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda created this revision.
jasonmolenda added a reviewer: JDevlieghere.
jasonmolenda added a project: LLDB.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

`SymbolVendorMacOSX::CreateInstance()` calls 
`LocateMacOSXFilesUsingDebugSymbols()`, to the DebugSymbols framework on macOS, 
to find a dSYM on the local computer or from a remote server.  This method 
constructs a Module, and it finds a dSYM, creates an ObjectFile for it, then 
calls SymbolVendor::AddSymbolFileRepresentation with that ObjectFile.  The 
location of the dSYM hasn't been recorded in the Module anywhere, so 
AddSymbolFileRepresentation eventually (under many layers) calls 
`LocateMacOSXFilesUsingDebugSymbols()` again.  So we call into the DebugSymbols 
framework twice.  It's easy to fix; have `SymbolVendorMacOSX::CreateInstance()` 
add the dSYM path we found from the first call into 
`LocateMacOSXFilesUsingDebugSymbols()` in the Module before we call 
AddSymbolFileRepresentation().

The second perf fix is to `LocateMacOSXFilesUsingDebugSymbols()` so when it is 
handed a ModuleSpec that has a binary file path, and that file exists, one of 
the keys we get back from the DebugSymbols framework gives us a "symbol rich 
binary" (possibly unstripped).  This isn't adding anything when we have the 
dSYM - we can use the original (possibly stripped) binary that we had to begin 
with.  The symbol rich binary may even be over an NFS filesystem, introducing a 
large performance cost to using it over the local stripped binary.

Pretty straightforward stuff, not sure who to ask for review, this is more my 
area than anyone else I can think of these days.  If anyone has comments, 
please let me know.

rdar://84576917


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125616

Files:
  lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
  lldb/source/Symbol/LocateSymbolFileMacOSX.cpp


Index: lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
===
--- lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
+++ lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
@@ -18,9 +18,11 @@
 #include "Host/macosx/cfcpp/CFCData.h"
 #include "Host/macosx/cfcpp/CFCReleaser.h"
 #include "Host/macosx/cfcpp/CFCString.h"
+#include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Host/Host.h"
+#include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/DataBuffer.h"
@@ -147,7 +149,52 @@
 uuid_dict = static_cast(
 ::CFDictionaryGetValue(dict.get(), uuid_cfstr.get()));
   }
-  if (uuid_dict) {
+
+  // Check to see if we have the file on the local filesystem.
+  if (!module_spec.GetFileSpec().GetPath().empty() &&
+  FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
+ModuleSpec exe_spec;
+exe_spec.GetFileSpec() = module_spec.GetFileSpec();
+exe_spec.GetUUID() = module_spec.GetUUID();
+ModuleSP module_sp;
+module_sp.reset(new Module(exe_spec));
+if (module_sp && module_sp->GetObjectFile() &&
+module_sp->MatchesModuleSpec(exe_spec)) {
+  success = true;
+  return_module_spec.GetFileSpec() = module_spec.GetFileSpec();
+  if (log) {
+LLDB_LOGF(log, "using original binary filepath %s for UUID %s",
+  module_spec.GetFileSpec().GetPath().c_str(),
+  uuid->GetAsString().c_str());
+  }
+  ++items_found;
+}
+  }
+
+  // Check if the requested image is in our shared cache.
+  if (!success) {
+SharedCacheImageInfo image_info = 
HostInfo::GetSharedCacheImageInfo(
+module_spec.GetFileSpec().GetPath());
+
+// If we found it and it has the correct UUID, let's proceed with
+// creating a module from the memory contents.
+if (image_info.uuid && (!module_spec.GetUUID() ||
+module_spec.GetUUID() == image_info.uuid)) 
{
+  success = true;
+  return_module_spec.GetFileSpec() = module_spec.GetFileSpec();
+  if (log) {
+LLDB_LOGF(log,
+  "using binary from shared cache for filepath %s for "
+  "UUID %s",
+  module_spec.GetFileSpec().GetPath().c_str(),
+  uuid->GetAsString().c_str());
+  }
+  ++items_found;
+}
+  }
+
+  // Use the DBGSymbolRichExecutable filepath if present
+  if (!success && uuid_dict) {
 CFStringRef exec_cf_path =
 static_cast(::CFDictionaryGetValue(