Using Advanced Platform Builder Debugger Features Chenghui Lian Microsoft China Technology Center
Agenda Introduction to the PB Kernel Debugger Tools for debugging Remote tools Demo
Debugger Architecture foo.exe KdStub (kd.dll) kernel (nk.exe) Windows CE Device Desktop cemgr.exe Platform Builder Debugger (cepb.exe) KITL
PB kernel debugger VC++ version 6 roots –Familiar UI –Rich in features System Debugger –Exceptions from any process –Stops interrupts while in break state –Uses KITL connections –HW Assist thru 3rd party support Debugging Applications –Slightly different from eVC
Debug build vs. retail build –Debug Full debugging on by default Optimizations off can be easier to debug More messages output –Retail Default: IMGNODEBUGGER =1 Optimizations enabled Code Movement Less messages output
Debug/Retail Build vs. Debugger Debug/Retail build –Optimization off/on –Compiler options –Controlled by “set wincedebug=debug” or “set wincedebug=retail” Debugger –Modules included in run time image to enable debugging –Controlled by “set IMGNODEBUGGER=”
Tools for debugging System debugging Hardware-assisted debugging Kernel profiler
Target State: Running CE Target Control service (shell.exe) populates Data Windows Processes Moduales –Path to *.pdb for each loaded module –Image Address & Relocated Address –Can Manually Unload symbols Threads –Call Stack for each thread only available when device is in break-state
Process Window (run)
Modules Window (run)
Threads Window (run)
Target State: Halted Can set Breakpoints Threads window includes call stacks Can set behavior for Exceptions Call Stack Window Watches Window Auto / Locals / this Window Registers Window Memory Window Disassembly Window
What are Breakpoints? Replace instruction with trap (ie INT 3) Requires Write Access to Instruction Kernel will page-in memory and lock Source-level stepping is implemented with breakpoints Max 256 BP Can set BP in call stack, source, or disassembly
Types of Breakpoints Location Breakpoints Conditional Breakpoints –Based on expression (iFoo == 27) Data Breakpoints –When iFoo changes, break –Can watch an array, and can limit scope Message Breakpoints –Break when window message received in a specific context Cond., Data, and Msg Breakpoints are based on VS6 implementation
Edit \ Breakpoints (ctrl+b)
Exceptions Control KdStub passes all exceptions to debugger (when connected) Specify behavior per exception type –Stop Always Debugger will break on each instance of an exception –Stop if not handled Debugger will return control to application’s exception handler (first chance). Can add custom exception types
Target \ CE Exceptions
Call Stack Switch process / thread context easily Frame Pointer Parameter values and types Source file and line number Can set breakpoints on function return Can “go to source” on each frame Can quickly log entire callstack output window
Call Stack Window
Disassembly Window Essential for debugging retail devices Can set breakpoints in disassembly Can be set to “Mixed Source” Mode Works best with Debug build Can “Jump to Source” Can view raw code bytes or assembler instructions All CE CPU types supported
Debug Zone What is the simplest software debugging technique? –Output debug messages from applications –OutputDebugString API function allows you to output a debug message You can control the output of debug messages using debug zone. –If a debug zone is open, all messages sent on behalf of this zone will be accepted. –If a debug zone is closed, all debug messages for this zone will be ignored.
Debug Zone Allows you to access the debug zones of any registered module Dynamically turn on or off any debug zone on your platform Makes it easier to locate a particular debug message in the debug stream
Dynamically turn on/off debug zone
Using Debug Zone in Your Code Include DbgApi.h header file in your source code Declare a DBGPARAM structure that contains: –Module name –A name for each debug zone –An initial mask for the output status of all debug zones DBGPARAM structure must be called dpCurSettings dpCurSettings must be a global variable in your module
Hardware Assisted Debugging Can debug device without KdStub! Requires a 3 rd party probe & driver Same look and feel, tight integration Can debug *all* code –Can debug Device Bootup (ie OEMInit()) –Interrupt Service Routines –Bootloaders Can set breakpoints / step in ROM Additional features provided by probe –Tracing, Triggers, etc…
HW Debugging: eXDI Debugger(PB) Probe ( JTAG,BDM… ) or Emulator CPU eXDI Callbacks eXDI Interface Plug-ins Plug-ins Plug-ins Plug-ins eXDI Callbacks Driver Optional 3 rd party interface OsAxS.dll Can launch
Limitations of HW Assist Potentially Expensive Fewer available breakpoints (generally) Potentially more complicated setup Because no KdStub… –No kernel Data Windows (when halted) –Cannot view / edit all memory Cannot page-in memory on demand –No Module Load Notifications No Deferred Breakpoints Static (manual refresh) Modules List
HW Debug Probe Vendors ARM - ARM cores EPI - ARM cores, XSCALE, MIPS IV Hitachi - SH3, SH4 MacGregor/Intel - XSCALE NEC/Midas – MIPS II, MIPS IV Special Computing - X86, AMD, NSC Geode
Just-In-Time Debugging Required: Passive KITL Exception Occurs (“first chance”) –if(dbgr) passed to Debugger –if(!dbgr) application’s exception handler is called If application does not handle (“second chance”) –if(!dbgr) KdStub halts OS, waiting for debugger connection When Debugger connects, can debug failure!
Kernel Profiler Debugging tool to collect various information –Monte Carlo profiling –System call profiling –Instrumented kernel profiling
Kernel Profiler Controlling the kernel profiler –Using prof command –Using profiler API –Using keyboard on the target device Mode of kernel profiler –Buffered –Unbuffered
Remote tools Remote heap walker Remote process viewer Remote spy Remote call profiler Remote kernel tracker Remote performance monitor
Remote tools
Tools & Resources msdn.microsoft.com/ embedded microsoft.public. windowsxp.embedded windowsce.platbuilder windowsce.platbuilder windowsce.embedded.vc windowsce.embedded.vc blogs.msdn.com/ mikehall Windows CE 5.0 Eval Kit Windows XP Embedded Eval Kit msdn.microsoft.com/ mobility microsoft.public. pocketpc.developer smartphone.developer dotnet.framework.compactframework blogs.msdn.com/ windowsmobile vsdteam netcfteam Windows Mobile 5.0 Eval Kit Websites Newsgroups Blogs Tools Build Develop
请填写资料袋内的黄色大会来宾反馈表, 到大会接 待台领取大会纪念包。 请在课程结束后填写课程培训反馈表,参加抽奖。 您还可以: 参加 Windows Mobile 动手实验室; 参观微软及合作伙伴展区; 体验基于 Windows Mobile 平台开发的最新硬件产品及解决方案。 大会注意事项