Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -105,24 +106,21 @@ enum {
#include "SymbolFilePDBPropertiesEnum.inc"
};

#if LLVM_ENABLE_DIA_SDK && defined(_WIN32)
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;
});

return g_use_native_by_default;
}
static const 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())
return true;
#endif

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:
static llvm::StringRef GetSettingName() {
Expand All @@ -136,6 +134,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);
Comment on lines +142 to +144
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors and warnings should start the first sentence with a lowercase letter, and finish the last sentence without a period, if it would end in one otherwise.

Suggested change
"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);
"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);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I forgot that. Opened #160398.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, thanks for the quick fix!

}
return true;
#endif
}

private:
bool IsNativeReaderRequested() const {
auto value =
GetPropertyAtIndexAs<PDBReader>(ePropertyReader, ePDBReaderDefault);
switch (value) {
Expand All @@ -144,12 +157,8 @@ class PluginProperties : public Properties {
case ePDBReaderDIA:
return false;
default:
case ePDBReaderDefault:
return ShouldUseNativeReaderByDefault();
return g_should_use_native_reader_by_default;
}
#else
return true;
#endif
}
};

Expand Down
71 changes: 71 additions & 0 deletions lldb/test/Shell/SymbolFile/NativePDB/native-setting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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=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' \
// 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() {}
31 changes: 25 additions & 6 deletions lldb/test/Shell/SymbolFile/PDB/native-setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,68 @@

// 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=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' \
// 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
Expand Down
Loading