|
From: <sv...@va...> - 2005-06-09 23:59:34
|
Author: sewardj
Date: 2005-06-10 00:58:36 +0100 (Fri, 10 Jun 2005)
New Revision: 3864
Log:
When printing XML, partially escape the output so that <, > and & in
C++ function names do not totally screw up XML parsers.
Modified:
trunk/coregrind/m_debuginfo/symtab.c
Modified: trunk/coregrind/m_debuginfo/symtab.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_debuginfo/symtab.c 2005-06-09 21:31:55 UTC (rev 386=
3)
+++ trunk/coregrind/m_debuginfo/symtab.c 2005-06-09 23:58:36 UTC (rev 386=
4)
@@ -2435,17 +2435,41 @@
#endif /* TEST */
=20
/* Print into buf info on code address, function name and filename */
+
+static Int putStr ( Int n, Int n_buf, Char* buf, Char* str )=20
+{
+ for (; n < n_buf-1 && *str !=3D 0; n++,str++)
+ buf[n] =3D *str;
+ buf[n] =3D '\0';
+ return n;
+}
+static Int putStrEsc ( Int n, Int n_buf, Char* buf, Char* str )=20
+{
+ Char alt[2];
+ for (; *str !=3D 0; str++) {
+ switch (*str) {
+ case '&': n =3D putStr( n, n_buf, buf, "&"); break;
+ case '<': n =3D putStr( n, n_buf, buf, "<"); break;
+ case '>': n =3D putStr( n, n_buf, buf, ">"); break;
+ default: alt[0] =3D *str;
+ alt[1] =3D 0;
+ n =3D putStr( n, n_buf, buf, alt );
+ break;
+ }
+ }
+ return n;
+}
+
Char* VG_(describe_IP)(Addr eip, Char* buf, Int n_buf)
{
-#define APPEND(str) \
- { UChar* sss; \
- for (sss =3D str; n < n_buf-1 && *sss !=3D 0; n++,sss++) \
- buf[n] =3D *sss; \
- buf[n] =3D '\0'; \
- }
+# define APPEND(_str) \
+ n =3D putStr(n, n_buf, buf, _str);
+# define APPEND_ESC(_str) \
+ n =3D putStrEsc(n, n_buf, buf, _str);
+
UInt lineno;=20
UChar ibuf[50];
- UInt n =3D 0;
+ Int n =3D 0;
static UChar buf_fn[VG_ERRTXT_LEN];
static UChar buf_obj[VG_ERRTXT_LEN];
static UChar buf_srcloc[VG_ERRTXT_LEN];
@@ -2468,19 +2492,19 @@
if (know_objname) {
APPEND(maybe_newline);
APPEND("<obj>");
- APPEND(buf_obj);
+ APPEND_ESC(buf_obj);
APPEND("</obj>");
}
if (know_fnname) {
APPEND(maybe_newline);
APPEND("<fn>");
- APPEND(buf_fn);
+ APPEND_ESC(buf_fn);
APPEND("</fn>");
}
if (know_srcloc) {
APPEND(maybe_newline);
APPEND("<file>");
- APPEND(buf_srcloc);
+ APPEND_ESC(buf_srcloc);
APPEND("</file>");
APPEND(maybe_newline);
APPEND("<line>");
@@ -2522,7 +2546,8 @@
}
return buf;
=20
-#undef APPEND
+# undef APPEND
+# undef APPEND_ESC
}
=20
/* Returns True if OK. If not OK, *{ip,sp,fp}P are not changed. */
|