LLDB
mainline
llvm-project
lldb
source
Host
freebsd
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
9
#include "
lldb/Host/freebsd/HostInfoFreeBSD.h
"
10
#include "llvm/Support/FormatVariadic.h"
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
#include <unistd.h>
18
19
using namespace
lldb_private
;
20
21
llvm::VersionTuple
HostInfoFreeBSD::GetOSVersion
() {
22
struct
utsname un;
23
24
::memset(&un, 0,
sizeof
(utsname));
25
if
(uname(&un) < 0)
26
return
llvm::VersionTuple();
27
28
unsigned
major, minor;
29
if
(2 == sscanf(un.release,
"%u.%u"
, &major, &minor))
30
return
llvm::VersionTuple(major, minor);
31
return
llvm::VersionTuple();
32
}
33
34
std::optional<std::string>
HostInfoFreeBSD::GetOSBuildString
() {
35
int
mib[2] = {CTL_KERN, KERN_OSREV};
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
45
FileSpec
HostInfoFreeBSD::GetProgramFileSpec
() {
46
static
FileSpec
g_program_filespec;
47
if
(!g_program_filespec) {
48
int
exe_path_mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid()};
49
char
exe_path[
PATH_MAX
];
50
size_t
exe_path_size =
sizeof
(exe_path);
51
if
(sysctl(exe_path_mib, 4, exe_path, &exe_path_size, NULL, 0) == 0)
52
g_program_filespec.
SetFile
(exe_path, FileSpec::Style::native);
53
}
54
return
g_program_filespec;
55
}
HostInfoFreeBSD.h
lldb_private::FileSpec
A file utility class.
Definition
FileSpec.h:57
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::HostInfoFreeBSD::GetOSVersion
static llvm::VersionTuple GetOSVersion()
Definition
HostInfoFreeBSD.cpp:21
lldb_private::HostInfoFreeBSD::GetOSBuildString
static std::optional< std::string > GetOSBuildString()
Definition
HostInfoFreeBSD.cpp:34
lldb_private::HostInfoFreeBSD::GetProgramFileSpec
static FileSpec GetProgramFileSpec()
Definition
HostInfoFreeBSD.cpp:45
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:25
Generated on
for LLDB by
1.14.0