Suppress printing of superfluous BFD error messages
This commit adds a hook to the BFD error handler for suppressing
identical messages which have been output once already.
It's motivated by this Fedora bug...
https://bugzilla.redhat.com/show_bug.cgi?id=
2083315
...in which over 900,000 BFD error messages are output when attaching
to firefox. From the bug report, the messages all say:
BFD: /usr/lib/debug/usr/lib64/firefox/libxul.so-100.0-2.fc35.x86_64.debug: attempt to load strings from a non-string section (number 38)
Since there's no (additional) context which might assist the user in
determining what's wrong, there's really no point in outputting more
than one message. Of course, if BFD should output some
other/different message, it should be output too, but all future
messages identical to those already output should be suppressed.
For the firefox problem, it turned out that there were only 37
sections, but something was referring to section #38. I haven't
investigated further to find out how this came to be.
Despite this problem, useful debugging might still be done, especially
if the user doesn't care about debugging the problematic library.
If it turns out that knowing the quantity of messages might be useful,
I've implemented the suppression mechanism by keeping a count of each
identical message. A new GDB command, perhaps a 'maintenance'
command, could be added to print out each message along with the
count. I haven't implemented this though because I'm not convinced of
its utility. Also, the BFD message printer has support for BFD-
specific format specifiers. The BFD message strings that GDB stores
in its map are sufficient for distinguishing messages from each
other, but are not identical to those output by BFD's default error
handler. So, that problem would need to be solved too.