
Its appearance has made a real revolution in the market of mobile devices, suppressing the hegemony of Microsoft Widows Mobile, Apple iOS and Symbian OS, in consequence of becoming the most popular and mass operating system for mobile systems in the world. Until now, the popularity of the system continues . Over the past six years, Android has greatly expanded and evolved, and the range of supported devices continues to grow. Now this operating system is used not only in mobile phones, but also in tablets, TVs, music players, cameras, laptops, nettops and other exotic things, including military equipment. The fillings of these devices can differ quite noticeably from each other: over the past years, the list of supported architectures has expanded from ARM to MIPS and x86, support has been provided for various peripherals, not to mention the evolving Android API.

For a start, a small remark: Android, as you know, is a Unix-like operating system, very similar to regular Linux or BSD, and most Android source code follows a license, ASL2.0 . Who worked with Android, knows that a considerable number of Android modules have moved from BSD to a greater extent than from Linux. However, everything related to native-code and architecture, if not to go into details, is very close and known to all those who used Linux. Therefore, it is quite possible to use exactly the same or similar tools for developing and debugging code as for Unix-like systems. In the case of compilers, these are gcc, clang (llvm), icc and others. The same can be said about the whole GCC toolchain and some other utilities that are either already ported or not very difficult to port.





bash-4.2$ # hello_world.c bash-4.2$ cat ./hello_world.c #include <stdio.h> int main(void) { printf(“Hello, World!\n”); return 0; } bash-4.2$ # Android, gcc 4.7 x86, 18 bash-4.2$ /users/NDK_current/toolchains/x86-4.7/prebuilt/linux-x86/bin/i686-linux-android-gcc –sysroot=/users/NDK_current/platforms/android-18/arch-x86 ./hello_world.c -o ./hello_world.exe bash-4.2$ echo $? 0 bash-4.2$ #, bash-4.2$ # bash-4.2$ ./hello_world.exe bash-4.2$ #, bash-4.2$ # bash-4.2$ adb devices List of devices attached 0146AFFC18020012 device bash-4.2$ #, - bash-4.2$ adb -s 0146AFFC18020012 shell echo 'Hello, Android!' Hello, Android! bash-4.2$ #, bash-4.2$ export ANDROID_SERIAL=0146AFFC18020012 bash-4.2$ # bash-4.2$ adb shell echo 'Hello, Android!' Hello, Android! bash-4.2$ #- , bash-4.2$ adb push ./hello_world.exe /data/local/ bash-4.2$ #- , bash-4.2$ adb shell /data/local/hello_world.exe Hello, World! bash-4.2$ #adb , , , bash-4.2$ adb shell “/data/local/hello_world.exe && echo $?” Hello, World! 0 bash-4.2$ #, bash-4.2$ # , bash-4.2$ # , (linux, mac, windows) bash-4.2$ # , - bash-4.2$ # , -static /users//NDK_current/toolchains/x86-4.7/prebuilt/linux-x86/bin/i686-linux-android-gcc –sysroot=/users/ /NDK_current/platforms/android-18/arch-x86 -static ./hello_world.c -o ./hello_world.exe bash-4.2$ echo $? 0 bash-4.2$ #, - bash-4.2$ ./hello_world.exe Hello, World! bash-4.2$ echo $? 0 bash-4.2$ #, bash-4.2$ bash-4.2$ # g++ bash-4.2$ cat ./hello_world.C #include <iostream> int main(void) { std::cout << “Hello, World!\n”; return 0; } bash-4.2$ # STL, bash-4.2$ # bash-4.2$ # , bash-4.2$ # , -l%STL_LIB% ! bash-4.2$ # _shared, _static bash-4.2$ # g++ -L, -I – gnustl/stlport/gabi bash-4.2$ /users/ /NDK_current/toolchains/x86-4.7/prebuilt/linux-x86/bin/i686-linux-android-g++ –sysroot=/users/NDK_current/platforms/android-18/arch-x86 -I/users/NDK_current/sources/cxx-stl/gnu-libstdc++/4.7/include -I/users/NDK_current/sources/cxx-stl/gnu-libstdc++/4.7/libs/x86/include -L/users//NDK_current/sources/cxx-stl/gnu-libstdc++/4.7/libs/x86 ./hello_world.C -o ./hello_world.exe -lgnustl_shared bash-4.2$ echo $? 0 bash-4.2$ #, - / / bash-4.2$ adb push ./hello_world.exe /data/local/ bash-4.2$ #- , bash-4.2$ adb shell “/data/local/hello_world.exe && echo $?” soinfo_link_image(linker.cpp:1635): could not load library “libgnustl_shared.so” needed by “/data/local/hello_world.exe”; caused by load_library(linker.cpp:745): library “libgnustl_shared.so” not foundCANNOT LINK EXECUTABLE bash-4.2$ # , bash-4.2$ #libgnustl_shared.so Android, bash-4.2$ adb push /users//NDK_current/sources/cxx-stl/gnu-libstdc++/4.7/libs/x86/libgnustl_shared.so /data/local/libgnustl_shared.so bash-4.2$ #, , LD_LIBRARY_PATH bash-4.2$ adb shell “export LD_LIBRARY_PATH=/data/local/:$LD_LIBRARY_PATH && /data/local/hello_world.exe && echo $\?” Hello, World! 0 bash-4.2$ # – /system/lib bash-4.2$ # bash-4.2$ adb shell “/data/local/hello_world.exe && echo $\?” Hello, World! 0 bash-4.2$ # ----------------------------------------------------------------------------- # Run the unit tests built against x86 bionic on an x86 host. # ----------------------------------------------------------------------------- ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86) ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) ifeq ($(TARGET_ARCH),x86) LINKER = linker else LINKER = linker64 endif # gtest needs ANDROID_DATA/local/tmp for death test output. # Make sure to create ANDROID_DATA/local/tmp if doesn't exist. # bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT. bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh if [ ! -d /system -o ! -d /system/bin ]; then \ echo "Attempting to create /system/bin"; \ sudo mkdir -p -m 0777 /system/bin; \ fi mkdir -p $(TARGET_OUT_DATA)/local/tmp cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin ANDROID_DATA=$(TARGET_OUT_DATA) \ ANDROID_ROOT=$(TARGET_OUT) \ LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \ $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests endif endif bash-4.2$ # , , - , bash-4.2$ #, , coverage bash-4.2$ # , , bash-4.2$ # , -fprofile-dir=%android_exec_dir% bash-4.2$ # , , GCOV_PREFIX GCOV_PREFIX_STRIP bash-4.2$ # , env adb ( shell adb shell %command% bash-4.2$ /users//NDK_current/toolchains/x86-4.7/prebuilt/linux-x86/bin/i686-linux-android-gcc –sysroot=/users//NDK_current/platforms/android-18/arch-x86 ./gcov-1.c -fprofile-arcs -fprofile-dir=. -ftest-coverage -lm -o ./gcov-1.exe bash-4.2$ adb push ./gcov-1.exe /data/local/gcov-1.exe bash-4.2$ #adb shell “export GCOV_PREFIX=/data/local && export GCOV_PREFIX_STRIP=13 && /data/local/gcov-1.exe && echo $\?” bash-4.2$ unset GCOV_PREFIX && unset GCOV_PREFIX_STRIP && cd /data/local && ./gcov-1.exe && echo $\?” 0 bash-4.2$ adb shell ls /data/local/gcov-1.gcda /data/local/gcov-1.gcda bash-4.2$ # bash-4.2$ adb pull /data/local/gcov-1.gcda . bash-4.2$ ls ./gcov-1.gcda ./gcov-1.gcda bash-4.2$ # NDK gcov, , bash-4.2$ /users/NDK_current/toolchains/x86-4.7/prebuilt/linux-x86/bin/i686-linux-android-gcov gcov-1.gcda File 'gcov-1.c' Lines executed:100.00% of 6 Creating 'gcov-1.c.gcov' bash-4.2$ 
bash-4.2$ # NDK , , gdb bash-4.2$ # -g, bash-4.2$ /users /NDK_current/toolchains/x86-4.7/prebuilt/linux-x86/bin/i686-linux-android-gcc –sysroot=/users/NDK_current/platforms/android-18/arch-x86 ./hello_world.c -o ./hello_world.exe bash-4.2$ adb push ./hello_world.exe /data/local/hello_world.exe bash-4.2$ adb shell gdbserver :5039 /data/local/hello_world.exe & Process /data/local/hello_world.exe created; pid = 29744 Listening on port 5039 bash-4.2$ adb forward tcp:5039 tcp:5039 bash-4.2$ /users/NDK_current/toolchains/x86-4.7/prebuilt/linux-x86/bin/i686-linux-android-gdb hello_world.exe Remote debugging from host 127.0.0.1 libthread_db:td_ta_new: Probing system for platform bug. libthread_db:td_ta_new: Running as root, nothing to do. Hello, World! Child exited with status 0 GDBserver exiting bash-4.2$ cat test.gdb set sysroot /users/igveresx set solib-absolute-prefix /users/igveresx/symbols/ set solib-search-path /users/igveresx/symbols/lib set auto-solib-add on target remote :5039 stepi stepi c Quit bash-4.2$ # logcat bash-4.2$ adb logcat *:E >logcat.log & bash-4.2$ tail -5 logcat.log E/Intel PowerHAL( 2093): Error in reading vsync hint E/Intel PowerHAL( 2093): Error reading from /sys/devices/system/cpu/cpufreq/interactive/vsync_count: No such file or directory E/Intel PowerHAL( 2093): Error in reading vsync count E/Intel PowerHAL( 2093): Error reading from /sys/devices/system/cpu/cpufreq/interactive/touch_event: No such file or directory E/Intel PowerHAL( 2093): Error in reading vsync hint bash-4.2$ # kernel bash-4.2$ adb shell dmesg | tail -5 <6>[245665.256198] intel_mdf_battery msic_battery: vbus_volt:4974 <6>[245665.265332] intel_mdf_battery msic_battery: vbatt:4116250 temp:300 <4>[245669.213759] kct_daemon: loop. <4>[245673.213561] kct_daemon: loop. <4>[245677.213379] kct_daemon: loop. bash-4.2$ adb shell 'cat /proc/kmsg' >kmsg.log bash-4.2$ tail -5 kmsg.log <4>[245673.213561] kct_daemon: loop. <4>[245677.213379] kct_daemon: loop. <4>[245681.213248] kct_daemon: loop. <4>[245685.213083] kct_daemon: loop. <4>[245689.212932] kct_daemon: loop. bash-4.2$ 
runtest –target_board = androideabi
set rootme “.” set tmpdir “.” set srcdir “/path/to/gcc_%version%_release/gcc/testsuite” set CFLAGS “” set CXXFLAGS “” set GDB “/path/to/GDB_UNDER_TEST” set GCOV_UNDER_TEST “/path/to/GCOV_UNDER_TEST” set GCC_UNDER_TEST “/path/to/GCC_UNDER_TEST” set GXX_UNDER_TEST “/path/to/GXX_UNDER_TEST” set GFORTRAN_UNDER_TEST “no” set OBJC_UNDER_TEST “no” set libiconv “” set HOSTCC “gcc” set HOSTCFLAGS “” set TESTING_IN_BUILD_TREE 1 set GMPINC “” set ENABLE_LTO 1 set HAVE_LIBSTDCXX_V3 1 set host_triplet i686-pc-linux-gnu set build_triplet i686-pc-linux-gnu set target_triplet i686-pc-linux-android-gnu set target_alias i686-pc-linux-android set android_tmp_dir “/temporary/folder/on/device/with/executable/permissions” set bridge_tmp_dir “/temporary/folder/on/device/with/executable/permissions” append boards_dir “/path/to/share/dejagnu/baseboards” export ADB_SERIAL=$ANDROID_SERIAL make -j $parallel check DEJAGNU=/path/to/site.exp RUNTESTFLAGS=”–target_board=androideabi” #!/bin/bash /path/to/NDK_folder/toolchains/$arch-%compiler_version%/prebuilt/linux-x86/bin/%arch_prefix%-linux-android-gcc –sysroot=/path/to/NDK_folder/platforms/android-${device_platform}/arch-$arch “$@” #!/bin/bash echo $@ | grep ” \-nostdlib” 1>/dev/null 2>/dev/null if [ $? != 0 ]; then echo $@ | grep ” \-static” 1>/dev/null 2>/dev/null if [ $? != 0 ]; then /path/to/NDK_folder/toolchains/$arch-%compiler_version%/prebuilt/linux-x86/bin/%arch_prefix%-linux-android-g++ –sysroot=/path/to/NDK_folder/platforms/android-${device_platform}/arch-$arch -I/path/to/NDK_folder/sources/cxx-stl/%stl lib folder%/%compiler version%/include -I/path/to/NDK_folder/sources/cxx-stl/%stl lib folder%/%compiler version%/libs/$arch/include -L/path/to/NDK_folder/sources/cxx-stl/%stl lib folder%/%compiler version%/libs/$arch “$@” -lgnustl_shared else /path/to/NDK_folder/toolchains/$arch-%compiler_version%/prebuilt/linux-x86/bin/%arch_prefix%-linux-android-g++ –sysroot=/path/to/NDK_folder/platforms/android-${device_platform}/arch-$arch -I/path/to/NDK_folder/sources/cxx-stl/%stl lib folder%/%compiler version%/include -I/path/to/NDK_folder/sources/cxx-stl/%stl lib folder%/%compiler version%/libs/$arch/include -L/path/to/NDK_folder/sources/cxx-stl/%stl lib folder%/%compiler version%/libs/$arch “$@” -lgnustl_static fi else /path/to/NDK_folder/toolchains/$arch-%compiler_version%/prebuilt/linux-x86/bin/%arch_prefix%-linux-android-g++ –sysroot=/path/to/NDK_folder/platforms/android-${device_platform}/arch-$arch -I/path/to/NDK_folder/sources/cxx-stl/%stl lib folder%/%compiler version%/include -I/path/to/NDK_folder/sources/cxx-stl/%stl lib folder%/%compiler version%/libs/$arch/include -L/path/to/NDK_folder/sources/cxx-stl/%stl lib folder%/%compiler version%/libs/$arch “$@” fi adb push perf /data/local/ adb shell cd /data/local chmod 777 perf perf record ./coremark.exe 0×0 0×0 0×66 0 7 1 2000 # or any arguments required # data saved at ./perf.data</li> export PAGER=cat # otherwise it will look for “less” perf report 


