From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by sourceware.org (Postfix) with ESMTPS id A48ED3858D35 for ; Mon, 27 Jul 2020 07:42:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A48ED3858D35 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=1595835719; bh=bI2tziy78mNbWhVjNm6gkkDMRXXM4uTExqK4Cnnr93E=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=aQFHhBYtdXDTYmBLgbhdXvYnUrimaYzKYejjYWJJ/XHEBg7B0E0q5NMQ9b5eb8xsj vu50CGHjGFB6sJZQdF948T74k3Qujq1rEAftXx3411hqHm59UG2LW9CnrIeRjHdeJX 63VuT9GrVNsIEJ396jXbo9eaH9rAIE6mebuIl+7g= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([89.79.191.25]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MtOGa-1kmqd71XUE-00uohe; Mon, 27 Jul 2020 09:41:59 +0200 From: Kamil Rytarowski To: gdb-patches@sourceware.org Subject: [PATCH] Implement xfer_partial TARGET_OBJECT_SIGNAL_INFO for NetBSD Date: Mon, 27 Jul 2020 09:41:18 +0200 Message-Id: <20200727074118.4030-1-n54@gmx.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:pB5pYwUWA6drNZLphk1B2wVUgjLH/fUTYvLDAGKQg7FxYWTX/DB O3nknw1wFIfVXIQxUiod1TznRO72Rx+DA4h9Nbcn7zvrJoMoyCsoPTzZqnbU5WKlxXKqgCY 4zMzMKSEpBq2hkrjvmKq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7gX+TCgfD+wjJXL4dM piNhRHYI5RccvgHlXR75b7gXr8AMhSdMNjhZMMeOIpO/PiWUh3QCEXE8EYBq8g4Ls/94WZ98l n8D+Z2dBxSlN3K9VLO0g6QzZxVH1xjWTn9zeCP9EOwO4V2T08K0IUH0H5fTln1bs8iKsFYBSP 4C28qN9B98pfE4A7/1DyZgveQBdsilTuyHKbitMqP95GICQbHWMV2irSmLU3kKnTKDPynXwza o6XwCVzvhzOaEi7BnmLqprHzufXT+mgFX9MQwdILGjPIkhHYwT5YwL5hoeutrQehWrZZLi9dD 60NscRoBkmNyKiEUi X-Spam-Status: No, score=-8.9 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, UNWANTED_LANGUAGE_BODY 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: Mon, 27 Jul 2020 07:42:05 -0000 NetBSD implementes 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 | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 233 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0c2c6552d95..6800dfd1e56 100644 =2D-- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2020-07-26 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-25 Andrew Burgess PR fortran/23051 diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c index a9405ebf862..6a9bfa1a13b 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..faf41313f68 100644 =2D-- a/gdb/nbsd-tdep.c +++ b/gdb/nbsd-tdep.c @@ -373,6 +373,169 @@ 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) +{ + struct nbsd_gdbarch_data *nbsd_gdbarch_data; + struct type *char_type, *int_type, *long_type; + struct type *void_ptr_type; + struct type *int32_type, *uint32_type, *uint64_type; + struct type *pid_type, *lwpid_type, *uid_type, *clock_type; + struct type *sigval_type, *option_type; + struct type *siginfo_type; + struct type *ksiginfo_type; + struct type *reason_type; + struct type *type; + bool lp64; + + nbsd_gdbarch_data =3D get_nbsd_gdbarch_data (gdbarch); + if (nbsd_gdbarch_data->siginfo_type !=3D NULL) + return nbsd_gdbarch_data->siginfo_type; + + char_type =3D builtin_type (gdbarch)->builtin_char; + int_type =3D builtin_type (gdbarch)->builtin_int; + long_type =3D builtin_type (gdbarch)->builtin_long; + + void_ptr_type =3D lookup_pointer_type (builtin_type (gdbarch)->builtin_= void); + + int32_type =3D builtin_type (gdbarch)->builtin_int32; + uint32_type =3D builtin_type (gdbarch)->builtin_uint32; + uint64_type =3D builtin_type (gdbarch)->builtin_uint64; + + lp64 =3D TYPE_LENGTH (void_ptr_type) =3D=3D 8; + + /* pid_t */ + pid_type =3D arch_type (gdbarch, TYPE_CODE_TYPEDEF, + TYPE_LENGTH (int32_type) * TARGET_CHAR_BIT, "pid_t"); + TYPE_TARGET_TYPE (pid_type) =3D int32_type; + TYPE_TARGET_STUB (pid_type) =3D 1; + + /* uid_t */ + uid_type =3D arch_type (gdbarch, TYPE_CODE_TYPEDEF, + TYPE_LENGTH (uint32_type) * TARGET_CHAR_BIT, + "uid_t"); + TYPE_TARGET_TYPE (uid_type) =3D uint32_type; + TYPE_TARGET_STUB (uid_type) =3D 1; + + /* clock_t */ + clock_type =3D arch_type (gdbarch, TYPE_CODE_TYPEDEF, + TYPE_LENGTH (int_type) * TARGET_CHAR_BIT, + "clock_t"); + TYPE_TARGET_TYPE (clock_type) =3D int_type; + TYPE_TARGET_STUB (clock_type) =3D 1; + + /* lwpid_t */ + lwpid_type =3D arch_type (gdbarch, TYPE_CODE_TYPEDEF, + TYPE_LENGTH (int32_type) * TARGET_CHAR_BIT, + "lwpid_t"); + TYPE_TARGET_TYPE (lwpid_type) =3D int32_type; + TYPE_TARGET_STUB (lwpid_type) =3D 1; + + /* union sigval */ + sigval_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); + sigval_type->set_name (xstrdup ("sigval")); + append_composite_type_field (sigval_type, "sival_int", int_type); + append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type); + + /* union _option */ + option_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); + option_type->set_name (xstrdup ("_option")); + append_composite_type_field (option_type, "_pe_other_pid", pid_type); + append_composite_type_field (option_type, "_pe_lwp", lwpid_type); + + /* union _reason */ + reason_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); + + /* _rt */ + type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); + append_composite_type_field (type, "_pid", pid_type); + append_composite_type_field (type, "_uid", uid_type); + append_composite_type_field (type, "_value", sigval_type); + append_composite_type_field (reason_type, "_rt", type); + + /* _child */ + type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); + append_composite_type_field (type, "_pid", pid_type); + append_composite_type_field (type, "_uid", uid_type); + append_composite_type_field (type, "_status", int_type); + append_composite_type_field (type, "_utime", clock_type); + append_composite_type_field (type, "_stime", clock_type); + append_composite_type_field (reason_type, "_child", type); + + /* _fault */ + type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); + append_composite_type_field (type, "_addr", void_ptr_type); + append_composite_type_field (type, "_trap", int_type); + append_composite_type_field (type, "_trap2", int_type); + append_composite_type_field (type, "_trap3", int_type); + append_composite_type_field (reason_type, "_fault", type); + + /* _poll */ + type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); + append_composite_type_field (type, "_band", long_type); + append_composite_type_field (type, "_fd", int_type); + append_composite_type_field (reason_type, "_poll", type); + + /* _syscall */ + type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); + append_composite_type_field (type, "_sysnum", int_type); + append_composite_type_field (type, "_retval", + init_vector_type (int_type, 2)); + append_composite_type_field (type, "_error", int_type); + append_composite_type_field (type, "_args", + init_vector_type (uint64_type, 8)); + append_composite_type_field (reason_type, "_syscall", type); + + /* _ptrace_state */ + type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); + append_composite_type_field (type, "_pe_report_event", int_type); + append_composite_type_field (type, "_option", option_type); + append_composite_type_field (reason_type, "_ptrace_state", type); + + /* struct _ksiginfo */ + ksiginfo_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT)= ; + ksiginfo_type->set_name (xstrdup ("_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 */ + siginfo_type =3D arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); + siginfo_type->set_name (xstrdup ("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 +632,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