Skip to content

Commit bb745a0

Browse files
authored
Merge pull request #411 from dcci/cherry-meee
Ignore generated @import statements in the expression evaluator
2 parents 2dddc0b + 836908f commit bb745a0

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,26 @@ using namespace lldb_private;
105105
class ClangExpressionParser::LLDBPreprocessorCallbacks : public PPCallbacks {
106106
ClangModulesDeclVendor &m_decl_vendor;
107107
ClangPersistentVariables &m_persistent_vars;
108+
clang::SourceManager &m_source_mgr;
108109
StreamString m_error_stream;
109110
bool m_has_errors = false;
110111

111112
public:
112113
LLDBPreprocessorCallbacks(ClangModulesDeclVendor &decl_vendor,
113-
ClangPersistentVariables &persistent_vars)
114-
: m_decl_vendor(decl_vendor), m_persistent_vars(persistent_vars) {}
114+
ClangPersistentVariables &persistent_vars,
115+
clang::SourceManager &source_mgr)
116+
: m_decl_vendor(decl_vendor), m_persistent_vars(persistent_vars),
117+
m_source_mgr(source_mgr) {}
115118

116119
void moduleImport(SourceLocation import_location, clang::ModuleIdPath path,
117120
const clang::Module * /*null*/) override {
121+
// Ignore modules that are imported in the wrapper code as these are not
122+
// loaded by the user.
123+
llvm::StringRef filename =
124+
m_source_mgr.getPresumedLoc(import_location).getFilename();
125+
if (filename == ClangExpressionSourceCode::g_prefix_file_name)
126+
return;
127+
118128
SourceModule module;
119129

120130
for (const std::pair<IdentifierInfo *, SourceLocation> &component : path)
@@ -557,8 +567,8 @@ ClangExpressionParser::ClangExpressionParser(
557567
llvm::cast<ClangPersistentVariables>(
558568
target_sp->GetPersistentExpressionStateForLanguage(
559569
lldb::eLanguageTypeC));
560-
std::unique_ptr<PPCallbacks> pp_callbacks(
561-
new LLDBPreprocessorCallbacks(*decl_vendor, *clang_persistent_vars));
570+
std::unique_ptr<PPCallbacks> pp_callbacks(new LLDBPreprocessorCallbacks(
571+
*decl_vendor, *clang_persistent_vars, m_compiler->getSourceManager()));
562572
m_pp_callbacks =
563573
static_cast<LLDBPreprocessorCallbacks *>(pp_callbacks.get());
564574
m_compiler->getPreprocessor().addPPCallbacks(std::move(pp_callbacks));

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929

3030
using namespace lldb_private;
3131

32+
#define PREFIX_NAME "<lldb wrapper prefix>"
33+
34+
const llvm::StringRef ClangExpressionSourceCode::g_prefix_file_name = PREFIX_NAME;
35+
3236
const char *ClangExpressionSourceCode::g_expression_prefix =
33-
R"(
34-
#line 1 "<lldb wrapper prefix>"
37+
"#line 1 \"" PREFIX_NAME R"("
3538
#ifndef offsetof
3639
#define offsetof(t, d) __builtin_offsetof(t, d)
3740
#endif

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class ExecutionContext;
2323

2424
class ClangExpressionSourceCode : public ExpressionSourceCode {
2525
public:
26+
/// The file name we use for the wrapper code that we inject before
27+
/// the user expression.
28+
static const llvm::StringRef g_prefix_file_name;
2629
static const char *g_expression_prefix;
2730

2831
static ClangExpressionSourceCode *CreateWrapped(llvm::StringRef filename,

0 commit comments

Comments
 (0)