Commit 6b247542 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Improve parsing of linker problems

parent a797b1f9
......@@ -34,41 +34,65 @@
using namespace ProjectExplorer;
namespace {
const char * const FILE_PATTERN("^(([a-zA-Z]:)?[^:]*\\.[^:]+):");
// opt. drive letter + filename: (2 brackets)
const char * const FILE_PATTERN("^(([a-zA-Z]:)?[^:]*):");
// line no. or elf segment + offset: (1 bracket)
const char * const POSITION_PATTERN("(\\d+|\\(\\.[a-zA-Z0-9]*.0x[a-fA-F0-9]+\\)):");
}
GccParser::GccParser()
{
// e.g.
//
m_regExp.setPattern(QString::fromLatin1(FILE_PATTERN) + "(\\d+):(\\d+:)*(\\s#?(warning|error):?)?\\s(.+)$");
m_regExp.setPattern(QString::fromLatin1(FILE_PATTERN) + QLatin1String("(\\d+):(\\d+:)?\\s(#?(warning|error):?\\s)(.+)$"));
m_regExp.setMinimal(true);
m_regExpIncluded.setPattern("^.*from\\s([^:]+):(\\d+)(,|:)$");
m_regExpIncluded.setMinimal(true);
// e.g.:
// c:\Qt\4.6\lib/QtGuid4.dll: file not recognized: File format not recognized
m_regExpLinker.setPattern(QString::fromLatin1(FILE_PATTERN) + "((\\d+|[^:]*):)?\\s(.+)$");
m_regExpLinker.setPattern(QString::fromLatin1(FILE_PATTERN) + '(' + QLatin1String(POSITION_PATTERN) + ")?\\s(.+)$");
m_regExpLinker.setMinimal(true);
// m_regExpGccNames.setPattern("^([a-z0-9]+-[a-z0-9]+-[a-z0-9]+-)(gcc|g\\+\\+)(-[0-9\\.]+)?:");
m_regExpGccNames.setPattern("^(gcc|g\\+\\+):\\s");
m_regExpGccNames.setMinimal(true);
}
void GccParser::stdError(const QString &line)
{
QString lne = line.trimmed();
if (m_regExp.indexIn(lne) > -1) {
if (lne.startsWith(QLatin1String("collect2:")) ||
lne.startsWith(QLatin1String("ERROR:")) ||
lne == QLatin1String("* cpp failed")) {
emit addTask(TaskWindow::Task(TaskWindow::Error,
lne /* description */,
QString() /* filename */,
-1 /* linenumber */,
Constants::TASK_CATEGORY_COMPILE));
return;
} else if (m_regExpGccNames.indexIn(lne) > -1) {
emit addTask(TaskWindow::Task(TaskWindow::Error,
lne.mid(m_regExpGccNames.matchedLength()), /* description */
QString(), /* filename */
-1, /* line */
Constants::TASK_CATEGORY_COMPILE));
return;
} else if (m_regExp.indexIn(lne) > -1) {
QString filename = m_regExp.cap(1);
int lineno = m_regExp.cap(3).toInt();
TaskWindow::Task task(TaskWindow::Unknown,
m_regExp.cap(7) /* description */,
m_regExp.cap(1) /* filename */,
m_regExp.cap(3).toInt() /* line number */,
filename, lineno,
Constants::TASK_CATEGORY_COMPILE);
if (m_regExp.cap(5) == QLatin1String("warning"))
if (m_regExp.cap(6) == QLatin1String("warning"))
task.type = TaskWindow::Warning;
else if (m_regExp.cap(5) == QLatin1String("error"))
task.type = TaskWindow::Error;
else if (task.description.startsWith(QLatin1String("undefined reference to")))
else if (m_regExp.cap(6) == QLatin1String("error") ||
task.description.startsWith(QLatin1String("undefined reference to")))
task.type = TaskWindow::Error;
// Prepend "#warning" or "#error" if that triggered the match on (warning|error)
// We want those to show how the warning was triggered
if (m_regExp.cap(5).startsWith(QChar('#')))
task.description = m_regExp.cap(5) + task.description;
emit addTask(task);
return;
} else if (m_regExpLinker.indexIn(lne) > -1) {
......@@ -77,11 +101,15 @@ void GccParser::stdError(const QString &line)
if (!ok)
lineno = -1;
QString description = m_regExpLinker.cap(5);
emit addTask(TaskWindow::Task(TaskWindow::Error,
description,
m_regExpLinker.cap(1) /* filename */,
lineno,
Constants::TASK_CATEGORY_COMPILE));
TaskWindow::Task task(TaskWindow::Error,
description,
m_regExpLinker.cap(1) /* filename */,
lineno,
Constants::TASK_CATEGORY_COMPILE);
if (description.startsWith(QLatin1String("In function `")))
task.type = TaskWindow::Unknown;
emit addTask(task);
return;
} else if (m_regExpIncluded.indexIn(lne) > -1) {
emit addTask(TaskWindow::Task(TaskWindow::Unknown,
......@@ -90,15 +118,6 @@ void GccParser::stdError(const QString &line)
m_regExpIncluded.cap(2).toInt() /* linenumber */,
Constants::TASK_CATEGORY_COMPILE));
return;
} else if (lne.startsWith(QLatin1String("collect2:")) ||
lne.startsWith(QLatin1String("ERROR:")) ||
lne == QLatin1String("* cpp failed")) {
emit addTask(TaskWindow::Task(TaskWindow::Error,
lne /* description */,
QString() /* filename */,
-1 /* linenumber */,
Constants::TASK_CATEGORY_COMPILE));
return;
}
IOutputParser::stdError(line);
}
......@@ -243,6 +262,27 @@ void ProjectExplorerPlugin::testGccOutputParsers_data()
Constants::TASK_CATEGORY_COMPILE)
)
<< QString();
QTest::newRow("linker: dll format not recognized")
<< QString::fromLatin1("c:\\Qt\\4.6\\lib/QtGuid4.dll: file not recognized: File format not recognized")
<< OutputParserTester::STDERR
<< QString() << QString()
<< (QList<ProjectExplorer::TaskWindow::Task>()
<< TaskWindow::Task(TaskWindow::Error,
QLatin1String("file not recognized: File format not recognized"),
QLatin1String("c:\\Qt\\4.6\\lib/QtGuid4.dll"), -1,
Constants::TASK_CATEGORY_COMPILE))
<< QString();
QTest::newRow("Invalid rpath")
<< QString::fromLatin1("g++: /usr/local/lib: No such file or directory")
<< OutputParserTester::STDERR
<< QString() << QString()
<< (QList<ProjectExplorer::TaskWindow::Task>()
<< TaskWindow::Task(TaskWindow::Error,
QLatin1String("/usr/local/lib: No such file or directory"),
QString(), -1,
Constants::TASK_CATEGORY_COMPILE))
<< QString();
}
void ProjectExplorerPlugin::testGccOutputParsers()
......
......@@ -48,6 +48,7 @@ private:
QRegExp m_regExp;
QRegExp m_regExpIncluded;
QRegExp m_regExpLinker;
QRegExp m_regExpGccNames;
};
} // namespace ProjectExplorer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment