@@ -71,6 +71,93 @@ LLDB_PLUGIN_DEFINE(SymbolFilePDB)
71
71
char SymbolFilePDB::ID;
72
72
73
73
namespace {
74
+
75
+ enum UseNativePDBReader {
76
+ eUseNativePDBReaderDefault,
77
+ eUseNativePDBReaderOn,
78
+ eUseNativePDBReaderOff,
79
+ };
80
+
81
+ constexpr OptionEnumValueElement g_native_pdb_reader_enums[] = {
82
+ {
83
+ eUseNativePDBReaderDefault,
84
+ " default" ,
85
+ " Use DIA PDB reader unless LLDB_USE_NATIVE_PDB_READER environment "
86
+ " variable is set" ,
87
+ },
88
+ {
89
+ eUseNativePDBReaderOn,
90
+ " on" ,
91
+ " Use native PDB reader" ,
92
+ },
93
+ {
94
+ eUseNativePDBReaderOff,
95
+ " off" ,
96
+ " Use DIA PDB reader" ,
97
+ },
98
+ };
99
+
100
+ #define LLDB_PROPERTIES_symbolfilepdb
101
+ #include " SymbolFilePDBProperties.inc"
102
+
103
+ enum {
104
+ #define LLDB_PROPERTIES_symbolfilepdb
105
+ #include " SymbolFilePDBPropertiesEnum.inc"
106
+ };
107
+
108
+ #if LLVM_ENABLE_DIA_SDK && defined(_WIN32)
109
+ bool ShouldUseNativeReaderByDefault () {
110
+ static bool g_use_native_by_default = true ;
111
+
112
+ static llvm::once_flag g_initialize;
113
+ llvm::call_once (g_initialize, [] {
114
+ llvm::StringRef env_value = ::getenv (" LLDB_USE_NATIVE_PDB_READER" );
115
+ if (!env_value.equals_insensitive (" on" ) &&
116
+ !env_value.equals_insensitive (" yes" ) &&
117
+ !env_value.equals_insensitive (" 1" ) &&
118
+ !env_value.equals_insensitive (" true" ))
119
+ g_use_native_by_default = false ;
120
+ });
121
+
122
+ return g_use_native_by_default;
123
+ }
124
+ #endif
125
+
126
+ class PluginProperties : public Properties {
127
+ public:
128
+ static llvm::StringRef GetSettingName () {
129
+ return SymbolFilePDB::GetPluginNameStatic ();
130
+ }
131
+
132
+ PluginProperties () {
133
+ m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName ());
134
+ m_collection_sp->Initialize (g_symbolfilepdb_properties);
135
+ }
136
+
137
+ bool UseNativeReader () const {
138
+ #if LLVM_ENABLE_DIA_SDK && defined(_WIN32)
139
+ auto value = GetPropertyAtIndexAs<UseNativePDBReader>(
140
+ ePropertyUseNativeReader, eUseNativePDBReaderDefault);
141
+ switch (value) {
142
+ case eUseNativePDBReaderOn:
143
+ return true ;
144
+ case eUseNativePDBReaderOff:
145
+ return false ;
146
+ default :
147
+ case eUseNativePDBReaderDefault:
148
+ return ShouldUseNativeReaderByDefault ();
149
+ }
150
+ #else
151
+ return true ;
152
+ #endif
153
+ }
154
+ };
155
+
156
+ PluginProperties &GetGlobalPluginProperties () {
157
+ static PluginProperties g_settings;
158
+ return g_settings;
159
+ }
160
+
74
161
lldb::LanguageType TranslateLanguage (PDB_Lang lang) {
75
162
switch (lang) {
76
163
case PDB_Lang::Cpp:
@@ -97,46 +184,43 @@ bool ShouldAddLine(uint32_t requested_line, uint32_t actual_line,
97
184
}
98
185
} // namespace
99
186
100
- static bool ShouldUseNativeReader () {
101
- #if defined(_WIN32)
102
- #if LLVM_ENABLE_DIA_SDK
103
- llvm::StringRef use_native = ::getenv (" LLDB_USE_NATIVE_PDB_READER" );
104
- if (!use_native.equals_insensitive (" on" ) &&
105
- !use_native.equals_insensitive (" yes" ) &&
106
- !use_native.equals_insensitive (" 1" ) &&
107
- !use_native.equals_insensitive (" true" ))
108
- return false ;
109
- #endif
110
- #endif
111
- return true ;
112
- }
113
-
114
187
void SymbolFilePDB::Initialize () {
115
- if (ShouldUseNativeReader ()) {
116
- npdb::SymbolFileNativePDB::Initialize ();
117
- } else {
118
- PluginManager::RegisterPlugin (GetPluginNameStatic (),
119
- GetPluginDescriptionStatic (), CreateInstance,
120
- DebuggerInitialize);
121
- }
188
+ // Initialize both but check in CreateInstance for the desired plugin
189
+ npdb::SymbolFileNativePDB::Initialize ();
190
+
191
+ PluginManager::RegisterPlugin (GetPluginNameStatic (),
192
+ GetPluginDescriptionStatic (), CreateInstance,
193
+ DebuggerInitialize);
122
194
}
123
195
124
196
void SymbolFilePDB::Terminate () {
125
- if (ShouldUseNativeReader ()) {
126
- npdb::SymbolFileNativePDB::Terminate ();
127
- } else {
128
- PluginManager::UnregisterPlugin (CreateInstance);
129
- }
197
+ npdb::SymbolFileNativePDB::Terminate ();
198
+
199
+ PluginManager::UnregisterPlugin (CreateInstance);
200
+ }
201
+
202
+ bool SymbolFilePDB::UseNativePDB () {
203
+ return GetGlobalPluginProperties ().UseNativeReader ();
130
204
}
131
205
132
- void SymbolFilePDB::DebuggerInitialize (lldb_private::Debugger &debugger) {}
206
+ void SymbolFilePDB::DebuggerInitialize (lldb_private::Debugger &debugger) {
207
+ if (!PluginManager::GetSettingForSymbolFilePlugin (
208
+ debugger, PluginProperties::GetSettingName ())) {
209
+ PluginManager::CreateSettingForSymbolFilePlugin (
210
+ debugger, GetGlobalPluginProperties ().GetValueProperties (),
211
+ " Properties for the PDB symbol-file plug-in." , true );
212
+ }
213
+ }
133
214
134
215
llvm::StringRef SymbolFilePDB::GetPluginDescriptionStatic () {
135
216
return " Microsoft PDB debug symbol file reader." ;
136
217
}
137
218
138
219
lldb_private::SymbolFile *
139
220
SymbolFilePDB::CreateInstance (ObjectFileSP objfile_sp) {
221
+ if (UseNativePDB ())
222
+ return nullptr ;
223
+
140
224
return new SymbolFilePDB (std::move (objfile_sp));
141
225
}
142
226
0 commit comments