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