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

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