From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26237 invoked by alias); 24 Mar 2010 22:00:20 -0000 Received: (qmail 26212 invoked by uid 22791); 24 Mar 2010 22:00:17 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 24 Mar 2010 22:00:13 +0000 Received: (qmail 13508 invoked from network); 24 Mar 2010 22:00:12 -0000 Received: from unknown (HELO orlando.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 24 Mar 2010 22:00:12 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Re: Teach gdbserver to step over internal breakpoints Date: Wed, 24 Mar 2010 22:00:00 -0000 User-Agent: KMail/1.12.2 (Linux/2.6.31-20-generic; KDE/4.3.2; x86_64; ; ) References: <201003161839.52618.pedro@codesourcery.com> <201003241213.31420.pedro@codesourcery.com> <201003242122.39450.pedro@codesourcery.com> In-Reply-To: <201003242122.39450.pedro@codesourcery.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201003242200.10102.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: 2010-03/txt/msg00835.txt.bz2 On Wednesday 24 March 2010 21:22:39, Pedro Alves wrote: > Also tested on x86_64, with and without a thread > event breakpoint, and also with a had that makes x86-64 > use reinsert breakpoints. I'll show that for the archives > shortly. s/a had/ a hack/. Here it is. This makes an x86 gdbserver use reinsert (single software single-step) breakpoints to step over the thread event breakpoint, thus it make it easier to test those code paths on my devel machine. I've only used it thoroughly with x86-64, but it should work with ix86 as well. For the archives. -- Pedro Alves --- gdb/gdbserver/linux-low.c | 2 +- gdb/gdbserver/linux-x86-low.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) Index: src/gdb/gdbserver/linux-x86-low.c =================================================================== --- src.orig/gdb/gdbserver/linux-x86-low.c 2010-03-24 20:34:18.000000000 +0000 +++ src/gdb/gdbserver/linux-x86-low.c 2010-03-24 21:41:42.000000000 +0000 @@ -824,6 +824,39 @@ x86_arch_setup (void) num_xmm_registers = 8; } +/* We only place breakpoints in empty marker functions, and thread + locking is outside of the function. So rather than importing + software single-step, we can just run until exit. */ + +static CORE_ADDR +x86_reinsert_addr (void) +{ + struct regcache *regcache = get_thread_regcache (current_inferior, 1); + +#ifdef __x86_64__ + int use_64bit = register_size (0) == 8; + + if (use_64bit) + { + unsigned long sp, ret; + + collect_register_by_name (regcache, "rsp", &sp); + if (read_inferior_memory (sp, (unsigned char *) &ret, 8) != 0) + return 0; + return ret; + } + else +#endif + { + unsigned int sp, ret; + + collect_register_by_name (regcache, "esp", &sp); + if (read_inferior_memory (sp, (unsigned char *) &ret, 4) != 0) + return 0; + return ret; + } +} + /* This is initialized assuming an amd64 target. x86_arch_setup will correct it for i386 or amd64 targets. */ @@ -838,7 +871,7 @@ struct linux_target_ops the_low_target = x86_set_pc, x86_breakpoint, x86_breakpoint_len, - NULL, + x86_reinsert_addr, 1, x86_breakpoint_at, x86_insert_point, Index: src/gdb/gdbserver/linux-low.c =================================================================== --- src.orig/gdb/gdbserver/linux-low.c 2010-03-24 21:43:01.000000000 +0000 +++ src/gdb/gdbserver/linux-low.c 2010-03-24 21:55:16.000000000 +0000 @@ -3421,7 +3421,7 @@ linux_look_up_symbols (void) /* If the kernel supports tracing forks then it also supports tracing clones, and then we don't need to use the magic thread event breakpoint to learn about threads. */ - thread_db_init (!linux_supports_tracefork_flag); + thread_db_init (1); #endif }