Path: blob/main/contrib/llvm-project/lldb/source/Host/netbsd/HostInfoNetBSD.cpp
39607 views
//===-- HostInfoNetBSD.cpp ------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Host/netbsd/HostInfoNetBSD.h"910#include <cinttypes>11#include <climits>12#include <cstdio>13#include <cstring>14#include <optional>15#include <pthread.h>16#include <sys/sysctl.h>17#include <sys/types.h>18#include <sys/utsname.h>19#include <unistd.h>2021using namespace lldb_private;2223llvm::VersionTuple HostInfoNetBSD::GetOSVersion() {24struct utsname un;2526::memset(&un, 0, sizeof(un));27if (::uname(&un) < 0)28return llvm::VersionTuple();2930/* Accept versions like 7.99.21 and 6.1_STABLE */31uint32_t major, minor, update;32int status = ::sscanf(un.release, "%" PRIu32 ".%" PRIu32 ".%" PRIu32, &major,33&minor, &update);34switch (status) {35case 1:36return llvm::VersionTuple(major);37case 2:38return llvm::VersionTuple(major, minor);39case 3:40return llvm::VersionTuple(major, minor, update);41}42return llvm::VersionTuple();43}4445std::optional<std::string> HostInfoNetBSD::GetOSBuildString() {46int mib[2] = {CTL_KERN, KERN_OSREV};47int osrev = 0;48size_t osrev_len = sizeof(osrev);4950if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0)51return llvm::formatv("{0,10:10}", osrev).str();5253return std::nullopt;54}5556FileSpec HostInfoNetBSD::GetProgramFileSpec() {57static FileSpec g_program_filespec;5859if (!g_program_filespec) {60static const int name[] = {61CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME,62};63char path[MAXPATHLEN];64size_t len;6566len = sizeof(path);67if (sysctl(name, __arraycount(name), path, &len, NULL, 0) != -1) {68g_program_filespec.SetFile(path, FileSpec::Style::native);69}70}71return g_program_filespec;72}737475