This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 1/7] Emit a warning when writing to a readonly section and trust_readonly is true
- From: Yao Qi <yao at codesourcery dot com>
- To: <gdb-patches at sourceware dot org>
- Date: Sun, 8 Sep 2013 20:03:21 +0800
- Subject: [PATCH 1/7] Emit a warning when writing to a readonly section and trust_readonly is true
- Authentication-results: sourceware.org; auth=none
- References: <1378432920-7731-1-git-send-email-yao at codesourcery dot com> <1378641807-24256-1-git-send-email-yao at codesourcery dot com>
If users write a readonly section, such as .text, the contents of the inferior
and of the executable become out of sync. It is better to emit a warning
to ask users to "set trust-readonly-sections off".
(gdb) set trust-readonly-sections on
(gdb) p /x* (char *) 0x080484c1 = 0xcc
warning: Writing to a readonly section so that the contents in the
inferior and in the executable are out of sync. Please 'set
trust-readonly-sections off'.
$1 = 0xcc
gdb:
2013-09-08 Yao Qi <yao@codesourcery.com>
* target.c (memory_xfer_partial_1): Emit a warning if GDB
writes to a readonly section and 'trust_readonly' is true.
---
gdb/target.c | 31 ++++++++++++++++++++++---------
1 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/gdb/target.c b/gdb/target.c
index d55712d..f6a58ff 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1471,11 +1471,13 @@ 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 "trust-readonly-sections" is set, read from the executable
+ 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)
{
struct target_section *secp;
- struct target_section_table *table;
secp = target_section_by_addr (ops, memaddr);
if (secp != NULL
@@ -1483,12 +1485,23 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
secp->the_bfd_section)
& SEC_READONLY))
{
- table = target_get_section_table (ops);
- return section_table_xfer_memory_partial (readbuf, writebuf,
- memaddr, len,
- table->sections,
- table->sections_end,
- NULL);
+
+ if (readbuf != NULL)
+ {
+ struct target_section_table *table;
+
+ table = target_get_section_table (ops);
+ return section_table_xfer_memory_partial (readbuf, writebuf,
+ memaddr, len,
+ table->sections,
+ table->sections_end,
+ NULL);
+ }
+
+ if (writebuf != NULL)
+ warning (_("Writing to a readonly section so that the contents"
+ " in the inferior and in the executable are out of"
+ " sync. Please 'set trust-readonly-sections off'."));
}
}
--
1.7.7.6