On Чт, ноя 14, 2019 at 15:55, Alexander Monakov <amona...@ispras.ru> wrote:
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-an...@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?

Thanks! Unfortunately AFAIK ternary expressions are broken in gdb https://sourceware.org/bugzilla/show_bug.cgi?id=22466 :c


Reply via email to