[Lldb-commits] [lldb] r121295 - in /lldb/trunk/tools/driver: Driver.cpp Driver.h
Greg Clayton
gclayton at apple.com
Wed Dec 8 14:23:24 PST 2010
Author: gclayton
Date: Wed Dec 8 16:23:24 2010
New Revision: 121295
URL: http://llvm.org/viewvc/llvm-project?rev=121295&view=rev
Log:
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
Modified:
lldb/trunk/tools/driver/Driver.cpp
lldb/trunk/tools/driver/Driver.h
Modified: lldb/trunk/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=121295&r1=121294&r2=121295&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Wed Dec 8 16:23:24 2010
@@ -371,7 +371,7 @@
}
Driver::OptionData::OptionData () :
- m_filename(),
+ m_args(),
m_script_lang (lldb::eScriptLanguageDefault),
m_crash_log (),
m_source_command_files (),
@@ -390,7 +390,7 @@
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 @@
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 @@
{
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 @@
}
}
- // 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 @@
}
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 @@
}
}
- 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
Modified: lldb/trunk/tools/driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.h?rev=121295&r1=121294&r2=121295&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.h (original)
+++ lldb/trunk/tools/driver/Driver.h Wed Dec 8 16:23:24 2010
@@ -96,7 +96,7 @@
//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;
More information about the lldb-commits
mailing list