static bool GetFreeBSDProcessUserAndGroup(ProcessInstanceInfo &process_info) { struct kinfo_proc proc_kinfo; size_t proc_kinfo_size; if (process_info.ProcessIDIsValid()) { int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)process_info.GetProcessID() }; proc_kinfo_size = sizeof(struct kinfo_proc); if (::sysctl (mib, 4, &proc_kinfo, &proc_kinfo_size, NULL, 0) == 0) { if (proc_kinfo_size > 0) { process_info.SetParentProcessID (proc_kinfo.ki_ppid); process_info.SetUserID (proc_kinfo.ki_ruid); process_info.SetGroupID (proc_kinfo.ki_rgid); process_info.SetEffectiveUserID (proc_kinfo.ki_uid); if (proc_kinfo.ki_ngroups > 0) process_info.SetEffectiveGroupID (proc_kinfo.ki_groups[0]); else process_info.SetEffectiveGroupID (UINT32_MAX); return true; } } } process_info.SetParentProcessID (LLDB_INVALID_PROCESS_ID); process_info.SetUserID (UINT32_MAX); process_info.SetGroupID (UINT32_MAX); process_info.SetEffectiveUserID (UINT32_MAX); process_info.SetEffectiveGroupID (UINT32_MAX); return false; }
static bool GetNetBSDProcessArgs (const ProcessInstanceInfoMatch *match_info_ptr, ProcessInstanceInfo &process_info) { if (!process_info.ProcessIDIsValid()) return false; int pid = process_info.GetProcessID(); int mib[4] = { CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_ARGV }; char arg_data[8192]; size_t arg_data_size = sizeof(arg_data); if (::sysctl (mib, 4, arg_data, &arg_data_size , NULL, 0) != 0) return false; DataExtractor data (arg_data, arg_data_size, lldb::endian::InlHostByteOrder(), sizeof(void *)); lldb::offset_t offset = 0; const char *cstr; cstr = data.GetCStr (&offset); if (!cstr) return false; process_info.GetExecutableFile().SetFile(cstr, false); if (!(match_info_ptr == NULL || NameMatches (process_info.GetExecutableFile().GetFilename().GetCString(), match_info_ptr->GetNameMatchType(), match_info_ptr->GetProcessInfo().GetName()))) return false; Args &proc_args = process_info.GetArguments(); while (1) { const uint8_t *p = data.PeekData(offset, 1); while ((p != NULL) && (*p == '\0') && offset < arg_data_size) { ++offset; p = data.PeekData(offset, 1); } if (p == NULL || offset >= arg_data_size) break; cstr = data.GetCStr(&offset); if (!cstr) break; proc_args.AppendArgument(cstr); } return true; }
static bool GetNetBSDProcessUserAndGroup(ProcessInstanceInfo &process_info) { ::kvm_t *kdp; char errbuf[_POSIX2_LINE_MAX]; /* XXX: error string unused */ struct ::kinfo_proc2 *proc_kinfo; const int pid = process_info.GetProcessID(); int nproc; if (!process_info.ProcessIDIsValid()) goto error; if ((kdp = ::kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL) goto error; if ((proc_kinfo = ::kvm_getproc2(kdp, KERN_PROC_PID, pid, sizeof(struct ::kinfo_proc2), &nproc)) == NULL) { ::kvm_close(kdp); goto error; } if (nproc < 1) { ::kvm_close(kdp); /* XXX: we don't check for error here */ goto error; } process_info.SetParentProcessID (proc_kinfo->p_ppid); process_info.SetUserID (proc_kinfo->p_ruid); process_info.SetGroupID (proc_kinfo->p_rgid); process_info.SetEffectiveUserID (proc_kinfo->p_uid); process_info.SetEffectiveGroupID (proc_kinfo->p_gid); ::kvm_close(kdp); /* XXX: we don't check for error here */ return true; error: process_info.SetParentProcessID (LLDB_INVALID_PROCESS_ID); process_info.SetUserID (UINT32_MAX); process_info.SetGroupID (UINT32_MAX); process_info.SetEffectiveUserID (UINT32_MAX); process_info.SetEffectiveGroupID (UINT32_MAX); return false; }
void GDBRemoteCommunicationServerCommon::CreateProcessInfoResponse( const ProcessInstanceInfo &proc_info, StreamString &response) { response.Printf( "pid:%" PRIu64 ";ppid:%" PRIu64 ";uid:%i;gid:%i;euid:%i;egid:%i;", proc_info.GetProcessID(), proc_info.GetParentProcessID(), proc_info.GetUserID(), proc_info.GetGroupID(), proc_info.GetEffectiveUserID(), proc_info.GetEffectiveGroupID()); response.PutCString("name:"); response.PutCStringAsRawHex8(proc_info.GetExecutableFile().GetCString()); response.PutChar(';'); const ArchSpec &proc_arch = proc_info.GetArchitecture(); if (proc_arch.IsValid()) { const llvm::Triple &proc_triple = proc_arch.GetTriple(); response.PutCString("triple:"); response.PutCStringAsRawHex8(proc_triple.getTriple().c_str()); response.PutChar(';'); } }
static void CreateProcessInfoResponse (const ProcessInstanceInfo &proc_info, StreamString &response) { response.Printf ("pid:%llu;ppid:%llu;uid:%i;gid:%i;euid:%i;egid:%i;", proc_info.GetProcessID(), proc_info.GetParentProcessID(), proc_info.GetUserID(), proc_info.GetGroupID(), proc_info.GetEffectiveUserID(), proc_info.GetEffectiveGroupID()); response.PutCString ("name:"); response.PutCStringAsRawHex8(proc_info.GetName()); response.PutChar(';'); const ArchSpec &proc_arch = proc_info.GetArchitecture(); if (proc_arch.IsValid()) { const llvm::Triple &proc_triple = proc_arch.GetTriple(); response.PutCString("triple:"); response.PutCStringAsRawHex8(proc_triple.getTriple().c_str()); response.PutChar(';'); } }
void GDBRemoteCommunicationServerCommon:: CreateProcessInfoResponse_DebugServerStyle( const ProcessInstanceInfo &proc_info, StreamString &response) { response.Printf("pid:%" PRIx64 ";parent-pid:%" PRIx64 ";real-uid:%x;real-gid:%x;effective-uid:%x;effective-gid:%x;", proc_info.GetProcessID(), proc_info.GetParentProcessID(), proc_info.GetUserID(), proc_info.GetGroupID(), proc_info.GetEffectiveUserID(), proc_info.GetEffectiveGroupID()); const ArchSpec &proc_arch = proc_info.GetArchitecture(); if (proc_arch.IsValid()) { const llvm::Triple &proc_triple = proc_arch.GetTriple(); #if defined(__APPLE__) // We'll send cputype/cpusubtype. const uint32_t cpu_type = proc_arch.GetMachOCPUType(); if (cpu_type != 0) response.Printf("cputype:%" PRIx32 ";", cpu_type); const uint32_t cpu_subtype = proc_arch.GetMachOCPUSubType(); if (cpu_subtype != 0) response.Printf("cpusubtype:%" PRIx32 ";", cpu_subtype); const std::string vendor = proc_triple.getVendorName(); if (!vendor.empty()) response.Printf("vendor:%s;", vendor.c_str()); #else // We'll send the triple. response.PutCString("triple:"); response.PutCStringAsRawHex8(proc_triple.getTriple().c_str()); response.PutChar(';'); #endif std::string ostype = proc_triple.getOSName(); // Adjust so ostype reports ios for Apple/ARM and Apple/ARM64. if (proc_triple.getVendor() == llvm::Triple::Apple) { switch (proc_triple.getArch()) { case llvm::Triple::arm: case llvm::Triple::thumb: case llvm::Triple::aarch64: ostype = "ios"; break; default: // No change. break; } } response.Printf("ostype:%s;", ostype.c_str()); switch (proc_arch.GetByteOrder()) { case lldb::eByteOrderLittle: response.PutCString("endian:little;"); break; case lldb::eByteOrderBig: response.PutCString("endian:big;"); break; case lldb::eByteOrderPDP: response.PutCString("endian:pdp;"); break; default: // Nothing. break; } // In case of MIPS64, pointer size is depend on ELF ABI // For N32 the pointer size is 4 and for N64 it is 8 std::string abi = proc_arch.GetTargetABI(); if (!abi.empty()) response.Printf("elf_abi:%s;", abi.c_str()); response.Printf("ptrsize:%d;", proc_arch.GetAddressByteSize()); } }