Scripting: The Debugger Shell, Getting Started…
Join the DZone community and get the full member experience.
Join For Free(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
Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments