This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add more examples of perl/gdb usage.
[perl5.git] / pod / perlhacktips.pod
CommitLineData
0061d4fa 1
04c692a8
DR
2=encoding utf8
3
4=for comment
5Consistent formatting of this file is achieved with:
6 perl ./Porting/podtidy pod/perlhacktips.pod
7
8=head1 NAME
9
10perlhacktips - Tips for Perl core C code hacking
11
12=head1 DESCRIPTION
13
14This document will help you learn the best way to go about hacking on
15the Perl core C code. It covers common problems, debugging, profiling,
16and more.
17
18If you haven't read L<perlhack> and L<perlhacktut> yet, you might want
19to do that first.
20
21=head1 COMMON PROBLEMS
22
23Perl source plays by ANSI C89 rules: no C99 (or C++) extensions. In
24some cases we have to take pre-ANSI requirements into consideration.
25You don't care about some particular platform having broken Perl? I
26hear there is still a strong demand for J2EE programmers.
27
28=head2 Perl environment problems
29
30=over 4
31
32=item *
33
34Not compiling with threading
35
36Compiling with threading (-Duseithreads) completely rewrites the
37function prototypes of Perl. You better try your changes with that.
38Related to this is the difference between "Perl_-less" and "Perl_-ly"
39APIs, for example:
40
41 Perl_sv_setiv(aTHX_ ...);
42 sv_setiv(...);
43
44The first one explicitly passes in the context, which is needed for
45e.g. threaded builds. The second one does that implicitly; do not get
46them mixed. If you are not passing in a aTHX_, you will need to do a
47dTHX (or a dVAR) as the first thing in the function.
48
49See L<perlguts/"How multiple interpreters and concurrency are
50supported"> for further discussion about context.
51
52=item *
53
54Not compiling with -DDEBUGGING
55
56The DEBUGGING define exposes more code to the compiler, therefore more
57ways for things to go wrong. You should try it.
58
59=item *
60
61Introducing (non-read-only) globals
62
63Do not introduce any modifiable globals, truly global or file static.
64They are bad form and complicate multithreading and other forms of
65concurrency. The right way is to introduce them as new interpreter
66variables, see F<intrpvar.h> (at the very end for binary
67compatibility).
68
69Introducing read-only (const) globals is okay, as long as you verify
70with e.g. C<nm libperl.a|egrep -v ' [TURtr] '> (if your C<nm> has
71BSD-style output) that the data you added really is read-only. (If it
72is, it shouldn't show up in the output of that command.)
73
74If you want to have static strings, make them constant:
75
76 static const char etc[] = "...";
77
78If you want to have arrays of constant strings, note carefully the
79right combination of C<const>s:
80
81 static const char * const yippee[] =
82 {"hi", "ho", "silver"};
83
84There is a way to completely hide any modifiable globals (they are all
85moved to heap), the compilation setting
86C<-DPERL_GLOBAL_STRUCT_PRIVATE>. It is not normally used, but can be
87used for testing, read more about it in L<perlguts/"Background and
88PERL_IMPLICIT_CONTEXT">.
89
90=item *
91
92Not exporting your new function
93
94Some platforms (Win32, AIX, VMS, OS/2, to name a few) require any
95function that is part of the public API (the shared Perl library) to be
96explicitly marked as exported. See the discussion about F<embed.pl> in
97L<perlguts>.
98
99=item *
100
101Exporting your new function
102
103The new shiny result of either genuine new functionality or your
104arduous refactoring is now ready and correctly exported. So what could
105possibly go wrong?
106
107Maybe simply that your function did not need to be exported in the
108first place. Perl has a long and not so glorious history of exporting
109functions that it should not have.
110
111If the function is used only inside one source code file, make it
112static. See the discussion about F<embed.pl> in L<perlguts>.
113
114If the function is used across several files, but intended only for
115Perl's internal use (and this should be the common case), do not export
116it to the public API. See the discussion about F<embed.pl> in
117L<perlguts>.
118
119=back
120
121=head2 Portability problems
122
123The following are common causes of compilation and/or execution
124failures, not common to Perl as such. The C FAQ is good bedtime
125reading. Please test your changes with as many C compilers and
126platforms as possible; we will, anyway, and it's nice to save oneself
127from public embarrassment.
128
129If using gcc, you can add the C<-std=c89> option which will hopefully
130catch most of these unportabilities. (However it might also catch
131incompatibilities in your system's header files.)
132
133Use the Configure C<-Dgccansipedantic> flag to enable the gcc C<-ansi
134-pedantic> flags which enforce stricter ANSI rules.
135
136If using the C<gcc -Wall> note that not all the possible warnings (like
137C<-Wunitialized>) are given unless you also compile with C<-O>.
138
139Note that if using gcc, starting from Perl 5.9.5 the Perl core source
140code files (the ones at the top level of the source code distribution,
141but not e.g. the extensions under ext/) are automatically compiled with
142as many as possible of the C<-std=c89>, C<-ansi>, C<-pedantic>, and a
143selection of C<-W> flags (see cflags.SH).
144
145Also study L<perlport> carefully to avoid any bad assumptions about the
146operating system, filesystems, and so forth.
147
148You may once in a while try a "make microperl" to see whether we can
149still compile Perl with just the bare minimum of interfaces. (See
150README.micro.)
151
152Do not assume an operating system indicates a certain compiler.
153
154=over 4
155
156=item *
157
158Casting pointers to integers or casting integers to pointers
159
160 void castaway(U8* p)
161 {
162 IV i = p;
163
164or
165
166 void castaway(U8* p)
167 {
168 IV i = (IV)p;
169
170Both are bad, and broken, and unportable. Use the PTR2IV() macro that
171does it right. (Likewise, there are PTR2UV(), PTR2NV(), INT2PTR(), and
172NUM2PTR().)
173
174=item *
175
176Casting between data function pointers and data pointers
177
178Technically speaking casting between function pointers and data
179pointers is unportable and undefined, but practically speaking it seems
180to work, but you should use the FPTR2DPTR() and DPTR2FPTR() macros.
181Sometimes you can also play games with unions.
182
183=item *
184
185Assuming sizeof(int) == sizeof(long)
186
187There are platforms where longs are 64 bits, and platforms where ints
188are 64 bits, and while we are out to shock you, even platforms where
189shorts are 64 bits. This is all legal according to the C standard. (In
190other words, "long long" is not a portable way to specify 64 bits, and
191"long long" is not even guaranteed to be any wider than "long".)
192
193Instead, use the definitions IV, UV, IVSIZE, I32SIZE, and so forth.
194Avoid things like I32 because they are B<not> guaranteed to be
195I<exactly> 32 bits, they are I<at least> 32 bits, nor are they
196guaranteed to be B<int> or B<long>. If you really explicitly need
19764-bit variables, use I64 and U64, but only if guarded by HAS_QUAD.
198
199=item *
200
201Assuming one can dereference any type of pointer for any type of data
202
203 char *p = ...;
204 long pony = *p; /* BAD */
205
206Many platforms, quite rightly so, will give you a core dump instead of
768312ab 207a pony if the p happens not to be correctly aligned.
04c692a8
DR
208
209=item *
210
211Lvalue casts
212
213 (int)*p = ...; /* BAD */
214
215Simply not portable. Get your lvalue to be of the right type, or maybe
216use temporary variables, or dirty tricks with unions.
217
218=item *
219
220Assume B<anything> about structs (especially the ones you don't
221control, like the ones coming from the system headers)
222
223=over 8
224
225=item *
226
227That a certain field exists in a struct
228
229=item *
230
231That no other fields exist besides the ones you know of
232
233=item *
234
235That a field is of certain signedness, sizeof, or type
236
237=item *
238
239That the fields are in a certain order
240
241=over 8
242
243=item *
244
245While C guarantees the ordering specified in the struct definition,
246between different platforms the definitions might differ
247
248=back
249
250=item *
251
252That the sizeof(struct) or the alignments are the same everywhere
253
254=over 8
255
256=item *
257
258There might be padding bytes between the fields to align the fields -
259the bytes can be anything
260
261=item *
262
263Structs are required to be aligned to the maximum alignment required by
264the fields - which for native types is for usually equivalent to
265sizeof() of the field
266
267=back
268
269=back
270
271=item *
272
273Assuming the character set is ASCIIish
274
275Perl can compile and run under EBCDIC platforms. See L<perlebcdic>.
276This is transparent for the most part, but because the character sets
277differ, you shouldn't use numeric (decimal, octal, nor hex) constants
278to refer to characters. You can safely say 'A', but not 0x41. You can
279safely say '\n', but not \012. If a character doesn't have a trivial
eb6d698b
KW
280input form, you should add it to the list in
281F<regen/unicode_constants.pl>, and have Perl create #defines for you,
282based on the current platform.
04c692a8
DR
283
284Also, the range 'A' - 'Z' in ASCII is an unbroken sequence of 26 upper
285case alphabetic characters. That is not true in EBCDIC. Nor for 'a' to
286'z'. But '0' - '9' is an unbroken range in both systems. Don't assume
287anything about other ranges.
288
289Many of the comments in the existing code ignore the possibility of
290EBCDIC, and may be wrong therefore, even if the code works. This is
291actually a tribute to the successful transparent insertion of being
292able to handle EBCDIC without having to change pre-existing code.
293
294UTF-8 and UTF-EBCDIC are two different encodings used to represent
295Unicode code points as sequences of bytes. Macros with the same names
296(but different definitions) in C<utf8.h> and C<utfebcdic.h> are used to
297allow the calling code to think that there is only one such encoding.
298This is almost always referred to as C<utf8>, but it means the EBCDIC
299version as well. Again, comments in the code may well be wrong even if
300the code itself is right. For example, the concept of C<invariant
301characters> differs between ASCII and EBCDIC. On ASCII platforms, only
302characters that do not have the high-order bit set (i.e. whose ordinals
303are strict ASCII, 0 - 127) are invariant, and the documentation and
304comments in the code may assume that, often referring to something
305like, say, C<hibit>. The situation differs and is not so simple on
306EBCDIC machines, but as long as the code itself uses the
307C<NATIVE_IS_INVARIANT()> macro appropriately, it works, even if the
308comments are wrong.
309
310=item *
311
312Assuming the character set is just ASCII
313
314ASCII is a 7 bit encoding, but bytes have 8 bits in them. The 128 extra
315characters have different meanings depending on the locale. Absent a
316locale, currently these extra characters are generally considered to be
317unassigned, and this has presented some problems. This is being changed
318starting in 5.12 so that these characters will be considered to be
319Latin-1 (ISO-8859-1).
320
321=item *
322
323Mixing #define and #ifdef
324
325 #define BURGLE(x) ... \
326 #ifdef BURGLE_OLD_STYLE /* BAD */
327 ... do it the old way ... \
328 #else
329 ... do it the new way ... \
330 #endif
331
332You cannot portably "stack" cpp directives. For example in the above
333you need two separate BURGLE() #defines, one for each #ifdef branch.
334
335=item *
336
337Adding non-comment stuff after #endif or #else
338
339 #ifdef SNOSH
340 ...
341 #else !SNOSH /* BAD */
342 ...
343 #endif SNOSH /* BAD */
344
345The #endif and #else cannot portably have anything non-comment after
346them. If you want to document what is going (which is a good idea
347especially if the branches are long), use (C) comments:
348
349 #ifdef SNOSH
350 ...
351 #else /* !SNOSH */
352 ...
353 #endif /* SNOSH */
354
355The gcc option C<-Wendif-labels> warns about the bad variant (by
356default on starting from Perl 5.9.4).
357
358=item *
359
360Having a comma after the last element of an enum list
361
362 enum color {
363 CERULEAN,
364 CHARTREUSE,
365 CINNABAR, /* BAD */
366 };
367
368is not portable. Leave out the last comma.
369
370Also note that whether enums are implicitly morphable to ints varies
371between compilers, you might need to (int).
372
373=item *
374
375Using //-comments
376
377 // This function bamfoodles the zorklator. /* BAD */
378
379That is C99 or C++. Perl is C89. Using the //-comments is silently
380allowed by many C compilers but cranking up the ANSI C89 strictness
381(which we like to do) causes the compilation to fail.
382
383=item *
384
385Mixing declarations and code
386
387 void zorklator()
388 {
389 int n = 3;
390 set_zorkmids(n); /* BAD */
391 int q = 4;
392
393That is C99 or C++. Some C compilers allow that, but you shouldn't.
394
395The gcc option C<-Wdeclaration-after-statements> scans for such
396problems (by default on starting from Perl 5.9.4).
397
398=item *
399
400Introducing variables inside for()
401
402 for(int i = ...; ...; ...) { /* BAD */
403
404That is C99 or C++. While it would indeed be awfully nice to have that
405also in C89, to limit the scope of the loop variable, alas, we cannot.
406
407=item *
408
409Mixing signed char pointers with unsigned char pointers
410
411 int foo(char *s) { ... }
412 ...
413 unsigned char *t = ...; /* Or U8* t = ... */
414 foo(t); /* BAD */
415
416While this is legal practice, it is certainly dubious, and downright
417fatal in at least one platform: for example VMS cc considers this a
418fatal error. One cause for people often making this mistake is that a
419"naked char" and therefore dereferencing a "naked char pointer" have an
420undefined signedness: it depends on the compiler and the flags of the
421compiler and the underlying platform whether the result is signed or
422unsigned. For this very same reason using a 'char' as an array index is
423bad.
424
425=item *
426
427Macros that have string constants and their arguments as substrings of
428the string constants
429
430 #define FOO(n) printf("number = %d\n", n) /* BAD */
431 FOO(10);
432
433Pre-ANSI semantics for that was equivalent to
434
435 printf("10umber = %d\10");
436
437which is probably not what you were expecting. Unfortunately at least
438one reasonably common and modern C compiler does "real backward
439compatibility" here, in AIX that is what still happens even though the
440rest of the AIX compiler is very happily C89.
441
442=item *
443
444Using printf formats for non-basic C types
445
446 IV i = ...;
447 printf("i = %d\n", i); /* BAD */
448
449While this might by accident work in some platform (where IV happens to
450be an C<int>), in general it cannot. IV might be something larger. Even
451worse the situation is with more specific types (defined by Perl's
452configuration step in F<config.h>):
453
454 Uid_t who = ...;
455 printf("who = %d\n", who); /* BAD */
456
457The problem here is that Uid_t might be not only not C<int>-wide but it
458might also be unsigned, in which case large uids would be printed as
459negative values.
460
461There is no simple solution to this because of printf()'s limited
462intelligence, but for many types the right format is available as with
463either 'f' or '_f' suffix, for example:
464
465 IVdf /* IV in decimal */
466 UVxf /* UV is hexadecimal */
467
468 printf("i = %"IVdf"\n", i); /* The IVdf is a string constant. */
469
470 Uid_t_f /* Uid_t in decimal */
471
472 printf("who = %"Uid_t_f"\n", who);
473
474Or you can try casting to a "wide enough" type:
475
476 printf("i = %"IVdf"\n", (IV)something_very_small_and_signed);
477
478Also remember that the C<%p> format really does require a void pointer:
479
480 U8* p = ...;
481 printf("p = %p\n", (void*)p);
482
483The gcc option C<-Wformat> scans for such problems.
484
485=item *
486
487Blindly using variadic macros
488
489gcc has had them for a while with its own syntax, and C99 brought them
490with a standardized syntax. Don't use the former, and use the latter
491only if the HAS_C99_VARIADIC_MACROS is defined.
492
493=item *
494
495Blindly passing va_list
496
497Not all platforms support passing va_list to further varargs (stdarg)
498functions. The right thing to do is to copy the va_list using the
499Perl_va_copy() if the NEED_VA_COPY is defined.
500
501=item *
502
503Using gcc statement expressions
504
505 val = ({...;...;...}); /* BAD */
506
507While a nice extension, it's not portable. The Perl code does
508admittedly use them if available to gain some extra speed (essentially
509as a funky form of inlining), but you shouldn't.
510
511=item *
512
513Binding together several statements in a macro
514
515Use the macros STMT_START and STMT_END.
516
517 STMT_START {
518 ...
519 } STMT_END
520
521=item *
522
523Testing for operating systems or versions when should be testing for
524features
525
526 #ifdef __FOONIX__ /* BAD */
527 foo = quux();
528 #endif
529
530Unless you know with 100% certainty that quux() is only ever available
531for the "Foonix" operating system B<and> that is available B<and>
532correctly working for B<all> past, present, B<and> future versions of
533"Foonix", the above is very wrong. This is more correct (though still
534not perfect, because the below is a compile-time check):
535
536 #ifdef HAS_QUUX
537 foo = quux();
538 #endif
539
540How does the HAS_QUUX become defined where it needs to be? Well, if
541Foonix happens to be Unixy enough to be able to run the Configure
542script, and Configure has been taught about detecting and testing
543quux(), the HAS_QUUX will be correctly defined. In other platforms, the
544corresponding configuration step will hopefully do the same.
545
546In a pinch, if you cannot wait for Configure to be educated, or if you
547have a good hunch of where quux() might be available, you can
548temporarily try the following:
549
550 #if (defined(__FOONIX__) || defined(__BARNIX__))
551 # define HAS_QUUX
552 #endif
553
554 ...
555
556 #ifdef HAS_QUUX
557 foo = quux();
558 #endif
559
560But in any case, try to keep the features and operating systems
561separate.
562
563=back
564
565=head2 Problematic System Interfaces
566
567=over 4
568
569=item *
570
571malloc(0), realloc(0), calloc(0, 0) are non-portable. To be portable
572allocate at least one byte. (In general you should rarely need to work
573at this low level, but instead use the various malloc wrappers.)
574
575=item *
576
577snprintf() - the return type is unportable. Use my_snprintf() instead.
578
579=back
580
581=head2 Security problems
582
583Last but not least, here are various tips for safer coding.
584
585=over 4
586
587=item *
588
589Do not use gets()
590
591Or we will publicly ridicule you. Seriously.
592
593=item *
594
595Do not use strcpy() or strcat() or strncpy() or strncat()
596
597Use my_strlcpy() and my_strlcat() instead: they either use the native
598implementation, or Perl's own implementation (borrowed from the public
599domain implementation of INN).
600
601=item *
602
603Do not use sprintf() or vsprintf()
604
605If you really want just plain byte strings, use my_snprintf() and
606my_vsnprintf() instead, which will try to use snprintf() and
607vsnprintf() if those safer APIs are available. If you want something
608fancier than a plain byte string, use SVs and Perl_sv_catpvf().
609
610=back
611
612=head1 DEBUGGING
613
614You can compile a special debugging version of Perl, which allows you
615to use the C<-D> option of Perl to tell more about what Perl is doing.
616But sometimes there is no alternative than to dive in with a debugger,
617either to see the stack trace of a core dump (very useful in a bug
618report), or trying to figure out what went wrong before the core dump
619happened, or how did we end up having wrong or unexpected results.
620
621=head2 Poking at Perl
622
623To really poke around with Perl, you'll probably want to build Perl for
624debugging, like this:
625
626 ./Configure -d -D optimize=-g
627 make
628
629C<-g> is a flag to the C compiler to have it produce debugging
630information which will allow us to step through a running program, and
631to see in which C function we are at (without the debugging information
632we might see only the numerical addresses of the functions, which is
633not very helpful).
634
635F<Configure> will also turn on the C<DEBUGGING> compilation symbol
636which enables all the internal debugging code in Perl. There are a
637whole bunch of things you can debug with this: L<perlrun> lists them
638all, and the best way to find out about them is to play about with
639them. The most useful options are probably
640
641 l Context (loop) stack processing
642 t Trace execution
643 o Method and overloading resolution
644 c String/numeric conversions
645
646Some of the functionality of the debugging code can be achieved using
647XS modules.
648
649 -Dr => use re 'debug'
650 -Dx => use O 'Debug'
651
652=head2 Using a source-level debugger
653
654If the debugging output of C<-D> doesn't help you, it's time to step
655through perl's execution with a source-level debugger.
656
657=over 3
658
659=item *
660
661We'll use C<gdb> for our examples here; the principles will apply to
662any debugger (many vendors call their debugger C<dbx>), but check the
663manual of the one you're using.
664
665=back
666
667To fire up the debugger, type
668
669 gdb ./perl
670
671Or if you have a core dump:
672
673 gdb ./perl core
674
675You'll want to do that in your Perl source tree so the debugger can
676read the source code. You should see the copyright message, followed by
677the prompt.
678
679 (gdb)
680
681C<help> will get you into the documentation, but here are the most
682useful commands:
683
684=over 3
685
686=item * run [args]
687
688Run the program with the given arguments.
689
690=item * break function_name
691
692=item * break source.c:xxx
693
694Tells the debugger that we'll want to pause execution when we reach
695either the named function (but see L<perlguts/Internal Functions>!) or
696the given line in the named source file.
697
698=item * step
699
700Steps through the program a line at a time.
701
702=item * next
703
704Steps through the program a line at a time, without descending into
705functions.
706
707=item * continue
708
709Run until the next breakpoint.
710
711=item * finish
712
713Run until the end of the current function, then stop again.
714
715=item * 'enter'
716
717Just pressing Enter will do the most recent operation again - it's a
718blessing when stepping through miles of source code.
719
8b029fdf
MH
720=item * ptype
721
722Prints the C definition of the argument given.
723
724 (gdb) ptype PL_op
725 type = struct op {
726 OP *op_next;
727 OP *op_sibling;
728 OP *(*op_ppaddr)(void);
729 PADOFFSET op_targ;
730 unsigned int op_type : 9;
731 unsigned int op_opt : 1;
732 unsigned int op_slabbed : 1;
733 unsigned int op_savefree : 1;
734 unsigned int op_static : 1;
735 unsigned int op_folded : 1;
736 unsigned int op_spare : 2;
737 U8 op_flags;
738 U8 op_private;
739 } *
740
04c692a8
DR
741=item * print
742
743Execute the given C code and print its results. B<WARNING>: Perl makes
744heavy use of macros, and F<gdb> does not necessarily support macros
745(see later L</"gdb macro support">). You'll have to substitute them
746yourself, or to invoke cpp on the source code files (see L</"The .i
747Targets">) So, for instance, you can't say
748
749 print SvPV_nolen(sv)
750
751but you have to say
752
753 print Perl_sv_2pv_nolen(sv)
754
755=back
756
757You may find it helpful to have a "macro dictionary", which you can
758produce by saying C<cpp -dM perl.c | sort>. Even then, F<cpp> won't
759recursively apply those macros for you.
760
761=head2 gdb macro support
762
763Recent versions of F<gdb> have fairly good macro support, but in order
764to use it you'll need to compile perl with macro definitions included
765in the debugging information. Using F<gcc> version 3.1, this means
766configuring with C<-Doptimize=-g3>. Other compilers might use a
767different switch (if they support debugging macros at all).
768
769=head2 Dumping Perl Data Structures
770
771One way to get around this macro hell is to use the dumping functions
772in F<dump.c>; these work a little like an internal
773L<Devel::Peek|Devel::Peek>, but they also cover OPs and other
774structures that you can't get at from Perl. Let's take an example.
775We'll use the C<$a = $b + $c> we used before, but give it a bit of
776context: C<$b = "6XXXX"; $c = 2.3;>. Where's a good place to stop and
777poke around?
778
779What about C<pp_add>, the function we examined earlier to implement the
780C<+> operator:
781
782 (gdb) break Perl_pp_add
783 Breakpoint 1 at 0x46249f: file pp_hot.c, line 309.
784
785Notice we use C<Perl_pp_add> and not C<pp_add> - see
786L<perlguts/Internal Functions>. With the breakpoint in place, we can
787run our program:
788
789 (gdb) run -e '$b = "6XXXX"; $c = 2.3; $a = $b + $c'
790
791Lots of junk will go past as gdb reads in the relevant source files and
792libraries, and then:
793
794 Breakpoint 1, Perl_pp_add () at pp_hot.c:309
795 309 dSP; dATARGET; tryAMAGICbin(add,opASSIGN);
796 (gdb) step
797 311 dPOPTOPnnrl_ul;
798 (gdb)
799
800We looked at this bit of code before, and we said that
801C<dPOPTOPnnrl_ul> arranges for two C<NV>s to be placed into C<left> and
802C<right> - let's slightly expand it:
803
804 #define dPOPTOPnnrl_ul NV right = POPn; \
805 SV *leftsv = TOPs; \
806 NV left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
807
808C<POPn> takes the SV from the top of the stack and obtains its NV
809either directly (if C<SvNOK> is set) or by calling the C<sv_2nv>
810function. C<TOPs> takes the next SV from the top of the stack - yes,
811C<POPn> uses C<TOPs> - but doesn't remove it. We then use C<SvNV> to
812get the NV from C<leftsv> in the same way as before - yes, C<POPn> uses
813C<SvNV>.
814
815Since we don't have an NV for C<$b>, we'll have to use C<sv_2nv> to
816convert it. If we step again, we'll find ourselves there:
817
8b029fdf 818 (gdb) step
04c692a8
DR
819 Perl_sv_2nv (sv=0xa0675d0) at sv.c:1669
820 1669 if (!sv)
821 (gdb)
822
823We can now use C<Perl_sv_dump> to investigate the SV:
824
8b029fdf 825 (gdb) print Perl_sv_dump(sv)
04c692a8
DR
826 SV = PV(0xa057cc0) at 0xa0675d0
827 REFCNT = 1
828 FLAGS = (POK,pPOK)
829 PV = 0xa06a510 "6XXXX"\0
830 CUR = 5
831 LEN = 6
832 $1 = void
833
834We know we're going to get C<6> from this, so let's finish the
835subroutine:
836
837 (gdb) finish
838 Run till exit from #0 Perl_sv_2nv (sv=0xa0675d0) at sv.c:1671
839 0x462669 in Perl_pp_add () at pp_hot.c:311
840 311 dPOPTOPnnrl_ul;
841
842We can also dump out this op: the current op is always stored in
843C<PL_op>, and we can dump it with C<Perl_op_dump>. This'll give us
844similar output to L<B::Debug|B::Debug>.
845
8b029fdf 846 (gdb) print Perl_op_dump(PL_op)
04c692a8
DR
847 {
848 13 TYPE = add ===> 14
849 TARG = 1
850 FLAGS = (SCALAR,KIDS)
851 {
852 TYPE = null ===> (12)
853 (was rv2sv)
854 FLAGS = (SCALAR,KIDS)
855 {
856 11 TYPE = gvsv ===> 12
857 FLAGS = (SCALAR)
858 GV = main::b
859 }
860 }
861
862# finish this later #
863
8b029fdf
MH
864=head2 Using gdb to look at specific parts of a program
865
866With the example above, you knew to look for C<Perl_pp_add>, but what if
867there were multiple calls to it all over the place, or you didn't know what
868the op was you were looking for?
869
870One way to do this is to inject a rare call somewhere near what you're looking
871for. For example, you could add C<study> before your method:
872
873 study;
874
875And in gdb do:
876
877 (gdb) break Perl_pp_study
878
879And then step until you hit what you're looking for. This works well in a loop
880if you want to only break at certain iterations:
881
882 for my $c (1..100) {
883 study if $c == 50;
884 }
885
886=head2 Using gdb to look at what the parser/lexer are doing
887
888If you want to see what perl is doing when parsing/lexing your code, you can
889use C<<BEGIN {}>>:
890
891 print "Before\n";
892 BEGIN { study; }
893 print "After\n";
894
895And in gdb:
896
897 (gdb) break Perl_pp_study
898
899If you want to see what the parser/lexer is doing inside of C<if> blocks and
900the like you need to be a little trickier:
901
902 if ($a && $b && do { BEGIN { study } 1 } && $c) { ... }
903
04c692a8
DR
904=head1 SOURCE CODE STATIC ANALYSIS
905
906Various tools exist for analysing C source code B<statically>, as
907opposed to B<dynamically>, that is, without executing the code. It is
908possible to detect resource leaks, undefined behaviour, type
909mismatches, portability problems, code paths that would cause illegal
910memory accesses, and other similar problems by just parsing the C code
911and looking at the resulting graph, what does it tell about the
912execution and data flows. As a matter of fact, this is exactly how C
913compilers know to give warnings about dubious code.
914
915=head2 lint, splint
916
917The good old C code quality inspector, C<lint>, is available in several
918platforms, but please be aware that there are several different
919implementations of it by different vendors, which means that the flags
920are not identical across different platforms.
921
922There is a lint variant called C<splint> (Secure Programming Lint)
923available from http://www.splint.org/ that should compile on any
924Unix-like platform.
925
926There are C<lint> and <splint> targets in Makefile, but you may have to
927diddle with the flags (see above).
928
929=head2 Coverity
930
931Coverity (http://www.coverity.com/) is a product similar to lint and as
932a testbed for their product they periodically check several open source
933projects, and they give out accounts to open source developers to the
934defect databases.
935
936=head2 cpd (cut-and-paste detector)
937
938The cpd tool detects cut-and-paste coding. If one instance of the
939cut-and-pasted code changes, all the other spots should probably be
940changed, too. Therefore such code should probably be turned into a
941subroutine or a macro.
942
943cpd (http://pmd.sourceforge.net/cpd.html) is part of the pmd project
944(http://pmd.sourceforge.net/). pmd was originally written for static
945analysis of Java code, but later the cpd part of it was extended to
946parse also C and C++.
947
948Download the pmd-bin-X.Y.zip () from the SourceForge site, extract the
949pmd-X.Y.jar from it, and then run that on source code thusly:
950
0cbf2b31
FC
951 java -cp pmd-X.Y.jar net.sourceforge.pmd.cpd.CPD \
952 --minimum-tokens 100 --files /some/where/src --language c > cpd.txt
04c692a8
DR
953
954You may run into memory limits, in which case you should use the -Xmx
955option:
956
957 java -Xmx512M ...
958
959=head2 gcc warnings
960
961Though much can be written about the inconsistency and coverage
962problems of gcc warnings (like C<-Wall> not meaning "all the warnings",
963or some common portability problems not being covered by C<-Wall>, or
964C<-ansi> and C<-pedantic> both being a poorly defined collection of
965warnings, and so forth), gcc is still a useful tool in keeping our
966coding nose clean.
967
968The C<-Wall> is by default on.
969
970The C<-ansi> (and its sidekick, C<-pedantic>) would be nice to be on
971always, but unfortunately they are not safe on all platforms, they can
972for example cause fatal conflicts with the system headers (Solaris
973being a prime example). If Configure C<-Dgccansipedantic> is used, the
974C<cflags> frontend selects C<-ansi -pedantic> for the platforms where
975they are known to be safe.
976
977Starting from Perl 5.9.4 the following extra flags are added:
978
979=over 4
980
981=item *
982
983C<-Wendif-labels>
984
985=item *
986
987C<-Wextra>
988
989=item *
990
991C<-Wdeclaration-after-statement>
992
993=back
994
995The following flags would be nice to have but they would first need
996their own Augean stablemaster:
997
998=over 4
999
1000=item *
1001
1002C<-Wpointer-arith>
1003
1004=item *
1005
1006C<-Wshadow>
1007
1008=item *
1009
1010C<-Wstrict-prototypes>
1011
1012=back
1013
1014The C<-Wtraditional> is another example of the annoying tendency of gcc
1015to bundle a lot of warnings under one switch (it would be impossible to
1016deploy in practice because it would complain a lot) but it does contain
1017some warnings that would be beneficial to have available on their own,
1018such as the warning about string constants inside macros containing the
1019macro arguments: this behaved differently pre-ANSI than it does in
1020ANSI, and some C compilers are still in transition, AIX being an
1021example.
1022
1023=head2 Warnings of other C compilers
1024
1025Other C compilers (yes, there B<are> other C compilers than gcc) often
1026have their "strict ANSI" or "strict ANSI with some portability
1027extensions" modes on, like for example the Sun Workshop has its C<-Xa>
1028mode on (though implicitly), or the DEC (these days, HP...) has its
1029C<-std1> mode on.
1030
1031=head1 MEMORY DEBUGGERS
1032
d1fd4856
VP
1033B<NOTE 1>: Running under older memory debuggers such as Purify,
1034valgrind or Third Degree greatly slows down the execution: seconds
1035become minutes, minutes become hours. For example as of Perl 5.8.1, the
04c692a8
DR
1036ext/Encode/t/Unicode.t takes extraordinarily long to complete under
1037e.g. Purify, Third Degree, and valgrind. Under valgrind it takes more
1038than six hours, even on a snappy computer. The said test must be doing
1039something that is quite unfriendly for memory debuggers. If you don't
1040feel like waiting, that you can simply kill away the perl process.
d1fd4856
VP
1041Roughly valgrind slows down execution by factor 10, AddressSanitizer by
1042factor 2.
04c692a8
DR
1043
1044B<NOTE 2>: To minimize the number of memory leak false alarms (see
1045L</PERL_DESTRUCT_LEVEL> for more information), you have to set the
d8651d0d 1046environment variable PERL_DESTRUCT_LEVEL to 2. For example, like this:
04c692a8
DR
1047
1048 env PERL_DESTRUCT_LEVEL=2 valgrind ./perl -Ilib ...
1049
1050B<NOTE 3>: There are known memory leaks when there are compile-time
1051errors within eval or require, seeing C<S_doeval> in the call stack is
1052a good sign of these. Fixing these leaks is non-trivial, unfortunately,
1053but they must be fixed eventually.
1054
1055B<NOTE 4>: L<DynaLoader> will not clean up after itself completely
1056unless Perl is built with the Configure option
1057C<-Accflags=-DDL_UNLOAD_ALL_AT_EXIT>.
1058
04c692a8
DR
1059=head2 valgrind
1060
d1fd4856
VP
1061The valgrind tool can be used to find out both memory leaks and illegal
1062heap memory accesses. As of version 3.3.0, Valgrind only supports Linux
1063on x86, x86-64 and PowerPC and Darwin (OS X) on x86 and x86-64). The
1064special "test.valgrind" target can be used to run the tests under
1065valgrind. Found errors and memory leaks are logged in files named
1066F<testfile.valgrind>.
04c692a8
DR
1067
1068Valgrind also provides a cachegrind tool, invoked on perl as:
1069
1070 VG_OPTS=--tool=cachegrind make test.valgrind
1071
1072As system libraries (most notably glibc) are also triggering errors,
1073valgrind allows to suppress such errors using suppression files. The
1074default suppression file that comes with valgrind already catches a lot
1075of them. Some additional suppressions are defined in F<t/perl.supp>.
1076
1077To get valgrind and for more information see
1078
0061d4fa 1079 http://valgrind.org/
04c692a8 1080
81c3bbe7
RU
1081=head2 AddressSanitizer
1082
4dd56148
NC
1083AddressSanitizer is a clang and gcc extension, included in clang since
1084v3.1 and gcc since v4.8. It checks illegal heap pointers, global
1085pointers, stack pointers and use after free errors, and is fast enough
1086that you can easily compile your debugging or optimized perl with it.
1087It does not check memory leaks though. AddressSanitizer is available
1088for Linux, Mac OS X and soon on Windows.
81c3bbe7 1089
8a64fbaa
VP
1090To build perl with AddressSanitizer, your Configure invocation should
1091look like:
81c3bbe7 1092
e8596d90
VP
1093 sh Configure -des -Dcc=clang \
1094 -Accflags=-faddress-sanitizer -Aldflags=-faddress-sanitizer \
1095 -Alddlflags=-shared\ -faddress-sanitizer
81c3bbe7
RU
1096
1097where these arguments mean:
1098
1099=over 4
1100
1101=item * -Dcc=clang
1102
8a64fbaa
VP
1103This should be replaced by the full path to your clang executable if it
1104is not in your path.
81c3bbe7
RU
1105
1106=item * -Accflags=-faddress-sanitizer
1107
8a64fbaa 1108Compile perl and extensions sources with AddressSanitizer.
81c3bbe7
RU
1109
1110=item * -Aldflags=-faddress-sanitizer
1111
8a64fbaa 1112Link the perl executable with AddressSanitizer.
81c3bbe7 1113
e8596d90 1114=item * -Alddlflags=-shared\ -faddress-sanitizer
81c3bbe7 1115
e8596d90
VP
1116Link dynamic extensions with AddressSanitizer. You must manually
1117specify C<-shared> because using C<-Alddlflags=-shared> will prevent
1118Configure from setting a default value for C<lddlflags>, which usually
5dfc6e97 1119contains C<-shared> (at least on Linux).
81c3bbe7
RU
1120
1121=back
1122
8a64fbaa
VP
1123See also
1124L<http://code.google.com/p/address-sanitizer/wiki/AddressSanitizer>.
81c3bbe7
RU
1125
1126
04c692a8
DR
1127=head1 PROFILING
1128
1129Depending on your platform there are various ways of profiling Perl.
1130
1131There are two commonly used techniques of profiling executables:
1132I<statistical time-sampling> and I<basic-block counting>.
1133
1134The first method takes periodically samples of the CPU program counter,
1135and since the program counter can be correlated with the code generated
1136for functions, we get a statistical view of in which functions the
1137program is spending its time. The caveats are that very small/fast
1138functions have lower probability of showing up in the profile, and that
1139periodically interrupting the program (this is usually done rather
1140frequently, in the scale of milliseconds) imposes an additional
1141overhead that may skew the results. The first problem can be alleviated
1142by running the code for longer (in general this is a good idea for
1143profiling), the second problem is usually kept in guard by the
1144profiling tools themselves.
1145
1146The second method divides up the generated code into I<basic blocks>.
1147Basic blocks are sections of code that are entered only in the
1148beginning and exited only at the end. For example, a conditional jump
1149starts a basic block. Basic block profiling usually works by
1150I<instrumenting> the code by adding I<enter basic block #nnnn>
1151book-keeping code to the generated code. During the execution of the
1152code the basic block counters are then updated appropriately. The
1153caveat is that the added extra code can skew the results: again, the
1154profiling tools usually try to factor their own effects out of the
1155results.
1156
1157=head2 Gprof Profiling
1158
e2aed43d
NC
1159I<gprof> is a profiling tool available in many Unix platforms which
1160uses I<statistical time-sampling>. You can build a profiled version of
1161F<perl> by compiling using gcc with the flag C<-pg>. Either edit
1162F<config.sh> or re-run F<Configure>. Running the profiled version of
1163Perl will create an output file called F<gmon.out> which contains the
1164profiling data collected during the execution.
04c692a8 1165
e2aed43d
NC
1166quick hint:
1167
1168 $ sh Configure -des -Dusedevel -Accflags='-pg' \
1169 -Aldflags='-pg' -Alddlflags='-pg -shared' \
1170 && make perl
1171 $ ./perl ... # creates gmon.out in current directory
1172 $ gprof ./perl > out
1173 $ less out
1174
1175(you probably need to add C<-shared> to the <-Alddlflags> line until RT
1176#118199 is resolved)
04c692a8 1177
e2aed43d
NC
1178The F<gprof> tool can then display the collected data in various ways.
1179Usually F<gprof> understands the following options:
04c692a8
DR
1180
1181=over 4
1182
1183=item * -a
1184
1185Suppress statically defined functions from the profile.
1186
1187=item * -b
1188
1189Suppress the verbose descriptions in the profile.
1190
1191=item * -e routine
1192
1193Exclude the given routine and its descendants from the profile.
1194
1195=item * -f routine
1196
1197Display only the given routine and its descendants in the profile.
1198
1199=item * -s
1200
1201Generate a summary file called F<gmon.sum> which then may be given to
1202subsequent gprof runs to accumulate data over several runs.
1203
1204=item * -z
1205
1206Display routines that have zero usage.
1207
1208=back
1209
1210For more detailed explanation of the available commands and output
e2aed43d 1211formats, see your own local documentation of F<gprof>.
04c692a8 1212
e2aed43d 1213=head2 GCC gcov Profiling
04c692a8 1214
e2aed43d
NC
1215I<basic block profiling> is officially available in gcc 3.0 and later.
1216You can build a profiled version of F<perl> by compiling using gcc with
1217the flags C<-fprofile-arcs -ftest-coverage>. Either edit F<config.sh>
1218or re-run F<Configure>.
04c692a8 1219
e2aed43d 1220quick hint:
04c692a8 1221
e2aed43d
NC
1222 $ sh Configure -des -Dusedevel -Doptimize='-g' \
1223 -Accflags='-fprofile-arcs -ftest-coverage' \
1224 -Aldflags='-fprofile-arcs -ftest-coverage' \
1225 -Alddlflags='-fprofile-arcs -ftest-coverage -shared' \
1226 && make perl
1227 $ rm -f regexec.c.gcov regexec.gcda
1228 $ ./perl ...
1229 $ gcov regexec.c
1230 $ less regexec.c.gcov
04c692a8 1231
e2aed43d
NC
1232(you probably need to add C<-shared> to the <-Alddlflags> line until RT
1233#118199 is resolved)
04c692a8
DR
1234
1235Running the profiled version of Perl will cause profile output to be
e2aed43d 1236generated. For each source file an accompanying F<.gcda> file will be
04c692a8
DR
1237created.
1238
e2aed43d 1239To display the results you use the I<gcov> utility (which should be
04c692a8
DR
1240installed if you have gcc 3.0 or newer installed). F<gcov> is run on
1241source code files, like this
1242
1243 gcov sv.c
1244
1245which will cause F<sv.c.gcov> to be created. The F<.gcov> files contain
1246the source code annotated with relative frequencies of execution
6f134219
NC
1247indicated by "#" markers. If you want to generate F<.gcov> files for
1248all profiled object files, you can run something like this:
1249
1250 for file in `find . -name \*.gcno`
1251 do sh -c "cd `dirname $file` && gcov `basename $file .gcno`"
1252 done
04c692a8
DR
1253
1254Useful options of F<gcov> include C<-b> which will summarise the basic
1255block, branch, and function call coverage, and C<-c> which instead of
1256relative frequencies will use the actual counts. For more information
1257on the use of F<gcov> and basic block profiling with gcc, see the
e2aed43d
NC
1258latest GNU CC manual. As of gcc 4.8, this is at
1259L<http://gcc.gnu.org/onlinedocs/gcc/Gcov-Intro.html#Gcov-Intro>
04c692a8
DR
1260
1261=head1 MISCELLANEOUS TRICKS
1262
1263=head2 PERL_DESTRUCT_LEVEL
1264
1265If you want to run any of the tests yourself manually using e.g.
4dd56148
NC
1266valgrind, please note that by default perl B<does not> explicitly
1267cleanup all the memory it has allocated (such as global memory arenas)
1268but instead lets the exit() of the whole program "take care" of such
1269allocations, also known as "global destruction of objects".
04c692a8
DR
1270
1271There is a way to tell perl to do complete cleanup: set the environment
1272variable PERL_DESTRUCT_LEVEL to a non-zero value. The t/TEST wrapper
1273does set this to 2, and this is what you need to do too, if you don't
f01ecde8 1274want to see the "global leaks": For example, for running under valgrind
04c692a8 1275
f01ecde8 1276 env PERL_DESTRUCT_LEVEL=2 valgrind ./perl -Ilib t/foo/bar.t
04c692a8
DR
1277
1278(Note: the mod_perl apache module uses also this environment variable
1279for its own purposes and extended its semantics. Refer to the mod_perl
1280documentation for more information. Also, spawned threads do the
1281equivalent of setting this variable to the value 1.)
1282
1283If, at the end of a run you get the message I<N scalars leaked>, you
1284can recompile with C<-DDEBUG_LEAKING_SCALARS>, which will cause the
1285addresses of all those leaked SVs to be dumped along with details as to
1286where each SV was originally allocated. This information is also
1287displayed by Devel::Peek. Note that the extra details recorded with
1288each SV increases memory usage, so it shouldn't be used in production
1289environments. It also converts C<new_SV()> from a macro into a real
1290function, so you can use your favourite debugger to discover where
1291those pesky SVs were allocated.
1292
1293If you see that you're leaking memory at runtime, but neither valgrind
1294nor C<-DDEBUG_LEAKING_SCALARS> will find anything, you're probably
1295leaking SVs that are still reachable and will be properly cleaned up
1296during destruction of the interpreter. In such cases, using the C<-Dm>
1297switch can point you to the source of the leak. If the executable was
1298built with C<-DDEBUG_LEAKING_SCALARS>, C<-Dm> will output SV
1299allocations in addition to memory allocations. Each SV allocation has a
1300distinct serial number that will be written on creation and destruction
1301of the SV. So if you're executing the leaking code in a loop, you need
1302to look for SVs that are created, but never destroyed between each
1303cycle. If such an SV is found, set a conditional breakpoint within
1304C<new_SV()> and make it break only when C<PL_sv_serial> is equal to the
1305serial number of the leaking SV. Then you will catch the interpreter in
1306exactly the state where the leaking SV is allocated, which is
1307sufficient in many cases to find the source of the leak.
1308
1309As C<-Dm> is using the PerlIO layer for output, it will by itself
1310allocate quite a bunch of SVs, which are hidden to avoid recursion. You
1311can bypass the PerlIO layer if you use the SV logging provided by
1312C<-DPERL_MEM_LOG> instead.
1313
1314=head2 PERL_MEM_LOG
1315
1316If compiled with C<-DPERL_MEM_LOG>, both memory and SV allocations go
1317through logging functions, which is handy for breakpoint setting.
1318
1319Unless C<-DPERL_MEM_LOG_NOIMPL> is also compiled, the logging functions
1320read $ENV{PERL_MEM_LOG} to determine whether to log the event, and if
1321so how:
1322
1323 $ENV{PERL_MEM_LOG} =~ /m/ Log all memory ops
1324 $ENV{PERL_MEM_LOG} =~ /s/ Log all SV ops
1325 $ENV{PERL_MEM_LOG} =~ /t/ include timestamp in Log
1326 $ENV{PERL_MEM_LOG} =~ /^(\d+)/ write to FD given (default is 2)
1327
1328Memory logging is somewhat similar to C<-Dm> but is independent of
1329C<-DDEBUGGING>, and at a higher level; all uses of Newx(), Renew(), and
1330Safefree() are logged with the caller's source code file and line
1331number (and C function name, if supported by the C compiler). In
1332contrast, C<-Dm> is directly at the point of C<malloc()>. SV logging is
1333similar.
1334
1335Since the logging doesn't use PerlIO, all SV allocations are logged and
1336no extra SV allocations are introduced by enabling the logging. If
1337compiled with C<-DDEBUG_LEAKING_SCALARS>, the serial number for each SV
1338allocation is also logged.
1339
1340=head2 DDD over gdb
1341
1342Those debugging perl with the DDD frontend over gdb may find the
1343following useful:
1344
1345You can extend the data conversion shortcuts menu, so for example you
1346can display an SV's IV value with one click, without doing any typing.
1347To do that simply edit ~/.ddd/init file and add after:
1348
1349 ! Display shortcuts.
1350 Ddd*gdbDisplayShortcuts: \
1351 /t () // Convert to Bin\n\
1352 /d () // Convert to Dec\n\
1353 /x () // Convert to Hex\n\
1354 /o () // Convert to Oct(\n\
1355
1356the following two lines:
1357
1358 ((XPV*) (())->sv_any )->xpv_pv // 2pvx\n\
1359 ((XPVIV*) (())->sv_any )->xiv_iv // 2ivx
1360
1361so now you can do ivx and pvx lookups or you can plug there the sv_peek
1362"conversion":
1363
1364 Perl_sv_peek(my_perl, (SV*)()) // sv_peek
1365
1366(The my_perl is for threaded builds.) Just remember that every line,
1367but the last one, should end with \n\
1368
1369Alternatively edit the init file interactively via: 3rd mouse button ->
1370New Display -> Edit Menu
1371
1372Note: you can define up to 20 conversion shortcuts in the gdb section.
1373
1374=head2 Poison
1375
1376If you see in a debugger a memory area mysteriously full of 0xABABABAB
1377or 0xEFEFEFEF, you may be seeing the effect of the Poison() macros, see
1378L<perlclib>.
1379
1380=head2 Read-only optrees
1381
1382Under ithreads the optree is read only. If you want to enforce this, to
1383check for write accesses from buggy code, compile with
04c692a8 1384C<-DPERL_DEBUG_READONLY_OPS> to enable code that allocates op memory
4dd56148
NC
1385via C<mmap>, and sets it read-only when it is attached to a subroutine.
1386Any write access to an op results in a C<SIGBUS> and abort.
04c692a8
DR
1387
1388This code is intended for development only, and may not be portable
1389even to all Unix variants. Also, it is an 80% solution, in that it
4dd56148
NC
1390isn't able to make all ops read only. Specifically it does not apply to
1391op slabs belonging to C<BEGIN> blocks.
04c692a8 1392
4dd56148
NC
1393However, as an 80% solution it is still effective, as it has caught
1394bugs in the past.
04c692a8 1395
f789f6a4
FC
1396=head2 When is a bool not a bool?
1397
1398On pre-C99 compilers, C<bool> is defined as equivalent to C<char>.
1399Consequently assignment of any larger type to a C<bool> is unsafe and may
1400be truncated. The C<cBOOL> macro exists to cast it correctly.
1401
1402On those platforms and compilers where C<bool> really is a boolean (C++,
1403C99), it is easy to forget the cast. You can force C<bool> to be a C<char>
1404by compiling with C<-Accflags=-DPERL_BOOL_AS_CHAR>. You may also wish to
50e4f4d4
CB
1405run C<Configure> with something like
1406
cbc13c3d 1407 -Accflags='-Wconversion -Wno-sign-conversion -Wno-shorten-64-to-32'
50e4f4d4
CB
1408
1409or your compiler's equivalent to make it easier to spot any unsafe truncations
1410that show up.
f789f6a4 1411
04c692a8
DR
1412=head2 The .i Targets
1413
1414You can expand the macros in a F<foo.c> file by saying
1415
1416 make foo.i
1417
d1fd4856
VP
1418which will expand the macros using cpp. Don't be scared by the
1419results.
04c692a8
DR
1420
1421=head1 AUTHOR
1422
1423This document was originally written by Nathan Torkington, and is
1424maintained by the perl5-porters mailing list.