Skip to content

Commit

Permalink
Fix the bc command for inactive breakpoints under most circumstances
Browse files Browse the repository at this point in the history
Closes #3058
  • Loading branch information
mrexodia committed May 20, 2023
1 parent f9ddb52 commit 5eb556e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
41 changes: 32 additions & 9 deletions src/dbg/breakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ bool BpGet(duint Address, BP_TYPE Type, const char* Name, BREAKPOINT* Bp)
char* RVAPos = DLLName + (separatorPos - Name);
RVAPos[0] = RVAPos[1] = '\0';
RVAPos = RVAPos + 2; //Now 2 strings separated by NULs
if(valfromstring(RVAPos, &Address)) //"Address" reused here. No usage of original "Address" argument.
duint Rva;
if(valfromstring(RVAPos, &Rva))
{
if(separatorPos != Name) //Check if DLL name is surrounded by quotes. Don't be out of bounds!
{
Expand All @@ -210,16 +211,18 @@ bool BpGet(duint Address, BP_TYPE Type, const char* Name, BREAKPOINT* Bp)
if(DLLName[0] != '\0')
{
duint base = ModBaseFromName(DLLName); //Is the DLL actually loaded?
Address += base ? base : ModHashFromName(DLLName);
Rva += base ? base : ModHashFromName(DLLName);
}
else
{
duint base = ModBaseFromName(DLLName + 1);
Address += base ? base : ModHashFromName(DLLName + 1);
Rva += base ? base : ModHashFromName(DLLName + 1);
}

free(DLLName);

// Perform a lookup by address only
BREAKPOINT* bpInfo = BpInfoFromAddr(Type, Address);
BREAKPOINT* bpInfo = BpInfoFromAddr(Type, Rva);

if(!bpInfo)
return false;
Expand All @@ -229,11 +232,14 @@ bool BpGet(duint Address, BP_TYPE Type, const char* Name, BREAKPOINT* Bp)
return true;

*Bp = *bpInfo;
Bp->addr = Address;
Bp->addr = Rva;
setBpActive(*Bp);
return true;
}
free(DLLName);
else
{
free(DLLName);
}
}

// Do a lookup by breakpoint name
Expand Down Expand Up @@ -347,10 +353,27 @@ bool BpDelete(duint Address, BP_TYPE Type)
EXCLUSIVE_ACQUIRE(LockBreakpoints);

// Erase the index from the global list
if(Type != BPDLL)
return (breakpoints.erase(BreakpointKey(Type, ModHashFromAddr(Address))) > 0);
if(Type != BPDLL && Type != BPEXCEPTION)
return breakpoints.erase(BreakpointKey(Type, ModHashFromAddr(Address))) > 0;
else
return (breakpoints.erase(BreakpointKey(BPDLL, Address)) > 0);
return breakpoints.erase(BreakpointKey(Type, Address)) > 0;
}

bool BpDelete(const BREAKPOINT & Bp)
{
// Breakpoints without a module can be deleted without special logic
if(Bp.type == BPDLL || Bp.type == BPEXCEPTION || Bp.mod[0] == '\0')
return breakpoints.erase(BreakpointKey(Bp.type, Bp.addr)) > 0;

// Extract the RVA from the breakpoint
auto rva = Bp.addr;
auto loadedBase = ModBaseFromName(Bp.mod);
if(loadedBase != 0 && Bp.addr > loadedBase)
rva -= loadedBase;

// Calculate the breakpoint key with the module hash and rva
auto modHash = ModHashFromName(Bp.mod);
return breakpoints.erase(BreakpointKey(Bp.type, modHash + rva)) > 0;
}

bool BpEnable(duint Address, BP_TYPE Type, bool Enable)
Expand Down
1 change: 1 addition & 0 deletions src/dbg/breakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ bool BpNewDll(const char* module, bool Enable, bool Singleshot, DWORD TitanType,
bool BpGet(duint Address, BP_TYPE Type, const char* Name, BREAKPOINT* Bp);
bool BpGetAny(BP_TYPE Type, const char* Name, BREAKPOINT* Bp);
bool BpDelete(duint Address, BP_TYPE Type);
bool BpDelete(const BREAKPOINT & Bp);
bool BpEnable(duint Address, BP_TYPE Type, bool Enable);
bool BpSetName(duint Address, BP_TYPE Type, const char* Name);
bool BpSetTitanType(duint Address, BP_TYPE Type, int TitanType);
Expand Down
16 changes: 8 additions & 8 deletions src/dbg/commands/cmd-breakpoint-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ static bool cbDeleteAllBreakpoints(const BREAKPOINT* bp)
{
if(bp->type != BPNORMAL)
return true;
if(!BpDelete(bp->addr, BPNORMAL))
if(!BpDelete(*bp))
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Delete breakpoint failed (BpDelete): %p\n"), bp->addr);
return false;
}
if(bp->enabled && !DeleteBPX(bp->addr))
if(bp->enabled && bp->active && !DeleteBPX(bp->addr))
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Delete breakpoint failed (DeleteBPX): %p\n"), bp->addr);
return false;
Expand Down Expand Up @@ -331,12 +331,12 @@ static bool cbDeleteAllHardwareBreakpoints(const BREAKPOINT* bp)
{
if(bp->type != BPHARDWARE)
return true;
if(!BpDelete(bp->addr, BPHARDWARE))
if(!BpDelete(*bp))
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Delete hardware breakpoint failed (BpDelete): %p\n"), bp->addr);
return false;
}
if(bp->enabled && TITANDRXVALID(bp->titantype) && !DeleteHardwareBreakPoint(TITANGETDRX(bp->titantype)))
if(bp->enabled && bp->active && TITANDRXVALID(bp->titantype) && !DeleteHardwareBreakPoint(TITANGETDRX(bp->titantype)))
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Delete hardware breakpoint failed (DeleteHardwareBreakPoint): %p\n"), bp->addr);
return false;
Expand Down Expand Up @@ -636,12 +636,12 @@ static bool cbDeleteAllMemoryBreakpoints(const BREAKPOINT* bp)
return true;
duint size;
MemFindBaseAddr(bp->addr, &size);
if(!BpDelete(bp->addr, BPMEMORY))
if(!BpDelete(*bp))
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Delete memory breakpoint failed (BpDelete): %p\n"), bp->addr);
return false;
}
if(bp->enabled && !RemoveMemoryBPX(bp->addr, size))
if(bp->enabled && bp->active && !RemoveMemoryBPX(bp->addr, size))
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Delete memory breakpoint failed (RemoveMemoryBPX): %p\n"), bp->addr);
return false;
Expand Down Expand Up @@ -905,7 +905,7 @@ static bool cbDeleteAllDllBreakpoints(const BREAKPOINT* bp)
{
if(bp->type != BPDLL || !bp->enabled)
return true;
if(!BpDelete(bp->addr, BPDLL))
if(!BpDelete(*bp))
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Could not delete DLL breakpoint %s (BpDelete)\n"), bp->mod);
return false;
Expand Down Expand Up @@ -1121,7 +1121,7 @@ static bool cbDeleteAllExceptionBreakpoints(const BREAKPOINT* bp)
if(bp->type != BPEXCEPTION)
return true;

if(!BpDelete(bp->addr, BPEXCEPTION))
if(!BpDelete(*bp))
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Could not delete exception breakpoint %p (BpEnable)\n"), bp->addr);
return false;
Expand Down

0 comments on commit 5eb556e

Please sign in to comment.