2010-07-07 11:36:20 +08:00
|
|
|
//===-- CommandObjectSource.cpp ---------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CommandObjectCommands.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Interpreter/Args.h"
|
|
|
|
#include "lldb/Core/Debugger.h"
|
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
|
|
|
#include "lldb/Interpreter/Options.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// CommandObjectCommandsSource
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class CommandObjectCommandsSource : public CommandObject
|
|
|
|
{
|
2011-02-18 08:54:25 +08:00
|
|
|
private:
|
|
|
|
|
|
|
|
class CommandOptions : public Options
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
CommandOptions (){}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~CommandOptions (){}
|
|
|
|
|
|
|
|
virtual Error
|
|
|
|
SetOptionValue (int option_idx, const char *option_arg)
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
char short_option = (char) m_getopt_table[option_idx].val;
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
switch (short_option)
|
|
|
|
{
|
|
|
|
case 'e':
|
|
|
|
m_stop_on_error = Args::StringToBoolean(option_arg, true, &success);
|
|
|
|
if (!success)
|
|
|
|
error.SetErrorStringWithFormat("Invalid value for stop-on-error: %s.\n", option_arg);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
m_stop_on_continue = Args::StringToBoolean(option_arg, true, &success);
|
|
|
|
if (!success)
|
|
|
|
error.SetErrorStringWithFormat("Invalid value for stop-on-continue: %s.\n", option_arg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ResetOptionValues ()
|
|
|
|
{
|
|
|
|
m_stop_on_error = true;
|
|
|
|
m_stop_on_continue = true;
|
|
|
|
}
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
const OptionDefinition*
|
2011-02-18 08:54:25 +08:00
|
|
|
GetDefinitions ()
|
|
|
|
{
|
|
|
|
return g_option_table;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Options table: Required for subclasses of Options.
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
static OptionDefinition g_option_table[];
|
2011-02-18 08:54:25 +08:00
|
|
|
|
|
|
|
// Instance variables to hold the values for command options.
|
|
|
|
|
|
|
|
bool m_stop_on_error;
|
|
|
|
bool m_stop_on_continue;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Options table: Required for subclasses of Options.
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
static OptionDefinition g_option_table[];
|
2011-02-18 08:54:25 +08:00
|
|
|
|
|
|
|
CommandOptions m_options;
|
|
|
|
|
|
|
|
virtual Options *
|
|
|
|
GetOptions ()
|
|
|
|
{
|
|
|
|
return &m_options;
|
|
|
|
}
|
|
|
|
|
2010-07-07 11:36:20 +08:00
|
|
|
public:
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectCommandsSource(CommandInterpreter &interpreter) :
|
|
|
|
CommandObject (interpreter,
|
|
|
|
"commands source",
|
|
|
|
"Read in debugger commands from the file <filename> and execute them.",
|
2010-10-05 06:28:36 +08:00
|
|
|
NULL)
|
2010-07-07 11:36:20 +08:00
|
|
|
{
|
2010-10-05 06:28:36 +08:00
|
|
|
CommandArgumentEntry arg;
|
|
|
|
CommandArgumentData file_arg;
|
|
|
|
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
file_arg.arg_type = eArgTypeFilename;
|
|
|
|
file_arg.arg_repetition = eArgRepeatPlain;
|
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the argument entry.
|
|
|
|
arg.push_back (file_arg);
|
|
|
|
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back (arg);
|
2010-07-07 11:36:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~CommandObjectCommandsSource ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Execute
|
|
|
|
(
|
|
|
|
Args& args,
|
|
|
|
CommandReturnObject &result
|
|
|
|
)
|
|
|
|
{
|
|
|
|
const int argc = args.GetArgumentCount();
|
|
|
|
if (argc == 1)
|
|
|
|
{
|
|
|
|
const char *filename = args.GetArgumentAtIndex(0);
|
|
|
|
|
|
|
|
result.AppendMessageWithFormat ("Executing commands in '%s'.\n", filename);
|
|
|
|
|
2010-10-21 05:40:50 +08:00
|
|
|
FileSpec cmd_file (filename, true);
|
2011-02-18 08:54:25 +08:00
|
|
|
ExecutionContext *exe_ctx = NULL; // Just use the default context.
|
|
|
|
bool echo_commands = true;
|
|
|
|
bool print_results = true;
|
|
|
|
|
|
|
|
m_interpreter.HandleCommandsFromFile (cmd_file,
|
|
|
|
exe_ctx,
|
|
|
|
m_options.m_stop_on_continue,
|
|
|
|
m_options.m_stop_on_error,
|
|
|
|
echo_commands,
|
|
|
|
print_results,
|
|
|
|
result);
|
2010-07-07 11:36:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendErrorWithFormat("'%s' takes exactly one executable filename argument.\n", GetCommandName());
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
|
|
|
return result.Succeeded();
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
OptionDefinition
|
2011-02-18 08:54:25 +08:00
|
|
|
CommandObjectCommandsSource::CommandOptions::g_option_table[] =
|
|
|
|
{
|
|
|
|
{ LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', required_argument, NULL, 0, eArgTypeBoolean, "If true, stop executing commands on error."},
|
|
|
|
{ LLDB_OPT_SET_ALL, false, "stop-on-continue", 'c', required_argument, NULL, 0, eArgTypeBoolean, "If true, stop executing commands on continue."},
|
|
|
|
{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
|
|
|
|
};
|
|
|
|
|
2010-07-07 11:36:20 +08:00
|
|
|
#pragma mark CommandObjectCommandsAlias
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// CommandObjectCommandsAlias
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class CommandObjectCommandsAlias : public CommandObject
|
|
|
|
{
|
|
|
|
public:
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectCommandsAlias (CommandInterpreter &interpreter) :
|
|
|
|
CommandObject (interpreter,
|
|
|
|
"commands alias",
|
2010-09-09 05:06:11 +08:00
|
|
|
"Allow users to define their own debugger command abbreviations.",
|
2010-10-05 06:28:36 +08:00
|
|
|
NULL)
|
2010-07-07 11:36:20 +08:00
|
|
|
{
|
|
|
|
SetHelpLong(
|
|
|
|
"'alias' allows the user to create a short-cut or abbreviation for long \n\
|
|
|
|
commands, multi-word commands, and commands that take particular options. \n\
|
|
|
|
Below are some simple examples of how one might use the 'alias' command: \n\
|
2010-09-09 06:08:58 +08:00
|
|
|
\n 'commands alias sc script' // Creates the abbreviation 'sc' for the 'script' \n\
|
|
|
|
// command. \n\
|
|
|
|
'commands alias bp breakpoint' // Creates the abbreviation 'bp' for the 'breakpoint' \n\
|
|
|
|
// command. Since breakpoint commands are two-word \n\
|
|
|
|
// commands, the user will still need to enter the \n\
|
|
|
|
// second word after 'bp', e.g. 'bp enable' or \n\
|
|
|
|
// 'bp delete'. \n\
|
|
|
|
'commands alias bpl breakpoint list' // Creates the abbreviation 'bpl' for the \n\
|
|
|
|
// two-word command 'breakpoint list'. \n\
|
2010-07-07 11:36:20 +08:00
|
|
|
\nAn alias can include some options for the command, with the values either \n\
|
|
|
|
filled in at the time the alias is created, or specified as positional \n\
|
|
|
|
arguments, to be filled in when the alias is invoked. The following example \n\
|
|
|
|
shows how to create aliases with options: \n\
|
|
|
|
\n\
|
2010-09-09 06:08:58 +08:00
|
|
|
'commands alias bfl breakpoint set -f %1 -l %2' \n\
|
2010-07-07 11:36:20 +08:00
|
|
|
\nThis creates the abbreviation 'bfl' (for break-file-line), with the -f and -l \n\
|
|
|
|
options already part of the alias. So if the user wants to set a breakpoint \n\
|
|
|
|
by file and line without explicitly having to use the -f and -l options, the \n\
|
|
|
|
user can now use 'bfl' instead. The '%1' and '%2' are positional placeholders \n\
|
|
|
|
for the actual arguments that will be passed when the alias command is used. \n\
|
|
|
|
The number in the placeholder refers to the position/order the actual value \n\
|
|
|
|
occupies when the alias is used. So all the occurrences of '%1' in the alias \n\
|
|
|
|
will be replaced with the first argument, all the occurrences of '%2' in the \n\
|
|
|
|
alias will be replaced with the second argument, and so on. This also allows \n\
|
|
|
|
actual arguments to be used multiple times within an alias (see 'process \n\
|
|
|
|
launch' example below). So in the 'bfl' case, the actual file value will be \n\
|
|
|
|
filled in with the first argument following 'bfl' and the actual line number \n\
|
|
|
|
value will be filled in with the second argument. The user would use this \n\
|
|
|
|
alias as follows: \n\
|
2010-09-09 06:08:58 +08:00
|
|
|
\n (lldb) commands alias bfl breakpoint set -f %1 -l %2 \n\
|
2010-08-10 02:50:15 +08:00
|
|
|
<... some time later ...> \n\
|
2010-09-09 06:08:58 +08:00
|
|
|
(lldb) bfl my-file.c 137 \n\
|
2010-07-07 11:36:20 +08:00
|
|
|
\nThis would be the same as if the user had entered \n\
|
|
|
|
'breakpoint set -f my-file.c -l 137'. \n\
|
|
|
|
\nAnother example: \n\
|
2010-09-09 06:08:58 +08:00
|
|
|
\n (lldb) commands alias pltty process launch -s -o %1 -e %1 \n\
|
|
|
|
(lldb) pltty /dev/tty0 \n\
|
2010-08-10 02:50:15 +08:00
|
|
|
// becomes 'process launch -s -o /dev/tty0 -e /dev/tty0' \n\
|
2010-07-07 11:36:20 +08:00
|
|
|
\nIf the user always wanted to pass the same value to a particular option, the \n\
|
|
|
|
alias could be defined with that value directly in the alias as a constant, \n\
|
|
|
|
rather than using a positional placeholder: \n\
|
2010-08-10 02:50:15 +08:00
|
|
|
\n commands alias bl3 breakpoint set -f %1 -l 3 // Always sets a breakpoint on line \n\
|
|
|
|
// 3 of whatever file is indicated. \n");
|
2010-07-07 11:36:20 +08:00
|
|
|
|
2010-10-05 06:28:36 +08:00
|
|
|
CommandArgumentEntry arg1;
|
|
|
|
CommandArgumentEntry arg2;
|
|
|
|
CommandArgumentEntry arg3;
|
|
|
|
CommandArgumentData alias_arg;
|
|
|
|
CommandArgumentData cmd_arg;
|
|
|
|
CommandArgumentData options_arg;
|
|
|
|
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
alias_arg.arg_type = eArgTypeAliasName;
|
|
|
|
alias_arg.arg_repetition = eArgRepeatPlain;
|
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the argument entry.
|
|
|
|
arg1.push_back (alias_arg);
|
|
|
|
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
cmd_arg.arg_type = eArgTypeCommandName;
|
|
|
|
cmd_arg.arg_repetition = eArgRepeatPlain;
|
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the argument entry.
|
|
|
|
arg2.push_back (cmd_arg);
|
|
|
|
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
options_arg.arg_type = eArgTypeAliasOptions;
|
|
|
|
options_arg.arg_repetition = eArgRepeatOptional;
|
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the argument entry.
|
|
|
|
arg3.push_back (options_arg);
|
|
|
|
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back (arg1);
|
|
|
|
m_arguments.push_back (arg2);
|
|
|
|
m_arguments.push_back (arg3);
|
2010-07-07 11:36:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~CommandObjectCommandsAlias ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-12-10 06:52:49 +08:00
|
|
|
bool
|
|
|
|
WantsRawCommandString ()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ExecuteRawCommandString (const char *raw_command_line, CommandReturnObject &result)
|
|
|
|
{
|
|
|
|
Args args (raw_command_line);
|
|
|
|
std::string raw_command_string (raw_command_line);
|
|
|
|
|
|
|
|
size_t argc = args.GetArgumentCount();
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
{
|
|
|
|
result.AppendError ("'alias' requires at least two arguments");
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the alias command.
|
|
|
|
|
|
|
|
const std::string alias_command = args.GetArgumentAtIndex (0);
|
|
|
|
|
|
|
|
// Strip the new alias name off 'raw_command_string' (leave it on args, which gets passed to 'Execute', which
|
|
|
|
// does the stripping itself.
|
|
|
|
size_t pos = raw_command_string.find (alias_command);
|
|
|
|
if (pos == 0)
|
|
|
|
{
|
|
|
|
raw_command_string = raw_command_string.substr (alias_command.size());
|
|
|
|
pos = raw_command_string.find_first_not_of (' ');
|
|
|
|
if ((pos != std::string::npos) && (pos > 0))
|
|
|
|
raw_command_string = raw_command_string.substr (pos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendError ("Error parsing command string. No alias created.");
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Verify that the command is alias-able.
|
|
|
|
if (m_interpreter.CommandExists (alias_command.c_str()))
|
|
|
|
{
|
|
|
|
result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be redefined.\n",
|
|
|
|
alias_command.c_str());
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get CommandObject that is being aliased. The command name is read from the front of raw_command_string.
|
|
|
|
// raw_command_string is returned with the name of the command object stripped off the front.
|
|
|
|
CommandObject *cmd_obj = m_interpreter.GetCommandObjectForCommand (raw_command_string);
|
|
|
|
|
|
|
|
if (!cmd_obj)
|
|
|
|
{
|
|
|
|
result.AppendErrorWithFormat ("Invalid command given to 'alias'. '%s' does not begin with a valid command."
|
|
|
|
" No alias created.", raw_command_string.c_str());
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (!cmd_obj->WantsRawCommandString ())
|
|
|
|
{
|
|
|
|
// Note that args was initialized with the original command, and has not been updated to this point.
|
|
|
|
// Therefore can we pass it to the version of Execute that does not need/expect raw input in the alias.
|
|
|
|
return Execute (args, result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Verify & handle any options/arguments passed to the alias command
|
|
|
|
|
|
|
|
OptionArgVectorSP option_arg_vector_sp = OptionArgVectorSP (new OptionArgVector);
|
|
|
|
OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
|
|
|
|
|
|
|
|
// Check to see if there's anything left in the input command string.
|
|
|
|
if (raw_command_string.size() > 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Check to see if the command being aliased can take any command options.
|
|
|
|
Options *options = cmd_obj->GetOptions();
|
|
|
|
if (options)
|
|
|
|
{
|
|
|
|
// See if any options were specified as part of the alias; if so, handle them appropriately
|
Many improvements to the Platform base class and subclasses. The base Platform
class now implements the Host functionality for a lot of things that make
sense by default so that subclasses can check:
int
PlatformSubclass::Foo ()
{
if (IsHost())
return Platform::Foo (); // Let the platform base class do the host specific stuff
// Platform subclass specific code...
int result = ...
return result;
}
Added new functions to the platform:
virtual const char *Platform::GetUserName (uint32_t uid);
virtual const char *Platform::GetGroupName (uint32_t gid);
The user and group names are cached locally so that remote platforms can avoid
sending packets multiple times to resolve this information.
Added the parent process ID to the ProcessInfo class.
Added a new ProcessInfoMatch class which helps us to match processes up
and changed the Host layer over to using this new class. The new class allows
us to search for processs:
1 - by name (equal to, starts with, ends with, contains, and regex)
2 - by pid
3 - And further check for parent pid == value, uid == value, gid == value,
euid == value, egid == value, arch == value, parent == value.
This is all hookup up to the "platform process list" command which required
adding dumping routines to dump process information. If the Host class
implements the process lookup routines, you can now lists processes on
your local machine:
machine1.foo.com % lldb
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
94727 244 username usergroup username usergroup x86_64-apple-darwin Xcode
92742 92710 username usergroup username usergroup i386-apple-darwin debugserver
This of course also works remotely with the lldb-platform:
machine1.foo.com % lldb-platform --listen 1234
machine2.foo.com % lldb
(lldb) platform create remote-macosx
Platform: remote-macosx
Connected: no
(lldb) platform connect connect://localhost:1444
Platform: remote-macosx
Triple: x86_64-apple-darwin
OS Version: 10.6.7 (10J869)
Kernel: Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386
Hostname: machine1.foo.com
Connected: yes
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99556 244 username usergroup username usergroup x86_64-apple-darwin trustevaluation
99548 65539 username usergroup username usergroup x86_64-apple-darwin lldb
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
The lldb-platform implements everything with the Host:: layer, so this should
"just work" for linux. I will probably be adding more stuff to the Host layer
for launching processes and attaching to processes so that this support should
eventually just work as well.
Modified the target to be able to be created with an architecture that differs
from the main executable. This is needed for iOS debugging since we can have
an "armv6" binary which can run on an "armv7" machine, so we want to be able
to do:
% lldb
(lldb) platform create remote-ios
(lldb) file --arch armv7 a.out
Where "a.out" is an armv6 executable. The platform then can correctly decide
to open all "armv7" images for all dependent shared libraries.
Modified the disassembly to show the current PC value. Example output:
(lldb) disassemble --frame
a.out`main:
0x1eb7: pushl %ebp
0x1eb8: movl %esp, %ebp
0x1eba: pushl %ebx
0x1ebb: subl $20, %esp
0x1ebe: calll 0x1ec3 ; main + 12 at test.c:18
0x1ec3: popl %ebx
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
0x1edb: leal 213(%ebx), %eax
0x1ee1: movl %eax, (%esp)
0x1ee4: calll 0x1f1e ; puts
0x1ee9: calll 0x1f0c ; getchar
0x1eee: movl $20, (%esp)
0x1ef5: calll 0x1e6a ; sleep_loop at test.c:6
0x1efa: movl $12, %eax
0x1eff: addl $20, %esp
0x1f02: popl %ebx
0x1f03: leave
0x1f04: ret
This can be handy when dealing with the new --line options that was recently
added:
(lldb) disassemble --line
a.out`main + 13 at test.c:19
18 {
-> 19 printf("Process: %i\n\n", getpid());
20 puts("Press any key to continue..."); getchar();
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
Modified the ModuleList to have a lookup based solely on a UUID. Since the
UUID is typically the MD5 checksum of a binary image, there is no need
to give the path and architecture when searching for a pre-existing
image in an image list.
Now that we support remote debugging a bit better, our lldb_private::Module
needs to be able to track what the original path for file was as the platform
knows it, as well as where the file is locally. The module has the two
following functions to retrieve both paths:
const FileSpec &Module::GetFileSpec () const;
const FileSpec &Module::GetPlatformFileSpec () const;
llvm-svn: 128563
2011-03-31 02:16:51 +08:00
|
|
|
options->Reset ();
|
2010-12-10 06:52:49 +08:00
|
|
|
Args tmp_args (raw_command_string.c_str());
|
|
|
|
args.Unshift ("dummy_arg");
|
|
|
|
args.ParseAliasOptions (*options, result, option_arg_vector, raw_command_string);
|
|
|
|
args.Shift ();
|
|
|
|
if (result.Succeeded())
|
|
|
|
options->VerifyPartialOptions (result);
|
|
|
|
if (!result.Succeeded() && result.GetStatus() != lldb::eReturnStatusStarted)
|
|
|
|
{
|
|
|
|
result.AppendError ("Unable to create requested alias.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Anything remaining must be plain raw input. Push it in as a single raw input argument.
|
|
|
|
if (raw_command_string.size() > 0)
|
|
|
|
option_arg_vector->push_back (OptionArgPair ("<argument>",
|
|
|
|
OptionArgValue (-1,
|
|
|
|
raw_command_string)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the alias
|
|
|
|
if (m_interpreter.AliasExists (alias_command.c_str())
|
|
|
|
|| m_interpreter.UserCommandExists (alias_command.c_str()))
|
|
|
|
{
|
|
|
|
OptionArgVectorSP temp_option_arg_sp (m_interpreter.GetAliasOptions (alias_command.c_str()));
|
|
|
|
if (temp_option_arg_sp.get())
|
|
|
|
{
|
|
|
|
if (option_arg_vector->size() == 0)
|
|
|
|
m_interpreter.RemoveAliasOptions (alias_command.c_str());
|
|
|
|
}
|
|
|
|
result.AppendWarningWithFormat ("Overwriting existing definition for '%s'.\n",
|
|
|
|
alias_command.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandObjectSP cmd_obj_sp = m_interpreter.GetCommandSPExact (cmd_obj->GetCommandName(), false);
|
2010-12-15 02:51:39 +08:00
|
|
|
if (cmd_obj_sp)
|
|
|
|
{
|
|
|
|
m_interpreter.AddAlias (alias_command.c_str(), cmd_obj_sp);
|
|
|
|
if (option_arg_vector->size() > 0)
|
|
|
|
m_interpreter.AddOrReplaceAliasOptions (alias_command.c_str(), option_arg_vector_sp);
|
|
|
|
result.SetStatus (eReturnStatusSuccessFinishNoResult);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendError ("Unable to create requested alias.\n");
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
2010-12-10 06:52:49 +08:00
|
|
|
}
|
|
|
|
return result.Succeeded();
|
|
|
|
}
|
2010-07-07 11:36:20 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
Execute
|
|
|
|
(
|
|
|
|
Args& args,
|
|
|
|
CommandReturnObject &result
|
|
|
|
)
|
|
|
|
{
|
2010-09-22 07:25:40 +08:00
|
|
|
size_t argc = args.GetArgumentCount();
|
2010-07-07 11:36:20 +08:00
|
|
|
|
|
|
|
if (argc < 2)
|
2010-07-10 04:39:50 +08:00
|
|
|
{
|
2010-07-07 11:36:20 +08:00
|
|
|
result.AppendError ("'alias' requires at least two arguments");
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
return false;
|
2010-07-10 04:39:50 +08:00
|
|
|
}
|
2010-07-07 11:36:20 +08:00
|
|
|
|
|
|
|
const std::string alias_command = args.GetArgumentAtIndex(0);
|
|
|
|
const std::string actual_command = args.GetArgumentAtIndex(1);
|
|
|
|
|
|
|
|
args.Shift(); // Shift the alias command word off the argument vector.
|
|
|
|
args.Shift(); // Shift the old command word off the argument vector.
|
|
|
|
|
|
|
|
// Verify that the command is alias'able, and get the appropriate command object.
|
|
|
|
|
2010-09-18 09:14:36 +08:00
|
|
|
if (m_interpreter.CommandExists (alias_command.c_str()))
|
2010-07-07 11:36:20 +08:00
|
|
|
{
|
|
|
|
result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be redefined.\n",
|
|
|
|
alias_command.c_str());
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectSP command_obj_sp(m_interpreter.GetCommandSPExact (actual_command.c_str(), true));
|
2010-07-07 11:36:20 +08:00
|
|
|
CommandObjectSP subcommand_obj_sp;
|
|
|
|
bool use_subcommand = false;
|
|
|
|
if (command_obj_sp.get())
|
|
|
|
{
|
|
|
|
CommandObject *cmd_obj = command_obj_sp.get();
|
2010-07-10 04:39:50 +08:00
|
|
|
CommandObject *sub_cmd_obj = NULL;
|
2010-07-07 11:36:20 +08:00
|
|
|
OptionArgVectorSP option_arg_vector_sp = OptionArgVectorSP (new OptionArgVector);
|
|
|
|
OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
|
|
|
|
|
2010-12-10 06:52:49 +08:00
|
|
|
while (cmd_obj->IsMultiwordObject() && args.GetArgumentCount() > 0)
|
2010-07-07 11:36:20 +08:00
|
|
|
{
|
|
|
|
if (argc >= 3)
|
|
|
|
{
|
|
|
|
const std::string sub_command = args.GetArgumentAtIndex(0);
|
|
|
|
assert (sub_command.length() != 0);
|
|
|
|
subcommand_obj_sp =
|
|
|
|
(((CommandObjectMultiword *) cmd_obj)->GetSubcommandSP (sub_command.c_str()));
|
|
|
|
if (subcommand_obj_sp.get())
|
|
|
|
{
|
|
|
|
sub_cmd_obj = subcommand_obj_sp.get();
|
|
|
|
use_subcommand = true;
|
|
|
|
args.Shift(); // Shift the sub_command word off the argument vector.
|
2010-12-10 06:52:49 +08:00
|
|
|
cmd_obj = sub_cmd_obj;
|
2010-07-07 11:36:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-03 03:00:04 +08:00
|
|
|
result.AppendErrorWithFormat("'%s' is not a valid sub-command of '%s'. "
|
|
|
|
"Unable to create alias.\n",
|
|
|
|
sub_command.c_str(), actual_command.c_str());
|
2010-07-07 11:36:20 +08:00
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify & handle any options/arguments passed to the alias command
|
|
|
|
|
|
|
|
if (args.GetArgumentCount () > 0)
|
|
|
|
{
|
|
|
|
if ((!use_subcommand && (cmd_obj->GetOptions() != NULL))
|
|
|
|
|| (use_subcommand && (sub_cmd_obj->GetOptions() != NULL)))
|
|
|
|
{
|
|
|
|
Options *options;
|
|
|
|
if (use_subcommand)
|
|
|
|
options = sub_cmd_obj->GetOptions();
|
|
|
|
else
|
|
|
|
options = cmd_obj->GetOptions();
|
Many improvements to the Platform base class and subclasses. The base Platform
class now implements the Host functionality for a lot of things that make
sense by default so that subclasses can check:
int
PlatformSubclass::Foo ()
{
if (IsHost())
return Platform::Foo (); // Let the platform base class do the host specific stuff
// Platform subclass specific code...
int result = ...
return result;
}
Added new functions to the platform:
virtual const char *Platform::GetUserName (uint32_t uid);
virtual const char *Platform::GetGroupName (uint32_t gid);
The user and group names are cached locally so that remote platforms can avoid
sending packets multiple times to resolve this information.
Added the parent process ID to the ProcessInfo class.
Added a new ProcessInfoMatch class which helps us to match processes up
and changed the Host layer over to using this new class. The new class allows
us to search for processs:
1 - by name (equal to, starts with, ends with, contains, and regex)
2 - by pid
3 - And further check for parent pid == value, uid == value, gid == value,
euid == value, egid == value, arch == value, parent == value.
This is all hookup up to the "platform process list" command which required
adding dumping routines to dump process information. If the Host class
implements the process lookup routines, you can now lists processes on
your local machine:
machine1.foo.com % lldb
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
94727 244 username usergroup username usergroup x86_64-apple-darwin Xcode
92742 92710 username usergroup username usergroup i386-apple-darwin debugserver
This of course also works remotely with the lldb-platform:
machine1.foo.com % lldb-platform --listen 1234
machine2.foo.com % lldb
(lldb) platform create remote-macosx
Platform: remote-macosx
Connected: no
(lldb) platform connect connect://localhost:1444
Platform: remote-macosx
Triple: x86_64-apple-darwin
OS Version: 10.6.7 (10J869)
Kernel: Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386
Hostname: machine1.foo.com
Connected: yes
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99556 244 username usergroup username usergroup x86_64-apple-darwin trustevaluation
99548 65539 username usergroup username usergroup x86_64-apple-darwin lldb
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
The lldb-platform implements everything with the Host:: layer, so this should
"just work" for linux. I will probably be adding more stuff to the Host layer
for launching processes and attaching to processes so that this support should
eventually just work as well.
Modified the target to be able to be created with an architecture that differs
from the main executable. This is needed for iOS debugging since we can have
an "armv6" binary which can run on an "armv7" machine, so we want to be able
to do:
% lldb
(lldb) platform create remote-ios
(lldb) file --arch armv7 a.out
Where "a.out" is an armv6 executable. The platform then can correctly decide
to open all "armv7" images for all dependent shared libraries.
Modified the disassembly to show the current PC value. Example output:
(lldb) disassemble --frame
a.out`main:
0x1eb7: pushl %ebp
0x1eb8: movl %esp, %ebp
0x1eba: pushl %ebx
0x1ebb: subl $20, %esp
0x1ebe: calll 0x1ec3 ; main + 12 at test.c:18
0x1ec3: popl %ebx
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
0x1edb: leal 213(%ebx), %eax
0x1ee1: movl %eax, (%esp)
0x1ee4: calll 0x1f1e ; puts
0x1ee9: calll 0x1f0c ; getchar
0x1eee: movl $20, (%esp)
0x1ef5: calll 0x1e6a ; sleep_loop at test.c:6
0x1efa: movl $12, %eax
0x1eff: addl $20, %esp
0x1f02: popl %ebx
0x1f03: leave
0x1f04: ret
This can be handy when dealing with the new --line options that was recently
added:
(lldb) disassemble --line
a.out`main + 13 at test.c:19
18 {
-> 19 printf("Process: %i\n\n", getpid());
20 puts("Press any key to continue..."); getchar();
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
Modified the ModuleList to have a lookup based solely on a UUID. Since the
UUID is typically the MD5 checksum of a binary image, there is no need
to give the path and architecture when searching for a pre-existing
image in an image list.
Now that we support remote debugging a bit better, our lldb_private::Module
needs to be able to track what the original path for file was as the platform
knows it, as well as where the file is locally. The module has the two
following functions to retrieve both paths:
const FileSpec &Module::GetFileSpec () const;
const FileSpec &Module::GetPlatformFileSpec () const;
llvm-svn: 128563
2011-03-31 02:16:51 +08:00
|
|
|
options->Reset ();
|
2010-12-10 06:52:49 +08:00
|
|
|
std::string empty_string;
|
2010-07-07 11:36:20 +08:00
|
|
|
args.Unshift ("dummy_arg");
|
2010-12-10 06:52:49 +08:00
|
|
|
args.ParseAliasOptions (*options, result, option_arg_vector, empty_string);
|
2010-07-07 11:36:20 +08:00
|
|
|
args.Shift ();
|
|
|
|
if (result.Succeeded())
|
|
|
|
options->VerifyPartialOptions (result);
|
2010-09-22 07:25:40 +08:00
|
|
|
if (!result.Succeeded() && result.GetStatus() != lldb::eReturnStatusStarted)
|
|
|
|
{
|
|
|
|
result.AppendError ("Unable to create requested command alias.\n");
|
2010-10-29 07:17:48 +08:00
|
|
|
return false;
|
2010-09-22 07:25:40 +08:00
|
|
|
}
|
2010-07-07 11:36:20 +08:00
|
|
|
}
|
2010-09-22 07:25:40 +08:00
|
|
|
|
|
|
|
// Anything remaining in args must be a plain argument.
|
|
|
|
|
|
|
|
argc = args.GetArgumentCount();
|
|
|
|
for (size_t i = 0; i < argc; ++i)
|
2010-12-08 03:58:26 +08:00
|
|
|
if (strcmp (args.GetArgumentAtIndex (i), "") != 0)
|
|
|
|
option_arg_vector->push_back
|
|
|
|
(OptionArgPair ("<argument>",
|
|
|
|
OptionArgValue (-1,
|
|
|
|
std::string (args.GetArgumentAtIndex (i)))));
|
2010-07-07 11:36:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the alias.
|
|
|
|
|
2010-09-18 09:14:36 +08:00
|
|
|
if (m_interpreter.AliasExists (alias_command.c_str())
|
|
|
|
|| m_interpreter.UserCommandExists (alias_command.c_str()))
|
2010-07-07 11:36:20 +08:00
|
|
|
{
|
2010-09-18 09:14:36 +08:00
|
|
|
OptionArgVectorSP tmp_option_arg_sp (m_interpreter.GetAliasOptions (alias_command.c_str()));
|
2010-07-07 11:36:20 +08:00
|
|
|
if (tmp_option_arg_sp.get())
|
|
|
|
{
|
|
|
|
if (option_arg_vector->size() == 0)
|
2010-09-18 09:14:36 +08:00
|
|
|
m_interpreter.RemoveAliasOptions (alias_command.c_str());
|
2010-07-07 11:36:20 +08:00
|
|
|
}
|
|
|
|
result.AppendWarningWithFormat ("Overwriting existing definition for '%s'.\n",
|
|
|
|
alias_command.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_subcommand)
|
2010-09-18 09:14:36 +08:00
|
|
|
m_interpreter.AddAlias (alias_command.c_str(), subcommand_obj_sp);
|
2010-07-07 11:36:20 +08:00
|
|
|
else
|
2010-09-18 09:14:36 +08:00
|
|
|
m_interpreter.AddAlias (alias_command.c_str(), command_obj_sp);
|
2010-07-07 11:36:20 +08:00
|
|
|
if (option_arg_vector->size() > 0)
|
2010-09-18 09:14:36 +08:00
|
|
|
m_interpreter.AddOrReplaceAliasOptions (alias_command.c_str(), option_arg_vector_sp);
|
2010-07-07 11:36:20 +08:00
|
|
|
result.SetStatus (eReturnStatusSuccessFinishNoResult);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendErrorWithFormat ("'%s' is not an existing command.\n", actual_command.c_str());
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
2010-10-29 07:17:48 +08:00
|
|
|
return false;
|
2010-07-07 11:36:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.Succeeded();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#pragma mark CommandObjectCommandsUnalias
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// CommandObjectCommandsUnalias
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class CommandObjectCommandsUnalias : public CommandObject
|
|
|
|
{
|
|
|
|
public:
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectCommandsUnalias (CommandInterpreter &interpreter) :
|
|
|
|
CommandObject (interpreter,
|
|
|
|
"commands unalias",
|
2010-09-12 12:56:10 +08:00
|
|
|
"Allow the user to remove/delete a user-defined command abbreviation.",
|
2010-10-05 06:28:36 +08:00
|
|
|
NULL)
|
2010-07-07 11:36:20 +08:00
|
|
|
{
|
2010-10-05 06:28:36 +08:00
|
|
|
CommandArgumentEntry arg;
|
|
|
|
CommandArgumentData alias_arg;
|
|
|
|
|
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
alias_arg.arg_type = eArgTypeAliasName;
|
|
|
|
alias_arg.arg_repetition = eArgRepeatPlain;
|
|
|
|
|
|
|
|
// There is only one variant this argument could be; put it into the argument entry.
|
|
|
|
arg.push_back (alias_arg);
|
|
|
|
|
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back (arg);
|
2010-07-07 11:36:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~CommandObjectCommandsUnalias()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
Execute
|
|
|
|
(
|
|
|
|
Args& args,
|
|
|
|
CommandReturnObject &result
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CommandObject::CommandMap::iterator pos;
|
|
|
|
CommandObject *cmd_obj;
|
|
|
|
|
|
|
|
if (args.GetArgumentCount() != 0)
|
|
|
|
{
|
|
|
|
const char *command_name = args.GetArgumentAtIndex(0);
|
2010-09-18 09:14:36 +08:00
|
|
|
cmd_obj = m_interpreter.GetCommandObject(command_name);
|
2010-07-07 11:36:20 +08:00
|
|
|
if (cmd_obj)
|
|
|
|
{
|
2010-09-18 09:14:36 +08:00
|
|
|
if (m_interpreter.CommandExists (command_name))
|
2010-07-07 11:36:20 +08:00
|
|
|
{
|
|
|
|
result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be removed.\n",
|
|
|
|
command_name);
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
2010-09-18 09:14:36 +08:00
|
|
|
if (m_interpreter.RemoveAlias (command_name) == false)
|
2010-07-07 11:36:20 +08:00
|
|
|
{
|
2010-09-18 09:14:36 +08:00
|
|
|
if (m_interpreter.AliasExists (command_name))
|
2010-07-07 11:36:20 +08:00
|
|
|
result.AppendErrorWithFormat ("Error occurred while attempting to unalias '%s'.\n",
|
|
|
|
command_name);
|
|
|
|
else
|
|
|
|
result.AppendErrorWithFormat ("'%s' is not an existing alias.\n", command_name);
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result.SetStatus (eReturnStatusSuccessFinishNoResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendErrorWithFormat ("'%s' is not a known command.\nTry 'help' to see a "
|
|
|
|
"current list of commands.\n",
|
|
|
|
command_name);
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.AppendError ("must call 'unalias' with a valid alias");
|
|
|
|
result.SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.Succeeded();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#pragma mark CommandObjectMultiwordCommands
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// CommandObjectMultiwordCommands
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
CommandObjectMultiwordCommands::CommandObjectMultiwordCommands (CommandInterpreter &interpreter) :
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectMultiword (interpreter,
|
|
|
|
"commands",
|
2010-09-08 06:38:08 +08:00
|
|
|
"A set of commands for managing or customizing the debugger commands.",
|
2010-07-07 11:36:20 +08:00
|
|
|
"commands <subcommand> [<subcommand-options>]")
|
|
|
|
{
|
2010-09-18 09:14:36 +08:00
|
|
|
LoadSubCommand ("source", CommandObjectSP (new CommandObjectCommandsSource (interpreter)));
|
|
|
|
LoadSubCommand ("alias", CommandObjectSP (new CommandObjectCommandsAlias (interpreter)));
|
|
|
|
LoadSubCommand ("unalias", CommandObjectSP (new CommandObjectCommandsUnalias (interpreter)));
|
2010-07-07 11:36:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CommandObjectMultiwordCommands::~CommandObjectMultiwordCommands ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|