From patchwork Tue Oct 20 18:10:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Ristovski X-Patchwork-Id: 9276 Received: (qmail 94082 invoked by alias); 20 Oct 2015 18:11:25 -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 93998 invoked by uid 89); 20 Oct 2015 18:11:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: smtp-a02.blackberry.com Received: from smtp-a02.blackberry.com (HELO smtp-a02.blackberry.com) (208.65.78.91) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Oct 2015 18:11:23 +0000 Received: from mhs103cnc.rim.net ([10.65.141.77]) by mhs215cnc-app.rim.net with ESMTP; 20 Oct 2015 14:11:20 -0400 Received: from unknown (HELO qnxws9580.ott.qnx.com) ([10.65.140.253]) by mhs103cnc.rim.net with ESMTP; 20 Oct 2015 18:11:17 +0000 From: Aleksandar Ristovski To: gdb-patches@sourceware.org Cc: palves@redhat.com, Aleksandar Ristovski Subject: [PATCH 1/2] [nto] Fix nto target stopped by watchpoint. Date: Tue, 20 Oct 2015 14:10:48 -0400 Message-Id: <1445364649-12175-2-git-send-email-aristovski@qnx.com> In-Reply-To: <1445364649-12175-1-git-send-email-aristovski@qnx.com> References: <5621218D.6070801@redhat.com> <1445364649-12175-1-git-send-email-aristovski@qnx.com> Fix 'stopped by watchpoint' detection: add inferior data, use inferior data for storing last stopped flags needed for detection. gdb/ChangeLog: * nto-procfs.c (procfs_wait): Set stopped_flags nad stopped_pc. (procfs_stopped_by_watchpoint): Use flags stored in inferior data. * nto-tdep.c (nto_new_inferior_data_reg): New definition. (nto_new_inferior_data, nto_inferior_data_cleanup, nto_inferior_data): New functions. (_initialize_nto_tdep): New forward declaration, new function. * nto-tdep.h (struct nto_inferior_data): New struct. (nto_inferior_data): New function declaration. --- gdb/nto-procfs.c | 21 ++++++++++++++++++++- gdb/nto-tdep.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/nto-tdep.h | 13 +++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index 82b428c..6ab78e3 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -784,6 +784,9 @@ procfs_wait (struct target_ops *ops, devctl (ctl_fd, DCMD_PROC_STATUS, &status, sizeof (status), 0); } + nto_inferior_data (NULL)->stopped_flags = status.flags; + nto_inferior_data (NULL)->stopped_pc = status.ip; + if (status.flags & _DEBUG_FLAG_SSTEP) { ourstatus->kind = TARGET_WAITKIND_STOPPED; @@ -1626,5 +1629,21 @@ procfs_insert_hw_watchpoint (struct target_ops *self, static int procfs_stopped_by_watchpoint (struct target_ops *ops) { - return 0; + /* NOTE: nto_stopped_by_watchpoint will be called ONLY while we are + stopped due to a SIGTRAP. This assumes gdb works in 'all-stop' mode; + future gdb versions will likely run in 'non-stop' mode in which case + we will have to store/examine statuses per thread in question. + Until then, this will work fine. */ + + struct inferior *inf = current_inferior (); + struct nto_inferior_data *inf_data; + + gdb_assert (inf != NULL); + + inf_data = nto_inferior_data (inf); + + return inf_data->stopped_flags + & (_DEBUG_FLAG_TRACE_RD + | _DEBUG_FLAG_TRACE_WR + | _DEBUG_FLAG_TRACE_MODIFY); } diff --git a/gdb/nto-tdep.c b/gdb/nto-tdep.c index 62eb88a..e50d302 100644 --- a/gdb/nto-tdep.c +++ b/gdb/nto-tdep.c @@ -46,6 +46,8 @@ static char default_nto_target[] = ""; struct nto_target_ops current_nto_target; +static const struct inferior_data *nto_inferior_data_reg; + static char * nto_target (void) { @@ -477,3 +479,53 @@ nto_read_auxv_from_initial_stack (CORE_ADDR initial_stack, gdb_byte *readbuf, } return len_read; } + +/* Allocate new nto_inferior_data object. */ + +static struct nto_inferior_data * +nto_new_inferior_data (void) +{ + struct nto_inferior_data *const inf_data + = XCNEW (struct nto_inferior_data); + + return inf_data; +} + +/* Free inferior data. */ + +static void +nto_inferior_data_cleanup (struct inferior *const inf, void *const dat) +{ + xfree (dat); +} + +/* Return nto_inferior_data for the given INFERIOR. If not yet created, + construct it. */ + +struct nto_inferior_data * +nto_inferior_data (struct inferior *const inferior) +{ + struct inferior *const inf = inferior ? inferior : current_inferior (); + struct nto_inferior_data *inf_data; + + gdb_assert (inf != NULL); + + inf_data = inferior_data (inf, nto_inferior_data_reg); + if (inf_data == NULL) + { + set_inferior_data (inf, nto_inferior_data_reg, + (inf_data = nto_new_inferior_data ())); + } + + return inf_data; +} + +/* Provide a prototype to silence -Wmissing-prototypes. */ +extern initialize_file_ftype _initialize_nto_tdep; + +void +_initialize_nto_tdep (void) +{ + nto_inferior_data_reg + = register_inferior_data_with_cleanup (NULL, nto_inferior_data_cleanup); +} diff --git a/gdb/nto-tdep.h b/gdb/nto-tdep.h index d029f07..6ed9da0 100644 --- a/gdb/nto-tdep.h +++ b/gdb/nto-tdep.h @@ -142,6 +142,16 @@ struct private_thread_info char name[1]; }; +/* Per-inferior data, common for both procfs and remote. */ +struct nto_inferior_data +{ + /* Last stopped flags result from wait function */ + unsigned int stopped_flags; + + /* Last known stopped PC */ + CORE_ADDR stopped_pc; +}; + /* Generic functions in nto-tdep.c. */ void nto_init_solib_absolute_prefix (void); @@ -171,4 +181,7 @@ char *nto_extra_thread_info (struct target_ops *self, struct thread_info *); LONGEST nto_read_auxv_from_initial_stack (CORE_ADDR inital_stack, gdb_byte *readbuf, LONGEST len, size_t sizeof_auxv_t); + +struct nto_inferior_data *nto_inferior_data (struct inferior *inf); + #endif