1
0
Fork 0

DBG+BRIDGE+GUI: make single loops show properly

This commit is contained in:
mrexodia 2016-11-22 21:54:39 +01:00
parent e4efed3eaf
commit b89fdcd3c1
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
6 changed files with 22 additions and 8 deletions

View File

@ -520,7 +520,9 @@ BRIDGE_IMPEXP LOOPTYPE DbgGetLoopTypeAt(duint addr, int depth)
return LOOP_NONE; return LOOP_NONE;
duint start = info.loop.start; duint start = info.loop.start;
duint end = info.loop.end; duint end = info.loop.end;
if(addr == start) if(start == end || info.loop.instrcount == 1)
return LOOP_SINGLE;
else if(addr == start)
return LOOP_BEGIN; return LOOP_BEGIN;
else if(addr == end) else if(addr == end)
return LOOP_END; return LOOP_END;

View File

@ -142,7 +142,8 @@ typedef enum
LOOP_BEGIN, LOOP_BEGIN,
LOOP_MIDDLE, LOOP_MIDDLE,
LOOP_ENTRY, LOOP_ENTRY,
LOOP_END LOOP_END,
LOOP_SINGLE
} LOOPTYPE; } LOOPTYPE;
//order by most important type last //order by most important type last
@ -450,6 +451,7 @@ typedef struct
int depth; //IN int depth; //IN
duint start; //OUT duint start; //OUT
duint end; //OUT duint end; //OUT
duint instrcount; //OUT
} LOOP; } LOOP;
#ifndef _NO_ADDRINFO #ifndef _NO_ADDRINFO

View File

@ -230,7 +230,7 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
} }
if(addrinfo->flags & flagloop) if(addrinfo->flags & flagloop)
{ {
if(LoopGet(addrinfo->loop.depth, addr, &addrinfo->loop.start, &addrinfo->loop.end)) if(LoopGet(addrinfo->loop.depth, addr, &addrinfo->loop.start, &addrinfo->loop.end, &addrinfo->loop.instrcount))
retval = true; retval = true;
} }
if(addrinfo->flags & flagargs) if(addrinfo->flags & flagargs)

View File

@ -5,7 +5,7 @@
std::map<DepthModuleRange, LOOPSINFO, DepthModuleRangeCompare> loops; std::map<DepthModuleRange, LOOPSINFO, DepthModuleRangeCompare> loops;
bool LoopAdd(duint Start, duint End, bool Manual) bool LoopAdd(duint Start, duint End, bool Manual, duint instructionCount)
{ {
ASSERT_DEBUGGING("Export call"); ASSERT_DEBUGGING("Export call");
@ -35,6 +35,7 @@ bool LoopAdd(duint Start, duint End, bool Manual)
loopInfo.end = End - moduleBase; loopInfo.end = End - moduleBase;
loopInfo.depth = finalDepth; loopInfo.depth = finalDepth;
loopInfo.manual = Manual; loopInfo.manual = Manual;
loopInfo.instructioncount = instructionCount;
ModNameFromAddr(Start, loopInfo.mod, true); ModNameFromAddr(Start, loopInfo.mod, true);
// Link this to a parent loop if one does exist // Link this to a parent loop if one does exist
@ -53,7 +54,7 @@ bool LoopAdd(duint Start, duint End, bool Manual)
} }
// Get the start/end of a loop at a certain depth and address // Get the start/end of a loop at a certain depth and address
bool LoopGet(int Depth, duint Address, duint* Start, duint* End) bool LoopGet(int Depth, duint Address, duint* Start, duint* End, duint* InstructionCount)
{ {
ASSERT_DEBUGGING("Export call"); ASSERT_DEBUGGING("Export call");
@ -78,6 +79,9 @@ bool LoopGet(int Depth, duint Address, duint* Start, duint* End)
if(End) if(End)
*End = found->second.end + moduleBase; *End = found->second.end + moduleBase;
if(InstructionCount)
*InstructionCount = found->second.instructioncount;
return true; return true;
} }
@ -183,6 +187,7 @@ void LoopCacheSave(JSON Root)
json_object_set_new(currentJson, "end", json_hex(currentLoop.end)); json_object_set_new(currentJson, "end", json_hex(currentLoop.end));
json_object_set_new(currentJson, "depth", json_integer(currentLoop.depth)); json_object_set_new(currentJson, "depth", json_integer(currentLoop.depth));
json_object_set_new(currentJson, "parent", json_hex(currentLoop.parent)); json_object_set_new(currentJson, "parent", json_hex(currentLoop.parent));
json_object_set_new(currentJson, "icount", json_hex(currentLoop.instructioncount));
if(currentLoop.manual) if(currentLoop.manual)
json_array_append_new(jsonLoops, currentJson); json_array_append_new(jsonLoops, currentJson);
@ -228,6 +233,7 @@ void LoopCacheLoad(JSON Root)
loopInfo.end = (duint)json_hex_value(json_object_get(value, "end")); loopInfo.end = (duint)json_hex_value(json_object_get(value, "end"));
loopInfo.depth = (int)json_integer_value(json_object_get(value, "depth")); loopInfo.depth = (int)json_integer_value(json_object_get(value, "depth"));
loopInfo.parent = (duint)json_hex_value(json_object_get(value, "parent")); loopInfo.parent = (duint)json_hex_value(json_object_get(value, "parent"));
loopInfo.instructioncount = (duint)json_hex_value(json_object_get(value, "icount"));
loopInfo.manual = Manual; loopInfo.manual = Manual;
// Sanity check: Make sure the loop starts before it ends // Sanity check: Make sure the loop starts before it ends

View File

@ -11,10 +11,11 @@ struct LOOPSINFO
duint parent; duint parent;
int depth; int depth;
bool manual; bool manual;
duint instructioncount;
}; };
bool LoopAdd(duint Start, duint End, bool Manual); bool LoopAdd(duint Start, duint End, bool Manual, duint InstructionCount = 0);
bool LoopGet(int Depth, duint Address, duint* Start, duint* End); bool LoopGet(int Depth, duint Address, duint* Start = nullptr, duint* End = nullptr, duint* InstructionCount = nullptr);
bool LoopOverlaps(int Depth, duint Start, duint End, int* FinalDepth); bool LoopOverlaps(int Depth, duint Start, duint End, int* FinalDepth);
bool LoopDelete(int Depth, duint Address); bool LoopDelete(int Depth, duint Address);
void LoopCacheSave(JSON Root); void LoopCacheSave(JSON Root);

View File

@ -470,6 +470,9 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
Function_t funcType; Function_t funcType;
switch(loopType) switch(loopType)
{ {
case LOOP_SINGLE:
funcType = Function_single;
break;
case LOOP_BEGIN: case LOOP_BEGIN:
funcType = Function_start; funcType = Function_start;
break; break;
@ -485,7 +488,7 @@ QString Disassembly::paintContent(QPainter* painter, dsint rowBase, int rowOffse
default: default:
break; break;
} }
loopsize += paintFunctionGraphic(painter, x + loopsize, y, funcType, true); loopsize += paintFunctionGraphic(painter, x + loopsize, y, funcType, loopType != LOOP_SINGLE);
depth++; depth++;
} }