Uncategorized

Debugging Embedded Microprocessor Systems

First of all, software trace requires you to instrument your code. If you have an existing codebase that does not have trace instrumentation, it could take months to insert trace statements in all of the interesting code fragments. And if you overlook some of the interesting code or neglect to instrument some functions, you may spend a good deal of time investigating the wrong cause of your bug.

A second advantage of hardware trace data is that it often has the ability to provide data values along with each instruction that is executed. This lets you see the values that caused the program to take the incorrect execution path, which gives you more insight into what caused the problem and how to fix it. While you can certainly log values with software trace, it is impractical to log more than a few, and if a bug occurs and you did not instrument one necessary value then you may not be able to find the cause of your bug.

This is vital for applications that may involve timing errors, interrupt latency issues, or other bugs that only appear when a specific set of circumstances arises. Additionally, it is often impractical to instrument code in interrupt handlers or other timing-sensitive code.


  1. Berkeley: Philosophy in an Hour.
  2. Cause a Disturbance: If You Can Slice a Melon or Make a Right-Hand Turn, You Can Be a Breakthrough Innovator;
  3. Bard King (Polis Book 2)?
  4. Swamp Sniper (A Miss Fortune Mystery, Book 3).
  5. Reward Yourself?
  6. The Thief Who Pulled On Troubles Braids (Amra Thetys Series Book 1).
  7. What is Kobo Super Points?;

In nearly all high-reliability applications, you must certify and test the final code without any instrumentation, and software trace almost certainly cannot be enabled in production code, making it impossible to use software trace to track down bugs that appear in the production version of the code. Hardware trace data is generated and output by microprocessors and collected using a Trace Port Analyzer TPA , which is a device that records trace data from a microprocessor and stores it into a trace buffer on the device. This data is output over a dedicated trace port and consists of a stream of highly compressed packets.

Figure 1 shows a trace collection system with a microprocessor outputting trace data that is collected by a TPA and a PC that software engineers use to debug software. Trace data essentially consists of a log of each instruction that is executed by the processor. This is often referred to as "PC Trace" because it is a simply a list of PCs executed by the processor.

Many trace implementations also contain information about data that is read from and written to memory called "Data Trace" , as well as information about when context switches and interrupts occur. This information combines to give you a complete view of exactly what the processor was doing as your system was running. Trace data lets you debug either a single application or the entire system by showing you the interactions between various tasks and interrupts. This is essential for finding the most difficult bugs in complicated systems.

As you can imagine, collecting a full log of the PCs executed and data values accessed involves a lot of data.

Embedded Systems

For instance, if you have a processor running at MHz and executing roughly one instruction per cycle, storing a full trace log of bit PCs involves storing roughly MB of trace data per second. On top of this, if 20 percent of the instructions are data accesses assuming data trace consists of bits of address and bits of data , then that is another MB of data per second. That's well over 1 GB of data per second for a relatively slow processor! Due to this high volume of data, the designers of trace-enabled microprocessors have implemented efficient compression systems to minimize the amount of data that is streaming out of the processor.

With these compression schemes, trace ports generally output between 4 and 20 bits per cycle, depending on the compression scheme, whether data trace is available, and how many pins the chip designers are willing to dedicate to trace. Even with a high rate of compression, trace data still uses very high bandwidth. Thus, even a very large trace buffer on a TPA fills up in a few seconds or less. To allow tracing over longer periods of time, the devices that collect trace data generally use a circular buffer to constantly collect data, always throwing away the oldest data once the buffer is full.

Using a circular buffer to collect trace data makes it important to be able to precisely stop trace collection when a problem occurs because the trace buffer wraps around so quickly. This problem is solved by "trace triggers," which are special signals from the trace hardware that are sent through the trace port when a condition defined the user occurs.

Potential trigger conditions include executing a specific instruction and reading from a selected memory location. When the TPA receives the trigger signal, it collects a user-defined portion of the buffer and then stops trace collection. For instance, you can configure the TPA to trigger in the center of the trace buffer, which collects half of your trace buffer before and half after the trigger occurs. Likewise, you could put the trigger at the beginning or end of the buffer, or anywhere in between, depending on what information you are trying to collect.

For example, if you are trying to debug an error message that occurs intermittently, you could set a trigger to occur when the error message is printed. Further, you could configure the trigger to occur at the end of the trace buffer. Once the error message is printed with trace collection enabled, your trace buffer will contain information about what instructions were executed prior to the error message. You will now be able to examine in detail the code paths that were executed, looking at memory and register values to help you determine what caused the error message you are interested in.

