Skip to content

Commit

Permalink
Copy the contents of the %DB::sub entry if it exists
Browse files Browse the repository at this point in the history
Closes RT#50524
  • Loading branch information
ilmari committed Aug 8, 2014
1 parent bcbff2c commit 3967e62
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
34 changes: 34 additions & 0 deletions Name.xs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,40 @@ subname(name, sub)
Safefree(namepv);
name = end;
}

/* under debugger, provide information about sub location */
if (PL_DBsub && CvGV(cv)) {
HV *hv = GvHV(PL_DBsub);

char* new_pkg = HvNAME(stash);

char* old_name = GvNAME( CvGV(cv) );
char* old_pkg = HvNAME( GvSTASH(CvGV(cv)) );

int old_len = strlen(old_name) + strlen(old_pkg);
int new_len = strlen(name) + strlen(new_pkg);

char* full_name;
Newxz(full_name, (old_len > new_len ? old_len : new_len) + 3, char);

strcat(full_name, old_pkg);
strcat(full_name, "::");
strcat(full_name, old_name);

SV** old_data = hv_fetch(hv, full_name, strlen(full_name), 0);

if (old_data) {
strcpy(full_name, new_pkg);
strcat(full_name, "::");
strcat(full_name, name);

SvREFCNT_inc(*old_data);
if (!hv_store(hv, full_name, strlen(full_name), *old_data, 0))
SvREFCNT_dec(*old_data);
}
Safefree(full_name);
}

gv = (GV *) newSV(0);
gv_init(gv, stash, name, s - name, TRUE);

Expand Down
18 changes: 17 additions & 1 deletion t/smoke.t
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#!/usr/bin/perl

BEGIN { print "1..5\n"; }
BEGIN { print "1..10\n"; $^P |= 0x210 }


use Sub::Name;

my $x = subname foo => sub { (caller 0)[3] };
my $line = __LINE__ - 1;
my $file = __FILE__;
my $anon = $DB::sub{"main::__ANON__[${file}:${line}]"};

print $x->() eq "main::foo" ? "ok 1\n" : "not ok 1\n";


Expand All @@ -26,4 +30,16 @@ for (4 .. 5) {
print $x->() eq "Blork::Dynamic $_" ? "ok $_\n" : "not ok $_\n";
}

print $DB::sub{"main::foo"} eq $anon ? "ok 6\n" : "not ok 6\n";

for (4 .. 5) {
print $DB::sub{"Blork::Dynamic $_"} eq $anon ? "ok ".($_+3)."\n" : "not ok ".($_+3)."\n";
}

my $i = 9;
for ("Blork:: Bar!", "Foo::Bar::Baz") {
print $DB::sub{$_} eq $anon ? "ok $i\n" : "not ok $_ \n";
$i++;
}

# vim: ft=perl

0 comments on commit 3967e62

Please sign in to comment.