public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Chris Co <Christopher.Co@microsoft.com>
To: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Leif Lindholm <leif.lindholm@linaro.org>,
	Michael D Kinney <michael.d.kinney@intel.com>
Subject: [PATCH edk2-platforms 3/3] Platform/Microsoft: Add Lauterbach debug library
Date: Tue, 17 Jul 2018 02:05:45 +0000	[thread overview]
Message-ID: <20180717020529.19496-4-christopher.co@microsoft.com> (raw)
In-Reply-To: <20180717020529.19496-1-christopher.co@microsoft.com>

This debug library provides support for importing symbols to
debug using Lauterbach.

Derived from: ArmPkg\Library\DebugPeCoffExtraActionLib

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Christopher Co <christopher.co@microsoft.com>
---
 Platform/Microsoft/Library/LauterbachPeCoffExtraActionLib/LauterbachPeCoffExtraActionLib.c   | 142 ++++++++++++++++++++
 Platform/Microsoft/Library/LauterbachPeCoffExtraActionLib/LauterbachPeCoffExtraActionLib.inf |  41 ++++++
 2 files changed, 183 insertions(+)

diff --git a/Platform/Microsoft/Library/LauterbachPeCoffExtraActionLib/LauterbachPeCoffExtraActionLib.c b/Platform/Microsoft/Library/LauterbachPeCoffExtraActionLib/LauterbachPeCoffExtraActionLib.c
new file mode 100644
index 000000000000..0adfacdbe5cf
--- /dev/null
+++ b/Platform/Microsoft/Library/LauterbachPeCoffExtraActionLib/LauterbachPeCoffExtraActionLib.c
@@ -0,0 +1,142 @@
+/**@file
+
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
+Portions copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation. All rights reserved.<BR>
+
+This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution.  The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <PiDxe.h>
+#include <Library/PeCoffLib.h>
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/PeCoffExtraActionLib.h>
+#include <Library/PrintLib.h>
+
+
+/**
+  If the build is done on cygwin the paths are cygpaths.
+  /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert
+  them to work with RVD commands
+
+  @param  Name  Path to convert if needed
+
+**/
+CHAR8 *
+DeCygwinPathIfNeeded (
+  IN  CHAR8   *Name,
+  IN  CHAR8   *Temp,
+  IN  UINTN   Size
+  )
+{
+  CHAR8   *Ptr;
+  UINTN   Index;
+  UINTN   Index2;
+
+  Ptr = AsciiStrStr (Name, "/cygdrive/");
+  if (Ptr == NULL) {
+    return Name;
+  }
+
+  for (Index = 9, Index2 = 0; (Index < (Size + 9)) && (Ptr[Index] != '\0'); Index++, Index2++) {
+    Temp[Index2] = Ptr[Index];
+    if (Temp[Index2] == '/') {
+      Temp[Index2] = '\\' ;
+  }
+
+    if (Index2 == 1) {
+      Temp[Index2 - 1] = Ptr[Index];
+      Temp[Index2] = ':';
+    }
+  }
+
+  return Temp;
+}
+
+
+/**
+  Performs additional actions after a PE/COFF image has been loaded and relocated.
+
+  If ImageContext is NULL, then ASSERT().
+
+  @param  ImageContext  Pointer to the image context structure that describes the
+                        PE/COFF image that has already been loaded and relocated.
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderRelocateImageExtraAction (
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext
+  )
+{
+#if !defined(MDEPKG_NDEBUG)
+  CHAR8 Temp[512];
+#endif
+
+  if (ImageContext->PdbPointer) {
+#ifdef __CC_ARM
+#if (__ARMCC_VERSION < 500000)
+    // Print out the command for the RVD debugger to load symbols for this image
+    DEBUG ((DEBUG_LOAD | DEBUG_INFO, "load /a /ni /np %a &0x%p\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
+#else
+    // Print out the command for the DS-5 to load symbols for this image
+    DEBUG ((DEBUG_LOAD | DEBUG_INFO, "add-symbol-file %a 0x%p\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
+#endif
+#elif __GNUC__
+    // This may not work correctly if you generate PE/COFF directlyas then the Offset would not be required
+    DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Data.load.elf %a /reloc .text at 0x%p /nocode /noclear\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
+#else
+    DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Loading driver at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN) ImageContext->ImageAddress, FUNCTION_ENTRY_POINT (ImageContext->EntryPoint)));
+#endif
+  } else {
+    DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Loading driver at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN) ImageContext->ImageAddress, FUNCTION_ENTRY_POINT (ImageContext->EntryPoint)));
+  }
+}
+
+
+
+/**
+  Performs additional actions just before a PE/COFF image is unloaded.  Any resources
+  that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
+
+  If ImageContext is NULL, then ASSERT().
+
+  @param  ImageContext  Pointer to the image context structure that describes the
+                        PE/COFF image that is being unloaded.
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderUnloadImageExtraAction (
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext
+  )
+{
+#if !defined(MDEPKG_NDEBUG)
+  CHAR8 Temp[512];
+#endif
+
+  if (ImageContext->PdbPointer) {
+#ifdef __CC_ARM
+    // Print out the command for the RVD debugger to load symbols for this image
+    DEBUG ((DEBUG_ERROR, "unload symbols_only %a\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp))));
+#elif __GNUC__
+    // This may not work correctly if you generate PE/COFF directlyas then the Offset would not be required
+    DEBUG ((DEBUG_ERROR, "remove-symbol-file %a 0x%08x\n", DeCygwinPathIfNeeded (ImageContext->PdbPointer, Temp, sizeof (Temp)), (UINTN)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders)));
+#else
+    DEBUG ((DEBUG_ERROR, "Unloading %a\n", ImageContext->PdbPointer));
+#endif
+  } else {
+    DEBUG ((DEBUG_ERROR, "Unloading driver at 0x%11p\n", (VOID *)(UINTN) ImageContext->ImageAddress));
+  }
+}
diff --git a/Platform/Microsoft/Library/LauterbachPeCoffExtraActionLib/LauterbachPeCoffExtraActionLib.inf b/Platform/Microsoft/Library/LauterbachPeCoffExtraActionLib/LauterbachPeCoffExtraActionLib.inf
new file mode 100644
index 000000000000..2cfc51b0578f
--- /dev/null
+++ b/Platform/Microsoft/Library/LauterbachPeCoffExtraActionLib/LauterbachPeCoffExtraActionLib.inf
@@ -0,0 +1,41 @@
+#/** @file
+# PeCoff extra action libary for DXE phase that run Unix emulator.
+#
+# Lib to provide memory journal status code reporting Routines
+# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
+# Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution.  The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+#**/
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = LauterbachPeCoffExtraActionLib
+  FILE_GUID                      = F5D296F5-C546-431F-8CAC-3E91043B452D
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = PeCoffExtraActionLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = ARM
+#
+
+[Sources.common]
+  LauterbachPeCoffExtraActionLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  DebugLib
-- 
2.16.2.gvfs.1.33.gf5370f1



  parent reply	other threads:[~2018-07-17  2:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-17  2:05 [PATCH edk2-platforms 0/3] Add Platform-Generic Packages to support Windows IoT Core Chris Co
2018-07-17  2:05 ` [PATCH edk2-platforms 1/3] Platform/Microsoft: Add SdMmc Dxe Driver Chris Co
2018-07-31 20:33   ` Leif Lindholm
2018-08-02  0:05     ` Chris Co
2018-08-02 11:38       ` Leif Lindholm
2018-07-17  2:05 ` [PATCH edk2-platforms 2/3] Platform/Microsoft: Add MsPkg Chris Co
2018-07-31 20:38   ` Leif Lindholm
2018-07-17  2:05 ` Chris Co [this message]
2018-07-31 20:56   ` [PATCH edk2-platforms 3/3] Platform/Microsoft: Add Lauterbach debug library Leif Lindholm
2018-07-31 20:59     ` Ard Biesheuvel
2018-08-01  9:39       ` Leif Lindholm
2018-08-02  1:27         ` Chris Co
2018-08-02 11:22           ` Leif Lindholm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180717020529.19496-4-christopher.co@microsoft.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox