diff options
author | Andrew Burgess <aburgess@redhat.com> | 2023-09-24 12:37:40 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2023-10-05 12:21:46 +0100 |
commit | 3d38b301bb50f1822e9d07d2aacef1ebe1a97073 (patch) | |
tree | 95746bf7b46457396896ada812624039c830c04e /gdb/utils.c | |
parent | b09dba5a5fcf061bf93c1e5a5c9fd56928c6340c (diff) | |
download | gdb-3d38b301bb50f1822e9d07d2aacef1ebe1a97073.zip gdb-3d38b301bb50f1822e9d07d2aacef1ebe1a97073.tar.gz gdb-3d38b301bb50f1822e9d07d2aacef1ebe1a97073.tar.bz2 |
gdb: remove print_sys_errmsg
This started with me running into this comment in symfile.c:
/* FIXME, should use print_sys_errmsg but it's not filtered. */
gdb_printf (_("`%ps' has disappeared; keeping its symbols.\n"),
styled_string (file_name_style.style (), filename));
In this particular case I think I disagree with the comment; I think
the output should be a warning rather than just a message printed to
gdb_stdout, I think when the executable, or some other objfile that is
currently being debugged, disappears from disk, this is likely an
unexpected situation, and worth warning the user about.
So, in theory, I could just call print_sys_errmsg and remove the
comment, but that would mean loosing the filename styling in the
output... so in the end I remove the comment and updated the code to
call warning.
But that got me looking at print_sys_errmsg and how it's used.
Currently the function takes a string and an errno, and prints, to
stderr, the string followed by the result of calling strerror on the
errno.
In some places the string passed to print_sys_errmsg is just a
filename, and this is used when something goes wrong. In these cases,
I think calling warning rather than gdb_printf to gdb_stderr, would be
better, and in fact, in a couple of places we manually print a
"warning" prefix, and then call print_sys_errmsg. And so, for these
users I have added a new function warning_filename_and_errno, which
takes a filename, which is printed with styling, and an errno, which
is passed through strerror and the resulting string printed. This new
function calls warning to print its output. I then updated some of
the print_sys_errmsg users to use this new function.
Some other users of print_sys_errmsg are also emitting what is clearly
a warning, however, the string being passed in is more than just a
filename, so the new warning_filename_and_errno function can't be
used, it would style the whole string. For these users I have
switched to calling warning directly, this allows me to style the
warning message correctly.
Finally, in inflow.c there is one last call to print_sys_errmsg, in
this case I just inlined the definition of print_sys_errmsg. This is
a really weird case, as after printing this message GDB just does a
hard exit. This is pretty old code, dating back to the initial GDB
import, I guess it should be updated to call error() maybe, but I'm
reluctant to make this change as part of this commit, just in case
there's some reason why we can't throw an error at this point.
With that done there are now no users of print_sys_errmsg, and so the
old function can be removed.
While I was doing all of the above I added some additional filename
styling in soure.c, this is in an else block where the if contained
the print_sys_errmsg call, so these felt related.
And finally, while I was updating the uses of print_sys_errmsg in
procfs.c, I noticed that we used a static errmsg buffer to format some
error strings. As the above changes got rid of one of the users of
errmsg I also removed the other two users, and the static buffer.
There were a couple of tests that depended on the existing output
message format that needed updating. In one case we gained an extra
'warning: ' prefix, and in the other 'Warning: ' becomes 'warning: ',
I think in both cases the new output is an improvement.
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index 2f54533..a191d26 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -619,14 +619,13 @@ perror_warning_with_name (const char *string) warning (_("%s"), combined.c_str ()); } -/* Print the system error message for ERRCODE, and also mention STRING - as the file name for which the error was encountered. */ +/* See utils.h. */ void -print_sys_errmsg (const char *string, int errcode) +warning_filename_and_errno (const char *filename, int saved_errno) { - const char *err = safe_strerror (errcode); - gdb_printf (gdb_stderr, "%s: %s.\n", string, err); + warning (_("%ps: %s"), styled_string (file_name_style.style (), filename), + safe_strerror (saved_errno)); } /* Control C eventually causes this to be called, at a convenient time. */ |