Expanding Debugging Capabilities with UDB Addons

Expanding Debugging Capabilities with UDB Addons

At Undo, we make a full product release once a quarter. Each release debuts new features and capabilities, and increases our support for newer Linux distributions and CPUs. For instance, the recent 8.2 release introduces support for pointer authentication, a feature of ARM CPUs designed to improve memory safety. All these changes are of course carefully designed and fully tested. But there are lots of ideas that we’d like to share with our users, that aren’t quite ready to appear in the main product just yet.

Enter addons. Addons allows us to provide extra capabilities and iterate on them quickly, without having to wait for a full release. From version 8.2 of UDB, addons can be installed from the UDB prompt. Just type extend to get a list of currently available addons, and extend NAME to install.

Type extend to get a list of currently available addons

Addons don’t persist between runs of UDB, but you can put the extend NAME command into an initialization file so that they will be present every time UDB is started.

Let’s take a look at some of the addons available so far.

Better backtraces

Pretty much anyone who’s tried to debug a codebase of any size will have used a stack backtrace at some point. Typing the bt command in GDB can become second nature after a while. But it’s also really useful to know when a function was called, for a couple of reasons. First, it gives you more context: the longer a function has been running, the more likely it is that whatever went wrong happened during the function versus before it was called. Second, with a time travel debugger it’s not just a matter of interest – you can actually go there! 

The ubt addon is very simple: it introduces a new command, imaginatively named ubt, which adds a “bbcount” (Undo’s internal time unit) to each line of the backtrace, like this:

The ubt addon adds a bbcount to each line of the backtrace

Viewing variables

Another task that developers face during debugging is understanding why a variable, let’s call it x, came to have an unexpected value. Assuming you can track down the relevant assignment, say x = a + b, it still leaves the question of whether a or b is wrong. In unfamiliar code, dodgy values may not stand out. When logging values is inconvenient, it’s tempting to engage in lots of backward reasoning to work out what the unlogged values must have been, frequently with no better tool than some hastily scribbled notes, and at the risk of one mistake bringing down the whole chain of logic. 

Instead of that, why not watch all the variables as the function progresses? This is what the value-tracer addon can do. You can see each line of code, and the updates to the variables after each line, using the value-tracer-function command:

Value-tracer addon enables you to see each line of code and the updates to the variables after each line

Or in a more compact format with the value-tracer-inline command. In this view it’s easier to see the algorithm performing multiple iterations of a do…while loop as it converges on the result.

Or in a more compact format with the value-tracer-inline command. In this view it’s easier to see the algorithm performing multiple iterations of a do…while loop as it converges on the result.

Watching waveforms

Addons are also a useful way to support specific classes of applications.  In the Electronic Design Automation (EDA) industry, for example, systems are frequently modeled using SystemC. For the uninitiated, SystemC is a set of C++ classes which allow the programmer to create logic elements whose inputs and outputs are wired together to achieve an overall design. When the input signals change, such as when the system clock ticks, elements are triggered to examine their inputs and recalculate their outputs.

SystemC supports a tracing mechanism for logging signals – the downside is that logging all signals is prohibitively slow, and tracing can only be configured at the start, which is not great news if the simulation takes hours to run and you realize that a vital signal is missing.

With a recording, all things can be made visible. The systemc-trace addon extracts signal information, bypassing the normal tracing mechanism which allows it to work on runs where tracing was never enabled. It outputs the information in a standard VCD (Value Change Dump) format, which can then be displayed in an oscilloscope-like waveform viewer:

systemc-trace addon extracts signal information, and outputs it in a standard VCD format.

We’re just getting started with addons, so watch this space for more!

Stay informed. Get the latest in your inbox.