From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 92741 invoked by alias); 18 Sep 2015 01:14:28 -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 92089 invoked by uid 89); 18 Sep 2015 01:14:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=no 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 18 Sep 2015 01:14:26 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id F03E4C0A1473 for ; Fri, 18 Sep 2015 01:14:24 +0000 (UTC) Received: from pinnacle.lan (ovpn-113-104.phx2.redhat.com [10.3.113.104]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8I1EOeo018990 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA256 bits=256 verify=NO) for ; Thu, 17 Sep 2015 21:14:24 -0400 Date: Fri, 18 Sep 2015 01:14:00 -0000 From: Kevin Buettner To: gdb-patches@sourceware.org Subject: Re: [PATCH 2/8] Add new gdbarch method, unconditional_branch_address Message-ID: <20150917181422.233f13f6@pinnacle.lan> In-Reply-To: <55DC5BFD.3070506@redhat.com> References: <20150818235334.1afb0c85@pinnacle.lan> <20150819000002.06f6a2cf@pinnacle.lan> <55DC5BFD.3070506@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-09/txt/msg00432.txt.bz2 On Tue, 25 Aug 2015 13:13:49 +0100 Pedro Alves wrote: > > +# Examine instruction at PC. If instruction at PC is an unconditional > > +# branch, return the address to which control is transferred when the > > +# branch is taken. Return 0 when this method is not implemented by > > +# architecture, PC refers to an invalid address, or instruction at PC > > +# is not an unconditional branch. > > +m:CORE_ADDR:unconditional_branch_address:CORE_ADDR pc:pc::default_unconditional_branch_address::0 > > + > > In addition to the comments in the other patch, I wonder if we would > better name this in terms of a higher level concept, around > "breakpoint address" instead of a "low level branch destination"? I gave this some thought, but could not come up with a name that was meaningful yet not overly long. If you have a name that you like, I'm quite willing to revise the patches again. In the midst of adding a parameter for holding the branch destination, I noticed that gdbarch.sh has a method called insn_is_jump, which is used in btrace.c. (There is also insn_is_call and insn_is_ret.) I thought about using insn_is_jump, but I would need to modify it to return the branch destination. I decided that the work I'm doing here should have it's own method. If GCC should someday emit DWARF which sets is_stmt to 0 for the branch instruction at the beginning of a while loop, this work might not be needed any longer. It'll be easier to rip it out and clean things up again if I don't modify gdbarch methods that were added for other purposes. In the end, I decided to go with the name that you suggested in your review of patch #3, unconditional_branch_destination. Here's the revised patch: Add new gdbarch method, unconditional_branch_destination. gdb/ChangeLog: * gdbarch.sh (unconditional_branch_destination): New gdbarch method. * gdbarch.h, gdbarch.c: Regenerate. * arch-utils.h (default_unconditional_branch_destination): Declare. * arch-utils.c (default_unconditional_branch_destination): New function. --- gdb/arch-utils.c | 7 +++++++ gdb/arch-utils.h | 4 ++++ gdb/gdbarch.c | 23 +++++++++++++++++++++++ gdb/gdbarch.h | 9 +++++++++ gdb/gdbarch.sh | 6 ++++++ 5 files changed, 49 insertions(+) diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 7df5570..23f9e69 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -821,6 +821,13 @@ default_gen_return_address (struct gdbarch *gdbarch, } int +default_unconditional_branch_destination (struct gdbarch *gdbarch, CORE_ADDR pc, + CORE_ADDR *dest) +{ + return 0; +} + +int default_return_in_first_hidden_param_p (struct gdbarch *gdbarch, struct type *type) { diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h index 18e2290..e3a9a7d 100644 --- a/gdb/arch-utils.h +++ b/gdb/arch-utils.h @@ -204,4 +204,8 @@ extern char *default_gcc_target_options (struct gdbarch *gdbarch); extern const char *default_gnu_triplet_regexp (struct gdbarch *gdbarch); extern int default_addressable_memory_unit_size (struct gdbarch *gdbarch); +extern int default_unconditional_branch_destination (struct gdbarch *gdbarch, + CORE_ADDR pc, + CORE_ADDR *dest); + #endif diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index f04eef9..a2e7dfb 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -330,6 +330,7 @@ struct gdbarch gdbarch_gcc_target_options_ftype *gcc_target_options; gdbarch_gnu_triplet_regexp_ftype *gnu_triplet_regexp; gdbarch_addressable_memory_unit_size_ftype *addressable_memory_unit_size; + gdbarch_unconditional_branch_destination_ftype *unconditional_branch_destination; }; /* Create a new ``struct gdbarch'' based on information provided by @@ -432,6 +433,7 @@ gdbarch_alloc (const struct gdbarch_info *info, gdbarch->gcc_target_options = default_gcc_target_options; gdbarch->gnu_triplet_regexp = default_gnu_triplet_regexp; gdbarch->addressable_memory_unit_size = default_addressable_memory_unit_size; + gdbarch->unconditional_branch_destination = default_unconditional_branch_destination; /* gdbarch_alloc() */ return gdbarch; @@ -674,6 +676,7 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of gcc_target_options, invalid_p == 0 */ /* Skip verify of gnu_triplet_regexp, invalid_p == 0 */ /* Skip verify of addressable_memory_unit_size, invalid_p == 0 */ + /* Skip verify of unconditional_branch_destination, invalid_p == 0 */ buf = ui_file_xstrdup (log, &length); make_cleanup (xfree, buf); if (length > 0) @@ -1364,6 +1367,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) "gdbarch_dump: target_desc = %s\n", host_address_to_string (gdbarch->target_desc)); fprintf_unfiltered (file, + "gdbarch_dump: unconditional_branch_destination = <%s>\n", + host_address_to_string (gdbarch->unconditional_branch_destination)); + fprintf_unfiltered (file, "gdbarch_dump: gdbarch_unwind_pc_p() = %d\n", gdbarch_unwind_pc_p (gdbarch)); fprintf_unfiltered (file, @@ -4761,6 +4767,23 @@ set_gdbarch_addressable_memory_unit_size (struct gdbarch *gdbarch, gdbarch->addressable_memory_unit_size = addressable_memory_unit_size; } +int +gdbarch_unconditional_branch_destination (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR *dest) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->unconditional_branch_destination != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_unconditional_branch_destination called\n"); + return gdbarch->unconditional_branch_destination (gdbarch, pc, dest); +} + +void +set_gdbarch_unconditional_branch_destination (struct gdbarch *gdbarch, + gdbarch_unconditional_branch_destination_ftype unconditional_branch_destination) +{ + gdbarch->unconditional_branch_destination = unconditional_branch_destination; +} + /* Keep a registry of per-architecture data-pointers required by GDB modules. */ diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index 82e0259..2d0cf8d 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -1478,6 +1478,15 @@ typedef int (gdbarch_addressable_memory_unit_size_ftype) (struct gdbarch *gdbarc extern int gdbarch_addressable_memory_unit_size (struct gdbarch *gdbarch); extern void set_gdbarch_addressable_memory_unit_size (struct gdbarch *gdbarch, gdbarch_addressable_memory_unit_size_ftype *addressable_memory_unit_size); +/* Examine instruction at PC. If instruction at PC is an unconditional + branch, return 1 and set *DEST to the branch destination address. + Return 0 when this method is not implemented by architecture, PC refers + to an invalid address, or instruction at PC is not an unconditional branch. */ + +typedef int (gdbarch_unconditional_branch_destination_ftype) (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR *dest); +extern int gdbarch_unconditional_branch_destination (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR *dest); +extern void set_gdbarch_unconditional_branch_destination (struct gdbarch *gdbarch, gdbarch_unconditional_branch_destination_ftype *unconditional_branch_destination); + /* Definition for an unknown syscall, used basically in error-cases. */ #define UNKNOWN_SYSCALL (-1) diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh index 388920f..b87fd19 100755 --- a/gdb/gdbarch.sh +++ b/gdb/gdbarch.sh @@ -1123,6 +1123,12 @@ m:const char *:gnu_triplet_regexp:void:::default_gnu_triplet_regexp::0 # each address in memory. m:int:addressable_memory_unit_size:void:::default_addressable_memory_unit_size::0 +# Examine instruction at PC. If instruction at PC is an unconditional +# branch, return 1 and set *DEST to the branch destination address. +# Return 0 when this method is not implemented by architecture, PC refers +# to an invalid address, or instruction at PC is not an unconditional branch. +m:int:unconditional_branch_destination:CORE_ADDR pc, CORE_ADDR *dest:pc, dest::default_unconditional_branch_destination::0 + EOF }