|
|
7a6771 |
http://sourceware.org/gdb/wiki/ProjectArcher
|
|
|
7a6771 |
http://sourceware.org/gdb/wiki/ArcherBranchManagement
|
|
|
7a6771 |
|
|
|
7a6771 |
GIT snapshot:
|
|
|
7a6771 |
commit cfee64ee869a6a6e4ab0b64af149d4cf59517d80
|
|
|
7a6771 |
|
|
|
7a6771 |
tromey/python
|
|
|
7a6771 |
|
|
|
7a6771 |
|
|
|
7a6771 |
diff --git a/README.archer b/README.archer
|
|
|
7a6771 |
new file mode 100644
|
|
|
7a6771 |
index 0000000..173b8ea
|
|
|
7a6771 |
--- /dev/null
|
|
|
7a6771 |
+++ b/README.archer
|
|
|
7a6771 |
@@ -0,0 +1,2 @@
|
|
|
7a6771 |
+This branch originally held the Python code for gdb. It still exists
|
|
|
7a6771 |
+because a small amount of code here has not yet been merged upstream.
|
|
|
7a6771 |
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
|
|
|
7a6771 |
index 5af6103..9c69cb0 100644
|
|
|
7a6771 |
--- a/gdb/Makefile.in
|
|
|
7a6771 |
+++ b/gdb/Makefile.in
|
|
|
7a6771 |
@@ -1553,6 +1553,12 @@ stamp-h: $(srcdir)/config.in config.status
|
|
|
7a6771 |
CONFIG_LINKS= \
|
|
|
7a6771 |
$(SHELL) config.status
|
|
|
7a6771 |
|
|
|
7a6771 |
+.gdbinit: $(srcdir)/gdbinit.in config.status
|
|
|
7a6771 |
+ CONFIG_FILES=".gdbinit:gdbinit.in" \
|
|
|
7a6771 |
+ CONFIG_COMMANDS= \
|
|
|
7a6771 |
+ CONFIG_HEADERS= \
|
|
|
7a6771 |
+ $(SHELL) config.status
|
|
|
7a6771 |
+
|
|
|
7a6771 |
config.status: $(srcdir)/configure configure.tgt configure.host ../bfd/development.sh
|
|
|
7a6771 |
$(SHELL) config.status --recheck
|
|
|
7a6771 |
|
|
|
7a6771 |
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
|
|
|
7a6771 |
index 3f23516..b5d6390 100644
|
|
|
7a6771 |
--- a/gdb/data-directory/Makefile.in
|
|
|
7a6771 |
+++ b/gdb/data-directory/Makefile.in
|
|
|
7a6771 |
@@ -66,7 +66,10 @@ PYTHON_FILE_LIST = \
|
|
|
7a6771 |
gdb/unwinder.py \
|
|
|
7a6771 |
gdb/prompt.py \
|
|
|
7a6771 |
gdb/xmethod.py \
|
|
|
7a6771 |
+ gdb/types.py \
|
|
|
7a6771 |
gdb/command/__init__.py \
|
|
|
7a6771 |
+ gdb/command/ignore_errors.py \
|
|
|
7a6771 |
+ gdb/command/pahole.py \
|
|
|
7a6771 |
gdb/command/xmethods.py \
|
|
|
7a6771 |
gdb/command/frame_filters.py \
|
|
|
7a6771 |
gdb/command/unwinders.py \
|
|
|
7a6771 |
@@ -78,6 +81,8 @@ PYTHON_FILE_LIST = \
|
|
|
7a6771 |
gdb/function/as_string.py \
|
|
|
7a6771 |
gdb/function/caller_is.py \
|
|
|
7a6771 |
gdb/function/strfns.py \
|
|
|
7a6771 |
+ gdb/function/caller_is.py \
|
|
|
7a6771 |
+ gdb/function/in_scope.py \
|
|
|
7a6771 |
gdb/printer/__init__.py \
|
|
|
7a6771 |
gdb/printer/bound_registers.py
|
|
|
7a6771 |
|
|
|
7a6771 |
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
|
|
|
7a6771 |
index f5dde61..1d92bd6 100644
|
|
|
7a6771 |
--- a/gdb/doc/gdb.texinfo
|
|
|
7a6771 |
+++ b/gdb/doc/gdb.texinfo
|
|
|
7a6771 |
@@ -1225,6 +1225,16 @@ for remote debugging.
|
|
|
7a6771 |
Run using @var{device} for your program's standard input and output.
|
|
|
7a6771 |
@c FIXME: kingdon thinks there is more to -tty. Investigate.
|
|
|
7a6771 |
|
|
|
7a6771 |
+@item -P
|
|
|
7a6771 |
+@cindex @code{-P}
|
|
|
7a6771 |
+@itemx --python
|
|
|
7a6771 |
+@cindex @code{--python}
|
|
|
7a6771 |
+Change interpretation of command line so that the argument immediately
|
|
|
7a6771 |
+following this switch is taken to be the name of a Python script file.
|
|
|
7a6771 |
+This option stops option processing; subsequent options are passed to
|
|
|
7a6771 |
+Python as @code{sys.argv}. This option is only available if Python
|
|
|
7a6771 |
+scripting support was enabled when @value{GDBN} was configured.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
@c resolve the situation of these eventually
|
|
|
7a6771 |
@item -tui
|
|
|
7a6771 |
@cindex @code{--tui}
|
|
|
7a6771 |
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
|
|
|
7a6771 |
index a17e37d..c56068b 100644
|
|
|
7a6771 |
--- a/gdb/doc/python.texi
|
|
|
7a6771 |
+++ b/gdb/doc/python.texi
|
|
|
7a6771 |
@@ -88,8 +88,6 @@ containing @code{end}. For example:
|
|
|
7a6771 |
|
|
|
7a6771 |
@smallexample
|
|
|
7a6771 |
(@value{GDBP}) python
|
|
|
7a6771 |
-Type python script
|
|
|
7a6771 |
-End with a line saying just "end".
|
|
|
7a6771 |
>print 23
|
|
|
7a6771 |
>end
|
|
|
7a6771 |
23
|
|
|
7a6771 |
diff --git a/gdb/gdb-gdb.gdb.in b/gdb/gdb-gdb.gdb.in
|
|
|
7a6771 |
index 05a38b2..9801fdf 100644
|
|
|
7a6771 |
--- a/gdb/gdb-gdb.gdb.in
|
|
|
7a6771 |
+++ b/gdb/gdb-gdb.gdb.in
|
|
|
7a6771 |
@@ -1,5 +1,15 @@
|
|
|
7a6771 |
echo Setting up the environment for debugging gdb.\n
|
|
|
7a6771 |
|
|
|
7a6771 |
+# Set up the Python library and "require" command.
|
|
|
7a6771 |
+python
|
|
|
7a6771 |
+from os.path import abspath
|
|
|
7a6771 |
+gdb.datadir = abspath ('@srcdir@/python/lib')
|
|
|
7a6771 |
+gdb.pythonlibdir = gdb.datadir
|
|
|
7a6771 |
+gdb.__path__ = [gdb.datadir + '/gdb']
|
|
|
7a6771 |
+sys.path.insert(0, gdb.datadir)
|
|
|
7a6771 |
+end
|
|
|
7a6771 |
+source @srcdir@/python/lib/gdb/__init__.py
|
|
|
7a6771 |
+
|
|
|
7a6771 |
if !$gdb_init_done
|
|
|
7a6771 |
set variable $gdb_init_done = 1
|
|
|
7a6771 |
|
|
|
7a6771 |
diff --git a/gdb/main.c b/gdb/main.c
|
|
|
7a6771 |
index 5477379..b7e413f 100644
|
|
|
7a6771 |
--- a/gdb/main.c
|
|
|
7a6771 |
+++ b/gdb/main.c
|
|
|
7a6771 |
@@ -33,6 +33,7 @@
|
|
|
7a6771 |
|
|
|
7a6771 |
#include "interps.h"
|
|
|
7a6771 |
#include "main.h"
|
|
|
7a6771 |
+#include "python/python.h"
|
|
|
7a6771 |
#include "source.h"
|
|
|
7a6771 |
#include "cli/cli-cmds.h"
|
|
|
7a6771 |
#include "objfiles.h"
|
|
|
7a6771 |
@@ -459,6 +460,8 @@ captured_main (void *data)
|
|
|
7a6771 |
char *cdarg = NULL;
|
|
|
7a6771 |
char *ttyarg = NULL;
|
|
|
7a6771 |
|
|
|
7a6771 |
+ int python_script = 0;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
/* These are static so that we can take their address in an
|
|
|
7a6771 |
initializer. */
|
|
|
7a6771 |
static int print_help;
|
|
|
7a6771 |
@@ -663,10 +666,14 @@ captured_main (void *data)
|
|
|
7a6771 |
{"args", no_argument, &set_args, 1},
|
|
|
7a6771 |
{"l", required_argument, 0, 'l'},
|
|
|
7a6771 |
{"return-child-result", no_argument, &return_child_result, 1},
|
|
|
7a6771 |
+#if HAVE_PYTHON
|
|
|
7a6771 |
+ {"python", no_argument, 0, 'P'},
|
|
|
7a6771 |
+ {"P", no_argument, 0, 'P'},
|
|
|
7a6771 |
+#endif
|
|
|
7a6771 |
{0, no_argument, 0, 0}
|
|
|
7a6771 |
};
|
|
|
7a6771 |
|
|
|
7a6771 |
- while (1)
|
|
|
7a6771 |
+ while (!python_script)
|
|
|
7a6771 |
{
|
|
|
7a6771 |
int option_index;
|
|
|
7a6771 |
|
|
|
7a6771 |
@@ -684,6 +691,9 @@ captured_main (void *data)
|
|
|
7a6771 |
case 0:
|
|
|
7a6771 |
/* Long option that just sets a flag. */
|
|
|
7a6771 |
break;
|
|
|
7a6771 |
+ case 'P':
|
|
|
7a6771 |
+ python_script = 1;
|
|
|
7a6771 |
+ break;
|
|
|
7a6771 |
case OPT_SE:
|
|
|
7a6771 |
symarg = optarg;
|
|
|
7a6771 |
execarg = optarg;
|
|
|
7a6771 |
@@ -864,7 +874,31 @@ captured_main (void *data)
|
|
|
7a6771 |
|
|
|
7a6771 |
/* Now that gdb_init has created the initial inferior, we're in
|
|
|
7a6771 |
position to set args for that inferior. */
|
|
|
7a6771 |
- if (set_args)
|
|
|
7a6771 |
+ if (python_script)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ /* The first argument is a python script to evaluate, and
|
|
|
7a6771 |
+ subsequent arguments are passed to the script for
|
|
|
7a6771 |
+ processing there. */
|
|
|
7a6771 |
+ if (optind >= argc)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ fprintf_unfiltered (gdb_stderr,
|
|
|
7a6771 |
+ _("%s: Python script file name required\n"),
|
|
|
7a6771 |
+ argv[0]);
|
|
|
7a6771 |
+ exit (1);
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ /* FIXME: should handle inferior I/O intelligently here.
|
|
|
7a6771 |
+ E.g., should be possible to run gdb in pipeline and have
|
|
|
7a6771 |
+ Python (and gdb) output go to stderr or file; and if a
|
|
|
7a6771 |
+ prompt is needed, open the tty. */
|
|
|
7a6771 |
+ quiet = 1;
|
|
|
7a6771 |
+ /* FIXME: should read .gdbinit if, and only if, a prompt is
|
|
|
7a6771 |
+ requested by the script. Though... maybe this is not
|
|
|
7a6771 |
+ ideal? */
|
|
|
7a6771 |
+ /* FIXME: likewise, reading in history. */
|
|
|
7a6771 |
+ inhibit_gdbinit = 1;
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ else if (set_args)
|
|
|
7a6771 |
{
|
|
|
7a6771 |
/* The remaining options are the command-line options for the
|
|
|
7a6771 |
inferior. The first one is the sym/exec file, and the rest
|
|
|
7a6771 |
@@ -1127,7 +1161,8 @@ captured_main (void *data)
|
|
|
7a6771 |
|
|
|
7a6771 |
/* Read in the old history after all the command files have been
|
|
|
7a6771 |
read. */
|
|
|
7a6771 |
- init_history ();
|
|
|
7a6771 |
+ if (!python_script)
|
|
|
7a6771 |
+ init_history ();
|
|
|
7a6771 |
|
|
|
7a6771 |
if (batch_flag)
|
|
|
7a6771 |
{
|
|
|
7a6771 |
@@ -1138,13 +1173,25 @@ captured_main (void *data)
|
|
|
7a6771 |
/* Show time and/or space usage. */
|
|
|
7a6771 |
do_cleanups (pre_stat_chain);
|
|
|
7a6771 |
|
|
|
7a6771 |
- /* NOTE: cagney/1999-11-07: There is probably no reason for not
|
|
|
7a6771 |
- moving this loop and the code found in captured_command_loop()
|
|
|
7a6771 |
- into the command_loop() proper. The main thing holding back that
|
|
|
7a6771 |
- change - SET_TOP_LEVEL() - has been eliminated. */
|
|
|
7a6771 |
- while (1)
|
|
|
7a6771 |
+#if HAVE_PYTHON
|
|
|
7a6771 |
+ if (python_script)
|
|
|
7a6771 |
{
|
|
|
7a6771 |
- catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
|
|
|
7a6771 |
+ extern int pagination_enabled;
|
|
|
7a6771 |
+ pagination_enabled = 0;
|
|
|
7a6771 |
+ run_python_script (argc - optind, &argv[optind]);
|
|
|
7a6771 |
+ return 1;
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ else
|
|
|
7a6771 |
+#endif
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ /* NOTE: cagney/1999-11-07: There is probably no reason for not
|
|
|
7a6771 |
+ moving this loop and the code found in captured_command_loop()
|
|
|
7a6771 |
+ into the command_loop() proper. The main thing holding back that
|
|
|
7a6771 |
+ change - SET_TOP_LEVEL() - has been eliminated. */
|
|
|
7a6771 |
+ while (1)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
}
|
|
|
7a6771 |
/* No exit -- exit is through quit_command. */
|
|
|
7a6771 |
}
|
|
|
7a6771 |
@@ -1187,6 +1234,12 @@ print_gdb_help (struct ui_file *stream)
|
|
|
7a6771 |
fputs_unfiltered (_("\
|
|
|
7a6771 |
This is the GNU debugger. Usage:\n\n\
|
|
|
7a6771 |
gdb [options] [executable-file [core-file or process-id]]\n\
|
|
|
7a6771 |
+ gdb [options] --args executable-file [inferior-arguments ...]\n"), stream);
|
|
|
7a6771 |
+#if HAVE_PYTHON
|
|
|
7a6771 |
+ fputs_unfiltered (_("\
|
|
|
7a6771 |
+ gdb [options] [--python|-P] script-file [script-arguments ...]\n"), stream);
|
|
|
7a6771 |
+#endif
|
|
|
7a6771 |
+ fputs_unfiltered (_("\n\
|
|
|
7a6771 |
gdb [options] --args executable-file [inferior-arguments ...]\n\n\
|
|
|
7a6771 |
"), stream);
|
|
|
7a6771 |
fputs_unfiltered (_("\
|
|
|
7a6771 |
@@ -1231,6 +1284,13 @@ Output and user interface control:\n\n\
|
|
|
7a6771 |
#endif
|
|
|
7a6771 |
fputs_unfiltered (_("\
|
|
|
7a6771 |
--dbx DBX compatibility mode.\n\
|
|
|
7a6771 |
+"), stream);
|
|
|
7a6771 |
+#if HAVE_PYTHON
|
|
|
7a6771 |
+ fputs_unfiltered (_("\
|
|
|
7a6771 |
+ --python, -P Following argument is Python script file; remaining\n\
|
|
|
7a6771 |
+ arguments are passed to script.\n"), stream);
|
|
|
7a6771 |
+#endif
|
|
|
7a6771 |
+ fputs_unfiltered (_("\
|
|
|
7a6771 |
-q, --quiet, --silent\n\
|
|
|
7a6771 |
Do not print version number on startup.\n\n\
|
|
|
7a6771 |
"), stream);
|
|
|
7a6771 |
diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
|
|
|
7a6771 |
new file mode 100644
|
|
|
7a6771 |
index 0000000..6fa48ff
|
|
|
7a6771 |
--- /dev/null
|
|
|
7a6771 |
+++ b/gdb/python/lib/gdb/command/ignore_errors.py
|
|
|
7a6771 |
@@ -0,0 +1,37 @@
|
|
|
7a6771 |
+# Ignore errors in user commands.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+# Copyright (C) 2008 Free Software Foundation, Inc.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+# This program is free software; you can redistribute it and/or modify
|
|
|
7a6771 |
+# it under the terms of the GNU General Public License as published by
|
|
|
7a6771 |
+# the Free Software Foundation; either version 3 of the License, or
|
|
|
7a6771 |
+# (at your option) any later version.
|
|
|
7a6771 |
+#
|
|
|
7a6771 |
+# This program is distributed in the hope that it will be useful,
|
|
|
7a6771 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7a6771 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
7a6771 |
+# GNU General Public License for more details.
|
|
|
7a6771 |
+#
|
|
|
7a6771 |
+# You should have received a copy of the GNU General Public License
|
|
|
7a6771 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+import gdb
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+class IgnoreErrorsCommand (gdb.Command):
|
|
|
7a6771 |
+ """Execute a single command, ignoring all errors.
|
|
|
7a6771 |
+Only one-line commands are supported.
|
|
|
7a6771 |
+This is primarily useful in scripts."""
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ def __init__ (self):
|
|
|
7a6771 |
+ super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
|
|
|
7a6771 |
+ gdb.COMMAND_OBSCURE,
|
|
|
7a6771 |
+ # FIXME...
|
|
|
7a6771 |
+ gdb.COMPLETE_COMMAND)
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ def invoke (self, arg, from_tty):
|
|
|
7a6771 |
+ try:
|
|
|
7a6771 |
+ gdb.execute (arg, from_tty)
|
|
|
7a6771 |
+ except:
|
|
|
7a6771 |
+ pass
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+IgnoreErrorsCommand ()
|
|
|
7a6771 |
diff --git a/gdb/python/lib/gdb/command/pahole.py b/gdb/python/lib/gdb/command/pahole.py
|
|
|
7a6771 |
new file mode 100644
|
|
|
7a6771 |
index 0000000..e08eaf5
|
|
|
7a6771 |
--- /dev/null
|
|
|
7a6771 |
+++ b/gdb/python/lib/gdb/command/pahole.py
|
|
|
7a6771 |
@@ -0,0 +1,81 @@
|
|
|
7a6771 |
+# pahole command for gdb
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+# Copyright (C) 2008, 2009, 2012 Free Software Foundation, Inc.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+# This program is free software; you can redistribute it and/or modify
|
|
|
7a6771 |
+# it under the terms of the GNU General Public License as published by
|
|
|
7a6771 |
+# the Free Software Foundation; either version 3 of the License, or
|
|
|
7a6771 |
+# (at your option) any later version.
|
|
|
7a6771 |
+#
|
|
|
7a6771 |
+# This program is distributed in the hope that it will be useful,
|
|
|
7a6771 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7a6771 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
7a6771 |
+# GNU General Public License for more details.
|
|
|
7a6771 |
+#
|
|
|
7a6771 |
+# You should have received a copy of the GNU General Public License
|
|
|
7a6771 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+import gdb
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+class Pahole (gdb.Command):
|
|
|
7a6771 |
+ """Show the holes in a structure.
|
|
|
7a6771 |
+This command takes a single argument, a type name.
|
|
|
7a6771 |
+It prints the type and displays comments showing where holes are."""
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ def __init__ (self):
|
|
|
7a6771 |
+ super (Pahole, self).__init__ ("pahole", gdb.COMMAND_NONE,
|
|
|
7a6771 |
+ gdb.COMPLETE_SYMBOL)
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ def maybe_print_hole(self, bitpos, field_bitpos):
|
|
|
7a6771 |
+ if bitpos != field_bitpos:
|
|
|
7a6771 |
+ hole = field_bitpos - bitpos
|
|
|
7a6771 |
+ print (' /* XXX %d bit hole, try to pack */' % hole)
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ def pahole (self, type, level, name):
|
|
|
7a6771 |
+ if name is None:
|
|
|
7a6771 |
+ name = ''
|
|
|
7a6771 |
+ tag = type.tag
|
|
|
7a6771 |
+ if tag is None:
|
|
|
7a6771 |
+ tag = ''
|
|
|
7a6771 |
+ print ('%sstruct %s {' % (' ' * (2 * level), tag))
|
|
|
7a6771 |
+ bitpos = 0
|
|
|
7a6771 |
+ for field in type.fields ():
|
|
|
7a6771 |
+ # Skip static fields.
|
|
|
7a6771 |
+ if not hasattr (field, ('bitpos')):
|
|
|
7a6771 |
+ continue
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ ftype = field.type.strip_typedefs()
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ self.maybe_print_hole(bitpos, field.bitpos)
|
|
|
7a6771 |
+ bitpos = field.bitpos
|
|
|
7a6771 |
+ if field.bitsize > 0:
|
|
|
7a6771 |
+ fieldsize = field.bitsize
|
|
|
7a6771 |
+ else:
|
|
|
7a6771 |
+ # TARGET_CHAR_BIT here...
|
|
|
7a6771 |
+ fieldsize = 8 * ftype.sizeof
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ # TARGET_CHAR_BIT
|
|
|
7a6771 |
+ print (' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)), end = "")
|
|
|
7a6771 |
+ bitpos = bitpos + fieldsize
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ if ftype.code == gdb.TYPE_CODE_STRUCT:
|
|
|
7a6771 |
+ self.pahole (ftype, level + 1, field.name)
|
|
|
7a6771 |
+ else:
|
|
|
7a6771 |
+ print (' ' * (2 + 2 * level), end = "")
|
|
|
7a6771 |
+ print ('%s %s' % (str (ftype), field.name))
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ if level == 0:
|
|
|
7a6771 |
+ self.maybe_print_hole(bitpos, 8 * type.sizeof)
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ print (' ' * (14 + 2 * level), end = "")
|
|
|
7a6771 |
+ print ('} %s' % name)
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ def invoke (self, arg, from_tty):
|
|
|
7a6771 |
+ type = gdb.lookup_type (arg)
|
|
|
7a6771 |
+ type = type.strip_typedefs ()
|
|
|
7a6771 |
+ if type.code != gdb.TYPE_CODE_STRUCT:
|
|
|
7a6771 |
+ raise (TypeError, '%s is not a struct type' % arg)
|
|
|
7a6771 |
+ print (' ' * 14, end = "")
|
|
|
7a6771 |
+ self.pahole (type, 0, '')
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+Pahole()
|
|
|
7a6771 |
diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
|
|
|
7a6771 |
new file mode 100644
|
|
|
7a6771 |
index 0000000..8742680
|
|
|
7a6771 |
--- /dev/null
|
|
|
7a6771 |
+++ b/gdb/python/lib/gdb/function/in_scope.py
|
|
|
7a6771 |
@@ -0,0 +1,47 @@
|
|
|
7a6771 |
+# In-scope function.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+# Copyright (C) 2008 Free Software Foundation, Inc.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+# This program is free software; you can redistribute it and/or modify
|
|
|
7a6771 |
+# it under the terms of the GNU General Public License as published by
|
|
|
7a6771 |
+# the Free Software Foundation; either version 3 of the License, or
|
|
|
7a6771 |
+# (at your option) any later version.
|
|
|
7a6771 |
+#
|
|
|
7a6771 |
+# This program is distributed in the hope that it will be useful,
|
|
|
7a6771 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7a6771 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
7a6771 |
+# GNU General Public License for more details.
|
|
|
7a6771 |
+#
|
|
|
7a6771 |
+# You should have received a copy of the GNU General Public License
|
|
|
7a6771 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+import gdb
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+class InScope (gdb.Function):
|
|
|
7a6771 |
+ """Return True if all the given variables or macros are in scope.
|
|
|
7a6771 |
+Takes one argument for each variable name to be checked."""
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ def __init__ (self):
|
|
|
7a6771 |
+ super (InScope, self).__init__ ("in_scope")
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ def invoke (self, *vars):
|
|
|
7a6771 |
+ if len (vars) == 0:
|
|
|
7a6771 |
+ raise (TypeError, "in_scope takes at least one argument")
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ # gdb.Value isn't hashable so it can't be put in a map.
|
|
|
7a6771 |
+ # Convert to string first.
|
|
|
7a6771 |
+ wanted = set (map (lambda x: x.string (), vars))
|
|
|
7a6771 |
+ found = set ()
|
|
|
7a6771 |
+ block = gdb.selected_frame ().block ()
|
|
|
7a6771 |
+ while block:
|
|
|
7a6771 |
+ for sym in block:
|
|
|
7a6771 |
+ if (sym.is_argument or sym.is_constant
|
|
|
7a6771 |
+ or sym.is_function or sym.is_variable):
|
|
|
7a6771 |
+ if sym.name in wanted:
|
|
|
7a6771 |
+ found.add (sym.name)
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ block = block.superblock
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ return wanted == found
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+InScope ()
|
|
|
7a6771 |
diff --git a/gdb/python/python.c b/gdb/python/python.c
|
|
|
7a6771 |
index 621e201..703a1a0 100644
|
|
|
7a6771 |
--- a/gdb/python/python.c
|
|
|
7a6771 |
+++ b/gdb/python/python.c
|
|
|
7a6771 |
@@ -95,6 +95,8 @@ const struct extension_language_defn extension_language_python =
|
|
|
7a6771 |
#include "linespec.h"
|
|
|
7a6771 |
#include "source.h"
|
|
|
7a6771 |
#include "version.h"
|
|
|
7a6771 |
+#include "inferior.h"
|
|
|
7a6771 |
+#include "gdbthread.h"
|
|
|
7a6771 |
#include "target.h"
|
|
|
7a6771 |
#include "gdbthread.h"
|
|
|
7a6771 |
#include "interps.h"
|
|
|
7a6771 |
@@ -1263,6 +1265,92 @@ gdbpy_print_stack (void)
|
|
|
7a6771 |
|
|
|
7a6771 |
/* Return the current Progspace.
|
|
|
7a6771 |
There always is one. */
|
|
|
7a6771 |
+/* True if 'gdb -P' was used, false otherwise. */
|
|
|
7a6771 |
+static int running_python_script;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+/* True if we are currently in a call to 'gdb.cli', false otherwise. */
|
|
|
7a6771 |
+static int in_cli;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+/* Enter the command loop. */
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+static PyObject *
|
|
|
7a6771 |
+gdbpy_cli (PyObject *unused1, PyObject *unused2)
|
|
|
7a6771 |
+{
|
|
|
7a6771 |
+ if (! running_python_script || in_cli)
|
|
|
7a6771 |
+ return PyErr_Format (PyExc_RuntimeError, "cannot invoke CLI recursively");
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ if (ui_out_is_mi_like_p (current_uiout))
|
|
|
7a6771 |
+ return PyErr_Format (PyExc_RuntimeError, _("Cannot invoke CLI from MI."));
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ in_cli = 1;
|
|
|
7a6771 |
+ /* See captured_command_loop. */
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ /* Give the interpreter a chance to print a prompt. */
|
|
|
7a6771 |
+ interp_pre_command_loop (top_level_interpreter ());
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ /* Now it's time to start the event loop. */
|
|
|
7a6771 |
+ start_event_loop ();
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ in_cli = 0;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ Py_RETURN_NONE;
|
|
|
7a6771 |
+}
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+/* Set up the Python argument vector and evaluate a script. This is
|
|
|
7a6771 |
+ used to implement 'gdb -P'. */
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+void
|
|
|
7a6771 |
+run_python_script (int argc, char **argv)
|
|
|
7a6771 |
+{
|
|
|
7a6771 |
+ FILE *input;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ /* We never free this, since we plan to exit at the end. */
|
|
|
7a6771 |
+ ensure_python_env (get_current_arch (), current_language);
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ running_python_script = 1;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+#if PYTHON_ABI_VERSION < 3
|
|
|
7a6771 |
+ PySys_SetArgv (argc - 1, argv + 1);
|
|
|
7a6771 |
+#else
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ wchar_t **wargv = (wchar_t **) alloca (sizeof (*wargv) * (argc + 1));
|
|
|
7a6771 |
+ int i;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ for (i = 1; i < argc; i++)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ size_t len = mbstowcs (NULL, argv[i], 0);
|
|
|
7a6771 |
+ /* Python-related GDB sources are built with -DNDEBUG
|
|
|
7a6771 |
+ https://sourceware.org/bugzilla/show_bug.cgi?id=20445 */
|
|
|
7a6771 |
+ size_t len2 ATTRIBUTE_UNUSED;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ if (len == (size_t) -1)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ fprintf (stderr, "Invalid multibyte argument #%d \"%s\"\n",
|
|
|
7a6771 |
+ i, argv[i]);
|
|
|
7a6771 |
+ exit (1);
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ wargv[i] = (wchar_t *) alloca (sizeof (**wargv) * (len + 1));
|
|
|
7a6771 |
+ len2 = mbstowcs (wargv[i], argv[i], len + 1);
|
|
|
7a6771 |
+ assert (len2 == len);
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ wargv[argc] = NULL;
|
|
|
7a6771 |
+ PySys_SetArgv (argc - 1, wargv + 1);
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+#endif
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ input = fopen (argv[0], "r");
|
|
|
7a6771 |
+ if (! input)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ fprintf (stderr, "could not open %s: %s\n", argv[0], strerror (errno));
|
|
|
7a6771 |
+ exit (1);
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ PyRun_SimpleFile (input, argv[0]);
|
|
|
7a6771 |
+ fclose (input);
|
|
|
7a6771 |
+ exit (0);
|
|
|
7a6771 |
+}
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+
|
|
|
7a6771 |
|
|
|
7a6771 |
static PyObject *
|
|
|
7a6771 |
gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2)
|
|
|
7a6771 |
@@ -1981,6 +2069,8 @@ PyMethodDef python_GdbMethods[] =
|
|
|
7a6771 |
Evaluate command, a string, as a gdb CLI command. Optionally returns\n\
|
|
|
7a6771 |
a Python String containing the output of the command if to_string is\n\
|
|
|
7a6771 |
set to True." },
|
|
|
7a6771 |
+ { "cli", gdbpy_cli, METH_NOARGS,
|
|
|
7a6771 |
+ "Enter the gdb CLI" },
|
|
|
7a6771 |
{ "parameter", gdbpy_parameter, METH_VARARGS,
|
|
|
7a6771 |
"Return a gdb parameter's value" },
|
|
|
7a6771 |
|
|
|
7a6771 |
diff --git a/gdb/python/python.h b/gdb/python/python.h
|
|
|
7a6771 |
index b810187..a3620ab 100644
|
|
|
7a6771 |
--- a/gdb/python/python.h
|
|
|
7a6771 |
+++ b/gdb/python/python.h
|
|
|
7a6771 |
@@ -25,4 +25,6 @@
|
|
|
7a6771 |
/* This is all that python exports to gdb. */
|
|
|
7a6771 |
extern const struct extension_language_defn extension_language_python;
|
|
|
7a6771 |
|
|
|
7a6771 |
+extern void run_python_script (int argc, char **argv);
|
|
|
7a6771 |
+
|
|
|
7a6771 |
#endif /* GDB_PYTHON_H */
|
|
|
7a6771 |
diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
|
|
|
7a6771 |
index 2fdd9e3..391900d 100644
|
|
|
7a6771 |
--- a/gdb/testsuite/gdb.gdb/selftest.exp
|
|
|
7a6771 |
+++ b/gdb/testsuite/gdb.gdb/selftest.exp
|
|
|
7a6771 |
@@ -87,6 +87,10 @@ proc do_steps_and_nexts {} {
|
|
|
7a6771 |
set description "step over cmdarg_vec initialization"
|
|
|
7a6771 |
set command "step"
|
|
|
7a6771 |
}
|
|
|
7a6771 |
+ -re ".*python_script = 0.*$gdb_prompt $" {
|
|
|
7a6771 |
+ set description "step over python_script initialization"
|
|
|
7a6771 |
+ set command "step"
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
-re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" {
|
|
|
7a6771 |
set description "next over make_command_stats_cleanup and everything it calls"
|
|
|
7a6771 |
set command "next"
|
|
|
7a6771 |
diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
|
|
|
7a6771 |
index b5a4682..d5451a6 100644
|
|
|
7a6771 |
--- a/gdb/testsuite/gdb.python/py-frame.exp
|
|
|
7a6771 |
+++ b/gdb/testsuite/gdb.python/py-frame.exp
|
|
|
7a6771 |
@@ -95,6 +95,8 @@ gdb_test "python print ('result = %s' % f0.read_var ('a'))" " = 1" "test Frame.r
|
|
|
7a6771 |
|
|
|
7a6771 |
gdb_test "python print ('result = %s' % (gdb.selected_frame () == f1))" " = True" "test gdb.selected_frame"
|
|
|
7a6771 |
|
|
|
7a6771 |
+gdb_test "python print ('result = %s' % (f0.block ()))" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
|
|
|
7a6771 |
+
|
|
|
7a6771 |
# Can read SP register.
|
|
|
7a6771 |
gdb_test "python print ('result = %s' % (gdb.selected_frame ().read_register ('sp') == gdb.parse_and_eval ('\$sp')))" \
|
|
|
7a6771 |
" = True" \
|
|
|
7a6771 |
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
|
|
|
7a6771 |
index 57a9ba1..d90d85a 100644
|
|
|
7a6771 |
--- a/gdb/testsuite/gdb.python/py-value.exp
|
|
|
7a6771 |
+++ b/gdb/testsuite/gdb.python/py-value.exp
|
|
|
7a6771 |
@@ -397,6 +397,15 @@ proc test_value_after_death {} {
|
|
|
7a6771 |
"print value's type"
|
|
|
7a6771 |
}
|
|
|
7a6771 |
|
|
|
7a6771 |
+# Regression test for a cast failure. The bug was that if we cast a
|
|
|
7a6771 |
+# value to its own type, gdb could crash. This happened because we
|
|
|
7a6771 |
+# could end up double-freeing a struct value.
|
|
|
7a6771 |
+proc test_cast_regression {} {
|
|
|
7a6771 |
+ gdb_test "python v = gdb.Value(5)" "" "create value for cast test"
|
|
|
7a6771 |
+ gdb_test "python v = v.cast(v.type)" "" "cast value for cast test"
|
|
|
7a6771 |
+ gdb_test "python print(v)" "5" "print value for cast test"
|
|
|
7a6771 |
+}
|
|
|
7a6771 |
+
|
|
|
7a6771 |
# Regression test for invalid subscript operations. The bug was that
|
|
|
7a6771 |
# the type of the value was not being checked before allowing a
|
|
|
7a6771 |
# subscript operation to proceed.
|
|
|
7a6771 |
@@ -526,6 +535,7 @@ test_value_in_inferior
|
|
|
7a6771 |
test_inferior_function_call
|
|
|
7a6771 |
test_lazy_strings
|
|
|
7a6771 |
test_value_after_death
|
|
|
7a6771 |
+test_cast_regression
|
|
|
7a6771 |
|
|
|
7a6771 |
# Test either C or C++ values.
|
|
|
7a6771 |
|