[PATCH] D36347: Add new script to launch lldb and set breakpoints for diagnostics all diagnostics seen.
Zachary Turner via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 20 09:35:50 PDT 2017
zturner added a comment.
In https://reviews.llvm.org/D36347#902157, @clayborg wrote:
> Please do convert to python. Just know that you can use "lldb -P" to get the python path that is needed in order to do "import lldb" in the python script. So you can try doing a "import lldb", and if that fails, catch the exception, run "lldb -P", add that path to the python path:
>
> try:
> # Just try for LLDB in case the lldb module is already in the python search
> # paths
> import lldb
> except ImportError:
> # We failed to import lldb automatically. Run lldb with the -P option so
> # it tells us the python path we should use.
> lldb_py_dirs = list()
> (status, output) = commands.getstatusoutput("lldb -P")
> dir = os.path.realpath(output)
> if status == 0 and os.path.isdir(dir):
> lldb_py_dirs.append(dir)
> success = False
> for lldb_py_dir in lldb_py_dirs:
> if os.path.exists(lldb_py_dir):
> if not (sys.path.__contains__(lldb_py_dir)):
> sys.path.append(lldb_py_dir)
> try:
> import lldb
> except ImportError:
> pass
> else:
> success = True
> break
> if not success:
> print("error: couldn't locate the 'lldb' module, please set "
> "PYTHONPATH correctly")
> sys.exit(1)
>
>
Is any of this really necessary? If you load this script via `command script add` (which is definitely better than having this be a post-processing script that someone has to manually run) then it is guaranteed to be in the path. Just import it, like the other examples in `lldb/examples/python/jump.py` for an example. The idea is to have it do the indexing when the command is loaded and save it to a global, and then each time it runs it uses the global index. This way it's invisible to the user, you just run `bcd -Wcovered-switch` or something without worrying about it.
https://reviews.llvm.org/D36347
More information about the cfe-commits
mailing list