kgdb調試kernel或者driver module

來源:互聯網
上載者:User
 Who may read this document?
===========================

1. People who familiar with gdb but not never use kgdb

2. People who like to debug kernel or driver module using the gdb way.

Why to Using KGDB
=================

1. Want to debug kernel

2. Want to debug driver module

What’s hardware you needed to use KGDB
=======================================

1. Target system with have serial port

2. Host system with have serial port

3. Serial line

How to Debug Kernel using KGDB
==============================

1. Download kgdb patch for your kernel at http://kgdb.linsyssoft.com/downloads

2. Host: cd /path/to/kernel/source/

3. Host: patch –p1 –i /path/to/patch/file

4. Host: make menuconfig, to confirm you choose kgdb support in KERNEL_HACKING

5. Host: make dep;make bzImage

6. Copy built bzImage to your target system.

7. Target: boot your target using the built bzImage with gdb gdbttyS=x gdbbaud=38400
you may add these parameters to your grub menu. Here ‘x’ is the index of your serial port used to connect your host such as 0,1 or 2.

8. Host: cd /path/to/kernel/source

9. Host: gdb vmlinux

10. Host gdb: set remotebaud 38400

11. Host gdb: target remote /dev/ttySx. Here ‘x’ is the index of your serial port used to connect your target.

How to Debug Driver Module using KGDB
=====================================

1. Host: build your driver module with –g option.

2. Copy your driver.o to your target system.

3. Reboot target with kernel build in kgdb.

4. Host gdb: Set breakpoint before kernel call module’s initialization function so we can debug module’s initialization function.
Kernel call module’s initialization in kernel/module.c: sys_init_module():mod->init().

5. Target: load your driver module using insmod and will stop at breakpoint set by 4.

6. Host gdb: p/x module_list

7. Host gdb: add-symbol-file /path/to/your/driver/module/sourcecode address
where address is the value of module_list+sizeof(module_list).
This command loads symbol file of your module so you can debug it.

8. As 7 have add the symbol file of your module, so you can set breakpoints to your source code such as module’s init function and enjoy the debugging.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.