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

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