From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from nwk-aaemail-lapp03.apple.com (nwk-aaemail-lapp03.apple.com [17.151.62.68]) by mx.groups.io with SMTP id smtpd.web10.7821.1572454582331582568 for ; Wed, 30 Oct 2019 09:56:23 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@apple.com header.s=20180706 header.b=fBjDMCus; spf=pass (domain: apple.com, ip: 17.151.62.68, mailfrom: afish@apple.com) Received: from pps.filterd (nwk-aaemail-lapp03.apple.com [127.0.0.1]) by nwk-aaemail-lapp03.apple.com (8.16.0.27/8.16.0.27) with SMTP id x9UGqCLg010096; Wed, 30 Oct 2019 09:56:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=sender : from : message-id : content-type : mime-version : subject : date : in-reply-to : cc : to : references; s=20180706; bh=z2R7uGMVZa3MxOLMNq/jdrB6sxN3UKK6AexSoU4U1Ok=; b=fBjDMCus7E0NWX4QVpJOweMIUdfllTkAMoVUpL3X9ZbLHqgfuGJ0fpLZZTTqVd4Kpnuz ny8FjBHiUfscI80oexL/2cQc4XObsuBe/uECAnZ1PfUi1SsXIOqSEI5ZLCF3yPcqH7n6 S9V16/2Eromdzmuczqkqtinnp1Gpo+IF6f0d1WWXtIckKUTNesW/LCCdoRTymTPGVaRT bwTPUa7LRtNqC6mzcIhUKc1GluxJFcN+4R66goGlsxgkPthKtKXm5rMt5pOKbsljqjTA DwF9dTqOE4oM+6x5Y+pM39W1CTN9XH4xeJUdoBdhRyu3SvmK6e4M6VhHVdPOLCesuaL7 3w== Received: from ma1-mtap-s02.corp.apple.com (ma1-mtap-s02.corp.apple.com [17.40.76.6]) by nwk-aaemail-lapp03.apple.com with ESMTP id 2vxwf8cbxc-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Wed, 30 Oct 2019 09:56:20 -0700 Received: from nwk-mmpp-sz13.apple.com (nwk-mmpp-sz13.apple.com [17.128.115.216]) by ma1-mtap-s02.corp.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPS id <0Q0700BS95PV0QA0@ma1-mtap-s02.corp.apple.com>; Wed, 30 Oct 2019 09:56:20 -0700 (PDT) Received: from process_milters-daemon.nwk-mmpp-sz13.apple.com by nwk-mmpp-sz13.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) id <0Q0700M005MJDW00@nwk-mmpp-sz13.apple.com>; Wed, 30 Oct 2019 09:56:19 -0700 (PDT) X-Va-A: X-Va-T-CD: ea8ecdd7c7fec670404234df68c44261 X-Va-E-CD: ee6a9d68cbbe910720828183870d63e9 X-Va-R-CD: b77b10d15fa4e93de411a376a6fa4afa X-Va-CD: 0 X-Va-ID: 1b292a67-6754-463f-9fa3-9f34f464adfa X-V-A: X-V-T-CD: e48e8dc3f6c377b8dc939b4126ad19f3 X-V-E-CD: ee6a9d68cbbe910720828183870d63e9 X-V-R-CD: b77b10d15fa4e93de411a376a6fa4afa X-V-CD: 0 X-V-ID: 2e9294d7-37a7-4fc2-94c5-9c6e4b7fd4f6 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-30_07:,, signatures=0 Received: from [17.235.53.249] (unknown [17.235.53.249]) by nwk-mmpp-sz13.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPSA id <0Q07001BB5PTBR90@nwk-mmpp-sz13.apple.com>; Wed, 30 Oct 2019 09:56:19 -0700 (PDT) Sender: afish@apple.com From: "Andrew Fish" Message-id: <3275E3A1-246A-4888-A467-19DBC14CEFDB@apple.com> MIME-version: 1.0 (Mac OS X Mail 13.0 \(3594.4.17\)) Subject: Re: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak() Date: Wed, 30 Oct 2019 09:56:17 -0700 In-reply-to: Cc: "Gao, Liming" , "KILIAN_KEGEL@OUTLOOK.COM" , "Richardson, Brian" , "Ni, Ray" To: devel@edk2.groups.io, Mike Kinney References: <2d5ec4d308504c87b7b1390c1e2f1495@zhaoxin.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14E5325C1@SHSMSX104.ccr.corp.intel.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14E534825@SHSMSX104.ccr.corp.intel.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14E534D71@SHSMSX104.ccr.corp.intel.com> X-Mailer: Apple Mail (2.3594.4.17) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-30_07:,, signatures=0 Content-type: multipart/alternative; boundary="Apple-Mail=_1E8CA6BF-76C2-48ED-BA47-D4F96DF80FD8" --Apple-Mail=_1E8CA6BF-76C2-48ED-BA47-D4F96DF80FD8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 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.=20 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 techniq= ue 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 d= o. 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' (o= r gdb) option drops you into a debugger prompt so you can set breakpoints e= arly in boot.=20 Long term maybe we could have a common Python based build commands for bot= h Windows and Unix and at that point we could move to launching via the deb= ugger for all paths?=20 [1] https://github.com/tianocore/edk2/blob/master/EmulatorPkg/build.sh#L22= 1 Thanks, Andrew Fish > On Oct 30, 2019, at 9:16 AM, Michael D Kinney wrote: >=20 > Liming, > > This may be something that is better with a command line option when Win= Host.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 >= =20 > Sent: Wednesday, October 30, 2019 8:03 AM > To: devel@edk2.groups.io ; KILIAN_KEGEL@OUT= LOOK.COM > Cc: Richardson, Brian >; Kinney, Michael D >; Ni, Ray > > Subject: RE: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak() > > Kilian: > I think this idea is good. It can be enabled when the developer wants t= o do the source level debug. So, one PCD may be introduced to control the l= ogic. By default, there is no change. When PCD is enabled, WinHost will wai= t for the developer input.=20 > > Can you submit BZ for this request, and prepare the patch for the change= ? > > Thanks > Liming > <>From: devel@edk2.groups.io > On Behalf Of Kilian Kegel > Sent: Wednesday, October 30, 2019 5:17 PM > To: Gao, Liming >; de= vel@edk2.groups.io > Cc: Richardson, Brian >; Kinney, Michael D > > 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 sam= e way as you do. > > But with newer Windows versions, Windows just terminates the =E2=80=9Cex= ceptional=E2=80=9D process that emits > INT 3 or any other violation trap and does not offer to debug the proces= s =E2=80=93 surly for security reasons=E2=80=A6 > > For debugging purpose on newer Windows 10 versions I always insert the c= ode snippet below. > > It gives the developer the chance to connect VS to the process to be deb= ugged, 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 an= d 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 > Sent: Wednesday, October 30, 2019 06:33 AM > To: devel@edk2.groups.io ; KILIAN_KEGEL@OUT= LOOK.COM > Cc: Richardson, Brian ; Kinney, Micha= el D > 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@e= dk2.groups.io ] On Behalf Of Kilian Kegel > Sent: Monday, October 28, 2019 9:01 PM > To: Gao, Liming > > Cc: devel@edk2.groups.io ; Richardson, Bria= n >; Kinney,= Michael D > > 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 de= bug it. > So in WinHost.exe too. > > That=E2=80=99s why I usually insert the code snippet below to run into g= etchar() > 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 debugge= r (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 =3D 1 ; i < Argc ; i++){ > if(0 =3D=3D strcmp("/debug", Argv[i])){ > //SecPrint("IF YOU WANT TO DEBUG from the very b= eginning of the EMULATION:\n\t1. start the TASKMGR\n\t2. connect WinHost.ex= e 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 b= ox\n"); > SecPrint("\t6. go back to Visual Studio an RUN/S= INGLE 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/emul= ation process, good luck... > // > SecPrint("");//now you can single step the entir= e boot/emulation process, good luck... > } > } > } > } > >=20 --Apple-Mail=_1E8CA6BF-76C2-48ED-BA47-D4F96DF80FD8 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Mike,

