From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web12.7303.1572452181931672417 for ; Wed, 30 Oct 2019 09:16:22 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: michael.d.kinney@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 09:16:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,247,1569308400"; d="scan'208,217";a="351347965" Received: from orsmsx103.amr.corp.intel.com ([10.22.225.130]) by orsmga004.jf.intel.com with ESMTP; 30 Oct 2019 09:16:21 -0700 Received: from orsmsx161.amr.corp.intel.com (10.22.240.84) by ORSMSX103.amr.corp.intel.com (10.22.225.130) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 30 Oct 2019 09:16:20 -0700 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.28]) by ORSMSX161.amr.corp.intel.com ([169.254.4.146]) with mapi id 14.03.0439.000; Wed, 30 Oct 2019 09:16:21 -0700 From: "Michael D Kinney" To: "Gao, Liming" , "devel@edk2.groups.io" , "KILIAN_KEGEL@OUTLOOK.COM" , "Kinney, Michael D" CC: "Richardson, Brian" , "Ni, Ray" Subject: Re: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak() Thread-Topic: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak() Thread-Index: AQHVjY/dkwkEHs6zfkisAAYYE7u686dzIWcAgAA+RYCAAGDagP//nq5Q Date: Wed, 30 Oct 2019 16:16:20 +0000 Message-ID: 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: <4A89E2EF3DFEDB4C8BFDE51014F606A14E534D71@SHSMSX104.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.22.254.139] MIME-Version: 1.0 Return-Path: michael.d.kinney@intel.com Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_E92EE9817A31E24EB0585FDF735412F5B9DF540AORSMSX113amrcor_" --_000_E92EE9817A31E24EB0585FDF735412F5B9DF540AORSMSX113amrcor_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Liming, This may be something that is better with a command line option when WinHo= st.exe is started instead of a PCD. I also think there is a way to run VS first and start a process from VS an= d do an initial BP. Does that work with latest Windows 10? Mike From: Gao, Liming Sent: Wednesday, October 30, 2019 8:03 AM 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_E92EE9817A31E24EB0585FDF735412F5B9DF540AORSMSX113amrcor_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

L= iming,

<= o:p> 

T= his may be something that is better with a command line option when WinHost= .exe is started instead of a PCD.

<= o:p> 

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?

<= o:p> 

M= ike

<= o:p> 

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, M= ichael D <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com&g= t;
Subject: RE: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak()=

 

Kilian:

 I think this idea is good. It can be enabled when the develo= per wants to do the source level debug. So, one PCD may be introduced to co= ntrol 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 <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()=

&nb= sp;

Hi Limin= g,

&nb= sp;

CpuBreak= Point() is the same as __debugbreak() on Microsoft Compiler and generates I= NT 3 DebugTrap.

&nb= sp;

Yes, tha= t procedure has worked in the past and I have used it in the same way as yo= u do.

&nb= sp;

But with= newer Windows versions, Windows just terminates the “exceptionalR= 21; process that emits

INT 3 or= any other violation trap and does not offer to debug the process – s= urly for security reasons…

&nb= sp;

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

&nb= sp;

It gives= the developer the chance to connect VS to the process to be debugged, whil= e waiting on keyboard input.

(ALT-CTR= L-P attach to process)

&nb= sp;

After th= at, with the debuggee is connected to VS _before_ the debug trap app= ears. VS is now

availabl= e for debugging the process with full source code.

&nb= sp;

The Emul= atorPkg (and Nt32Pkg) was the most helpful tool to understand and debug UEF= I internals for me.

&nb= sp;

Emulator= Pkg should also usable and helpful for other devolpers.

Can you = please insert the code snippet into main() from WinHost.c?

&nb= sp;

Thanks,<= o:p>

Kilian

&nb= sp;

&nb= sp;

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()=

&nb= sp;

Kilian:

   I normally modify the source code and insert CpuBreakpoi= nt() 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 <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()

&nb= sp;

Hi Limin= g,

&nb= sp;

If have = observed in newer Windows 10 versions, when using __debugbreak()in any

applicat= ion that Windows just terminates the app, instead offering to debug it.

So in Wi= nHost.exe too.

&nb= sp;

ThatR= 17;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)<= o:p>

and conn= ect to WinHost.exe process for debugging.

&nb= sp;

Do you h= ave a better solution without modifying the source code?<= /p>

&nb= sp;

Thanks,<= o:p>

Kilian

 = ;   if(1){

 = ;       int i;

=  

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

 = ;       SecPrint ("add \"/debug\&qu= ot; command line switch, to connect to the debugger at the very beginning o= f POST emulation\n");

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

=  

 = ;       if(Argc > 1){

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

 = ;            &n= bsp;  if(0 =3D=3D strcmp("/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. connect WinHost.exe to the debugger\n\t3. and press ENTE= R in this command box\nOR\n");

 = ;            &n= bsp;          SecPrint("\= t1. start Visual Studio\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"= );

 = ;             &= nbsp;         SecPrint("\t4. S= ET A SOFTWARE BREAKPOINT (F9) in line 445\n");

 = ;            &n= bsp;          SecPrint("\= t5. and press ENTER in 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 enter to continue...\n");

 = ;            &n= bsp;          getchar();

 = ;            &n= bsp;          //

 = ;            &n= bsp;          // 1. SET A SOFT= WARE BREAKPOINT TO THE NEXT LINE of code below -->> SecPrint("&q= uot;);

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

 = ;            &n= bsp;          // 3. start sing= le stepping the entire boot/emulation process, good luck...

 = ;            &n= bsp;          //

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

 = ;            &n= bsp;     }

 = ;           }<= /span>

 = ;       }

 = ;   }

&nb= sp;

--_000_E92EE9817A31E24EB0585FDF735412F5B9DF540AORSMSX113amrcor_--