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.

DS-5 provides an example of a simple character device driver, modex.c that you can compile, run, and debug on your target. The supplied project does not contain the image binaries for the module. See the readme.html provided with the example for more information on how to compile the kernel and the module.


Before you can debug the module you must ensure that you:

  • Unpack kernel source code and compile the kernel against exactly the same kernel version as the target

  • Compile the loadable module against exactly the same kernel version as the target.


Ensure that you compile both images with debug information. The debugger requires run-time information from both images when debugging the module.


To debug the loadable module, modex.c:

  1. Connect the debugger to the target. The device driver example provides a preconfigured launch file:

    1. Select Debug Configurations... from the Run menu.

    2. Expand the DS-5 Debugger the configuration tree.

    3. Select the module-beagle-example entry.

    4. The Connection tab contains most of the connection settings with the exception of the Debug Hardware Address field. Enter the IP address or name for the connection between the debugger and the debug hardware agent.

      Figure 12. Connection tab for a Linux kernel configuration

      Connection tab for a Linux kernel configuration

    5. The Files tab contains the debugger settings to load debug information for the Linux kernel and the module. For this example, ignore the Application on host to download field and select both the kernel image and the module image as shown in the following figure.

      Figure 13. Select the kernel and module images for the debugger to use

      Select the kernel and module images for the debugger to use

    6. In the Debugger tab, select Connect only in the Run control panel.

    7. Click on Debug to connect the debugger to the target.

  2. Add the Modules view to DS-5 Debug perspective.

  3. Configure and connect a terminal shell to the target. You can use the Remote System Explorer (RSE) provided with DS-5.

  4. Using RSE, copy the compiled module to the target:

    1. Navigate to the .../linux_system/kernel_module/stripped directory on the host workstation.

    2. Drag and drop the module, modex.ko to a writeable directory on the target.

  5. In the terminal shell, insert the module:

    1. Navigate to the location of the module.

    2. Execute the following command:

      insmod modex.ko

    The Modules view updates to display details of the loaded module.

  6. To debug the module, set breakpoints, run, and step as required.

  7. To modify the module source code:

    1. Remove the module. For example:

      rmmod modex
    2. Recompile the module.

    3. Repeat steps 4, 5 and 6 as required.


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:


Displays information about all the loaded modules.


Inserts a loadable module.


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.

Show/hideModules view

OS modules loaded after connection are displayed in the Modules view.

The Modules view is not visible by default. To add this view:

  1. Ensure that you are in the DS-5 Debug perspective.

  2. Select Window → Show View to open the Show View dialog box.

  3. Select Modules view.

Show/hideSee also

Copyright © 2010, 2011 ARM. All rights reserved.ARM DUI 0478D