* [PATCH v1 0/1] ArmPlatformPkg/Scripts: Create add-symbol-file commands from UEFI console
@ 2021-06-15 15:11 Artem Kopotev
2021-06-15 15:11 ` [PATCH v1 1/1] " Artem Kopotev
[not found] ` <1688D28138E4C4FE.1864@groups.io>
0 siblings, 2 replies; 6+ messages in thread
From: Artem Kopotev @ 2021-06-15 15:11 UTC (permalink / raw)
To: devel; +Cc: Leif Lindholm, Ard Biesheuvel
cmd_load_symbols.py can only load symbols from a firmware volume. Add the possibility to
use UEFI console output to calculate dll load address and send
add-symbol-file commands directly to ArmDS debugger
Public branch:
https://github.com/artkopotev/edk2/commits/fix_armds_debug_script
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
artem.kopotev (1):
ArmPlatformPkg/Scripts: Create add-symbol-file commands from UEFI
console
.../Scripts/Ds5/cmd_load_symbols.py | 17 ++++-
ArmPlatformPkg/Scripts/Ds5/console_loader.py | 68 +++++++++++++++++++
2 files changed, 83 insertions(+), 2 deletions(-)
create mode 100644 ArmPlatformPkg/Scripts/Ds5/console_loader.py
--
2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v1 1/1] ArmPlatformPkg/Scripts: Create add-symbol-file commands from UEFI console
2021-06-15 15:11 [PATCH v1 0/1] ArmPlatformPkg/Scripts: Create add-symbol-file commands from UEFI console Artem Kopotev
@ 2021-06-15 15:11 ` Artem Kopotev
2021-06-22 14:49 ` [edk2-devel] " PierreGondois
[not found] ` <1688D28138E4C4FE.1864@groups.io>
1 sibling, 1 reply; 6+ messages in thread
From: Artem Kopotev @ 2021-06-15 15:11 UTC (permalink / raw)
To: devel
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>
Change-Id: I3ac5ea761254a346bbb5806fb089b0979419bc01
---
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/ArmPlatformPkg/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
+from console_loader import load_symbol_from_console
+
import re, sys, getopt
import edk2_debugger
@@ -21,12 +23,16 @@ def usage():
print "-m,--sysmem=(base,size): System Memory region"
print "-f,--fv=(base,size): Firmware region"
print "-r,--rom=(base,size): ROM region"
+ print "-i,--input=: Filename for the EDK2 console output"
+ print "-o,--objdump=: Path to the objdump tool"
verbose = False
load_all = False
report_file = None
+input_file = None
+objdump = None
regions = []
-opts,args = getopt.getopt(sys.argv[1:], "hvar:vm:vr:vf:v", ["help","verbose","all","report=","sysmem=","rom=","fv="])
+opts,args = getopt.getopt(sys.argv[1:], "hvar:i:o:vm:vr:vf:v", ["help","verbose","all","report=","sysmem=","rom=","fv=","input=","objdump="])
if (opts is None) or (not opts):
report_file = '../../../report.log'
else:
@@ -55,6 +61,10 @@ else:
elif o in ("-r","--rom"):
region_type = edk2_debugger.ArmPlatformDebugger.REGION_TYPE_ROM
regex = region_reg
+ elif o in ("-i","--input"):
+ input_file = a
+ elif o in ("-o", "--objdump"):
+ objdump = a
else:
assert False, "Unhandled option (%s)" % o
@@ -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 = 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 = [i for i in list if module_name in i and re.search(r'\b'+module_name+r'\b', i)]
+ if len(line) == 0:
+ # Module was not loaded using DxeDispatcher or PeiDispatcher. It is a SEC module
+ # Symbols for these modules are loaded from FV, not from console log
+ return None
+
+ entrypoint_str = line[0].rsplit(' ')[4]
+ return entrypoint_str.rsplit('=')[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 parameter 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 = open(console_file).read().splitlines()
+
+ efi_list = [i for i in full_list if "EntryPoint=" in i]
+
+ full_list = dict.fromkeys(full_list)
+ full_list = [i for i in full_list if "add-symbol-file" in i]
+
+ module_dict = {}
+
+ for line in full_list:
+ name = get_module_name(line)
+ module_dict[name] = (get_module_path(line), get_module_entrypoint(efi_list, name))
+
+ for module in module_dict:
+ entrypoint_addr = module_dict[module][1]
+
+ if entrypoint_addr is not None:
+ path = module_dict[module][0]
+ if not os.path.exists(path):
+ print "Module not found: " + path + ". Skipping..."
+ continue
+
+ sp = subprocess.Popen([objdump,'-S', path], stdout = subprocess.PIPE)
+
+ objdump_out = sp.stdout.readlines()
+ entrypoint_record = [i for i in objdump_out if "<_ModuleEntryPoint>" in i]
+
+ entrypoint_offset = entrypoint_record[0].split(' ')[0]
+
+ load_addr = int(entrypoint_addr, 16) - int(entrypoint_offset, 16)
+
+ edk2_debugger.load_symbol_from_file(ec, path, load_addr, verbose)
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [edk2-devel] [PATCH v1 1/1] ArmPlatformPkg/Scripts: Create add-symbol-file commands from UEFI console
2021-06-15 15:11 ` [PATCH v1 1/1] " Artem Kopotev
@ 2021-06-22 14:49 ` PierreGondois
2021-07-09 9:02 ` PierreGondois
0 siblings, 1 reply; 6+ messages in thread
From: PierreGondois @ 2021-06-22 14:49 UTC (permalink / raw)
To: Artem Kopotev, devel
[-- Attachment #1: Type: text/plain, Size: 98 bytes --]
Hello,
I tested this patch on the ArmVExpress-FVP-AArch64 platform with DS-5,
Regards,
Pierre
[-- Attachment #2: Type: text/html, Size: 110 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [edk2-devel] [PATCH v1 1/1] ArmPlatformPkg/Scripts: Create add-symbol-file commands from UEFI console
2021-06-22 14:49 ` [edk2-devel] " PierreGondois
@ 2021-07-09 9:02 ` PierreGondois
2021-07-19 7:39 ` Ard Biesheuvel
0 siblings, 1 reply; 6+ messages in thread
From: PierreGondois @ 2021-07-09 9:02 UTC (permalink / raw)
To: PierreGondois, devel
[-- Attachment #1: Type: text/plain, Size: 70 bytes --]
More formally:
Tested-by: Pierre Gondois <Pierre.Gondois@arm.com>
[-- Attachment #2: Type: text/html, Size: 88 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [edk2-devel] [PATCH v1 1/1] ArmPlatformPkg/Scripts: Create add-symbol-file commands from UEFI console
[not found] ` <1688D28138E4C4FE.1864@groups.io>
@ 2021-07-14 9:53 ` Artem Kopotev
0 siblings, 0 replies; 6+ messages in thread
From: Artem Kopotev @ 2021-07-14 9:53 UTC (permalink / raw)
To: devel@edk2.groups.io, Artem Kopotev
Cc: Leif Lindholm, Ard Biesheuvel, Sami Mujawar
Hello,
This is the second email, which originally didn't have CC to maintainers.
Best regards, Artem.
-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Artem Kopotev via groups.io
Sent: 15 June 2021 16:11
To: devel@edk2.groups.io
Subject: [edk2-devel] [PATCH v1 1/1] ArmPlatformPkg/Scripts: Create add-symbol-file commands from UEFI console
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>
Change-Id: I3ac5ea761254a346bbb5806fb089b0979419bc01
---
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/ArmPlatformPkg/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
+from console_loader import load_symbol_from_console
+
import re, sys, getopt
import edk2_debugger
@@ -21,12 +23,16 @@ def usage():
print "-m,--sysmem=(base,size): System Memory region"
print "-f,--fv=(base,size): Firmware region"
print "-r,--rom=(base,size): ROM region"
+ print "-i,--input=: Filename for the EDK2 console output"
+ print "-o,--objdump=: Path to the objdump tool"
verbose = False
load_all = False
report_file = None
+input_file = None
+objdump = None
regions = []
-opts,args = getopt.getopt(sys.argv[1:], "hvar:vm:vr:vf:v", ["help","verbose","all","report=","sysmem=","rom=","fv="])
+opts,args = getopt.getopt(sys.argv[1:], "hvar:i:o:vm:vr:vf:v",
+["help","verbose","all","report=","sysmem=","rom=","fv=","input=","objd
+ump="])
if (opts is None) or (not opts):
report_file = '../../../report.log'
else:
@@ -55,6 +61,10 @@ else:
elif o in ("-r","--rom"):
region_type = edk2_debugger.ArmPlatformDebugger.REGION_TYPE_ROM
regex = region_reg
+ elif o in ("-i","--input"):
+ input_file = a
+ elif o in ("-o", "--objdump"):
+ objdump = a
else:
assert False, "Unhandled option (%s)" % o
@@ -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 = 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 = [i for i in list if module_name in i and re.search(r'\b'+module_name+r'\b', i)]
+ if len(line) == 0:
+ # Module was not loaded using DxeDispatcher or PeiDispatcher. It is a SEC module
+ # Symbols for these modules are loaded from FV, not from console log
+ return None
+
+ entrypoint_str = line[0].rsplit(' ')[4]
+ return entrypoint_str.rsplit('=')[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 parameter 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 = open(console_file).read().splitlines()
+
+ efi_list = [i for i in full_list if "EntryPoint=" in i]
+
+ full_list = dict.fromkeys(full_list)
+ full_list = [i for i in full_list if "add-symbol-file" in i]
+
+ module_dict = {}
+
+ for line in full_list:
+ name = get_module_name(line)
+ module_dict[name] = (get_module_path(line),
+ get_module_entrypoint(efi_list, name))
+
+ for module in module_dict:
+ entrypoint_addr = module_dict[module][1]
+
+ if entrypoint_addr is not None:
+ path = module_dict[module][0]
+ if not os.path.exists(path):
+ print "Module not found: " + path + ". Skipping..."
+ continue
+
+ sp = subprocess.Popen([objdump,'-S', path], stdout =
+ subprocess.PIPE)
+
+ objdump_out = sp.stdout.readlines()
+ entrypoint_record = [i for i in objdump_out if
+ "<_ModuleEntryPoint>" in i]
+
+ entrypoint_offset = entrypoint_record[0].split(' ')[0]
+
+ load_addr = int(entrypoint_addr, 16) -
+ int(entrypoint_offset, 16)
+
+ edk2_debugger.load_symbol_from_file(ec, path,
+ load_addr, verbose)
--
2.17.1
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [edk2-devel] [PATCH v1 1/1] ArmPlatformPkg/Scripts: Create add-symbol-file commands from UEFI console
2021-07-09 9:02 ` PierreGondois
@ 2021-07-19 7:39 ` Ard Biesheuvel
0 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2021-07-19 7:39 UTC (permalink / raw)
To: edk2-devel-groups-io, Pierre
On Fri, 9 Jul 2021 at 11:03, PierreGondois <pierre.gondois@arm.com> wrote:
>
> More formally:
>
> Tested-by: Pierre Gondois <Pierre.Gondois@arm.com>
>
Merged as #1821
Thanks,
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-07-19 7:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-15 15:11 [PATCH v1 0/1] ArmPlatformPkg/Scripts: Create add-symbol-file commands from UEFI console Artem Kopotev
2021-06-15 15:11 ` [PATCH v1 1/1] " Artem Kopotev
2021-06-22 14:49 ` [edk2-devel] " PierreGondois
2021-07-09 9:02 ` PierreGondois
2021-07-19 7:39 ` Ard Biesheuvel
[not found] ` <1688D28138E4C4FE.1864@groups.io>
2021-07-14 9:53 ` Artem Kopotev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox