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