GithubHelp home page GithubHelp logo

facebookexperimental / extendedandroidtools Goto Github PK

View Code? Open in Web Editor NEW
174.0 174.0 51.0 174 KB

Extended Android Tools is a place to host and maintain a build environment and makefiles cross compiling Linux tools we all love for Android.

License: Apache License 2.0

Shell 4.20% Makefile 45.47% C 1.35% C++ 0.07% Dockerfile 0.35% Python 45.49% Starlark 3.07%

extendedandroidtools's People

Contributors

amaxguan avatar danielocfb avatar daquiver1 avatar mauriciolempke avatar michalgr avatar simpleton avatar tnovak avatar wekesa360 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

extendedandroidtools's Issues

FileNotFoundError: [Errno 2] No such file or directory: '/sys/kernel/debug/kprobes/blacklist'

When I use bcc tools, such as cachestat, python3 cachestat -T

this error:
Traceback (most recent call last):
File "/data/local/tmp/bpftools/share/bcc/tools/cachestat", line 104, in
if BPF.get_kprobe_functions(b'folio_account_dirtied'):
File "/data/local/tmp/bpftools/lib/python3.10/site-packages/bcc/init.py", line 698, in get_kprobe_functions
raise e
File "/data/local/tmp/bpftools/lib/python3.10/site-packages/bcc/init.py", line 694, in get_kprobe_functions
with open(blacklist_file, "rb") as blacklist_f:
FileNotFoundError: [Errno 2] No such file or directory: '/sys/kernel/debug/kprobes/blacklist'

struct bpf_load_program_xattr not defined with libbpf v1.0.0

I'm building x86_64. The buildsystem uses libbpf with tag v1.0.0.
There struct bpf_load_program_xattr has been removed . However in bpftrace in
bpffeature.cpp you still use struct bpf_load_program_xattr as for
(at least in my build bpf_load_program_xattr is not set).
If I switch to v0.8.1 and add some compiler.h macros I can compile though.
s there some logical missunderstanding?

Create scaffolding for new JDWP debugger project

  1. Initialize new buck project at the root of ExtendedAndroidTools
  2. Setup necessary toolchains for python development
  3. Create placeholder targets:
    • //projects/jdwp:main
    • //projects/jdwp:lib
    • //projects/jdwp/tests:tests
  4. Setup pyre to typecheck //projects/jdwp/...

After this issue is completed we should be able to run the following commands:

make python-host
eval `make setup-env`
buck2 run //projects/jdwp:main
buck2 test //projects/jdwp/tests/...
cd projects/jdwp && pyre

No output for kprobes

Hi!

I've built bpftools (including bpftrace) for aach64.

# /data/bin/bpftools/bpftrace --info
System
  OS: Linux 5.10.43 #9 SMP PREEMPT Tue Jun 27 12:32:32 UTC 2023
  Arch: aarch64

Build
  version: v0.16.0-96-g58bd
  LLVM: 14.0.6
  unsafe uprobe: no
  bfd: no
  libdw (DWARF support): no

Kernel helpers
  probe_read: yes
  probe_read_str: yes
  probe_read_user: yes
  probe_read_user_str: yes
  probe_read_kernel: yes
  probe_read_kernel_str: yes
  get_current_cgroup_id: yes
  send_signal: yes
  override_return: yes
  get_boot_ns: yes
  dpath: no
  skboutput: no

Kernel features
  Instruction limit: 1000000
  Loop support: yes
  btf: no
  map batch: yes
  uprobe refcount (depends on Build:bcc bpf_attach_uprobe refcount): no

Map types
  hash: yes
  percpu hash: yes
  array: yes
  percpu array: yes
  stack_trace: yes
  perf_event_array: yes

Probe types
  kprobe: yes
  tracepoint: yes
  perf_event: yes
  kfunc: no
  iter:task: no
  iter:task_file: no
  kprobe_multi: no
  raw_tp_special: yes

Tracepoints are caught fine, but I can't get any output for kernel probes (kprobes).

