Debugger: Fix #12940.

- Add new interface TeamFunctionSourceInformation. Currently this
  exposes a single function allowing one to query for the currently
  active source code given a FunctionDebugInfo instance.
- Implement TeamFunctionSourceInformation on TeamDebugInfo.
- Pass TeamFunctionSourceInformation to Dwarf{Team,Image}DebugInfo.
  In turn, make use of it in DwarfImageDebugInfo::GetStatement() in
  order to determine whether to return the corresponding assembly
  or source statement.

With this piece of information, the debugger is now correctly able to
determine that the user is currently looking at disassembly despite debug
info being available, and consequently adjust its stepping behavior based on
that. Previously, the source code statement was always used, leading to it
not being possible to single step assembly lines in such a circumstance
without manually using run to cursor.

Other related cleanups:
- TeamDebugInfo now inherits BReferenceable directly, rather than relying on
  indirectly inheriting it from TeamTypeInformation.
- Remove BReferenceable from TeamTypeInformation. The latter is only an
  interface anyways, and inheriting that base class from multiple locations
  was causing GCC5 trouble when resolving BReference<TeamDebugInfo>, even
  when virtual inheritance was used.
This commit is contained in:
Rene Gollent 2016-09-09 22:41:07 -04:00
parent 7079e52233
commit b65adbdfbc
10 changed files with 112 additions and 14 deletions

View File

