Commit 7d2cfbe4 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Fix the port to QRegularExpression

I made some mistakes when porting from QRegExp to QRegularExpression:
- With QRegularExpression::DotMatchesEverythingOption enabled, better use
  QRegularExpression::anchoredPattern and not rely on "^" and "$" to anchor
  the pattern (anchoredPattern uses "\A" and "\z" which is more accurate/precise)
- Disable QRegularExpression::DotMatchesEverythingOption before subsequent
  setPattern calls, it's only needed for the first matching
- When calling setPattern, obviously the previous QRegularExpression::anchoredPattern
  isn't going to be in effect, call it again if you want the pattern to be

Thanks to sitter for the unit tests that exposed the issue, and for
spotting the issue with needing to anchor the pattern.

All unit tests pass.
parent 7512f620
......@@ -56,8 +56,8 @@ void BacktraceLineGdb::parse()
// "#5 0x00007f50e99f776f in QWidget::testAttribute_helper (this=0x6e6440,\n attribute=Qt::WA_WState_Created) at kernel/qwidget.cpp:9081\n"
// gdb breaks long stack frame lines into multiple ones for readability
"^#([0-9]+)" //matches the stack frame number, ex. "#0"
"#([0-9]+)" //matches the stack frame number, ex. "#0"
"[\\s]+(?:0x[0-9a-f]+[\\s]+in[\\s]+)?" // matches " 0x0000dead in " (optionally)
"((?:\\(anonymous namespace\\)::)?[^\\(]+)?" //matches the function name
//(anything except left parenthesis, which is the start of the arguments section)
......@@ -70,7 +70,7 @@ void BacktraceLineGdb::parse()
"([\\s]+" //beginning of optional file information
"(from|at)[\\s]+" //matches "from " or "at "
"(.+)" //matches the filename (source file or shared library file)
")?\n$")); //matches trailing newline.
")?\n"))); //matches trailing newline.
//the )? at the end closes the parenthesis before [\\s]+(from|at) and
//notes that the whole expression from there is optional.
......@@ -108,25 +108,30 @@ void BacktraceLineGdb::parse()
regExp.setPattern(QStringLiteral(".*\\(no debugging symbols found\\).*|"
".*\\[Thread debugging using libthread_db enabled\\].*|"
".*\\[New .*|"
"Current language:.*"));
regExp.setPatternOptions(regExp.patternOptions() & ~QRegularExpression::DotMatchesEverythingOption);
QStringLiteral(".*\\(no debugging symbols found\\).*|"
".*\\[Thread debugging using libthread_db enabled\\].*|"
".*\\[New .*|"
"Current language:.*")));
if (regExp.match(d->m_line).hasMatch()) {
qCDebug(DRKONQI_PARSER_LOG) << "garbage detected:" << d->m_line;
d->m_type = Crap;
regExp.setPattern(QStringLiteral("Thread [0-9]+\\s+\\(Thread [0-9a-fx]+\\s+\\(.*\\)\\):\n"));
QStringLiteral("Thread [0-9]+\\s+\\(Thread [0-9a-fx]+\\s+\\(.*\\)\\):\n")));
if (regExp.match(d->m_line).hasMatch()) {
qCDebug(DRKONQI_PARSER_LOG) << "thread start detected:" << d->m_line;
d->m_type = ThreadStart;
regExp.setPattern(QStringLiteral("\\[Current thread is [0-9]+ \\(.*\\)\\]\n"));
QStringLiteral("\\[Current thread is [0-9]+ \\(.*\\)\\]\n")));
if (regExp.match(d->m_line).hasMatch()) {
qCDebug(DRKONQI_PARSER_LOG) << "thread indicator detected:" << d->m_line;
d->m_type = ThreadIndicator;
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