Home | History | Annotate | Download | only in Ds5
      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 
     13 from arm_ds.debugger_v1 import Debugger
     14 from arm_ds.debugger_v1 import DebugException
     15 
     16 import re, sys, getopt
     17 
     18 import edk2_debugger
     19 
     20 # Reload external classes

     21 reload(edk2_debugger)
     22 
     23 def 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 
     31 verbose = False
     32 load_all = False
     33 report_file = None
     34 regions = []
     35 opts,args = getopt.getopt(sys.argv[1:], "hvar:vm:vr:vf:v", ["help","verbose","all","report=","sysmem=","rom=","fv="])
     36 if (opts is None) or (not opts):
     37     report_file = '../../../report.log'
     38 else:
     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

     81 debugger = Debugger()
     82 
     83 # Initialisation commands

     84 ec = debugger.getExecutionContext(0)
     85 ec.getExecutionService().stop()
     86 ec.getExecutionService().waitForStop()
     87 # in case the execution context reference is out of date

     88 ec = debugger.getExecutionContext(0)
     89 
     90 try:
     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()
     97 except IOError, (ErrorNumber, ErrorMessage):
     98     print "Error: %s" % ErrorMessage
     99 except Exception, (ErrorClass, ErrorMessage):
    100     print "Error(%s): %s" % (ErrorClass, ErrorMessage)
    101 except DebugException, de:
    102     print "DebugError: %s" % (de.getMessage())
    103