2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
strace 사용
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
strace는 프로세스에서 생성하는 시스템 호출, 그리고 이러한 시스템 호출이 무엇을 반환하는지 확인할 수 있게 해줍니다.
strace 빌드
strace를 빌드하려면 다음을 실행합니다.
mmma -j6 external/strace
실행 중인 프로세스에 연결
strace와 관련된 가장 간단하고 일반적인 사용 사례는 다음을 사용하여 실행 중인 프로세스에 연결하는 것입니다.
adb shell strace -f -p PID
-f
플래그는 프로세스의 모든 스레드, 그리고 나중에 생성되는 새 스레드에 연결되도록 strace에 지시합니다.
일반적인 프로세스는 다수의 시스템 호출을 생성하므로 strace man page를 검토하여 실제로 관심 있는 데이터만 수집하는 방법을 알아보는 것이 좋습니다.
앱에서 사용
앱에서 strace를 사용하려면 다음 단계를 따르세요.
- strace를 실행할 수 있도록 기기를 설정합니다. 루트인 상태에서 SELinux를 사용 중지하고 런타임을 재시작하여 seccomp 필터를 제거해야 합니다. 필터를 제거하지 않으면 strace가 다음이 실행하지 않습니다.
adb root
adb shell setenforce 0
adb shell stop
adb shell start
- strace 로그에 누구나 쓸 수 있는 디렉터리를 설정합니다. 이는 strace가 앱의 UID로 실행되기 때문입니다.
adb shell mkdir -m 777 /data/local/tmp/strace
- 추적할 프로세스를 선택하고 실행합니다.
adb shell setprop wrap.com.android.calendar '"logwrapper strace -f -o /data/local/tmp/strace/strace.com.android.calendar.txt"'
- 프로세스를 정상적으로 실행합니다.
zygote에 사용
strace를 zygote에 사용하려면 관련 init.rc
zygote 행을 수정합니다(adb shell setenforce 0
필요).
cd system/core/
patch -p1 <<EOF
--- a/rootdir/init.zygote32.rc
+++ b/rootdir/init.zygote32.rc
@@ -1,4 +1,4 @@
-service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
+service zygote /system/bin/strace -o /data/local/tmp/zygote.strace /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
class main
socket zygote stream 660 root system
onrestart write /sys/android_power/request_state wake
EOF
Android 부팅 중에 strace 로그 가져오기
Android 부팅 도중에 strace 로그를 가져오려면 다음과 같은 변경사항을 적용합니다.
- 프로세스 이름이
zygote
에서 strace
로 변경되므로 strace
의 누락된 SELinux file_context
로 인해 서비스가 시작되지 않을 수 있습니다. 해결 방법은 system/sepolicy/private/file_contexts
의 strace에 새 행을 추가하고 원본 파일 컨텍스트를 복사하는 것입니다. 예:
/dev/socket/zygote u:object_r:zygote_socket:s0
+ /system/bin/strace u:object_r:zygote_socket:s0
- 커널 또는 bootconfig 매개변수를 추가한 다음 SELinux 허용 모드에서 기기를 부팅합니다.
androidboot.selinux=permissive
를 BOARD_KERNEL_CMDLINE
에 추가하거나 Android 12의 커널 버전 5.10 이상에서 BOARD_BOOTCONFIG
에 추가하면 됩니다.
(이 변수는 build/core/Makefile
에서는 읽기 전용이지만 /device/*/BoardConfig
아래에서 항상 사용 가능함)
/device/google/marlin/sailfish/BoardConfig.mk
의 Pixel(sailfish) 기기
예시:
- BOARD_KERNEL_CMDLINE := .... androidboot.hardware=sailfish ...
+BOARD_KERNEL_CMDLINE := .... androidboot.hardware=sailfish ... androidboot.selinux=permissive
변경 후에 부팅 이미지를 빌드하고 플래시하면 기기가 허용 모드에서 부팅됩니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Use strace\n\n[Strace](https://strace.io) enables you to see the system calls a\nprocess makes and what those system calls return.\n\nBuild strace\n------------\n\nTo build strace, run the following: \n\n```\nmmma -j6 external/strace\n```\n\nAttach to a running process\n---------------------------\n\nThe simplest and most common use case for strace is to attach it to a running\nprocess, which you can do with: \n\n```\nadb shell strace -f -p PID\n```\n\nThe `-f` flag tells strace to attach to all the threads in the\nprocess, plus any new threads spawned later.\n\nA typical process makes a lot of system calls, so you'll want to review the\n[strace man page](http://man7.org/linux/man-pages/man1/strace.1.html)\nto learn how to collect only data you're actually interested in.\n\nUse on an app\n-------------\n\nTo use strace on an app:\n\n1. Set up the device so that you can run strace. You need to be root, disable SELinux, and restart the runtime to remove the seccomp filter that will otherwise prevent strace from running: \n\n adb root\n adb shell setenforce 0\n adb shell stop\n adb shell start\n\n2. Set up a world-writable directory for strace logs, because strace will be running under the app's uid: \n\n adb shell mkdir -m 777 /data/local/tmp/strace\n\n3. Choose the process to trace and launch it: \n\n ```\n adb shell setprop wrap.com.android.calendar '\"logwrapper strace -f -o /data/local/tmp/strace/strace.com.android.calendar.txt\"'\n ```\n4. Launch the process normally.\n\nUse on the zygote\n-----------------\n\nTo use strace on the zygote, fix the relevant `init.rc` zygote\nline (requires `adb shell setenforce 0`): \n\n cd system/core/\n patch -p1 \u003c\u003cEOF\n --- a/rootdir/init.zygote32.rc\n +++ b/rootdir/init.zygote32.rc\n @@ -1,4 +1,4 @@\n -service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server\n +service zygote /system/bin/strace -o /data/local/tmp/zygote.strace /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server\n class main\n socket zygote stream 660 root system\n onrestart write /sys/android_power/request_state wake\n EOF\n\nGet strace logs during Android boot\n-----------------------------------\n\nTo get strace logs during Android boot, make the following changes:\n\n- Since the process name changes from `zygote` to `strace`, the given service may fail to start due to the missing SELinux `file_context` for `strace`. The solution is to add a new line for strace in `system/sepolicy/private/file_contexts` and copy the original file context over. Example: \n\n ```\n /dev/socket/zygote u:object_r:zygote_socket:s0\n + /system/bin/strace u:object_r:zygote_socket:s0\n ```\n- Add kernel or bootconfig parameter, then boot the device in SELinux permissive mode. You can do this by adding `androidboot.selinux=permissive`to `BOARD_KERNEL_CMDLINE`, or to `BOARD_BOOTCONFIG` in Android 12 with kernel version 5.10 or greater. (This variable becomes read-only in `build/core/Makefile` but is always available under `/device/*/BoardConfig`.) \n\n Example for the Pixel (sailfish) device in `/device/google/marlin/sailfish/BoardConfig.mk`: \n\n ```\n - BOARD_KERNEL_CMDLINE := .... androidboot.hardware=sailfish ...\n +BOARD_KERNEL_CMDLINE := .... androidboot.hardware=sailfish ... androidboot.selinux=permissive\n ```\n After making the change, build and flash the boot image and the device will boot in permissive mode."]]