Using Advanced Platform Builder Debugger Features
E N D
Presentation Transcript
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
Desktop Windows CE Device cemgr.exe KITL kernel (nk.exe) KdStub (kd.dll) Platform Builder Debugger (cepb.exe) foo.exe Debugger Architecture
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
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
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
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
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
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 3rd 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 eXDI Callbacks OsAxS.dll Debugger (PB) Probe (JTAG,BDM…) or Emulator Driver eXDI Interface Can launch eXDI Callbacks Plug-ins CPU Plug-ins Plug-ins Optional 3rd party interface Plug-ins
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
Tools & Resources Build Develop Websites msdn.microsoft.com/embedded msdn.microsoft.com/mobility Newsgroups microsoft.public.pocketpc.developer smartphone.developer dotnet.framework.compactframework microsoft.public.windowsxp.embedded windowsce.platbuilder windowsce.embedded.vc Blogs blogs.msdn.com/mikehall blogs.msdn.com/windowsmobilevsdteamnetcfteam Tools Windows CE 5.0 Eval KitWindows XP Embedded Eval Kit Windows Mobile 5.0 Eval Kit
大会注意事项 请在课程结束后填写课程培训反馈表,参加抽奖。 请填写资料袋内的黄色大会来宾反馈表,到大会接待台领取大会纪念包。 您还可以: 参加Windows Mobile动手实验室; 参观微软及合作伙伴展区; 体验基于 Windows Mobile平台开发的最新硬件产品及解决方案。