|
From: <sv...@va...> - 2009-08-22 22:51:02
|
Author: njn
Date: 2009-08-22 23:50:40 +0100 (Sat, 22 Aug 2009)
New Revision: 10858
Log:
Modify some messaging infrastructure. Start some conversions to the new
infrastructure.
Fix an option printing problem in Cachegrind, and (ironically) a bad call to
VG_(printf_xml_no_f_c) in m_main.c.
Note that there's some temporary behaviour in here that will change
eventually.
Modified:
branches/MSG2/cachegrind/cg_main.c
branches/MSG2/coregrind/m_libcprint.c
branches/MSG2/coregrind/m_main.c
branches/MSG2/coregrind/m_options.c
branches/MSG2/coregrind/m_signals.c
branches/MSG2/coregrind/m_ume/main.c
branches/MSG2/include/pub_tool_libcprint.h
branches/MSG2/tests/filter_stderr_basic
Modified: branches/MSG2/cachegrind/cg_main.c
===================================================================
--- branches/MSG2/cachegrind/cg_main.c 2009-08-22 05:10:48 UTC (rev 10857)
+++ branches/MSG2/cachegrind/cg_main.c 2009-08-22 22:50:40 UTC (rev 10858)
@@ -1655,13 +1655,13 @@
/*--- Command line processing ---*/
/*--------------------------------------------------------------------*/
-static void parse_cache_opt ( cache_t* cache, Char* opt )
+static void parse_cache_opt ( cache_t* cache, Char* opt, Char* optval )
{
Long i1, i2, i3;
Char* endptr;
// Option argument looks like "65536,2,64". Extract them.
- i1 = VG_(strtoll10)(opt, &endptr); if (*endptr != ',') goto bad;
+ i1 = VG_(strtoll10)(optval, &endptr); if (*endptr != ',') goto bad;
i2 = VG_(strtoll10)(endptr+1, &endptr); if (*endptr != ',') goto bad;
i3 = VG_(strtoll10)(endptr+1, &endptr); if (*endptr != '\0') goto bad;
@@ -1678,8 +1678,6 @@
overflow:
VG_(umsg)("one of the cache parameters was too large and overflowed\n");
bad:
- // XXX: this omits the "--I1/D1/L2=" part from the message, but that's
- // not a big deal.
VG_(err_bad_option)(opt);
}
@@ -1689,11 +1687,11 @@
// 5 is length of "--I1="
if VG_STR_CLO(arg, "--I1", tmp_str)
- parse_cache_opt(&clo_I1_cache, tmp_str);
+ parse_cache_opt(&clo_I1_cache, arg, tmp_str);
else if VG_STR_CLO(arg, "--D1", tmp_str)
- parse_cache_opt(&clo_D1_cache, tmp_str);
+ parse_cache_opt(&clo_D1_cache, arg, tmp_str);
else if VG_STR_CLO(arg, "--L2", tmp_str)
- parse_cache_opt(&clo_L2_cache, tmp_str);
+ parse_cache_opt(&clo_L2_cache, arg, tmp_str);
else if VG_STR_CLO( arg, "--cachegrind-out-file", clo_cachegrind_out_file) {}
else if VG_BOOL_CLO(arg, "--cache-sim", clo_cache_sim) {}
Modified: branches/MSG2/coregrind/m_libcprint.c
===================================================================
--- branches/MSG2/coregrind/m_libcprint.c 2009-08-22 05:10:48 UTC (rev 10857)
+++ branches/MSG2/coregrind/m_libcprint.c 2009-08-22 22:50:40 UTC (rev 10858)
@@ -160,7 +160,6 @@
return ret;
}
-/* An exact clone of VG_(printf_xml), unfortunately. */
UInt VG_(printf_xml_no_f_c) ( const HChar *format, ... )
{
UInt ret;
@@ -402,14 +401,6 @@
HChar ch;
Int i, depth;
- switch (b->kind) {
- case Vg_UserMsg: ch = '='; break;
- case Vg_DebugMsg: ch = '-'; break;
- case Vg_DebugExtraMsg: ch = '+'; break;
- case Vg_ClientMsg: ch = '*'; break;
- default: ch = '?'; break;
- }
-
// Print one '>' in front of the messages for each level of
// self-hosting being performed.
depth = RUNNING_ON_VALGRIND;
@@ -419,26 +410,50 @@
b->buf[b->buf_used++] = '>';
}
- b->buf[b->buf_used++] = ch;
- b->buf[b->buf_used++] = ch;
+ if (Vg_StartFailMsg == b->kind) {
+ // "valgrind: " prefix.
+ b->buf[b->buf_used++] = 'v';
+ b->buf[b->buf_used++] = 'a';
+ b->buf[b->buf_used++] = 'l';
+ b->buf[b->buf_used++] = 'g';
+ b->buf[b->buf_used++] = 'r';
+ b->buf[b->buf_used++] = 'i';
+ b->buf[b->buf_used++] = 'n';
+ b->buf[b->buf_used++] = 'd';
+ b->buf[b->buf_used++] = ':';
+ b->buf[b->buf_used++] = ' ';
- if (VG_(clo_time_stamp)) {
- VG_(memset)(tmp, 0, sizeof(tmp));
- VG_(elapsed_wallclock_time)(tmp);
+ } else {
+ // "==pid=="-style prefix.
+ switch (b->kind) {
+ case Vg_UserMsg: ch = '='; break;
+ case Vg_ValgrindMsg: ch = '-'; break;
+ case Vg_DebugMsg: ch = '+'; break; // MMM: use debugLog
+ case Vg_ClientMsg: ch = '*'; break;
+ default: VG_(core_panic)("add_to__vmessage_buf");
+ }
+
+ b->buf[b->buf_used++] = ch;
+ b->buf[b->buf_used++] = ch;
+
+ if (VG_(clo_time_stamp)) {
+ VG_(memset)(tmp, 0, sizeof(tmp));
+ VG_(elapsed_wallclock_time)(tmp);
+ tmp[sizeof(tmp)-1] = 0;
+ for (i = 0; tmp[i]; i++)
+ b->buf[b->buf_used++] = tmp[i];
+ }
+
+ VG_(sprintf)(tmp, "%d", b->my_pid);
tmp[sizeof(tmp)-1] = 0;
for (i = 0; tmp[i]; i++)
b->buf[b->buf_used++] = tmp[i];
+
+ b->buf[b->buf_used++] = ch;
+ b->buf[b->buf_used++] = ch;
+ b->buf[b->buf_used++] = ' ';
}
- VG_(sprintf)(tmp, "%d", b->my_pid);
- tmp[sizeof(tmp)-1] = 0;
- for (i = 0; tmp[i]; i++)
- b->buf[b->buf_used++] = tmp[i];
-
- b->buf[b->buf_used++] = ch;
- b->buf[b->buf_used++] = ch;
- b->buf[b->buf_used++] = ' ';
-
/* We can't possibly have stuffed 96 chars in merely as a result
of making the preamble (can we?) */
vg_assert(b->buf_used < sizeof(b->buf)-32);
@@ -455,7 +470,7 @@
b->atLeft = c == '\n';
}
-
+// MMM: make private
UInt VG_(vmessage) ( VgMsgKind kind, const HChar* format, va_list vargs )
{
UInt ret;
@@ -491,6 +506,7 @@
}
/* Send a simple single-part XML message. */
+// MMM: make private?
UInt VG_(message_no_f_c) ( VgMsgKind kind, const HChar* format, ... )
{
UInt count;
@@ -502,6 +518,7 @@
}
/* Send a simple single-part message. */
+// MMM: make private
UInt VG_(message) ( VgMsgKind kind, const HChar* format, ... )
{
UInt count;
@@ -513,6 +530,19 @@
}
/* VG_(message) variants with hardwired first argument. */
+
+UInt VG_(msgf) ( const HChar* format, ... )
+{
+ UInt count;
+ va_list vargs;
+ va_start(vargs,format);
+ count = VG_(vmessage) ( Vg_StartFailMsg, format, vargs );
+ va_end(vargs);
+ return count;
+}
+
+// MMM: get rid of eventually, then rename VG_(msgu) as VG_(umsg). Likewise
+// for dmsg.
UInt VG_(umsg) ( const HChar* format, ... )
{
UInt count;
@@ -523,6 +553,26 @@
return count;
}
+UInt VG_(msgu) ( const HChar* format, ... )
+{
+ UInt count;
+ va_list vargs;
+ va_start(vargs,format);
+ count = VG_(vmessage) ( Vg_UserMsg, format, vargs );
+ va_end(vargs);
+ return count;
+}
+
+UInt VG_(msgv) ( const HChar* format, ... )
+{
+ UInt count;
+ va_list vargs;
+ va_start(vargs,format);
+ count = VG_(vmessage) ( Vg_ValgrindMsg, format, vargs );
+ va_end(vargs);
+ return count;
+}
+
UInt VG_(dmsg) ( const HChar* format, ... )
{
UInt count;
@@ -533,12 +583,12 @@
return count;
}
-UInt VG_(emsg) ( const HChar* format, ... )
+UInt VG_(msgd) ( const HChar* format, ... )
{
UInt count;
va_list vargs;
va_start(vargs,format);
- count = VG_(vmessage) ( Vg_DebugExtraMsg, format, vargs );
+ count = VG_(vmessage) ( Vg_DebugMsg, format, vargs );
va_end(vargs);
return count;
}
Modified: branches/MSG2/coregrind/m_main.c
===================================================================
--- branches/MSG2/coregrind/m_main.c 2009-08-22 05:10:48 UTC (rev 10857)
+++ branches/MSG2/coregrind/m_main.c 2009-08-22 22:50:40 UTC (rev 10858)
@@ -1088,8 +1088,8 @@
VG_(printf_xml_no_f_c)(" <exe>%t</exe>\n",
VG_(name_of_launcher));
else
- VG_(printf_xml_no_f_c)(Vg_UserMsg, " <exe>%t</exe>\n",
- "(launcher name unknown)");
+ VG_(printf_xml_no_f_c)(" <exe>%t</exe>\n",
+ "(launcher name unknown)");
for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) {
VG_(printf_xml_no_f_c)(
" <arg>%t</arg>\n",
Modified: branches/MSG2/coregrind/m_options.c
===================================================================
--- branches/MSG2/coregrind/m_options.c 2009-08-22 05:10:48 UTC (rev 10857)
+++ branches/MSG2/coregrind/m_options.c 2009-08-22 22:50:40 UTC (rev 10858)
@@ -108,8 +108,8 @@
void VG_(err_bad_option) ( Char* opt )
{
revert_to_stderr();
- VG_(printf)("valgrind: Bad option '%s'; aborting.\n", opt);
- VG_(printf)("valgrind: Use --help for more information.\n");
+ VG_(msgf)("Bad option '%s'; aborting.\n", opt);
+ VG_(msgf)("Use --help for more information.\n");
VG_(exit)(1);
}
@@ -117,8 +117,8 @@
void VG_(err_missing_prog) ( void )
{
revert_to_stderr();
- VG_(printf)("valgrind: no program specified\n");
- VG_(printf)("valgrind: Use --help for more information.\n");
+ VG_(msgf)("no program specified\n");
+ VG_(msgf)("Use --help for more information.\n");
VG_(exit)(1);
}
@@ -126,8 +126,8 @@
void VG_(err_config_error) ( Char* msg )
{
revert_to_stderr();
- VG_(printf)("valgrind: Startup or configuration error:\n %s\n", msg);
- VG_(printf)("valgrind: Unable to start up properly. Giving up.\n");
+ VG_(msgf)("Startup or configuration error:\n %s\n", msg);
+ VG_(msgf)("Unable to start up properly. Giving up.\n");
VG_(exit)(1);
}
@@ -144,7 +144,7 @@
if (VG_STREQ(format, "")) {
// Empty name, bad.
- VG_(umsg)("%s: filename is empty", option_name);
+ VG_(msgf)("%s: filename is empty\n", option_name);
goto bad;
}
@@ -153,11 +153,13 @@
// that we don't allow a legitimate filename beginning with '~' but that
// seems very unlikely.
if (format[0] == '~') {
- VG_(umsg)("%s: filename begins with '~'\n", option_name);
- VG_(umsg)("You probably expected the shell to expand the '~', but it\n");
- VG_(umsg)("didn't. The rules for '~'-expansion "
- "vary from shell to shell.\n");
- VG_(umsg)("You might have more luck using $HOME instead.\n");
+ VG_(msgf)(
+ "%s: filename begins with '~'\n"
+ "You probably expected the shell to expand the '~',\n"
+ "but it didn't. The rules for '~'-expansion vary\n"
+ "from shell to shell. Try using $HOME instead.\n",
+ option_name
+ );
goto bad;
}
@@ -211,8 +213,7 @@
qualname = &format[i];
while (True) {
if (0 == format[i]) {
- VG_(message)(Vg_UserMsg, "%s: malformed %%q specifier\n",
- option_name);
+ VG_(msgf)("%s: malformed %%q specifier\n", option_name);
goto bad;
} else if ('}' == format[i]) {
// Temporarily replace the '}' with NUL to extract var
@@ -220,9 +221,8 @@
format[i] = 0;
qual = VG_(getenv)(qualname);
if (NULL == qual) {
- VG_(message)(Vg_UserMsg,
- "%s: environment variable %s is not set\n",
- option_name, qualname);
+ VG_(msgf)("%s: environment variable %s is not set\n",
+ option_name, qualname);
format[i] = '}'; // Put the '}' back.
goto bad;
}
@@ -235,15 +235,13 @@
ENSURE_THIS_MUCH_SPACE(VG_(strlen)(qual));
j += VG_(sprintf)(&out[j], "%s", qual);
} else {
- VG_(message)(Vg_UserMsg,
- "%s: expected '{' after '%%q'\n", option_name);
+ VG_(msgf)("%s: expected '{' after '%%q'\n", option_name);
goto bad;
}
}
else {
// Something else, abort.
- VG_(message)(Vg_UserMsg,
- "%s: expected 'p' or 'q' or '%%' after '%%'\n", option_name);
+ VG_(msgf)("%s: expected 'p' or 'q' or '%%' after '%%'\n", option_name);
goto bad;
}
}
Modified: branches/MSG2/coregrind/m_signals.c
===================================================================
--- branches/MSG2/coregrind/m_signals.c 2009-08-22 05:10:48 UTC (rev 10857)
+++ branches/MSG2/coregrind/m_signals.c 2009-08-22 22:50:40 UTC (rev 10858)
@@ -935,7 +935,7 @@
m_SP = VG_(get_SP)(tid);
if (VG_(clo_trace_signals))
- VG_(emsg)("sys_sigaltstack: tid %d, "
+ VG_(dmsg)("sys_sigaltstack: tid %d, "
"ss %p{%p,sz=%llu,flags=0x%llx}, oss %p (current SP %p)\n",
tid, (void*)ss,
ss ? ss->ss_sp : 0,
@@ -980,7 +980,7 @@
vki_sigaction_fromK_t* old_act )
{
if (VG_(clo_trace_signals))
- VG_(emsg)("sys_sigaction: sigNo %d, "
+ VG_(dmsg)("sys_sigaction: sigNo %d, "
"new %#lx, old %#lx, new flags 0x%llx\n",
signo, (UWord)new_act, (UWord)old_act,
(ULong)(new_act ? new_act->sa_flags : 0));
@@ -1129,7 +1129,7 @@
vki_sigset_t* oldset )
{
if (VG_(clo_trace_signals))
- VG_(emsg)("do_setmask: tid = %d how = %d (%s), newset = %p (%s)\n",
+ VG_(dmsg)("do_setmask: tid = %d how = %d (%s), newset = %p (%s)\n",
tid, how,
how==VKI_SIG_BLOCK ? "SIG_BLOCK" : (
how==VKI_SIG_UNBLOCK ? "SIG_UNBLOCK" : (
@@ -1141,7 +1141,7 @@
if (oldset) {
*oldset = VG_(threads)[tid].sig_mask;
if (VG_(clo_trace_signals))
- VG_(emsg)("\toldset=%p %s\n", oldset, format_sigset(oldset));
+ VG_(dmsg)("\toldset=%p %s\n", oldset, format_sigset(oldset));
}
if (newset) {
do_sigprocmask_bitops (how, &VG_(threads)[tid].sig_mask, newset );
Modified: branches/MSG2/coregrind/m_ume/main.c
===================================================================
--- branches/MSG2/coregrind/m_ume/main.c 2009-08-22 05:10:48 UTC (rev 10857)
+++ branches/MSG2/coregrind/m_ume/main.c 2009-08-22 22:50:40 UTC (rev 10858)
@@ -243,7 +243,7 @@
// Was it not executable?
} else if (0 != VG_(check_executable)(NULL, exe_name,
False/*allow_setuid*/)) {
- VG_(printf)("valgrind: %s: %s\n", exe_name, VG_(strerror)(ret));
+ VG_(msgf)("%s: %s\n", exe_name, VG_(strerror)(ret));
// Did it start with "#!"? If so, it must have been a bad interpreter.
} else if (is_hash_bang_file(exe_name)) {
Modified: branches/MSG2/include/pub_tool_libcprint.h
===================================================================
--- branches/MSG2/include/pub_tool_libcprint.h 2009-08-22 05:10:48 UTC (rev 10857)
+++ branches/MSG2/include/pub_tool_libcprint.h 2009-08-22 22:50:40 UTC (rev 10858)
@@ -75,6 +75,8 @@
extern UInt VG_(vprintf_xml) ( const HChar *format, va_list vargs )
PRINTF_CHECK(1, 0);
+// Just like VG_(printf_xml) but without the PRINTF_CHECK, so it can be used
+// with our non-standard %t format specifier.
extern UInt VG_(printf_xml_no_f_c) ( const HChar *format, ... );
// Percentify n/m with d decimal places. Includes the '%' symbol at the end.
@@ -92,11 +94,15 @@
/* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind.
Should be used for all user output. */
+// MMM: remove all the Vg/Vg_ prefixes here. Do it after VG_(message) has
+// been made private to minimise changes
typedef
- enum { Vg_UserMsg, /* '?' == '=' */
- Vg_DebugMsg, /* '?' == '-' */
- Vg_DebugExtraMsg, /* '?' == '+' */
- Vg_ClientMsg /* '?' == '*' */
+ enum { // Prefix
+ Vg_StartFailMsg, // "valgrind:"
+ Vg_UserMsg, // "==pid=="
+ Vg_ValgrindMsg, // "--pid--"
+ Vg_DebugMsg, // "++pid++"
+ Vg_ClientMsg // "**pid**"
}
VgMsgKind;
@@ -108,18 +114,26 @@
/* Send a single-part message. The format specification may contain
any ISO C format specifier. The gcc compiler will verify
consistency of the format string and the argument list. */
+// MMM: make private?
extern UInt VG_(message)( VgMsgKind kind, const HChar* format, ... )
PRINTF_CHECK(2, 3);
+// MMM: remove?
extern UInt VG_(vmessage)( VgMsgKind kind, const HChar* format, va_list vargs )
PRINTF_CHECK(2, 0);
// Short-cuts for VG_(message)().
-extern UInt VG_(umsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2);
-extern UInt VG_(dmsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2);
-extern UInt VG_(emsg)( const HChar* format, ... ) PRINTF_CHECK(1, 2);
+// MMM: rename these as vmsg/fmsg/etc eventually
+extern UInt VG_(msgf) ( const HChar* format, ... ) PRINTF_CHECK(1, 2);
+extern UInt VG_(msgu) ( const HChar* format, ... ) PRINTF_CHECK(1, 2);
+extern UInt VG_(msgv) ( const HChar* format, ... ) PRINTF_CHECK(1, 2);
+extern UInt VG_(msgd) ( const HChar* format, ... ) PRINTF_CHECK(1, 2);
+// MMM: get rid of these to begin with
+extern UInt VG_(umsg) ( const HChar* format, ... ) PRINTF_CHECK(1, 2);
+extern UInt VG_(dmsg) ( const HChar* format, ... ) PRINTF_CHECK(1, 2);
/* Flush any output cached by previous calls to VG_(message) et al. */
+// MMM: remove?
extern void VG_(message_flush) ( void );
#endif // __PUB_TOOL_LIBCPRINT_H
Modified: branches/MSG2/tests/filter_stderr_basic
===================================================================
--- branches/MSG2/tests/filter_stderr_basic 2009-08-22 05:10:48 UTC (rev 10857)
+++ branches/MSG2/tests/filter_stderr_basic 2009-08-22 22:50:40 UTC (rev 10858)
@@ -13,6 +13,7 @@
perl -p -e 's/(==|--|\+\+|\*\*)[0-9]{1,7}\1 //' |
# Remove any --pid:0: strings (debuglog level zero output)
+# MMM: change/remove
sed "/^--[0-9]\{1,7\}:0:*/d" |
# Remove "Command: line". (If wrapping occurs, it won't remove the
|