xref: /openbsd-src/gnu/llvm/lldb/examples/python/sources.py (revision be691f3bb6417f04a68938fadbcaee2d5795e764)
1*be691f3bSpatrick#!/usr/bin/env python
2061da546Spatrickfrom __future__ import print_function
3061da546Spatrick
4061da546Spatrickimport lldb
5061da546Spatrickimport shlex
6061da546Spatrick
7061da546Spatrick
8061da546Spatrickdef dump_module_sources(module, result):
9061da546Spatrick    if module:
10061da546Spatrick        print("Module: %s" % (module.file), file=result)
11061da546Spatrick        for compile_unit in module.compile_units:
12061da546Spatrick            if compile_unit.file:
13061da546Spatrick                print("  %s" % (compile_unit.file), file=result)
14061da546Spatrick
15061da546Spatrick
16061da546Spatrickdef info_sources(debugger, command, result, dict):
17061da546Spatrick    description = '''This command will dump all compile units in any modules that are listed as arguments, or for all modules if no arguments are supplied.'''
18061da546Spatrick    module_names = shlex.split(command)
19061da546Spatrick    target = debugger.GetSelectedTarget()
20061da546Spatrick    if module_names:
21061da546Spatrick        for module_name in module_names:
22061da546Spatrick            dump_module_sources(target.module[module_name], result)
23061da546Spatrick    else:
24061da546Spatrick        for module in target.modules:
25061da546Spatrick            dump_module_sources(module, result)
26061da546Spatrick
27061da546Spatrick
28061da546Spatrickdef __lldb_init_module(debugger, dict):
29061da546Spatrick    # Add any commands contained in this module to LLDB
30061da546Spatrick    debugger.HandleCommand(
31061da546Spatrick        'command script add -f sources.info_sources info_sources')
32061da546Spatrick    print('The "info_sources" command has been installed, type "help info_sources" or "info_sources --help" for detailed help.')
33