From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web12.6610.1572449037638946292 for ; Wed, 30 Oct 2019 08:23:57 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: liming.gao@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 08:23:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,247,1569308400"; d="scan'208,217";a="212132275" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga002.jf.intel.com with ESMTP; 30 Oct 2019 08:23:56 -0700 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 30 Oct 2019 08:23:56 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX157.amr.corp.intel.com (10.18.116.73) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 30 Oct 2019 08:23:55 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.127]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.2]) with mapi id 14.03.0439.000; Wed, 30 Oct 2019 23:23:53 +0800 From: "Liming Gao" To: Minnow Ware , "devel@edk2.groups.io" , "KILIAN_KEGEL@OUTLOOK.COM" CC: "Richardson, Brian" , "Kinney, Michael D" , "Ni, Ray" Subject: Re: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak() Thread-Topic: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak() Thread-Index: AQHVjY/g3fyCPIGsFE2OwuZEPryr9qdyqqyw//+5i4CAAOZFAP//f+2AgACGVqA= Date: Wed, 30 Oct 2019 15:23:52 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E534DC3@SHSMSX104.ccr.corp.intel.com> References: <2d5ec4d308504c87b7b1390c1e2f1495@zhaoxin.com>,<4A89E2EF3DFEDB4C8BFDE51014F606A14E5325C1@SHSMSX104.ccr.corp.intel.com> ,<4A89E2EF3DFEDB4C8BFDE51014F606A14E534825@SHSMSX104.ccr.corp.intel.com> ,<4A89E2EF3DFEDB4C8BFDE51014F606A14E534D71@SHSMSX104.ccr.corp.intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZjUwZmE3N2QtZWZlOC00MGY4LThmNDMtMTEwOGMwNTU3MTA5IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoibDFwcFNzMmhGY1cxd1pUdFBQd3ZSSGdTQkJSV0w3dTNpXC9HMnpySG8zbzB1dm9Ca1wvdUwxNUZEV0tOYUdpSGVFIn0= dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: liming.gao@intel.com Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_4A89E2EF3DFEDB4C8BFDE51014F606A14E534DC3SHSMSX104ccrcor_" --_000_4A89E2EF3DFEDB4C8BFDE51014F606A14E534DC3SHSMSX104ccrcor_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable OK. I see now. This way is better. Thanks Liming From: Minnow Ware Sent: Wednesday, October 30, 2019 11:22 PM To: devel@edk2.groups.io; Gao, Liming ; KILIAN_KEGEL= @OUTLOOK.COM Cc: Richardson, Brian ; Kinney, Michael D ; Ni, Ray Subject: RE: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak() Hi Liming, 1. when you invoke WINHOST.EXE /debug, it waits for developer input 2. otherwise default behavior A PCD is needless. Regards, Kilian ________________________________ From: devel@edk2.groups.io > on behalf of Liming Gao > Sent: Wednesday, October 30, 2019 4:03:13 PM To: devel@edk2.groups.io >; KILIAN_KEGEL@OUTLOOK.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 to = do the source level debug. So, one PCD may be introduced to control the log= ic. 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 > On Behalf Of Kilian Kegel Sent: Wednesday, October 30, 2019 5:17 PM To: Gao, Liming >; devel= @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 ge= nerates 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 cod= e snippet below. It gives the developer the chance to connect VS to the process to be debug= ged, while waiting on keyboard input. (ALT-CTRL-P attach to process) After that, with the debuggee is connected to VS _before_ the debug trap a= ppears. 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 Sent: Wednesday, October 30, 2019 06:33 AM To: devel@edk2.groups.io; KILIAN_KEGEL@OUTLOO= K.COM Cc: Richardson, Brian; Kinney, Michael = 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@edk2= .groups.io] On Behalf Of Kilian Kegel Sent: Monday, October 28, 2019 9:01 PM To: Gao, Liming > Cc: devel@edk2.groups.io; Richardson, Brian <= brian.richardson@intel.com>; Kinney, Mic= hael 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 debu= g 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 d= ebugger 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 beg= inning 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 + AL= T + P) --> WinHost.exe\n"); SecPrint("\t3. Break All (CTRL + ALT + Break) -->= WinHost.exe\n"); SecPrint("\t4. SET A SOFTWARE BREAKPOINT (F9) in l= ine 445\n"); SecPrint("\t5. and press ENTER in this command box= \n"); SecPrint("\t6. go back to Visual Studio an RUN/SIN= GLE STEP the application\n"); SecPrint("\t7. otherwise press enter to continue..= .\n"); getchar(); // // 1. SET A SOFTWARE BREAKPOINT TO THE NEXT LINE o= f code below -->> SecPrint(""); // 2. switch to the command box and press ENTER // 3. start single stepping the entire boot/emulat= ion process, good luck... // SecPrint("");//now you can single step the entire = boot/emulation process, good luck... } } } } --_000_4A89E2EF3DFEDB4C8BFDE51014F606A14E534DC3SHSMSX104ccrcor_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

OK.= I see now. This way is better.

 

Tha= nks

Lim= ing

From: Minnow Ware <minnowwar= e@outlook.com>
Sent: Wednesday, October 30, 2019 11:22 PM
To: devel@edk2.groups.io; Gao, Liming <liming.gao@intel.com>;= KILIAN_KEGEL@OUTLOOK.COM
Cc: Richardson, Brian <brian.richardson@intel.com>; Kinney, M= ichael D <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com&g= t;
Subject: RE: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak()=

 

