Logging and Crash Handling

This example illustrates techniques for tracking the state of a NaCl module via PostMessage and status of the module's lastError attribute. Messages from the modules are in the form of

Exception API

As of Chrome 28, NativeClient exception handling is possible without requiring special command-line flags. This feature is not always available so developers should avoid requring it under normal operation. However it can be a very useful tool for diagnosing crashes, especially in the field. NativeClient provides a library called "error_handling" for registering the exception handler, as well as unwinding the exception context.
NOTE: The library requires '-fno-omit-frame-pointer' to facilitate unwinding the stack.

Trace Walkthrough

First we request the exception handler interface, and use it to register both a handler and an exception stack. We use a separate stack since we do not know the state of stack for the thread handling the exception. Next, we create a worker thread which will take the exception. It is recommended that modules do as much work as possible off the main thread. Failure to do so can block the browser, making the page unresponsive and/or preventing communication with JavaScript. In addition blocking calls, which can greatly simplify code, are only allowed off the main thread.

After two seconds, JavaScript sends a message to the module which will cause it take an exception on the worker thread. The exception handler unwinds the stack while creating a stringified JSON object containing the stack frame information. Once unwound, or the buffer is exhausted, the JSON object is sent to JavaScript for processing.

The message handler in JavaScript takes the JSON object and uses the arch key to load the appropriate MAP file using an XMLHttpRequest. It then processes the MAP file and prints out a stack trace using the exception data in the JSON object.

Exception Handling in the Field

For real world applications, it's important to get the crash information back the developer. In this case, the JSON object could be sent via XMLHttpRequest. The JSON object can the be processed by the developers QA team to manage bugs in the field. The handler.py script provided in the example sources shows how the JSON object can be used with the tools to provide a better stack trace. Simply cut and paste the JSON object to a text file and run the handler.py script on it.


Status: NO-STATUS

Log

JSON


Stack Trace