From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR03-DB5-obe.outbound.protection.outlook.com (EUR03-DB5-obe.outbound.protection.outlook.com [40.92.71.48]) by mx.groups.io with SMTP id smtpd.web09.2077.1572426998537258197 for ; Wed, 30 Oct 2019 02:16:39 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@outlook.com header.s=selector1 header.b=DzQYteuk; spf=pass (domain: outlook.com, ip: 40.92.71.48, mailfrom: kilian_kegel@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eYJA9i/tPdd4bzOdo50JQch23+DPHPjOEFEDRSqmiQHhfTMd0wFkYSt7GvVqn78g40UHMPty9hblIJPotPLE7rz7NA0Z8sl7fHp8TM7kUsJrCpbOSuVB6jgIh827vkoE44Q+VhTRYHT2Zz2PHH0OBEbNOS3i5rdoLlxJVQdKwsAwb2YofJwjOvc4h87kip/8XuhOwGA/9iUQxJg9Xy2O951sdZOjCcISI9wkVNxfZ1uVRrfLlFh4TLu2mTRs+y+AcwTEQnvUZxusXoe9sC5nfEWRSqtuTLqPEcwQrwt27M8a71tfX8KOmn5iQN/274LJ2kyDhm5iHdMXaxW2stwYnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7k38i6ip6Xs1RIOEDA3/SOh814WM6EUlCzflbN4t9jQ=; b=c0KRbnUyyvbQH+5myNNA/5LabZW6iKwKy+b2HpcwTgv2sMM/aVX7zTnV3y9LLY5phmQ6IG7zPXZ+3/e0KhvsO8XBojyNwFSylO6yGuGEbZvOY6jky5B+RN11Sf+FJ5dZw+IBdMyehg/Bp4Arqa+QZrwUe4QRU5errO1Lrsr5BSeNEDzfSkEF0ZuSJr46Ru4mVlP6a7zLR9znH3+F1U2V6OQCazeqfir1vqwlEmkQj6WnSapjRIt/u7py6WItNBn7fCNxSqNayzsJjF6t+qVl+PS0UyDdsqW1MYg6u+jDJ2/DCOgDu36JVIYsEf9uGjLq8pJoX78qDEmtksLd6SdgWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7k38i6ip6Xs1RIOEDA3/SOh814WM6EUlCzflbN4t9jQ=; b=DzQYteukXCIn19Cx6LlkSTW8NejjhQqOguZssmOtjeLJ4YC8SBd2ZHoDz9kVrX0fS1rBxNWAJU3OIJYvjxGCMOkKt/c0uwX8PlfsMfOz3eP4SgLqVAltq8Wi8ELXm2Zokdv7vrMCI9hn0CRc9umeIf+KcfJaD8q0I7YsfbxLn9h/pYqU3beGDYeciZ85qAkYZX3Rlqs1aPBYTtfOItNbFp6S8khNiVovMqd0YMYcO1ahv97Gec52YmaTZBdsnMIa/QST2g0NqFA4XB7AARHF5/NWfnWG3oOU8ZgQBSSThJVbmB5Plv4QnzgoomQBK8wN2OVL3zmt56Xc7X+lJWNUgg== Received: from AM5EUR03FT029.eop-EUR03.prod.protection.outlook.com (10.152.16.60) by AM5EUR03HT024.eop-EUR03.prod.protection.outlook.com (10.152.17.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2387.20; Wed, 30 Oct 2019 09:16:35 +0000 Received: from VI1PR0502MB3968.eurprd05.prod.outlook.com (10.152.16.53) by AM5EUR03FT029.mail.protection.outlook.com (10.152.16.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2387.20 via Frontend Transport; Wed, 30 Oct 2019 09:16:35 +0000 Received: from VI1PR0502MB3968.eurprd05.prod.outlook.com ([fe80::d1ae:fb86:1c1a:b74]) by VI1PR0502MB3968.eurprd05.prod.outlook.com ([fe80::d1ae:fb86:1c1a:b74%5]) with mapi id 15.20.2387.028; Wed, 30 Oct 2019 09:16:35 +0000 From: "Kilian Kegel" To: "Gao, Liming" , "devel@edk2.groups.io" CC: "Richardson, Brian" , "Kinney, Michael D" Subject: Re: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak() Thread-Topic: [edk2-devel] [edk2] [EmulatorPkg] using __debugbreak() Thread-Index: AQHVjY/MGMCILGZZT0Oc6Q9Dy/NV+adyrA4AgAAiB28= Date: Wed, 30 Oct 2019 09:16:35 +0000 Message-ID: References: <2d5ec4d308504c87b7b1390c1e2f1495@zhaoxin.com>,<4A89E2EF3DFEDB4C8BFDE51014F606A14E5325C1@SHSMSX104.ccr.corp.intel.com> ,<4A89E2EF3DFEDB4C8BFDE51014F606A14E534825@SHSMSX104.ccr.corp.intel.com> In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14E534825@SHSMSX104.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:6203B23DD38051459984432553D703B5CD9F420C6193C0B257D5361A566862F5;UpperCasedChecksum:59155A509A2317E351EB6F53A2E45148BFDE1216D737DA94B7E2D974E005ADF0;SizeAsReceived:7234;Count:44 x-tmn: [MjFsn4bqE/UFaoeWVyysXwIMSTVQbUPy] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-traffictypediagnostic: AM5EUR03HT024: x-ms-exchange-purlcount: 5 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: kL55jagiXxLrm1C+4aF4csQaoCipAw3GABgM6xrsPZl0RXgY/6E4PwaUym9kfWxye0ZrXaZuwlpycJv1BkyrP4bIEK1GUFF2l9ItWL3NUklPsKce3yVSrq/oe6pT7EQZ0EIiZFsbu+m3tqFs2YbUPnwlQu1qp9mdaG6/ChcSI1VufADBBbRG6aAQozCA5QjQ25YsrbNyDFHiSdxncJNYP7bZuZf4COYHg34pt43aau4= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: e0a05a2c-f71b-47c2-fae8-08d75d19dcf2 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Oct 2019 09:16:35.7961 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5EUR03HT024 X-Groupsio-MsgNum: 49647 Content-Language: en-US Content-Type: multipart/related; boundary="_004_VI1PR0502MB396820663F2CADB61E1D91DBEB600VI1PR0502MB3968_"; type="multipart/alternative" --_004_VI1PR0502MB396820663F2CADB61E1D91DBEB600VI1PR0502MB3968_ Content-Type: multipart/alternative; boundary="_000_VI1PR0502MB396820663F2CADB61E1D91DBEB600VI1PR0502MB3968_" --_000_VI1PR0502MB396820663F2CADB61E1D91DBEB600VI1PR0502MB3968_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable 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 =93exceptiona= l=94 process that emits INT 3 or any other violation trap and does not offer to debug the process = = =96 surly for security reasons=85 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 Kili= an Kegel Sent: Monday, October 28, 2019 9:01 PM To: Gao, Liming Cc: devel@edk2.groups.io; Richardson, Brian ; = 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 debu= g it. So in WinHost.exe too. That=92s 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_VI1PR0502MB396820663F2CADB61E1D91DBEB600VI1PR0502MB3968_ Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable

Hi Liming,

 

CpuBreakPoint() is the same as __debugbreak() on Mi= crosoft Compiler and generates INT 3 DebugTrap.

 

Yes, that procedure has worked in the past and I ha= ve used it in the same way as you do.

 

But with newer Windows versions, Windows just termi= nates the =93exceptional=94 process that emits

INT 3 or any other violation trap and does not offe= r to debug the process =96 surly for security reasons=85

 

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 _<= i>before_ the debug trap appears. VS is now

available for debugging the process with full sourc= e 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 othe= r 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 normal= ly modify the source code and insert CpuBreakpoint() function. That will tr= ig VS debugger for the source code.

 

Thanks

Liming

From: devel@edk2.groups.io [mailto:devel@edk= 2.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 <brian.richardson@in= tel.com>; Kinney, Michael D <michael.d.kinney@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, i= nstead offering to debug it.

So in WinHost.exe too.

 

That=92s why I usually insert the code snippet belo= w to run into getchar()

when the program was started with the /debug comman= d 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= ;

 

        SecPr= int ("################################################################= ######################################\n");

        SecPr= int ("add \"/debug\" command line switch, to connect to the = debugger at the very beginning of POST emulation\n");

        SecPr= int ("################################################################= ######################################\n");

 

        if(Ar= gc > 1){

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

        =         if(0 =3D=3D strcmp("/debug", Argv[i])){

        =             &nb= sp;   //SecPrint("IF YOU WANT TO DEBUG from the very beginni= ng of the EMULATION:\n\t1. start the TASKMGR\n\t2. connect WinHost.exe to t= he debugger\n\t3. and press ENTER in this command box\nOR\n");

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

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

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

        =              &n= bsp;  SecPrint("\t4. SET A SOFTWARE BREAKPOINT (F9) in line 445\n= ");

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

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

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

        =             &nb= sp;   getchar();<= /p>

        =             &nb= sp;   //

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

        =             &nb= sp;   // 2. switch to the command box and press ENTER<= /b>

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

        =             &nb= sp;   //

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

        =            }

        =     }

        }

    }

 

--_000_VI1PR0502MB396820663F2CADB61E1D91DBEB600VI1PR0502MB3968_-- --_004_VI1PR0502MB396820663F2CADB61E1D91DBEB600VI1PR0502MB3968_ Content-Type: image/png; name="84E6CE3361ED498BA9AC3CEA8ECF7B11.png" Content-Description: 84E6CE3361ED498BA9AC3CEA8ECF7B11.png Content-Disposition: inline; filename="84E6CE3361ED498BA9AC3CEA8ECF7B11.png"; size=144; creation-date="Wed, 30 Oct 2019 09:16:34 GMT"; modification-date="Wed, 30 Oct 2019 09:16:34 GMT" Content-ID: Content-Transfer-Encoding: base64 iVBORw0KGgoAAAANSUhEUgAAAsQAAAACCAYAAABfe8oDAAAAAXNSR0IArs4c6QAAAARnQU1BAACx jwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAlSURBVFhH7cMBDQAACAMg+5cygQkeRoMIGwUA AK/1ZFVV9efsAW0/ZqCCeHKlAAAAAElFTkSuQmCC --_004_VI1PR0502MB396820663F2CADB61E1D91DBEB600VI1PR0502MB3968_--