在qemu模拟的aarch32上使用kgtp

KGTP 介绍

KGTP 是一个能在产品系统上实时分析 Linux 内核和应用程序(包括 Android)问题的全面动态跟踪器。 使用 KGTP 不需要 在 Linux 内核上打 PATCH 或者重新编译,只要编译 KGTP 模块并insmod 就可以。 其让 Linux 内核提供一个远程 GDB 调试接口,于是在本地或者远程的主机上的 GDB 可以在不需要停止内核的情况下用 GDB tracepoint 和其他一些功能调试和跟踪Linux内核和应用程序。

Github

https://github.com/teawater/kgtp

在上面有帮助手册,也可以点击这里查看帮助手册

本文目的

在Qemu模拟的vexpress板子上面体验KGTP

软件版本

Linux 4.10

Qemu-2.8

ARM-Versatile Express

arm-none-linux-gnueabi 4.8.3

正文

一、交叉编译gdb

请参考博客 http://www.cnblogs.com/pengdonglin137/p/7093417.html

编译完成后,将生成的gdb可执行程序拷贝到板子上

二、重新编译kernel,打开相关的配置

要编译kgtp的话,需要打开下面的几个配置:

General setup --->
  [*] Kprobes
  [*] Enable loadable module support --->
Kernel hacking --->
  Compile-time checks and compiler options  --->
    [*] Compile the kernel with debug info
  [*] Tracers  --->
    [*]   Enable uprobes-based dynamic events

使能上面的配置后,重新编译kernel。

三、交叉编译KGTP

目前KGTP在Linux-4.10上还无法直接编译通过,需要稍作修改,修改后的kgtp我上传到了github,可以使用下面的命令下载:

git clone [email protected]:pengdonglin137/kgtp.git -b  aarch32_version

下载完成后,需要对Makefile稍作修改,将其中的INSTALL、KERNELDIR以及OUT

使用下面的命令编译

make
make install

然后将生成的可执行程序以及ko文件拷贝到板子上

四、测试

1、本地测试

我们将编译出的vmlinux拷贝到板子上,加载gtp.ko,直接在板子上运行GDB,然后连接GTP,开始测试:

# 在PC机上将vmlinux拷贝到NFS共享目录下
cp /home/pengdonglin/src/qemu/aarch32/linux-4.10/out_aarch32/vmlinux /nfsroot/

# 进入板子,挂载共享目录
[[email protected] ]# mount -t nfs -o nolock 192.168.1.100:/nfsroot /mnt

# 加载驱动
[[email protected] ]# insmod /mnt/install/modules/gtp.ko 

# 运行gdb
[[email protected] ]# gdb
GNU gdb (GDB) 8.0
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-none-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".

# 加在vmlinux
(gdb) file /mnt/vmlinux
Reading symbols from /mnt/vmlinux...done.

# 将gdb连接到gtp上
(gdb) target remote /sys/kernel/debug/gtp
Remote debugging using /sys/kernel/debug/gtp

#打印jiffies_64变量
(gdb) p jiffies_64
$1 = 4294969128
(gdb) p jiffies_64
$2 = 4294969245
(gdb) p jiffies_64
$3 = 4294969332
(gdb) p jiffies_64
$4 = 4294969419
(gdb) 

可以看到,jiffies_64的值一直在递增。

2、远程测试

在PC上运行GDB,连接板子上的GTP,开始调试:

在板子上运行nc命令:

nc -l -p 2345 < /sys/kernel/debug/gtp > /sys/kernel/debug/gtp 

之后,nc会在那里等待连接。

在PC上运行GDB:

$arm-none-linux-gnueabi-gdb ./vmlinux
GNU gdb (Sourcery CodeBench Lite 2014.05-29) 7.7.50.20140217-cvs
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://sourcery.mentor.com/GNUToolchain/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./vmlinux...done.
# 连接板子上的GTP
(gdb) target remote 192.168.1.2:2345
Remote debugging using 192.168.1.2:2345
0x00000000 in ?? ()

# 查看jiffies_64的值
(gdb) p jiffies_64
$1 = 4295030342
(gdb) p jiffies_64
$2 = 4295030453
(gdb) p jiffies_64
$3 = 4295030536
(gdb) p jiffies_64
$4 = 4295030622
(gdb) 

完。

时间: 2024-07-31 17:54:37

在qemu模拟的aarch32上使用kgtp的相关文章

以Qemu模拟Linux,学习Linux内核

