From patchwork Fri Oct 7 12:37:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Kolesov X-Patchwork-Id: 16341 Received: (qmail 129658 invoked by alias); 7 Oct 2016 12:38:11 -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 129481 invoked by uid 89); 7 Oct 2016 12:38:09 -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, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=12466 X-HELO: smtprelay.synopsys.com Received: from us01smtprelay-2.synopsys.com (HELO smtprelay.synopsys.com) (198.182.60.111) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Oct 2016 12:38:08 +0000 Received: from dc8secmta2.synopsys.com (dc8secmta2.synopsys.com [10.13.218.202]) by smtprelay.synopsys.com (Postfix) with ESMTP id D60FA10C150F for ; Fri, 7 Oct 2016 05:38:06 -0700 (PDT) Received: from dc8secmta2.internal.synopsys.com (dc8secmta2.internal.synopsys.com [127.0.0.1]) by dc8secmta2.internal.synopsys.com (Service) with ESMTP id C9320A4112 for ; Fri, 7 Oct 2016 05:38:06 -0700 (PDT) Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by dc8secmta2.internal.synopsys.com (Service) with ESMTP id 93240A4102 for ; Fri, 7 Oct 2016 05:38:06 -0700 (PDT) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id 7A6C7284; Fri, 7 Oct 2016 05:38:06 -0700 (PDT) Received: from akolesov-lab.internal.synopsys.com (akolesov-lab.internal.synopsys.com [10.121.8.134]) by mailhost.synopsys.com (Postfix) with ESMTP id 7FB1A27B; Fri, 7 Oct 2016 05:38:05 -0700 (PDT) From: Anton Kolesov To: gdb-patches@sourceware.org Cc: Anton Kolesov , Francois Bedard Subject: [PATCH 2/3] arc: Add evaluation of long jump targets Date: Fri, 7 Oct 2016 15:37:49 +0300 Message-Id: <1475843870-11449-2-git-send-email-Anton.Kolesov@synopsys.com> In-Reply-To: <1475843870-11449-1-git-send-email-Anton.Kolesov@synopsys.com> References: <1475843870-11449-1-git-send-email-Anton.Kolesov@synopsys.com> Standard get_longjmp_target implementation, similar to what is in arm-tdep.c. Actual value of jb_pc should be set in init_osabi methods of particular OS/ABI implementations. gdb/ChangeLog: * arc-tdep.h (gdbarch_tdep): Add jb_pc. * arc-tdep.c (arc_get_longjmp_target): New function. (arc_gdbarch_init): Set get_longjmp_target if jb_pc is non-negative. (arc_dump_tdep): Print jb_pc. --- gdb/arc-tdep.c | 36 +++++++++++++++++++++++++++++++++++- gdb/arc-tdep.h | 3 +++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c index 58de8e9..bc8bb98 100644 --- a/gdb/arc-tdep.c +++ b/gdb/arc-tdep.c @@ -557,6 +557,34 @@ arc_store_return_value (struct gdbarch *gdbarch, struct type *type, error (_("arc_store_return_value: type length too large.")); } +/* Implement the "get_longjmp_target" gdbarch method. + + Detemine the address the longjmp will jump to. We need to use the frame + info to get the register pointing to the jmp_buf, then extract the PC from + that. Since jmp_buf is the first argument to longjmp () it will be in r0. + Where we then go depends on the OS - OS/ABI initialization should set offset + from jmp_buf start to the stored PC location. */ + +static int +arc_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc) +{ + if (arc_debug) + debug_printf ("arc: get_longjmp_target\n"); + + struct gdbarch *gdbarch = get_frame_arch (frame); + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + int pc_offset = tdep->jb_pc * ARC_REGISTER_SIZE; + gdb_byte buf[ARC_REGISTER_SIZE]; + CORE_ADDR jb_addr = get_frame_register_unsigned (frame, ARC_FIRST_ARG_REGNUM); + + if (target_read_memory (jb_addr + pc_offset, buf, ARC_REGISTER_SIZE)) + return 0; /* Failed to read from memory. */ + + *pc = extract_unsigned_integer (buf, ARC_REGISTER_SIZE, + gdbarch_byte_order (gdbarch)); + return 1; +} + /* Implement the "return_value" gdbarch method. */ static enum return_value_convention @@ -1162,6 +1190,7 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) /* Allocate the ARC-private target-dependent information structure, and the GDB target-independent information structure. */ struct gdbarch_tdep *tdep = XCNEW (struct gdbarch_tdep); + tdep->jb_pc = -1; /* No longjmp support by default. */ struct gdbarch *gdbarch = gdbarch_alloc (&info, tdep); /* Data types. */ @@ -1246,6 +1275,9 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) It can override functions set earlier. */ gdbarch_init_osabi (info, gdbarch); + if (tdep->jb_pc >= 0) + set_gdbarch_get_longjmp_target (gdbarch, arc_get_longjmp_target); + tdesc_use_registers (gdbarch, tdesc, tdesc_data); return gdbarch; @@ -1256,7 +1288,9 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) static void arc_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file) { - /* Empty for now. */ + struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + fprintf_unfiltered (file, "arc_dump_tdep: jb_pc = %i\n", tdep->jb_pc); } /* Suppress warning from -Wmissing-prototypes. */ diff --git a/gdb/arc-tdep.h b/gdb/arc-tdep.h index ea34b9e..1e792b9 100644 --- a/gdb/arc-tdep.h +++ b/gdb/arc-tdep.h @@ -81,6 +81,9 @@ extern int arc_debug; struct gdbarch_tdep { + /* Offset to PC value in jump buffer. If this is negative, longjmp + support will be disabled. */ + int jb_pc; }; /* Utility functions used by other ARC-specific modules. */