gdbstub: Use type alias for breakpoint maps

Rather than having to type out the full std::map type signature, we can
just use a straightforward alias. While we're at it, rename
GetBreakpointList to GetBreakpointMap, which makes the name more
accurate. We can also get rid of unnecessary u64 static_casts, since
VAddr is an alias for a u64.
This commit is contained in:
Lioncash 2018-08-05 16:11:29 -04:00
parent 89c076b4b1
commit 00f7e584ce

View File

@ -175,9 +175,10 @@ struct Breakpoint {
u64 len;
};
std::map<u64, Breakpoint> breakpoints_execute;
std::map<u64, Breakpoint> breakpoints_read;
std::map<u64, Breakpoint> breakpoints_write;
using BreakpointMap = std::map<VAddr, Breakpoint>;
BreakpointMap breakpoints_execute;
BreakpointMap breakpoints_read;
BreakpointMap breakpoints_write;
struct Module {
std::string name;
@ -419,11 +420,11 @@ static u8 CalculateChecksum(const u8* buffer, size_t length) {
}
/**
* Get the list of breakpoints for a given breakpoint type.
* Get the map of breakpoints for a given breakpoint type.
*
* @param type Type of breakpoint list.
* @param type Type of breakpoint map.
*/
static std::map<u64, Breakpoint>& GetBreakpointList(BreakpointType type) {
static BreakpointMap& GetBreakpointMap(BreakpointType type) {
switch (type) {
case BreakpointType::Execute:
return breakpoints_execute;
@ -443,19 +444,21 @@ static std::map<u64, Breakpoint>& GetBreakpointList(BreakpointType type) {
* @param addr Address of breakpoint.
*/
static void RemoveBreakpoint(BreakpointType type, VAddr addr) {
std::map<u64, Breakpoint>& p = GetBreakpointList(type);
BreakpointMap& p = GetBreakpointMap(type);
const auto bp = p.find(addr);
if (bp == p.end()) {
return;
}
auto bp = p.find(static_cast<u64>(addr));
if (bp != p.end()) {
LOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: {:016X} bytes at {:016X} of type {}",
bp->second.len, bp->second.addr, static_cast<int>(type));
p.erase(static_cast<u64>(addr));
}
p.erase(addr);
}
BreakpointAddress GetNextBreakpointFromAddress(VAddr addr, BreakpointType type) {
std::map<u64, Breakpoint>& p = GetBreakpointList(type);
auto next_breakpoint = p.lower_bound(static_cast<u64>(addr));
const BreakpointMap& p = GetBreakpointMap(type);
const auto next_breakpoint = p.lower_bound(addr);
BreakpointAddress breakpoint;
if (next_breakpoint != p.end()) {
@ -474,10 +477,13 @@ bool CheckBreakpoint(VAddr addr, BreakpointType type) {
return false;
}
std::map<u64, Breakpoint>& p = GetBreakpointList(type);
const BreakpointMap& p = GetBreakpointMap(type);
const auto bp = p.find(addr);
if (bp == p.end()) {
return false;
}
auto bp = p.find(static_cast<u64>(addr));
if (bp != p.end()) {
u64 len = bp->second.len;
// IDA Pro defaults to 4-byte breakpoints for all non-hardware breakpoints
@ -499,7 +505,6 @@ bool CheckBreakpoint(VAddr addr, BreakpointType type) {
static_cast<int>(type), addr, bp->second.addr, bp->second.addr + len, len);
return true;
}
}
return false;
}
@ -977,7 +982,7 @@ static void Continue() {
* @param len Length of breakpoint.
*/
static bool CommitBreakpoint(BreakpointType type, VAddr addr, u64 len) {
std::map<u64, Breakpoint>& p = GetBreakpointList(type);
BreakpointMap& p = GetBreakpointMap(type);
Breakpoint breakpoint;
breakpoint.active = true;