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