@@ -71,6 +71,93 @@ LLDB_PLUGIN_DEFINE(SymbolFilePDB)
7171char SymbolFilePDB::ID;
7272
7373namespace {
74+
75+ enum PDBReader {
76+ ePDBReaderDefault,
77+ ePDBReaderDIA,
78+ ePDBReaderNative,
79+ };
80+
81+ constexpr OptionEnumValueElement g_pdb_reader_enums[] = {
82+ {
83+ ePDBReaderDefault,
84+ " default" ,
85+ " Use DIA PDB reader unless LLDB_USE_NATIVE_PDB_READER environment "
86+ " variable is set" ,
87+ },
88+ {
89+ ePDBReaderDIA,
90+ " dia" ,
91+ " Use DIA PDB reader" ,
92+ },
93+ {
94+ ePDBReaderNative,
95+ " native" ,
96+ " Use native 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 =
140+ GetPropertyAtIndexAs<PDBReader>(ePropertyReader, ePDBReaderDefault);
141+ switch (value) {
142+ case ePDBReaderNative:
143+ return true ;
144+ case ePDBReaderDIA:
145+ return false ;
146+ default :
147+ case ePDBReaderDefault:
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+
74161lldb::LanguageType TranslateLanguage (PDB_Lang lang) {
75162 switch (lang) {
76163 case PDB_Lang::Cpp:
@@ -97,46 +184,43 @@ bool ShouldAddLine(uint32_t requested_line, uint32_t actual_line,
97184}
98185} // namespace
99186
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-
114187void 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);
122194}
123195
124196void 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 ();
130204}
131205
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+ }
133214
134215llvm::StringRef SymbolFilePDB::GetPluginDescriptionStatic () {
135216 return " Microsoft PDB debug symbol file reader." ;
136217}
137218
138219lldb_private::SymbolFile *
139220SymbolFilePDB::CreateInstance (ObjectFileSP objfile_sp) {
221+ if (UseNativePDB ())
222+ return nullptr ;
223+
140224 return new SymbolFilePDB (std::move (objfile_sp));
141225}
142226
0 commit comments