]> granicus.if.org Git - python/commitdiff
merge #15043: Improve test_gdb support of gdb >= 7.4.
authorR David Murray <rdmurray@bitdance.com>
Sat, 27 Oct 2012 17:26:14 +0000 (13:26 -0400)
committerR David Murray <rdmurray@bitdance.com>
Sat, 27 Oct 2012 17:26:14 +0000 (13:26 -0400)
Instead of requiring the tester to manually add the path to the python-gdb.py
file in the checkout to their .gdbinit file, add it automatically when
invoking gdb in the test.

1  2 
Lib/test/test_gdb.py

index a872e68250c3c6ee53319ae44cad43b7a1157b6d,6d96550a9bc892ebae77df77b4e320b0d8683592..9713dc9c0692de83ac2dcb004391bed02b19cd7f
@@@ -31,25 -26,41 +33,42 @@@ if gdb_major_version < 7
      raise unittest.SkipTest("gdb versions before 7.0 didn't support python embedding"
                              " Saw:\n" + gdb_version.decode('ascii', 'replace'))
  
 +if not sysconfig.is_python_build():
 +    raise unittest.SkipTest("test_gdb only works on source builds at the moment.")
 +
+ # Location of custom hooks file in a repository checkout.
+ checkout_hook_path = os.path.join(os.path.dirname(sys.executable),
+                                   'python-gdb.py')
+ def run_gdb(*args, **env_vars):
+     """Runs gdb in --batch mode with the additional arguments given by *args.
+     Returns its (stdout, stderr) decoded from utf-8 using the replace handler.
+     """
+     if env_vars:
+         env = os.environ.copy()
+         env.update(env_vars)
+     else:
+         env = None
+     base_cmd = ('gdb', '--batch')
+     if (gdb_major_version, gdb_minor_version) >= (7, 4):
+         base_cmd += ('-iex', 'add-auto-load-safe-path ' + checkout_hook_path)
+     out, err = subprocess.Popen(base_cmd + args,
+         stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env,
+         ).communicate()
+     return out.decode('utf-8', 'replace'), err.decode('utf-8', 'replace')
  # Verify that "gdb" was built with the embedded python support enabled:
- cmd = "--eval-command=python import sys; print sys.version_info"
- p = subprocess.Popen(["gdb", "--batch", cmd],
-                      stdout=subprocess.PIPE)
- gdbpy_version, _ = p.communicate()
- if gdbpy_version == b'':
+ gdbpy_version, _ = run_gdb("--eval-command=python import sys; print sys.version_info")
+ if not gdbpy_version:
      raise unittest.SkipTest("gdb not built with embedded python support")
  
- # Verify that "gdb" can load our custom hooks
- p = subprocess.Popen(["gdb", "--batch", cmd,
-                       "--args", sys.executable],
-                      stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- __, gdbpy_errors = p.communicate()
- if b"auto-loading has been declined" in gdbpy_errors:
-     msg = "gdb security settings prevent use of custom hooks: %s"
-     raise unittest.SkipTest(msg % gdbpy_errors)
 -# Verify that "gdb" can load our custom hooks.  In theory this should never
 -# fail, but we don't handle the case of the hooks file not existing if the
 -# tests are run from an installed Python (we'll produce failures in that case).
++# Verify that "gdb" can load our custom hooks. In theory this should never fail.
+ cmd = ['--args', sys.executable]
+ _, gdbpy_errors = run_gdb('--args', sys.executable)
+ if "auto-loading has been declined" in gdbpy_errors:
+     msg = "gdb security settings prevent use of custom hooks: "
+     raise unittest.SkipTest(msg + gdbpy_errors.rstrip())
  
  def gdb_has_frame_select():
      # Does this build of gdb have gdb.Frame.select ?