This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/3] Trust readonly sections if target has memory protection


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]