【问题标题】:Android Systemtap can not load moduleAndroid Systemtap 无法加载模块
【发布时间】:2014-05-08 07:58:08
【问题描述】:

我正在尝试在我的 GT-i9300 上加载一个简单的 Systemtap 模块

我得到了错误

插入模块“/sdcard/systemtap/modules/monitor_fopen.ko”时出错: 模块中的未知符号

我采取的步骤:


1。在设备上获取 root

我通过安装这个Rom来做到这一点

2。构建自定义内核

# ====================================================
# Add toolchain

user@ubuntu1210:~/Programs$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7

user@ubuntu1210:~$ sudo gedit .bashrc


    # Toolchain
    export PATH=${PATH}:~/Programs/arm-linux-androideabi-4.7/bin


# Reboot ubuntu 
# ====================================================


# ====================================================
# Download and extract to ~/android/kernel : 
# https://github.com/SlimRoms/kernel_samsung_smdk4412.git

user@ubuntu1210:~$ cd android/kernel/kernel_samsung_smdk4412/


# ====================================================


# ====================================================
# Set configuration for compiling


user@ubuntu1210:~/android/kernel/kernel_samsung_smdk4412$ make clean -j4 ARCH=arm SUBARCH=arm CROSS_COMPILE=arm-linux-androideabi-

user@ubuntu1210:~/android/kernel/kernel_samsung_smdk4412$ make ARCH=arm SUBARCH=arm CROSS_COMPILE=arm-linux-androideabi- slim_i9300_defconfig

user@ubuntu1210:~/android/kernel/kernel_samsung_smdk4412$ gedit .config

    # Enable config parameters:
    CONFIG_DEBUG_INFO, CONFIG_KPROBES, CONFIG_RELAY, CONFIG_DEBUG_FS, CONFIG_MODULES, CONFIG_MODULE_UNLOAD


# ====================================================
# Build Kernel

user@ubuntu1210:~/android/kernel/kernel_samsung_smdk4412$ make -j4 ARCH=arm SUBARCH=arm CROSS_COMPILE=arm-linux-androideabi-

3。 Flash 将 zImage 构建到设备

# Download and extract bootimg_tools.zip from
# http://forum.xda-developers.com/showpost.php?p=44670032&postcount=12
# 
# Download correct ROM .zip file and extract boot.img to the same folder as bootimg_tools

user@ubuntu1210:~/bootimg_tools$ perl split_bootimg.pl boot.img

user@ubuntu1210:~/bootimg_tools$ perl unpack_ramdisk boot.img-ramdisk.gz ramdisk

user@ubuntu1210:~/bootimg_tools$ perl repack_ramdisk ramdisk boot.img-ramdisk.cpio.gz

user@ubuntu1210:~/bootimg_tools$ cp /home/user/kernel_samsung_smdk4412/arch/arm/boot/zImage boot.img-kernel

user@ubuntu1210:~/bootimg_tools$ ./mkbootimg --kernel boot.img-kernel --ramdisk boot.img-ramdisk.cpio.gz --cmdline 'console=null androidboot.hardware=qcom user_debug=31 zcache' --base 0x80200000 --pagesize 2048 -o boot.img

# Download and install heimdall
# https://bitbucket.org/benjamin_dobell/heimdall/downloads

user@ubuntu1210:~/bootimg_tools$ adb reboot bootloader

user@ubuntu1210:~/bootimg_tools$ sudo heimdall flash --BOOT boot.img --verbose

4。在 PC 上安装 systemtap

user@ubuntu1210:~$ mkdir systemtap
user@ubuntu1210:~$ cd systemtap/
user@ubuntu1210:~/systemtap$ git clone https://github.com/flipreverse/systemtap-android.git
user@ubuntu1210:~/systemtap$ cd systemtap-android/
user@ubuntu1210:~/systemtap/systemtap-android$ git submodule init
user@ubuntu1210:~/systemtap/systemtap-android$ git submodule update
user@ubuntu1210:~/systemtap/systemtap-android$ sh build.sh 

5。创建 .stp 文件

