Bruce Mitchener | 910af4d | 2015-10-13 05:04:13 +0000 | [diff] [blame] | 1 | //===-- HostInfoNetBSD.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/netbsd/HostInfoNetBSD.h" |
| 11 | |
| 12 | #include <limits.h> |
| 13 | #include <stdio.h> |
| 14 | #include <string.h> |
| 15 | #include <sys/types.h> |
| 16 | #include <sys/sysctl.h> |
| 17 | #include <sys/utsname.h> |
| 18 | #include <unistd.h> |
| 19 | #include <pthread.h> |
| 20 | #include <inttypes.h> |
| 21 | |
| 22 | |
| 23 | using namespace lldb_private; |
| 24 | |
| 25 | uint32_t |
| 26 | HostInfoNetBSD::GetMaxThreadNameLength() |
| 27 | { |
| 28 | return PTHREAD_MAX_NAMELEN_NP; |
| 29 | } |
| 30 | |
| 31 | bool |
| 32 | HostInfoNetBSD::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update) |
| 33 | { |
| 34 | struct utsname un; |
| 35 | |
| 36 | ::memset(&un, 0, sizeof(un)); |
| 37 | if (::uname(&un) < 0) |
| 38 | return false; |
| 39 | |
| 40 | /* Accept versions like 7.99.21 and 6.1_STABLE */ |
| 41 | int status = ::sscanf(un.release, "%" PRIu32 ".%" PRIu32 ".%" PRIu32, &major, &minor, &update); |
| 42 | switch(status) { |
| 43 | case 0: |
| 44 | return false; |
| 45 | case 1: |
| 46 | minor = 0; |
| 47 | /* FALLTHROUGH */ |
| 48 | case 2: |
| 49 | update = 0; |
| 50 | /* FALLTHROUGH */ |
| 51 | case 3: |
| 52 | default: |
| 53 | return true; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | bool |
| 58 | HostInfoNetBSD::GetOSBuildString(std::string &s) |
| 59 | { |
| 60 | int mib[2] = {CTL_KERN, KERN_OSREV}; |
| 61 | char osrev_str[12]; |
| 62 | int osrev = 0; |
| 63 | size_t osrev_len = sizeof(osrev); |
| 64 | |
| 65 | if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0) |
| 66 | { |
| 67 | ::snprintf(osrev_str, sizeof(osrev_str), "%-10.10d", osrev); |
| 68 | s.assign(osrev_str); |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | s.clear(); |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | bool |
| 77 | HostInfoNetBSD::GetOSKernelDescription(std::string &s) |
| 78 | { |
| 79 | struct utsname un; |
| 80 | |
| 81 | ::memset(&un, 0, sizeof(un)); |
| 82 | s.clear(); |
| 83 | |
| 84 | if (::uname(&un) < 0) |
| 85 | return false; |
| 86 | |
| 87 | s.assign(un.version); |
| 88 | |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | FileSpec |
| 93 | HostInfoNetBSD::GetProgramFileSpec() |
| 94 | { |
| 95 | static FileSpec g_program_filespec; |
| 96 | |
| 97 | if (!g_program_filespec) |
| 98 | { |
| 99 | ssize_t len; |
| 100 | static char buf[PATH_MAX]; |
| 101 | char name[PATH_MAX]; |
| 102 | |
| 103 | ::snprintf(name, PATH_MAX, "/proc/%d/exe", ::getpid()); |
| 104 | len = ::readlink(name, buf, PATH_MAX - 1); |
| 105 | if (len != -1) |
| 106 | { |
| 107 | buf[len] = '\0'; |
| 108 | g_program_filespec.SetFile(buf, false); |
| 109 | } |
| 110 | } |
| 111 | return g_program_filespec; |
| 112 | } |