@ -1,6 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2014, Rene Gollent, rene@gollent.com.
* Copyright 2014-2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef TEAM_DEBUG_INFO_H
@ -15,9 +15,9 @@
#include "GlobalTypeLookup.h"
#include "ImageInfo.h"
#include "TeamFunctionSourceInformation.h"
#include "TeamTypeInformation.h"
class Architecture;
class DebuggerInterface;
class DisassembledCode;
@ -35,7 +35,8 @@ class SourceLocation;
class SpecificTeamDebugInfo;
class TeamDebugInfo : public GlobalTypeLookup, public TeamTypeInformation {
class TeamDebugInfo : public BReferenceable, public GlobalTypeLookup,
public TeamTypeInformation, public TeamFunctionSourceInformation {
public:
TeamDebugInfo(
DebuggerInterface* debuggerInterface,
@ -59,6 +60,9 @@ public:
virtual bool TypeExistsByName(const BString& name,
const TypeLookupConstraints& constraints);
virtual status_t GetActiveSourceCode(FunctionDebugInfo* info,
SourceCode*& _code);
status_t LoadImageDebugInfo(const ImageInfo& imageInfo,
LocatableFile* imageFile,
ImageDebugInfoLoadingState& state,

View File

@ -0,0 +1,25 @@
/*
* Copyright 2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef TEAM_FUNCTION_SOURCE_INFORMATION_H
#define TEAM_FUNCTION_SOURCE_INFORMATION_H
#include <SupportDefs.h>
class FunctionDebugInfo;
class SourceCode;
class TeamFunctionSourceInformation {
public:
virtual ~TeamFunctionSourceInformation();
virtual status_t GetActiveSourceCode(FunctionDebugInfo* info,
SourceCode*& _code) = 0;
// returns reference
};
#endif // TEAM_FUNCTION_SOURCE_INFORMATION_H

View File

@ -1,12 +1,11 @@
/*
* Copyright 2011-2014, Rene Gollent, rene@gollent.com.
* Copyright 2011-2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef TEAM_TYPE_INFORMATION_H
#define TEAM_TYPE_INFORMATION_H
#include <Referenceable.h>
#include <SupportDefs.h>
@ -15,7 +14,7 @@ class Type;
class TypeLookupConstraints;
class TeamTypeInformation : public BReferenceable {
class TeamTypeInformation {
public:
virtual ~TeamTypeInformation();

View File

@ -211,6 +211,7 @@ local sources =
SystemInfo.cpp
TargetHost.cpp
Team.cpp
TeamFunctionSourceInformation.cpp
TeamInfo.cpp
TeamMemory.cpp
TeamMemoryBlock.cpp

View File

@ -54,6 +54,7 @@
#include "SymbolInfo.h"
#include "TargetAddressRangeList.h"
#include "Team.h"
#include "TeamFunctionSourceInformation.h"
#include "TeamMemory.h"
#include "Tracing.h"
#include "TypeLookupConstraints.h"
@ -329,7 +330,8 @@ struct DwarfImageDebugInfo::TypeEntryInfo {
DwarfImageDebugInfo::DwarfImageDebugInfo(const ImageInfo& imageInfo,
DebuggerInterface* interface, Architecture* architecture,
FileManager* fileManager, GlobalTypeLookup* typeLookup,
GlobalTypeCache* typeCache, DwarfFile* file)
GlobalTypeCache* typeCache, TeamFunctionSourceInformation* sourceInfo,
DwarfFile* file)
:
fLock("dwarf image debug info"),
fImageInfo(imageInfo),
@ -338,6 +340,7 @@ DwarfImageDebugInfo::DwarfImageDebugInfo(const ImageInfo& imageInfo,
fFileManager(fileManager),
fTypeLookup(typeLookup),
fTypeCache(typeCache),
fSourceInfo(sourceInfo),
fTypeNameTable(NULL),
fFile(file),
fTextSegment(NULL),
@ -809,6 +812,17 @@ DwarfImageDebugInfo::GetStatement(FunctionDebugInfo* _function,
return fArchitecture->GetStatement(function, address, _statement);
}
SourceCode* sourceCode = NULL;
status_t error = fSourceInfo->GetActiveSourceCode(_function, sourceCode);
BReference<SourceCode> sourceReference(sourceCode, true);
if (error != B_OK || dynamic_cast<DisassembledCode*>(sourceCode) != NULL) {
// either no source code or disassembly is currently active (i.e.
// due to failing to locate the source file on disk or the user
// deliberately switching to disassembly view).
// return the assembly statement.
return fArchitecture->GetStatement(function, address, _statement);
}
// get the index of the source file in the compilation unit for cheaper
// comparison below
int32 fileIndex = _GetSourceFileIndex(unit, file);

View File

@ -1,6 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2010-2014, Rene Gollent, rene@gollent.com.
* Copyright 2010-2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef DWARF_IMAGE_DEBUG_INFO_H
@ -33,6 +33,7 @@ class GlobalTypeCache;
class GlobalTypeLookup;
class LocatableFile;
class SourceCode;
class TeamFunctionSourceInformation;
class DwarfImageDebugInfo : public SpecificImageDebugInfo {
@ -43,6 +44,7 @@ public:
FileManager* fileManager,
GlobalTypeLookup* typeLookup,
GlobalTypeCache* typeCache,
TeamFunctionSourceInformation* sourceInfo,
DwarfFile* file);
virtual ~DwarfImageDebugInfo();
@ -138,6 +140,7 @@ private:
FileManager* fFileManager;
GlobalTypeLookup* fTypeLookup;
GlobalTypeCache* fTypeCache;
TeamFunctionSourceInformation* fSourceInfo;
TypeNameTable* fTypeNameTable;
DwarfFile* fFile;
ElfSegment* fTextSegment;

View File

@ -1,6 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2014, Rene Gollent, rene@gollent.com.
* Copyright 2014-2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
@ -23,13 +23,15 @@
DwarfTeamDebugInfo::DwarfTeamDebugInfo(Architecture* architecture,
DebuggerInterface* interface, FileManager* fileManager,
GlobalTypeLookup* typeLookup, GlobalTypeCache* typeCache)
GlobalTypeLookup* typeLookup, TeamFunctionSourceInformation* sourceInfo,
GlobalTypeCache* typeCache)
:
fArchitecture(architecture),
fDebuggerInterface(interface),
fFileManager(fileManager),
fManager(NULL),
fTypeLookup(typeLookup),
fSourceInfo(sourceInfo),
fTypeCache(typeCache)
{
fDebuggerInterface->AcquireReference();
@ -95,7 +97,7 @@ DwarfTeamDebugInfo::CreateImageDebugInfo(const ImageInfo& imageInfo,
// create the image debug info
DwarfImageDebugInfo* debugInfo = new(std::nothrow) DwarfImageDebugInfo(
imageInfo, fDebuggerInterface, fArchitecture, fFileManager,
fTypeLookup, fTypeCache, dwarfState->GetFileState().dwarfFile);
fTypeLookup, fTypeCache, fSourceInfo, dwarfState->GetFileState().dwarfFile);
if (debugInfo == NULL)
return B_NO_MEMORY;

View File

@ -1,6 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2014, Rene Gollent, rene@gollent.com.
* Copyright 2014-2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef DWARF_TEAM_DEBUG_INFO_H
@ -16,6 +16,7 @@ class FileManager;
class ImageInfo;
class GlobalTypeCache;
class GlobalTypeLookup;
class TeamFunctionSourceInformation;
class TeamMemory;
@ -25,6 +26,7 @@ public:
DebuggerInterface* interface,
FileManager* fileManager,
GlobalTypeLookup* typeLookup,
TeamFunctionSourceInformation* sourceInfo,
GlobalTypeCache* typeCache);
virtual ~DwarfTeamDebugInfo();
@ -41,6 +43,7 @@ private:
FileManager* fFileManager;
DwarfManager* fManager;
GlobalTypeLookup* fTypeLookup;
TeamFunctionSourceInformation* fSourceInfo;
GlobalTypeCache* fTypeCache;
};

View File

@ -1,6 +1,6 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2012-2014, Rene Gollent, rene@gollent.com.
* Copyright 2012-2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
@ -346,7 +346,8 @@ TeamDebugInfo::Init()
// DWARF
DwarfTeamDebugInfo* dwarfInfo = new(std::nothrow) DwarfTeamDebugInfo(
fArchitecture, fDebuggerInterface, fFileManager, this, fTypeCache);
fArchitecture, fDebuggerInterface, fFileManager, this, this,
fTypeCache);
if (dwarfInfo == NULL || !fSpecificInfos.AddItem(dwarfInfo)) {
delete dwarfInfo;
return B_NO_MEMORY;
@ -476,6 +477,40 @@ TeamDebugInfo::HasType(GlobalTypeCache* cache, const BString& name,
}
status_t
TeamDebugInfo::GetActiveSourceCode(FunctionDebugInfo* info, SourceCode*& _code)
{
AutoLocker<BLocker> locker(fLock);
LocatableFile* file = info->SourceFile();
if (file != NULL) {
Function* function = FunctionAtSourceLocation(file,
info->SourceStartLocation());
if (function != NULL) {
if (function->SourceCodeState() == FUNCTION_SOURCE_LOADED) {
_code = function->GetSourceCode();
_code->AcquireReference();
return B_OK;
}
}
}
for (int32 i = 0; i < fImages.CountItems(); i++) {
ImageDebugInfo* imageInfo = fImages.ItemAt(i);
FunctionInstance* instance = imageInfo->FunctionAtAddress(
info->Address());
if (instance != NULL && instance->SourceCodeState()
== FUNCTION_SOURCE_LOADED) {
_code = instance->GetSourceCode();
_code->AcquireReference();
return B_OK;
}
}
return B_ENTRY_NOT_FOUND;
}
status_t
TeamDebugInfo::LoadImageDebugInfo(const ImageInfo& imageInfo,
LocatableFile* imageFile, ImageDebugInfoLoadingState& _state,

View File

@ -0,0 +1,12 @@
/*
* Copyright 2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#include "TeamFunctionSourceInformation.h"
TeamFunctionSourceInformation::~TeamFunctionSourceInformation()
{
}