binutils-gdb/gdb/dwarf2
Andrew Burgess 5c5e642dc0 gdb: improve error reporting for 'save gdb-index'
While making recent changes to 'save gdb-index' command I triggered
some errors -- of the kind a user might be expected to trigger if they
do something wrong -- and I didn't find GDB's output as helpful as it
might be.

For example:

  $ gdb -q /tmp/hello.x
  ...
  (gdb) save gdb-index /non_existing_dir
  Error while writing index for `/tmp/hello': mkstemp: No such file or directory.

That the error message mentions '/tmp/hello', which does exist, but
doesn't mention '/non_existing_dir', which doesn't is, I think,
confusing.

Also, I find the 'mkstemp' in the error message confusing for a user
facing error.  A user might not know what mkstemp means, and even if
they do, that it appears in the error message is an internal GDB
detail.  The user doesn't care what function failed, but wants to know
what was wrong with their input, and what they should do to fix
things.

Similarly, for a directory that does exist, but can't be written to:

  (gdb) save gdb-index /no_access_dir
  Error while writing index for `/tmp/hello': mkstemp: Permission denied.

In this case, the 'Permission denied' might make the user thing there
is a permissions issue with '/tmp/hello', which is not the case.

After this patch, the new errors are:

  (gdb) save gdb-index /non_existing_dir
  Error while writing index for `/tmp/hello': `/non_existing_dir': No such file or directory.

and:

  (gdb) save gdb-index /no_access_dir
  Error while writing index for `/tmp/hello': `/no_access_dir': Permission denied.

we also have:

  (gdb) save gdb-index /tmp/not_a_directory
  Error while writing index for `/tmp/hello': `/tmp/not_a_directory': Is not a directory.

I think these do a better job of guiding the user towards fixing the
problem.

I've added a new test that exercises all of these cases, and also
checks the case where a user tries to use an executable that already
contains an index in order to generate an index.  As part of the new
test I've factored out some code from ensure_gdb_index (lib/gdb.exp)
into a new proc (get_index_type), which I've then used in the new
test.  I've confirmed that all the tests that use ensure_gdb_index
still pass.

During review it was pointed out that the testsuite proc
have_index (lib/gdb.exp) is similar to the new get_index_type proc, so
I've rewritten have_index to also use get_index_type, I've confirmed
that all the tests that use have_index still pass.

Nothing that worked correctly before this patch should give an error
after this patch; I've only changed the output when the user was going
to get an error anyway.

Reviewed-By: Tom de Vries <tdevries@suse.de>
Reviewed-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
2023-12-13 08:54:06 +00:00
..
abbrev-cache.c Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
abbrev-cache.h gdb: move call site types to call-site.h 2023-01-20 14:48:57 -05:00
abbrev.c [gdb/symtab] Add optimized out static var to cooked index 2023-07-21 08:25:25 +02:00
abbrev.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
ada-imported.c Handle Ada Pragma Import and Pragma Export 2023-05-12 13:25:28 -06:00
aranges.c Move read_addrmap_from_aranges to new file 2023-10-29 10:35:29 -06:00
aranges.h Move read_addrmap_from_aranges to new file 2023-10-29 10:35:29 -06:00
attribute.c Use unrelocated_addr in the DWARF reader 2023-06-05 09:59:18 -06:00
attribute.h gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
call-site.h Use unrelocated_addr in the DWARF reader 2023-06-05 09:59:18 -06:00
comp-unit-head.c Use unrelocated_addr in the DWARF reader 2023-06-05 09:59:18 -06:00
comp-unit-head.h Use unrelocated_addr in the DWARF reader 2023-06-05 09:59:18 -06:00
cooked-index.c Always use expand_symtabs_matching in ada-lang.c 2023-12-06 10:14:24 -07:00
cooked-index.h gdb: Use std::string_view instead of gdb::string_view 2023-11-21 11:52:36 +00:00
cu.c [gdb/symtab] Work around gas PR28629 2023-11-01 00:33:12 +01:00
cu.h gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
die.c Use unrelocated_addr in the DWARF reader 2023-06-05 09:59:18 -06:00
die.h gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
dwz.c Pre-read DWZ file in DWARF reader 2023-11-05 12:32:34 -07:00
dwz.h [gdb/symtab] Error out for .debug_types section in dwz file 2023-09-20 16:05:55 +02:00
expr.c Simplify case DW_OP_GNU_uninit in dwarf_expr_context::execute_stack_op 2023-06-12 16:02:40 -07:00
expr.h Change value::m_initialized to bool 2023-02-15 15:07:07 -07:00
file-and-dir.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
frame-tailcall.c Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
frame-tailcall.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
frame.c gdb: Use C++17's std::make_unique instead of gdb::make_unique 2023-11-21 11:52:35 +00:00
frame.h gdb: dwarf2 generic implementation for caching function data 2023-01-25 21:04:40 +01:00
index-cache.c [gdb/symtab] Fix data race on bfd::{cacheable,format} 2023-08-04 15:02:43 +02:00
index-cache.h gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
index-common.c gdb: Use std::string_view instead of gdb::string_view 2023-11-21 11:52:36 +00:00
index-common.h gdb: Use std::string_view instead of gdb::string_view 2023-11-21 11:52:36 +00:00
index-write.c gdb: improve error reporting for 'save gdb-index' 2023-12-13 08:54:06 +00:00
index-write.h Only use the per-BFD object to write a DWARF index 2023-02-24 11:46:53 -07:00
leb.c Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
leb.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
line-header.c gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
line-header.h [gdb] Fix typos 2023-06-03 22:43:57 +02:00
loc.c Use gdb::byte_vector in agent_expr 2023-06-20 11:00:19 -06:00
loc.h Use unrelocated_addr in the DWARF reader 2023-06-05 09:59:18 -06:00
macro.c Use C++17 [[fallthrough]] attribute 2023-11-29 14:29:43 -07:00
macro.h gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
mapped-index.h Write the DWARF index in the background 2023-02-24 11:46:53 -07:00
public.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
read-debug-names.c Remove quick_symbol_functions::expand_matching_symbols 2023-12-06 10:14:25 -07:00
read-debug-names.h gdb/dwarf2: split .debug_names reading code to own file 2023-02-15 15:12:06 -05:00
read-gdb-index.c Remove quick_symbol_functions::expand_matching_symbols 2023-12-06 10:14:25 -07:00
read-gdb-index.h gdb/dwarf2: split .gdb_index reading code to own file 2023-02-15 15:12:01 -05:00
read.c Remove quick_symbol_functions::expand_matching_symbols 2023-12-06 10:14:25 -07:00
read.h [gdb/symtab] Redo "Fix assert in set_length" 2023-12-06 10:29:17 +01:00
sect-names.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
section.c Rename bfd_bread and bfd_bwrite 2023-08-09 08:48:09 +09:30
section.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
stringify.c Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
stringify.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
tag.h Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
types.h gdb: update some copyright years (2022 -> 2023) 2023-03-01 20:54:56 -05:00