forked from OSchip/llvm-project
[Driver] Use libOption with tablegen.
This patch modifies the lldb driver to use libOption for option parsing. It allows us to decouple option parsing from option processing which is important when arguments affect initialization. This was previously not possible because the debugger need to be initialized as some option interpretation (like the scripting language etc) was handled by the debugger, rather than in the driver. Differential revision: https://reviews.llvm.org/D54692 llvm-svn: 347709
This commit is contained in:
parent
3aeeaff89f
commit
00eae5ea31
|
@ -0,0 +1 @@
|
|||
expr 0
|
|
@ -0,0 +1 @@
|
|||
expr 2
|
|
@ -0,0 +1 @@
|
|||
expr 4
|
|
@ -0,0 +1 @@
|
|||
expr 6
|
|
@ -0,0 +1,41 @@
|
|||
# RUN: %lldb -x -b \
|
||||
# RUN: -S %S/Inputs/Print0.in \
|
||||
# RUN: -O 'expr 1' \
|
||||
# RUN: -S %S/Inputs/Print2.in \
|
||||
# RUN: -O 'expr 3' \
|
||||
# RUN: -s %S/Inputs/Print4.in \
|
||||
# RUN: -o 'expr 5' \
|
||||
# RUN: -s %S/Inputs/Print6.in \
|
||||
# RUN: -o 'expr 7' \
|
||||
# RUN: | FileCheck %s
|
||||
#
|
||||
# RUN: %lldb -x -b \
|
||||
# RUN: -s %S/Inputs/Print4.in \
|
||||
# RUN: -o 'expr 5' \
|
||||
# RUN: -s %S/Inputs/Print6.in \
|
||||
# RUN: -o 'expr 7' \
|
||||
# RUN: -S %S/Inputs/Print0.in \
|
||||
# RUN: -O 'expr 1' \
|
||||
# RUN: -S %S/Inputs/Print2.in \
|
||||
# RUN: -O 'expr 3' \
|
||||
# RUN: | FileCheck %s
|
||||
#
|
||||
# RUN: %lldb -x -b \
|
||||
# RUN: -s %S/Inputs/Print4.in \
|
||||
# RUN: -S %S/Inputs/Print0.in \
|
||||
# RUN: -o 'expr 5' \
|
||||
# RUN: -O 'expr 1' \
|
||||
# RUN: -s %S/Inputs/Print6.in \
|
||||
# RUN: -S %S/Inputs/Print2.in \
|
||||
# RUN: -o 'expr 7' \
|
||||
# RUN: -O 'expr 3' \
|
||||
# RUN: | FileCheck %s
|
||||
|
||||
# CHECK: (int) $0 = 0
|
||||
# CHECK: (int) $1 = 1
|
||||
# CHECK: (int) $2 = 2
|
||||
# CHECK: (int) $3 = 3
|
||||
# CHECK: (int) $4 = 4
|
||||
# CHECK: (int) $5 = 5
|
||||
# CHECK: (int) $6 = 6
|
||||
# CHECK: (int) $7 = 7
|
|
@ -0,0 +1,4 @@
|
|||
# RUN: %lldb --no-use-color -s %s | FileCheck %s
|
||||
settings show use-color
|
||||
# CHECK: use-color (boolean) = false
|
||||
q
|
|
@ -2373,6 +2373,8 @@
|
|||
260A248D15D06C4F009981B0 /* OptionValues.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OptionValues.h; path = include/lldb/Interpreter/OptionValues.h; sourceTree = "<group>"; };
|
||||
26BC7E8610F1B85900F91463 /* Options.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Options.cpp; path = source/Interpreter/Options.cpp; sourceTree = "<group>"; };
|
||||
26BC7D6D10F1B77400F91463 /* Options.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Options.h; path = include/lldb/Interpreter/Options.h; sourceTree = "<group>"; };
|
||||
DD5F951A21ADE5BD00B8265A /* Options.inc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.pascal; name = Options.inc; path = build/Debug/include/Options.inc; sourceTree = "<group>"; };
|
||||
DD5F951B21ADE5F000B8265A /* Options.td */ = {isa = PBXFileReference; lastKnownFileType = text; name = Options.td; path = tools/driver/Options.td; sourceTree = "<group>"; };
|
||||
4C562CC21CC07DDD00C52EAC /* PDBASTParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PDBASTParser.cpp; path = PDB/PDBASTParser.cpp; sourceTree = "<group>"; };
|
||||
4C562CC31CC07DDD00C52EAC /* PDBASTParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PDBASTParser.h; path = PDB/PDBASTParser.h; sourceTree = "<group>"; };
|
||||
4CA0C6CA20F929C600CFE6BB /* PDBLocationToDWARFExpression.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PDBLocationToDWARFExpression.cpp; path = PDB/PDBLocationToDWARFExpression.cpp; sourceTree = "<group>"; };
|
||||
|
@ -5916,6 +5918,8 @@
|
|||
26F5C22510F3D956009D5894 /* Driver */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
DD5F951B21ADE5F000B8265A /* Options.td */,
|
||||
DD5F951A21ADE5BD00B8265A /* Options.inc */,
|
||||
26F5C27210F3D9E4009D5894 /* lldb-Info.plist */,
|
||||
26F5C27410F3D9E4009D5894 /* Driver.h */,
|
||||
26F5C27310F3D9E4009D5894 /* Driver.cpp */,
|
||||
|
@ -7173,6 +7177,7 @@
|
|||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 26F5C26E10F3D9C5009D5894 /* Build configuration list for PBXNativeTarget "lldb-tool" */;
|
||||
buildPhases = (
|
||||
DD5F951721ADD0C900B8265A /* Run Tablegen */,
|
||||
26F5C26710F3D9A4009D5894 /* Sources */,
|
||||
26F5C26810F3D9A4009D5894 /* Frameworks */,
|
||||
);
|
||||
|
@ -7514,9 +7519,29 @@
|
|||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = "/bin/sh -x";
|
||||
shellScript = "/bin/rm -rf \"$INSTALL_ROOT/System/Library/PrivateFrameworks/LLDB.framework/Resources\" \"$INSTALL_ROOT/System/Library/PrivateFrameworks/LLDB.framework/Swift\"";
|
||||
shellScript = "/bin/rm -rf \"$INSTALL_ROOT/System/Library/PrivateFrameworks/LLDB.framework/Resources\" \"$INSTALL_ROOT/System/Library/PrivateFrameworks/LLDB.framework/Swift\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
DD5F951721ADD0C900B8265A /* Run Tablegen */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputFileListPaths = (
|
||||
);
|
||||
inputPaths = (
|
||||
$SOURCE_DIR/tools/driver/Options.td,
|
||||
);
|
||||
name = "Run Tablegen";
|
||||
outputFileListPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
$BUILT_PRODUCTS_DIR/Options.inc,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "mkdir -p $BUILT_PRODUCTS_DIR/include\n$LLVM_BUILD_DIR/x86_64/bin/llvm-tblgen -I$LLVM_SOURCE_DIR/include -gen-opt-parser-defs $SRCROOT/tools/driver/Options.td -o $BUILT_PRODUCTS_DIR/include/Options.inc\n";
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
|
@ -10531,7 +10556,7 @@
|
|||
"$(LLVM_BUILD_DIR)/archives.txt",
|
||||
);
|
||||
PRODUCT_NAME = lldb;
|
||||
USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/include $(SRCROOT)/source $(LLVM_SOURCE_DIR)/include $(LLVM_BUILD_DIR)/$(LLVM_BUILD_DIR_ARCH)/include";
|
||||
USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/include $(SRCROOT)/source $(LLVM_SOURCE_DIR)/include $(LLVM_BUILD_DIR)/$(LLVM_BUILD_DIR_ARCH)/include ${LLDB_BUILD_DIR}/include";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
};
|
||||
name = Release;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
set(LLVM_TARGET_DEFINITIONS Options.td)
|
||||
tablegen(LLVM Options.inc -gen-opt-parser-defs)
|
||||
add_public_tablegen_target(LLDBOptionsTableGen)
|
||||
|
||||
if ((CMAKE_SYSTEM_NAME MATCHES "Windows") OR
|
||||
(CMAKE_SYSTEM_NAME MATCHES "NetBSD" ))
|
||||
# These targets do not have getopt support, so they rely on the one provided by
|
||||
|
@ -17,6 +21,7 @@ add_lldb_tool(lldb
|
|||
${host_lib}
|
||||
|
||||
LINK_COMPONENTS
|
||||
Option
|
||||
Support
|
||||
)
|
||||
|
||||
|
@ -24,4 +29,8 @@ if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
|
|||
add_definitions( -DIMPORT_LIBLLDB )
|
||||
endif()
|
||||
|
||||
add_dependencies(lldb ${LLDB_SUITE_TARGET})
|
||||
add_dependencies(lldb
|
||||
${LLDB_SUITE_TARGET}
|
||||
LLDBOptionsTableGen
|
||||
${tablegen_deps}
|
||||
)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -12,15 +12,19 @@
|
|||
|
||||
#include "Platform.h"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "lldb/API/SBBroadcaster.h"
|
||||
#include "lldb/API/SBDebugger.h"
|
||||
#include "lldb/API/SBDefines.h"
|
||||
#include "lldb/API/SBError.h"
|
||||
|
||||
#include "llvm/Option/Arg.h"
|
||||
#include "llvm/Option/ArgList.h"
|
||||
#include "llvm/Option/Option.h"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Driver : public lldb::SBBroadcaster {
|
||||
public:
|
||||
typedef enum CommandPlacement {
|
||||
|
@ -38,8 +42,8 @@ public:
|
|||
/// @return The exit code that the process should return.
|
||||
int MainLoop();
|
||||
|
||||
lldb::SBError ParseArgs(int argc, const char *argv[], FILE *out_fh,
|
||||
bool &do_exit);
|
||||
lldb::SBError ProcessArgs(const llvm::opt::InputArgList &args, FILE *out_fh,
|
||||
bool &do_exit);
|
||||
|
||||
const char *GetFilename() const;
|
||||
|
||||
|
@ -61,13 +65,13 @@ public:
|
|||
|
||||
void Clear();
|
||||
|
||||
void AddInitialCommand(const char *command, CommandPlacement placement,
|
||||
void AddInitialCommand(std::string command, CommandPlacement placement,
|
||||
bool is_file, lldb::SBError &error);
|
||||
|
||||
struct InitialCmdEntry {
|
||||
InitialCmdEntry(const char *in_contents, bool in_is_file,
|
||||
InitialCmdEntry(std::string contents, bool in_is_file,
|
||||
bool is_cwd_lldbinit_file_read, bool in_quiet = false)
|
||||
: contents(in_contents), is_file(in_is_file),
|
||||
: contents(std::move(contents)), is_file(in_is_file),
|
||||
is_cwd_lldbinit_file_read(is_cwd_lldbinit_file_read),
|
||||
source_quietly(in_quiet) {}
|
||||
|
||||
|
@ -89,7 +93,6 @@ public:
|
|||
bool m_source_quietly;
|
||||
bool m_print_version;
|
||||
bool m_print_python_path;
|
||||
bool m_print_help;
|
||||
bool m_wait_for;
|
||||
bool m_repl;
|
||||
lldb::LanguageType m_repl_lang;
|
||||
|
|
|
@ -0,0 +1,218 @@
|
|||
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>;
|
||||
|
||||
// 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>;
|
||||
|
||||
def script_language: Separate<["--", "-"], "script-language">, MetaVarName<"<language>">,
|
||||
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">;
|
||||
|
||||
def repl: Separate<["--", "-"], "repl">,
|
||||
HelpText<"Runs lldb in REPL mode with a stub process.">,
|
||||
Group<grp_repl>;
|
||||
def: Separate<["-"], "r">,
|
||||
Alias<repl>,
|
||||
HelpText<"Alias for --repl">,
|
||||
Group<grp_repl>;
|
||||
|
||||
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>;
|
||||
|
||||
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">,
|
||||
HelpText<"Tells the debugger to execute this one-line lldb command before any file has been loaded.">,
|
||||
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>">,
|
||||
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<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">;
|
||||
|
||||
def core: F<"core">,
|
||||
HelpText<"Tells the debugger to use the full path to <core> as the core file.">;
|
||||
def: Flag<["-"], "c">,
|
||||
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">;
|
||||
|
||||
def reproducer: Separate<["--", "-"], "reproducer">,
|
||||
MetaVarName<"<filename>">,
|
||||
HelpText<"Tells the debugger to use the fullpath to <filename> as a reproducer.">;
|
||||
def: Separate<["-"], "z">,
|
||||
Alias<file>,
|
||||
HelpText<"Alias for --reproducer">;
|
||||
|
||||
def REM : R<["--"], "">;
|
Loading…
Reference in New Issue