Kate debugs in hardware
Or how to debug embedded devices with Kate editor, GCC toolchain, OpenOCD and JTAG. Or, how to replace Eclipse in embedded developer’s work.
I do most of my work with open source software, including this running on PC desktop. Few years ago my environment of choice became KDE (KDE SC nowadays). One of areas in which this choice (not ideal) shows its superiority over other desktops is multitude of accompanying applications. And the most useful for me are text editors. This backyard is dominated by indissoluble duo: KWrite and Kate. As it appears, these tools (more precisely, Kate – as it is “bigger brother”) can be used to do much more than editing.
So if you sit with KDE and some embedded stuff in front of your eyes why not give Kate a try? Curiously enough, it took me a while to hit on this idea;)
I assume that you:
- have working GCC toolchain,
- know how to use GDB (most preferably),
- have proper Makefile(s), sources, linker scripts, vectors tables etc.,
- know how to configure and use OpenOCD,
- have hardware to play with (hardware debugger and target).
Start with regular Kate setup. Make new session, choose directory for it and import some source files – let us have something to play with. After that enable two plugins that Kate comes with: “Build Plugin” and “GDB”.
First one can execute “make” inside project directory, second gives actual ability to debug. Both of them extend interface of Kate a bit. This is how my editor looks now:
At top toolbar area appeared a bunch of unsurprisingly familiar buttons. I had to manually add first one (“Start debugging”). At the bottom there are two new activators: “Debug View” and “Build Output”. Open the first one and go to “Settings” tab, then click “Advanced Settings”.
This is where your desired setup may start to diverge from mine, but general guidelines should be the same for any case. In “GDB command” field put GDB executable name. Full path here is preferred, I didn’t manage to make it work relying on PATH. From select choose “Remote TCP”, set “localhost” as a host and “3333” as a port that GDB will connect to. OpenOCD usually binds there. In “Custom Startup Commands” type all instructions that GDB have to execute before start debugging. This is important step, as Kate doesn’t know anything about debug server and your target. Every initialization step you have to undertake should go here or to OpenOCD scripts. Most common are loading binary to flash, remapping memory, setting clocks. To program flash you can use either GDB commands (if they work) or pass OpenOCD instructions as argument of “monitor” (or shortly: “mon”) command – as I do. Note last line of my input: I make GDB automatically break on “main” function.
Back to Settings tab, set path to executable file (usually in ELF format). If you set working directory, executable can be just a file name. The nice thing about Kate GDB plugin is that apart from controlling GDB it gives you its command prompt (GDB output tab). To keep focus on GDB console, select “Keep focus”. If your setup handles IO redirection properly, you should be able to control it in tab “IO”, which appears after checking “Redirect IO”. Mine doesn’t, so I did not test it. I saved this setup under “openocd” name; use whichever you like. Configurations are easily selectable in “Debug > Targets” top menu.
Next, configure build add-on settings. Hit “Build Output” activator at the bottom and select “Target Settings” tab. Fill in working directory, and next three inputs. I chose “Build” command to run both clean and make so the “Quick compile” executes only make and “Build” rebuilds entire project. Again, you can save this configuration under arbitrary name and load it later in “Build > Targets”. Build plugin doesn’t have its own toolbar so commands will be available in “Build” top menu.
Let’s run it!
Having this done we can move into action. Build your project using menu “Build > Build”. Then go to “Terminal” activator and type OpenOCD startup command. This activator shows up after enabling “Terminal tool view” plugin.
For my target I execute:
openocd -f board/stm32f4discovery.cfg
Click “Start Debugging” button. GDB Output tab should appear:
This is just a GDB console. Debugger stopped at “main” function as we told it to do. You can type “c” (continue) directly in highlighted input box, or hit “Continue” button from toolbar. Before doing that set cursor in editor to certain place in main() and make there breakpoint with “Toggle breakpoint” button.
Breakpoint line gets light red background. Inserting breakpoints is possible only when program is not being run.
Toggling activator to the right of main window, we get local variables preview.
To sum up
There are few more options that both described plugins provide, but most of “the meat” ends here. This is no equivalent to Eclipse-based toolchain setup (not to mention others), but makes nice distinction (faster! not Java! …and not Java!). And also gives very good quality of text editing, something what KatePart is known of. There is even vi-like mode:) Should you happen to consider improving current state of GDB plugin, maybe to push it more towards embeded world or to contribute to Kate itself – do not hesitate, it’s authors will welcome your efforts warm. So do I!
23. February 2013 by resset
Categories: Electronics, Software | Tags: ARM, debugger, embedded, GDB, JTAG, Kate, KDE, make, Makefile, OpenOCD, toolchain | Leave a comment