1# 2# Copyright (c) 2011-2013, ARM Limited. All rights reserved. 3# 4# This program and the accompanying materials 5# are licensed and made available under the terms and conditions of the BSD License 6# which accompanies this distribution. The full text of the license may be found at 7# http://opensource.org/licenses/bsd-license.php 8# 9# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11# 12 13from arm_ds.debugger_v1 import Debugger 14from arm_ds.debugger_v1 import DebugException 15 16import re, sys, getopt 17 18import edk2_debugger 19 20# Reload external classes 21reload(edk2_debugger) 22 23def usage(): 24 print "-v,--verbose" 25 print "-a,--all: Load all symbols" 26 print "-l,--report=: Filename for the EDK2 report log" 27 print "-m,--sysmem=(base,size): System Memory region" 28 print "-f,--fv=(base,size): Firmware region" 29 print "-r,--rom=(base,size): ROM region" 30 31verbose = False 32load_all = False 33report_file = None 34regions = [] 35opts,args = getopt.getopt(sys.argv[1:], "hvar:vm:vr:vf:v", ["help","verbose","all","report=","sysmem=","rom=","fv="]) 36if (opts is None) or (not opts): 37 report_file = '../../../report.log' 38else: 39 region_reg = re.compile("\((.*),(.*)\)") 40 base_reg = re.compile("(.*)") 41 42 for o,a in opts: 43 region_type = None 44 regex = None 45 m = None 46 if o in ("-h","--help"): 47 usage() 48 sys.exit() 49 elif o in ("-v","--verbose"): 50 verbose = True 51 elif o in ("-a","--all"): 52 load_all = True 53 elif o in ("-l","--report"): 54 report_file = a 55 elif o in ("-m","--sysmem"): 56 region_type = edk2_debugger.ArmPlatformDebugger.REGION_TYPE_SYSMEM 57 regex = region_reg 58 elif o in ("-f","--fv"): 59 region_type = edk2_debugger.ArmPlatformDebugger.REGION_TYPE_FV 60 regex = region_reg 61 elif o in ("-r","--rom"): 62 region_type = edk2_debugger.ArmPlatformDebugger.REGION_TYPE_ROM 63 regex = region_reg 64 else: 65 assert False, "Unhandled option (%s)" % o 66 67 if region_type: 68 m = regex.match(a) 69 if m: 70 if regex.groups == 1: 71 regions.append((region_type,int(m.group(1),0),0)) 72 else: 73 regions.append((region_type,int(m.group(1),0),int(m.group(2),0))) 74 else: 75 if regex.groups == 1: 76 raise Exception('cmd_load_symbols', "Expect a base address") 77 else: 78 raise Exception('cmd_load_symbols', "Expect a region format as (base,size)") 79 80# Debugger object for accessing the debugger 81debugger = Debugger() 82 83# Initialisation commands 84ec = debugger.getExecutionContext(0) 85ec.getExecutionService().stop() 86ec.getExecutionService().waitForStop() 87# in case the execution context reference is out of date 88ec = debugger.getExecutionContext(0) 89 90try: 91 armplatform_debugger = edk2_debugger.ArmPlatformDebugger(ec, report_file, regions, verbose) 92 93 if load_all: 94 armplatform_debugger.load_all_symbols() 95 else: 96 armplatform_debugger.load_current_symbols() 97except IOError, (ErrorNumber, ErrorMessage): 98 print "Error: %s" % ErrorMessage 99except Exception, (ErrorClass, ErrorMessage): 100 print "Error(%s): %s" % (ErrorClass, ErrorMessage) 101except DebugException, de: 102 print "DebugError: %s" % (de.getMessage()) 103