Skip to content

Commit b3aa4b8

Browse files
committed
xml-parser: read valgrind's diagnostic message
1 parent 585bc60 commit b3aa4b8

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/xml-parser.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,33 @@ void ValgrindTreeDecoder::readRoot(
138138
noteEvt.verbosityLevel = /* note */ 1;
139139
}
140140

141+
/// read valgrind's message
142+
std::string readMsg(const pt::ptree &defNode)
143+
{
144+
const pt::ptree *whatNode;
145+
if (findChildOf(&whatNode, defNode, "what"))
146+
// message found in <what>...</what>
147+
return whatNode->get_value<std::string>();
148+
149+
if (findChildOf(&whatNode, defNode, "xwhat")
150+
&& findChildOf(&whatNode, *whatNode, "text"))
151+
// message found in <xwhat><text>...</text></xwhat>
152+
return whatNode->get_value<std::string>();
153+
154+
// message not found
155+
return "<unknown>";
156+
}
157+
141158
bool ValgrindTreeDecoder::readNode(Defect *pDef, pt::ptree::const_iterator defIter)
142159
{
143160
static const std::string errorKey = "error";
144161
if (errorKey != defIter->first)
145162
// not a node we are interested in
146163
return false;
147164

165+
// the current "error" node representing a single valgrind's report
166+
const pt::ptree &defNode = defIter->second;
167+
148168
// initialize the defect structure
149169
Defect &def = *pDef;
150170
def = this->defPrototype;
@@ -153,9 +173,10 @@ bool ValgrindTreeDecoder::readNode(Defect *pDef, pt::ptree::const_iterator defIt
153173
def.keyEventIdx = def.events.size();
154174
def.events.push_back(DefEvent("warning"));
155175
DefEvent &keyEvent = def.events.back();
176+
keyEvent.fileName = "<unknown>";
177+
keyEvent.msg = readMsg(defNode);
156178

157179
// read "kind" of the report
158-
const pt::ptree &defNode = defIter->second;
159180
pt::ptree::const_assoc_iterator itKind = defNode.find("kind");
160181
if (defNode.not_found() != itKind)
161182
keyEvent.event += "[" + itKind->second.get_value<std::string>() + "]";

0 commit comments

Comments
 (0)