From 8d846daa81396c888d754156b189dfea9574d81c Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Wed, 8 Dec 2010 22:23:24 +0000 Subject: [PATCH] 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 --- lldb/tools/driver/Driver.cpp | 80 ++++++++++++++++++++++-------------- 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 0db567377032..d331ece88f1e 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 0) + { + for (int arg_idx=0; arg_idx 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 756b6b0499d5..37d5eed7ce37 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 m_args; lldb::ScriptLanguage m_script_lang; std::string m_crash_log; std::vector m_source_command_files;