Add format specifier %ps: only escape XML-metacharacters for --xml=yes

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12135 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_debuglog.c b/coregrind/m_debuglog.c
index 7ad3f8c..c3dcb19 100644
--- a/coregrind/m_debuglog.c
+++ b/coregrind/m_debuglog.c
@@ -56,6 +56,13 @@
 #include "pub_core_debuglog.h"   /* our own iface */
 #include "valgrind.h"            /* for RUNNING_ON_VALGRIND */
 
+static Bool clo_xml;
+
+void VG_(debugLog_setXml)(Bool xml)
+{
+   clo_xml = xml;
+}
+
 /*------------------------------------------------------------*/
 /*--- Stuff to make us completely independent.             ---*/
 /*------------------------------------------------------------*/
@@ -730,6 +737,17 @@
                if (str == (char*) 0)
                   str = "(null)";
                ret += myvprintf_str_XML_simplistic(send, send_arg2, str);
+            } else if (format[i+1] == 's') {
+               i++;
+               /* %ps, synonym for %s with --xml=no / %pS with --xml=yes */
+               char *str = va_arg (vargs, char *);
+               if (str == (char*) 0)
+                  str = "(null)";
+               if (clo_xml)
+                  ret += myvprintf_str_XML_simplistic(send, send_arg2, str);
+               else
+                  ret += myvprintf_str(send, send_arg2, flags, width, str,
+                                       False);
             } else {
                /* %p */
                ret += 2;
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
index a8edffb..1981321 100644
--- a/coregrind/m_main.c
+++ b/coregrind/m_main.c
@@ -462,7 +462,9 @@
          VG_(clo_verbosity)--;
 
       else if VG_BOOL_CLO(arg, "--stats",          VG_(clo_stats)) {}
-      else if VG_BOOL_CLO(arg, "--xml",            VG_(clo_xml)) {}
+      else if VG_BOOL_CLO(arg, "--xml",            VG_(clo_xml))
+         VG_(debugLog_setXml)(VG_(clo_xml));
+
       else if VG_XACT_CLO(arg, "--vgdb=no",        VG_(clo_vgdb), Vg_VgdbNo) {}
       else if VG_XACT_CLO(arg, "--vgdb=yes",       VG_(clo_vgdb), Vg_VgdbYes) {}
       else if VG_XACT_CLO(arg, "--vgdb=full",      VG_(clo_vgdb), Vg_VgdbFull) {}
diff --git a/coregrind/pub_core_debuglog.h b/coregrind/pub_core_debuglog.h
index 9cdcd61..865963e 100644
--- a/coregrind/pub_core_debuglog.h
+++ b/coregrind/pub_core_debuglog.h
@@ -59,6 +59,10 @@
 void VG_(debugLog_startup) ( Int level, HChar* who );
 
 
+/* Whether %ps should escape XML metacharacters. */
+extern void VG_(debugLog_setXml)(Bool xml);
+
+
 /* Get the logging threshold level, as set by the most recent call to
    VG_(debugLog_startup), or zero if there have been no such calls so
    far. */