Blame SOURCES/gdb-archer.patch

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