This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don't use /dev/tty if it happens to exist on Windows
[perl5.git] / pod / perlhacktips.pod
index 004b53e..3032bb2 100644 (file)
@@ -204,7 +204,7 @@ Assuming one can dereference any type of pointer for any type of data
   long pony = *p;    /* BAD */
 
 Many platforms, quite rightly so, will give you a core dump instead of
-a pony if the p happens not be correctly aligned.
+a pony if the p happens not to be correctly aligned.
 
 =item *
 
@@ -886,7 +886,8 @@ parse also C and C++.
 Download the pmd-bin-X.Y.zip () from the SourceForge site, extract the
 pmd-X.Y.jar from it, and then run that on source code thusly:
 
-  java -cp pmd-X.Y.jar net.sourceforge.pmd.cpd.CPD --minimum-tokens 100 --files /some/where/src --language c > cpd.txt
+  java -cp pmd-X.Y.jar net.sourceforge.pmd.cpd.CPD \
+   --minimum-tokens 100 --files /some/where/src --language c > cpd.txt
 
 You may run into memory limits, in which case you should use the -Xmx
 option:
@@ -967,14 +968,16 @@ C<-std1> mode on.
 
 =head1 MEMORY DEBUGGERS
 
-B<NOTE 1>: Running under memory debuggers such as Purify, valgrind, or
-Third Degree greatly slows down the execution: seconds become minutes,
-minutes become hours. For example as of Perl 5.8.1, the
+B<NOTE 1>: Running under older memory debuggers such as Purify,
+valgrind or Third Degree greatly slows down the execution: seconds
+become minutes, minutes become hours. For example as of Perl 5.8.1, the
 ext/Encode/t/Unicode.t takes extraordinarily long to complete under
 e.g. Purify, Third Degree, and valgrind. Under valgrind it takes more
 than six hours, even on a snappy computer. The said test must be doing
 something that is quite unfriendly for memory debuggers. If you don't
 feel like waiting, that you can simply kill away the perl process.
+Roughly valgrind slows down execution by factor 10, AddressSanitizer by
+factor 2.
 
 B<NOTE 2>: To minimize the number of memory leak false alarms (see
 L</PERL_DESTRUCT_LEVEL> for more information), you have to set the
@@ -1137,12 +1140,12 @@ finally report any memory problems.
 
 =head2 valgrind
 
-The excellent valgrind tool can be used to find out both memory leaks
-and illegal memory accesses. As of version 3.3.0, Valgrind only
-supports Linux on x86, x86-64 and PowerPC and Darwin (OS X) on x86 and
-x86-64). The special "test.valgrind" target can be used to run the
-tests under valgrind. Found errors and memory leaks are logged in
-files named F<testfile.valgrind>.
+The valgrind tool can be used to find out both memory leaks and illegal
+heap memory accesses. As of version 3.3.0, Valgrind only supports Linux
+on x86, x86-64 and PowerPC and Darwin (OS X) on x86 and x86-64). The
+special "test.valgrind" target can be used to run the tests under
+valgrind. Found errors and memory leaks are logged in files named
+F<testfile.valgrind>.
 
 Valgrind also provides a cachegrind tool, invoked on perl as:
 
@@ -1157,6 +1160,52 @@ To get valgrind and for more information see
 
     http://valgrind.org/
 
+=head2 AddressSanitizer
+
+AddressSanitizer is a clang extension, included in clang since v3.1. It
+checks illegal heap pointers, global pointers, stack pointers and use
+after free errors, and is fast enough that you can easily compile your
+debugging or optimized perl with it. It does not check memory leaks
+though. AddressSanitizer is available for linux, Mac OS X and soon on
+Windows.
+
+To build perl with AddressSanitizer, your Configure invocation should
+look like:
+
+    sh Configure -des -Dcc=clang \
+       -Accflags=-faddress-sanitizer -Aldflags=-faddress-sanitizer \
+       -Alddlflags=-shared\ -faddress-sanitizer
+
+where these arguments mean:
+
+=over 4
+
+=item * -Dcc=clang
+
+This should be replaced by the full path to your clang executable if it
+is not in your path.
+
+=item * -Accflags=-faddress-sanitizer
+
+Compile perl and extensions sources with AddressSanitizer.
+
+=item * -Aldflags=-faddress-sanitizer
+
+Link the perl executable with AddressSanitizer.
+
+=item * -Alddlflags=-shared\ -faddress-sanitizer
+
+Link dynamic extensions with AddressSanitizer. You must manually
+specify C<-shared> because using C<-Alddlflags=-shared> will prevent
+Configure from setting a default value for C<lddlflags>, which usually
+contains C<-shared> (at least on linux).
+
+=back
+
+See also
+L<http://code.google.com/p/address-sanitizer/wiki/AddressSanitizer>.
+
+
 =head1 PROFILING
 
 Depending on your platform there are various ways of profiling Perl.
@@ -1411,10 +1460,9 @@ L<perlclib>.
 
 Under ithreads the optree is read only. If you want to enforce this, to
 check for write accesses from buggy code, compile with
-C<-DPL_OP_SLAB_ALLOC> to enable the OP slab allocator and
 C<-DPERL_DEBUG_READONLY_OPS> to enable code that allocates op memory
-via C<mmap>, and sets it read-only at run time. Any write access to an
-op results in a C<SIGBUS> and abort.
+via C<mmap>, and sets it read-only when it is attached to a subroutine. Any
+write access to an op results in a C<SIGBUS> and abort.
 
 This code is intended for development only, and may not be portable
 even to all Unix variants. Also, it is an 80% solution, in that it
@@ -1424,13 +1472,14 @@ isn't able to make all ops read only. Specifically it
 
 =item * 1
 
-Only sets read-only on all slabs of ops at C<CHECK> time, hence ops
-allocated later via C<require> or C<eval> will be re-write
+Does not apply to op slabs belonging to C<BEGIN> blocks.
 
 =item * 2
 
 Turns an entire slab of ops read-write if the refcount of any op in the
-slab needs to be decreased.
+slab needs to be increased or decreased.  This means that anonymous
+closures will never have read-only ops, and thread creation will make all
+existing ops read-write.
 
 =item * 3
 
@@ -1443,9 +1492,8 @@ It's not possible to turn the slabs to read-only after an action
 requiring read-write access, as either can happen during op tree
 building time, so there may still be legitimate write access.
 
-However, as an 80% solution it is still effective, as currently it
-catches a write access during the generation of F<Config.pm>, which
-means that we can't yet build F<perl> with this enabled.
+However, as an 80% solution it is still effective, as currently it catches
+the setting of breakpoints in the debugger and some XSUB definitions.
 
 =head2 The .i Targets
 
@@ -1453,7 +1501,8 @@ You can expand the macros in a F<foo.c> file by saying
 
     make foo.i
 
-which will expand the macros using cpp.  Don't be scared by the results.
+which will expand the macros using cpp.  Don't be scared by the
+results.
 
 =head1 AUTHOR