https://github.com/Nerixyz updated https://github.com/llvm/llvm-project/pull/160067
>From 4dab54fd1d003e99ac0b1014b276f0c6d24f9de2 Mon Sep 17 00:00:00 2001 From: Nerixyz <[email protected]> Date: Mon, 22 Sep 2025 12:32:08 +0200 Subject: [PATCH 1/4] [LLDB][PDB] Warn if DIA plugin is requested but not available --- .../Plugins/SymbolFile/PDB/SymbolFilePDB.cpp | 27 ++++++-- .../SymbolFile/NativePDB/native-setting.cpp | 65 +++++++++++++++++++ .../Shell/SymbolFile/PDB/native-setting.cpp | 25 +++++-- 3 files changed, 106 insertions(+), 11 deletions(-) create mode 100644 lldb/test/Shell/SymbolFile/NativePDB/native-setting.cpp diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp index 0e2ca1784e7e9..68e229b697116 100644 --- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp @@ -14,6 +14,7 @@ #include "clang/Lex/Lexer.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" +#include "lldb/Core/Debugger.h" #include "lldb/Core/Mangled.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" @@ -105,7 +106,6 @@ enum { #include "SymbolFilePDBPropertiesEnum.inc" }; -#if LLVM_ENABLE_DIA_SDK && defined(_WIN32) bool ShouldUseNativeReaderByDefault() { static bool g_use_native_by_default = true; @@ -117,11 +117,16 @@ bool ShouldUseNativeReaderByDefault() { !env_value.equals_insensitive("1") && !env_value.equals_insensitive("true")) g_use_native_by_default = false; + +#if !LLVM_ENABLE_DIA_SDK || !defined(_WIN32) + // if the environment value is unset, the native reader is requested + if (env_value.empty()) + g_use_native_by_default = true; +#endif }); return g_use_native_by_default; } -#endif class PluginProperties : public Properties { public: @@ -136,6 +141,21 @@ class PluginProperties : public Properties { bool UseNativeReader() const { #if LLVM_ENABLE_DIA_SDK && defined(_WIN32) + return IsNativeReaderRequested(); +#else + if (!IsNativeReaderRequested()) { + static std::once_flag g_warning_shown; + Debugger::ReportWarning( + "The DIA PDB reader was explicitly requested, but LLDB was built " + "without the DIA SDK. The native reader will be used instead.", + {}, &g_warning_shown); + } + return true; +#endif + } + +private: + bool IsNativeReaderRequested() const { auto value = GetPropertyAtIndexAs<PDBReader>(ePropertyReader, ePDBReaderDefault); switch (value) { @@ -147,9 +167,6 @@ class PluginProperties : public Properties { case ePDBReaderDefault: return ShouldUseNativeReaderByDefault(); } -#else - return true; -#endif } }; diff --git a/lldb/test/Shell/SymbolFile/NativePDB/native-setting.cpp b/lldb/test/Shell/SymbolFile/NativePDB/native-setting.cpp new file mode 100644 index 0000000000000..fc0ee218dd0d2 --- /dev/null +++ b/lldb/test/Shell/SymbolFile/NativePDB/native-setting.cpp @@ -0,0 +1,65 @@ +// REQUIRES: !diasdk, target-windows + +// Test plugin.symbol-file.pdb.reader setting without the DIA SDK +// RUN: %build -o %t.exe -- %s +// RUN: env -u LLDB_USE_NATIVE_PDB_READER %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=NO-ENV %s +// RUN: env LLDB_USE_NATIVE_PDB_READER= %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=NO-ENV %s +// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s +// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV1 %s +// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb \ +// RUN: -o 'settings set plugin.symbol-file.pdb.reader dia' \ +// RUN: -o 'target create %t.exe' \ +// RUN: -o 'target modules dump symfile' \ +// RUN: 2>&1 | FileCheck --check-prefix=ENV0-SET-DIA %s +// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb \ +// RUN: -o 'settings set plugin.symbol-file.pdb.reader dia' \ +// RUN: -o 'target create %t.exe' \ +// RUN: -o 'target modules dump symfile' \ +// RUN: 2>&1 | FileCheck --check-prefix=ENV1-SET-DIA %s +// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb \ +// RUN: -o 'settings set plugin.symbol-file.pdb.reader native' \ +// RUN: -o 'target create %t.exe' \ +// RUN: -o 'target modules dump symfile' \ +// RUN: 2>&1 | FileCheck --check-prefix=ENV0-SET-NATIVE %s +// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb \ +// RUN: -o 'settings set plugin.symbol-file.pdb.reader native' \ +// RUN: -o 'target create %t.exe' \ +// RUN: -o 'target modules dump symfile' \ +// RUN: 2>&1 | FileCheck --check-prefix=ENV1-SET-NATIVE %s + +// NO-ENV-NOT: warning: +// NO-ENV: (lldb) target modules dump symfile +// NO-ENV: Dumping debug symbols for 1 modules. +// NO-ENV: SymbolFile native-pdb + +// ENV0: warning: The DIA PDB reader was explicitly requested, but LLDB was built without the DIA SDK. The native reader will be used instead. +// ENV0: (lldb) target modules dump symfile +// ENV0: Dumping debug symbols for 1 modules. +// ENV0: SymbolFile native-pdb + +// ENV1-NOT: warning: +// ENV1: (lldb) target modules dump symfile +// ENV1: Dumping debug symbols for 1 modules. +// ENV1: SymbolFile native-pdb + +// ENV0-SET-DIA: warning: The DIA PDB reader was explicitly requested, but LLDB was built without the DIA SDK. The native reader will be used instead. +// ENV0-SET-DIA: (lldb) target modules dump symfile +// ENV0-SET-DIA: Dumping debug symbols for 1 modules. +// ENV0-SET-DIA: SymbolFile native-pdb + +// ENV1-SET-DIA: warning: The DIA PDB reader was explicitly requested, but LLDB was built without the DIA SDK. The native reader will be used instead. +// ENV1-SET-DIA: (lldb) target modules dump symfile +// ENV1-SET-DIA: Dumping debug symbols for 1 modules. +// ENV1-SET-DIA: SymbolFile native-pdb + +// ENV1-SET-NATIVE-NOT: warning: +// ENV0-SET-NATIVE: (lldb) target modules dump symfile +// ENV0-SET-NATIVE: Dumping debug symbols for 1 modules. +// ENV0-SET-NATIVE: SymbolFile native-pdb + +// ENV1-SET-NATIVE-NOT: warning: +// ENV1-SET-NATIVE: (lldb) target modules dump symfile +// ENV1-SET-NATIVE: Dumping debug symbols for 1 modules. +// ENV1-SET-NATIVE: SymbolFile native-pdb + +int main() {} diff --git a/lldb/test/Shell/SymbolFile/PDB/native-setting.cpp b/lldb/test/Shell/SymbolFile/PDB/native-setting.cpp index a3077252f08f1..750a61666912d 100644 --- a/lldb/test/Shell/SymbolFile/PDB/native-setting.cpp +++ b/lldb/test/Shell/SymbolFile/PDB/native-setting.cpp @@ -2,49 +2,62 @@ // Test plugin.symbol-file.pdb.reader setting // RUN: %build -o %t.exe -- %s -// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb %t.exe -o 'target modules dump symfile' | FileCheck --check-prefix=ENV0 %s -// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb %t.exe -o 'target modules dump symfile' | FileCheck --check-prefix=ENV1 %s +// RUN: env -u LLDB_USE_NATIVE_PDB_READER %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=NO-ENV %s +// RUN: env LLDB_USE_NATIVE_PDB_READER= %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=NO-ENV %s +// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s +// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV1 %s // RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb \ // RUN: -o 'settings set plugin.symbol-file.pdb.reader dia' \ // RUN: -o 'target create %t.exe' \ // RUN: -o 'target modules dump symfile' \ -// RUN: | FileCheck --check-prefix=ENV0-SET-DIA %s +// RUN: 2>&1 | FileCheck --check-prefix=ENV0-SET-DIA %s // RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb \ // RUN: -o 'settings set plugin.symbol-file.pdb.reader dia' \ // RUN: -o 'target create %t.exe' \ // RUN: -o 'target modules dump symfile' \ -// RUN: | FileCheck --check-prefix=ENV1-SET-DIA %s +// RUN: 2>&1 | FileCheck --check-prefix=ENV1-SET-DIA %s // RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb \ // RUN: -o 'settings set plugin.symbol-file.pdb.reader native' \ // RUN: -o 'target create %t.exe' \ // RUN: -o 'target modules dump symfile' \ -// RUN: | FileCheck --check-prefix=ENV0-SET-NATIVE %s +// RUN: 2>&1 | FileCheck --check-prefix=ENV0-SET-NATIVE %s // RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb \ // RUN: -o 'settings set plugin.symbol-file.pdb.reader native' \ // RUN: -o 'target create %t.exe' \ // RUN: -o 'target modules dump symfile' \ -// RUN: | FileCheck --check-prefix=ENV1-SET-NATIVE %s +// RUN: 2>&1 | FileCheck --check-prefix=ENV1-SET-NATIVE %s +// NO-ENV-NOT: warning: +// NO-ENV: (lldb) target modules dump symfile +// NO-ENV: Dumping debug symbols for 1 modules. +// NO-ENV: SymbolFile pdb + +// ENV0-NOT: warning: // ENV0: (lldb) target modules dump symfile // ENV0: Dumping debug symbols for 1 modules. // ENV0: SymbolFile pdb +// ENV1-NOT: warning: // ENV1: (lldb) target modules dump symfile // ENV1: Dumping debug symbols for 1 modules. // ENV1: SymbolFile native-pdb +// ENV0-SET-DIA-NOT: warning: // ENV0-SET-DIA: (lldb) target modules dump symfile // ENV0-SET-DIA: Dumping debug symbols for 1 modules. // ENV0-SET-DIA: SymbolFile pdb +// ENV1-SET-DIA-NOT: warning: // ENV1-SET-DIA: (lldb) target modules dump symfile // ENV1-SET-DIA: Dumping debug symbols for 1 modules. // ENV1-SET-DIA: SymbolFile pdb +// ENV0-SET-NATIVE-NOT: warning: // ENV0-SET-NATIVE: (lldb) target modules dump symfile // ENV0-SET-NATIVE: Dumping debug symbols for 1 modules. // ENV0-SET-NATIVE: SymbolFile native-pdb +// ENV1-SET-NATIVE-NOT: warning: // ENV1-SET-NATIVE: (lldb) target modules dump symfile // ENV1-SET-NATIVE: Dumping debug symbols for 1 modules. // ENV1-SET-NATIVE: SymbolFile native-pdb >From c4927f334dea26331f7a8b15471679323d728b00 Mon Sep 17 00:00:00 2001 From: Nerixyz <[email protected]> Date: Mon, 22 Sep 2025 12:47:02 +0200 Subject: [PATCH 2/4] fix: use `default` in switch If `case ePDBReaderDefault` and `default` is used, Clang and GCC complain. If only `case ePDBReaderDefault` is used, MSVC complains. --- lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp index 68e229b697116..91bfe5d052b89 100644 --- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp @@ -164,7 +164,6 @@ class PluginProperties : public Properties { case ePDBReaderDIA: return false; default: - case ePDBReaderDefault: return ShouldUseNativeReaderByDefault(); } } >From 482623b93fed2aa61cb8fb2367afad0640038eee Mon Sep 17 00:00:00 2001 From: Nerixyz <[email protected]> Date: Mon, 22 Sep 2025 19:29:45 +0200 Subject: [PATCH 3/4] fix: use lambda for static --- .../Plugins/SymbolFile/PDB/SymbolFilePDB.cpp | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp index 91bfe5d052b89..d806e97912e81 100644 --- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp @@ -106,27 +106,20 @@ enum { #include "SymbolFilePDBPropertiesEnum.inc" }; -bool ShouldUseNativeReaderByDefault() { - static bool g_use_native_by_default = true; - - static llvm::once_flag g_initialize; - llvm::call_once(g_initialize, [] { - llvm::StringRef env_value = ::getenv("LLDB_USE_NATIVE_PDB_READER"); - if (!env_value.equals_insensitive("on") && - !env_value.equals_insensitive("yes") && - !env_value.equals_insensitive("1") && - !env_value.equals_insensitive("true")) - g_use_native_by_default = false; +static bool g_should_use_native_reader_by_default = [] { + llvm::StringRef env_value = ::getenv("LLDB_USE_NATIVE_PDB_READER"); #if !LLVM_ENABLE_DIA_SDK || !defined(_WIN32) - // if the environment value is unset, the native reader is requested - if (env_value.empty()) - g_use_native_by_default = true; + // if the environment value is unset, the native reader is requested + if (env_value.empty()) + return true; #endif - }); - return g_use_native_by_default; -} + return env_value.equals_insensitive("on") || + env_value.equals_insensitive("yes") || + env_value.equals_insensitive("1") || + env_value.equals_insensitive("true"); +}(); class PluginProperties : public Properties { public: @@ -164,7 +157,7 @@ class PluginProperties : public Properties { case ePDBReaderDIA: return false; default: - return ShouldUseNativeReaderByDefault(); + return g_should_use_native_reader_by_default; } } }; >From 3933e2d21cccbdd8ecb7bbc061c8984518a06a84 Mon Sep 17 00:00:00 2001 From: Nerixyz <[email protected]> Date: Mon, 22 Sep 2025 19:30:00 +0200 Subject: [PATCH 4/4] test: add checks for non-booleanish values --- lldb/test/Shell/SymbolFile/NativePDB/native-setting.cpp | 6 ++++++ lldb/test/Shell/SymbolFile/PDB/native-setting.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lldb/test/Shell/SymbolFile/NativePDB/native-setting.cpp b/lldb/test/Shell/SymbolFile/NativePDB/native-setting.cpp index fc0ee218dd0d2..41ddba746b4ac 100644 --- a/lldb/test/Shell/SymbolFile/NativePDB/native-setting.cpp +++ b/lldb/test/Shell/SymbolFile/NativePDB/native-setting.cpp @@ -4,8 +4,14 @@ // RUN: %build -o %t.exe -- %s // RUN: env -u LLDB_USE_NATIVE_PDB_READER %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=NO-ENV %s // RUN: env LLDB_USE_NATIVE_PDB_READER= %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=NO-ENV %s + // RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s // RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV1 %s + +// RUN: env LLDB_USE_NATIVE_PDB_READER=foo %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s +// RUN: env LLDB_USE_NATIVE_PDB_READER=42 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s +// RUN: env LLDB_USE_NATIVE_PDB_READER=-1 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s + // RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb \ // RUN: -o 'settings set plugin.symbol-file.pdb.reader dia' \ // RUN: -o 'target create %t.exe' \ diff --git a/lldb/test/Shell/SymbolFile/PDB/native-setting.cpp b/lldb/test/Shell/SymbolFile/PDB/native-setting.cpp index 750a61666912d..f5e54592b0b31 100644 --- a/lldb/test/Shell/SymbolFile/PDB/native-setting.cpp +++ b/lldb/test/Shell/SymbolFile/PDB/native-setting.cpp @@ -4,8 +4,14 @@ // RUN: %build -o %t.exe -- %s // RUN: env -u LLDB_USE_NATIVE_PDB_READER %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=NO-ENV %s // RUN: env LLDB_USE_NATIVE_PDB_READER= %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=NO-ENV %s + // RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s // RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV1 %s + +// RUN: env LLDB_USE_NATIVE_PDB_READER=foo %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s +// RUN: env LLDB_USE_NATIVE_PDB_READER=42 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s +// RUN: env LLDB_USE_NATIVE_PDB_READER=-1 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s + // RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb \ // RUN: -o 'settings set plugin.symbol-file.pdb.reader dia' \ // RUN: -o 'target create %t.exe' \ _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
