std::unique_ptr<Acceptor> Acceptor::Create(StringRef name, const bool child_processes_inherit, Error &error) { error.Clear(); LocalSocketIdFunc local_socket_id; std::unique_ptr<Socket> listener_socket = nullptr; std::string host_str; std::string port_str; int32_t port = INT32_MIN; if (Socket::DecodeHostAndPort (name, host_str, port_str, port, &error)) { auto tcp_socket = new TCPSocket(child_processes_inherit, error); local_socket_id = [tcp_socket]() { auto local_port = tcp_socket->GetLocalPortNumber(); return (local_port != 0) ? std::to_string(local_port) : ""; }; listener_socket.reset(tcp_socket); } else { const std::string socket_name = name; local_socket_id = [socket_name](){ return socket_name; }; listener_socket.reset(new DomainSocket(child_processes_inherit, error)); } if (error.Success()) return std::unique_ptr<Acceptor>( new Acceptor(std::move(listener_socket), name, local_socket_id)); return std::unique_ptr<Acceptor>(); }
bool lldb_private::formatters::NSDictionaryMSyntheticFrontEnd::Update() { m_children.clear(); ValueObjectSP valobj_sp = m_backend.GetSP(); m_ptr_size = 0; delete m_data_32; m_data_32 = NULL; delete m_data_64; m_data_64 = NULL; if (!valobj_sp) return false; m_exe_ctx_ref = valobj_sp->GetExecutionContextRef(); Error error; error.Clear(); lldb::ProcessSP process_sp(valobj_sp->GetProcessSP()); if (!process_sp) return false; m_ptr_size = process_sp->GetAddressByteSize(); m_order = process_sp->GetByteOrder(); uint64_t data_location = valobj_sp->GetValueAsUnsigned(0) + m_ptr_size; if (m_ptr_size == 4) { m_data_32 = new DataDescriptor_32(); process_sp->ReadMemory (data_location, m_data_32, sizeof(DataDescriptor_32), error); } else { m_data_64 = new DataDescriptor_64(); process_sp->ReadMemory (data_location, m_data_64, sizeof(DataDescriptor_64), error); } if (error.Fail()) return false; return false; }
void IRMemoryMap::WriteScalarToMemory (lldb::addr_t process_address, Scalar &scalar, size_t size, Error &error) { error.Clear(); if (size == UINT32_MAX) size = scalar.GetByteSize(); if (size > 0) { uint8_t buf[32]; const size_t mem_size = scalar.GetAsMemoryData (buf, size, GetByteOrder(), error); if (mem_size > 0) { return WriteMemory(process_address, buf, mem_size, error); } else { error.SetErrorToGenericError(); error.SetErrorString ("Couldn't write scalar: failed to get scalar as memory data"); } } else { error.SetErrorToGenericError(); error.SetErrorString ("Couldn't write scalar: its size was zero"); } return; }
addr_t ProcessFreeBSD::DoAllocateMemory(size_t size, uint32_t permissions, Error &error) { addr_t allocated_addr = LLDB_INVALID_ADDRESS; unsigned prot = 0; if (permissions & lldb::ePermissionsReadable) prot |= eMmapProtRead; if (permissions & lldb::ePermissionsWritable) prot |= eMmapProtWrite; if (permissions & lldb::ePermissionsExecutable) prot |= eMmapProtExec; if (InferiorCallMmap(this, allocated_addr, 0, size, prot, eMmapFlagsAnon | eMmapFlagsPrivate, -1, 0)) { m_addr_to_mmap_size[allocated_addr] = size; error.Clear(); } else { allocated_addr = LLDB_INVALID_ADDRESS; error.SetErrorStringWithFormat("unable to allocate %zu bytes of memory with permissions %s", size, GetPermissionsAsCString (permissions)); } return allocated_addr; }
bool CommunicationKDP::SendRawRequest (uint8_t command_byte, const void *src, // Raw packet payload bytes uint32_t src_len, // Raw packet payload length DataExtractor &reply_packet, Error &error) { PacketStreamType request_packet (Stream::eBinary, m_addr_byte_size, m_byte_order); // Size is header + address size + uint32_t length const uint32_t command_length = 8 + src_len; const CommandType command = (CommandType)command_byte; const uint32_t request_sequence_id = m_request_sequence_id; MakeRequestPacketHeader (command, request_packet, command_length); request_packet.PutRawBytes(src, src_len); if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet)) { uint32_t offset = 8; uint32_t kdp_error = reply_packet.GetU32 (&offset); if (kdp_error) error.SetErrorStringWithFormat ("request packet 0x%8.8x failed (error %u)", command_byte, kdp_error); else { error.Clear(); return true; } } else { error.SetErrorString ("failed to send packet"); } return false; }
std::unique_ptr<Socket> Socket::Create(const SocketProtocol protocol, bool child_processes_inherit, Error &error) { error.Clear(); std::unique_ptr<Socket> socket_up; switch (protocol) { case ProtocolTcp: socket_up.reset(new TCPSocket(child_processes_inherit, error)); break; case ProtocolUdp: socket_up.reset(new UDPSocket(child_processes_inherit, error)); break; case ProtocolUnixDomain: #ifndef LLDB_DISABLE_POSIX socket_up.reset(new DomainSocket(child_processes_inherit, error)); #else error.SetErrorString("Unix domain sockets are not supported on this platform."); #endif break; case ProtocolUnixAbstract: #ifdef __linux__ socket_up.reset(new AbstractSocket(child_processes_inherit, error)); #else error.SetErrorString("Abstract domain sockets are not supported on this platform."); #endif break; } if (error.Fail()) socket_up.reset(); return socket_up; }
void IRMemoryMap::WritePointerToMemory(lldb::addr_t process_address, lldb::addr_t address, Error &error) { error.Clear(); Scalar scalar(address); WriteScalarToMemory(process_address, scalar, GetAddressByteSize(), error); }
OperatingSystemGo::Goroutine OperatingSystemGo::CreateGoroutineAtIndex(uint64_t idx, Error &err) { err.Clear(); Goroutine result; ValueObjectSP g = m_allg_sp->GetSyntheticArrayMember(idx, true)->Dereference(err); if (err.Fail()) { return result; } ConstString name("goid"); ValueObjectSP val = g->GetChildMemberWithName(name, true); bool success = false; result.m_goid = val->GetValueAsUnsigned(0, &success); if (!success) { err.SetErrorToGenericError(); err.SetErrorString("unable to read goid"); return result; } name.SetCString("atomicstatus"); val = g->GetChildMemberWithName(name, true); result.m_status = (uint32_t)val->GetValueAsUnsigned(0, &success); if (!success) { err.SetErrorToGenericError(); err.SetErrorString("unable to read atomicstatus"); return result; } name.SetCString("sched"); val = g->GetChildMemberWithName(name, true); result.m_gobuf = val->GetAddressOf(false); name.SetCString("stack"); val = g->GetChildMemberWithName(name, true); name.SetCString("lo"); ValueObjectSP child = val->GetChildMemberWithName(name, true); result.m_lostack = child->GetValueAsUnsigned(0, &success); if (!success) { err.SetErrorToGenericError(); err.SetErrorString("unable to read stack.lo"); return result; } name.SetCString("hi"); child = val->GetChildMemberWithName(name, true); result.m_histack = child->GetValueAsUnsigned(0, &success); if (!success) { err.SetErrorToGenericError(); err.SetErrorString("unable to read stack.hi"); return result; } return result; }
Error ClangExpressionParser::MakeDWARF () { Error err; llvm::Module *module = m_code_generator->GetModule(); if (!module) { err.SetErrorToGenericError(); err.SetErrorString("IR doesn't contain a module"); return err; } ClangExpressionVariableList *local_variables = m_expr.LocalVariables(); ClangExpressionDeclMap *decl_map = m_expr.DeclMap(); if (!local_variables) { err.SetErrorToGenericError(); err.SetErrorString("Can't convert an expression without a VariableList to DWARF"); return err; } if (!decl_map) { err.SetErrorToGenericError(); err.SetErrorString("Can't convert an expression without a DeclMap to DWARF"); return err; } std::string function_name; if (!FindFunctionInModule(function_name, module, m_expr.FunctionName())) { err.SetErrorToGenericError(); err.SetErrorStringWithFormat("Couldn't find %s() in the module", m_expr.FunctionName()); return err; } IRToDWARF ir_to_dwarf(*local_variables, decl_map, m_expr.DwarfOpcodeStream(), function_name.c_str()); if (!ir_to_dwarf.runOnModule(*module)) { err.SetErrorToGenericError(); err.SetErrorString("Couldn't convert the expression to DWARF"); return err; } err.Clear(); return err; }
lldb::ProcessSP PlatformRemoteGDBServer::Attach( ProcessAttachInfo &attach_info, Debugger &debugger, Target *target, // Can be NULL, if NULL create a new target, else use // existing one Error &error) { lldb::ProcessSP process_sp; if (IsRemote()) { if (IsConnected()) { lldb::pid_t debugserver_pid = LLDB_INVALID_PROCESS_ID; std::string connect_url; if (!LaunchGDBServer(debugserver_pid, connect_url)) { error.SetErrorStringWithFormat("unable to launch a GDB server on '%s'", GetHostname()); } else { if (target == NULL) { TargetSP new_target_sp; error = debugger.GetTargetList().CreateTarget( debugger, NULL, NULL, false, NULL, new_target_sp); target = new_target_sp.get(); } else error.Clear(); if (target && error.Success()) { debugger.GetTargetList().SetSelectedTarget(target); // The darwin always currently uses the GDB remote debugger plug-in // so even when debugging locally we are debugging remotely! process_sp = target->CreateProcess( attach_info.GetListenerForProcess(debugger), "gdb-remote", NULL); if (process_sp) { error = process_sp->ConnectRemote(nullptr, connect_url.c_str()); if (error.Success()) { ListenerSP listener_sp = attach_info.GetHijackListener(); if (listener_sp) process_sp->HijackProcessEvents(listener_sp); error = process_sp->Attach(attach_info); } if (error.Fail() && debugserver_pid != LLDB_INVALID_PROCESS_ID) { KillSpawnedProcess(debugserver_pid); } } } } } else { error.SetErrorString("not connected to remote gdb server"); } } return process_sp; }
std::unique_ptr<Acceptor> Acceptor::Create(StringRef name, const bool child_processes_inherit, Error &error) { error.Clear(); Socket::SocketProtocol socket_protocol = Socket::ProtocolUnixDomain; int port; std::string scheme, host, path; // Try to match socket name as URL - e.g., tcp://localhost:5555 if (UriParser::Parse(name.str(), scheme, host, port, path)) { if (!FindProtocolByScheme(scheme.c_str(), socket_protocol)) error.SetErrorStringWithFormat("Unknown protocol scheme \"%s\"", scheme.c_str()); else name = name.drop_front(scheme.size() + strlen("://")); } else { std::string host_str; std::string port_str; int32_t port = INT32_MIN; // Try to match socket name as $host:port - e.g., localhost:5555 if (Socket::DecodeHostAndPort(name, host_str, port_str, port, nullptr)) socket_protocol = Socket::ProtocolTcp; } if (error.Fail()) return std::unique_ptr<Acceptor>(); std::unique_ptr<Socket> listener_socket_up = Socket::Create(socket_protocol, child_processes_inherit, error); LocalSocketIdFunc local_socket_id; if (error.Success()) { if (listener_socket_up->GetSocketProtocol() == Socket::ProtocolTcp) { TCPSocket *tcp_socket = static_cast<TCPSocket *>(listener_socket_up.get()); local_socket_id = [tcp_socket]() { auto local_port = tcp_socket->GetLocalPortNumber(); return (local_port != 0) ? llvm::to_string(local_port) : ""; }; } else { const std::string socket_name = name; local_socket_id = [socket_name]() { return socket_name; }; } return std::unique_ptr<Acceptor>( new Acceptor(std::move(listener_socket_up), name, local_socket_id)); } return std::unique_ptr<Acceptor>(); }
void IRMemoryMap::Free (lldb::addr_t process_address, Error &error) { error.Clear(); AllocationMap::iterator iter = m_allocations.find(process_address); if (iter == m_allocations.end()) { error.SetErrorToGenericError(); error.SetErrorString("Couldn't free: allocation doesn't exist"); return; } Allocation &allocation = iter->second; switch (allocation.m_policy) { default: case eAllocationPolicyHostOnly: { lldb::ProcessSP process_sp = m_process_wp.lock(); if (process_sp) { if (process_sp->CanJIT() && process_sp->IsAlive()) process_sp->DeallocateMemory(allocation.m_process_alloc); // FindSpace allocated this for real } break; } case eAllocationPolicyMirror: case eAllocationPolicyProcessOnly: { lldb::ProcessSP process_sp = m_process_wp.lock(); if (process_sp) process_sp->DeallocateMemory(allocation.m_process_alloc); } } if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)) { log->Printf("IRMemoryMap::Free (0x%" PRIx64 ") freed [0x%" PRIx64 "..0x%" PRIx64 ")", (uint64_t)process_address, iter->second.m_process_start, iter->second.m_process_start + iter->second.m_size); } m_allocations.erase(iter); }
Error TCPSocket::Connect(llvm::StringRef name) { if (m_socket == kInvalidSocketValue) return Error("Invalid socket"); Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_COMMUNICATION)); if (log) log->Printf("TCPSocket::%s (host/port = %s)", __FUNCTION__, name.data()); Error error; std::string host_str; std::string port_str; int32_t port = INT32_MIN; if (!DecodeHostAndPort(name, host_str, port_str, port, &error)) return error; struct sockaddr_in sa; ::memset(&sa, 0, sizeof(sa)); sa.sin_family = kDomain; sa.sin_port = htons(port); int inet_pton_result = ::inet_pton(kDomain, host_str.c_str(), &sa.sin_addr); if (inet_pton_result <= 0) { struct hostent *host_entry = gethostbyname(host_str.c_str()); if (host_entry) host_str = ::inet_ntoa(*(struct in_addr *)*host_entry->h_addr_list); inet_pton_result = ::inet_pton(kDomain, host_str.c_str(), &sa.sin_addr); if (inet_pton_result <= 0) { if (inet_pton_result == -1) SetLastError(error); else error.SetErrorStringWithFormat("invalid host string: '%s'", host_str.c_str()); return error; } } if (-1 == ::connect(GetNativeSocket(), (const struct sockaddr *)&sa, sizeof(sa))) { SetLastError(error); return error; } // Keep our TCP packets coming without any delays. SetOptionNoDelay(); error.Clear(); return error; }
void IRMemoryMap::Leak(lldb::addr_t process_address, Error &error) { error.Clear(); AllocationMap::iterator iter = m_allocations.find(process_address); if (iter == m_allocations.end()) { error.SetErrorToGenericError(); error.SetErrorString("Couldn't leak: allocation doesn't exist"); return; } Allocation &allocation = iter->second; allocation.m_leak = true; }
void IRMemoryMap::ReadPointerFromMemory (lldb::addr_t *address, lldb::addr_t process_address, Error &error) { error.Clear(); Scalar pointer_scalar; ReadScalarFromMemory(pointer_scalar, process_address, GetAddressByteSize(), error); if (!error.Success()) return; *address = pointer_scalar.ULongLong(); return; }
lldb::ProcessSP PlatformLinux::Attach(ProcessAttachInfo &attach_info, Debugger &debugger, Target *target, Listener &listener, Error &error) { lldb::ProcessSP process_sp; if (IsHost()) { if (target == NULL) { TargetSP new_target_sp; FileSpec emptyFileSpec; ArchSpec emptyArchSpec; error = debugger.GetTargetList().CreateTarget (debugger, emptyFileSpec, emptyArchSpec, false, m_remote_platform_sp, new_target_sp); target = new_target_sp.get(); } else error.Clear(); if (target && error.Success()) { debugger.GetTargetList().SetSelectedTarget(target); process_sp = target->CreateProcess (listener, attach_info.GetProcessPluginName(), NULL); if (process_sp) error = process_sp->Attach (attach_info); } } else { if (m_remote_platform_sp) process_sp = m_remote_platform_sp->Attach (attach_info, debugger, target, listener, error); else error.SetErrorString ("the platform is not currently connected"); } return process_sp; }
lldb::ProcessSP PlatformWindows::Attach(ProcessAttachInfo &attach_info, Debugger &debugger, Target *target, Listener &listener, Error &error) { lldb::ProcessSP process_sp; if (IsHost()) { if (target == NULL) { TargetSP new_target_sp; FileSpec emptyFileSpec; ArchSpec emptyArchSpec; error = debugger.GetTargetList().CreateTarget (debugger, NULL, NULL, false, NULL, new_target_sp); target = new_target_sp.get(); } else error.Clear(); if (target && error.Success()) { debugger.GetTargetList().SetSelectedTarget(target); // The Windows platform always currently uses the GDB remote debugger plug-in // so even when debugging locally we are debugging remotely! // Just like the darwin plugin. process_sp = target->CreateProcess (listener, "gdb-remote", NULL); if (process_sp) error = process_sp->Attach (attach_info); } } else { if (m_remote_platform_sp) process_sp = m_remote_platform_sp->Attach (attach_info, debugger, target, listener, error); else error.SetErrorString ("the platform is not currently connected"); } return process_sp; }
bool BreakpointID::StringIsBreakpointName(const char *name, Error &error) { error.Clear(); if (name && (name[0] >= 'A' && name[0] <= 'z')) { if (strcspn(name, ".- ") != strlen(name)) { error.SetErrorStringWithFormat("invalid breakpoint name: \"%s\"", name); } return true; } else return false; }
uint32_t CommunicationKDP::SendRequestReadRegisters (uint32_t cpu, uint32_t flavor, void *dst, uint32_t dst_len, Error &error) { PacketStreamType request_packet (Stream::eBinary, m_addr_byte_size, m_byte_order); const CommandType command = KDP_READREGS; // Size is header + 4 byte cpu and 4 byte flavor const uint32_t command_length = 8 + 4 + 4; const uint32_t request_sequence_id = m_request_sequence_id; MakeRequestPacketHeader (command, request_packet, command_length); request_packet.PutHex32 (cpu); request_packet.PutHex32 (flavor); DataExtractor reply_packet; if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet)) { uint32_t offset = 8; uint32_t kdp_error = reply_packet.GetU32 (&offset); uint32_t src_len = reply_packet.GetByteSize() - 12; if (src_len > 0) { const uint32_t bytes_to_copy = std::min<uint32_t>(src_len, dst_len); const void *src = reply_packet.GetData(&offset, bytes_to_copy); if (src) { ::memcpy (dst, src, bytes_to_copy); error.Clear(); // Return the number of bytes we could have returned regardless if // we copied them or not, just so we know when things don't match up return src_len; } } if (kdp_error) error.SetErrorStringWithFormat("failed to read kdp registers for cpu %u flavor %u (error %u)", cpu, flavor, kdp_error); else error.SetErrorStringWithFormat("failed to read kdp registers for cpu %u flavor %u", cpu, flavor); } else { error.SetErrorString ("failed to send packet"); } return 0; }
IRMemoryMap::~IRMemoryMap() { lldb::ProcessSP process_sp = m_process_wp.lock(); if (process_sp) { AllocationMap::iterator iter; Error err; while ((iter = m_allocations.begin()) != m_allocations.end()) { err.Clear(); if (iter->second.m_leak) m_allocations.erase(iter); else Free(iter->first, err); } } }
lldb::ProcessSP PlatformWindows::Attach(ProcessAttachInfo &attach_info, Debugger &debugger, Target *target, Error &error) { error.Clear(); lldb::ProcessSP process_sp; if (!IsHost()) { 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; } if (target == nullptr) { TargetSP new_target_sp; FileSpec emptyFileSpec; ArchSpec emptyArchSpec; error = debugger.GetTargetList().CreateTarget(debugger, nullptr, nullptr, false, nullptr, new_target_sp); target = new_target_sp.get(); } if (!target || error.Fail()) return process_sp; debugger.GetTargetList().SetSelectedTarget(target); const char *plugin_name = attach_info.GetProcessPluginName(); process_sp = target->CreateProcess(attach_info.GetListenerForProcess(debugger), plugin_name, nullptr); process_sp->HijackProcessEvents(attach_info.GetHijackListener()); if (process_sp) error = process_sp->Attach (attach_info); return process_sp; }
uint32_t File::GetPermissions(const FileSpec &file_spec, Error &error) { if (file_spec) { struct stat file_stats; if (::stat(file_spec.GetCString(), &file_stats) == -1) error.SetErrorToErrno(); else { error.Clear(); return file_stats.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); } } else error.SetErrorString ("empty file spec"); return 0; }
uint32_t CommunicationKDP::SendRequestReadMemory (lldb::addr_t addr, void *dst, uint32_t dst_len, Error &error) { PacketStreamType request_packet (Stream::eBinary, m_addr_byte_size, m_byte_order); bool use_64 = (GetVersion() >= 11); uint32_t command_addr_byte_size = use_64 ? 8 : 4; const CommandType command = use_64 ? KDP_READMEM64 : KDP_READMEM; // Size is header + address size + uint32_t length const uint32_t command_length = 8 + command_addr_byte_size + 4; const uint32_t request_sequence_id = m_request_sequence_id; MakeRequestPacketHeader (command, request_packet, command_length); request_packet.PutMaxHex64 (addr, command_addr_byte_size); request_packet.PutHex32 (dst_len); DataExtractor reply_packet; if (SendRequestAndGetReply (command, request_sequence_id, request_packet, reply_packet)) { uint32_t offset = 8; uint32_t kdp_error = reply_packet.GetU32 (&offset); uint32_t src_len = reply_packet.GetByteSize() - 12; if (src_len > 0) { const void *src = reply_packet.GetData(&offset, src_len); if (src) { ::memcpy (dst, src, src_len); error.Clear(); return src_len; } } if (kdp_error) error.SetErrorStringWithFormat ("kdp read memory failed (error %u)", kdp_error); else error.SetErrorString ("kdp read memory failed"); } else { error.SetErrorString ("failed to send packet"); } return 0; }
NativeSocket Socket::CreateSocket(const int domain, const int type, const int protocol, bool child_processes_inherit, Error& error) { error.Clear(); auto socketType = type; #ifdef SOCK_CLOEXEC if (!child_processes_inherit) socketType |= SOCK_CLOEXEC; #endif auto sock = ::socket (domain, socketType, protocol); if (sock == kInvalidSocketValue) SetLastError(error); return sock; }
bool lldb_private::formatters::NSSetISyntheticFrontEnd::Update() { m_children.clear(); delete m_data_32; m_data_32 = nullptr; delete m_data_64; m_data_64 = nullptr; m_ptr_size = 0; ValueObjectSP valobj_sp = m_backend.GetSP(); if (!valobj_sp) return false; if (!valobj_sp) return false; m_exe_ctx_ref = valobj_sp->GetExecutionContextRef(); Error error; if (valobj_sp->IsPointerType()) { valobj_sp = valobj_sp->Dereference(error); if (error.Fail() || !valobj_sp) return false; } error.Clear(); lldb::ProcessSP process_sp(valobj_sp->GetProcessSP()); if (!process_sp) return false; m_ptr_size = process_sp->GetAddressByteSize(); uint64_t data_location = valobj_sp->GetAddressOf() + m_ptr_size; if (m_ptr_size == 4) { m_data_32 = new DataDescriptor_32(); process_sp->ReadMemory (data_location, m_data_32, sizeof(DataDescriptor_32), error); } else { m_data_64 = new DataDescriptor_64(); process_sp->ReadMemory (data_location, m_data_64, sizeof(DataDescriptor_64), error); } if (error.Fail()) return false; m_data_ptr = data_location + m_ptr_size; return false; }
void IRMemoryMap::ReadScalarFromMemory(Scalar &scalar, lldb::addr_t process_address, size_t size, Error &error) { error.Clear(); if (size > 0) { DataBufferHeap buf(size, 0); ReadMemory(buf.GetBytes(), process_address, size, error); if (!error.Success()) return; DataExtractor extractor(buf.GetBytes(), buf.GetByteSize(), GetByteOrder(), GetAddressByteSize()); lldb::offset_t offset = 0; switch (size) { default: error.SetErrorToGenericError(); error.SetErrorStringWithFormat( "Couldn't read scalar: unsupported size %" PRIu64, (uint64_t)size); return; case 1: scalar = extractor.GetU8(&offset); break; case 2: scalar = extractor.GetU16(&offset); break; case 4: scalar = extractor.GetU32(&offset); break; case 8: scalar = extractor.GetU64(&offset); break; } } else { error.SetErrorToGenericError(); error.SetErrorString("Couldn't read scalar: its size was zero"); } return; }
uint32_t File::GetPermissions(Error &error) const { int fd = GetDescriptor(); if (fd != kInvalidDescriptor) { struct stat file_stats; if (::fstat (fd, &file_stats) == -1) error.SetErrorToErrno(); else { error.Clear(); return file_stats.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); } } else { error.SetErrorString ("invalid file descriptor"); } return 0; }
static lldb::addr_t GetObjectPointer (lldb::StackFrameSP frame_sp, ConstString &object_name, Error &err) { err.Clear(); if (!frame_sp) { err.SetErrorStringWithFormat("Couldn't load '%s' because the context is incomplete", object_name.AsCString()); return LLDB_INVALID_ADDRESS; } lldb::VariableSP var_sp; lldb::ValueObjectSP valobj_sp; valobj_sp = frame_sp->GetValueForVariableExpressionPath(object_name.AsCString(), lldb::eNoDynamicValues, StackFrame::eExpressionPathOptionCheckPtrVsMember || StackFrame::eExpressionPathOptionsAllowDirectIVarAccess || StackFrame::eExpressionPathOptionsNoFragileObjcIvar || StackFrame::eExpressionPathOptionsNoSyntheticChildren || StackFrame::eExpressionPathOptionsNoSyntheticArrayRange, var_sp, err); if (!err.Success()) return LLDB_INVALID_ADDRESS; lldb::addr_t ret = valobj_sp->GetValueAsUnsigned(LLDB_INVALID_ADDRESS); if (ret == LLDB_INVALID_ADDRESS) { err.SetErrorStringWithFormat("Couldn't load '%s' because its value couldn't be evaluated", object_name.AsCString()); return LLDB_INVALID_ADDRESS; } return ret; }
NativeSocket Socket::AcceptSocket(NativeSocket sockfd, struct sockaddr *addr, socklen_t *addrlen, bool child_processes_inherit, Error& error) { error.Clear(); #if defined(ANDROID_ARM_BUILD_STATIC) || defined(ANDROID_MIPS_BUILD_STATIC) // Temporary workaround for statically linking Android lldb-server with the // latest API. int fd = syscall(__NR_accept, sockfd, addr, addrlen); if (fd >= 0 && !child_processes_inherit) { int flags = ::fcntl(fd, F_GETFD); if (flags != -1 && ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC) != -1) return fd; SetLastError(error); close(fd); } return fd; #elif defined(SOCK_CLOEXEC) int flags = 0; if (!child_processes_inherit) { flags |= SOCK_CLOEXEC; } #if defined(__NetBSD__) NativeSocket fd = ::paccept (sockfd, addr, addrlen, nullptr, flags); #else NativeSocket fd = ::accept4 (sockfd, addr, addrlen, flags); #endif #else NativeSocket fd = ::accept (sockfd, addr, addrlen); #endif if (fd == kInvalidSocketValue) SetLastError(error); return fd; }
uint32_t File::GetPermissions (const char *path, Error &error) { if (path && path[0]) { struct stat file_stats; if (::stat (path, &file_stats) == -1) error.SetErrorToErrno(); else { error.Clear(); return file_stats.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); } } else { if (path) error.SetErrorString ("invalid path"); else error.SetErrorString ("empty path"); } return 0; }