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