Giter Site home page Giter Site logo

adeb's Introduction

Note: The project is not maintained for new Android and Debian releases, but likely works with little effort. I suggest reaching out to me if you are interested in maintaining it and I will decide.

adeb

adeb (also known as androdeb) provides a powerful Linux shell environment where one can run popular and mainstream Linux tracing, compiling, editing and other development tools on an existing Android device. All the commands typically available on a modern Linux system are supported in adeb.

Usecases

  1. Powerful development environment with all tools ready to go (editors, compilers, tracers, perl/python etc) for your on-device development.

  2. No more cross-compiler needed: Because it comes with gcc and clang, one can build target packages natively without needing to do any cross compilation. We even ship git, and have support to run apt-get to get any missing development packages from the web.

  3. Using these one can run popular tools such as BCC that are difficult to run in an Android environment due to lack of packages, dependencies and cross-compilation needed for their operation. Check BCC on Android using adeb for more information on that.

  4. No more crippled tools: Its often a theme to build a static binary with features disabled, because you couldn't cross-compile the feature's dependencies. One classic example is perf. However, thanks to adeb, we can build perf natively on device without having to cripple it.

Requirements for running

Target: An ARM64 android N or later device which has "adb root" supported. Typically this is a build in a userdebug configuration. Device should have atleast 2 GB free space in the data partition. If you would like to use other architectures, see the Other Architectures section.

You can also use ssh to run on non-android systems. The system must still be rooted and has 2 GB of free space.

Host: A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. Host needs debootstrap and qemu-debootstrap packages. To install it, run sudo apt-get install qemu-user-static debootstrap. Other distributions may work but they are not tested.

Quick Start Instructions

  • First clone this repository into adeb and cd into it.
cd adeb

# Add some short cuts:
sudo ln -s $(pwd)/adeb /usr/bin/adeb

# Cached image downloads result in a huge speed-up. These are automatic if you
# cloned the repository using git. However, if you downloaded the repository
# as a zip file (or you want to host images elsewere), you could set the
# ADEB_REPO_URL environment variable in your bashrc file.
# Disclaimer: Google is not liable for the below URL and this
#             is just an example.
export ADEB_REPO_URL="github.com/joelagnel/adeb/"
  • Installing adeb onto your device: First make sure device is connected to system Then run, for the base image:
adeb prepare

The previous command only downloads and installs the base image. Instead if you want to download and install the full image, do:

adeb prepare --full
  • Now run adeb shell to enter your new environment!:
adeb shell
  • Once done, hit CTRL + D and you will exit out of the shell. To remove adeb from the device, run:
adeb remove

If you have multiple devices connected, please add -s <serialnumber>. Serial numbers of all devices connected can be obtained by adb devices.

  • To update an existing adeb clone on your host, run:
adeb git-pull
  • To use ssh instead of adb to communicate with the target
adeb --ssh <uri> --sshpass <pass> <cmd>

If you use keys to authenticate then you can omit --sshpass option. If you don't use keys you can still omit --sshpass option but you'd need to keep an eye to enter the password at the right moments when prompted or it'll timeout.

The first time you connect to the target make sure to ssh outside of adeb first to add it to your known_hosts.

More advanced usage instructions

Build and prepare device with a custom rootfs locally:

The adeb fs will be prepared locally by downloading packages as needed:

adeb prepare --build

This is unlike the default behavior, where the adeb rootfs is itself pulled from the web.

If you wish to do a full build (that is locally prepare a rootfs with all packages, including bcc, then do):

adeb prepare --full --build

Build/install a base image with BCC:

adeb prepare --bcc --build

Note: BCC is built from source.

Extract the FS from the device, after its prepared:

adeb prepare --full --buildtar /path/

After device is prepared, it will extract the root fs from it and store it as a tar archive at /path/adeb-fs.tgz. This can be used later.

Use a previously prepared adeb rootfs tar from local:

adeb prepare --archive /path/adeb-fs.tgz

Build a standalone raw EXT4 image out of the FS:

adeb prepare --build-image /path/to/image.img

This can then be passed to Qemu as -hda. Note: This option doesn't need a device connected.

How to use adeb for other Architectures (other than ARM64)

By default adeb assumes the target Android device is based on ARM64 processor architecture. For other architectures, use the --arch and --build option. For example for x86_64 architecture, run:

adeb prepare --build --arch amd64

Note: For arch other than ARM 64-bit, you have to pass the --build option to adeb. Without this, adeb tries to download an ARM image and will not work. TODO: We should auto detect this issue and provide an informative error. This is because we only provide pre-built filesystems for ARM 64-bit at the moment.

Common Trouble shooting

  1. Installing g++ with apt-get install g++ fails.

Solution: Run adeb shell apt-get update after the adeb prepare stage.

  1. It's too slow to use debootstrap to create debian fs

Solution: Use a local mirror, for example in China you could use https://mirror.tuna.tsinghua.edu.cn/debian/ instead of debian official website http://deb.debian.org/debian/

adeb's People

Contributors

ayrx avatar duyuchao avatar erickreyesr avatar jellybeans avatar joelagnel avatar liucintel avatar mspecter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adeb's Issues

`adeb prepare` or `adeb prepare --full` download failed

