ARM Technical Support Knowledge Articles

Can I debug relocated code at source-level with DS-5 Debugger?

Applies to: DS-5


Yes, DS-5 Debugger supports the debug at source-level of code that has been relocated (that is, moved or copied to execute at another address in the memory map), by using the add-symbol-file command.

Assuming you have a debug version of the ELF image (compiled with -g) available that contains debug information, you can load the debug symbols into DS-5 Debugger and have them applied with an address offset.

For example, if you have some code within an executable file prog.axf that is built at a base address 0x8000, but which relocates some functions at run-time (without the build tools knowledge, for example, without using the ARM Linker's scatter-loading mechanism) to an address 0x18000, then an address offset of 0x10000 can be applied to allow the code to be debugged after it has moved.

loadfile prog.axf                   # Load image and its debug information

You can debug this initial code (for example, single-step though it) at source level.
Now run the code that moves/copies some functions.  Stop the code just before executing one of those functions, then:

file                                # Discard existing debug information
add-symbol-file prog.axf 0x10000    # Load debug information and apply an offset

You can now debug that function (for example, single-step though it) at source level.
If you need to return to the original unmoved calling code:

file                                # Discard existing debug information
add-symbol-file prog.axf            # Load debug information for original base address

This feature is typically used for debugging bootloaders such as U-Boot that relocate code to a different place in RAM (for an example, see the DS-5 U-Boot example), and also for debugging OS code before the MMU is turned on, for example, in the Linux kernel.

For source-level debug of the Linux kernel before the MMU is on you need to calculate the offset between the virtual and physical addresses of the code.  For instance if the kernel is linked at virtual address 0xC0008000 and has been loaded at physical address 0x80008000 (as is the case with the DS-5 Example Linux Distribution), the offset is 0x80008000 - 0xC0008000 = -0x40000000.
You can the load the kernel debug symbols, with the offset:
add-symbol-file vmlinux -0x40000000

For a complete example of how DS-5 Debugger can be used to debug the Linux kernel, both pre-MMU enable and post-MMU enable stages, see Software Enablement Blog: Porting Linux Made Easy With DS-5

Article last edited on: 2011-06-07 10:18:55

Rate this article

Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential