Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <yao@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH 2/3] Trust readonly sections if target has memory protection
Date: Fri, 06 Sep 2013 02:03:00 -0000	[thread overview]
Message-ID: <1378432920-7731-3-git-send-email-yao@codesourcery.com> (raw)
In-Reply-To: <1378432920-7731-1-git-send-email-yao@codesourcery.com>

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.  Then, this patch adds a
gdbarch hook method "has_memory_protection".  Patch 2/2 is to
implement the hook method for linux target.

gdb:

2013-09-06  Yao Qi  <yao@codesourcery.com>

	* 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.

	* NEWS: Describe the default option of
	"trust-readonly-sections" becomes "auto" and the related
	changes.

gdb/doc:

2013-09-06  Yao Qi  <yao@codesourcery.com>

	* gdb.texinfo (Files): Explain the default option of
	"trust-readonly-sections" is "auto".
---
 gdb/NEWS            |    4 ++++
 gdb/arch-utils.c    |    7 +++++++
 gdb/arch-utils.h    |    2 ++
 gdb/doc/gdb.texinfo |    6 +++++-
 gdb/gdbarch.c       |   24 ++++++++++++++++++++++++
 gdb/gdbarch.h       |    6 ++++++
 gdb/gdbarch.sh      |    3 +++
 gdb/target.c        |   32 +++++++++++++++++++++++---------
 8 files changed, 74 insertions(+), 10 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index ad97f6f..a3bdf84 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,10 @@
 
 *** Changes since GDB 7.6
 
+* The default value of option "trust-readonly-sections" is "auto".  GDB
+  trusts the contents of read-only sections from the object file on the
+  GNU/Linux targets.
+
 * The "maintenance print objfiles" command now takes an optional regexp.
 
 * The "catch syscall" command now works on arm*-linux* targets.
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/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index d8e4adf..5efa966 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -16673,7 +16673,11 @@ out of the object file, rather than from the target program.
 For some targets (notably embedded ones), this can be a significant
 enhancement to debugging performance.
 
-The default is off.
+@item set trust-readonly-sections auto
+This is the default mode.  Tell @value{GDBN} to trust read-only
+sections on some targets which have memory protection, such as
+GNU/Linux, because the contents of the section in the target program
+can't change.
 
 @item set trust-readonly-sections off
 Tell @value{GDBN} not to trust readonly sections.  This means that
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 d55712d..80f1f87 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,18 @@ 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;
+
+  return gdbarch_has_memory_protection (target_gdbarch ());
+}
+
 /* Perform a partial memory transfer.
    For docs see target.h, to_xfer_partial.  */
 
@@ -1472,7 +1484,7 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
     }
 
   /* Try the executable files, if "trust-readonly-sections" is set.  */
-  if (readbuf != NULL && trust_readonly)
+  if (readbuf != NULL && trust_readonly_p ())
     {
       struct target_section *secp;
       struct target_section_table *table;
@@ -5086,16 +5098,18 @@ 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, memory reads from readonly sections will be\n\
+read from the object file if the target has memory protection.\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


  reply	other threads:[~2013-09-06  2:03 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-06  2:03 [PATCH 0/3] " Yao Qi
2013-09-06  2:03 ` Yao Qi [this message]
2013-09-06  6:05   ` [PATCH 2/3] " Eli Zaretskii
2013-09-06  9:07     ` Yao Qi
2013-09-06  9:24       ` Eli Zaretskii
2013-09-06  2:03 ` [PATCH 1/3] set trust-readonly-sections off in test cases Yao Qi
2013-09-06  5:56   ` Eli Zaretskii
2013-09-06 17:23   ` Pedro Alves
2013-09-06  2:03 ` [PATCH 3/3] Linux has memory protection Yao Qi
2013-09-06  5:57 ` [PATCH 0/3] Trust readonly sections if target " Eli Zaretskii
2013-09-06  8:24   ` Yao Qi
2013-09-06  8:45     ` Eli Zaretskii
2013-09-06 13:03       ` Joel Brobecker
2013-09-06 13:27         ` Yao Qi
2013-09-06 13:32         ` Eli Zaretskii
2013-09-06 14:17           ` Pierre Muller
     [not found]           ` <"000d01ceab0b$d53ae600$7fb0b200$@muller"@ics-cnrs.unistra.fr>
2013-09-06 14:38             ` Eli Zaretskii
2013-09-06 14:52           ` Joel Brobecker
2013-09-06 15:56             ` Eli Zaretskii
2013-09-06 18:10               ` Joel Brobecker
2013-09-06 18:36                 ` Eli Zaretskii
2013-09-06 13:00 ` Joel Brobecker
2013-09-08 12:04 ` [PATCH 0/7 V2] " Yao Qi
2013-09-08 12:04   ` [PATCH 1/7] Emit a warning when writing to a readonly section and trust_readonly is true Yao Qi
2013-09-08 15:10     ` Eli Zaretskii
2013-09-08 12:05   ` [PATCH 5/7] DOC and NEWS Yao Qi
2013-09-08 12:05   ` [PATCH 6/7] Linux has memory protection Yao Qi
2013-09-08 12:05   ` [PATCH 3/7] New function windows_init_abi Yao Qi
2013-09-08 12:05   ` [PATCH 4/7] Trust readonly sections if target has memory protection Yao Qi
2013-09-08 15:13     ` Eli Zaretskii
2013-09-09  7:49       ` Yao Qi
2013-09-09 16:25         ` Eli Zaretskii
2013-09-08 12:05   ` [PATCH 7/7] Windows " Yao Qi
2013-09-08 12:05   ` [PATCH 2/7] set trust-readonly-sections off in test cases Yao Qi
2013-09-09 19:16   ` [PATCH 0/7 V2] Trust readonly sections if target has memory protection Mark Kettenis
2013-09-10  4:06     ` Yao Qi
2013-09-12  8:30       ` Yao Qi
2013-09-12  9:49         ` Mark Kettenis
2013-09-13  8:17           ` Yao Qi
2013-09-30 17:50             ` Pedro Alves
2013-09-30 18:08               ` Pedro Alves
2013-10-07 22:29                 ` Stan Shebs
2013-10-08 12:18                   ` Pedro Alves
2013-10-08 12:47                     ` Abid, Hafiz
2013-10-08 13:36                       ` tmirza
2013-10-09  2:24               ` Doug Evans
2013-10-23 10:16                 ` Yao Qi
2013-10-15  0:44               ` Yao Qi
2013-09-20  2:47   ` [PATCH 0/7 V3] " Yao Qi
2013-09-20  2:47     ` [PATCH 7/7] Windows " Yao Qi
2013-09-20  2:47     ` [PATCH 1/7] Emit a query when writing to a readonly section and trust_readonly is true Yao Qi
2013-09-20  2:47     ` [PATCH 4/7] Trust readonly sections if target has memory protection and in remote debugging Yao Qi
2013-09-20  2:47     ` [PATCH 5/7] DOC and NEWS Yao Qi
2013-09-20  8:21       ` Eli Zaretskii
2013-09-20  2:47     ` [PATCH 2/7] set trust-readonly-sections off in test cases Yao Qi
2013-09-20  2:47     ` [PATCH 6/7] Linux has memory protection Yao Qi
2013-09-20  2:47     ` [PATCH 3/7] New function windows_init_abi Yao Qi
2013-09-30 18:23       ` Pedro Alves
2013-10-01  6:47         ` Yao Qi
2013-10-01  9:35           ` Pedro Alves
2013-10-01 13:23             ` Yao Qi
2013-09-29 13:51     ` [PATCH 0/7 V3] Trust readonly sections if target has memory protection Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1378432920-7731-3-git-send-email-yao@codesourcery.com \
    --to=yao@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox