From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 83953 invoked by alias); 3 Jan 2017 13:14:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 83942 invoked by uid 89); 3 Jan 2017 13:14:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL,BAYES_05,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=gmbh, GmbH, traced, Managing X-HELO: mga02.intel.com Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Jan 2017 13:14:17 +0000 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP; 03 Jan 2017 05:14:15 -0800 X-ExtLoop1: 1 Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by orsmga005.jf.intel.com with ESMTP; 03 Jan 2017 05:14:14 -0800 Received: from irsmsx104.ger.corp.intel.com ([169.254.5.142]) by IRSMSX102.ger.corp.intel.com ([169.254.2.230]) with mapi id 14.03.0248.002; Tue, 3 Jan 2017 13:14:13 +0000 From: "Metzger, Markus T" To: "gdb-patches@sourceware.org" CC: Daniel Jacobowitz , "Pedro Alves (palves@redhat.com)" Subject: [ping] [PATCH 1/2] gdbserver: catch fetch registers error Date: Tue, 03 Jan 2017 13:14:00 -0000 Message-ID: Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-01/txt/msg00009.txt.bz2 ping > -----Original Message----- > From: Metzger, Markus T > Sent: Tuesday, December 6, 2016 4:55 PM > To: gdb-patches@sourceware.org > Cc: Daniel Jacobowitz > Subject: [PATCH 1/2] gdbserver: catch fetch registers error >=20 > When the PTRACE_PEEKUSER ptrace request to read registers fails, gdbserer > throws > an error that is caught in captured_main, where it causes a E01 error pac= ket to > be sent and gdbserer to quit (if --once was specified) or the event loop = to be > re-started (otherwise). >=20 > We may get such ptrace errors when trying to fetch registers for an exite= d or > running thread. There are checks in GDB that check those conditions and = throw > meaningful error messages before we could run into the above ptrace error, > e.g. thread.c:validate_registers_access. >=20 > I ran into a new case and, rather than adding another call to > validate_registers_access in GDB, I propose to catch the error already wh= en > handling the 'g' packet in gdbserver and reply with an error packet - ass= uming > that gdbserver's internal state is still intact. >=20 > To not replace a meaningful error message with E01, I'm trying to generat= e a > useful error message when the error is detected and the exception is thro= wn. >=20 > It would look like this ... >=20 > gdb) PASS: gdb.btrace/enable-running.exp: continue to breakpoint: cont to= 44 > cont& > Continuing. > (gdb) PASS: gdb.btrace/enable-running.exp: cont& > record btrace > warning: Remote failure reply: E.Selected thread is running. > warning: Remote failure reply: E.Selected thread is running. >=20 > ... although in this particular case, I'm going to suppress the warning. >=20 > To make this look a bit nicer, we could consider stripping the "E." or the > entire "Remote failure reply: E." when (re-)throwing the error inside GDB= in > remote.c. >=20 > CC: Daniel Jacobowitz >=20 > 2016-12-06 Markus Metzger >=20 > gdbserver/ > * server.c (process_serial_event): Add TRY/CATCH. > * linux-low.c (fetch_register): Improve error message. > --- > gdb/gdbserver/linux-low.c | 19 ++++++++++++++++++- > gdb/gdbserver/server.c | 18 ++++++++++++++++-- > 2 files changed, 34 insertions(+), 3 deletions(-) >=20 > diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c > index e3e372c..a942b87 100644 > --- a/gdb/gdbserver/linux-low.c > +++ b/gdb/gdbserver/linux-low.c > @@ -5692,7 +5692,24 @@ fetch_register (const struct usrregs_info *usrregs, > (PTRACE_TYPE_ARG3) (uintptr_t) regaddr, (PTRACE_TYPE_ARG4) > 0); > regaddr +=3D sizeof (PTRACE_XFER_TYPE); > if (errno !=3D 0) > - error ("reading register %d: %s", regno, strerror (errno)); > + { > + /* ESRCH could mean that the thread is not traced, exited, or is not > + stopped. */ > + if (errno =3D=3D ESRCH) > + { > + struct lwp_info *lwp =3D get_thread_lwp (current_thread); > + > + if (!lwp_is_stopped (lwp)) > + error (_("Selected thread is running.")); > + > + if (lwp_is_marked_dead (lwp)) > + error (_("Selected thread has terminated.")); > + } > + > + /* Report a generic error if we could not determine the exact > + reason. */ > + error (_("Could not read register %d: %s."), regno, strerror (errno)); > + } > } >=20 > if (the_low_target.supply_ptrace_register) > diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c > index ef8dd03..3064b4f 100644 > --- a/gdb/gdbserver/server.c > +++ b/gdb/gdbserver/server.c > @@ -4132,8 +4132,22 @@ process_serial_event (void) > write_enn (own_buf); > else > { > - regcache =3D get_thread_regcache (current_thread, 1); > - registers_to_string (regcache, own_buf); > + TRY > + { > + regcache =3D get_thread_regcache (current_thread, 1); > + registers_to_string (regcache, own_buf); > + } > + CATCH (exception, RETURN_MASK_ALL) > + { > + const char *message; > + > + message =3D exception.message; > + if (message =3D=3D NULL) > + message =3D _("Reading registers failed."); > + > + sprintf (own_buf, "E.%s", message); > + } > + END_CATCH > } > } > break; > -- > 1.8.3.1 Intel Deutschland GmbH Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Christian Lamprechter Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928