Native Client

Debugging

Note: The content on this page is valid as of 13-Sept-2011.

Native Client is still in its early stages, and as such debugging support is not as smooth as on other platform. The Native Client SDK team is working hard on providing integrated debugging support in IDEs. In the meantime, below are some common techniques to help debug your Native Client project.

Basic debugging

In the absence of any debugger, you can still get information about code processes using various forms of logging and output.

Using environment variables

Set the following environment variables to increase the output of the Native Client logs. In addition, you can and to redirect STD OUT and STD ERR but please note that these must point to seperate files.

  • NACL_DEBUG_ENABLE = 1
  • PPAPI_BROWSER_DEBUG = 1
  • NACL_PLUGIN_DEBUG = 1
  • NACL_PPAPI_PROXY_DEBUG = 1
  • NACL_SRPC_DEBUG = [1-255] (# pick higher number for increased verbosity)
  • NACLVERBOSITY = [1-255]
  • NACLLOG = c:\nacl.log
  • NACL_EXE_STDOUT = c:\nacl_stdout.log (must run chrome with --no-sandbox flag)
  • NACL_EXE_STDERR = c:\nacl_stderr.log (must run chrome with --no-sandbox flag)

In your C/C++ code, you can output custom message to the above log as follows:

#include <stdio.h>
void logmsg(const char* pMsg){
  fprintf(stdout,"logmsg: %s\n",pMsg);
}
void errormsg(const char* pMsg){
  fprintf(stderr,"logerr: %s\n",pMsg);
}

If you've set the NACL_EXE_STDOUT and NACL_EXE_STDERR variables, the above functions will output to the files you specified.

Using JavaScript, Console.Log, Pepper, and Chrome

Another option for logging messages is to use the Pepper messaging system to send messages from your C/C++ code to JavaScript. Once there, you can use the Console.Log() function to output the messages to the console in Chrome's developer tools.

Advanced debugging

As mentioned above, Native Client does not currently have advanced debugging support integrated into IDEs. Until then, you can use some advanced techniques to debug your modules on Windows, Mac, and Linux:

Profiling

Since Native Client Apps run inside of a plugin, and are distributed across mutliple processes, gathering profiling data can become a bit daunting. Thankfully, there's a set of resources over at Chromium.org which describes how to do profiling on 64-bit windows and linux machines.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.