# ./strace -ebpf /data/bin/bpftools/bpftrace -e 'kprobe:do_nanosleep { printf("function is called\n"); }' -v                                    
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=17585, si_uid=0, si_status=0, si_utime=1, si_stime=0} ---
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=17589, si_uid=0, si_status=0, si_utime=0, si_stime=1} ---
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=17591, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
bpf(0x17 /* BPF_??? */, 0x7fccfe4410, 12) = -1 ENOENT (No such file or directory)
bpf(0x17 /* BPF_??? */, 0x7fccfe3f50, 12) = -1 ENOENT (No such file or directory)
INFO: node count: 6
Attaching 1 probe...
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2, insns=0x7fccfe40e0, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(0, 0, 0), prog_flags=0, prog_name="", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS}, 116) = -1 EINVAL (Invalid argument)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2, insns=0x7fccfe40f0, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(0, 0, 0), prog_flags=0, prog_name="libbpf_nametest"}, 64) = 3
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=8, map_flags=0, inner_map_fd=0, map_name="printf", map_ifindex=0}, 72) = 3
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fccfe461c, value=0x7fccfe45dc, flags=BPF_ANY}, 32) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fccfe461c, value=0x7fccfe45dc, flags=BPF_ANY}, 32) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fccfe461c, value=0x7fccfe45dc, flags=BPF_ANY}, 32) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fccfe461c, value=0x7fccfe45dc, flags=BPF_ANY}, 32) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fccfe461c, value=0x7fccfe45dc, flags=BPF_ANY}, 32) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fccfe461c, value=0x7fccfe45dc, flags=BPF_ANY}, 32) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fccfe461c, value=0x7fccfe45dc, flags=BPF_ANY}, 32) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x7fccfe461c, value=0x7fccfe45dc, flags=BPF_ANY}, 32) = 0
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=2, insns=0x7fccfe4030, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(0, 0, 0), prog_flags=0, prog_name="ksys_read", prog_ifindex=0, expected_attach_type=0x2a /* BPF_??? */}, 128) = 13
bpf(0x1c /* BPF_??? */, 0x7fccfe3ea0, 48) = -1 EINVAL (Invalid argument)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=12, insns=0xb400007771a0b320, license="GPL", log_level=1, log_size=1000000, log_buf="", kern_version=KERNEL_VERSION(5, 10, 43), prog_flags=0, prog_name="do_nanosleep", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS}, 128) = 14
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=14, info_len=232 => 208, info=0x7fccfe41d0}}, 16) = 0

Program ID: 86

The verifier log: 
processed 10 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0

Attaching kprobe:do_nanosleep

Currently kernel is built with flags (+ CONFIG_IKHEADERS) specified in check_kernel_features.sh except CONFIG_BPF_JIT, CONFIG_UPROBES and CONFIG_UPROBE_EVENTS.

Could you please suggest what can be a reason of such behavior if you've faced with the similar problem? Or what steps can be done to troubleshot it?

Thanks!

Static bpftrace binary?

Hi there @michalgr @danielocfb! Do we have public instructions around how to build bpftrace for Android statically? If not, any chance that could be documented as part of this project?

thanks a lot

run bpftrace on android meet proble" cannot locate symbol "CrcGenerateTable" "

Hi,

I pull this project and build bpftrace, but when I run bpftrace on android, but the error like below:

WARNING: linker: Warning: "/data/local/tmp/bpftools/lib/libc++_shared.so" unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0) (ignoring)
WARNING: linker: Warning: "/data/local/tmp/bpftools/lib/libc++_shared.so" unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0) (ignoring)
WARNING: linker: Warning: "/data/local/tmp/bpftools/lib/libc++_shared.so" unused DT entry: unknown processor-specific (type 0x70000001 arg 0x0) (ignoring)
CANNOT LINK EXECUTABLE "bpftrace": cannot locate symbol "CrcGenerateTable" referenced by "/system/lib64/libunwindstack.so"...

So , Is any one can help me out, how to slove this problem.

Implement codegen generating JDWP parsers/serializers

Once #56 is completed, implement codegen tool using new JDWP description to generate data structures and serialization/deserialization logic, together with any python modules accompanying generated code, necessary to send and receive JDWP messages. At this point we should be able to open a socket and send raw JDWP messages to Java processes from Python REPL. We should also have a debugging tool snooping on JDWP communication between jdb (or any other Java debugger) and a Java VM.

Implement Java debugger Python API

Raw JDWP is too verbose for convenient debugging experience. Ideally we would be able to debug Java processes using API consisting of Threads, StackFrames, Variables and Breakpoints that underneath translates all interactions to/from JDWP messages. The API should support two use cases:

  • Interactive debugging from Python REPL, for example
debugger = connect(...)
event = await debugger.on("void java.lang.Integer.toString()")
thread = event.thread
thread.stackTrace
thread.frame[0].this
thread.resume()
  • Scripting, users specifying set of breakpoints and reactions to breakpoints as standalone python scripts, for example:
debugger = connect(...)

@debugger.on("void java.lang.Integer.toString()")
async def callback(event: BreakpointEvent):
    thread = event.thread
    println(f"Called toString on ${thread.frame[0].this}")
    println(thread.stackTrace)
    event2 = await thread.singleStep()
    println(thread.stackTrace)    

