Skip to content

Commit

Permalink
display semihosting stdout and stderr with LOG_USER()
Browse files Browse the repository at this point in the history
this allows gdb to display the messages when openocd is connected by a pipe with `target remote | openocd -c "gdb_port pipe; log_output openocd.log"`
  • Loading branch information
nraynaud committed Jan 16, 2019
1 parent 31ea703 commit d0581ae
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/target/semihosting_common.c
Expand Up @@ -727,15 +727,13 @@ int semihosting_common(struct target *target)
LOG_DEBUG("dup(STDIN)=%d",
(int)semihosting->result);
} else if (mode < 8) {
semihosting->result = dup(
STDOUT_FILENO);
semihosting->sys_errno = errno;
semihosting->result = STDOUT_FILENO;
semihosting->sys_errno = -1;
LOG_DEBUG("dup(STDOUT)=%d",
(int)semihosting->result);
} else {
semihosting->result = dup(
STDERR_FILENO);
semihosting->sys_errno = errno;
semihosting->result = STDERR_FILENO;
semihosting->sys_errno = -1;
LOG_DEBUG("dup(STDERR)=%d",
(int)semihosting->result);
}
Expand Down Expand Up @@ -1142,7 +1140,7 @@ int semihosting_common(struct target *target)
fileio_info->param_2 = addr;
fileio_info->param_3 = len;
} else {
uint8_t *buf = malloc(len);
uint8_t *buf = malloc(len + 1);
if (!buf) {
semihosting->result = -1;
semihosting->sys_errno = ENOMEM;
Expand All @@ -1152,8 +1150,13 @@ int semihosting_common(struct target *target)
free(buf);
return retval;
}
semihosting->result = write(fd, buf, len);
semihosting->sys_errno = errno;
if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
buf[len] = 0;
LOG_USER("%s", buf);
} else {
semihosting->result = write(fd, buf, len);
semihosting->sys_errno = errno;
}
LOG_DEBUG("write(%d, 0x%" PRIx64 ", %zu)=%d",
fd,
addr,
Expand Down

0 comments on commit d0581ae

Please sign in to comment.