From nobody Sat May 4 13:33:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+76556+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+76556+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1623779118; cv=none; d=zohomail.com; s=zohoarc; b=OM5zDa6faz+JgjefvXsk/Vkj5MspZhSXUH/eObfCwTAbvBaN9ZVnpUQKmSovEXz46VPXsd+KrLhgITD2logZbRfEIYpONV2f6QyfJ7zhH/325irbNGe2tkYnWeCoGwYomyMBQHXyBZ9rn1p7Wx5jeQ+vPGb27iPU8fQUeF/bR/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623779118; h=Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=+8N0JvttZt3ks9Y9cK5Nt1SF5H7qbtTAvVyPQCfGrCE=; b=c+DNq7TYPz6N8w7n/zG2qvDnDxwvrnOmxjO8Q2M9iEPXzaffjLqAXWVscUlBDfWeDO2wwgIbxWSkIB5Qwex6ybK/cqwHRugXWbf9hw505riqFofQ0kuovNQdAm80+CdP6XeJE3FSSwi9uXXhpkn7ceTGjgTyAGm0hY1bw9ZjQZI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+76556+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1623779118892834.9189513739791; Tue, 15 Jun 2021 10:45:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id NrZ6YY1788612xFUxvkgWm0Y; Tue, 15 Jun 2021 10:45:18 -0700 X-Received: from cam-smtp0.cambridge.arm.com (cam-smtp0.cambridge.arm.com [217.140.106.55]) by mx.groups.io with SMTP id smtpd.web11.10880.1623769880094989789 for ; Tue, 15 Jun 2021 08:11:20 -0700 X-Received: from e123346.cambridge.arm.com (e123346.cambridge.arm.com [10.2.76.51]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id 15FFBFoL000796 for ; Tue, 15 Jun 2021 16:11:16 +0100 From: "Artem Kopotev" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v1 1/1] ArmPlatformPkg/Scripts: Create add-symbol-file commands from UEFI console Date: Tue, 15 Jun 2021 16:11:16 +0100 Message-Id: <20210615151116.972-2-artem.kopotev@arm.com> In-Reply-To: <20210615151116.972-1-artem.kopotev@arm.com> References: <20210615151116.972-1-artem.kopotev@arm.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,Artem.Kopotev@arm.com X-Gm-Message-State: CtsOV0XJRJwllvpA6iXPEj28x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1623779118; bh=I/6zRXNp/YLoYMgf/ed5he8ACwTkDdj2YgpweKZcUC8=; h=Date:From:Reply-To:Subject:To; b=Yoab6e3yw3BBTluBz7gezXdLvnOexnltQ8Ng9059x+Q6/Idb6D/e91HDQX1ECu0Ero1 f+AniQAFZCfcl+HXGQtwULPzvpr5XF+UZRynw7liSuKDnB5Cj5k5eY5CtgO7+lX1uidws 2XxQy1AOcF4QA9uq97t4/1mrBCPCiyueO5M= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=3D
from UEFI console output (entrypoint) 3) dll load address is (entrypoint)-(offset) Signed-off-by: Artem Kopotev Change-Id: I3ac5ea761254a346bbb5806fb089b0979419bc01 Tested-by: Pierre Gondois --- ArmPlatformPkg/Scripts/Ds5/cmd_load_symbols.py | 17 ++++- ArmPlatformPkg/Scripts/Ds5/console_loader.py | 68 ++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/ArmPlatformPkg/Scripts/Ds5/cmd_load_symbols.py b/ArmPlatformPk= g/Scripts/Ds5/cmd_load_symbols.py index de4332edc7d4..89d2f28ba27d 100644 --- a/ArmPlatformPkg/Scripts/Ds5/cmd_load_symbols.py +++ b/ArmPlatformPkg/Scripts/Ds5/cmd_load_symbols.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2011-2013, ARM Limited. All rights reserved. +# Copyright (c) 2011-2021, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -7,6 +7,8 @@ from arm_ds.debugger_v1 import Debugger from arm_ds.debugger_v1 import DebugException =20 +from console_loader import load_symbol_from_console + import re, sys, getopt =20 import edk2_debugger @@ -21,12 +23,16 @@ def usage(): print "-m,--sysmem=3D(base,size): System Memory region" print "-f,--fv=3D(base,size): Firmware region" print "-r,--rom=3D(base,size): ROM region" + print "-i,--input=3D: Filename for the EDK2 console output" + print "-o,--objdump=3D: Path to the objdump tool" =20 verbose =3D False load_all =3D False report_file =3D None +input_file =3D None +objdump =3D None regions =3D [] -opts,args =3D getopt.getopt(sys.argv[1:], "hvar:vm:vr:vf:v", ["help","verb= ose","all","report=3D","sysmem=3D","rom=3D","fv=3D"]) +opts,args =3D getopt.getopt(sys.argv[1:], "hvar:i:o:vm:vr:vf:v", ["help","= verbose","all","report=3D","sysmem=3D","rom=3D","fv=3D","input=3D","objdump= =3D"]) if (opts is None) or (not opts): report_file =3D '../../../report.log' else: @@ -55,6 +61,10 @@ else: elif o in ("-r","--rom"): region_type =3D edk2_debugger.ArmPlatformDebugger.REGION_TYPE_= ROM regex =3D region_reg + elif o in ("-i","--input"): + input_file =3D a + elif o in ("-o", "--objdump"): + objdump =3D a else: assert False, "Unhandled option (%s)" % o =20 @@ -94,3 +104,6 @@ except Exception, (ErrorClass, ErrorMessage): print "Error(%s): %s" % (ErrorClass, ErrorMessage) except DebugException, de: print "DebugError: %s" % (de.getMessage()) + +if input_file: + load_symbol_from_console(ec, input_file, objdump, verbose) diff --git a/ArmPlatformPkg/Scripts/Ds5/console_loader.py b/ArmPlatformPkg/= Scripts/Ds5/console_loader.py new file mode 100644 index 000000000000..0ce217876d95 --- /dev/null +++ b/ArmPlatformPkg/Scripts/Ds5/console_loader.py @@ -0,0 +1,68 @@ +# +# Copyright (c) 2021, Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +from arm_ds.debugger_v1 import DebugException + +import subprocess, os, edk2_debugger, re + +def get_module_name(line): + path =3D line.rsplit(' ')[1] + return os.path.splitext(os.path.basename(path))[0] + +def get_module_path(line): + return line.rsplit(' ')[1] + +def get_module_entrypoint(list, module_name): + line =3D [i for i in list if module_name in i and re.search(r'\b'+modu= le_name+r'\b', i)] + if len(line) =3D=3D 0: + # Module was not loaded using DxeDispatcher or PeiDispatcher. It i= s a SEC module + # Symbols for these modules are loaded from FV, not from console l= og + return None + + entrypoint_str =3D line[0].rsplit(' ')[4] + return entrypoint_str.rsplit('=3D')[1] + +def load_symbol_from_console(ec, console_file, objdump, verbose): + if objdump is None: + print "Error: A path to objdump tool is not specified, but -i para= meter is provided" + elif not os.path.exists(objdump): + print "Error: Provided path to objdump is invalid: %s" % objdump + elif not os.path.exists(console_file): + print "Error: UEFI console file is not found: %s" % console_file + else: + + full_list =3D open(console_file).read().splitlines() + + efi_list =3D [i for i in full_list if "EntryPoint=3D" in i] + + full_list =3D dict.fromkeys(full_list) + full_list =3D [i for i in full_list if "add-symbol-file" in i] + + module_dict =3D {} + + for line in full_list: + name =3D get_module_name(line) + module_dict[name] =3D (get_module_path(line), get_module_entry= point(efi_list, name)) + + for module in module_dict: + entrypoint_addr =3D module_dict[module][1] + + if entrypoint_addr is not None: + path =3D module_dict[module][0] + if not os.path.exists(path): + print "Module not found: " + path + ". Skipping..." + continue + + sp =3D subprocess.Popen([objdump,'-S', path], stdout =3D s= ubprocess.PIPE) + + objdump_out =3D sp.stdout.readlines() + entrypoint_record =3D [i for i in objdump_out if "<_Module= EntryPoint>" in i] + + entrypoint_offset =3D entrypoint_record[0].split(' ')[0] + + load_addr =3D int(entrypoint_addr, 16) - int(entrypoint_of= fset, 16) + + edk2_debugger.load_symbol_from_file(ec, path, load_addr, v= erbose) --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#76556): https://edk2.groups.io/g/devel/message/76556 Mute This Topic: https://groups.io/mt/83561852/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-