… | |
… | |
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 | |
|
|
43 | SV * |
|
|
44 | ptr2ref (IV ptr) |
|
|
45 | CODE: |
|
|
46 | RETVAL = newRV_inc (INT2PTR (SV *, ptr)); |
|
|
47 | OUTPUT: |
|
|
48 | RETVAL |
|
|
49 | |
45 | |
50 | void |
46 | void |
51 | find_ (SV *target) |
47 | find_ (SV *target) |
52 | PPCODE: |
48 | PPCODE: |
53 | { |
49 | { |
… | |
… | |
79 | if ((rmagical = SvRMAGICAL (sv))) |
75 | if ((rmagical = SvRMAGICAL (sv))) |
80 | SvRMAGICAL_off (sv); |
76 | SvRMAGICAL_off (sv); |
81 | |
77 | |
82 | if (SvTYPE (sv) >= SVt_PVMG) |
78 | if (SvTYPE (sv) >= SVt_PVMG) |
83 | { |
79 | { |
84 | |
|
|
85 | if (SvTYPE (sv) != SVt_PVMG || SvPAD_OUR (sv)) |
80 | if (SvTYPE (sv) == SVt_PVMG && SvPAD_OUR (sv)) |
|
|
81 | { |
|
|
82 | /* I have no clue what this is */ |
|
|
83 | /* maybe some placeholder for our variables for eval? */ |
|
|
84 | /* it doesn't seem to reference anything, so we should be able to ignore it */ |
|
|
85 | } |
|
|
86 | else |
86 | { |
87 | { |
87 | MAGIC *mg = SvMAGIC (sv); |
88 | MAGIC *mg = SvMAGIC (sv); |
88 | |
89 | |
89 | while (mg) |
90 | while (mg) |
90 | { |
91 | { |
… | |
… | |
97 | mg = mg->mg_moremagic; |
98 | mg = mg->mg_moremagic; |
98 | } |
99 | } |
99 | } |
100 | } |
100 | } |
101 | } |
101 | |
102 | |
102 | if (SvROK (sv)) |
103 | if (SvROK (sv) && !SvWEAKREF (sv)) |
103 | { |
104 | { |
104 | if (sv != target && SvRV (sv) == targ && !SvWEAKREF (sv)) |
105 | if (sv != target && SvRV (sv) == targ && !SvWEAKREF (sv)) |
105 | res_pair ("referenced by"); |
106 | res_pair ("referenced by"); |
106 | } |
107 | } |
107 | else |
108 | else |
… | |
… | |
130 | case SVt_PVCV: |
131 | case SVt_PVCV: |
131 | { |
132 | { |
132 | int depth = CvDEPTH (sv); |
133 | int depth = CvDEPTH (sv); |
133 | |
134 | |
134 | /* Anonymous subs have a padlist but zero depth */ |
135 | /* Anonymous subs have a padlist but zero depth */ |
135 | if (!depth && CvPADLIST (sv)) |
136 | if (CvANON (sv) && !depth && CvPADLIST (sv)) |
136 | depth = 1; |
137 | depth = 1; |
137 | |
138 | |
138 | if (depth) |
139 | if (depth) |
139 | { |
140 | { |
140 | AV *padlist = CvPADLIST (sv); |
141 | AV *padlist = CvPADLIST (sv); |
… | |
… | |
143 | { |
144 | { |
144 | AV *pad = (AV *)AvARRAY (padlist)[depth]; |
145 | AV *pad = (AV *)AvARRAY (padlist)[depth]; |
145 | |
146 | |
146 | av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ |
147 | av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ |
147 | |
148 | |
|
|
149 | /* The 0th pad slot is @_ */ |
|
|
150 | if (AvARRAY (pad)[0] == targ) |
|
|
151 | res_pair ("the argument array for"); |
|
|
152 | |
148 | for (i = AvFILLp (pad) + 1; i--; ) |
153 | for (i = AvFILLp (pad) + 1; --i; ) |
149 | if (AvARRAY (pad)[i] == targ) |
154 | if (AvARRAY (pad)[i] == targ) |
150 | { |
155 | { |
151 | /* Values from constant functions are stored in the pad without any name */ |
156 | /* Values from constant functions are stored in the pad without any name */ |
152 | SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; |
157 | SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; |
153 | |
158 | |
… | |
… | |
164 | if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ) |
169 | if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ) |
165 | res_pair ("the constant value of"); |
170 | res_pair ("the constant value of"); |
166 | |
171 | |
167 | if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ) |
172 | if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ) |
168 | res_pair ("the containing scope for"); |
173 | res_pair ("the containing scope for"); |
|
|
174 | |
|
|
175 | if (sv == targ && CvANON (sv)) |
|
|
176 | if (CvSTART (sv) |
|
|
177 | && CvSTART (sv)->op_type == OP_NEXTSTATE |
|
|
178 | && CopLINE ((COP *)CvSTART (sv))) |
|
|
179 | res_text (form ("the closure created at %s:%d", |
|
|
180 | CopFILE ((COP *)CvSTART (sv)) ? CopFILE ((COP *)CvSTART (sv)) : "<unknown>", |
|
|
181 | CopLINE ((COP *)CvSTART (sv)))); |
|
|
182 | else |
|
|
183 | res_text (form ("the closure created somewhere in file %s (PLEASE REPORT!)", |
|
|
184 | CvFILE (sv) ? CvFILE (sv) : "<unknown>")); |
169 | } |
185 | } |
170 | |
186 | |
171 | break; |
187 | break; |
172 | |
188 | |
173 | case SVt_PVGV: |
189 | case SVt_PVGV: |
… | |
… | |
185 | if (rmagical) |
201 | if (rmagical) |
186 | SvRMAGICAL_on (sv); |
202 | SvRMAGICAL_on (sv); |
187 | } |
203 | } |
188 | } |
204 | } |
189 | |
205 | |
|
|
206 | if (targ == (SV*)PL_main_cv) |
|
|
207 | res_text ("the main body of the program"); |
|
|
208 | |
190 | EXTEND (SP, 2); |
209 | EXTEND (SP, 2); |
191 | PUSHs (sv_2mortal (newRV_noinc ((SV *)about))); |
210 | PUSHs (sv_2mortal (newRV_noinc ((SV *)about))); |
192 | PUSHs (sv_2mortal (newRV_noinc ((SV *)excl))); |
211 | PUSHs (sv_2mortal (newRV_noinc ((SV *)excl))); |
193 | } |
212 | } |
194 | |
213 | |
|
|
214 | SV * |
|
|
215 | ptr2ref (UV ptr) |
|
|
216 | CODE: |
|
|
217 | RETVAL = newRV_inc (INT2PTR (SV *, ptr)); |
|
|
218 | OUTPUT: |
|
|
219 | RETVAL |
|
|
220 | |
|
|
221 | UV |
|
|
222 | ref2ptr (SV *rv) |
|
|
223 | CODE: |
|
|
224 | RETVAL = PTR2UV (SvRV (rv)); |
|
|
225 | OUTPUT: |
|
|
226 | RETVAL |
|
|
227 | |
|
|
228 | U32 |
|
|
229 | _refcnt (SV *rv) |
|
|
230 | CODE: |
|
|
231 | RETVAL = SvREFCNT (SvRV (rv)); |
|
|
232 | OUTPUT: |
|
|
233 | RETVAL |