Mike,

On the Unix side the strategy was to launch via the debugger [1], and also pass 
EFI specific debugger scripts into the debuggers on launch. 

I've played with trick with OS apps by using CpuDeadLoop(). To get unstuck you 
just need to update Index to be non Zero.  I've also used this technique for 
JTAG debuggers. For an EFI App I generally use CpuBreakpoint(). The advantage 
to using getchar() is the "otherwise press enter to continue..." path. So I 
agree the command line option seems like a reasonable thing to do.

The other trick I played in this area was to have both a `run` and `lldb` 
option to the script. The `run` option launches the debugger, the 'lldb' (or 
gdb) option drops you into a debugger prompt so you can set breakpoints early 
in boot. 

Long term maybe we could have a common Python based build commands for both 
Windows and Unix and at that point we could move to launching via the debugger 
for all paths? 

[1] https://github.com/tianocore/edk2/blob/master/EmulatorPkg/build.sh#L221

Thanks,

Andrew Fish


> On Oct 30, 2019, at 9:16 AM, Michael D Kinney <michael.d.kin...@intel.com> 
> wrote:
> 
> Liming,
>
> This may be something that is better with a command line option when 
> WinHost.exe is started instead of a PCD.
>
> I also think there is a way to run VS first and start a process from VS and 
> do an initial BP.  Does that work with latest Windows 10?
>
> Mike
>
> From: Gao, Liming <liming....@intel.com <mailto:liming....@intel.com>> 
> Sent: Wednesday, October 30, 2019 8:03 AM
> To: devel@edk2.groups.io <mailto:devel@edk2.groups.io>; 
> kilian_ke...@outlook.com <mailto:kilian_ke...@outlook.com>
> Cc: Richardson, Brian <brian.richard...@intel.com 
> <mailto:brian.richard...@intel.com>>; Kinney, Michael D 
> <michael.d.kin...@intel.com <mailto:michael.d.kin...@intel.com>>; Ni, Ray 
> <ray...@intel.com <mailto:ray...@intel.com>>
> Subject: RE: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak()
>
> Kilian:
>  I think this idea is good. It can be enabled when the developer wants to do 
> the source level debug. So, one PCD may be introduced to control the logic. 
> By default, there is no change. When PCD is enabled, WinHost will wait for 
> the developer input. 
>
> Can you submit BZ for this request, and prepare the patch for the change?
>
> Thanks
> Liming
>  <>From: devel@edk2.groups.io <mailto:devel@edk2.groups.io> 
> <devel@edk2.groups.io <mailto:devel@edk2.groups.io>> On Behalf Of Kilian Kegel
> Sent: Wednesday, October 30, 2019 5:17 PM
> To: Gao, Liming <liming....@intel.com <mailto:liming....@intel.com>>; 
> devel@edk2.groups.io <mailto:devel@edk2.groups.io>
> Cc: Richardson, Brian <brian.richard...@intel.com 
> <mailto:brian.richard...@intel.com>>; Kinney, Michael D 
> <michael.d.kin...@intel.com <mailto:michael.d.kin...@intel.com>>
> Subject: Re: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak()
>
> Hi Liming,
>
> CpuBreakPoint() is the same as __debugbreak() on Microsoft Compiler and 
> generates INT 3 DebugTrap.
>
> Yes, that procedure has worked in the past and I have used it in the same way 
> as you do.
>
> But with newer Windows versions, Windows just terminates the “exceptional” 
> process that emits
> INT 3 or any other violation trap and does not offer to debug the process – 
> surly for security reasons…
>
> For debugging purpose on newer Windows 10 versions I always insert the code 
> snippet  below.
>
> It gives the developer the chance to connect VS to the process to be 
> debugged, while waiting on keyboard input.
> (ALT-CTRL-P attach to process)
>
> After that, with the debuggee is connected to VS _before_ the debug trap 
> appears. VS is now
> available for debugging the process with full source code.
>
> The EmulatorPkg (and Nt32Pkg) was the most helpful tool to understand and 
> debug UEFI internals for me.
>
> EmulatorPkg should also usable and helpful for other devolpers.
> Can you please insert the code snippet into main() from WinHost.c?
>
> Thanks,
> Kilian
>
>
> From: Gao, Liming <mailto:liming....@intel.com>
> Sent: Wednesday, October 30, 2019 06:33 AM
> To: devel@edk2.groups.io <mailto:devel@edk2.groups.io>; 
> kilian_ke...@outlook.com <mailto:kilian_ke...@outlook.com>
> Cc: Richardson, Brian <mailto:brian.richard...@intel.com>; Kinney, Michael D 
> <mailto:michael.d.kin...@intel.com>
> Subject: RE: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak()
>
> Kilian:
>    I normally modify the source code and insert CpuBreakpoint() function. 
> That will trig VS debugger for the source code.
>
> Thanks
> Liming
> From: devel@edk2.groups.io <mailto:devel@edk2.groups.io> 
> [mailto:devel@edk2.groups.io <mailto:devel@edk2.groups.io>] On Behalf Of 
> Kilian Kegel
> Sent: Monday, October 28, 2019 9:01 PM
> To: Gao, Liming <liming....@intel.com <mailto:liming....@intel.com>>
> Cc: devel@edk2.groups.io <mailto:devel@edk2.groups.io>; Richardson, Brian 
> <brian.richard...@intel.com <mailto:brian.richard...@intel.com>>; Kinney, 
> Michael D <michael.d.kin...@intel.com <mailto:michael.d.kin...@intel.com>>
> Subject: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak()
>
> Hi Liming,
>
> If have observed in newer Windows 10 versions, when using __debugbreak()in any
> application that Windows just terminates the app, instead offering to debug 
> it.
> So in WinHost.exe too.
>
> That’s why I usually insert the code snippet below to run into getchar()
> when the program was started with the /debug command line switch.
> As long as the App waits for the next keystroke, I can start the debugger 
> (VS2019)
> and connect to WinHost.exe process for debugging.
>
> Do you have a better solution without modifying the source code?
>
> Thanks,
> Kilian
>     if(1){
>         int i;
>
>         SecPrint 
> ("######################################################################################################\n");
>         SecPrint ("add \"/debug\" command line switch, to connect to the 
> debugger at the very beginning of POST emulation\n");
>         SecPrint 
> ("######################################################################################################\n");
>
>         if(Argc > 1){
>             for(i = 1 ; i < Argc ; i++){
>                 if(0 == strcmp("/debug", Argv[i])){
>                         //SecPrint("IF YOU WANT TO DEBUG from the very 
> beginning of the EMULATION:\n\t1. start the TASKMGR\n\t2. connect WinHost.exe 
> to the debugger\n\t3. and press ENTER in this command box\nOR\n");
>                         SecPrint("\t1. start Visual Studio\n");
>                         SecPrint("\t2. DEBUG->ATTACH TO PROCESS (CTRL + ALT + 
> P) --> WinHost.exe\n");
>                         SecPrint("\t3. Break All  (CTRL + ALT + Break) --> 
> WinHost.exe\n");
>                         SecPrint("\t4. SET A SOFTWARE BREAKPOINT (F9) in line 
> 445\n");
>                         SecPrint("\t5. and press ENTER in this command 
> box\n");
>                         SecPrint("\t6. go back to Visual Studio an RUN/SINGLE 
> STEP the application\n");
>                         SecPrint("\t7. otherwise press enter to 
> continue...\n");
>                         getchar();
>                         //
>                         // 1. SET A SOFTWARE BREAKPOINT TO THE NEXT LINE of 
> code below -->> SecPrint("");
>                         // 2. switch to the command box and press ENTER
>                         // 3. start single stepping the entire boot/emulation 
> process, good luck...
>                         //
>                         SecPrint("");//now you can single step the entire 
> boot/emulation process, good luck...
>                    }
>             }
>         }
>     }
>
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#49680): https://edk2.groups.io/g/devel/message/49680
Mute This Topic: https://groups.io/mt/38879075/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to