diff options
Diffstat (limited to 'gdb/python/lib')
-rw-r--r-- | gdb/python/lib/gdb/__init__.py | 35 | ||||
-rw-r--r-- | gdb/python/lib/gdb/command/explore.py | 32 | ||||
-rw-r--r-- | gdb/python/lib/gdb/command/pretty_printers.py | 20 | ||||
-rw-r--r-- | gdb/python/lib/gdb/command/type_printers.py | 14 | ||||
-rw-r--r-- | gdb/python/lib/gdb/printing.py | 5 | ||||
-rw-r--r-- | gdb/python/lib/gdb/prompt.py | 3 |
6 files changed, 54 insertions, 55 deletions
diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py index 0671526..4790420 100644 --- a/gdb/python/lib/gdb/__init__.py +++ b/gdb/python/lib/gdb/__init__.py @@ -18,9 +18,17 @@ import os import sys import _gdb +if sys.version_info[0] > 2: + # Python 3 moved "reload" + from imp import reload + from _gdb import * -class GdbOutputFile: +class _GdbFile (object): + # These two are needed in Python 3 + encoding = "UTF-8" + errors = "strict" + def close(self): # Do nothing. return None @@ -28,9 +36,6 @@ class GdbOutputFile: def isatty(self): return False - def write(self, s): - write(s, stream=STDOUT) - def writelines(self, iterable): for line in iterable: self.write(line) @@ -38,26 +43,16 @@ class GdbOutputFile: def flush(self): flush() -sys.stdout = GdbOutputFile() - -class GdbOutputErrorFile: - def close(self): - # Do nothing. - return None +class GdbOutputFile (_GdbFile): + def write(self, s): + write(s, stream=STDOUT) - def isatty(self): - return False +sys.stdout = GdbOutputFile() +class GdbOutputErrorFile (_GdbFile): def write(self, s): write(s, stream=STDERR) - def writelines(self, iterable): - for line in iterable: - self.write(line) - - def flush(self): - flush() - sys.stderr = GdbOutputErrorFile() # Default prompt hook does nothing. @@ -107,7 +102,7 @@ def auto_load_packages(): else: __import__(modname) except: - print >> sys.stderr, traceback.format_exc() + sys.stderr.write (traceback.format_exc() + "\n") auto_load_packages() diff --git a/gdb/python/lib/gdb/command/explore.py b/gdb/python/lib/gdb/command/explore.py index aad3671..e6f762f 100644 --- a/gdb/python/lib/gdb/command/explore.py +++ b/gdb/python/lib/gdb/command/explore.py @@ -17,7 +17,12 @@ """Implementation of the GDB 'explore' command using the GDB Python API.""" import gdb +import sys +if sys.version_info[0] > 2: + # Python 3 renamed raw_input to input + raw_input = input + class Explorer(object): """Internal class which invokes other explorers.""" @@ -155,7 +160,7 @@ class Explorer(object): """A utility function which prints that the current exploration session is returning to the parent value. Useful when exploring values. """ - print "\nReturning to parent value...\n" + print ("\nReturning to parent value...\n") @staticmethod def return_to_parent_value_prompt(): @@ -170,7 +175,7 @@ class Explorer(object): """A utility function which prints that the current exploration session is returning to the enclosing type. Useful when exploring types. """ - print "\nReturning to enclosing type...\n" + print ("\nReturning to enclosing type...\n") @staticmethod def return_to_enclosing_type_prompt(): @@ -192,7 +197,7 @@ class ScalarExplorer(object): """ print ("'%s' is a scalar value of type '%s'." % (expr, value.type)) - print "%s = %s" % (expr, str(value)) + print ("%s = %s" % (expr, str(value))) if is_child: Explorer.return_to_parent_value_prompt() @@ -211,13 +216,13 @@ class ScalarExplorer(object): print ("%s is of an enumerated type '%s'." % (name, str(datatype))) else: - print "'%s' is an enumerated type." % name + print ("'%s' is an enumerated type." % name) else: if is_child: print ("%s is of a scalar type '%s'." % (name, str(datatype))) else: - print "'%s' is a scalar type." % name + print ("'%s' is a scalar type." % name) if is_child: Explorer.return_to_enclosing_type_prompt() @@ -268,7 +273,7 @@ class PointerExplorer(object): try: str(element) except gdb.MemoryError: - print "Cannot read value at index %d." % index + print ("Cannot read value at index %d." % index) continue Explorer.explore_expr(element_expr, element, True) return False @@ -338,7 +343,7 @@ class ArrayExplorer(object): element = value[index] str(element) except gdb.MemoryError: - print "Cannot read value at index %d." % index + print ("Cannot read value at index %d." % index) raw_input("Press enter to continue... ") return True @@ -352,7 +357,7 @@ class ArrayExplorer(object): See Explorer.explore_type for more information. """ target_type = datatype.target() - print "%s is an array of '%s'." % (name, str(target_type)) + print ("%s is an array of '%s'." % (name, str(target_type))) Explorer.explore_type("the array element of %s" % name, target_type, is_child) @@ -371,9 +376,8 @@ class CompoundExplorer(object): if max_field_name_length < len(pair[0]): max_field_name_length = len(pair[0]) - format_str = " {0:>%d} = {1}" % max_field_name_length for pair in print_list: - print format_str.format(pair[0], pair[1]) + print (" %*s = %s" % (max_field_name_length, pair[0], pair[1])) @staticmethod def _get_real_field_count(fields): @@ -447,7 +451,7 @@ class CompoundExplorer(object): print_list.append((field.name, literal_value)) CompoundExplorer._print_fields(print_list) - print "" + print ("") if has_explorable_fields: choice = raw_input("Enter the field number of choice: ") @@ -484,7 +488,7 @@ class CompoundExplorer(object): (name, type_desc, str(datatype))) Explorer.return_to_enclosing_type_prompt() else: - print "'%s' is a %s with no fields." % (name, type_desc) + print ("'%s' is a %s with no fields." % (name, type_desc)) return False if is_child: @@ -515,7 +519,7 @@ class CompoundExplorer(object): current_choice = current_choice + 1 CompoundExplorer._print_fields(print_list) - print "" + print ("") if len(choice_to_compound_field_map) > 0: choice = raw_input("Enter the field number of choice: ") @@ -741,7 +745,7 @@ class ExploreTypeCommand(gdb.Command): value = ExploreUtils.get_value_from_str(arg_str) if value is not None: - print "'%s' is of type '%s'." % (arg_str, str(value.type)) + print ("'%s' is of type '%s'." % (arg_str, str(value.type))) Explorer.explore_type(str(value.type), value.type, False) raise gdb.GdbError(("'%s' is not a type or value in the current " diff --git a/gdb/python/lib/gdb/command/pretty_printers.py b/gdb/python/lib/gdb/command/pretty_printers.py index 3ae3517..bd44f5d 100644 --- a/gdb/python/lib/gdb/command/pretty_printers.py +++ b/gdb/python/lib/gdb/command/pretty_printers.py @@ -124,21 +124,17 @@ class InfoPrettyPrinter(gdb.Command): """Print a list of pretty-printers.""" # A potential enhancement is to provide an option to list printers in # "lookup order" (i.e. unsorted). - sorted_pretty_printers = copy.copy(pretty_printers) - sorted_pretty_printers.sort(lambda x, y: - cmp(self.printer_name(x), - self.printer_name(y))) + sorted_pretty_printers = sorted (copy.copy(pretty_printers), + key = self.printer_name) for printer in sorted_pretty_printers: name = self.printer_name(printer) enabled = self.enabled_string(printer) if name_re.match(name): - print " %s%s" % (name, enabled) + print (" %s%s" % (name, enabled)) if (hasattr(printer, "subprinters") and printer.subprinters is not None): - sorted_subprinters = copy.copy(printer.subprinters) - sorted_subprinters.sort(lambda x, y: - cmp(self.printer_name(x), - self.printer_name(y))) + sorted_subprinters = sorted (copy.copy(printer.subprinters), + key = self.printer_name) for subprinter in sorted_subprinters: if (not subname_re or subname_re.match(subprinter.name)): @@ -150,7 +146,7 @@ class InfoPrettyPrinter(gdb.Command): obj_name_to_match, object_re, name_re, subname_re): """Subroutine of invoke to simplify it.""" if printer_list and object_re.match(obj_name_to_match): - print title + print (title) self.list_pretty_printers(printer_list, name_re, subname_re) def invoke(self, arg, from_tty): @@ -219,7 +215,7 @@ def show_pretty_printer_enabled_summary(): We count subprinters individually. """ (enabled_count, total_count) = count_all_enabled_printers() - print "%d of %d printers enabled" % (enabled_count, total_count) + print ("%d of %d printers enabled" % (enabled_count, total_count)) def do_enable_pretty_printer_1 (pretty_printers, name_re, subname_re, flag): @@ -301,7 +297,7 @@ def do_enable_pretty_printer (arg, flag): state = "enabled" else: state = "disabled" - print "%d %s %s" % (total, pluralize("printer", total), state) + print ("%d %s %s" % (total, pluralize("printer", total), state)) # Print the total list of printers currently enabled/disabled. # This is to further assist the user in determining whether the result diff --git a/gdb/python/lib/gdb/command/type_printers.py b/gdb/python/lib/gdb/command/type_printers.py index b7d6930..207e0a9 100644 --- a/gdb/python/lib/gdb/command/type_printers.py +++ b/gdb/python/lib/gdb/command/type_printers.py @@ -33,29 +33,29 @@ class InfoTypePrinter(gdb.Command): """Print a list of type printers.""" # A potential enhancement is to provide an option to list printers in # "lookup order" (i.e. unsorted). - sorted_type_printers = copy.copy(type_printers) - sorted_type_printers.sort(lambda x, y: cmp(x.name, y.name)) + sorted_type_printers = sorted (copy.copy(type_printers), + key = lambda x: x.name) for printer in sorted_type_printers: if printer.enabled: enabled = '' else: enabled = " [disabled]" - print " %s%s" % (printer.name, enabled) + print (" %s%s" % (printer.name, enabled)) def invoke(self, arg, from_tty): """GDB calls this to perform the command.""" sep = '' for objfile in gdb.objfiles(): if objfile.type_printers: - print "%sType printers for %s:" % (sep, objfile.name) + print ("%sType printers for %s:" % (sep, objfile.name)) self.list_type_printers(objfile.type_printers) sep = '\n' if gdb.current_progspace().type_printers: - print "%sType printers for program space:" % sep + print ("%sType printers for program space:" % sep) self.list_type_printers(gdb.current_progspace().type_printers) sep = '\n' if gdb.type_printers: - print "%sGlobal type printers:" % sep + print ("%sGlobal type printers:" % sep) self.list_type_printers(gdb.type_printers) class _EnableOrDisableCommand(gdb.Command): @@ -83,7 +83,7 @@ class _EnableOrDisableCommand(gdb.Command): if self.set_some(name, gdb.type_printers): ok = True if not ok: - print "No type printer named '%s'" % name + print ("No type printer named '%s'" % name) def add_some(self, result, word, printers): for p in printers: diff --git a/gdb/python/lib/gdb/printing.py b/gdb/python/lib/gdb/printing.py index b4e798d..13f9c42 100644 --- a/gdb/python/lib/gdb/printing.py +++ b/gdb/python/lib/gdb/printing.py @@ -19,7 +19,12 @@ import gdb import gdb.types import re +import sys +if sys.version_info[0] > 2: + # Python 3 removed basestring and long + basestring = str + long = int class PrettyPrinter(object): """A basic pretty-printer. diff --git a/gdb/python/lib/gdb/prompt.py b/gdb/python/lib/gdb/prompt.py index 1f49b54..be20131 100644 --- a/gdb/python/lib/gdb/prompt.py +++ b/gdb/python/lib/gdb/prompt.py @@ -98,8 +98,7 @@ def prompt_help(): functions.""" result = '' - keys = prompt_substitutions.keys() - keys.sort() + keys = sorted (prompt_substitutions.keys()) for key in keys: result += ' \\%s\t%s\n' % (key, prompt_substitutions[key].__doc__) result += """ |