haiku/headers/private/debugger/arch/Architecture.h

157 lines
4.3 KiB
C
Raw Normal View History

/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2011-2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef ARCHITECTURE_H
#define ARCHITECTURE_H
#include <ByteOrder.h>
#include <OS.h>
#include <Referenceable.h>
#include <Variant.h>
#include "ReturnValueInfo.h"
#include "Types.h"
class CfaContext;
class CpuState;
* Since disassembled code is actually function instance specific, FunctionInstance does now also have a (DisassembledCode) source code attribute. Function keeps its attribute, but it explicitly is a FileSourceCode now. * SourceCode: - Removed GetStatementAtLocation(). Instead DisassembledCode has a StatementAtLocation() now. As well as a StatementAtAddress() and StatementAddressRange(). Rather cast to the subclass (in two instances) instead of having those methods in the base class. In most cases we already have the subclasses now, anyway. - Added Lock()/Unlock(), which are implemented in FileSourceCode. The statement ranges are no longer immutable, so we have to lock. * TeamDebugModel: - Revived GetBreakpointsInAddressRange(). - GetBreakpointsForSourceCode(): Optimized for DisassembledCode and fixed in the FileSourceCode case. We need to compare with the functions' source file instead of their source code, since they might not have the source code set yet. Fixed two instances of the same problem in SourceView. Setting breakpoints in functions that have no associated source code yet, works now. * Team: - GetStatementAtAddress(): Optimized by using the DisassembledCode, if available. - GetStatementAtSourceLocation(): If the supplied source code is DisassembledCode, we have to get the statement from it directly, since we can't get that information from the image debug info. * TeamDebugInfo: Added LoadSourceCode() and DisassembleFunction(), the new way to get FileSourceCode respectively DisassembledCode. SpecificTeamDebugInfo has lost LoadSourceCode() and gained service methods AddSourceCodeInfo() and ReadCode(). This avoids unnecessary code duplication in the subclasses. Moreover it allows for joining source location info source files from different images (and compilation units) -- interesting for inline functions in headers. * Adjusted LoadSourceCodeJob and TeamDebugger::FunctionSourceCodeRequested() accordingly. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31514 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-11 04:05:26 +04:00
class DisassembledCode;
class FunctionDebugInfo;
class Image;
class ImageDebugInfoProvider;
class InstructionInfo;
class Register;
class RegisterMap;
class StackFrame;
class StackTrace;
class Statement;
class Team;
class TeamMemory;
class ValueLocation;
enum {
STACK_GROWTH_DIRECTION_POSITIVE = 0,
STACK_GROWTH_DIRECTION_NEGATIVE
};
enum {
WATCHPOINT_CAPABILITY_FLAG_READ = 1,
2012-11-11 21:03:28 +04:00
WATCHPOINT_CAPABILITY_FLAG_WRITE = 2,
WATCHPOINT_CAPABILITY_FLAG_READ_WRITE = 4
};
class Architecture : public BReferenceable {
public:
Architecture(TeamMemory* teamMemory,
uint8 addressSize,
size_t debugCpuStateSize,
bool bigEndian);
virtual ~Architecture();
virtual status_t Init();
inline uint8 AddressSize() const { return fAddressSize; }
inline size_t DebugCpuStateSize() const
{ return fDebugCpuStateSize; }
inline bool IsBigEndian() const { return fBigEndian; }
inline bool IsHostEndian() const;
virtual int32 StackGrowthDirection() const = 0;
virtual int32 CountRegisters() const = 0;
virtual const Register* Registers() const = 0;
virtual status_t InitRegisterRules(CfaContext& context) const;
virtual status_t GetDwarfRegisterMaps(RegisterMap** _toDwarf,
RegisterMap** _fromDwarf) const = 0;
// returns references
virtual status_t GetCpuFeatures(uint32& flags) = 0;
virtual status_t CreateCpuState(CpuState*& _state) = 0;
virtual status_t CreateCpuState(const void* cpuStateData,
size_t size, CpuState*& _state) = 0;
virtual status_t CreateStackFrame(Image* image,
FunctionDebugInfo* function,
CpuState* cpuState, bool isTopFrame,
StackFrame*& _frame,
CpuState*& _previousCpuState) = 0;
// returns reference to previous frame
// and CPU state; returned CPU state
// can be NULL
virtual void UpdateStackFrameCpuState(
const StackFrame* frame,
Image* previousImage,
FunctionDebugInfo* previousFunction,
CpuState* previousCpuState) = 0;
// Called after a CreateStackFrame()
// with the image/function corresponding
// to the CPU state.
virtual status_t ReadValueFromMemory(target_addr_t address,
uint32 valueType, BVariant& _value) const
= 0;
virtual status_t ReadValueFromMemory(target_addr_t addressSpace,
target_addr_t address, uint32 valueType,
BVariant& _value) const = 0;
virtual status_t DisassembleCode(FunctionDebugInfo* function,
const void* buffer, size_t bufferSize,
* Since disassembled code is actually function instance specific, FunctionInstance does now also have a (DisassembledCode) source code attribute. Function keeps its attribute, but it explicitly is a FileSourceCode now. * SourceCode: - Removed GetStatementAtLocation(). Instead DisassembledCode has a StatementAtLocation() now. As well as a StatementAtAddress() and StatementAddressRange(). Rather cast to the subclass (in two instances) instead of having those methods in the base class. In most cases we already have the subclasses now, anyway. - Added Lock()/Unlock(), which are implemented in FileSourceCode. The statement ranges are no longer immutable, so we have to lock. * TeamDebugModel: - Revived GetBreakpointsInAddressRange(). - GetBreakpointsForSourceCode(): Optimized for DisassembledCode and fixed in the FileSourceCode case. We need to compare with the functions' source file instead of their source code, since they might not have the source code set yet. Fixed two instances of the same problem in SourceView. Setting breakpoints in functions that have no associated source code yet, works now. * Team: - GetStatementAtAddress(): Optimized by using the DisassembledCode, if available. - GetStatementAtSourceLocation(): If the supplied source code is DisassembledCode, we have to get the statement from it directly, since we can't get that information from the image debug info. * TeamDebugInfo: Added LoadSourceCode() and DisassembleFunction(), the new way to get FileSourceCode respectively DisassembledCode. SpecificTeamDebugInfo has lost LoadSourceCode() and gained service methods AddSourceCodeInfo() and ReadCode(). This avoids unnecessary code duplication in the subclasses. Moreover it allows for joining source location info source files from different images (and compilation units) -- interesting for inline functions in headers. * Adjusted LoadSourceCodeJob and TeamDebugger::FunctionSourceCodeRequested() accordingly. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31514 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-07-11 04:05:26 +04:00
DisassembledCode*& _sourceCode) = 0;
virtual status_t GetStatement(FunctionDebugInfo* function,
target_addr_t address,
Statement*& _statement) = 0;
virtual status_t GetInstructionInfo(target_addr_t address,
Rework how return values are handled. - ArchitectureX86 now hands off the work for GetInstructionInfo() to DisassemblerX86, since the latter has all the information we need to properly classify and evaluate instructions. Correspondingly a CpuState is passed down to it in order to perform address calculations for the instruction if it's a jump or call instruction. The latter's targets are then stored on the thread for later retrieval when constructing a stack trace. Adjust X86_64 accordingly for the signature changes. This also fixes a bug where Step Over would sometimes result in a Step Into instead due to the previous implementation of GetInstructionInfo() occasionally failing to classify call instructions correctly. - Architecture::CreateStackTrace() now takes an argument specifying the address of the last executed function if applicable. This is used to decide who/where to decode a return value from. Adjust callers. - DwarfImageDebugInfo::_CreateReturnValue() uses the above information in order to know directly who the caller it needs to look up a return value for is, rather than trying to walk backwards to find them. Type resolution is now also a bit more sophisticated due to various cases where the subprogram entry didn't directly contain the return type but referred to another DIE that did. Retrieving return value now appears to work properly in all cases except when position independent code is involved. The latter however will require resolving the appropriate function address in the PLT, which will need some additional work.
2013-01-01 07:54:39 +04:00
InstructionInfo& _info,
CpuState* state) = 0;
virtual status_t ResolvePICFunctionAddress(target_addr_t
instructionAddress,
CpuState* state,
target_addr_t& _targetAddress) = 0;
status_t CreateStackTrace(Team* team,
ImageDebugInfoProvider* imageInfoProvider,
CpuState* cpuState,
StackTrace*& _stackTrace,
ReturnValueInfoList* returnValueInfos,
int32 maxStackDepth = -1,
bool useExistingTrace = false,
bool getFullFrameInfo = true);
// team is not locked
virtual status_t GetWatchpointDebugCapabilities(
int32& _maxRegisterCount,
int32& _maxBytesPerRegister,
uint8& _watchpointCapabilityFlags) = 0;
virtual status_t GetReturnAddressLocation(
StackFrame* frame, target_size_t valueSize,
ValueLocation*& _location) = 0;
protected:
TeamMemory* fTeamMemory;
uint8 fAddressSize;
size_t fDebugCpuStateSize;
bool fBigEndian;
};
bool
Architecture::IsHostEndian() const
{
return fBigEndian == (B_HOST_IS_BENDIAN != 0);
}
#endif // ARCHITECTURE_H