[asan_symbolize] Add a simple plugin architecture
authorDan Liew <dan@su-root.co.uk>
Thu, 18 Apr 2019 11:34:31 +0000 (11:34 +0000)
committerDan Liew <dan@su-root.co.uk>
Thu, 18 Apr 2019 11:34:31 +0000 (11:34 +0000)
commit403d3187a79bd3feb8b54ea4717567c047fea608
tree66e1d6e034685472a76e5e05ea9b1b5239c2797b
parenta630b340573fe141414a3b82c7bdf0b5c4a8ccf7
[asan_symbolize] Add a simple plugin architecture

Summary:
This change adds a simple plugin architecture to `asan_symbolize.py`.
The motivation here is that sometimes it's necessary to perform extra
work to figure out where binaries with debug symbols can actually be
found. For example it might be the case that a remote service needs
to be queried for binaries and then copied to the local system.

This "extra work" can be extremely site-specific such that adding the
code directly into the `asan_symbolize.py` would just clutter the code
for a very niche use case. To avoid this, the `asan_symbolize.py` can
now load external code via a new `--plugins` command line option.

These plugins are loaded before main command line argument parsing so
that they can add their own command line options.

Right now the only hook into the behaviour of symbolization is the
`filter_binary_path()` function which assumes a very similar role
to the `binary_name_filter` function that was previously in the code.
We can add more hooks as necessary.

Code in the `asan_symbolize.py` script does not call plugin code
directly. Instead it uses a `AsanSymbolizerPlugInProxy` object.
This object

* Loads plugins from files.
* Manages the lifetime of the plugins.
* Provides an interface for calling into plugin functions and handles
  calling into multiple plugins.

To unify the way binary paths are filtered the old `sysroot_path_filter`
function (and associated code) has been turned into a simple plugin
(`SysRootFilterPlugIn`) that is always loaded. The plugin unloads
itself if the `-s` option is not present on the command line. Users
should not see any functional change relating to this command line
option.

Some simple tests are provided to illustrate what plugin code looks
like and also to check the functionality continues to work.

rdar://problem/49476995

Reviewers: kubamracek, yln, samsonov, dvyukov, vitalybuka

Subscribers: srhines, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 358657
compiler-rt/lib/asan/scripts/asan_symbolize.py
compiler-rt/test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op.py [new file with mode: 0644]
compiler-rt/test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op_help_output.cc [new file with mode: 0644]
compiler-rt/test/asan/TestCases/Posix/asan_symbolize_script/plugin_no_op_symbolicate.cc [new file with mode: 0644]