Blame SOURCES/gdb-archer.patch

b2f73e
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
b2f73e
From: Fedora GDB patches <invalid@email.com>
b2f73e
Date: Fri, 27 Oct 2017 21:07:50 +0200
b2f73e
Subject: gdb-archer.patch
b2f73e
b2f73e
;; Python patches of: http://sourceware.org/gdb/wiki/ProjectArcher
b2f73e
;;=push
b2f73e
b2f73e
http://sourceware.org/gdb/wiki/ProjectArcher
b2f73e
http://sourceware.org/gdb/wiki/ArcherBranchManagement
b2f73e
b2f73e
GIT snapshot:
b2f73e
commit 718a1618b2f691a7f407213bb50f100ac59f91c3
b2f73e
b2f73e
tromey/python
b2f73e
b2f73e
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
b2f73e
--- a/gdb/data-directory/Makefile.in
b2f73e
+++ b/gdb/data-directory/Makefile.in
b2f73e
@@ -80,6 +80,7 @@ PYTHON_FILE_LIST = \
b2f73e
 	gdb/unwinder.py \
b2f73e
 	gdb/xmethod.py \
b2f73e
 	gdb/command/__init__.py \
b2f73e
+	gdb/command/ignore_errors.py \
b2f73e
 	gdb/command/explore.py \
b2f73e
 	gdb/command/backtrace.py \
b2f73e
 	gdb/command/frame_filters.py \
b2f73e
@@ -92,6 +93,7 @@ PYTHON_FILE_LIST = \
b2f73e
 	gdb/function/as_string.py \
b2f73e
 	gdb/function/caller_is.py \
b2f73e
 	gdb/function/strfns.py \
b2f73e
+	gdb/function/in_scope.py \
b2f73e
 	gdb/printer/__init__.py \
b2f73e
 	gdb/printer/bound_registers.py
b2f73e
 
b2f73e
diff --git a/gdb/gdb-gdb.gdb.in b/gdb/gdb-gdb.gdb.in
b2f73e
--- a/gdb/gdb-gdb.gdb.in
b2f73e
+++ b/gdb/gdb-gdb.gdb.in
b2f73e
@@ -1,5 +1,15 @@
b2f73e
 echo Setting up the environment for debugging gdb.\n
b2f73e
 
b2f73e
+# Set up the Python library and "require" command.
b2f73e
+python
b2f73e
+from os.path import abspath
b2f73e
+gdb.datadir = abspath ('@srcdir@/python/lib')
b2f73e
+gdb.pythonlibdir = gdb.datadir
b2f73e
+gdb.__path__ = [gdb.datadir + '/gdb']
b2f73e
+sys.path.insert(0, gdb.datadir)
b2f73e
+end
b2f73e
+source @srcdir@/python/lib/gdb/__init__.py
b2f73e
+
b2f73e
 if !$gdb_init_done
b2f73e
   set variable $gdb_init_done = 1
b2f73e
 
