From patchwork Thu Jun 2 09:30:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 12705 Received: (qmail 83717 invoked by alias); 2 Jun 2016 09:31:17 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 83604 invoked by uid 89); 2 Jun 2016 09:31:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=874, Hx-languages-length:2725 X-HELO: mail-pf0-f194.google.com Received: from mail-pf0-f194.google.com (HELO mail-pf0-f194.google.com) (209.85.192.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 02 Jun 2016 09:31:08 +0000 Received: by mail-pf0-f194.google.com with SMTP id c84so7368381pfc.1 for ; Thu, 02 Jun 2016 02:31:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=3olkpB1zWI5/BH0AKeigFL3xNO7eOGJBDuHWiOQDePU=; b=Fq6GkvoOhuPSGQT9KasCcHe7aKaQrWKAGInD2k+8UatKeUes4iv5SeKG1trhRysmEg AEmRnkOMmdf50mVJjCy68/ybWP9W1An9qfeNx9cRl6esxgNO6m7qcZ/ihvO+8+uAH/69 63a7pOYOcqC1O831T7qrLj8yrLiA+aTTH+/q2hVoMLUonWSTuDGJHJqYDJY9canU+qIU L8OPbfEr3AZ5ZXi2WyiTrVCXhmwaOa8xcwhRzxBjqBGShZXwrnLkXKumOrtxC/LGkPsB 0V+LsljnIWaoAlxN6f4nP1cvFw4rtDZN80R/2DwTtJu+TaGs0eF4u50rF8GWGo1X1Bmv dolA== X-Gm-Message-State: ALyK8tLbRC6Ryo3CXXe3TKPS6NXl8mz+8b5/7326HQi5DlIj5+eL06lFkPaSNuvq1jF7eQ== X-Received: by 10.98.193.197 with SMTP id i188mr2556048pfg.151.1464859866836; Thu, 02 Jun 2016 02:31:06 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc113.osuosl.org. [140.211.9.71]) by smtp.gmail.com with ESMTPSA id hw10sm68656218pac.15.2016.06.02.02.31.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Jun 2016 02:31:06 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 10/12] Switch current_thread to lwp's thread in install_software_single_step_breakpoints Date: Thu, 2 Jun 2016 10:30:44 +0100 Message-Id: <1464859846-15619-11-git-send-email-yao.qi@linaro.org> In-Reply-To: <1464859846-15619-1-git-send-email-yao.qi@linaro.org> References: <1464859846-15619-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes install_software_single_step_breakpoints has parameter lwp, but still need to switch to current_thread. In order to simplify its caller, we do the current_thread save/restore inside install_software_single_step_breakpoints. gdb/gdbserver: 2016-05-25 Yao Qi * gdbthread.h (make_cleanup_restore_current_thread): Declare. * inferiors.c (do_restore_current_thread_cleanup): New function. (make_cleanup_restore_current_thread): Likewise. * linux-low.c (install_software_single_step_breakpoints): Call make_cleanup_restore_current_thread. Switch current_thread to thread. --- gdb/gdbserver/gdbthread.h | 3 +++ gdb/gdbserver/inferiors.c | 12 ++++++++++++ gdb/gdbserver/linux-low.c | 8 ++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gdb/gdbserver/gdbthread.h b/gdb/gdbserver/gdbthread.h index 4dcb1b7..d2326fb 100644 --- a/gdb/gdbserver/gdbthread.h +++ b/gdb/gdbserver/gdbthread.h @@ -87,4 +87,7 @@ struct thread_info *find_any_thread_of_pid (int pid); /* Get current thread ID (Linux task ID). */ #define current_ptid (current_thread->entry.id) +/* Create a cleanup to restore current_thread. */ +struct cleanup *make_cleanup_restore_current_thread (void); + #endif /* GDB_THREAD_H */ diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c index 4bea4fd..c15b2e1 100644 --- a/gdb/gdbserver/inferiors.c +++ b/gdb/gdbserver/inferiors.c @@ -411,3 +411,15 @@ current_process (void) gdb_assert (current_thread != NULL); return get_thread_process (current_thread); } + +static void +do_restore_current_thread_cleanup (void *arg) +{ + current_thread = (struct thread_info *) arg; +} + +struct cleanup * +make_cleanup_restore_current_thread (void) +{ + return make_cleanup (do_restore_current_thread_cleanup, current_thread); +} diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 414117b..6f32911 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -4143,10 +4143,14 @@ install_software_single_step_breakpoints (struct lwp_info *lwp) { int i; CORE_ADDR pc; - struct regcache *regcache = get_thread_regcache (current_thread, 1); + struct thread_info *thread = get_lwp_thread (lwp); + struct regcache *regcache = get_thread_regcache (thread, 1); VEC (CORE_ADDR) *next_pcs = NULL; - struct cleanup *old_chain = make_cleanup (VEC_cleanup (CORE_ADDR), &next_pcs); + struct cleanup *old_chain = make_cleanup_restore_current_thread (); + + make_cleanup (VEC_cleanup (CORE_ADDR), &next_pcs); + current_thread = thread; next_pcs = (*the_low_target.get_next_pcs) (regcache); for (i = 0; VEC_iterate (CORE_ADDR, next_pcs, i, pc); ++i)