Hide

Cloud Debugger


The Cloud Debugger is a feature of the Google Cloud Platform that lets you inspect the state of a Java App Engine application at a specific code ___location without stopping or slowing down the running application. The Cloud Debugger makes it easier to view the application state without adding logging statements to track down bugs.

You can use the Cloud Debugger on both production and staging instances of your application. The Cloud Debugger adds less than 10ms when capturing the application state, which in most cases is not noticeable by users.

Requirements

The Cloud Debugger requires the following:

The Cloud Debugger is enabled by default for all projects meeting these criteria.

Watchpoints

A watchpoint is a ___location in your source code that is watched by the Cloud Debugger. A watchpoint applies to all instances of an application that are currently running. The first time any running instance of the application executes the code at the watched ___location, the Cloud Debugger takes a snapshot of the local variables and the call stack. You can then examine the watchpoint results and use the data to debug your application. The Debugger implements several strategies for minimizing the amount of time the application is paused while the data is collected.

Setting a watchpoint

To set a watchpoint:

  1. Select Source Code > Browse in the left-hand navigation panel of the Google Developers Console.
  2. Navigate to the file that contains the source code you want to watch.
  3. Click the Debug button Debug button. The Cloud Debugger panel opens.
  4. Click on the line number of the source code location to watch.

View a watchpoint

If your project is using Push-to-Deploy, Cloud Debugger will validate that you are viewing the correct version of your source code. If you are viewing a file version that is different from the version currently deployed, Cloud Debugger will prompt you to switch to the correct version of the code, or update the deployed version.

Watchpoint condition

A watchpoint condition is a simple expression in the application language (Java) that tells the Cloud Debugger to take a snapshot of the application state when the condition evaluates to true at the time execution reaches the watchpoint location. Watchpoint conditions are evaluated separately for each application instance.

You can specify a watchpoint condition after you have set the watchpoint location by clicking the Condition, entering an expression, and hitting the Enter key or the Refresh button. This sets the watchpoint to capture another snapshot of your data.

The following are examples of watchpoint conditions:

travelAccessory == “Towel”
ultimateAnswer <= 42

You can only have one condition per watchpoint. The condition is a full boolean expression that can include logical operators to make up a more complex expression as follows:

travelAccessory == “Towel” && ultimateAnswer <= 42

You can use the following language features to express conditions:

  • All numerical and boolean operations (example: x + y < 20)
  • References to local variables (example: a == 8)
  • References to instance and static fields (examples: counter > 100, this.counter == 20, this.myObj.isShutdown, myStatic, com.mycompany.MyClass.staticMember)
  • String comparison with equality operator (example: myString == "abc")
  • Function calls. Currently, only functions in the java.lang package are supported, and only read-only functions can be used (example: StringBuilder.indexOf() is supported, but not StringBuilder.append())
  • Type casting, with fully qualified types (example: ((com.myprod.ClassImpl)myInterface).internalField)

Not supported:

  • Array access
  • Unboxing of numeric types (such as Integer); use myInteger.value instead

Watch expressions

Watch expressions allow you to evaluate complex expressions or traverse object hierarchies when a watchpoint is triggered. Watch expressions support the same language features as watchpoint conditions, described above.

Common uses for watch expressions are:

  • To view static or global variables that are not part of the local variable set
  • To easily view nested member variables without having to expand a local variable in the debugger panel every time (for example, this.locator.numFound)
  • To avoid repetitive mathematical calculations (for example, `(endTimeMillis - startTimeMillis) / 1000')

You can specify a watch expression after you have set the watchpoint ___location by clicking the Add Expression button, entering the expression in the Expression field, and hitting the Enter key. This updates the watchpoint. The result of the watch expression will be shown in the Cloud Debugger panel when the watchpoint is triggered.

Removing a watchpoint

You can remove a watchpoint by clicking the watchpoint icon next to the line number.

Viewing Watchpoint Results

Watchpoint results appear in the Cloud Debugger panel when the application executes the source code at the watchpoint ___location. Instance variables and local variables appear in the Local section of the panel. The stack trace appears in the Call Stack section of the panel.

Watchpoint results

You can examine the value of local variables at the moment the watchpoint was triggered, and drill down into deeper data structures. You can also click on any function further up the call stack, and examine the local variables at that level in the stack.

Refreshing a watchpoint

A watchpoint is only triggered once. If you want to capture another snapshot of your application's data after it has been triggered, you must manually refresh it.

To refresh a watchpoint, click the Refresh button near the top of the debugger panel.

refresh button

Sharing watchpoints

You can share a watchpoint and its captured data with another project member by simply copying the URL from your browser and sharing it with the other project member. You can also save this URL for future reference and come back to it again to view its results. Each refresh of a watchpoint results in a new URL, so you can share distinct sets of results even if they were captured at the same location in the code.

Closing the Cloud Debugger

Click the Debug button again (Debug button) to close the Cloud Debugger panel and return to normal source code browsing.