Revised 2012-02-18

NOTE: Use these instructinos to enable source level debugging via serial port with the UDK_TM_B9_srcdbg.rom BIOS image for the Intel DQ57TM UEFI 2.3.1 Development Kit

1. Configure Debug Host Machine
The Intel(r) UEFI Development Kit Debugger Tool is available for Windows and Linux. Please refer to "UDK Debugger Tool User Manual.pdf" published in "Intel UEFI Development Kit Debugger Tool" for installation instructions.

http://www.intel.com/content/www/us/en/architecture-and-technology/unified-extensible-firmware-interface/intel-uefi-development-kit-debugger-tool.html

2. Step by step on how to debug IHV code through serial cable
a) Burn bios image which supports Source Level Debug feature to the target board.
   (UDK_TM_B9_srcdbg.rom)
   
b) Use serial cable to connect host and target machines
   User needs to record which serial port of host machine is used.

c) Configure Intel UDK Tool
   Select Start -> All Programs -> Intel UDK Debugger Tool -> Change Configurations
   (1) Ensure that the value of "Port" field in "Debug Port" section is the port recorded at the above step.
   (2) Ensure that the values of "Executable" and "Directory" fields in "Debugger" Section points to the actual installation path of Debugging Tools for Windows.
       
   Note: Please use Administrator Privilege to edit/save the configuration changes at Windows 7.

d) Build the driver or application to be debugged at host machine
   Recommend disabling compiler optimization. Such as for VS2008 compiler, add /Od and /GL- compiler option.

   There are three ways to help debugging source code.
   (1) Add CpuDeadLoop() statement in source code where user want to debug.
       In this way WinDbg will show "Debuggee is running". User should manually halt the execution flow by pressing F5 and jump out the dead loop by changing Instruction Address.
   (2) Add CpuBreakPoint() statement in source code where user want to debug.
       In this way WinDbg will automatically halt at the line user adds the statement.

   Note: CpuDeadLoop()/CpuBreakPoint() is specific for EDKII driver or application. For Edk driver, user may use EFI_DEADLOOP() and EFI_BREAKPOINT().
   (3) Manually open driver or application source code at WinDbg and select the line user want to debug and press F9.
       In this way user can add breakpoint even if the code is not loaded into memory.

e) Debug the driver or application
   (1) Run "Start WinDbg with Intel UDK Debugger Tool" from Windows Start -> All Programs -> Intel UDK Debugger Tool.
       WinDbg will show "debugger not connected".
   (2) Power-on or restart the target machine.
   (3) WinDbg will show "Kernel Debugger connection established" and halt at early phase of bios boot.
   (4) Enter "g" or press F5 to continue bios code execution flow.
       WinDbg will show "Debuggee is running".
   (5) Waiting for bios code booting to shell or entering setup page.
   (6) Insert usb disk which have the driver or application binary to be debugged.
   (7) Run "connect -r" at shell.
   (8) Run "map -r" to show all block devices.
   (9) Go to the file system in usb disk and manually run "load driver.efi" cmd or "application.efi" cmd.

f) an example on how to debug HelloWorld application by WinDbg
   (1) Build the application.
       This application locates at MdeModulePkg\Application\HelloWorld
   (2) Copy the generated HelloWorld.efi into usb disk.
   (3) Execute e) step (1) ~ step (8)
   (4) Halt WinDbg by pressing F5, open HelloWorld.c in WinDbg, add breakpoint at any statement in UefiMain(). Press F5 again to make WinDbg run.
   (5) Go to the file system in usb disk and execute "HelloWorld.efi" at shell.
       User will see the WinDbg halt at the line user add breakpoint.

g) an example on how to debug DriverSample driver by WinDbg
   (1) Build the driver.
       This driver locates at MdeModulePkg\Universal\DriverSampleDxe
   (2) Copy the generated DriverSample.efi into usb disk.
   (3) Execute e) step (1) ~ step (8)
   (4) Halt WinDbg by pressing F5, open DriverSample.c in WinDbg, add breakpoint at any statement in DriverSampleInit (). Press F5 again to make WinDbg run.
   (5) Go to the file system in usb disk and execute "load DriverSample.efi" at shell.
       User will see the WinDbg halt at the line user add breakpoint.
