2

As I understand, on linux systems debugging is done via the ptrace sys-call.
I would like to know how would I write a debugger for a micro-controller (no-OS).
Let us for the sake of simplicity assume the case of a software debugger for a board like Arduino Due (ARM based).

  • What would I have to learn to accomplish such a project, assuming I have a fair idea on how debuggers work on Linux and Windows
  • How different would programming a debugger for a MCU system be? (I can't use sys-calls)
  • Is debugging achievable via USB or serial interface?
  • Which languages should I use? (C, C++, Arm assembly)
  • How can the armgcc compiler help me with my project (are there flag options such as -g etc?)

I plan to implement the debugger as a command line Linux utility.

2
  • Read Gdb internals documentation (now a wiki) Commented Jan 22, 2014 at 17:24
  • 2
    I recommend you have a look at GDB debugger stubs. These are tiny, easily-implementable pieces of code that communicate with GDB over serial using the GDB Remote Serial Protocol. It is documented here (sourceware.org/gdb/current/onlinedocs/gdb/Remote-Protocol.html) and an example is here (embecosm.com/appnotes/ean4/…). You would then connect to your board with target remote. The protocol consists essentially of text packets beginning in $, followed by a command and its arguments, and ended with # and a checksum. Commented Jan 22, 2014 at 17:27

1 Answer 1

3

Most modern processors, including the ARM on the Arduino Due have on-chip debug support accesses via a JTAG interface. The Cortex-M3 on-chip debug supports 8 hardware breakpoints and some other features - with code running in flash memory you cannot set software breakpoints.

The JTAG interface itself is rather simple, but you will need special hardware to support it from a PC. Depending of performance and features a JTAG debugger may vary in cost hugely from very low to serious money. Software to interface the JTAG to the debugger software is required. OpenOCD is an open source tool for interfacing JTAG/On-chip debug to GDB allowing GDB-ARM to be hosted on a PC to debug the remote ARM target.

You could in theory write your own software to to access the OCD via JTAG. I have never considered implementating a target hosted debugger on a microcontroller, although I have used VxWorks on ARM9, SrongARM and x86 and it has limited support for target hosted debugging. The utility of target hosted debug is limited by the lack of the source code and symbol table information that is available to a hosted debugger to support source-level debugging.

Even so, I believe that it is possible to access the on-chip debug from the target itself see ARM's documentation for details.

Sign up to request clarification or add additional context in comments.

2 Comments

There's an intermediate possibility, too - remote debugging where the debugger program and symbol tables are on the development machine, but using a stub such a gdbserver running on the target rather than JTAG/SWD. While this won't work if the target is completely non-functional, it does have the advantage or running over end-user interfaces like async serial, USB, or network - unlike JTAG/SWD which require debug-only electrical connections.
@ChrisStratton: True, but the debug stub will still need to access the CoreSight OCD to set breakpoints in code running from Flash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.