forked from openresty/openresty-systemtap-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 3
/
fix-lua-bt
executable file
·80 lines (60 loc) · 1.63 KB
/
fix-lua-bt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env perl
use 5.006001;
use strict;
use warnings;
my $infile = shift or
die "No input file specified.\n";
my %funcs;
open my $in, $infile
or die "Cannot open $infile for reading: $!\n";
while (<$in>) {
if (/^((?:\w+:)?)\@(.*):(\d+)/) {
my ($prefix, $path, $ln) = ($1, $2, $3);
my $key = "$path:$ln";
my $func = $funcs{$key};
if (defined $func) {
#warn "Found $key\n";
print "$func\n";
next;
}
#print "looking for $path:$ln\n";
my $file;
if ($path =~ m{lib((?:\/[-\w]+)+)\.lua}) {
$file = $1;
$file =~ s/^\///g;
$file =~ s/\//\./g;
$file =~ s/-/_/g;
} elsif ($path =~ m{[-\w]+\.lua}) {
$file = $&;
} else {
$file = $path;
}
if ($ln > 0) {
open my $in, $path
or die "failed to open $path for reading: $!\n";
while (<$in>) {
if ($. == $ln) {
if (/function\s+((?:\w+[.:])*\w+)\s*\(/) {
$func = $1;
} elsif (/(\S+)\s*=\s*function\s*\(/) {
$func = $1;
} else {
$func = $ln;
}
last;
}
}
close $in;
if (!defined $func) {
die "$path:$ln not found.\n";
}
} else {
$func = $ln;
}
$funcs{$key} = "$file:$func";
print "$prefix$file:$func\n";
} else {
print $_;
}
}
close $in;