Python Pretty Printers get disabled on libstdc++ reload by GDB (PR libstdc++/68448)
diff mbox

Message ID 20151119202151.GA7640@host1.jankratochvil.net
State New
Headers show

Commit Message

Jan Kratochvil Nov. 19, 2015, 8:21 p.m. UTC
Hi,

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68448
https://bugzilla.redhat.com/show_bug.cgi?id=1279406

echo -e '#include <vector>\nint main(){std::vector<int> l;\nreturn 0;}'|g++ -g -Wall -x c++ -;gdb -q ./a.out -batch -ex 'b 3' -ex r -ex 'p l' -ex r -ex 'p l'

Actual:
[...]
$1 = std::vector of length 0, capacity 0
[...]
$2 = {<std::_Vector_base<int, std::allocator<int> >> = {_M_impl = {<std::allocator<int>> = {<__gnu_cxx::new_allocator<int>> = {<No data fields>}, <No data fields>}, _M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0}}, <No data fields>}

Expected:
[...]
$1 = std::vector of length 0, capacity 0
[...]
$2 = std::vector of length 0, capacity 0


Thanks,
Jan
* python/hook.in: Call register_libstdcxx_printers.
	* python/libstdcxx/v6/__init__.py: Wrap it to
	register_libstdcxx_printers.

Comments

Jan Kratochvil Nov. 20, 2015, 5:28 p.m. UTC | #1
On Thu, 19 Nov 2015 21:21:51 +0100, Jan Kratochvil wrote:
> 	* python/hook.in: Call register_libstdcxx_printers.
> 	* python/libstdcxx/v6/__init__.py: Wrap it to
> 	register_libstdcxx_printers.
[...]
> -import libstdcxx.v6
> +# Call a function as a plain import would not execute body of the included file
> +# on repeated reloads of this object file.
> +from libstdcxx.v6 import register_libstdcxx_printers
> +register_libstdcxx_printers(gdb.current_objfile())

Jonathan Wakely mentioned:
	[libstdc++] Refactor python/hook.in
	https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02518.html
	From: Siva Chandra <sivachandra@google.com>
	Message-ID: <CAGyQ6gyqMPZyJMN6326qtAzSTAAc1azodk5Jx3ZtMoFYM5puOQ@mail.gmail.com>
	https://gcc.gnu.org/r215726

That change introduced this regression.  This patch does not undo it, goal of
the patch by Siva Chandra - minimizing hook.in - stays achieved.


Jan
Jonathan Wakely Nov. 20, 2015, 5:40 p.m. UTC | #2
On 20/11/15 18:28 +0100, Jan Kratochvil wrote:
>On Thu, 19 Nov 2015 21:21:51 +0100, Jan Kratochvil wrote:
>> 	* python/hook.in: Call register_libstdcxx_printers.
>> 	* python/libstdcxx/v6/__init__.py: Wrap it to
>> 	register_libstdcxx_printers.
>[...]
>> -import libstdcxx.v6
>> +# Call a function as a plain import would not execute body of the included file
>> +# on repeated reloads of this object file.
>> +from libstdcxx.v6 import register_libstdcxx_printers
>> +register_libstdcxx_printers(gdb.current_objfile())
>
>Jonathan Wakely mentioned:
>	[libstdc++] Refactor python/hook.in
>	https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02518.html
>	From: Siva Chandra <sivachandra@google.com>
>	Message-ID: <CAGyQ6gyqMPZyJMN6326qtAzSTAAc1azodk5Jx3ZtMoFYM5puOQ@mail.gmail.com>
>	https://gcc.gnu.org/r215726
>
>That change introduced this regression.  This patch does not undo it, goal of
>the patch by Siva Chandra - minimizing hook.in - stays achieved.

OK, thanks for checking, Jan.

The patch is OK for trunk and gcc-5-branch.
Jan Kratochvil Nov. 20, 2015, 7:12 p.m. UTC | #3
On Fri, 20 Nov 2015 18:40:46 +0100, Jonathan Wakely wrote:
> The patch is OK for trunk and gcc-5-branch.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68448
trunk:
	https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=230669
5.x:
	https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=230670


Jan

Patch
diff mbox

diff --git a/libstdc++-v3/python/hook.in b/libstdc++-v3/python/hook.in
index 07fe4c6..703b6a7 100644
--- a/libstdc++-v3/python/hook.in
+++ b/libstdc++-v3/python/hook.in
@@ -55,4 +55,7 @@  if gdb.current_objfile () is not None:
     if not dir_ in sys.path:
         sys.path.insert(0, dir_)
 
-import libstdcxx.v6
+# Call a function as a plain import would not execute body of the included file
+# on repeated reloads of this object file.
+from libstdcxx.v6 import register_libstdcxx_printers
+register_libstdcxx_printers(gdb.current_objfile())
diff --git a/libstdc++-v3/python/libstdcxx/v6/__init__.py b/libstdc++-v3/python/libstdcxx/v6/__init__.py
index de3aa72..d8e060c 100644
--- a/libstdc++-v3/python/libstdcxx/v6/__init__.py
+++ b/libstdc++-v3/python/libstdcxx/v6/__init__.py
@@ -15,10 +15,6 @@ 
 
 import gdb
 
-# Load the pretty-printers.
-from .printers import register_libstdcxx_printers
-register_libstdcxx_printers(gdb.current_objfile())
-
 # Load the xmethods if GDB supports them.
 def gdb_has_xmethods():
     try:
@@ -27,6 +23,11 @@  def gdb_has_xmethods():
     except ImportError:
         return False
 
-if gdb_has_xmethods():
-    from .xmethods import register_libstdcxx_xmethods
-    register_libstdcxx_xmethods(gdb.current_objfile())
+def register_libstdcxx_printers(obj):
+    # Load the pretty-printers.
+    from .printers import register_libstdcxx_printers
+    register_libstdcxx_printers(obj)
+
+    if gdb_has_xmethods():
+        from .xmethods import register_libstdcxx_xmethods
+        register_libstdcxx_xmethods(obj)