Category: Java/C++ Runtime

Q

How can I debug the C++ parts of my mixed Java/C++ application?

A

You can debug the application using any C++ debugger. Obviously, a standard C++ debugger will only allow you to step through the C++ parts of your application (see another FAQ for information on debugging the Java parts of your application).

When using gdb on Linux (and possibly other Unix platforms), you might have to customize the signal handling in the debugger because some JVMs use certain signals as part of their normal garbage collection processing. If you can't seem to singlestep through your application code and if the debugger continuously breaks due to SIGSEGVs, you will have to customize how the debugger processes SIGSEGV. We have successfully used the following gdb configuration options in such cases:

           handle SIGSEGV pass noprint nostop
           handle SIGUSR1 pass noprint nostop
           handle SIGUSR2 pass noprint nostop

This Google search might yield some useful background information on the above issue.

In debugging your application, you might have to look at some proxy object internals that you would normally never look at. Here are some guidelines for helping you interpret what you are seeing:

  • Proxy objects are just a thin wrapper around Java objects.
    Each proxy object maintains a "handle" representing the Java object. You can inspect the value of that handle by looking at the owner_ field.
  • A proxy object represents a null reference when the value of the owner_ field is 0.
  • You cannot observe the values of Java fields directly in the C++ debugger because they are resolved dynamically upon usage.
  • You cannot directly see the value of a Java string in the corresponding C++ proxy object unless the C++ instance already caches the value after a to_chars() invocation.
  • Two proxy objects can represent the same Java object even if they have different values for the "handle."

Copyright 2006-2011 by Codemesh, Inc., ALL RIGHTS RESERVED

:
frequently asked questions
home products support customers partners newsroom about us contact us