From a9d53d9e7e24ac82e150d792f05ea45bf8e497a1 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Tue, 22 Nov 2016 23:06:09 -0500 Subject: [PATCH] Debugger: Fix regression introduced in hrev50534. FunctionInstance: - Add new state FUNCTION_SOURCE_SUPPRESSED. This signals that the user explicitly forced disassembly to be loaded despite source code being available. LoadSourceCodeJob: - When forced to disassembly, use the above suppressed state accordingly. SourceView/TeamWindow/TeamDebugger: - Adjust to take new state into account as needed. TeamDebugInfo::GetActiveSourceCode: - When looking at a function to decide whether to return line information based on source or disassembly, first examine the source code state. If the source has never been loaded for that function, but we have it available, set it on the function at that point. This lazily addresses the fact that LoadSourceCodeJob is called on behalf of a specific function, and consequently only sets the source code onto that function, and not all others present in the same file. This allows us to differentiate between the case where a function doesn't have source code available at all, versus a function that has simply been forced to disassembly view at this point in time. The primary symptom of the above issue was that attempting to set a breakpoint outside of the currently active function, but within the same file would result in the breakpoints view indicating that the breakpoint was at line 0 rather than the appropriate line, and breakpoints would also not be drawn in the source view for such locations. Thanks to Humdinger for the heads up! --- .../debugger/debug_info/FunctionInstance.h | 4 +++- .../gui/team_window/SourceView.cpp | 7 ++++--- .../gui/team_window/TeamWindow.cpp | 9 ++++++--- .../debugger/controllers/TeamDebugger.cpp | 5 +++-- .../debugger/debug_info/TeamDebugInfo.cpp | 20 +++++++++++++++++++ src/kits/debugger/jobs/LoadSourceCodeJob.cpp | 6 +++--- 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/headers/private/debugger/debug_info/FunctionInstance.h b/headers/private/debugger/debug_info/FunctionInstance.h index 6af6832b21..11d8f67cd9 100644 --- a/headers/private/debugger/debug_info/FunctionInstance.h +++ b/headers/private/debugger/debug_info/FunctionInstance.h @@ -1,5 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2016, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #ifndef FUNCTION_INSTANCE_H @@ -14,7 +15,8 @@ enum function_source_state { FUNCTION_SOURCE_NOT_LOADED, FUNCTION_SOURCE_LOADING, FUNCTION_SOURCE_LOADED, - FUNCTION_SOURCE_UNAVAILABLE + FUNCTION_SOURCE_UNAVAILABLE, + FUNCTION_SOURCE_SUPPRESSED }; diff --git a/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp b/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp index fdb93281f5..98e90e73a6 100644 --- a/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp +++ b/src/apps/debugger/user_interface/gui/team_window/SourceView.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2009-2014, Rene Gollent, rene@gollent.com. + * Copyright 2009-2016, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -2140,8 +2140,9 @@ SourceView::MessageReceived(BMessage* message) code = instance->GetSourceCode(); } else { Function* function = instance->GetFunction(); - if (function->SourceCodeState() - == FUNCTION_SOURCE_NOT_LOADED) { + if (function->SourceCodeState() == FUNCTION_SOURCE_NOT_LOADED + || function->SourceCodeState() + == FUNCTION_SOURCE_SUPPRESSED) { fListener->FunctionSourceCodeRequested(instance, false); break; } diff --git a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp index 7116614860..f5898698b7 100644 --- a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp +++ b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2010-2015, Rene Gollent, rene@gollent.com. + * Copyright 2010-2016, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -1535,8 +1535,11 @@ TeamWindow::_UpdateSourcePathState() if (sourceFile != NULL && !sourceFile->GetLocatedPath(sourceText)) sourceFile->GetPath(sourceText); - if (fActiveFunction->GetFunction()->SourceCodeState() - != FUNCTION_SOURCE_NOT_LOADED + function_source_state state = fActiveFunction->GetFunction() + ->SourceCodeState(); + if (state == FUNCTION_SOURCE_SUPPRESSED) + sourceText.Prepend("Disassembly for: "); + else if (state != FUNCTION_SOURCE_NOT_LOADED && fActiveSourceCode->GetSourceFile() == NULL && sourceFile != NULL) { sourceText.Prepend("Click to locate source file '"); diff --git a/src/kits/debugger/controllers/TeamDebugger.cpp b/src/kits/debugger/controllers/TeamDebugger.cpp index e47500185e..faf3944573 100644 --- a/src/kits/debugger/controllers/TeamDebugger.cpp +++ b/src/kits/debugger/controllers/TeamDebugger.cpp @@ -1008,8 +1008,9 @@ TeamDebugger::FunctionSourceCodeRequested(FunctionInstance* functionInstance, functionInstance->SetSourceCode(NULL, FUNCTION_SOURCE_LOADING); bool loadForFunction = false; - if (!forceDisassembly && function->SourceCodeState() - == FUNCTION_SOURCE_NOT_LOADED) { + if (!forceDisassembly && (function->SourceCodeState() + == FUNCTION_SOURCE_NOT_LOADED + || function->SourceCodeState() == FUNCTION_SOURCE_SUPPRESSED)) { loadForFunction = true; function->SetSourceCode(NULL, FUNCTION_SOURCE_LOADING); } diff --git a/src/kits/debugger/debug_info/TeamDebugInfo.cpp b/src/kits/debugger/debug_info/TeamDebugInfo.cpp index 1736a19713..5ed9ba1e88 100644 --- a/src/kits/debugger/debug_info/TeamDebugInfo.cpp +++ b/src/kits/debugger/debug_info/TeamDebugInfo.cpp @@ -487,10 +487,30 @@ TeamDebugInfo::GetActiveSourceCode(FunctionDebugInfo* info, SourceCode*& _code) Function* function = FunctionAtSourceLocation(file, info->SourceStartLocation()); if (function != NULL) { + function_source_state state = function->SourceCodeState(); if (function->SourceCodeState() == FUNCTION_SOURCE_LOADED) { _code = function->GetSourceCode(); _code->AcquireReference(); return B_OK; + } else if (state == FUNCTION_SOURCE_NOT_LOADED) { + // if the function's source state is not loaded, check + // if we already know the file anyways. Currently, when + // a source code job runs, it does so on behalf of a specific + // function, and consequently only sets the loaded source code + // on that particular function at that point in time, rather + // than all others sharing that same file. Consequently, + // set it lazily here. + SourceFileEntry* entry = fSourceFiles->Lookup(file); + if (entry != NULL) { + FileSourceCode* sourceCode = entry->GetSourceCode(); + if (sourceCode != NULL) { + function->SetSourceCode(sourceCode, + FUNCTION_SOURCE_LOADED); + _code = sourceCode; + _code->AcquireReference(); + return B_OK; + } + } } } } diff --git a/src/kits/debugger/jobs/LoadSourceCodeJob.cpp b/src/kits/debugger/jobs/LoadSourceCodeJob.cpp index 6265a03ff3..517ee64e0f 100644 --- a/src/kits/debugger/jobs/LoadSourceCodeJob.cpp +++ b/src/kits/debugger/jobs/LoadSourceCodeJob.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2012, Rene Gollent, rene@gollent.com. + * Copyright 2012-2016, Rene Gollent, rene@gollent.com. * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. */ @@ -94,11 +94,11 @@ LoadSourceCodeJob::Do() if (function->SourceCodeState() == FUNCTION_SOURCE_LOADED) { FileSourceCode* sourceCode = function->GetSourceCode(); function->SetSourceCode(sourceCode, - FUNCTION_SOURCE_NOT_LOADED); + FUNCTION_SOURCE_SUPPRESSED); } fFunctionInstance->SetSourceCode(sourceCode, - FUNCTION_SOURCE_LOADED); + FUNCTION_SOURCE_SUPPRESSED); sourceCode->ReleaseReference(); } } else