2018-11-28 05:00:32 +08:00
|
|
|
include "llvm/Option/OptParser.td"
|
|
|
|
|
|
|
|
class F<string name>: Flag<["--", "-"], name>;
|
|
|
|
class S<string name>: Separate<["--", "-"], name>;
|
|
|
|
class R<list<string> prefixes, string name>
|
|
|
|
: Option<prefixes, name, KIND_REMAINING_ARGS>;
|
|
|
|
|
2019-11-21 06:53:37 +08:00
|
|
|
// Please keep this in sync with the man page in docs/man/lldb.rst
|
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
// Attaching options.
|
|
|
|
def grp_attach : OptionGroup<"attaching">, HelpText<"ATTACHING">;
|
|
|
|
|
|
|
|
def attach_name: Separate<["--", "-"], "attach-name">,
|
|
|
|
MetaVarName<"<name>">,
|
|
|
|
HelpText<"Tells the debugger to attach to a process with the given name.">,
|
|
|
|
Group<grp_attach>;
|
|
|
|
def: Separate<["-"], "n">,
|
|
|
|
Alias<attach_name>,
|
|
|
|
HelpText<"Alias for --attach-name">,
|
|
|
|
Group<grp_attach>;
|
|
|
|
|
|
|
|
def wait_for: F<"wait-for">,
|
|
|
|
HelpText<"Tells the debugger to wait for a process with the given pid or name to launch before attaching.">,
|
|
|
|
Group<grp_attach>;
|
|
|
|
def: Flag<["-"], "w">,
|
|
|
|
Alias<wait_for>,
|
|
|
|
HelpText<"Alias for --wait-for">,
|
|
|
|
Group<grp_attach>;
|
|
|
|
|
|
|
|
def attach_pid: Separate<["--", "-"], "attach-pid">,
|
|
|
|
MetaVarName<"<pid>">,
|
|
|
|
HelpText<"Tells the debugger to attach to a process with the given pid.">,
|
|
|
|
Group<grp_attach>;
|
|
|
|
def: Separate<["-"], "p">,
|
|
|
|
Alias<attach_pid>,
|
|
|
|
HelpText<"Alias for --attach-pid">,
|
|
|
|
Group<grp_attach>;
|
|
|
|
|
|
|
|
|
|
|
|
// Scripting options.
|
|
|
|
def grp_scripting : OptionGroup<"scripting">, HelpText<"SCRIPTING">;
|
|
|
|
|
|
|
|
def python_path: F<"python-path">,
|
|
|
|
HelpText<"Prints out the path to the lldb.py file for this version of lldb.">,
|
|
|
|
Group<grp_scripting>;
|
|
|
|
def: Flag<["-"], "P">,
|
|
|
|
Alias<python_path>,
|
|
|
|
HelpText<"Alias for --python-path">,
|
|
|
|
Group<grp_scripting>;
|
|
|
|
|
[lldb] make it easier to find LLDB's python
It is surprisingly difficult to write a simple python script that
can reliably `import lldb` without failing, or crashing. I'm
currently resorting to convolutions like this:
def find_lldb(may_reexec=False):
if prefix := os.environ.get('LLDB_PYTHON_PREFIX'):
if os.path.realpath(prefix) != os.path.realpath(sys.prefix):
raise Exception("cannot import lldb.\n"
f" sys.prefix should be: {prefix}\n"
f" but it is: {sys.prefix}")
else:
line1, line2 = subprocess.run(
['lldb', '-x', '-b', '-o', 'script print(sys.prefix)'],
encoding='utf8', stdout=subprocess.PIPE,
check=True).stdout.strip().splitlines()
assert line1.strip() == '(lldb) script print(sys.prefix)'
prefix = line2.strip()
os.environ['LLDB_PYTHON_PREFIX'] = prefix
if sys.prefix != prefix:
if not may_reexec:
raise Exception(
"cannot import lldb.\n" +
f" This python, at {sys.prefix}\n"
f" does not math LLDB's python at {prefix}")
os.environ['LLDB_PYTHON_PREFIX'] = prefix
python_exe = os.path.join(prefix, 'bin', 'python3')
os.execl(python_exe, python_exe, *sys.argv)
lldb_path = subprocess.run(['lldb', '-P'],
check=True, stdout=subprocess.PIPE,
encoding='utf8').stdout.strip()
sys.path = [lldb_path] + sys.path
This patch aims to replace all that with:
#!/usr/bin/env lldb-python
import lldb
...
... by adding the following features:
* new command line option: --print-script-interpreter-info. This
prints language-specific information about the script interpreter
in JSON format.
* new tool (unix only): lldb-python which finds python and exec's it.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D112973
2021-11-11 02:33:33 +08:00
|
|
|
def print_script_interpreter_info: F<"print-script-interpreter-info">,
|
|
|
|
HelpText<"Prints out a json dictionary with information about the scripting language interpreter.">,
|
|
|
|
Group<grp_scripting>;
|
|
|
|
|
2018-12-18 02:11:48 +08:00
|
|
|
def script_language: Separate<["--", "-"], "script-language">,
|
|
|
|
MetaVarName<"<language>">,
|
2018-11-28 05:00:32 +08:00
|
|
|
HelpText<"Tells the debugger to use the specified scripting language for user-defined scripts.">,
|
|
|
|
Group<grp_scripting>;
|
|
|
|
def: Separate<["-"], "l">,
|
|
|
|
Alias<script_language>,
|
|
|
|
HelpText<"Alias for --script-language">,
|
|
|
|
Group<grp_scripting>;
|
|
|
|
|
|
|
|
// Repl options.
|
|
|
|
def grp_repl : OptionGroup<"repl">, HelpText<"REPL">;
|
|
|
|
|
2018-12-18 02:11:48 +08:00
|
|
|
def repl: Flag<["--", "-"], "repl">,
|
2018-11-28 05:00:32 +08:00
|
|
|
HelpText<"Runs lldb in REPL mode with a stub process.">,
|
|
|
|
Group<grp_repl>;
|
2018-12-18 02:11:48 +08:00
|
|
|
def: Flag<["-"], "r">,
|
2018-11-28 05:00:32 +08:00
|
|
|
Alias<repl>,
|
|
|
|
HelpText<"Alias for --repl">,
|
|
|
|
Group<grp_repl>;
|
2018-12-18 02:11:48 +08:00
|
|
|
def repl_: Joined<["--", "-"], "repl=">,
|
|
|
|
MetaVarName<"<flags>">,
|
|
|
|
HelpText<"Runs lldb in REPL mode with a stub process with the given flags.">,
|
|
|
|
Group<grp_repl>;
|
|
|
|
def: Joined<["-"], "r=">,
|
|
|
|
MetaVarName<"<flags>">,
|
|
|
|
Alias<repl_>,
|
|
|
|
HelpText<"Alias for --repl=<flags>">,
|
|
|
|
Group<grp_repl>;
|
2018-11-28 05:00:32 +08:00
|
|
|
|
|
|
|
def repl_language: Separate<["--", "-"], "repl-language">,
|
|
|
|
MetaVarName<"<language>">,
|
|
|
|
HelpText<"Chooses the language for the REPL.">,
|
|
|
|
Group<grp_repl>;
|
|
|
|
def: Separate<["-"], "R">,
|
|
|
|
Alias<repl_language>,
|
|
|
|
HelpText<"Alias for --repl-language">,
|
|
|
|
Group<grp_repl>;
|
|
|
|
|
|
|
|
|
|
|
|
// Command options.
|
|
|
|
def grp_command : OptionGroup<"command">, HelpText<"COMMANDS">;
|
|
|
|
|
|
|
|
def no_lldbinit: F<"no-lldbinit">,
|
|
|
|
HelpText<"Do not automatically parse any '.lldbinit' files.">,
|
|
|
|
Group<grp_command>;
|
|
|
|
def: Flag<["-"], "x">,
|
|
|
|
Alias<no_lldbinit>,
|
|
|
|
HelpText<"Alias for --no-lldbinit">,
|
|
|
|
Group<grp_command>;
|
2019-05-08 00:57:17 +08:00
|
|
|
def local_lldbinit: F<"local-lldbinit">,
|
|
|
|
HelpText<"Allow the debugger to parse the .lldbinit files in the current working directory, unless --no-lldbinit is passed.">,
|
|
|
|
Group<grp_command>;
|
2018-11-28 05:00:32 +08:00
|
|
|
|
|
|
|
def batch: F<"batch">,
|
|
|
|
HelpText<"Tells the debugger to run the commands from -s, -S, -o & -O, and then quit.">,
|
|
|
|
Group<grp_command>;
|
|
|
|
def: Flag<["-"], "b">,
|
|
|
|
Alias<batch>,
|
|
|
|
HelpText<"Alias for --batch">,
|
|
|
|
Group<grp_command>;
|
|
|
|
|
|
|
|
def source_quietly: F<"source-quietly">,
|
2021-11-03 02:01:53 +08:00
|
|
|
HelpText<"Tells the debugger not to echo commands while sourcing files or one-line commands provided on the command line.">,
|
2018-11-28 05:00:32 +08:00
|
|
|
Group<grp_command>;
|
|
|
|
def: Flag<["-"], "Q">,
|
|
|
|
Alias<source_quietly>,
|
|
|
|
HelpText<"Alias for --source-quietly">,
|
|
|
|
Group<grp_command>;
|
|
|
|
|
|
|
|
def one_line_on_crash: Separate<["--", "-"], "one-line-on-crash">,
|
|
|
|
MetaVarName<"<command>">,
|
2019-11-21 06:53:37 +08:00
|
|
|
HelpText<"When in batch mode, tells the debugger to run this one-line lldb command if the target crashes.">,
|
2018-11-28 05:00:32 +08:00
|
|
|
Group<grp_command>;
|
|
|
|
def: Separate<["-"], "k">,
|
|
|
|
Alias<one_line_on_crash>,
|
|
|
|
HelpText<"Alias for --one-line-on-crash">,
|
|
|
|
Group<grp_command>;
|
|
|
|
|
|
|
|
def source_on_crash: Separate<["--", "-"], "source-on-crash">,
|
|
|
|
MetaVarName<"<file>">,
|
|
|
|
HelpText<"When in batch mode, tells the debugger to source this file of lldb commands if the target crashes.">,
|
|
|
|
Group<grp_command>;
|
|
|
|
def: Separate<["-"], "K">,
|
|
|
|
Alias<source_on_crash>,
|
|
|
|
HelpText<"Alias for --source-on-crash">,
|
|
|
|
Group<grp_command>;
|
|
|
|
|
|
|
|
def source: Separate<["--", "-"], "source">,
|
|
|
|
MetaVarName<"<file>">,
|
|
|
|
HelpText<"Tells the debugger to read in and execute the lldb commands in the given file, after any file has been loaded.">,
|
|
|
|
Group<grp_command>;
|
|
|
|
def: Separate<["-"], "s">,
|
|
|
|
Alias<source>,
|
|
|
|
HelpText<"Alias for --source">,
|
|
|
|
Group<grp_command>;
|
|
|
|
|
|
|
|
def source_before_file: Separate<["--", "-"], "source-before-file">,
|
|
|
|
MetaVarName<"<file>">,
|
|
|
|
HelpText<"Tells the debugger to read in and execute the lldb commands in the given file, before any file has been loaded.">,
|
|
|
|
Group<grp_command>;
|
|
|
|
def: Separate<["-"], "S">,
|
|
|
|
Alias<source_before_file>,
|
|
|
|
HelpText<"Alias for --source-before-file">,
|
|
|
|
Group<grp_command>;
|
|
|
|
|
|
|
|
def one_line: Separate<["--", "-"], "one-line">,
|
|
|
|
MetaVarName<"<command>">,
|
|
|
|
HelpText<"Tells the debugger to execute this one-line lldb command after any file provided on the command line has been loaded.">,
|
|
|
|
Group<grp_command>;
|
|
|
|
def: Separate<["-"], "o">,
|
|
|
|
Alias<one_line>,
|
|
|
|
HelpText<"Alias for --one-line">,
|
|
|
|
Group<grp_command>;
|
|
|
|
|
|
|
|
def one_line_before_file: Separate<["--", "-"], "one-line-before-file">,
|
|
|
|
MetaVarName<"<command>">,
|
|
|
|
HelpText<"Tells the debugger to execute this one-line lldb command before any file provided on the command line has been loaded.">,
|
|
|
|
Group<grp_command>;
|
|
|
|
def: Separate<["-"], "O">,
|
|
|
|
Alias<one_line_before_file>,
|
|
|
|
HelpText<"Alias for --one-line-before-file">,
|
|
|
|
Group<grp_command>;
|
|
|
|
|
|
|
|
|
|
|
|
// General options.
|
|
|
|
def version: F<"version">,
|
|
|
|
HelpText<"Prints out the current version number of the LLDB debugger.">;
|
|
|
|
def: Flag<["-"], "v">,
|
|
|
|
Alias<version>,
|
|
|
|
HelpText<"Alias for --version">;
|
|
|
|
|
|
|
|
def help: F<"help">,
|
|
|
|
HelpText<"Prints out the usage information for the LLDB debugger.">;
|
|
|
|
def: Flag<["-"], "h">,
|
|
|
|
Alias<help>,
|
|
|
|
HelpText<"Alias for --help">;
|
|
|
|
|
2018-11-29 08:22:28 +08:00
|
|
|
def core: Separate<["--", "-"], "core">,
|
|
|
|
MetaVarName<"<filename>">,
|
|
|
|
HelpText<"Tells the debugger to use the full path to <filename> as the core file.">;
|
|
|
|
def: Separate<["-"], "c">,
|
2018-11-28 05:00:32 +08:00
|
|
|
Alias<core>,
|
|
|
|
HelpText<"Alias for --core">;
|
|
|
|
|
|
|
|
def editor: F<"editor">,
|
|
|
|
HelpText<"Tells the debugger to open source files using the host's \"external editor\" mechanism.">;
|
|
|
|
def: Flag<["-"], "e">,
|
|
|
|
Alias<editor>,
|
|
|
|
HelpText<"Alias for --editor">;
|
|
|
|
|
|
|
|
def no_use_colors: F<"no-use-colors">,
|
|
|
|
HelpText<"Do not use colors.">;
|
|
|
|
def: Flag<["-"], "X">,
|
|
|
|
Alias<no_use_colors>,
|
|
|
|
HelpText<"Alias for --no-use-color">;
|
|
|
|
|
|
|
|
def file: Separate<["--", "-"], "file">,
|
|
|
|
MetaVarName<"<filename>">,
|
|
|
|
HelpText<"Tells the debugger to use the file <filename> as the program to be debugged.">;
|
|
|
|
def: Separate<["-"], "f">,
|
|
|
|
Alias<file>,
|
|
|
|
HelpText<"Alias for --file">;
|
|
|
|
|
|
|
|
def arch: Separate<["--", "-"], "arch">,
|
|
|
|
MetaVarName<"<architecture>">,
|
|
|
|
HelpText<"Tells the debugger to use the specified architecture when starting and running the program.">;
|
|
|
|
def: Separate<["-"], "a">,
|
|
|
|
Alias<arch>,
|
|
|
|
HelpText<"Alias for --arch">;
|
|
|
|
|
|
|
|
def debug: F<"debug">,
|
|
|
|
HelpText<"Tells the debugger to print out extra information for debugging itself.">;
|
|
|
|
def: Flag<["-"], "d">,
|
|
|
|
Alias<debug>,
|
|
|
|
HelpText<"Alias for --debug">;
|
|
|
|
|
2019-03-13 00:44:18 +08:00
|
|
|
def capture: F<"capture">,
|
|
|
|
HelpText<"Tells the debugger to capture a reproducer.">;
|
|
|
|
def capture_path: Separate<["--", "-"], "capture-path">,
|
2018-11-28 05:00:32 +08:00
|
|
|
MetaVarName<"<filename>">,
|
2019-03-13 00:44:18 +08:00
|
|
|
HelpText<"Tells the debugger to use the given filename for the reproducer.">;
|
2020-07-10 01:35:16 +08:00
|
|
|
def generate_on_exit: F<"reproducer-generate-on-exit">,
|
2020-01-16 11:44:46 +08:00
|
|
|
HelpText<"Generate reproducer on exit.">;
|
2018-11-28 05:00:32 +08:00
|
|
|
|
|
|
|
def REM : R<["--"], "">;
|