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 git@github.com: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/ # 进入板子,挂载共享目录
[root@vexpress ]# mount -t nfs -o nolock 192.168.1.100:/nfsroot /mnt # 加载驱动
[root@vexpress ]# insmod /mnt/install/modules/gtp.ko # 运行gdb
[root@vexpress ]# gdb
GNU gdb (GDB) 8.0
Copyright (C) Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 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
$ =
(gdb) p jiffies_64
$ =
(gdb) p jiffies_64
$ =
(gdb) p jiffies_64
$ =
(gdb)

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

2、远程测试

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

在板子上运行nc命令:

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

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

在PC上运行GDB:

$arm-none-linux-gnueabi-gdb ./vmlinux
GNU gdb (Sourcery CodeBench Lite 2014.05-) 7.7.50.20140217-cvs
Copyright (C) Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 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:
Remote debugging using 192.168.1.2:
0x00000000 in ?? () # 查看jiffies_64的值
(gdb) p jiffies_64
$ =
(gdb) p jiffies_64
$ =
(gdb) p jiffies_64
$ =
(gdb) p jiffies_64
$ =
(gdb)

完。

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

  1. qemu 模拟-arm-mini2440开发板-启动u-boot,kernel和nfs文件系统

    qemu 本文介绍了如何编译u-boot.linux kernel,然后用qemu启动u-boot和linux kernel,达到与开发板上一样的学习效果! 虽然已经买了2440开发板,但是在实际学习 ...

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

    http://www.tinylab.org/using-qemu-simulation-inserts-the-type-system-to-produce-the-whole-process/ 利 ...

  3. 以Qemu模拟Linux,学习Linux内核

    文章名称:以Qemu模拟Linux,学习Linux内核作      者:five_cent文章地址:http://www.cnblogs.com/senix/archive/2013/02/21/29 ...

  4. qemu 模拟-arm-mini2440开发板-启动u-boot,kernel和nfs文件系统【转】

    转自:http://www.cnblogs.com/riskyer/p/3366001.html qemu 本文介绍了如何编译u-boot.linux kernel,然后用qemu启动u-boot和l ...

  5. 用Qemu模拟vexpress-a9 (一) --- 搭建Linux kernel调试环境【转】

    转自:http://www.cnblogs.com/pengdonglin137/p/5023342.html#_label2 阅读目录(Content) 环境介绍: 下载Linux内核 安装arm的 ...

  6. 【记录】尝试用QEMU模拟ARM开发板去加载并运行Uboot,kernel,rootfs【转】

    转自:https://www.crifan.com/try_use_qemu_emulate_arm_board_to_load_and_run_uboot_kernel_rootfs/ [背景] 手 ...

  7. ubuntu下使用qemu模拟ARM(六)------驱动程序【转】

    转自:http://blog.csdn.net/rfidunion/article/details/54709843 驱动程序分为在ubuntu上运行和在ARM开发板上运行两种,我们分别来进行测试 1 ...

  8. 用Qemu模拟vexpress-a9 (一) --- 搭建Linux kernel调试环境

    参考: http://blog.csdn.net/linyt/article/details/42504975 环境介绍: Win7 64 + Vmware 11 + ubuntu14.04 32 u ...

  9. QEMU 模拟运行 VxWorks 6.6

    QEMU 模拟运行 VxWorks 6.6 项目简介 本项目是在 Windows 系统编译运行 X86 平台 VxWorks 6.6 系统,使用的模拟软件是 qemu for Windows Host ...

随机推荐

  1. Identical Binary Tree

    Check if two binary trees are identical. Identical means the two binary trees have the same structur ...

  2. mysql5.7 主从复制的正常切换【转】

    目前环境如下: master server IP:172.17.61.131 slave server IP:172.17.61.132 mysql version: mysql-5.7.21-lin ...

  3. nio--自己总结

    阻塞/非阻塞  +  同步/异步 其实,这两者存在本质的区别,面向的对象是不同的. 阻塞/非阻塞:进程/线程需要操作的数据如果尚未就绪,是否妨碍了当前进程/线程的后续操作. 同步/异步:数据如果尚未就 ...

  4. [转] React 最佳实践——那些 React 没告诉你但很重要的事

    前言:对很多 react 新手来说,网上能找到的资源大都是些简单的 tutorial ,它们能教会你如何使用 react ,但并不会告诉你怎么在实际项目中优雅的组织和编写 react 代码.用谷歌搜中 ...

  5. 用 javascript 实现 ping 一个主机,仅测试是否能够连接。

    function ping(ip){ var img = new Image(); var start = new Date().getTime(); img.src = "http://& ...

  6. CSS3&HTML5各浏览器支持情况一览表

    http://fmbip.com/ CSS3性质(CSS3 Properties) 平台 MAC WIN 浏览器 CHROME FIREFOX OPERA SAFARI CHROME FIREFOX ...

  7. tispark部署步骤

    正常在我们的环境使用tidb集群,都默认没有spark集群的,但之前部署tidb的时候,spark默认已经和系统编译,下面我们的工作就是搭建spark集群和tikv融合 官方是要我们下载tispark ...

  8. 【LOJ】#2495. 「AHOI / HNOI2018」转盘

    题面 题解 考虑我肯定是从一个人出发,开始依次标记,而不会跳过某个人,因为如果我跳过了,那么我之后回来还需要标记它,比不上我等完它再一直走到最后(因为多了走一圈之后走回它的代价) 我们倍长整个序列,我 ...

  9. 【AtCoder】AGC028 (A-E)题解

    A - Two Abbreviations 如果有最小答案的话这个答案一定是N和M的lcm 我们考虑一下什么情况下 \(k \frac{L}{N} = h \frac{L}{M}\)且\(k,g\)互 ...

  10. Web开发模式演变(转)

    add by zhj:目前用的最多应该是模式二,其次是三.四,而模式五比较新,我自己也不太懂. 模式二--前后台交互的方式为整个页面,即每次请求,服务器都将HTML模板渲染后发给客户端,每次请求都返回 ...