Skip to content

Commit

Permalink
Remove duplicated handling of DREQ_GET_MEM/DREQ_GET_MEM_BINARY
Browse files Browse the repository at this point in the history
  • Loading branch information
rocallahan committed Mar 23, 2024
1 parent 27d2cb5 commit 6478614
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 38 deletions.
15 changes: 2 additions & 13 deletions src/GdbServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -500,18 +500,7 @@ void GdbServer::dispatch_debugger_request(Session& session,
dbg->reply_get_auxv(target->vm()->saved_auxv());
return;
}
case DREQ_GET_MEM: {
vector<uint8_t> mem;
mem.resize(req.mem().len);
ssize_t nread = target->read_bytes_fallible(req.mem().addr, req.mem().len,
mem.data());
mem.resize(max(ssize_t(0), nread));
target->vm()->replace_breakpoints_with_original_values(
mem.data(), mem.size(), req.mem().addr);
maybe_intercept_mem_request(target, req, &mem);
dbg->reply_get_mem(mem);
return;
}
case DREQ_GET_MEM:
case DREQ_GET_MEM_BINARY: {
vector<uint8_t> mem;
mem.resize(req.mem().len);
Expand All @@ -521,7 +510,7 @@ void GdbServer::dispatch_debugger_request(Session& session,
target->vm()->replace_breakpoints_with_original_values(
mem.data(), mem.size(), req.mem().addr);
maybe_intercept_mem_request(target, req, &mem);
dbg->reply_get_mem_binary(mem);
dbg->reply_get_mem(mem);
return;
}
case DREQ_SET_MEM_BINARY: {
Expand Down
33 changes: 14 additions & 19 deletions src/GdbServerConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1848,28 +1848,23 @@ void GdbServerConnection::reply_select_thread(bool ok) {
}

void GdbServerConnection::reply_get_mem(const vector<uint8_t>& mem) {
DEBUG_ASSERT(DREQ_GET_MEM == req.type);
DEBUG_ASSERT(DREQ_GET_MEM == req.type || DREQ_GET_MEM_BINARY == req.type);
DEBUG_ASSERT(mem.size() <= req.mem().len);

if (req.mem().len > 0 && mem.size() == 0) {
write_packet("E01");
} else {
write_hex_bytes_packet(mem.data(), mem.size());
}

consume_request();
}

void GdbServerConnection::reply_get_mem_binary(const vector<uint8_t>& mem) {
DEBUG_ASSERT(DREQ_GET_MEM_BINARY == req.type);
DEBUG_ASSERT(mem.size() <= req.mem().len);

if (!req.mem().len) {
write_packet("OK");
} else if (!mem.size()) {
write_packet("E01");
if (DREQ_GET_MEM == req.type) {
if (req.mem().len > 0 && mem.size() == 0) {
write_packet("E01");
} else {
write_hex_bytes_packet(mem.data(), mem.size());
}
} else {
write_binary_packet("", mem.data(), mem.size());
if (!req.mem().len) {
write_packet("OK");
} else if (!mem.size()) {
write_packet("E01");
} else {
write_binary_packet("", mem.data(), mem.size());
}
}

consume_request();
Expand Down
6 changes: 0 additions & 6 deletions src/GdbServerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,6 @@ class GdbServerConnection {
*/
void reply_get_mem(const std::vector<uint8_t>& mem);

/**
* The first |mem.size()| bytes of the request were read into |mem|.
* |mem.size()| must be less than or equal to the length of the request.
*/
void reply_get_mem_binary(const std::vector<uint8_t>& mem);

/**
* |ok| is true if a SET_MEM_BINARY request succeeded, false otherwise. This
* function *must* be called whenever a SET_MEM_BINARY request is made,
Expand Down

0 comments on commit 6478614

Please sign in to comment.