On the Unix side the strategy was to launc= h via the debugger [1], and also pass EFI specific debugger scripts into th= e 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 u= sed this technique for JTAG debuggers. For an EFI App I generally use CpuBr= eakpoint(). The advantage to using getchar() is the "otherwise press enter = to continue..." path. So I agree the command line option seems like a reaso= nable 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 f= or both Windows and Unix and at that point we could move to launching via t= he debugger for all paths? 

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

Thanks,

Andrew Fish


On Oct 30, 2019, at 9:16 AM, Michael D Kinney &= lt;michael.d.kinne= y@intel.com> wrote:

Liming,
 
This may be something that is better with a command line option when Win= Host.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.gao@intel.com> 
Sent: Wednesday, October 30, 2019 8:03 AM
To: devel@edk2.groups.io; KILIAN_KEGEL@OUTLOOK.COM
Cc: 
Richardson, Brian <brian.richardson@intel.com>;= Kinney, Michael D <mich= ael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com>
Subject: 
RE: [edk2-devel] [edk2] [Em= ulatorPkg] using __debugbreak()
 
Kilian:
 I think this idea is good. It can be e= nabled when the developer wants to do the source level debug. So, one PCD m= ay 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.i= o <devel@edk2.groups.io> On Behalf Of Kilian Kegel
Sent: Wednesday, Oct= ober 30, 2019 5:17 PM
To: Gao, Liming <liming.gao@intel.com>; devel@edk2.group= s.io
Cc: Richardson, Brian <brian.richardson@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>= ;
Subject: Re: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak(= )
 
