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