aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2023-12-02 11:36:43 +0000
committerAndrew Burgess <aburgess@redhat.com>2023-12-13 08:54:06 +0000
commit5c5e642dc0f6b223c2339d8dee64fbc63eee8e1a (patch)
tree2219ab9fc23a0904a9d5d5f41d4fe721917ad6df /gdb/dwarf2
parentb70a487d5945b13e5ab503be4fc37b964819ec0e (diff)
downloadgdb-5c5e642dc0f6b223c2339d8dee64fbc63eee8e1a.zip
gdb-5c5e642dc0f6b223c2339d8dee64fbc63eee8e1a.tar.gz
gdb-5c5e642dc0f6b223c2339d8dee64fbc63eee8e1a.tar.bz2
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>
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r--gdb/dwarf2/index-write.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index b4a0117..842708a 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1569,6 +1569,13 @@ struct index_wip_file
index_wip_file (const char *dir, const char *basename,
const char *suffix)
{
+ /* Validate DIR is a valid directory. */
+ struct stat buf;
+ if (stat (dir, &buf) == -1)
+ perror_with_name (string_printf (_("`%s'"), dir).c_str ());
+ if ((buf.st_mode & S_IFDIR) != S_IFDIR)
+ error (_("`%s': Is not a directory."), dir);
+
filename = (std::string (dir) + SLASH_STRING + basename
+ suffix);
@@ -1577,7 +1584,8 @@ struct index_wip_file
scoped_fd out_file_fd = gdb_mkostemp_cloexec (filename_temp.data (),
O_BINARY);
if (out_file_fd.get () == -1)
- perror_with_name (("mkstemp"));
+ perror_with_name (string_printf (_("couldn't open `%s'"),
+ filename_temp.data ()).c_str ());
out_file = out_file_fd.to_file ("wb");