Skip to content

Commit 5b3dd43

Browse files
authored
[LLDB][PDB] Warn if DIA plugin is requested but not available (llvm#160067)
If LLDB was built without the DIA SDK and the DIA reader is explicitly requested (through `LLDB_USE_NATIVE_PDB_READER=0` or `settings set plugin.symbol-file.pdb.reader dia`), LLDB should print a warning, because it will use the native reader in any case (llvm#159769 (comment)). This PR adds the warning and a test when LLDB is not built with the SDK on Windows. I don't think any builder runs this configuration, as there are still five failing tests. I tested this locally with and without the SDK.
1 parent 6f02969 commit 5b3dd43

File tree

3 files changed

+126
-27
lines changed

3 files changed

+126
-27
lines changed

lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "clang/Lex/Lexer.h"
1515

1616
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
17+
#include "lldb/Core/Debugger.h"
1718
#include "lldb/Core/Mangled.h"
1819
#include "lldb/Core/Module.h"
1920
#include "lldb/Core/PluginManager.h"
@@ -105,24 +106,21 @@ enum {
105106
#include "SymbolFilePDBPropertiesEnum.inc"
106107
};
107108

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-
}
109+
static const bool g_should_use_native_reader_by_default = [] {
110+
llvm::StringRef env_value = ::getenv("LLDB_USE_NATIVE_PDB_READER");
111+
112+
#if !LLVM_ENABLE_DIA_SDK || !defined(_WIN32)
113+
// if the environment value is unset, the native reader is requested
114+
if (env_value.empty())
115+
return true;
124116
#endif
125117

118+
return env_value.equals_insensitive("on") ||
119+
env_value.equals_insensitive("yes") ||
120+
env_value.equals_insensitive("1") ||
121+
env_value.equals_insensitive("true");
122+
}();
123+
126124
class PluginProperties : public Properties {
127125
public:
128126
static llvm::StringRef GetSettingName() {
@@ -136,6 +134,21 @@ class PluginProperties : public Properties {
136134

137135
bool UseNativeReader() const {
138136
#if LLVM_ENABLE_DIA_SDK && defined(_WIN32)
137+
return IsNativeReaderRequested();
138+
#else
139+
if (!IsNativeReaderRequested()) {
140+
static std::once_flag g_warning_shown;
141+
Debugger::ReportWarning(
142+
"The DIA PDB reader was explicitly requested, but LLDB was built "
143+
"without the DIA SDK. The native reader will be used instead.",
144+
{}, &g_warning_shown);
145+
}
146+
return true;
147+
#endif
148+
}
149+
150+
private:
151+
bool IsNativeReaderRequested() const {
139152
auto value =
140153
GetPropertyAtIndexAs<PDBReader>(ePropertyReader, ePDBReaderDefault);
141154
switch (value) {
@@ -144,12 +157,8 @@ class PluginProperties : public Properties {
144157
case ePDBReaderDIA:
145158
return false;
146159
default:
147-
case ePDBReaderDefault:
148-
return ShouldUseNativeReaderByDefault();
160+
return g_should_use_native_reader_by_default;
149161
}
150-
#else
151-
return true;
152-
#endif
153162
}
154163
};
155164

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// REQUIRES: !diasdk, target-windows
2+
3+
// Test plugin.symbol-file.pdb.reader setting without the DIA SDK
4+
// RUN: %build -o %t.exe -- %s
5+
// RUN: env -u LLDB_USE_NATIVE_PDB_READER %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=NO-ENV %s
6+
// RUN: env LLDB_USE_NATIVE_PDB_READER= %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=NO-ENV %s
7+
8+
// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s
9+
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV1 %s
10+
11+
// RUN: env LLDB_USE_NATIVE_PDB_READER=foo %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s
12+
// RUN: env LLDB_USE_NATIVE_PDB_READER=42 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s
13+
// RUN: env LLDB_USE_NATIVE_PDB_READER=-1 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s
14+
15+
// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb \
16+
// RUN: -o 'settings set plugin.symbol-file.pdb.reader dia' \
17+
// RUN: -o 'target create %t.exe' \
18+
// RUN: -o 'target modules dump symfile' \
19+
// RUN: 2>&1 | FileCheck --check-prefix=ENV0-SET-DIA %s
20+
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb \
21+
// RUN: -o 'settings set plugin.symbol-file.pdb.reader dia' \
22+
// RUN: -o 'target create %t.exe' \
23+
// RUN: -o 'target modules dump symfile' \
24+
// RUN: 2>&1 | FileCheck --check-prefix=ENV1-SET-DIA %s
25+
// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb \
26+
// RUN: -o 'settings set plugin.symbol-file.pdb.reader native' \
27+
// RUN: -o 'target create %t.exe' \
28+
// RUN: -o 'target modules dump symfile' \
29+
// RUN: 2>&1 | FileCheck --check-prefix=ENV0-SET-NATIVE %s
30+
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb \
31+
// RUN: -o 'settings set plugin.symbol-file.pdb.reader native' \
32+
// RUN: -o 'target create %t.exe' \
33+
// RUN: -o 'target modules dump symfile' \
34+
// RUN: 2>&1 | FileCheck --check-prefix=ENV1-SET-NATIVE %s
35+
36+
// NO-ENV-NOT: warning:
37+
// NO-ENV: (lldb) target modules dump symfile
38+
// NO-ENV: Dumping debug symbols for 1 modules.
39+
// NO-ENV: SymbolFile native-pdb
40+
41+
// ENV0: warning: The DIA PDB reader was explicitly requested, but LLDB was built without the DIA SDK. The native reader will be used instead.
42+
// ENV0: (lldb) target modules dump symfile
43+
// ENV0: Dumping debug symbols for 1 modules.
44+
// ENV0: SymbolFile native-pdb
45+
46+
// ENV1-NOT: warning:
47+
// ENV1: (lldb) target modules dump symfile
48+
// ENV1: Dumping debug symbols for 1 modules.
49+
// ENV1: SymbolFile native-pdb
50+
51+
// 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.
52+
// ENV0-SET-DIA: (lldb) target modules dump symfile
53+
// ENV0-SET-DIA: Dumping debug symbols for 1 modules.
54+
// ENV0-SET-DIA: SymbolFile native-pdb
55+
56+
// 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.
57+
// ENV1-SET-DIA: (lldb) target modules dump symfile
58+
// ENV1-SET-DIA: Dumping debug symbols for 1 modules.
59+
// ENV1-SET-DIA: SymbolFile native-pdb
60+
61+
// ENV1-SET-NATIVE-NOT: warning:
62+
// ENV0-SET-NATIVE: (lldb) target modules dump symfile
63+
// ENV0-SET-NATIVE: Dumping debug symbols for 1 modules.
64+
// ENV0-SET-NATIVE: SymbolFile native-pdb
65+
66+
// ENV1-SET-NATIVE-NOT: warning:
67+
// ENV1-SET-NATIVE: (lldb) target modules dump symfile
68+
// ENV1-SET-NATIVE: Dumping debug symbols for 1 modules.
69+
// ENV1-SET-NATIVE: SymbolFile native-pdb
70+
71+
int main() {}

lldb/test/Shell/SymbolFile/PDB/native-setting.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,68 @@
22

33
// Test plugin.symbol-file.pdb.reader setting
44
// RUN: %build -o %t.exe -- %s
5-
// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb %t.exe -o 'target modules dump symfile' | FileCheck --check-prefix=ENV0 %s
6-
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb %t.exe -o 'target modules dump symfile' | FileCheck --check-prefix=ENV1 %s
5+
// RUN: env -u LLDB_USE_NATIVE_PDB_READER %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=NO-ENV %s
6+
// RUN: env LLDB_USE_NATIVE_PDB_READER= %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=NO-ENV %s
7+
8+
// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s
9+
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV1 %s
10+
11+
// RUN: env LLDB_USE_NATIVE_PDB_READER=foo %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s
12+
// RUN: env LLDB_USE_NATIVE_PDB_READER=42 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s
13+
// RUN: env LLDB_USE_NATIVE_PDB_READER=-1 %lldb %t.exe -o 'target modules dump symfile' 2>&1 | FileCheck --check-prefix=ENV0 %s
14+
715
// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb \
816
// RUN: -o 'settings set plugin.symbol-file.pdb.reader dia' \
917
// RUN: -o 'target create %t.exe' \
1018
// RUN: -o 'target modules dump symfile' \
11-
// RUN: | FileCheck --check-prefix=ENV0-SET-DIA %s
19+
// RUN: 2>&1 | FileCheck --check-prefix=ENV0-SET-DIA %s
1220
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb \
1321
// RUN: -o 'settings set plugin.symbol-file.pdb.reader dia' \
1422
// RUN: -o 'target create %t.exe' \
1523
// RUN: -o 'target modules dump symfile' \
16-
// RUN: | FileCheck --check-prefix=ENV1-SET-DIA %s
24+
// RUN: 2>&1 | FileCheck --check-prefix=ENV1-SET-DIA %s
1725
// RUN: env LLDB_USE_NATIVE_PDB_READER=0 %lldb \
1826
// RUN: -o 'settings set plugin.symbol-file.pdb.reader native' \
1927
// RUN: -o 'target create %t.exe' \
2028
// RUN: -o 'target modules dump symfile' \
21-
// RUN: | FileCheck --check-prefix=ENV0-SET-NATIVE %s
29+
// RUN: 2>&1 | FileCheck --check-prefix=ENV0-SET-NATIVE %s
2230
// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb \
2331
// RUN: -o 'settings set plugin.symbol-file.pdb.reader native' \
2432
// RUN: -o 'target create %t.exe' \
2533
// RUN: -o 'target modules dump symfile' \
26-
// RUN: | FileCheck --check-prefix=ENV1-SET-NATIVE %s
34+
// RUN: 2>&1 | FileCheck --check-prefix=ENV1-SET-NATIVE %s
35+
36+
// NO-ENV-NOT: warning:
37+
// NO-ENV: (lldb) target modules dump symfile
38+
// NO-ENV: Dumping debug symbols for 1 modules.
39+
// NO-ENV: SymbolFile pdb
2740

41+
// ENV0-NOT: warning:
2842
// ENV0: (lldb) target modules dump symfile
2943
// ENV0: Dumping debug symbols for 1 modules.
3044
// ENV0: SymbolFile pdb
3145

46+
// ENV1-NOT: warning:
3247
// ENV1: (lldb) target modules dump symfile
3348
// ENV1: Dumping debug symbols for 1 modules.
3449
// ENV1: SymbolFile native-pdb
3550

51+
// ENV0-SET-DIA-NOT: warning:
3652
// ENV0-SET-DIA: (lldb) target modules dump symfile
3753
// ENV0-SET-DIA: Dumping debug symbols for 1 modules.
3854
// ENV0-SET-DIA: SymbolFile pdb
3955

56+
// ENV1-SET-DIA-NOT: warning:
4057
// ENV1-SET-DIA: (lldb) target modules dump symfile
4158
// ENV1-SET-DIA: Dumping debug symbols for 1 modules.
4259
// ENV1-SET-DIA: SymbolFile pdb
4360

61+
// ENV0-SET-NATIVE-NOT: warning:
4462
// ENV0-SET-NATIVE: (lldb) target modules dump symfile
4563
// ENV0-SET-NATIVE: Dumping debug symbols for 1 modules.
4664
// ENV0-SET-NATIVE: SymbolFile native-pdb
4765

66+
// ENV1-SET-NATIVE-NOT: warning:
4867
// ENV1-SET-NATIVE: (lldb) target modules dump symfile
4968
// ENV1-SET-NATIVE: Dumping debug symbols for 1 modules.
5069
// ENV1-SET-NATIVE: SymbolFile native-pdb

0 commit comments

Comments
 (0)