/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Core/UserSettingsController.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- UserSettingsController.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 | | |
9 | | #include "lldb/Core/UserSettingsController.h" |
10 | | |
11 | | #include "lldb/Interpreter/OptionValueProperties.h" |
12 | | #include "lldb/Utility/Status.h" |
13 | | #include "lldb/Utility/Stream.h" |
14 | | |
15 | | #include <memory> |
16 | | |
17 | | namespace lldb_private { |
18 | | class CommandInterpreter; |
19 | | } |
20 | | namespace lldb_private { |
21 | | class ConstString; |
22 | | } |
23 | | namespace lldb_private { |
24 | | class ExecutionContext; |
25 | | } |
26 | | namespace lldb_private { |
27 | | class Property; |
28 | | } |
29 | | |
30 | | using namespace lldb; |
31 | | using namespace lldb_private; |
32 | | |
33 | | lldb::OptionValueSP |
34 | | Properties::GetPropertyValue(const ExecutionContext *exe_ctx, |
35 | 57 | llvm::StringRef path, Status &error) const { |
36 | 57 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
37 | 57 | if (properties_sp) |
38 | 57 | return properties_sp->GetSubValue(exe_ctx, path, error); |
39 | 0 | return lldb::OptionValueSP(); |
40 | 57 | } |
41 | | |
42 | | Status Properties::SetPropertyValue(const ExecutionContext *exe_ctx, |
43 | | VarSetOperationType op, |
44 | | llvm::StringRef path, |
45 | 26.5k | llvm::StringRef value) { |
46 | 26.5k | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
47 | 26.5k | if (properties_sp) |
48 | 26.5k | return properties_sp->SetSubValue(exe_ctx, op, path, value); |
49 | 0 | Status error; |
50 | 0 | error.SetErrorString("no properties"); |
51 | 0 | return error; |
52 | 26.5k | } |
53 | | |
54 | | void Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx, |
55 | | Stream &strm, uint32_t dump_mask, |
56 | 6 | bool is_json) { |
57 | 6 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
58 | 6 | if (!properties_sp) |
59 | 0 | return; |
60 | | |
61 | 6 | if (is_json) { |
62 | 1 | llvm::json::Value json = properties_sp->ToJSON(exe_ctx); |
63 | 1 | strm.Printf("%s", llvm::formatv("{0:2}", json).str().c_str()); |
64 | 1 | } else |
65 | 5 | properties_sp->DumpValue(exe_ctx, strm, dump_mask); |
66 | 6 | } |
67 | | |
68 | | void Properties::DumpAllDescriptions(CommandInterpreter &interpreter, |
69 | 1 | Stream &strm) const { |
70 | 1 | strm.PutCString("Top level variables:\n\n"); |
71 | | |
72 | 1 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
73 | 1 | if (properties_sp) |
74 | 1 | return properties_sp->DumpAllDescriptions(interpreter, strm); |
75 | 1 | } |
76 | | |
77 | | Status Properties::DumpPropertyValue(const ExecutionContext *exe_ctx, |
78 | | Stream &strm, |
79 | | llvm::StringRef property_path, |
80 | 105 | uint32_t dump_mask, bool is_json) { |
81 | 105 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
82 | 105 | if (properties_sp) { |
83 | 105 | return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path, |
84 | 105 | dump_mask, is_json); |
85 | 105 | } |
86 | 0 | Status error; |
87 | 0 | error.SetErrorString("empty property list"); |
88 | 0 | return error; |
89 | 105 | } |
90 | | |
91 | | size_t |
92 | | Properties::Apropos(llvm::StringRef keyword, |
93 | 7 | std::vector<const Property *> &matching_properties) const { |
94 | 7 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
95 | 7 | if (properties_sp) { |
96 | 7 | properties_sp->Apropos(keyword, matching_properties); |
97 | 7 | } |
98 | 7 | return matching_properties.size(); |
99 | 7 | } |
100 | | |
101 | 96.1k | llvm::StringRef Properties::GetExperimentalSettingsName() { |
102 | 96.1k | static constexpr llvm::StringLiteral g_experimental("experimental"); |
103 | 96.1k | return g_experimental; |
104 | 96.1k | } |
105 | | |
106 | 57.1k | bool Properties::IsSettingExperimental(llvm::StringRef setting) { |
107 | 57.1k | if (setting.empty()) |
108 | 0 | return false; |
109 | | |
110 | 57.1k | llvm::StringRef experimental = GetExperimentalSettingsName(); |
111 | 57.1k | size_t dot_pos = setting.find_first_of('.'); |
112 | 57.1k | return setting.take_front(dot_pos) == experimental; |
113 | 57.1k | } |