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