Blame SOURCES/gdb-dts-rhel6-python-compat.patch

b2f73e
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
b2f73e
From: Fedora GDB patches <invalid@email.com>
b2f73e
Date: Fri, 27 Oct 2017 21:07:50 +0200
b2f73e
Subject: gdb-dts-rhel6-python-compat.patch
b2f73e
b2f73e
;; [rhel6] DTS backward Python compatibility API (BZ 1020004, Phil Muldoon).
b2f73e
;;=fedora
b2f73e
b2f73e
https://bugzilla.redhat.com/show_bug.cgi?id=1020004
b2f73e
b2f73e
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
b2f73e
--- a/gdb/data-directory/Makefile.in
b2f73e
+++ b/gdb/data-directory/Makefile.in
b2f73e
@@ -71,6 +71,8 @@ PYTHON_FILE_LIST = \
b2f73e
 	gdb/__init__.py \
b2f73e
 	gdb/FrameDecorator.py \
b2f73e
 	gdb/FrameIterator.py \
b2f73e
+	gdb/FrameWrapper.py \
b2f73e
+	gdb/backtrace.py \
b2f73e
 	gdb/frames.py \
b2f73e
 	gdb/printing.py \
b2f73e
 	gdb/prompt.py \
b2f73e
@@ -79,6 +81,7 @@ PYTHON_FILE_LIST = \
b2f73e
 	gdb/xmethod.py \
b2f73e
 	gdb/command/__init__.py \
b2f73e
 	gdb/command/explore.py \
b2f73e
+	gdb/command/backtrace.py \
b2f73e
 	gdb/command/frame_filters.py \
b2f73e
 	gdb/command/pretty_printers.py \
b2f73e
 	gdb/command/prompt.py \
