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