本文整理汇总了C++中Error::Success方法的典型用法代码示例。如果您正苦于以下问题:C++ Error::Success方法的具体用法?C++ Error::Success怎么用?C++ Error::Success使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Error
的用法示例。
在下文中一共展示了Error::Success方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadMemory
void IRMemoryMap::ReadMemory(uint8_t *bytes, lldb::addr_t process_address,
size_t size, Error &error) {
error.Clear();
AllocationMap::iterator iter = FindAllocation(process_address, size);
if (iter == m_allocations.end()) {
lldb::ProcessSP process_sp = m_process_wp.lock();
if (process_sp) {
process_sp->ReadMemory(process_address, bytes, size, error);
return;
}
lldb::TargetSP target_sp = m_target_wp.lock();
if (target_sp) {
Address absolute_address(process_address);
target_sp->ReadMemory(absolute_address, false, bytes, size, error);
return;
}
error.SetErrorToGenericError();
error.SetErrorString("Couldn't read: no allocation contains the target "
"range, and neither the process nor the target exist");
return;
}
Allocation &allocation = iter->second;
uint64_t offset = process_address - allocation.m_process_start;
if (offset > allocation.m_size) {
error.SetErrorToGenericError();
error.SetErrorString("Couldn't read: data is not in the allocation");
return;
}
lldb::ProcessSP process_sp;
switch (allocation.m_policy) {
default:
error.SetErrorToGenericError();
error.SetErrorString("Couldn't read: invalid allocation policy");
return;
case eAllocationPolicyHostOnly:
if (!allocation.m_data.GetByteSize()) {
error.SetErrorToGenericError();
error.SetErrorString("Couldn't read: data buffer is empty");
return;
}
if (allocation.m_data.GetByteSize() < offset + size) {
error.SetErrorToGenericError();
error.SetErrorString("Couldn't read: not enough underlying data");
return;
}
::memcpy(bytes, allocation.m_data.GetBytes() + offset, size);
break;
case eAllocationPolicyMirror:
process_sp = m_process_wp.lock();
if (process_sp) {
process_sp->ReadMemory(process_address, bytes, size, error);
if (!error.Success())
return;
} else {
if (!allocation.m_data.GetByteSize()) {
error.SetErrorToGenericError();
error.SetErrorString("Couldn't read: data buffer is empty");
return;
}
::memcpy(bytes, allocation.m_data.GetBytes() + offset, size);
}
break;
case eAllocationPolicyProcessOnly:
process_sp = m_process_wp.lock();
if (process_sp) {
process_sp->ReadMemory(process_address, bytes, size, error);
if (!error.Success())
return;
}
break;
}
if (lldb_private::Log *log =
lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) {
log->Printf("IRMemoryMap::ReadMemory (0x%" PRIx64 ", 0x%" PRIx64
", 0x%" PRId64 ") came from [0x%" PRIx64 "..0x%" PRIx64 ")",
(uint64_t)process_address, (uint64_t)bytes, (uint64_t)size,
(uint64_t)allocation.m_process_start,
(uint64_t)allocation.m_process_start +
(uint64_t)allocation.m_size);
}
}
示例2: getenv
//.........这里部分代码省略.........
if (hostname)
{
snprintf (host_and_port, sizeof(host_and_port), "%s:%u", hostname, in_port);
debugserver_args.AppendArgument(host_and_port);
}
else
{
host_and_port[0] = '\0';
}
// use native registers, not the GDB registers
debugserver_args.AppendArgument("--native-regs");
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
示例3: resolved_exe_file
Error
PlatformLinux::ResolveExecutable (const FileSpec &exe_file,
const ArchSpec &exe_arch,
lldb::ModuleSP &exe_module_sp,
const FileSpecList *module_search_paths_ptr)
{
Error error;
// Nothing special to do here, just use the actual file and architecture
char exe_path[PATH_MAX];
FileSpec resolved_exe_file (exe_file);
if (IsHost())
{
// If we have "ls" as the exe_file, resolve the executable location based on
// the current path variables
if (!resolved_exe_file.Exists())
{
exe_file.GetPath(exe_path, sizeof(exe_path));
resolved_exe_file.SetFile(exe_path, true);
}
if (!resolved_exe_file.Exists())
resolved_exe_file.ResolveExecutableLocation ();
if (resolved_exe_file.Exists())
error.Clear();
else
{
exe_file.GetPath(exe_path, sizeof(exe_path));
error.SetErrorStringWithFormat("unable to find executable for '%s'", exe_path);
}
}
else
{
if (m_remote_platform_sp)
{
error = m_remote_platform_sp->ResolveExecutable (exe_file,
exe_arch,
exe_module_sp,
NULL);
}
else
{
// We may connect to a process and use the provided executable (Don't use local $PATH).
if (resolved_exe_file.Exists())
error.Clear();
else
error.SetErrorStringWithFormat("the platform is not currently connected, and '%s' doesn't exist in the system root.", exe_path);
}
}
if (error.Success())
{
ModuleSpec module_spec (resolved_exe_file, exe_arch);
if (exe_arch.IsValid())
{
error = ModuleList::GetSharedModule (module_spec,
exe_module_sp,
NULL,
NULL,
NULL);
if (error.Fail())
{
// If we failed, it may be because the vendor and os aren't known. If that is the
// case, try setting them to the host architecture and give it another try.
llvm::Triple &module_triple = module_spec.GetArchitecture().GetTriple();
bool is_vendor_specified = (module_triple.getVendor() != llvm::Triple::UnknownVendor);
bool is_os_specified = (module_triple.getOS() != llvm::Triple::UnknownOS);
if (!is_vendor_specified || !is_os_specified)
{
const llvm::Triple &host_triple = Host::GetArchitecture (Host::eSystemDefaultArchitecture).GetTriple();
if (!is_vendor_specified)
module_triple.setVendorName (host_triple.getVendorName());
if (!is_os_specified)
module_triple.setOSName (host_triple.getOSName());
error = ModuleList::GetSharedModule (module_spec,
exe_module_sp,
NULL,
NULL,
NULL);
}
}
// TODO find out why exe_module_sp might be NULL
if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL)
{
exe_module_sp.reset();
error.SetErrorStringWithFormat ("'%s' doesn't contain the architecture %s",
exe_file.GetPath().c_str(),
exe_arch.GetArchitectureName());
}
}
else
{
// No valid architecture was specified, ask the platform for
// the architectures that we should be using (in the correct order)
//.........这里部分代码省略.........
示例4: Listener
lldb::ProcessSP
PlatformPOSIX::Attach (ProcessAttachInfo &attach_info,
Debugger &debugger,
Target *target,
Error &error)
{
lldb::ProcessSP process_sp;
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM));
if (IsHost())
{
if (target == NULL)
{
TargetSP new_target_sp;
error = debugger.GetTargetList().CreateTarget (debugger,
NULL,
NULL,
false,
NULL,
new_target_sp);
target = new_target_sp.get();
if (log)
log->Printf ("PlatformPOSIX::%s created new target", __FUNCTION__);
}
else
{
error.Clear();
if (log)
log->Printf ("PlatformPOSIX::%s target already existed, setting target", __FUNCTION__);
}
if (target && error.Success())
{
debugger.GetTargetList().SetSelectedTarget(target);
if (log)
{
ModuleSP exe_module_sp = target->GetExecutableModule ();
log->Printf("PlatformPOSIX::%s set selected target to %p %s", __FUNCTION__, (void *)target,
exe_module_sp ? exe_module_sp->GetFileSpec().GetPath().c_str() : "<null>");
}
process_sp = target->CreateProcess (attach_info.GetListenerForProcess(debugger), attach_info.GetProcessPluginName(), NULL);
if (process_sp)
{
// Set UnixSignals appropriately.
process_sp->SetUnixSignals (Host::GetUnixSignals ());
auto listener_sp = attach_info.GetHijackListener();
if (listener_sp == nullptr)
{
listener_sp.reset(new Listener("lldb.PlatformPOSIX.attach.hijack"));
attach_info.SetHijackListener(listener_sp);
}
process_sp->HijackProcessEvents(listener_sp.get());
error = process_sp->Attach (attach_info);
}
}
}
else
{
if (m_remote_platform_sp)
process_sp = m_remote_platform_sp->Attach (attach_info, debugger, target, error);
else
error.SetErrorString ("the platform is not currently connected");
}
return process_sp;
}
示例5: process_sp
//.........这里部分代码省略.........
.setCodeModel(codeModel)
.setOptLevel(llvm::CodeGenOpt::Less);
llvm::StringRef mArch;
llvm::StringRef mCPU;
llvm::SmallVector<std::string, 0> mAttrs;
for (std::string &feature : m_cpu_features)
mAttrs.push_back(feature);
llvm::TargetMachine *target_machine = builder.selectTarget(triple,
mArch,
mCPU,
mAttrs);
m_execution_engine_ap.reset(builder.create(target_machine));
if (!m_execution_engine_ap.get())
{
error.SetErrorToGenericError();
error.SetErrorStringWithFormat("Couldn't JIT the function: %s", error_string.c_str());
return;
}
// Make sure we see all sections, including ones that don't have relocations...
m_execution_engine_ap->setProcessAllSections(true);
m_execution_engine_ap->DisableLazyCompilation();
// We don't actually need the function pointer here, this just forces it to get resolved.
void *fun_ptr = m_execution_engine_ap->getPointerToFunction(function);
if (!error.Success())
{
// We got an error through our callback!
return;
}
if (!function)
{
error.SetErrorToGenericError();
error.SetErrorStringWithFormat("Couldn't find '%s' in the JITted module", m_name.AsCString());
return;
}
if (!fun_ptr)
{
error.SetErrorToGenericError();
error.SetErrorStringWithFormat("'%s' was in the JITted module but wasn't lowered", m_name.AsCString());
return;
}
m_jitted_functions.push_back (JittedFunction(m_name.AsCString(), (lldb::addr_t)fun_ptr));
CommitAllocations(process_sp);
ReportAllocations(*m_execution_engine_ap);
WriteData(process_sp);
if (m_failed_lookups.size())
{
StreamString ss;
ss.PutCString("Couldn't lookup symbols:\n");
bool emitNewLine = false;
示例6: 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_ap.get(), 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
*const_cast<lldb::addr_t*>(&arg.value) = sp;
}
#if HEX_ABI_DEBUG
// print the original stack pointer
printf( "sp : %04" PRIx64 " \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 );
// reg_ctx->WriteRegisterFromUnsigned ( FP ??? );
//.........这里部分代码省略.........
示例7: if
bool
ClangUserExpression::Parse (Stream &error_stream,
ExecutionContext &exe_ctx,
lldb_private::ExecutionPolicy execution_policy,
bool keep_result_in_memory)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Error err;
InstallContext(exe_ctx);
ScanContext(exe_ctx, err);
if (!err.Success())
{
error_stream.Printf("warning: %s\n", err.AsCString());
}
StreamString m_transformed_stream;
////////////////////////////////////
// Generate the expression
//
ApplyObjcCastHack(m_expr_text);
//ApplyUnicharHack(m_expr_text);
std::unique_ptr<ExpressionSourceCode> source_code (ExpressionSourceCode::CreateWrapped(m_expr_prefix.c_str(), m_expr_text.c_str()));
lldb::LanguageType lang_type;
if (m_cplusplus)
lang_type = lldb::eLanguageTypeC_plus_plus;
else if(m_objectivec)
lang_type = lldb::eLanguageTypeObjC;
else
lang_type = lldb::eLanguageTypeC;
if (!source_code->GetText(m_transformed_text, lang_type, m_const_object, m_static_method))
{
error_stream.PutCString ("error: couldn't construct expression body");
return false;
}
if (log)
log->Printf("Parsing the following code:\n%s", m_transformed_text.c_str());
////////////////////////////////////
// Set up the target and compiler
//
Target *target = exe_ctx.GetTargetPtr();
if (!target)
{
error_stream.PutCString ("error: invalid target\n");
return false;
}
//////////////////////////
// Parse the expression
//
m_materializer_ap.reset(new Materializer());
m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory, exe_ctx));
class OnExit
{
public:
typedef std::function <void (void)> Callback;
OnExit (Callback const &callback) :
m_callback(callback)
{
}
~OnExit ()
{
m_callback();
}
private:
Callback m_callback;
};
OnExit on_exit([this]() { m_expr_decl_map.reset(); });
if (!m_expr_decl_map->WillParse(exe_ctx, m_materializer_ap.get()))
{
error_stream.PutCString ("error: current process state is unsuitable for expression parsing\n");
m_expr_decl_map.reset(); // We are being careful here in the case of breakpoint conditions.
return false;
}
Process *process = exe_ctx.GetProcessPtr();
ExecutionContextScope *exe_scope = process;
//.........这里部分代码省略.........
示例8: assert
lldb_private::Error
NativeRegisterContextLinux_mips64::ReadRegister (const RegisterInfo *reg_info, RegisterValue ®_value)
{
Error error;
if (!reg_info)
{
error.SetErrorString ("reg_info NULL");
return error;
}
const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
if (reg == LLDB_INVALID_REGNUM)
{
// This is likely an internal register for lldb use only and should not be directly queried.
error.SetErrorStringWithFormat ("register \"%s\" is an internal-only lldb register, cannot read directly", reg_info->name);
return error;
}
if (IsMSA(reg) && !IsMSAAvailable())
{
error.SetErrorString ("MSA not available on this processor");
return error;
}
if (IsMSA(reg) || IsFPR(reg))
{
uint8_t *src;
error = ReadCP1();
if (!error.Success())
{
error.SetErrorString ("failed to read co-processor 1 register");
return error;
}
if (IsFPR(reg))
{
assert (reg_info->byte_offset < sizeof(UserArea));
src = (uint8_t *)&m_fpr + reg_info->byte_offset - (sizeof(m_gpr));
}
else
{
assert (reg_info->byte_offset < sizeof(UserArea));
src = (uint8_t *)&m_msa + reg_info->byte_offset - (sizeof(m_gpr) + sizeof(m_fpr));
}
switch (reg_info->byte_size)
{
case 4:
reg_value.SetUInt32(*(uint32_t *)src);
break;
case 8:
reg_value.SetUInt64(*(uint64_t *)src);
break;
case 16:
reg_value.SetBytes((const void *)src, 16, GetByteOrder());
break;
default:
assert(false && "Unhandled data size.");
error.SetErrorStringWithFormat ("unhandled byte size: %" PRIu32, reg_info->byte_size);
break;
}
}
else
{
error = ReadRegisterRaw(reg, reg_value);
}
return error;
}
示例9: Error
lldb_private::Error
NativeRegisterContextLinux_mips64::WriteRegister (const RegisterInfo *reg_info, const RegisterValue ®_value)
{
Error error;
assert (reg_info && "reg_info is null");
const uint32_t reg_index = reg_info->kinds[lldb::eRegisterKindLLDB];
if (reg_index == LLDB_INVALID_REGNUM)
return Error ("no lldb regnum for %s", reg_info && reg_info->name ? reg_info->name : "<unknown register>");
if (IsMSA(reg_index) && !IsMSAAvailable())
{
error.SetErrorString ("MSA not available on this processor");
return error;
}
if (IsFPR(reg_index) || IsMSA(reg_index))
{
uint8_t *dst;
uint64_t *src;
// Initialise the FP and MSA buffers by reading all co-processor 1 registers
ReadCP1();
if (IsFPR(reg_index))
{
assert (reg_info->byte_offset < sizeof(UserArea));
dst = (uint8_t *)&m_fpr + reg_info->byte_offset - (sizeof(m_gpr));
}
else
{
assert (reg_info->byte_offset < sizeof(UserArea));
dst = (uint8_t *)&m_msa + reg_info->byte_offset - (sizeof(m_gpr) + sizeof(m_fpr));
}
switch (reg_info->byte_size)
{
case 4:
*(uint32_t *)dst = reg_value.GetAsUInt32();
break;
case 8:
*(uint64_t *)dst = reg_value.GetAsUInt64();
break;
case 16:
src = (uint64_t *)reg_value.GetBytes();
*(uint64_t *)dst = *src;
*(uint64_t *)(dst + 8) = *(src + 1);
break;
default:
assert(false && "Unhandled data size.");
error.SetErrorStringWithFormat ("unhandled byte size: %" PRIu32, reg_info->byte_size);
break;
}
error = WriteCP1();
if (!error.Success())
{
error.SetErrorString ("failed to write co-processor 1 register");
return error;
}
}
else
{
error = WriteRegisterRaw(reg_index, reg_value);
}
return error;
}
示例10: if
bool
Host::AddPosixSpawnFileAction(void *_file_actions, const FileAction *info, Log *log, Error &error)
{
if (info == NULL)
return false;
posix_spawn_file_actions_t *file_actions = reinterpret_cast<posix_spawn_file_actions_t *>(_file_actions);
switch (info->GetAction())
{
case FileAction::eFileActionNone:
error.Clear();
break;
case FileAction::eFileActionClose:
if (info->GetFD() == -1)
error.SetErrorString("invalid fd for posix_spawn_file_actions_addclose(...)");
else
{
error.SetError(::posix_spawn_file_actions_addclose(file_actions, info->GetFD()), eErrorTypePOSIX);
if (log && (error.Fail() || log))
error.PutToLog(log, "posix_spawn_file_actions_addclose (action=%p, fd=%i)",
static_cast<void *>(file_actions), info->GetFD());
}
break;
case FileAction::eFileActionDuplicate:
if (info->GetFD() == -1)
error.SetErrorString("invalid fd for posix_spawn_file_actions_adddup2(...)");
else if (info->GetActionArgument() == -1)
error.SetErrorString("invalid duplicate fd for posix_spawn_file_actions_adddup2(...)");
else
{
error.SetError(
::posix_spawn_file_actions_adddup2(file_actions, info->GetFD(), info->GetActionArgument()),
eErrorTypePOSIX);
if (log && (error.Fail() || log))
error.PutToLog(log, "posix_spawn_file_actions_adddup2 (action=%p, fd=%i, dup_fd=%i)",
static_cast<void *>(file_actions), info->GetFD(), info->GetActionArgument());
}
break;
case FileAction::eFileActionOpen:
if (info->GetFD() == -1)
error.SetErrorString("invalid fd in posix_spawn_file_actions_addopen(...)");
else
{
int oflag = info->GetActionArgument();
mode_t mode = 0;
if (oflag & O_CREAT)
mode = 0640;
error.SetError(
::posix_spawn_file_actions_addopen(file_actions, info->GetFD(), info->GetPath(), oflag, mode),
eErrorTypePOSIX);
if (error.Fail() || log)
error.PutToLog(log,
"posix_spawn_file_actions_addopen (action=%p, fd=%i, path='%s', oflag=%i, mode=%i)",
static_cast<void *>(file_actions), info->GetFD(), info->GetPath(), oflag, mode);
}
break;
}
return error.Success();
}
示例11: if
bool
JITLoaderGDB::ReadJITDescriptor(bool all_entries)
{
if (m_jit_descriptor_addr == LLDB_INVALID_ADDRESS)
return false;
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_JIT_LOADER));
Target &target = m_process->GetTarget();
ModuleList &module_list = target.GetImages();
jit_descriptor jit_desc;
const size_t jit_desc_size = sizeof(jit_desc);
Error error;
size_t bytes_read = m_process->DoReadMemory(
m_jit_descriptor_addr, &jit_desc, jit_desc_size, error);
if (bytes_read != jit_desc_size || !error.Success())
{
if (log)
log->Printf("JITLoaderGDB::%s failed to read JIT descriptor",
__FUNCTION__);
return false;
}
jit_actions_t jit_action = (jit_actions_t)jit_desc.action_flag;
addr_t jit_relevant_entry = (addr_t)jit_desc.relevant_entry;
if (all_entries)
{
jit_action = JIT_REGISTER_FN;
jit_relevant_entry = (addr_t)jit_desc.first_entry;
}
while (jit_relevant_entry != 0)
{
jit_code_entry jit_entry;
const size_t jit_entry_size = sizeof(jit_entry);
bytes_read = m_process->DoReadMemory(jit_relevant_entry, &jit_entry, jit_entry_size, error);
if (bytes_read != jit_entry_size || !error.Success())
{
if (log)
log->Printf(
"JITLoaderGDB::%s failed to read JIT entry at 0x%" PRIx64,
__FUNCTION__, jit_relevant_entry);
return false;
}
const addr_t &symbolfile_addr = (addr_t)jit_entry.symfile_addr;
const size_t &symbolfile_size = (size_t)jit_entry.symfile_size;
ModuleSP module_sp;
if (jit_action == JIT_REGISTER_FN)
{
if (log)
log->Printf(
"JITLoaderGDB::%s registering JIT entry at 0x%" PRIx64
" (%" PRIu64 " bytes)",
__FUNCTION__, symbolfile_addr, (uint64_t) symbolfile_size);
char jit_name[64];
snprintf(jit_name, 64, "JIT(0x%" PRIx64 ")", symbolfile_addr);
module_sp = m_process->ReadModuleFromMemory(
FileSpec(jit_name, false), symbolfile_addr, symbolfile_size);
if (module_sp && module_sp->GetObjectFile())
{
bool changed;
m_jit_objects.insert(std::make_pair(symbolfile_addr, module_sp));
if (module_sp->GetObjectFile()->GetPluginName() == ConstString("mach-o"))
{
ObjectFile *image_object_file = module_sp->GetObjectFile();
if (image_object_file)
{
const SectionList *section_list = image_object_file->GetSectionList ();
if (section_list)
{
uint64_t vmaddrheuristic = 0;
uint64_t lower = (uint64_t)-1;
uint64_t upper = 0;
updateSectionLoadAddress(*section_list, target, symbolfile_addr, symbolfile_size,
vmaddrheuristic, lower, upper);
}
}
}
else
{
module_sp->SetLoadAddress(target, 0, true, changed);
}
// load the symbol table right away
module_sp->GetObjectFile()->GetSymtab();
module_list.AppendIfNeeded(module_sp);
ModuleList module_list;
module_list.Append(module_sp);
target.ModulesDidLoad(module_list);
}
else
{
if (log)
log->Printf("JITLoaderGDB::%s failed to load module for "
//.........这里部分代码省略.........
示例12: sigemptyset
//.........这里部分代码省略.........
error.SetErrorStringWithFormat("Path doesn't name a directory: %s",
working_dir.GetCString());
} else {
error.SetErrorStringWithFormat("An unknown error occurred when changing directory for process execution.");
}
return error;
}
#else
if (::getcwd(current_dir, sizeof(current_dir)) == NULL)
{
error.SetError(errno, eErrorTypePOSIX);
error.LogIfError(log, "unable to save the current directory");
return error;
}
if (::chdir(working_dir.GetCString()) == -1)
{
error.SetError(errno, eErrorTypePOSIX);
error.LogIfError(log, "unable to change working directory to %s",
working_dir.GetCString());
return error;
}
#endif
}
::pid_t result_pid = LLDB_INVALID_PROCESS_ID;
const size_t num_file_actions = launch_info.GetNumFileActions ();
if (num_file_actions > 0)
{
posix_spawn_file_actions_t file_actions;
error.SetError( ::posix_spawn_file_actions_init (&file_actions), eErrorTypePOSIX);
if (error.Fail() || log)
error.PutToLog(log, "::posix_spawn_file_actions_init ( &file_actions )");
if (error.Fail())
return error;
// Make a quick class that will cleanup the posix spawn attributes in case
// we return in the middle of this function.
lldb_utility::CleanUp <posix_spawn_file_actions_t *, int> posix_spawn_file_actions_cleanup (&file_actions, posix_spawn_file_actions_destroy);
for (size_t i=0; i<num_file_actions; ++i)
{
const FileAction *launch_file_action = launch_info.GetFileActionAtIndex(i);
if (launch_file_action)
{
if (!AddPosixSpawnFileAction(&file_actions, launch_file_action, log, error))
return error;
}
}
error.SetError(::posix_spawnp(&result_pid, exe_path, &file_actions, &attr, argv, envp), eErrorTypePOSIX);
if (error.Fail() || log)
{
error.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", result_pid,
exe_path, static_cast<void *>(&file_actions), static_cast<void *>(&attr), reinterpret_cast<const void *>(argv),
reinterpret_cast<const void *>(envp));
if (log)
{
for (int ii=0; argv[ii]; ++ii)
log->Printf("argv[%i] = '%s'", ii, argv[ii]);
}
}
}
else
{
error.SetError(::posix_spawnp(&result_pid, exe_path, NULL, &attr, argv, envp), eErrorTypePOSIX);
if (error.Fail() || log)
{
error.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = NULL, attr = %p, argv = %p, envp = %p )",
result_pid, exe_path, static_cast<void *>(&attr), reinterpret_cast<const void *>(argv),
reinterpret_cast<const void *>(envp));
if (log)
{
for (int ii=0; argv[ii]; ++ii)
log->Printf("argv[%i] = '%s'", ii, argv[ii]);
}
}
}
pid = result_pid;
if (working_dir)
{
#if defined (__APPLE__)
// No more thread specific current working directory
__pthread_fchdir (-1);
#else
if (::chdir(current_dir) == -1 && error.Success())
{
error.SetError(errno, eErrorTypePOSIX);
error.LogIfError(log, "unable to change current directory back to %s",
current_dir);
}
#endif
}
return error;
}
示例13: timeout_time
Error
Host::RunShellCommand(const Args &args,
const FileSpec &working_dir,
int *status_ptr,
int *signo_ptr,
std::string *command_output_ptr,
uint32_t timeout_sec,
bool run_in_default_shell)
{
Error error;
ProcessLaunchInfo launch_info;
launch_info.SetArchitecture(HostInfo::GetArchitecture());
if (run_in_default_shell)
{
// Run the command in a shell
launch_info.SetShell(HostInfo::GetDefaultShell());
launch_info.GetArguments().AppendArguments(args);
const bool localhost = true;
const bool will_debug = false;
const bool first_arg_is_full_shell_command = false;
launch_info.ConvertArgumentsForLaunchingInShell (error,
localhost,
will_debug,
first_arg_is_full_shell_command,
0);
}
else
{
// No shell, just run it
const bool first_arg_is_executable = true;
launch_info.SetArguments(args, first_arg_is_executable);
}
if (working_dir)
launch_info.SetWorkingDirectory(working_dir);
llvm::SmallString<PATH_MAX> output_file_path;
if (command_output_ptr)
{
// 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"
FileSpec tmpdir_file_spec;
if (HostInfo::GetLLDBPath(ePathTypeLLDBTempSystemDir, tmpdir_file_spec))
{
tmpdir_file_spec.AppendPathComponent("lldb-shell-output.%%%%%%");
llvm::sys::fs::createUniqueFile(tmpdir_file_spec.GetPath().c_str(), output_file_path);
}
else
{
llvm::sys::fs::createTemporaryFile("lldb-shell-output.%%%%%%", "", output_file_path);
}
}
FileSpec output_file_spec{output_file_path.c_str(), false};
launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
if (output_file_spec)
{
launch_info.AppendOpenFileAction(STDOUT_FILENO, output_file_spec, false, true);
launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO);
}
else
{
launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true);
launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true);
}
// The process monitor callback will delete the 'shell_info_ptr' below...
std::unique_ptr<ShellInfo> shell_info_ap (new ShellInfo());
const bool monitor_signals = false;
launch_info.SetMonitorProcessCallback(MonitorShellCommand, shell_info_ap.get(), monitor_signals);
error = LaunchProcess (launch_info);
const lldb::pid_t pid = launch_info.GetProcessID();
if (error.Success() && pid == LLDB_INVALID_PROCESS_ID)
error.SetErrorString("failed to get process ID");
if (error.Success())
{
// The process successfully launched, so we can defer ownership of
// "shell_info" to the MonitorShellCommand callback function that will
// get called when the process dies. We release the unique pointer as it
// doesn't need to delete the ShellInfo anymore.
ShellInfo *shell_info = shell_info_ap.release();
TimeValue *timeout_ptr = nullptr;
TimeValue timeout_time(TimeValue::Now());
if (timeout_sec > 0) {
timeout_time.OffsetWithSeconds(timeout_sec);
timeout_ptr = &timeout_time;
}
bool timed_out = false;
shell_info->process_reaped.WaitForValueEqualTo(true, timeout_ptr, &timed_out);
if (timed_out)
{
error.SetErrorString("timed out waiting for shell command to complete");
// Kill the process since it didn't complete within the timeout specified
//.........这里部分代码省略.........
示例14: GetMemoryData
void IRMemoryMap::GetMemoryData(DataExtractor &extractor,
lldb::addr_t process_address, size_t size,
Error &error) {
error.Clear();
if (size > 0) {
AllocationMap::iterator iter = FindAllocation(process_address, size);
if (iter == m_allocations.end()) {
error.SetErrorToGenericError();
error.SetErrorStringWithFormat(
"Couldn't find an allocation containing [0x%" PRIx64 "..0x%" PRIx64
")",
process_address, process_address + size);
return;
}
Allocation &allocation = iter->second;
switch (allocation.m_policy) {
default:
error.SetErrorToGenericError();
error.SetErrorString(
"Couldn't get memory data: invalid allocation policy");
return;
case eAllocationPolicyProcessOnly:
error.SetErrorToGenericError();
error.SetErrorString(
"Couldn't get memory data: memory is only in the target");
return;
case eAllocationPolicyMirror: {
lldb::ProcessSP process_sp = m_process_wp.lock();
if (!allocation.m_data.GetByteSize()) {
error.SetErrorToGenericError();
error.SetErrorString("Couldn't get memory data: data buffer is empty");
return;
}
if (process_sp) {
process_sp->ReadMemory(allocation.m_process_start,
allocation.m_data.GetBytes(),
allocation.m_data.GetByteSize(), error);
if (!error.Success())
return;
uint64_t offset = process_address - allocation.m_process_start;
extractor = DataExtractor(allocation.m_data.GetBytes() + offset, size,
GetByteOrder(), GetAddressByteSize());
return;
}
} break;
case eAllocationPolicyHostOnly:
if (!allocation.m_data.GetByteSize()) {
error.SetErrorToGenericError();
error.SetErrorString("Couldn't get memory data: data buffer is empty");
return;
}
uint64_t offset = process_address - allocation.m_process_start;
extractor = DataExtractor(allocation.m_data.GetBytes() + offset, size,
GetByteOrder(), GetAddressByteSize());
return;
}
} else {
error.SetErrorToGenericError();
error.SetErrorString("Couldn't get memory data: its size was zero");
return;
}
}
示例15: platform_module_spec
//.........这里部分代码省略.........
if (GetFileInSDK (platform_file_path, connected_sdk_idx, platform_module_spec.GetFileSpec()))
{
module_sp.reset();
error = ResolveExecutable (platform_module_spec,
module_sp,
NULL);
if (module_sp)
{
m_last_module_sdk_idx = connected_sdk_idx;
error.Clear();
return error;
}
}
}
// Try the last SDK index if it is set as most files from an SDK
// will tend to be valid in that same SDK.
if (m_last_module_sdk_idx < num_sdk_infos)
{
if (GetFileInSDK (platform_file_path, m_last_module_sdk_idx, platform_module_spec.GetFileSpec()))
{
module_sp.reset();
error = ResolveExecutable (platform_module_spec,
module_sp,
NULL);
if (module_sp)
{
error.Clear();
return error;
}
}
}
// First try for an exact match of major, minor and update:
// If a particalar SDK version was specified via --version or --build, look for a match on disk.
const SDKDirectoryInfo *current_sdk_info = GetSDKDirectoryForCurrentOSVersion();
const uint32_t current_sdk_idx = GetSDKIndexBySDKDirectoryInfo(current_sdk_info);
if (current_sdk_idx < num_sdk_infos && current_sdk_idx != m_last_module_sdk_idx)
{
if (GetFileInSDK (platform_file_path, current_sdk_idx, platform_module_spec.GetFileSpec()))
{
module_sp.reset();
error = ResolveExecutable (platform_module_spec,
module_sp,
NULL);
if (module_sp)
{
m_last_module_sdk_idx = current_sdk_idx;
error.Clear();
return error;
}
}
}
// Second try all SDKs that were found.
for (uint32_t sdk_idx=0; sdk_idx<num_sdk_infos; ++sdk_idx)
{
if (m_last_module_sdk_idx == sdk_idx)
{
// Skip the last module SDK index if we already searched
// it above
continue;
}
if (GetFileInSDK (platform_file_path, sdk_idx, platform_module_spec.GetFileSpec()))
{
//printf ("sdk[%u]: '%s'\n", sdk_idx, local_file.GetPath().c_str());
error = ResolveExecutable (platform_module_spec, module_sp, NULL);
if (module_sp)
{
// Remember the index of the last SDK that we found a file
// in in case the wrong SDK was selected.
m_last_module_sdk_idx = sdk_idx;
error.Clear();
return error;
}
}
}
}
// Not the module we are looking for... Nothing to see here...
module_sp.reset();
// This may not be an SDK-related module. Try whether we can bring in the thing to our local cache.
error = GetSharedModuleWithLocalCache(module_spec, module_sp, module_search_paths_ptr, old_module_sp_ptr, did_create_ptr);
if (error.Success())
return error;
const bool always_create = false;
error = ModuleList::GetSharedModule (module_spec,
module_sp,
module_search_paths_ptr,
old_module_sp_ptr,
did_create_ptr,
always_create);
if (module_sp)
module_sp->SetPlatformFileSpec(platform_file);
return error;
}