perlの配布物の中にあるINSTALLの"Building a debugging perl"セクションにある通り、-DDEBUGGING=ナニガシを指定すればよい。
指定する値によって、
- "perl internal debugging code"とデバッグシンボルの両方が有効になったもの (-DDEBUGGINGもしくは-DDEBUGGING=both)
- デバッグシンボルが有効になったもの (-DDEBUGGING=-g)
とできあがるperlが異なる。
"perl internal debugging code"を有効にすると、"much, much more slowly"になるとINSTALLには書かれている。
Note that a perl built with -DDEBUGGING will be much bigger and will run
much, much more slowly than a standard perl.
ビルド済みのperlが、どんなデバッグオプションでビルドされたかを確認するには、perl -Vをみればよい。
$ perl -V
Summary of my perl5 (revision 5 version 16 subversion 2) configuration:
Platform:
osname=linux, osvers=2.6.38-13-generic, archname=x86_64-linux
uname='linux goa 2.6.38-13-generic #54~lucid1-ubuntu smp wed jan 4 13:00:37 utc 2012 x86_64 gnulinux '
...
Compiler:
cc='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2 -g',
cppflags='-DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
...
Characteristics of this binary (from libperl):
Compile-time options: DEBUGGING HAS_TIMES PERLIO_LAYERS
PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP
...
Built under linux
... 着目するのは「Compiler:」の「optimize」と、「Compile-time options:」の2つ。
- perlbrew install --notest perl-5.16.2
- perlbrew install --notest perl-5.16.2 --as=perl-5.16.2-both -DEBUGGING=both
- perlbrew install --notest perl-5.16.2 --as=perl-5.16.2-g -DEBUGGING=-g
の3つのperlでここらへんの値がどうなってるかは次の通り。
| Compiler: optimize | Compile-time options | |
|---|---|---|
| standard | -O2 | なし |
| -g | -O2 -g | なし |
| both | -O2 -g | DEBUGGING |
「-O2じゃなくて-O0がイイ!」という向きは、
とかするといいと思います。
注意点としては:
- Perl 5.8.9では
-DEBUGGINGは-DDEBUGGINGの別名として使えますが、5.8.8では-DEBUGGINGは使えません。-DDEBUGGINGを指定しましょう。 - Perl 5.8.8では
-DDEBUGGING=-gが効きません。指定してもデバッグシンボルがつきません。デバッグシンボルをつけるには、-Doptimize='-O2 -g'を指定すればいいのですが、optimizeに-gが含まれているとDEBUGGINGまで有効になってしまいます。。。デバッグシンボルだけつけたいのですが、install時のオプションではどうしようもなさそうだったので、Configureにパッチ(↓のパッチはCentOSのperlから拝借しました)を当てて(perlbrewの場合は、patchperlにDEBUGGINGを有効にしないようにするパッチを当てて)ビルドするようにしました。。- 5.8.9なら
-DDEBUGGING=-gが効きます。
- 5.8.9なら
--- perl-5.8.7/Configure.orig 2005-08-28 18:48:03.000000000 -0400 +++ perl-5.8.7/Configure 2005-08-28 18:49:28.000000000 -0400 @@ -4707,9 +4707,6 @@ case "$gccversion" in 1*) dflt='-fpcc-struct-return' ;; esac - case "$optimize" in - *-g*) dflt="$dflt -DDEBUGGING";; - esac case "$gccversion" in 2*) if test -d /etc/conf/kconfig.d && $contains _POSIX_VERSION $usrinc/sys/unistd.h >/dev/null 2>&1