From 60e2c6aa433e6cbb3eb13377c9e8904209416267 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 30 Nov 2011 23:18:53 +0000 Subject: [PATCH] rdar://problem/10501020 ClangASTSource::~ClangASTSource() was calling ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(); which had the side effect of deleting this very ClangASTSource instance. Not good. Change it to // We are in the process of destruction, don't create clang ast context on demand // by passing false to Target::GetScratchClangASTContext(create_on_demand). ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(false); The Target::GetScratchClangASTContext(bool create_on_demand=true) has a new signature. llvm-svn: 145537 --- lldb/include/lldb/Target/Target.h | 2 +- lldb/source/Expression/ClangASTSource.cpp | 4 +++- lldb/source/Target/Target.cpp | 4 ++-- lldb/test/functionalities/load_unload/TestLoadUnload.py | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 5f99957e54d3..70ed0434c6c1 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -799,7 +799,7 @@ public: GetImageSearchPathList (); ClangASTContext * - GetScratchClangASTContext(); + GetScratchClangASTContext(bool create_on_demand=true); ClangASTImporter * GetClangASTImporter(); diff --git a/lldb/source/Expression/ClangASTSource.cpp b/lldb/source/Expression/ClangASTSource.cpp index db08539b9776..ca97fc19d34f 100644 --- a/lldb/source/Expression/ClangASTSource.cpp +++ b/lldb/source/Expression/ClangASTSource.cpp @@ -27,7 +27,9 @@ ClangASTSource::~ClangASTSource() { m_ast_importer->ForgetDestination(m_ast_context); - ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(); + // We are in the process of destruction, don't create clang ast context on demand + // by passing false to Target::GetScratchClangASTContext(create_on_demand). + ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(false); if (!scratch_clang_ast_context) return; diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 53e8ccfdac69..978ab5ec4d5c 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1335,10 +1335,10 @@ Target::ImageSearchPathsChanged } ClangASTContext * -Target::GetScratchClangASTContext() +Target::GetScratchClangASTContext(bool create_on_demand) { // Now see if we know the target triple, and if so, create our scratch AST context: - if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid()) + if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand) { m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str())); m_scratch_ast_source_ap.reset (new ClangASTSource(GetSP())); diff --git a/lldb/test/functionalities/load_unload/TestLoadUnload.py b/lldb/test/functionalities/load_unload/TestLoadUnload.py index 20b5d717cf2f..fca156b84ade 100644 --- a/lldb/test/functionalities/load_unload/TestLoadUnload.py +++ b/lldb/test/functionalities/load_unload/TestLoadUnload.py @@ -49,7 +49,7 @@ class LoadUnloadTestCase(TestBase): # Add teardown hook to clear image-search-paths after the test. # rdar://problem/10501020 # Uncomment the following to reproduce 10501020. - #self.addTearDownHook(lambda: self.runCmd("target modules search-paths clear")) + self.addTearDownHook(lambda: self.runCmd("target modules search-paths clear")) self.expect("target modules search-paths list", substrs = [os.getcwd(), new_dir])