네이티브 코드 디버깅하기

네이티브 코드를 디버깅하려면 네이티브 디버깅 실행 환경을 만들어 줘야 한다. 이전 장에서 앱을 빌드하고 실행한 환경은 앱 실행 환경이었다.

네이티브 디버깅 실행환경을 만들기 위해서 Edit Configurations...를 실행한다.

대화상자가 나타나면 화살표가 가리키고 있는 + 버튼을 클릭한다.

Android Native 메뉴를 선택한다.

표시한 부분을 설정한다.

사용할 Native Debugger를 선택한다.

Apply 버튼을 누르면 네이티브 코드 디버깅 실행 환경이 만들어진다. 그림처럼 native-debugging 실행 환경을 선택한다.

이제 네이티브 코드로 이동해 브레이크 포인트를 설정해 보자.

디버그 실행 버튼을 눌러 앱을 디버그 모드로 실행한다. 그러면 아래와 같이 디버거와 연결이 되었다는 메세지가 디버그 콘솔에 출력된다

Waiting for device.
Target device: pantech-im_a870k-70cb3852
Uploading file
    local path: /Users/burt/Projects/Repository/Study/temp/HelloJNI/app/build/outputs/apk/app-debug.apk
    remote path: /data/local/tmp/kr.pe.burt.hellojni
Installing kr.pe.burt.hellojni
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/kr.pe.burt.hellojni"
pkg: /data/local/tmp/kr.pe.burt.hellojni
Success


Launching application: kr.pe.burt.hellojni/kr.pe.burt.hellojni.MainActivity.
DEVICE SHELL COMMAND: am start  -n "kr.pe.burt.hellojni/kr.pe.burt.hellojni.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Copying /system/bin/app_process from device.
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=kr.pe.burt.hellojni/.MainActivity }

Copying /system/lib/libc.so from device.
Launching gdbserver: run-as kr.pe.burt.hellojni lib/gdbserver +debugsock --attach 4134
GDBServer launched and port forwarding established.
Now Launching Native Debug Session
Launching gdb: /Users/burt/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gdb
gdb connection established.

디버거와의 연결을 확인한 다음 버튼을 누르면 아래 그림과 같이 브레이크 포인터에서 실행 컨텍스트가 멈추게 되고 실행 컨텍스트의 환경을 디버거에 출력하게 된다.

이렇게 네이티브 코드를 디버깅 할 수 있다.

Last updated