+/**@file\r
+\r
+Copyright (c) 2006 - 2009, Intel Corporation\r
+Portions copyright (c) 2008-2010 Apple Inc. All rights reserved.\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+#include <Library/PeCoffLib.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/PeCoffExtraActionLib.h>\r
+#include <Library/PrintLib.h>\r
+\r
+\r
+/**\r
+ If the build is done on cygwin the paths are cygpaths. \r
+ /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert\r
+ them to work with RVD commands\r
+\r
+ @param Name Path to convert if needed\r
+\r
+**/\r
+CHAR8 *\r
+DeCygwinPathIfNeeded (\r
+ IN CHAR8 *Name\r
+ )\r
+{\r
+ CHAR8 *Ptr;\r
+ UINTN Index;\r
+ UINTN Len;\r
+ \r
+ Ptr = AsciiStrStr (Name, "/cygdrive/");\r
+ if (Ptr == NULL) {\r
+ return Name;\r
+ }\r
+ \r
+ Len = AsciiStrLen (Ptr);\r
+ \r
+ // convert "/cygdrive" to spaces\r
+ for (Index = 0; Index < 9; Index++) {\r
+ Ptr[Index] = ' ';\r
+ }\r
+\r
+ // convert /c to c:\r
+ Ptr[9] = Ptr[10];\r
+ Ptr[10] = ':';\r
+ \r
+ // switch path seperators\r
+ for (Index = 11; Index < Len; Index++) {\r
+ if (Ptr[Index] == '/') {\r
+ Ptr[Index] = '\\' ;\r
+ }\r
+ }\r
+\r
+ return Name;\r
+}\r
+\r
+\r
+/**\r
+ Performs additional actions after a PE/COFF image has been loaded and relocated.\r
+\r
+ If ImageContext is NULL, then ASSERT().\r
+\r
+ @param ImageContext Pointer to the image context structure that describes the\r
+ PE/COFF image that has already been loaded and relocated.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageExtraAction (\r
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+#ifdef __CC_ARM\r
+ // Print out the command for the RVD debugger to load symbols for this image\r
+ DEBUG ((EFI_D_ERROR, "load /a /ni /np %a &0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));\r
+#elif __GNUC__\r
+ // This may not work correctly if you generate PE/COFF directlyas then the Offset would not be required\r
+ DEBUG ((EFI_D_ERROR, "add-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));\r
+#else\r
+ DEBUG ((EFI_D_ERROR, "Loading driver at 0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN) ImageContext->ImageAddress, FUNCTION_ENTRY_POINT (ImageContext->EntryPoint)));\r
+#endif\r
+}\r
+\r
+\r
+\r
+/**\r
+ Performs additional actions just before a PE/COFF image is unloaded. Any resources\r
+ that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.\r
+ \r
+ If ImageContext is NULL, then ASSERT().\r
+ \r
+ @param ImageContext Pointer to the image context structure that describes the\r
+ PE/COFF image that is being unloaded.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderUnloadImageExtraAction (\r
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
+ )\r
+{\r
+#ifdef __CC_ARM\r
+ // Print out the command for the RVD debugger to load symbols for this image\r
+ DEBUG ((EFI_D_ERROR, "unload symbols_only %a", DeCygwinPathIfNeeded (ImageContext->PdbPointer)));\r
+#elif __GNUC__\r
+ // This may not work correctly if you generate PE/COFF directlyas then the Offset would not be required\r
+ DEBUG ((EFI_D_ERROR, "remove-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));\r
+#else\r
+ DEBUG ((EFI_D_ERROR, "Unloading %a", ImageContext->PdbPointer));\r
+#endif\r
+}\r