Plotting from GDB

Florian Lorenzen lorenzen@physik.fu-berlin.de
Thu Jan 31 17:32:00 GMT 2008


Hello,

I spent a lot of time debugging numerical codes. Very often, it is
useful to plot a certain quantity instead of staring on numbers. To
help with this, I wrote some small user defined commands to create a
plot with gnuplot during the debugging session. Perhaps, you want to
include it in your distribution, I attach you the file. (I know, DDD
has this functionality, but perhaps CLI or Emacs users might be
interested in this.)

Best regards,

Florian

-------------- next part --------------
# plot1d.gdb
#
# Copyright (C) 2008 Florian Lorenzen
#
# Plot an expression that expands to {x1, x2, ..., xN}, i. e.
# N numbers using gnuplot.
#
# This file is for the GNU debugger 6.x.
#
# It writes temporary files named __plot1d.dump, __plot1d.dat, __plot1d.gp, so
# you should not have files of the same name in the working directory.
#
# It requires sed, awk, and gnuplot available in the $PATH.

# plot1d_opt_range <expr> <opt> <range>
#
# Plot the points of <expr> passing <opt> as plot options using
# <range> in the set yrange command.
define plot1d_opt_range
  shell rm -f __plot1d.dump __plot1d.dat __plot1d.gp
  set logging file __plot1d.dump
  set logging on
  output $arg0
  set logging off
  shell awk '{printf("%s", $0)}' < __plot1d.dump | \
    sed 's/^{\(.*\)}$/\1/;s/, */\n/g' > __plot1d.dat
  shell echo "set yrange $arg2; plot '__plot1d.dat' $arg1 title '$arg0'; \
    pause -1 \"Press enter to continue\"" > __plot1d.gp
  shell gnuplot __plot1d.gp
  shell rm -f __plot1d.dump __plot1d.dat __plot1d.gp
end

# plot1d <expr>
#
# Just plot the points of <expr>.
define plot1d
  plot1d_opt_range $arg0 "" "[*:*]"
end

# plot1d_opt <expr> <opt>
#
# Plot the points of <expr> passing <opt> to the
# plot command after the datafile. So, one can pass
# "with lines" here.
define plot1d_opt
  plot1d_opt_range $arg0 $arg1 "[*:*]"
end

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20080131/b6288d05/attachment.sig>


More information about the Gdb-patches mailing list