From patchwork Sat Nov 1 21:46:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 3545 Received: (qmail 27890 invoked by alias); 1 Nov 2014 21:46:42 -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 27875 invoked by uid 89); 1 Nov 2014 21:46:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 01 Nov 2014 21:46:39 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sA1Lkbv6019282 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Sat, 1 Nov 2014 17:46:37 -0400 Received: from host1.jankratochvil.net (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sA1LkZdY022316 for ; Sat, 1 Nov 2014 17:46:36 -0400 Subject: [PATCH v3 06/14] add infcall_mmap and gcc_target_options gdbarch methods From: Jan Kratochvil To: gdb-patches@sourceware.org Date: Sat, 01 Nov 2014 22:46:35 +0100 Message-ID: <20141101214635.13230.66878.stgit@host1.jankratochvil.net> In-Reply-To: <20141101214552.13230.45564.stgit@host1.jankratochvil.net> References: <20141101214552.13230.45564.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes The compiler needed two new gdbarch methods. The infcall_mmap method allocates memory in the inferior. This is used when inserting the object code. The gcc_target_options method computes some arch-specific gcc options to pass to the compiler. This is used to ensure that gcc generates object code for the correct architecture. 2014-10-07 Jan Kratochvil * arch-utils.c (default_infcall_mmap) (default_gcc_target_options): New functions. * arch-utils.h (default_infcall_mmap, default_gcc_target_options): Declare. * gdbarch.h: Rebuild. * gdbarch.c: Rebuild. * gdbarch.sh (infcall_mmap, gcc_target_options): New methods. --- gdb/ChangeLog | 10 ++++++++++ gdb/arch-utils.c | 13 +++++++++++++ gdb/arch-utils.h | 4 ++++ gdb/gdbarch.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ gdb/gdbarch.h | 18 ++++++++++++++++++ gdb/gdbarch.sh | 12 ++++++++++++ 6 files changed, 103 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ede97a2..910fcc2 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2014-10-07 Jan Kratochvil + * arch-utils.c (default_infcall_mmap) + (default_gcc_target_options): New functions. + * arch-utils.h (default_infcall_mmap, default_gcc_target_options): + Declare. + * gdbarch.h: Rebuild. + * gdbarch.c: Rebuild. + * gdbarch.sh (infcall_mmap, gcc_target_options): New methods. + +2014-10-07 Jan Kratochvil + * dummy-frame.c (struct dummy_frame) : New fields. (pop_dummy_frame): Call the destructor if it exists. diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 41cf828..5771484 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -826,6 +826,19 @@ int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr) return 0; } +CORE_ADDR +default_infcall_mmap (CORE_ADDR size, unsigned prot) +{ + error (_("This target does not support inferior memory allocation by mmap.")); +} + +char * +default_gcc_target_options (struct gdbarch *gdbarch) +{ + return xstrprintf ("-m%d%s", gdbarch_ptr_bit (gdbarch), + gdbarch_ptr_bit (gdbarch) == 64 ? " -mcmodel=large" : ""); +} + /* */ /* -Wmissing-prototypes */ diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h index a609662..53358ed 100644 --- a/gdb/arch-utils.h +++ b/gdb/arch-utils.h @@ -178,4 +178,8 @@ extern int default_insn_is_jump (struct gdbarch *, CORE_ADDR); /* Do-nothing version of vsyscall_range. Returns false. */ extern int default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range); + +extern CORE_ADDR default_infcall_mmap (CORE_ADDR size, unsigned prot); +extern char *default_gcc_target_options (struct gdbarch *gdbarch); + #endif diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 2984358..8d882bc 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -316,6 +316,8 @@ struct gdbarch gdbarch_insn_is_jump_ftype *insn_is_jump; gdbarch_auxv_parse_ftype *auxv_parse; gdbarch_vsyscall_range_ftype *vsyscall_range; + gdbarch_infcall_mmap_ftype *infcall_mmap; + gdbarch_gcc_target_options_ftype *gcc_target_options; }; /* Create a new ``struct gdbarch'' based on information provided by @@ -409,6 +411,8 @@ gdbarch_alloc (const struct gdbarch_info *info, gdbarch->insn_is_ret = default_insn_is_ret; gdbarch->insn_is_jump = default_insn_is_jump; gdbarch->vsyscall_range = default_vsyscall_range; + gdbarch->infcall_mmap = default_infcall_mmap; + gdbarch->gcc_target_options = default_gcc_target_options; /* gdbarch_alloc() */ return gdbarch; @@ -629,6 +633,8 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of insn_is_jump, invalid_p == 0 */ /* Skip verify of auxv_parse, has predicate. */ /* Skip verify of vsyscall_range, invalid_p == 0 */ + /* Skip verify of infcall_mmap, invalid_p == 0 */ + /* Skip verify of gcc_target_options, invalid_p == 0 */ buf = ui_file_xstrdup (log, &length); make_cleanup (xfree, buf); if (length > 0) @@ -890,6 +896,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) "gdbarch_dump: frame_red_zone_size = %s\n", plongest (gdbarch->frame_red_zone_size)); fprintf_unfiltered (file, + "gdbarch_dump: gcc_target_options = <%s>\n", + host_address_to_string (gdbarch->gcc_target_options)); + fprintf_unfiltered (file, "gdbarch_dump: gdbarch_gcore_bfd_target_p() = %d\n", gdbarch_gcore_bfd_target_p (gdbarch)); fprintf_unfiltered (file, @@ -956,6 +965,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) "gdbarch_dump: in_solib_return_trampoline = <%s>\n", host_address_to_string (gdbarch->in_solib_return_trampoline)); fprintf_unfiltered (file, + "gdbarch_dump: infcall_mmap = <%s>\n", + host_address_to_string (gdbarch->infcall_mmap)); + fprintf_unfiltered (file, "gdbarch_dump: gdbarch_info_proc_p() = %d\n", gdbarch_info_proc_p (gdbarch)); fprintf_unfiltered (file, @@ -4406,6 +4418,40 @@ set_gdbarch_vsyscall_range (struct gdbarch *gdbarch, gdbarch->vsyscall_range = vsyscall_range; } +CORE_ADDR +gdbarch_infcall_mmap (struct gdbarch *gdbarch, CORE_ADDR size, unsigned prot) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->infcall_mmap != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_infcall_mmap called\n"); + return gdbarch->infcall_mmap (size, prot); +} + +void +set_gdbarch_infcall_mmap (struct gdbarch *gdbarch, + gdbarch_infcall_mmap_ftype infcall_mmap) +{ + gdbarch->infcall_mmap = infcall_mmap; +} + +char * +gdbarch_gcc_target_options (struct gdbarch *gdbarch) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->gcc_target_options != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_gcc_target_options called\n"); + return gdbarch->gcc_target_options (gdbarch); +} + +void +set_gdbarch_gcc_target_options (struct gdbarch *gdbarch, + gdbarch_gcc_target_options_ftype gcc_target_options) +{ + gdbarch->gcc_target_options = gcc_target_options; +} + /* Keep a registry of per-architecture data-pointers required by GDB modules. */ diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index f5330c2..0b2292b 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -1330,6 +1330,24 @@ typedef int (gdbarch_vsyscall_range_ftype) (struct gdbarch *gdbarch, struct mem_ extern int gdbarch_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range); extern void set_gdbarch_vsyscall_range (struct gdbarch *gdbarch, gdbarch_vsyscall_range_ftype *vsyscall_range); +/* Allocate SIZE bytes of PROT protected page aligned memory in inferior. + PROT has rwx bitmask format - bit 2 (value 4) is for readable memory, bit 1 + (value 2) is for writable memory and bit 0 (value 1) is for executable memory. + Throw an error if it is not possible. Returned address is always valid. */ + +typedef CORE_ADDR (gdbarch_infcall_mmap_ftype) (CORE_ADDR size, unsigned prot); +extern CORE_ADDR gdbarch_infcall_mmap (struct gdbarch *gdbarch, CORE_ADDR size, unsigned prot); +extern void set_gdbarch_infcall_mmap (struct gdbarch *gdbarch, gdbarch_infcall_mmap_ftype *infcall_mmap); + +/* Return string (caller has to use xfree for it) with options for GCC + to produce code for this target, typically "-m64", "-m32" or "-m31". + These options are put before CU's DW_AT_producer compilation options so that + they can override it. Method may also return NULL. */ + +typedef char * (gdbarch_gcc_target_options_ftype) (struct gdbarch *gdbarch); +extern char * gdbarch_gcc_target_options (struct gdbarch *gdbarch); +extern void set_gdbarch_gcc_target_options (struct gdbarch *gdbarch, gdbarch_gcc_target_options_ftype *gcc_target_options); + /* 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 5442799..ac63a8b 100755 --- a/gdb/gdbarch.sh +++ b/gdb/gdbarch.sh @@ -1036,6 +1036,18 @@ M:int:auxv_parse:gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_AD # range with zero length is returned. Returns true if the vsyscall is # found, false otherwise. m:int:vsyscall_range:struct mem_range *range:range::default_vsyscall_range::0 + +# Allocate SIZE bytes of PROT protected page aligned memory in inferior. +# PROT has rwx bitmask format - bit 2 (value 4) is for readable memory, bit 1 +# (value 2) is for writable memory and bit 0 (value 1) is for executable memory. +# Throw an error if it is not possible. Returned address is always valid. +f:CORE_ADDR:infcall_mmap:CORE_ADDR size, unsigned prot:size, prot::default_infcall_mmap::0 + +# Return string (caller has to use xfree for it) with options for GCC +# to produce code for this target, typically "-m64", "-m32" or "-m31". +# These options are put before CU's DW_AT_producer compilation options so that +# they can override it. Method may also return NULL. +m:char *:gcc_target_options:void:::default_gcc_target_options::0 EOF }