… | |
… | |
24 | av_push (av, sv_rvweaken (newRV_inc (sv))); \ |
24 | av_push (av, sv_rvweaken (newRV_inc (sv))); \ |
25 | if (rmagical) SvRMAGICAL_off (sv); \ |
25 | if (rmagical) SvRMAGICAL_off (sv); \ |
26 | av_push (about, newRV_noinc ((SV *)av)); \ |
26 | av_push (about, newRV_noinc ((SV *)av)); \ |
27 | } while (0) |
27 | } while (0) |
28 | |
28 | |
29 | #define res_gv(sigil) \ |
29 | #define res_text(text) \ |
30 | do { \ |
30 | do { \ |
31 | AV *av = newAV (); \ |
31 | AV *av = newAV (); \ |
32 | av_push (av, newSVpv (form ("in the global %c%s::%.*s", sigil, \ |
32 | av_push (av, newSVpv (text, 0)); \ |
33 | HvNAME (GvSTASH (sv)), \ |
|
|
34 | GvNAMELEN (sv), GvNAME (sv) ? GvNAME (sv) : "<anonymous>"), \ |
|
|
35 | 0)); \ |
|
|
36 | av_push (about, newRV_noinc ((SV *)av)); \ |
33 | av_push (about, newRV_noinc ((SV *)av)); \ |
37 | } while (0) |
34 | } while (0) |
38 | |
35 | |
|
|
36 | #define res_gv(sigil) \ |
|
|
37 | res_text (form ("in the global %c%s::%.*s", sigil, \ |
|
|
38 | HvNAME (GvSTASH (sv)), \ |
|
|
39 | GvNAMELEN (sv), \ |
|
|
40 | GvNAME (sv) ? GvNAME (sv) : "<anonymous>")) |
|
|
41 | |
39 | MODULE = Devel::FindRef PACKAGE = Devel::FindRef |
42 | MODULE = Devel::FindRef PACKAGE = Devel::FindRef |
40 | |
43 | |
41 | PROTOTYPES: ENABLE |
44 | PROTOTYPES: ENABLE |
42 | |
45 | |
43 | SV * |
46 | SV * |
44 | ptr2ref (IV ptr) |
47 | ptr2ref (UV ptr) |
45 | CODE: |
48 | CODE: |
46 | RETVAL = newRV_inc (INT2PTR (SV *, ptr)); |
49 | RETVAL = newRV_inc (INT2PTR (SV *, ptr)); |
|
|
50 | OUTPUT: |
|
|
51 | RETVAL |
|
|
52 | |
|
|
53 | UV |
|
|
54 | ref2ptr (SV *rv) |
|
|
55 | CODE: |
|
|
56 | RETVAL = PTR2UV (SvRV (rv)); |
47 | OUTPUT: |
57 | OUTPUT: |
48 | RETVAL |
58 | RETVAL |
49 | |
59 | |
50 | void |
60 | void |
51 | find_ (SV *target) |
61 | find_ (SV *target) |
… | |
… | |
79 | if ((rmagical = SvRMAGICAL (sv))) |
89 | if ((rmagical = SvRMAGICAL (sv))) |
80 | SvRMAGICAL_off (sv); |
90 | SvRMAGICAL_off (sv); |
81 | |
91 | |
82 | if (SvTYPE (sv) >= SVt_PVMG) |
92 | if (SvTYPE (sv) >= SVt_PVMG) |
83 | { |
93 | { |
84 | |
|
|
85 | if (SvTYPE (sv) != SVt_PVMG || SvPAD_OUR (sv)) |
94 | if (SvTYPE (sv) == SVt_PVMG && SvPAD_OUR (sv)) |
|
|
95 | { |
|
|
96 | /* I have no clue what this is */ |
|
|
97 | /* maybe some placeholder for our variables for eval? */ |
|
|
98 | /* it doesn't seem to reference anything, so we should be able to ignore it */ |
|
|
99 | } |
|
|
100 | else |
86 | { |
101 | { |
87 | MAGIC *mg = SvMAGIC (sv); |
102 | MAGIC *mg = SvMAGIC (sv); |
88 | |
103 | |
89 | while (mg) |
104 | while (mg) |
90 | { |
105 | { |
… | |
… | |
130 | case SVt_PVCV: |
145 | case SVt_PVCV: |
131 | { |
146 | { |
132 | int depth = CvDEPTH (sv); |
147 | int depth = CvDEPTH (sv); |
133 | |
148 | |
134 | /* Anonymous subs have a padlist but zero depth */ |
149 | /* Anonymous subs have a padlist but zero depth */ |
135 | if (!depth && CvPADLIST (sv)) |
150 | if (CvANON (sv) && !depth && CvPADLIST (sv)) |
136 | depth = 1; |
151 | depth = 1; |
137 | |
152 | |
138 | if (depth) |
153 | if (depth) |
139 | { |
154 | { |
140 | AV *padlist = CvPADLIST (sv); |
155 | AV *padlist = CvPADLIST (sv); |
… | |
… | |
143 | { |
158 | { |
144 | AV *pad = (AV *)AvARRAY (padlist)[depth]; |
159 | AV *pad = (AV *)AvARRAY (padlist)[depth]; |
145 | |
160 | |
146 | av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ |
161 | av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ |
147 | |
162 | |
|
|
163 | /* The 0th pad slot is @_ */ |
|
|
164 | if (AvARRAY (pad)[0] == targ) |
|
|
165 | res_pair ("the argument array for"); |
|
|
166 | |
148 | for (i = AvFILLp (pad) + 1; i--; ) |
167 | for (i = AvFILLp (pad) + 1; --i; ) |
149 | if (AvARRAY (pad)[i] == targ) |
168 | if (AvARRAY (pad)[i] == targ) |
150 | { |
169 | { |
151 | /* Values from constant functions are stored in the pad without any name */ |
170 | /* Values from constant functions are stored in the pad without any name */ |
152 | SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; |
171 | SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; |
153 | |
172 | |
… | |
… | |
164 | if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ) |
183 | if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ) |
165 | res_pair ("the constant value of"); |
184 | res_pair ("the constant value of"); |
166 | |
185 | |
167 | if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ) |
186 | if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ) |
168 | res_pair ("the containing scope for"); |
187 | res_pair ("the containing scope for"); |
|
|
188 | |
|
|
189 | if (sv == targ && CvANON (sv)) |
|
|
190 | if (CvSTART (sv) |
|
|
191 | && CvSTART (sv)->op_type == OP_NEXTSTATE |
|
|
192 | && CopLINE ((COP *)CvSTART (sv))) |
|
|
193 | res_text (form ("the closure created at %s:%d", |
|
|
194 | CopFILE ((COP *)CvSTART (sv)) ? CopFILE ((COP *)CvSTART (sv)) : "<unknown>", |
|
|
195 | CopLINE ((COP *)CvSTART (sv)))); |
|
|
196 | else |
|
|
197 | res_text (form ("the closure created somewhere in file %s (PLEASE REPORT!)", |
|
|
198 | CvFILE (sv) ? CvFILE (sv) : "<unknown>")); |
169 | } |
199 | } |
170 | |
200 | |
171 | break; |
201 | break; |
172 | |
202 | |
173 | case SVt_PVGV: |
203 | case SVt_PVGV: |
… | |
… | |
185 | if (rmagical) |
215 | if (rmagical) |
186 | SvRMAGICAL_on (sv); |
216 | SvRMAGICAL_on (sv); |
187 | } |
217 | } |
188 | } |
218 | } |
189 | |
219 | |
|
|
220 | if (targ == (SV*)PL_main_cv) |
|
|
221 | res_text ("the main body of the program"); |
|
|
222 | |
190 | EXTEND (SP, 2); |
223 | EXTEND (SP, 2); |
191 | PUSHs (sv_2mortal (newRV_noinc ((SV *)about))); |
224 | PUSHs (sv_2mortal (newRV_noinc ((SV *)about))); |
192 | PUSHs (sv_2mortal (newRV_noinc ((SV *)excl))); |
225 | PUSHs (sv_2mortal (newRV_noinc ((SV *)excl))); |
193 | } |
226 | } |
194 | |
227 | |