ARM Technical Support Knowledge Articles

My program crashes or exits before reaching main()

Applies to: ARM Developer Suite (ADS)

Answer

When you build a project written in C or C++ and load the generated image in the debugger, the core's program counter initially points to __main. This function performs the scatter-loading and the C library initialization, and finally branches to main().

In some cases the program crashes or exits before reaching main(). These are the most common reasons why this can happen:

  1. The image hasn't been loaded correctly in memory. For example, this can happen if there is no memory or read-only memory at the address where the image is loaded. It can also happen if the MMU/MPU hasn't been programmed correctly.

    Before loading the image you should ensure that there is RAM at the target address by opening a memory window and writing to it.

    Once the image is loaded you can ensure that it is loaded correctly by checking the contents of memory in the disassembly window.

  2. There is an exception (e.g. an interrupt or a memory abort) before reaching main(). Exceptions can be detecting by enabling vector catch in the debugger.

  3. The stack is placed at an address where there is no RAM. This can happen, for instance, if the debugger variable $top_of_memory is not set up correctly.

  4. The endianness of the image doesn't match the endianness of the target or the debugger.

  5. Semihosting is disabled or the debugger / JTAG emulator doesn't support it.

  6. There is no breakpoint on main(), and the program hangs inside of your code. You can ensure that there is a breakpoint in main() by placing it manually in the debugger.

For more information about $top_of_memory__main and the C library initialization, please see Application Note 107: Embedded Software Development with ADS v1.2.

Article last edited on: 2008-09-09 15:47:41

Rate this article

[Bad]
|
|
[Good]
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