binutils-gdb/gdb/complaints.c

87 lines
2.3 KiB
C
Raw Normal View History

/* Support for complaint handling during symbol reading in GDB.
Copyright (C) 1990-2018 Free Software Foundation, Inc.
1999-07-07 22:19:36 +02:00
This file is part of GDB.
1999-07-07 22:19:36 +02:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
1999-07-07 22:19:36 +02:00
(at your option) any later version.
1999-07-07 22:19:36 +02:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
1999-07-07 22:19:36 +02:00
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "complaints.h"
#include "command.h"
#include "gdbcmd.h"
#include <unordered_map>
/* Map format strings to counters. */
static std::unordered_map<const char *, int> counters;
/* How many complaints about a particular thing should be printed
before we stop whining about it? Default is no whining at all,
since so many systems have ill-constructed symbol files. */
Avoid expensive complaint calls when complaints are disabled Running perf on "gdb -nx -readnow -batch gdb", I'm seeing a lot of time (24%.75!) spent in gettext, via complaints. 'perf report -g' shows: - 86.23% 0.00% gdb gdb [.] gdb_main - gdb_main - 85.60% catch_command_errors symbol_file_add_main_adapter symbol_file_add_main symbol_file_add_main_1 symbol_file_add - symbol_file_add_with_addrs - 84.31% dw2_expand_all_symtabs - dw2_instantiate_symtab - 83.79% dw2_do_instantiate_symtab - 70.85% process_die - 41.11% dwarf_decode_macros - 41.09% dwarf_decode_macro_bytes - 39.74% dwarf_decode_macro_bytes >>>>>>>>>>>>>>>>>>>>>>> + 24.75% __dcigettext <<<<<<< + 7.37% macro_define_object_internal + 3.16% macro_define_function 0.77% splay_tree_insert + 0.76% savestring + 0.58% free 0.53% read_indirect_string_at_offset_from 0.54% macro_define_object_internal 0.51% macro_start_file + 25.57% process_die + 4.07% dwarf_decode_lines + 4.28% compute_delayed_physnames + 3.85% end_symtab_from_static_block + 3.38% load_cu + 1.29% end_symtab_get_static_block + 0.52% do_my_cleanups + 1.29% read_symbols + 0.54% gdb_init The problem is that we're always computing the arguments to pass to complaint, including passing the format strings through gettext, even when complaints are disabled. As seen above, gettext can be quite expensive. Fix this by wrapping complaint in a macro that skips the real complaint call when complaints are disabled. This improves "gdb -nx -readnow -batch gdb" from ~11.0s => ~7.8s with -O2 -g3, and ~6.0s => ~5.3s with -O2 -g. w/ gcc 5.3.1, on x86_64, for me. gdb/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * complaints.c (stop_whining): Make extern. (complaint): Rename to ... (complaint_internal): ... this. * complaints.h (complaint): Rename to ... (complaint_internal): ... this. (complaint): Reimplement as macro around complaint_internal. gdb/testsuite/ChangeLog: 2017-11-08 Pedro Alves <palves@redhat.com> * gdb.gdb/complaints.exp (test_initial_complaints) (test_serial_complaints, test_short_complaints): Call complaint_internal instead of complaint.
2017-11-09 00:42:11 +01:00
int stop_whining = 0;
/* See complaints.h. */
void
complaint_internal (const char *fmt, ...)
{
va_list args;
if (++counters[fmt] > stop_whining)
return;
va_start (args, fmt);
if (deprecated_warning_hook)
(*deprecated_warning_hook) (fmt, args);
else
{
Simplify complaints even more This removes the SHORT_FIRST_MESSAGE case from complaints, leaving only a single case. This allows for the removal of the last argument to clear_complaints, and also simplifies complaint_internal, removing an extra allocation in the process. After this, the "./gdb -iex 'set complaint 1' -nx ./gdb" example will show: Reading symbols from ./gdb... During symbol reading: .debug_ranges entry has start address of zero [in module /home/tromey/gdb/build/gdb/gdb] During symbol reading: DW_AT_low_pc 0x0 is zero for DIE at 0x17116c1 [in module /home/tromey/gdb/build/gdb/gdb] During symbol reading: .debug_line address at offset 0xa22f5 is 0 [in module /home/tromey/gdb/build/gdb/gdb] During symbol reading: unsupported tag: 'DW_TAG_unspecified_type' During symbol reading: const value length mismatch for 'std::ratio<1, 1000000000>::num', got 8, expected 0 This is a bit wordier but, I think, a bit more clear, as the form of the message no longer depends on precisely when it was emitted. In particular if you compare to the output from the 'Clean up "Reading symbols" output' patch, you can see that earlier gdb would switch from the prefix-less form to the "During symbol reading" form at a point that is meaningless to the user (specifically, after psymtab reading is done and gdb tries to expand a CU). 2018-10-04 Tom Tromey <tom@tromey.com> * symfile.c (syms_from_objfile_1, finish_new_objfile) (reread_symbols): Update. * complaints.h (clear_complaints): Remove argument. * complaints.c (enum complaint_series): Remove. (series): Remove global. (complaint_internal): Update. (clear_complaints): Remove argument. gdb/testsuite/ChangeLog 2018-10-04 Tom Tromey <tom@tromey.com> * gdb.cp/maint.exp (test_invalid_name): Update expected output. * gdb.gdb/complaints.exp (test_short_complaints): Remove. (test_initial_complaints, test_empty_complaints): Update. * gdb.dwarf2/dw2-stack-boundary.exp: Update.
2018-05-28 05:31:14 +02:00
fputs_filtered (_("During symbol reading: "), gdb_stderr);
vfprintf_filtered (gdb_stderr, fmt, args);
fputs_filtered ("\n", gdb_stderr);
}
va_end (args);
}
Simplify complaints even more This removes the SHORT_FIRST_MESSAGE case from complaints, leaving only a single case. This allows for the removal of the last argument to clear_complaints, and also simplifies complaint_internal, removing an extra allocation in the process. After this, the "./gdb -iex 'set complaint 1' -nx ./gdb" example will show: Reading symbols from ./gdb... During symbol reading: .debug_ranges entry has start address of zero [in module /home/tromey/gdb/build/gdb/gdb] During symbol reading: DW_AT_low_pc 0x0 is zero for DIE at 0x17116c1 [in module /home/tromey/gdb/build/gdb/gdb] During symbol reading: .debug_line address at offset 0xa22f5 is 0 [in module /home/tromey/gdb/build/gdb/gdb] During symbol reading: unsupported tag: 'DW_TAG_unspecified_type' During symbol reading: const value length mismatch for 'std::ratio<1, 1000000000>::num', got 8, expected 0 This is a bit wordier but, I think, a bit more clear, as the form of the message no longer depends on precisely when it was emitted. In particular if you compare to the output from the 'Clean up "Reading symbols" output' patch, you can see that earlier gdb would switch from the prefix-less form to the "During symbol reading" form at a point that is meaningless to the user (specifically, after psymtab reading is done and gdb tries to expand a CU). 2018-10-04 Tom Tromey <tom@tromey.com> * symfile.c (syms_from_objfile_1, finish_new_objfile) (reread_symbols): Update. * complaints.h (clear_complaints): Remove argument. * complaints.c (enum complaint_series): Remove. (series): Remove global. (complaint_internal): Update. (clear_complaints): Remove argument. gdb/testsuite/ChangeLog 2018-10-04 Tom Tromey <tom@tromey.com> * gdb.cp/maint.exp (test_invalid_name): Update expected output. * gdb.gdb/complaints.exp (test_short_complaints): Remove. (test_initial_complaints, test_empty_complaints): Update. * gdb.dwarf2/dw2-stack-boundary.exp: Update.
2018-05-28 05:31:14 +02:00
/* See complaints.h. */
void
Simplify complaints even more This removes the SHORT_FIRST_MESSAGE case from complaints, leaving only a single case. This allows for the removal of the last argument to clear_complaints, and also simplifies complaint_internal, removing an extra allocation in the process. After this, the "./gdb -iex 'set complaint 1' -nx ./gdb" example will show: Reading symbols from ./gdb... During symbol reading: .debug_ranges entry has start address of zero [in module /home/tromey/gdb/build/gdb/gdb] During symbol reading: DW_AT_low_pc 0x0 is zero for DIE at 0x17116c1 [in module /home/tromey/gdb/build/gdb/gdb] During symbol reading: .debug_line address at offset 0xa22f5 is 0 [in module /home/tromey/gdb/build/gdb/gdb] During symbol reading: unsupported tag: 'DW_TAG_unspecified_type' During symbol reading: const value length mismatch for 'std::ratio<1, 1000000000>::num', got 8, expected 0 This is a bit wordier but, I think, a bit more clear, as the form of the message no longer depends on precisely when it was emitted. In particular if you compare to the output from the 'Clean up "Reading symbols" output' patch, you can see that earlier gdb would switch from the prefix-less form to the "During symbol reading" form at a point that is meaningless to the user (specifically, after psymtab reading is done and gdb tries to expand a CU). 2018-10-04 Tom Tromey <tom@tromey.com> * symfile.c (syms_from_objfile_1, finish_new_objfile) (reread_symbols): Update. * complaints.h (clear_complaints): Remove argument. * complaints.c (enum complaint_series): Remove. (series): Remove global. (complaint_internal): Update. (clear_complaints): Remove argument. gdb/testsuite/ChangeLog 2018-10-04 Tom Tromey <tom@tromey.com> * gdb.cp/maint.exp (test_invalid_name): Update expected output. * gdb.gdb/complaints.exp (test_short_complaints): Remove. (test_initial_complaints, test_empty_complaints): Update. * gdb.dwarf2/dw2-stack-boundary.exp: Update.
2018-05-28 05:31:14 +02:00
clear_complaints ()
{
counters.clear ();
}
static void
2005-02-16 Andrew Cagney <cagney@gnu.org> Merge setshow print and show parameters. * command.h (show_value_ftype): Define. (deprecated_show_value_hack): Declare. (add_setshow_enum_cmd, add_setshow_auto_boolean_cmd) (add_setshow_boolean_cmd, add_setshow_filename_cmd) (add_setshow_string_cmd, add_setshow_uinteger_cmd) (add_setshow_zinteger_cmd): Change type of show_func to show_value_ftype. * cli/cli-decode.h (struct cmd_list_element): Replace fprint_setshow with show_value_func. * cli/cli-decode.c (add_setshow_cmd_full): Update show_func parameter. Set show_value_func. Do not set cmd_sfunc. (add_setshow_enum_cmd, add_setshow_auto_boolean_cmd) (add_setshow_boolean_cmd, add_setshow_filename_cmd) (add_setshow_string_cmd, add_setshow_uinteger_cmd) (add_setshow_zinteger_cmd): Update. * complaints.c (complaints_show_value): Replace fprint_setshow_complaints. (_initialize_complaints): Update. * mips-tdep.c (show_mask_address): Update. * arm-tdep.c (show_fp_model): Update. * cli/cli-setshow.c (do_setshow_command): Call show_value_func instead of fprint_setshow. Use deprecated_show_value_hack. (deprecated_show_value_hack): New function. * remote.c (add_packet_config_cmd, show_remote_cmd): (show_remote_protocol_P_packet_cmd) (show_remote_protocol_P_packet_cmd) (show_remote_protocol_Z_access_wp_packet_cmd) (show_remote_protocol_Z_hardware_bp_packet_cmd) (show_remote_protocol_Z_packet_cmd) (show_remote_protocol_Z_read_wp_packet_cmd) (show_remote_protocol_Z_software_bp_packet_cmd) (show_remote_protocol_Z_write_wp_packet_cmd) (show_remote_protocol_binary_download_cmd) (show_remote_protocol_p_packet_cmd) (show_remote_protocol_qPart_auxv_packet_cmd) (show_remote_protocol_qSymbol_packet_cmd) (show_remote_protocol_vcont_packet_cmd): Update.
2005-02-16 18:20:59 +01:00
complaints_show_value (struct ui_file *file, int from_tty,
struct cmd_list_element *cmd, const char *value)
{
fprintf_filtered (file, _("Max number of complaints about incorrect"
2005-02-16 Andrew Cagney <cagney@gnu.org> Merge setshow print and show parameters. * command.h (show_value_ftype): Define. (deprecated_show_value_hack): Declare. (add_setshow_enum_cmd, add_setshow_auto_boolean_cmd) (add_setshow_boolean_cmd, add_setshow_filename_cmd) (add_setshow_string_cmd, add_setshow_uinteger_cmd) (add_setshow_zinteger_cmd): Change type of show_func to show_value_ftype. * cli/cli-decode.h (struct cmd_list_element): Replace fprint_setshow with show_value_func. * cli/cli-decode.c (add_setshow_cmd_full): Update show_func parameter. Set show_value_func. Do not set cmd_sfunc. (add_setshow_enum_cmd, add_setshow_auto_boolean_cmd) (add_setshow_boolean_cmd, add_setshow_filename_cmd) (add_setshow_string_cmd, add_setshow_uinteger_cmd) (add_setshow_zinteger_cmd): Update. * complaints.c (complaints_show_value): Replace fprint_setshow_complaints. (_initialize_complaints): Update. * mips-tdep.c (show_mask_address): Update. * arm-tdep.c (show_fp_model): Update. * cli/cli-setshow.c (do_setshow_command): Call show_value_func instead of fprint_setshow. Use deprecated_show_value_hack. (deprecated_show_value_hack): New function. * remote.c (add_packet_config_cmd, show_remote_cmd): (show_remote_protocol_P_packet_cmd) (show_remote_protocol_P_packet_cmd) (show_remote_protocol_Z_access_wp_packet_cmd) (show_remote_protocol_Z_hardware_bp_packet_cmd) (show_remote_protocol_Z_packet_cmd) (show_remote_protocol_Z_read_wp_packet_cmd) (show_remote_protocol_Z_software_bp_packet_cmd) (show_remote_protocol_Z_write_wp_packet_cmd) (show_remote_protocol_binary_download_cmd) (show_remote_protocol_p_packet_cmd) (show_remote_protocol_qPart_auxv_packet_cmd) (show_remote_protocol_qSymbol_packet_cmd) (show_remote_protocol_vcont_packet_cmd): Update.
2005-02-16 18:20:59 +01:00
" symbols is %s.\n"),
value);
}
void
2000-07-30 03:48:28 +02:00
_initialize_complaints (void)
{
add_setshow_zinteger_cmd ("complaints", class_support,
&stop_whining, _("\
Set max number of complaints about incorrect symbols."), _("\
Show max number of complaints about incorrect symbols."), NULL,
2005-02-16 Andrew Cagney <cagney@gnu.org> Merge setshow print and show parameters. * command.h (show_value_ftype): Define. (deprecated_show_value_hack): Declare. (add_setshow_enum_cmd, add_setshow_auto_boolean_cmd) (add_setshow_boolean_cmd, add_setshow_filename_cmd) (add_setshow_string_cmd, add_setshow_uinteger_cmd) (add_setshow_zinteger_cmd): Change type of show_func to show_value_ftype. * cli/cli-decode.h (struct cmd_list_element): Replace fprint_setshow with show_value_func. * cli/cli-decode.c (add_setshow_cmd_full): Update show_func parameter. Set show_value_func. Do not set cmd_sfunc. (add_setshow_enum_cmd, add_setshow_auto_boolean_cmd) (add_setshow_boolean_cmd, add_setshow_filename_cmd) (add_setshow_string_cmd, add_setshow_uinteger_cmd) (add_setshow_zinteger_cmd): Update. * complaints.c (complaints_show_value): Replace fprint_setshow_complaints. (_initialize_complaints): Update. * mips-tdep.c (show_mask_address): Update. * arm-tdep.c (show_fp_model): Update. * cli/cli-setshow.c (do_setshow_command): Call show_value_func instead of fprint_setshow. Use deprecated_show_value_hack. (deprecated_show_value_hack): New function. * remote.c (add_packet_config_cmd, show_remote_cmd): (show_remote_protocol_P_packet_cmd) (show_remote_protocol_P_packet_cmd) (show_remote_protocol_Z_access_wp_packet_cmd) (show_remote_protocol_Z_hardware_bp_packet_cmd) (show_remote_protocol_Z_packet_cmd) (show_remote_protocol_Z_read_wp_packet_cmd) (show_remote_protocol_Z_software_bp_packet_cmd) (show_remote_protocol_Z_write_wp_packet_cmd) (show_remote_protocol_binary_download_cmd) (show_remote_protocol_p_packet_cmd) (show_remote_protocol_qPart_auxv_packet_cmd) (show_remote_protocol_qSymbol_packet_cmd) (show_remote_protocol_vcont_packet_cmd): Update.
2005-02-16 18:20:59 +01:00
NULL, complaints_show_value,
&setlist, &showlist);
}