diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-01-06 23:53:22 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-01-08 12:19:40 +0000 |
commit | ec98a4ad5bfcba33deb5cb786c023082adbbfb46 (patch) | |
tree | ec1e5af6779f35b0912adbc96df476f179c413c7 /gdb/source.c | |
parent | 62ea19c1000856c2633a952c52269fca4143931a (diff) | |
download | gdb-ec98a4ad5bfcba33deb5cb786c023082adbbfb46.zip gdb-ec98a4ad5bfcba33deb5cb786c023082adbbfb46.tar.gz gdb-ec98a4ad5bfcba33deb5cb786c023082adbbfb46.tar.bz2 |
gdb: Handle requests to print source lines backward
...by which I mean from high line number to low, not, actually
backward character by character!
Commit:
commit 62f29fda90cf1d5a1899f57ef78452471c707fd6
Date: Tue Oct 9 22:21:05 2018 -0600
Highlight source code using GNU Source Highlight
introduced a regression in the test gdb.linespec/explicit.exp, in
which a request is made to GDB to print a reverse sequence of lines,
from +10 to -10 from the current line number. The expected behaviour
is that GDB prints nothing. The above commit changed this so that GDB
now prints:
Line number 32 out of range; /path/to/gdb/testsuite/gdb.linespec/explicit.c has 71 lines.
which is a little confusing.
This commit fixes the regression, and restores the behaviour that GDB
prints nothing.
While I was passing I noticed a call to `back` on a std::string that I
was concerned could be empty if the request for source lines returns
an empty string. I don't know if it would be possible for a request
for lines to return an empty string, I guess it should be impossible,
in which case, maybe this should be an assertion, but adding a `empty`
check, seems like an easy and cheap safety net.
gdb/ChangeLog:
* source.c (print_source_lines_base): Handle requests to print
reverse line number sequences, and guard against empty lines
string.
Diffstat (limited to 'gdb/source.c')
-rw-r--r-- | gdb/source.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/gdb/source.c b/gdb/source.c index e77789c..71da396 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1346,6 +1346,16 @@ print_source_lines_base (struct symtab *s, int line, int stopline, last_source_error = 0; + /* If the user requested a sequence of lines that seems to go backward + (from high to low line numbers) then we don't print anything. + The use of '- 1' here instead of '<=' is currently critical, we rely + on the undefined wrap around behaviour of 'int' for stopline. When + the use has done: 'set listsize unlimited' then stopline can overflow + and appear as MIN_INT. This is a long-standing bug that needs + fixing. */ + if (stopline - 1 < line) + return; + std::string lines; if (!g_source_cache.get_source_lines (s, line, stopline - 1, &lines)) error (_("Line number %d out of range; %s has %d lines."), @@ -1392,7 +1402,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline, if (c == '\0') break; } - if (lines.back () != '\n') + if (!lines.empty() && lines.back () != '\n') uiout->text ("\n"); } |