文章名称:以Qemu模拟Linux,学习Linux内核作      者:five_cent文章地址:http://www.cnblogs.com/senix/archive/2013/02/21/2921221.html维护日志:2013-02-21 建立文档(注:文章参考自http://www.linuxidc.com/Linux/2011-07/39373.htm, 是对该篇文章的一些补充和说明.文章内所使用的环境是Ubuntu 12.04,如果其中遇到编译问题,请自行参考错误说明,配置依赖

利用qemu模拟嵌入式系统制作全过程

http://www.tinylab.org/using-qemu-simulation-inserts-the-type-system-to-produce-the-whole-process/ 利用qemu模拟嵌入式系统制作全过程 by Pingbo Wen of TinyLab.org 2013/08/31 这篇文章,将介绍如何用qemu来搭建一个基于ARM的嵌入式linux系统.通过该文章,你可以学习到如何配置kernel,如何交叉编译 kernel,如何配置busybox并编译,如何制

利用 qemu 模拟嵌入式系统制作全过程

利用qemu模拟嵌入式系统制作全过程 by Pingbo Wen of TinyLab.org 2013/08/31 这篇文章将介绍如何用 Qemu 来搭建一个基于 ARM 的嵌入式 Linux 系统.通过该文章可以学习到如何配置和交叉编译 Kernel,如何配置 Busybox 并编译,如何制作 Initramfs,如何制作根文件系统,如何定制自己的 Uboot,如何通过 Uboot 向 Kernel 传递参数等.开始干活! 零.环境搭建 在实现我们的目标之前,我们需要搭建自己的工作环境.在这

RPi 2B QEMU 模拟树莓派

/******************************************************************************** * RPi 2B QEMU 模拟树莓派 * 说明: * 网络上有找到一些资料,不过在我的电脑上运行会出一些问题,经验证,需要提前 * 修改文件系统中的链接库和分区挂载表. * * 2017-5-21 台湾 中和区 曾剑锋 *********************************************************

Qemu模拟IO和半虚拟化Virtio的区别以及I/O半虚拟化驱动介绍

QEMU的基本原理和优缺点 基本原理: 使用QEMU模拟I/O的情况下,当客户机中的设备驱动程序(device driver)发起I/O操作请求之时,KVM模块中的I/O操作捕获代码会拦截这次I/O请求,然后经过处理后将本次I/O请求的信息存放到I/O共享页,并通知用户控件的QEMU程序.QEMU模拟程序获得I/O操作的具体信息之后,交由硬件模拟代码来模拟出本次的I/O操作,完成之后,将结果放回到I/O共享页,并通知KVM模块中的I/O操作捕获代码.最后,由KVM模块中的捕获代码读取I/O共享页

qemu模拟vexpress开发板(续)

1. 问题描述 续接上文,利用qemu模拟cortex-a9开发板,流程:qemu ===> u-boot ===> kernel ===>  nfsroot             ||             ======> ramdisk 进行到kernel引导根文件系统时,总是失败.经过尝试,终于解决了!!! 2. 解决方法 2.1 关于bootargs 前文说过,u-boot可以通过 bootargs 这个环境变量来传递参数给内核,那么可以传递哪些参数?格式又是如何?这个

CentOS7使用Qemu模拟ARM64

准备 RPM包安装 yum安装交叉编译工具 yum install -y binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu bison flex glib2 glib2-devel pixman-devel bc 手动安装glibc yum库中没有glibc-aarch64,所以需要手动安装相应的包.在该网站下载以下连个rpm包进行安装 glibc-aarch64-linux-gnu glibc-aarch64-linux-gnu-devel 下载

用QEMU模拟运行uboot从SD卡启动Linux

平台:Qemu + vexpress-a9 u-boot:u-boot-2019.10 Linux:linux-4.14.13 之前介绍过用Qemu模拟运行uboot,然后从网络启动linux(用Qemu模拟vexpress-a9 (三)--- 实现用u-boot引导Linux内核),下面介绍用Qemu运行uboot,然后将存放在虚拟出来的SD卡里加载linux kernel.设备树,并运行. 一.编译uboot 下载最新的uboot,编译vexpress-a9: make ARCH=arm C

Android实现模拟表单上传

很久以前,写过一篇关于下载的文章:基于HTTP协议的下载功能实现,今天对于Android上的文件上传,也简单的提两笔.在Android上,一般使用Http 模拟表单或者FTP来进行文件上传,使用FTP协议,可以直接使用Appache的FTPClient,使用方法很简单,不再赘述.这里主要说明一下Http模拟表单上传的实现. 模拟表单上传,其实也很简单,主要需要在Http post 的数据体中构建表单信息(multipart/form),表单数据格式的规范,可以参考REC标准.下面是一个格式示例: