|
|
6240d7 |
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
|
|
|
6240d7 |
From: Fedora GDB patches <invalid@email.com>
|
|
|
6240d7 |
Date: Fri, 27 Oct 2017 21:07:50 +0200
|
|
|
6240d7 |
Subject: gdb-archer.patch
|
|
|
6240d7 |
|
|
|
6240d7 |
;; Python patches of: http://sourceware.org/gdb/wiki/ProjectArcher
|
|
|
6240d7 |
;;=push
|
|
|
6240d7 |
|
|
|
6240d7 |
http://sourceware.org/gdb/wiki/ProjectArcher
|
|
|
6240d7 |
http://sourceware.org/gdb/wiki/ArcherBranchManagement
|
|
|
6240d7 |
|
|
|
6240d7 |
GIT snapshot:
|
|
|
6240d7 |
commit 718a1618b2f691a7f407213bb50f100ac59f91c3
|
|
|
6240d7 |
|
|
|
6240d7 |
tromey/python
|
|
|
6240d7 |
|
|
|
6240d7 |
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
|
|
|
6240d7 |
--- a/gdb/Makefile.in
|
|
|
6240d7 |
+++ b/gdb/Makefile.in
|
|
|
6240d7 |
@@ -2082,6 +2082,12 @@ stamp-h: $(srcdir)/config.in config.status
|
|
|
6240d7 |
CONFIG_LINKS= \
|
|
|
6240d7 |
$(SHELL) config.status
|
|
|
6240d7 |
|
|
|
6240d7 |
+.gdbinit: $(srcdir)/gdbinit.in config.status
|
|
|
6240d7 |
+ CONFIG_FILES=".gdbinit:gdbinit.in" \
|
|
|
6240d7 |
+ CONFIG_COMMANDS= \
|
|
|
6240d7 |
+ CONFIG_HEADERS= \
|
|
|
6240d7 |
+ $(SHELL) config.status
|
|
|
6240d7 |
+
|
|
|
6240d7 |
config.status: $(srcdir)/configure configure.nat configure.tgt configure.host ../bfd/development.sh
|
|
|
6240d7 |
$(SHELL) config.status --recheck
|
|
|
6240d7 |
|
|
|
6240d7 |
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
|
|
|
6240d7 |
--- a/gdb/data-directory/Makefile.in
|
|
|
6240d7 |
+++ b/gdb/data-directory/Makefile.in
|
|
|
6240d7 |
@@ -80,6 +80,7 @@ PYTHON_FILE_LIST = \
|
|
|
6240d7 |
gdb/unwinder.py \
|
|
|
6240d7 |
gdb/xmethod.py \
|
|
|
6240d7 |
gdb/command/__init__.py \
|
|
|
6240d7 |
+ gdb/command/ignore_errors.py \
|
|
|
6240d7 |
gdb/command/explore.py \
|
|
|
6240d7 |
gdb/command/backtrace.py \
|
|
|
6240d7 |
gdb/command/frame_filters.py \
|
|
|
6240d7 |
@@ -92,6 +93,8 @@ PYTHON_FILE_LIST = \
|
|
|
6240d7 |
gdb/function/as_string.py \
|
|
|
6240d7 |
gdb/function/caller_is.py \
|
|
|
6240d7 |
gdb/function/strfns.py \
|
|
|
6240d7 |
+ gdb/function/caller_is.py \
|
|
|
6240d7 |
+ gdb/function/in_scope.py \
|
|
|
6240d7 |
gdb/printer/__init__.py \
|
|
|
6240d7 |
gdb/printer/bound_registers.py
|
|
|
6240d7 |
|
|
|
6240d7 |
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
|
|
|
6240d7 |
--- a/gdb/doc/gdb.texinfo
|
|
|
6240d7 |
+++ b/gdb/doc/gdb.texinfo
|
|
|
6240d7 |
@@ -1251,6 +1251,16 @@ for remote debugging.
|
|
|
6240d7 |
Run using @var{device} for your program's standard input and output.
|
|
|
6240d7 |
@c FIXME: kingdon thinks there is more to -tty. Investigate.
|
|
|
6240d7 |
|
|
|
6240d7 |
+@item -P
|
|
|
6240d7 |
+@cindex @code{-P}
|
|
|
6240d7 |
+@itemx --python
|
|
|
6240d7 |
+@cindex @code{--python}
|
|
|
6240d7 |
+Change interpretation of command line so that the argument immediately
|
|
|
6240d7 |
+following this switch is taken to be the name of a Python script file.
|
|
|
6240d7 |
+This option stops option processing; subsequent options are passed to
|
|
|
6240d7 |
+Python as @code{sys.argv}. This option is only available if Python
|
|
|
6240d7 |
+scripting support was enabled when @value{GDBN} was configured.
|
|
|
6240d7 |
+
|
|
|
6240d7 |
@c resolve the situation of these eventually
|
|
|
6240d7 |
@item -tui
|
|
|
6240d7 |
@cindex @code{--tui}
|
|
|
6240d7 |
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
|
|
|
6240d7 |
--- a/gdb/doc/python.texi
|
|
|
6240d7 |
+++ b/gdb/doc/python.texi
|
|
|
6240d7 |
@@ -90,8 +90,6 @@ containing @code{end}. For example:
|
|
|
6240d7 |
|
|
|
6240d7 |
@smallexample
|
|
|
6240d7 |
(@value{GDBP}) python
|
|
|
6240d7 |
-Type python script
|
|
|
6240d7 |
-End with a line saying just "end".
|
|
|
6240d7 |
>print 23
|
|
|
6240d7 |
>end
|
|
|
6240d7 |
23
|
|
|
6240d7 |
diff --git a/gdb/gdb-gdb.gdb.in b/gdb/gdb-gdb.gdb.in
|
|
|
6240d7 |
--- a/gdb/gdb-gdb.gdb.in
|
|
|
6240d7 |
+++ b/gdb/gdb-gdb.gdb.in
|
|
|
6240d7 |
@@ -1,5 +1,15 @@
|
|
|
6240d7 |
echo Setting up the environment for debugging gdb.\n
|
|
|
6240d7 |
|
|
|
6240d7 |
+# Set up the Python library and "require" command.
|
|
|
6240d7 |
+python
|
|
|
6240d7 |
+from os.path import abspath
|
|
|
6240d7 |
+gdb.datadir = abspath ('@srcdir@/python/lib')
|
|
|
6240d7 |
+gdb.pythonlibdir = gdb.datadir
|
|
|
6240d7 |
+gdb.__path__ = [gdb.datadir + '/gdb']
|
|
|
6240d7 |
+sys.path.insert(0, gdb.datadir)
|
|
|
6240d7 |
+end
|
|
|
6240d7 |
+source @srcdir@/python/lib/gdb/__init__.py
|
|
|
6240d7 |
+
|
|
|
6240d7 |
if !$gdb_init_done
|
|
|
6240d7 |
set variable $gdb_init_done = 1
|
|
|
6240d7 |
|
|
|
6240d7 |
diff --git a/gdb/main.c b/gdb/main.c
|
|
|
6240d7 |
--- a/gdb/main.c
|
|
|
6240d7 |
+++ b/gdb/main.c
|
|
|
6240d7 |
@@ -33,6 +33,7 @@
|
|
|
6240d7 |
|
|
|
6240d7 |
#include "interps.h"
|
|
|
6240d7 |
#include "main.h"
|
|
|
6240d7 |
+#include "python/python.h"
|
|
|
6240d7 |
#include "source.h"
|
|
|
6240d7 |
#include "cli/cli-cmds.h"
|
|
|
6240d7 |
#include "objfiles.h"
|
|
|
6240d7 |
@@ -478,7 +479,7 @@ exec_or_core_file_attach (const char *filename, int from_tty)
|
|
|
6240d7 |
}
|
|
|
6240d7 |
|
|
|
6240d7 |
static void
|
|
|
6240d7 |
-captured_main_1 (struct captured_main_args *context)
|
|
|
6240d7 |
+captured_main_1 (struct captured_main_args *context, int &python_script)
|
|
|
6240d7 |
{
|
|
|
6240d7 |
int argc = context->argc;
|
|
|
6240d7 |
char **argv = context->argv;
|
|
|
6240d7 |
@@ -698,10 +699,14 @@ captured_main_1 (struct captured_main_args *context)
|
|
|
6240d7 |
{"args", no_argument, &set_args, 1},
|
|
|
6240d7 |
{"l", required_argument, 0, 'l'},
|
|
|
6240d7 |
{"return-child-result", no_argument, &return_child_result, 1},
|
|
|
6240d7 |
+#if HAVE_PYTHON
|
|
|
6240d7 |
+ {"python", no_argument, 0, 'P'},
|
|
|
6240d7 |
+ {"P", no_argument, 0, 'P'},
|
|
|
6240d7 |
+#endif
|
|
|
6240d7 |
{0, no_argument, 0, 0}
|
|
|
6240d7 |
};
|
|
|
6240d7 |
|
|
|
6240d7 |
- while (1)
|
|
|
6240d7 |
+ while (!python_script)
|
|
|
6240d7 |
{
|
|
|
6240d7 |
int option_index;
|
|
|
6240d7 |
|
|
|
6240d7 |
@@ -719,6 +724,9 @@ captured_main_1 (struct captured_main_args *context)
|
|
|
6240d7 |
case 0:
|
|
|
6240d7 |
/* Long option that just sets a flag. */
|
|
|
6240d7 |
break;
|
|
|
6240d7 |
+ case 'P':
|
|
|
6240d7 |
+ python_script = 1;
|
|
|
6240d7 |
+ break;
|
|
|
6240d7 |
case OPT_SE:
|
|
|
6240d7 |
symarg = optarg;
|
|
|
6240d7 |
execarg = optarg;
|
|
|
6240d7 |
@@ -898,7 +906,31 @@ captured_main_1 (struct captured_main_args *context)
|
|
|
6240d7 |
|
|
|
6240d7 |
/* Now that gdb_init has created the initial inferior, we're in
|
|
|
6240d7 |
position to set args for that inferior. */
|
|
|
6240d7 |
- if (set_args)
|
|
|
6240d7 |
+ if (python_script)
|
|
|
6240d7 |
+ {
|
|
|
6240d7 |
+ /* The first argument is a python script to evaluate, and
|
|
|
6240d7 |
+ subsequent arguments are passed to the script for
|
|
|
6240d7 |
+ processing there. */
|
|
|
6240d7 |
+ if (optind >= argc)
|
|
|
6240d7 |
+ {
|
|
|
6240d7 |
+ fprintf_unfiltered (gdb_stderr,
|
|
|
6240d7 |
+ _("%s: Python script file name required\n"),
|
|
|
6240d7 |
+ argv[0]);
|
|
|
6240d7 |
+ exit (1);
|
|
|
6240d7 |
+ }
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ /* FIXME: should handle inferior I/O intelligently here.
|
|
|
6240d7 |
+ E.g., should be possible to run gdb in pipeline and have
|
|
|
6240d7 |
+ Python (and gdb) output go to stderr or file; and if a
|
|
|
6240d7 |
+ prompt is needed, open the tty. */
|
|
|
6240d7 |
+ quiet = 1;
|
|
|
6240d7 |
+ /* FIXME: should read .gdbinit if, and only if, a prompt is
|
|
|
6240d7 |
+ requested by the script. Though... maybe this is not
|
|
|
6240d7 |
+ ideal? */
|
|
|
6240d7 |
+ /* FIXME: likewise, reading in history. */
|
|
|
6240d7 |
+ inhibit_gdbinit = 1;
|
|
|
6240d7 |
+ }
|
|
|
6240d7 |
+ else if (set_args)
|
|
|
6240d7 |
{
|
|
|
6240d7 |
/* The remaining options are the command-line options for the
|
|
|
6240d7 |
inferior. The first one is the sym/exec file, and the rest
|
|
|
6240d7 |
@@ -1199,7 +1231,8 @@ captured_main_1 (struct captured_main_args *context)
|
|
|
6240d7 |
|
|
|
6240d7 |
/* Read in the old history after all the command files have been
|
|
|
6240d7 |
read. */
|
|
|
6240d7 |
- init_history ();
|
|
|
6240d7 |
+ if (!python_script)
|
|
|
6240d7 |
+ init_history ();
|
|
|
6240d7 |
|
|
|
6240d7 |
if (batch_flag)
|
|
|
6240d7 |
{
|
|
|
6240d7 |
@@ -1215,24 +1248,37 @@ static void
|
|
|
6240d7 |
captured_main (void *data)
|
|
|
6240d7 |
{
|
|
|
6240d7 |
struct captured_main_args *context = (struct captured_main_args *) data;
|
|
|
6240d7 |
+ int python_script = 0;
|
|
|
6240d7 |
|
|
|
6240d7 |
- captured_main_1 (context);
|
|
|
6240d7 |
+ captured_main_1 (context, python_script);
|
|
|
6240d7 |
|
|
|
6240d7 |
- /* NOTE: cagney/1999-11-07: There is probably no reason for not
|
|
|
6240d7 |
- moving this loop and the code found in captured_command_loop()
|
|
|
6240d7 |
- into the command_loop() proper. The main thing holding back that
|
|
|
6240d7 |
- change - SET_TOP_LEVEL() - has been eliminated. */
|
|
|
6240d7 |
- while (1)
|
|
|
6240d7 |
+#if HAVE_PYTHON
|
|
|
6240d7 |
+ if (python_script)
|
|
|
6240d7 |
{
|
|
|
6240d7 |
- TRY
|
|
|
6240d7 |
- {
|
|
|
6240d7 |
- captured_command_loop ();
|
|
|
6240d7 |
- }
|
|
|
6240d7 |
- CATCH (ex, RETURN_MASK_ALL)
|
|
|
6240d7 |
+ extern int pagination_enabled;
|
|
|
6240d7 |
+ pagination_enabled = 0;
|
|
|
6240d7 |
+ run_python_script (context->argc - optind, &context->argv[optind]);
|
|
|
6240d7 |
+ return;
|
|
|
6240d7 |
+ }
|
|
|
6240d7 |
+ else
|
|
|
6240d7 |
+#endif
|
|
|
6240d7 |
+ {
|
|
|
6240d7 |
+ /* NOTE: cagney/1999-11-07: There is probably no reason for not
|
|
|
6240d7 |
+ moving this loop and the code found in captured_command_loop()
|
|
|
6240d7 |
+ into the command_loop() proper. The main thing holding back that
|
|
|
6240d7 |
+ change - SET_TOP_LEVEL() - has been eliminated. */
|
|
|
6240d7 |
+ while (1)
|
|
|
6240d7 |
{
|
|
|
6240d7 |
- exception_print (gdb_stderr, ex);
|
|
|
6240d7 |
+ TRY
|
|
|
6240d7 |
+ {
|
|
|
6240d7 |
+ captured_command_loop ();
|
|
|
6240d7 |
+ }
|
|
|
6240d7 |
+ CATCH (ex, RETURN_MASK_ALL)
|
|
|
6240d7 |
+ {
|
|
|
6240d7 |
+ exception_print (gdb_stderr, ex);
|
|
|
6240d7 |
+ }
|
|
|
6240d7 |
+ END_CATCH
|
|
|
6240d7 |
}
|
|
|
6240d7 |
- END_CATCH
|
|
|
6240d7 |
}
|
|
|
6240d7 |
/* No exit -- exit is through quit_command. */
|
|
|
6240d7 |
}
|
|
|
6240d7 |
@@ -1275,6 +1321,12 @@ print_gdb_help (struct ui_file *stream)
|
|
|
6240d7 |
fputs_unfiltered (_("\
|
|
|
6240d7 |
This is the GNU debugger. Usage:\n\n\
|
|
|
6240d7 |
gdb [options] [executable-file [core-file or process-id]]\n\
|
|
|
6240d7 |
+ gdb [options] --args executable-file [inferior-arguments ...]\n"), stream);
|
|
|
6240d7 |
+#if HAVE_PYTHON
|
|
|
6240d7 |
+ fputs_unfiltered (_("\
|
|
|
6240d7 |
+ gdb [options] [--python|-P] script-file [script-arguments ...]\n"), stream);
|
|
|
6240d7 |
+#endif
|
|
|
6240d7 |
+ fputs_unfiltered (_("\n\
|
|
|
6240d7 |
gdb [options] --args executable-file [inferior-arguments ...]\n\n\
|
|
|
6240d7 |
"), stream);
|
|
|
6240d7 |
fputs_unfiltered (_("\
|
|
|
6240d7 |
@@ -1320,6 +1372,13 @@ Output and user interface control:\n\n\
|
|
|
6240d7 |
#endif
|
|
|
6240d7 |
fputs_unfiltered (_("\
|
|
|
6240d7 |
--dbx DBX compatibility mode.\n\
|
|
|
6240d7 |
+"), stream);
|
|
|
6240d7 |
+#if HAVE_PYTHON
|
|
|
6240d7 |
+ fputs_unfiltered (_("\
|
|
|
6240d7 |
+ --python, -P Following argument is Python script file; remaining\n\
|
|
|
6240d7 |
+ arguments are passed to script.\n"), stream);
|
|
|
6240d7 |
+#endif
|
|
|
6240d7 |
+ fputs_unfiltered (_("\
|
|
|
6240d7 |
-q, --quiet, --silent\n\
|
|
|
6240d7 |
Do not print version number on startup.\n\n\
|
|
|
6240d7 |
"), stream);
|
|
|
6240d7 |
diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
|
|
|
6240d7 |
new file mode 100644
|
|
|
6240d7 |
--- /dev/null
|
|
|
6240d7 |
+++ b/gdb/python/lib/gdb/command/ignore_errors.py
|
|
|
6240d7 |
@@ -0,0 +1,37 @@
|
|
|
6240d7 |
+# Ignore errors in user commands.
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+# Copyright (C) 2008 Free Software Foundation, Inc.
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+# This program is free software; you can redistribute it and/or modify
|
|
|
6240d7 |
+# it under the terms of the GNU General Public License as published by
|
|
|
6240d7 |
+# the Free Software Foundation; either version 3 of the License, or
|
|
|
6240d7 |
+# (at your option) any later version.
|
|
|
6240d7 |
+#
|
|
|
6240d7 |
+# This program is distributed in the hope that it will be useful,
|
|
|
6240d7 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
6240d7 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
6240d7 |
+# GNU General Public License for more details.
|
|
|
6240d7 |
+#
|
|
|
6240d7 |
+# You should have received a copy of the GNU General Public License
|
|
|
6240d7 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+import gdb
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+class IgnoreErrorsCommand (gdb.Command):
|
|
|
6240d7 |
+ """Execute a single command, ignoring all errors.
|
|
|
6240d7 |
+Only one-line commands are supported.
|
|
|
6240d7 |
+This is primarily useful in scripts."""
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ def __init__ (self):
|
|
|
6240d7 |
+ super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
|
|
|
6240d7 |
+ gdb.COMMAND_OBSCURE,
|
|
|
6240d7 |
+ # FIXME...
|
|
|
6240d7 |
+ gdb.COMPLETE_COMMAND)
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ def invoke (self, arg, from_tty):
|
|
|
6240d7 |
+ try:
|
|
|
6240d7 |
+ gdb.execute (arg, from_tty)
|
|
|
6240d7 |
+ except:
|
|
|
6240d7 |
+ pass
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+IgnoreErrorsCommand ()
|
|
|
6240d7 |
diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
|
|
|
6240d7 |
new file mode 100644
|
|
|
6240d7 |
--- /dev/null
|
|
|
6240d7 |
+++ b/gdb/python/lib/gdb/function/in_scope.py
|
|
|
6240d7 |
@@ -0,0 +1,47 @@
|
|
|
6240d7 |
+# In-scope function.
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+# Copyright (C) 2008 Free Software Foundation, Inc.
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+# This program is free software; you can redistribute it and/or modify
|
|
|
6240d7 |
+# it under the terms of the GNU General Public License as published by
|
|
|
6240d7 |
+# the Free Software Foundation; either version 3 of the License, or
|
|
|
6240d7 |
+# (at your option) any later version.
|
|
|
6240d7 |
+#
|
|
|
6240d7 |
+# This program is distributed in the hope that it will be useful,
|
|
|
6240d7 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
6240d7 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
6240d7 |
+# GNU General Public License for more details.
|
|
|
6240d7 |
+#
|
|
|
6240d7 |
+# You should have received a copy of the GNU General Public License
|
|
|
6240d7 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+import gdb
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+class InScope (gdb.Function):
|
|
|
6240d7 |
+ """Return True if all the given variables or macros are in scope.
|
|
|
6240d7 |
+Takes one argument for each variable name to be checked."""
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ def __init__ (self):
|
|
|
6240d7 |
+ super (InScope, self).__init__ ("in_scope")
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ def invoke (self, *vars):
|
|
|
6240d7 |
+ if len (vars) == 0:
|
|
|
6240d7 |
+ raise (TypeError, "in_scope takes at least one argument")
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ # gdb.Value isn't hashable so it can't be put in a map.
|
|
|
6240d7 |
+ # Convert to string first.
|
|
|
6240d7 |
+ wanted = set (map (lambda x: x.string (), vars))
|
|
|
6240d7 |
+ found = set ()
|
|
|
6240d7 |
+ block = gdb.selected_frame ().block ()
|
|
|
6240d7 |
+ while block:
|
|
|
6240d7 |
+ for sym in block:
|
|
|
6240d7 |
+ if (sym.is_argument or sym.is_constant
|
|
|
6240d7 |
+ or sym.is_function or sym.is_variable):
|
|
|
6240d7 |
+ if sym.name in wanted:
|
|
|
6240d7 |
+ found.add (sym.name)
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ block = block.superblock
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ return wanted == found
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+InScope ()
|
|
|
6240d7 |
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
|
|
|
6240d7 |
--- a/gdb/python/python-internal.h
|
|
|
6240d7 |
+++ b/gdb/python/python-internal.h
|
|
|
6240d7 |
@@ -709,6 +709,9 @@ private:
|
|
|
6240d7 |
PyThreadState *m_save;
|
|
|
6240d7 |
};
|
|
|
6240d7 |
|
|
|
6240d7 |
+struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
|
|
|
6240d7 |
+ const struct language_defn *language);
|
|
|
6240d7 |
+
|
|
|
6240d7 |
extern struct gdbarch *python_gdbarch;
|
|
|
6240d7 |
extern const struct language_defn *python_language;
|
|
|
6240d7 |
|
|
|
6240d7 |
diff --git a/gdb/python/python.c b/gdb/python/python.c
|
|
|
6240d7 |
--- a/gdb/python/python.c
|
|
|
6240d7 |
+++ b/gdb/python/python.c
|
|
|
6240d7 |
@@ -94,6 +94,8 @@ const struct extension_language_defn extension_language_python =
|
|
|
6240d7 |
#include "linespec.h"
|
|
|
6240d7 |
#include "source.h"
|
|
|
6240d7 |
#include "common/version.h"
|
|
|
6240d7 |
+#include "inferior.h"
|
|
|
6240d7 |
+#include "gdbthread.h"
|
|
|
6240d7 |
#include "target.h"
|
|
|
6240d7 |
#include "gdbthread.h"
|
|
|
6240d7 |
#include "interps.h"
|
|
|
6240d7 |
@@ -235,6 +237,29 @@ gdbpy_enter::~gdbpy_enter ()
|
|
|
6240d7 |
restore_active_ext_lang (m_previous_active);
|
|
|
6240d7 |
}
|
|
|
6240d7 |
|
|
|
6240d7 |
+static void
|
|
|
6240d7 |
+restore_python_env (void *p)
|
|
|
6240d7 |
+{
|
|
|
6240d7 |
+ gdbpy_enter *env = (gdbpy_enter *) p;
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ delete env;
|
|
|
6240d7 |
+}
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+/* Called before entering the Python interpreter to install the
|
|
|
6240d7 |
+ current language and architecture to be used for Python values.
|
|
|
6240d7 |
+ Also set the active extension language for GDB so that SIGINT's
|
|
|
6240d7 |
+ are directed our way, and if necessary install the right SIGINT
|
|
|
6240d7 |
+ handler. */
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+struct cleanup *
|
|
|
6240d7 |
+ensure_python_env (struct gdbarch *gdbarch,
|
|
|
6240d7 |
+ const struct language_defn *language)
|
|
|
6240d7 |
+{
|
|
|
6240d7 |
+ gdbpy_enter *env = new gdbpy_enter (gdbarch, language);
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ return make_cleanup (restore_python_env, env);
|
|
|
6240d7 |
+}
|
|
|
6240d7 |
+
|
|
|
6240d7 |
/* Set the quit flag. */
|
|
|
6240d7 |
|
|
|
6240d7 |
static void
|
|
|
6240d7 |
@@ -1283,6 +1308,92 @@ gdbpy_print_stack_or_quit ()
|
|
|
6240d7 |
|
|
|
6240d7 |
|
|
|
6240d7 |
|
|
|
6240d7 |
+/* True if 'gdb -P' was used, false otherwise. */
|
|
|
6240d7 |
+static int running_python_script;
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+/* True if we are currently in a call to 'gdb.cli', false otherwise. */
|
|
|
6240d7 |
+static int in_cli;
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+/* Enter the command loop. */
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+static PyObject *
|
|
|
6240d7 |
+gdbpy_cli (PyObject *unused1, PyObject *unused2)
|
|
|
6240d7 |
+{
|
|
|
6240d7 |
+ if (! running_python_script || in_cli)
|
|
|
6240d7 |
+ return PyErr_Format (PyExc_RuntimeError, "cannot invoke CLI recursively");
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ if (current_uiout->is_mi_like_p ())
|
|
|
6240d7 |
+ return PyErr_Format (PyExc_RuntimeError, _("Cannot invoke CLI from MI."));
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ in_cli = 1;
|
|
|
6240d7 |
+ /* See captured_command_loop. */
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ /* Give the interpreter a chance to print a prompt. */
|
|
|
6240d7 |
+ interp_pre_command_loop (top_level_interpreter ());
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ /* Now it's time to start the event loop. */
|
|
|
6240d7 |
+ start_event_loop ();
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ in_cli = 0;
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ Py_RETURN_NONE;
|
|
|
6240d7 |
+}
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+/* Set up the Python argument vector and evaluate a script. This is
|
|
|
6240d7 |
+ used to implement 'gdb -P'. */
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+void
|
|
|
6240d7 |
+run_python_script (int argc, char **argv)
|
|
|
6240d7 |
+{
|
|
|
6240d7 |
+ FILE *input;
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ /* We never free this, since we plan to exit at the end. */
|
|
|
6240d7 |
+ ensure_python_env (get_current_arch (), current_language);
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ running_python_script = 1;
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+#if PYTHON_ABI_VERSION < 3
|
|
|
6240d7 |
+ PySys_SetArgv (argc - 1, argv + 1);
|
|
|
6240d7 |
+#else
|
|
|
6240d7 |
+ {
|
|
|
6240d7 |
+ wchar_t **wargv = (wchar_t **) alloca (sizeof (*wargv) * (argc + 1));
|
|
|
6240d7 |
+ int i;
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ for (i = 1; i < argc; i++)
|
|
|
6240d7 |
+ {
|
|
|
6240d7 |
+ size_t len = mbstowcs (NULL, argv[i], 0);
|
|
|
6240d7 |
+ /* Python-related GDB sources are built with -DNDEBUG
|
|
|
6240d7 |
+ https://sourceware.org/bugzilla/show_bug.cgi?id=20445 */
|
|
|
6240d7 |
+ size_t len2 ATTRIBUTE_UNUSED;
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ if (len == (size_t) -1)
|
|
|
6240d7 |
+ {
|
|
|
6240d7 |
+ fprintf (stderr, "Invalid multibyte argument #%d \"%s\"\n",
|
|
|
6240d7 |
+ i, argv[i]);
|
|
|
6240d7 |
+ exit (1);
|
|
|
6240d7 |
+ }
|
|
|
6240d7 |
+ wargv[i] = (wchar_t *) alloca (sizeof (**wargv) * (len + 1));
|
|
|
6240d7 |
+ len2 = mbstowcs (wargv[i], argv[i], len + 1);
|
|
|
6240d7 |
+ assert (len2 == len);
|
|
|
6240d7 |
+ }
|
|
|
6240d7 |
+ wargv[argc] = NULL;
|
|
|
6240d7 |
+ PySys_SetArgv (argc - 1, wargv + 1);
|
|
|
6240d7 |
+ }
|
|
|
6240d7 |
+#endif
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+ input = fopen (argv[0], "r");
|
|
|
6240d7 |
+ if (! input)
|
|
|
6240d7 |
+ {
|
|
|
6240d7 |
+ fprintf (stderr, "could not open %s: %s\n", argv[0], strerror (errno));
|
|
|
6240d7 |
+ exit (1);
|
|
|
6240d7 |
+ }
|
|
|
6240d7 |
+ PyRun_SimpleFile (input, argv[0]);
|
|
|
6240d7 |
+ fclose (input);
|
|
|
6240d7 |
+ exit (0);
|
|
|
6240d7 |
+}
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+
|
|
|
6240d7 |
+
|
|
|
6240d7 |
/* Return a sequence holding all the Progspaces. */
|
|
|
6240d7 |
|
|
|
6240d7 |
static PyObject *
|
|
|
6240d7 |
@@ -1937,6 +2048,8 @@ PyMethodDef python_GdbMethods[] =
|
|
|
6240d7 |
Evaluate command, a string, as a gdb CLI command. Optionally returns\n\
|
|
|
6240d7 |
a Python String containing the output of the command if to_string is\n\
|
|
|
6240d7 |
set to True." },
|
|
|
6240d7 |
+ { "cli", gdbpy_cli, METH_NOARGS,
|
|
|
6240d7 |
+ "Enter the gdb CLI" },
|
|
|
6240d7 |
{ "parameter", gdbpy_parameter, METH_VARARGS,
|
|
|
6240d7 |
"Return a gdb parameter's value" },
|
|
|
6240d7 |
|
|
|
6240d7 |
diff --git a/gdb/python/python.h b/gdb/python/python.h
|
|
|
6240d7 |
--- a/gdb/python/python.h
|
|
|
6240d7 |
+++ b/gdb/python/python.h
|
|
|
6240d7 |
@@ -25,7 +25,10 @@
|
|
|
6240d7 |
/* This is all that python exports to gdb. */
|
|
|
6240d7 |
extern const struct extension_language_defn extension_language_python;
|
|
|
6240d7 |
|
|
|
6240d7 |
+
|
|
|
6240d7 |
/* Command element for the 'python' command. */
|
|
|
6240d7 |
extern cmd_list_element *python_cmd_element;
|
|
|
6240d7 |
|
|
|
6240d7 |
+extern void run_python_script (int argc, char **argv);
|
|
|
6240d7 |
+
|
|
|
6240d7 |
#endif /* PYTHON_PYTHON_H */
|
|
|
6240d7 |
diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
|
|
|
6240d7 |
--- a/gdb/testsuite/gdb.python/py-frame.exp
|
|
|
6240d7 |
+++ b/gdb/testsuite/gdb.python/py-frame.exp
|
|
|
6240d7 |
@@ -95,6 +95,8 @@ gdb_test "python print ('result = %s' % f0.read_var ('a'))" " = 1" "test Frame.r
|
|
|
6240d7 |
|
|
|
6240d7 |
gdb_test "python print ('result = %s' % (gdb.selected_frame () == f1))" " = True" "test gdb.selected_frame"
|
|
|
6240d7 |
|
|
|
6240d7 |
+gdb_test "python print ('result = %s' % (f0.block ()))" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
|
|
|
6240d7 |
+
|
|
|
6240d7 |
# Can read SP register.
|
|
|
6240d7 |
gdb_test "python print ('result = %s' % (gdb.selected_frame ().read_register ('sp') == gdb.parse_and_eval ('\$sp')))" \
|
|
|
6240d7 |
" = True" \
|
|
|
6240d7 |
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
|
|
|
6240d7 |
--- a/gdb/testsuite/gdb.python/py-value.exp
|
|
|
6240d7 |
+++ b/gdb/testsuite/gdb.python/py-value.exp
|
|
|
6240d7 |
@@ -399,6 +399,15 @@ proc test_value_after_death {} {
|
|
|
6240d7 |
"print value's type"
|
|
|
6240d7 |
}
|
|
|
6240d7 |
|
|
|
6240d7 |
+# Regression test for a cast failure. The bug was that if we cast a
|
|
|
6240d7 |
+# value to its own type, gdb could crash. This happened because we
|
|
|
6240d7 |
+# could end up double-freeing a struct value.
|
|
|
6240d7 |
+proc test_cast_regression {} {
|
|
|
6240d7 |
+ gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
|
|
|
6240d7 |
+ gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
|
|
|
6240d7 |
+ gdb_test "python print(v)" "5" "print value for cast test"
|
|
|
6240d7 |
+}
|
|
|
6240d7 |
+
|
|
|
6240d7 |
# Regression test for invalid subscript operations. The bug was that
|
|
|
6240d7 |
# the type of the value was not being checked before allowing a
|
|
|
6240d7 |
# subscript operation to proceed.
|
|
|
6240d7 |
@@ -585,6 +594,7 @@ test_value_in_inferior
|
|
|
6240d7 |
test_value_from_buffer
|
|
|
6240d7 |
test_inferior_function_call
|
|
|
6240d7 |
test_value_after_death
|
|
|
6240d7 |
+test_cast_regression
|
|
|
6240d7 |
|
|
|
6240d7 |
# Test either C or C++ values.
|
|
|
6240d7 |
|
|
|
6240d7 |
diff --git a/gdb/varobj.c b/gdb/varobj.c
|
|
|
6240d7 |
--- a/gdb/varobj.c
|
|
|
6240d7 |
+++ b/gdb/varobj.c
|
|
|
6240d7 |
@@ -217,6 +217,14 @@ is_root_p (const struct varobj *var)
|
|
|
6240d7 |
}
|
|
|
6240d7 |
|
|
|
6240d7 |
#ifdef HAVE_PYTHON
|
|
|
6240d7 |
+/* Helper function to install a Python environment suitable for
|
|
|
6240d7 |
+ use during operations on VAR. */
|
|
|
6240d7 |
+struct cleanup *
|
|
|
6240d7 |
+varobj_ensure_python_env (const struct varobj *var)
|
|
|
6240d7 |
+{
|
|
|
6240d7 |
+ return ensure_python_env (var->root->exp->gdbarch,
|
|
|
6240d7 |
+ var->root->exp->language_defn);
|
|
|
6240d7 |
+}
|
|
|
6240d7 |
|
|
|
6240d7 |
/* See python-internal.h. */
|
|
|
6240d7 |
gdbpy_enter_varobj::gdbpy_enter_varobj (const struct varobj *var)
|
|
|
6240d7 |
diff --git a/gdb/varobj.h b/gdb/varobj.h
|
|
|
6240d7 |
--- a/gdb/varobj.h
|
|
|
6240d7 |
+++ b/gdb/varobj.h
|
|
|
6240d7 |
@@ -328,6 +328,8 @@ extern bool varobj_has_more (const struct varobj *var, int to);
|
|
|
6240d7 |
|
|
|
6240d7 |
extern bool varobj_is_dynamic_p (const struct varobj *var);
|
|
|
6240d7 |
|
|
|
6240d7 |
+extern struct cleanup *varobj_ensure_python_env (const struct varobj *var);
|
|
|
6240d7 |
+
|
|
|
6240d7 |
extern bool varobj_default_value_is_changeable_p (const struct varobj *var);
|
|
|
6240d7 |
extern bool varobj_value_is_changeable_p (const struct varobj *var);
|
|
|
6240d7 |
|