本文整理汇总了C++中CommandReturnObject::SetStatus方法的典型用法代码示例。如果您正苦于以下问题:C++ CommandReturnObject::SetStatus方法的具体用法?C++ CommandReturnObject::SetStatus怎么用?C++ CommandReturnObject::SetStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandReturnObject
的用法示例。
在下文中一共展示了CommandReturnObject::SetStatus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
virtual bool
Execute (Args& command,
CommandReturnObject &result)
{
Process *process = m_interpreter.GetDebugger().GetExecutionContext().process;
if (process == NULL)
{
result.AppendError("need a process to read memory");
result.SetStatus(eReturnStatusFailed);
return false;
}
const size_t argc = command.GetArgumentCount();
if (m_options.m_infile)
{
if (argc < 1)
{
result.AppendErrorWithFormat ("%s takes a destination address when writing file contents.\n", m_cmd_name.c_str());
result.SetStatus(eReturnStatusFailed);
return false;
}
}
else if (argc < 2)
{
result.AppendErrorWithFormat ("%s takes a destination address and at least one value.\n", m_cmd_name.c_str());
result.SetStatus(eReturnStatusFailed);
return false;
}
StreamString buffer (Stream::eBinary,
process->GetTarget().GetArchitecture().GetAddressByteSize(),
process->GetTarget().GetArchitecture().GetByteOrder());
size_t item_byte_size = m_options.m_byte_size;
lldb::addr_t addr = Args::StringToUInt64(command.GetArgumentAtIndex(0), LLDB_INVALID_ADDRESS, 0);
if (addr == LLDB_INVALID_ADDRESS)
{
result.AppendErrorWithFormat("Invalid address string '%s'.\n", command.GetArgumentAtIndex(0));
result.SetStatus(eReturnStatusFailed);
return false;
}
if (m_options.m_infile)
{
size_t length = SIZE_MAX;
if (m_options.m_byte_size > 0)
length = m_options.m_byte_size;
lldb::DataBufferSP data_sp (m_options.m_infile.ReadFileContents (m_options.m_infile_offset, length));
if (data_sp)
{
length = data_sp->GetByteSize();
if (length > 0)
{
Error error;
size_t bytes_written = process->WriteMemory (addr, data_sp->GetBytes(), length, error);
if (bytes_written == length)
{
// All bytes written
result.GetOutputStream().Printf("%zu bytes were written to 0x%llx\n", bytes_written, addr);
result.SetStatus(eReturnStatusSuccessFinishResult);
}
else if (bytes_written > 0)
{
// Some byte written
result.GetOutputStream().Printf("%zu bytes of %zu requested were written to 0x%llx\n", bytes_written, length, addr);
result.SetStatus(eReturnStatusSuccessFinishResult);
}
else
{
result.AppendErrorWithFormat ("Memory write to 0x%llx failed: %s.\n", addr, error.AsCString());
result.SetStatus(eReturnStatusFailed);
}
}
}
else
{
result.AppendErrorWithFormat ("Unable to read contents of file.\n");
result.SetStatus(eReturnStatusFailed);
}
return result.Succeeded();
}
else if (m_options.m_byte_size == 0)
{
if (m_options.m_format == eFormatPointer)
item_byte_size = buffer.GetAddressByteSize();
else
item_byte_size = 1;
}
command.Shift(); // shift off the address argument
uint64_t uval64;
int64_t sval64;
bool success = false;
const uint32_t num_value_args = command.GetArgumentCount();
uint32_t i;
for (i=0; i<num_value_args; ++i)
//.........这里部分代码省略.........
示例2: scoped_timer
bool
CommandObjectFile::Execute
(
CommandInterpreter &interpreter,
Args& command,
CommandReturnObject &result
)
{
const char *file_path = command.GetArgumentAtIndex(0);
Timer scoped_timer(__PRETTY_FUNCTION__, "(dbg) file '%s'", file_path);
const int argc = command.GetArgumentCount();
if (argc == 1)
{
FileSpec file_spec (file_path);
if (! file_spec.Exists())
{
result.AppendErrorWithFormat ("File '%s' does not exist.\n", file_path);
result.SetStatus (eReturnStatusFailed);
return result.Succeeded();
}
TargetSP target_sp;
ArchSpec arch;
if (m_options.m_arch.IsValid())
arch = m_options.m_arch;
else
{
arch = lldb_private::GetDefaultArchitecture ();
if (!arch.IsValid())
arch = LLDB_ARCH_DEFAULT;
}
Debugger &debugger = interpreter.GetDebugger();
Error error = debugger.GetTargetList().CreateTarget (debugger, file_spec, arch, NULL, true, target_sp);
if (error.Fail() && !m_options.m_arch.IsValid())
{
if (arch == LLDB_ARCH_DEFAULT_32BIT)
arch = LLDB_ARCH_DEFAULT_64BIT;
else
arch = LLDB_ARCH_DEFAULT_32BIT;
error = debugger.GetTargetList().CreateTarget (debugger, file_spec, arch, NULL, true, target_sp);
}
if (target_sp)
{
debugger.GetTargetList().SetCurrentTarget(target_sp.get());
result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, arch.AsCString());
result.SetStatus (eReturnStatusSuccessFinishNoResult);
}
else
{
result.AppendError(error.AsCString());
result.SetStatus (eReturnStatusFailed);
}
}
else
{
result.AppendErrorWithFormat("'%s' takes exactly one executable path argument.\n", m_cmd_name.c_str());
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
}
示例3: extractor
bool
DoExecute (Args& command, CommandReturnObject &result)
{
const size_t argc = command.GetArgumentCount();
if (argc == 0)
{
if (!m_command_byte.GetOptionValue().OptionWasSet())
{
result.AppendError ("the --command option must be set to a valid command byte");
result.SetStatus (eReturnStatusFailed);
}
else
{
const uint64_t command_byte = m_command_byte.GetOptionValue().GetUInt64Value(0);
if (command_byte > 0 && command_byte <= UINT8_MAX)
{
ProcessKDP *process = (ProcessKDP *)m_interpreter.GetExecutionContext().GetProcessPtr();
if (process)
{
const StateType state = process->GetState();
if (StateIsStoppedState (state, true))
{
std::vector<uint8_t> payload_bytes;
const char *ascii_hex_bytes_cstr = m_packet_data.GetOptionValue().GetCurrentValue();
if (ascii_hex_bytes_cstr && ascii_hex_bytes_cstr[0])
{
StringExtractor extractor(ascii_hex_bytes_cstr);
const size_t ascii_hex_bytes_cstr_len = extractor.GetStringRef().size();
if (ascii_hex_bytes_cstr_len & 1)
{
result.AppendErrorWithFormat ("payload data must contain an even number of ASCII hex characters: '%s'", ascii_hex_bytes_cstr);
result.SetStatus (eReturnStatusFailed);
return false;
}
payload_bytes.resize(ascii_hex_bytes_cstr_len/2);
if (extractor.GetHexBytes(&payload_bytes[0], payload_bytes.size(), '\xdd') != payload_bytes.size())
{
result.AppendErrorWithFormat ("payload data must only contain ASCII hex characters (no spaces or hex prefixes): '%s'", ascii_hex_bytes_cstr);
result.SetStatus (eReturnStatusFailed);
return false;
}
}
Error error;
DataExtractor reply;
process->GetCommunication().SendRawRequest (command_byte,
payload_bytes.empty() ? NULL : payload_bytes.data(),
payload_bytes.size(),
reply,
error);
if (error.Success())
{
// Copy the binary bytes into a hex ASCII string for the result
StreamString packet;
packet.PutBytesAsRawHex8(reply.GetDataStart(),
reply.GetByteSize(),
lldb::endian::InlHostByteOrder(),
lldb::endian::InlHostByteOrder());
result.AppendMessage(packet.GetString().c_str());
result.SetStatus (eReturnStatusSuccessFinishResult);
return true;
}
else
{
const char *error_cstr = error.AsCString();
if (error_cstr && error_cstr[0])
result.AppendError (error_cstr);
else
result.AppendErrorWithFormat ("unknown error 0x%8.8x", error.GetError());
result.SetStatus (eReturnStatusFailed);
return false;
}
}
else
{
result.AppendErrorWithFormat ("process must be stopped in order to send KDP packets, state is %s", StateAsCString (state));
result.SetStatus (eReturnStatusFailed);
}
}
else
{
result.AppendError ("invalid process");
result.SetStatus (eReturnStatusFailed);
}
}
else
{
result.AppendErrorWithFormat ("invalid command byte 0x%" PRIx64 ", valid values are 1 - 255", command_byte);
result.SetStatus (eReturnStatusFailed);
}
}
}
else
{
result.AppendErrorWithFormat ("'%s' takes no arguments, only options.", m_cmd_name.c_str());
result.SetStatus (eReturnStatusFailed);
}
return false;
}
示例4: platform_sp
virtual bool
DoExecute (Args& args, CommandReturnObject &result)
{
PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
if (platform_sp)
{
Error error;
const uint32_t argc = args.GetArgumentCount();
Target *target = m_exe_ctx.GetTargetPtr();
Module *exe_module = target->GetExecutableModulePointer();
if (exe_module)
{
m_options.launch_info.GetExecutableFile () = exe_module->GetFileSpec();
char exe_path[PATH_MAX];
if (m_options.launch_info.GetExecutableFile ().GetPath (exe_path, sizeof(exe_path)))
m_options.launch_info.GetArguments().AppendArgument (exe_path);
m_options.launch_info.GetArchitecture() = exe_module->GetArchitecture();
}
if (argc > 0)
{
if (m_options.launch_info.GetExecutableFile ())
{
// We already have an executable file, so we will use this
// and all arguments to this function are extra arguments
m_options.launch_info.GetArguments().AppendArguments (args);
}
else
{
// We don't have any file yet, so the first argument is our
// executable, and the rest are program arguments
const bool first_arg_is_executable = true;
m_options.launch_info.SetArguments (args, first_arg_is_executable);
}
}
if (m_options.launch_info.GetExecutableFile ())
{
Debugger &debugger = m_interpreter.GetDebugger();
if (argc == 0)
target->GetRunArguments(m_options.launch_info.GetArguments());
ProcessSP process_sp (platform_sp->DebugProcess (m_options.launch_info,
debugger,
target,
debugger.GetListener(),
error));
if (process_sp && process_sp->IsAlive())
{
result.SetStatus (eReturnStatusSuccessFinishNoResult);
return true;
}
if (error.Success())
result.AppendError ("process launch failed");
else
result.AppendError (error.AsCString());
result.SetStatus (eReturnStatusFailed);
}
else
{
result.AppendError ("'platform process launch' uses the current target file and arguments, or the executable and its arguments can be specified in this command");
result.SetStatus (eReturnStatusFailed);
return false;
}
}
else
{
result.AppendError ("no platform is selected\n");
}
return result.Succeeded();
}
示例5: DoExecute
bool
DoExecute(Args& command, CommandReturnObject &result) override
{
StringList commands;
commands.AppendString("thread backtrace");
Thread *thread = m_exe_ctx.GetThreadPtr();
if (thread)
{
char command_buffer[256];
uint32_t frame_count = thread->GetStackFrameCount();
for (uint32_t i = 0; i < frame_count; ++i)
{
StackFrameSP frame = thread->GetStackFrameAtIndex(i);
lldb::addr_t pc = frame->GetStackID().GetPC();
snprintf(command_buffer, sizeof(command_buffer), "disassemble --bytes --address 0x%" PRIx64, pc);
commands.AppendString(command_buffer);
snprintf(command_buffer, sizeof(command_buffer), "image show-unwind --address 0x%" PRIx64, pc);
commands.AppendString(command_buffer);
}
}
const FileSpec &outfile_spec = m_outfile_options.GetFile().GetCurrentValue();
if (outfile_spec)
{
char path[PATH_MAX];
outfile_spec.GetPath (path, sizeof(path));
uint32_t open_options = File::eOpenOptionWrite |
File::eOpenOptionCanCreate |
File::eOpenOptionAppend |
File::eOpenOptionCloseOnExec;
const bool append = m_outfile_options.GetAppend().GetCurrentValue();
if (!append)
open_options |= File::eOpenOptionTruncate;
StreamFileSP outfile_stream = std::make_shared<StreamFile>();
Error error = outfile_stream->GetFile().Open(path, open_options);
if (error.Fail())
{
result.AppendErrorWithFormat("Failed to open file '%s' for %s: %s\n",
path,
append ? "append" : "write",
error.AsCString());
result.SetStatus(eReturnStatusFailed);
return false;
}
result.SetImmediateOutputStream(outfile_stream);
}
CommandInterpreterRunOptions options;
options.SetStopOnError(false);
options.SetEchoCommands(true);
options.SetPrintResults(true);
options.SetAddToHistory(false);
m_interpreter.HandleCommands(commands, &m_exe_ctx, options, result);
return result.Succeeded();
}
示例6: exe_ctx
bool
DoExecute (Args& command, CommandReturnObject &result)
{
const int argc = command.GetArgumentCount();
if (argc != 0)
{
result.AppendErrorWithFormat("'%s' takes no arguments, only flags.\n", GetCommandName());
result.SetStatus (eReturnStatusFailed);
return false;
}
ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Target *target = exe_ctx.GetTargetPtr();
if (target == NULL)
target = m_interpreter.GetDebugger().GetSelectedTarget().get();
if (target == NULL)
{
result.AppendError ("invalid target, create a debug target using the 'target create' command");
result.SetStatus (eReturnStatusFailed);
return false;
}
SymbolContextList sc_list;
if (!m_options.symbol_name.empty())
{
// Displaying the source for a symbol:
ConstString name(m_options.symbol_name.c_str());
bool include_symbols = false;
bool include_inlines = true;
bool append = true;
size_t num_matches = 0;
if (m_options.modules.size() > 0)
{
ModuleList matching_modules;
for (unsigned i = 0, e = m_options.modules.size(); i != e; i++)
{
FileSpec module_file_spec(m_options.modules[i].c_str(), false);
if (module_file_spec)
{
ModuleSpec module_spec (module_file_spec);
matching_modules.Clear();
target->GetImages().FindModules (module_spec, matching_modules);
num_matches += matching_modules.FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list);
}
}
}
else
{
num_matches = target->GetImages().FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list);
}
SymbolContext sc;
if (num_matches == 0)
{
result.AppendErrorWithFormat("Could not find function named: \"%s\".\n", m_options.symbol_name.c_str());
result.SetStatus (eReturnStatusFailed);
return false;
}
sc_list.GetContextAtIndex (0, sc);
FileSpec start_file;
uint32_t start_line;
uint32_t end_line;
FileSpec end_file;
if (sc.function != NULL)
{
sc.function->GetStartLineSourceInfo (start_file, start_line);
if (start_line == 0)
{
result.AppendErrorWithFormat("Could not find line information for start of function: \"%s\".\n", m_options.symbol_name.c_str());
result.SetStatus (eReturnStatusFailed);
return false;
}
sc.function->GetEndLineSourceInfo (end_file, end_line);
}
else
{
result.AppendErrorWithFormat("Could not find function info for: \"%s\".\n", m_options.symbol_name.c_str());
result.SetStatus (eReturnStatusFailed);
return false;
}
if (num_matches > 1)
{
// This could either be because there are multiple functions of this name, in which case
// we'll have to specify this further... Or it could be because there are multiple inlined instances
// of one function. So run through the matches and if they all have the same file & line then we can just
// list one.
bool found_multiple = false;
for (size_t i = 1; i < num_matches; i++)
{
SymbolContext scratch_sc;
sc_list.GetContextAtIndex (i, scratch_sc);
//.........这里部分代码省略.........
示例7: if
bool
CommandObjectHelp::Execute (Args& command, CommandReturnObject &result)
{
CommandObject::CommandMap::iterator pos;
CommandObject *cmd_obj;
const int argc = command.GetArgumentCount ();
// 'help' doesn't take any options or arguments, other than command names. If argc is 0, we show the user
// all commands and aliases. Otherwise every argument must be the name of a command or a sub-command.
if (argc == 0)
{
result.SetStatus (eReturnStatusSuccessFinishNoResult);
m_interpreter.GetHelp (result); // General help, for ALL commands.
}
else
{
// Get command object for the first command argument. Only search built-in command dictionary.
StringList matches;
cmd_obj = m_interpreter.GetCommandObject (command.GetArgumentAtIndex (0), &matches);
bool is_alias_command = m_interpreter.AliasExists (command.GetArgumentAtIndex (0));
std::string alias_name = command.GetArgumentAtIndex(0);
if (cmd_obj != NULL)
{
StringList matches;
bool all_okay = true;
CommandObject *sub_cmd_obj = cmd_obj;
// Loop down through sub_command dictionaries until we find the command object that corresponds
// to the help command entered.
for (int i = 1; i < argc && all_okay; ++i)
{
std::string sub_command = command.GetArgumentAtIndex(i);
matches.Clear();
if (! sub_cmd_obj->IsMultiwordObject ())
{
all_okay = false;
}
else
{
CommandObject *found_cmd;
found_cmd = ((CommandObjectMultiword *) sub_cmd_obj)->GetSubcommandObject(sub_command.c_str(),
&matches);
if (found_cmd == NULL)
all_okay = false;
else if (matches.GetSize() > 1)
all_okay = false;
else
sub_cmd_obj = found_cmd;
}
}
if (!all_okay || (sub_cmd_obj == NULL))
{
std::string cmd_string;
command.GetCommandString (cmd_string);
if (matches.GetSize() < 2)
{
result.AppendErrorWithFormat("'%s' is not a known command.\n"
"Try 'help' to see a current list of commands.\n",
cmd_string.c_str());
}
else
{
StreamString s;
s.Printf ("ambiguous command %s", cmd_string.c_str());
size_t num_matches = matches.GetSize();
for (size_t match_idx = 0; match_idx < num_matches; match_idx++)
{
s.Printf ("\n\t%s", matches.GetStringAtIndex(match_idx));
}
s.Printf ("\n");
result.AppendError(s.GetData());
}
result.SetStatus (eReturnStatusFailed);
}
else
{
Stream &output_strm = result.GetOutputStream();
if (sub_cmd_obj->GetOptions() != NULL)
{
if (sub_cmd_obj->WantsRawCommandString())
{
std::string help_text (sub_cmd_obj->GetHelp());
help_text.append (" This command takes 'raw' input (no need to quote stuff).");
m_interpreter.OutputFormattedHelpText (output_strm, "", "", help_text.c_str(), 1);
}
else
m_interpreter.OutputFormattedHelpText (output_strm, "", "", sub_cmd_obj->GetHelp(), 1);
output_strm.Printf ("\nSyntax: %s\n", sub_cmd_obj->GetSyntax());
sub_cmd_obj->GetOptions()->GenerateOptionUsage (m_interpreter, output_strm, sub_cmd_obj);
const char *long_help = sub_cmd_obj->GetHelpLong();
if ((long_help != NULL)
&& (strlen (long_help) > 0))
output_strm.Printf ("\n%s", long_help);
// Mark this help command with a success status.
if (sub_cmd_obj->WantsRawCommandString())
{
m_interpreter.OutputFormattedHelpText (output_strm, "", "", "\nIMPORTANT NOTE: Because this command takes 'raw' input, if you use any command options you must use ' -- ' between the end of the command options and the beginning of the raw input.", 1);
}
//.........这里部分代码省略.........
示例8: new_args
void
CommandInterpreter::BuildAliasCommandArgs
(
CommandObject *alias_cmd_obj,
const char *alias_name,
Args &cmd_args,
CommandReturnObject &result
)
{
OptionArgVectorSP option_arg_vector_sp = GetAliasOptions (alias_name);
if (option_arg_vector_sp.get())
{
// Make sure that the alias name is the 0th element in cmd_args
std::string alias_name_str = alias_name;
if (alias_name_str.compare (cmd_args.GetArgumentAtIndex(0)) != 0)
cmd_args.Unshift (alias_name);
Args new_args (alias_cmd_obj->GetCommandName());
if (new_args.GetArgumentCount() == 2)
new_args.Shift();
OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
int old_size = cmd_args.GetArgumentCount();
int *used = (int *) malloc ((old_size + 1) * sizeof (int));
memset (used, 0, (old_size + 1) * sizeof (int));
used[0] = 1;
for (int i = 0; i < option_arg_vector->size(); ++i)
{
OptionArgPair option_pair = (*option_arg_vector)[i];
std::string option = option_pair.first;
std::string value = option_pair.second;
if (option.compare ("<argument>") == 0)
new_args.AppendArgument (value.c_str());
else
{
new_args.AppendArgument (option.c_str());
if (value.compare ("<no-argument>") != 0)
{
int index = GetOptionArgumentPosition (value.c_str());
if (index == 0)
// value was NOT a positional argument; must be a real value
new_args.AppendArgument (value.c_str());
else if (index >= cmd_args.GetArgumentCount())
{
result.AppendErrorWithFormat
("Not enough arguments provided; you need at least %d arguments to use this alias.\n",
index);
result.SetStatus (eReturnStatusFailed);
return;
}
else
{
new_args.AppendArgument (cmd_args.GetArgumentAtIndex (index));
used[index] = 1;
}
}
}
}
for (int j = 0; j < cmd_args.GetArgumentCount(); ++j)
{
if (!used[j])
new_args.AppendArgument (cmd_args.GetArgumentAtIndex (j));
}
cmd_args.Clear();
cmd_args.SetArguments (new_args.GetArgumentCount(), (const char **) new_args.GetArgumentVector());
}
else
{
result.SetStatus (eReturnStatusSuccessFinishNoResult);
// This alias was not created with any options; nothing further needs to be done.
return;
}
result.SetStatus (eReturnStatusSuccessFinishNoResult);
return;
}
示例9: if
virtual bool
DoExecute (Args& command, CommandReturnObject &result)
{
Stream &strm = result.GetOutputStream();
RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext ();
const RegisterInfo *reg_info = NULL;
if (command.GetArgumentCount() == 0)
{
size_t set_idx;
size_t num_register_sets = 1;
const size_t set_array_size = m_command_options.set_indexes.GetSize();
if (set_array_size > 0)
{
for (size_t i=0; i<set_array_size; ++i)
{
set_idx = m_command_options.set_indexes[i]->GetUInt64Value (UINT32_MAX, NULL);
if (set_idx < reg_ctx->GetRegisterSetCount())
{
if (!DumpRegisterSet (m_exe_ctx, strm, reg_ctx, set_idx))
{
if (errno)
result.AppendErrorWithFormat ("register read failed: %s\n", strerror(errno));
else
result.AppendError ("unknown error while reading registers.\n");
result.SetStatus (eReturnStatusFailed);
break;
}
}
else
{
result.AppendErrorWithFormat ("invalid register set index: %zu\n", set_idx);
result.SetStatus (eReturnStatusFailed);
break;
}
}
}
else
{
if (m_command_options.dump_all_sets)
num_register_sets = reg_ctx->GetRegisterSetCount();
for (set_idx = 0; set_idx < num_register_sets; ++set_idx)
{
// When dump_all_sets option is set, dump primitive as well as derived registers.
DumpRegisterSet (m_exe_ctx, strm, reg_ctx, set_idx, !m_command_options.dump_all_sets.GetCurrentValue());
}
}
}
else
{
if (m_command_options.dump_all_sets)
{
result.AppendError ("the --all option can't be used when registers names are supplied as arguments\n");
result.SetStatus (eReturnStatusFailed);
}
else if (m_command_options.set_indexes.GetSize() > 0)
{
result.AppendError ("the --set <set> option can't be used when registers names are supplied as arguments\n");
result.SetStatus (eReturnStatusFailed);
}
else
{
const char *arg_cstr;
for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
{
// in most LLDB commands we accept $rbx as the name for register RBX - and here we would
// reject it and non-existant. we should be more consistent towards the user and allow them
// to say reg read $rbx - internally, however, we should be strict and not allow ourselves
// to call our registers $rbx in our own API
if (*arg_cstr == '$')
arg_cstr = arg_cstr+1;
reg_info = reg_ctx->GetRegisterInfoByName(arg_cstr);
if (reg_info)
{
if (!DumpRegister (m_exe_ctx, strm, reg_ctx, reg_info))
strm.Printf("%-12s = error: unavailable\n", reg_info->name);
}
else
{
result.AppendErrorWithFormat ("Invalid register name '%s'.\n", arg_cstr);
}
}
}
}
return result.Succeeded();
}
示例10: error
virtual bool
DoExecute(Args& command, CommandReturnObject &result)
{
DataExtractor reg_data;
RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext ();
if (command.GetArgumentCount() != 2)
{
result.AppendError ("register write takes exactly 2 arguments: <reg-name> <value>");
result.SetStatus (eReturnStatusFailed);
}
else
{
const char *reg_name = command.GetArgumentAtIndex(0);
const char *value_str = command.GetArgumentAtIndex(1);
// in most LLDB commands we accept $rbx as the name for register RBX - and here we would
// reject it and non-existant. we should be more consistent towards the user and allow them
// to say reg write $rbx - internally, however, we should be strict and not allow ourselves
// to call our registers $rbx in our own API
if (reg_name && *reg_name == '$')
reg_name = reg_name+1;
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(reg_name);
if (reg_info)
{
RegisterValue reg_value;
Error error (reg_value.SetValueFromCString (reg_info, value_str));
if (error.Success())
{
if (reg_ctx->WriteRegister (reg_info, reg_value))
{
// Toss all frames and anything else in the thread
// after a register has been written.
m_exe_ctx.GetThreadRef().Flush();
result.SetStatus (eReturnStatusSuccessFinishNoResult);
return true;
}
}
if (error.AsCString())
{
result.AppendErrorWithFormat ("Failed to write register '%s' with value '%s': %s\n",
reg_name,
value_str,
error.AsCString());
}
else
{
result.AppendErrorWithFormat ("Failed to write register '%s' with value '%s'",
reg_name,
value_str);
}
result.SetStatus (eReturnStatusFailed);
}
else
{
result.AppendErrorWithFormat ("Register not found for '%s'.\n", reg_name);
result.SetStatus (eReturnStatusFailed);
}
}
return result.Succeeded();
}
示例11: DoExecute
virtual bool
DoExecute (Args& command, CommandReturnObject &result)
{
Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
if (target == NULL)
{
result.AppendError ("Invalid target. No current target or watchpoints.");
result.SetStatus (eReturnStatusSuccessFinishNoResult);
return true;
}
if (target->GetProcessSP() && target->GetProcessSP()->IsAlive())
{
uint32_t num_supported_hardware_watchpoints;
Error error = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
if (error.Success())
result.AppendMessageWithFormat("Number of supported hardware watchpoints: %u\n",
num_supported_hardware_watchpoints);
}
const WatchpointList &watchpoints = target->GetWatchpointList();
Mutex::Locker locker;
target->GetWatchpointList().GetListMutex(locker);
size_t num_watchpoints = watchpoints.GetSize();
if (num_watchpoints == 0)
{
result.AppendMessage("No watchpoints currently set.");
result.SetStatus(eReturnStatusSuccessFinishNoResult);
return true;
}
Stream &output_stream = result.GetOutputStream();
if (command.GetArgumentCount() == 0)
{
// No watchpoint selected; show info about all currently set watchpoints.
result.AppendMessage ("Current watchpoints:");
for (size_t i = 0; i < num_watchpoints; ++i)
{
Watchpoint *wp = watchpoints.GetByIndex(i).get();
AddWatchpointDescription(&output_stream, wp, m_options.m_level);
}
result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
else
{
// Particular watchpoints selected; enable them.
std::vector<uint32_t> wp_ids;
if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, wp_ids))
{
result.AppendError("Invalid watchpoints specification.");
result.SetStatus(eReturnStatusFailed);
return false;
}
const size_t size = wp_ids.size();
for (size_t i = 0; i < size; ++i)
{
Watchpoint *wp = watchpoints.FindByID(wp_ids[i]).get();
if (wp)
AddWatchpointDescription(&output_stream, wp, m_options.m_level);
result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
}
return result.Succeeded();
}
示例12: exe_ctx
virtual bool
DoExecute (Args& command, CommandReturnObject &result)
{
ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
StackFrame *frame = exe_ctx.GetFramePtr();
if (frame == NULL)
{
result.AppendError ("you must be stopped in a valid stack frame to view frame variables.");
result.SetStatus (eReturnStatusFailed);
return false;
}
Stream &s = result.GetOutputStream();
bool get_file_globals = true;
// Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList
// for the thread. So hold onto a shared pointer to the frame so it stays alive.
VariableList *variable_list = frame->GetVariableList (get_file_globals);
VariableSP var_sp;
ValueObjectSP valobj_sp;
const char *name_cstr = NULL;
size_t idx;
TypeSummaryImplSP summary_format_sp;
if (!m_option_variable.summary.IsCurrentValueEmpty())
DataVisualization::NamedSummaryFormats::GetSummaryFormat(ConstString(m_option_variable.summary.GetCurrentValue()), summary_format_sp);
else if (!m_option_variable.summary_string.IsCurrentValueEmpty())
summary_format_sp.reset(new StringSummaryFormat(TypeSummaryImpl::Flags(),m_option_variable.summary_string.GetCurrentValue()));
ValueObject::DumpValueObjectOptions options;
options.SetMaximumPointerDepth(m_varobj_options.ptr_depth)
.SetMaximumDepth(m_varobj_options.max_depth)
.SetShowTypes(m_varobj_options.show_types)
.SetShowLocation(m_varobj_options.show_location)
.SetUseObjectiveC(m_varobj_options.use_objc)
.SetUseDynamicType(m_varobj_options.use_dynamic)
.SetUseSyntheticValue(m_varobj_options.use_synth)
.SetFlatOutput(m_varobj_options.flat_output)
.SetOmitSummaryDepth(m_varobj_options.no_summary_depth)
.SetIgnoreCap(m_varobj_options.ignore_cap)
.SetSummary(summary_format_sp);
if (m_varobj_options.be_raw)
options.SetRawDisplay(true);
if (variable_list)
{
const Format format = m_option_format.GetFormat();
options.SetFormat(format);
if (command.GetArgumentCount() > 0)
{
VariableList regex_var_list;
// If we have any args to the variable command, we will make
// variable objects from them...
for (idx = 0; (name_cstr = command.GetArgumentAtIndex(idx)) != NULL; ++idx)
{
if (m_option_variable.use_regex)
{
const uint32_t regex_start_index = regex_var_list.GetSize();
RegularExpression regex (name_cstr);
if (regex.Compile(name_cstr))
{
size_t num_matches = 0;
const size_t num_new_regex_vars = variable_list->AppendVariablesIfUnique(regex,
regex_var_list,
num_matches);
if (num_new_regex_vars > 0)
{
for (uint32_t regex_idx = regex_start_index, end_index = regex_var_list.GetSize();
regex_idx < end_index;
++regex_idx)
{
var_sp = regex_var_list.GetVariableAtIndex (regex_idx);
if (var_sp)
{
valobj_sp = frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
if (valobj_sp)
{
// if (format != eFormatDefault)
// valobj_sp->SetFormat (format);
if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
{
bool show_fullpaths = false;
bool show_module = true;
if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
s.PutCString (": ");
}
ValueObject::DumpValueObject (result.GetOutputStream(),
valobj_sp.get(),
options);
}
}
//.........这里部分代码省略.........
示例13: if
bool
CommandObjectHelp::DoExecute (Args& command, CommandReturnObject &result)
{
CommandObject::CommandMap::iterator pos;
CommandObject *cmd_obj;
const size_t argc = command.GetArgumentCount ();
// 'help' doesn't take any arguments, other than command names. If argc is 0, we show the user
// all commands (aliases and user commands if asked for). Otherwise every argument must be the name of a command or a sub-command.
if (argc == 0)
{
uint32_t cmd_types = CommandInterpreter::eCommandTypesBuiltin;
if (m_options.m_show_aliases)
cmd_types |= CommandInterpreter::eCommandTypesAliases;
if (m_options.m_show_user_defined)
cmd_types |= CommandInterpreter::eCommandTypesUserDef;
if (m_options.m_show_hidden)
cmd_types |= CommandInterpreter::eCommandTypesHidden;
result.SetStatus (eReturnStatusSuccessFinishNoResult);
m_interpreter.GetHelp (result, cmd_types); // General help
}
else
{
// Get command object for the first command argument. Only search built-in command dictionary.
StringList matches;
cmd_obj = m_interpreter.GetCommandObject (command.GetArgumentAtIndex (0), &matches);
bool is_alias_command = m_interpreter.AliasExists (command.GetArgumentAtIndex (0));
std::string alias_name = command.GetArgumentAtIndex(0);
if (cmd_obj != nullptr)
{
StringList matches;
bool all_okay = true;
CommandObject *sub_cmd_obj = cmd_obj;
// Loop down through sub_command dictionaries until we find the command object that corresponds
// to the help command entered.
std::string sub_command;
for (size_t i = 1; i < argc && all_okay; ++i)
{
sub_command = command.GetArgumentAtIndex(i);
matches.Clear();
if (sub_cmd_obj->IsAlias())
sub_cmd_obj = ((CommandAlias*)sub_cmd_obj)->GetUnderlyingCommand().get();
if (! sub_cmd_obj->IsMultiwordObject ())
{
all_okay = false;
}
else
{
CommandObject *found_cmd;
found_cmd = sub_cmd_obj->GetSubcommandObject(sub_command.c_str(), &matches);
if (found_cmd == nullptr)
all_okay = false;
else if (matches.GetSize() > 1)
all_okay = false;
else
sub_cmd_obj = found_cmd;
}
}
if (!all_okay || (sub_cmd_obj == nullptr))
{
std::string cmd_string;
command.GetCommandString (cmd_string);
if (matches.GetSize() >= 2)
{
StreamString s;
s.Printf ("ambiguous command %s", cmd_string.c_str());
size_t num_matches = matches.GetSize();
for (size_t match_idx = 0; match_idx < num_matches; match_idx++)
{
s.Printf ("\n\t%s", matches.GetStringAtIndex(match_idx));
}
s.Printf ("\n");
result.AppendError(s.GetData());
result.SetStatus (eReturnStatusFailed);
return false;
}
else if (!sub_cmd_obj)
{
StreamString error_msg_stream;
GenerateAdditionalHelpAvenuesMessage(&error_msg_stream,
cmd_string.c_str(),
m_interpreter.GetCommandPrefix(),
sub_command.c_str());
result.AppendErrorWithFormat("%s",error_msg_stream.GetData());
result.SetStatus (eReturnStatusFailed);
return false;
}
else
{
GenerateAdditionalHelpAvenuesMessage(&result.GetOutputStream(),
cmd_string.c_str(),
m_interpreter.GetCommandPrefix(),
sub_command.c_str());
result.GetOutputStream().Printf("\nThe closest match is '%s'. Help on it follows.\n\n", sub_cmd_obj->GetCommandName());
}
}
//.........这里部分代码省略.........
示例14: command_args
bool
CommandInterpreter::HandleCommand
(
const char *command_line,
bool add_to_history,
CommandReturnObject &result,
ExecutionContext *override_context
)
{
// FIXME: there should probably be a mutex to make sure only one thread can
// run the interpreter at a time.
// TODO: this should be a logging channel in lldb.
// if (DebugSelf())
// {
// result.AppendMessageWithFormat ("Processing command: %s\n", command_line);
// }
m_debugger.UpdateExecutionContext (override_context);
if (command_line == NULL || command_line[0] == '\0')
{
if (m_command_history.empty())
{
result.AppendError ("empty command");
result.SetStatus(eReturnStatusFailed);
return false;
}
else
{
command_line = m_repeat_command.c_str();
if (m_repeat_command.empty())
{
result.AppendErrorWithFormat("No auto repeat.\n");
result.SetStatus (eReturnStatusFailed);
return false;
}
}
add_to_history = false;
}
Args command_args(command_line);
if (command_args.GetArgumentCount() > 0)
{
const char *command_cstr = command_args.GetArgumentAtIndex(0);
if (command_cstr)
{
// We're looking up the command object here. So first find an exact match to the
// command in the commands.
CommandObject *command_obj = GetCommandObject(command_cstr);
if (command_obj != NULL)
{
if (command_obj->IsAlias())
{
BuildAliasCommandArgs (command_obj, command_cstr, command_args, result);
if (!result.Succeeded())
return false;
}
if (add_to_history)
{
const char *repeat_command = command_obj->GetRepeatCommand(command_args, 0);
if (repeat_command != NULL)
m_repeat_command.assign(repeat_command);
else
m_repeat_command.assign(command_line);
m_command_history.push_back (command_line);
}
if (command_obj->WantsRawCommandString())
{
const char *stripped_command = ::strstr (command_line, command_cstr);
if (stripped_command)
{
stripped_command += strlen(command_cstr);
while (isspace(*stripped_command))
++stripped_command;
command_obj->ExecuteRawCommandString (*this, stripped_command, result);
}
}
else
{
// Remove the command from the args.
command_args.Shift();
command_obj->ExecuteWithOptions (*this, command_args, result);
}
}
else
{
// We didn't find the first command object, so complete the first argument.
StringList matches;
int num_matches;
int cursor_index = 0;
int cursor_char_position = strlen (command_args.GetArgumentAtIndex(0));
bool word_complete;
//.........这里部分代码省略.........
示例15: arch
bool
CommandObjectDisassemble::Execute
(
CommandInterpreter &interpreter,
Args& command,
CommandReturnObject &result
)
{
Target *target = interpreter.GetDebugger().GetCurrentTarget().get();
if (target == NULL)
{
result.AppendError ("invalid target, set executable file using 'file' command");
result.SetStatus (eReturnStatusFailed);
return false;
}
ArchSpec arch(target->GetArchitecture());
if (!arch.IsValid())
{
result.AppendError ("target needs valid architecure in order to be able to disassemble");
result.SetStatus (eReturnStatusFailed);
return false;
}
Disassembler *disassembler = Disassembler::FindPlugin(arch);
if (disassembler == NULL)
{
result.AppendErrorWithFormat ("Unable to find Disassembler plug-in for %s architecture.\n", arch.AsCString());
result.SetStatus (eReturnStatusFailed);
return false;
}
result.SetStatus (eReturnStatusSuccessFinishResult);
if (command.GetArgumentCount() != 0)
{
result.AppendErrorWithFormat ("\"disassemble\" doesn't take any arguments.\n");
result.SetStatus (eReturnStatusFailed);
return false;
}
ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext());
if (m_options.show_mixed && m_options.num_lines_context == 0)
m_options.num_lines_context = 3;
if (!m_options.m_func_name.empty())
{
ConstString name(m_options.m_func_name.c_str());
if (Disassembler::Disassemble (interpreter.GetDebugger(),
arch,
exe_ctx,
name,
NULL, // Module *
m_options.show_mixed ? m_options.num_lines_context : 0,
m_options.show_bytes,
result.GetOutputStream()))
{
result.SetStatus (eReturnStatusSuccessFinishResult);
}
else
{
result.AppendErrorWithFormat ("Unable to find symbol with name '%s'.\n", name.GetCString());
result.SetStatus (eReturnStatusFailed);
}
}
else
{
AddressRange range;
if (m_options.m_start_addr != LLDB_INVALID_ADDRESS)
{
range.GetBaseAddress().SetOffset (m_options.m_start_addr);
if (m_options.m_end_addr != LLDB_INVALID_ADDRESS)
{
if (m_options.m_end_addr < m_options.m_start_addr)
{
result.AppendErrorWithFormat ("End address before start address.\n");
result.SetStatus (eReturnStatusFailed);
return false;
}
range.SetByteSize (m_options.m_end_addr - m_options.m_start_addr);
}
else
range.SetByteSize (DEFAULT_DISASM_BYTE_SIZE);
}
else
{
if (exe_ctx.frame)
{
SymbolContext sc(exe_ctx.frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol));
if (sc.function)
range = sc.function->GetAddressRange();
else if (sc.symbol && sc.symbol->GetAddressRangePtr())
range = *sc.symbol->GetAddressRangePtr();
else
range.GetBaseAddress() = exe_ctx.frame->GetPC();
}
else
{
//.........这里部分代码省略.........