aboutsummaryrefslogtreecommitdiff
path: root/gdb/source-cache.c
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2019-09-08 00:05:22 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2019-09-17 15:53:32 -0400
commit67f3ed6afef86d08ef9989cc251eac585e9ef9cf (patch)
treeb4a93b3ab7485c8f1dbf8b426463f9056502cbf6 /gdb/source-cache.c
parent743321899674e03cf572fcfeb6c7705aded7c9a5 (diff)
downloadgdb-67f3ed6afef86d08ef9989cc251eac585e9ef9cf.zip
gdb-67f3ed6afef86d08ef9989cc251eac585e9ef9cf.tar.gz
gdb-67f3ed6afef86d08ef9989cc251eac585e9ef9cf.tar.bz2
gdb: Catch exceptions when accessing source cache
The source_cache::get_line_charpos function can currently throw an exception if the source file is missing, which doesn't match the expected behaviour documented in the functions header file. The documented behaviour is to return false on failure, and this is how the function appears to be used throughout GDB. I spotted this in the 'info source' command, currently for a missing source file you'll see something like this: (gdb) info source Current source file is /path/to/src/file.c Compilation directory is /path/to/build/ /path/to/src/file.c: No such file or directory. (gdb) After this patch we see this: (gdb) info source Current source file is /path/to/src/file.c Compilation directory is /path/to/build/ Source language is c. Producer is COMPILER VERSION AND FLAGS. Compiled with DWARF 2 debugging format. Does not include preprocessor macro info. We don't currently indicate that the source file can't be found, and maybe that would be something worth adding in the future. gdb/ChangeLog: * source-cache.c (source_cache::get_line_charpos): Catch exceptions and return false, this matches the behaviour documented in the header file. gdb/testsuite/ChangeLog: * gdb.base/list-missing-source.exp: New file.
Diffstat (limited to 'gdb/source-cache.c')
-rw-r--r--gdb/source-cache.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 18e2be9..7a52ce9 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -231,19 +231,26 @@ bool
source_cache::get_line_charpos (struct symtab *s,
const std::vector<off_t> **offsets)
{
- std::string fullname = symtab_to_fullname (s);
+ try
+ {
+ std::string fullname = symtab_to_fullname (s);
+
+ auto iter = m_offset_cache.find (fullname);
+ if (iter == m_offset_cache.end ())
+ {
+ ensure (s);
+ iter = m_offset_cache.find (fullname);
+ /* cache_source_text ensured this was entered. */
+ gdb_assert (iter != m_offset_cache.end ());
+ }
- auto iter = m_offset_cache.find (fullname);
- if (iter == m_offset_cache.end ())
+ *offsets = &iter->second;
+ return true;
+ }
+ catch (const gdb_exception_error &e)
{
- ensure (s);
- iter = m_offset_cache.find (fullname);
- /* cache_source_text ensured this was entered. */
- gdb_assert (iter != m_offset_cache.end ());
+ return false;
}
-
- *offsets = &iter->second;
- return true;
}
/* A helper function that extracts the desired source lines from TEXT,