Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Host / netbsd / HostInfoNetBSD.cpp
blob0de4f2530bbaa96944eb45914584aea8d9349b64
1 //===-- HostInfoNetBSD.cpp ------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Host/netbsd/HostInfoNetBSD.h"
11 #include <cinttypes>
12 #include <climits>
13 #include <cstdio>
14 #include <cstring>
15 #include <optional>
16 #include <pthread.h>
17 #include <sys/sysctl.h>
18 #include <sys/types.h>
19 #include <sys/utsname.h>
20 #include <unistd.h>
22 using namespace lldb_private;
24 llvm::VersionTuple HostInfoNetBSD::GetOSVersion() {
25 struct utsname un;
27 ::memset(&un, 0, sizeof(un));
28 if (::uname(&un) < 0)
29 return llvm::VersionTuple();
31 /* Accept versions like 7.99.21 and 6.1_STABLE */
32 uint32_t major, minor, update;
33 int status = ::sscanf(un.release, "%" PRIu32 ".%" PRIu32 ".%" PRIu32, &major,
34 &minor, &update);
35 switch (status) {
36 case 1:
37 return llvm::VersionTuple(major);
38 case 2:
39 return llvm::VersionTuple(major, minor);
40 case 3:
41 return llvm::VersionTuple(major, minor, update);
43 return llvm::VersionTuple();
46 std::optional<std::string> HostInfoNetBSD::GetOSBuildString() {
47 int mib[2] = {CTL_KERN, KERN_OSREV};
48 char osrev_str[12];
49 int osrev = 0;
50 size_t osrev_len = sizeof(osrev);
52 if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0)
53 return llvm::formatv("{0,10:10}", osrev).str();
55 return std::nullopt;
58 FileSpec HostInfoNetBSD::GetProgramFileSpec() {
59 static FileSpec g_program_filespec;
61 if (!g_program_filespec) {
62 static const int name[] = {
63 CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME,
65 char path[MAXPATHLEN];
66 size_t len;
68 len = sizeof(path);
69 if (sysctl(name, __arraycount(name), path, &len, NULL, 0) != -1) {
70 g_program_filespec.SetFile(path, FileSpec::Style::native);
73 return g_program_filespec;