diff --git a/lldb/include/lldb/Core/SourceManager.h b/lldb/include/lldb/Core/SourceManager.h --- a/lldb/include/lldb/Core/SourceManager.h +++ b/lldb/include/lldb/Core/SourceManager.h @@ -87,7 +87,7 @@ private: void CommonInitializer(const FileSpec &file_spec, Target *target); - bool IsNewerThanDebuggedExecutable(llvm::sys::TimePoint<> time); + bool IsNewerThanCurrentModule(llvm::sys::TimePoint<> time); void Update(llvm::sys::TimePoint<> mod_time); }; diff --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp --- a/lldb/source/Core/SourceManager.cpp +++ b/lldb/source/Core/SourceManager.cpp @@ -21,7 +21,10 @@ #include "lldb/Symbol/LineEntry.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Target/PathMappingList.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" +#include "lldb/Target/Thread.h" #include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/ConstString.h" #include "lldb/Utility/DataBuffer.h" @@ -532,7 +535,13 @@ // For now we check each time we want to display info for the file. auto curr_mod_time = FileSystem::Instance().GetModificationTime(m_file_spec); - if (IsNewerThanDebuggedExecutable(curr_mod_time)) + // If the source file is newer than the executable don't update, + // otherwise the source file being displayed will be different from + // the executable being ran. + // (We only want to update if the executable has been recompiled) + if (IsNewerThanCurrentModule(curr_mod_time)) + // TODO: maybe issue a: + // 'warning: Source file is more recent than executable.' ? return; if (curr_mod_time != llvm::sys::TimePoint<>() && @@ -541,31 +550,43 @@ } } -bool SourceManager::File::IsNewerThanDebuggedExecutable( +bool SourceManager::File::IsNewerThanCurrentModule( llvm::sys::TimePoint<> time) { - // Check if we are running in a debugger. DebuggerSP debugger_sp(m_debugger_wp.lock()); - if (debugger_sp) { - lldb::TargetSP target_sp(debugger_sp->GetSelectedTarget()); - if (target_sp) { - lldb::ModuleSP exec_module_sp(target_sp->GetExecutableModule()); - if (exec_module_sp) { - auto exec_module_mod_time = exec_module_sp->GetModificationTime(); - - // If the source file is newer than the executable don't update, - // otherwise the source file being displayed will be different from - // the executable being ran. - // (We only want to update if the executable has been recompiled) - if (time > exec_module_mod_time) { - // TODO: maybe issue a: - // 'warning: Source file is more recent than executable.' ? - return true; - } - } - } + if (!debugger_sp) + return false; + + lldb::TargetSP target_sp(debugger_sp->GetSelectedTarget()); + if (!target_sp) + return false; + + lldb::ProcessSP process_sp(target_sp->CalculateProcess()); + if (!process_sp) + return false; + + ThreadList &thread_list(process_sp->GetThreadList()); + + lldb::ThreadSP thread_sp(thread_list.GetSelectedThread()); + if (!thread_sp) + return false; + + lldb::StackFrameSP stackframe_sp(thread_sp->GetSelectedFrame()); + if (!stackframe_sp) + return false; + + const Address pc_addr(stackframe_sp->GetFrameCodeAddress()); + + lldb::ModuleSP current_module(pc_addr.GetModule()); + if (!current_module) + return false; + + auto current_module_mod_time = current_module->GetModificationTime(); + + if (time <= current_module_mod_time) { + return false; } - return false; + return true; } void SourceManager::File::Update(llvm::sys::TimePoint<> modification_time) {