From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by sourceware.org (Postfix) with ESMTPS id DD57F3842430 for ; Tue, 28 Jul 2020 15:05:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DD57F3842430 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gmx.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=n54@gmx.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1595948700; bh=znv89BLb1q3xTAbu1rjIGEJErqpxcMLyDvipDye7WaY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Hry9nN9UNpZUec802kZDl6kahC7YW4dqUxKtWJ26J1QQaOHQEUXiAxkvwInIyiZBw QdRQ00HyeSUjAtT+Qp09YMxuRQgJDKsbNW5fuv1o0aIRzttceLnDyw6Rdxq9AOMN4t FirxdYY3kYzDDUALukE44IL56+9OTh8ezSXdHc+M= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([89.79.191.25]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1Mi2Jt-1keQjy3RPl-00e5XK; Tue, 28 Jul 2020 17:05:00 +0200 From: Kamil Rytarowski To: gdb-patches@sourceware.org, jhb@FreeBSD.org, simark@simark.ca Subject: [PATCH v2] Implement xfer_partial TARGET_OBJECT_SIGNAL_INFO for NetBSD Date: Tue, 28 Jul 2020 17:04:18 +0200 Message-Id: <20200728150418.19720-1-n54@gmx.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200727074118.4030-1-n54@gmx.com> References: <20200727074118.4030-1-n54@gmx.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:tfi2PnRtMxAQLja8ioYd8ghNnJKrZcUQd7bMtV6swXp7Enrskd6 cLGXKT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uoOHzel1r9bIxzC0uaTsCxap1Tok HmgYyALFi54YyD2Ww9oJTMNyTkgGBG6bA8m+T5ATN9lSO+unTsWzum96J+9JWkC8ftD0+jFrQ Ryp5ZlFDzPrklApsJR1RsUso4EbSipB59ui+gYAG/xooQoEWD7FcW00cjOWR8VsCxnbUVTlsE Z0T614hm0xZA6vcsSLvvLIUFBog+mlCQ9oR+jYd1Ws2KIrTB9jxDT8eNdfntOQT4BBLGhE7Gq qFvNQQqZjJdzdKvLu9t3LvfPnfd0FyU3G9DMSWc7pmTcfPn6yiMLuikHI5hilyEufHiRgvSCe zN4Cvp7m/qz9z8GsR55xEg+cUbpcdwYQsEVRNb15T+uiRCfrkyD/aDmFhulW8cMEfbam7EXbV 6qRmkI6p+6cCtxWEs X-Spam-Status: No, score=-18.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jul 2020 15:05:11 -0000 NetBSD implements reading and overwriting siginfo_t received by the tracee. With TARGET_OBJECT_SIGNAL_INFO signal information can be examined and modified through the special variable $_siginfo. Implement the "get_siginfo_type" gdbarch method for NetBSD architectures. As with Linux architectures, cache the created type in the gdbarch when it is first created. Currently NetBSD uses an identical siginfo type on all architectures, so there is no support for architecture-specific fields= . gdb/ChangeLog: * nbsd-nat.h (nbsd_nat_target::xfer_partial): New declaration. * nbsd-nat.c (nbsd_nat_target::xfer_partial): New function. * nbsd-tdep.c (nbsd_gdbarch_data_handle, struct nbsd_gdbarch_data) (init_nbsd_gdbarch_data, get_nbsd_gdbarch_data) (nbsd_get_siginfo_type): New. (nbsd_init_abi): Install gdbarch "get_siginfo_type" method. (_initialize_nbsd_tdep): New =2D-- gdb/ChangeLog | 10 ++++ gdb/nbsd-nat.c | 45 ++++++++++++++ gdb/nbsd-nat.h | 6 ++ gdb/nbsd-tdep.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 217 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index defca83c263..c12eda04285 100644 =2D-- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2020-07-28 Kamil Rytarowski + + * nbsd-nat.h (nbsd_nat_target::xfer_partial): New declaration. + * nbsd-nat.c (nbsd_nat_target::xfer_partial): New function. + * nbsd-tdep.c (nbsd_gdbarch_data_handle, struct nbsd_gdbarch_data) + (init_nbsd_gdbarch_data, get_nbsd_gdbarch_data) + (nbsd_get_siginfo_type): New. + (nbsd_init_abi): Install gdbarch "get_siginfo_type" method. + (_initialize_nbsd_tdep): New. + 2020-07-28 H.J. Lu PR binutils/26301 diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c index a9405ebf862..bdf3388de0b 100644 =2D-- a/gdb/nbsd-nat.c +++ b/gdb/nbsd-nat.c @@ -845,3 +845,48 @@ nbsd_nat_target::supports_multi_process () { return true; } + +/* Implement the "xfer_partial" target_ops method. */ + +enum target_xfer_status +nbsd_nat_target::xfer_partial (enum target_object object, + const char *annex, gdb_byte *readbuf, + const gdb_byte *writebuf, + ULONGEST offset, ULONGEST len, + ULONGEST *xfered_len) +{ + pid_t pid =3D inferior_ptid.pid (); + + switch (object) + { + case TARGET_OBJECT_SIGNAL_INFO: + { + ptrace_siginfo_t psi; + + if (offset > sizeof (siginfo_t)) + return TARGET_XFER_E_IO; + + if (ptrace (PT_GET_SIGINFO, pid, &psi, sizeof (psi)) =3D=3D -1) + return TARGET_XFER_E_IO; + + if (offset + len > sizeof (siginfo_t)) + len =3D sizeof (siginfo_t) - offset; + + if (readbuf !=3D NULL) + memcpy (readbuf, ((gdb_byte *) &psi.psi_siginfo) + offset, len); + else + { + memcpy (((gdb_byte *) &psi.psi_siginfo) + offset, writebuf, len); + + if (ptrace (PT_SET_SIGINFO, pid, &psi, sizeof (psi)) =3D=3D -1) + return TARGET_XFER_E_IO; + } + *xfered_len =3D len; + return TARGET_XFER_OK; + } + default: + return inf_ptrace_target::xfer_partial (object, annex, + readbuf, writebuf, offset, + len, xfered_len); + } +} diff --git a/gdb/nbsd-nat.h b/gdb/nbsd-nat.h index 0a7048ecf35..59210ad1d03 100644 =2D-- a/gdb/nbsd-nat.h +++ b/gdb/nbsd-nat.h @@ -49,6 +49,12 @@ struct nbsd_nat_target : public inf_ptrace_target override; bool supports_multi_process () override; + enum target_xfer_status xfer_partial (enum target_object object, + const char *annex, + gdb_byte *readbuf, + const gdb_byte *writebuf, + ULONGEST offset, ULONGEST len, + ULONGEST *xfered_len) override; }; #endif /* nbsd-nat.h */ diff --git a/gdb/nbsd-tdep.c b/gdb/nbsd-tdep.c index 4fdfe476b59..ecbcbcfe163 100644 =2D-- a/gdb/nbsd-tdep.c +++ b/gdb/nbsd-tdep.c @@ -373,6 +373,153 @@ nbsd_skip_solib_resolver (struct gdbarch *gdbarch, C= ORE_ADDR pc) return find_solib_trampoline_target (get_current_frame (), pc); } +static struct gdbarch_data *nbsd_gdbarch_data_handle; + +struct nbsd_gdbarch_data +{ + struct type *siginfo_type; +}; + +static void * +init_nbsd_gdbarch_data (struct gdbarch *gdbarch) +{ + return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct nbsd_gdbarch_data); +} + +static struct nbsd_gdbarch_data * +get_nbsd_gdbarch_data (struct gdbarch *gdbarch) +{ + return ((struct nbsd_gdbarch_data *) + gdbarch_data (gdbarch, nbsd_gdbarch_data_handle)); +} + +/* Implement the "get_siginfo_type" gdbarch method. */ + +static struct type * +nbsd_get_siginfo_type (struct gdbarch *gdbarch) +{ + nbsd_gdbarch_data *nbsd_gdbarch_data =3D get_nbsd_gdbarch_data (gdbarch= ); + if (nbsd_gdbarch_data->siginfo_type !=3D NULL) + return nbsd_gdbarch_data->siginfo_type; + + type *char_type =3D builtin_type (gdbarch)->builtin_char; + type *int_type =3D builtin_type (gdbarch)->builtin_int; + type *long_type =3D builtin_type (gdbarch)->builtin_long; + + type *void_ptr_type + =3D lookup_pointer_type (builtin_type (gdbarch)->builtin_void); + + type *int32_type =3D builtin_type (gdbarch)->builtin_int32; + type *uint32_type =3D builtin_type (gdbarch)->builtin_uint32; + type *uint64_type =3D builtin_type (gdbarch)->builtin_uint64; + + bool lp64 =3D TYPE_LENGTH (void_ptr_type) =3D=3D 8; + size_t char_bits =3D gdbarch_addressable_memory_unit_size (gdbarch) * 8= ; + + /* pid_t */ + type *pid_type =3D arch_type (gdbarch, TYPE_CODE_TYPEDEF, + TYPE_LENGTH (int32_type) * char_bits, "pid_t"); + TYPE_TARGET_TYPE (pid_type) =3D int32_type; + + /* uid_t */ + type *uid_type =3D arch_type (gdbarch, TYPE_CODE_TYPEDEF, + TYPE_LENGTH (uint32_type) * char_bits, "uid_t"); + TYPE_TARGET_TYPE (uid_type) =3D uint32_type; + + /* clock_t */ + type *clock_type =3D arch_type (gdbarch, TYPE_CODE_TYPEDEF, + TYPE_LENGTH (int_type) * char_bits, "clock_t"); + TYPE_TARGET_TYPE (clock_type) =3D int_type; + + /* lwpid_t */ + type *lwpid_type =3D arch_type (gdbarch, TYPE_CODE_TYPEDEF, + TYPE_LENGTH (int32_type) * char_bits, + "lwpid_t"); + TYPE_TARGET_TYPE (lwpid_type) =3D int32_type; + + /* union sigval */ + type *sigval_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_UNI= ON); + sigval_type->set_name (gdbarch_obstack_strdup (gdbarch, "sigval")); + append_composite_type_field (sigval_type, "sival_int", int_type); + append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type); + + /* union _option */ + type *option_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_UNI= ON); + option_type->set_name (gdbarch_obstack_strdup (gdbarch, "_option")); + append_composite_type_field (option_type, "_pe_other_pid", pid_type); + append_composite_type_field (option_type, "_pe_lwp", lwpid_type); + + /* union _reason */ + type *reason_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_UNI= ON); + + /* _rt */ + type *t =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); + append_composite_type_field (t, "_pid", pid_type); + append_composite_type_field (t, "_uid", uid_type); + append_composite_type_field (t, "_value", sigval_type); + append_composite_type_field (reason_type, "_rt", t); + + /* _child */ + t =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); + append_composite_type_field (t, "_pid", pid_type); + append_composite_type_field (t, "_uid", uid_type); + append_composite_type_field (t, "_status", int_type); + append_composite_type_field (t, "_utime", clock_type); + append_composite_type_field (t, "_stime", clock_type); + append_composite_type_field (reason_type, "_child", t); + + /* _fault */ + t =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); + append_composite_type_field (t, "_addr", void_ptr_type); + append_composite_type_field (t, "_trap", int_type); + append_composite_type_field (t, "_trap2", int_type); + append_composite_type_field (t, "_trap3", int_type); + append_composite_type_field (reason_type, "_fault", t); + + /* _poll */ + t =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); + append_composite_type_field (t, "_band", long_type); + append_composite_type_field (t, "_fd", int_type); + append_composite_type_field (reason_type, "_poll", t); + + /* _syscall */ + t =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); + append_composite_type_field (t, "_sysnum", int_type); + append_composite_type_field (t, "_retval", + init_vector_type (int_type, 2)); + append_composite_type_field (t, "_error", int_type); + append_composite_type_field (t, "_args", + init_vector_type (uint64_type, 8)); + append_composite_type_field (reason_type, "_syscall", t); + + /* _ptrace_state */ + t =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); + append_composite_type_field (t, "_pe_report_event", int_type); + append_composite_type_field (t, "_option", option_type); + append_composite_type_field (reason_type, "_ptrace_state", t); + + /* struct _ksiginfo */ + type *ksiginfo_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_S= TRUCT); + ksiginfo_type->set_name (gdbarch_obstack_strdup (gdbarch, "_ksiginfo"))= ; + append_composite_type_field (ksiginfo_type, "_signo", int_type); + append_composite_type_field (ksiginfo_type, "_code", int_type); + append_composite_type_field (ksiginfo_type, "_errno", int_type); + if (lp64) + append_composite_type_field (ksiginfo_type, "_pad", int_type); + append_composite_type_field (ksiginfo_type, "_reason", reason_type); + + /* union siginfo */ + type *siginfo_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_UN= ION); + siginfo_type->set_name (gdbarch_obstack_strdup (gdbarch, "siginfo")); + append_composite_type_field (siginfo_type, "si_pad", + init_vector_type (char_type, 128)); + append_composite_type_field (siginfo_type, "_info", ksiginfo_type); + + nbsd_gdbarch_data->siginfo_type =3D siginfo_type; + + return siginfo_type; +} + /* See nbsd-tdep.h. */ void @@ -469,8 +616,17 @@ nbsd_init_abi (struct gdbarch_info info, struct gdbar= ch *gdbarch) set_gdbarch_gdb_signal_to_target (gdbarch, nbsd_gdb_signal_to_target); set_gdbarch_skip_solib_resolver (gdbarch, nbsd_skip_solib_resolver); set_gdbarch_auxv_parse (gdbarch, svr4_auxv_parse); + set_gdbarch_get_siginfo_type (gdbarch, nbsd_get_siginfo_type); /* `catch syscall' */ set_xml_syscall_file_name (gdbarch, "syscalls/netbsd.xml"); set_gdbarch_get_syscall_number (gdbarch, nbsd_get_syscall_number); } + +void _initialize_nbsd_tdep (); +void +_initialize_nbsd_tdep () +{ + nbsd_gdbarch_data_handle + =3D gdbarch_data_register_post_init (init_nbsd_gdbarch_data); +} =2D- 2.26.2