DBG: fixed some bugs with hardware breakpoints
This commit is contained in:
parent
31e82f73dd
commit
001c744a9f
|
@ -114,6 +114,17 @@ bool bpsetname(uint addr, BP_TYPE type, const char* name)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool bpsettitantype(uint addr, BP_TYPE type, int titantype)
|
||||
{
|
||||
if(!DbgIsDebugging())
|
||||
return false;
|
||||
BreakpointsInfo::iterator found=breakpoints.find(BreakpointKey(type, modhashfromva(addr)));
|
||||
if(found==breakpoints.end()) //not found
|
||||
return false;
|
||||
breakpoints[found->first].titantype=titantype;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bpenumall(BPENUMCALLBACK cbEnum, const char* module)
|
||||
{
|
||||
if(!DbgIsDebugging())
|
||||
|
|
|
@ -4,6 +4,14 @@
|
|||
#include "_global.h"
|
||||
#include "TitanEngine\TitanEngine.h"
|
||||
|
||||
//macros
|
||||
#define TITANSETDRX(titantype, drx) titantype &= 0x0FF; titantype |= (drx<<8)
|
||||
#define TITANGETDRX(titantype) (titantype >> 8) & 0xF
|
||||
#define TITANSETTYPE(titantype, type) titantype &= 0xF0F; titantype |= (type<<4)
|
||||
#define TITANGETTYPE(titantype) (titantype >> 4) & 0xF
|
||||
#define TITANSETSIZE(titantype, size) titantype &= 0xFF0; titantype |= size;
|
||||
#define TITANGETSIZE(titantype) titantype & 0xF
|
||||
|
||||
//enums
|
||||
enum BP_TYPE
|
||||
{
|
||||
|
@ -38,6 +46,7 @@ bool bpget(uint addr, BP_TYPE type, const char* name, BREAKPOINT* bp);
|
|||
bool bpdel(uint addr, BP_TYPE type);
|
||||
bool bpenable(uint addr, BP_TYPE type, bool enable);
|
||||
bool bpsetname(uint addr, BP_TYPE type, const char* name);
|
||||
bool bpsettitantype(uint addr, BP_TYPE type, int titantype);
|
||||
bool bpenumall(BPENUMCALLBACK cbEnum);
|
||||
bool bpenumall(BPENUMCALLBACK cbEnum, const char* module);
|
||||
int bpgetcount(BP_TYPE type, bool enabledonly = false);
|
||||
|
|
|
@ -319,7 +319,7 @@ void cbHardwareBreakpoint(void* ExceptionAddress)
|
|||
else
|
||||
{
|
||||
const char* bpsize="";
|
||||
switch(bp.titantype&0xF) //size
|
||||
switch(TITANGETSIZE(bp.titantype)) //size
|
||||
{
|
||||
case UE_HARDWARE_SIZE_1:
|
||||
bpsize="byte, ";
|
||||
|
@ -337,7 +337,7 @@ void cbHardwareBreakpoint(void* ExceptionAddress)
|
|||
#endif //_WIN64
|
||||
}
|
||||
const char* bptype="";
|
||||
switch((bp.titantype>>4)&0xF) //type
|
||||
switch(TITANGETTYPE(bp.titantype)) //type
|
||||
{
|
||||
case UE_HARDWARE_EXECUTE:
|
||||
bptype="execute";
|
||||
|
@ -544,7 +544,16 @@ static bool cbSetModuleBreakpoints(const BREAKPOINT* bp)
|
|||
|
||||
case BPHARDWARE:
|
||||
{
|
||||
if(!SetHardwareBreakPoint(bp->addr, 0, (bp->titantype>>4)&0xF, bp->titantype&0xF, (void*)cbHardwareBreakpoint))
|
||||
DWORD drx=0;
|
||||
if(!GetUnusedHardwareBreakPointRegister(&drx))
|
||||
{
|
||||
dputs("you can only set 4 hardware breakpoints");
|
||||
return false;
|
||||
}
|
||||
int titantype = bp->titantype;
|
||||
TITANSETDRX(titantype, drx);
|
||||
bpsettitantype(bp->addr, BPHARDWARE, titantype);
|
||||
if(!SetHardwareBreakPoint(bp->addr, drx, TITANGETTYPE(bp->titantype), TITANGETSIZE(bp->titantype), (void*)cbHardwareBreakpoint))
|
||||
dprintf("could not set hardware breakpoint "fhex"!\n", bp->addr);
|
||||
}
|
||||
break;
|
||||
|
@ -570,7 +579,7 @@ static bool cbRemoveModuleBreakpoints(const BREAKPOINT* bp)
|
|||
break;
|
||||
case BPHARDWARE:
|
||||
if(bp->enabled)
|
||||
DeleteHardwareBreakPoint((bp->titantype>>8)&0xF);
|
||||
DeleteHardwareBreakPoint(TITANGETDRX(bp->titantype));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1280,12 +1289,16 @@ bool cbEnableAllHardwareBreakpoints(const BREAKPOINT* bp)
|
|||
{
|
||||
if(bp->type!=BPHARDWARE or bp->enabled)
|
||||
return true;
|
||||
if(!GetUnusedHardwareBreakPointRegister(0))
|
||||
DWORD drx=0;
|
||||
if(!GetUnusedHardwareBreakPointRegister(&drx))
|
||||
{
|
||||
dprintf("did not enable hardware breakpoint "fhex" (all slots full)\n", bp->addr);
|
||||
return true;
|
||||
}
|
||||
if(!bpenable(bp->addr, BPHARDWARE, true) or !SetHardwareBreakPoint(bp->addr, (bp->titantype>>8)&0xF, (bp->titantype>>4)&0xF, bp->titantype&0xF, (void*)cbHardwareBreakpoint))
|
||||
int titantype = bp->titantype;
|
||||
TITANSETDRX(titantype, drx);
|
||||
bpsettitantype(bp->addr, BPHARDWARE, titantype);
|
||||
if(!bpenable(bp->addr, BPHARDWARE, true) or !SetHardwareBreakPoint(bp->addr, drx, TITANGETTYPE(bp->titantype), TITANGETSIZE(bp->titantype), (void*)cbHardwareBreakpoint))
|
||||
{
|
||||
dprintf("could not enable hardware breakpoint "fhex"\n", bp->addr);
|
||||
return false;
|
||||
|
@ -1297,7 +1310,7 @@ bool cbDisableAllHardwareBreakpoints(const BREAKPOINT* bp)
|
|||
{
|
||||
if(bp->type!=BPHARDWARE or !bp->enabled)
|
||||
return true;
|
||||
if(!bpenable(bp->addr, BPHARDWARE, false) or !DeleteHardwareBreakPoint((bp->titantype>>8)&0xF))
|
||||
if(!bpenable(bp->addr, BPHARDWARE, false) or !DeleteHardwareBreakPoint(TITANGETDRX(bp->titantype)))
|
||||
{
|
||||
dprintf("could not disable hardware breakpoint "fhex"\n", bp->addr);
|
||||
return false;
|
||||
|
@ -1323,7 +1336,7 @@ bool cbDisableAllMemoryBreakpoints(const BREAKPOINT* bp)
|
|||
{
|
||||
if(bp->type!=BPMEMORY or !bp->enabled)
|
||||
return true;
|
||||
if(!bpenable(bp->addr, BPMEMORY, false) or !DeleteHardwareBreakPoint((bp->titantype>>8)&0xF))
|
||||
if(!bpenable(bp->addr, BPMEMORY, false) or !DeleteHardwareBreakPoint(TITANGETDRX(bp->titantype)))
|
||||
{
|
||||
dprintf("could not disable memory breakpoint "fhex"\n", bp->addr);
|
||||
return false;
|
||||
|
@ -1371,7 +1384,7 @@ bool cbDeleteAllHardwareBreakpoints(const BREAKPOINT* bp)
|
|||
{
|
||||
if(!bp->enabled)
|
||||
return true;
|
||||
if(!bpdel(bp->addr, BPHARDWARE) or !DeleteHardwareBreakPoint((bp->titantype>>8)&0xF))
|
||||
if(!bpdel(bp->addr, BPHARDWARE) or !DeleteHardwareBreakPoint(TITANGETDRX(bp->titantype)))
|
||||
{
|
||||
dprintf("delete hardware breakpoint failed: "fhex"\n", bp->addr);
|
||||
return STATUS_ERROR;
|
||||
|
|
|
@ -630,7 +630,10 @@ CMDRESULT cbDebugSetHardwareBreakpoint(int argc, char* argv[])
|
|||
dputs("you can only set 4 hardware breakpoints");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
int titantype=(drx<<8)|(type<<4)|(DWORD)size;
|
||||
int titantype=0;
|
||||
TITANSETDRX(titantype, drx);
|
||||
TITANSETTYPE(titantype, type);
|
||||
TITANSETSIZE(titantype, size);
|
||||
//TODO: hwbp in multiple threads TEST
|
||||
if(bpget(addr, BPHARDWARE, 0, 0))
|
||||
{
|
||||
|
@ -666,7 +669,7 @@ CMDRESULT cbDebugDeleteHardwareBreakpoint(int argc, char* argv[])
|
|||
BREAKPOINT found;
|
||||
if(bpget(0, BPHARDWARE, arg1, &found)) //found a breakpoint with name
|
||||
{
|
||||
if(!bpdel(found.addr, BPHARDWARE) or !DeleteHardwareBreakPoint((found.titantype>>8)&0xF))
|
||||
if(!bpdel(found.addr, BPHARDWARE) or !DeleteHardwareBreakPoint(TITANGETDRX(found.titantype)))
|
||||
{
|
||||
dprintf("delete hardware breakpoint failed: "fhex"\n", found.addr);
|
||||
return STATUS_ERROR;
|
||||
|
@ -679,7 +682,7 @@ CMDRESULT cbDebugDeleteHardwareBreakpoint(int argc, char* argv[])
|
|||
dprintf("no such hardware breakpoint \"%s\"\n", arg1);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if(!bpdel(found.addr, BPHARDWARE) or !DeleteHardwareBreakPoint((found.titantype>>8)&0xF))
|
||||
if(!bpdel(found.addr, BPHARDWARE) or !DeleteHardwareBreakPoint(TITANGETDRX(found.titantype)))
|
||||
{
|
||||
dprintf("delete hardware breakpoint failed: "fhex"\n", found.addr);
|
||||
return STATUS_ERROR;
|
||||
|
@ -1142,7 +1145,7 @@ CMDRESULT cbDebugEnableHardwareBreakpoint(int argc, char* argv[])
|
|||
{
|
||||
char arg1[deflen]="";
|
||||
DWORD drx=0;
|
||||
if(!GetUnusedHardwareBreakPointRegister(0))
|
||||
if(!GetUnusedHardwareBreakPointRegister(&drx))
|
||||
{
|
||||
dputs("you can only set 4 hardware breakpoints");
|
||||
return STATUS_ERROR;
|
||||
|
@ -1173,7 +1176,9 @@ CMDRESULT cbDebugEnableHardwareBreakpoint(int argc, char* argv[])
|
|||
GuiUpdateAllViews();
|
||||
return STATUS_CONTINUE;
|
||||
}
|
||||
if(!bpenable(found.addr, BPHARDWARE, true) or !SetHardwareBreakPoint(found.addr, 0, (found.titantype>>4)&0xF, found.titantype&0xF, (void*)cbHardwareBreakpoint))
|
||||
TITANSETDRX(found.titantype, drx);
|
||||
bpsettitantype(found.addr, BPHARDWARE, found.titantype);
|
||||
if(!bpenable(found.addr, BPHARDWARE, true) or !SetHardwareBreakPoint(found.addr, drx, TITANGETTYPE(found.titantype), TITANGETSIZE(found.titantype), (void*)cbHardwareBreakpoint))
|
||||
{
|
||||
dprintf("could not enable hardware breakpoint "fhex"\n", found.addr);
|
||||
return STATUS_ERROR;
|
||||
|
@ -1211,7 +1216,7 @@ CMDRESULT cbDebugDisableHardwareBreakpoint(int argc, char* argv[])
|
|||
dputs("hardware breakpoint already disabled!");
|
||||
return STATUS_CONTINUE;
|
||||
}
|
||||
if(!bpenable(found.addr, BPHARDWARE, false) or !DeleteHardwareBreakPoint((found.titantype>>8)&0xF))
|
||||
if(!bpenable(found.addr, BPHARDWARE, false) or !DeleteHardwareBreakPoint(TITANGETDRX(found.titantype)))
|
||||
{
|
||||
dprintf("could not disable hardware breakpoint "fhex"\n", found.addr);
|
||||
return STATUS_ERROR;
|
||||
|
|
Loading…
Reference in New Issue