From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7035 invoked by alias); 4 Nov 2008 16:17:48 -0000 Received: (qmail 6926 invoked by uid 22791); 4 Nov 2008 16:17:47 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 04 Nov 2008 16:17:10 +0000 Received: (qmail 9776 invoked from network); 4 Nov 2008 16:17:08 -0000 Received: from unknown (HELO orlando.local) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 4 Nov 2008 16:17:08 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Re: [PATCH 1/4] 'catch syscall' feature -- Architecture-independent =?utf-8?q?=09part?= Date: Tue, 04 Nov 2008 16:17:00 -0000 User-Agent: KMail/1.9.10 Cc: =?utf-8?q?S=C3=A9rgio_Durigan_J=C3=BAnior?= References: <1225773079.24532.52.camel@miki> In-Reply-To: <1225773079.24532.52.camel@miki> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200811041617.10621.pedro@codesourcery.com> X-IsSubscribed: yes 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 X-SW-Source: 2008-11/txt/msg00036.txt.bz2 On Tuesday 04 November 2008 04:31:19, S=C3=A9rgio Durigan J=C3=BAnior wrote: > +static enum print_stop_action > +print_it_catch_syscall (struct breakpoint *b) > +{ > + =C2=A0/* This is needed because we want to know in which state a > + =C2=A0 =C2=A0 syscall is. =C2=A0It can be in the TARGET_WAITKIND_SYSCAL= L_ENTRY > + =C2=A0 =C2=A0 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we > + =C2=A0 =C2=A0 must print "called syscall" or "returned from syscall". = =C2=A0*/ > + =C2=A0struct thread_info *th_info =3D find_thread_pid (inferior_ptid); > + =C2=A0const char *syscall_name =3D > + =C2=A0 =C2=A0gdbarch_syscall_name_from_number (current_gdbarch, b->sysc= all_number); > + > + =C2=A0annotate_catchpoint (b->number); > + =C2=A0printf_filtered (_("\nCatchpoint %d ("), b->number); > + > + =C2=A0if (th_info->syscall_state =3D=3D TARGET_WAITKIND_SYSCALL_ENTRY) > + =C2=A0 =C2=A0printf_filtered (_("calling ")); > + =C2=A0else > + =C2=A0 =C2=A0printf_filtered (_("returned from ")); This bit left me wondering about the below. Take these with a grain of salt, please :-) syscall_state has been placed in struct thread_info, and linux-nat.c toggles it between entry/exit, but that's mainly because on linux, the same trap is sent in both cases. In the ttrace case (inf-ttrace.c), for example, you have distinct TTEVT_SYSCALL_ENTRY and TTEVT_SYSCALL_RETURN events at the target level. Shouldn't we be doing the same on linux? That is, move 'syscall_state' to 'struct lwp_info', thus making it private to the linux-nat.c implementation, and have the core side always distinguish them from the TARGET_WAITKIND_SYSCALL_* type returned from target_wait? It looks weird for the target side to be writing to a thread_info directly. I always tend to ponder how I'd do these things in gdbserver to validate target_ops designs --- I guess I wouldn't be able to tweak gdb's common code from there. :-) Was it because you need to access it in print_it_catch_syscall? You could get it from the last target event like you do in breakpoint_hit_catch_syscall, I guess. (I guess the ideal solution would be for a bpstat to be able to hold extra catchpoint hit state without re-querying the last target event, but that would require an extra redesign of the breakpoint hit -> bpstat building.) Also, I'm not 100% sure, but I think you can crash in linux-nat.c:linux_handle_extended_wait if an lwp happens to hit a syscall you're catching before it's corresponding thread has been added to the thread list in linux-thread-db.c. Also, while we're on to speaking of these matters, would it make sense to be able to catch only syscall entry or syscall return events at the UI level? That is, separate "catch syscall entry", "catch syscall return" or some such? --=20 Pedro Alves