… | |
… | |
18 | |
18 | |
19 | /* pre-5.10 perls always succeed, with 5.10, we have to check first apparently */ |
19 | /* pre-5.10 perls always succeed, with 5.10, we have to check first apparently */ |
20 | #ifndef GvNAME_HEK |
20 | #ifndef GvNAME_HEK |
21 | # define GvNAME_HEK(sv) 1 |
21 | # define GvNAME_HEK(sv) 1 |
22 | #endif |
22 | #endif |
|
|
23 | |
|
|
24 | #ifndef PadARRAY |
|
|
25 | # define PadARRAY(pad) AvARRAY (pad) |
|
|
26 | # define PadlistARRAY(pl) ((PAD **)AvARRAY (pl)) |
|
|
27 | #endif |
|
|
28 | |
23 | |
29 | |
24 | #define res_pair(text) \ |
30 | #define res_pair(text) \ |
25 | do { \ |
31 | do { \ |
26 | AV *av = newAV (); \ |
32 | AV *av = newAV (); \ |
27 | av_push (av, newSVpv (text, 0)); \ |
33 | av_push (av, newSVpv (text, 0)); \ |
… | |
… | |
37 | av_push (av, newSVpv (text, 0)); \ |
43 | av_push (av, newSVpv (text, 0)); \ |
38 | av_push (about, newRV_noinc ((SV *)av)); \ |
44 | av_push (about, newRV_noinc ((SV *)av)); \ |
39 | } while (0) |
45 | } while (0) |
40 | |
46 | |
41 | #define res_gv(sigil) \ |
47 | #define res_gv(sigil) \ |
42 | res_text (form ("in the global %c%s::%.*s", sigil, \ |
48 | res_text (form ("the global %c%s::%.*s", sigil, \ |
43 | HvNAME (GvSTASH (sv)), \ |
49 | HvNAME (GvSTASH (sv)), \ |
44 | GvNAME_HEK (sv) ? GvNAMELEN (sv) : 11, \ |
50 | GvNAME_HEK (sv) ? GvNAMELEN (sv) : 11, \ |
45 | GvNAME_HEK (sv) ? GvNAME (sv) : "<anonymous>")) |
51 | GvNAME_HEK (sv) ? GvNAME (sv) : "<anonymous>")) |
46 | |
52 | |
47 | MODULE = Devel::FindRef PACKAGE = Devel::FindRef |
53 | MODULE = Devel::FindRef PACKAGE = Devel::FindRef |
… | |
… | |
101 | { |
107 | { |
102 | /* I have no clue what this is */ |
108 | /* I have no clue what this is */ |
103 | /* maybe some placeholder for our variables for eval? */ |
109 | /* maybe some placeholder for our variables for eval? */ |
104 | /* it doesn't seem to reference anything, so we should be able to ignore it */ |
110 | /* it doesn't seem to reference anything, so we should be able to ignore it */ |
105 | } |
111 | } |
106 | else |
112 | else if (SvMAGICAL (sv)) /* name-pads use SvMAGIC for other purposes */ |
107 | { |
113 | { |
108 | MAGIC *mg = SvMAGIC (sv); |
114 | MAGIC *mg = SvMAGIC (sv); |
109 | |
115 | |
110 | while (mg) |
116 | while (mg) |
111 | { |
117 | { |
… | |
… | |
132 | { |
138 | { |
133 | case SVt_PVAV: |
139 | case SVt_PVAV: |
134 | if (AvREAL (sv)) |
140 | if (AvREAL (sv)) |
135 | for (i = AvFILLp (sv) + 1; i--; ) |
141 | for (i = AvFILLp (sv) + 1; i--; ) |
136 | if (AvARRAY (sv)[i] == targ) |
142 | if (AvARRAY (sv)[i] == targ) |
137 | res_pair (form ("in array element %d of", i)); |
143 | res_pair (form ("the array element %d of", i)); |
138 | |
144 | |
139 | break; |
145 | break; |
140 | |
146 | |
141 | case SVt_PVHV: |
147 | case SVt_PVHV: |
142 | if (hv_iterinit ((HV *)sv)) |
148 | if (hv_iterinit ((HV *)sv)) |
143 | { |
149 | { |
144 | HE *he; |
150 | HE *he; |
145 | |
151 | |
146 | while ((he = hv_iternext ((HV *)sv))) |
152 | while ((he = hv_iternext ((HV *)sv))) |
147 | if (HeVAL (he) == targ) |
153 | if (HeVAL (he) == targ) |
148 | res_pair (form ("in the member '%.*s' of", HeKLEN (he), HeKEY (he))); |
154 | res_pair (form ("the hash member '%.*s' of", HeKLEN (he), HeKEY (he))); |
149 | } |
155 | } |
150 | |
156 | |
151 | break; |
157 | break; |
152 | |
158 | |
153 | case SVt_PVCV: |
159 | case SVt_PVCV: |
154 | { |
160 | { |
155 | int depth = CvDEPTH (sv); |
161 | PADLIST *padlist = CvPADLIST (sv); |
156 | |
162 | |
157 | /* Anonymous subs have a padlist but zero depth */ |
|
|
158 | if (CvANON (sv) && !depth && CvPADLIST (sv)) |
|
|
159 | depth = 1; |
|
|
160 | |
|
|
161 | if (depth) |
163 | if (padlist) |
162 | { |
164 | { |
163 | AV *padlist = CvPADLIST (sv); |
165 | int depth = CvDEPTH (sv); |
|
|
166 | |
|
|
167 | /* Anonymous subs have a padlist but zero depth */ |
|
|
168 | /* some hacks switch CvANON off, so we just blindly assume a minimum of 1 */ |
|
|
169 | if (!depth) |
|
|
170 | depth = 1; |
164 | |
171 | |
165 | while (depth) |
172 | while (depth) |
166 | { |
173 | { |
167 | AV *pad = (AV *)AvARRAY (padlist)[depth]; |
174 | PAD *pad = PadlistARRAY (padlist)[depth]; |
168 | |
175 | |
169 | av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ |
176 | av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ |
170 | |
177 | |
171 | /* The 0th pad slot is @_ */ |
178 | /* The 0th pad slot is @_ */ |
172 | if (AvARRAY (pad)[0] == targ) |
179 | if (PadARRAY (pad)[0] == targ) |
173 | res_pair ("the argument array for"); |
180 | res_pair ("the argument array for"); |
174 | |
181 | |
175 | for (i = AvFILLp (pad) + 1; --i; ) |
182 | for (i = AvFILLp (pad) + 1; --i; ) |
176 | if (AvARRAY (pad)[i] == targ) |
183 | if (AvARRAY (pad)[i] == targ) |
177 | { |
184 | { |
178 | /* Values from constant functions are stored in the pad without any name */ |
185 | /* Values from constant functions are stored in the pad without any name */ |
179 | SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; |
186 | SV *name_sv = PadARRAY (PadlistARRAY (padlist)[0])[i]; |
180 | |
187 | |
181 | if (name_sv && SvPOK (name_sv)) |
188 | if (name_sv && SvPOK (name_sv)) |
182 | res_pair (form ("the lexical '%s' in", SvPVX (name_sv))); |
189 | res_pair (form ("the lexical '%s' in", SvPVX (name_sv))); |
183 | else |
190 | else |
184 | res_pair ("an unnamed lexical in"); |
191 | res_pair ("an unnamed lexical in"); |
… | |
… | |
226 | { |
233 | { |
227 | MAGIC *mg = mg_find (sv, PERL_MAGIC_defelem); |
234 | MAGIC *mg = mg_find (sv, PERL_MAGIC_defelem); |
228 | |
235 | |
229 | if (mg && mg->mg_obj) |
236 | if (mg && mg->mg_obj) |
230 | res_pair (form ("the target for the lvalue hash element '%.*s',", |
237 | res_pair (form ("the target for the lvalue hash element '%.*s',", |
231 | SvCUR (mg->mg_obj), SvPV_nolen (mg->mg_obj))); |
238 | (int)SvCUR (mg->mg_obj), SvPV_nolen (mg->mg_obj))); |
232 | else |
239 | else |
233 | res_pair (form ("the target for the lvalue array element #%d,", LvTARGOFF (sv))); |
240 | res_pair (form ("the target for the lvalue array element #%d,", LvTARGOFF (sv))); |
234 | } |
241 | } |
235 | else |
242 | else |
236 | res_pair (form ("an lvalue reference target (type '%c', ofs %d, len %d),", |
243 | res_pair (form ("an lvalue reference target (type '%c', ofs %d, len %d),", |