This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2 2/2] gdbinit.in: allow to pass function argument explicitly


On Thu, 14 Nov 2019, Konstantin Kharlamov wrote:

> Generally, people expect functions to accept arguments directly. But
> ones defined in gdbinit did not use the argument, which may be confusing
> for newcomers. But we can't change behavior to use the argument without
> breaking existing users of the gdbinit. Let's fix this by adding a check
> for whether a user passed an argument, and either use it or go with
> older behavior.

Thank you for working on this. I think it's possible to avoid code duplication,
see below.

> 2019-11-14  Konstantin Kharlamov  <Hi-Angel@yandex.ru>
> 
>         * gdbinit.in (pp, pr, prl, pt, pct, pgg, pgq, pgs, pge, pmz, ptc, pdn,
>         ptn, pdd, prc, pi, pbm, pel, trt):
>         Make use of $arg0 if a user passed it

(note: no need to start a new line, "Make use ..." can go immediately after the colon)

> --- a/gcc/gdbinit.in
> +++ b/gcc/gdbinit.in
> @@ -17,7 +17,11 @@
>  # <http://www.gnu.org/licenses/>.
>  
>  define pp
> -call debug ($)
> +  if ($argc == 0)
> +    call debug ($)
> +  else
> +    call debug ($arg0)
> +  end
>  end

I think here you can use simply use

    call debug ($argc ? $arg0 : $)

and likewise in other instances. Where it would make the line too complicated, I
think you can introduce a convenience variable, e.g. instead of

> +  if ($argc == 0)
> +    output $.decl_minimal.name->identifier.id.str
> +  else
> +    output $arg0.decl_minimal.name->identifier.id.str
> +  end

have something like

    set $dbgarg = $argc ? $arg0 : $
    output $dbgarg.decl_minimal.name->identifier.id.str

WDYT?

Alexander


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]