forked from Imagelibrary/binutils-gdb
Merge gdb and gdbserver implementations for siginfo
Extract the compatible siginfo handling from amd64-linux-nat.c and gdbserver/linux-x86-low to a new file nat/amd64-linux-siginfo.c. 2016-02-02 Walfred Tedeschi <walfred.tedeschi@intel.com> gdb/ChangeLog: * nat/amd64-linux-siginfo.c: New file. * nat/amd64-linux-siginfo.h: New file. * Makefile.in (HFILES_NO_SRCDIR): Add nat/amd64-linux-siginfo.h. (amd64-linux-siginfo.o): New rule. * config/i386/linux64.mh (NATDEPFILES): Add amd64-linux-siginfo.o. * amd64-linux-nat.c (nat/amd64-linux-siginfo.h): New include. (compat_siginfo_from_siginfo, siginfo_from_compat_siginfo) (compat_x32_siginfo_from_siginfo, siginfo_from_compat_x32_siginfo) (compat_timeval, compat_sigval, compat_x32_clock, cpt_si_pid) (cpt_si_uid, cpt_si_timerid, cpt_si_overrun, cpt_si_status) (cpt_si_utime, cpt_si_stime, cpt_si_ptr, cpt_si_addr, cpt_si_band) (cpt_si_fd, si_timerid, si_overrun): Move to nat/amd64-linux-siginfo.c. gdb/gdbserver/ChangeLog: * configure.srv (x86_64-*-linux*): Add amd64-linux-siginfo.o to srv_tgtobj. (i[34567]86-*-linux*): Add amd64-linux-siginfo.o to srv_tgtobj. * linux-x86-low.c [__x86_64__]: Include "nat/amd64-linux-siginfo.h". (compat_siginfo_from_siginfo, siginfo_from_compat_siginfo) (compat_x32_siginfo_from_siginfo, siginfo_from_compat_x32_siginfo) (compat_timeval, compat_sigval, compat_x32_clock, cpt_si_pid) (cpt_si_uid, cpt_si_timerid, cpt_si_overrun, cpt_si_status) (cpt_si_utime, cpt_si_stime, cpt_si_ptr, cpt_si_addr, cpt_si_band) (cpt_si_fd, si_timerid, si_overrun): Move from nat/amd64-linux-siginfo.c. * Makefile.in (amd64-linux-siginfo.o:): New rule.
This commit is contained in:
@@ -27,6 +27,10 @@
|
||||
#include "x86-xstate.h"
|
||||
#include "nat/gdb_ptrace.h"
|
||||
|
||||
#ifdef __x86_64__
|
||||
#include "nat/amd64-linux-siginfo.h"
|
||||
#endif
|
||||
|
||||
#include "gdb_proc_service.h"
|
||||
/* Don't include elf/common.h if linux/elf.h got included by
|
||||
gdb_proc_service.h. */
|
||||
@@ -670,399 +674,6 @@ x86_debug_reg_state (pid_t pid)
|
||||
as debugging it with a 32-bit GDBSERVER, we do the 32-bit <-> 64-bit
|
||||
conversion in-place ourselves. */
|
||||
|
||||
/* These types below (compat_*) define a siginfo type that is layout
|
||||
compatible with the siginfo type exported by the 32-bit userspace
|
||||
support. */
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
typedef int compat_int_t;
|
||||
typedef unsigned int compat_uptr_t;
|
||||
|
||||
typedef int compat_time_t;
|
||||
typedef int compat_timer_t;
|
||||
typedef int compat_clock_t;
|
||||
|
||||
struct compat_timeval
|
||||
{
|
||||
compat_time_t tv_sec;
|
||||
int tv_usec;
|
||||
};
|
||||
|
||||
typedef union compat_sigval
|
||||
{
|
||||
compat_int_t sival_int;
|
||||
compat_uptr_t sival_ptr;
|
||||
} compat_sigval_t;
|
||||
|
||||
typedef struct compat_siginfo
|
||||
{
|
||||
int si_signo;
|
||||
int si_errno;
|
||||
int si_code;
|
||||
|
||||
union
|
||||
{
|
||||
int _pad[((128 / sizeof (int)) - 3)];
|
||||
|
||||
/* kill() */
|
||||
struct
|
||||
{
|
||||
unsigned int _pid;
|
||||
unsigned int _uid;
|
||||
} _kill;
|
||||
|
||||
/* POSIX.1b timers */
|
||||
struct
|
||||
{
|
||||
compat_timer_t _tid;
|
||||
int _overrun;
|
||||
compat_sigval_t _sigval;
|
||||
} _timer;
|
||||
|
||||
/* POSIX.1b signals */
|
||||
struct
|
||||
{
|
||||
unsigned int _pid;
|
||||
unsigned int _uid;
|
||||
compat_sigval_t _sigval;
|
||||
} _rt;
|
||||
|
||||
/* SIGCHLD */
|
||||
struct
|
||||
{
|
||||
unsigned int _pid;
|
||||
unsigned int _uid;
|
||||
int _status;
|
||||
compat_clock_t _utime;
|
||||
compat_clock_t _stime;
|
||||
} _sigchld;
|
||||
|
||||
/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
|
||||
struct
|
||||
{
|
||||
unsigned int _addr;
|
||||
} _sigfault;
|
||||
|
||||
/* SIGPOLL */
|
||||
struct
|
||||
{
|
||||
int _band;
|
||||
int _fd;
|
||||
} _sigpoll;
|
||||
} _sifields;
|
||||
} compat_siginfo_t;
|
||||
|
||||
/* For x32, clock_t in _sigchld is 64bit aligned at 4 bytes. */
|
||||
typedef long __attribute__ ((__aligned__ (4))) compat_x32_clock_t;
|
||||
|
||||
typedef struct compat_x32_siginfo
|
||||
{
|
||||
int si_signo;
|
||||
int si_errno;
|
||||
int si_code;
|
||||
|
||||
union
|
||||
{
|
||||
int _pad[((128 / sizeof (int)) - 3)];
|
||||
|
||||
/* kill() */
|
||||
struct
|
||||
{
|
||||
unsigned int _pid;
|
||||
unsigned int _uid;
|
||||
} _kill;
|
||||
|
||||
/* POSIX.1b timers */
|
||||
struct
|
||||
{
|
||||
compat_timer_t _tid;
|
||||
int _overrun;
|
||||
compat_sigval_t _sigval;
|
||||
} _timer;
|
||||
|
||||
/* POSIX.1b signals */
|
||||
struct
|
||||
{
|
||||
unsigned int _pid;
|
||||
unsigned int _uid;
|
||||
compat_sigval_t _sigval;
|
||||
} _rt;
|
||||
|
||||
/* SIGCHLD */
|
||||
struct
|
||||
{
|
||||
unsigned int _pid;
|
||||
unsigned int _uid;
|
||||
int _status;
|
||||
compat_x32_clock_t _utime;
|
||||
compat_x32_clock_t _stime;
|
||||
} _sigchld;
|
||||
|
||||
/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
|
||||
struct
|
||||
{
|
||||
unsigned int _addr;
|
||||
} _sigfault;
|
||||
|
||||
/* SIGPOLL */
|
||||
struct
|
||||
{
|
||||
int _band;
|
||||
int _fd;
|
||||
} _sigpoll;
|
||||
} _sifields;
|
||||
} compat_x32_siginfo_t __attribute__ ((__aligned__ (8)));
|
||||
|
||||
#define cpt_si_pid _sifields._kill._pid
|
||||
#define cpt_si_uid _sifields._kill._uid
|
||||
#define cpt_si_timerid _sifields._timer._tid
|
||||
#define cpt_si_overrun _sifields._timer._overrun
|
||||
#define cpt_si_status _sifields._sigchld._status
|
||||
#define cpt_si_utime _sifields._sigchld._utime
|
||||
#define cpt_si_stime _sifields._sigchld._stime
|
||||
#define cpt_si_ptr _sifields._rt._sigval.sival_ptr
|
||||
#define cpt_si_addr _sifields._sigfault._addr
|
||||
#define cpt_si_band _sifields._sigpoll._band
|
||||
#define cpt_si_fd _sifields._sigpoll._fd
|
||||
|
||||
/* glibc at least up to 2.3.2 doesn't have si_timerid, si_overrun.
|
||||
In their place is si_timer1,si_timer2. */
|
||||
#ifndef si_timerid
|
||||
#define si_timerid si_timer1
|
||||
#endif
|
||||
#ifndef si_overrun
|
||||
#define si_overrun si_timer2
|
||||
#endif
|
||||
|
||||
static void
|
||||
compat_siginfo_from_siginfo (compat_siginfo_t *to, siginfo_t *from)
|
||||
{
|
||||
memset (to, 0, sizeof (*to));
|
||||
|
||||
to->si_signo = from->si_signo;
|
||||
to->si_errno = from->si_errno;
|
||||
to->si_code = from->si_code;
|
||||
|
||||
if (to->si_code == SI_TIMER)
|
||||
{
|
||||
to->cpt_si_timerid = from->si_timerid;
|
||||
to->cpt_si_overrun = from->si_overrun;
|
||||
to->cpt_si_ptr = (intptr_t) from->si_ptr;
|
||||
}
|
||||
else if (to->si_code == SI_USER)
|
||||
{
|
||||
to->cpt_si_pid = from->si_pid;
|
||||
to->cpt_si_uid = from->si_uid;
|
||||
}
|
||||
else if (to->si_code < 0)
|
||||
{
|
||||
to->cpt_si_pid = from->si_pid;
|
||||
to->cpt_si_uid = from->si_uid;
|
||||
to->cpt_si_ptr = (intptr_t) from->si_ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (to->si_signo)
|
||||
{
|
||||
case SIGCHLD:
|
||||
to->cpt_si_pid = from->si_pid;
|
||||
to->cpt_si_uid = from->si_uid;
|
||||
to->cpt_si_status = from->si_status;
|
||||
to->cpt_si_utime = from->si_utime;
|
||||
to->cpt_si_stime = from->si_stime;
|
||||
break;
|
||||
case SIGILL:
|
||||
case SIGFPE:
|
||||
case SIGSEGV:
|
||||
case SIGBUS:
|
||||
to->cpt_si_addr = (intptr_t) from->si_addr;
|
||||
break;
|
||||
case SIGPOLL:
|
||||
to->cpt_si_band = from->si_band;
|
||||
to->cpt_si_fd = from->si_fd;
|
||||
break;
|
||||
default:
|
||||
to->cpt_si_pid = from->si_pid;
|
||||
to->cpt_si_uid = from->si_uid;
|
||||
to->cpt_si_ptr = (intptr_t) from->si_ptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
siginfo_from_compat_siginfo (siginfo_t *to, compat_siginfo_t *from)
|
||||
{
|
||||
memset (to, 0, sizeof (*to));
|
||||
|
||||
to->si_signo = from->si_signo;
|
||||
to->si_errno = from->si_errno;
|
||||
to->si_code = from->si_code;
|
||||
|
||||
if (to->si_code == SI_TIMER)
|
||||
{
|
||||
to->si_timerid = from->cpt_si_timerid;
|
||||
to->si_overrun = from->cpt_si_overrun;
|
||||
to->si_ptr = (void *) (intptr_t) from->cpt_si_ptr;
|
||||
}
|
||||
else if (to->si_code == SI_USER)
|
||||
{
|
||||
to->si_pid = from->cpt_si_pid;
|
||||
to->si_uid = from->cpt_si_uid;
|
||||
}
|
||||
else if (to->si_code < 0)
|
||||
{
|
||||
to->si_pid = from->cpt_si_pid;
|
||||
to->si_uid = from->cpt_si_uid;
|
||||
to->si_ptr = (void *) (intptr_t) from->cpt_si_ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (to->si_signo)
|
||||
{
|
||||
case SIGCHLD:
|
||||
to->si_pid = from->cpt_si_pid;
|
||||
to->si_uid = from->cpt_si_uid;
|
||||
to->si_status = from->cpt_si_status;
|
||||
to->si_utime = from->cpt_si_utime;
|
||||
to->si_stime = from->cpt_si_stime;
|
||||
break;
|
||||
case SIGILL:
|
||||
case SIGFPE:
|
||||
case SIGSEGV:
|
||||
case SIGBUS:
|
||||
to->si_addr = (void *) (intptr_t) from->cpt_si_addr;
|
||||
break;
|
||||
case SIGPOLL:
|
||||
to->si_band = from->cpt_si_band;
|
||||
to->si_fd = from->cpt_si_fd;
|
||||
break;
|
||||
default:
|
||||
to->si_pid = from->cpt_si_pid;
|
||||
to->si_uid = from->cpt_si_uid;
|
||||
to->si_ptr = (void* ) (intptr_t) from->cpt_si_ptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
compat_x32_siginfo_from_siginfo (compat_x32_siginfo_t *to,
|
||||
siginfo_t *from)
|
||||
{
|
||||
memset (to, 0, sizeof (*to));
|
||||
|
||||
to->si_signo = from->si_signo;
|
||||
to->si_errno = from->si_errno;
|
||||
to->si_code = from->si_code;
|
||||
|
||||
if (to->si_code == SI_TIMER)
|
||||
{
|
||||
to->cpt_si_timerid = from->si_timerid;
|
||||
to->cpt_si_overrun = from->si_overrun;
|
||||
to->cpt_si_ptr = (intptr_t) from->si_ptr;
|
||||
}
|
||||
else if (to->si_code == SI_USER)
|
||||
{
|
||||
to->cpt_si_pid = from->si_pid;
|
||||
to->cpt_si_uid = from->si_uid;
|
||||
}
|
||||
else if (to->si_code < 0)
|
||||
{
|
||||
to->cpt_si_pid = from->si_pid;
|
||||
to->cpt_si_uid = from->si_uid;
|
||||
to->cpt_si_ptr = (intptr_t) from->si_ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (to->si_signo)
|
||||
{
|
||||
case SIGCHLD:
|
||||
to->cpt_si_pid = from->si_pid;
|
||||
to->cpt_si_uid = from->si_uid;
|
||||
to->cpt_si_status = from->si_status;
|
||||
to->cpt_si_utime = from->si_utime;
|
||||
to->cpt_si_stime = from->si_stime;
|
||||
break;
|
||||
case SIGILL:
|
||||
case SIGFPE:
|
||||
case SIGSEGV:
|
||||
case SIGBUS:
|
||||
to->cpt_si_addr = (intptr_t) from->si_addr;
|
||||
break;
|
||||
case SIGPOLL:
|
||||
to->cpt_si_band = from->si_band;
|
||||
to->cpt_si_fd = from->si_fd;
|
||||
break;
|
||||
default:
|
||||
to->cpt_si_pid = from->si_pid;
|
||||
to->cpt_si_uid = from->si_uid;
|
||||
to->cpt_si_ptr = (intptr_t) from->si_ptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
siginfo_from_compat_x32_siginfo (siginfo_t *to,
|
||||
compat_x32_siginfo_t *from)
|
||||
{
|
||||
memset (to, 0, sizeof (*to));
|
||||
|
||||
to->si_signo = from->si_signo;
|
||||
to->si_errno = from->si_errno;
|
||||
to->si_code = from->si_code;
|
||||
|
||||
if (to->si_code == SI_TIMER)
|
||||
{
|
||||
to->si_timerid = from->cpt_si_timerid;
|
||||
to->si_overrun = from->cpt_si_overrun;
|
||||
to->si_ptr = (void *) (intptr_t) from->cpt_si_ptr;
|
||||
}
|
||||
else if (to->si_code == SI_USER)
|
||||
{
|
||||
to->si_pid = from->cpt_si_pid;
|
||||
to->si_uid = from->cpt_si_uid;
|
||||
}
|
||||
else if (to->si_code < 0)
|
||||
{
|
||||
to->si_pid = from->cpt_si_pid;
|
||||
to->si_uid = from->cpt_si_uid;
|
||||
to->si_ptr = (void *) (intptr_t) from->cpt_si_ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (to->si_signo)
|
||||
{
|
||||
case SIGCHLD:
|
||||
to->si_pid = from->cpt_si_pid;
|
||||
to->si_uid = from->cpt_si_uid;
|
||||
to->si_status = from->cpt_si_status;
|
||||
to->si_utime = from->cpt_si_utime;
|
||||
to->si_stime = from->cpt_si_stime;
|
||||
break;
|
||||
case SIGILL:
|
||||
case SIGFPE:
|
||||
case SIGSEGV:
|
||||
case SIGBUS:
|
||||
to->si_addr = (void *) (intptr_t) from->cpt_si_addr;
|
||||
break;
|
||||
case SIGPOLL:
|
||||
to->si_band = from->cpt_si_band;
|
||||
to->si_fd = from->cpt_si_fd;
|
||||
break;
|
||||
default:
|
||||
to->si_pid = from->cpt_si_pid;
|
||||
to->si_uid = from->cpt_si_uid;
|
||||
to->si_ptr = (void* ) (intptr_t) from->cpt_si_ptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
||||
/* Convert a native/host siginfo object, into/from the siginfo in the
|
||||
layout of the inferiors' architecture. Returns true if any
|
||||
conversion was done; false otherwise. If DIRECTION is 1, then copy
|
||||
@@ -1079,30 +690,12 @@ x86_siginfo_fixup (siginfo_t *native, void *inf, int direction)
|
||||
|
||||
/* Is the inferior 32-bit? If so, then fixup the siginfo object. */
|
||||
if (!is_64bit_tdesc ())
|
||||
{
|
||||
gdb_assert (sizeof (siginfo_t) == sizeof (compat_siginfo_t));
|
||||
|
||||
if (direction == 0)
|
||||
compat_siginfo_from_siginfo ((struct compat_siginfo *) inf, native);
|
||||
else
|
||||
siginfo_from_compat_siginfo (native, (struct compat_siginfo *) inf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
return amd64_linux_siginfo_fixup_common (native, inf, direction,
|
||||
FIXUP_32);
|
||||
/* No fixup for native x32 GDB. */
|
||||
else if (!is_elf64 && sizeof (void *) == 8)
|
||||
{
|
||||
gdb_assert (sizeof (siginfo_t) == sizeof (compat_x32_siginfo_t));
|
||||
|
||||
if (direction == 0)
|
||||
compat_x32_siginfo_from_siginfo ((struct compat_x32_siginfo *) inf,
|
||||
native);
|
||||
else
|
||||
siginfo_from_compat_x32_siginfo (native,
|
||||
(struct compat_x32_siginfo *) inf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
return amd64_linux_siginfo_fixup_common (native, inf, direction,
|
||||
FIXUP_X32);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user