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