LLDB mainline
UserIDResolver.h
Go to the documentation of this file.
1//===-- UserIDResolver.h ----------------------------------------*- C++ -*-===//
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#ifndef LLDB_UTILITY_USERIDRESOLVER_H
10#define LLDB_UTILITY_USERIDRESOLVER_H
11
12#include "llvm/ADT/DenseMap.h"
13#include "llvm/ADT/StringRef.h"
14#include <mutex>
15#include <optional>
16
17namespace lldb_private {
18
19/// An abstract interface for things that know how to map numeric user/group IDs
20/// into names. It caches the resolved names to avoid repeating expensive
21/// queries. The cache is internally protected by a mutex, so concurrent queries
22/// are safe.
24public:
25 typedef uint32_t id_t;
26 virtual ~UserIDResolver(); // anchor
27
28 std::optional<llvm::StringRef> GetUserName(id_t uid) {
30 }
31 std::optional<llvm::StringRef> GetGroupName(id_t gid) {
33 }
34
35 /// Returns a resolver which returns a failure value for each query. Useful as
36 /// a fallback value for the case when we know all lookups will fail.
38
39protected:
40 virtual std::optional<std::string> DoGetUserName(id_t uid) = 0;
41 virtual std::optional<std::string> DoGetGroupName(id_t gid) = 0;
42
43private:
44 using Map = llvm::DenseMap<id_t, std::optional<std::string>>;
45
46 std::optional<llvm::StringRef>
47 Get(id_t id, Map &cache,
48 std::optional<std::string> (UserIDResolver::*do_get)(id_t));
49
50 std::mutex m_mutex;
53};
54
55} // namespace lldb_private
56
57#endif // LLDB_UTILITY_USERIDRESOLVER_H
An abstract interface for things that know how to map numeric user/group IDs into names.
std::optional< llvm::StringRef > GetGroupName(id_t gid)
virtual std::optional< std::string > DoGetGroupName(id_t gid)=0
static UserIDResolver & GetNoopResolver()
Returns a resolver which returns a failure value for each query.
virtual std::optional< std::string > DoGetUserName(id_t uid)=0
llvm::DenseMap< id_t, std::optional< std::string > > Map
std::optional< llvm::StringRef > GetUserName(id_t uid)
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