public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] make gdbhooks.py idempotent with respect to reloading
@ 2019-06-28 11:52 Vladislav Ivanishin
  2019-07-02 22:39 ` Vladislav Ivanishin
  0 siblings, 1 reply; 3+ messages in thread
From: Vladislav Ivanishin @ 2019-06-28 11:52 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 610 bytes --]

Hi!

It is nice to be able to reload the pretty printers and convenience
functions from gdbhooks.py without exiting GDB: reloading cc1 takes
several seconds (plus, the debugging session is lost).

Previously:

   (gdb) python import imp; imp.reload(gdbhooks);
   RuntimeError: pretty-printer already registered: gcc

Fixing this turned out easier than I expected.
    (gdb) py help (gdb.printing)
revealed, that we can pass replace parameter to register_pretty_printer
(which is False by default).

With the patch:

    (gdb) python import imp; imp.reload(gdbhooks);
    Successfully loaded GDB hooks for GCC


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-make-gdbhooks.py-idempotent-with-respect-to-reloadin.patch --]
[-- Type: text/x-patch, Size: 599 bytes --]

gcc/

        * gdbhooks.py: Pass replace=True to
        gdb.printing.register_pretty_printer.
---
 gcc/gdbhooks.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index 15a5ceaa56f..26a09749aa3 100644
--- a/gcc/gdbhooks.py
+++ b/gcc/gdbhooks.py
@@ -602,7 +602,8 @@ def build_pretty_printer():
 
 gdb.printing.register_pretty_printer(
     gdb.current_objfile(),
-    build_pretty_printer())
+    build_pretty_printer(),
+    replace=True)
 
 def find_gcc_source_dir():
     # Use location of global "g" to locate the source tree
-- 
2.22.0


[-- Attachment #3: Type: text/plain, Size: 138 bytes --]


OK?

BTW, perhaps I should also add a convenience function for 'import imp;
imp.reload(gdbhooks)' or something to that effect?

-- 
Vlad

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] make gdbhooks.py idempotent with respect to reloading
  2019-06-28 11:52 [PATCH] make gdbhooks.py idempotent with respect to reloading Vladislav Ivanishin
@ 2019-07-02 22:39 ` Vladislav Ivanishin
  2019-07-23 14:23   ` [committed] " Vladislav Ivanishin
  0 siblings, 1 reply; 3+ messages in thread
From: Vladislav Ivanishin @ 2019-07-02 22:39 UTC (permalink / raw)
  To: gcc-patches; +Cc: David Malcolm

[-- Attachment #1: Type: text/plain, Size: 1730 bytes --]

Vladislav Ivanishin <vlad@ispras.ru> writes:

> Hi!
>
> It is nice to be able to reload the pretty printers and convenience
> functions from gdbhooks.py without exiting GDB: reloading cc1 takes
> several seconds (plus, the debugging session is lost).
>
> Previously:
>
>    (gdb) python import imp; imp.reload(gdbhooks);
>    RuntimeError: pretty-printer already registered: gcc
>
> Fixing this turned out easier than I expected.
>     (gdb) py help (gdb.printing)
> revealed, that we can pass replace parameter to register_pretty_printer
> (which is False by default).
>
> With the patch:
>
>     (gdb) python import imp; imp.reload(gdbhooks);
>     Successfully loaded GDB hooks for GCC
>
> gcc/
>
>         * gdbhooks.py: Pass replace=True to
>         gdb.printing.register_pretty_printer.
> ---
>  gcc/gdbhooks.py | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
> index 15a5ceaa56f..26a09749aa3 100644
> --- a/gcc/gdbhooks.py
> +++ b/gcc/gdbhooks.py
> @@ -602,7 +602,8 @@ def build_pretty_printer():
>  
>  gdb.printing.register_pretty_printer(
>      gdb.current_objfile(),
> -    build_pretty_printer())
> +    build_pretty_printer(),
> +    replace=True)
>  
>  def find_gcc_source_dir():
>      # Use location of global "g" to locate the source tree
> -- 
> 2.22.0
>
>
> OK?

I actually think, that change is obvious.  It has proven useful and I've
not run into any issues with it.

> BTW, perhaps I should also add a convenience function for 'import imp;
> imp.reload(gdbhooks)' or something to that effect?

I added a user-defined gdb command and a short alias for it.  I think,
this is obvious too, but would feel more comfortable if someone OKs it.
Dave?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gdbinit.in-add-reload-gdbhooks-rh-command.patch --]
[-- Type: text/x-patch, Size: 830 bytes --]

[PATCH] gdbinit.in: add reload-gdbhooks (rh) command

gcc/
        * gdbinit.in (reload-gdbhooks): New command with an attached doc string.
        (rh): New alias for it.
---
 gcc/gdbinit.in | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gcc/gdbinit.in b/gcc/gdbinit.in
index cec55f86749..2454441f859 100644
--- a/gcc/gdbinit.in
+++ b/gcc/gdbinit.in
@@ -216,6 +216,16 @@ is emitted (as opposed to those warnings that are suppressed by
 command-line options).
 end
 
+define reload-gdbhooks
+python import imp; imp.reload(gdbhooks)
+end
+
+document reload-gdbhooks
+Load the gdbhooks.py module again in order to pick up any changes made to it.
+end
+
+alias rh = reload-gdbhooks
+
 # Define some macros helpful to gdb when it is expanding macros.
 macro define __FILE__ "gdb"
 macro define __LINE__ 1
-- 
2.22.0


[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


Thanks,
Vlad

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [committed] Re: [PATCH] make gdbhooks.py idempotent with respect to reloading
  2019-07-02 22:39 ` Vladislav Ivanishin
