This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
added patch, tweaked PERL_OBJECT things
[perl5.git] / deb.c
CommitLineData
a0d0e21e 1/* deb.c
79072805 2 *
9607fc9c 3 * Copyright (c) 1991-1997, Larry Wall
79072805
LW
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
LW
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
LW
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;
a0d0e21e 25 GV* gv = curcop->cop_filegv;
79072805 26
11343788 27#ifdef USE_THREADS
5dc0d613
MB
28 PerlIO_printf(Perl_debug_log, "0x%lx (%s:%ld)\t",
29 (unsigned long) thr,
30 SvTYPE(gv) == SVt_PVGV ? SvPVX(GvSV(gv)) : "<free>",
31 (long)curcop->cop_line);
11343788 32#else
760ac839 33 PerlIO_printf(Perl_debug_log, "(%s:%ld)\t",
a0d0e21e
LW
34 SvTYPE(gv) == SVt_PVGV ? SvPVX(GvSV(gv)) : "<free>",
35 (long)curcop->cop_line);
11343788 36#endif /* USE_THREADS */
79072805 37 for (i=0; i<dlevel; i++)
760ac839 38 PerlIO_printf(Perl_debug_log, "%c%c ",debname[i],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
LW
45
46void
8ac85365 47deb_growlevel(void)
79072805 48{
17c3b450 49#ifdef DEBUGGING
79072805
LW
50 dlmax += 128;
51 Renew(debname, dlmax, char);
52 Renew(debdelim, dlmax, char);
17c3b450 53#endif /* DEBUGGING */
79072805
LW
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",
0c2634fc 62 (unsigned long)curstack, (unsigned long)stack_base,
a0d0e21e
LW
63 (long)*markstack_ptr, (long)(stack_sp-stack_base),
64 (long)(stack_max-stack_base));
760ac839 65 PerlIO_printf(Perl_debug_log, "%8lx %8lx %8ld %8ld %8ld\n",
0c2634fc 66 (unsigned long)mainstack, (unsigned long)AvARRAY(curstack),
93965878 67 (long)mainstack, (long)AvFILLp(curstack), (long)AvMAX(curstack));
17c3b450 68#endif /* DEBUGGING */
79072805
LW
69 return 0;
70}
71
72I32
8ac85365 73debstack(void)
79072805 74{
17c3b450 75#ifdef DEBUGGING
11343788 76 dTHR;
a0d0e21e
LW
77 I32 top = stack_sp - stack_base;
78 register I32 i = top - 30;
e336de0d 79 I32 *markscan = curstackinfo->si_markbase;
a0d0e21e
LW
80
81 if (i < 0)
82 i = 0;
83
84 while (++markscan <= markstack_ptr)
85 if (*markscan >= i)
86 break;
79072805 87
11343788 88#ifdef USE_THREADS
5dc0d613
MB
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 */
a0d0e21e 94 if (stack_base[0] != &sv_undef || stack_sp < stack_base)
760ac839 95 PerlIO_printf(Perl_debug_log, " [STACK UNDERFLOW!!!]\n");
a0d0e21e
LW
96 do {
97 ++i;
98 if (markscan <= markstack_ptr && *markscan < i) {
99 do {
100 ++markscan;
760ac839 101 PerlIO_putc(Perl_debug_log, '*');
a0d0e21e
LW
102 }
103 while (markscan <= markstack_ptr && *markscan < i);
760ac839 104 PerlIO_printf(Perl_debug_log, " ");
79072805 105 }
a0d0e21e
LW
106 if (i > top)
107 break;
760ac839 108 PerlIO_printf(Perl_debug_log, "%-4s ", SvPEEK(stack_base[i]));
79072805 109 }
a0d0e21e 110 while (1);
760ac839 111 PerlIO_printf(Perl_debug_log, "\n");
17c3b450 112#endif /* DEBUGGING */
79072805
LW
113 return 0;
114}