Once completed we should be able to use new API to debug Java processes on host machine, as well as Java processes on Android devices.

Describe JDWP messages.

Implement a set of python modules containing objects describing layout of JDWP messages.

An example of such description could look like this:

Version = Command(
    name="version",
    id=1,
    out=None,
    reply=Struct([
        Field("description", types.String),
        Field("jdwp major", types.Int),
        Field("jdwp minor", types.Int),
        Field("vm version", types.String),
        Field("vm name", types.String),
    ]),
)

ClassesBySignature = Command(
    name="classes by signature",
    id=2,
    out=Struct([
        Field("signature", types.String),
    ]),
    reply=Struct([
      ...
    ]),
)

...

VirtualMachine = CommandSet(
    name="VirtualMachine",
    id=1,
    commands=[
      Version,
      ClassesBySignature,
    ],
)

The schema should allow us to express common data types (see table at the bottom of this page), compound structures, arrays (see ClassesBySignature command) and tagged unions (see Composite Command). Schema and each command set should be defined in a separate module. Such JDWP description should support pattern matching as a major tool to analyze shape of structs.

Having such description will allow us to write codegen tools generating JDWP data structures and parsers/serializers for different programming languages.

request update for std::filesystem

Hi,

As more and more functions have depend on std::filesystem in bpftrace, request update for std::filesystem.

By now ndk r22 has released, as discussed in #5 , the best way is to move to ndk r22. If so, use the gcc in ndk r17c, and use the std::filesystem in ndk r22?

thanks

@michalgr

build bpftools error

make[1]: Leaving directory `/ExtendedAndroidTools/build/android/arm64/python' touch build/android/arm64/python.done mkdir -p build/android/arm64/xz cd build/android/arm64/xz && /ExtendedAndroidTools/projects/xz/sources/configure --host=aarch64-linux-android --prefix=/ExtendedAndroidTools/out/android/arm64 LDFLAGS="-pie" /bin/sh: 1: /ExtendedAndroidTools/projects/xz/sources/configure: not found projects/xz/build.mk:17: recipe for target 'build/android/arm64/xz' failed make: *** [build/android/arm64/xz] Error 127
occur error when I chose docker script to build this.seems like xz sources dir doesn't have configure.

Add buck2 as a project

Create projects/buck2 directory with README and build.mk files following the same pattern as all the other projects. build.mk should define a target fetching a prebuilt buck2 binary for the host os and architecture and making it available under out/host/bin/buck2.

For reference, here is my abandoned attempt to add buck1. Note that buck2 setup should be a bit simpler, it does not require java and does not require ant or any compilation.

After this task is completed we should be able to run the following commands in the build environment:

make buck2-host
out/host/bin/buck2 --help

Adding libbpf

Hi,
me again :-)

I'm working on a project which uses libbpf to load the bpf program (moving from bcc to libbpf).
Can I modify ExtendedAndroidTools to statically compile the library to libbpf.a for android?
If so, which files should I edit?

Thanks,
Yaniv

lastest bpftrace need -lstdc++fs

Hi,

The lastest bpftrace master need -lstdc++fs, current env not supported.
I found libc++fs is available on Android R AOSP source code(external/libcxx).
also available in projects/llvm/sources/libcxx.

So, use libc++fs instead of libstdc++fs?
Do you have any suggestion?

Very thanks

Add pyre type checker as a project

Create projects/pyre directory with README and build.mk files following the same pattern as all the other projects. build.mk should define a target making out/host/bin/pyre binary available. This can be done by running the following command: $(HOST_OUT_DIR)/bin/python3 -m pip install pyre-check.

After this issue is completed we should be able to run the following commands in the build environment:

make pyre-host
out/host/bin/pyre --help

Enabling touchscreen and wifi modules of pixel3a by default

Hi,

I'm so glad I found this repo, as I wanted to experiment running bpf code on a pixel3a phone I have,
and didn't know how to port the bpf code to 4.9.

I understand that touchscreen and wifi are kernel modules in pixel3a, which require the use of adb and remounting to copy the updated modules (every time phone is restarted?)
but if I change:
CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_CORE_v27=m
CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_RMI_DEV_v27=m
CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_FW_UPDATE_v27=m
CONFIG_TOUCHSCREEN_SYNAPTICS_DSX_TEST_REPORTING_v27=m

in bonito_defconfig to 'y', touchscreen is now enabled without the need for a kernel module!

so I wanted to ask:

  1. Is there a reason not to change this from 'm' to 'y'?
  2. Wifi code is available out of tree in google sources - do you think it should be easy to put it in the kernel sources and also compile it with the kernel? I tried to do that and failed :-(

Thanks,
Yaniv

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.