LLDB
mainline
llvm-project
lldb
source
Host
openbsd
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
9
#include "
lldb/Host/openbsd/HostInfoOpenBSD.h
"
10
#include "lldb/Host/Config.h"
11
12
#include <climits>
13
#include <cstdio>
14
#include <cstring>
15
#include <optional>
16
#include <sys/sysctl.h>
17
#include <sys/types.h>
18
#include <sys/utsname.h>
19
#include <unistd.h>
20
21
using namespace
lldb_private
;
22
23
llvm::VersionTuple
HostInfoOpenBSD::GetOSVersion
() {
24
struct
utsname un;
25
26
::memset(&un, 0,
sizeof
(un));
27
if
(::uname(&un) < 0)
28
return
llvm::VersionTuple();
29
30
uint32_t major, minor;
31
int
status = ::sscanf(un.release,
"%"
PRIu32
".%"
PRIu32, &major, &minor);
32
switch
(status) {
33
case
1:
34
return
llvm::VersionTuple(major);
35
case
2:
36
return
llvm::VersionTuple(major, minor);
37
}
38
return
llvm::VersionTuple();
39
}
40
41
std::optional<std::string>
HostInfoOpenBSD::GetOSBuildString
() {
42
int
mib[2] = {CTL_KERN, KERN_OSREV};
43
uint32_t osrev = 0;
44
size_t
osrev_len =
sizeof
(osrev);
45
46
if
(::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0)
47
return
llvm::formatv(
"{0,8:8}"
, osrev).str();
48
49
return
std::nullopt;
50
}
51
52
FileSpec
HostInfoOpenBSD::GetProgramFileSpec
() {
53
static
FileSpec
g_program_filespec;
54
55
#if HAVE_GETEXECPATH
56
if
(!g_program_filespec) {
57
char
path[
PATH_MAX
];
58
59
if
(getexecpath(path,
sizeof
(path)) != -1)
60
g_program_filespec.
SetFile
(path, FileSpec::Style::native);
61
}
62
#endif
63
return
g_program_filespec;
64
}
HostInfoOpenBSD.h
lldb_private::FileSpec
A file utility class.
Definition
FileSpec.h:56
lldb_private::FileSpec::SetFile
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition
FileSpec.cpp:174
lldb_private::HostInfoOpenBSD::GetOSBuildString
static std::optional< std::string > GetOSBuildString()
Definition
HostInfoOpenBSD.cpp:41
lldb_private::HostInfoOpenBSD::GetOSVersion
static llvm::VersionTuple GetOSVersion()
Definition
HostInfoOpenBSD.cpp:23
lldb_private::HostInfoOpenBSD::GetProgramFileSpec
static FileSpec GetProgramFileSpec()
Definition
HostInfoOpenBSD.cpp:52
lldb_private
A class that represents a running process on the host machine.
Definition
SBAddressRange.h:14
PATH_MAX
#define PATH_MAX
Definition
windows/PosixApi.h:27
Generated on
for LLDB by
1.14.0