Last time, we looked at how to set up the Windows-hosted (NT32) UEFI environment provided by the EDK2. The NT32 environment is very useful for debugging UEFI applications which aren't tied to specific hardware devices. So in this article, I'll show how to add on debugging support in Visual Studio 2010.
This article assumes you have already loaded the Visual Studio project to build the EDK2's NT32 platform in C:\edk2 as described previously.
1. Select the NT32 project in the Solution Explorer. Select Project->Properties.
2. Select "Debugging" on the right. Select "Command" and click the drop-down arrow.
3. Click "<Edit...>" A separate editor window should open up. Enter "C:\edk2\Build\NT32\DEBUG_VS2010x86\IA32\SecMain.exe"
4. Do the same for "Working Directory" and enter "C:\edk2\Build\NT32\DEBUG_VS2010x86\IA32"
6. Now, since Environment variables no longer work for NT32, we need to actually change the DSC file. Open up Nt32Pkg.dsc (located in C:\edk2\Nt32Pkg\Nt32Pkg.dsc).
7. Find the section labeled "Pcd Dynamic Section."
8. Find the line for PcdWinNtGop and change it so it reads
gEfiNt32PkgTokenSpaceGuid.PcdWinNtGop|L"GOP Window 1!GOP Window 2"|VOID*|52
9. Save and close the file.
Now you are ready to actually debug. Press F5 (or select Debug->Start Debugging). It will always ask you if you want to rebuild the project, since we haven't added any source files which Visual Studio can use to determine if the project source has been changed. For now, choose yes and you will see the program begin to execute normally
You can halt the execution of the emulated UEFI environment at any time by selecting Debug->Break All. Then you can set some breakpoints on a specific function by using Debug->New Breakpoint->Break At Function and type in the function name. You can force a breakpoint by inserting a __debugbreak() into your code
As the code executes, you will notice that the Visual Studio output window talks about various DLLs being loaded. The Windows-hosted environment actually loads your UEFI drivers and applications as DLLs (look in PUT_FILEPATH_HERE). The actual main program is called SecMain.exe