@ 2019-07-23 14:23   ` Vladislav Ivanishin
  0 siblings, 0 replies; 3+ messages in thread
From: Vladislav Ivanishin @ 2019-07-23 14:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: David Malcolm

Vladislav Ivanishin <vlad@ispras.ru> writes:

> Vladislav Ivanishin <vlad@ispras.ru> writes:
>
>> Hi!
>>
>> It is nice to be able to reload the pretty printers and convenience
>> functions from gdbhooks.py without exiting GDB: reloading cc1 takes
>> several seconds (plus, the debugging session is lost).
>>
>> Previously:
>>
>>    (gdb) python import imp; imp.reload(gdbhooks);
>>    RuntimeError: pretty-printer already registered: gcc
>>
>> Fixing this turned out easier than I expected.
>>     (gdb) py help (gdb.printing)
>> revealed, that we can pass replace parameter to register_pretty_printer
>> (which is False by default).
>>
>> With the patch:
>>
>>     (gdb) python import imp; imp.reload(gdbhooks);
>>     Successfully loaded GDB hooks for GCC
>>
>> gcc/
>>
>>         * gdbhooks.py: Pass replace=True to
>>         gdb.printing.register_pretty_printer.
>> ---
>>  gcc/gdbhooks.py | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
>> index 15a5ceaa56f..26a09749aa3 100644
>> --- a/gcc/gdbhooks.py
>> +++ b/gcc/gdbhooks.py
>> @@ -602,7 +602,8 @@ def build_pretty_printer():
>>  
>>  gdb.printing.register_pretty_printer(
>>      gdb.current_objfile(),
>> -    build_pretty_printer())
>> +    build_pretty_printer(),
>> +    replace=True)
>>  
>>  def find_gcc_source_dir():
>>      # Use location of global "g" to locate the source tree
>> -- 
>> 2.22.0
>>
>>
>> OK?
>
> I actually think, that change is obvious.  It has proven useful and I've
> not run into any issues with it.
>
>> BTW, perhaps I should also add a convenience function for 'import imp;
>> imp.reload(gdbhooks)' or something to that effect?
>
> I added a user-defined gdb command and a short alias for it.  I think,
> this is obvious too, but would feel more comfortable if someone OKs it.
> Dave?
>
> [PATCH] gdbinit.in: add reload-gdbhooks (rh) command
>
> gcc/
>         * gdbinit.in (reload-gdbhooks): New command with an attached doc string.
>         (rh): New alias for it.
> ---
>  gcc/gdbinit.in | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/gcc/gdbinit.in b/gcc/gdbinit.in
> index cec55f86749..2454441f859 100644
> --- a/gcc/gdbinit.in
> +++ b/gcc/gdbinit.in
> @@ -216,6 +216,16 @@ is emitted (as opposed to those warnings that are suppressed by
>  command-line options).
>  end
>  
> +define reload-gdbhooks
> +python import imp; imp.reload(gdbhooks)
> +end
> +
> +document reload-gdbhooks
> +Load the gdbhooks.py module again in order to pick up any changes made to it.
> +end
> +
> +alias rh = reload-gdbhooks
> +
>  # Define some macros helpful to gdb when it is expanding macros.
>  macro define __FILE__ "gdb"
>  macro define __LINE__ 1

Committed both patches as obvious, revisions 273737 and 273738
respectively.

-- 
Vlad

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-23 14:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-28 11:52 [PATCH] make gdbhooks.py idempotent with respect to reloading Vladislav Ivanishin
2019-07-02 22:39 ` Vladislav Ivanishin
2019-07-23 14:23   ` [committed] " Vladislav Ivanishin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).