From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20837 invoked by alias); 20 Sep 2013 02:47:55 -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 20794 invoked by uid 89); 20 Sep 2013 02:47:55 -0000 Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Sep 2013 02:47:55 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RDNS_NONE,SPF_HELO_FAIL autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1VMql4-0004i6-HA from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Thu, 19 Sep 2013 19:47:50 -0700 Received: from SVR-ORW-FEM-03.mgc.mentorg.com ([147.34.97.39]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Thu, 19 Sep 2013 19:47:50 -0700 Received: from qiyao.dyndns.org (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.2.247.3; Thu, 19 Sep 2013 19:47:49 -0700 From: Yao Qi To: Subject: [PATCH 4/7] Trust readonly sections if target has memory protection and in remote debugging Date: Fri, 20 Sep 2013 02:47:00 -0000 Message-ID: <1379645226-8719-5-git-send-email-yao@codesourcery.com> In-Reply-To: <1379645226-8719-1-git-send-email-yao@codesourcery.com> References: <1378641807-24256-1-git-send-email-yao@codesourcery.com> <1379645226-8719-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2013-09/txt/msg00716.txt.bz2 This patch first changes command "trust-readonly-sections" to an auto_boolean command, so "auto" means that GDB trusts read-only sections if the target has memory protection and GDB is donging remote debugging. Then, this patch adds a gdbarch hook method "has_memory_protection". Next patches are to implement the hook method for linux target and windows target. Compared with V2, the only change in V3 is here, +/* Return true if GDB trusts readonly sections. Return false + otherwise. */ + +static int +trust_readonly_p (void) +{ + if (trust_readonly != AUTO_BOOLEAN_AUTO) + return trust_readonly == AUTO_BOOLEAN_TRUE; + + /* We only trust readonly sections when GDB is dong remote debugging + on the targets which have memory protection. */ + return (gdbarch_has_memory_protection (target_gdbarch ()) + && (strcmp (target_shortname, "remote") == 0 + || strcmp (target_shortname, "extended-remote") == 0)); +} we add some code to checker whether the target is remote or extended-remote. gdb: 2013-09-20 Yao Qi * arch-utils.c (default_has_memory_protection): New function. * arch-utils.h (default_has_memory_protection): Declaration. * gdbarch.sh (has_memory_protection): New hook method. * gdbarch.c: Re-generated. * gdbarch.h: Re-generated. * target.c (trust_readonly): Change type to 'enum auto_boolean' and initialize it to 'AUTO_BOOLEAN_AUTO'. (trust_readonly_p): New function. (memory_xfer_partial_1): Call trust_readonly_p. (initialize_targets): Register command "trust-readonly-sections" as add_setshow_auto_boolean_cmd. --- gdb/arch-utils.c | 7 +++++++ gdb/arch-utils.h | 2 ++ gdb/gdbarch.c | 24 ++++++++++++++++++++++++ gdb/gdbarch.h | 6 ++++++ gdb/gdbarch.sh | 3 +++ gdb/target.c | 39 +++++++++++++++++++++++++++++---------- 6 files changed, 71 insertions(+), 10 deletions(-) diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 459fd88..8418bbc 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -769,6 +769,13 @@ default_has_shared_address_space (struct gdbarch *gdbarch) } int +default_has_memory_protection (struct gdbarch *gdbarch) +{ + /* Simply say no. */ + return 0; +} + +int default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr, int *isize, char **msg) { diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h index 3f0e64f..61973c0 100644 --- a/gdb/arch-utils.h +++ b/gdb/arch-utils.h @@ -153,6 +153,8 @@ extern struct gdbarch *get_current_arch (void); extern int default_has_shared_address_space (struct gdbarch *); +extern int default_has_memory_protection (struct gdbarch *gdbarch); + extern int default_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr, int *isize, char **msg); diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 1f3380e..13e5e82 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -278,6 +278,7 @@ struct gdbarch int has_global_solist; int has_global_breakpoints; gdbarch_has_shared_address_space_ftype *has_shared_address_space; + gdbarch_has_memory_protection_ftype *has_memory_protection; gdbarch_fast_tracepoint_valid_at_ftype *fast_tracepoint_valid_at; gdbarch_auto_charset_ftype *auto_charset; gdbarch_auto_wide_charset_ftype *auto_wide_charset; @@ -451,6 +452,7 @@ struct gdbarch startup_gdbarch = 0, /* has_global_solist */ 0, /* has_global_breakpoints */ default_has_shared_address_space, /* has_shared_address_space */ + default_has_memory_protection, /* has_memory_protection */ default_fast_tracepoint_valid_at, /* fast_tracepoint_valid_at */ default_auto_charset, /* auto_charset */ default_auto_wide_charset, /* auto_wide_charset */ @@ -546,6 +548,7 @@ gdbarch_alloc (const struct gdbarch_info *info, gdbarch->displaced_step_location = NULL; gdbarch->relocate_instruction = NULL; gdbarch->has_shared_address_space = default_has_shared_address_space; + gdbarch->has_memory_protection = default_has_memory_protection; gdbarch->fast_tracepoint_valid_at = default_fast_tracepoint_valid_at; gdbarch->auto_charset = default_auto_charset; gdbarch->auto_wide_charset = default_auto_wide_charset; @@ -757,6 +760,7 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of has_global_solist, invalid_p == 0 */ /* Skip verify of has_global_breakpoints, invalid_p == 0 */ /* Skip verify of has_shared_address_space, invalid_p == 0 */ + /* Skip verify of has_memory_protection, invalid_p == 0 */ /* Skip verify of fast_tracepoint_valid_at, invalid_p == 0 */ /* Skip verify of auto_charset, invalid_p == 0 */ /* Skip verify of auto_wide_charset, invalid_p == 0 */ @@ -1078,6 +1082,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) "gdbarch_dump: has_global_solist = %s\n", plongest (gdbarch->has_global_solist)); fprintf_unfiltered (file, + "gdbarch_dump: has_memory_protection = <%s>\n", + host_address_to_string (gdbarch->has_memory_protection)); + fprintf_unfiltered (file, "gdbarch_dump: has_shared_address_space = <%s>\n", host_address_to_string (gdbarch->has_shared_address_space)); fprintf_unfiltered (file, @@ -4240,6 +4247,23 @@ set_gdbarch_has_shared_address_space (struct gdbarch *gdbarch, } int +gdbarch_has_memory_protection (struct gdbarch *gdbarch) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->has_memory_protection != NULL); + if (gdbarch_debug >= 2) + fprintf_unfiltered (gdb_stdlog, "gdbarch_has_memory_protection called\n"); + return gdbarch->has_memory_protection (gdbarch); +} + +void +set_gdbarch_has_memory_protection (struct gdbarch *gdbarch, + gdbarch_has_memory_protection_ftype has_memory_protection) +{ + gdbarch->has_memory_protection = has_memory_protection; +} + +int gdbarch_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr, int *isize, char **msg) { gdb_assert (gdbarch != NULL); diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index 013f071..ade07d7 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -1176,6 +1176,12 @@ typedef int (gdbarch_has_shared_address_space_ftype) (struct gdbarch *gdbarch); extern int gdbarch_has_shared_address_space (struct gdbarch *gdbarch); extern void set_gdbarch_has_shared_address_space (struct gdbarch *gdbarch, gdbarch_has_shared_address_space_ftype *has_shared_address_space); +/* True if the target has memory protection. */ + +typedef int (gdbarch_has_memory_protection_ftype) (struct gdbarch *gdbarch); +extern int gdbarch_has_memory_protection (struct gdbarch *gdbarch); +extern void set_gdbarch_has_memory_protection (struct gdbarch *gdbarch, gdbarch_has_memory_protection_ftype *has_memory_protection); + /* True if a fast tracepoint can be set at an address. */ typedef int (gdbarch_fast_tracepoint_valid_at_ftype) (struct gdbarch *gdbarch, CORE_ADDR addr, int *isize, char **msg); diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh index 04ca38c..080a5ec 100755 --- a/gdb/gdbarch.sh +++ b/gdb/gdbarch.sh @@ -932,6 +932,9 @@ v:int:has_global_breakpoints:::0:0::0 # True if inferiors share an address space (e.g., uClinux). m:int:has_shared_address_space:void:::default_has_shared_address_space::0 +# True if the target has memory protection. +m:int:has_memory_protection:void:::default_has_memory_protection::0 + # True if a fast tracepoint can be set at an address. m:int:fast_tracepoint_valid_at:CORE_ADDR addr, int *isize, char **msg:addr, isize, msg::default_fast_tracepoint_valid_at::0 diff --git a/gdb/target.c b/gdb/target.c index 37db36b..955a292 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -168,10 +168,10 @@ struct target_ops current_target; static struct cmd_list_element *targetlist = NULL; -/* Nonzero if we should trust readonly sections from the +/* If AUTO_BOOLEAN_TRUE, we should trust readonly sections from the executable when reading memory. */ -static int trust_readonly = 0; +static enum auto_boolean trust_readonly = AUTO_BOOLEAN_AUTO; /* Nonzero if we should show true memory content including memory breakpoint inserted by gdb. */ @@ -1437,6 +1437,22 @@ memory_xfer_live_readonly_partial (struct target_ops *ops, return 0; } +/* Return true if GDB trusts readonly sections. Return false + otherwise. */ + +static int +trust_readonly_p (void) +{ + if (trust_readonly != AUTO_BOOLEAN_AUTO) + return trust_readonly == AUTO_BOOLEAN_TRUE; + + /* We only trust readonly sections when GDB is dong remote debugging + on the targets which have memory protection. */ + return (gdbarch_has_memory_protection (target_gdbarch ()) + && (strcmp (target_shortname, "remote") == 0 + || strcmp (target_shortname, "extended-remote") == 0)); +} + /* Perform a partial memory transfer. For docs see target.h, to_xfer_partial. */ @@ -1475,7 +1491,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object, files. When GDB writes to a readonly section of the inferior, emit a warning that option 'trust-readonly-sections' should be turned off. */ - if (trust_readonly) + if (trust_readonly_p ()) { struct target_section *secp; @@ -1502,7 +1518,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object, { if (query (_("Address is read-only and trust-readonly-sections\ is set to \"on\".\nSet it to \"off\" and write to a read-only section? "))) - trust_readonly = 0; + trust_readonly = AUTO_BOOLEAN_FALSE; else return -1; } @@ -5103,16 +5119,19 @@ command."), show_targetdebug, &setdebuglist, &showdebuglist); - add_setshow_boolean_cmd ("trust-readonly-sections", class_support, - &trust_readonly, _("\ + add_setshow_auto_boolean_cmd ("trust-readonly-sections", class_support, + &trust_readonly, _("\ Set mode for reading from readonly sections."), _("\ Show mode for reading from readonly sections."), _("\ When this mode is on, memory reads from readonly sections (such as .text)\n\ will be read from the object file instead of from the target. This will\n\ -result in significant performance improvement for remote targets."), - NULL, - show_trust_readonly, - &setlist, &showlist); +result in significant performance improvement for remote targets.\n\ +When this mode is auto, GDB will decide based on the target memory\n\ +protection features whether to read readonly sections from object file\n\ +instead of from the inferior's memory in remote debugging.\n"), + NULL, + show_trust_readonly, + &setlist, &showlist); add_com ("monitor", class_obscure, do_monitor_command, _("Send a command to the remote monitor (remote targets only).")); -- 1.7.7.6