1
votes

I am trying to remotely debug a linux kernel running on an arm cortex-a9 target using jtag probe and gdb. I can connect to the kernel and halt it with gdb. I am able to set breakpoints in the kernel code and gdb confirms there placement as well but the problem is that once I start the execution and issue a continue command, the breakpoints are never hit and the kernel continues to run....

Please help me out in this regard. Thanks.

3
I have turned off all optimizations while compiling my kernel and have enabled "build with debug info" option from menuconfig kernel hacking option....sbunny

3 Answers

3
votes

As pointed in this thread, you should set the breakpoints as hardware breakpoints, namely - using the hbreak command. Only then the breakpoints will be hit.

2
votes

For anyone reading this, the debugger will not break with software breakpoints by default, see the relevant doc:

"If the architecture that you are using supports the kernel option CONFIG_STRICT_KERNEL_RWX, you should consider turning it off. This option will prevent the use of software breakpoints because it marks certain regions of the kernel’s memory space as read-only. If kgdb supports it for the architecture you are using, you can use hardware breakpoints if you desire to run with the CONFIG_STRICT_KERNEL_RWX option turned on, else you need to turn off this option."

at https://www.kernel.org/doc/html/v4.14/dev-tools/kgdb.html

Disable RWX and recompile, then software breakpoints should work (they started working normally here after this)

0
votes

Is some cases, KASLR (Kernel Address Space Layout Randomization) can be the culprit. Even though you setup hbreak, the actual code location can be different from the address seen from the .elf file when using KASLR, so either pass --append "nokaslr" to the kernel boot argument, or configure the kernel with RANDOMIZE_BASE=n. This applies for arm64 and x86_64. (maybe other architectures too).