user@ubuntu1210:~$ cd /home/user/systemtap/systemtap-android/scripts/
user@ubuntu1210:~$ vi monitor_fopen.stp

#! /usr/bin/stap


probe begin
{
        printf("start monitoring");
}

probe end
{
        printf("end monitoring");
}

6。使用已编译的内核从 .stp 文件中构建 .ko 文件

user@ubuntu1210:~$ /home/user/systemtap/systemtap-android/installed/bin/stap 
-p 4 -v  
-a arm 
-B CROSS_COMPILE=/home/user/Programs/arm-linux-androideabi-4.7/bin/arm-linux-androideabi- 
-r /home/user/android/kernel/kernel_samsung_smdk4412/ 
-j /home/user/systemtap/systemtap-android/installed/share/systemtap/tapset/ 
-R /home/user/systemtap/systemtap-android/installed/share/systemtap/runtime/ 
-t -g -m monitor_fopen /home/user/systemtap/systemtap-android/scripts/monitor_fopen.stp

7.在运行自定义内核的设备上安装 Systemtap Android App

https://github.com/flipreverse/systemtap-android-app

8。启动应用并授予应用 root 访问权限

Superuser.apk 应该询问您 Systemtap 是否可以具有 root 访问权限

9。将步骤 6 中的 .ko 文件推送到 sdcard

user@ubuntu1210:~$ adb push monitor_fopen.ko /sdcard/systemtap/modules/monitor_fopen.ko

10。加载模块

user@ubuntu1210:~$ adb shell
shell@android:/ $ su
root@android:/ # cd /data/data/com.systemtap.android
root@android:/data/data/com.systemtap.android # sh start_stap.sh   

modulename=monitor_fopen
moduledir=/sdcard/systemtap/modules
outputname=monitor_fopen_2014.mm.dd_sss
outputdir=/sdcard/systemtap/stap_output
logdir=/sdcard/systemtap/stap_log
rundir=/sdcard/systemtap/stap_run
stapdir=/data/data/com.systemtap.android
:q!

11.读取模块加载结果

user@ubuntu1210:~$ adb shell
shell@android:/ $ cd sdcard/systemtap/stap_log/
shell@android:/sdcard/systemtap/stap_log $ cat monitor_fopen_2014.mm.dd_sss.txt

加载的内核模块:monitor_fopen.ko 输出文件:monitor_fopen_2014.mm.dd_sss.* 插入模块“/sdcard/systemtap/modules/monitor_fopen.ko”时出错:模块中有未知符号


我不知道我错在哪一步。有人知道吗?

【问题讨论】:

  • 尝试加载模块后,在设备上运行 dmesg - 日志应包含出现问题的符号名称。
  • 好吧,我遇到了一个奇怪的错误:/root/sukritk/systemtap-android/installed//share/systemtap/runtime/linux/alloc.c:345:14:错误:静态声明'vzalloc' 遵循非静态声明 static void *vzalloc(unsigned long size) ^ 是否需要设置其他一些环境变量或运行时参数。 /root/sukritk/systemtap-android/已安装//bin/stap -p 4 -v -a arm -B CROSS_COMPILE=arm-linux-androideabi- -r /root/sukritk/kernel/goldfish/ -R /root/sukritk /systemtap-android/installed//share/systemtap/runtime/ -t -g -m monitor_fopen scripts/monitor_fopen.stp

标签: android linux-kernel systemtap


【解决方案1】:

感谢@adelphus,他记得我使用了 dmesg,我发现了错误:

Android:未知符号_GLOBAL_OFFSET_TABLE_

this site的帮助下,我将内核的Makefile编辑为

CFLAGS_MODULE   = -fno-pic

然后重做我的 OP 中的所有其他步骤。

【讨论】:

    猜你喜欢
    • 2011-03-08
    • 2021-01-11
    • 2015-02-09
    • 1970-01-01
    • 2016-10-09
    • 2012-09-07
    • 2012-10-10
    • 2017-09-22
    • 1970-01-01
    相关资源
    最近更新 更多