gdbhio: stat structure needs to be packed

This commit is contained in:
TuxSH 2019-05-04 21:19:15 +02:00
parent 53df2f20b8
commit b34182d53d
3 changed files with 39 additions and 7 deletions

View File

@ -24,7 +24,7 @@ int gdbHioDevGetStdout(void);
///< Returns a file descriptor mapping to the GDB client console's standard error stream. ///< Returns a file descriptor mapping to the GDB client console's standard error stream.
int gdbHioDevGetStderr(void); int gdbHioDevGetStderr(void);
///< Redirects 0 to 3 of the application's standard streams to GDB client console's. ///< Redirects 0 to 3 of the application's standard streams to GDB client console's. Returns -1, -2, or -3, resp., on failure; 0 on success.
int gdbHioDevRedirectStdStreams(bool in, bool out, bool err); int gdbHioDevRedirectStdStreams(bool in, bool out, bool err);
///< GDB HIO POSIX function gettimeofday. ///< GDB HIO POSIX function gettimeofday.

View File

@ -204,7 +204,8 @@ static int _gdbExportSeekFlag(int flag)
} }
// https://sourceware.org/gdb/onlinedocs/gdb/struct-stat.html#struct-stat // https://sourceware.org/gdb/onlinedocs/gdb/struct-stat.html#struct-stat
typedef u32 gdbhio_time_t; typedef u32 gdbhio_time_t;
struct gdbhio_stat {
struct PACKED ALIGN(4) gdbhio_stat {
u32 st_dev; /* device */ u32 st_dev; /* device */
u32 st_ino; /* inode */ u32 st_ino; /* inode */
gdbhio_mode_t st_mode; /* protection */ gdbhio_mode_t st_mode; /* protection */
@ -261,7 +262,9 @@ static void _gdbHioImportStructTimeval(struct timeval *out, const struct gdbhio_
static void _gdbHioSetErrno(int gdbErrno, bool ctrlC) static void _gdbHioSetErrno(int gdbErrno, bool ctrlC)
{ {
if (gdbErrno != 0) {
errno = _gdbHioImportErrno(gdbErrno); errno = _gdbHioImportErrno(gdbErrno);
}
g_gdbHioWasInterruptedByCtrlC = ctrlC; g_gdbHioWasInterruptedByCtrlC = ctrlC;
} }

View File

@ -22,6 +22,19 @@ static int _gdbHioGetFd(int fd)
return *(int *)handle->fileStruct; return *(int *)handle->fileStruct;
} }
static bool _gdbHioCompareFd(int fd, int fdval)
{
__handle *handle = __get_handle(fd);
if (handle == NULL) {
return false;
}
if(strcmp(devoptab_list[handle->device]->name, "gdbhio") != 0) {
return false;
}
return *(int *)handle->fileStruct == fdval;
}
static inline int _gdbHioGetFdFromPtr(void *fdptr) static inline int _gdbHioGetFdFromPtr(void *fdptr)
{ {
return *(int *)fdptr; return *(int *)fdptr;
@ -189,8 +202,24 @@ int gdbHioDevGetStderr(void)
int gdbHioDevRedirectStdStreams(bool in, bool out, bool err) int gdbHioDevRedirectStdStreams(bool in, bool out, bool err)
{ {
int ret = 0; int ret = 0;
if (in && (ret = dup2(gdbHioDevGetStdin(), STDIN_FILENO) < 0)) return ret; int fd = -1;
if (out && (ret = dup2(gdbHioDevGetStdout(), STDOUT_FILENO) < 0)) return ret; if (in && !_gdbHioCompareFd(STDIN_FILENO, GDBHIO_STDIN_FILENO)) {
if (err && (ret = dup2(gdbHioDevGetStderr(), STDERR_FILENO) < 0)) return ret; fd = gdbHioDevGetStdin();
ret = dup2(fd, STDIN_FILENO);
close(fd);
if (ret < 0) return -1;
}
if (out && !_gdbHioCompareFd(STDOUT_FILENO, GDBHIO_STDOUT_FILENO)) {
fd = gdbHioDevGetStdout();
ret = dup2(fd, STDOUT_FILENO);
close(fd);
if (ret < 0) return -2;
}
if (err && !_gdbHioCompareFd(STDERR_FILENO, GDBHIO_STDERR_FILENO)) {
fd = gdbHioDevGetStderr();
ret = dup2(fd, STDERR_FILENO);
close(fd);
if (ret < 0) return -3;
}
return ret; return ret;
} }