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