smith@smith-Inspiron-5545:~/adeb/adeb$ adeb prepare
adeb: v0.99g
--------------
16:05:32 - INFO : Looking for device..
16:05:32 - INFO : Preparing device...
16:05:32 - INFO : Doing a base install.
16:05:32 - INFO :
16:05:32 - INFO : Downloading Androdeb from the web...
16:05:32 - INFO :
% Total % Received % Xferd Average Speed Time Time Time Current
                             Dload  Upload   Total   Spent    Left  Speed

100 618 0 618 0 0 467 0 --:--:-- 0:00:01 --:--:-- 467
20 48.5M 20 9.8M 0 0 36543 0 0:23:13 0:04:43 0:18:30 0
20 48.5M 20 9.8M 0 0 36414 0 0:23:17 0:04:44 0:18:33 0

20 48.5M 20 9.8M 0 0 21247 0 0:39:55 0:08:08 0:31:47 0
curl: (56) OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104
16:05:41 - ERROR : Failed to download adeb release.

eBPF C: cannot use strcmp and strncmp

   I met an issue of cannot use strcmp(strcmp(key.comm, "xxx");), eBPF verify show below error, I traced strcmp realized in strcmp.S. 
   After I rewrite the strcmp function with C language, it works well, but I think this is inconvenient, so I want ask whether you have good idea, thank you.

========================error log============================
root@localhost:/# ./submit_bio.py
bpf: Failed to load program: Invalid argument
0: (79) r6 = *(u64 *)(r1 +0)
1: (b7) r1 = 0
2: (7b) *(u64 *)(r10 -8) = r1
3: (7b) *(u64 *)(r10 -16) = r1
4: (7b) *(u64 *)(r10 -24) = r1
5: (7b) *(u64 *)(r10 -32) = r1
6: (7b) *(u64 *)(r10 -40) = r1
7: (7b) *(u64 *)(r10 -48) = r1
8: (7b) *(u64 *)(r10 -56) = r1
9: (7b) *(u64 *)(r10 -64) = r1
10: (7b) *(u64 *)(r10 -72) = r1
11: (bf) r7 = r10
12: (07) r7 += -68
13: (bf) r1 = r7
14: (b7) r2 = 16
15: (85) call bpf_get_current_comm#16
16: (85) call bpf_get_current_pid_tgid#14
17: (63) *(u32 *)(r10 -52) = r0
18: (bf) r1 = r7
19: BUG_ld_00
invalid BPF_LD_IMM insn

Traceback (most recent call last):
File "./submit_bio.py", line 92, in
b.attach_kprobe(event="submit_bio", fn_name="print_submit_bio")
File "/usr/lib/python2.7/dist-packages/bcc/init.py", line 592, in attach_kprobe
fn = self.load_func(fn_name, BPF.KPROBE)
File "/usr/lib/python2.7/dist-packages/bcc/init.py", line 377, in load_func
(func_name, errstr))
Exception: Failed to load BPF program print_submit_bio: Invalid argument

Question: Should I be able to execute AOSP binaries via the adeb shell?

adeb is awesome in that I now have my usual zsh shell with vim working on my device (much like Termux on my phone), my original hope though was that I would get tools like ldd and be able to execute AOSP binaries via the adeb shell (and vice versa execute adeb binaries via the adb shell)

Using readelf I see that a different linker/interpreter is used (/lib/ld-linux-aarch64.so.1 vs /apex/com.android.runtime/bin/linker64 (not mounted in the adeb shell)). Is there however a way to execute AOSP binaries?

In one AOSP training exercise I did before finding adeb, we setup a rootfs system, manually built binaries with a gcc toolchain, installed all the deps in /lib and /lib64, and I was able to execute these from the adb shell.

Thanks

Extend adeb to connect to a target through ssh

I managed to use adeb image to create an environment on which I can run eBPF on non android system (buildroot initramfs with no desk mounted). It would be nice to extend adeb to streamline the process for non android system.

The steps I had to do to get this working:

  1. adeb prepare --kernelsrc /path/to/kernel --build-image deb.img --bcc
  2. mount deb.img ./tmp && chroot tmp
  3. cd bcc-master && ./build-bcc.sh
  4. Create /lib/modules/$(uname -r)/build (for kernel headers)
  5. scp the image to the device and ssh and chroot in a similar manner to adb

I am happy to send patches to get this work done. But it would be nice to know first if the concept is OK and if there's any preference on methodology.

What I think needs doing is:

  1. squash steps 2-4 and hide them behind --build-image and --bcc options. I don't see why bcc-master needs to be compiled at the target and can be done offline at the host.

I'm not sure how you manage step 4 at the moment. It would be nice to do this offline at the host too.

These are my quick thoughts. I'll try to get some patches ready meanwhile ;-)

bcc compilation on target board failed

Hi,
I am trying to get adeb-BCC working on a Hikey970 android platform.
By default, use the command “adeb prepare --build --bcc --kernelsrc usr/src/linux-4.9.119” to compile bcc is failed.

