Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to SYS_READ changes in PR #727 per review. #729

Merged
merged 6 commits into from
Jul 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/gdbserver/semihosting.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
int fd;
uint32_t buffer_len;
void *buffer;
int read_result;
ssize_t read_result;

if (mem_read(sl, r1, args, sizeof (args)) != 0 ) {
DLOG("Semihosting SYS_READ error: "
Expand Down Expand Up @@ -338,20 +338,20 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
DLOG("Semihosting: read(%d, target_addr:0x%08x, %zu)\n", fd,
buffer_address, buffer_len);

read_result = (uint32_t)read(fd, buffer, buffer_len);
read_result = read(fd, buffer, buffer_len);
saved_errno = errno;

if (*ret == (uint32_t)-1) {
if (read_result == (uint32_t)-1) {
Nightwalker-87 marked this conversation as resolved.
Show resolved Hide resolved
*ret = buffer_len;
} else {
if (mem_write(sl, buffer_address, buffer, *ret) != 0 ) {
if (mem_write(sl, buffer_address, buffer, read_result) != 0 ) {
DLOG("Semihosting SYS_READ error: "
"cannot write buffer to target memory\n");
free(buffer);
*ret = buffer_len;
return -1;
} else {
*ret = buffer_len - read_result;
*ret = buffer_len - (uint32_t)read_result;
}
}

Expand Down