Update BasePeCoff to handle the PE/COFF image without DEBUG entry.
authorlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Fri, 21 Nov 2008 07:20:54 +0000 (07:20 +0000)
committerlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Fri, 21 Nov 2008 07:20:54 +0000 (07:20 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1369 7335b38e-4728-0410-8992-fb3ffe349368

Source/C/Common/BasePeCoff.c

index c89d96c..196e97a 100644 (file)
@@ -1239,12 +1239,14 @@ PeCoffLoaderGetPdbPointer (
       for (Index1 = 0; Index1 < Index; Index1 ++) {\r
        if ((DirectoryEntry->VirtualAddress >= SectionHeader[Index1].VirtualAddress) && \r
                 (DirectoryEntry->VirtualAddress < (SectionHeader[Index1].VirtualAddress + SectionHeader[Index1].Misc.VirtualSize))) {\r
+          DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.Te +\r
+                        DirectoryEntry->VirtualAddress - \r
+                        SectionHeader [Index1].VirtualAddress + \r
+                        SectionHeader [Index1].PointerToRawData + \r
+                        TEImageAdjust);\r
           break;\r
         }\r
       }\r
-      DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.Te +\r
-                    DirectoryEntry->VirtualAddress - SectionHeader [Index1].VirtualAddress + SectionHeader [Index1].PointerToRawData + \r
-                    TEImageAdjust);\r
     }\r
   } else if (EFI_IMAGE_NT_SIGNATURE == Hdr.Pe32->Signature) {\r
     //\r
@@ -1295,7 +1297,7 @@ PeCoffLoaderGetPdbPointer (
       DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
     }\r
 \r
-    if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
+    if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG || DirectoryEntry->VirtualAddress == 0) {\r
       DirectoryEntry = NULL;\r
       DebugEntry = NULL;\r
     } else {\r
@@ -1305,10 +1307,14 @@ PeCoffLoaderGetPdbPointer (
       for (Index1 = 0; Index1 < Index; Index1 ++) {\r
        if ((DirectoryEntry->VirtualAddress >= SectionHeader[Index1].VirtualAddress) && \r
                 (DirectoryEntry->VirtualAddress < (SectionHeader[Index1].VirtualAddress + SectionHeader[Index1].Misc.VirtualSize))) {\r
+          DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (\r
+                       (UINTN) Pe32Data + \r
+                       DirectoryEntry->VirtualAddress - \r
+                       SectionHeader[Index1].VirtualAddress + \r
+                       SectionHeader[Index1].PointerToRawData);\r
           break;\r
         }\r
       }\r
-      DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress - SectionHeader[Index1].VirtualAddress + SectionHeader[Index1].PointerToRawData);\r
     }\r
   } else {\r
     return NULL;\r
@@ -1330,10 +1336,21 @@ PeCoffLoaderGetPdbPointer (
              for (Index1 = 0; Index1 < Index; Index1 ++) {\r
                if ((DebugEntry->RVA >= SectionHeader[Index1].VirtualAddress) && \r
                         (DebugEntry->RVA < (SectionHeader[Index1].VirtualAddress + SectionHeader[Index1].Misc.VirtualSize))) {\r
+                 CodeViewEntryPointer = (VOID *) (\r
+                                        ((UINTN)Pe32Data) + \r
+                                        (UINTN) DebugEntry->RVA - \r
+                                        SectionHeader[Index1].VirtualAddress + \r
+                                        SectionHeader[Index1].PointerToRawData + \r
+                                        (UINTN)TEImageAdjust);\r
                  break;\r
                }\r
              }\r
-        CodeViewEntryPointer = (VOID *) (((UINTN)Pe32Data) + (UINTN) DebugEntry->RVA - SectionHeader[Index1].VirtualAddress + SectionHeader[Index1].PointerToRawData + (UINTN)TEImageAdjust);\r
+             if (Index1 >= Index) {\r
+               //\r
+               // Can't find CodeViewEntryPointer in raw PE/COFF image.\r
+               //\r
+               continue;\r
+             }\r
         switch (* (UINT32 *) CodeViewEntryPointer) {\r
         case CODEVIEW_SIGNATURE_NB10:\r
           return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));\r