The error information are as follows:
bash: cannot set terminal process group (16629): Inappropriate ioctl for device
bash: no job control in this shell
-- The C compiler identification is Clang 6.0.1
-- The CXX compiler identification is Clang 6.0.1
-- Check for working C compiler: /usr/bin/clang-6.0
-- Check for working C compiler: /usr/bin/clang-6.0 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang++-6.0
-- Check for working CXX compiler: /usr/bin/clang++-6.0 -- broken
CMake Error at /usr/share/cmake-3.11/Modules/CMakeTestCXXCompiler.cmake:45 (message):
The C++ compiler

"/usr/bin/clang++-6.0"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /bcc-master/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_7686c/fast"
/usr/bin/make -f CMakeFiles/cmTC_7686c.dir/build.make CMakeFiles/cmTC_7686c.dir/build
make[1]: Entering directory '/bcc-master/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_7686c.dir/testCXXCompiler.cxx.o
/usr/bin/clang++-6.0     -o CMakeFiles/cmTC_7686c.dir/testCXXCompiler.cxx.o -c /bcc-master/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
Linking CXX executable cmTC_7686c
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7686c.dir/link.txt --verbose=1
/usr/bin/clang++-6.0       -rdynamic CMakeFiles/cmTC_7686c.dir/testCXXCompiler.cxx.o  -o cmTC_7686c 
/usr/bin/ld: cannot find -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [CMakeFiles/cmTC_7686c.dir/build.make:87: cmTC_7686c] Error 1
make[1]: Leaving directory '/bcc-master/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:126: cmTC_7686c/fast] Error 2

Exception: Failed to compile BPF module <text>

I want to use adeb on my phone, but I got the above error.

root@localhost:/# filetop
sh: modprobe: command not found
Unable to find kernel headers. Try rebuilding kernel with CONFIG_IKHEADERS=m (module)
chdir(/lib/modules/4.14.117-perf-g63f048d/build): No such file or directory
Traceback (most recent call last):
  File "/usr/share/bcc/tools/filetop", line 161, in <module>
    b = BPF(text=bpf_text)
  File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 343, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>

From the git log, we can see the '--kernelsrc' option was removed, so I can't specify the header path.

Can you tell me why this option was removed? And is there an alternative option? Thanks.

sh -t : unknown option

When I run 'adeb shell' after 'adeb prepare --full' I got the following errors.

$ adeb shell
/system/bin/sh: /system/bin/sh: -t: unknown option

what does this -t option mean?

Please note that I checked Android N/O/Q versions and they all got the same issue.

biolatency biosnoop biotop bitesize no log output

Hi
I am trying to get adeb-BCC working on a arm64 android platform.
linux kernel is 4.9
biolatency biosnoop biotop bitesize no log output

root@localhost:/usr/share/bcc/tools# ./bitesize

