| 53 | |
| 54 | |
| 55 | == Debugging native code with Eclipse == #debug-native |
| 56 | |
| 57 | Here are the steps for debugging PJSIP native code using Eclipse: |
| 58 | 1. Build PJSIP with debugging enabled, e.g: insert {{{CFLAGS += -g}}} into {{{user.mak}}} in PJSIP root directory. |
| 59 | 1. Make sure that the JNI part of the application is built using {{{ndk-build}}}. For reference, check apjsua's {{{Android.mk}}} build config in {{{pjsip-apps/src/apjsua/jni}}}, it contains sample of how to import PJSIP build settings (build search paths, build flags, etc) and SWIG invocation. |
| 60 | 1. Enable NDK plugin for Eclipse, check [http://tools.android.com/recent/usingthendkplugin this] and follow the instructions. |
| 61 | 1. It is recommended to introduce delay (about 5 seconds) in the application code between loading the native code library and calling any native functions (to be debugged), e.g: |
| 62 | {{{ |
| 63 | try { |
| 64 | System.loadLibrary("some_native_lib.so"); |
| 65 | } catch (UnsatisfiedLinkError e) { |
| 66 | return -1; |
| 67 | } |
| 68 | |
| 69 | // Wait for GDB init |
| 70 | if ((getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { |
| 71 | try { |
| 72 | Thread.sleep(5000); |
| 73 | } catch (InterruptedException e) { } |
| 74 | } |
| 75 | |
| 76 | // Start calling native functions here |
| 77 | // ... |
| 78 | }}} |
| 79 | 1. Load PJSIP project to Eclipse, and try put breakpoint anywhere in the PJSIP code before launching the application debug configuration in Eclipse. |
| 80 | |
| 81 | |