When working with debug messages, keep in mind that heavy use of debug messages slows down code execution. Perhaps even more important, the system serializes the debug output operations, which can provide an unintentional thread synchronization mechanism. For example, multiple threads running unsynchronized in release builds might cause issues not noticeable in debug builds.

When working with debug messages and debug zones, consider the following best practices:

¦ Use Conditional statements Use debug macros with conditional statements based on debug zones. Do not use DEBUGMSG(TRUE). Also avoid using retail macros without conditional statements, such as RETAILMSG(TRUE), although some model device driver (MDD)/platform dependent driver (PDD) drivers must use this technique.

¦ Exclude debugging code from release builds If you only use debug zones in debug builds, include the global variable dpCurSettings and zone mask definitions in #ifdef DEBUG #endif guards and restrict the use of debug zones to debug macros (such as DEBUGMSG).

¦ Use retail macros in release builds If you also want to use debug zones in release builds, include the global variable dpCurSettings and zone mask definitions in #ifndef SHIP_BUILD #endif guards and replace the call to DEBUGREGISTER with a call to RETAILREGISTERZONES.

¦ Clearly identify the module name If possible, set the dpCurSettings.lpszName value to the module's file name.

¦ Limit verbosity by default Set the default zones for your drivers to ZONE_ERROR and ZONE_WARNING only. When bringing up a new platform, enable ZONE_INIT.

¦ Restrict the error debug zone to unrecoverable issues Use ZONE_ERROR only when your module or significant functionality fails due to incorrect configuration or other issues. Use ZONE_WARNING for recoverable issues.

¦ Eliminate all errors and warnings if possible Your module should be able to load without any ZONE_ERROR or ZONE_WARNING messages.

Target Control Commands

The Target Control service provides access to a command shell for the debugger to transfer files to the target device and debug applications. This target control shell, displayed in Figure 4-3, is accessible from within Visual Studio with Platform Builder via the Target Control option on the Target menu. However, it is important to keep in mind that the target control shell is only available if the Platform Builder instance is attached to a device through KITL.

Figure 4-3 The target control shell

Among other things, the target control shell enables you to perform the following debugging actions:

¦ Break into the Kernel Debugger (break command).

¦ Send a memory dump to the debug output (dd command) or to a file (df command).

¦ Analyze memory usage for the kernel (mi kernel command) or the entire system (mi full command).

¦ List processes (gi proc command), threads (gi thrd command), and thread priorities (tp command), as well as the modules loaded on the system (gi mod command).

¦ Launch processes (s command) and end processes (kp command).

¦ Dump the processes heap (hp command).

¦ Enable or disable the system profiler (prof command).

NOTE Target control commands

For a complete list of target control commands, see the section 'Target Control Debugging Commands' in the Windows Embedded CE 6.0 Documentation, available on the Microsoft MSDN® Web site at http://msdn2.microsoft.com/en-us/library/aa936032.aspx.

Debugger Extension Commands (CEDebugX)

In addition to the regular debugger commands, the Target Control service provides the debugger with a debugger commands extension (CEDebugX) to increase the efficiency of kernel and application debugging. This extension provides additional features to detect memory leaks and deadlocks and diagnose the overall health of the system. The additional commands are accessible through the target control shell and start with an exclamation point (!).

To use CEDebugX, you need to break into the Kernel Debugger by using the break command in the target control shell or the Break All command on the Target menu in Visual Studio. Among other things, you can then enter a !diagnose all command to identify the potential reason for a failure, such as heap corruption, deadlocks, or memory starvation. On a healthy system, the CEDebugX should detect no any issues, as illustrated in Figure 4-4.

Figure 4-4 Diagnosing a run-time image with CEDebugX

The !diagnose all command runs the following diagnostics:

¦ Heap Diagnoses all the heap objects of all processes on the system to identify potential content corruption.

¦ Exception Diagnoses an exception that occurs on the system and is able to provide details on the exception, such as process and thread ID, and PC address at the exception time.

¦ Memory Diagnoses the system memory to identify potential memory corruptions and low memory conditions.

¦ Deadlock Diagnoses the thread states and system objects (see Chapter 3 for more details on thread synchronization). It can provide a list of system objects and thread IDs that generated the deadlock.

¦ Starvation Diagnoses threads and system objects to identify potential thread starvation. Starvation occurs when a thread is never scheduled on the system by the scheduler because the scheduler is busy with higher-priority threads.

Advanced Debugger Tools

The target control shell and CEDebugX commands enable you to perform a thorough analysis of a running system or a CE dump file (if you select the CE Dump File Reader as the debugger to perform postmortem debugging), yet you are not restricted to the command-line interface. Platform Builder includes several graphical tools with a dedicated purpose to increase your debugging efficiency. You can access these advanced debugger tools in Visual Studio via the Debug menu when you open the Windows submenu.

The Platform Builder IDE includes the following advanced debugger tools:

¦ Breakpoints Lists the breakpoints enabled on the system and provides access to the

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату