Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[lldb] Cherry-picks from ToT #7008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

medismailben
Copy link

@medismailben medismailben commented Jun 16, 2023

This patch contains a bunch of fix and improvements cherry-picked from the top-of-tree llvm repo, namely:

  • Fixes for JSON ObjectFile module loading
  • Add the ability to load inlined symbols from crash report files
  • Fix a PID parsing issue in crash report
  • Remove tempfile prefix from module list
  • Fix a racing issue when loading inlined symbols in a scripted process
  • Create an interactive crashlog session with no target binary
  • Disable variable watchpoint when the variable goes out of scope

This PR also contains some python re-formatting patches.

In 27f27d1, we added a new way to use textual (JSON) object files
and symbol files with the interactive crashlog command, using the
inlined symbols from the crash report.

However, there was a missing piece after successfully adding the textual
module to the target, we didn't mark it as available causing the module
loading to exit early.

This patch addresses that issue by marking the module as available when
added successfully to the target.

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

Signed-off-by: Med Ismail Bennani <[email protected]>
Sometimes, crash reports come with inlined symbols. These provide the
exact stacktrace from the user binary.

However, when investigating a crash, it's very likely that the images related
to the crashed thread are not available on the debugging user system or
that the versions don't match. This causes interactive crashlog to show
a degraded backtrace in lldb.

This patch aims to address that issue, by parsing the inlined symbols
from the crash report and load them into lldb's target.

This patch is a follow-up to 27f27d1, focusing on inlined symbols
loading from legacy (non-json) crash reports.

To do so, it updates the stack frame regular expression to make the
capture groups more granular, to be able to extract the symbol name, the
offset and the source location if available, while making it more
maintainable.

So now, when parsing the crash report, we build a data structure
containing all the symbol information for each stackframe. Then, after
launching the scripted process for interactive mode, we write a JSON
symbol file for each module, only containing the symbols that it contains.

Finally, we load the json symbol file into lldb, before showing the user
the process status and backtrace.

rdar://97345586

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

Signed-off-by: Med Ismail Bennani <[email protected]>
This patch should fix an issue when parsing the process pid and setting
it in the scripted process.

It can happen that the `crashlog.process_id` attribute is sometimes
parsed as a string. That would cause the scripted process to pick the
default value (0).

To address that, this patch makes sure that the parsed attributed is
converted to the integer type before passing it to the scripted process.

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

Signed-off-by: Med Ismail Bennani <[email protected]>
This patch fixes the log commands by replacing the LLDB_LOG macro by the
LLDB_LOGF macro. This is necessary in order to format argument with printf.

Signed-off-by: Med Ismail Bennani <[email protected]>
This patch adds support to eStopReasonTrace to Scripted Threads.

This is necessary when using a Scrited Process with a Scripted Thread
Plan to report a special thread stop reason to the thread plan.

rdar://109425542

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

Signed-off-by: Med Ismail Bennani <[email protected]>
This patch changes the way we generate the ObjectFileJSON files
containing the inlined symbols from the crash report to remove the
tempfile prefix from the object file name.

To do so, instead of creating a new tempfile for each module, we create a
temporary directory that contains each module object file with the same
name as the module.

This makes the backtraces only contain the module name without the
temfile prefix which makes it look like a regular stackframe.

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

Signed-off-by: Med Ismail Bennani <[email protected]>
Following abba5de, some tests started failing on green-dragon:

https://green.lab.llvm.org/green/job/lldb-cmake/55460/console

Looking at the backtrace, there seems to be a racing issue when deleting
the temporary directory containing all the JSON object files:

```
Traceback (most recent call last):
  File "/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lib/python3.10/site-packages/lldb/macosx/crashlog.py", line 1115, in __call__
    SymbolicateCrashLogs(debugger, shlex.split(command), result)
  File "/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lib/python3.10/site-packages/lldb/macosx/crashlog.py", line 1457, in SymbolicateCrashLogs
    SymbolicateCrashLog(crash_log, options)
  File "/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lib/python3.10/site-packages/lldb/macosx/crashlog.py", line 1158, in SymbolicateCrashLog
    with tempfile.TemporaryDirectory() as obj_dir:
  File "/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tempfile.py", line 869, in __exit__
    self.cleanup()
  File "/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tempfile.py", line 873, in cleanup
    self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)
  File "/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tempfile.py", line 855, in _rmtree
    _shutil.rmtree(name, onerror=onerror)
  File "/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/lib/python3.10/shutil.py", line 731, in rmtree
    onerror(os.rmdir, path, sys.exc_info())
  File "/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/lib/python3.10/shutil.py", line 729, in rmtree
    os.rmdir(path)
OSError: [Errno 66] Directory not empty: '/var/folders/09/r4vw4v8n5kb67jl66zvlbljw0000gn/T/tmp6qfifxk7'
```

This patch should fix that issue since it won't delete the object file
directory until we're sure that the modules adding tasks completed.

Signed-off-by: Med Ismail Bennani <[email protected]>
This patch changes the way we load a crash report into a scripted
process by creating a empty target.

To do so, it parses the architecture information from the report (for
both the legacy and json format) and uses that to create a target that
doesn't have any executable, like what we do when attaching to a process.

For the legacy format, we mostly rely on the `Code Type` line, since the
architure is an optional field on the `Binary Images` sections.

However for the json format, we first try to get the architecture while
parsing the image dictionary if we couldn't find it, we try to infer it
using the "flavor" key when parsing the frame's registers.

If the architecture is still not set after parsing the report, we raise
an exception.

rdar://107850263

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

Differential

Signed-off-by: Med Ismail Bennani <[email protected]>
@medismailben
Copy link
Author

@swift-ci test

If we use a variable watchpoint with a condition using a scope variable,
if we go out-of-scope, the watpoint remains active which can the
expression evaluator to fail to parse the watchpoint condition (because
of the missing varible bindings).

This was discovered after `watchpoint_callback.test` started failing on
the green dragon bot.

This patch should address that issue by setting an internal breakpoint
on the return addresss of the current frame when creating a variable
watchpoint. The breakpoint has a callback that will disable the watchpoint
if the the breakpoint execution context matches the watchpoint execution
context.

This is only enabled for local variables.

This patch also re-enables the failing test following e108638.

rdar://109574319

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

Signed-off-by: Med Ismail Bennani <[email protected]>
@medismailben
Copy link
Author

@swift-ci test

@medismailben
Copy link
Author

@swift-ci test windows platform

@JDevlieghere
Copy link

JDevlieghere commented Jun 16, 2023

I discussed this offline with @medismailben and he'll split up the PR into multiple PRs that are easier to review. All the changes here are related, but there's to much too meaningfully decide whether this is safe to go in or not.

@medismailben
Copy link
Author

@JDevlieghere @adrian-prantl I've tried to split this across #7009 #7010 #7012 #7014 & #7015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants