[PATCH 0/2] gdbinit.in fixes

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/2] gdbinit.in fixes

Konstantin Kharlamov
This includes the unmerged previously posted here patch about calling
with `call`. I made a typo in commit message formatting, so I fix it
here.

I'd like to note that I am not subscribed to the list, so please add me
to CC when replying. Thanks in advance.

Konstantin Kharlamov (2):
  gdbinit.in: call a function with "call", not "set"
  gdbinit.in: fix wrong reference to function argument

 gcc/gdbinit.in | 84 +++++++++++++++++++++++++-------------------------
 1 file changed, 42 insertions(+), 42 deletions(-)

--
2.24.0

Reply | Threaded
Open this post in threaded view
|

[PATCH 1/2] gdbinit.in: call a function with "call", not "set"

Konstantin Kharlamov
Last time a command that calls a function of debuggee with "set" was
added is 2013 year. Apparently something has changed since then, since
doing "set foo()" in gdb to call a "foo()" results in error.
Disregarding, it looks wrong to call a function with "set". Let's use
"call" instead.

* (debug_rtx,debug_rtx_list,debug_tree,debug_c_tree,debug_gimple_stmt,
debug_gimple_seq,mpz_out_str,debug_dwarf_die,print_binding_stack,
bitmap_print): Replace "set" with "call"
---
 gcc/gdbinit.in | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/gcc/gdbinit.in b/gcc/gdbinit.in
index 42302aecfe3..a933ddc6141 100644
--- a/gcc/gdbinit.in
+++ b/gcc/gdbinit.in
@@ -26,7 +26,7 @@ Works only when an inferior is executing.
 end
 
 define pr
-set debug_rtx ($)
+call debug_rtx ($)
 end
 
 document pr
@@ -35,7 +35,7 @@ Works only when an inferior is executing.
 end
 
 define prl
-set debug_rtx_list ($, debug_rtx_count)
+call debug_rtx_list ($, debug_rtx_count)
 end
 
 document prl
@@ -50,7 +50,7 @@ it using debug_rtx_list. Usage example: set $foo=debug_rtx_find(first, 42)
 end
 
 define pt
-set debug_tree ($)
+call debug_tree ($)
 end
 
 document pt
@@ -59,7 +59,7 @@ Works only when an inferior is executing.
 end
 
 define pct
-set debug_c_tree ($)
+call debug_c_tree ($)
 end
 
 document pct
@@ -68,7 +68,7 @@ Works only when an inferior is executing.
 end
 
 define pgg
-set debug_gimple_stmt ($)
+call debug_gimple_stmt ($)
 end
 
 document pgg
@@ -77,7 +77,7 @@ Works only when an inferior is executing.
 end
 
 define pgq
-set debug_gimple_seq ($)
+call debug_gimple_seq ($)
 end
 
 document pgq
@@ -86,7 +86,7 @@ Works only when an inferior is executing.
 end
 
 define pgs
-set debug_generic_stmt ($)
+call debug_generic_stmt ($)
 end
 
 document pgs
@@ -95,7 +95,7 @@ Works only when an inferior is executing.
 end
 
 define pge
-set debug_generic_expr ($)
+call debug_generic_expr ($)
 end
 
 document pge
@@ -104,7 +104,7 @@ Works only when an inferior is executing.
 end
 
 define pmz
-set mpz_out_str(stderr, 10, $)
+call mpz_out_str(stderr, 10, $)
 end
 
 document pmz
@@ -140,7 +140,7 @@ Print the name of the type-node that is $.
 end
 
 define pdd
-set debug_dwarf_die ($)
+call debug_dwarf_die ($)
 end
 
 document pdd
@@ -167,7 +167,7 @@ Print the fields of an instruction that is $.
 end
 
 define pbs
-set print_binding_stack ()
+call print_binding_stack ()
 end
 
 document pbs
@@ -176,7 +176,7 @@ including the global binding level.
 end
 
 define pbm
-set bitmap_print (stderr, $, "", "\n")
+call bitmap_print (stderr, $, "", "\n")
 end
 
 document pbm
--
2.24.0

Reply | Threaded
Open this post in threaded view
|

[PATCH 2/2] gdbinit.in: fix wrong reference to function argument

Konstantin Kharlamov
In reply to this post by Konstantin Kharlamov
Gdb documentation says that gdb-defined functions refer to their args as
$arg0…$argN. The just "$" that gdbinit is using here refers to something
else, which results in gdb errors, or even crashes of debuggee. Let's
fix that.

* (debug,debug_rtx,pr,prl,pt,pct,pgg,pgq,pgq,pgs,pge,pmz,ptc,
pdn,ptn,pdd,prc,pi,pbs,pbm,pel,pcfun,trt): replace $ with $arg0
---
 gcc/gdbinit.in | 82 +++++++++++++++++++++++++-------------------------
 1 file changed, 41 insertions(+), 41 deletions(-)

diff --git a/gcc/gdbinit.in b/gcc/gdbinit.in
index a933ddc6141..71a01edaa71 100644
--- a/gcc/gdbinit.in
+++ b/gcc/gdbinit.in
@@ -17,153 +17,153 @@
 # <http://www.gnu.org/licenses/>.
 
 define pp
-call debug ($)
+call debug ($arg0)
 end
 
 document pp
-Print a representation of the GCC data structure that is $.
+Print a representation of the GCC data structure that is $arg0.
 Works only when an inferior is executing.
 end
 
 define pr
-call debug_rtx ($)
+call debug_rtx ($arg0)
 end
 
 document pr
-Print the full structure of the rtx that is $.
+Print the full structure of the rtx that is $arg0.
 Works only when an inferior is executing.
 end
 
 define prl
-call debug_rtx_list ($, debug_rtx_count)
+call debug_rtx_list ($arg0, debug_rtx_count)
 end
 
 document prl
-Print the full structure of all rtx insns beginning at $.
+Print the full structure of all rtx insns beginning at $arg0.
 Works only when an inferior is executing.
 Uses variable debug_rtx_count to control number of insns printed:
-  debug_rtx_count > 0: print from $ on.
-  debug_rtx_count < 0: print a window around $.
+  debug_rtx_count > 0: print from $arg0 on.
+  debug_rtx_count < 0: print a window around $arg0.
 
 There is also debug_rtx_find (rtx, uid) that will scan a list for UID and print
 it using debug_rtx_list. Usage example: set $foo=debug_rtx_find(first, 42)
 end
 
 define pt
-call debug_tree ($)
+call debug_tree ($arg0)
 end
 
 document pt
-Print the full structure of the tree that is $.
+Print the full structure of the tree that is $arg0.
 Works only when an inferior is executing.
 end
 
 define pct
-call debug_c_tree ($)
+call debug_c_tree ($arg0)
 end
 
 document pct
-Print the tree that is $ in C syntax.
+Print the tree that is $arg0 in C syntax.
 Works only when an inferior is executing.
 end
 
 define pgg
-call debug_gimple_stmt ($)
+call debug_gimple_stmt ($arg0)
 end
 
 document pgg
-Print the Gimple statement that is $ in C syntax.
+Print the Gimple statement that is $arg0 in C syntax.
 Works only when an inferior is executing.
 end
 
 define pgq
-call debug_gimple_seq ($)
+call debug_gimple_seq ($arg0)
 end
 
 document pgq
-Print the Gimple sequence that is $ in C syntax.
+Print the Gimple sequence that is $arg0 in C syntax.
 Works only when an inferior is executing.
 end
 
 define pgs
-call debug_generic_stmt ($)
+call debug_generic_stmt ($arg0)
 end
 
 document pgs
-Print the statement that is $ in C syntax.
+Print the statement that is $arg0 in C syntax.
 Works only when an inferior is executing.
 end
 
 define pge
-call debug_generic_expr ($)
+call debug_generic_expr ($arg0)
 end
 
 document pge
-Print the expression that is $ in C syntax.
+Print the expression that is $arg0 in C syntax.
 Works only when an inferior is executing.
 end
 
 define pmz
-call mpz_out_str(stderr, 10, $)
+call mpz_out_str(stderr, 10, $arg0)
 end
 
 document pmz
-Print the mpz value that is $
+Print the mpz value that is $arg0
 Works only when an inferior is executing.
 end
 
 define ptc
-output (enum tree_code) $.base.code
+output (enum tree_code) $arg0.base.code
 echo \n
 end
 
 document ptc
-Print the tree-code of the tree node that is $.
+Print the tree-code of the tree node that is $arg0.
 end
 
 define pdn
-output $.decl_minimal.name->identifier.id.str
+output $arg0.decl_minimal.name->identifier.id.str
 echo \n
 end
 
 document pdn
-Print the name of the decl-node that is $.
+Print the name of the decl-node that is $arg0.
 end
 
 define ptn
-output $.type.name->decl_minimal.name->identifier.id.str
+output $arg0.type.name->decl_minimal.name->identifier.id.str
 echo \n
 end
 
 document ptn
-Print the name of the type-node that is $.
+Print the name of the type-node that is $arg0.
 end
 
 define pdd
-call debug_dwarf_die ($)
+call debug_dwarf_die ($arg0)
 end
 
 document pdd
-Print the dw_die_ref that is in $.
+Print the dw_die_ref that is in $arg0.
 end
 
 define prc
-output (enum rtx_code) $.code
+output (enum rtx_code) $arg0.code
 echo \ (
-output $.mode
+output $arg0.mode
 echo )\n
 end
 
 document prc
-Print the rtx-code and machine mode of the rtx that is $.
+Print the rtx-code and machine mode of the rtx that is $arg0.
 end
 
 define pi
-print $.u.fld[0].rt_rtx@7
+print $arg0.u.fld[0].rt_rtx@7
 end
 
 document pi
-Print the fields of an instruction that is $.
+Print the fields of an instruction that is $arg0.
 end
 
 define pbs
@@ -176,20 +176,20 @@ including the global binding level.
 end
 
 define pbm
-call bitmap_print (stderr, $, "", "\n")
+call bitmap_print (stderr, $arg0, "", "\n")
 end
 
 document pbm
-Dump the bitmap that is in $ as a comma-separated list of numbers.
+Dump the bitmap that is in $arg0 as a comma-separated list of numbers.
 end
 
 define pel
-output expand_location ($)
+output expand_location ($arg0)
 echo \n
 end
 
 document pel
-Print expanded location of $.
+Print expanded location of $arg0.
 end
 
 define pcfun
@@ -202,11 +202,11 @@ Print current function.
 end
 
 define trt
-print ($.typed.type)
+print ($arg0.typed.type)
 end
 
 document trt
-Print TREE_TYPE of the tree node that is $
+Print TREE_TYPE of the tree node that is $arg0
 end
 
 define break-on-diagnostic
--
2.24.0

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] gdbinit.in: fix wrong reference to function argument

Andreas Schwab
On Nov 12 2019, Konstantin Kharlamov wrote:

> Gdb documentation says that gdb-defined functions refer to their args as
> $arg0…$argN. The just "$" that gdbinit is using here refers to something
> else,

That's the last thing printed.

> which results in gdb errors, or even crashes of debuggee. Let's
> fix that.

That breaks all users of these macros, since you are now required to
pass an argument.

Andreas.

--
Andreas Schwab, SUSE Labs, [hidden email]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] gdbinit.in: fix wrong reference to function argument

Konstantin Kharlamov


On Вт, ноя 12, 2019 at 13:50, Andreas Schwab <[hidden email]>
wrote:
> On Nov 12 2019, Konstantin Kharlamov wrote:
>
>>  Gdb documentation says that gdb-defined functions refer to their
>> args as
>>  $arg0…$argN. The just "$" that gdbinit is using here refers to
>> something
>>  else,
>
> That's the last thing printed.

Hmm, okay… Am I missing something…? As I'm reading, this looks
definitely wrong, because the "last thing printed" is just a random
value. To illustrate: I can do a calculation, like `p 2 + 2`, and then
I execute, say, `pgg stmt`, and debuggee crashes because it calls
`debug_gimple_stmt(4)`. That's what happened to me a lot of times until
I figured the problem is in gdbinit.

>>  which results in gdb errors, or even crashes of debuggee. Let's
>>  fix that.
>
> That breaks all users of these macros, since you are now required to
> pass an argument.

I'm definitely missing something. Who are these users, and how can they
make anything useful of these functions if they don't even pass an
argument?

> Andreas.
>
> --
> Andreas Schwab, SUSE Labs, [hidden email]
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA
> B9D7
> "And now for something completely different."


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] gdbinit.in: fix wrong reference to function argument

Andreas Schwab
On Nov 12 2019, Konstantin Kharlamov wrote:

> I'm definitely missing something. Who are these users, and how can they
> make anything useful of these functions if they don't even pass an
> argument?

By printing the desired value.

Andreas.

--
Andreas Schwab, SUSE Labs, [hidden email]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] gdbinit.in: fix wrong reference to function argument

Konstantin Kharlamov


On Вт, ноя 12, 2019 at 14:08, Andreas Schwab <[hidden email]>
wrote:
> On Nov 12 2019, Konstantin Kharlamov wrote:
>
>>  I'm definitely missing something. Who are these users, and how can
>> they
>>  make anything useful of these functions if they don't even pass an
>>  argument?
>
> By printing the desired value.

Hah, okay. Well, in this case their workflow now gonna be 2 times
simpler since they don't have to type in two commands, but only one :)

Besides, I suspect, the number of actual users of this gdbinit is
around zero, otherwise someone would have noticed the warning that gdb
prints on every usage of these functions while the PATCH 1/2 is not
applied.


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] gdbinit.in: fix wrong reference to function argument

Andreas Schwab
On Nov 12 2019, Konstantin Kharlamov wrote:

> Besides, I suspect, the number of actual users of this gdbinit is around
> zero, otherwise someone would have noticed the warning that gdb prints on
> every usage of these functions while the PATCH 1/2 is not applied.

It's easy to ignore it.

Andreas.

--
Andreas Schwab, SUSE Labs, [hidden email]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] gdbinit.in: call a function with "call", not "set"

Segher Boessenkool
In reply to this post by Konstantin Kharlamov
Hi!

On Tue, Nov 12, 2019 at 02:47:33PM +0300, Konstantin Kharlamov wrote:
> Last time a command that calls a function of debuggee with "set" was
> added is 2013 year. Apparently something has changed since then, since
> doing "set foo()" in gdb to call a "foo()" results in error.
> Disregarding, it looks wrong to call a function with "set". Let's use
> "call" instead.

I got a warning, not an error?  Your modified code works fine btw, also
with (at least some) older versions of GDB.

> * (debug_rtx,debug_rtx_list,debug_tree,debug_c_tree,debug_gimple_stmt,
> debug_gimple_seq,mpz_out_str,debug_dwarf_die,print_binding_stack,
> bitmap_print): Replace "set" with "call"

That changelog has multiple problems.  Please use something like this:

2019-11-13  Konstantin Kharlamov  <[hidden email]>

        * gdbinit.in (pr, prl, pt, pct, pgg, pgq, pgs, pge, pmz, pdd, pbs, pbm):
        Use "call" instead of "set".

Looks good to me otherwise, thanks!  (This is not an approval, I am not
maintainer of this part of GCC).


Segher
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] gdbinit.in: fix wrong reference to function argument

Segher Boessenkool
In reply to this post by Konstantin Kharlamov
On Tue, Nov 12, 2019 at 04:17:17PM +0300, Konstantin Kharlamov wrote:

> On Вт, ноя 12, 2019 at 14:08, Andreas Schwab <[hidden email]>
> wrote:
> >On Nov 12 2019, Konstantin Kharlamov wrote:
> >> I'm definitely missing something. Who are these users, and how can
> >>they
> >> make anything useful of these functions if they don't even pass an
> >> argument?
> >
> >By printing the desired value.
>
> Hah, okay. Well, in this case their workflow now gonna be 2 times
> simpler since they don't have to type in two commands, but only one :)

Do we have to type parentheses now?  That more than undoes that gain :-/

> Besides, I suspect, the number of actual users of this gdbinit is
> around zero, otherwise someone would have noticed the warning that gdb
> prints on every usage of these functions while the PATCH 1/2 is not
> applied.

There are users.  There are users who have been used to this behaviour
for many many many years.

People just do (say I have an "rtx insn"):
  p insn
  pr

A new version where you just say
  pr insn
would be nice; something that requires
  pr(insn)
is less nice.

It would be great if you could come up with something that keeps the
old syntax working as well, especially since many of us have to work
with older versions of the gdbinit as well, for years to come.  People
can adjust their work habits of course, but that causes a lot of
friction ;-)


Segher
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] gdbinit.in: fix wrong reference to function argument

Jason Merrill
On Wed, Nov 13, 2019 at 6:39 AM Segher Boessenkool <
[hidden email]> wrote:

> On Tue, Nov 12, 2019 at 04:17:17PM +0300, Konstantin Kharlamov wrote:
> > On Вт, ноя 12, 2019 at 14:08, Andreas Schwab <[hidden email]>
> > wrote:
> > >On Nov 12 2019, Konstantin Kharlamov wrote:
> > >> I'm definitely missing something. Who are these users, and how can
> > >>they
> > >> make anything useful of these functions if they don't even pass an
> > >> argument?
> > >
> > >By printing the desired value.
> >
> > Hah, okay. Well, in this case their workflow now gonna be 2 times
> > simpler since they don't have to type in two commands, but only one :)
>
> Do we have to type parentheses now?  That more than undoes that gain :-/
>
> > Besides, I suspect, the number of actual users of this gdbinit is
> > around zero, otherwise someone would have noticed the warning that gdb
> > prints on every usage of these functions while the PATCH 1/2 is not
> > applied.
>
> There are users.  There are users who have been used to this behaviour
> for many many many years.
>
> People just do (say I have an "rtx insn"):
>   p insn
>   pr
>

Indeed.  I use this constantly.

Jason
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] gdbinit.in: call a function with "call", not "set"

