From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6706 invoked by alias); 22 Jun 2011 17:19:52 -0000 Received: (qmail 6689 invoked by uid 22791); 22 Jun 2011 17:19:50 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD 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, 22 Jun 2011 17:19:34 +0000 Received: (qmail 16304 invoked from network); 22 Jun 2011 17:19:33 -0000 Received: from unknown (HELO scottsdale.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 22 Jun 2011 17:19:33 -0000 From: Pedro Alves To: Tom Tromey Subject: Re: [4/6] make catchpoints a bit more OO: catch exec Date: Wed, 22 Jun 2011 17:19:00 -0000 User-Agent: KMail/1.13.6 (Linux/2.6.38-8-generic; KDE/4.6.2; x86_64; ; ) Cc: gdb-patches@sourceware.org References: <201106202123.01154.pedro@codesourcery.com> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201106221819.31477.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: 2011-06/txt/msg00317.txt.bz2 On Tuesday 21 June 2011 17:44:11, Tom Tromey wrote: > >>>>> "Pedro" == Pedro Alves writes: > > Pedro> +/* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG > Pedro> + is non-zero, then make the breakpoint temporary. If COND_STRING is > Pedro> + not NULL, then store it in the breakpoint. OPS, if not NULL, is > Pedro> + the breakpoint_ops structure associated to the catchpoint. */ > Pedro> + > Pedro> +/* An instance of this type is used to represent an exec catchpoint. > Pedro> + It includes a "struct breakpoint" as a kind of base class; users > Pedro> + downcast to "struct breakpoint *" when needed. A breakpoint is > Pedro> + really of this type iff its ops pointer points to > Pedro> + CATCH_EXEC_BREAKPOINT_OPS. */ > Pedro> + > > I think that first comment is misplaced. Eh, I have no idea how that got there. :-) Thanks, I removed it. (It's a copy of the comment that now lives on init_catchpoint.) Below's what I applied. Pedro Alves 2011-06-22 Pedro Alves gdb/ * breakpoint.h (struct breakpoint): Delete field `exec_pathname'. * breakpoint.c (init_raw_breakpoint_without_location): Remove reference to exec_pathname. (struct exec_catchpoint): New type. (dtor_catch_exec): New function. (insert_catch_exec, print_it_catch_exec, print_one_catch_exec): Adjust. (catch_exec_breakpoint_ops): Install dtor_catch_syscall. (catch_exec_command_1): Adjust to use init_catchpoint. (delete_breakpoint): Remove reference to exec_pathname. --- gdb/breakpoint.c | 60 ++++++++++++++++++++++++++++++++++++++++++++----------- gdb/breakpoint.h | 5 ---- 2 files changed, 49 insertions(+), 16 deletions(-) Index: src/gdb/breakpoint.h =================================================================== --- src.orig/gdb/breakpoint.h 2011-06-22 18:09:19.315110790 +0100 +++ src/gdb/breakpoint.h 2011-06-22 18:09:38.935110784 +0100 @@ -608,11 +608,6 @@ struct breakpoint aborting, so you can back up to just before the abort. */ int hit_count; - /* Filename of a program whose exec triggered this catchpoint. - This field is only valid immediately after this catchpoint has - triggered. */ - char *exec_pathname; - /* Methods associated with this breakpoint. */ struct breakpoint_ops *ops; Index: src/gdb/breakpoint.c =================================================================== --- src.orig/gdb/breakpoint.c 2011-06-22 18:09:19.315110790 +0100 +++ src/gdb/breakpoint.c 2011-06-22 18:09:38.945110784 +0100 @@ -5826,7 +5826,6 @@ init_raw_breakpoint_without_location (st b->ignore_count = 0; b->commands = NULL; b->frame_id = null_frame_id; - b->exec_pathname = NULL; b->ops = NULL; b->condition_not_parsed = 0; b->py_bp_object = NULL; @@ -6934,6 +6933,34 @@ create_fork_vfork_event_catchpoint (stru /* Exec catchpoints. */ +/* An instance of this type is used to represent an exec catchpoint. + It includes a "struct breakpoint" as a kind of base class; users + downcast to "struct breakpoint *" when needed. A breakpoint is + really of this type iff its ops pointer points to + CATCH_EXEC_BREAKPOINT_OPS. */ + +struct exec_catchpoint +{ + /* The base class. */ + struct breakpoint base; + + /* Filename of a program whose exec triggered this catchpoint. + This field is only valid immediately after this catchpoint has + triggered. */ + char *exec_pathname; +}; + +/* Implement the "dtor" breakpoint_ops method for exec + catchpoints. */ + +static void +dtor_catch_exec (struct breakpoint *b) +{ + struct exec_catchpoint *c = (struct exec_catchpoint *) b; + + xfree (c->exec_pathname); +} + static int insert_catch_exec (struct bp_location *bl) { @@ -6950,21 +6977,26 @@ static int breakpoint_hit_catch_exec (const struct bp_location *bl, struct address_space *aspace, CORE_ADDR bp_addr) { - return inferior_has_execd (inferior_ptid, &bl->owner->exec_pathname); + struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; + + return inferior_has_execd (inferior_ptid, &c->exec_pathname); } static enum print_stop_action print_it_catch_exec (struct breakpoint *b) { + struct exec_catchpoint *c = (struct exec_catchpoint *) b; + annotate_catchpoint (b->number); printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, - b->exec_pathname); + c->exec_pathname); return PRINT_SRC_AND_LOC; } static void print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) { + struct exec_catchpoint *c = (struct exec_catchpoint *) b; struct value_print_options opts; get_user_print_options (&opts); @@ -6976,10 +7008,10 @@ print_one_catch_exec (struct breakpoint ui_out_field_skip (uiout, "addr"); annotate_field (5); ui_out_text (uiout, "exec"); - if (b->exec_pathname != NULL) + if (c->exec_pathname != NULL) { ui_out_text (uiout, ", program \""); - ui_out_field_string (uiout, "what", b->exec_pathname); + ui_out_field_string (uiout, "what", c->exec_pathname); ui_out_text (uiout, "\" "); } } @@ -7001,7 +7033,7 @@ print_recreate_catch_exec (struct breakp static struct breakpoint_ops catch_exec_breakpoint_ops = { - NULL, /* dtor */ + dtor_catch_exec, insert_catch_exec, remove_catch_exec, breakpoint_hit_catch_exec, @@ -9834,6 +9866,7 @@ static void catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) { + struct exec_catchpoint *c; struct gdbarch *gdbarch = get_current_arch (); int tempflag; char *cond_string = NULL; @@ -9854,10 +9887,16 @@ catch_exec_command_1 (char *arg, int fro if ((*arg != '\0') && !isspace (*arg)) error (_("Junk at end of arguments.")); - /* If this target supports it, create an exec catchpoint - and enable reporting of such events. */ - create_catchpoint (gdbarch, tempflag, cond_string, - &catch_exec_breakpoint_ops); + c = XNEW (struct exec_catchpoint); + init_catchpoint (&c->base, gdbarch, tempflag, cond_string, + &catch_exec_breakpoint_ops); + c->exec_pathname = NULL; + + /* Now, we have to mention the breakpoint and update the global + location list. */ + mention (&c->base); + observer_notify_breakpoint_created (&c->base); + update_global_location_list (1); } static enum print_stop_action @@ -10918,7 +10957,6 @@ delete_breakpoint (struct breakpoint *bp xfree (bpt->exp_string_reparse); value_free (bpt->val); xfree (bpt->source_file); - xfree (bpt->exec_pathname); /* Be sure no bpstat's are pointing at the breakpoint after it's