# include as in gdb --init-command gdbinit-my --args perl OPTIONS

# See https://pari.math.u-bordeaux.fr/Events/PARI2012/talks/source.pdf
# No `document Foo Bar' commands there!

#  conflicts with `info'
define i
  call output((GEN)$arg0)
end

document i
Print the PARI value the same way as GP's print().
end

# What do these functions do with Pari stack???

define ilb
  call outmat(lift(lift(lift((GEN)$arg0))))
end

document ilb
Pretty-print the PARI value lifting whenever possible.
end

# prec_w: shallow copy with precision decreased

define isb
  call outmat(gprec_w((GEN)$arg0,3))
end

document ilb
Pretty-print the PARI value with at most 3 words of precision.
end

# Recursively display structure, truncating leaves at 2 words (or the second argument) [($argc > 1 ? $arg1 : 2) does not work]

define v
  if $argc > 1
    call dbgGEN((GEN)$arg0, $arg1)
  else
    call dbgGEN((GEN)$arg0, 2)
  end
end

document v
Emit the PARI value the same way as GP's \x.
By default, truncates the leaves at 2 words.  (Change by the 2nd optional argument.)
end

# ============ Added ============

define heap
  call dbg_pari_heap()
end

document heap
Report the stats of the PARI stack, PARI heap and PARI variables (like \s).
end

define icl
  call closure_disassemble($arg0)
end

document icl
Disassemble the argument (must be a closure).
end


# ============ Advanced (with bb renamed to be, cc to ss ============

define w1
  shell rm -f /tmp/gp.tmp1
  call gpwritebin("/tmp/gp.tmp1",$arg0)
end

document w1
Write the value of the argument to a binary PARI file /tmp/gp.tmp1.
end

define be
  break pari_err
#  break pari_err2GEN
end

document be
Set a breakpoint in a PARI error handler.
end

define ss
  signal SIGINT
end

document ss
Send the debugged program an INT signal (emulate Ctrl-C).
end

define fs
  p fill_stack()
end

document fs
Overwrite the unused portion of PARI's stack by garbage (bytes 0xFE).
end

