پروژه خود را اشکال زدایی کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
اشکال زدایی خرابی های بومی
اگر برای درک یک خرابی بومی یا سنگ قبر مشکل دارید، Debugging Native Platform Android Code مقدمه خوبی است.
برای کاتالوگ کاملتر از انواع رایج خرابی و نحوه بررسی آنها، به تشخیص خرابیهای بومی مراجعه کنید.
ابزار ndk-stack می تواند به نماد خرابی های شما کمک کند. میتوانید خرابیها را در Android Studio همانطور که در سند کلی «اشکالزدایی» برنامهتان توضیح داده شده است، اشکالزدایی کنید. اگر ترجیح می دهید از خط فرمان استفاده کنید، ndk-gdb به شما امکان می دهد gdb
یا lldb
از پوسته خود متصل کنید.
دسترسی مستقیم به آثار سنگ قبر را برای برنامهها فراهم کنید
با شروع Android 12 (سطح API 31)، میتوانید از طریق روش ApplicationExitInfo.getTraceInputStream()
به سنگ قبر اصلی خرابی برنامه خود به عنوان بافر پروتکل دسترسی داشته باشید. بافر پروتکل با استفاده از این طرح سریالی می شود. پیش از این، تنها راه دسترسی به این اطلاعات از طریق پل اشکال زدایی اندروید (adb) بود.
در اینجا مثالی از نحوه پیاده سازی آن در برنامه خود آورده شده است:
ActivityManager activityManager: ActivityManager = getSystemService(Context.ACTIVITY_SERVICE);
MutableList<ApplicationExitInfo> exitReasons = activityManager.getHistoricalProcessExitReasons(/* packageName = */ null, /* pid = */ 0, /* maxNum = */ 5);
for (ApplicationExitInfo aei: exitReasons) {
if (aei.getReason() == REASON_CRASH_NATIVE) {
// Get the tombstone input stream.
InputStream trace = aei.getTraceInputStream();
// The tombstone parser built with protoc uses the tombstone schema, then parses the trace.
Tombstone tombstone = Tombstone.parseFrom(trace);
}
}
اشکال زدایی مشکلات حافظه بومی
ضد عفونی کننده آدرس (HWASan/ASan)
HWAddress Sanitizer (HWASan) و Address Sanitizer (ASan) مشابه Valgrind هستند، اما به طور قابل توجهی سریعتر و بسیار بهتر در Android پشتیبانی می شوند.
اینها بهترین گزینه شما برای رفع اشکال خطاهای حافظه در اندروید هستند.
اشکال زدایی Malloc
برای توضیح کامل گزینههای داخلی کتابخانه C برای اشکالزدایی مشکلات حافظه بومی، Malloc Debug و Native Memory Tracking با استفاده از libc Callbacks را ببینید.
قلاب مالوک
اگر میخواهید ابزارهای خود را بسازید، libc اندروید از رهگیری همه تماسهای تخصیص/رایگانی که در طول اجرای برنامه اتفاق میافتد نیز پشتیبانی میکند. برای دستورالعمل های استفاده به مستندات malloc_hooks مراجعه کنید.
آمار Malloc
Android از پسوندهای mallinfo(3) و malloc_info(3) برای <malloc.h>
پشتیبانی میکند.
عملکرد malloc_info
در Android 6.0 (Marshmallow) و بالاتر موجود است و طرح XML آن در هدر malloc.h Bionic مستند شده است.
پروفایل کردن
برای پروفایل CPU کد بومی، می توانید از Simpleperf استفاده کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Debug your project\n\nDebug native crashes\n--------------------\n\nIf you're struggling to understand a native crash dump or tombstone,\n[Debugging Native Android Platform Code](https://source.android.com/devices/tech/debug/index.html)\nis a good introduction.\n\nFor a fuller catalog of common types of crash and how to investigate them, see\n[Diagnosing Native Crashes](https://source.android.com/devices/tech/debug/native-crash).\n\nThe [ndk-stack](/ndk/guides/ndk-stack) tool can help symbolize your crashes.\nYou can debug crashes in Android Studio as described in the general\n[Debug your app](/studio/debug) documentation. If you prefer to use the\ncommand-line, [ndk-gdb](/ndk/guides/ndk-gdb) lets you attach either `gdb` or\n`lldb` from your shell.\n\n### Provide apps direct access to tombstone traces\n\nStarting in Android 12 (API level 31), you can access your app's native crash\ntombstone as a\n[protocol buffer](https://developers.google.com/protocol-buffers/) through the\n[`ApplicationExitInfo.getTraceInputStream()`](/reference/android/app/ApplicationExitInfo#getTraceInputStream())\nmethod. The protocol buffer is serialized using [this schema](https://android.googlesource.com/platform/system/core/+/refs/heads/main/debuggerd/proto/tombstone.proto).\nPreviously, the only way to get access to this information was through the\n[Android Debug Bridge](/studio/command-line/adb) (adb).\n\nHere's an example of how to implement this in your app: \n\n ActivityManager activityManager: ActivityManager = getSystemService(Context.ACTIVITY_SERVICE);\n MutableList\u003cApplicationExitInfo\u003e exitReasons = activityManager.getHistoricalProcessExitReasons(/* packageName = */ null, /* pid = */ 0, /* maxNum = */ 5);\n for (ApplicationExitInfo aei: exitReasons) {\n if (aei.getReason() == REASON_CRASH_NATIVE) {\n // Get the tombstone input stream.\n InputStream trace = aei.getTraceInputStream();\n // The tombstone parser built with protoc uses the tombstone schema, then parses the trace.\n Tombstone tombstone = Tombstone.parseFrom(trace);\n }\n }\n\nDebug native memory issues\n--------------------------\n\n### Address Sanitizer (HWASan/ASan)\n\n[HWAddress Sanitizer](/ndk/guides/hwasan) (HWASan) and\n[Address Sanitizer](/ndk/guides/asan) (ASan) are similar to Valgrind, but\nsignificantly faster and much better supported on Android.\n\nThese are your best option for debugging memory errors on Android.\n\n### Malloc debug\n\nSee\n[Malloc Debug](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_debug/README.md)\nand\n[Native Memory Tracking using libc Callbacks](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_debug/README_api.md)\nfor a thorough description of the C library's built-in options for debugging\nnative memory issues.\n\n### Malloc hooks\n\nIf you want to build your own tools, Android's libc also supports intercepting\nall allocation/free calls that happen during program execution. See the\n[malloc_hooks documentation](https://android.googlesource.com/platform/bionic/+/main/libc/malloc_hooks/README.md)\nfor usage instructions.\n\n### Malloc statistics\n\nAndroid supports the\n[mallinfo(3)](http://man7.org/linux/man-pages/man3/mallinfo.3.html)\nand\n[malloc_info(3)](http://man7.org/linux/man-pages/man3/malloc_info.3.html)\nextensions to `\u003cmalloc.h\u003e`.\n\nThe `malloc_info` functionality is available in Android 6.0 (Marshmallow) and\nhigher and its XML schema is documented in Bionic's\n[malloc.h](https://android.googlesource.com/platform/bionic/+/main/libc/include/malloc.h)\nheader.\n\nProfiling\n---------\n\nFor CPU profiling of native code, you can use [Simpleperf](/ndk/guides/simpleperf)."]]