6.10.3 About debugging Linux kernel modules

Linux kernel modules provide a way to extend the functionality of the kernel, and are typically used for things such as device and file system drivers. Modules can either be built into the kernel or can be compiled as a loadable module and then dynamically inserted and removed from a running kernel during development without having to frequently recompile the kernel. However, some modules must be built into the kernel and are not suitable for loading dynamically. An example of a built-in module is one that is required during kernel boot and must be available prior to the root file system being mounted.
You can set source-level breakpoints in a module after loading the module debug information into the debugger. For example, you can load the debug information using add-symbol-file modex.ko. To set a source-level breakpoint in a module before it is loaded into the kernel, use break -p to create a pending breakpoint. When the kernel loads the module, the debugger loads the symbols and applies the pending breakpoint.
When debugging a module, you must ensure that the module on your target is the same as that on your host. The code layout must be identical, but the module on your target does not require debug information.

Built-in module

To debug a module that has been built into the kernel, the procedure is the same as for debugging the kernel itself:
  1. Compile the kernel together with the module.
  2. Load the kernel image on to the target.
  3. Load the related kernel image with debug information into the debugger
  4. Debug the module as you would for any other kernel code.
Built-in (statically linked) modules are indistinguishable from the rest of the kernel code, so are not listed by the info os-modules command and do not appear in the Modules view.

Loadable module

The procedure for debugging a loadable kernel module is more complex. From a Linux terminal shell, you can use the insmod and rmmod commands to insert and remove a module. Debug information for both the kernel and the loadable module must be loaded into the debugger. When you insert and remove a module the debugger automatically resolves memory locations for debug information and existing breakpoints. To do this, the debugger intercepts calls within the kernel to insert and remove modules. This introduces a small delay for each action whilst the debugger stops the kernel to interrogate various data structures. For more information on debugging a loadable kernel module, see the tutorial in Getting Started with DS-5.

Note

A connection must be established and Operating System (OS) support enabled within the debugger before a loadable module can be detected. OS support is automatically enabled when a Linux kernel image is loaded into the debugger. However, you can manually control this by using the set os command.
Related concepts
6.10.2 About debugging a Linux kernel
6.7 About debugging bare-metal symmetric multiprocessing systems
Related tasks
2.7 Configuring a connection to a Linux kernel
Related reference
3.2 Running, stopping, and stepping through an application
5.1 Examining the target execution environment
5.2 Examining the call stack
3.12 Handling UNIX signals
3.13 Handling processor exceptions
11.4 Breakpoints view
11.6 Commands view
11.7 Debug Control view
11.8 Disassembly view
11.14 Memory view
11.16 Modules view
11.17 Registers view
11.26 Variables view
Related information
Debugging a loadable kernel module
Non-ConfidentialPDF file icon PDF versionARM DUI0446W
Copyright © 2010-2015 ARM. All rights reserved.