Blob Blame History Raw
diff -up Python-2.7.3/Lib/test/test_gdb.py.gdb-autoload-safepath Python-2.7.3/Lib/test/test_gdb.py
--- Python-2.7.3/Lib/test/test_gdb.py.gdb-autoload-safepath	2012-04-30 15:53:57.254045220 -0400
+++ Python-2.7.3/Lib/test/test_gdb.py	2012-04-30 16:19:19.569941124 -0400
@@ -54,6 +54,19 @@ def gdb_has_frame_select():
 
 HAS_PYUP_PYDOWN = gdb_has_frame_select()
 
+def gdb_has_autoload_safepath():
+    # Recent GDBs will only auto-load scripts from certain safe
+    # locations, so we will need to turn off this protection.
+    # However, if the GDB doesn't have it, then the following
+    # command will generate noise on stderr (rhbz#817072):
+    cmd = "--eval-command=set auto-load safe-path /"
+    p = subprocess.Popen(["gdb", "--batch", cmd],
+                         stderr=subprocess.PIPE)
+    _, stderr = p.communicate()
+    return '"on" or "off" expected.' not in stderr
+    
+HAS_AUTOLOAD_SAFEPATH = gdb_has_autoload_safepath()
+
 class DebuggerTests(unittest.TestCase):
 
     """Test that the debugger can debug Python."""
@@ -112,15 +125,28 @@ class DebuggerTests(unittest.TestCase):
                     'set print entry-values no',
 
                     'run']
+
+        if HAS_AUTOLOAD_SAFEPATH:
+            # Recent GDBs will only auto-load scripts from certain safe
+            # locations.
+            # Where necessary, turn off this protection to ensure that
+            # our -gdb.py script can be loaded - but not on earlier gdb builds
+            # as this would generate noise on stderr (rhbz#817072):
+            init_commands = ['set auto-load safe-path /']
+        else:
+            init_commands = []
+
         if cmds_after_breakpoint:
             commands += cmds_after_breakpoint
         else:
             commands += ['backtrace']
 
+        # print init_commands
         # print commands
 
         # Use "commands" to generate the arguments with which to invoke "gdb":
         args = ["gdb", "--batch"]
+        args += ['--init-eval-command=%s' % cmd for cmd in init_commands]
         args += ['--eval-command=%s' % cmd for cmd in commands]
         args += ["--args",
                  sys.executable]