do_sv_dump does dump (core) on IO handles
[p5sagit/p5-mst-13.2.git] / deb.c
CommitLineData
a0d0e21e 1/* deb.c
79072805 2 *
4eb8286e 3 * Copyright (c) 1991-1999, Larry Wall
79072805 4 *
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
7 *
a0d0e21e 8 */
9
10/*
11 * "Didst thou think that the eyes of the White Tower were blind? Nay, I
12 * have seen more than thou knowest, Gray Fool." --Denethor
79072805 13 */
14
15#include "EXTERN.h"
16#include "perl.h"
17
8990e307 18void
71be2cbc 19deb(const char *pat, ...)
79072805 20{
17c3b450 21#ifdef DEBUGGING
11343788 22 dTHR;
79072805 23 va_list args;
79072805 24 register I32 i;
3280af22 25 GV* gv = PL_curcop->cop_filegv;
79072805 26
11343788 27#ifdef USE_THREADS
5dc0d613 28 PerlIO_printf(Perl_debug_log, "0x%lx (%s:%ld)\t",
29 (unsigned long) thr,
30 SvTYPE(gv) == SVt_PVGV ? SvPVX(GvSV(gv)) : "<free>",
533c011a 31 (long)PL_curcop->cop_line);
11343788 32#else
760ac839 33 PerlIO_printf(Perl_debug_log, "(%s:%ld)\t",
a0d0e21e 34 SvTYPE(gv) == SVt_PVGV ? SvPVX(GvSV(gv)) : "<free>",
3280af22 35 (long)PL_curcop->cop_line);
11343788 36#endif /* USE_THREADS */
3280af22 37 for (i=0; i<PL_dlevel; i++)
38 PerlIO_printf(Perl_debug_log, "%c%c ",PL_debname[i],PL_debdelim[i]);
79072805 39
8990e307 40 va_start(args, pat);
760ac839 41 (void) PerlIO_vprintf(Perl_debug_log,pat,args);
79072805 42 va_end( args );
17c3b450 43#endif /* DEBUGGING */
79072805 44}
79072805 45
46void
8ac85365 47deb_growlevel(void)
79072805 48{
17c3b450 49#ifdef DEBUGGING
3280af22 50 PL_dlmax += 128;
51 Renew(PL_debname, PL_dlmax, char);
52 Renew(PL_debdelim, PL_dlmax, char);
17c3b450 53#endif /* DEBUGGING */
79072805 54}
55
56I32
8ac85365 57debstackptrs(void)
79072805 58{
17c3b450 59#ifdef DEBUGGING
11343788 60 dTHR;
760ac839 61 PerlIO_printf(Perl_debug_log, "%8lx %8lx %8ld %8ld %8ld\n",
3280af22 62 (unsigned long)PL_curstack, (unsigned long)PL_stack_base,
63 (long)*PL_markstack_ptr, (long)(PL_stack_sp-PL_stack_base),
64 (long)(PL_stack_max-PL_stack_base));
760ac839 65 PerlIO_printf(Perl_debug_log, "%8lx %8lx %8ld %8ld %8ld\n",
3280af22 66 (unsigned long)PL_mainstack, (unsigned long)AvARRAY(PL_curstack),
67 (long)PL_mainstack, (long)AvFILLp(PL_curstack), (long)AvMAX(PL_curstack));
17c3b450 68#endif /* DEBUGGING */
79072805 69 return 0;
70}
71
72I32
8ac85365 73debstack(void)
79072805 74{
17c3b450 75#ifdef DEBUGGING
11343788 76 dTHR;
3280af22 77 I32 top = PL_stack_sp - PL_stack_base;
a0d0e21e 78 register I32 i = top - 30;
3280af22 79 I32 *markscan = PL_curstackinfo->si_markbase;
a0d0e21e 80
81 if (i < 0)
82 i = 0;
83
3280af22 84 while (++markscan <= PL_markstack_ptr)
a0d0e21e 85 if (*markscan >= i)
86 break;
79072805 87
11343788 88#ifdef USE_THREADS
5dc0d613 89 PerlIO_printf(Perl_debug_log, i ? "0x%lx => ... " : "0x%lx => ",
90 (unsigned long) thr);
11343788 91#else
760ac839 92 PerlIO_printf(Perl_debug_log, i ? " => ... " : " => ");
11343788 93#endif /* USE_THREADS */
3280af22 94 if (PL_stack_base[0] != &PL_sv_undef || PL_stack_sp < PL_stack_base)
760ac839 95 PerlIO_printf(Perl_debug_log, " [STACK UNDERFLOW!!!]\n");
a0d0e21e 96 do {
97 ++i;
3280af22 98 if (markscan <= PL_markstack_ptr && *markscan < i) {
a0d0e21e 99 do {
100 ++markscan;
760ac839 101 PerlIO_putc(Perl_debug_log, '*');
a0d0e21e 102 }
3280af22 103 while (markscan <= PL_markstack_ptr && *markscan < i);
760ac839 104 PerlIO_printf(Perl_debug_log, " ");
79072805 105 }
a0d0e21e 106 if (i > top)
107 break;
3280af22 108 PerlIO_printf(Perl_debug_log, "%-4s ", SvPEEK(PL_stack_base[i]));
79072805 109 }
a0d0e21e 110 while (1);
760ac839 111 PerlIO_printf(Perl_debug_log, "\n");
17c3b450 112#endif /* DEBUGGING */
79072805 113 return 0;
114}