From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web09.6218.1572447796937064155 for ; Wed, 30 Oct 2019 08:03:17 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: liming.gao@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 08:03:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,247,1569308400"; d="scan'208,217";a="211344395" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga001.fm.intel.com with ESMTP; 30 Oct 2019 08:03:16 -0700 Received: from fmsmsx121.amr.corp.intel.com (10.18.125.36) 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:03:15 -0700 Received: from shsmsx153.ccr.corp.intel.com (10.239.6.53) by fmsmsx121.amr.corp.intel.com (10.18.125.36) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 30 Oct 2019 08:03:15 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.127]) by SHSMSX153.ccr.corp.intel.com ([169.254.12.215]) with mapi id 14.03.0439.000; Wed, 30 Oct 2019 23:03:13 +0800 From: "Liming Gao" 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() Thread-Topic: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak() Thread-Index: AQHVjY/g3fyCPIGsFE2OwuZEPryr9qdyqqyw//+5i4CAAOZFAA== Date: Wed, 30 Oct 2019 15:03:13 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E534D71@SHSMSX104.ccr.corp.intel.com> References: <2d5ec4d308504c87b7b1390c1e2f1495@zhaoxin.com>,<4A89E2EF3DFEDB4C8BFDE51014F606A14E5325C1@SHSMSX104.ccr.corp.intel.com> ,<4A89E2EF3DFEDB4C8BFDE51014F606A14E534825@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: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMGE3MjllOTgtYTlhOS00NDc3LTgyM2EtNDI4NWQyNzc1ZTUxIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiM2d0MDFYUmNSVXRKNWVaZ3o2VmNuVnhRck9QQ0hkNE1OVCtQR0Y1N2RndG1iUDVlMVhwcXlBSGQyaHpNSGFQUSJ9 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_4A89E2EF3DFEDB4C8BFDE51014F606A14E534D71SHSMSX104ccrcor_" --_000_4A89E2EF3DFEDB4C8BFDE51014F606A14E534D71SHSMSX104ccrcor_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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 Kege= l 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_4A89E2EF3DFEDB4C8BFDE51014F606A14E534D71SHSMSX104ccrcor_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Kil= ian:

&nb= sp;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 lo= gic. 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?=

 

Tha= nks

Lim= ing

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<= br> Cc: Richardson, Brian <brian.richardson@intel.com>; Kinney, M= ichael D <michael.d.kinney@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 version= s, Windows just terminates the “exceptional” process that emits=

INT 3 or any other violation t= rap and does not offer to debug the process – surly for security reas= ons…

 

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

 

It gives the developer the cha= nce 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 pr= ocess 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@OUTLOOK.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() functio= n. That will trig VS debugger for the source code.

&= nbsp;

Thanks=

Liming=

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,

 

If have observed in newer Wind= ows 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 ins= ert the code snippet below to run into getchar()

when the program was started w= ith the /debug command line switch.

As long as the App waits for t= he next keystroke, I can start the debugger (VS2019)

and connect to WinHost.exe pro= cess for debugging.

 

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

 

Thanks,

Kilian

    if(1){

    &nb= sp;   int i;

 

    &nb= sp;   SecPrint ("###########################################= ###########################################################\n");<= /o:p>

     &n= bsp;  SecPrint ("add \"/debug\" command line switc= h, to connect to the debugger at the very beginning of POST emulation\n&quo= t;);

    &nb= sp;   SecPrint ("###########################################= ###########################################################\n");<= /o:p>

 

     &n= bsp;  if(Argc > 1){

    &nb= sp;       for(i =3D 1 ; i < Argc ; i+&= #43;){

    &nb= sp;           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. con= nect WinHost.exe to the debugger\n\t3. and press ENTER in this command box\= nOR\n");

    &nb= sp;            =        SecPrint("\t1. start Visual Studi= o\n");

    &nb= sp;            =        SecPrint("\t2. DEBUG->ATTACH T= O PROCESS (CTRL + ALT + P) --> WinHost.exe\n");<= /span>

    &nb= sp;            =        SecPrint("\t3. Break All  (C= TRL + ALT + Break) --> WinHost.exe\n");

    &nb= sp;             = ;      SecPrint("\t4. SET A SOFTWARE BREAKPOI= NT (F9) in line 445\n");

    &nb= sp;            =        SecPrint("\t5. and press ENTER in= this command box\n");

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

    &nb= sp;            =        SecPrint("\t7. otherwise press en= ter to continue...\n");

    &nb= sp;            =        getchar();

    &nb= sp;            =        //

    &nb= sp;            =        // 1. SET A SOFTWARE BREAKPOINT TO THE= NEXT LINE of code below -->> SecPrint("");

    &nb= sp;            =        // 2. switch to the command box and pr= ess ENTER

    &nb= sp;            =        // 3. start single stepping the entire= boot/emulation process, good luck...

    &nb= sp;            =        //

    &nb= sp;            =        SecPrint("");//now you can s= ingle step the entire boot/emulation process, good luck...

    &nb= sp;            =   }

    &nb= sp;       }

    &nb= sp;   }

    }=

 

--_000_4A89E2EF3DFEDB4C8BFDE51014F606A14E534D71SHSMSX104ccrcor_--