From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30070 invoked by alias); 13 Jan 2014 19:24:41 -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 29999 invoked by uid 89); 13 Jan 2014 19:24:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS,UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 13 Jan 2014 19:24:38 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0DJDFo1007183 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 13 Jan 2014 14:13:15 -0500 Received: from barimba.redhat.com (ovpn-113-85.phx2.redhat.com [10.3.113.85]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s0DJCpta016701; Mon, 13 Jan 2014 14:13:15 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC 30/32] convert to_search_memory Date: Mon, 13 Jan 2014 19:24:00 -0000 Message-Id: <1389640367-5571-31-git-send-email-tromey@redhat.com> In-Reply-To: <1389640367-5571-1-git-send-email-tromey@redhat.com> References: <1389640367-5571-1-git-send-email-tromey@redhat.com> X-SW-Source: 2014-01/txt/msg00355.txt.bz2 2014-01-08 Tom Tromey * target-delegates.c : Rebuild. * target.c (default_search_memory): New function. (simple_search_memory): Update comment. (target_search_memory): Unconditionally delegate. * target.h (struct target_ops) : Use TARGET_DEFAULT_FUNC. convert to_disable_btrace 2014-01-08 Tom Tromey * target-delegates.c : Rebuild. * target.c (target_disable_btrace): Unconditionally delegate. * target.h (struct target_ops) : Use TARGET_DEFAULT_NORETURN. convert to_teardown_btrace 2014-01-08 Tom Tromey * target-delegates.c : Rebuild. * target.c (target_teardown_btrace): Unconditionally delegate. * target.h (struct target_ops) : Use TARGET_DEFAULT_NORETURN. convert to_read_btrace 2014-01-08 Tom Tromey * target-delegates.c : Rebuild. * target.c (target_read_btrace): Unconditionally delegate. * target.h (struct target_ops) : Use TARGET_DEFAULT_NORETURN. convert to_enable_btrace 2014-01-08 Tom Tromey * target-delegates.c : Rebuild. * target.c (target_enable_btrace): Unconditionally delegate. * target.h (struct target_ops) : Use TARGET_DEFAULT_NORETURN. convert to_stop_recording 2014-01-08 Tom Tromey * record.c (record_stop): Unconditionally delegate. * target-delegates.c : Rebuild. * target.c (target_stop_recording): Unconditionally delegate. * target.h (struct target_ops) : Use TARGET_DEFAULT_IGNORE. convert to_disconnect 2014-01-08 Tom Tromey * target-delegates.c : Rebuild. * target.c (target_disconnect): Unconditionally delegate. * target.h (struct target_ops) : Use TARGET_DEFAULT_NORETURN. convert to_can_run 2014-01-08 Tom Tromey * target-delegates.c : Rebuild. * target.c (update_current_target): Don't inherit or default to_can_run. (find_default_run_target): Check against delegate_can_run. * target.h (struct target_ops) : Use TARGET_DEFAULT_RETURN. --- gdb/ChangeLog | 61 ++++++++++++++++++++++++ gdb/record.c | 3 +- gdb/target-delegates.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++ gdb/target.c | 124 ++++++++++++++----------------------------------- gdb/target.h | 24 ++++++---- 5 files changed, 235 insertions(+), 98 deletions(-) diff --git a/gdb/record.c b/gdb/record.c index 77b1ce5..c81bd2a 100644 --- a/gdb/record.c +++ b/gdb/record.c @@ -103,8 +103,7 @@ record_stop (struct target_ops *t) { DEBUG ("stop %s", t->to_shortname); - if (t->to_stop_recording != NULL) - t->to_stop_recording (t); + t->to_stop_recording (t); } /* Unpush the record target. */ diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index 456f70e..66c0625 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -35,6 +35,19 @@ tdefault_detach (struct target_ops *self, const char *arg1, int arg2) } static void +delegate_disconnect (struct target_ops *self, char *arg1, int arg2) +{ + self = self->beneath; + self->to_disconnect (self, arg1, arg2); +} + +static void +tdefault_disconnect (struct target_ops *self, char *arg1, int arg2) +{ + tcomplain (); +} + +static void delegate_resume (struct target_ops *self, ptid_t arg1, int arg2, enum gdb_signal arg3) { self = self->beneath; @@ -517,6 +530,19 @@ delegate_mourn_inferior (struct target_ops *self) self->to_mourn_inferior (self); } +static int +delegate_can_run (struct target_ops *self) +{ + self = self->beneath; + return self->to_can_run (self); +} + +static int +tdefault_can_run (struct target_ops *self) +{ + return 0; +} + static void delegate_pass_signals (struct target_ops *self, int arg1, unsigned char *arg2) { @@ -790,6 +816,13 @@ delegate_auxv_parse (struct target_ops *self, gdb_byte **arg1, gdb_byte *arg2, C } static int +delegate_search_memory (struct target_ops *self, CORE_ADDR arg1, ULONGEST arg2, const gdb_byte *arg3, ULONGEST arg4, CORE_ADDR *arg5) +{ + self = self->beneath; + return self->to_search_memory (self, arg1, arg2, arg3, arg4, arg5); +} + +static int delegate_can_execute_reverse (struct target_ops *self) { self = self->beneath; @@ -1293,6 +1326,70 @@ tdefault_supports_btrace (struct target_ops *self) return 0; } +static struct btrace_target_info * +delegate_enable_btrace (struct target_ops *self, ptid_t arg1) +{ + self = self->beneath; + return self->to_enable_btrace (self, arg1); +} + +static struct btrace_target_info * +tdefault_enable_btrace (struct target_ops *self, ptid_t arg1) +{ + tcomplain (); +} + +static void +delegate_disable_btrace (struct target_ops *self, struct btrace_target_info *arg1) +{ + self = self->beneath; + self->to_disable_btrace (self, arg1); +} + +static void +tdefault_disable_btrace (struct target_ops *self, struct btrace_target_info *arg1) +{ + tcomplain (); +} + +static void +delegate_teardown_btrace (struct target_ops *self, struct btrace_target_info *arg1) +{ + self = self->beneath; + self->to_teardown_btrace (self, arg1); +} + +static void +tdefault_teardown_btrace (struct target_ops *self, struct btrace_target_info *arg1) +{ + tcomplain (); +} + +static VEC (btrace_block_s) * +delegate_read_btrace (struct target_ops *self, struct btrace_target_info *arg1, enum btrace_read_type arg2) +{ + self = self->beneath; + return self->to_read_btrace (self, arg1, arg2); +} + +static VEC (btrace_block_s) * +tdefault_read_btrace (struct target_ops *self, struct btrace_target_info *arg1, enum btrace_read_type arg2) +{ + tcomplain (); +} + +static void +delegate_stop_recording (struct target_ops *self) +{ + self = self->beneath; + self->to_stop_recording (self); +} + +static void +tdefault_stop_recording (struct target_ops *self) +{ +} + static void delegate_save_record (struct target_ops *self, const char *arg1) { @@ -1471,6 +1568,8 @@ install_delegators (struct target_ops *ops) ops->to_post_attach = delegate_post_attach; if (ops->to_detach == NULL) ops->to_detach = delegate_detach; + if (ops->to_disconnect == NULL) + ops->to_disconnect = delegate_disconnect; if (ops->to_resume == NULL) ops->to_resume = delegate_resume; if (ops->to_wait == NULL) @@ -1553,6 +1652,8 @@ install_delegators (struct target_ops *ops) ops->to_has_exited = delegate_has_exited; if (ops->to_mourn_inferior == NULL) ops->to_mourn_inferior = delegate_mourn_inferior; + if (ops->to_can_run == NULL) + ops->to_can_run = delegate_can_run; if (ops->to_pass_signals == NULL) ops->to_pass_signals = delegate_pass_signals; if (ops->to_program_signals == NULL) @@ -1603,6 +1704,8 @@ install_delegators (struct target_ops *ops) ops->to_get_ada_task_ptid = delegate_get_ada_task_ptid; if (ops->to_auxv_parse == NULL) ops->to_auxv_parse = delegate_auxv_parse; + if (ops->to_search_memory == NULL) + ops->to_search_memory = delegate_search_memory; if (ops->to_can_execute_reverse == NULL) ops->to_can_execute_reverse = delegate_can_execute_reverse; if (ops->to_execution_direction == NULL) @@ -1683,6 +1786,16 @@ install_delegators (struct target_ops *ops) ops->to_can_use_agent = delegate_can_use_agent; if (ops->to_supports_btrace == NULL) ops->to_supports_btrace = delegate_supports_btrace; + if (ops->to_enable_btrace == NULL) + ops->to_enable_btrace = delegate_enable_btrace; + if (ops->to_disable_btrace == NULL) + ops->to_disable_btrace = delegate_disable_btrace; + if (ops->to_teardown_btrace == NULL) + ops->to_teardown_btrace = delegate_teardown_btrace; + if (ops->to_read_btrace == NULL) + ops->to_read_btrace = delegate_read_btrace; + if (ops->to_stop_recording == NULL) + ops->to_stop_recording = delegate_stop_recording; if (ops->to_save_record == NULL) ops->to_save_record = delegate_save_record; if (ops->to_delete_record == NULL) @@ -1717,6 +1830,7 @@ install_dummy_methods (struct target_ops *ops) ops->to_attach = find_default_attach; ops->to_post_attach = tdefault_post_attach; ops->to_detach = tdefault_detach; + ops->to_disconnect = tdefault_disconnect; ops->to_resume = tdefault_resume; ops->to_wait = tdefault_wait; ops->to_fetch_registers = tdefault_fetch_registers; @@ -1758,6 +1872,7 @@ install_dummy_methods (struct target_ops *ops) ops->to_set_syscall_catchpoint = tdefault_set_syscall_catchpoint; ops->to_has_exited = tdefault_has_exited; ops->to_mourn_inferior = default_mourn_inferior; + ops->to_can_run = tdefault_can_run; ops->to_pass_signals = tdefault_pass_signals; ops->to_program_signals = tdefault_program_signals; ops->to_thread_alive = tdefault_thread_alive; @@ -1783,6 +1898,7 @@ install_dummy_methods (struct target_ops *ops) ops->to_flash_done = tdefault_flash_done; ops->to_get_ada_task_ptid = default_get_ada_task_ptid; ops->to_auxv_parse = default_auxv_parse; + ops->to_search_memory = default_search_memory; ops->to_can_execute_reverse = tdefault_can_execute_reverse; ops->to_execution_direction = default_execution_direction; ops->to_supports_multi_process = tdefault_supports_multi_process; @@ -1823,6 +1939,11 @@ install_dummy_methods (struct target_ops *ops) ops->to_use_agent = tdefault_use_agent; ops->to_can_use_agent = tdefault_can_use_agent; ops->to_supports_btrace = tdefault_supports_btrace; + ops->to_enable_btrace = tdefault_enable_btrace; + ops->to_disable_btrace = tdefault_disable_btrace; + ops->to_teardown_btrace = tdefault_teardown_btrace; + ops->to_read_btrace = tdefault_read_btrace; + ops->to_stop_recording = tdefault_stop_recording; ops->to_save_record = tdefault_save_record; ops->to_delete_record = tdefault_delete_record; ops->to_record_is_replaying = tdefault_record_is_replaying; diff --git a/gdb/target.c b/gdb/target.c index c3a5e77..df11fc0 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -66,6 +66,13 @@ static int default_follow_fork (struct target_ops *self, int follow_child, static void default_mourn_inferior (struct target_ops *self); +static int default_search_memory (struct target_ops *ops, + CORE_ADDR start_addr, + ULONGEST search_space_len, + const gdb_byte *pattern, + ULONGEST pattern_len, + CORE_ADDR *found_addrp); + static void tcomplain (void) ATTRIBUTE_NORETURN; static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *); @@ -644,7 +651,7 @@ update_current_target (void) /* Do not inherit to_set_syscall_catchpoint. */ /* Do not inherit to_has_exited. */ /* Do not inherit to_mourn_inferior. */ - INHERIT (to_can_run, t); + /* Do not inherit to_can_run. */ /* Do not inherit to_pass_signals. */ /* Do not inherit to_program_signals. */ /* Do not inherit to_thread_alive. */ @@ -739,9 +746,6 @@ update_current_target (void) (int (*) (CORE_ADDR, gdb_byte *, int, int, struct mem_attrib *, struct target_ops *)) nomemory); - de_fault (to_can_run, - (int (*) (struct target_ops *)) - return_zero); current_target.to_read_description = NULL; #undef de_fault @@ -2392,24 +2396,15 @@ target_detach (const char *args, int from_tty) void target_disconnect (char *args, int from_tty) { - struct target_ops *t; - /* If we're in breakpoints-always-inserted mode or if breakpoints are global across processes, we have to remove them before disconnecting. */ remove_breakpoints (); - for (t = current_target.beneath; t != NULL; t = t->beneath) - if (t->to_disconnect != NULL) - { - if (targetdebug) - fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n", - args, from_tty); - t->to_disconnect (t, args, from_tty); - return; - } - - tcomplain (); + if (targetdebug) + fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n", + args, from_tty); + current_target.to_disconnect (¤t_target, args, from_tty); } ptid_t @@ -2579,8 +2574,7 @@ target_read_description (struct target_ops *target) return NULL; } -/* The default implementation of to_search_memory. - This implements a basic search of memory, reading target memory and +/* This implements a basic search of memory, reading target memory and performing the search here (as opposed to performing the search in on the target side with, for example, gdbserver). */ @@ -2687,6 +2681,20 @@ simple_search_memory (struct target_ops *ops, return 0; } +/* Default implementation of memory-searching. */ + +static int +default_search_memory (struct target_ops *self, + CORE_ADDR start_addr, ULONGEST search_space_len, + const gdb_byte *pattern, ULONGEST pattern_len, + CORE_ADDR *found_addrp) +{ + /* Start over from the top of the target stack. */ + return simple_search_memory (current_target.beneath, + start_addr, search_space_len, + pattern, pattern_len, found_addrp); +} + /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the sequence of bytes in PATTERN with length PATTERN_LEN. @@ -2699,34 +2707,15 @@ target_search_memory (CORE_ADDR start_addr, ULONGEST search_space_len, const gdb_byte *pattern, ULONGEST pattern_len, CORE_ADDR *found_addrp) { - struct target_ops *t; int found; - /* We don't use INHERIT to set current_target.to_search_memory, - so we have to scan the target stack and handle targetdebug - ourselves. */ - if (targetdebug) fprintf_unfiltered (gdb_stdlog, "target_search_memory (%s, ...)\n", hex_string (start_addr)); - for (t = current_target.beneath; t != NULL; t = t->beneath) - if (t->to_search_memory != NULL) - break; - - if (t != NULL) - { - found = t->to_search_memory (t, start_addr, search_space_len, - pattern, pattern_len, found_addrp); - } - else - { - /* If a special version of to_search_memory isn't available, use the - simple version. */ - found = simple_search_memory (current_target.beneath, - start_addr, search_space_len, - pattern, pattern_len, found_addrp); - } + found = current_target.to_search_memory (¤t_target, start_addr, + search_space_len, + pattern, pattern_len, found_addrp); if (targetdebug) fprintf_unfiltered (gdb_stdlog, " = %d\n", found); @@ -2789,7 +2778,7 @@ find_default_run_target (char *do_mesg) for (t = target_structs; t < target_structs + target_struct_size; ++t) { - if ((*t)->to_can_run && target_can_run (*t)) + if ((*t)->to_can_run != delegate_can_run && target_can_run (*t)) { runable = *t; ++count; @@ -3712,14 +3701,7 @@ target_ranged_break_num_registers (void) struct btrace_target_info * target_enable_btrace (ptid_t ptid) { - struct target_ops *t; - - for (t = current_target.beneath; t != NULL; t = t->beneath) - if (t->to_enable_btrace != NULL) - return t->to_enable_btrace (t, ptid); - - tcomplain (); - return NULL; + return current_target.to_enable_btrace (¤t_target, ptid); } /* See target.h. */ @@ -3727,16 +3709,7 @@ target_enable_btrace (ptid_t ptid) void target_disable_btrace (struct btrace_target_info *btinfo) { - struct target_ops *t; - - for (t = current_target.beneath; t != NULL; t = t->beneath) - if (t->to_disable_btrace != NULL) - { - t->to_disable_btrace (t, btinfo); - return; - } - - tcomplain (); + current_target.to_disable_btrace (¤t_target, btinfo); } /* See target.h. */ @@ -3744,16 +3717,7 @@ target_disable_btrace (struct btrace_target_info *btinfo) void target_teardown_btrace (struct btrace_target_info *btinfo) { - struct target_ops *t; - - for (t = current_target.beneath; t != NULL; t = t->beneath) - if (t->to_teardown_btrace != NULL) - { - t->to_teardown_btrace (t, btinfo); - return; - } - - tcomplain (); + current_target.to_teardown_btrace (¤t_target, btinfo); } /* See target.h. */ @@ -3762,14 +3726,7 @@ VEC (btrace_block_s) * target_read_btrace (struct btrace_target_info *btinfo, enum btrace_read_type type) { - struct target_ops *t; - - for (t = current_target.beneath; t != NULL; t = t->beneath) - if (t->to_read_btrace != NULL) - return t->to_read_btrace (t, btinfo, type); - - tcomplain (); - return NULL; + return current_target.to_read_btrace (¤t_target, btinfo, type); } /* See target.h. */ @@ -3777,16 +3734,7 @@ target_read_btrace (struct btrace_target_info *btinfo, void target_stop_recording (void) { - struct target_ops *t; - - for (t = current_target.beneath; t != NULL; t = t->beneath) - if (t->to_stop_recording != NULL) - { - t->to_stop_recording (t); - return; - } - - /* This is optional. */ + current_target.to_stop_recording (¤t_target); } /* See target.h. */ diff --git a/gdb/target.h b/gdb/target.h index 987112e..978941b 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -395,7 +395,8 @@ struct target_ops TARGET_DEFAULT_IGNORE (); void (*to_detach) (struct target_ops *ops, const char *, int) TARGET_DEFAULT_IGNORE (); - void (*to_disconnect) (struct target_ops *, char *, int); + void (*to_disconnect) (struct target_ops *, char *, int) + TARGET_DEFAULT_NORETURN (tcomplain ()); void (*to_resume) (struct target_ops *, ptid_t, int, enum gdb_signal) TARGET_DEFAULT_NORETURN (noprocess ()); ptid_t (*to_wait) (struct target_ops *, @@ -532,7 +533,8 @@ struct target_ops TARGET_DEFAULT_RETURN (0); void (*to_mourn_inferior) (struct target_ops *) TARGET_DEFAULT_FUNC (default_mourn_inferior); - int (*to_can_run) (struct target_ops *); + int (*to_can_run) (struct target_ops *) + TARGET_DEFAULT_RETURN (0); /* Documentation of this routine is provided with the corresponding target_* macro. */ @@ -700,7 +702,8 @@ struct target_ops int (*to_search_memory) (struct target_ops *ops, CORE_ADDR start_addr, ULONGEST search_space_len, const gdb_byte *pattern, ULONGEST pattern_len, - CORE_ADDR *found_addrp); + CORE_ADDR *found_addrp) + TARGET_DEFAULT_FUNC (default_search_memory); /* Can target execute in reverse? */ int (*to_can_execute_reverse) (struct target_ops *) @@ -982,26 +985,31 @@ struct target_ops /* Enable branch tracing for PTID and allocate a branch trace target information struct for reading and for disabling branch trace. */ struct btrace_target_info *(*to_enable_btrace) (struct target_ops *, - ptid_t ptid); + ptid_t ptid) + TARGET_DEFAULT_NORETURN (tcomplain ()); /* Disable branch tracing and deallocate TINFO. */ void (*to_disable_btrace) (struct target_ops *, - struct btrace_target_info *tinfo); + struct btrace_target_info *tinfo) + TARGET_DEFAULT_NORETURN (tcomplain ()); /* Disable branch tracing and deallocate TINFO. This function is similar to to_disable_btrace, except that it is called during teardown and is only allowed to perform actions that are safe. A counter-example would be attempting to talk to a remote target. */ void (*to_teardown_btrace) (struct target_ops *, - struct btrace_target_info *tinfo); + struct btrace_target_info *tinfo) + TARGET_DEFAULT_NORETURN (tcomplain ()); /* Read branch trace data. */ VEC (btrace_block_s) *(*to_read_btrace) (struct target_ops *, struct btrace_target_info *, - enum btrace_read_type); + enum btrace_read_type) + TARGET_DEFAULT_NORETURN (tcomplain ()); /* Stop trace recording. */ - void (*to_stop_recording) (struct target_ops *); + void (*to_stop_recording) (struct target_ops *) + TARGET_DEFAULT_IGNORE (); /* Print information about the recording. */ void (*to_info_record) (struct target_ops *); -- 1.8.1.4