LLDB mainline
UserIDResolver.cpp
Go to the documentation of this file.
1//===-- UserIDResolver.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/ManagedStatic.h"
11#include <optional>
12
13using namespace lldb_private;
14
16
17std::optional<llvm::StringRef> UserIDResolver::Get(
18 id_t id, Map &cache,
19 std::optional<std::string> (UserIDResolver::*do_get)(id_t)) {
20
21 std::lock_guard<std::mutex> guard(m_mutex);
22 auto iter_bool = cache.try_emplace(id, std::nullopt);
23 if (iter_bool.second)
24 iter_bool.first->second = (this->*do_get)(id);
25 if (iter_bool.first->second)
26 return llvm::StringRef(*iter_bool.first->second);
27 return std::nullopt;
28}
29
30namespace {
31class NoopResolver : public UserIDResolver {
32protected:
33 std::optional<std::string> DoGetUserName(id_t uid) override {
34 return std::nullopt;
35 }
36
37 std::optional<std::string> DoGetGroupName(id_t gid) override {
38 return std::nullopt;
39 }
40};
41} // namespace
42
43static llvm::ManagedStatic<NoopResolver> g_noop_resolver;
44
static llvm::ManagedStatic< NoopResolver > g_noop_resolver
An abstract interface for things that know how to map numeric user/group IDs into names.
static UserIDResolver & GetNoopResolver()
Returns a resolver which returns a failure value for each query.
llvm::DenseMap< id_t, std::optional< std::string > > Map
std::optional< llvm::StringRef > Get(id_t id, Map &cache, std::optional< std::string >(UserIDResolver::*do_get)(id_t))
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14