Blame SOURCES/gdb-archer.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-archer.patch
5ad05e
5ad05e
;; Python patches of: http://sourceware.org/gdb/wiki/ProjectArcher
5ad05e
;;=push
5ad05e
5ad05e
http://sourceware.org/gdb/wiki/ProjectArcher
5ad05e
http://sourceware.org/gdb/wiki/ArcherBranchManagement
5ad05e
5ad05e
GIT snapshot:
5ad05e
commit 718a1618b2f691a7f407213bb50f100ac59f91c3
5ad05e
5ad05e
tromey/python
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
@@ -80,6 +80,7 @@ PYTHON_FILE_LIST = \
5ad05e
 	gdb/unwinder.py \
5ad05e
 	gdb/xmethod.py \
5ad05e
 	gdb/command/__init__.py \
5ad05e
+	gdb/command/ignore_errors.py \
5ad05e
 	gdb/command/explore.py \
5ad05e
 	gdb/command/backtrace.py \
5ad05e
 	gdb/command/frame_filters.py \
5ad05e
@@ -92,6 +93,7 @@ PYTHON_FILE_LIST = \
5ad05e
 	gdb/function/as_string.py \
5ad05e
 	gdb/function/caller_is.py \
5ad05e
 	gdb/function/strfns.py \
5ad05e
+	gdb/function/in_scope.py \
5ad05e
 	gdb/printer/__init__.py \
5ad05e
 	gdb/printer/bound_registers.py
5ad05e
 
5ad05e
diff --git a/gdb/gdb-gdb.gdb.in b/gdb/gdb-gdb.gdb.in
5ad05e
--- a/gdb/gdb-gdb.gdb.in
5ad05e
+++ b/gdb/gdb-gdb.gdb.in
5ad05e
@@ -1,5 +1,15 @@
5ad05e
 echo Setting up the environment for debugging gdb.\n
5ad05e
 
5ad05e
+# Set up the Python library and "require" command.
5ad05e
+python
5ad05e
+from os.path import abspath
5ad05e
+gdb.datadir = abspath ('@srcdir@/python/lib')
5ad05e
+gdb.pythonlibdir = gdb.datadir
5ad05e
+gdb.__path__ = [gdb.datadir + '/gdb']
5ad05e
+sys.path.insert(0, gdb.datadir)
5ad05e
+end
5ad05e
+source @srcdir@/python/lib/gdb/__init__.py
5ad05e
+
5ad05e
 if !$gdb_init_done
5ad05e
   set variable $gdb_init_done = 1
5ad05e
 
5ad05e
diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
5ad05e
new file mode 100644
5ad05e
--- /dev/null
5ad05e
+++ b/gdb/python/lib/gdb/command/ignore_errors.py
5ad05e
@@ -0,0 +1,37 @@
5ad05e
+# Ignore errors in user commands.
5ad05e
+
5ad05e
+# Copyright (C) 2008 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
+class IgnoreErrorsCommand (gdb.Command):
5ad05e
+    """Execute a single command, ignoring all errors.
5ad05e
+Only one-line commands are supported.
5ad05e
+This is primarily useful in scripts."""
5ad05e
+
5ad05e
+    def __init__ (self):
5ad05e
+        super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
5ad05e
+                                                    gdb.COMMAND_OBSCURE,
5ad05e
+                                                    # FIXME...
5ad05e
+                                                    gdb.COMPLETE_COMMAND)
5ad05e
+
5ad05e
+    def invoke (self, arg, from_tty):
5ad05e
+        try:
5ad05e
+            gdb.execute (arg, from_tty)
5ad05e
+        except:
5ad05e
+            pass
5ad05e
+
5ad05e
+IgnoreErrorsCommand ()
5ad05e
diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
5ad05e
new file mode 100644
5ad05e
--- /dev/null
5ad05e
+++ b/gdb/python/lib/gdb/function/in_scope.py
5ad05e
@@ -0,0 +1,47 @@
5ad05e
+# In-scope function.
5ad05e
+
5ad05e
+# Copyright (C) 2008 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
+class InScope (gdb.Function):
5ad05e
+    """Return True if all the given variables or macros are in scope.
5ad05e
+Takes one argument for each variable name to be checked."""
5ad05e
+
5ad05e
+    def __init__ (self):
5ad05e
+        super (InScope, self).__init__ ("in_scope")
5ad05e
+
5ad05e
+    def invoke (self, *vars):
5ad05e
+        if len (vars) == 0:
5ad05e
+            raise (TypeError, "in_scope takes at least one argument")
5ad05e
+
5ad05e
+        # gdb.Value isn't hashable so it can't be put in a map.
5ad05e
+        # Convert to string first.
5ad05e
+        wanted = set (map (lambda x: x.string (), vars))
5ad05e
+        found = set ()
5ad05e
+        block = gdb.selected_frame ().block ()
5ad05e
+        while block:
5ad05e
+            for sym in block:
5ad05e
+                if (sym.is_argument or sym.is_constant
5ad05e
+                      or sym.is_function or sym.is_variable):
5ad05e
+                    if sym.name in wanted:
5ad05e
+                        found.add (sym.name)
5ad05e
+
5ad05e
+            block = block.superblock
5ad05e
+
5ad05e
+        return wanted == found
5ad05e
+
5ad05e
+InScope ()
5ad05e
diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
5ad05e
--- a/gdb/testsuite/gdb.python/py-frame.exp
5ad05e
+++ b/gdb/testsuite/gdb.python/py-frame.exp
5ad05e
@@ -95,6 +95,8 @@ gdb_test "python print ('result = %s' % f0.read_var ('a'))" " = 1" "test Frame.r
5ad05e
 
5ad05e
 gdb_test "python print ('result = %s' % (gdb.selected_frame () == f1))" " = True" "test gdb.selected_frame"
5ad05e
 
5ad05e
+gdb_test "python print ('result = %s' % (f0.block ()))" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
5ad05e
+
5ad05e
 # Can read SP register.
5ad05e
 gdb_test "python print ('result = %s' % (gdb.selected_frame ().read_register ('sp') == gdb.parse_and_eval ('\$sp')))" \
5ad05e
   " = True" \
5ad05e
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
5ad05e
--- a/gdb/testsuite/gdb.python/py-value.exp
5ad05e
+++ b/gdb/testsuite/gdb.python/py-value.exp
5ad05e
@@ -419,6 +419,15 @@ proc test_value_after_death {} {
5ad05e
     "print value's type"
5ad05e
 }
5ad05e
 
5ad05e
+# Regression test for a cast failure.  The bug was that if we cast a
5ad05e
+# value to its own type, gdb could crash.  This happened because we
5ad05e
+# could end up double-freeing a struct value.
5ad05e
+proc test_cast_regression {} {
5ad05e
+  gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
5ad05e
+  gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
5ad05e
+  gdb_test "python print(v)" "5" "print value for cast test"
5ad05e
+}
5ad05e
+
5ad05e
 # Regression test for invalid subscript operations.  The bug was that
5ad05e
 # the type of the value was not being checked before allowing a
5ad05e
 # subscript operation to proceed.
5ad05e
@@ -606,6 +615,7 @@ test_value_in_inferior
5ad05e
 test_value_from_buffer
5ad05e
 test_inferior_function_call
5ad05e
 test_value_after_death
5ad05e
+test_cast_regression
5ad05e
 
5ad05e
 # Test either C or C++ values. 
5ad05e