1 //===-- HostInfoFreeBSD.cpp -------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Host/freebsd/HostInfoFreeBSD.h" 11 12 #include <stdio.h> 13 #include <string.h> 14 #include <sys/sysctl.h> 15 #include <sys/types.h> 16 #include <sys/utsname.h> 17 18 using namespace lldb_private; 19 20 uint32_t HostInfoFreeBSD::GetMaxThreadNameLength() { return 16; } 21 22 bool HostInfoFreeBSD::GetOSVersion(uint32_t &major, uint32_t &minor, 23 uint32_t &update) { 24 struct utsname un; 25 26 ::memset(&un, 0, sizeof(utsname)); 27 if (uname(&un) < 0) 28 return false; 29 30 int status = sscanf(un.release, "%u.%u", &major, &minor); 31 return status == 2; 32 } 33 34 bool HostInfoFreeBSD::GetOSBuildString(std::string &s) { 35 int mib[2] = {CTL_KERN, KERN_OSREV}; 36 char osrev_str[12]; 37 uint32_t osrev = 0; 38 size_t osrev_len = sizeof(osrev); 39 40 if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0) { 41 ::snprintf(osrev_str, sizeof(osrev_str), "%-8.8u", osrev); 42 s.assign(osrev_str); 43 return true; 44 } 45 46 s.clear(); 47 return false; 48 } 49 50 bool HostInfoFreeBSD::GetOSKernelDescription(std::string &s) { 51 struct utsname un; 52 53 ::memset(&un, 0, sizeof(utsname)); 54 s.clear(); 55 56 if (uname(&un) < 0) 57 return false; 58 59 s.assign(un.version); 60 61 return true; 62 } 63 64 FileSpec HostInfoFreeBSD::GetProgramFileSpec() { 65 static FileSpec g_program_filespec; 66 if (!g_program_filespec) { 67 int exe_path_mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid()}; 68 size_t exe_path_size; 69 if (sysctl(exe_path_mib, 4, NULL, &exe_path_size, NULL, 0) == 0) { 70 char *exe_path = new char[exe_path_size]; 71 if (sysctl(exe_path_mib, 4, exe_path, &exe_path_size, NULL, 0) == 0) 72 g_program_filespec.SetFile(exe_path, false); 73 delete[] exe_path; 74 } 75 } 76 return g_program_filespec; 77 }