Native(C++)에서 callstack을 로그에 남기고 싶을 때 CallStack 클래스를 사용할 수 있습니다.
CallStack은 아래 파일에 정의되어 있습니다.
android/system/core/libutils/include/utils/CallStack.h
android/system/core/libutils/CallStack.cpp
구현
CallStack를 사용하려면 Android.bp
의 shared library에 다음과 같이 libutils
가 추가되어야 합니다.
shared_libs: [
"libutils"
]
다음과 같이 header를 선언하고, CallStack::logStack()
처럼 static 함수를 호출하면 callstack이 출력됩니다.
#include <utils/CallStack.h>
void function() {
....
CallStack::logStack("LOG_TAG");
}
logStack()
의 코드는 다음과 같습니다. 인자가 3개이지만 2개는 default 값이 설정되어있습니다.
static void ALWAYS_INLINE logStack(const char* logtag, CallStack* stack = getCurrent().get(),
android_LogPriority priority = ANDROID_LOG_DEBUG) {
if (reinterpret_cast<uintptr_t>(logStackInternal) != 0 && stack != nullptr) {
logStackInternal(logtag, stack, priority);
} else {
ALOG(LOG_WARN, logtag, "CallStack::logStackInternal not linked");
}
}
만약 다음과 같이 2번째 인자에 getCurrent(5)
처럼 설정하면 callstack에서 index 0~4번 라인은 출력되지 않고 5번 라인부터 출력이 됩니다.
CallStack::logStack("LOG_TAG", getCurrent(5).get());
Recommended Posts:
- AIDEGen으로 IDE에서 Android Framework 개발
- Android - adb shell input 명령어 사용 방법
- Android - App VersionCode, VersionName 등 설치 정보 확인
- Android - Call Stack 출력하는 방법
- Android 앱의 SQLite DB 테이블 확인
- Java 코드를 DEX로 변환, 안드로이드 디바이스에서 실행
- Android - adb로 실행 중인 프로세스, 쓰레드 리스트 & 메모리 정보 확인
- Android - PlayStore 앱 설치(다운로드) 화면으로 이동하는 방법
- Android - 파일의 MimeType(확장자) 가져오는 방법
- Mockito cannot mock/spy final class 에러 해결 방법
- Android Studio에서 Google Test로 C++ unit 테스트 작성
- Android Emulator에서 adb remount 하는 방법 (Writable)
- 안드로이드 스튜디오, custom framework.jar로 빌드하기