wiki:TBR/Review/Debugging/Start

Version 23 (modified by Joel Sherrill, on Nov 19, 2018 at 8:22:35 PM) (diff)

Removed obviously out of date material that has current content elsewhere

Debugging

WARNING THE CONTENT MAY BE OUT OF DATE

Hardware Assisted Debugging

Embedded processors these days provide hardware assisted debugging. Typically the processor provides an interface which allows an external device the ability to take control of the processor. In the past hardware assisted debugging required an emulator. These were expensive, often difficult and fragile to connect to the target hardware and often limited in numbers in a project making debugging a time share operation. Any newer or faster processor usually required a new emulator. Todays microprocessors implement a range of functions found in emulators in the processor allowing every target the ability to be used for hardware assisted debugging.

Different microprocessors have different ways of the implementing hardware assisted debugging.

  • Freescale Coldfire and M683xx processors use Background Debug Mode (BDM).
  • ARM uses JTAG.
  • PowerPC MPC5xx and MPC8xx use BDM, while the rest of the PowerPC family uses various kinds of JTAG interfaces.

Coldfire and M683xx BDM

The BDM interface is a synchronous serial bus interface. The physical interface (connector) varies between the M683xx and Coldfire processor yet the way BDM works is similar. BDM is support by an Open Source Project which you can find here http://bdm.sourceforge.net/. The BDM project's software uses a low cost pod that connects between your target hardware. You can use the older parallel port pods that connect to your PC's parallel port or you can use the newer USB pods.

The USB pod is an open source design called the Turbo BDM Light Coldfire (TBLCF) created by Daniel Malik. You can download the design and build yourself http://forums.freescale.com/freescale/board/message?board.id=CFCOMM&thread.id=624 or you can obtain a manufactured pod from Axiom Manufacturing http://www.axman.com/?q=node/303.

If using a parallel port pod watch you get the correct pod. Different procesor speeds and core voltages require different pods. Newer pods should be able to handle the faster processors and different core voltages.

The latest version of the BDM software use a GDB server program and allows the use of the standard M68K GDB tool provided in the RTEMS binary tools packages.

Debugging a BSP

To test a BSP you need an application. The samples and tests provide a proven set of applications that allow you to test your BSP. Select a sample application such as the Hello World to try first, then move to an application that uses more interrupt sources.

The following is a list of debugging tools and setups that we recommended. Time spent on this will be rewarded further into the project:

  • Try to create a working debugger environment for the target hardware. The GNU debugger, GDB, supports a number of different ways to connect to a target. The interface can be a simple serial port using a GdbSerialMonitor, or an expensive TCP/IP type hardware probe.
  • If your target processor supports a simulator it is recommended you learn how to use it. It will give you a stable debugging enviroment.
  • Implement a printk interface in your BSP. For target hardware that does not have a video interface the printk outputs to a serial port. The driver is normally a simple polled UART driver.
  • Use the Capture Engine to aid the debugging and verfication of your real-time design.

BSP rtems_initialize_executive_late call dies

Your target is booting and the BSP is initialising but a call to rtems_initialize_executive_late results in an exception, or the target locking up. This can be due to a few reasons that you will need to work through.

  • The memory map is not correct. RTEMS use the WorkSpace? to create the initialization task, it's stack, the interrupt stack, plus more. If the WorkSpace? is wrong the target will die. The exact way depends on the specific processor and mapping error. If you have implemented printk it may be a good idea to add some code to bsp_pretasking_hook to show you the base and size:
          printk ("Heap : %5d KB @ 0x%08x\n   ", heap_size >> 10, heap_start);
  • The initialization process encountered an error. The set of these is documented in the Classic API C User's Guide. For RTEMS 4.6.1, this was documented in the Initialization Manager Failure section.
  • Interrupts are pending and no interrupt handler is present, or a bug exists in the interrupt handler, or vector table layout. RTEMS will enable interrupts when it switches to the initialization task rtems_initialize_executive_late creates. This problem can be found by getting to the context switch call, _CPU_Context_Switch, then the crash or lockup. The fix is to make sure the BSP has masked all sources of interrupts in the hardware around the processor. This allows RTEMS and the application an ordered and controlled initialization of driver and therefore interrupts.

The initialization task is a real task in RTEMS. The rtems_initialize_executive_late creates it and switches context to it. This means your BSP environment is another context that RTEMS will switch back to when RTEMS is shut down. This allows your BSP to take control again, then perform any specific functions it needs. A typical operational thing to do is to reboot as embedded targets should not stop.

GDB Cannot Find My Source Files

If you find the source code paths in your executable as seen by GDB are missing, you may find using an absolute path to invoke the RTEMS configure script may help. When RTEMS libraries get built, nested Makefiles are executed that walk through the build directory structure. Therefore, each file is compiled from a certain point in the build directory structure that lies in parallel to the source directory structure.

As a consequence of this, you get a varying number of "dots", depending on how deep the corresponding directory is inside the build tree. There is no common location, from which the source file pointers in the debug info is correct for all object files.

If you call the initial <tt>configure</tt> in an absolute way such as :

/usr/local/src/rtems/tools/rtems-4.6.0/configure

rather than a relative way :

../rtems-4.6.0/configure

GDB should find the source.

Starting With Hello World

Congratulations! You are a new RTEMS user and you just got the hello world example to run on either a simulator or target hardware. You are on top of the world. So you modify hello world -- wouldn't it be cool to put a sleep between some prints like this:

printf( "Hello world -- line 1\n");
sleep(1);
printf( "Hello world -- line 2\n");

That sleep() could be any other call which blocks the caller while time passes. But when you run this program, it only prints "Hello world -- line 1" and appears to lock up. What is happening?

The answer is simpler than you think. RTEMS is always custom configured to meet the requirements of an application. This means that the number and types of objects and device drivers available are tailored. The hello world application does not require a clock device driver and thus it is not configured. When you added the sleep(), you added a call which needs the clock device driver configured in order to work. All you have to do is added this line to the configure section of the application BEFORE including confdefs.h.

#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER

As you add to your program, you may have to increase the number of objects configured as well.

Standard IO and File Issues

Newlib's Stdio Functions return -1/EOF

The stdio functions in newlib depend on both initialised and uninitialised data. If you find they are returning -1, ensure your .bss and .data sections are correctly setup. Check your linkcmds file is creating the correct memory map and that your bsp boot process is copying/zeroing all appropriate sections in ram. It's also worth double checking that your ram and other hardware is working correctly!

open, fopen, and socket creation fail

RTEMS has very tight default configuration limits. Not being able to open a file or create a socket is a common error which indicates that you need to configure enough open file descriptors. By default, the constant CONFIGURE_LIBIO_MAXIMUM_DESCRIPTORS is set to 3 for stdin, stdout, and stderr. You will need to set it to the appropriate value for your application.

Optional Debugging Tools Provided by RTEMS

There are a number of optional debugging tools available with RTEMS that are not too well documented (yet!). These tools (and other goodies) can be found under cpukit/libmisc, and are well worth investigating.

Note: Most of what follows has been gleaned from the associated README files; I haven't added much original content, partly due to sloth, but more justifiably because I haven't yet used these tools extensively enough to be able to do any better! My primary purpose, at this point, in including these is so others, especially "nuBees" are aware of them.

= FUTURE ===

#Determine how/if gcc will generate stack probe calls and support that.