b2f73e
diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
b2f73e
new file mode 100644
b2f73e
--- /dev/null
b2f73e
+++ b/gdb/python/lib/gdb/command/ignore_errors.py
b2f73e
@@ -0,0 +1,37 @@
b2f73e
+# Ignore errors in user commands.
b2f73e
+
b2f73e
+# Copyright (C) 2008 Free Software Foundation, Inc.
b2f73e
+
b2f73e
+# This program is free software; you can redistribute it and/or modify
b2f73e
+# it under the terms of the GNU General Public License as published by
b2f73e
+# the Free Software Foundation; either version 3 of the License, or
b2f73e
+# (at your option) any later version.
b2f73e
+#
b2f73e
+# This program is distributed in the hope that it will be useful,
b2f73e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b2f73e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b2f73e
+# GNU General Public License for more details.
b2f73e
+#
b2f73e
+# You should have received a copy of the GNU General Public License
b2f73e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
b2f73e
+
b2f73e
+import gdb
b2f73e
+
b2f73e
+class IgnoreErrorsCommand (gdb.Command):
b2f73e
+    """Execute a single command, ignoring all errors.
b2f73e
+Only one-line commands are supported.
b2f73e
+This is primarily useful in scripts."""
b2f73e
+
b2f73e
+    def __init__ (self):
b2f73e
+        super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
b2f73e
+                                                    gdb.COMMAND_OBSCURE,
b2f73e
+                                                    # FIXME...
b2f73e
+                                                    gdb.COMPLETE_COMMAND)
b2f73e
+
b2f73e
+    def invoke (self, arg, from_tty):
b2f73e
+        try:
b2f73e
+            gdb.execute (arg, from_tty)
b2f73e
+        except:
b2f73e
+            pass
b2f73e
+
b2f73e
+IgnoreErrorsCommand ()
b2f73e
diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
b2f73e
new file mode 100644
b2f73e
--- /dev/null
b2f73e
+++ b/gdb/python/lib/gdb/function/in_scope.py
b2f73e
@@ -0,0 +1,47 @@
b2f73e
+# In-scope function.
b2f73e
+
b2f73e
+# Copyright (C) 2008 Free Software Foundation, Inc.
b2f73e
+
b2f73e
+# This program is free software; you can redistribute it and/or modify
b2f73e
+# it under the terms of the GNU General Public License as published by
b2f73e
+# the Free Software Foundation; either version 3 of the License, or
b2f73e
+# (at your option) any later version.
b2f73e
+#
b2f73e
+# This program is distributed in the hope that it will be useful,
b2f73e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b2f73e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b2f73e
+# GNU General Public License for more details.
b2f73e
+#
b2f73e
+# You should have received a copy of the GNU General Public License
b2f73e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
b2f73e
+
b2f73e
+import gdb
b2f73e
+
b2f73e
+class InScope (gdb.Function):
b2f73e
+    """Return True if all the given variables or macros are in scope.
b2f73e
+Takes one argument for each variable name to be checked."""
b2f73e
+
b2f73e
+    def __init__ (self):
b2f73e
+        super (InScope, self).__init__ ("in_scope")
b2f73e
+
b2f73e
+    def invoke (self, *vars):
b2f73e
+        if len (vars) == 0:
b2f73e
+            raise (TypeError, "in_scope takes at least one argument")
b2f73e
+
b2f73e
+        # gdb.Value isn't hashable so it can't be put in a map.
b2f73e
+        # Convert to string first.
b2f73e
+        wanted = set (map (lambda x: x.string (), vars))
b2f73e
+        found = set ()
b2f73e
+        block = gdb.selected_frame ().block ()
b2f73e
+        while block:
b2f73e
+            for sym in block:
b2f73e
+                if (sym.is_argument or sym.is_constant
b2f73e
+                      or sym.is_function or sym.is_variable):
b2f73e
+                    if sym.name in wanted:
b2f73e
+                        found.add (sym.name)
b2f73e
+
b2f73e
+            block = block.superblock
b2f73e
+
b2f73e
+        return wanted == found
b2f73e
+
b2f73e
+InScope ()
b2f73e
diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
b2f73e
--- a/gdb/testsuite/gdb.python/py-frame.exp
b2f73e
+++ b/gdb/testsuite/gdb.python/py-frame.exp
b2f73e
@@ -95,6 +95,8 @@ gdb_test "python print ('result = %s' % f0.read_var ('a'))" " = 1" "test Frame.r
b2f73e
 
b2f73e
 gdb_test "python print ('result = %s' % (gdb.selected_frame () == f1))" " = True" "test gdb.selected_frame"
b2f73e
 
b2f73e
+gdb_test "python print ('result = %s' % (f0.block ()))" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
b2f73e
+
b2f73e
 # Can read SP register.
b2f73e
 gdb_test "python print ('result = %s' % (gdb.selected_frame ().read_register ('sp') == gdb.parse_and_eval ('\$sp')))" \
b2f73e
   " = True" \
b2f73e
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
b2f73e
--- a/gdb/testsuite/gdb.python/py-value.exp
b2f73e
+++ b/gdb/testsuite/gdb.python/py-value.exp
b2f73e
@@ -419,6 +419,15 @@ proc test_value_after_death {} {
b2f73e
     "print value's type"
b2f73e
 }
b2f73e
 
b2f73e
+# Regression test for a cast failure.  The bug was that if we cast a
b2f73e
+# value to its own type, gdb could crash.  This happened because we
b2f73e
+# could end up double-freeing a struct value.
b2f73e
+proc test_cast_regression {} {
b2f73e
+  gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
b2f73e
+  gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
b2f73e
+  gdb_test "python print(v)" "5" "print value for cast test"
b2f73e
+}
b2f73e
+
b2f73e
 # Regression test for invalid subscript operations.  The bug was that
b2f73e
 # the type of the value was not being checked before allowing a
b2f73e
 # subscript operation to proceed.
b2f73e
@@ -606,6 +615,7 @@ test_value_in_inferior
b2f73e
 test_value_from_buffer
b2f73e
 test_inferior_function_call
b2f73e
 test_value_after_death
b2f73e
+test_cast_regression
b2f73e
 
b2f73e
 # Test either C or C++ values. 
b2f73e