From 69d42e3d4b36f501a90a0da4e3fc6952ae9f126f Mon Sep 17 00:00:00 2001 From: Florian Krohm Date: Sat, 29 Nov 2014 14:41:32 +0000 Subject: [PATCH] Fix BZ 334802. Patch by Mark Wielaard with a few mods to make it apply. r14794 is related as well. Also: remove -Wno-format-zero-length from compile options. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14795 --- Makefile.all.am | 1 - NEWS | 1 + cachegrind/cg_arch.c | 2 +- callgrind/main.c | 1 - coregrind/m_gdbserver/remote-utils.c | 4 ++-- coregrind/m_libcprint.c | 8 ++++++++ coregrind/m_main.c | 9 +++++---- coregrind/pub_core_libcprint.h | 5 +++++ include/pub_tool_options.h | 9 ++++++--- massif/ms_main.c | 4 ++-- none/tests/cmdline4.stderr.exp | 2 +- 11 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Makefile.all.am b/Makefile.all.am index 68f8fe57e0..6257a20b70 100644 --- a/Makefile.all.am +++ b/Makefile.all.am @@ -105,7 +105,6 @@ AM_CFLAGS_BASE = \ -Wpointer-arith \ -Wstrict-prototypes \ -Wmissing-declarations \ - @FLAG_W_NO_FORMAT_ZERO_LENGTH@ \ @FLAG_W_NO_TAUTOLOGICAL_COMPARE@ \ -fno-strict-aliasing \ -fno-builtin diff --git a/NEWS b/NEWS index fc4b73b4d1..4841de464b 100644 --- a/NEWS +++ b/NEWS @@ -41,6 +41,7 @@ where XXXXXX is the bug number as listed below. 269360 s390x: Fix addressing mode selection for compare-and-swap 333051 mmap of huge pages fails due to incorrect alignment == 339163 +334802 valgrind does not always explain why a given option is bad 335440 arm64: ld1 (single structure) is not implemented 335713 arm64: unhanded instruction: prfm (immediate) 338731 ppc: Fix testuite build for toolchains not supporting -maltivec diff --git a/cachegrind/cg_arch.c b/cachegrind/cg_arch.c index 2afda87c4a..265044e236 100644 --- a/cachegrind/cg_arch.c +++ b/cachegrind/cg_arch.c @@ -105,7 +105,7 @@ static void parse_cache_opt ( cache_t* cache, const HChar* opt, return; bad: - VG_(fmsg_bad_option)(opt, ""); + VG_(fmsg_bad_option)(opt, "Bad argument '%s'\n", optval); overflow: VG_(fmsg_bad_option)(opt, diff --git a/callgrind/main.c b/callgrind/main.c index 158f02185f..740213123b 100644 --- a/callgrind/main.c +++ b/callgrind/main.c @@ -1860,7 +1860,6 @@ void clg_print_stats(void) CLG_(stat).bb_retranslations); VG_(message)(Vg_DebugMsg, "Distinct instrs: %d\n", CLG_(stat).distinct_instrs); - VG_(message)(Vg_DebugMsg, ""); VG_(message)(Vg_DebugMsg, "LRU Contxt Misses: %d\n", CLG_(stat).cxt_lru_misses); diff --git a/coregrind/m_gdbserver/remote-utils.c b/coregrind/m_gdbserver/remote-utils.c index 56c8617fbd..1cdb49179b 100644 --- a/coregrind/m_gdbserver/remote-utils.c +++ b/coregrind/m_gdbserver/remote-utils.c @@ -395,7 +395,7 @@ void remote_open (const HChar *name) o = VG_(open) (shared_mem, VKI_O_CREAT|VKI_O_RDWR, 0600); if (sr_isError (o)) { sr_perror(o, "cannot create shared_mem file %s\n", shared_mem); - fatal(""); + fatal("Cannot recover from previous error. Good-bye."); } else { shared_mem_fd = sr_Res(o); } @@ -412,7 +412,7 @@ void remote_open (const HChar *name) if (sr_isError(res)) { sr_perror(res, "error VG_(am_shared_mmap_file_float_valgrind) %s\n", shared_mem); - fatal(""); + fatal("Cannot recover from previous error. Good-bye."); } addr_shared = sr_Res (res); } diff --git a/coregrind/m_libcprint.c b/coregrind/m_libcprint.c index 13258568b5..3617c039a8 100644 --- a/coregrind/m_libcprint.c +++ b/coregrind/m_libcprint.c @@ -636,6 +636,14 @@ void VG_(fmsg_bad_option) ( const HChar* opt, const HChar* format, ... ) VG_(exit)(1); } +void VG_(fmsg_unknown_option) ( const HChar* opt) +{ + revert_to_stderr(); + VG_(message) (Vg_FailMsg, "Unknown option: %s\n", opt); + VG_(message) (Vg_FailMsg, "Use --help for more information or consult the user manual.\n"); + VG_(exit)(1); +} + UInt VG_(umsg) ( const HChar* format, ... ) { UInt count; diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 2a0b2a6778..2b2ac79b50 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -624,8 +624,8 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd, else if (VG_(strcmp)(tmp_str, "no") == 0) VG_(clo_fair_sched) = disable_fair_sched; else - VG_(fmsg_bad_option)(arg, ""); - + VG_(fmsg_bad_option)(arg, + "Bad argument, should be 'yes', 'try' or 'no'\n"); } else if VG_BOOL_CLO(arg, "--trace-sched", VG_(clo_trace_sched)) {} else if VG_BOOL_CLO(arg, "--trace-signals", VG_(clo_trace_signals)) {} @@ -845,7 +845,7 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd, else if ( ! VG_(needs).command_line_options || ! VG_TDICT_CALL(tool_process_cmd_line_option, arg) ) { - VG_(fmsg_bad_option)(arg, ""); + VG_(fmsg_unknown_option)(arg); } } @@ -961,7 +961,8 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd, chaos. No big deal; dump_error is a flag for debugging V itself. */ if (VG_(clo_dump_error) > 0) { - VG_(fmsg_bad_option)("--xml=yes together with --dump-error", ""); + VG_(fmsg_bad_option)("--xml=yes", + "Cannot be used together with --dump-error"); } /* Disable error limits (this might be a bad idea!) */ diff --git a/coregrind/pub_core_libcprint.h b/coregrind/pub_core_libcprint.h index c9adb0b24f..aedd915bb7 100644 --- a/coregrind/pub_core_libcprint.h +++ b/coregrind/pub_core_libcprint.h @@ -66,6 +66,11 @@ extern void VG_(err_missing_prog) ( void ); __attribute__((noreturn)) extern void VG_(err_config_error) ( const HChar* format, ... ); +/* Called by main_process_cmd_line_options to indicate an unrecognised + command line option. */ +__attribute__((noreturn)) +extern void VG_(fmsg_unknown_option) ( const HChar *opt ); + #endif // __PUB_CORE_LIBCPRINT_H /*--------------------------------------------------------------------*/ diff --git a/include/pub_tool_options.h b/include/pub_tool_options.h index cb34639b8d..c9f8559855 100644 --- a/include/pub_tool_options.h +++ b/include/pub_tool_options.h @@ -105,7 +105,8 @@ Long n = VG_(strtoll10)( val, &s ); \ (qq_var) = n; \ /* Check for non-numeralness, or overflow. */ \ - if ('\0' != s[0] || (qq_var) != n) VG_(fmsg_bad_option)(qq_arg, ""); \ + if ('\0' != s[0] || (qq_var) != n) VG_(fmsg_bad_option)(qq_arg, \ + "Invalid integer value '%s'\n", val); \ True; \ }) \ ) @@ -123,7 +124,8 @@ /* for all the other macros in this file. */ \ /* Check for non-numeralness, or overflow. */ \ /* Nb: it will overflow if qq_var is unsigned and qq_val is negative! */ \ - if ('\0' != s[0] || (qq_var) != n) VG_(fmsg_bad_option)(qq_arg, ""); \ + if ('\0' != s[0] || (qq_var) != n) VG_(fmsg_bad_option)(qq_arg, \ + "Invalid integer value '%s'\n", val); \ /* Check bounds. */ \ if ((qq_var) < (qq_lo) || (qq_var) > (qq_hi)) { \ VG_(fmsg_bad_option)(qq_arg, \ @@ -153,7 +155,8 @@ double n = VG_(strtod)( val, &s ); \ (qq_var) = n; \ /* Check for non-numeralness */ \ - if ('\0' != s[0]) VG_(fmsg_bad_option)(qq_arg, ""); \ + if ('\0' != s[0]) VG_(fmsg_bad_option)(qq_arg, \ + "Invalid floating point value '%s'\n",val); \ True; \ }) \ ) diff --git a/massif/ms_main.c b/massif/ms_main.c index 7d11631d3b..450379dd15 100644 --- a/massif/ms_main.c +++ b/massif/ms_main.c @@ -2447,8 +2447,8 @@ static void ms_post_clo_init(void) // Check options. if (clo_pages_as_heap) { if (clo_stacks) { - VG_(fmsg_bad_option)( - "--pages-as-heap=yes together with --stacks=yes", ""); + VG_(fmsg_bad_option)("--pages-as-heap=yes", + "Cannot be used together with --stacks=yes"); } } if (!clo_heap) { diff --git a/none/tests/cmdline4.stderr.exp b/none/tests/cmdline4.stderr.exp index f9b9ba6585..879e12a28c 100644 --- a/none/tests/cmdline4.stderr.exp +++ b/none/tests/cmdline4.stderr.exp @@ -1,2 +1,2 @@ -valgrind: Bad option: --bad-bad-option +valgrind: Unknown option: --bad-bad-option valgrind: Use --help for more information or consult the user manual. -- 2.47.2