Once the trace data is collected, the analysis software uploads the data from the TPA and decompresses it. After decompressing the trace data, the trace-analysis software displays the list of instructions that were executed. However, because most software is written at a much higher level than assembly code, a list of instructions executed by the processor is not all that useful to software engineers. Software that can analyze this information and present it to software developers in an easy-to-understand format that allows them to see exactly what is happening in their system is a major benefit that trace data can provide to the embedded software development process.

One of the best examples of a situation where trace data is particularly useful is a system that suffers from resource contention problems. For instance, if two tasks try to access a shared memory-mapped bus without some sort of locking mechanism, one or both tasks will get incorrect values. This could cause any number of system glitches and errors.

This type of problem is often not obvious from looking at the source code for either task because the bug only occurs due to the interaction between two tasks. Additionally, in complicated systems, this type of problem may occur infrequently, making it even harder to track down the root cause. With trace, as long as you catch the bug occurring one time, you have a good chance at discovering the root cause and fixing the bug. Listing One is a simplified example of two tasks incorrectly sharing a resource. In this case, two tasks read from the I 2 C bus on a processor.

Roughly, an I 2 C bus is a serial bus requiring multiple transactions to read a single piece of data, including selecting a device and then reading from the selected device.

Using Trace to Debug Real-Time Systems | Dr Dobb's

Task A checks for an invalid reading from the temperature sensor and prints an error when it gets an invalid reading. You can set a trigger to occur when the error condition printf statement is executed. Then enable trace when you start running the program and wait for the trigger to be hit. Once the trigger is hit, the trace data will be loaded into the trace-analysis software and you will be able to look at what happened in your system prior to the error. Many trace-analysis software packages convert the list of instructions executed by the processor into a list of functions that were executed and what task was running at each point in time.

This is a relatively elementary type of analysis that can give useful information to programmers debugging a system. For this example, Figure 3 shows a sequence of functions and context switches that indicate that a context switch occurred after selecting one device on the bus but before reading the data from that device. From examining this series of function calls, it is clear that one task initiated an I 2 C bus transaction while another bus transaction was in progress. However, especially since these two devices seem unrelated at first glance, traditional debugging techniques will probably not uncover this bug nearly as quickly as the trace tools.

Trace data also makes performance analysis easy by processing a trace log and displaying profiling information. This lets you easily see how much processor time each part of your system uses without requiring any code instrumentation or other overhead.


  • The Imperative Mood.
  • Lilys Story.
  • Join Kobo & start eReading today.
  • Using Trace to Debug Real-Time Systems;
  • Embedded Systems Recent Articles;
  • Additionally, because it does not require any code modifications, profiling information generated from trace data lets you see how long various interrupt handlers take when they run and let you identify situations where various components will not meet their real-time deadlines. Making Sense of Sensors. PC Systems, Installation and Maintenance. The Conservative Party and British Politics - Conservative Politics in National and Imperial Crisis.

    There was a problem providing the content you requested

    The Heath Government How to write a great review. The review must be at least 50 characters long. The title should be at least 4 characters long. Your display name should be at least 2 characters long. At Kobo, we try to ensure that published reviews do not contain rude or profane language, spoilers, or any of our reviewer's personal information.

    You submitted the following rating and review. We'll publish them on our site once we've reviewed them. Item s unavailable for purchase. Please review your cart. You can remove the unavailable item s now or we'll automatically remove it at Checkout.

    Account Options

    Continue shopping Checkout Continue shopping. Chi ama i libri sceglie Kobo e inMondadori. Available in Russia Shop from Russia to buy this item. Or, get it for Kobo Super Points! Addresses real-world issues like design changes, time pressures, equipment or component availability Practical, time-saving methods for preventing and correcting design problems Covers debugging tools and programmer test routines. Ratings and Reviews 0 0 star ratings 0 reviews. Overall rating No ratings yet 0. How to write a great review Do Say what you liked best and least Describe the author's style Explain the rating you gave Don't Use rude and profane language Include any personal information Mention spoilers or the book's price Recap the plot.

    Close Report a review At Kobo, we try to ensure that published reviews do not contain rude or profane language, spoilers, or any of our reviewer's personal information.

    Would you like us to take another look at this review? No, cancel Yes, report it Thanks!

    Debugging Embedded Microprocessor Systems