Blame SOURCES/gdb-archer.patch

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