Re: v3 of GDB hooks for debugging GCC

2013-08-27 Thread Jeff Law

On 08/26/2013 12:42 PM, David Malcolm wrote:

The patch also adds me a maintainer of gdbhooks.py into the MAINTAINERS
file.  (There doesn't seem to be any sort order to the maintainer part
of that file, should there be?)

Finally, I added a copyright header to the new file (part of GCC, FSF
assignee, GPLv3 or later).

OK for trunk?

Yes.  This is good.

Thanks,

jeff


Re: v3 of GDB hooks for debugging GCC

2013-08-27 Thread David Malcolm
On Tue, 2013-08-27 at 09:58 -0600, Jeff Law wrote:
 On 08/26/2013 12:42 PM, David Malcolm wrote:
  The patch also adds me a maintainer of gdbhooks.py into the MAINTAINERS
  file.  (There doesn't seem to be any sort order to the maintainer part
  of that file, should there be?)
 
  Finally, I added a copyright header to the new file (part of GCC, FSF
  assignee, GPLv3 or later).
 
  OK for trunk?
 Yes.  This is good.

Thanks; committed to trunk as r202040.



v3 of GDB hooks for debugging GCC

2013-08-26 Thread David Malcolm
On Wed, 2013-08-21 at 15:01 -0600, Tom Tromey wrote:
  David == David Malcolm dmalc...@redhat.com writes:
 
 Tom Naughty.
 
 David We chatted about this at Cauldron; I haven't yet had a chance to
 David implement the magic bullet approach we discussed there.  In the
 David meantime, is there a API I can call to determine how safe this kludge
 David is?
 
 Not right now.  You can just call the function and catch the exception
 that occurs if it can't be done.
 
 I think you can still run into trouble sometimes.  For example if the
 user puts a breakpoint in one of the functions used by the
 pretty-printer, and then does bt, hitting the breakpoint while
 printing the backtrace... not sure what happens then, maybe a crash.
 
 Tom I think you could set up the safe-path in the gcc .gdbinit.
 
 David Interesting idea - but .gdbinit itself seems to get declined, so I 
 don't
 David think this can help.
 
 Haha, I didn't think of that :-)

But you were on the right track... if one marks gcc's .gdbinit as
loadable, then gdb can happily *import* (rather than autoload) the
python hooks without needing the user to grant extra permission.

I'm attaching a revised patch that reworks things to use this scheme, by
adding a python import line into the configure[.ac] hook that generates
builddir/gcc/.gdbinit : all that a gcc hacker has to do to use the
python hooks now is to ensure that their ~/.gdbinit script contains a
line like this:

   add-auto-load-safe-path /absolute/path/to/build/gcc

and it all should just work.  You need this already to get the
pre-existing gdbinit hooks to work with a recent gdb that has the
autoload protection.  [I renamed the file from gdb-hooks.py to
gdbhooks.py so that it's importable as a python module.  Doing it from
the srcdir avoids having to copy the file to the builddir].

So in this scheme, the Python hooks piggyback on top of the older gdb
hooks.  Hope that's OK.  As noted earlier in the thread, the Python
hooks can be disabled by running:

 (gdb) disable pretty-printer .* gcc
 7 printers disabled

The patch also adds me a maintainer of gdbhooks.py into the MAINTAINERS
file.  (There doesn't seem to be any sort order to the maintainer part
of that file, should there be?)

Finally, I added a copyright header to the new file (part of GCC, FSF
assignee, GPLv3 or later).

OK for trunk?

Dave
commit 9ef4a9c7474b56f19bfa49905944931e52e95514
Author: David Malcolm dmalc...@redhat.com
Date:   Wed Aug 21 15:45:55 2013 -0400

initial version of gdb hooks

	* MAINTAINERS (gdbhooks.py): Add myself as maintainer

gcc/
	* gdbhooks.py: New.
	* configure.ac (gdbinit.in): Add import of gcc/gdbhooks.py.
	* configure: Regenerate.

diff --git a/MAINTAINERS b/MAINTAINERS
index 78b288f..50ede75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -256,6 +256,7 @@ testsuite		Rainer Orth		r...@cebitec.uni-bielefeld.de
 testsuite		Mike Stump		mikest...@comcast.net
 testsuite		Janis Johnson		jani...@codesourcery.com
 register allocation	Vladimir Makarov	vmaka...@redhat.com
+gdbhooks.py		David Malcolm		dmalc...@redhat.com
 
 Note that individuals who maintain parts of the compiler need approval to
 check in changes outside of the parts of the compiler they maintain.
diff --git a/gcc/configure b/gcc/configure
index ec662f5..c6bc3a6 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -27397,6 +27397,7 @@ if test x$subdirs != x; then
 	done
 fi
 echo source ${srcdir}/gdbinit.in  .gdbinit
+echo python import sys; sys.path.append('${srcdir}'); import gdbhooks  .gdbinit
 
 gcc_tooldir='$(libsubdir)/$(libsubdir_to_prefix)$(target_noncanonical)'
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 62d3053..5d3e5ad 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -5181,6 +5181,7 @@ if test x$subdirs != x; then
 	done
 fi
 echo source ${srcdir}/gdbinit.in  .gdbinit
+echo python import sys; sys.path.append('${srcdir}'); import gdbhooks  .gdbinit
 
 gcc_tooldir='$(libsubdir)/$(libsubdir_to_prefix)$(target_noncanonical)'
 AC_SUBST(gcc_tooldir)
diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
new file mode 100644
index 000..3d69b11
--- /dev/null
+++ b/gcc/gdbhooks.py
@@ -0,0 +1,397 @@
+# Python hooks for gdb for debugging GCC
+# Copyright (C) 2013 Free Software Foundation, Inc.
+
+# Contributed by David Malcolm dmalc...@redhat.com
+
+# This file is part of GCC.
+
+# GCC 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, or (at your option) any later
+# version.
+
+# GCC 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 GCC; see the file COPYING3.  If not see
+# http://www.gnu.org/licenses/.
+
+
+Enabling