Crash Reporting For MinGW 32 (Windows) and Clang (macOS) With Qt

I recently had a customer describe some very random crashes with my software. There didn’t seem to be a pattern or a way for me to reproduce the problems locally to debug them. So my first thought was to get him to install a version with some kind of crash reporting tooling so I could get a stack trace to help track down the issue.

I’d looked into implementing some form of crash reporting quite a while ago, but it was never a very high priority for me because I don’t get a lot of bug reports. In this case though it seemed like it would be easiest if I could produce a version of my software with some built-in stack tracing.

The first thing I did was to look at what libraries were available for this. My criteria were:

  • simple to use/integrate with a Qt application
  • works with the MinGW 32-bit compiler on Windows and the clang compiler on macOS
  • inexpensive (or free!)
  • usable in commercial software

The most promising were BreakPad (older) or CrashPad (newer) from Google. From what I understand, Breakpad no longer works on macOS which is why they switched to CrashPad. Unfortunately CrashPad doesn’t handle 32-bit MinGW builds. The reason I’m stuck with the 32-bit version is that Qt currently ships its MinGW builds of the libraries and toolchain using the 32-bit MinGW 4.9.2 compiler.

So after a lot of searching and piecing things together, I’ve created something that works and fits my criteria. It’s very simple – all it does is save the stack trace to a file that the user can send me – and requires some instructions to the user to work with it. If I wanted to get fancier I could have it automatically post the information to a web server, but for now this is simple and it works.

It might work on Linux too since the code path for macOS should be POSIX compliant, though I haven’t tried it. It could also be extended to handle MSVC compiles (or maybe it already does!), but I don’t use that compiler so I can’t test it.

I used many different sites in my search, but my primary sources were Catching Exceptions and Printing Stack Traces for C on Windows, Linux, & Mac by Job Vranish, Printing a Stack Trace with MinGW by Daniel Holden, and the C++ name mangling article on Wikipedia.

Continue reading

Code Coverage Of Unit Tests Using Qt 5 On macOS

Qt Library

Qt Framework

I was inspired while watching a talk by Kevin Ottens about refactoring OpenGL code in Qt to take a look at gcov & lcov. gcov is used to analyze code coverage – which lines of code have actually been executed while running an application. lcov is a tool that can produce HTML reports from the gcov output.

If you have a suite of unit tests that you run on your code, you can use these tools to see which the lines of code are covered by your tests and which are not.

I couldn’t find a decent primer on how to set this up properly for my Qt projects on macOS so I could run it from Qt Creator, so I thought I’d write up how I did it.

Continue reading

Packaging a Mac OS X Application Using a DMG

I learned early on in my software career that packaging up a release of an application can be a real pain. Not only is it time consuming, but it is quite easy to forget a file or miss something when there are so many steps involved and you have to do it frequently. The solution to this is to automate the process. Putting together scripts to package up a release helps avoid missing steps and speeds up development and deployment of releases and updates.

One of the challenges of automating this on Mac OS X is figuring out how to script the creation of Apple disk image (DMG) files. Getting the arguments to hdiutil correct can be quite a challenge! In this post, I’ll give an example of a script I use to do the following:

  • Copy all the necessary files to a staging area
  • Strip and compress the executable files and libraries
  • Create a DMG of the correct size for the release
  • Add a link to /Applications to the DMG
  • Add a background to the DMG so when it opens up your company logo or application graphic appears
  • Check the background image’s DPI to ensure it is 72. Fix it if it’s not.
  • Resize the window and icons, and position items in the DMG so when it opens everything is in the right place
  • Create a final, compressed DMG

Packaging An Application Using a DMG

Packaging An Application Using a DMG

Let’s take a look… Continue reading

Cppcheck

Cppcheck is an open source cool tool by Daniel Marjamäki used to statically analyse C/C++ code for errors, questionable code, and style. I’ve been tracking it for a number of months and, while it is still in active development, it is already a very useful tool. There are command line and GUI versions available for several platforms.

The Cppcheck wiki page gives a lot more information about it, and lists a couple of hundred checks that are performed on your code.

A git repository is available which makes it easy to keep up-to-date with the latest developments. The source also includes a Qt-based GUI which is quite straightforward to compile using Qt Creator. The GUI is functional, but could use a little bit of work to make it more friendly. In order to view error or warning in the source, for example, Cppcheck requires an external program. It really ought to show you the code in context in the main window, allowing you to correct things within the application.

Continue reading

ImageOptim

ImageOptim is a cool tool by Kornel Lesiński for Mac OS X used to optimize images. Why would I want to do that you ask? It reduces the size of images so they take up less disk space. This means if you are working on a website, it will load a little faster for your users. If you are working on games, it can reduce the amount of data being sent to the GPU which can speed up the loading of textures [make sure you are using lossless compression of course].

ImageOptim is a front-end to several image optimizing tools including AdvPNG, OptiPNG, Pngcrush, JpegOptim, jpegtran, and Gifsicle. It works on PNG, JPG, and GIF images.

ImageOptim Example

ImageOptim Example

Photoshop is especially bad at creating small files when it saves them. It’s incredible the number of images on the web that can be optimized to save everyone time and money. Anyone running a website should consider using ImageOptim or a tool like it on their images.