[PATCH] D69461: [XRay] Sanitize DOT labels in graph output
Alex Cameron via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 1 19:54:00 PDT 2019
tetsuo-cpp updated this revision to Diff 227562.
tetsuo-cpp added a comment.
Use StringRef.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69461/new/
https://reviews.llvm.org/D69461
Files:
llvm/tools/llvm-xray/xray-graph.cpp
Index: llvm/tools/llvm-xray/xray-graph.cpp
===================================================================
--- llvm/tools/llvm-xray/xray-graph.cpp
+++ llvm/tools/llvm-xray/xray-graph.cpp
@@ -170,6 +170,30 @@
S.Sum += L;
}
+// Labels in a DOT graph must be legal XML strings so it's necessary to escape
+// certain characters.
+static std::string escapeString(StringRef Label) {
+ std::string Str;
+ Str.reserve(Label.size());
+ for (const auto C : Label) {
+ switch (C) {
+ case '&':
+ Str.append("&");
+ break;
+ case '<':
+ Str.append("<");
+ break;
+ case '>':
+ Str.append(">");
+ break;
+ default:
+ Str.push_back(C);
+ break;
+ }
+ }
+ return Str;
+}
+
// Evaluates an XRay record and performs accounting on it.
//
// If the record is an ENTER record it pushes the FuncID and TSC onto a
@@ -405,8 +429,9 @@
if (V.first == 0)
continue;
OS << "F" << V.first << " [label=\"" << (VT != StatType::NONE ? "{" : "")
- << (VA.SymbolName.size() > 40 ? VA.SymbolName.substr(0, 40) + "..."
- : VA.SymbolName);
+ << escapeString(VA.SymbolName.size() > 40
+ ? VA.SymbolName.substr(0, 40) + "..."
+ : VA.SymbolName);
if (VT != StatType::NONE)
OS << "|" << VA.S.getString(VT) << "}\"";
else
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69461.227562.patch
Type: text/x-patch
Size: 1402 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191102/60f2ec6b/attachment.bin>
More information about the llvm-commits
mailing list