In file included from /virtual/main.c:3:
In file included from include/linux/blkdev.h:14:
include/linux/pagemap.h:556:16: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
if (unlikely(__put_user(0, uaddr) != 0))
^
./arch/arm64/include/asm/uaccess.h:340:2: note: expanded from macro '__put_user'
__put_user_err((x), (ptr), __pu_err);
^
./arch/arm64/include/asm/uaccess.h:328:38: note: expanded from macro '__put_user_err'
__put_user_asm("str", "sttr", "%", __pu_val, (ptr),
^
include/linux/pagemap.h:556:16: note: use constraint modifier "w"
./arch/arm64/include/asm/uaccess.h:340:2: note: expanded from macro '__put_user'
__put_user_err((x), (ptr), __pu_err);
^
./arch/arm64/include/asm/uaccess.h:328:34: note: expanded from macro '__put_user_err'
__put_user_asm("str", "sttr", "%", __pu_val, (ptr),
^
In file included from /virtual/main.c:3:
In file included from include/linux/blkdev.h:14:
include/linux/pagemap.h:556:16: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
if (unlikely(__put_user(0, uaddr) != 0))
^
./arch/arm64/include/asm/uaccess.h:340:2: note: expanded from macro '__put_user'
__put_user_err((x), (ptr), __pu_err);
^
./arch/arm64/include/asm/uaccess.h:328:38: note: expanded from macro '__put_user_err'
__put_user_asm("str", "sttr", "%", __pu_val, (ptr),
^
include/linux/pagemap.h:556:16: note: use constraint modifier "w"
./arch/arm64/include/asm/uaccess.h:340:2: note: expanded from macro '__put_user'
__put_user_err((x), (ptr), __pu_err);
^
./arch/arm64/include/asm/uaccess.h:328:34: note: expanded from macro '__put_user_err'
__put_user_asm("str", "sttr", "%", __pu_val, (ptr),
^
In file included from /virtual/main.c:3:
In file included from include/linux/blkdev.h:14:
include/linux/pagemap.h:564:10: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
return __put_user(0, end);
^
./arch/arm64/include/asm/uaccess.h:340:2: note: expanded from macro '__put_user'
__put_user_err((x), (ptr), __pu_err);
^
./arch/arm64/include/asm/uaccess.h:328:38: note: expanded from macro '__put_user_err'
__put_user_asm("str", "sttr", "%", __pu_val, (ptr),
^
include/linux/pagemap.h:564:10: note: use constraint modifier "w"
./arch/arm64/include/asm/uaccess.h:340:2: note: expanded from macro '__put_user'
__put_user_err((x), (ptr), __pu_err);
^
./arch/arm64/include/asm/uaccess.h:328:34: note: expanded from macro '__put_user_err'
__put_user_asm("str", "sttr", "%", __pu_val, (ptr),
^
In file included from /virtual/main.c:3:
In file included from include/linux/blkdev.h:14:
include/linux/pagemap.h:564:10: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]
return __put_user(0, end);
^
./arch/arm64/include/asm/uaccess.h:340:2: note: expanded from macro '__put_user'
__put_user_err((x), (ptr), __pu_err);
^
./arch/arm64/include/asm/uaccess.h:328:38: note: expanded from macro '__put_user_err'
__put_user_asm("str", "sttr", "%", __pu_val, (ptr),
^
include/linux/pagemap.h:564:10: note: use constraint modifier "w"
./arch/arm64/include/asm/uaccess.h:340:2: note: expanded from macro '__put_user'
__put_user_err((x), (ptr), __pu_err);
^
./arch/arm64/include/asm/uaccess.h:328:34: note: expanded from macro '__put_user_err'
__put_user_asm("str", "sttr", "%", __pu_val, (ptr),
^
4 warnings generated.

Tracing... Hit Ctrl-C to end.

^Croot@localhost:/usr/share/bcc/tools#

Any suggestions?
Thank you very much

Tracing user space functions outside the chroot

When I run trace 'p:c:write (arg1 == 1) "writing %d bytes to STDOUT" I see traces of any writes to stdout happening inside the chroot but nothing outside of it is traced. For example, if I have an adb shell open and I do a echo hello there it is not traced but anything happening on the stdout of another adeb shell is traced. Is this the intended behavior for user space tracing? Is there any way to trace user events outside the chroot?

adeb prepare advertises --distro flag but doesn't accept it

Hi there, a little error I got when I tried to upgrade from debian buster (now superseded by bullseye).

$ git clone https://github.com/joelagnel/adeb.git
$ cd adeb
$ ./adeb prepare
> ./adeb
15:09:33 - INFO    : USAGE:
15:09:33 - INFO    : adeb
15:09:33 - INFO    :    shell           Enter the androdeb shell environment and get to work!
15:09:33 - INFO    :    remove          Remove androdeb from the device
15:09:33 - INFO    :    git-pull        Git pull androdeb to update it on your host
15:09:33 - INFO    :    pull            Copy files from the androdeb filesystem in the device
15:09:33 - INFO    :    push            Copy files to the androdeb filesystem in the device
15:09:33 - INFO    :
15:09:33 - INFO    :    prepare         Prepare the device (when running for the first time)
15:09:33 - INFO    :                    By default, this will download and install a base image.
15:09:33 - INFO    :    ** Folowing are the prepare options **
15:09:33 - INFO    :      --full        Pass this to prepare to download and install the full image which
15:09:33 - INFO    :                    contains compilers, editors, tracers etc.
15:09:33 - INFO    :
15:09:33 - INFO    :      --build       Instead of download, build and install the image onto the device
15:09:33 - INFO    :
15:09:33 - INFO    :      --archive     Use archive for root fs (overrides all other prepare options)
15:09:33 - INFO    :
15:09:33 - INFO    :      --buildtar    While preparing, also build a tar.gz.zip file of the filesystem,
15:09:33 - INFO    :                            this is how images that are downloaded by prepare are built
15:09:33 - INFO    :
15:09:33 - INFO    :      --build-image Build an ext4 .img with the base image and BCC (useful for Qemu)
15:09:33 - INFO    :
15:09:33 - INFO    :    ** Folowing are misc build options **
15:09:33 - INFO    :      --tempdir     Use a specific temporary directory for build operation
15:09:33 - INFO    :      --arch                Specify an ARCH to build for (default arm64)
15:09:33 - INFO    :      --distro      Debian distro to base on (default is buster)
[snip]
$  ./adeb prepare --distro bullseye
15:09:06 - ERROR   : Unknown option (--distro)

This was in order to get the latest version of bpftrace which should contain a fix for bpftrace/bpftrace#515.

What is the "supported" Android kernel with `CONFIG_IKHEADERS`?

I see that the most recent changes to adeb removed the --kernelsrc flag and expects to run on a kernel with CONFIG_IKHEADERS.

Based on https://cateee.net/lkddb/web-lkddb/IKHEADERS.html, it seems like only kernels 5.2+ have that option. It looks like the goldfish kernel only has 4.14 as the latest supported kernel.

Where do I find a kernel tree that can run adeb? Or am I expected to apply the patch from https://lore.kernel.org/patchwork/patch/1067310/ to whatever kernel I'm building?

bpftrace uprobe pthread_create on android adeb env

On Android adeb env, if use bpftrace trace uprobe pthread_create, the path should be uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_create,
not uprobe:/system/lib/bootstrap/libc.so:pthread_create, uprobe:/system/lib64/bootstrap/libc.so:pthread_create.
Is that right?

All these paths could list the function path:
root@localhost:/# bpftrace -l 'uprobe:/system/lib/bootstrap/libc.so:pthread*'
uprobe:/system/lib/bootstrap/libc.so:pthread_setspecific
uprobe:/system/lib/bootstrap/libc.so:pthread_barrierattr_getpshared
uprobe:/system/lib/bootstrap/libc.so:pthread_exit
uprobe:/system/lib/bootstrap/libc.so:pthread_mutexattr_gettype
uprobe:/system/lib/bootstrap/libc.so:pthread_attr_getscope
uprobe:/system/lib/bootstrap/libc.so:pthread_cond_timedwait_monotonic_np
uprobe:/system/lib/bootstrap/libc.so:pthread_attr_setguardsize
uprobe:/system/lib/bootstrap/libc.so:pthread_attr_setschedpolicy
uprobe:/system/lib/bootstrap/libc.so:pthread_getschedparam
uprobe:/system/lib/bootstrap/libc.so:pthread_rwlock_timedwrlock
uprobe:/system/lib/bootstrap/libc.so:pthread_mutexattr_getpshared
uprobe:/system/lib/bootstrap/libc.so:pthread_attr_setinheritsched
...

root@localhost:/# bpftrace -l 'uprobe:/system/lib64/bootstrap/libc.so:pthread*'
uprobe:/system/lib64/bootstrap/libc.so:pthread_mutex_lock
uprobe:/system/lib64/bootstrap/libc.so:pthread_mutexattr_destroy
uprobe:/system/lib64/bootstrap/libc.so:pthread_cond_signal
uprobe:/system/lib64/bootstrap/libc.so:pthread_cond_timedwait
uprobe:/system/lib64/bootstrap/libc.so:pthread_rwlockattr_setpshared
uprobe:/system/lib64/bootstrap/libc.so:pthread_create
uprobe:/system/lib64/bootstrap/libc.so:pthread_attr_setstacksize
uprobe:/system/lib64/bootstrap/libc.so:pthread_mutexattr_gettype
uprobe:/system/lib64/bootstrap/libc.so:pthread_attr_destroy
uprobe:/system/lib64/bootstrap/libc.so:pthread_gettid_np
...

root@localhost:/# bpftrace -l 'uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread*'
uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_getattr_np
uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_condattr_getpshared
uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_attr_setaffinity_np
uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_rwlockattr_init
uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_timedjoin_np
uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_attr_setguardsize
uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_attr_getstackaddr
uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_condattr_setclock
uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_sigqueue
uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_attr_setscope
uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_barrierattr_setpshared
uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_condattr_setpshared
...

I write a test program that calls pthread_create, built under adeb env, could trace the output result:
root@localhost:/# bpftrace -e 'BEGIN { printf("%-10s %-6s %-16s %s\n", "TIME(ms)", "PID", "COMM", "FUNC");} uprobe:/lib/aarch64-linux-gnu/libpthread.so.0:pthread_create{ printf("%-10u %-6d %-16s %s\n", elapsed /1000000, pid, comm, usym(arg2));}'
Attaching 2 probes...
TIME(ms) PID COMM FUNC
181 4669 pthread_test ChildThreadFunction
457 4669 pthread_test ChildThreadFunction
764 4669 pthread_test ChildThreadFunction
1065 4669 pthread_test ChildThreadFunction
1366 4669 pthread_test ChildThreadFunction
1666 4669 pthread_test ChildThreadFunction
1966 4669 pthread_test ChildThreadFunction
2266 4669 pthread_test ChildThreadFunction
2566 4669 pthread_test ChildThreadFunction
2866 4669 pthread_test ChildThreadFunction
3165 4669 pthread_test ChildThreadFunction
3466 4669 pthread_test ChildThreadFunction
3765 4669 pthread_test ChildThreadFunction
^C

but for test program built for android which execute under adb env, there is no trace result output:
root@localhost:/# bpftrace -e 'BEGIN { printf("%-10s %-6s %-16s %s\n", "TIME(ms)", "PID", "COMM", "FUNC");} uprobe:/system/lib/bootstrap/libc.so:pthread_create{ printf("%-6d %-16s\n", pid, comm);}'
Attaching 2 probes...
TIME(ms) PID COMM FUNC
^C

root@localhost:/# bpftrace -e 'BEGIN { printf("%-10s %-6s %-16s %s\n", "TIME(ms)", "PID", "COMM", "FUNC");} uprobe:/system/lib64/bootstrap/libc.so:pthread_create{ printf("%-10u %-6d %-16s %s\n", elapsed /1000000, pid, comm, usym(arg2));}'
Attaching 2 probes...
TIME(ms) PID COMM FUNC
^C

So, my problem is that under adeb env, no ability to trace the function caller to bionic library?

can not find /data/androdeb/run

Hello

I want to use adeb in my android target but stuck here.
I spent a day to solve this issue. Can't understand that isssue.

after prepare adeb in my target,
and run adeb shell.

pino@pino-virtual-machine:~$ adeb shell
/system/bin/sh: /data/androdeb/run: No such file or directory

But that file is exist in my target.

So please give me some any idea?

thanks, pino.

Why are there so many '[unknown]' address info while using uprobe?

I installed 'adeb' tool in Android R platform, I've enabled the below kernel config:

CONFIG_IKHEADERS=m
CONFIG_BPF_JIT=y
CONFIG_BPF=y
CONFIG_BPF_SYSCALL=y
CONFIG_BPF_JIT_ALWAYS_ON=y
CONFIG_HAVE_EBPF_JIT=y
CONFIG_BPF_EVENTS=y
CONFIG_KPROBES=y
CONFIG_KPROBE_EVENTS=y
CONFIG_UPROBES=y
CONFIG_UPROBE_EVENTS=y
CONFIG_TRACEPOINTS=y
CONFIG_PREEMPTIRQ_EVENTS=y

But while I running the below command to catch the kernel & user space call stack, I found most of the user space call stack was marked with [unknown]. Are there any way to fix this issue? Thanks in advance.

trace 'do_sys_open "%s", arg2' -T -K -U > trace.txt

Part of the abnormal call stack info(I've attached the trace.txt):

17:51:04 1093 2027 InputReader do_sys_open /dev/pmsg0
do_sys_open+0x0 [kernel]
el0_svc_common+0xa0 [kernel]
el0_svc_handler+0x78 [kernel]
el0_svc+0x8 [kernel]
__openat+0x8 [libc.so]
[unknown] [liblog.so]
__android_log_bwrite+0x88 [liblog.so]
[unknown] [libandroid_runtime.so]
[unknown] [boot-framework.oat]
......
17:51:05 1093 24670 Binder:1093_1D do_sys_open /dev/pmsg0
do_sys_open+0x0 [kernel]
el0_svc_common+0xa0 [kernel]
el0_svc_handler+0x78 [kernel]
el0_svc+0x8 [kernel]
__openat+0x8 [libc.so]
[unknown] [liblog.so]
[unknown] [liblog.so]
__android_log_logd_logger+0x7c [liblog.so]
[unknown] [libbase.so]
[unknown] [libbase.so]
std::__1::__function::__func<art::InitLogging(char**, void (&)(char const*))::LogdLoggerLocked, std::__1::allocator<art::InitLogging(char**, void (&)(char const*))::LogdLoggerLocked>, void (android::base::LogId, android::base::LogSeverity, char const*, char const*, unsigned int, char const*)>::operator()(android::base::LogId&&, android::base::LogSeverity&&, char const*&&, char const*&&, unsigned int&&, char const*&&)+0x74 [libartbase.so]
[unknown] [libbase.so]
__android_log_buf_write+0xbc [liblog.so]
[unknown]
[unknown]
[unknown]
[unknown]
[unknown]
[unknown]
......
17:51:12 3749 4577 AsyncTask #2 do_sys_open /dev/pmsg0
do_sys_open+0x0 [kernel]
el0_svc_common+0xa0 [kernel]
el0_svc_handler+0x78 [kernel]
el0_svc+0x8 [kernel]
[unknown]
[unknown]
[unknown]
[unknown]
[unknown]
[unknown]
[unknown]
[unknown]
[unknown]
[unknown]

chroot: exec /bin/bash: No such file or directory after step https://github.com/joelagnel/adeb/blob/master/BCC.md#build-bcc-during-adeb-install-optional

Enviroment:
Host Ubuntu: 18.04
Client Android: Android P + 4.9 kernel with root

Reproduce:

- Terminal shows up:

:adeb$ adeb prepare --build --bcc --kernelsrc ./kernel-headers
adeb: v0.99g
--------------
15:01:39 - INFO : Looking for device..
15:01:39 - INFO : Preparing device...
15:01:39 - INFO : Doing a full install.
15:01:39 - INFO :
15:01:39 - INFO : Building and updating kernel headers from kernel source dir (/home/cuiyingyun/code/4tb_disk/adeb/versace-stuff/kernel-headers)
15:01:43 - INFO : Using temporary directory: /tmp/tmp.THkf5av3D6
15:01:43 - INFO : The next stage runs as sudo, please enter password if asked.
I: Running command: debootstrap --arch arm64 --foreign --include=llvm-6.0-dev,libclang-6.0-dev,libelf-dev,libfl-dev,libunwind-dev,libdw-dev,git,gcc,libtool,autoconf,make,cmake,iperf,arping,ethtool,flex,bison,python,clang-6.0,python-netaddr,python-
pyroute2,bash,ca-certificates,apt,net-tools,iputils-ping,procps,vim --variant=minbase buster /tmp/tmp.THkf5av3D6/debian http://deb.debian.org/debian/
W: Cannot check Release signature; keyring file not available /usr/share/keyrings/debian-archive-keyring.gpg
I: Retrieving Release
I: Retrieving Packages
I: Validating Packages
I: Found packages in base already in required: apt bash
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Found additional required dependencies: adduser debian-archive-keyring fdisk gcc-8-base gpgv libacl1 libapt-pkg5.0 libattr1 libaudit-common libaudit1 libblkid1 libbz2-1.0 libc6 libcap-ng0 libcom-err2 libdb5.3 libdebconfclient0 libext2fs2 libfdi
sk1 libffi6 libgcc1 libgcrypt20 libgmp10 libgnutls30 libgpg-error0 libhogweed4 libidn2-0 liblz4-1 liblzma5 libmount1 libncursesw6 libnettle6 libp11-kit0 libpam0g libpcre3 libseccomp2 libselinux1 libsemanage-common libsemanage1 libsepol1 libsmartco
ls1 libss2 libstdc++6 libsystemd0 libtasn1-6 libtinfo6 libudev1 libunistring2 libuuid1 libzstd1 zlib1g
I: Found additional base dependencies: autotools-dev binfmt-support binutils binutils-aarch64-linux-gnu binutils-common cmake-data cpp cpp-8 file gcc-8 git-man ieee-data libarchive13 libasan5 libatomic1 libbinutils libbison-dev libbsd0 libc-dev-bi
n libc6-dev libcap2 libcc1-0 libclang-common-6.0-dev libclang1-6.0 libcurl3-gnutls libcurl4 libdw1 libedit2 libelf1 liberror-perl libexpat1 libffi-dev libfl2 libgcc-8-dev libgdbm-compat4 libgdbm6 libgomp1 libgpm2 libgssapi-krb5-2 libicu63 libisl19
libitm1 libjsoncpp1 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 libldap-2.4-2 libldap-common libllvm6.0 liblsan0 liblzma-dev libmagic-mgc libmagic1 libmpc3 libmpfr6 libncurses-dev libncurses6 libnet1 libnghttp2-14 libobjc-8-dev libobjc4 l
ibpcap0.8 libpcre2-8-0 libperl5.28 libpipeline1 libprocps7 libpsl5 libpython-stdlib libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib libreadline7 librhash0 librtmp1 libsasl2-2 libsasl2-modules-db libsigsegv2 libsqlite3-0 libssh2-1 libssl
1.1 libstdc++-8-dev libtinfo-dev libtsan0 libubsan1 libunwind8 libuv1 libxml2 linux-libc-dev llvm-6.0 llvm-6.0-runtime lsb-base m4 mime-support openssl perl perl-modules-5.28 python-minimal python2 python2-minimal python2.7 python2.7-minimal readl
ine-common vim-common vim-runtime wget xxd zlib1g-dev
I: Checking component main on http://deb.debian.org/debian...
I: Retrieving libacl1 2.2.52-3+b1
I: Validating libacl1 2.2.52-3+b1
I: Retrieving adduser 3.118

A lot of logs for updating package

I: Chosen extractor for .deb packages: dpkg-deb
I: Extracting libacl1...
I: Extracting adduser...

real 8m3.377s
user 0m29.522s
sys 0m11.618s
umount: /tmp/tmp.THkf5av3D6/debian/proc/sys/fs/binfmt_misc: not found
umount: /tmp/tmp.THkf5av3D6/debian/proc: not found
chroot: failed to run command ‘rm’: No such file or directory
chroot: failed to run command ‘ln’: No such file or directory
16:01:47 - WARNING : _apt user cannot be added to AID_INET group
/home/cuiyingyun/code/4tb_disk/adeb/buildstrap: line 60: /tmp/tmp.THkf5av3D6/debian/etc/resolv.conf: No such file or directory
Cloning into '/tmp/tmp.THkf5av3D6/debian/bcc-master'...
remote: Enumerating objects: 52, done.
remote: Counting objects: 100% (52/52), done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 17061 (delta 15), reused 28 (delta 12), pack-reused 17009
Receiving objects: 100% (17061/17061), 8.19 MiB | 1.76 MiB/s, done.
Resolving deltas: 100% (11050/11050), done.
Checking connectivity... done.
16:01:56 - INFO : Compressing new filesystem to prepare to push to Android /data/androdeb/
/tmp/tmp.THkf5av3D6/deb.tar.gz: 1 file pu...hed. 23.5 MB/s (23319243 bytes in 0.945s)
/home/cuiyingyun/code/4tb_disk/adeb/addon...le pushed. 0.0 MB/s (652 bytes in 0.021s)
/home/cuiyingyun/code/4tb_disk/adeb/addon...e pushed. 0.1 MB/s (1162 bytes in 0.021s)
/home/cuiyingyun/code/4tb_disk/adeb/addon...ile pushed. 0.0 MB/s (93 bytes in 0.017s)
/home/cuiyingyun/code/4tb_disk/adeb/addon...le pushed. 0.0 MB/s (573 bytes in 0.014s)
/home/cuiyingyun/code/4tb_disk/adeb/addon...le pushed. 0.0 MB/s (242 bytes in 0.014s)
/home/cuiyingyun/code/4tb_disk/adeb/addon...le pushed. 0.0 MB/s (762 bytes in 0.015s)
/home/cuiyingyun/code/4tb_disk/adeb/addon...le pushed. 0.0 MB/s (311 bytes in 0.014s)
/home/cuiyingyun/code/4tb_disk/adeb/addon...le pushed. 0.0 MB/s (113 bytes in 0.014s)
/home/cuiyingyun/code/4tb_disk/adeb/addon...le pushed. 0.0 MB/s (229 bytes in 0.013s)
/home/cuiyingyun/code/4tb_disk/adeb/addon...e pushed. 0.1 MB/s (1157 bytes in 0.015s)
10 files pushed. 0.0 MB/s (5294 bytes in 0.179s)
Unpack of rootfs successful!
mount: '/proc'->'debian/proc/': No such file or directory
mount: '/dev'->'debian/dev/': No such file or directory
mount: '/dev/pts'->'debian/dev/pts': No such file or directory
mount: '/sys'->'debian/sys/': No such file or directory
mount: '/sys/fs/bpf/'->'debian/sys/fs/bpf/': No such file or directory
mount: '/sys/kernel/debug/'->'debian/sys/kernel/debug/': No such file or directory
mount: '/sys/kernel/debug/tracing/'->'debian/sys/kernel/debug/tracing/': No such file or directory
chmod: debian/sys/kernel/debug: No such file or directory
chmod: debian/sys/kernel/debug/tracing: No such file or directory
chroot: exec /bin/bash: No such file or directory

adeb$ adeb shell
chroot: exec /bin/bash: No such file or directory

Other infomation:

  • It works if I run the command "adeb prepare --full --kernelsrc /path/to/kernel-source/" only.

CONFIG_BPF_SYSCALL is undefined

Hi,
I am trying to get adeb-BCC working on a Hikey970 android platform. This has 4.9 kernel flashed. I got the BCC compiled in adeb environment.
I built the kernel with required configurations enabled in kernel as per the page https://github.com/joelagnel/adeb/blob/master/BCC.md. I made sure CONFIG_BPF_SYSCALL is enabled by putting a kernel print.
But, any BCC tool I use including hello_world.py complains that CONFIG_BPF_SYSCALL is not enabled. Below is detailed log. Any pointers would be of great help !

root@localhost:/# /usr/share/bcc/examples/hello_world.py
In file included from :3:
/virtual/include/bcc/helpers.h:26:2: error: "CONFIG_BPF_SYSCALL is undefined, please check your .config or ask your Linux distro to enable this feature"
#error "CONFIG_BPF_SYSCALL is undefined, please check your .config or ask your Linux distro to enable this feature"
^
1 error generated.
Traceback (most recent call last):
File "/usr/share/bcc/examples/hello_world.py", line 12, in
BPF(text='int kprobe__sys_clone(void *ctx) { bpf_trace_printk("Hello, World!\n"); return 0; }').trace_print()
File "/usr/lib/python2.7/dist-packages/bcc/init.py", line 318, in init
raise Exception("Failed to compile BPF text")
Exception: Failed to compile BPF text
root@localhost:/#

Failed to run some commands

root@localhost:/usr/share/bcc/tools# filetop 5 10
sh: modprobe: command not found
Unable to find kernel headers. Try rebuilding kernel with CONFIG_IKHEADERS=m (module)
chdir(/lib/modules/4.9.186-perf-g4773f96/build): No such file or directory
Traceback (most recent call last):
File "/usr/share/bcc/tools/filetop", line 161, in
b = BPF(text=bpf_text)
File "/usr/lib/python2.7/dist-packages/bcc/init.py", line 343, in init
raise Exception("Failed to compile BPF module %s" % (src_file or ""))
Exception: Failed to compile BPF module

Got failed for building arm32 arch bcc

I have support adeb on my arm64 android device,i just run " adeb prepare --full",and then
the adeb runs perfect on the arm64 android device.Adeb is so powerful for debugging.
And then I want to support adeb on my arm32 platform,so i try to "adeb prepare --arch armel --build --bcc --kernelsrc /path/to/kernel-source/", but i got failed when build bcc,the the error message as follow:
"""
[ 90%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_shared_table.cc.o
In file included from /bcc-master/tests/cc/test_shared_table.cc:17:
In file included from /bcc-master/src/cc/api/BPF.h:25:
In file included from /bcc-master/src/cc/api/BPFTable.h:30:
In file included from /bcc-master/src/cc/bcc_syms.h:24:
/bcc-master/src/cc/libbpf/include/uapi/linux/bpf.h:3405:1: warning: struct has size 0 in C, size 1 in C++ [-Wextern-c-compat]
struct bpf_raw_tracepoint_args {
^
1 warning generated.
[ 90%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_usdt_args.cc.o
/usr/bin/ld: ../../src/cc/frontends/clang/libclang_frontend.a(loader.cc.o): in function ebpf::ClangLoader::do_compile(std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >*, ebpf::TableStorage&, bool, std::vector<char const*, std::allocator<char const*> > const&, std::vector<char const*, std::allocator<char const*> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ebpf::FuncSource&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::map<int, std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int, int, int>, std::less<int>, std::allocator<std::pair<int const, std::tuple<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int, int, int> > > >&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > >&)': loader.cc:(.text+0x2688): undefined reference to __atomic_fetch_sub_4'
/usr/bin/ld: loader.cc:(.text+0x2cf4): undefined reference to __atomic_fetch_add_4' /usr/bin/ld: loader.cc:(.text+0x2d44): undefined reference to __atomic_fetch_add_4'
/usr/bin/ld: loader.cc:(.text+0x316c): undefined reference to __atomic_fetch_add_4' /usr/bin/ld: loader.cc:(.text+0x31bc): undefined reference to __atomic_fetch_add_4'
/usr/bin/ld: loader.cc:(.text+0x3618): undefined reference to `__atomic_fetch_add_4'
"""
And then i tried to build arm64 bcc by myself, runs "adeb prepare --arch arm64 --build --bcc --kernelsrc /path/to/kernel-source/" on the arm64 device, and the bcc built successful and the adeb works well.
So, i guess the bcc maybe not support arm architecture.
Ask for your help that the adeb support arm architeture,and i could get adeb for arm32 device by running "adeb prepare --full --arch armel".
Waiting for your good news

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.