This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] [PR gdb/23093] Implementation of "gdbarch_gdb_signal_to/from_target" on FreeBSD
- From: Rajendra SY <rajendra dot sy at gmail dot com>
- To: John Baldwin <jhb at freebsd dot org>
- Cc: gdb-patches at sourceware dot org
- Date: Sat, 5 May 2018 11:15:20 +0530
- Subject: Re: [PATCH] [PR gdb/23093] Implementation of "gdbarch_gdb_signal_to/from_target" on FreeBSD
- References: <CAMAnt0mWQLGsYpwqJucrkuf0U+3caSVy_6BgDb1CwShB3cYnew@mail.gmail.com> <3393443.3hyCjj7TaN@ralph.baldwin.cx>
John,
Thanks for the review comments.
> Do you have a copyright assignment on file for contributions to GDB?
No
Would you please commit this patch?
Thanks
Rajendra
On Sat, May 5, 2018 at 12:01 AM, John Baldwin <jhb@freebsd.org> wrote:
> On Friday, April 27, 2018 08:55:03 AM Rajendra SY wrote:
>> Resending the same patch for review comments.
>>
>> Problem:
>> The $_exitsignal internal variable does not get updated on FreeBSD platform.
>>
>> Cause:
>> FreeBSD target is missing signal mapping functions
>> "gdb_signal_to_target" & "gdb_signal_from_target".
>> The code flow gdb/infrun.c:5075 [a call to
>> gdbarch_gdb_signal_to_target_p()] tries to find out if the target has
>> these functions. In case of FreeBSD it is not so it just skips
>> updating '$_exitsignal' variable.
>>
>> The attached patch implements these functions to provide correct
>> FreeBSD signal to GDB signal mapping information.
>>
>> Tests:
>> FAIL: gdb.base/exitsignal.exp: $_exitsignal is 11 (SIGSEGV) after SIGSEGV.
>> FAIL: gdb.base/exitsignal.exp: $_exitsignal is 11 (SIGSEGV) after
>> restarting the inferior
>>
>> These above currently failing tests will pass with this fix.
>>
>> gdb/ChangeLog:
>> 2018-04-27 Rajendra SY <rajendra.sy@gmail.com>
>>
>> PR gdb/23093
>> * gdb/fbsd-tdep.c (enum gdb_signal):
>> (fbsd_gdb_signal_from_target):
>> (fbsd_gdb_signal_to_target):
>> (fbsd_init_abi):
>
> Thanks, I've tested this change and I have some small changes to it below. Do
> you have a copyright assignment on file for contributions to GDB?
>
> From 4346c0567fd137f845cdc46c0a0d8f6047db0ec9 Mon Sep 17 00:00:00 2001
> From: Rajendra SY <rajendra.sy@gmail.com>
> Date: Wed, 2 May 2018 11:04:24 -0700
> Subject: [PATCH] Implement the "gdb_signal_to/from_target" gdbarch methods for
> FreeBSD.
>
> This fixes failures in the gdb.base/exitsignal.exp test.
>
> gdb/ChangeLog:
>
> PR gdb/23093
> * gdb/fbsd-tdep.c (fbsd_gdb_signal_from_target)
> (fbsd_gdb_signal_to_target): New.
> (fbsd_init_abi): Install gdbarch "signal_from_target" and
> "signal_to_target" methods.
> ---
> gdb/ChangeLog | 8 ++
> gdb/fbsd-tdep.c | 282 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 290 insertions(+)
>
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index f326c8e2d3..46c474b612 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,11 @@
> +2018-05-02 Rajendra SY <rajendra.sy@gmail.com>
> +
> + PR gdb/23093
> + * gdb/fbsd-tdep.c (fbsd_gdb_signal_from_target)
> + (fbsd_gdb_signal_to_target): New.
> + (fbsd_init_abi): Install gdbarch "signal_from_target" and
> + "signal_to_target" methods.
> +
> 2018-05-02 Tom Tromey <tom@tromey.com>
>
> PR python/20084:
> diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
> index e49a9aff09..6703cd698d 100644
> --- a/gdb/fbsd-tdep.c
> +++ b/gdb/fbsd-tdep.c
> @@ -29,6 +29,46 @@
> #include "elf-bfd.h"
> #include "fbsd-tdep.h"
>
> +/* This enum is derived from FreeBSD's <sys/signal.h>. */
> +
> +enum
> + {
> + FREEBSD_SIGHUP = 1,
> + FREEBSD_SIGINT = 2,
> + FREEBSD_SIGQUIT = 3,
> + FREEBSD_SIGILL = 4,
> + FREEBSD_SIGTRAP = 5,
> + FREEBSD_SIGABRT = 6,
> + FREEBSD_SIGEMT = 7,
> + FREEBSD_SIGFPE = 8,
> + FREEBSD_SIGKILL = 9,
> + FREEBSD_SIGBUS = 10,
> + FREEBSD_SIGSEGV = 11,
> + FREEBSD_SIGSYS = 12,
> + FREEBSD_SIGPIPE = 13,
> + FREEBSD_SIGALRM = 14,
> + FREEBSD_SIGTERM = 15,
> + FREEBSD_SIGURG = 16,
> + FREEBSD_SIGSTOP = 17,
> + FREEBSD_SIGTSTP = 18,
> + FREEBSD_SIGCONT = 19,
> + FREEBSD_SIGCHLD = 20,
> + FREEBSD_SIGTTIN = 21,
> + FREEBSD_SIGTTOU = 22,
> + FREEBSD_SIGIO = 23,
> + FREEBSD_SIGXCPU = 24,
> + FREEBSD_SIGXFSZ = 25,
> + FREEBSD_SIGVTALRM = 26,
> + FREEBSD_SIGPROF = 27,
> + FREEBSD_SIGWINCH = 28,
> + FREEBSD_SIGINFO = 29,
> + FREEBSD_SIGUSR1 = 30,
> + FREEBSD_SIGUSR2 = 31,
> + FREEBSD_SIGTHR = 32,
> + FREEBSD_SIGLIBRT = 33,
> + FREEBSD_SIGRTMIN = 65,
> + FREEBSD_SIGRTMAX = 126,
> + };
>
> /* FreeBSD kernels 12.0 and later include a copy of the
> 'ptrace_lwpinfo' structure returned by the PT_LWPINFO ptrace
> @@ -1143,6 +1183,246 @@ fbsd_get_siginfo_type (struct gdbarch *gdbarch)
> return siginfo_type;
> }
>
> +/* Implement the "gdb_signal_from_target" gdbarch method. */
> +
> +static enum gdb_signal
> +fbsd_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
> +{
> + switch (signal)
> + {
> + case 0:
> + return GDB_SIGNAL_0;
> +
> + case FREEBSD_SIGHUP:
> + return GDB_SIGNAL_HUP;
> +
> + case FREEBSD_SIGINT:
> + return GDB_SIGNAL_INT;
> +
> + case FREEBSD_SIGQUIT:
> + return GDB_SIGNAL_QUIT;
> +
> + case FREEBSD_SIGILL:
> + return GDB_SIGNAL_ILL;
> +
> + case FREEBSD_SIGTRAP:
> + return GDB_SIGNAL_TRAP;
> +
> + case FREEBSD_SIGABRT:
> + return GDB_SIGNAL_ABRT;
> +
> + case FREEBSD_SIGEMT:
> + return GDB_SIGNAL_EMT;
> +
> + case FREEBSD_SIGFPE:
> + return GDB_SIGNAL_FPE;
> +
> + case FREEBSD_SIGKILL:
> + return GDB_SIGNAL_KILL;
> +
> + case FREEBSD_SIGBUS:
> + return GDB_SIGNAL_BUS;
> +
> + case FREEBSD_SIGSEGV:
> + return GDB_SIGNAL_SEGV;
> +
> + case FREEBSD_SIGSYS:
> + return GDB_SIGNAL_SYS;
> +
> + case FREEBSD_SIGPIPE:
> + return GDB_SIGNAL_PIPE;
> +
> + case FREEBSD_SIGALRM:
> + return GDB_SIGNAL_ALRM;
> +
> + case FREEBSD_SIGTERM:
> + return GDB_SIGNAL_TERM;
> +
> + case FREEBSD_SIGURG:
> + return GDB_SIGNAL_URG;
> +
> + case FREEBSD_SIGSTOP:
> + return GDB_SIGNAL_STOP;
> +
> + case FREEBSD_SIGTSTP:
> + return GDB_SIGNAL_TSTP;
> +
> + case FREEBSD_SIGCONT:
> + return GDB_SIGNAL_CONT;
> +
> + case FREEBSD_SIGCHLD:
> + return GDB_SIGNAL_CHLD;
> +
> + case FREEBSD_SIGTTIN:
> + return GDB_SIGNAL_TTIN;
> +
> + case FREEBSD_SIGTTOU:
> + return GDB_SIGNAL_TTOU;
> +
> + case FREEBSD_SIGIO:
> + return GDB_SIGNAL_IO;
> +
> + case FREEBSD_SIGXCPU:
> + return GDB_SIGNAL_XCPU;
> +
> + case FREEBSD_SIGXFSZ:
> + return GDB_SIGNAL_XFSZ;
> +
> + case FREEBSD_SIGVTALRM:
> + return GDB_SIGNAL_VTALRM;
> +
> + case FREEBSD_SIGPROF:
> + return GDB_SIGNAL_PROF;
> +
> + case FREEBSD_SIGWINCH:
> + return GDB_SIGNAL_WINCH;
> +
> + case FREEBSD_SIGINFO:
> + return GDB_SIGNAL_INFO;
> +
> + case FREEBSD_SIGUSR1:
> + return GDB_SIGNAL_USR1;
> +
> + case FREEBSD_SIGUSR2:
> + return GDB_SIGNAL_USR2;
> +
> + /* SIGTHR is the same as SIGLWP on FreeBSD. */
> + case FREEBSD_SIGTHR:
> + return GDB_SIGNAL_LWP;
> +
> + case FREEBSD_SIGLIBRT:
> + return GDB_SIGNAL_LIBRT;
> + }
> +
> + if (signal >= FREEBSD_SIGRTMIN && signal <= FREEBSD_SIGRTMAX)
> + {
> + int offset = signal - FREEBSD_SIGRTMIN;
> +
> + return (enum gdb_signal) ((int) GDB_SIGNAL_REALTIME_65 + offset);
> + }
> +
> + return GDB_SIGNAL_UNKNOWN;
> +}
> +
> +/* Implement the "gdb_signal_to_target" gdbarch method. */
> +
> +static int
> +fbsd_gdb_signal_to_target (struct gdbarch *gdbarch,
> + enum gdb_signal signal)
> +{
> + switch (signal)
> + {
> + case GDB_SIGNAL_0:
> + return 0;
> +
> + case GDB_SIGNAL_HUP:
> + return FREEBSD_SIGHUP;
> +
> + case GDB_SIGNAL_INT:
> + return FREEBSD_SIGINT;
> +
> + case GDB_SIGNAL_QUIT:
> + return FREEBSD_SIGQUIT;
> +
> + case GDB_SIGNAL_ILL:
> + return FREEBSD_SIGILL;
> +
> + case GDB_SIGNAL_TRAP:
> + return FREEBSD_SIGTRAP;
> +
> + case GDB_SIGNAL_ABRT:
> + return FREEBSD_SIGABRT;
> +
> + case GDB_SIGNAL_EMT:
> + return FREEBSD_SIGEMT;
> +
> + case GDB_SIGNAL_FPE:
> + return FREEBSD_SIGFPE;
> +
> + case GDB_SIGNAL_KILL:
> + return FREEBSD_SIGKILL;
> +
> + case GDB_SIGNAL_BUS:
> + return FREEBSD_SIGBUS;
> +
> + case GDB_SIGNAL_SEGV:
> + return FREEBSD_SIGSEGV;
> +
> + case GDB_SIGNAL_SYS:
> + return FREEBSD_SIGSYS;
> +
> + case GDB_SIGNAL_PIPE:
> + return FREEBSD_SIGPIPE;
> +
> + case GDB_SIGNAL_ALRM:
> + return FREEBSD_SIGALRM;
> +
> + case GDB_SIGNAL_TERM:
> + return FREEBSD_SIGTERM;
> +
> + case GDB_SIGNAL_URG:
> + return FREEBSD_SIGURG;
> +
> + case GDB_SIGNAL_STOP:
> + return FREEBSD_SIGSTOP;
> +
> + case GDB_SIGNAL_TSTP:
> + return FREEBSD_SIGTSTP;
> +
> + case GDB_SIGNAL_CONT:
> + return FREEBSD_SIGCONT;
> +
> + case GDB_SIGNAL_CHLD:
> + return FREEBSD_SIGCHLD;
> +
> + case GDB_SIGNAL_TTIN:
> + return FREEBSD_SIGTTIN;
> +
> + case GDB_SIGNAL_TTOU:
> + return FREEBSD_SIGTTOU;
> +
> + case GDB_SIGNAL_IO:
> + return FREEBSD_SIGIO;
> +
> + case GDB_SIGNAL_XCPU:
> + return FREEBSD_SIGXCPU;
> +
> + case GDB_SIGNAL_XFSZ:
> + return FREEBSD_SIGXFSZ;
> +
> + case GDB_SIGNAL_VTALRM:
> + return FREEBSD_SIGVTALRM;
> +
> + case GDB_SIGNAL_PROF:
> + return FREEBSD_SIGPROF;
> +
> + case GDB_SIGNAL_WINCH:
> + return FREEBSD_SIGWINCH;
> +
> + case GDB_SIGNAL_INFO:
> + return FREEBSD_SIGINFO;
> +
> + case GDB_SIGNAL_USR1:
> + return FREEBSD_SIGUSR1;
> +
> + case GDB_SIGNAL_USR2:
> + return FREEBSD_SIGUSR2;
> +
> + case GDB_SIGNAL_LWP:
> + return FREEBSD_SIGTHR;
> + }
> +
> + if (signal >= GDB_SIGNAL_REALTIME_65
> + && signal <= GDB_SIGNAL_REALTIME_126)
> + {
> + int offset = signal - GDB_SIGNAL_REALTIME_65;
> +
> + return FREEBSD_SIGRTMIN + offset;
> + }
> +
> + return -1;
> +}
> +
> /* Implement the "get_syscall_number" gdbarch method. */
>
> static LONGEST
> @@ -1171,6 +1451,8 @@ fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
> set_gdbarch_core_info_proc (gdbarch, fbsd_core_info_proc);
> set_gdbarch_print_auxv_entry (gdbarch, fbsd_print_auxv_entry);
> set_gdbarch_get_siginfo_type (gdbarch, fbsd_get_siginfo_type);
> + set_gdbarch_gdb_signal_from_target (gdbarch, fbsd_gdb_signal_from_target);
> + set_gdbarch_gdb_signal_to_target (gdbarch, fbsd_gdb_signal_to_target);
>
> /* `catch syscall' */
> set_xml_syscall_file_name (gdbarch, "syscalls/freebsd.xml");
> --
> 2.15.1
>
>
>
> --
> John Baldwin