]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPlatformPkg/Scripts: Infer dll load address from console output
authorArtem Kopotev <Artem.Kopotev@arm.com>
Tue, 15 Jun 2021 15:11:16 +0000 (16:11 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 19 Jul 2021 07:38:14 +0000 (07:38 +0000)
cmd_load_symbols.py can only load symbols from FV. Add the possibility to
use UEFI console output to calculate dll load address and send
add-symbol-file commands directly to ArmDS debugger

dll load address can't be used directly from UEFI output, see comment in
DebugPeCoffExtraActionLib: "This may not work correctly if you generate
PE/COFF directly as then the Offset would not be required".

1) Use objdump -S module.dll | grep <_ModuleEntryPoint> to get offset
in dll (offset)
2) Use Entrypoint=<address> from UEFI console output (entrypoint)
3) dll load address is (entrypoint)-(offset)

Signed-off-by: Artem Kopotev <artem.kopotev@arm.com>
Tested-by: Pierre Gondois <Pierre.Gondois@arm.com>
ArmPlatformPkg/Scripts/Ds5/cmd_load_symbols.py
ArmPlatformPkg/Scripts/Ds5/console_loader.py [new file with mode: 0644]

index de4332edc7d4a2b130656dc174cb055e83b9f545..89d2f28ba27d97b39c43d373267fbd2b8a586ad7 100644 (file)
@@ -1,5 +1,5 @@
 #\r
-#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
+#  Copyright (c) 2011-2021, Arm Limited. All rights reserved.\r
 #\r
 #  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
@@ -7,6 +7,8 @@
 from arm_ds.debugger_v1 import Debugger\r
 from arm_ds.debugger_v1 import DebugException\r
 \r
+from console_loader import load_symbol_from_console\r
+\r
 import re, sys, getopt\r
 \r
 import edk2_debugger\r
@@ -21,12 +23,16 @@ def usage():
     print "-m,--sysmem=(base,size): System Memory region"\r
     print "-f,--fv=(base,size): Firmware region"\r
     print "-r,--rom=(base,size): ROM region"\r
+    print "-i,--input=: Filename for the EDK2 console output"\r
+    print "-o,--objdump=: Path to the objdump tool"\r
 \r
 verbose = False\r
 load_all = False\r
 report_file = None\r
+input_file = None\r
+objdump = None\r
 regions = []\r
-opts,args = getopt.getopt(sys.argv[1:], "hvar:vm:vr:vf:v", ["help","verbose","all","report=","sysmem=","rom=","fv="])\r
+opts,args = getopt.getopt(sys.argv[1:], "hvar:i:o:vm:vr:vf:v", ["help","verbose","all","report=","sysmem=","rom=","fv=","input=","objdump="])\r
 if (opts is None) or (not opts):\r
     report_file = '../../../report.log'\r
 else:\r
@@ -55,6 +61,10 @@ else:
         elif o in ("-r","--rom"):\r
             region_type = edk2_debugger.ArmPlatformDebugger.REGION_TYPE_ROM\r
             regex = region_reg\r
+        elif o in ("-i","--input"):\r
+            input_file = a\r
+        elif o in ("-o", "--objdump"):\r
+            objdump = a\r
         else:\r
             assert False, "Unhandled option (%s)" % o\r
 \r
@@ -94,3 +104,6 @@ except Exception, (ErrorClass, ErrorMessage):
     print "Error(%s): %s" % (ErrorClass, ErrorMessage)\r
 except DebugException, de:\r
     print "DebugError: %s" % (de.getMessage())\r
+\r
+if input_file:\r
+    load_symbol_from_console(ec, input_file, objdump, verbose)\r
diff --git a/ArmPlatformPkg/Scripts/Ds5/console_loader.py b/ArmPlatformPkg/Scripts/Ds5/console_loader.py
new file mode 100644 (file)
index 0000000..e9c52d5
--- /dev/null
@@ -0,0 +1,68 @@
+#\r
+#  Copyright (c) 2021, Arm Limited. All rights reserved.\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+\r
+from arm_ds.debugger_v1 import DebugException\r
+\r
+import subprocess, os, edk2_debugger, re\r
+\r
+def get_module_name(line):\r
+    path = line.rsplit(' ')[1]\r
+    return os.path.splitext(os.path.basename(path))[0]\r
+\r
+def get_module_path(line):\r
+    return line.rsplit(' ')[1]\r
+\r
+def get_module_entrypoint(list, module_name):\r
+    line = [i for i in list if module_name in i and re.search(r'\b'+module_name+r'\b', i)]\r
+    if len(line) == 0:\r
+        # Module was not loaded using DxeDispatcher or PeiDispatcher. It is a SEC module\r
+        # Symbols for these modules are loaded from FV, not from console log\r
+        return None\r
+\r
+    entrypoint_str =  line[0].rsplit(' ')[4]\r
+    return entrypoint_str.rsplit('=')[1]\r
+\r
+def load_symbol_from_console(ec, console_file, objdump, verbose):\r
+    if objdump is None:\r
+        print "Error: A path to objdump tool is not specified, but -i parameter is provided"\r
+    elif not os.path.exists(objdump):\r
+        print "Error: Provided path to objdump is invalid: %s" % objdump\r
+    elif not os.path.exists(console_file):\r
+        print "Error: UEFI console file is not found: %s" % console_file\r
+    else:\r
+\r
+        full_list = open(console_file).read().splitlines()\r
+\r
+        efi_list = [i for i in full_list if "EntryPoint=" in i]\r
+\r
+        full_list = dict.fromkeys(full_list)\r
+        full_list = [i for i in full_list if "add-symbol-file" in i]\r
+\r
+        module_dict = {}\r
+\r
+        for line in full_list:\r
+            name = get_module_name(line)\r
+            module_dict[name] = (get_module_path(line), get_module_entrypoint(efi_list, name))\r
+\r
+        for module in module_dict:\r
+            entrypoint_addr = module_dict[module][1]\r
+\r
+            if entrypoint_addr is not None:\r
+                path = module_dict[module][0]\r
+                if not os.path.exists(path):\r
+                    print "Module not found: " + path + ". Skipping..."\r
+                    continue\r
+\r
+                sp = subprocess.Popen([objdump,'-S', path], stdout = subprocess.PIPE)\r
+\r
+                objdump_out = sp.stdout.readlines()\r
+                entrypoint_record = [i for i in objdump_out if "<_ModuleEntryPoint>" in i]\r
+\r
+                entrypoint_offset = entrypoint_record[0].split(' ')[0]\r
+\r
+                load_addr = int(entrypoint_addr, 16) - int(entrypoint_offset, 16)\r
+\r
+                edk2_debugger.load_symbol_from_file(ec, path, load_addr, verbose)\r