LLDB  mainline
HostInfoFreeBSD.cpp
Go to the documentation of this file.
1 //===-- HostInfoFreeBSD.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 #include "llvm/Support/FormatVariadic.h"
11 #include <cstdio>
12 #include <cstring>
13 #include <sys/sysctl.h>
14 #include <sys/types.h>
15 #include <sys/utsname.h>
16 #include <unistd.h>
17 
18 using namespace lldb_private;
19 
20 llvm::VersionTuple HostInfoFreeBSD::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 
33 llvm::Optional<std::string> HostInfoFreeBSD::GetOSBuildString() {
34  int mib[2] = {CTL_KERN, KERN_OSREV};
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  if (!g_program_filespec) {
47  int exe_path_mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid()};
48  char exe_path[PATH_MAX];
49  size_t exe_path_size = sizeof(exe_path);
50  if (sysctl(exe_path_mib, 4, exe_path, &exe_path_size, NULL, 0) == 0)
51  g_program_filespec.SetFile(exe_path, FileSpec::Style::native);
52  }
53  return g_program_filespec;
54 }
lldb_private::HostInfoFreeBSD::GetOSVersion
static llvm::VersionTuple GetOSVersion()
Definition: HostInfoFreeBSD.cpp:20
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::HostInfoFreeBSD::GetProgramFileSpec
static FileSpec GetProgramFileSpec()
Definition: HostInfoFreeBSD.cpp:44
uint32_t
HostInfoFreeBSD.h
lldb_private::HostInfoFreeBSD::GetOSBuildString
static llvm::Optional< std::string > GetOSBuildString()
Definition: HostInfoFreeBSD.cpp:33
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::FileSpec::SetFile
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition: FileSpec.cpp:174
PATH_MAX
#define PATH_MAX
Definition: windows/PosixApi.h:25