本文整理汇总了C++中Error::Fail方法的典型用法代码示例。如果您正苦于以下问题:C++ Error::Fail方法的具体用法?C++ Error::Fail怎么用?C++ Error::Fail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Error
的用法示例。
在下文中一共展示了Error::Fail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resolved_module_spec
//.........这里部分代码省略.........
}
if (!resolved_module_spec.GetFileSpec().Exists())
resolved_module_spec.GetFileSpec().ResolveExecutableLocation ();
if (resolved_module_spec.GetFileSpec().Exists())
error.Clear();
else
{
error.SetErrorStringWithFormat("unable to find executable for '%s'", resolved_module_spec.GetFileSpec().GetPath().c_str());
}
}
else
{
if (m_remote_platform_sp)
{
error = GetCachedExecutable (resolved_module_spec, exe_module_sp, module_search_paths_ptr, *m_remote_platform_sp);
}
else
{
// We may connect to a process and use the provided executable (Don't use local $PATH).
// Resolve any executable within a bundle on MacOSX
Host::ResolveExecutableInBundle (resolved_module_spec.GetFileSpec());
if (resolved_module_spec.GetFileSpec().Exists())
{
error.Clear();
}
else
{
error.SetErrorStringWithFormat("the platform is not currently connected, and '%s' doesn't exist in the system root.", resolved_module_spec.GetFileSpec().GetPath().c_str());
}
}
}
if (error.Success())
{
if (resolved_module_spec.GetArchitecture().IsValid())
{
error = ModuleList::GetSharedModule (resolved_module_spec,
exe_module_sp,
module_search_paths_ptr,
NULL,
NULL);
if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL)
{
exe_module_sp.reset();
error.SetErrorStringWithFormat ("'%s' doesn't contain the architecture %s",
resolved_module_spec.GetFileSpec().GetPath().c_str(),
resolved_module_spec.GetArchitecture().GetArchitectureName());
}
}
else
{
// No valid architecture was specified, ask the platform for
// the architectures that we should be using (in the correct order)
// and see if we can find a match that way
StreamString arch_names;
for (uint32_t idx = 0; GetSupportedArchitectureAtIndex (idx, resolved_module_spec.GetArchitecture()); ++idx)
{
error = ModuleList::GetSharedModule (resolved_module_spec,
exe_module_sp,
module_search_paths_ptr,
NULL,
NULL);
// Did we find an executable using one of the
if (error.Success())
{
if (exe_module_sp && exe_module_sp->GetObjectFile())
break;
else
error.SetErrorToGenericError();
}
if (idx > 0)
arch_names.PutCString (", ");
arch_names.PutCString (resolved_module_spec.GetArchitecture().GetArchitectureName());
}
if (error.Fail() || !exe_module_sp)
{
if (resolved_module_spec.GetFileSpec().Readable())
{
error.SetErrorStringWithFormat ("'%s' doesn't contain any '%s' platform architectures: %s",
resolved_module_spec.GetFileSpec().GetPath().c_str(),
GetPluginName().GetCString(),
arch_names.GetString().c_str());
}
else
{
error.SetErrorStringWithFormat("'%s' is not readable", resolved_module_spec.GetFileSpec().GetPath().c_str());
}
}
}
}
return error;
}
示例2: Error
Error
SoftwareBreakpoint::EnableSoftwareBreakpoint (NativeProcessProtocol &process, lldb::addr_t addr, size_t bp_opcode_size, const uint8_t *bp_opcode_bytes, uint8_t *saved_opcode_bytes)
{
assert (bp_opcode_size <= MAX_TRAP_OPCODE_SIZE && "bp_opcode_size out of valid range");
assert (bp_opcode_bytes && "bp_opcode_bytes is NULL");
assert (saved_opcode_bytes && "saved_opcode_bytes is NULL");
Log *log (GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
if (log)
log->Printf ("SoftwareBreakpoint::%s addr = 0x%" PRIx64, __FUNCTION__, addr);
// Save the original opcodes by reading them so we can restore later.
size_t bytes_read = 0;
Error error = process.ReadMemory(addr, saved_opcode_bytes, bp_opcode_size, bytes_read);
if (error.Fail ())
{
if (log)
log->Printf ("SoftwareBreakpoint::%s failed to read memory while attempting to set breakpoint: %s", __FUNCTION__, error.AsCString ());
return error;
}
// Ensure we read as many bytes as we expected.
if (bytes_read != bp_opcode_size)
{
if (log)
log->Printf ("SoftwareBreakpoint::%s failed to read memory while attempting to set breakpoint: attempted to read %lu bytes but only read %" PRIu64, __FUNCTION__, bp_opcode_size, (uint64_t)bytes_read);
return Error ("SoftwareBreakpoint::%s failed to read memory while attempting to set breakpoint: attempted to read %lu bytes but only read %" PRIu64, __FUNCTION__, bp_opcode_size, (uint64_t)bytes_read);
}
// Log what we read.
if (log)
{
int i = 0;
for (const uint8_t *read_byte = saved_opcode_bytes; read_byte < saved_opcode_bytes + bp_opcode_size; ++read_byte)
{
log->Printf("SoftwareBreakpoint::%s addr = 0x%" PRIx64
" ovewriting byte index %d (was 0x%hhx)",
__FUNCTION__, addr, i++, *read_byte);
}
}
// Write a software breakpoint in place of the original opcode.
size_t bytes_written = 0;
error = process.WriteMemory(addr, bp_opcode_bytes, bp_opcode_size, bytes_written);
if (error.Fail ())
{
if (log)
log->Printf ("SoftwareBreakpoint::%s failed to write memory while attempting to set breakpoint: %s", __FUNCTION__, error.AsCString ());
return error;
}
// Ensure we wrote as many bytes as we expected.
if (bytes_written != bp_opcode_size)
{
error.SetErrorStringWithFormat("SoftwareBreakpoint::%s failed write memory while attempting to set breakpoint: attempted to write %lu bytes but only wrote %" PRIu64, __FUNCTION__, bp_opcode_size, (uint64_t)bytes_written);
if (log)
log->PutCString (error.AsCString ());
return error;
}
uint8_t verify_bp_opcode_bytes [MAX_TRAP_OPCODE_SIZE];
size_t verify_bytes_read = 0;
error = process.ReadMemory(addr, verify_bp_opcode_bytes, bp_opcode_size, verify_bytes_read);
if (error.Fail ())
{
if (log)
log->Printf ("SoftwareBreakpoint::%s failed to read memory while attempting to verify the breakpoint set: %s", __FUNCTION__, error.AsCString ());
return error;
}
// Ensure we read as many verification bytes as we expected.
if (verify_bytes_read != bp_opcode_size)
{
if (log)
log->Printf ("SoftwareBreakpoint::%s failed to read memory while attempting to verify breakpoint: attempted to read %lu bytes but only read %" PRIu64, __FUNCTION__, bp_opcode_size, (uint64_t)verify_bytes_read);
return Error ("SoftwareBreakpoint::%s failed to read memory while attempting to verify breakpoint: attempted to read %lu bytes but only read %" PRIu64, __FUNCTION__, bp_opcode_size, (uint64_t)verify_bytes_read);
}
if (::memcmp(bp_opcode_bytes, verify_bp_opcode_bytes, bp_opcode_size) != 0)
{
if (log)
log->Printf ("SoftwareBreakpoint::%s: verification of software breakpoint writing failed - trap opcodes not successfully read back after writing when setting breakpoint at 0x%" PRIx64, __FUNCTION__, addr);
return Error ("SoftwareBreakpoint::%s: verification of software breakpoint writing failed - trap opcodes not successfully read back after writing when setting breakpoint at 0x%" PRIx64, __FUNCTION__, addr);
}
if (log)
log->Printf ("SoftwareBreakpoint::%s addr = 0x%" PRIx64 " -- SUCCESS", __FUNCTION__, addr);
return Error ();
}
示例3: printf
bool
ABISysV_hexagon::PrepareTrivialCall ( Thread &thread,
lldb::addr_t sp ,
lldb::addr_t pc ,
lldb::addr_t ra ,
llvm::Type &prototype,
llvm::ArrayRef<ABI::CallArgument> args) const
{
// default number of register passed arguments for varg functions
const int nVArgRegParams = 1;
Error error;
// grab the process so we have access to the memory for spilling
lldb::ProcessSP proc = thread.GetProcess( );
// push host data onto target
for ( size_t i = 0; i < args.size( ); i++ )
{
const ABI::CallArgument &arg = args[i];
// skip over target values
if ( arg.type == ABI::CallArgument::TargetValue )
continue;
// round up to 8 byte multiple
size_t argSize = ( arg.size | 0x7 ) + 1;
// create space on the stack for this data
sp -= argSize;
// write this argument onto the stack of the host process
proc.get( )->WriteMemory( sp, arg.data, arg.size, error );
if ( error.Fail( ) )
return false;
// update the argument with the target pointer
//XXX: This is a gross hack for getting around the const
*((size_t*)(&arg.value)) = sp;
}
#if HEX_ABI_DEBUG
// print the original stack pointer
printf( "sp : %04lx \n", sp );
#endif
// make sure number of parameters matches prototype
assert( prototype.getFunctionNumParams( ) == args.size( ) );
// check if this is a variable argument function
bool isVArg = prototype.isFunctionVarArg();
// get the register context for modifying all of the registers
RegisterContext *reg_ctx = thread.GetRegisterContext().get();
if (!reg_ctx)
return false;
// number of arguments passed by register
int nRegArgs = nVArgRegParams;
if (! isVArg )
{
// number of arguments is limited by [R0 : R5] space
nRegArgs = args.size( );
if ( nRegArgs > 6 )
nRegArgs = 6;
}
// pass arguments that are passed via registers
for ( int i = 0; i < nRegArgs; i++ )
{
// get the parameter as a u32
uint32_t param = (uint32_t)args[i].value;
// write argument into register
if (!reg_ctx->WriteRegisterFromUnsigned( i, param ))
return false;
}
// number of arguments to spill onto stack
int nSpillArgs = args.size( ) - nRegArgs;
// make space on the stack for arguments
sp -= 4 * nSpillArgs;
// align stack on an 8 byte boundary
if ( sp & 7 )
sp -= 4;
// arguments that are passed on the stack
for ( size_t i = nRegArgs, offs=0; i < args.size( ); i++ )
{
// get the parameter as a u32
uint32_t param = (uint32_t)args[i].value;
// write argument to stack
proc->WriteMemory( sp + offs, (void*)¶m, sizeof( param ), error );
if ( !error.Success( ) )
return false;
//
offs += 4;
}
// update registers with current function call state
reg_ctx->WriteRegisterFromUnsigned ( 41, pc );
reg_ctx->WriteRegisterFromUnsigned ( 31, ra );
reg_ctx->WriteRegisterFromUnsigned ( 29, sp );
//.........这里部分代码省略.........
示例4: locker
//.........这里部分代码省略.........
// Fixup the incoming path in case the path points to a valid file, yet
// the arch or UUID (if one was passed in) don't match.
ModuleSpec located_binary_modulespec = Symbols::LocateExecutableObjectFile (module_spec);
// Don't look for the file if it appears to be the same one we already
// checked for above...
if (located_binary_modulespec.GetFileSpec() != module_file_spec)
{
if (!located_binary_modulespec.GetFileSpec().Exists())
{
located_binary_modulespec.GetFileSpec().GetPath(path, sizeof(path));
if (path[0] == '\0')
module_file_spec.GetPath(path, sizeof(path));
// How can this check ever be true? This branch it is false, and we haven't modified file_spec.
if (located_binary_modulespec.GetFileSpec().Exists())
{
std::string uuid_str;
if (uuid_ptr && uuid_ptr->IsValid())
uuid_str = uuid_ptr->GetAsString();
if (arch.IsValid())
{
if (!uuid_str.empty())
error.SetErrorStringWithFormat("'%s' does not contain the %s architecture and UUID %s", path, arch.GetArchitectureName(), uuid_str.c_str());
else
error.SetErrorStringWithFormat("'%s' does not contain the %s architecture.", path, arch.GetArchitectureName());
}
}
else
{
error.SetErrorStringWithFormat("'%s' does not exist", path);
}
if (error.Fail())
module_sp.reset();
return error;
}
// Make sure no one else can try and get or create a module while this
// function is actively working on it by doing an extra lock on the
// global mutex list.
ModuleSpec platform_module_spec(module_spec);
platform_module_spec.GetFileSpec() = located_binary_modulespec.GetFileSpec();
platform_module_spec.GetPlatformFileSpec() = located_binary_modulespec.GetFileSpec();
platform_module_spec.GetSymbolFileSpec() = located_binary_modulespec.GetSymbolFileSpec();
ModuleList matching_module_list;
if (shared_module_list.FindModules (platform_module_spec, matching_module_list) > 0)
{
module_sp = matching_module_list.GetModuleAtIndex(0);
// If we didn't have a UUID in mind when looking for the object file,
// then we should make sure the modification time hasn't changed!
if (platform_module_spec.GetUUIDPtr() == nullptr)
{
TimeValue file_spec_mod_time(located_binary_modulespec.GetFileSpec().GetModificationTime());
if (file_spec_mod_time.IsValid())
{
if (file_spec_mod_time != module_sp->GetModificationTime())
{
if (old_module_sp_ptr)
*old_module_sp_ptr = module_sp;
shared_module_list.Remove (module_sp);
module_sp.reset();
}
}
}
示例5: assert
Error
SoftwareBreakpoint::DoDisable ()
{
Error error;
assert (m_addr && (m_addr != LLDB_INVALID_ADDRESS) && "can't remove a software breakpoint for an invalid address");
Log *log (GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
if (log)
log->Printf ("SoftwareBreakpoint::%s addr = 0x%" PRIx64, __FUNCTION__, m_addr);
assert ( (m_opcode_size > 0) && "cannot restore opcodes when there are no opcodes");
if (m_opcode_size > 0)
{
// Clear a software breakpoint instruction
uint8_t curr_break_op [MAX_TRAP_OPCODE_SIZE];
bool break_op_found = false;
assert (m_opcode_size <= sizeof (curr_break_op));
// Read the breakpoint opcode
size_t bytes_read = 0;
error = m_process.ReadMemory (m_addr, curr_break_op, m_opcode_size, bytes_read);
if (error.Success() && bytes_read < m_opcode_size)
{
error.SetErrorStringWithFormat ("SoftwareBreakpointr::%s addr=0x%" PRIx64 ": tried to read %lu bytes but only read %" PRIu64, __FUNCTION__, m_addr, m_opcode_size, (uint64_t)bytes_read);
}
if (error.Success ())
{
bool verify = false;
// Make sure the breakpoint opcode exists at this address
if (::memcmp (curr_break_op, m_trap_opcodes, m_opcode_size) == 0)
{
break_op_found = true;
// We found a valid breakpoint opcode at this address, now restore
// the saved opcode.
size_t bytes_written = 0;
error = m_process.WriteMemory (m_addr, m_saved_opcodes, m_opcode_size, bytes_written);
if (error.Success() && bytes_written < m_opcode_size)
{
error.SetErrorStringWithFormat ("SoftwareBreakpoint::%s addr=0x%" PRIx64 ": tried to write %lu bytes but only wrote %" PRIu64, __FUNCTION__, m_addr, m_opcode_size, (uint64_t)bytes_written);
}
if (error.Success ())
{
verify = true;
}
}
else
{
error.SetErrorString("Original breakpoint trap is no longer in memory.");
// Set verify to true and so we can check if the original opcode has already been restored
verify = true;
}
if (verify)
{
uint8_t verify_opcode [MAX_TRAP_OPCODE_SIZE];
assert (m_opcode_size <= sizeof (verify_opcode));
// Verify that our original opcode made it back to the inferior
size_t verify_bytes_read = 0;
error = m_process.ReadMemory (m_addr, verify_opcode, m_opcode_size, verify_bytes_read);
if (error.Success() && verify_bytes_read < m_opcode_size)
{
error.SetErrorStringWithFormat ("SoftwareBreakpoint::%s addr=0x%" PRIx64 ": tried to read %lu verification bytes but only read %" PRIu64, __FUNCTION__, m_addr, m_opcode_size, (uint64_t)verify_bytes_read);
}
if (error.Success ())
{
// compare the memory we just read with the original opcode
if (::memcmp (m_saved_opcodes, verify_opcode, m_opcode_size) == 0)
{
// SUCCESS
if (log)
{
int i = 0;
for (const uint8_t *verify_byte = verify_opcode; verify_byte < verify_opcode + m_opcode_size; ++verify_byte)
{
log->Printf("SoftwareBreakpoint::%s addr = 0x%" PRIx64
" replaced byte index %d with 0x%hhx",
__FUNCTION__, m_addr, i++, *verify_byte);
}
log->Printf ("SoftwareBreakpoint::%s addr = 0x%" PRIx64 " -- SUCCESS", __FUNCTION__, m_addr);
}
return error;
}
else
{
if (break_op_found)
error.SetErrorString("Failed to restore original opcode.");
}
}
else
error.SetErrorString("Failed to read memory to verify that breakpoint trap was restored.");
}
}
}
if (log && error.Fail ())
log->Printf ("SoftwareBreakpoint::%s addr = 0x%" PRIx64 " -- FAILED: %s",
__FUNCTION__,
m_addr,
//.........这里部分代码省略.........
示例6: fprintf
void
ConnectToRemote(GDBRemoteCommunicationServerLLGS &gdb_server,
bool reverse_connect, const char *const host_and_port,
const char *const progname, const char *const subcommand,
const char *const named_pipe_path, int unnamed_pipe_fd)
{
Error error;
if (host_and_port && host_and_port[0])
{
// Parse out host and port.
std::string final_host_and_port;
std::string connection_host;
std::string connection_port;
uint32_t connection_portno = 0;
// If host_and_port starts with ':', default the host to be "localhost" and expect the remainder to be the port.
if (host_and_port[0] == ':')
final_host_and_port.append ("localhost");
final_host_and_port.append (host_and_port);
const std::string::size_type colon_pos = final_host_and_port.find (':');
if (colon_pos != std::string::npos)
{
connection_host = final_host_and_port.substr (0, colon_pos);
connection_port = final_host_and_port.substr (colon_pos + 1);
connection_portno = StringConvert::ToUInt32 (connection_port.c_str (), 0);
}
else
{
fprintf (stderr, "failed to parse host and port from connection string '%s'\n", final_host_and_port.c_str ());
display_usage (progname, subcommand);
exit (1);
}
if (reverse_connect)
{
// llgs will connect to the gdb-remote client.
// Ensure we have a port number for the connection.
if (connection_portno == 0)
{
fprintf (stderr, "error: port number must be specified on when using reverse connect");
exit (1);
}
// Build the connection string.
char connection_url[512];
snprintf(connection_url, sizeof(connection_url), "connect://%s", final_host_and_port.c_str ());
// Create the connection.
std::unique_ptr<ConnectionFileDescriptor> connection_up (new ConnectionFileDescriptor ());
connection_up.reset (new ConnectionFileDescriptor ());
auto connection_result = connection_up->Connect (connection_url, &error);
if (connection_result != eConnectionStatusSuccess)
{
fprintf (stderr, "error: failed to connect to client at '%s' (connection status: %d)", connection_url, static_cast<int> (connection_result));
exit (-1);
}
if (error.Fail ())
{
fprintf (stderr, "error: failed to connect to client at '%s': %s", connection_url, error.AsCString ());
exit (-1);
}
// We're connected.
printf ("Connection established.\n");
gdb_server.SetConnection (connection_up.release());
}
else
{
// llgs will listen for connections on the given port from the given address.
// Start the listener on a new thread. We need to do this so we can resolve the
// bound listener port.
StartListenThread(connection_host.c_str (), static_cast<uint16_t> (connection_portno));
printf ("Listening to port %s for a connection from %s...\n", connection_port.c_str (), connection_host.c_str ());
// If we have a named pipe to write the port number back to, do that now.
if (named_pipe_path && named_pipe_path[0] && connection_portno == 0)
{
const uint16_t bound_port = s_listen_connection_up->GetListeningPort (10);
if (bound_port > 0)
{
error = writePortToPipe (named_pipe_path, bound_port);
if (error.Fail ())
{
fprintf (stderr, "failed to write to the named pipe \'%s\': %s", named_pipe_path, error.AsCString());
}
}
else
{
fprintf (stderr, "unable to get the bound port for the listening connection\n");
}
}
// If we have an unnamed pipe to write the port number back to, do that now.
if (unnamed_pipe_fd >= 0 && connection_portno == 0)
{
const uint16_t bound_port = s_listen_connection_up->GetListeningPort(10);
if (bound_port > 0)
//.........这里部分代码省略.........
示例7: value_sp
Error
OptionValueArray::SetArgs (const Args &args, VarSetOperationType op)
{
Error error;
const size_t argc = args.GetArgumentCount();
switch (op)
{
case eVarSetOperationInvalid:
error.SetErrorString("unsupported operation");
break;
case eVarSetOperationInsertBefore:
case eVarSetOperationInsertAfter:
if (argc > 1)
{
uint32_t idx = StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
const uint32_t count = GetSize();
if (idx > count)
{
error.SetErrorStringWithFormat("invalid insert array index %u, index must be 0 through %u", idx, count);
}
else
{
if (op == eVarSetOperationInsertAfter)
++idx;
for (size_t i=1; i<argc; ++i, ++idx)
{
lldb::OptionValueSP value_sp (CreateValueFromCStringForTypeMask (args.GetArgumentAtIndex(i),
m_type_mask,
error));
if (value_sp)
{
if (error.Fail())
return error;
if (idx >= m_values.size())
m_values.push_back(value_sp);
else
m_values.insert(m_values.begin() + idx, value_sp);
}
else
{
error.SetErrorString("array of complex types must subclass OptionValueArray");
return error;
}
}
}
}
else
{
error.SetErrorString("insert operation takes an array index followed by one or more values");
}
break;
case eVarSetOperationRemove:
if (argc > 0)
{
const uint32_t size = m_values.size();
std::vector<int> remove_indexes;
bool all_indexes_valid = true;
size_t i;
for (i=0; i<argc; ++i)
{
const size_t idx =
StringConvert::ToSInt32(args.GetArgumentAtIndex(i), INT32_MAX);
if (idx >= size)
{
all_indexes_valid = false;
break;
}
else
remove_indexes.push_back(idx);
}
if (all_indexes_valid)
{
size_t num_remove_indexes = remove_indexes.size();
if (num_remove_indexes)
{
// Sort and then erase in reverse so indexes are always valid
if (num_remove_indexes > 1)
{
std::sort(remove_indexes.begin(), remove_indexes.end());
for (std::vector<int>::const_reverse_iterator pos = remove_indexes.rbegin(), end = remove_indexes.rend(); pos != end; ++pos)
{
m_values.erase(m_values.begin() + *pos);
}
}
else
{
// Only one index
m_values.erase(m_values.begin() + remove_indexes.front());
}
}
}
else
{
error.SetErrorStringWithFormat("invalid array index '%s', aborting remove operation", args.GetArgumentAtIndex(i));
}
}
else
//.........这里部分代码省略.........
示例8: descriptor
bool
lldb_private::formatters::NSIndexSetSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
{
ProcessSP process_sp = valobj.GetProcessSP();
if (!process_sp)
return false;
ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
if (!runtime)
return false;
ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj));
if (!descriptor.get() || !descriptor->IsValid())
return false;
uint32_t ptr_size = process_sp->GetAddressByteSize();
lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
if (!valobj_addr)
return false;
const char* class_name = descriptor->GetClassName().GetCString();
if (!class_name || !*class_name)
return false;
uint64_t count = 0;
do {
if (!strcmp(class_name,"NSIndexSet") || !strcmp(class_name,"NSMutableIndexSet"))
{
Error error;
uint32_t mode = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr+ptr_size, 4, 0, error);
if (error.Fail())
return false;
// this means the set is empty - count = 0
if ((mode & 1) == 1)
{
count = 0;
break;
}
if ((mode & 2) == 2)
mode = 1; // this means the set only has one range
else
mode = 2; // this means the set has multiple ranges
if (mode == 1)
{
count = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr+3*ptr_size, ptr_size, 0, error);
if (error.Fail())
return false;
}
else
{
// read a pointer to the data at 2*ptr_size
count = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr+2*ptr_size, ptr_size, 0, error);
if (error.Fail())
return false;
// read the data at 2*ptr_size from the first location
count = process_sp->ReadUnsignedIntegerFromMemory(count+2*ptr_size, ptr_size, 0, error);
if (error.Fail())
return false;
}
}
else
{
if (!ExtractValueFromObjCExpression(valobj, "unsigned long long int", "count", count))
return false;
}
} while (false);
stream.Printf("%" PRIu64 " index%s",
count,
(count == 1 ? "" : "es"));
return true;
}
示例9: switch
size_t
ConnectionFileDescriptor::Write (const void *src, size_t src_len, ConnectionStatus &status, Error *error_ptr)
{
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION));
if (log)
log->Printf ("%p ConnectionFileDescriptor::Write (src = %p, src_len = %" PRIu64 ")",
static_cast<void*>(this), static_cast<const void*>(src),
static_cast<uint64_t>(src_len));
if (!IsConnected ())
{
if (error_ptr)
error_ptr->SetErrorString("not connected");
status = eConnectionStatusNoConnection;
return 0;
}
Error error;
size_t bytes_sent = src_len;
error = m_write_sp->Write(src, bytes_sent);
if (log)
{
log->Printf ("%p ConnectionFileDescriptor::Write(fd = %" PRIu64 ", src = %p, src_len = %" PRIu64 ") => %" PRIu64 " (error = %s)",
static_cast<void*>(this),
static_cast<uint64_t>(m_write_sp->GetWaitableHandle()),
static_cast<const void*>(src),
static_cast<uint64_t>(src_len),
static_cast<uint64_t>(bytes_sent),
error.AsCString());
}
if (error_ptr)
*error_ptr = error;
if (error.Fail())
{
switch (error.GetError())
{
case EAGAIN:
case EINTR:
status = eConnectionStatusSuccess;
return 0;
case ECONNRESET:// The connection is closed by the peer during a read attempt on a socket.
case ENOTCONN: // A read is attempted on an unconnected socket.
status = eConnectionStatusLostConnection;
break; // Break to close....
default:
status = eConnectionStatusError;
break; // Break to close....
}
return 0;
}
status = eConnectionStatusSuccess;
return bytes_sent;
}
示例10: if
//.........这里部分代码省略.........
if (have_pipe_fd)
FD_SET (pipe_fd, FD_SET_DATA(read_fds));
Error error;
if (log)
{
if (have_pipe_fd)
log->Printf("%p ConnectionFileDescriptor::BytesAvailable() ::select (nfds=%i, fds={%i, %i}, NULL, NULL, timeout=%p)...",
static_cast<void*>(this), nfds, handle, pipe_fd,
static_cast<void*>(tv_ptr));
else
log->Printf("%p ConnectionFileDescriptor::BytesAvailable() ::select (nfds=%i, fds={%i}, NULL, NULL, timeout=%p)...",
static_cast<void*>(this), nfds, handle,
static_cast<void*>(tv_ptr));
}
const int num_set_fds = ::select (nfds, FD_SET_DATA(read_fds), NULL, NULL, tv_ptr);
if (num_set_fds < 0)
error.SetErrorToErrno();
else
error.Clear();
if (log)
{
if (have_pipe_fd)
log->Printf("%p ConnectionFileDescriptor::BytesAvailable() ::select (nfds=%i, fds={%i, %i}, NULL, NULL, timeout=%p) => %d, error = %s",
static_cast<void*>(this), nfds, handle,
pipe_fd, static_cast<void*>(tv_ptr), num_set_fds,
error.AsCString());
else
log->Printf("%p ConnectionFileDescriptor::BytesAvailable() ::select (nfds=%i, fds={%i}, NULL, NULL, timeout=%p) => %d, error = %s",
static_cast<void*>(this), nfds, handle,
static_cast<void*>(tv_ptr), num_set_fds,
error.AsCString());
}
if (error_ptr)
*error_ptr = error;
if (error.Fail())
{
switch (error.GetError())
{
case EBADF: // One of the descriptor sets specified an invalid descriptor.
return eConnectionStatusLostConnection;
case EINVAL: // The specified time limit is invalid. One of its components is negative or too large.
default: // Other unknown error
return eConnectionStatusError;
case EAGAIN: // The kernel was (perhaps temporarily) unable to
// allocate the requested number of file descriptors,
// or we have non-blocking IO
case EINTR: // A signal was delivered before the time limit
// expired and before any of the selected events
// occurred.
break; // Lets keep reading to until we timeout
}
}
else if (num_set_fds == 0)
{
return eConnectionStatusTimedOut;
}
else if (num_set_fds > 0)
{
if (FD_ISSET(handle, FD_SET_DATA(read_fds)))
return eConnectionStatusSuccess;
if (have_pipe_fd && FD_ISSET(pipe_fd, FD_SET_DATA(read_fds)))
{
// We got a command to exit. Read the data from that pipe:
char buffer[16];
ssize_t bytes_read;
do
{
bytes_read = ::read (pipe_fd, buffer, sizeof(buffer));
} while (bytes_read < 0 && errno == EINTR);
switch (buffer[0])
{
case 'q':
if (log)
log->Printf("%p ConnectionFileDescriptor::BytesAvailable() got data: %*s from the command channel.",
static_cast<void*>(this),
static_cast<int>(bytes_read), buffer);
return eConnectionStatusEndOfFile;
case 'i':
// Interrupt the current read
return eConnectionStatusInterrupted;
}
}
}
}
}
if (error_ptr)
error_ptr->SetErrorString("not connected");
return eConnectionStatusLostConnection;
}
示例11: getenv
//.........这里部分代码省略.........
if (launch_info.GetLaunchInSeparateProcessGroup())
{
debugserver_args.AppendArgument("--setsid");
}
llvm::SmallString<PATH_MAX> named_pipe_path;
Pipe port_pipe;
bool listen = false;
if (host_and_port[0])
{
// Create a temporary file to get the stdout/stderr and redirect the
// output of the command into this file. We will later read this file
// if all goes well and fill the data into "command_output_ptr"
if (in_port == 0)
{
// Binding to port zero, we need to figure out what port it ends up
// using using a named pipe...
error = port_pipe.CreateWithUniqueName("debugserver-named-pipe", false, named_pipe_path);
if (error.Success())
{
debugserver_args.AppendArgument("--named-pipe");
debugserver_args.AppendArgument(named_pipe_path.c_str());
}
else
{
if (log)
log->Printf("GDBRemoteCommunication::%s() "
"named pipe creation failed: %s",
__FUNCTION__, error.AsCString());
// let's try an unnamed pipe
error = port_pipe.CreateNew(true);
if (error.Fail())
{
if (log)
log->Printf("GDBRemoteCommunication::%s() "
"unnamed pipe creation failed: %s",
__FUNCTION__, error.AsCString());
return error;
}
int write_fd = port_pipe.GetWriteFileDescriptor();
debugserver_args.AppendArgument("--pipe");
debugserver_args.AppendArgument(std::to_string(write_fd).c_str());
launch_info.AppendCloseFileAction(port_pipe.GetReadFileDescriptor());
}
}
else
{
listen = true;
}
}
else
{
// No host and port given, so lets listen on our end and make the debugserver
// connect to us..
error = StartListenThread ("127.0.0.1", 0);
if (error.Fail())
return error;
ConnectionFileDescriptor *connection = (ConnectionFileDescriptor *)GetConnection ();
// Wait for 10 seconds to resolve the bound port
out_port = connection->GetListeningPort(10);
if (out_port > 0)
{
char port_cstr[32];
示例12: descriptor
bool
lldb_private::formatters::NSArraySummaryProvider (ValueObject& valobj, Stream& stream)
{
ProcessSP process_sp = valobj.GetProcessSP();
if (!process_sp)
return false;
ObjCLanguageRuntime* runtime = (ObjCLanguageRuntime*)process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC);
if (!runtime)
return false;
ObjCLanguageRuntime::ClassDescriptorSP descriptor(runtime->GetClassDescriptor(valobj));
if (!descriptor.get() || !descriptor->IsValid())
return false;
uint32_t ptr_size = process_sp->GetAddressByteSize();
lldb::addr_t valobj_addr = valobj.GetValueAsUnsigned(0);
if (!valobj_addr)
return false;
uint64_t value = 0;
const char* class_name = descriptor->GetClassName().GetCString();
if (!class_name || !*class_name)
return false;
if (!strcmp(class_name,"__NSArrayI"))
{
Error error;
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
if (error.Fail())
return false;
}
else if (!strcmp(class_name,"__NSArrayM"))
{
Error error;
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + ptr_size, ptr_size, 0, error);
if (error.Fail())
return false;
}
else if (!strcmp(class_name,"__NSCFArray"))
{
Error error;
value = process_sp->ReadUnsignedIntegerFromMemory(valobj_addr + 2 * ptr_size, ptr_size, 0, error);
if (error.Fail())
return false;
}
else
{
if (!ExtractValueFromObjCExpression(valobj, "int", "count", value))
return false;
}
stream.Printf("@\"%" PRIu64 " object%s\"",
value,
value == 1 ? "" : "s");
return true;
}
示例13: dst_dir_path
static FileSpec::EnumerateDirectoryResult
RecurseCopy_Callback (void *baton,
FileSpec::FileType file_type,
const FileSpec &src)
{
RecurseCopyBaton* rc_baton = (RecurseCopyBaton*)baton;
switch (file_type)
{
case FileSpec::eFileTypePipe:
case FileSpec::eFileTypeSocket:
// we have no way to copy pipes and sockets - ignore them and continue
return FileSpec::eEnumerateDirectoryResultNext;
break;
case FileSpec::eFileTypeDirectory:
{
// make the new directory and get in there
FileSpec dst_dir = rc_baton->dst;
if (!dst_dir.GetFilename())
dst_dir.GetFilename() = src.GetLastPathComponent();
std::string dst_dir_path (dst_dir.GetPath());
Error error = rc_baton->platform_ptr->MakeDirectory(dst_dir_path.c_str(), lldb::eFilePermissionsDirectoryDefault);
if (error.Fail())
{
rc_baton->error.SetErrorStringWithFormat("unable to setup directory %s on remote end", dst_dir_path.c_str());
return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
}
// now recurse
std::string src_dir_path (src.GetPath());
// Make a filespec that only fills in the directory of a FileSpec so
// when we enumerate we can quickly fill in the filename for dst copies
FileSpec recurse_dst;
recurse_dst.GetDirectory().SetCString(dst_dir.GetPath().c_str());
RecurseCopyBaton rc_baton2 = { recurse_dst, rc_baton->platform_ptr, Error() };
FileSpec::EnumerateDirectory(src_dir_path.c_str(), true, true, true, RecurseCopy_Callback, &rc_baton2);
if (rc_baton2.error.Fail())
{
rc_baton->error.SetErrorString(rc_baton2.error.AsCString());
return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
}
return FileSpec::eEnumerateDirectoryResultNext;
}
break;
case FileSpec::eFileTypeSymbolicLink:
{
// copy the file and keep going
FileSpec dst_file = rc_baton->dst;
if (!dst_file.GetFilename())
dst_file.GetFilename() = src.GetFilename();
char buf[PATH_MAX];
rc_baton->error = Host::Readlink (src.GetPath().c_str(), buf, sizeof(buf));
if (rc_baton->error.Fail())
return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
rc_baton->error = rc_baton->platform_ptr->CreateSymlink(dst_file.GetPath().c_str(), buf);
if (rc_baton->error.Fail())
return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
return FileSpec::eEnumerateDirectoryResultNext;
}
break;
case FileSpec::eFileTypeRegular:
{
// copy the file and keep going
FileSpec dst_file = rc_baton->dst;
if (!dst_file.GetFilename())
dst_file.GetFilename() = src.GetFilename();
Error err = rc_baton->platform_ptr->PutFile(src, dst_file);
if (err.Fail())
{
rc_baton->error.SetErrorString(err.AsCString());
return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
}
return FileSpec::eEnumerateDirectoryResultNext;
}
break;
case FileSpec::eFileTypeInvalid:
case FileSpec::eFileTypeOther:
case FileSpec::eFileTypeUnknown:
rc_baton->error.SetErrorStringWithFormat("invalid file detected during copy: %s", src.GetPath().c_str());
return FileSpec::eEnumerateDirectoryResultQuit; // got an error, bail out
break;
}
}
示例14: Error
Error
PlatformAndroid::DownloadSymbolFile (const lldb::ModuleSP& module_sp,
const FileSpec& dst_file_spec)
{
// For oat file we can try to fetch additional debug info from the device
if (module_sp->GetFileSpec().GetFileNameExtension() != ConstString("oat"))
return Error("Symbol file downloading only supported for oat files");
// If we have no information about the platform file we can't execute oatdump
if (!module_sp->GetPlatformFileSpec())
return Error("No platform file specified");
// Symbolizer isn't available before SDK version 23
if (GetSdkVersion() < 23)
return Error("Symbol file generation only supported on SDK 23+");
// If we already have symtab then we don't have to try and generate one
if (module_sp->GetSectionList()->FindSectionByName(ConstString(".symtab")) != nullptr)
return Error("Symtab already available in the module");
int status = 0;
std::string tmpdir;
StreamString command;
command.Printf("mktemp --directory --tmpdir %s", GetWorkingDirectory().GetCString());
Error error = RunShellCommand(command.GetData(),
GetWorkingDirectory(),
&status,
nullptr,
&tmpdir,
5 /* timeout (s) */);
if (error.Fail() || status != 0 || tmpdir.empty())
return Error("Failed to generate temporary directory on the device (%s)", error.AsCString());
tmpdir.erase(tmpdir.size() - 1); // Remove trailing new line
// Create file remover for the temporary directory created on the device
std::unique_ptr<std::string, std::function<void(std::string*)>> tmpdir_remover(
&tmpdir,
[this](std::string* s) {
StreamString command;
command.Printf("rm -rf %s", s->c_str());
Error error = this->RunShellCommand(command.GetData(),
GetWorkingDirectory(),
nullptr,
nullptr,
nullptr,
5 /* timeout (s) */);
Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
if (error.Fail())
log->Printf("Failed to remove temp directory: %s", error.AsCString());
}
);
FileSpec symfile_platform_filespec(tmpdir.c_str(), false);
symfile_platform_filespec.AppendPathComponent("symbolized.oat");
// Execute oatdump on the remote device to generate a file with symtab
command.Clear();
command.Printf("oatdump --symbolize=%s --output=%s",
module_sp->GetPlatformFileSpec().GetCString(false),
symfile_platform_filespec.GetCString(false));
error = RunShellCommand(command.GetData(),
GetWorkingDirectory(),
&status,
nullptr,
nullptr,
60 /* timeout (s) */);
if (error.Fail() || status != 0)
return Error("Oatdump failed: %s", error.AsCString());
// Download the symbolfile from the remote device
return GetFile(symfile_platform_filespec, dst_file_spec);
}
示例15: if
//.........这里部分代码省略.........
}
}
}
else
{
// Can't convert a file address to anything valid without more
// context (which Module it came from)
error.SetErrorString ("can't read memory from file address without more context");
}
}
}
break;
case eValueTypeHostAddress:
address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
address_type = eAddressTypeHost;
if (exe_ctx)
{
Target *target = exe_ctx->GetTargetPtr();
if (target)
{
data.SetByteOrder(target->GetArchitecture().GetByteOrder());
data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize());
break;
}
}
// fallback to host settings
data.SetByteOrder(lldb::endian::InlHostByteOrder());
data.SetAddressByteSize(sizeof(void *));
break;
}
// Bail if we encountered any errors
if (error.Fail())
return error;
if (address == LLDB_INVALID_ADDRESS)
{
error.SetErrorStringWithFormat ("invalid %s address", address_type == eAddressTypeHost ? "host" : "load");
return error;
}
// If we got here, we need to read the value from memory
uint32_t byte_size = GetValueByteSize (ast_context, &error);
// Bail if we encountered any errors getting the byte size
if (error.Fail())
return error;
// Make sure we have enough room within "data", and if we don't make
// something large enough that does
if (!data.ValidOffsetForDataOfSize (data_offset, byte_size))
{
DataBufferSP data_sp(new DataBufferHeap (data_offset + byte_size, '\0'));
data.SetData(data_sp);
}
uint8_t* dst = const_cast<uint8_t*>(data.PeekData (data_offset, byte_size));
if (dst != NULL)
{
if (address_type == eAddressTypeHost)
{
// The address is an address in this process, so just copy it
memcpy (dst, (uint8_t*)NULL + address, byte_size);
}
else if ((address_type == eAddressTypeLoad) || (address_type == eAddressTypeFile))