Revision: 17071
          http://sourceforge.net/p/edk2/code/17071
Author:   vanjeff
Date:     2015-03-25 01:51:23 +0000 (Wed, 25 Mar 2015)
Log Message:
-----------
PeCoffExtraActionLibDebug: Restore debug registers in PeCoffExtraActionLibDebug

PeCoffExtraActionLibDebug uses the debug registers to pass module load 
information to the 
DebugAgent, then restores the old register values.
However, it was missing code to restore Dr7 in the
DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3 case.  This broke hardware breakpoints and 
watchpoints.  
It could also lose modifications the debugger made to Cr4.

Restore the Dr7 and Cr4 values correctly in the
DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3 case, as well as the 
DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT case.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Brian J. Johnson <[email protected]>
Reviewed-by: Jeff Fan <[email protected]>
Reviewed-by: Michael Kinney <[email protected]>

Modified Paths:
--------------
    
trunk/edk2/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c

Modified: 
trunk/edk2/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c
===================================================================
--- 
trunk/edk2/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c
     2015-03-24 02:09:36 UTC (rev 17070)
+++ 
trunk/edk2/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c
     2015-03-25 01:51:23 UTC (rev 17071)
@@ -104,7 +104,7 @@
   Dr1 = AsmReadDr1 ();
   Dr2 = AsmReadDr2 ();
   Dr3 = AsmReadDr3 ();
-  Dr7 = AsmReadDr7 ();
+  Dr7 = AsmReadDr7 () | BIT10; // H/w sets bit 10, some simulators don't
   Cr4 = AsmReadCr4 ();
 
   //
@@ -115,7 +115,7 @@
   // DR7 = Disables all HW breakpoints except for DR3 I/O port access of 
length 1 byte
   // CR4 = Make sure DE(BIT3) is set
   //
-  AsmWriteDr7 (0);
+  AsmWriteDr7 (BIT10);
   AsmWriteDr0 (Signature);
   AsmWriteDr1 ((UINTN) ImageContext->PdbPointer);
   AsmWriteDr2 ((UINTN) ImageContext);
@@ -144,7 +144,7 @@
   // E.g.: User halts the target and sets the HW breakpoint while target is 
   //       in the above exception handler
   //
-  NewDr7 = AsmReadDr7 ();
+  NewDr7 = AsmReadDr7 () | BIT10; // H/w sets bit 10, some simulators don't
   if (!IsDrxEnabled (0, NewDr7) && (AsmReadDr0 () == 0 || AsmReadDr0 () == 
Signature)) {
     //
     // If user changed Dr3 (by setting HW bp in the above exception handler,
@@ -161,12 +161,18 @@
   if (!IsDrxEnabled (3, NewDr7) && (AsmReadDr3 () == 
IO_PORT_BREAKPOINT_ADDRESS)) {
     AsmWriteDr3 (Dr3);
   }
-  if (AsmReadCr4 () == (Cr4 | BIT3)) {
-    AsmWriteCr4 (Cr4);
+  if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT) {
+    if (AsmReadCr4 () == (Cr4 | BIT3)) {
+      AsmWriteCr4 (Cr4);
+    }
+    if (NewDr7 == 0x20000480) {
+      AsmWriteDr7 (Dr7);
+    }
+  } else if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3) {
+    if (NewDr7 == BIT10) {
+      AsmWriteDr7 (Dr7);
+    }
   }
-  if (NewDr7 == 0x20000480) {
-    AsmWriteDr7 (Dr7);
-  }
   //
   // Restore original IDT entry for INT1 if it was hooked.
   //


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to