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