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