aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorShahab Vahedi <shahab@synopsys.com>2020-02-06 16:20:37 +0100
committerShahab Vahedi <shahab@synopsys.com>2020-02-06 17:54:59 +0100
commit1d5d29e73f4b5f1af4df5b6e39ccf2fa722acead (patch)
treedd6a33aef30b025d59e9acc7cddcf8ca7dad9ba1 /gdb/tui
parentb0999b9b4574371f4b7682d0ccf5f7dbf1702262 (diff)
downloadgdb-1d5d29e73f4b5f1af4df5b6e39ccf2fa722acead.zip
gdb-1d5d29e73f4b5f1af4df5b6e39ccf2fa722acead.tar.gz
gdb-1d5d29e73f4b5f1af4df5b6e39ccf2fa722acead.tar.bz2
gdb: Catch exceptions if the source file is not found
The source_cache::ensure method may throw an exception through the invocation of source_cache::get_plain_source_lines. This happens when the source file is not found. The expected behaviour of "ensure" is only returning "true" or "false" according to the documentation in the header file. So far, if gdb is in source layout and a file is missing, you see some outputs like below: ,---------------------------------------------. | test.c file is loaded in the source window. | | | | int main() | | ... | |---------------------------------------------| | Remote debugging using :1234 | | __start () at /path/to/crt0.S:141 | | /path/to/crt0.S: No such file or directory. | | (gdb) p/x $pc | | $1 = 0x124 | | (gdb) n | | /path/to/crt0.S: No such file or directory. | | (gdb) p/x $pc | | $2 = 0x128 | | (gdb) [pressing arrow-down key] | | (gdb) terminate called after throwing an | | instance of 'gdb_exception_error' | `---------------------------------------------' Other issues have been encountered as well [1]. The patch from Pedro [2] which is about preventing exceptions from crossing the "readline" mitigates the situation by not causing gdb crash, but still there are lots of errors printed: ,---------------------------------------------. | test.c file is loaded in the source window. | | | | int main() | | ... | |---------------------------------------------| | Remote debugging using :1234 | | __start () at /path/to/crt0.S:141 | | /path/to/crt0.S: No such file or directory. | | (gdb) [pressing arrow-down key] | | /path/to/crt0.S: No such file or directory. | | (gdb) [pressing arrow-down key] | | /path/to/crt0.S: No such file or directory. | | (gdb) [pressing arrow-up key] | | /path/to/crt0.S: No such file or directory. | `---------------------------------------------' With the changes of this patch, the behavior is like: ,---------------------------------------------. | initially, source window is empty because | | crt0.S is not found and according to the | | program counter that is the piece of code | | being executed. | | | | later, when we break at main (see commands | | below), this window will be filled with the | | the contents of test.c file. | |---------------------------------------------| | Remote debugging using :1234 | | __start () at /path/to/crt0.S:141 | | (gdb) p/x $pc | | $1 = 0x124 | | (gdb) n | | (gdb) p/x $pc | | $2 = 0x128 | | (gdb) b main | | Breakpoint 1 at 0x334: file test.c, line 8. | | (gdb) cont | | Continuing. | | Breakpoint 1, main () at hello.c:8 | | (gdb) n | | (gdb) | `---------------------------------------------' There is no crash and the error message is completely gone. Maybe it is good practice that the error is shown inside the source window. I tested this change against gdb.base/list-missing-source.exp and there was no regression. [1] It has also been observed in the past that the register values are not transferred from qemu's gdb stub, see: https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/issues/226 [2] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=2f267673f0fdee9287e6d404ecd4f2d29da0d2f2 gdb/ChangeLog: * source-cache.c (source_cache::ensure): Surround get_plain_source_lines with a try/catch. (source_cache::get_line_charpos): Get rid of try/catch and only check for the return value of "ensure". * tui/tui-source.c (tui_source_window::set_contents): Simplify "nlines" calculation. gdb/testsuite/ChangeLog: * gdb.tui/tui-missing-src.exp: Add the "missing source file" test for the TUI.
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-source.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 912eaa4..3c7a8e1 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -55,7 +55,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
line_width = width - TUI_EXECINFO_SIZE - 1;
/* Take hilite (window border) into account, when
calculating the number of lines. */
- nlines = (line_no + (height - 2)) - line_no;
+ nlines = height - 2;
std::string srclines;
const std::vector<off_t> *offsets;