diff options
author | Greg Clayton <gclayton@apple.com> | 2010-12-08 22:23:24 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2010-12-08 22:23:24 +0000 |
commit | 8d846daa81396c888d754156b189dfea9574d81c (patch) | |
tree | 02b6bf583803ed402063e9ae1a1e8277d2b5a489 | |
parent | e0df786c98a97f40b0bef54cf80fee5ff395a991 (diff) | |
download | bcm5719-llvm-8d846daa81396c888d754156b189dfea9574d81c.tar.gz bcm5719-llvm-8d846daa81396c888d754156b189dfea9574d81c.zip |
Any arguments that are not options to the "lldb" command line driver, now get
used as the arguments for the inferior program. So for example you can do
% lldb /bin/ls /tmp ~/Documents
And "lldb" will use "/bin/ls" as the program and send arguments "/tmp" and
"~/Documents" as the launch args.
If you specify a file, then all remaining args after option parsing
will be used for program arguments:
% lldb -f /bin/ls /tmp ~/Documents
If you need to pass option values to your inferior program, just terminate
the "lldb" command line driver options with "--":
% lldb -- /bin/ls -AFl /tmp
The arguments are placed into the "settings" variable named
"target.process.run-args". This allows you to just run the program using
"process launch" and, if no args are specified on that command, the
"target.process.run-args" values will be used:
% lldb -- /bin/ls -AFl /tmp
Current executable set to '/bin/ls' (x86_64).
(lldb) settings show target.process.run-args
target.process.run-args (array):
[0]: '-AFl'
[1]: '/tmp'
(lldb)
(lldb) r
Process 56753 launched: '/bin/ls' (x86_64)
lrwxr-xr-x@ 1 root wheel 11 Nov 19 2009 /tmp@ -> private/tmp
llvm-svn: 121295
-rw-r--r-- | lldb/tools/driver/Driver.cpp | 80 | ||||
-rw-r--r-- | lldb/tools/driver/Driver.h | 2 |
2 files changed, 51 insertions, 31 deletions
diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp index 0db56737703..d331ece88f1 100644 --- a/lldb/tools/driver/Driver.cpp +++ b/lldb/tools/driver/Driver.cpp @@ -371,7 +371,7 @@ BuildGetOptTable (lldb::OptionDefinition *expanded_option_table, std::vector<str } Driver::OptionData::OptionData () : - m_filename(), + m_args(), m_script_lang (lldb::eScriptLanguageDefault), m_crash_log (), m_source_command_files (), @@ -390,7 +390,7 @@ Driver::OptionData::~OptionData () void Driver::OptionData::Clear () { - m_filename.clear (); + m_args.clear (); m_script_lang = lldb::eScriptLanguageDefault; m_source_command_files.clear (); m_debug_mode = false; @@ -408,9 +408,9 @@ Driver::ResetOptionValues () const char * Driver::GetFilename() const { - if (m_option_data.m_filename.empty()) + if (m_option_data.m_args.empty()) return NULL; - return m_option_data.m_filename.c_str(); + return m_option_data.m_args.front().c_str(); } const char * @@ -581,13 +581,15 @@ Driver::ParseArgs (int argc, const char *argv[], FILE *out_fh, bool &exit) { SBFileSpec file(optarg); if (file.Exists()) - m_option_data.m_filename = optarg; + { + m_option_data.m_args.push_back (optarg); + } else if (file.ResolveExecutableLocation()) { char path[PATH_MAX]; int path_len; file.GetPath (path, path_len); - m_option_data.m_filename = path; + m_option_data.m_args.push_back (path); } else error.SetErrorStringWithFormat("file specified in --file (-f) option doesn't exist: '%s'", optarg); @@ -642,25 +644,6 @@ Driver::ParseArgs (int argc, const char *argv[], FILE *out_fh, bool &exit) } } - // If there is a trailing argument, it is the filename. - if (optind == argc - 1) - { - if (m_option_data.m_filename.empty()) - { - m_option_data.m_filename = argv[optind]; - } - else - { - error.SetErrorStringWithFormat ("error: don't provide a file both on in the -f option and as an argument."); - } - - } - else if (optind < argc - 1) - { - // Trailing extra arguments... - error.SetErrorStringWithFormat ("error: trailing extra arguments - only one the filename is allowed."); - } - if (error.Fail() || m_option_data.m_print_help) { ShowUsage (out_fh, g_options, m_option_data); @@ -677,7 +660,26 @@ Driver::ParseArgs (int argc, const char *argv[], FILE *out_fh, bool &exit) } else { - // All other combinations are valid; do nothing more here. + // Any arguments that are left over after option parsing are for + // the program. If a file was specified with -f then the filename + // is already in the m_option_data.m_args array, and any remaining args + // are arguments for the inferior program. If no file was specified with + // -f, then what is left is the program name followed by any arguments. + + // Skip any options we consumed with getopt_long + argc -= optind; + argv += optind; + + if (argc > 0) + { + for (int arg_idx=0; arg_idx<argc; ++arg_idx) + { + const char *arg = argv[arg_idx]; + if (arg) + m_option_data.m_args.push_back (arg); + } + } + } return error; @@ -1273,16 +1275,34 @@ Driver::MainLoop () } } - if (!m_option_data.m_filename.empty()) + const size_t num_args = m_option_data.m_args.size(); + if (num_args > 0) { char arch_name[64]; if (m_debugger.GetDefaultArchitecture (arch_name, sizeof (arch_name))) - ::snprintf (command_string, sizeof (command_string), "file --arch=%s '%s'", arch_name, - m_option_data.m_filename.c_str()); + ::snprintf (command_string, + sizeof (command_string), + "file --arch=%s '%s'", + arch_name, + m_option_data.m_args[0].c_str()); else - ::snprintf (command_string, sizeof(command_string), "file '%s'", m_option_data.m_filename.c_str()); + ::snprintf (command_string, + sizeof(command_string), + "file '%s'", + m_option_data.m_args[0].c_str()); m_debugger.HandleCommand (command_string); + + if (num_args > 1) + { + m_debugger.HandleCommand ("settings clear target.process.run-args"); + char arg_cstr[1024]; + for (size_t arg_idx = 1; arg_idx < num_args; ++arg_idx) + { + ::snprintf (arg_cstr, sizeof(arg_cstr), "settings append target.process.run-args \"%s\"", m_option_data.m_args[arg_idx].c_str()); + m_debugger.HandleCommand (arg_cstr); + } + } } // Now that all option parsing is done, we try and parse the .lldbinit diff --git a/lldb/tools/driver/Driver.h b/lldb/tools/driver/Driver.h index 756b6b0499d..37d5eed7ce3 100644 --- a/lldb/tools/driver/Driver.h +++ b/lldb/tools/driver/Driver.h @@ -96,7 +96,7 @@ public: //static lldb::OptionDefinition m_cmd_option_table[]; - std::string m_filename; + std::vector<std::string> m_args; lldb::ScriptLanguage m_script_lang; std::string m_crash_log; std::vector<std::string> m_source_command_files; |