[libcxx-commits] [PATCH] D110334: [libcxx][pretty printers] Check GDB Python scripting support
David Spickett via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Sep 23 07:34:37 PDT 2021
DavidSpickett created this revision.
Herald added a subscriber: arichardson.
DavidSpickett requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
I found this after upgrading from Ubuntu bionic (gdb 8.1.1) to
Focal (gdb 9.2). (where this test fails, but that's for a
different patch)
9.2 allows you to set breakpoint commands from
Python, which was added in 8.3.
(bintutils a913fffbdee21fdd50e8de0596358be425775678
"Allow breakpoint commands to be set from Python")
The reason this test never failed before was because it did so
silently. "source <python file>" doesn't fail even if that script
raises an Exception.
To fix this extend the gdb lit feature to check that:
- gdb exists
- has Python support
- allows you to set breakpoint commands
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D110334
Files:
libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
libcxx/utils/libcxx/test/features.py
Index: libcxx/utils/libcxx/test/features.py
===================================================================
--- libcxx/utils/libcxx/test/features.py
+++ libcxx/utils/libcxx/test/features.py
@@ -10,6 +10,7 @@
import re
import shutil
import sys
+from subprocess import check_output, CalledProcessError, DEVNULL
_isClang = lambda cfg: '__clang__' in compilerMacros(cfg) and '__apple_build_version__' not in compilerMacros(cfg)
_isAppleClang = lambda cfg: '__apple_build_version__' in compilerMacros(cfg)
@@ -159,10 +160,34 @@
Feature(name='buildhost=windows', when=lambda cfg: platform.system().lower().startswith('windows'))
]
-# Detect whether GDB is on the system, and if so add a substitution to access it.
+# Detect whether GDB is on the system, has Python scripting and supports
+# adding breakpoint commands. If so add a substitution to access it.
+def check_gdb(cfg):
+ gdb_path = shutil.which('gdb')
+ if gdb_path is None:
+ return False
+
+ # Check that we can set breakpoint commands, which was added in 8.3
+ test_src = """\
+try:
+ gdb.Breakpoint(\"main\").commands=\"foo\"
+except AttributeError:
+ gdb.execute(\"quit 1\")
+gdb.execute(\"quit\")"""
+
+ try:
+ stdout = check_output([gdb_path, "-ex", "python " + test_src, "--batch"],
+ stderr=DEVNULL, universal_newlines=True)
+ except CalledProcessError:
+ # We can't set breakpoint commands
+ return False
+
+ # Check we actually ran the Python
+ return not "Python scripting is not supported" in stdout
+
DEFAULT_FEATURES += [
- Feature(name='host-has-gdb',
- when=lambda cfg: shutil.which('gdb') is not None,
+ Feature(name='host-has-gdb-with-python',
+ when=check_gdb,
actions=[AddSubstitution('%{gdb}', lambda cfg: shutil.which('gdb'))]
)
]
Index: libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
===================================================================
--- libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
+++ libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
-// REQUIRES: host-has-gdb
+// REQUIRES: host-has-gdb-with-python
// UNSUPPORTED: libcpp-has-no-localization
// UNSUPPORTED: c++03
Index: libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
===================================================================
--- libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
+++ libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py
@@ -105,6 +105,7 @@
test_bp.enabled = True
test_bp.silent = True
test_bp.commands = "print_and_compare\ncontinue"
+
# "run" won't return if the program exits; ensure the script regains control.
gdb.events.exited.connect(exit_handler)
gdb.execute("run")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110334.374540.patch
Type: text/x-patch
Size: 2771 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210923/2ae6d7c8/attachment.bin>
More information about the libcxx-commits
mailing list