(This is the first in an occasional series around the scripting in eclipse and CodeWarrior. Post a comment – let me know what you think!)
Writing code should be fun, and debugging it is just a necessity because I rarely get it right the first time. Eclipse with its GUI is a great thing, and so is a command line interface. Luckily the CodeWarrior eclipse engineers have added that kind of tool for the CodeWarrior debugger: the Debugger Shell as command line debugger using the TCL scripting language. This gives me a powerful way to deal with the embedded target board: from basic access to memory, to stepping and controlling the execution up to programming the flash memory.
The Debugger Shell is available from the Window > Show View menu:
A good command to use is help. This lists the built-in commands:
It has an auto-completion feature as well: start typing a command and then press TAB: this will show all matching commands with the syntax:
Most commands have as well a short version: so I can type help or just h. That saves me some writing time. Additionally I can use the cursor keys to go up and down my command history.
If I default launch configuration, I simply use the debug command:
%>debug Launching {1}: 0% complete : 0% complete : 7% complete Launching application: 7% complete Creating debug session: 7% complete Launching executable: 7% complete Preparing executable: 7% complete Loading symbolic information: 7% complete Finished loading symbolic information: 7% complete Preparing executable: 7% complete thread break: Stopped, 0x0, 0x0, cpu68K, test_UIWidgets.elf (state, tid, pid, cpu, target) thread set: Stopped, 0x0, 0x0, cpu68K, test_UIWidgets.elf (state, tid, pid, cpu, target) Downloading 14468 bytes...: 7% complete Download using 3rd party component...: 7% complete Download using 3rd party component...: 100% complete thread break: Stopped, 0x0, 0x0, cpu68K, test_UIWidgets.elf (state, tid, pid, cpu, target)
But how to know which one is the default launch configuration? There is the launch command which tells this:
%>launch *>0 - test_UIWidgets_MCF51JM128_Internal_Flash_PnE U-MultiLink [CodeWarrior Download] 1 - TWR-LCD JM128 Bootloader PnE [CodeWarrior Download] 2 - Attach FSLBOT MCF52259_Internal_Flash [CodeWarrior Attach] 3 - Tower MCF52259 HotSync [CodeWarrior Attach]
The line item with the star (*) denotes my current default launch configuration. Knowing the list of launches, I can use any index to debug a project:
%>debug 1
Or I can use the name:
%>debug "TWR-LCD JM128 Bootloader PnE"
Terminating or killing the debug session is simple using the kill command:
%>kill thread exit: Stopped, 0x0, 0x0, cpu68K, TWR-LCDBootloader.elf (state, tid, pid, cpu, target)
Stepping is easy: step asm or stepi steps an assembly instruction:
%>step asm %>stepi
There are as well stepping instruction to step over, step into or step out of a function:
%>step into %>step over %>step out
To set a breakpoint, I use the bp command. Using bp without argument will list my breakpoints as well.
%>bp main id instance address type enabled? process description #5 #1 m:0x00002f86 -auto ENABLED $0 ProcessorExpert.c, line 53, main [TWR-LCDBootloader.elf]
To resume the application, I use the command go:
%>go
If it does not hit a breakpoint, I use stop to halt the target:
%>stop
To inspect my variables, I use the var command:
%>var fileStatus $00 %>var BL_flashErased $01
And to inspect the memory, I use the mem command:
%>mem 0x00800874 16 800874 $0000177A $00002F84 $00002F98 $00002C8A z... ./.. ./.. .,.. 800884 $00000000 $00002C9C $00000000 $65000C03 .... .,.. .... ...e 800894 $4A004D00 $31003200 $3800001E $45FF0000 .M.J .2.1 ...8 ...E 8008a4 $0200EB3C $904D5344 $4F53352E $30000220 <... DSM. .5SO ..0
OK, that’s enough for now. This allows me to do all the basic debugging.
Next time I’m going to explore how I can script a debug session. I want to automate things. The goal is to use scripts for unit tests using the Debugger Shell.
Happy Shell Debugging 🙂
Pingback: Dump my Device Memory | MCU on Eclipse
Pingback: Breakpoints with Special Effects | MCU on Eclipse
Pingback: Debugger Shell: Test Automation | MCU on Eclipse
Pingback: Standalone Flash Programmer | MCU on Eclipse
Pingback: CodeWarrior Flash Programming from a DOS Shell | MCU on Eclipse
Pingback: Programming Kinetis with CodeWarrior from the DOS Shell | MCU on Eclipse
Hi Erich:
Your post helped me a lot.
I tired to use CodeWarrior 10.6 debug shell command “redirect stdout server 22018” to output the debug message to local host port 22018 in Windows 7. I used a Labview client, the TCP/IP connection between the server and client was established successfully, but no data transmit to the client. use command “var counter”, the data only displayed in the debug shell. I also tried other client, but the same, connection is good, no data flow. Please help at the best of your convenience. thanks for your time.
Changhe Huang
LikeLike
Hi Changhe,
I have to admit that I never have used that redirect command (did not remember that this one exists?). I would have suggested to use another client, but obviously you did that already.
I’ll have to check the documentation if I find any information about that feature.
Erich
LikeLike
I have read now the online documentation about this feature:
COMMAND redirect – redirect I/O streams of the current target process.
I read this that this is for the target process, and not for the host process. Or in other words: your target (say board) needs to write to stdout, not the debugger shell.
I’m not sure to what stdout the target needs to write, but I assume this is for semihosting. I don’t think I did semihosting with CodeWarrior, but I did e.g. with KDS (https://mcuoneclipse.com/2014/06/06/semihosting-with-kinetis-design-studio/).
I hope this guides you into the right direction?
Erich
LikeLike
Hi Erich:
Thanks for the quick reply.
What I want to do is to program microcontroller, read ADC register and other parameters like counter, then use my own software like python or LabVIEW to do calibration, and finally reprogram microcontroller. You already showed me how to program microcontroller by command line. Is it possible to output “var , mem” information into python or LabVIEW through “redirect” command, or there is any other method?
Best
Changhe Huang
LikeLike
I would not use the debugger for this. Instead I would have the target/board send that information say over USB or UART directly to LabVIEW.
LikeLike