2.9 Debugging a loadable kernel module

You can use DS-5 to develop and debug a loadable kernel module. Loadable modules can be dynamically inserted and removed from a running kernel during development without the need to frequently recompile the kernel.

This tutorial uses a simple character device driver modex.c which is part of the ARMv7 Linux application examples available in DS-5.
You can use modex.c to compile, run, and debug against your target. The readme.html in the <install_directory>/examples/docs/kernel_module contains information about customising this for your target.

Note

If you are working with your own module, before you can debug it, you must ensure that you:
  • Unpack kernel source code and compile the kernel against exactly the same kernel version as your target.
  • Compile the loadable module against exactly the same kernel version as your target.
  • Ensure that you compile both images with debug information. The debugger requires run-time information from both images when debugging the module.

Procedure

  1. Create a new Debug Configuration.
    1. From the main DS-5 menu, select Run > Debug Configurations.
    2. In the Debug Configurations dialog box, create a New Launch Configuration and give it a name. For example, my_board.
    3. In the Connection tab, select the target and platform and set up your target connection.
      Figure 2-12 Typical connection settings for a Linux kernel/Device Driver Debug
      Typical connection settings for a Linux kernel/Device Driver Debug

    4. In the Files tab, set up the debugger settings to load debug information for the Linux kernel and the module.
      Figure 2-13 Typical Files settings for a Linux kernel/Device Driver Debug
      Typical Files settings for a Linux kernel/Device Driver Debug

    5. In the Debugger tab, select Connect only in the Run control panel.
    6. Click Debug to connect the debugger to the target.
  2. Configure and connect a terminal shell to the target. You can use the Remote System Explorer (RSE) provided with DS-5.
  3. Using RSE, copy the compiled module to the target:
    1. On the host workstation, navigate to .../linux_system/kernel_module/stripped/modex.ko file.
    2. Drag and drop the module to a writeable directory on the target.
  4. Using the terminal shell, insert the modex.ko kernel module.
    1. Navigate to the location of the kernel module.
    2. Execute the following command: insmod modex.ko
      The Modules view updates to display details of the loaded module.
  5. To debug the module, set breakpoints, run, and step as required.
  6. To modify the module source code:
    1. Remove the module using commands as required in the terminal shell. For example: rmmod modex
    2. Recompile the module.
    3. Repeat steps 3 to 5 as required.

Note

When you insert and remove a module, the debugger stops the target and automatically resolves memory locations for debug information and existing breakpoints. This means that you do not have to stop the debugger and reconnect when you recompile the source code.
Useful terminal shell commands:
lsmod
Displays information about all the loaded modules.
insmod
Inserts a loadable module.
rmmod
Removes a module.
Useful DS-5 Debugger commands:
info os-modules
Displays a list of OS modules loaded after connection.
info os-log
Displays the contents of the OS log buffer.
info os-version
Displays the version of the OS.
info processes
Displays a list of processes showing ID, current state and related stack frame information.
set os-log-capture
Controls the capturing and printing of Operating System (OS) logging messages to the console.
OS modules loaded after connection are displayed in the Modules view.
Related reference
3.6 Examples provided with DS-5
Related information
Configuring a connection to a Linux Kernel
Controlling execution
Examining the target
About debugging a Linux kernel
About debugging Linux kernel modules
ARM Linux problems and solutions
Target connection problems and solutions
Operating System (OS) DS-5 debugger commands
Target management terminal for serial and SSH connections
Non-Confidential - BetaPDF file icon PDF versionARM DUI0478U
Copyright © 2010-2015 ARM. All rights reserved.