Hi Liming,
<= div style=3D"margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibr= i, sans-serif;" class=3D""> 
CpuBreakPoint() is t= he same as __debugbreak() on Microsoft Compiler and generates INT 3 DebugTr= ap.
 
Yes, that procedure has worked in the past and I have us= ed it in the same way as you do.
 
But with newer Windows vers= ions, Windows just terminates the =E2=80=9Cexceptional=E2=80=9D process tha= t emits
INT 3 or any other violation trap and does not offer to debug t= he process =E2=80=93 surly for security reasons=E2=80=A6
 
For= debugging purpose on newer Windows 10 versions I always insert the code sn= ippet  below.
 
It gives the developer the chance to co= nnect VS to the process to be debugged, while waiting on keyboard input.
(ALT-CTRL-P attach to process)
 
After that, with the debugg= ee 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 under= stand and debug UEFI internals for me.
 
EmulatorPkg should al= so usable and helpful for other devolpers.
Can you please insert the co= de snippet into main() from WinHost.c?
 
Thanks,
Kilian
 
 
From:&nbs= p;Gao, Liming
Sent: Wednesday, October 30, 2019 06:33 AM
To: = devel@edk2.groups.io; KILIAN_KEGEL@OUTLOOK.COM
Cc:<= span class=3D"Apple-converted-space"> 
Richardson, Brian; Kinn= ey, Michael D
Subject: RE: [edk2-devel] [edk2] [EmulatorPkg] usi= ng __debugbreak()
 
K= ilian:
   I normally modif= y the source code and insert CpuBreakpoint() function. That will trig VS de= bugger for the source code.
 
Thanks
Liming
From: devel@edk2.groups.io [mailto:devel@edk2.gr= oups.io] On Behalf Of Kilian= Kegel
Sent: Monday, October 28, 2019 9:01 PM
To: Gao, Limin= g <liming.gao@intel.com><= br class=3D"">Cc:&n= bsp;devel@edk2.groups.io= ; Richardson, Brian <bria= n.richardson@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>
<= b class=3D"">Subject: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak()
 
Hi Liming,
 
If have observed in newer Windows 10 ve= rsions, when using __debugbreak()in any
application that Win= dows just terminates the app, instead offering to debug it.=
So in WinHo= st.exe too.
<= span class=3D""> 
That=E2=80=99s why I usually insert the code sni= ppet 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.
<= span class=3D""> 
Do you have a better solution without modifying = the source code?
 
Thanks,
Kilian
<= span class=3D"">    if(1){<= /div>
  = ;      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");
 
&nb= sp;       if(Argc > 1){
            f= or(i =3D 1 ; i < Argc ; i++){
   &n= bsp;            if(0= =3D=3D strcmp("/debug", Argv[i])){
     =             &nb= sp;      //SecPrint("IF YOU WANT TO DEBUG from the= very beginning of the EMULATION:\n\t1. start the TASKMGR\n\t2. connect Win= Host.exe to the debugger\n\t3. and press ENTER in this command box\nOR\n");=
        &nb= sp;            =    SecPrint("\t1. start Visual Studio\n");<= /span>
=             &nb= sp;           SecPrint("\= t2. DEBUG->ATTACH TO PROCESS (CTRL + ALT + P) --> WinHost.exe\n");
         &= nbsp;           &nbs= p;  SecPrint("\t3. Break All  (CTRL + ALT + Break) --> WinHost= .exe\n");
       &= nbsp;            &nb= sp;   SecPrint("\t4. SET A SOFTWARE BREAKPOINT (F9) in line 445\n= ");
        &= nbsp;           &nbs= p;   SecPrint("\t5. and press ENTER in this command box\n");
         &nb= sp;            =   SecPrint("\t6. go back to Visual Studio an RUN/SINGLE STEP the appli= cation\n");
       = ;            &n= bsp;    SecPrint("\t7. otherwise press enter to continue...\= n");
        =             &nb= sp;   getchar();
 = ;            &n= bsp;          //
           =              //= 1. SET A SOFTWARE BREAKPOINT TO THE NEXT LINE of code below -->> Sec= Print("");
       =             &nb= sp;    // 2. switch to the command box and press ENTER
=          &nbs= p;            &= nbsp; // 3. start single stepping the entire boot/emulation process, good l= uck...
       &nbs= p;            &= nbsp;   //
     &n= bsp;            = ;      SecPrint("");//now you can single step the = entire boot/emulation process, good luck...
 &nb= sp;            =      }
    &= nbsp;       }
 &nb= sp;      }
<= div style=3D"margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibr= i, sans-serif;" class=3D"">   = ; }
 

<= /div>

--Apple-Mail=_1E8CA6BF-76C2-48ED-BA47-D4F96DF80FD8--