xref: /openbsd-src/gnu/llvm/lldb/examples/python/sources.py (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1be691f3bSpatrick#!/usr/bin/env python
2061da546Spatrick
3061da546Spatrickimport lldb
4061da546Spatrickimport shlex
5061da546Spatrick
6061da546Spatrick
7061da546Spatrickdef dump_module_sources(module, result):
8061da546Spatrick    if module:
9061da546Spatrick        print("Module: %s" % (module.file), file=result)
10061da546Spatrick        for compile_unit in module.compile_units:
11061da546Spatrick            if compile_unit.file:
12061da546Spatrick                print("  %s" % (compile_unit.file), file=result)
13061da546Spatrick
14061da546Spatrick
15061da546Spatrickdef info_sources(debugger, command, result, dict):
16061da546Spatrick    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.'''
17061da546Spatrick    module_names = shlex.split(command)
18061da546Spatrick    target = debugger.GetSelectedTarget()
19061da546Spatrick    if module_names:
20061da546Spatrick        for module_name in module_names:
21061da546Spatrick            dump_module_sources(target.module[module_name], result)
22061da546Spatrick    else:
23061da546Spatrick        for module in target.modules:
24061da546Spatrick            dump_module_sources(module, result)
25061da546Spatrick
26061da546Spatrick
27061da546Spatrickdef __lldb_init_module(debugger, dict):
28061da546Spatrick    # Add any commands contained in this module to LLDB
29061da546Spatrick    debugger.HandleCommand(
30*f6aab3d8Srobert        'command script add -o -f sources.info_sources info_sources')
31061da546Spatrick    print('The "info_sources" command has been installed, type "help info_sources" or "info_sources --help" for detailed help.')
32