Coverage Report

Created: 2022-01-15 10:30

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Utility/Environment.h
Line
Count
Source (jump to first uncovered line)
1
//===-- Environment.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_ENVIRONMENT_H
10
#define LLDB_UTILITY_ENVIRONMENT_H
11
12
#include "llvm/ADT/StringMap.h"
13
#include "llvm/Support/Allocator.h"
14
#include "llvm/Support/FormatProviders.h"
15
16
namespace lldb_private {
17
18
class Environment : private llvm::StringMap<std::string> {
19
  using Base = llvm::StringMap<std::string>;
20
21
public:
22
  class Envp {
23
  public:
24
    Envp(Envp &&RHS) = default;
25
3.02k
    Envp &operator=(Envp &&RHS) = default;
26
27
6.60k
    char *const *get() const { return Data; }
28
6.60k
    operator char *const *() const { return get(); }
29
30
  private:
31
    explicit Envp(const Environment &Env);
32
    char *make_entry(llvm::StringRef Key, llvm::StringRef Value);
33
    Envp(const Envp &) = delete;
34
    Envp &operator=(const Envp &) = delete;
35
    friend class Environment;
36
37
    llvm::BumpPtrAllocator Allocator;
38
    char **Data;
39
  };
40
41
  using Base::const_iterator;
42
  using Base::iterator;
43
  using Base::value_type;
44
45
  using Base::begin;
46
  using Base::clear;
47
  using Base::count;
48
  using Base::empty;
49
  using Base::end;
50
  using Base::erase;
51
  using Base::find;
52
  using Base::insert;
53
  using Base::insert_or_assign;
54
  using Base::lookup;
55
  using Base::size;
56
  using Base::try_emplace;
57
  using Base::operator[];
58
59
61.4k
  Environment() {}
60
10.2k
  Environment(const Environment &RHS) : Base(RHS) {}
61
990
  Environment(Environment &&RHS) : Base(std::move(RHS)) {}
62
  Environment(char *const *Env)
63
14.0k
      : Environment(const_cast<const char *const *>(Env)) {}
Unexecuted instantiation: lldb_private::Environment::Environment(char* const*)
lldb_private::Environment::Environment(char* const*)
Line
Count
Source
63
14.0k
      : Environment(const_cast<const char *const *>(Env)) {}
64
  Environment(const char *const *Env);
65
66
18.6k
  Environment &operator=(Environment RHS) {
67
18.6k
    Base::operator=(std::move(RHS));
68
18.6k
    return *this;
69
18.6k
  }
70
71
269k
  std::pair<iterator, bool> insert(llvm::StringRef KeyEqValue) {
72
269k
    auto Split = KeyEqValue.split('=');
73
269k
    return insert(std::make_pair(Split.first, std::string(Split.second)));
74
269k
  }
75
76
  void insert(iterator first, iterator last);
77
78
11.0k
  Envp getEnvp() const { return Envp(*this); }
79
80
54
  static std::string compose(const value_type &KeyValue) {
81
54
    return (KeyValue.first() + "=" + KeyValue.second).str();
82
54
  }
83
};
84
85
} // namespace lldb_private
86
87
namespace llvm {
88
template <> struct format_provider<lldb_private::Environment> {
89
  static void format(const lldb_private::Environment &Env, raw_ostream &Stream,
90
2
                     StringRef Style) {
91
2
    for (const auto &KV : Env)
92
0
      Stream << "env[" << KV.first() << "] = " << KV.second << "\n";
93
2
  }
94
};
95
} // namespace llvm
96
97
#endif // LLDB_UTILITY_ENVIRONMENT_H