File indexing completed on 2022-09-27 14:08:50

0001 /* This file is part of KDevelop
0002    Copyright 2011 Mathieu Lornac <mathieu.lornac@gmail.com>
0003    Copyright 2011 Damien Coppel <damien.coppel@gmail.com>
0004    Copyright 2011 Lionel Duc <lionel.data@gmail.com>
0005    Copyright 2011 Sebastien Rannou <mxs@sbrk.org>
0006    Copyright 2016-2017 Anton Anikin <anton@anikin.xyz>
0007 
0008    This program is free software; you can redistribute it and/or
0009    modify it under the terms of the GNU General Public
0010    License as published by the Free Software Foundation; either
0011    version 2 of the License, or (at your option) any later version.
0012 
0013    This program is distributed in the hope that it will be useful,
0014    but WITHOUT ANY WARRANTY; without even the implied warranty of
0015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0016    General Public License for more details.
0017 
0018    You should have received a copy of the GNU General Public License
0019    along with this program; see the file COPYING.  If not, write to
0020    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0021    Boston, MA 02110-1301, USA.
0022 */
0023 
0024 #include "xmljob.h"
0025 #include "xmlconfig.h"
0026 
0027 #include "debug.h"
0028 #include "tool.h"
0029 #include "plugin.h"
0030 #include "problemmodel.h"
0031 #include "private/xmlparser.h"
0032 
0033 #include <QRegularExpression>
0034 
0035 namespace Valgrind
0036 {
0037 
0038 XmlJob::XmlJob(const Tool* tool, KDevelop::ILaunchConfiguration* launchConfig, XmlConfig* config)
0039     : Job(tool, launchConfig)
0040     , m_config(config)
0041 {
0042     Q_ASSERT(m_config);
0043 }
0044 
0045 XmlJob::~XmlJob() = default;
0046 
0047 void XmlJob::processValgrindOutput(const QStringList& lines)
0048 {
0049     static const auto xmlStartRegex = QRegularExpression("\\s*<");
0050 
0051     for (const QString& line : lines) {
0052         if (line.isEmpty()) {
0053             continue;
0054         }
0055 
0056         if (line.indexOf(xmlStartRegex) >= 0) { // the line contains XML
0057             m_xmlOutput << line;
0058         }
0059     }
0060 
0061     Job::processValgrindOutput(lines);
0062 }
0063 
0064 bool XmlJob::processEnded()
0065 {
0066     m_config->setConfigGroup(m_configGroup);
0067     m_config->load();
0068 
0069     auto problems = parseXml(m_tool->name(), m_xmlOutput.join(" "), m_config->showInstructionPointer());
0070     Plugin::self()->problemModel()->setProblems(problems);
0071 
0072     return true;
0073 }
0074 
0075 void XmlJob::addLoggingArgs(QStringList& args) const
0076 {
0077     args += QStringLiteral("--xml=yes");
0078     args += QStringLiteral("--xml-socket=127.0.0.1:%1").arg(m_tcpServerPort);
0079 }
0080 
0081 void XmlJob::addToolArgs(QStringList& args) const
0082 {
0083     m_config->setConfigGroup(m_configGroup);
0084     m_config->load();
0085 
0086     args += m_config->cmdArgs();
0087 }
0088 
0089 QWidget* XmlJob::createView()
0090 {
0091     return nullptr;
0092 }
0093 
0094 }