Jeff Law
In reply to this post by Segher Boessenkool
On 11/13/19 4:20 AM, Segher Boessenkool wrote:

> Hi!
>
> On Tue, Nov 12, 2019 at 02:47:33PM +0300, Konstantin Kharlamov wrote:
>> Last time a command that calls a function of debuggee with "set" was
>> added is 2013 year. Apparently something has changed since then, since
>> doing "set foo()" in gdb to call a "foo()" results in error.
>> Disregarding, it looks wrong to call a function with "set". Let's use
>> "call" instead.
>
> I got a warning, not an error?  Your modified code works fine btw, also
> with (at least some) older versions of GDB.
>
>> * (debug_rtx,debug_rtx_list,debug_tree,debug_c_tree,debug_gimple_stmt,
>> debug_gimple_seq,mpz_out_str,debug_dwarf_die,print_binding_stack,
>> bitmap_print): Replace "set" with "call"
>
> That changelog has multiple problems.  Please use something like this:
>
> 2019-11-13  Konstantin Kharlamov  <[hidden email]>
>
> * gdbinit.in (pr, prl, pt, pct, pgg, pgq, pgs, pge, pmz, pdd, pbs, pbm):
> Use "call" instead of "set".
>
> Looks good to me otherwise, thanks!  (This is not an approval, I am not
> maintainer of this part of GCC).
Approved with a fixed ChangeLog.

jeff

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] gdbinit.in: fix wrong reference to function argument

Konstantin Kharlamov
In reply to this post by Jason Merrill


On Ср, ноя 13, 2019 at 15:23, Jason Merrill <[hidden email]>
wrote:

> On Wed, Nov 13, 2019 at 6:39 AM Segher Boessenkool
> <[hidden email]> wrote:
>> On Tue, Nov 12, 2019 at 04:17:17PM +0300, Konstantin Kharlamov wrote:
>>  > On Вт, ноя 12, 2019 at 14:08, Andreas Schwab <[hidden email]>
>>  > wrote:
>>  > >On Nov 12 2019, Konstantin Kharlamov wrote:
>>  > >> I'm definitely missing something. Who are these users, and how
>> can
>>  > >>they
>>  > >> make anything useful of these functions if they don't even
>> pass an
>>  > >> argument?
>>  > >
>>  > >By printing the desired value.
>>  >
>>  > Hah, okay. Well, in this case their workflow now gonna be 2 times
>>  > simpler since they don't have to type in two commands, but only
>> one :)
>>
>>  Do we have to type parentheses now?  That more than undoes that
>> gain :-/
>>
>>  > Besides, I suspect, the number of actual users of this gdbinit is
>>  > around zero, otherwise someone would have noticed the warning
>> that gdb
>>  > prints on every usage of these functions while the PATCH 1/2 is
>> not
>>  > applied.
>>
>>  There are users.  There are users who have been used to this
>> behaviour
>>  for many many many years.
>>
>>  People just do (say I have an "rtx insn"):
>>    p insn
>>    pr
>
> Indeed.  I use this constantly.

Thanks everyone for answers. No, you don't have to type parentheses.
Gdb has it like in Haskell, i.e. arguments are separated by just
whitespace. So you type `pr insn`

You know what, I came up with an alternative solution that won't break
anyone's workflow neither confuse newbies: I can add a check for number
of arguments, and to branch on that to use either $ or $arg0.

I'll resend then a bit later the patchset with the fixed changelog for
the 1st patch, and these alternative changes for the 2nd patch.


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/2] gdbinit.in: fix wrong reference to function argument

Segher Boessenkool
On Thu, Nov 14, 2019 at 09:45:28AM +0300, Konstantin Kharlamov wrote:

> On Ср, ноя 13, 2019 at 15:23, Jason Merrill <[hidden email]>
> wrote:
> >On Wed, Nov 13, 2019 at 6:39 AM Segher Boessenkool
> ><[hidden email]> wrote:
> >> There are users.  There are users who have been used to this
> >>behaviour
> >> for many many many years.
> >>
> >> People just do (say I have an "rtx insn"):
> >>   p insn
> >>   pr
> >
> >Indeed.  I use this constantly.
>
> Thanks everyone for answers. No, you don't have to type parentheses.
> Gdb has it like in Haskell, i.e. arguments are separated by just
> whitespace. So you type `pr insn`
>
> You know what, I came up with an alternative solution that won't break
> anyone's workflow neither confuse newbies: I can add a check for number
> of arguments, and to branch on that to use either $ or $arg0.

That sounds great!  Thank you :-)


Segher