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