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

Address segmentation faults in the Log message handlers on macOS. #766

Merged
merged 6 commits into from
Jun 25, 2022
Merged

Address segmentation faults in the Log message handlers on macOS. #766

merged 6 commits into from
Jun 25, 2022

Conversation

philmb3487
Copy link
Contributor

@philmb3487 philmb3487 commented Mar 31, 2020

Problem

CaveSpectre and mimir (others?) have reported a crash on recent macOS builds.
The crash is a segmentation fault in a debug handler named DebugMessageHandler(),
at runtime, before the slash screen, or main window, is shown.

Root Cause

The issue has been tracked down to incorrect usage of the debug.log message handler override.
This is a part of Qt that allows us to log to debug.log, using a bypassed message handler
in the form of a callback function.

The issue is that we should not access some of the “context” information, passed in the form of
a QmessageLogContext.

If we peruse the Qt documentation:

Note: By default, this information is recorded only in debug builds. You can overwrite this explicitly by defining QT_MESSAGELOGCONTEXT or QT_NO_MESSAGELOGCONTEXT.

Solution

The correct way to fix this is to not make use of any of the potentially unavailable debugging information.

Furthermore, this Pull Request will pull in 4 additional commits, that are cherry-picks from Bitcoin upstream. The reason for this is to fix a build-time error on recent macOS versions,
due to code deprecation in the dock icon logic.

Unit Testing Results

Build on a relatively recent version of macOS, and see if:

  1. The build is successful.
  2. The user succeeds in launching the application to the main window.
  3. Additionally, because this Pull Request touches the dock icon handlers, it is requested that we verify the dock icon is sane: separators, exit entry, and such.

Qt `setWindowIcon()` does this work.
This moves the Dock icon click reaction code to the common place and
allows some cleanup in obj_c code.

According to the Apple's docs `class_replaceMethod` behaves as
`class_addMethod`, if the method identified by name does not yet exist;
or as `method_setImplementation`, if it does exist.
Qt `setAsDockMenu()` does this work.
@philmb3487
Copy link
Contributor Author

philmb3487 commented Mar 31, 2020

@CaveSpectre11
Please continue discussion here. My bad, it seems handling of PR's on Github is a bit strange, one can't delete an open pull request, is this okay?
Updated the PR with correct template information. Apologies to you for my rudeness other day.

Copy link
Collaborator

@CaveSpectre11 CaveSpectre11 left a comment

Choose a reason for hiding this comment

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

@sinetek thank you for using the form. You don't actually need to include the bounty and payment address sections. I had put those in when I developed the form since I was a bounty dev at the time. You can just remove those; no problem.

So I added the problem code when I was doing some Qt fixes recently. I wrapped with the #ifndef to prevent the new code from being used when the relevant QT_MESSAGELOGCONTEXT wasn't defined. Do you know where it's getting defined from?

I left the code in so that it could be used without people having to figure out how to add it. With that said, I would prefer that it be commented out, rather than removed from the code.

Great find!

src/qt/veil.cpp Outdated Show resolved Hide resolved
@CaveSpectre11 CaveSpectre11 added Tag: Build System Tag: OS - OSX Problems specific to Mac OS Tag: Segfault This issue causes the application to crash. labels Mar 31, 2020
@4x13
Copy link
Collaborator

4x13 commented Apr 3, 2020

ACK This does fix the segfault when natively compiling on OSX. I have not yet tried to compile using gitian, but I will tomorrow

src/qt/veil.cpp Outdated Show resolved Hide resolved
* This information is not always available and caused crashes
    in some builds.
@philmb3487
Copy link
Contributor Author

@CaveSpectre11 Changes done.

@philmb3487 philmb3487 added the Priority: 3 - High Critical item that should be done as soon as possible label Apr 5, 2020
@CaveSpectre11 CaveSpectre11 added Tag: Waiting For Code Review Waiting for code review from a core developer and removed Tag: Waiting For Developer labels May 8, 2020
@CaveSpectre11 CaveSpectre11 removed the Priority: 3 - High Critical item that should be done as soon as possible label Jun 14, 2020
CaveSpectre11 added a commit that referenced this pull request Jun 20, 2020
…ndler.

5416ae0 Do not use Qt's debugging information in the log handler. (sinetek)

Pull request description:

  (Commit cherry picked from #766 for fast tracking)
  ### Problem ###
  CaveSpectre and mimir (others?) have reported a crash on recent macOS builds.
  The crash is a segmentation fault in a debug handler named DebugMessageHandler(),
  at runtime, before the slash screen, or main window, is shown.

  ### Root Cause ###
  The issue has been tracked down to incorrect usage of the debug.log message handler override.
  This is a part of Qt that allows us to log to debug.log, using a bypassed message handler
  in the form of a callback function.

  The issue is that we should not access some of the “context” information, passed in the form of
  a QmessageLogContext.

  If we peruse the Qt documentation:

  Note: By default, this information is recorded only in debug builds. You can overwrite this explicitly by defining QT_MESSAGELOGCONTEXT or QT_NO_MESSAGELOGCONTEXT.

  ### Solution ###
  The correct way to fix this is to not make use of any of the potentially unavailable debugging information.

  ### Unit Testing Results ###
  Build on a relatively recent version of macOS, and see if:

  1)  The build is successful.
  2)  The user succeeds in launching the application to the main window.

Tree-SHA512: 7d15d01ecd406ba2738becd9d477a78aaa69babe77557927b6a8d4fd7535822b12c2ee38a3868946b8a41353ffbee2a5e413d631f350f523eba65cbc6138bf5e
@CaveSpectre11
Copy link
Collaborator

CaveSpectre11 commented Jul 5, 2020

Includes 3 of 6 commits from: bitcoin/bitcoin#14123
Includes bitcoin/bitcoin#16720

@seanPhill seanPhill added the QA: In Progress This is being tested by the QA team. KEEP CALM and RELAX. label Jun 24, 2022
@seanPhill seanPhill requested review from Zannick and removed request for mimirmim June 25, 2022 17:14
Copy link
Collaborator

@Zannick Zannick left a comment

Choose a reason for hiding this comment

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

utACK 386e15e

@seanPhill seanPhill merged commit 30f3827 into Veil-Project:master Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QA: In Progress This is being tested by the QA team. KEEP CALM and RELAX. Tag: Build System Tag: OS - OSX Problems specific to Mac OS Tag: Segfault This issue causes the application to crash. Tag: Waiting For Code Review Waiting for code review from a core developer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants