From 5fb0d81b5b1561187a858bee5d03cb91e197a124 Mon Sep 17 00:00:00 2001 From: Thiago Jung Bauermann Date: Wed, 6 Aug 2008 19:41:30 +0000 Subject: Initial python support. gdb/ 2008-08-06 Vladimir Prus Tom Tromey Thiago Jung Bauermann Doug Evans * Makefile.in (SUBDIR_PYTHON_OBS, SUBDIR_PYTHON_SRCS, SUBDIR_PYTHON_DEPS, SUBDIR_PYTHON_LDFLAGS, SUBDIR_PYTHON_CFLAGS, PYTHON_CFLAGS): New. (python_h, python_internal_h): New. (cli-script.o): Depend on python.h (python.o, python-utils.o): New. * cli/cli-script.c (print_command_lines): Handle python_control. (execute_control_command): Handle python_control. (execute_control_command_untraced): New function. (while_command): Call execute_control_command_untraced. (if_command): Likewise. (get_command_line): Remove static attribute. (read_next_line): Handle "python". (recurse_read_control_structure): Handle python_control. (read_command_lines): Handle python_control. Include python.h. * cli/cli-script.h (get_command_line): Add prototype. (execute_control_command_untraced): Likewise. * configure.ac: Add --with-python. * defs.h (enum command_control_type) : New constant. * python/python-internal.h: New file. * python/python.c: New file. * python/python.h: New file. * python/python-utils.c: New file. * NEWS: Mention Python scripting support and its new commands. gdb/doc/ 2008-08-06 Tom Tromey * gdb.texinfo (Extending GDB): New chapter. (Sequences): Demoted chapter, now a section under the new Extending GDB chapter. (Python): New section. gdb/testsuite/ 2008-08-06 Tom Tromey * gdb.python/python.exp: New file. --- gdb/configure.ac | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) (limited to 'gdb/configure.ac') diff --git a/gdb/configure.ac b/gdb/configure.ac index 3a5521823e8..74b7d6a9e3c 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -497,6 +497,125 @@ else fi fi +dnl Utility to simplify finding libpython. +AC_DEFUN([AC_TRY_LIBPYTHON], +[ + version=$1 + define([have_libpython_var],$2) + define([VERSION],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + [HAVE_LIB]VERSION=no + AC_MSG_CHECKING([for ${version}]) + save_LIBS=$LIBS + LIBS="$LIBS -l${version}" + AC_LINK_IFELSE(AC_LANG_PROGRAM([[#include "${version}/Python.h"]], + [[Py_Initialize ();]]), + [[HAVE_LIB]VERSION=yes + have_libpython_var=yes], + [LIBS=$save_LIBS]) + AC_MSG_RESULT([$[HAVE_LIB]VERSION]) +]) + +AC_ARG_WITH(python, + AS_HELP_STRING([--with-python], [include python support (auto/yes/no/)]), + [], [with_python=auto]) +AC_MSG_CHECKING([whether to use python]) +AC_MSG_RESULT([$with_python]) + +if test "${with_python}" = no; then + AC_MSG_WARN([python support disabled; some features may be unavailable.]) + have_libpython=no +else + case "${with_python}" in + yes | auto) + # Leave as empty, use defaults. + python_includes= + python_libs= + ;; + /*) + python_includes="-I${with_python}/include" + python_libs="-L${with_python}/lib" + ;; + *) + AC_ERROR(invalid value for --with-python) + ;; + esac + + save_CPPFLAGS=$CPPFLAGS + CPPFLAGS="$CPPFLAGS ${python_includes}" + save_LIBS=$LIBS + LIBS="$LIBS ${python_libs}" + have_libpython=no + if test "${have_libpython}" = no; then + AC_TRY_LIBPYTHON(python2.6, have_libpython) + if test "${HAVE_LIBPYTHON2_6}" = yes; then + AC_DEFINE(HAVE_LIBPYTHON2_6, 1, [Define if Python 2.6 is being used.]) + fi + fi + if test ${have_libpython} = no; then + AC_TRY_LIBPYTHON(python2.5, have_libpython) + if test "${HAVE_LIBPYTHON2_5}" = yes; then + AC_DEFINE(HAVE_LIBPYTHON2_5, 1, [Define if Python 2.5 is being used.]) + fi + fi + if test ${have_libpython} = no; then + AC_TRY_LIBPYTHON(python2.4, have_libpython) + if test "${HAVE_LIBPYTHON2_4}" = yes; then + AC_DEFINE(HAVE_LIBPYTHON2_4, 1, [Define if Python 2.4 is being used.]) + fi + fi + if test ${have_libpython} = no; then + case "${with_python}" in + yes) + AC_MSG_ERROR([python is missing or unusable]) + ;; + auto) + AC_MSG_WARN([python is missing or unusable; some features may be unavailable.]) + ;; + *) + AC_MSG_ERROR([no usable python found at ${with_python}]) + ;; + esac + CPPFLAGS=$save_CPPFLAGS + LIBS=$save_LIBS + fi +fi + +if test "${have_libpython}" = yes; then + AC_DEFINE(HAVE_PYTHON, 1, [Define if Python interpreter is being linked in.]) + CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_PYTHON_OBS)" + CONFIG_DEPS="$CONFIG_DEPS \$(SUBDIR_PYTHON_DEPS)" + CONFIG_SRCS="$CONFIG_SRCS \$(SUBDIR_PYTHON_SRCS)" + ENABLE_CFLAGS="$ENABLE_CFLAGS \$(SUBDIR_PYTHON_CFLAGS)" + + # Flags needed to compile Python code (taken from python-config --cflags). + # We cannot call python-config directly because it will output whatever was + # used when compiling the Python interpreter itself, including flags which + # would make the python-related objects be compiled differently from the + # rest of GDB (e.g., -O2 and -fPIC). + if test "${GCC}" = yes; then + tentative_python_cflags="-fno-strict-aliasing -DNDEBUG -fwrapv" + fi + + if test "x${tentative_python_cflags}" != x; then + AC_MSG_CHECKING(compiler flags for python code) + for flag in ${tentative_python_cflags}; do + # Check that the compiler accepts it + saved_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $flag" + AC_TRY_COMPILE([],[],PYTHON_CFLAGS="${PYTHON_CFLAGS} $flag",) + CFLAGS="$saved_CFLAGS" + done + AC_MSG_RESULT(${PYTHON_CFLAGS}) + fi +else + # Even if Python support is not compiled in, we need to have this file + # included in order to recognize the GDB command "python". + CONFIG_OBS="$CONFIG_OBS python.o" + CONFIG_SRCS="$CONFIG_SRCS python/python.c" +fi +AC_SUBST(PYTHON_CFLAGS) + # ------------------------- # # Checks for header files. # # ------------------------- # -- cgit v1.2.1