aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2021-02-19 17:39:18 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2021-02-24 16:58:05 +0000
commitdd80d75040a291400c0fddb0f8b05c3f40da49ff (patch)
tree64425fc2d5a9a68a32b9da4ded3e3795c496b6fd /gdb
parent336aa7b740c64070ae14d2364edddb7df7bce011 (diff)
downloadbinutils-dd80d75040a291400c0fddb0f8b05c3f40da49ff.zip
binutils-dd80d75040a291400c0fddb0f8b05c3f40da49ff.tar.gz
binutils-dd80d75040a291400c0fddb0f8b05c3f40da49ff.tar.bz2
gdb: use std::string instead of a fixed size buffer
The 'section' command uses a fixed size buffer into which a section name is copied. This commit replaces this with a use of std::string so we can now display very long section names. The expected results of one test need to be updated. gdb/ChangeLog: * exec.c (set_section_command): Move variable declarations into the function body, and use std::string instead of a fixed size buffer. gdb/testsuite/ChangeLog: * gdb.base/sect-cmd.exp: Update expected results.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/exec.c18
-rw-r--r--gdb/testsuite/ChangeLog4
-rw-r--r--gdb/testsuite/gdb.base/sect-cmd.exp14
4 files changed, 24 insertions, 18 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f50d89f..00a71fe 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com>
+ * exec.c (set_section_command): Move variable declarations into
+ the function body, and use std::string instead of a fixed size
+ buffer.
+
+2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com>
+
* exec.c (exec_target::get_section_table): Delete member function.
(section_table_read_available_memory): Use current_top_target, not
just the exec_ops target.
diff --git a/gdb/exec.c b/gdb/exec.c
index 8e3c19e..544a058 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -989,27 +989,23 @@ static void
set_section_command (const char *args, int from_tty)
{
const char *secname;
- unsigned seclen;
- unsigned long secaddr;
- char secprint[100];
- long offset;
if (args == 0)
error (_("Must specify section name and its virtual address"));
/* Parse out section name. */
for (secname = args; !isspace (*args); args++);
- seclen = args - secname;
+ unsigned seclen = args - secname;
/* Parse out new virtual address. */
- secaddr = parse_and_eval_address (args);
+ CORE_ADDR secaddr = parse_and_eval_address (args);
for (target_section &p : current_program_space->target_sections ())
{
if (!strncmp (secname, bfd_section_name (p.the_bfd_section), seclen)
&& bfd_section_name (p.the_bfd_section)[seclen] == '\0')
{
- offset = secaddr - p.addr;
+ long offset = secaddr - p.addr;
p.addr += offset;
p.endaddr += offset;
if (from_tty)
@@ -1017,11 +1013,9 @@ set_section_command (const char *args, int from_tty)
return;
}
}
- if (seclen >= sizeof (secprint))
- seclen = sizeof (secprint) - 1;
- strncpy (secprint, secname, seclen);
- secprint[seclen] = '\0';
- error (_("Section %s not found"), secprint);
+
+ std::string secprint (secname, seclen);
+ error (_("Section %s not found"), secprint.c_str ());
}
/* If we can find a section in FILENAME with BFD index INDEX, adjust
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 109ede3..922ba8c 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com>
+ * gdb.base/sect-cmd.exp: Update expected results.
+
+2021-02-24 Andrew Burgess <andrew.burgess@embecosm.com>
+
* gdb.base/sect-cmd.exp: Rewrite using modern testsuite
techniques. Enable the test for all targets.
diff --git a/gdb/testsuite/gdb.base/sect-cmd.exp b/gdb/testsuite/gdb.base/sect-cmd.exp
index e42f46d..7aa24ca 100644
--- a/gdb/testsuite/gdb.base/sect-cmd.exp
+++ b/gdb/testsuite/gdb.base/sect-cmd.exp
@@ -79,14 +79,16 @@ gdb_test_multiple "section FOOBARBAZ 0x1234" "" {
}
}
-# We "happen to know" that GDB uses a fixed size character buffer to
-# parse the section name into, and the buffer is declared to be 100
-# characters in length. Verify that GDB gracefully handles section
-# names longer than that. (The section is also non-existent.)
+# Check that GDB can still print the error message when the section
+# name is very long. It used to be the case that GDB could only print
+# (up to) 100 character section names in this error message, but that
+# is no longer the case.
#
-gdb_test_multiple "section A234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123 0x1234" \
+set long_sect_name \
+ "A234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123"
+gdb_test_multiple "section $long_sect_name 0x1234" \
"non-existent too-long section disallowed" {
- -re -wrap "Section A23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 not found" {
+ -re -wrap "Section $long_sect_name not found" {
pass $gdb_test_name
}
}