Fix branch lines

This commit is contained in:
Kingcom 2013-11-24 14:46:53 +01:00
parent 0672458a33
commit aab6f588f1
5 changed files with 43 additions and 33 deletions

View File

@ -923,7 +923,8 @@
</ClInclude>
<ClInclude Include="Debugger\DisassemblyManager.h">
<Filter>Debugger</Filter>
</ClInclude> </ItemGroup>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="CMakeLists.txt" />
<None Include="..\LICENSE.TXT" />

View File

@ -145,6 +145,23 @@ std::map<u32,DisassemblyEntry*>::iterator findDisassemblyEntry(std::map<u32,Disa
return entries.end();
}
std::vector<BranchLine> DisassemblyManager::getBranchLines(u32 start, u32 size)
{
std::vector<BranchLine> result;
auto it = findDisassemblyEntry(entries,start,false);
if (it != entries.end())
{
do
{
it->second->getBranchLines(start,size,result);
it++;
} while (it != entries.end() && start+size > it->second->getLineAddress(0));
}
return result;
}
DisassemblyLineInfo DisassemblyManager::getLine(u32 address, bool insertSymbols)
{
DisassemblyLineInfo result;
@ -306,6 +323,13 @@ bool DisassemblyFunction::disassemble(u32 address, DisassemblyLineInfo& dest, bo
return it->second->disassemble(address,dest,insertSymbols);
}
void DisassemblyFunction::getBranchLines(u32 start, u32 size, std::vector<BranchLine>& dest)
{
for (int i = 0; i < lines.size(); i++)
{
dest.push_back(lines[i]);
}
}
#define NUM_LANES 16

View File

@ -55,6 +55,7 @@ public:
virtual u32 getLineAddress(int line) = 0;
virtual u32 getTotalSize() = 0;
virtual bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols) = 0;
virtual void getBranchLines(u32 start, u32 size, std::vector<BranchLine>& dest) { };
};
class DisassemblyFunction: public DisassemblyEntry
@ -67,6 +68,7 @@ public:
virtual u32 getLineAddress(int line);
virtual u32 getTotalSize() { return size; };
virtual bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols);
virtual void getBranchLines(u32 start, u32 size, std::vector<BranchLine>& dest);
private:
u32 computeHash();
void generateBranchLines();
@ -134,6 +136,7 @@ public:
void setCpu(DebugInterface* _cpu) { cpu = _cpu; };
DisassemblyLineInfo getLine(u32 address, bool insertSymbols);
void analyze(u32 address, u32 size);
std::vector<BranchLine> getBranchLines(u32 start, u32 size);
u32 getStartAddress(u32 address);
u32 getNthPreviousAddress(u32 address, int n = 1);

View File

@ -300,7 +300,7 @@ void CtrlDisAsmView::assembleOpcode(u32 address, std::string defaultText)
scanFunctions();
if (address == curAddress)
gotoAddr(curAddress+4);
gotoAddr(manager.getNthNextAddress(curAddress,1));
redraw();
} else {
@ -310,10 +310,10 @@ void CtrlDisAsmView::assembleOpcode(u32 address, std::string defaultText)
}
void CtrlDisAsmView::drawBranchLine(HDC hdc, BranchLine& line)
void CtrlDisAsmView::drawBranchLine(HDC hdc, std::map<u32,int>& addressPositions, BranchLine& line)
{
HPEN pen;
u32 windowEnd = windowStart+visibleRows*instructionSize;
u32 windowEnd = manager.getNthNextAddress(windowStart,visibleRows);
int topY;
int bottomY;
@ -324,8 +324,7 @@ void CtrlDisAsmView::drawBranchLine(HDC hdc, BranchLine& line)
{
topY = rect.bottom+1;
} else {
int row = (line.first-windowStart)/instructionSize;
topY = row*rowHeight + rowHeight/2;
topY = addressPositions[line.first] + rowHeight/2;
}
if (line.second < windowStart)
@ -335,8 +334,7 @@ void CtrlDisAsmView::drawBranchLine(HDC hdc, BranchLine& line)
{
bottomY = rect.bottom+1;
} else {
int row = (line.second-windowStart)/instructionSize;
bottomY = row*rowHeight + rowHeight/2;
bottomY = addressPositions[line.second] + rowHeight/2;
}
if ((topY < 0 && bottomY < 0) || (topY > rect.bottom && bottomY > rect.bottom))
@ -429,6 +427,8 @@ void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
HICON breakPointDisable = (HICON)LoadIcon(GetModuleHandle(0),(LPCWSTR)IDI_STOPDISABLE);
unsigned int address = windowStart;
std::map<u32,int> addressPositions;
for (int i = 0; i < visibleRows; i++)
{
DisassemblyLineInfo line = manager.getLine(address,displaySymbols);
@ -436,6 +436,8 @@ void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
int rowY1 = rowHeight*i;
int rowY2 = rowHeight*(i+1);
addressPositions[address] = rowY1;
// draw background
COLORREF backgroundColor = whiteBackground ? 0xFFFFFF : debugger->getColor(address);
COLORREF textColor = 0x000000;
@ -504,23 +506,12 @@ void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
address += line.totalSize;
}
/* for (size_t i = 0; i < visibleFunctionAddresses.size(); i++)
std::vector<BranchLine> branchLines = manager.getBranchLines(windowStart,address-windowStart);
for (size_t i = 0; i < branchLines.size(); i++)
{
auto it = functions.find(visibleFunctionAddresses[i]);
if (it == functions.end()) continue;
DisassemblyFunc& func = it->second;
for (size_t l = 0; l < func.lines.size(); l++)
{
drawBranchLine(hdc,func.lines[l]);
}
drawBranchLine(hdc,addressPositions,branchLines[i]);
}
for (size_t i = 0; i < strayLines.size(); i++)
{
drawBranchLine(hdc,strayLines[i]);
}*/
SelectObject(hdc,oldFont);
SelectObject(hdc,oldPen);
SelectObject(hdc,oldBrush);

View File

@ -36,10 +36,6 @@ class CtrlDisAsmView
HFONT boldfont;
RECT rect;
// std::map<u32,DisassemblyFunc> functions;
std::vector<u32> visibleFunctionAddresses;
std::vector<BranchLine> strayLines;
DisassemblyManager manager;
u32 curAddress;
u32 selectRangeStart;
@ -81,7 +77,7 @@ class CtrlDisAsmView
void calculatePixelPositions();
bool getDisasmAddressText(u32 address, char* dest, bool abbreviateLabels);
void updateStatusBarText();
void drawBranchLine(HDC hdc, BranchLine& line);
void drawBranchLine(HDC hdc, std::map<u32,int>& addressPositions, BranchLine& line);
void copyInstructions(u32 startAddr, u32 endAddr, bool withDisasm);
public:
CtrlDisAsmView(HWND _wnd);
@ -103,12 +99,7 @@ public:
bool curAddressIsVisible();
void redraw();
void scanFunctions();
void clearFunctions()
{
// functions.clear();
visibleFunctionAddresses.clear();
strayLines.clear();
};
void clearFunctions() { };
void getOpcodeText(u32 address, char* dest);
int getRowHeight() { return rowHeight; };