[haiku-commits] haiku: hrev50534 - src/kits/debugger/debug_info headers/private/debugger/model headers/private/debugger/debug_info src/kits/debugger/model

  • From: anevilyak@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 14 Sep 2016 04:18:42 +0200 (CEST)

hrev50534 adds 1 changeset to branch 'master'
old head: 7079e522338336f1c80bf74af9d40230538a01d0
new head: b65adbdfbc322bb7d86d74049389c688e9962f15
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=b65adbdfbc32+%5E7079e5223383

----------------------------------------------------------------------------

b65adbdfbc32: 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.

                                         [ Rene Gollent <rene@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev50534
Commit:      b65adbdfbc322bb7d86d74049389c688e9962f15
URL:         http://cgit.haiku-os.org/haiku/commit/?id=b65adbdfbc32
Author:      Rene Gollent <rene@xxxxxxxxxxx>
Date:        Sat Sep 10 02:41:07 2016 UTC

Ticket:      https://dev.haiku-os.org/ticket/12940

----------------------------------------------------------------------------

10 files changed, 112 insertions(+), 14 deletions(-)
.../private/debugger/debug_info/TeamDebugInfo.h  | 10 +++--
.../model/TeamFunctionSourceInformation.h        | 25 +++++++++++++
.../private/debugger/model/TeamTypeInformation.h |  5 +--
src/kits/debugger/Jamfile                        |  1 +
.../debugger/debug_info/DwarfImageDebugInfo.cpp  | 16 +++++++-
.../debugger/debug_info/DwarfImageDebugInfo.h    |  5 ++-
.../debugger/debug_info/DwarfTeamDebugInfo.cpp   |  8 ++--
.../debugger/debug_info/DwarfTeamDebugInfo.h     |  5 ++-
src/kits/debugger/debug_info/TeamDebugInfo.cpp   | 39 +++++++++++++++++++-
.../model/TeamFunctionSourceInformation.cpp      | 12 ++++++

----------------------------------------------------------------------------

diff --git a/headers/private/debugger/debug_info/TeamDebugInfo.h 
b/headers/private/debugger/debug_info/TeamDebugInfo.h
index e95202a..817f02a 100644
--- a/headers/private/debugger/debug_info/TeamDebugInfo.h
+++ b/headers/private/debugger/debug_info/TeamDebugInfo.h
@@ -1,6 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
- * Copyright 2014, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2014-2016, Rene Gollent, rene@xxxxxxxxxxx.
  * 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,
diff --git a/headers/private/debugger/model/TeamFunctionSourceInformation.h 
b/headers/private/debugger/model/TeamFunctionSourceInformation.h
new file mode 100644
index 0000000..3c649a7
--- /dev/null
+++ b/headers/private/debugger/model/TeamFunctionSourceInformation.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2016, Rene Gollent, rene@xxxxxxxxxxx.
+ * 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
diff --git a/headers/private/debugger/model/TeamTypeInformation.h 
b/headers/private/debugger/model/TeamTypeInformation.h
index 6748056..0aafbb7 100644
--- a/headers/private/debugger/model/TeamTypeInformation.h
+++ b/headers/private/debugger/model/TeamTypeInformation.h
@@ -1,12 +1,11 @@
 /*
- * Copyright 2011-2014, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2011-2016, Rene Gollent, rene@xxxxxxxxxxx.
  * 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();
 
diff --git a/src/kits/debugger/Jamfile b/src/kits/debugger/Jamfile
index 6bab1ea..36f0956 100644
--- a/src/kits/debugger/Jamfile
+++ b/src/kits/debugger/Jamfile
@@ -211,6 +211,7 @@ local sources =
        SystemInfo.cpp
        TargetHost.cpp
        Team.cpp
+       TeamFunctionSourceInformation.cpp
        TeamInfo.cpp
        TeamMemory.cpp
        TeamMemoryBlock.cpp
diff --git a/src/kits/debugger/debug_info/DwarfImageDebugInfo.cpp 
b/src/kits/debugger/debug_info/DwarfImageDebugInfo.cpp
index 11e62ad..054c9b9 100644
--- a/src/kits/debugger/debug_info/DwarfImageDebugInfo.cpp
+++ b/src/kits/debugger/debug_info/DwarfImageDebugInfo.cpp
@@ -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);
diff --git a/src/kits/debugger/debug_info/DwarfImageDebugInfo.h 
b/src/kits/debugger/debug_info/DwarfImageDebugInfo.h
index db48b9b..05c163c 100644
--- a/src/kits/debugger/debug_info/DwarfImageDebugInfo.h
+++ b/src/kits/debugger/debug_info/DwarfImageDebugInfo.h
@@ -1,6 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
- * Copyright 2010-2014, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2010-2016, Rene Gollent, rene@xxxxxxxxxxx.
  * 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;
diff --git a/src/kits/debugger/debug_info/DwarfTeamDebugInfo.cpp 
b/src/kits/debugger/debug_info/DwarfTeamDebugInfo.cpp
index fa035bf..06d8e70 100644
--- a/src/kits/debugger/debug_info/DwarfTeamDebugInfo.cpp
+++ b/src/kits/debugger/debug_info/DwarfTeamDebugInfo.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
- * Copyright 2014, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2014-2016, Rene Gollent, rene@xxxxxxxxxxx.
  * 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;
 
diff --git a/src/kits/debugger/debug_info/DwarfTeamDebugInfo.h 
b/src/kits/debugger/debug_info/DwarfTeamDebugInfo.h
index fa2891b..ace6142 100644
--- a/src/kits/debugger/debug_info/DwarfTeamDebugInfo.h
+++ b/src/kits/debugger/debug_info/DwarfTeamDebugInfo.h
@@ -1,6 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
- * Copyright 2014, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2014-2016, Rene Gollent, rene@xxxxxxxxxxx.
  * 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;
 };
 
diff --git a/src/kits/debugger/debug_info/TeamDebugInfo.cpp 
b/src/kits/debugger/debug_info/TeamDebugInfo.cpp
index 6424786..1736a19 100644
--- a/src/kits/debugger/debug_info/TeamDebugInfo.cpp
+++ b/src/kits/debugger/debug_info/TeamDebugInfo.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxx.
- * Copyright 2012-2014, Rene Gollent, rene@xxxxxxxxxxx.
+ * Copyright 2012-2016, Rene Gollent, rene@xxxxxxxxxxx.
  * 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;
@@ -477,6 +478,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,
        ImageDebugInfo*& _imageDebugInfo)
diff --git a/src/kits/debugger/model/TeamFunctionSourceInformation.cpp 
b/src/kits/debugger/model/TeamFunctionSourceInformation.cpp
new file mode 100644
index 0000000..384d990
--- /dev/null
+++ b/src/kits/debugger/model/TeamFunctionSourceInformation.cpp
@@ -0,0 +1,12 @@
+/*
+ * Copyright 2016, Rene Gollent, rene@xxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include "TeamFunctionSourceInformation.h"
+
+
+TeamFunctionSourceInformation::~TeamFunctionSourceInformation()
+{
+}


Other related posts:

  • » [haiku-commits] haiku: hrev50534 - src/kits/debugger/debug_info headers/private/debugger/model headers/private/debugger/debug_info src/kits/debugger/model - anevilyak