diff --git a/linux-ramdump-parser-v2/gdbmi.py b/linux-ramdump-parser-v2/gdbmi.py index e7cec1085def82405cc1794514cb00c318b8f5f2..282f48fdc8b89c6440d7f789037c9810e4e89275 100644 --- a/linux-ramdump-parser-v2/gdbmi.py +++ b/linux-ramdump-parser-v2/gdbmi.py @@ -211,7 +211,7 @@ class GdbMI(object): def get_enum_lookup_table(self, enum, upperbound): """Return a table translating enum values to human readable strings.""" table = [] - for i in xrange(0, upperbound): + for i in range(0, upperbound): result = self._run_for_first( 'print ((enum {0}){1})'.format(enum, i)) parts = result.split(' ') @@ -239,18 +239,18 @@ class GdbMI(object): if __name__ == '__main__': if len(sys.argv) != 3: - print 'Usage: gdbmi.py gdb_path elf' + print('Usage: gdbmi.py gdb_path elf') sys.exit(1) gdb_path, elf = sys.argv[1:] with GdbMI(gdb_path, elf) as g: - print 'GDB Version:', g.version() - print 'ion_buffer.heap offset:', g.field_offset('struct ion_buffer', 'heap') - print 'atomic_t.counter offset:', g.field_offset('atomic_t', 'counter') - print 'sizeof(struct ion_buffer):', g.sizeof('struct ion_buffer') + print('GDB Version: ' + g.version()) + print('ion_buffer.heap offset: ' + str(g.field_offset('struct ion_buffer', 'heap'))) + print('atomic_t.counter offset: ' + str(g.field_offset('atomic_t', 'counter'))) + print('sizeof(struct ion_buffer): ' + str(g.sizeof('struct ion_buffer'))) addr = g.address_of('kernel_config_data') - print 'address of kernel_config_data:', hex(addr) + print('address of kernel_config_data: ' + hex(addr)) symbol = g.get_symbol_info(addr) - print 'symbol at', hex(addr), ':', symbol.symbol, \ - 'which is in section', symbol.section + print('symbol at ' + hex(addr) + ' : ' + symbol.symbol + \ + ' which is in section ' + symbol.section) diff --git a/linux-ramdump-parser-v2/lpaeiommulib.py b/linux-ramdump-parser-v2/lpaeiommulib.py index 85edcd967338b4cb6745f748e863e52b6e5d29ca..64fe5eed0f7c2b64109083697528c8502b742df1 100644 --- a/linux-ramdump-parser-v2/lpaeiommulib.py +++ b/linux-ramdump-parser-v2/lpaeiommulib.py @@ -9,7 +9,10 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -from collections import OrderedDict +try: + from collections import OrderedDict +except ImportError: + from ordereddict import OrderedDict from print_out import print_out_str from register import Register diff --git a/linux-ramdump-parser-v2/mmu.py b/linux-ramdump-parser-v2/mmu.py index fad2b3159791ccc8737e871f4e66836fbba8559d..383272ce3289ce4d4b862a3cf9a13aadba01f06b 100644 --- a/linux-ramdump-parser-v2/mmu.py +++ b/linux-ramdump-parser-v2/mmu.py @@ -585,7 +585,7 @@ class Armv8MMU(MMU): tl_index=(20,12), page_index=(11,0)) - fl_desc = self.do_fl_sl_level_lookup(self.ttbr, virt_r.fl_index, 12, 30) + fl_desc = self.do_fl_sl_level_lookup(self.ttbr, virt_r.fl_index, 12, 30) if fl_desc.dtype == Armv8MMU.DESCRIPTOR_BLOCK: return self.fl_block_desc_2_phys(fl_desc, virt_r) @@ -598,7 +598,7 @@ class Armv8MMU(MMU): except: return None - if sl_desc.dtype == Armv8MMU.DESCRIPTOR_BLOCK: + if sl_desc.dtype == Armv8MMU.DESCRIPTOR_BLOCK: r = self.sl_block_desc_2_phys(sl_desc, virt_r) return r diff --git a/linux-ramdump-parser-v2/ramparse.py b/linux-ramdump-parser-v2/ramparse.py index 859308df2f58d5925940713abb656c414e72b06a..1283458c76130259e4031b91550f8d7ae7d0b588 100755 --- a/linux-ramdump-parser-v2/ramparse.py +++ b/linux-ramdump-parser-v2/ramparse.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python2 # Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. # @@ -11,6 +11,13 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. +# this script requires python2. However, we'd like to be able to print +# an informative message to a user who might be unknowingly running +# python3 so we can't allow any python2 print statements to sneak in +# since they result in syntax errors in python3. By importing +# print_function we are requiring ourselves to use the python3 syntax. +from __future__ import print_function + import sys import os import re @@ -23,6 +30,27 @@ from print_out import print_out_str, set_outfile, print_out_section # Please update version when something is changed!' VERSION = '2.0' +# quick check of system requirements: +major, minor = sys.version_info[:2] +if major != 2: + print("This script requires python2 to run!\n") + print("You seem to be running: " + sys.version) + print() + sys.exit(1) +if minor != 7 and '--force-26' not in sys.argv: + from textwrap import dedent + print(dedent(""" + Warning! This script is developed and tested with Python 2.7. + You might be able to get things working on 2.6 by installing + a few dependencies (most notably, OrderedDict [1]) + and then passing --force-26 to bypass this version check, but + the recommended and supported approach is to install python2.7. + + [1] https://pypi.python.org/pypi/ordereddict""")) + sys.exit(1) +if '--force-26' in sys.argv: + sys.argv.remove('--force-26') + def parse_ram_file(option, opt_str, value, parser): a = getattr(parser.values, option.dest) @@ -223,8 +251,8 @@ if __name__ == '__main__': arm64=options.arm64) if options.shell or options.classic_shell: - print "Entering interactive shell mode." - print "The RamDump instance is available in the `dump' variable\n" + print("Entering interactive shell mode.") + print("The RamDump instance is available in the `dump' variable\n") do_fallback = options.classic_shell if not do_fallback: try: diff --git a/linux-ramdump-parser-v2/sizes.py b/linux-ramdump-parser-v2/sizes.py index db65602d81345e396284b9f9f06036f776a1f039..0f1a937f7ce6124ab8d26504692949943fd1309a 100644 --- a/linux-ramdump-parser-v2/sizes.py +++ b/linux-ramdump-parser-v2/sizes.py @@ -27,7 +27,10 @@ working with common sizes. """ import math -from collections import OrderedDict +try: + from collections import OrderedDict +except ImportError: + from ordereddict import OrderedDict SZ_1 = 0x00000001 SZ_2 = 0x00000002