adb shell echo userspace > /sys/devices/system/cpu/cpuX/cpufreq/scaling_governor echo 2000000 > /sys/devices/system/cpu/cpuX/cpufreq/scaling_max_freq echo 2000000 > /sys/devices/system/cpu/cpuX/cpufreq/scaling_min_freq [, [[, ar, arp, awk, base64, basename, bbconfig, beep, blkid, blockdev, bootchartd, bunzip2, bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod, chown, chpst, chroot, chrt, chvt, cksum, clear, cmp, comm, cp, cpio, crond, crontab, cttyhack, cut, dc, dd, deallocvt, depmod, devmem, diff, dirname, dmesg, dnsd, dos2unix, dpkg, dpkg-deb, du, dumpkmap, echo, ed, egrep, env, envdir, envuidgid, expand, expr, fakeidentd, false, fbset, fbsplash, fdflush, fdformat, fdisk, fgconsole, fgrep, find, findfs, flash_lock, flash_unlock, flashcp, flock, fold, free, freeramdisk, fsync, ftpd, ftpget, ftpput, fuser, getopt, grep, gunzip, gzip, halt, hd, hdparm, head, hexdump, httpd, hwclock, ifconfig, ifdown, ifup, init, inotifyd, insmod, install, iostat, ip, ipaddr, ipcalc, iplink, iproute, iprule, iptunnel, klogd, less, linuxrc, ln, loadkmap, losetup, lpd, lpq, lpr, ls, lsattr, lsmod, lsof, lspci, lsusb, lzcat, lzma, lzop, lzopcat, makedevs, makemime, man, md5sum, mdev, mesg, mkdir, mkfifo, mknod, mkswap, mktemp, modinfo, modprobe, more, mpstat, mv, nbd-client, nc, netstat, nice, nmeter, nohup, od, openvt, patch, pidof, ping, pipe_progress, pmap, popmaildir, poweroff, powertop, printenv, printf, ps, pscan, pstree, pwd, pwdx, raidautorun, rdev, readlink, readprofile, realpath, reboot, reformime, renice, reset, resize, rev, rm, rmdir, rmmod, route, rpm, rpm2cpio, rtcwake, run-parts, runsv, runsvdir, rx, script, scriptreplay, sed, sendmail, seq, setconsole, setkeycodes, setlogcons, setserial, setsid, setuidgid, sha1sum, sha256sum, sha3sum, sha512sum, showkey, sleep, smemcap, softlimit, sort, split, start-stop-daemon, strings, stty, sum, sv, svlogd, switch_root, sync, sysctl, tac, tail, tar, tcpsvd, tee, telnet, telnetd, test, tftp, tftpd, time, timeout, top, touch, tr, traceroute, true, ttysize, tunctl, tune2fs, udpsvd, uname, uncompress, unexpand, uniq, unix2dos, unlzma, unlzop, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, volname, watch, wc, wget, which, whoami, whois, xargs, xz, xzcat, yes, zcatSource: https://habr.com/ru/post/204642/
All Articles