前些天在erlang的源码里面闲逛的时候发现了 bin目录下的cerl,一看原来是个调试的高级货。
我之前写过一篇文章http://mryufeng.javaeye.com/blog/113852 如何调试erlang 但是这是土八路的方法, cerl才是现代化工业。
# This is a script to start Erlang/OTP for debugging. PATH is set to
# include this script so if slave nodes are started they will use this
# script as well.
#
# usage: cerl [ OPTIONS ] [ ARGS ]
#
# The OPTIONS are
#
# -rootdir $MYROOTDIR
# Run an installed emulator built from this source
# -debug Run debug compiled emulator
# -gdb Run the debug compiled emulator in emacs and gdb.
# You have to start beam in gdb using “run”.
# -break F Run the debug compiled emulator in emacs and gdb and set break.
# The session is started, i.e. “run” is already don for you.
# -xxgdb FIXME currently disabled
# -purify Run emulator compiled for purify
# -quantify Run emulator compiled for quantify
# -purecov Run emulator compiled for purecov
# -gcov Run emulator compiled for gcov
# -valgrind Run emulator compiled for valgrind
# -lcnt Run emulator compiled for lock counting
# -nox Unset the DISPLAY variable to disable us of X Windows
#
要使用cerl 我们最好准备个调试版本的erlang。R13B 修正了些编译错误,可以编译出debug版本的系统:./configure && make TYPE=debug && make
这样就生成了个beam.debug的运行期。
我们要调试的时候 就可以在otp的binx目录下运行 cerl -debug -gdb -break main
这时候cerl自动会加载 emacs 启动 gud, 整个过程都是自动的。但是这个脚本有点小问题, gud模型下没有把源码和当前对应的调试对应起来。可以通过以下方式修正:
yu-fengdemacbook-2:bin yufeng$ diff cerl cerl2
|
< exec $EMACS -- eval "(progn (gdb \"gdb $EMU\") $gdbcmd)"
|
> exec $EMACS -- eval "(progn (gdb \"gdb --annotate=3 $EMU\") $gdbcmd)"
|
具体的操作和界面可以参照这篇文章:
http://www.nabble.com/printing-of-Eterm%27s-from-gdb-td19240493.html
在调试的时候 我们会希望查看 eterm的值,但是由于eterm的格式非常复杂, gdb的print什么的无法满足我们的需求。 otp开发团队于是开发出了一套方法来减轻我们的负担:
1. erts/etc/unix/etp-commands 这是gdb的脚本 包含了几十个etp方法,而且文档非常详细。
2. 源码里面的 pp, ps等函数, 这些函数是专门为gdb调试开发的。 可以用gdb的 call pp(xxx)来调用。
有了这些工具 调试和研究erts变成了一件很快乐的事情!
分享到:
相关推荐
GDB调试GDB调试GDB调试GDB调试GDB调试 GDB调试GDB调试GDB调试GDB调试GDB调试
用GDB调试程序 用GDB调试程序 用GDB调试程序 用GDB调试程序 用GDB调试程序 用GDB调试程序
陈浩-用GDB调试程序(整理有书签).pdf+守望的个人博客-GDB调试指南(整理有书签).pdf
GDB调试精粹及使用实例GDB调试精粹及使用实例GDB调试精粹及使用实例GDB调试精粹及使用实例GDB调试精粹及使用实例GDB调试精粹及使用实例GDB调试精粹及使用实例GDB调试精粹及使用实例GDB调试精粹及使用实例GDB调试精粹...
用GDB调试程序 用GDB调试程序 用GDB调试程序 用GDB调试程序 用GDB调试程序
gdb调试器的使用gdb调试器的使用gdb调试器的使用gdb调试器的使用gdb调试器的使用
讲述常用gdb命令,以及讲述如何使用gdb调试程序崩溃后产生的core dump文件,让您在linux下开发更轻松
GDB调试程序[陈皓] GDB调试工具指南 两个pdf文件
经典实例用GDB调试程序 最经典的gdb调试实例讲解
是学习嵌入式的很好的资料哦!里面详细介绍了怎样用gdb调试程序,是嵌入式程序调试入门必备的资料!
用GDB调试程序
gdb rk可运行程序
使用GDB调试,英文版。对于从事 Linux C/C++ 后台开发的读者来说,GDB 调试是需要熟练掌握的一项技能
用GDB调试程序(zt).pdf
关于linux下使用GDB调试的资料 ,非常好。
使用gdb调试嵌入式应用程序 可使用gdb或者图形化的ddd和insight
非常详细的介绍 Linux下gdb调试工具指南