|
From: <sv...@va...> - 2011-10-22 08:29:17
|
Author: bart
Date: 2011-10-22 09:24:32 +0100 (Sat, 22 Oct 2011)
New Revision: 12188
Log:
XML output: escape XML-metacharacters in executable path and arguments. This is a modified version of the patch submitted by Evgeniy Stepanov <eug...@gm...>. See also #284621.
Modified:
trunk/coregrind/m_main.c
Modified: trunk/coregrind/m_main.c
===================================================================
--- trunk/coregrind/m_main.c 2011-10-21 08:07:13 UTC (rev 12187)
+++ trunk/coregrind/m_main.c 2011-10-22 08:24:32 UTC (rev 12188)
@@ -1026,21 +1026,26 @@
/*=== Printing the preamble ===*/
/*====================================================================*/
-// Print the command, escaping any chars that require it.
-static void umsg_or_xml_arg(const Char* arg,
- UInt (*umsg_or_xml)( const HChar*, ... ) )
+// Print the argument, escaping any chars that require it.
+static void umsg_arg(const Char* arg)
{
SizeT len = VG_(strlen)(arg);
Char* special = " \\<>";
Int i;
for (i = 0; i < len; i++) {
if (VG_(strchr)(special, arg[i])) {
- umsg_or_xml("\\"); // escape with a backslash if necessary
+ VG_(umsg)("\\"); // escape with a backslash if necessary
}
- umsg_or_xml("%c", arg[i]);
+ VG_(umsg)("%c", arg[i]);
}
}
+// Send output to the XML-stream and escape any XML meta-characters.
+static void xml_arg(const Char* arg)
+{
+ VG_(printf_xml)("%pS", arg);
+}
+
/* Ok, the logging sink is running now. Print a suitable preamble.
If logging to file or a socket, write details of parent PID and
command line args, to help people trying to interpret the
@@ -1055,6 +1060,9 @@
UInt (*umsg_or_xml)( const HChar*, ... )
= VG_(clo_xml) ? VG_(printf_xml) : VG_(umsg);
+ UInt (*umsg_or_xml_arg)( const HChar* )
+ = VG_(clo_xml) ? xml_arg : umsg_arg;
+
vg_assert( VG_(args_for_client) );
vg_assert( VG_(args_for_valgrind) );
vg_assert( toolname );
@@ -1106,11 +1114,12 @@
// favour utility and simplicity over aesthetics.
umsg_or_xml("%sCommand: ", xpre);
if (VG_(args_the_exename))
- umsg_or_xml_arg(VG_(args_the_exename), umsg_or_xml);
+ umsg_or_xml_arg(VG_(args_the_exename));
+
for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
HChar* s = *(HChar**)VG_(indexXA)( VG_(args_for_client), i );
umsg_or_xml(" ");
- umsg_or_xml_arg(s, umsg_or_xml);
+ umsg_or_xml_arg(s);
}
umsg_or_xml("%s\n", xpost);
|