b2f73e
diff --git a/gdb/python/lib/gdb/FrameWrapper.py b/gdb/python/lib/gdb/FrameWrapper.py
b2f73e
new file mode 100644
b2f73e
--- /dev/null
b2f73e
+++ b/gdb/python/lib/gdb/FrameWrapper.py
b2f73e
@@ -0,0 +1,122 @@
b2f73e
+# Wrapper API for frames.
b2f73e
+
b2f73e
+# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
b2f73e
+
b2f73e
+# This program is free software; you can redistribute it and/or modify
b2f73e
+# it under the terms of the GNU General Public License as published by
b2f73e
+# the Free Software Foundation; either version 3 of the License, or
b2f73e
+# (at your option) any later version.
b2f73e
+#
b2f73e
+# This program is distributed in the hope that it will be useful,
b2f73e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b2f73e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b2f73e
+# GNU General Public License for more details.
b2f73e
+#
b2f73e
+# You should have received a copy of the GNU General Public License
b2f73e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
b2f73e
+
b2f73e
+import gdb
b2f73e
+
b2f73e
+# FIXME: arguably all this should be on Frame somehow.
b2f73e
+class FrameWrapper:
b2f73e
+    def __init__ (self, frame):
b2f73e
+        self.frame = frame;
b2f73e
+
b2f73e
+    def write_symbol (self, stream, sym, block):
b2f73e
+        if len (sym.linkage_name):
b2f73e
+            nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block)
b2f73e
+            if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
b2f73e
+                sym = nsym
b2f73e
+
b2f73e
+        stream.write (sym.print_name + "=")
b2f73e
+        try:
b2f73e
+            val = self.read_var (sym)
b2f73e
+            if val != None:
b2f73e
+                val = str (val)
b2f73e
+        # FIXME: would be nice to have a more precise exception here.
b2f73e
+        except RuntimeError as text:
b2f73e
+            val = text
b2f73e
+        if val == None:
b2f73e
+            stream.write ("???")
b2f73e
+        else:
b2f73e
+            stream.write (str (val))
b2f73e
+
b2f73e
+    def print_frame_locals (self, stream, func):
b2f73e
+
b2f73e
+        try:
b2f73e
+            block = self.frame.block()
b2f73e
+        except RuntimeError:
b2f73e
+            block = None
b2f73e
+
b2f73e
+        while block != None:
b2f73e
+            if block.is_global or block.is_static:
b2f73e
+                break
b2f73e
+
b2f73e
+        for sym in block:
b2f73e
+            if sym.is_argument:
b2f73e
+                continue;
b2f73e
+
b2f73e
+            self.write_symbol (stream, sym, block)
b2f73e
+            stream.write ('\n')
b2f73e
+
b2f73e
+    def print_frame_args (self, stream, func):
b2f73e
+
b2f73e
+        try:
b2f73e
+            block = self.frame.block()
b2f73e
+        except RuntimeError:
b2f73e
+            block = None
b2f73e
+
b2f73e
+        while block != None:
b2f73e
+            if block.function != None:
b2f73e
+                break
b2f73e
+            block = block.superblock
b2f73e
+
b2f73e
+        first = True
b2f73e
+        for sym in block:
b2f73e
+            if not sym.is_argument:
b2f73e
+                continue;
b2f73e
+
b2f73e
+            if not first:
b2f73e
+                stream.write (", ")
b2f73e
+
b2f73e
+            self.write_symbol (stream, sym, block)
b2f73e
+            first = False
b2f73e
+
b2f73e
+    # FIXME: this should probably just be a method on gdb.Frame.
b2f73e
+    # But then we need stream wrappers.
b2f73e
+    def describe (self, stream, full):
b2f73e
+        if self.type () == gdb.DUMMY_FRAME:
b2f73e
+            stream.write (" <function called from gdb>\n")
b2f73e
+        elif self.type () == gdb.SIGTRAMP_FRAME:
b2f73e
+            stream.write (" <signal handler called>\n")
b2f73e
+        else:
b2f73e
+            sal = self.find_sal ()
b2f73e
+            pc = self.pc ()
b2f73e
+            name = self.name ()
b2f73e
+            if not name:
b2f73e
+                name = "??"
b2f73e
+            if pc != sal.pc or not sal.symtab:
b2f73e
+                stream.write (" 0x%08x in" % pc)
b2f73e
+            stream.write (" " + name + " (")
b2f73e
+
b2f73e
+            func = self.function ()
b2f73e
+            self.print_frame_args (stream, func)
b2f73e
+
b2f73e
+            stream.write (")")
b2f73e
+
b2f73e
+            if sal.symtab and sal.symtab.filename:
b2f73e
+                stream.write (" at " + sal.symtab.filename)
b2f73e
+                stream.write (":" + str (sal.line))
b2f73e
+
b2f73e
+            if not self.name () or (not sal.symtab or not sal.symtab.filename):
b2f73e
+                lib = gdb.solib_name (pc)
b2f73e
+                if lib:
b2f73e
+                    stream.write (" from " + lib)
b2f73e
+
b2f73e
+            stream.write ("\n")
b2f73e
+
b2f73e
+            if full:
b2f73e
+                self.print_frame_locals (stream, func)
b2f73e
+
b2f73e
+    def __getattr__ (self, name):
b2f73e
+        return getattr (self.frame, name)
b2f73e
diff --git a/gdb/python/lib/gdb/backtrace.py b/gdb/python/lib/gdb/backtrace.py
b2f73e
new file mode 100644
b2f73e
--- /dev/null
b2f73e
+++ b/gdb/python/lib/gdb/backtrace.py
b2f73e
@@ -0,0 +1,42 @@
b2f73e
+# Filtering backtrace.
b2f73e
+
b2f73e
+# Copyright (C) 2008, 2011 Free Software Foundation, Inc.
b2f73e
+
b2f73e
+# This program is free software; you can redistribute it and/or modify
b2f73e
+# it under the terms of the GNU General Public License as published by
b2f73e
+# the Free Software Foundation; either version 3 of the License, or
b2f73e
+# (at your option) any later version.
b2f73e
+#
b2f73e
+# This program is distributed in the hope that it will be useful,
b2f73e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b2f73e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b2f73e
+# GNU General Public License for more details.
b2f73e
+#
b2f73e
+# You should have received a copy of the GNU General Public License
b2f73e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
b2f73e
+
b2f73e
+import gdb
b2f73e
+import itertools
b2f73e
+
b2f73e
+# Our only exports.
b2f73e
+__all__ = ['push_frame_filter', 'create_frame_filter']
b2f73e
+
b2f73e
+old_frame_filter = None
b2f73e
+
b2f73e
+def push_frame_filter (constructor):
b2f73e
+    """Register a new backtrace filter class with the 'backtrace' command.
b2f73e
+The filter will be passed an iterator as an argument.  The iterator
b2f73e
+will return gdb.Frame-like objects.  The filter should in turn act as
b2f73e
+an iterator returning such objects."""
b2f73e
+    global old_frame_filter
b2f73e
+    if old_frame_filter == None:
b2f73e
+        old_frame_filter = constructor
b2f73e
+    else:
b2f73e
+        old_frame_filter = lambda iterator, filter = frame_filter: constructor (filter(iterator))
b2f73e
+
b2f73e
+def create_frame_filter (iter):
b2f73e
+    global old_frame_filter
b2f73e
+    if old_frame_filter is None:
b2f73e
+        return iter
b2f73e
+    return old_frame_filter (iter)
b2f73e
+
b2f73e
diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
b2f73e
new file mode 100644
b2f73e
--- /dev/null
b2f73e
+++ b/gdb/python/lib/gdb/command/backtrace.py
b2f73e
@@ -0,0 +1,106 @@
b2f73e
+# New backtrace command.
b2f73e
+
b2f73e
+# Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
b2f73e
+
b2f73e
+# This program is free software; you can redistribute it and/or modify
b2f73e
+# it under the terms of the GNU General Public License as published by
b2f73e
+# the Free Software Foundation; either version 3 of the License, or
b2f73e
+# (at your option) any later version.
b2f73e
+#
b2f73e
+# This program is distributed in the hope that it will be useful,
b2f73e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b2f73e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b2f73e
+# GNU General Public License for more details.
b2f73e
+#
b2f73e
+# You should have received a copy of the GNU General Public License
b2f73e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
b2f73e
+
b2f73e
+import gdb
b2f73e
+import gdb.backtrace
b2f73e
+import itertools
b2f73e
+from gdb.FrameIterator import FrameIterator
b2f73e
+from gdb.FrameWrapper import FrameWrapper
b2f73e
+import sys
b2f73e
+
b2f73e
+class ReverseBacktraceParameter (gdb.Parameter):
b2f73e
+    """The new-backtrace command can show backtraces in 'reverse' order.
b2f73e
+This means that the innermost frame will be printed last.
b2f73e
+Note that reverse backtraces are more expensive to compute."""
b2f73e
+
b2f73e
+    set_doc = "Enable or disable reverse backtraces."
b2f73e
+    show_doc = "Show whether backtraces will be printed in reverse order."
b2f73e
+
b2f73e
+    def __init__(self):
b2f73e
+        gdb.Parameter.__init__ (self, "reverse-backtrace",
b2f73e
+                                gdb.COMMAND_STACK, gdb.PARAM_BOOLEAN)
b2f73e
+        # Default to compatibility with gdb.
b2f73e
+        self.value = False
b2f73e
+
b2f73e
+class FilteringBacktrace (gdb.Command):
b2f73e
+    """Print backtrace of all stack frames, or innermost COUNT frames.
b2f73e
+With a negative argument, print outermost -COUNT frames.
b2f73e
+Use of the 'full' qualifier also prints the values of the local variables.
b2f73e
+Use of the 'raw' qualifier avoids any filtering by loadable modules.
b2f73e
+"""
b2f73e
+
b2f73e
+    def __init__ (self):
b2f73e
+        # FIXME: this is not working quite well enough to replace
b2f73e
+        # "backtrace" yet.
b2f73e
+        gdb.Command.__init__ (self, "new-backtrace", gdb.COMMAND_STACK)
b2f73e
+        self.reverse = ReverseBacktraceParameter()
b2f73e
+
b2f73e
+    def reverse_iter (self, iter):
b2f73e
+        result = []
b2f73e
+        for item in iter:
b2f73e
+            result.append (item)
b2f73e
+        result.reverse()
b2f73e
+        return result
b2f73e
+
b2f73e
+    def final_n (self, iter, x):
b2f73e
+        result = []
b2f73e
+        for item in iter:
b2f73e
+            result.append (item)
b2f73e
+        return result[x:]
b2f73e
+
b2f73e
+    def invoke (self, arg, from_tty):
b2f73e
+        i = 0
b2f73e
+        count = 0
b2f73e
+        filter = True
b2f73e
+        full = False
b2f73e
+
b2f73e
+        for word in arg.split (" "):
b2f73e
+            if word == '':
b2f73e
+                continue
b2f73e
+            elif word == 'raw':
b2f73e
+                filter = False
b2f73e
+            elif word == 'full':
b2f73e
+                full = True
b2f73e
+            else:
b2f73e
+                count = int (word)
b2f73e
+
b2f73e
+        # FIXME: provide option to start at selected frame
b2f73e
+        # However, should still number as if starting from newest
b2f73e
+        newest_frame = gdb.newest_frame()
b2f73e
+        iter = itertools.imap (FrameWrapper,
b2f73e
+                               FrameIterator (newest_frame))
b2f73e
+        if filter:
b2f73e
+            iter = gdb.backtrace.create_frame_filter (iter)
b2f73e
+
b2f73e
+        # Now wrap in an iterator that numbers the frames.
b2f73e
+        iter = itertools.izip (itertools.count (0), iter)
b2f73e
+
b2f73e
+        # Reverse if the user wanted that.
b2f73e
+        if self.reverse.value:
b2f73e
+            iter = self.reverse_iter (iter)
b2f73e
+
b2f73e
+        # Extract sub-range user wants.
b2f73e
+        if count < 0:
b2f73e
+            iter = self.final_n (iter, count)
b2f73e
+        elif count > 0:
b2f73e
+            iter = itertools.islice (iter, 0, count)
b2f73e
+
b2f73e
+        for pair in iter:
b2f73e
+            sys.stdout.write ("#%-2d" % pair[0])
b2f73e
+            pair[1].describe (sys.stdout, full)
b2f73e
+
b2f73e
+FilteringBacktrace()