{"id":6486,"date":"2015-05-20T05:46:08","date_gmt":"2015-05-20T04:46:08","guid":{"rendered":"http:\/\/sysprogs.com\/w\/?p=6486"},"modified":"2016-07-16T22:21:43","modified_gmt":"2016-07-16T21:21:43","slug":"about-android-toolchains-and-system-images","status":"publish","type":"post","link":"https:\/\/sysprogs.com\/w\/about-android-toolchains-and-system-images\/","title":{"rendered":"About Android toolchains and system images"},"content":{"rendered":"<p>Native Android debugging has always been somewhat tricky. In addition\u00a0to common source\u00a0path issues and random gdbserver failures, many VisualGDB users reported that\u00a0they can debug code on their device only if they use certain versions of NDK toolchains.\u00a0To figure it out once and for all we have added a VisualGDB feature that allows testing a certain Android\u00a0device\u00a0with all\u00a0the\u00a0toolchains available in the NDK. To get a general overview we have tested the\u00a0standard\u00a0ARM emulator images that\u00a0come with the Android SDK.<br \/>\n<!--more--><\/p>\n<h2>Android 4.x<\/h2>\n<p>On most Android 4.x ARM images (except the latest 4.4)\u00a0all toolchains\u00a0can debug the native code, but fail to\u00a0detect\u00a0shared library loads and load the symbols. As a result, you normally cannot debug the code running during startup of\u00a0the app. A workaround is to manually find the address of the &#8220;library loaded&#8221; callback, set a breakpoint on it and run the &#8220;sharedlibrary&#8221; command when it&#8217;s hit. VisualGDB does that automatically as doing it manually would be\u00a0a significant annoyance.\u00a0However, that&#8217;s not all: some\u00a0combinations of GDB and the Android linker need the breakpoint address to\u00a0include the thumb mode bit, making it even more complicated. E.g. on Android 4.0.3 the 4.6 toolchain does no need the thumb adjustment, while the 4.8 and 4.9 toolchains need it:<a href=\"http:\/\/sysprogs.com\/w\/wp-content\/uploads\/2015\/05\/1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6489\" src=\"http:\/\/sysprogs.com\/w\/wp-content\/uploads\/2015\/05\/1.png\" alt=\"1\" width=\"733\" height=\"535\" srcset=\"https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2015\/05\/1.png 733w, https:\/\/sysprogs.com\/w\/wp-content\/uploads\/2015\/05\/1-300x219.png 300w\" sizes=\"(max-width: 733px) 100vw, 733px\" \/><\/a>Here&#8217;s a table that\u00a0summarizes how the NDK toolchains perform on the 4.x Android ARM images. Workaround A\u00a0means that a manual breakpoint without Thumb bit adjustment is required. Workaround B means that a breakpoint with the Thumb adjustment bit is needed:<\/p>\n<table>\n<tbody>\n<tr>\n<td>Android\u00a0version<\/td>\n<td>4.6 Toolchain<\/td>\n<td>4.8 Toolchain<\/td>\n<td>4.9 Toolchain<\/td>\n<\/tr>\n<tr>\n<td>4.0.3<\/td>\n<td>Workaround A<\/td>\n<td>Workaround B<\/td>\n<td>Workaround B<\/td>\n<\/tr>\n<tr>\n<td>4.1.2<\/td>\n<td>Workaround A<\/td>\n<td>Workaround B<\/td>\n<td>Workaround B<\/td>\n<\/tr>\n<tr>\n<td>4.2.2<\/td>\n<td>Workaround A<\/td>\n<td>Workaround A<\/td>\n<td>Workaround A<\/td>\n<\/tr>\n<tr>\n<td>4.3.1<\/td>\n<td>Workaround A<\/td>\n<td>Workaround A<\/td>\n<td>Workaround A<\/td>\n<\/tr>\n<tr>\n<td>4.4.1<\/td>\n<td>Out-of-the-box<\/td>\n<td>Out-of-the-box<\/td>\n<td>Out-of-the-box<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>From the table\u00a0above it might look like the problems are over for Android 4.4 and later, but unfortunately this is not the case.<\/p>\n<h2>Android 5.x<\/h2>\n<p>While the newest Android 5.1 actually works without needing any special workarounds, the earlier 5.0 release still needs the same type of workaround as 4.2 and 4.3:<\/p>\n<table>\n<tbody>\n<tr>\n<td>Android\u00a0version<\/td>\n<td>4.6 Toolchain<\/td>\n<td>4.8 Toolchain<\/td>\n<td>4.9 Toolchain<\/td>\n<\/tr>\n<tr>\n<td>5.0.1<\/td>\n<td>Workaround A<\/td>\n<td>Workaround A<\/td>\n<td>Workaround A<\/td>\n<\/tr>\n<tr>\n<td>5.1.1<\/td>\n<td>Out-of-the-box<\/td>\n<td>Out-of-the-box<\/td>\n<td>Out-of-the-box<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Recommendations<\/h2>\n<p>If you want to get stable debugging experience with your native Android code, pick either Android 4.4.1 or 5.1.1 as your primary OS.\u00a0If you debug other Android versions with VisualGDB, it will automatically detect and apply the correct workaround, but that will\u00a0reduce the overall performance.<\/p>\n<p>Another good idea would be to use an x86 device that does not have the symbol loading problem. You can also use\u00a0VirtualBox or <a href=\"http:\/\/visualgdb.com\/tutorials\/android\/vmware\/\">VMWare to setup \u00a0an\u00a0x86 Android VM<\/a>\u00a0and use it for debugging.\u00a0This will be much faster than the default\u00a0Android emulator (even when\u00a0accelerated by HAXM).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Native Android debugging has always been somewhat tricky. In addition\u00a0to common source\u00a0path issues and random gdbserver failures, many VisualGDB users reported that\u00a0they can debug code on their device only if they use certain versions of NDK toolchains.\u00a0To figure it out once and for all we have added a VisualGDB feature that allows testing a certain &hellip; <a href=\"https:\/\/sysprogs.com\/w\/about-android-toolchains-and-system-images\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">About Android toolchains and system images<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/posts\/6486"}],"collection":[{"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/comments?post=6486"}],"version-history":[{"count":11,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/posts\/6486\/revisions"}],"predecessor-version":[{"id":8568,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/posts\/6486\/revisions\/8568"}],"wp:attachment":[{"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/media?parent=6486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/categories?post=6486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sysprogs.com\/w\/wp-json\/wp\/v2\/tags?post=6486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}