LLDB mainline
HostInfoOpenBSD.cpp
Go to the documentation of this file.
1//===-- HostInfoOpenBSD.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//===----------------------------------------------------------------------===//
8
10
11#include <cstdio>
12#include <cstring>
13#include <optional>
14#include <sys/sysctl.h>
15#include <sys/types.h>
16#include <sys/utsname.h>
17
18using namespace lldb_private;
19
20llvm::VersionTuple HostInfoOpenBSD::GetOSVersion() {
21 struct utsname un;
22
23 ::memset(&un, 0, sizeof(utsname));
24 if (uname(&un) < 0)
25 return llvm::VersionTuple();
26
27 unsigned major, minor;
28 if (2 == sscanf(un.release, "%u.%u", &major, &minor))
29 return llvm::VersionTuple(major, minor);
30 return llvm::VersionTuple();
31}
32
33std::optional<std::string> HostInfoOpenBSD::GetOSBuildString() {
34 int mib[2] = {CTL_KERN, KERN_OSREV};
35 char osrev_str[12];
36 uint32_t osrev = 0;
37 size_t osrev_len = sizeof(osrev);
38
39 if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0)
40 return llvm::formatv("{0,8:8}", osrev).str();
41
42 return std::nullopt;
43}
44
46 static FileSpec g_program_filespec;
47 return g_program_filespec;
48}
A file utility class.
Definition: FileSpec.h:56
static std::optional< std::string > GetOSBuildString()
static llvm::VersionTuple GetOSVersion()
static FileSpec GetProgramFileSpec()
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14