Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved out of process crash handler #5543

Merged
merged 2 commits into from
Nov 6, 2017
Merged

Conversation

NathanW2
Copy link
Member

@NathanW2 NathanW2 commented Nov 6, 2017

Description

This PR moves the crash handler work out into a new process called qgiscrashhandler.exe (only Windows at the moment). As part of this it will also generate a crash report folder inside %APPDATA%\QGIS\QGIS3\crashes. In future this lets us look back over the data from inside QGIS with a crash reporting tool. Report folder includes the users report in markdown format as well as the full stack trace with more info. In future, we can include a memory dump here if we want.

Main reasons for doing this:

  • Loading a dialog inside the crashed app can lock/crash the dialog which defeats the purpose of a crash dialog ;)
  • You can't reliability dump stack information from inside the crashed process (just like people shouldn't do operations on themselves)
  • Once we are out of process we can do a lot more e.g write the report, open web browsers, etc.

All arguments that the crash handler needs are written to a temp file on crash and then read back into the crash handler process, this includes stuff like process id, thread id, the pointer to expectation stack.

Checklist

Reviewing is a process done by project maintainers, mostly on a volunteer basis. We try to keep the overhead as small as possible and appreciate if you help us to do so by completing the following items. Feel free to ask in a comment if you have troubles with any of them.

  • Commit messages are descriptive and explain the rationale for changes
  • Commits which fix bugs include fixes #11111 in the commit message next to the description
  • Commits which add new features are tagged with [FEATURE] in the commit message
  • Commits which change the UI or existing user workflows are tagged with [needs-docs] in the commit message and containt sufficient information in the commit message to be documented
  • I have read the QGIS Coding Standards and this PR complies with them
  • This PR passes all existing unit tests (test results will be reported by travis-ci after opening this PR)
  • New unit tests have been added for core changes
  • I have run the scripts/prepare-commit.sh script before each commit

@NathanW2 NathanW2 self-assigned this Nov 6, 2017
@NathanW2 NathanW2 added this to the QGIS 3 milestone Nov 6, 2017
* This class doesn't need to be created by anyone as is only used to handle
* crashes in the application.
*/
QgsCrashHandler() {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= delete;

QString extraInfoFile = QString( argv[1] );
std::cout << "Extra Info File: " << extraInfoFile.toUtf8().data() << std::endl;

QFile file( extraInfoFile );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bomb out if this doesn't exist?

// bit gross but :)
QString info = file.readAll();
versionInfo = info.split("\n");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graceful exit if we can't open the file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might still show the dialog but with no info.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although this shouldn't really happen anyway but dialog might be better then just crashing out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With no info this is what you get:

image

I think that is ok to leave like that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect! Just needs a . between "information Your"

Also "Stack trace unable to be generated" should be "Stack trace could not be generated"

std::cout << "Exception Pointer: " << exceptionPointersString.toLocal8Bit().constData() << std::endl;
std::cout << "Symbol Path :" << symbolPaths.toUtf8().data() << std::endl;

QgsStackTrace *stackTrace = QgsStackTrace::trace( processId, threadId, exception, symbolPaths );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::unique_ptr

reportData.append( QStringLiteral( "Compiled against GDAL: %1" ).arg( GDAL_RELEASE_NAME ) );
reportData.append( QStringLiteral( "Running against GDAL: %1" ).arg( GDALVersionInfo( "RELEASE_NAME" ) ) );
reportData.append( mVersionInfo );
// reportData.append( QStringLiteral( "QGIS Version: %1" ).arg( Qgis::QGIS_VERSION ) );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the go here?

@@ -117,13 +129,13 @@ const QString QgsCrashReport::toHtml() const

const QString QgsCrashReport::crashID() const
{
if ( mStackTrace.isEmpty() )
if (!mStackTrace->symbolsLoaded || mStackTrace->lines.isEmpty() )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

astyle

fileName = folder + "/report.txt";

file.setFileName(fileName);
if ( file.open( QIODevice::WriteOnly | QIODevice::Text ) )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure you'll need QIODevice::Truncate here too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a new file each time so should be at the start already.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point!


QString QgsCrashReport::crashReportFolder()
{
return QStandardPaths::standardLocations( QStandardPaths::AppDataLocation ).value( 0 ) +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppLocalDataLocation ?

getStackTrace( stackTrace, symbolPath, trace );
trace->fullStack = QString::fromWCharArray( stackTrace->message );

// wchar_t dumpFilename[MAX_PATH + 1];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with all this? Better #if 0 it or kill it.

@nyalldawson
Copy link
Collaborator

You can't reliability dump stack information from inside the crashed process (just like people shouldn't do operations on themselves)

Speak for yourself! I've saved $1978 by following Youtube DIY surgical operation guides.

@nyalldawson
Copy link
Collaborator

Great move! This looks like a much better approach to me.

Copy link
Collaborator

@nyalldawson nyalldawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Let's merge and test

@NathanW2 NathanW2 merged commit ee59abf into qgis:master Nov 6, 2017
@NathanW2
Copy link
Member Author

NathanW2 commented Nov 6, 2017

@jef-n let me know if you see anything out of place here and I will fix it up. qgiscrashhandler doesn't need to go into osgeo4w\bin like qgis.exe as I'm loading it from the prefix path.

@NathanW2
Copy link
Member Author

NathanW2 commented Nov 6, 2017

Thanks for the review @nyalldawson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants