diff options
Diffstat (limited to 'share/gdb/python/gdb/command')
-rw-r--r-- | share/gdb/python/gdb/command/__init__.py | 16 | ||||
-rw-r--r-- | share/gdb/python/gdb/command/explore.py | 750 | ||||
-rw-r--r-- | share/gdb/python/gdb/command/frame_filters.py | 456 | ||||
-rw-r--r-- | share/gdb/python/gdb/command/pretty_printers.py | 365 | ||||
-rw-r--r-- | share/gdb/python/gdb/command/prompt.py | 65 | ||||
-rw-r--r-- | share/gdb/python/gdb/command/type_printers.py | 122 | ||||
-rw-r--r-- | share/gdb/python/gdb/command/unwinders.py | 195 | ||||
-rw-r--r-- | share/gdb/python/gdb/command/xmethods.py | 271 |
8 files changed, 0 insertions, 2240 deletions
diff --git a/share/gdb/python/gdb/command/__init__.py b/share/gdb/python/gdb/command/__init__.py deleted file mode 100644 index 9cd48f1..0000000 --- a/share/gdb/python/gdb/command/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (C) 2010-2019 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - - diff --git a/share/gdb/python/gdb/command/explore.py b/share/gdb/python/gdb/command/explore.py deleted file mode 100644 index f782a97..0000000 --- a/share/gdb/python/gdb/command/explore.py +++ /dev/null @@ -1,750 +0,0 @@ -# GDB 'explore' command. -# Copyright (C) 2012-2019 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -"""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.""" - - # This map is filled by the Explorer.init_env() function - type_code_to_explorer_map = { } - - _SCALAR_TYPE_LIST = ( - gdb.TYPE_CODE_CHAR, - gdb.TYPE_CODE_INT, - gdb.TYPE_CODE_BOOL, - gdb.TYPE_CODE_FLT, - gdb.TYPE_CODE_VOID, - gdb.TYPE_CODE_ENUM, - ) - - @staticmethod - def guard_expr(expr): - length = len(expr) - guard = False - - if expr[0] == '(' and expr[length-1] == ')': - pass - else: - i = 0 - while i < length: - c = expr[i] - if (c == '_' or ('a' <= c and c <= 'z') or - ('A' <= c and c <= 'Z') or ('0' <= c and c <= '9')): - pass - else: - guard = True - break - i += 1 - - if guard: - return "(" + expr + ")" - else: - return expr - - @staticmethod - def explore_expr(expr, value, is_child): - """Main function to explore an expression value. - - Arguments: - expr: The expression string that is being explored. - value: The gdb.Value value of the expression. - is_child: Boolean value to indicate if the expression is a child. - An expression is a child if it is derived from the main - expression entered by the user. For example, if the user - entered an expression which evaluates to a struct, then - when exploring the fields of the struct, is_child is set - to True internally. - - Returns: - No return value. - """ - type_code = value.type.code - if type_code in Explorer.type_code_to_explorer_map: - explorer_class = Explorer.type_code_to_explorer_map[type_code] - while explorer_class.explore_expr(expr, value, is_child): - pass - else: - print ("Explorer for type '%s' not yet available.\n" % - str(value.type)) - - @staticmethod - def explore_type(name, datatype, is_child): - """Main function to explore a data type. - - Arguments: - name: The string representing the path to the data type being - explored. - datatype: The gdb.Type value of the data type being explored. - is_child: Boolean value to indicate if the name is a child. - A name is a child if it is derived from the main name - entered by the user. For example, if the user entered - the name of struct type, then when exploring the fields - of the struct, is_child is set to True internally. - - Returns: - No return value. - """ - type_code = datatype.code - if type_code in Explorer.type_code_to_explorer_map: - explorer_class = Explorer.type_code_to_explorer_map[type_code] - while explorer_class.explore_type(name, datatype, is_child): - pass - else: - print ("Explorer for type '%s' not yet available.\n" % - str(datatype)) - - @staticmethod - def init_env(): - """Initializes the Explorer environment. - This function should be invoked before starting any exploration. If - invoked before an exploration, it need not be invoked for subsequent - explorations. - """ - Explorer.type_code_to_explorer_map = { - gdb.TYPE_CODE_CHAR : ScalarExplorer, - gdb.TYPE_CODE_INT : ScalarExplorer, - gdb.TYPE_CODE_BOOL : ScalarExplorer, - gdb.TYPE_CODE_FLT : ScalarExplorer, - gdb.TYPE_CODE_VOID : ScalarExplorer, - gdb.TYPE_CODE_ENUM : ScalarExplorer, - gdb.TYPE_CODE_STRUCT : CompoundExplorer, - gdb.TYPE_CODE_UNION : CompoundExplorer, - gdb.TYPE_CODE_PTR : PointerExplorer, - gdb.TYPE_CODE_REF : ReferenceExplorer, - gdb.TYPE_CODE_RVALUE_REF : ReferenceExplorer, - gdb.TYPE_CODE_TYPEDEF : TypedefExplorer, - gdb.TYPE_CODE_ARRAY : ArrayExplorer - } - - @staticmethod - def is_scalar_type(type): - """Checks whether a type is a scalar type. - A type is a scalar type of its type is - gdb.TYPE_CODE_CHAR or - gdb.TYPE_CODE_INT or - gdb.TYPE_CODE_BOOL or - gdb.TYPE_CODE_FLT or - gdb.TYPE_CODE_VOID or - gdb.TYPE_CODE_ENUM. - - Arguments: - type: The type to be checked. - - Returns: - 'True' if 'type' is a scalar type. 'False' otherwise. - """ - return type.code in Explorer._SCALAR_TYPE_LIST - - @staticmethod - def return_to_parent_value(): - """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") - - @staticmethod - def return_to_parent_value_prompt(): - """A utility function which prompts the user to press the 'enter' key - so that the exploration session can shift back to the parent value. - Useful when exploring values. - """ - raw_input("\nPress enter to return to parent value: ") - - @staticmethod - def return_to_enclosing_type(): - """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") - - @staticmethod - def return_to_enclosing_type_prompt(): - """A utility function which prompts the user to press the 'enter' key - so that the exploration session can shift back to the enclosing type. - Useful when exploring types. - """ - raw_input("\nPress enter to return to enclosing type: ") - - -class ScalarExplorer(object): - """Internal class used to explore scalar values.""" - - @staticmethod - def explore_expr(expr, value, is_child): - """Function to explore scalar values. - See Explorer.explore_expr and Explorer.is_scalar_type for more - information. - """ - print ("'%s' is a scalar value of type '%s'." % - (expr, value.type)) - print ("%s = %s" % (expr, str(value))) - - if is_child: - Explorer.return_to_parent_value_prompt() - Explorer.return_to_parent_value() - - return False - - @staticmethod - def explore_type(name, datatype, is_child): - """Function to explore scalar types. - See Explorer.explore_type and Explorer.is_scalar_type for more - information. - """ - if datatype.code == gdb.TYPE_CODE_ENUM: - if is_child: - print ("%s is of an enumerated type '%s'." % - (name, str(datatype))) - else: - 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) - - if is_child: - Explorer.return_to_enclosing_type_prompt() - Explorer.return_to_enclosing_type() - - return False - - -class PointerExplorer(object): - """Internal class used to explore pointer values.""" - - @staticmethod - def explore_expr(expr, value, is_child): - """Function to explore pointer values. - See Explorer.explore_expr for more information. - """ - print ("'%s' is a pointer to a value of type '%s'" % - (expr, str(value.type.target()))) - option = raw_input("Continue exploring it as a pointer to a single " - "value [y/n]: ") - if option == "y": - deref_value = None - try: - deref_value = value.dereference() - str(deref_value) - except gdb.MemoryError: - print ("'%s' a pointer pointing to an invalid memory " - "location." % expr) - if is_child: - Explorer.return_to_parent_value_prompt() - return False - Explorer.explore_expr("*%s" % Explorer.guard_expr(expr), - deref_value, is_child) - return False - - option = raw_input("Continue exploring it as a pointer to an " - "array [y/n]: ") - if option == "y": - while True: - index = 0 - try: - index = int(raw_input("Enter the index of the element you " - "want to explore in '%s': " % expr)) - except ValueError: - break - element_expr = "%s[%d]" % (Explorer.guard_expr(expr), index) - element = value[index] - try: - str(element) - except gdb.MemoryError: - print ("Cannot read value at index %d." % index) - continue - Explorer.explore_expr(element_expr, element, True) - return False - - if is_child: - Explorer.return_to_parent_value() - return False - - @staticmethod - def explore_type(name, datatype, is_child): - """Function to explore pointer types. - See Explorer.explore_type for more information. - """ - target_type = datatype.target() - print ("\n%s is a pointer to a value of type '%s'." % - (name, str(target_type))) - - Explorer.explore_type("the pointee type of %s" % name, - target_type, - is_child) - return False - - -class ReferenceExplorer(object): - """Internal class used to explore reference (TYPE_CODE_REF) values.""" - - @staticmethod - def explore_expr(expr, value, is_child): - """Function to explore array values. - See Explorer.explore_expr for more information. - """ - referenced_value = value.referenced_value() - Explorer.explore_expr(expr, referenced_value, is_child) - return False - - @staticmethod - def explore_type(name, datatype, is_child): - """Function to explore pointer types. - See Explorer.explore_type for more information. - """ - target_type = datatype.target() - Explorer.explore_type(name, target_type, is_child) - return False - -class ArrayExplorer(object): - """Internal class used to explore arrays.""" - - @staticmethod - def explore_expr(expr, value, is_child): - """Function to explore array values. - See Explorer.explore_expr for more information. - """ - target_type = value.type.target() - print ("'%s' is an array of '%s'." % (expr, str(target_type))) - index = 0 - try: - index = int(raw_input("Enter the index of the element you want to " - "explore in '%s': " % expr)) - except ValueError: - if is_child: - Explorer.return_to_parent_value() - return False - - element = None - try: - element = value[index] - str(element) - except gdb.MemoryError: - print ("Cannot read value at index %d." % index) - raw_input("Press enter to continue... ") - return True - - Explorer.explore_expr("%s[%d]" % (Explorer.guard_expr(expr), index), - element, True) - return True - - @staticmethod - def explore_type(name, datatype, is_child): - """Function to explore array types. - See Explorer.explore_type for more information. - """ - target_type = datatype.target() - print ("%s is an array of '%s'." % (name, str(target_type))) - - Explorer.explore_type("the array element of %s" % name, target_type, - is_child) - return False - - -class CompoundExplorer(object): - """Internal class used to explore struct, classes and unions.""" - - @staticmethod - def _print_fields(print_list): - """Internal function which prints the fields of a struct/class/union. - """ - max_field_name_length = 0 - for pair in print_list: - if max_field_name_length < len(pair[0]): - max_field_name_length = len(pair[0]) - - for pair in print_list: - print (" %*s = %s" % (max_field_name_length, pair[0], pair[1])) - - @staticmethod - def _get_real_field_count(fields): - real_field_count = 0; - for field in fields: - if not field.artificial: - real_field_count = real_field_count + 1 - - return real_field_count - - @staticmethod - def explore_expr(expr, value, is_child): - """Function to explore structs/classes and union values. - See Explorer.explore_expr for more information. - """ - datatype = value.type - type_code = datatype.code - fields = datatype.fields() - - if type_code == gdb.TYPE_CODE_STRUCT: - type_desc = "struct/class" - else: - type_desc = "union" - - if CompoundExplorer._get_real_field_count(fields) == 0: - print ("The value of '%s' is a %s of type '%s' with no fields." % - (expr, type_desc, str(value.type))) - if is_child: - Explorer.return_to_parent_value_prompt() - return False - - print ("The value of '%s' is a %s of type '%s' with the following " - "fields:\n" % (expr, type_desc, str(value.type))) - - has_explorable_fields = False - choice_to_compound_field_map = { } - current_choice = 0 - print_list = [ ] - for field in fields: - if field.artificial: - continue - field_full_name = Explorer.guard_expr(expr) + "." + field.name - if field.is_base_class: - field_value = value.cast(field.type) - else: - field_value = value[field.name] - literal_value = "" - if type_code == gdb.TYPE_CODE_UNION: - literal_value = ("<Enter %d to explore this field of type " - "'%s'>" % (current_choice, str(field.type))) - has_explorable_fields = True - else: - if Explorer.is_scalar_type(field.type): - literal_value = ("%s .. (Value of type '%s')" % - (str(field_value), str(field.type))) - else: - if field.is_base_class: - field_desc = "base class" - else: - field_desc = "field" - literal_value = ("<Enter %d to explore this %s of type " - "'%s'>" % - (current_choice, field_desc, - str(field.type))) - has_explorable_fields = True - - choice_to_compound_field_map[str(current_choice)] = ( - field_full_name, field_value) - current_choice = current_choice + 1 - - print_list.append((field.name, literal_value)) - - CompoundExplorer._print_fields(print_list) - print ("") - - if has_explorable_fields: - choice = raw_input("Enter the field number of choice: ") - if choice in choice_to_compound_field_map: - Explorer.explore_expr(choice_to_compound_field_map[choice][0], - choice_to_compound_field_map[choice][1], - True) - return True - else: - if is_child: - Explorer.return_to_parent_value() - else: - if is_child: - Explorer.return_to_parent_value_prompt() - - return False - - @staticmethod - def explore_type(name, datatype, is_child): - """Function to explore struct/class and union types. - See Explorer.explore_type for more information. - """ - type_code = datatype.code - type_desc = "" - if type_code == gdb.TYPE_CODE_STRUCT: - type_desc = "struct/class" - else: - type_desc = "union" - - fields = datatype.fields() - if CompoundExplorer._get_real_field_count(fields) == 0: - if is_child: - print ("%s is a %s of type '%s' with no fields." % - (name, type_desc, str(datatype))) - Explorer.return_to_enclosing_type_prompt() - else: - print ("'%s' is a %s with no fields." % (name, type_desc)) - return False - - if is_child: - print ("%s is a %s of type '%s' " - "with the following fields:\n" % - (name, type_desc, str(datatype))) - else: - print ("'%s' is a %s with the following " - "fields:\n" % - (name, type_desc)) - - has_explorable_fields = False - current_choice = 0 - choice_to_compound_field_map = { } - print_list = [ ] - for field in fields: - if field.artificial: - continue - if field.is_base_class: - field_desc = "base class" - else: - field_desc = "field" - rhs = ("<Enter %d to explore this %s of type '%s'>" % - (current_choice, field_desc, str(field.type))) - print_list.append((field.name, rhs)) - choice_to_compound_field_map[str(current_choice)] = ( - field.name, field.type, field_desc) - current_choice = current_choice + 1 - - CompoundExplorer._print_fields(print_list) - print ("") - - if len(choice_to_compound_field_map) > 0: - choice = raw_input("Enter the field number of choice: ") - if choice in choice_to_compound_field_map: - if is_child: - new_name = ("%s '%s' of %s" % - (choice_to_compound_field_map[choice][2], - choice_to_compound_field_map[choice][0], - name)) - else: - new_name = ("%s '%s' of '%s'" % - (choice_to_compound_field_map[choice][2], - choice_to_compound_field_map[choice][0], - name)) - Explorer.explore_type(new_name, - choice_to_compound_field_map[choice][1], True) - return True - else: - if is_child: - Explorer.return_to_enclosing_type() - else: - if is_child: - Explorer.return_to_enclosing_type_prompt() - - return False - - -class TypedefExplorer(object): - """Internal class used to explore values whose type is a typedef.""" - - @staticmethod - def explore_expr(expr, value, is_child): - """Function to explore typedef values. - See Explorer.explore_expr for more information. - """ - actual_type = value.type.strip_typedefs() - print ("The value of '%s' is of type '%s' " - "which is a typedef of type '%s'" % - (expr, str(value.type), str(actual_type))) - - Explorer.explore_expr(expr, value.cast(actual_type), is_child) - return False - - @staticmethod - def explore_type(name, datatype, is_child): - """Function to explore typedef types. - See Explorer.explore_type for more information. - """ - actual_type = datatype.strip_typedefs() - if is_child: - print ("The type of %s is a typedef of type '%s'." % - (name, str(actual_type))) - else: - print ("The type '%s' is a typedef of type '%s'." % - (name, str(actual_type))) - - Explorer.explore_type(name, actual_type, is_child) - return False - - -class ExploreUtils(object): - """Internal class which provides utilities for the main command classes.""" - - @staticmethod - def check_args(name, arg_str): - """Utility to check if adequate number of arguments are passed to an - explore command. - - Arguments: - name: The name of the explore command. - arg_str: The argument string passed to the explore command. - - Returns: - True if adequate arguments are passed, false otherwise. - - Raises: - gdb.GdbError if adequate arguments are not passed. - """ - if len(arg_str) < 1: - raise gdb.GdbError("ERROR: '%s' requires an argument." - % name) - return False - else: - return True - - @staticmethod - def get_type_from_str(type_str): - """A utility function to deduce the gdb.Type value from a string - representing the type. - - Arguments: - type_str: The type string from which the gdb.Type value should be - deduced. - - Returns: - The deduced gdb.Type value if possible, None otherwise. - """ - try: - # Assume the current language to be C/C++ and make a try. - return gdb.parse_and_eval("(%s *)0" % type_str).type.target() - except RuntimeError: - # If assumption of current language to be C/C++ was wrong, then - # lookup the type using the API. - try: - return gdb.lookup_type(type_str) - except RuntimeError: - return None - - @staticmethod - def get_value_from_str(value_str): - """A utility function to deduce the gdb.Value value from a string - representing the value. - - Arguments: - value_str: The value string from which the gdb.Value value should - be deduced. - - Returns: - The deduced gdb.Value value if possible, None otherwise. - """ - try: - return gdb.parse_and_eval(value_str) - except RuntimeError: - return None - - -class ExploreCommand(gdb.Command): - """Explore a value or a type valid in the current context. - -Usage: explore ARG - -- ARG is either a valid expression or a type name. -- At any stage of exploration, hit the return key (instead of a -choice, if any) to return to the enclosing type or value.""" - - def __init__(self): - super(ExploreCommand, self).__init__(name = "explore", - command_class = gdb.COMMAND_DATA, - prefix = True) - - def invoke(self, arg_str, from_tty): - if ExploreUtils.check_args("explore", arg_str) == False: - return - - # Check if it is a value - value = ExploreUtils.get_value_from_str(arg_str) - if value is not None: - Explorer.explore_expr(arg_str, value, False) - return - - # If it is not a value, check if it is a type - datatype = ExploreUtils.get_type_from_str(arg_str) - if datatype is not None: - Explorer.explore_type(arg_str, datatype, False) - return - - # If it is neither a value nor a type, raise an error. - raise gdb.GdbError( - ("'%s' neither evaluates to a value nor is a type " - "in the current context." % - arg_str)) - - -class ExploreValueCommand(gdb.Command): - """Explore value of an expression valid in the current context. - -Usage: explore value ARG - -- ARG is a valid expression. -- At any stage of exploration, hit the return key (instead of a -choice, if any) to return to the enclosing value.""" - - def __init__(self): - super(ExploreValueCommand, self).__init__( - name = "explore value", command_class = gdb.COMMAND_DATA) - - def invoke(self, arg_str, from_tty): - if ExploreUtils.check_args("explore value", arg_str) == False: - return - - value = ExploreUtils.get_value_from_str(arg_str) - if value is None: - raise gdb.GdbError( - (" '%s' does not evaluate to a value in the current " - "context." % - arg_str)) - return - - Explorer.explore_expr(arg_str, value, False) - - -class ExploreTypeCommand(gdb.Command): - """Explore a type or the type of an expression. - -Usage: explore type ARG - -- ARG is a valid expression or a type name. -- At any stage of exploration, hit the return key (instead of a -choice, if any) to return to the enclosing type.""" - - def __init__(self): - super(ExploreTypeCommand, self).__init__( - name = "explore type", command_class = gdb.COMMAND_DATA) - - def invoke(self, arg_str, from_tty): - if ExploreUtils.check_args("explore type", arg_str) == False: - return - - datatype = ExploreUtils.get_type_from_str(arg_str) - if datatype is not None: - Explorer.explore_type(arg_str, datatype, False) - return - - value = ExploreUtils.get_value_from_str(arg_str) - if value is not None: - print ("'%s' is of type '%s'." % (arg_str, str(value.type))) - Explorer.explore_type(str(value.type), value.type, False) - return - - raise gdb.GdbError(("'%s' is not a type or value in the current " - "context." % arg_str)) - - -Explorer.init_env() - -ExploreCommand() -ExploreValueCommand() -ExploreTypeCommand() diff --git a/share/gdb/python/gdb/command/frame_filters.py b/share/gdb/python/gdb/command/frame_filters.py deleted file mode 100644 index 9d28f84..0000000 --- a/share/gdb/python/gdb/command/frame_filters.py +++ /dev/null @@ -1,456 +0,0 @@ -# Frame-filter commands. -# Copyright (C) 2013-2019 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -"""GDB commands for working with frame-filters.""" - -import sys -import gdb -import copy -from gdb.FrameIterator import FrameIterator -from gdb.FrameDecorator import FrameDecorator -import gdb.frames -import itertools - -# GDB Commands. -class SetFilterPrefixCmd(gdb.Command): - """Prefix command for 'set' frame-filter related operations.""" - - def __init__(self): - super(SetFilterPrefixCmd, self).__init__("set frame-filter", - gdb.COMMAND_OBSCURE, - gdb.COMPLETE_NONE, True) - -class ShowFilterPrefixCmd(gdb.Command): - """Prefix command for 'show' frame-filter related operations.""" - def __init__(self): - super(ShowFilterPrefixCmd, self).__init__("show frame-filter", - gdb.COMMAND_OBSCURE, - gdb.COMPLETE_NONE, True) -class InfoFrameFilter(gdb.Command): - """List all registered Python frame-filters. - -Usage: info frame-filters""" - - def __init__(self): - super(InfoFrameFilter, self).__init__("info frame-filter", - gdb.COMMAND_DATA) - @staticmethod - def enabled_string(state): - """Return "Yes" if filter is enabled, otherwise "No".""" - if state: - return "Yes" - else: - return "No" - - def print_list(self, title, frame_filters, blank_line): - sorted_frame_filters = sorted(frame_filters.items(), - key=lambda i: gdb.frames.get_priority(i[1]), - reverse=True) - - if len(sorted_frame_filters) == 0: - return 0 - - print(title) - print(" Priority Enabled Name") - for frame_filter in sorted_frame_filters: - name = frame_filter[0] - try: - priority = '{:<8}'.format( - str(gdb.frames.get_priority(frame_filter[1]))) - enabled = '{:<7}'.format( - self.enabled_string(gdb.frames.get_enabled(frame_filter[1]))) - print(" %s %s %s" % (priority, enabled, name)) - except Exception: - e = sys.exc_info()[1] - print(" Error printing filter '"+name+"': "+str(e)) - if blank_line: - print("") - return 1 - - def invoke(self, arg, from_tty): - any_printed = self.print_list("global frame-filters:", gdb.frame_filters, True) - - cp = gdb.current_progspace() - any_printed += self.print_list("progspace %s frame-filters:" % cp.filename, - cp.frame_filters, True) - - for objfile in gdb.objfiles(): - any_printed += self.print_list("objfile %s frame-filters:" % objfile.filename, - objfile.frame_filters, False) - - if any_printed == 0: - print ("No frame filters.") - -# Internal enable/disable functions. - -def _enable_parse_arg(cmd_name, arg): - """ Internal worker function to take an argument from - enable/disable and return a tuple of arguments. - - Arguments: - cmd_name: Name of the command invoking this function. - args: The argument as a string. - - Returns: - A tuple containing the dictionary, and the argument, or just - the dictionary in the case of "all". - """ - - argv = gdb.string_to_argv(arg); - argc = len(argv) - if argc == 0: - raise gdb.GdbError(cmd_name + " requires an argument") - if argv[0] == "all": - if argc > 1: - raise gdb.GdbError(cmd_name + ": with 'all' " \ - "you may not specify a filter.") - elif argc != 2: - raise gdb.GdbError(cmd_name + " takes exactly two arguments.") - - return argv - -def _do_enable_frame_filter(command_tuple, flag): - """Worker for enabling/disabling frame_filters. - - Arguments: - command_type: A tuple with the first element being the - frame filter dictionary, and the second being - the frame filter name. - flag: True for Enable, False for Disable. - """ - - list_op = command_tuple[0] - op_list = gdb.frames.return_list(list_op) - - if list_op == "all": - for item in op_list: - gdb.frames.set_enabled(item, flag) - else: - frame_filter = command_tuple[1] - try: - ff = op_list[frame_filter] - except KeyError: - msg = "frame-filter '" + str(frame_filter) + "' not found." - raise gdb.GdbError(msg) - - gdb.frames.set_enabled(ff, flag) - -def _complete_frame_filter_list(text, word, all_flag): - """Worker for frame filter dictionary name completion. - - Arguments: - text: The full text of the command line. - word: The most recent word of the command line. - all_flag: Whether to include the word "all" in completion. - - Returns: - A list of suggested frame filter dictionary name completions - from text/word analysis. This list can be empty when there - are no suggestions for completion. - """ - if all_flag == True: - filter_locations = ["all", "global", "progspace"] - else: - filter_locations = ["global", "progspace"] - for objfile in gdb.objfiles(): - filter_locations.append(objfile.filename) - - # If the user just asked for completions with no completion - # hints, just return all the frame filter dictionaries we know - # about. - if (text == ""): - return filter_locations - - # Otherwise filter on what we know. - flist = filter(lambda x,y=text:x.startswith(y), filter_locations) - - # If we only have one completion, complete it and return it. - if len(flist) == 1: - flist[0] = flist[0][len(text)-len(word):] - - # Otherwise, return an empty list, or a list of frame filter - # dictionaries that the previous filter operation returned. - return flist - -def _complete_frame_filter_name(word, printer_dict): - """Worker for frame filter name completion. - - Arguments: - - word: The most recent word of the command line. - - printer_dict: The frame filter dictionary to search for frame - filter name completions. - - Returns: A list of suggested frame filter name completions - from word analysis of the frame filter dictionary. This list - can be empty when there are no suggestions for completion. - """ - - printer_keys = printer_dict.keys() - if (word == ""): - return printer_keys - - flist = filter(lambda x,y=word:x.startswith(y), printer_keys) - return flist - -class EnableFrameFilter(gdb.Command): - """GDB command to enable the specified frame-filter. - -Usage: enable frame-filter DICTIONARY [NAME] - -DICTIONARY is the name of the frame filter dictionary on which to -operate. If dictionary is set to "all", perform operations on all -dictionaries. Named dictionaries are: "global" for the global -frame filter dictionary, "progspace" for the program space's frame -filter dictionary. If either all, or the two named dictionaries -are not specified, the dictionary name is assumed to be the name -of an "objfile" -- a shared library or an executable. - -NAME matches the name of the frame-filter to operate on.""" - def __init__(self): - super(EnableFrameFilter, self).__init__("enable frame-filter", - gdb.COMMAND_DATA) - def complete(self, text, word): - """Completion function for both frame filter dictionary, and - frame filter name.""" - if text.count(" ") == 0: - return _complete_frame_filter_list(text, word, True) - else: - printer_list = gdb.frames.return_list(text.split()[0].rstrip()) - return _complete_frame_filter_name(word, printer_list) - - def invoke(self, arg, from_tty): - command_tuple = _enable_parse_arg("enable frame-filter", arg) - _do_enable_frame_filter(command_tuple, True) - - -class DisableFrameFilter(gdb.Command): - """GDB command to disable the specified frame-filter. - -Usage: disable frame-filter DICTIONARY [NAME] - -DICTIONARY is the name of the frame filter dictionary on which to -operate. If dictionary is set to "all", perform operations on all -dictionaries. Named dictionaries are: "global" for the global -frame filter dictionary, "progspace" for the program space's frame -filter dictionary. If either all, or the two named dictionaries -are not specified, the dictionary name is assumed to be the name -of an "objfile" -- a shared library or an executable. - -NAME matches the name of the frame-filter to operate on.""" - def __init__(self): - super(DisableFrameFilter, self).__init__("disable frame-filter", - gdb.COMMAND_DATA) - - def complete(self, text, word): - """Completion function for both frame filter dictionary, and - frame filter name.""" - if text.count(" ") == 0: - return _complete_frame_filter_list(text, word, True) - else: - printer_list = gdb.frames.return_list(text.split()[0].rstrip()) - return _complete_frame_filter_name(word, printer_list) - - def invoke(self, arg, from_tty): - command_tuple = _enable_parse_arg("disable frame-filter", arg) - _do_enable_frame_filter(command_tuple, False) - -class SetFrameFilterPriority(gdb.Command): - """GDB command to set the priority of the specified frame-filter. - -Usage: set frame-filter priority DICTIONARY NAME PRIORITY - -DICTIONARY is the name of the frame filter dictionary on which to -operate. Named dictionaries are: "global" for the global frame -filter dictionary, "progspace" for the program space's framefilter -dictionary. If either of these two are not specified, the -dictionary name is assumed to be the name of an "objfile" -- a -shared library or an executable. - -NAME matches the name of the frame filter to operate on. - -PRIORITY is the an integer to assign the new priority to the frame -filter.""" - - def __init__(self): - super(SetFrameFilterPriority, self).__init__("set frame-filter " \ - "priority", - gdb.COMMAND_DATA) - - def _parse_pri_arg(self, arg): - """Internal worker to parse a priority from a tuple. - - Arguments: - arg: Tuple which contains the arguments from the command. - - Returns: - A tuple containing the dictionary, name and priority from - the arguments. - - Raises: - gdb.GdbError: An error parsing the arguments. - """ - - argv = gdb.string_to_argv(arg); - argc = len(argv) - if argc != 3: - print("set frame-filter priority " \ - "takes exactly three arguments.") - return None - - return argv - - def _set_filter_priority(self, command_tuple): - """Internal worker for setting priority of frame-filters, by - parsing a tuple and calling _set_priority with the parsed - tuple. - - Arguments: - command_tuple: Tuple which contains the arguments from the - command. - """ - - list_op = command_tuple[0] - frame_filter = command_tuple[1] - - # GDB returns arguments as a string, so convert priority to - # a number. - priority = int(command_tuple[2]) - - op_list = gdb.frames.return_list(list_op) - - try: - ff = op_list[frame_filter] - except KeyError: - msg = "frame-filter '" + str(frame_filter) + "' not found." - raise gdb.GdbError(msg) - - gdb.frames.set_priority(ff, priority) - - def complete(self, text, word): - """Completion function for both frame filter dictionary, and - frame filter name.""" - if text.count(" ") == 0: - return _complete_frame_filter_list(text, word, False) - else: - printer_list = gdb.frames.return_list(text.split()[0].rstrip()) - return _complete_frame_filter_name(word, printer_list) - - def invoke(self, arg, from_tty): - command_tuple = self._parse_pri_arg(arg) - if command_tuple != None: - self._set_filter_priority(command_tuple) - -class ShowFrameFilterPriority(gdb.Command): - """GDB command to show the priority of the specified frame-filter. - -Usage: show frame-filter priority DICTIONARY NAME - -DICTIONARY is the name of the frame filter dictionary on which to -operate. Named dictionaries are: "global" for the global frame -filter dictionary, "progspace" for the program space's framefilter -dictionary. If either of these two are not specified, the -dictionary name is assumed to be the name of an "objfile" -- a -shared library or an executable. - -NAME matches the name of the frame-filter to operate on.""" - - def __init__(self): - super(ShowFrameFilterPriority, self).__init__("show frame-filter " \ - "priority", - gdb.COMMAND_DATA) - - def _parse_pri_arg(self, arg): - """Internal worker to parse a dictionary and name from a - tuple. - - Arguments: - arg: Tuple which contains the arguments from the command. - - Returns: - A tuple containing the dictionary, and frame filter name. - - Raises: - gdb.GdbError: An error parsing the arguments. - """ - - argv = gdb.string_to_argv(arg); - argc = len(argv) - if argc != 2: - print("show frame-filter priority " \ - "takes exactly two arguments.") - return None - - return argv - - def get_filter_priority(self, frame_filters, name): - """Worker for retrieving the priority of frame_filters. - - Arguments: - frame_filters: Name of frame filter dictionary. - name: object to select printers. - - Returns: - The priority of the frame filter. - - Raises: - gdb.GdbError: A frame filter cannot be found. - """ - - op_list = gdb.frames.return_list(frame_filters) - - try: - ff = op_list[name] - except KeyError: - msg = "frame-filter '" + str(name) + "' not found." - raise gdb.GdbError(msg) - - return gdb.frames.get_priority(ff) - - def complete(self, text, word): - """Completion function for both frame filter dictionary, and - frame filter name.""" - - if text.count(" ") == 0: - return _complete_frame_filter_list(text, word, False) - else: - printer_list = frame._return_list(text.split()[0].rstrip()) - return _complete_frame_filter_name(word, printer_list) - - def invoke(self, arg, from_tty): - command_tuple = self._parse_pri_arg(arg) - if command_tuple == None: - return - filter_name = command_tuple[1] - list_name = command_tuple[0] - try: - priority = self.get_filter_priority(list_name, filter_name); - except Exception: - e = sys.exc_info()[1] - print("Error printing filter priority for '"+name+"':"+str(e)) - else: - print("Priority of filter '" + filter_name + "' in list '" \ - + list_name + "' is: " + str(priority)) - -# Register commands -SetFilterPrefixCmd() -ShowFilterPrefixCmd() -InfoFrameFilter() -EnableFrameFilter() -DisableFrameFilter() -SetFrameFilterPriority() -ShowFrameFilterPriority() diff --git a/share/gdb/python/gdb/command/pretty_printers.py b/share/gdb/python/gdb/command/pretty_printers.py deleted file mode 100644 index c1bdf68..0000000 --- a/share/gdb/python/gdb/command/pretty_printers.py +++ /dev/null @@ -1,365 +0,0 @@ -# Pretty-printer commands. -# Copyright (C) 2010-2019 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -"""GDB commands for working with pretty-printers.""" - -import copy -import gdb -import re - - -def parse_printer_regexps(arg): - """Internal utility to parse a pretty-printer command argv. - - Arguments: - arg: The arguments to the command. The format is: - [object-regexp [name-regexp]]. - Individual printers in a collection are named as - printer-name;subprinter-name. - - Returns: - The result is a 3-tuple of compiled regular expressions, except that - the resulting compiled subprinter regexp is None if not provided. - - Raises: - SyntaxError: an error processing ARG - """ - - argv = gdb.string_to_argv(arg); - argc = len(argv) - object_regexp = "" # match everything - name_regexp = "" # match everything - subname_regexp = None - if argc > 3: - raise SyntaxError("too many arguments") - if argc >= 1: - object_regexp = argv[0] - if argc >= 2: - name_subname = argv[1].split(";", 1) - name_regexp = name_subname[0] - if len(name_subname) == 2: - subname_regexp = name_subname[1] - # That re.compile raises SyntaxError was determined empirically. - # We catch it and reraise it to provide a slightly more useful - # error message for the user. - try: - object_re = re.compile(object_regexp) - except SyntaxError: - raise SyntaxError("invalid object regexp: %s" % object_regexp) - try: - name_re = re.compile (name_regexp) - except SyntaxError: - raise SyntaxError("invalid name regexp: %s" % name_regexp) - if subname_regexp is not None: - try: - subname_re = re.compile(subname_regexp) - except SyntaxError: - raise SyntaxError("invalid subname regexp: %s" % subname_regexp) - else: - subname_re = None - return(object_re, name_re, subname_re) - - -def printer_enabled_p(printer): - """Internal utility to see if printer (or subprinter) is enabled.""" - if hasattr(printer, "enabled"): - return printer.enabled - else: - return True - - -class InfoPrettyPrinter(gdb.Command): - """GDB command to list all registered pretty-printers. - -Usage: info pretty-printer [OBJECT-REGEXP [NAME-REGEXP]] - -OBJECT-REGEXP is a regular expression matching the objects to list. -Objects are "global", the program space's file, and the objfiles within -that program space. - -NAME-REGEXP matches the name of the pretty-printer. -Individual printers in a collection are named as -printer-name;subprinter-name.""" - - def __init__ (self): - super(InfoPrettyPrinter, self).__init__("info pretty-printer", - gdb.COMMAND_DATA) - - @staticmethod - def enabled_string(printer): - """Return "" if PRINTER is enabled, otherwise " [disabled]".""" - if printer_enabled_p(printer): - return "" - else: - return " [disabled]" - - @staticmethod - def printer_name(printer): - """Return the printer's name.""" - if hasattr(printer, "name"): - return printer.name - if hasattr(printer, "__name__"): - return printer.__name__ - # This "shouldn't happen", but the public API allows for - # direct additions to the pretty-printer list, and we shouldn't - # crash because someone added a bogus printer. - # Plus we want to give the user a way to list unknown printers. - return "unknown" - - def list_pretty_printers(self, pretty_printers, name_re, subname_re): - """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 = 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)) - if (hasattr(printer, "subprinters") and - printer.subprinters is not None): - 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)): - print (" %s%s" % - (subprinter.name, - self.enabled_string(subprinter))) - - def invoke1(self, title, printer_list, - 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) - self.list_pretty_printers(printer_list, name_re, subname_re) - - def invoke(self, arg, from_tty): - """GDB calls this to perform the command.""" - (object_re, name_re, subname_re) = parse_printer_regexps(arg) - self.invoke1("global pretty-printers:", gdb.pretty_printers, - "global", object_re, name_re, subname_re) - cp = gdb.current_progspace() - self.invoke1("progspace %s pretty-printers:" % cp.filename, - cp.pretty_printers, "progspace", - object_re, name_re, subname_re) - for objfile in gdb.objfiles(): - self.invoke1("objfile %s pretty-printers:" % objfile.filename, - objfile.pretty_printers, objfile.filename, - object_re, name_re, subname_re) - - -def count_enabled_printers(pretty_printers): - """Return a 2-tuple of number of enabled and total printers.""" - enabled = 0 - total = 0 - for printer in pretty_printers: - if (hasattr(printer, "subprinters") - and printer.subprinters is not None): - if printer_enabled_p(printer): - for subprinter in printer.subprinters: - if printer_enabled_p(subprinter): - enabled += 1 - total += len(printer.subprinters) - else: - if printer_enabled_p(printer): - enabled += 1 - total += 1 - return (enabled, total) - - -def count_all_enabled_printers(): - """Return a 2-tuble of the enabled state and total number of all printers. - This includes subprinters. - """ - enabled_count = 0 - total_count = 0 - (t_enabled, t_total) = count_enabled_printers(gdb.pretty_printers) - enabled_count += t_enabled - total_count += t_total - (t_enabled, t_total) = count_enabled_printers(gdb.current_progspace().pretty_printers) - enabled_count += t_enabled - total_count += t_total - for objfile in gdb.objfiles(): - (t_enabled, t_total) = count_enabled_printers(objfile.pretty_printers) - enabled_count += t_enabled - total_count += t_total - return (enabled_count, total_count) - - -def pluralize(text, n, suffix="s"): - """Return TEXT pluralized if N != 1.""" - if n != 1: - return "%s%s" % (text, suffix) - else: - return text - - -def show_pretty_printer_enabled_summary(): - """Print the number of printers enabled/disabled. - We count subprinters individually. - """ - (enabled_count, total_count) = count_all_enabled_printers() - print ("%d of %d printers enabled" % (enabled_count, total_count)) - - -def do_enable_pretty_printer_1 (pretty_printers, name_re, subname_re, flag): - """Worker for enabling/disabling pretty-printers. - - Arguments: - pretty_printers: list of pretty-printers - name_re: regular-expression object to select printers - subname_re: regular expression object to select subprinters or None - if all are affected - flag: True for Enable, False for Disable - - Returns: - The number of printers affected. - This is just for informational purposes for the user. - """ - total = 0 - for printer in pretty_printers: - if (hasattr(printer, "name") and name_re.match(printer.name) or - hasattr(printer, "__name__") and name_re.match(printer.__name__)): - if (hasattr(printer, "subprinters") and - printer.subprinters is not None): - if not subname_re: - # Only record printers that change state. - if printer_enabled_p(printer) != flag: - for subprinter in printer.subprinters: - if printer_enabled_p(subprinter): - total += 1 - # NOTE: We preserve individual subprinter settings. - printer.enabled = flag - else: - # NOTE: Whether this actually disables the subprinter - # depends on whether the printer's lookup function supports - # the "enable" API. We can only assume it does. - for subprinter in printer.subprinters: - if subname_re.match(subprinter.name): - # Only record printers that change state. - if (printer_enabled_p(printer) and - printer_enabled_p(subprinter) != flag): - total += 1 - subprinter.enabled = flag - else: - # This printer has no subprinters. - # If the user does "disable pretty-printer .* .* foo" - # should we disable printers that don't have subprinters? - # How do we apply "foo" in this context? Since there is no - # "foo" subprinter it feels like we should skip this printer. - # There's still the issue of how to handle - # "disable pretty-printer .* .* .*", and every other variation - # that can match everything. For now punt and only support - # "disable pretty-printer .* .*" (i.e. subname is elided) - # to disable everything. - if not subname_re: - # Only record printers that change state. - if printer_enabled_p(printer) != flag: - total += 1 - printer.enabled = flag - return total - - -def do_enable_pretty_printer (arg, flag): - """Internal worker for enabling/disabling pretty-printers.""" - (object_re, name_re, subname_re) = parse_printer_regexps(arg) - - total = 0 - if object_re.match("global"): - total += do_enable_pretty_printer_1(gdb.pretty_printers, - name_re, subname_re, flag) - cp = gdb.current_progspace() - if object_re.match("progspace"): - total += do_enable_pretty_printer_1(cp.pretty_printers, - name_re, subname_re, flag) - for objfile in gdb.objfiles(): - if object_re.match(objfile.filename): - total += do_enable_pretty_printer_1(objfile.pretty_printers, - name_re, subname_re, flag) - - if flag: - state = "enabled" - else: - state = "disabled" - 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 - # is expected. Since we use regexps to select it's useful. - show_pretty_printer_enabled_summary() - - -# Enable/Disable one or more pretty-printers. -# -# This is intended for use when a broken pretty-printer is shipped/installed -# and the user wants to disable that printer without disabling all the other -# printers. -# -# A useful addition would be -v (verbose) to show each printer affected. - -class EnablePrettyPrinter (gdb.Command): - """GDB command to enable the specified pretty-printer. - -Usage: enable pretty-printer [OBJECT-REGEXP [NAME-REGEXP]] - -OBJECT-REGEXP is a regular expression matching the objects to examine. -Objects are "global", the program space's file, and the objfiles within -that program space. - -NAME-REGEXP matches the name of the pretty-printer. -Individual printers in a collection are named as -printer-name;subprinter-name.""" - - def __init__(self): - super(EnablePrettyPrinter, self).__init__("enable pretty-printer", - gdb.COMMAND_DATA) - - def invoke(self, arg, from_tty): - """GDB calls this to perform the command.""" - do_enable_pretty_printer(arg, True) - - -class DisablePrettyPrinter (gdb.Command): - """GDB command to disable the specified pretty-printer. - -Usage: disable pretty-printer [OBJECT-REGEXP [NAME-REGEXP]] - -OBJECT-REGEXP is a regular expression matching the objects to examine. -Objects are "global", the program space's file, and the objfiles within -that program space. - -NAME-REGEXP matches the name of the pretty-printer. -Individual printers in a collection are named as -printer-name;subprinter-name.""" - - def __init__(self): - super(DisablePrettyPrinter, self).__init__("disable pretty-printer", - gdb.COMMAND_DATA) - - def invoke(self, arg, from_tty): - """GDB calls this to perform the command.""" - do_enable_pretty_printer(arg, False) - - -def register_pretty_printer_commands(): - """Call from a top level script to install the pretty-printer commands.""" - InfoPrettyPrinter() - EnablePrettyPrinter() - DisablePrettyPrinter() - -register_pretty_printer_commands() diff --git a/share/gdb/python/gdb/command/prompt.py b/share/gdb/python/gdb/command/prompt.py deleted file mode 100644 index 3d662a7..0000000 --- a/share/gdb/python/gdb/command/prompt.py +++ /dev/null @@ -1,65 +0,0 @@ -# Extended prompt. -# Copyright (C) 2011-2019 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -"""GDB command for working with extended prompts.""" - -import gdb -import gdb.prompt - -class _ExtendedPrompt(gdb.Parameter): - - """Set the extended prompt. - -Usage: set extended-prompt VALUE - -Substitutions are applied to VALUE to compute the real prompt. - -The currently defined substitutions are: - -""" - # Add the prompt library's dynamically generated help to the - # __doc__ string. - __doc__ = __doc__ + gdb.prompt.prompt_help() - - set_doc = "Set the extended prompt." - show_doc = "Show the extended prompt." - - def __init__(self): - super(_ExtendedPrompt, self).__init__("extended-prompt", - gdb.COMMAND_SUPPORT, - gdb.PARAM_STRING_NOESCAPE) - self.value = '' - self.hook_set = False - - def get_show_string (self, pvalue): - if self.value is not '': - return "The extended prompt is: " + self.value - else: - return "The extended prompt is not set." - - def get_set_string (self): - if self.hook_set == False: - gdb.prompt_hook = self.before_prompt_hook - self.hook_set = True - return "" - - def before_prompt_hook(self, current): - if self.value is not '': - return gdb.prompt.substitute_prompt(self.value) - else: - return None - -_ExtendedPrompt() diff --git a/share/gdb/python/gdb/command/type_printers.py b/share/gdb/python/gdb/command/type_printers.py deleted file mode 100644 index f835f03..0000000 --- a/share/gdb/python/gdb/command/type_printers.py +++ /dev/null @@ -1,122 +0,0 @@ -# Type printer commands. -# Copyright (C) 2010-2019 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -import copy -import gdb - -"""GDB commands for working with type-printers.""" - -class InfoTypePrinter(gdb.Command): - """GDB command to list all registered type-printers. - -Usage: info type-printers""" - - def __init__ (self): - super(InfoTypePrinter, self).__init__("info type-printers", - gdb.COMMAND_DATA) - - def list_type_printers(self, type_printers): - """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 = 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)) - - 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.filename)) - self.list_type_printers(objfile.type_printers) - sep = '\n' - if gdb.current_progspace().type_printers: - 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) - self.list_type_printers(gdb.type_printers) - -class _EnableOrDisableCommand(gdb.Command): - def __init__(self, setting, name): - super(_EnableOrDisableCommand, self).__init__(name, gdb.COMMAND_DATA) - self.setting = setting - - def set_some(self, name, printers): - result = False - for p in printers: - if name == p.name: - p.enabled = self.setting - result = True - return result - - def invoke(self, arg, from_tty): - """GDB calls this to perform the command.""" - for name in arg.split(): - ok = False - for objfile in gdb.objfiles(): - if self.set_some(name, objfile.type_printers): - ok = True - if self.set_some(name, gdb.current_progspace().type_printers): - ok = True - if self.set_some(name, gdb.type_printers): - ok = True - if not ok: - print ("No type printer named '%s'" % name) - - def add_some(self, result, word, printers): - for p in printers: - if p.name.startswith(word): - result.append(p.name) - - def complete(self, text, word): - result = [] - for objfile in gdb.objfiles(): - self.add_some(result, word, objfile.type_printers) - self.add_some(result, word, gdb.current_progspace().type_printers) - self.add_some(result, word, gdb.type_printers) - return result - -class EnableTypePrinter(_EnableOrDisableCommand): - """GDB command to enable the specified type printer. - -Usage: enable type-printer NAME - -NAME is the name of the type-printer.""" - - def __init__(self): - super(EnableTypePrinter, self).__init__(True, "enable type-printer") - -class DisableTypePrinter(_EnableOrDisableCommand): - """GDB command to disable the specified type-printer. - -Usage: disable type-printer NAME - -NAME is the name of the type-printer.""" - - def __init__(self): - super(DisableTypePrinter, self).__init__(False, "disable type-printer") - -InfoTypePrinter() -EnableTypePrinter() -DisableTypePrinter() diff --git a/share/gdb/python/gdb/command/unwinders.py b/share/gdb/python/gdb/command/unwinders.py deleted file mode 100644 index 028ad7d..0000000 --- a/share/gdb/python/gdb/command/unwinders.py +++ /dev/null @@ -1,195 +0,0 @@ -# Unwinder commands. -# Copyright 2015-2019 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -import gdb -import re - - -def validate_regexp(exp, idstring): - try: - return re.compile(exp) - except SyntaxError: - raise SyntaxError("Invalid %s regexp: %s." % (idstring, exp)) - - -def parse_unwinder_command_args(arg): - """Internal utility to parse unwinder command argv. - - Arguments: - arg: The arguments to the command. The format is: - [locus-regexp [name-regexp]] - - Returns: - A 2-tuple of compiled regular expressions. - - Raises: - SyntaxError: an error processing ARG - """ - - argv = gdb.string_to_argv(arg) - argc = len(argv) - if argc > 2: - raise SyntaxError("Too many arguments.") - locus_regexp = "" - name_regexp = "" - if argc >= 1: - locus_regexp = argv[0] - if argc >= 2: - name_regexp = argv[1] - return (validate_regexp(locus_regexp, "locus"), - validate_regexp(name_regexp, "unwinder")) - - -class InfoUnwinder(gdb.Command): - """GDB command to list unwinders. - -Usage: info unwinder [LOCUS-REGEXP [NAME-REGEXP]] - -LOCUS-REGEXP is a regular expression matching the location of the -unwinder. If it is omitted, all registered unwinders from all -loci are listed. A locus can be 'global', 'progspace' to list -the unwinders from the current progspace, or a regular expression -matching filenames of objfiles. - -NAME-REGEXP is a regular expression to filter unwinder names. If -this omitted for a specified locus, then all registered unwinders -in the locus are listed.""" - - def __init__(self): - super(InfoUnwinder, self).__init__("info unwinder", - gdb.COMMAND_STACK) - - def list_unwinders(self, title, unwinders, name_re): - """Lists the unwinders whose name matches regexp. - - Arguments: - title: The line to print before the list. - unwinders: The list of the unwinders. - name_re: unwinder name filter. - """ - if not unwinders: - return - print(title) - for unwinder in unwinders: - if name_re.match(unwinder.name): - print(" %s%s" % (unwinder.name, - "" if unwinder.enabled else " [disabled]")) - - def invoke(self, arg, from_tty): - locus_re, name_re = parse_unwinder_command_args(arg) - if locus_re.match("global"): - self.list_unwinders("Global:", gdb.frame_unwinders, - name_re) - if locus_re.match("progspace"): - cp = gdb.current_progspace() - self.list_unwinders("Progspace %s:" % cp.filename, - cp.frame_unwinders, name_re) - for objfile in gdb.objfiles(): - if locus_re.match(objfile.filename): - self.list_unwinders("Objfile %s:" % objfile.filename, - objfile.frame_unwinders, name_re) - - -def do_enable_unwinder1(unwinders, name_re, flag): - """Enable/disable unwinders whose names match given regex. - - Arguments: - unwinders: The list of unwinders. - name_re: Unwinder name filter. - flag: Enable/disable. - - Returns: - The number of unwinders affected. - """ - total = 0 - for unwinder in unwinders: - if name_re.match(unwinder.name): - unwinder.enabled = flag - total += 1 - return total - - -def do_enable_unwinder(arg, flag): - """Enable/disable unwinder(s).""" - (locus_re, name_re) = parse_unwinder_command_args(arg) - total = 0 - if locus_re.match("global"): - total += do_enable_unwinder1(gdb.frame_unwinders, name_re, flag) - if locus_re.match("progspace"): - total += do_enable_unwinder1(gdb.current_progspace().frame_unwinders, - name_re, flag) - for objfile in gdb.objfiles(): - if locus_re.match(objfile.filename): - total += do_enable_unwinder1(objfile.frame_unwinders, name_re, - flag) - if total > 0: - gdb.invalidate_cached_frames() - print("%d unwinder%s %s" % (total, "" if total == 1 else "s", - "enabled" if flag else "disabled")) - - -class EnableUnwinder(gdb.Command): - """GDB command to enable unwinders. - -Usage: enable unwinder [LOCUS-REGEXP [NAME-REGEXP]] - -LOCUS-REGEXP is a regular expression specifying the unwinders to -enable. It can 'global', 'progspace', or the name of an objfile -within that progspace. - -NAME_REGEXP is a regular expression to filter unwinder names. If -this omitted for a specified locus, then all registered unwinders -in the locus are affected.""" - - def __init__(self): - super(EnableUnwinder, self).__init__("enable unwinder", - gdb.COMMAND_STACK) - - def invoke(self, arg, from_tty): - """GDB calls this to perform the command.""" - do_enable_unwinder(arg, True) - - -class DisableUnwinder(gdb.Command): - """GDB command to disable the specified unwinder. - -Usage: disable unwinder [LOCUS-REGEXP [NAME-REGEXP]] - -LOCUS-REGEXP is a regular expression specifying the unwinders to -disable. It can 'global', 'progspace', or the name of an objfile -within that progspace. - -NAME_REGEXP is a regular expression to filter unwinder names. If -this omitted for a specified locus, then all registered unwinders -in the locus are affected.""" - - def __init__(self): - super(DisableUnwinder, self).__init__("disable unwinder", - gdb.COMMAND_STACK) - - def invoke(self, arg, from_tty): - """GDB calls this to perform the command.""" - do_enable_unwinder(arg, False) - - -def register_unwinder_commands(): - """Installs the unwinder commands.""" - InfoUnwinder() - EnableUnwinder() - DisableUnwinder() - - -register_unwinder_commands() diff --git a/share/gdb/python/gdb/command/xmethods.py b/share/gdb/python/gdb/command/xmethods.py deleted file mode 100644 index ea02609..0000000 --- a/share/gdb/python/gdb/command/xmethods.py +++ /dev/null @@ -1,271 +0,0 @@ -# Xmethod commands. -# Copyright 2013-2019 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -import gdb -import re - -"""GDB commands for working with xmethods.""" - - -def validate_xm_regexp(part_name, regexp): - try: - return re.compile(regexp) - except SyntaxError: - raise SyntaxError("Invalid %s regexp: %s", part_name, regexp) - - -def parse_xm_command_args(arg): - """Parses the arguments passed to a xmethod command. - - Arguments: - arg: The argument string passed to a xmethod command. - - Returns: - A 3-tuple: (<locus matching regular expression>, - <matcher matching regular expression>, - <name matching regular experession>) - """ - argv = gdb.string_to_argv(arg) - argc = len(argv) - if argc > 2: - raise SyntaxError("Too many arguments to command.") - locus_regexp = "" - matcher_name_regexp = "" - xm_name_regexp = None - if argc >= 1: - locus_regexp = argv[0] - if argc == 2: - parts = argv[1].split(";", 1) - matcher_name_regexp = parts[0] - if len(parts) > 1: - xm_name_regexp = parts[1] - if xm_name_regexp: - name_re = validate_xm_regexp("xmethod name", xm_name_regexp) - else: - name_re = None - return (validate_xm_regexp("locus", locus_regexp), - validate_xm_regexp("matcher name", matcher_name_regexp), - name_re) - - -def get_global_method_matchers(locus_re, matcher_re): - """Returns a dict of matching globally registered xmethods. - - Arguments: - locus_re: Even though only globally registered xmethods are - looked up, they will be looked up only if 'global' matches - LOCUS_RE. - matcher_re: The regular expression matching the names of xmethods. - - Returns: - A dict of matching globally registered xmethod matchers. The only - key in the dict will be 'global'. - """ - locus_str = "global" - xm_dict = { locus_str: [] } - if locus_re.match("global"): - xm_dict[locus_str].extend( - [m for m in gdb.xmethods if matcher_re.match(m.name)]) - return xm_dict - - -def get_method_matchers_in_loci(loci, locus_re, matcher_re): - """Returns a dict of matching registered xmethods in the LOCI. - - Arguments: - loci: The list of loci to lookup matching xmethods in. - locus_re: If a locus is an objfile, then xmethod matchers will be - looked up in it only if its filename matches the regular - expression LOCUS_RE. If a locus is the current progspace, - then xmethod matchers will be looked up in it only if the - string "progspace" matches LOCUS_RE. - matcher_re: The regular expression to match the xmethod matcher - names. - - Returns: - A dict of matching xmethod matchers. The keys of the dict are the - filenames of the loci the xmethod matchers belong to. - """ - xm_dict = {} - for locus in loci: - if isinstance(locus, gdb.Progspace): - if not locus_re.match('progspace'): - continue - locus_type = "progspace" - else: - if not locus_re.match(locus.filename): - continue - locus_type = "objfile" - locus_str = "%s %s" % (locus_type, locus.filename) - xm_dict[locus_str] = [ - m for m in locus.xmethods if matcher_re.match(m.name)] - return xm_dict - - -def print_xm_info(xm_dict, name_re): - """Print a dictionary of xmethods.""" - def get_status_string(m): - if not m.enabled: - return " [disabled]" - else: - return "" - - if not xm_dict: - return - for locus_str in xm_dict: - if not xm_dict[locus_str]: - continue - print ("Xmethods in %s:" % locus_str) - for matcher in xm_dict[locus_str]: - print (" %s%s" % (matcher.name, get_status_string(matcher))) - if not matcher.methods: - continue - for m in matcher.methods: - if name_re is None or name_re.match(m.name): - print (" %s%s" % (m.name, get_status_string(m))) - - -def set_xm_status1(xm_dict, name_re, status): - """Set the status (enabled/disabled) of a dictionary of xmethods.""" - for locus_str, matchers in xm_dict.items(): - for matcher in matchers: - if not name_re: - # If the name regex is missing, then set the status of the - # matcher and move on. - matcher.enabled = status - continue - if not matcher.methods: - # The methods attribute could be None. Move on. - continue - for m in matcher.methods: - if name_re.match(m.name): - m.enabled = status - - -def set_xm_status(arg, status): - """Set the status (enabled/disabled) of xmethods matching ARG. - This is a helper function for enable/disable commands. ARG is the - argument string passed to the commands. - """ - locus_re, matcher_re, name_re = parse_xm_command_args(arg) - set_xm_status1(get_global_method_matchers(locus_re, matcher_re), name_re, - status) - set_xm_status1( - get_method_matchers_in_loci( - [gdb.current_progspace()], locus_re, matcher_re), - name_re, - status) - set_xm_status1( - get_method_matchers_in_loci(gdb.objfiles(), locus_re, matcher_re), - name_re, - status) - - -class InfoXMethod(gdb.Command): - """GDB command to list registered xmethod matchers. - -Usage: info xmethod [LOCUS-REGEXP [NAME-REGEXP]] - -LOCUS-REGEXP is a regular expression matching the location of the -xmethod matchers. If it is omitted, all registered xmethod matchers -from all loci are listed. A locus could be 'global', a regular expression -matching the current program space's filename, or a regular expression -matching filenames of objfiles. Locus could be 'progspace' to specify that -only xmethods from the current progspace should be listed. - -NAME-REGEXP is a regular expression matching the names of xmethod -matchers. If this omitted for a specified locus, then all registered -xmethods in the locus are listed. To list only a certain xmethods -managed by a single matcher, the name regexp can be specified as -matcher-name-regexp;xmethod-name-regexp.""" - - def __init__(self): - super(InfoXMethod, self).__init__("info xmethod", - gdb.COMMAND_DATA) - - def invoke(self, arg, from_tty): - locus_re, matcher_re, name_re = parse_xm_command_args(arg) - print_xm_info(get_global_method_matchers(locus_re, matcher_re), - name_re) - print_xm_info( - get_method_matchers_in_loci( - [gdb.current_progspace()], locus_re, matcher_re), - name_re) - print_xm_info( - get_method_matchers_in_loci(gdb.objfiles(), locus_re, matcher_re), - name_re) - - -class EnableXMethod(gdb.Command): - """GDB command to enable a specified (group of) xmethod(s). - -Usage: enable xmethod [LOCUS-REGEXP [NAME-REGEXP]] - -LOCUS-REGEXP is a regular expression matching the location of the -xmethod matchers. If it is omitted, all registered xmethods matchers -from all loci are enabled. A locus could be 'global', a regular expression -matching the current program space's filename, or a regular expression -matching filenames of objfiles. Locus could be 'progspace' to specify that -only xmethods from the current progspace should be enabled. - -NAME-REGEXP is a regular expression matching the names of xmethods -within a given locus. If this omitted for a specified locus, then all -registered xmethod matchers in the locus are enabled. To enable only -a certain xmethods managed by a single matcher, the name regexp can be -specified as matcher-name-regexp;xmethod-name-regexp.""" - - def __init__(self): - super(EnableXMethod, self).__init__("enable xmethod", - gdb.COMMAND_DATA) - - def invoke(self, arg, from_tty): - set_xm_status(arg, True) - - -class DisableXMethod(gdb.Command): - """GDB command to disable a specified (group of) xmethod(s). - -Usage: disable xmethod [LOCUS-REGEXP [NAME-REGEXP]] - -LOCUS-REGEXP is a regular expression matching the location of the -xmethod matchers. If it is omitted, all registered xmethod matchers -from all loci are disabled. A locus could be 'global', a regular -expression matching the current program space's filename, or a regular -expression filenames of objfiles. Locus could be 'progspace' to specify -that only xmethods from the current progspace should be disabled. - -NAME-REGEXP is a regular expression matching the names of xmethods -within a given locus. If this omitted for a specified locus, then all -registered xmethod matchers in the locus are disabled. To disable -only a certain xmethods managed by a single matcher, the name regexp -can be specified as matcher-name-regexp;xmethod-name-regexp.""" - - def __init__(self): - super(DisableXMethod, self).__init__("disable xmethod", - gdb.COMMAND_DATA) - - def invoke(self, arg, from_tty): - set_xm_status(arg, False) - - -def register_xmethod_commands(): - """Installs the xmethod commands.""" - InfoXMethod() - EnableXMethod() - DisableXMethod() - - -register_xmethod_commands() |