|
From: <sv...@va...> - 2008-07-01 07:46:16
|
Author: bart
Date: 2008-07-01 08:46:21 +0100 (Tue, 01 Jul 2008)
New Revision: 8323
Log:
- Moved VG_(ToXML)() from coregrind/m_debuglog to coregrind/m_libcprint.
- VG_(ToXML)() no longer uses an internal buffer -- the caller has to
provide one.
- Modified myvprintf_str_XML_simplistic() from static into extern.
Modified:
branches/FORMATCHECK/coregrind/m_debuglog.c
branches/FORMATCHECK/coregrind/m_errormgr.c
branches/FORMATCHECK/coregrind/m_libcprint.c
branches/FORMATCHECK/coregrind/m_main.c
branches/FORMATCHECK/coregrind/pub_core_debuglog.h
branches/FORMATCHECK/include/pub_tool_libcprint.h
branches/FORMATCHECK/memcheck/mc_errors.c
Modified: branches/FORMATCHECK/coregrind/m_debuglog.c
===================================================================
--- branches/FORMATCHECK/coregrind/m_debuglog.c 2008-06-30 17:10:29 UTC (rev 8322)
+++ branches/FORMATCHECK/coregrind/m_debuglog.c 2008-07-01 07:46:21 UTC (rev 8323)
@@ -49,8 +49,6 @@
#include "pub_core_basics.h" /* basic types */
#include "pub_core_vkiscnums.h" /* for syscall numbers */
#include "pub_core_debuglog.h" /* our own iface */
-#include "pub_core_libcassert.h" /* vg_assert() */
-#include "pub_tool_libcprint.h" /* VG_(ToXML)() */
#include "valgrind.h" /* for RUNNING_ON_VALGRIND */
/*------------------------------------------------------------*/
@@ -450,7 +448,6 @@
#define VG_MSG_COMMA 16 /* Add commas to numbers (for %d, %u) */
#define VG_MSG_ALTFORMAT 32 /* Convert the value to alternate format */
-
/* Copy a string into the buffer. */
static
UInt myvprintf_str ( void(*send)(HChar,void*),
@@ -500,7 +497,6 @@
/* Copy a string into the buffer, escaping bad XML chars. */
-static
UInt myvprintf_str_XML_simplistic ( void(*send)(HChar,void*),
void* send_arg2,
const HChar* str )
@@ -657,7 +653,7 @@
break;
case ',':
case '\'':
- /* If ',' follows '%', commas will be inserted. */
+ /* If ',' or '\'' follows '%', commas will be inserted. */
flags |= VG_MSG_COMMA;
break;
case '-':
@@ -881,29 +877,8 @@
va_end(vargs);
}
-static HChar xml_result_buf[256];
-static int xml_result_buf_pos;
-static void append_to_xml_result_buf(const HChar ch, void* arg2)
-{
- if (xml_result_buf_pos
- <= sizeof(xml_result_buf) / sizeof(xml_result_buf[0]) - 2)
- {
- xml_result_buf[xml_result_buf_pos++] = ch;
- }
-}
-/* Convert a string such that it can be inserted into an XML output stream. */
-extern HChar* VG_(ToXML)(const HChar* str)
-{
- if (str == NULL)
- str = "(null)";
- xml_result_buf_pos = 0;
- myvprintf_str_XML_simplistic(append_to_xml_result_buf, NULL, str);
- xml_result_buf[xml_result_buf_pos] = 0;
- return xml_result_buf;
-}
-
/*--------------------------------------------------------------------*/
/*--- end m_debuglog.c ---*/
/*--------------------------------------------------------------------*/
Modified: branches/FORMATCHECK/coregrind/m_errormgr.c
===================================================================
--- branches/FORMATCHECK/coregrind/m_errormgr.c 2008-06-30 17:10:29 UTC (rev 8322)
+++ branches/FORMATCHECK/coregrind/m_errormgr.c 2008-07-01 07:46:21 UTC (rev 8323)
@@ -699,6 +699,7 @@
{
Supp *su;
Bool any_supp;
+ HChar xml_sname[128];
if (VG_(clo_xml))
VG_(message)(Vg_DebugMsg, "<suppcounts>");
@@ -714,7 +715,8 @@
" <count>%d</count>\n"
" <name>%s</name>\n"
" </pair>",
- su->count, VG_(ToXML)(su->sname));
+ su->count,
+ VG_(ToXML)(xml_sname, sizeof(xml_sname), su->sname));
} else {
VG_(message)(Vg_DebugMsg, "supp: %6d %s", su->count, su->sname);
}
Modified: branches/FORMATCHECK/coregrind/m_libcprint.c
===================================================================
--- branches/FORMATCHECK/coregrind/m_libcprint.c 2008-06-30 17:10:29 UTC (rev 8322)
+++ branches/FORMATCHECK/coregrind/m_libcprint.c 2008-07-01 07:46:21 UTC (rev 8323)
@@ -285,6 +285,47 @@
/* ---------------------------------------------------------------------
+ ToXML()
+ ------------------------------------------------------------------ */
+
+struct xml_buf {
+ HChar* cur;
+ HChar* end;
+};
+
+static void append_to_xml_buf(const HChar ch, void* arg2)
+{
+ struct xml_buf* const xml_buf = arg2;
+
+ if (xml_buf->cur < xml_buf->end)
+ {
+ *xml_buf->cur++ = ch;
+ }
+ else
+ {
+ /* Make sure that it gets noticed if a buffer is too small. */
+ vg_assert(False);
+ }
+}
+
+/* Convert a string such that it can be inserted into an XML output stream. */
+
+extern HChar* VG_(ToXML)(HChar* const buf, const Int size,
+ const HChar* str)
+{
+ static struct xml_buf xml_buf;
+
+ if (str == NULL)
+ str = "(null)";
+ xml_buf.cur = buf;
+ xml_buf.end = buf + size - 1;
+ myvprintf_str_XML_simplistic(append_to_xml_buf, &xml_buf, str);
+ *xml_buf.cur++ = 0;
+ return buf;
+}
+
+
+/* ---------------------------------------------------------------------
elapsed_wallclock_time()
------------------------------------------------------------------ */
Modified: branches/FORMATCHECK/coregrind/m_main.c
===================================================================
--- branches/FORMATCHECK/coregrind/m_main.c 2008-06-30 17:10:29 UTC (rev 8322)
+++ branches/FORMATCHECK/coregrind/m_main.c 2008-07-01 07:46:21 UTC (rev 8323)
@@ -734,6 +734,9 @@
// Get the env var name, print its contents.
Char* qualname;
Char* qual;
+ Char xml_qualname[256];
+ Char xml_qual[256];
+
i++;
qualname = &format[i];
while (True) {
@@ -749,7 +752,9 @@
VG_(message)(Vg_UserMsg, "<logfilequalifier> <var>%s</var> "
"<value>%s</value> </logfilequalifier>",
- VG_(ToXML)(qualname), VG_(ToXML)(qual));
+ VG_(ToXML)(xml_qualname, sizeof(xml_qualname),
+ qualname),
+ VG_(ToXML)(xml_qual, sizeof(xml_qual), qual));
format[i] = '}';
i++;
}
@@ -850,10 +855,13 @@
}
else
if (VG_(clo_xml)) {
+ HChar xml_buf[256];
+
VG_(message)(Vg_UserMsg, "");
VG_(message)(Vg_UserMsg, "<pid>%d</pid>", VG_(getpid)());
VG_(message)(Vg_UserMsg, "<ppid>%d</ppid>", VG_(getppid)());
- VG_(message)(Vg_UserMsg, "<tool>%s</tool>", VG_(ToXML)(toolname));
+ VG_(message)(Vg_UserMsg, "<tool>%s</tool>",
+ VG_(ToXML)(xml_buf, sizeof(xml_buf), toolname));
if (VG_(clo_log_name))
print_file_vars(VG_(clo_log_name));
if (VG_(clo_xml_user_comment)) {
@@ -869,25 +877,30 @@
VG_(message)(Vg_UserMsg, " <vargv>");
if (VG_(name_of_launcher))
VG_(message)(Vg_UserMsg, " <exe>%s</exe>",
- VG_(ToXML)(VG_(name_of_launcher)));
+ VG_(ToXML)(xml_buf, sizeof(xml_buf),
+ VG_(name_of_launcher)));
else
VG_(message)(Vg_UserMsg, " <exe>%s</exe>",
- VG_(ToXML)("(launcher name unknown)"));
+ VG_(ToXML)(xml_buf, sizeof(xml_buf),
+ "(launcher name unknown)"));
for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) {
VG_(message)(Vg_UserMsg,
" <arg>%s</arg>",
- VG_(ToXML)(* (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i )));
+ VG_(ToXML)(xml_buf, sizeof(xml_buf),
+ * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i )));
}
VG_(message)(Vg_UserMsg, " </vargv>");
VG_(message)(Vg_UserMsg, " <argv>");
if (VG_(args_the_exename))
VG_(message)(Vg_UserMsg, " <exe>%s</exe>",
- VG_(ToXML)(VG_(args_the_exename)));
+ VG_(ToXML)(xml_buf, sizeof(xml_buf),
+ VG_(args_the_exename)));
for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
VG_(message)(Vg_UserMsg,
" <arg>%s</arg>",
- VG_(ToXML)(* (HChar**) VG_(indexXA)( VG_(args_for_client), i )));
+ VG_(ToXML)(xml_buf, sizeof(xml_buf),
+ * (HChar**) VG_(indexXA)( VG_(args_for_client), i )));
}
VG_(message)(Vg_UserMsg, " </argv>");
@@ -1933,12 +1946,14 @@
//--------------------------------------------------------------
if (VG_(clo_xml)) {
HChar buf[50];
+ HChar xml_buf[256];
+
VG_(elapsed_wallclock_time)(buf);
VG_(message)(Vg_UserMsg, "<status>\n"
" <state>RUNNING</state>\n"
" <time>%s</time>\n"
"</status>",
- VG_(ToXML)(buf));
+ VG_(ToXML)(xml_buf, sizeof(xml_buf), buf));
VG_(message)(Vg_UserMsg, "");
}
@@ -2040,6 +2055,8 @@
if (VG_(clo_xml)) {
HChar buf[50];
+ HChar xml_buf[256];
+
if (VG_(needs).core_errors || VG_(needs).tool_errors) {
VG_(show_error_counts_as_XML)();
VG_(message)(Vg_UserMsg, "");
@@ -2049,7 +2066,7 @@
" <state>FINISHED</state>\n"
" <time>%s</time>\n"
"</status>",
- VG_(ToXML)(buf));
+ VG_(ToXML)(xml_buf, sizeof(xml_buf), buf));
VG_(message)(Vg_UserMsg, "");
}
Modified: branches/FORMATCHECK/coregrind/pub_core_debuglog.h
===================================================================
--- branches/FORMATCHECK/coregrind/pub_core_debuglog.h 2008-06-30 17:10:29 UTC (rev 8322)
+++ branches/FORMATCHECK/coregrind/pub_core_debuglog.h 2008-07-01 07:46:21 UTC (rev 8323)
@@ -84,7 +84,12 @@
va_list vargs
);
+/* Copy a string into the buffer, escaping bad XML chars. */
+UInt myvprintf_str_XML_simplistic ( void(*send)(HChar,void*),
+ void* send_arg2,
+ const HChar* str );
+
#endif // __PUB_CORE_DEBUGLOG_H
/*--------------------------------------------------------------------*/
Modified: branches/FORMATCHECK/include/pub_tool_libcprint.h
===================================================================
--- branches/FORMATCHECK/include/pub_tool_libcprint.h 2008-06-30 17:10:29 UTC (rev 8322)
+++ branches/FORMATCHECK/include/pub_tool_libcprint.h 2008-07-01 07:46:21 UTC (rev 8323)
@@ -90,7 +90,7 @@
extern UInt VG_(vmessage) ( VgMsgKind kind, const HChar* format, va_list vargs ) PRINTF_CHECK(2, 0);
/* Convert a string such that it can be inserted into an XML output stream. */
-extern HChar* VG_(ToXML)(const HChar* const str);
+extern HChar* VG_(ToXML)(HChar* buf, Int size, const HChar* str);
#endif // __PUB_TOOL_LIBCPRINT_H
Modified: branches/FORMATCHECK/memcheck/mc_errors.c
===================================================================
--- branches/FORMATCHECK/memcheck/mc_errors.c 2008-06-30 17:10:29 UTC (rev 8322)
+++ branches/FORMATCHECK/memcheck/mc_errors.c 2008-07-01 07:46:21 UTC (rev 8323)
@@ -262,6 +262,7 @@
{
HChar* xpre = VG_(clo_xml) ? " <auxwhat>" : " ";
HChar* xpost = VG_(clo_xml) ? "</auxwhat>" : "";
+ HChar xml_buf[256];
switch (ai->tag) {
case Addr_Unknown:
@@ -321,7 +322,8 @@
xpre,
(ULong)a,
(ULong)ai->Addr.DataSym.offset,
- VG_(ToXML)(ai->Addr.DataSym.name),
+ VG_(ToXML)(xml_buf, sizeof(xml_buf),
+ ai->Addr.DataSym.name),
xpost);
break;
@@ -339,8 +341,10 @@
"%sAddress 0x%llx is in the %s segment of %s%s",
xpre,
(ULong)a,
- VG_(ToXML)(VG_(pp_SectKind)(ai->Addr.SectKind.kind)),
- VG_(ToXML)(ai->Addr.SectKind.objname),
+ VG_(ToXML)(xml_buf, sizeof(xml_buf),
+ VG_(pp_SectKind)(ai->Addr.SectKind.kind)),
+ VG_(ToXML)(xml_buf, sizeof(xml_buf),
+ ai->Addr.SectKind.objname),
xpost);
break;
@@ -420,6 +424,7 @@
void MC_(pp_Error) ( Error* err )
{
MC_Error* extra = VG_(get_error_extra)(err);
+ HChar xml_buf[256];
switch (VG_(get_error_kind)(err)) {
case Err_CoreMem: {
@@ -569,7 +574,8 @@
if (VG_(clo_xml)) {
VG_(message)(Vg_UserMsg, " <kind>%s</kind>",
- VG_(ToXML)(xml_leak_kind(l->loss_mode)));
+ VG_(ToXML)(xml_buf, sizeof(xml_buf),
+ xml_leak_kind(l->loss_mode)));
} else {
VG_(message)(Vg_UserMsg, "");
}
|