diff options
20 files changed, 353 insertions, 300 deletions
diff --git a/lldb/include/lldb/Core/Options.h b/lldb/include/lldb/Core/Options.h index acdd3118fae..c19f5e56aa0 100644 --- a/lldb/include/lldb/Core/Options.h +++ b/lldb/include/lldb/Core/Options.h @@ -20,6 +20,7 @@ // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" +#include "lldb/lldb-defines.h" #include "lldb/Core/Args.h" namespace lldb_private { @@ -134,8 +135,9 @@ public: struct option * GetLongOptions (); + // This gets passed the short option as an integer... void - OptionSeen (int option_idx); + OptionSeen (int short_option); bool VerifyOptions (CommandReturnObject &result); @@ -163,10 +165,10 @@ public: // this class. virtual const lldb::OptionDefinition* - GetDefinitions () = 0; + GetDefinitions () { return NULL; }; virtual void - ResetOptionValues () = 0; + ResetOptionValues (); //------------------------------------------------------------------ /// Set the value of an option. @@ -272,6 +274,7 @@ public: StringList &matches); protected: + // This is a set of options expressed as indexes into the options table for this Option. typedef std::set<char> OptionSet; std::vector<struct option> m_getopt_table; diff --git a/lldb/include/lldb/lldb-defines.h b/lldb/include/lldb/lldb-defines.h index 530d9ac7276..bf2d4839312 100644 --- a/lldb/include/lldb/lldb-defines.h +++ b/lldb/include/lldb/lldb-defines.h @@ -70,7 +70,21 @@ #define LLDB_ARCH_DEFAULT_64BIT "systemArch64" #define LLDB_INVALID_CPUTYPE (0xFFFFFFFEu) - +//---------------------------------------------------------------------- +/// Option Set defintions +//---------------------------------------------------------------------- +// FIXME: I'm sure there's some #define magic that can create all 32 sets on the +// fly. That would have the added benefit of making this unreadable. +#define LLDB_MAX_NUM_OPTION_SETS 32 +#define LLDB_OPT_SET_ALL 0xFFFFFFFF +#define LLDB_OPT_SET_1 1 << 0 +#define LLDB_OPT_SET_2 1 << 1 +#define LLDB_OPT_SET_3 1 << 2 +#define LLDB_OPT_SET_4 1 << 3 +#define LLDB_OPT_SET_5 1 << 4 +#define LLDB_OPT_SET_6 1 << 5 +#define LLDB_OPT_SET_7 1 << 6 +#define LLDB_OPT_SET_8 1 << 7 #if defined(__cplusplus) diff --git a/lldb/include/lldb/lldb-types.h b/lldb/include/lldb/lldb-types.h index fae11fff5d0..d9b42d09f94 100644 --- a/lldb/include/lldb/lldb-types.h +++ b/lldb/include/lldb/lldb-types.h @@ -131,7 +131,8 @@ namespace lldb { typedef struct { - uint32_t usage_level; // Used to mark options that can be used together. + uint32_t usage_mask; // Used to mark options that can be used together. If 1 << n && usage_mask != 0 + // then this option belongs to option set n. bool required; // This option is required (in the current usage level) CONST_CHAR_PTR long_option; // Full name for this option. char short_option; // Single character for this option. diff --git a/lldb/source/Commands/CommandObjectArgs.cpp b/lldb/source/Commands/CommandObjectArgs.cpp index 5e432d78ca7..f450e40c208 100644 --- a/lldb/source/Commands/CommandObjectArgs.cpp +++ b/lldb/source/Commands/CommandObjectArgs.cpp @@ -273,7 +273,7 @@ CommandObjectArgs::Execute(Args &command, lldb::OptionDefinition CommandObjectArgs::CommandOptions::g_option_table[] = { - { 0, false, "debug", 'g', no_argument, NULL, 0, NULL, "Enable verbose debug logging of the expression parsing and evaluation."}, + { LLDB_OPT_SET_1, false, "debug", 'g', no_argument, NULL, 0, NULL, "Enable verbose debug logging of the expression parsing and evaluation."}, { 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL } }; diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp index d24ba8f553b..68926e24b6d 100644 --- a/lldb/source/Commands/CommandObjectBreakpoint.cpp +++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp @@ -17,6 +17,7 @@ #include "lldb/Breakpoint/Breakpoint.h" #include "lldb/Breakpoint/BreakpointIDList.h" #include "lldb/Breakpoint/BreakpointLocation.h" +#include "lldb/Core/Options.h" #include "lldb/Core/RegularExpression.h" #include "lldb/Core/StreamString.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -62,47 +63,32 @@ CommandObjectBreakpointSet::CommandOptions::~CommandOptions () lldb::OptionDefinition CommandObjectBreakpointSet::CommandOptions::g_option_table[] = { - { 0, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, "<filename>", + { LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, "<shlib-name>", + "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."}, + + { LLDB_OPT_SET_ALL, false, "ignore_inlines", 'i', no_argument, NULL, 0, NULL, + "Ignore inlined subroutines when setting the breakppoint." }, + + { LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, "<filename>", "Set the breakpoint by source location in this particular file."}, - { 0, true, "line", 'l', required_argument, NULL, 0, "<linenum>", + { LLDB_OPT_SET_1, true, "line", 'l', required_argument, NULL, 0, "<linenum>", "Set the breakpoint by source location at this particular line."}, - { 0, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, "<shlib-name>", - "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."}, - // Comment out this option for the moment, as we don't actually use it, but will in the future. // This way users won't see it, but the infrastructure is left in place. // { 0, false, "column", 'c', required_argument, NULL, "<column>", // "Set the breakpoint by source location at this particular column."}, - { 0, false, "ignore_inlines", 'i', no_argument, NULL, 0, NULL, - "Ignore inlined subroutines when setting the breakppoint." }, - - { 1, true, "address", 'a', required_argument, NULL, 0, "<address>", + { LLDB_OPT_SET_2, true, "address", 'a', required_argument, NULL, 0, "<address>", "Set the breakpoint by address, at the specified address."}, - { 1, false, "ignore_inlines", 'i', no_argument, NULL, 0, NULL, - "Ignore inlined subroutines when setting the breakppoint." }, - - { 2, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, "<function-name>", + { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, "<function-name>", "Set the breakpoint by function name." }, - { 2, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, "<shlib-name>", - "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."}, - - { 2, false, "ignore_inlines", 'i', no_argument, NULL, 0, NULL, - "Ignore inlined subroutines when setting the breakpoint." }, - - { 3, true, "func_regex", 'r', required_argument, NULL, 0, "<regular-expression>", + { LLDB_OPT_SET_4, true, "func_regex", 'r', required_argument, NULL, 0, "<regular-expression>", "Set the breakpoint by function name, evaluating a regular-expression to find the function name(s)." }, - { 3, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, "<shlib-name>", - "Set the breakpoint only in this shared library (can use this option multiple times for multiple shlibs)."}, - - { 3, false, "ignore_inlines", 'i', no_argument, NULL, 0, NULL, - "Ignore inlined subroutines when setting the breakpoint." }, - { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; @@ -505,25 +491,19 @@ CommandObjectBreakpointList::CommandOptions::~CommandOptions () lldb::OptionDefinition CommandObjectBreakpointList::CommandOptions::g_option_table[] = { - { 0, false, "brief", 'b', no_argument, NULL, 0, NULL, + { LLDB_OPT_SET_ALL, false, "internal", 'i', no_argument, NULL, 0, NULL, + "Show debugger internal breakpoints" }, + + { LLDB_OPT_SET_1, false, "brief", 'b', no_argument, NULL, 0, NULL, "Give a brief description of the breakpoint (no location info)."}, // FIXME: We need to add an "internal" command, and then add this sort of thing to it. // But I need to see it for now, and don't want to wait. - { 0, false, "internal", 'i', no_argument, NULL, 0, NULL, - "Show debugger internal breakpoints" }, - - { 1, false, "full", 'f', no_argument, NULL, 0, NULL, + { LLDB_OPT_SET_2, false, "full", 'f', no_argument, NULL, 0, NULL, "Give a full description of the breakpoint and its locations."}, - // DITTO FIXME - { 1, false, "internal", 'i', no_argument, NULL, 0, NULL, - "Show debugger internal breakpoints" }, - { 2, false, "verbose", 'v', no_argument, NULL, 0, NULL, + { LLDB_OPT_SET_3, false, "verbose", 'v', no_argument, NULL, 0, NULL, "Explain everything we know about the breakpoint (for debugging debugger bugs)." }, - // DITTO FIXME - { 2, false, "internal", 'i', no_argument, NULL, 0, NULL, - "Show debugger internal breakpoints" }, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp index 8a5a443ea8e..dc1c84b0e64 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -44,13 +44,13 @@ CommandObjectBreakpointCommandAdd::CommandOptions::~CommandOptions () lldb::OptionDefinition CommandObjectBreakpointCommandAdd::CommandOptions::g_option_table[] = { - { 0, true, "script", 's', no_argument, NULL, 0, NULL, + { LLDB_OPT_SET_1, true, "script", 's', no_argument, NULL, 0, NULL, "Write the breakpoint command script in the default scripting language."}, - { 1, true, "python", 'p', no_argument, NULL, 0, NULL, + { LLDB_OPT_SET_2, true, "python", 'p', no_argument, NULL, 0, NULL, "Write the breakpoint command script in the Python scripting language."}, - { 2, true, "commands", 'c', no_argument, NULL, 0, NULL, + { LLDB_OPT_SET_3, true, "commands", 'c', no_argument, NULL, 0, NULL, "Write the breakpoint command script using the command line commands."}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } diff --git a/lldb/source/Commands/CommandObjectCall.cpp b/lldb/source/Commands/CommandObjectCall.cpp index 58d0a0e9f11..e7a5f8d1b1b 100644 --- a/lldb/source/Commands/CommandObjectCall.cpp +++ b/lldb/source/Commands/CommandObjectCall.cpp @@ -297,11 +297,11 @@ CommandObjectCall::Execute lldb::OptionDefinition CommandObjectCall::CommandOptions::g_option_table[] = { -{ 0, true, "language", 'l', required_argument, NULL, 0, "[c|c++|objc|objc++]", "Sets the language to use when parsing the expression."}, -{ 0, false, "format", 'f', required_argument, NULL, 0, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]", "Specify the format that the expression output should use."}, -{ 0, false, "debug", 'g', no_argument, NULL, 0, NULL, "Enable verbose debug logging of the expression parsing and evaluation."}, -{ 0, false, "noexecute", 'n', no_argument, NULL, 0, "no execute", "Only JIT and copy the wrapper & arguments, but don't execute."}, -{ 0, false, "useabi", 'a', no_argument, NULL, 0, NULL, "Use the ABI instead of the JIT to marshall arguments."}, +{ LLDB_OPT_SET_1, true, "language", 'l', required_argument, NULL, 0, "[c|c++|objc|objc++]", "Sets the language to use when parsing the expression."}, +{ LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]", "Specify the format that the expression output should use."}, +{ LLDB_OPT_SET_1, false, "debug", 'g', no_argument, NULL, 0, NULL, "Enable verbose debug logging of the expression parsing and evaluation."}, +{ LLDB_OPT_SET_1, false, "noexecute", 'n', no_argument, NULL, 0, "no execute", "Only JIT and copy the wrapper & arguments, but don't execute."}, +{ LLDB_OPT_SET_1, false, "useabi", 'a', no_argument, NULL, 0, NULL, "Use the ABI instead of the JIT to marshall arguments."}, { 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL } }; diff --git a/lldb/source/Commands/CommandObjectDisassemble.cpp b/lldb/source/Commands/CommandObjectDisassemble.cpp index 0985504e4ff..651858aa136 100644 --- a/lldb/source/Commands/CommandObjectDisassemble.cpp +++ b/lldb/source/Commands/CommandObjectDisassemble.cpp @@ -34,7 +34,8 @@ using namespace lldb_private; CommandObjectDisassemble::CommandOptions::CommandOptions () : Options(), m_func_name(), - m_load_addr() + m_start_addr(), + m_end_addr () { ResetOptionValues(); } @@ -64,13 +65,21 @@ CommandObjectDisassemble::CommandOptions::SetOptionValue (int option_idx, const show_bytes = true; break; - case 'a': - m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 0); - if (m_load_addr == LLDB_INVALID_ADDRESS) - m_load_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 16); + case 's': + m_start_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 0); + if (m_start_addr == LLDB_INVALID_ADDRESS) + m_start_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 16); - if (m_load_addr == LLDB_INVALID_ADDRESS) - error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", optarg); + if (m_start_addr == LLDB_INVALID_ADDRESS) + error.SetErrorStringWithFormat ("Invalid start address string '%s'.\n", optarg); + break; + case 'e': + m_end_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 0); + if (m_end_addr == LLDB_INVALID_ADDRESS) + m_end_addr = Args::StringToUInt64(optarg, LLDB_INVALID_ADDRESS, 16); + + if (m_end_addr == LLDB_INVALID_ADDRESS) + error.SetErrorStringWithFormat ("Invalid end address string '%s'.\n", optarg); break; case 'n': @@ -97,7 +106,8 @@ CommandObjectDisassemble::CommandOptions::ResetOptionValues () show_bytes = false; num_lines_context = 0; m_func_name.clear(); - m_load_addr = LLDB_INVALID_ADDRESS; + m_start_addr = LLDB_INVALID_ADDRESS; + m_end_addr = LLDB_INVALID_ADDRESS; } const lldb::OptionDefinition* @@ -109,22 +119,17 @@ CommandObjectDisassemble::CommandOptions::GetDefinitions () lldb::OptionDefinition CommandObjectDisassemble::CommandOptions::g_option_table[] = { -{ 0, false, "bytes", 'b', no_argument, NULL, 0, NULL, "Show opcode bytes when disassembling."}, -{ 0, false, "context", 'c', required_argument, NULL, 0, "<num-lines>", "Number of context lines of source to show."}, -{ 0, false, "mixed", 'm', no_argument, NULL, 0, NULL, "Enable mixed source and assembly display."}, -{ 0, false, "raw", 'r', no_argument, NULL, 0, NULL, "Print raw disassembly with no symbol information."}, - -{ 1, false, "address", 'a', required_argument, NULL, 0, "<address>", "Address to start disassembling."}, -{ 1, false, "bytes", 'b', no_argument, NULL, 0, NULL, "Show opcode bytes when disassembling."}, -{ 1, false, "context", 'c', required_argument, NULL, 0, "<num-lines>", "Number of context lines of source to show."}, -{ 1, false, "mixed", 'm', no_argument, NULL, 0, NULL, "Enable mixed source and assembly display."}, -{ 1, false, "raw", 'r', no_argument, NULL, 0, NULL, "Print raw disassembly with no symbol information."}, - -{ 2, false, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, "<function-name>", "Disassemble entire contents of the given function name."}, -{ 2, false, "bytes", 'b', no_argument, NULL, 0, NULL, "Show opcode bytes when disassembling."}, -{ 2, false, "context", 'c', required_argument, NULL, 0, "<num-lines>", "Number of context lines of source to show."}, -{ 2, false, "mixed", 'm', no_argument, NULL, 0, NULL, "Enable mixed source and assembly display."}, -{ 2, false, "raw", 'r', no_argument, NULL, 0, NULL, "Print raw disassembly with no symbol information."}, +{ LLDB_OPT_SET_ALL, false, "bytes", 'b', no_argument, NULL, 0, NULL, "Show opcode bytes when disassembling."}, +{ LLDB_OPT_SET_ALL, false, "context", 'c', required_argument, NULL, 0, "<num-lines>", "Number of context lines of source to show."}, +{ LLDB_OPT_SET_ALL, false, "mixed", 'm', no_argument, NULL, 0, NULL, "Enable mixed source and assembly display."}, +{ LLDB_OPT_SET_ALL, false, "raw", 'r', no_argument, NULL, 0, NULL, "Print raw disassembly with no symbol information."}, + +{ LLDB_OPT_SET_1, true, "start-address", 's', required_argument, NULL, 0, "<start-address>", "Address to start disassembling."}, +{ LLDB_OPT_SET_1, false, "end-address", 'e', required_argument, NULL, 0, "<end-address>", "Address to start disassembling."}, + +{ LLDB_OPT_SET_2, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, "<function-name>", "Disassemble entire contents of the given function name."}, + +{ LLDB_OPT_SET_3, false, "current-frame", 'f', no_argument, NULL, 0, "<current-frame>", "Disassemble entire contents of the current frame's function."}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; @@ -138,7 +143,7 @@ CommandObjectDisassemble::CommandOptions::g_option_table[] = CommandObjectDisassemble::CommandObjectDisassemble () : CommandObject ("disassemble", "Disassemble bytes in the current function or anywhere in the inferior program.", - "disassemble [[<start-addr> [<end-addr>]] | <function-name>] [<cmd-options>]") + "disassemble [<cmd-options>]") { } @@ -317,15 +322,35 @@ CommandObjectDisassemble::Execute lldb::addr_t end_addr = LLDB_INVALID_ADDRESS; ConstString name; const size_t argc = command.GetArgumentCount(); - if (argc == 0 && m_options.m_load_addr != LLDB_INVALID_ADDRESS) + if (argc != 0) { - addr = m_options.m_load_addr; - end_addr = addr + DEFAULT_DISASM_BYTE_SIZE; - } else if (argc == 0 && !m_options.m_func_name.empty()) + result.AppendErrorWithFormat ("\"disassemble\" doesn't take any arguments.\n"); + result.SetStatus (eReturnStatusFailed); + return false; + } + + if (m_options.m_start_addr != LLDB_INVALID_ADDRESS) + { + addr = m_options.m_start_addr; + if (m_options.m_end_addr != LLDB_INVALID_ADDRESS) + { + end_addr = m_options.m_end_addr; + if (end_addr < addr) + { + result.AppendErrorWithFormat ("End address before start address.\n"); + result.SetStatus (eReturnStatusFailed); + return false; + } + } + else + end_addr = addr + DEFAULT_DISASM_BYTE_SIZE; + } + else if (!m_options.m_func_name.empty()) { ConstString tmpname(m_options.m_func_name.c_str()); name = tmpname; - } else if (argc == 0) + } + else { ExecutionContext exe_ctx(context->GetExecutionContext()); if (exe_ctx.frame) @@ -361,38 +386,6 @@ CommandObjectDisassemble::Execute return false; } } - else if (argc == 1) - { - const char *arg = command.GetArgumentAtIndex(0); - addr = Args::StringToAddress (arg); - if (addr == LLDB_INVALID_ADDRESS) - { - // Lookup function or symbol name? - ConstString tmpname(arg); - name = tmpname; - } - else - { - end_addr = addr + DEFAULT_DISASM_BYTE_SIZE; - } - } - else if (argc >= 1 && argc <= 2) - { - addr = Args::StringToAddress (command.GetArgumentAtIndex(0)); - if (addr == LLDB_INVALID_ADDRESS) - { - result.AppendErrorWithFormat ("Unable to parse address '%s'.\n", command.GetArgumentAtIndex(0)); - result.SetStatus (eReturnStatusFailed); - return false; - } - end_addr = Args::StringToAddress (command.GetArgumentAtIndex(1), addr); - if (end_addr == LLDB_INVALID_ADDRESS) - { - result.AppendErrorWithFormat ("Unable to parse address '%s'.\n", command.GetArgumentAtIndex(1)); - result.SetStatus (eReturnStatusFailed); - return false; - } - } if (!name.IsEmpty()) { @@ -413,19 +406,10 @@ CommandObjectDisassemble::Execute return false; } } - - if (addr < end_addr) + else { Disassemble (context, interpreter, result, disassembler, addr, end_addr); } - if (addr == LLDB_INVALID_ADDRESS && name.IsEmpty()) - { - result.AppendError ("No recognizable address of function name provided"); - result.SetStatus (eReturnStatusFailed); - return false; - } - { - return result.Succeeded(); - } + return result.Succeeded(); } diff --git a/lldb/source/Commands/CommandObjectDisassemble.h b/lldb/source/Commands/CommandObjectDisassemble.h index 2cf800d2f59..e4587cb72c2 100644 --- a/lldb/source/Commands/CommandObjectDisassemble.h +++ b/lldb/source/Commands/CommandObjectDisassemble.h @@ -49,7 +49,8 @@ public: uint32_t num_lines_context; bool raw; std::string m_func_name; - lldb::addr_t m_load_addr; + lldb::addr_t m_start_addr; + lldb::addr_t m_end_addr; static lldb::OptionDefinition g_option_table[]; }; diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 9afc8c0a1a3..1ed606b74e9 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -546,9 +546,9 @@ CommandObjectExpression::ExecuteRawCommandString lldb::OptionDefinition CommandObjectExpression::CommandOptions::g_option_table[] = { -{ 0, true, "language", 'l', required_argument, NULL, 0, "[c|c++|objc|objc++]", "Sets the language to use when parsing the expression."}, -{ 0, false, "format", 'f', required_argument, NULL, 0, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]", "Specify the format that the expression output should use."}, -{ 0, false, "debug", 'g', no_argument, NULL, 0, NULL, "Enable verbose debug logging of the expression parsing and evaluation."}, +{ LLDB_OPT_SET_1, true, "language", 'l', required_argument, NULL, 0, "[c|c++|objc|objc++]", "Sets the language to use when parsing the expression."}, +{ LLDB_OPT_SET_2, false, "format", 'f', required_argument, NULL, 0, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]", "Specify the format that the expression output should use."}, +{ LLDB_OPT_SET_3, false, "debug", 'g', no_argument, NULL, 0, NULL, "Enable verbose debug logging of the expression parsing and evaluation."}, { 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL } }; diff --git a/lldb/source/Commands/CommandObjectFile.cpp b/lldb/source/Commands/CommandObjectFile.cpp index 01576c5b6d5..de40c6ee7fd 100644 --- a/lldb/source/Commands/CommandObjectFile.cpp +++ b/lldb/source/Commands/CommandObjectFile.cpp @@ -38,7 +38,7 @@ CommandObjectFile::CommandOptions::~CommandOptions () lldb::OptionDefinition CommandObjectFile::CommandOptions::g_option_table[] = { - { 0, false, "arch", 'a', required_argument, NULL, 0, "<arch>", "Specify the architecture to launch."}, + { LLDB_OPT_SET_1, false, "arch", 'a', required_argument, NULL, 0, "<arch>", "Specify the architecture to launch."}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; diff --git a/lldb/source/Commands/CommandObjectImage.cpp b/lldb/source/Commands/CommandObjectImage.cpp index ab728e9d32d..1f4d170e7b4 100644 --- a/lldb/source/Commands/CommandObjectImage.cpp +++ b/lldb/source/Commands/CommandObjectImage.cpp @@ -1066,13 +1066,13 @@ protected: lldb::OptionDefinition CommandObjectImageList::CommandOptions::g_option_table[] = { -{ 0, false, "arch", 'a', optional_argument, NULL, 0, "<width>", "Display the architecture when listing images."}, -{ 0, false, "uuid", 'u', no_argument, NULL, 0, NULL, "Display the UUID when listing images."}, -{ 0, false, "fullpath", 'f', optional_argument, NULL, 0, "<width>", "Display the fullpath to the image object file."}, -{ 0, false, "directory", 'd', optional_argument, NULL, 0, "<width>", "Display the directory with optional width for the image object file."}, -{ 0, false, "basename", 'b', optional_argument, NULL, 0, "<width>", "Display the basename with optional width for the image object file."}, -{ 0, false, "symfile", 's', optional_argument, NULL, 0, "<width>", "Display the fullpath to the image symbol file with optional width."}, -{ 0, false, "symfile-basename", 'S', optional_argument, NULL, 0, "<width>", "Display the basename to the image symbol file with optional width."}, +{ LLDB_OPT_SET_1, false, "arch", 'a', optional_argument, NULL, 0, "<width>", "Display the architecture when listing images."}, +{ LLDB_OPT_SET_1, false, "uuid", 'u', no_argument, NULL, 0, NULL, "Display the UUID when listing images."}, +{ LLDB_OPT_SET_1, false, "fullpath", 'f', optional_argument, NULL, 0, "<width>", "Display the fullpath to the image object file."}, +{ LLDB_OPT_SET_1, false, "directory", 'd', optional_argument, NULL, 0, "<width>", "Display the directory with optional width for the image object file."}, +{ LLDB_OPT_SET_1, false, "basename", 'b', optional_argument, NULL, 0, "<width>", "Display the basename with optional width for the image object file."}, +{ LLDB_OPT_SET_1, false, "symfile", 's', optional_argument, NULL, 0, "<width>", "Display the fullpath to the image symbol file with optional width."}, +{ LLDB_OPT_SET_1, false, "symfile-basename", 'S', optional_argument, NULL, 0, "<width>", "Display the basename to the image symbol file with optional width."}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; @@ -1381,15 +1381,14 @@ protected: lldb::OptionDefinition CommandObjectImageLookup::CommandOptions::g_option_table[] = { -{ 1, true, "address", 'a', required_argument, NULL, 0, "<addr>", "Lookup an address in one or more executable images."}, -{ 1, false, "offset", 'o', required_argument, NULL, 0, "<offset>", "When looking up an address subtract <offset> from any addresses before doing the lookup."}, -{ 2, true, "symbol", 's', required_argument, NULL, 0, "<name>", "Lookup a symbol by name in the symbol tables in one or more executable images."}, -{ 2, false, "regex", 'r', no_argument, NULL, 0, NULL, "The <name> argument for name lookups are regular expressions."}, -{ 3, true, "file", 'f', required_argument, NULL, 0, "<file>", "Lookup a file by fullpath or basename in one or more executable images."}, -{ 3, false, "line", 'l', required_argument, NULL, 0, "<line>", "Lookup a line number in a file (must be used in conjunction with --file)."}, -{ 3, false, "no-inlines", 'i', no_argument, NULL, 0, NULL, "Check inline line entries (must be used in conjunction with --file)."}, -{ 4, true, "function", 'n', required_argument, NULL, 0, "<name>", "Lookup a function by name in the debug symbols in one or more executable images."}, -{ 5, false, "regex", 'r', no_argument, NULL, 0, NULL, "The <name> argument for name lookups are regular expressions."}, +{ LLDB_OPT_SET_1, true, "address", 'a', required_argument, NULL, 0, "<addr>", "Lookup an address in one or more executable images."}, +{ LLDB_OPT_SET_1, false, "offset", 'o', required_argument, NULL, 0, "<offset>", "When looking up an address subtract <offset> from any addresses before doing the lookup."}, +{ LLDB_OPT_SET_2, true, "symbol", 's', required_argument, NULL, 0, "<name>", "Lookup a symbol by name in the symbol tables in one or more executable images."}, +{ LLDB_OPT_SET_2, false, "regex", 'r', no_argument, NULL, 0, NULL, "The <name> argument for name lookups are regular expressions."}, +{ LLDB_OPT_SET_3, true, "file", 'f', required_argument, NULL, 0, "<file>", "Lookup a file by fullpath or basename in one or more executable images."}, +{ LLDB_OPT_SET_3, false, "line", 'l', required_argument, NULL, 0, "<line>", "Lookup a line number in a file (must be used in conjunction with --file)."}, +{ LLDB_OPT_SET_3, false, "no-inlines", 'i', no_argument, NULL, 0, NULL, "Check inline line entries (must be used in conjunction with --file)."}, +{ LLDB_OPT_SET_4, true, "function", 'n', required_argument, NULL, 0, "<name>", "Lookup a function by name in the debug symbols in one or more executable images."}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp index 6b54badd7fc..58c1b81933a 100644 --- a/lldb/source/Commands/CommandObjectLog.cpp +++ b/lldb/source/Commands/CommandObjectLog.cpp @@ -226,14 +226,14 @@ protected: lldb::OptionDefinition CommandObjectLogEnable::CommandOptions::g_option_table[] = { -{ 0, false, "file", 'f', required_argument, NULL, 0, "<filename>", "Set the destination file to log to."}, -{ 0, false, "threadsafe", 't', no_argument, NULL, 0, NULL, "Enable thread safe logging to avoid interweaved log lines." }, -{ 0, false, "verbose", 'v', no_argument, NULL, 0, NULL, "Enable verbose logging." }, -{ 0, false, "debug", 'g', no_argument, NULL, 0, NULL, "Enable debug logging." }, -{ 0, false, "sequence", 's', no_argument, NULL, 0, NULL, "Prepend all log lines with an increasing integer sequence id." }, -{ 0, false, "timestamp", 'T', no_argument, NULL, 0, NULL, "Prepend all log lines with a timestamp." }, -{ 0, false, "pid-tid", 'p', no_argument, NULL, 0, NULL, "Prepend all log lines with the process and thread ID that generates the log line." }, -{ 0, false, "thread-name",'n', no_argument, NULL, 0, NULL, "Prepend all log lines with the thread name for the thread that generates the log line." }, +{ LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, 0, "<filename>", "Set the destination file to log to."}, +{ LLDB_OPT_SET_1, false, "threadsafe", 't', no_argument, NULL, 0, NULL, "Enable thread safe logging to avoid interweaved log lines." }, +{ LLDB_OPT_SET_1, false, "verbose", 'v', no_argument, NULL, 0, NULL, "Enable verbose logging." }, +{ LLDB_OPT_SET_1, false, "debug", 'g', no_argument, NULL, 0, NULL, "Enable debug logging." }, +{ LLDB_OPT_SET_1, false, "sequence", 's', no_argument, NULL, 0, NULL, "Prepend all log lines with an increasing integer sequence id." }, +{ LLDB_OPT_SET_1, false, "timestamp", 'T', no_argument, NULL, 0, NULL, "Prepend all log lines with a timestamp." }, +{ LLDB_OPT_SET_1, false, "pid-tid", 'p', no_argument, NULL, 0, NULL, "Prepend all log lines with the process and thread ID that generates the log line." }, +{ LLDB_OPT_SET_1, false, "thread-name",'n', no_argument, NULL, 0, NULL, "Prepend all log lines with the thread name for the thread that generates the log line." }, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 91abd81e9fd..aefe5fe9965 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -317,10 +317,10 @@ protected: lldb::OptionDefinition CommandObjectMemoryRead::CommandOptions::g_option_table[] = { - { 0, false, "format", 'f', required_argument, NULL, 0, "<format>", "The format that will be used to display the memory. Defaults to bytes with ASCII (--format=Y)."}, - { 0, false, "size", 's', required_argument, NULL, 0, "<byte-size>","The size in bytes to use when displaying with the selected format."}, - { 0, false, "num-per-line", 'l', required_argument, NULL, 0, "<N>", "The number of items per line to display."}, - { 0, false, "count", 'c', required_argument, NULL, 0, "<N>", "The number of total items to display."}, + { LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, "<format>", "The format that will be used to display the memory. Defaults to bytes with ASCII (--format=Y)."}, + { LLDB_OPT_SET_1, false, "size", 's', required_argument, NULL, 0, "<byte-size>","The size in bytes to use when displaying with the selected format."}, + { LLDB_OPT_SET_1, false, "num-per-line", 'l', required_argument, NULL, 0, "<N>", "The number of items per line to display."}, + { LLDB_OPT_SET_1, false, "count", 'c', required_argument, NULL, 0, "<N>", "The number of total items to display."}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; @@ -656,8 +656,8 @@ protected: lldb::OptionDefinition CommandObjectMemoryWrite::CommandOptions::g_option_table[] = { - { 0, false, "format", 'f', required_argument, NULL, 0, "<format>", "The format value types that will be decoded and written to memory."}, - { 0, false, "size", 's', required_argument, NULL, 0, "<byte-size>","The size in bytes of the values to write to memory."}, + { LLDB_OPT_SET_1, false, "format", 'f', required_argument, NULL, 0, "<format>", "The format value types that will be decoded and written to memory."}, + { LLDB_OPT_SET_1, false, "size", 's', required_argument, NULL, 0, "<byte-size>","The size in bytes of the values to write to memory."}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index ea0f6aff5eb..537fe7c9326 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -264,11 +264,11 @@ protected: lldb::OptionDefinition CommandObjectProcessLaunch::CommandOptions::g_option_table[] = { -{ 0, false, "stop-at-entry", 's', no_argument, NULL, 0, NULL, "Stop at the entry point of the program when launching a process."}, -{ 0, false, "stdin", 'i', required_argument, NULL, 0, "<path>", "Redirect stdin for the process to <path>."}, -{ 0, false, "stdout", 'o', required_argument, NULL, 0, "<path>", "Redirect stdout for the process to <path>."}, -{ 0, false, "stderr", 'e', required_argument, NULL, 0, "<path>", "Redirect stderr for the process to <path>."}, -{ 0, false, "plugin", 'p', required_argument, NULL, 0, "<plugin>", "Name of the process plugin you want to use."}, +{ LLDB_OPT_SET_1, false, "stop-at-entry", 's', no_argument, NULL, 0, NULL, "Stop at the entry point of the program when launching a process."}, +{ LLDB_OPT_SET_1, false, "stdin", 'i', required_argument, NULL, 0, "<path>", "Redirect stdin for the process to <path>."}, +{ LLDB_OPT_SET_1, false, "stdout", 'o', required_argument, NULL, 0, "<path>", "Redirect stdout for the process to <path>."}, +{ LLDB_OPT_SET_1, false, "stderr", 'e', required_argument, NULL, 0, "<path>", "Redirect stderr for the process to <path>."}, +{ LLDB_OPT_SET_1, false, "plugin", 'p', required_argument, NULL, 0, "<plugin>", "Name of the process plugin you want to use."}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; @@ -478,10 +478,10 @@ protected: lldb::OptionDefinition CommandObjectProcessAttach::CommandOptions::g_option_table[] = { -{ 0, false, "pid", 'p', required_argument, NULL, 0, "<pid>", "The process ID of an existing process to attach to."}, -{ 0, false, "plugin", 'P', required_argument, NULL, 0, "<plugin>", "Name of the process plugin you want to use."}, -{ 1, true, "name", 'n', required_argument, NULL, 0, "<process-name>", "The name of the process to attach to."}, -{ 1, false, "waitfor", 'w', no_argument, NULL, 0, NULL, "Wait for the the process with <process-name> to launch."}, +{ LLDB_OPT_SET_ALL, false, "plugin", 'P', required_argument, NULL, 0, "<plugin>", "Name of the process plugin you want to use."}, +{ LLDB_OPT_SET_1, false, "pid", 'p', required_argument, NULL, 0, "<pid>", "The process ID of an existing process to attach to."}, +{ LLDB_OPT_SET_2, true, "name", 'n', required_argument, NULL, 0, "<process-name>", "The name of the process to attach to."}, +{ LLDB_OPT_SET_2, false, "waitfor", 'w', no_argument, NULL, 0, NULL, "Wait for the the process with <process-name> to launch."}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; diff --git a/lldb/source/Commands/CommandObjectSourceFile.cpp b/lldb/source/Commands/CommandObjectSourceFile.cpp index df70bc9aea3..fbffe10081e 100644 --- a/lldb/source/Commands/CommandObjectSourceFile.cpp +++ b/lldb/source/Commands/CommandObjectSourceFile.cpp @@ -85,9 +85,9 @@ CommandObjectSourceFile::CommandOptions::GetDefinitions () lldb::OptionDefinition CommandObjectSourceFile::CommandOptions::g_option_table[] = { -{ 0, false, "line", 'l', required_argument, NULL, 0, "<line>", "The line number at which to start the display source."}, -{ 0, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, "<file>", "The file from which to display source."}, -{ 0, false, "count", 'n', required_argument, NULL, 0, "<count>", "The number of source lines to display."}, +{ LLDB_OPT_SET_1, false, "line", 'l', required_argument, NULL, 0, "<line>", "The line number at which to start the display source."}, +{ LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, "<file>", "The file from which to display source."}, +{ LLDB_OPT_SET_1, false, "count", 'n', required_argument, NULL, 0, "<count>", "The number of source lines to display."}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp index 0cc326f5f45..76d13e8cb54 100644 --- a/lldb/source/Commands/CommandObjectThread.cpp +++ b/lldb/source/Commands/CommandObjectThread.cpp @@ -619,8 +619,8 @@ g_duo_running_mode[] = lldb::OptionDefinition CommandObjectThreadStepWithTypeAndScope::CommandOptions::g_option_table[] = { -{ 0, true, "avoid_no_debug", 'a', required_argument, NULL, 0, "<avoid_no_debug>", "Should step-in step over functions with no debug information"}, -{ 0, true, "run_mode", 'm', required_argument, g_tri_running_mode, 0, "<run_mode>", "Determine how to run other threads while stepping this one"}, +{ LLDB_OPT_SET_1, true, "avoid_no_debug", 'a', required_argument, NULL, 0, "<avoid_no_debug>", "Should step-in step over functions with no debug information"}, +{ LLDB_OPT_SET_1, true, "run_mode", 'm', required_argument, g_tri_running_mode, 0, "<run_mode>", "Determine how to run other threads while stepping this one"}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; @@ -1056,9 +1056,9 @@ protected: lldb::OptionDefinition CommandObjectThreadUntil::CommandOptions::g_option_table[] = { -{ 0, true, "frame", 'f', required_argument, NULL, 0, "<frame>", "Frame index for until operation - defaults to 0"}, -{ 0, true, "thread", 't', required_argument, NULL, 0, "<thread>", "Thread index for the thread for until operation"}, -{ 0, true, "run_mode", 'm', required_argument, g_duo_running_mode, 0, "<run_mode>", "Determine how to run other threads while stepping this one"}, +{ LLDB_OPT_SET_1, true, "frame", 'f', required_argument, NULL, 0, "<frame>", "Frame index for until operation - defaults to 0"}, +{ LLDB_OPT_SET_1, true, "thread", 't', required_argument, NULL, 0, "<thread>", "Thread index for the thread for until operation"}, +{ LLDB_OPT_SET_1, true, "run_mode", 'm', required_argument, g_duo_running_mode, 0, "<run_mode>", "Determine how to run other threads while stepping this one"}, { 0, false, NULL, 0, 0, NULL, 0, NULL, NULL } }; diff --git a/lldb/source/Commands/CommandObjectVariable.cpp b/lldb/source/Commands/CommandObjectVariable.cpp index 6bde4829be0..c802374ed94 100644 --- a/lldb/source/Commands/CommandObjectVariable.cpp +++ b/lldb/source/Commands/CommandObjectVariable.cpp @@ -761,20 +761,20 @@ protected: lldb::OptionDefinition CommandObjectVariableList::CommandOptions::g_option_table[] = { -{ 0, false, "debug", 'D', no_argument, NULL, 0, NULL, "Show verbose debug information."}, -{ 0, false, "depth", 'd', required_argument, NULL, 0, "<count>", "Set the max recurse depth when dumping aggregate types (default is infinity)."}, -{ 0, false, "globals", 'g', no_argument, NULL, 0, NULL, "List global and static variables for the current stack frame source file."}, -{ 0, false, "global", 'G', required_argument, NULL, 0, NULL, "Find a global variable by name (which might not be in the current stack frame source file)."}, -{ 0, false, "location", 'L', no_argument, NULL, 0, NULL, "Show variable location information."}, -{ 0, false, "name", 'n', required_argument, NULL, 0, "<name>", "Lookup a variable by name or regex (--regex) for the current execution context."}, -{ 0, false, "no-args", 'a', no_argument, NULL, 0, NULL, "Omit function arguments."}, -{ 0, false, "no-locals", 'l', no_argument, NULL, 0, NULL, "Omit local variables."}, -{ 0, false, "no-types", 't', no_argument, NULL, 0, NULL, "Omit variable type names."}, -{ 0, false, "no-summary", 'y', no_argument, NULL, 0, NULL, "Omit summary information."}, -{ 0, false, "scope", 's', no_argument, NULL, 0, NULL, "Show variable scope (argument, local, global, static)."}, -{ 0, false, "objc", 'o', no_argument, NULL, 0, NULL, "When looking up a variable by name (--name), print as an Objective-C object."}, -{ 0, false, "ptr-depth", 'p', required_argument, NULL, 0, "<count>", "The number of pointers to be traversed when dumping values (default is zero)."}, -{ 0, false, "regex", 'r', no_argument, NULL, 0, NULL, "The <name> argument for name lookups are regular expressions."}, +{ LLDB_OPT_SET_1, false, "debug", 'D', no_argument, NULL, 0, NULL, "Show verbose debug information."}, +{ LLDB_OPT_SET_1, false, "depth", 'd', required_argument, NULL, 0, "<count>", "Set the max recurse depth when dumping aggregate types (default is infinity)."}, +{ LLDB_OPT_SET_1, false, "globals", 'g', no_argument, NULL, 0, NULL, "List global and static variables for the current stack frame source file."}, +{ LLDB_OPT_SET_1, false, "global", 'G', required_argument, NULL, 0, NULL, "Find a global variable by name (which might not be in the current stack frame source file)."}, +{ LLDB_OPT_SET_1, false, "location", 'L', no_argument, NULL, 0, NULL, "Show variable location information."}, +{ LLDB_OPT_SET_1, false, "name", 'n', required_argument, NULL, 0, "<name>", "Lookup a variable by name or regex (--regex) for the current execution context."}, +{ LLDB_OPT_SET_1, false, "no-args", 'a', no_argument, NULL, 0, NULL, "Omit function arguments."}, +{ LLDB_OPT_SET_1, false, "no-locals", 'l', no_argument, NULL, 0, NULL, "Omit local variables."}, +{ LLDB_OPT_SET_1, false, "no-types", 't', no_argument, NULL, 0, NULL, "Omit variable type names."}, +{ LLDB_OPT_SET_1, false, "no-summary", 'y', no_argument, NULL, 0, NULL, "Omit summary information."}, +{ LLDB_OPT_SET_1, false, "scope", 's', no_argument, NULL, 0, NULL, "Show variable scope (argument, local, global, static)."}, +{ LLDB_OPT_SET_1, false, "objc", 'o', no_argument, NULL, 0, NULL, "When looking up a variable by name (--name), print as an Objective-C object."}, +{ LLDB_OPT_SET_1, false, "ptr-depth", 'p', required_argument, NULL, 0, "<count>", "The number of pointers to be traversed when dumping values (default is zero)."}, +{ LLDB_OPT_SET_1, false, "regex", 'r', no_argument, NULL, 0, NULL, "The <name> argument for name lookups are regular expressions."}, { 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL } }; diff --git a/lldb/source/Core/Options.cpp b/lldb/source/Core/Options.cpp index 35a9fa40e1b..f43dc7c823e 100644 --- a/lldb/source/Core/Options.cpp +++ b/lldb/source/Core/Options.cpp @@ -31,6 +31,7 @@ using namespace lldb_private; Options::Options () : m_getopt_table () { + BuildValidOptionSets(); } Options::~Options () @@ -160,6 +161,9 @@ Options::VerifyOptions (CommandReturnObject &result) return options_are_valid; } +// This is called in the Options constructor, though we could call it lazily if that ends up being +// a performance problem. + void Options::BuildValidOptionSets () { @@ -173,32 +177,52 @@ Options::BuildValidOptionSets () return; const lldb::OptionDefinition *full_options_table = GetDefinitions(); - uint32_t usage_level = 0; m_required_options.resize(1); m_optional_options.resize(1); - - for (int i = 0; i < num_options; ++i) + + // First count the number of option sets we've got. Ignore LLDB_ALL_OPTION_SETS... + + uint32_t num_option_sets = 0; + + for (int i = 0; i < num_options; i++) { - // NOTE: Assumption: The full options table is ordered with usage level growing monotonically. - assert (full_options_table[i].usage_level >= usage_level); - - if (full_options_table[i].usage_level > usage_level) + uint32_t this_usage_mask = full_options_table[i].usage_mask; + if (this_usage_mask == LLDB_OPT_SET_ALL) { - // start a new level - usage_level = full_options_table[i].usage_level; - m_required_options.resize(m_required_options.size()+1); - m_optional_options.resize(m_optional_options.size()+1); + if (num_option_sets == 0) + num_option_sets = 1; } else { - assert (m_required_options.empty() == false); - assert (m_optional_options.empty() == false); + for (int j = 0; j < LLDB_MAX_NUM_OPTION_SETS; j++) + { + if (this_usage_mask & 1 << j) + { + if (num_option_sets <= j) + num_option_sets = j + 1; + } + } } + } - if (full_options_table[i].required) - m_required_options.back().insert(full_options_table[i].short_option); - else - m_optional_options.back().insert(full_options_table[i].short_option); + if (num_option_sets > 0) + { + m_required_options.resize(num_option_sets); + m_optional_options.resize(num_option_sets); + + for (int i = 0; i < num_options; ++i) + { + for (int j = 0; j < num_option_sets; j++) + { + if (full_options_table[i].usage_mask & 1 << j) + { + if (full_options_table[i].required) + m_required_options[j].insert(full_options_table[i].short_option); + else + m_optional_options[j].insert(full_options_table[i].short_option); + } + } + } } } @@ -206,6 +230,9 @@ uint32_t Options::NumCommandOptions () { const lldb::OptionDefinition *full_options_table = GetDefinitions (); + if (full_options_table == NULL) + return 0; + int i = 0; if (full_options_table != NULL) @@ -352,54 +379,61 @@ Options::GenerateOptionUsage // <cmd> [options-for-level-1] // etc. - uint32_t usage_level = 0; const uint32_t num_options = NumCommandOptions(); + if (num_options == 0) + return; + + BuildValidOptionSets (); + int num_option_sets = m_required_options.size(); + uint32_t i; - for (i = 0; i < num_options; ++i) + + for (uint32_t opt_set = 0; opt_set < num_option_sets; ++opt_set) { - if (i==0 || full_options_table[i].usage_level > usage_level) + uint32_t opt_set_mask; + + opt_set_mask = 1 << opt_set; + if (opt_set > 0) + strm.Printf ("\n"); + strm.Indent (name); + + for (i = 0; i < num_options; ++i) { - // start a new level - usage_level = full_options_table[i].usage_level; - if (usage_level > 0) + if (full_options_table[i].usage_mask & opt_set_mask) { - strm.Printf ("\n"); - } - strm.Indent (name); - } - - // Add current option to the end of out_stream. + // Add current option to the end of out_stream. - if (full_options_table[i].required) - { - if (full_options_table[i].option_has_arg == required_argument) - { - strm.Printf (" -%c %s", - full_options_table[i].short_option, - full_options_table[i].argument_name); - } - else if (full_options_table[i].option_has_arg == optional_argument) - { - strm.Printf (" -%c [%s]", - full_options_table[i].short_option, - full_options_table[i].argument_name); + if (full_options_table[i].required) + { + if (full_options_table[i].option_has_arg == required_argument) + { + strm.Printf (" -%c %s", + full_options_table[i].short_option, + full_options_table[i].argument_name); + } + else if (full_options_table[i].option_has_arg == optional_argument) + { + strm.Printf (" -%c [%s]", + full_options_table[i].short_option, + full_options_table[i].argument_name); + } + else + strm.Printf (" -%c", full_options_table[i].short_option); + } + else + { + if (full_options_table[i].option_has_arg == required_argument) + strm.Printf (" [-%c %s]", full_options_table[i].short_option, + full_options_table[i].argument_name); + else if (full_options_table[i].option_has_arg == optional_argument) + strm.Printf (" [-%c [%s]]", full_options_table[i].short_option, + full_options_table[i].argument_name); + else + strm.Printf (" [-%c]", full_options_table[i].short_option); + } } - else - strm.Printf (" -%c", full_options_table[i].short_option); - } - else - { - if (full_options_table[i].option_has_arg == required_argument) - strm.Printf (" [-%c %s]", full_options_table[i].short_option, - full_options_table[i].argument_name); - else if (full_options_table[i].option_has_arg == optional_argument) - strm.Printf (" [-%c [%s]]", full_options_table[i].short_option, - full_options_table[i].argument_name); - else - strm.Printf (" [-%c]", full_options_table[i].short_option); } } - strm.Printf ("\n\n"); // Now print out all the detailed information about the various options: long form, short form and help text: diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp index 6b0beb745ba..112678b9dc0 100644 --- a/lldb/tools/driver/Driver.cpp +++ b/lldb/tools/driver/Driver.cpp @@ -49,28 +49,28 @@ reset_stdin_termios () static lldb::OptionDefinition g_options[] = { - { 0, true, "help", 'h', no_argument, NULL, NULL, NULL, + { LLDB_OPT_SET_1, true, "help", 'h', no_argument, NULL, NULL, NULL, "Prints out the usage information for the LLDB debugger." }, - { 1, true, "version", 'v', no_argument, NULL, NULL, NULL, + { LLDB_OPT_SET_2, true, "version", 'v', no_argument, NULL, NULL, NULL, "Prints out the current version number of the LLDB debugger." }, - { 2, false, "file", 'f', required_argument, NULL, NULL, "<filename>", - "Tells the debugger to use the file <filename> as the program to be debugged." }, - - { 2, false, "arch", 'a', required_argument, NULL, NULL, "<architecture>", + { LLDB_OPT_SET_3, false, "arch", 'a', required_argument, NULL, NULL, "<architecture>", "Tells the debugger to use the specified architecture when starting and running the program. <architecture> must be one of the architectures for which the program was compiled." }, - { 2, false, "script-language",'l', required_argument, NULL, NULL, "<scripting-language>", + { LLDB_OPT_SET_3 | LLDB_OPT_SET_4, false, "script-language",'l', required_argument, NULL, NULL, "<scripting-language>", "Tells the debugger to use the specified scripting language for user-defined scripts, rather than the default. Valid scripting languages that can be specified include Python, Perl, Ruby and Tcl. Currently only the Python extensions have been implemented." }, - { 2, false, "debug", 'd', no_argument, NULL, NULL, NULL, + { LLDB_OPT_SET_3 | LLDB_OPT_SET_4, false, "debug", 'd', no_argument, NULL, NULL, NULL, "Tells the debugger to print out extra information for debugging itself." }, - { 2, false, "source", 's', required_argument, NULL, NULL, "<file>", + { LLDB_OPT_SET_3 | LLDB_OPT_SET_4, false, "source", 's', required_argument, NULL, NULL, "<file>", "Tells the debugger to read in and execute the file <file>, which should contain lldb commands." }, - { 3, false, "crash-log", 'c', required_argument, NULL, NULL, "<file>", + { LLDB_OPT_SET_3, false, "file", 'f', required_argument, NULL, NULL, "<filename>", + "Tells the debugger to use the file <filename> as the program to be debugged." }, + + { LLDB_OPT_SET_4, false, "crash-log", 'c', required_argument, NULL, NULL, "<file>", "Load executable images from a crash log for symbolication." }, { 0, false, NULL, 0, 0, NULL, NULL, NULL, NULL } @@ -172,7 +172,7 @@ ShowUsage (FILE *out, lldb::OptionDefinition *option_table, Driver::OptionData d const char *name = "lldb"; char spaces[screen_width+1]; uint32_t i; - + for (i = 0; i < screen_width; ++i) spaces[i] = ' '; spaces[i] = '\n'; @@ -188,39 +188,63 @@ ShowUsage (FILE *out, lldb::OptionDefinition *option_table, Driver::OptionData d // <cmd> [options-for-level-1] // etc. - uint32_t usage_level = 0; uint32_t num_options; - - for (num_options = 0; option_table[num_options].long_option != NULL; ++num_options); - - for (i = 0; i < num_options; ++i) + uint32_t num_option_sets = 0; + + for (num_options = 0; option_table[num_options].long_option != NULL; ++num_options) { - if (i == 0 || option_table[i].usage_level > usage_level) + uint32_t this_usage_mask = option_table[num_options].usage_mask; + if (this_usage_mask == LLDB_OPT_SET_ALL) { - // Start a new level. - usage_level = option_table[i].usage_level; - if (usage_level > 0) - fprintf (out, "\n\n"); - fprintf (out, "%s%s", spaces_string.substr(0, indent_level).c_str(), name); + if (num_option_sets == 0) + num_option_sets = 1; } - - if (option_table[i].required) + else { - if (option_table[i].option_has_arg == required_argument) - fprintf (out, " -%c %s", option_table[i].short_option, option_table[i].argument_name); - else if (option_table[i].option_has_arg == optional_argument) - fprintf (out, " -%c [%s]", option_table[i].short_option, option_table[i].argument_name); - else - fprintf (out, " -%c", option_table[i].short_option); + for (int j = 0; j < LLDB_MAX_NUM_OPTION_SETS; j++) + { + if (this_usage_mask & 1 << j) + { + if (num_option_sets <= j) + num_option_sets = j + 1; + } + } } - else + } + + for (uint32_t opt_set = 0; opt_set < num_option_sets; opt_set++) + { + uint32_t opt_set_mask; + + opt_set_mask = 1 << opt_set; + + if (opt_set > 0) + fprintf (out, "\n"); + fprintf (out, "%s%s", spaces_string.substr(0, indent_level).c_str(), name); + + for (uint32_t i = 0; i < num_options; ++i) { - if (option_table[i].option_has_arg == required_argument) - fprintf (out, " [-%c %s]", option_table[i].short_option, option_table[i].argument_name); - else if (option_table[i].option_has_arg == optional_argument) - fprintf (out, " [-%c [%s]]", option_table[i].short_option, option_table[i].argument_name); - else - fprintf (out, " [-%c]", option_table[i].short_option); + if (option_table[i].usage_mask & opt_set_mask) + { + if (option_table[i].required) + { + if (option_table[i].option_has_arg == required_argument) + fprintf (out, " -%c %s", option_table[i].short_option, option_table[i].argument_name); + else if (option_table[i].option_has_arg == optional_argument) + fprintf (out, " -%c [%s]", option_table[i].short_option, option_table[i].argument_name); + else + fprintf (out, " -%c", option_table[i].short_option); + } + else + { + if (option_table[i].option_has_arg == required_argument) + fprintf (out, " [-%c %s]", option_table[i].short_option, option_table[i].argument_name); + else if (option_table[i].option_has_arg == optional_argument) + fprintf (out, " [-%c [%s]]", option_table[i].short_option, option_table[i].argument_name); + else + fprintf (out, " [-%c]", option_table[i].short_option); + } + } } } @@ -239,7 +263,7 @@ ShowUsage (FILE *out, lldb::OptionDefinition *option_table, Driver::OptionData d indent_level += 5; - for (i = 0; i < num_options; ++i) + for (uint32_t i = 0; i < num_options; ++i) { // Only print this option if we haven't already seen it. pos = options_seen.find (option_table[i].short_option); @@ -555,27 +579,40 @@ Driver::ParseArgs (int argc, const char *argv[], FILE *out_fh, FILE *err_fh) ResetOptionValues (); - if (argc == 2 && *(argv[1]) != '-') + SBCommandReturnObject result; + + SBError error = ParseOptions (m_option_data, argc, argv); + if (error.Fail()) { - m_option_data.m_filename = argv[1]; + const char *error_cstr = error.GetCString (); + if (error_cstr) + ::fprintf (err_fh, "error: %s\n", error_cstr); + valid = false; } - else + + // If there is a trailing argument, it is the filename. + if (optind == argc - 1) { - SBCommandReturnObject result; - - SBError error = ParseOptions (m_option_data, argc, argv); - if (error.Fail()) + if (m_option_data.m_filename.empty()) { - const char *error_cstr = error.GetCString (); - if (error_cstr) - ::fprintf (err_fh, "error: %s\n", error_cstr); + m_option_data.m_filename = argv[optind]; + } + else + { + ::fprintf (err_fh, "error: don't provide a file both on in the -f option and as an argument."); + valid = false; } - } - - // Check to see if they just invoked the debugger with a filename. - - if (m_option_data.m_print_help) + } + else if (optind < argc - 1) + { + // Trailing extra arguments... + ::fprintf (err_fh, "error: trailing extra arguments - only one the filename is allowed."); + valid = false; + + } + + if (!valid || m_option_data.m_print_help) { ShowUsage (out_fh, g_options, m_option_data); valid = false; |