Hi Liming,

 

  1. when you invoke WINHOST.EXE /debug, it waits for develope= r input
  2. otherwise default = behavior

 

A PCD is needless.<= /span>

 

Regards,

Kilian

 


From:= devel@edk2.groups.io <devel@edk2.groups.io> on behalf o= f Liming Gao <liming.gao@intel.c= om>
Sent: Wednesday, October 30, 2019 4:03:13 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>; KILIAN_KEGEL@OUTLOOK.COM &= lt;KILIAN_KEGEL@OUTLOOK.COM= >
Cc: Richardson, Brian <brian.richardson@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Ni, R= ay <ray.ni@intel.com>
Subject: Re: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak()=

 

Ki= lian:

&n= bsp;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 wait for the developer input.

&n= bsp;

Ca= n you submit BZ for this request, and prepare the patch for the change?

&n= bsp;

Th= anks

Li= ming

From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Kilian Kegel
Sent: Wednesday, October 30, 2019 5:17 PM
To: Gao, Liming <liming.= gao@intel.com>; devel@edk2.groups.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,<= /p>

 

CpuBreakPoint() is the same a= s __debugbreak() on Microsoft Compiler and generates INT 3 DebugTrap.<= /o:p>

 

Yes, that procedure has worke= d in the past and I have used it in the same way as you do.

 

But with newer Windows versio= ns, Windows just terminates the “exceptional” process that emit= s

INT 3 or any other violation = trap and does not offer to debug the process – surly for security rea= sons…

 

For debugging purpose on newe= r Windows 10 versions I always insert the code snippet  below.

 

It gives the developer the ch= ance 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<= /o:p>

available for debugging the p= rocess with full source code.

 

The EmulatorPkg (and Nt32Pkg)= was the most helpful tool to understand and debug UEFI internals for me.

 

EmulatorPkg should also usabl= e and helpful for other devolpers.

Can you please insert the cod= e 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@OUTLOOK.COM
Cc: Richardson, Brian= ; Kinney, Michael D
Subject: RE: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak()=

 

Kilia= n:

 = ;  I normally modify the source code and insert CpuBreakpoint() functi= on. That will trig VS debugger for the source code.

 = ;

Thank= s

Limin= g

From: devel@edk2.groups.io [mailto:d= evel@edk2.groups.io] On Behalf Of Kilian Kegel
Sent: Monday, October 28, 2019 9:01 PM
To: Gao, Liming <liming.= gao@intel.com>
Cc: devel@edk2.groups.io; Richardson, Brian <bria= n.richardson@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>
Subject: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak()

 

Hi Liming,<= /p>

 

If have observed in newer Win= dows 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 in= sert 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 pr= ocess for debugging.

 

Do you have a better solution= without modifying the source code?

 

Thanks,

Kilian

    if(1){<= /span>

    &n= bsp;   int i;

 

    &n= bsp;   SecPrint ("##########################################= ############################################################\n");

     &= nbsp;  SecPrint ("add \"/debug\" command line swit= ch, to connect to the debugger at the very beginning of POST emulation\n&qu= ot;);

    &n= bsp;   SecPrint ("##########################################= ############################################################\n");

 

     &= nbsp;  if(Argc > 1){

    &n= bsp;       for(i =3D 1 ; i < Argc ; i+= +){

    &n= bsp;           if(0 =3D= =3D strcmp(&q= uot;/debug", Argv[i])){

    &n= bsp;            = ;       //SecPrint("IF YOU WANT TO DEBUG= from the very beginning of the EMULATION:\n\t1. start the TASKMGR\n\t2. co= nnect WinHost.exe to the debugger\n\t3. and press ENTER in this command box= \nOR\n");

    &n= bsp;            = ;       SecPrint("\t1. start Visual Stud= io\n");

    &n= bsp;            = ;       SecPrint("\t2. DEBUG->ATTACH = TO PROCESS (CTRL + ALT + P) --> WinHost.exe\n");=

    &n= bsp;            = ;       SecPrint("\t3. Break All  (= CTRL + ALT + Break) --> WinHost.exe\n");

    &n= bsp;            &nbs= p;      SecPrint("\t4. SET A SOFTWARE BREAKPO= INT (F9) in line 445\n");

    &n= bsp;            = ;       SecPrint("\t5. and press ENTER i= n this command box\n");

    &n= bsp;            = ;       SecPrint("\t6. go back to Visual= Studio an RUN/SINGLE STEP the application\n");

    &n= bsp;            = ;       SecPrint("\t7. otherwise press e= nter to continue...\n");

    &n= bsp;            = ;       getchar();

    &n= bsp;            = ;       //

    &n= bsp;            = ;       // 1. SET A SOFTWARE BREAKPOINT TO TH= E NEXT LINE of code below -->> SecPrint("");

    &n= bsp;            = ;       // 2. switch to the command box and p= ress ENTER

    &n= bsp;            = ;       // 3. start single stepping the entir= e boot/emulation process, good luck...=

    &n= bsp;            = ;       //

    &n= bsp;            = ;       SecPrint("");//now you can = single step the entire boot/emulation process, good luck...

    &n= bsp;            = ;  }

    &n= bsp;       }<= o:p>

    &n= bsp;   }

    }

 

--_000_4A89E2EF3DFEDB4C8BFDE51014F606A14E534DC3SHSMSX104ccrcor_--