PEmicro Blog

FreeRTOS: PEmicro Introduces OS-Aware Debugging in GDB Server for ARM devices

Mar 08, 2017

There comes a time when an embedded application becomes complex enough that it requires an operating system. This may be because of a need for rich driver libraries, or a sophisticated task scheduling engine. In either case, a developer needs an equally sophisticated debugger to provide invaluable context information of their application. To that end, PEmicro introduced OS-aware debugging in its GDB Server for ARM devices. Initial support is available now for FreeRTOS, with further OS modules to be developed. PEmicro's GDB Server for ARM devices is available for download at no cost and works with PEmicro Multilink, Cyclone, and OpenSDA hardware interfaces.

How Does It Work?

With PEmicro's OS-aware debugging plugin for Eclipse, the user does not have to do anything to set it up. The GDB server will automatically detect the presence, type, and configuration of an OS by the querying the application's symbol table for identifying characteristics. Using these discovered symbols, the debugger can traverse the kernel's internal data structures to enumerate the available threads and their corresponding execution context. This information is then used to dynamically populate the Eclipse views as the user navigates between the threads.

Getting Started

PEmicro GDB FreeRTOS support can be added into many Eclipse IDEs including :

For this example, NXP's Kinetis Design Studio is being used in conjunction with the MCUXpresso SDK with the FreeRTOS option enabled. A different example can be seen on the popular MCUOnEclipse blog.

MCUXpresso SDK Builder
Figure 1: Enable FreeRTOS Option in MCUXpresso SDK Builder

The MCUXpresso SDK Builder will generate a package containing libraries and the OS code custom built for the target device. Within each SDK are a number of example projects that demonstrate core OS concepts.

Example Projects
Figure 2: Example Projects

These projects are a great way to start building applications with FreeRTOS because they are guaranteed to be properly configured and compilable by the SDK builder.

Debugging one of these projects is just as easy when using a PEmicro debug probe in combination with the GDB server plugin. Upon creation of the new example project, the IDE will automatically generate a debug profile that can immediately be used to debug the target using the default settings.

Launch Configuration
Figure 3: Launch Configuration

Upon successful detection of a supported OS, the server will print "Successfully initialized kernel symbols." to the console window. Also, once the server detects that the scheduler has started it will print out "Kernel thread information now available." to the same console. At this point, thread information will begin to appear in the Eclipse views. These can be a quick ways of diagnosing problems with the project's setup in case auto detection fails.

Using the freertos_sem project, a user can learn how to debug a multi-threaded producer/consumer application using OS aware debugging. What this project does is create a producer thread that can unblock one of many consumer threads at any given time. The effect is that the producer prints a message to the console, blocks itself, and unblocks an arbitrary consumer. This consumer then prints its thread ID to the console, unblocks the producer, and blocks itself which completes the loop as depicted below.

FreeRTOS_sem Example
Figure 4: FreeRTOS_sem Example

With OS aware debugging enabled, all of these threads will be visible in the debug view of Eclipse. Here the stack trace, execution state, and name of each thread is visible. The most useful feature of this view though is that it allows the user to dynamically update the content of each Eclipse view to match any point of interest. For example, the code view can be updated to reflect the current program counter of another thread by simply clicking the point in the stack trace. Further, the variable values are also updated according to thread even if they point to the exact same code.

Dynamic Views
Figure 5: Dynamic Views (CLICK TO ENLARGE)

Overall, PEmicro's OS-aware debugging eases the development of complex multi-threaded applications using an approach that's completely invisible to the user. Interested users can get it now by updating an existing installation or installing it directly from the PEmicro Eclipse update site.

Tags related to this Blog Post

GDB Server     ARM