+EFI_STATUS
+AddHandle (
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
+ IN VOID *ModHandle
+ )
+/*++
+
+Routine Description:
+ Store the ModHandle in an array indexed by the Pdb File name.
+ The ModHandle is needed to unload the image.
+
+Arguments:
+ ImageContext - Input data returned from PE Laoder Library. Used to find the
+ .PDB file name of the PE Image.
+ ModHandle - Returned from LoadLibraryEx() and stored for call to
+ FreeLibrary().
+
+Returns:
+ EFI_SUCCESS - ModHandle was stored.
+
+--*/
+{
+ UINTN Index;
+ IMAGE_CONTEXT_TO_MOD_HANDLE *Array;
+ UINTN PreviousSize;
+
+
+ Array = mImageContextModHandleArray;
+ for (Index = 0; Index < mImageContextModHandleArraySize; Index++, Array++) {
+ if (Array->ImageContext == NULL) {
+ //
+ // Make a copy of the stirng and store the ModHandle
+ //
+ Array->ImageContext = ImageContext;
+ Array->ModHandle = ModHandle;
+ return EFI_SUCCESS;
+ }
+ }
+
+ //
+ // No free space in mImageContextModHandleArray so grow it by
+ // IMAGE_CONTEXT_TO_MOD_HANDLE entires. realloc will
+ // copy the old values to the new locaiton. But it does
+ // not zero the new memory area.
+ //
+ PreviousSize = mImageContextModHandleArraySize * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE);
+ mImageContextModHandleArraySize += MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE;
+
+ mImageContextModHandleArray = realloc (mImageContextModHandleArray, mImageContextModHandleArraySize * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE));
+ if (mImageContextModHandleArray == NULL) {
+ ASSERT (FALSE);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ memset (mImageContextModHandleArray + PreviousSize, 0, MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE));
+
+ return AddHandle (ImageContext, ModHandle);
+}
+
+
+VOID *
+RemoveHandle (
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+/*++
+
+Routine Description:
+ Return the ModHandle and delete the entry in the array.
+
+Arguments:
+ ImageContext - Input data returned from PE Laoder Library. Used to find the
+ .PDB file name of the PE Image.
+
+Returns:
+ ModHandle - ModHandle assoicated with ImageContext is returned
+ NULL - No ModHandle associated with ImageContext
+
+--*/
+{
+ UINTN Index;
+ IMAGE_CONTEXT_TO_MOD_HANDLE *Array;
+
+ if (ImageContext->PdbPointer == NULL) {
+ //
+ // If no PDB pointer there is no ModHandle so return NULL
+ //
+ return NULL;
+ }
+
+ Array = mImageContextModHandleArray;
+ for (Index = 0; Index < mImageContextModHandleArraySize; Index++, Array++) {
+ if ((Array->ImageContext == ImageContext)) {
+ //
+ // If you find a match return it and delete the entry
+ //
+ Array->ImageContext = NULL;
+ return Array->ModHandle;
+ }
+ }
+
+ return NULL;
+}
+
+
+
+//
+// Target for gdb breakpoint in a script that uses gGdbWorkingFileName to source a
+// add-symbol-file command. Hey what can you say scripting in gdb is not that great....
+//
+// Put .gdbinit in the CWD where you do gdb SecMain.dll for source level debug
+//
+// cat .gdbinit
+// b SecGdbScriptBreak
+// command
+// silent
+// source SecMain.dll.gdb
+// c
+// end
+//
+VOID
+SecGdbScriptBreak (
+ VOID
+ )
+{
+}