Dpkg/Shlibs/Symbol.pm

filter: Statementstmt 93.6% 236 / 252 Branchbran 77.6% 101 / 130 Conditioncond 65.2% 47 / 72 MC/DCmcdc 39.0% 16 / 41 Subroutinesub 95.1% 39 / 41 Podpod 0.0% 0 / 31 totaltotal 77.4% 439 / 567 CC 98 SCAR 21.7
CC
98
Cov
85%
equals
24.9
set_symbolname
15.2
initialize
11.4
CRAP 8.8
« Dpkg/Path.pm ↑ Summary Dpkg/Color.pm »
1 # Copyright © 2007 Raphaël Hertzog <hertzog@debian.org>
2 # Copyright © 2009-2010 Modestas Vainius <modax@debian.org>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16  
17 =encoding utf8
18  
19 =head1 NAME
20  
21 Dpkg::Shlibs::Symbol - represent an object file symbol
22  
23 =head1 DESCRIPTION
24  
25 This module provides a class to handle symbols from an executable or
26 shared object file.
27  
28 B<Note>: This is a private module, its API can change at any time.
29  
30 =cut
31  
32 package Dpkg::Shlibs::Symbol 0.01;
33  
34 2 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 2 ▶use Storable ();
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 2 ▶use Dpkg::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use Dpkg::ErrorHandling;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 2 ▶use Dpkg::Arch qw(debarch_is_concerned debarch_to_abiattrs);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 2 ▶use Dpkg::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 2 ▶use Dpkg::Shlibs::Cppfilt;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 # Supported alias types in the order of matching preference.
46 2 ▶use constant ALIAS_TYPES => qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
47 c++
48 symver
49 2 );
50  
51 14279 ▶sub new {
Subroutine new: called CC=3 SCAR=11.4
Pod undocumented
52 14279 my ($this, %opts) = @_;
53 14279 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0142790
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
54 14279 my $self = bless {
55 symbol => undef,
56 symbol_templ => undef,
57 minver => undef,
58 dep_id => 0,
59 deprecated => 0,
60 tags => {},
61 tagorder => [],
62 }, $class;
63 14279 $self->{$_} = $opts{$_} foreach keys %opts;
64 14279 return $self;
65 }
66  
67 # Deep clone.
68 237 ▶sub clone {
Subroutine clone: called CC=2 SCAR=6.9
Pod undocumented
69 237 my ($self, %opts) = @_;
70 237 my $clone = Storable::dclone($self);
71 237 $clone->{$_} = $opts{$_} foreach keys %opts;
72 237 return $clone;
73 }
74  
75 5257 ▶sub parse_tagspec {
Subroutine parse_tagspec: called CC=6 SCAR=17.9
Pod undocumented
76 5257 my ($self, $tagspec) = @_;
77  
78 5257 ▶ if ($tagspec =~ /^\s*\((.*?)\)(.*)$/ && $1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagspec =~ /^\s*\((.*?)\)(.*)$/u and $1) 233 5024 5257
Condition66%2/3
$tagspec =~ /^\s*\((.*?)\)(.*)$/u and $1
!ll&&!rl&&r
50240233
MC/DC50%1/2
$tagspec =~ /^\s*\((.*?)\)(.*)$/u and $1
$tagspec =~ /^\s*\((.*?)\)(.*)$/u $1
Truth table66%2/3
A and B
A= $tagspec =~ /^\s*\((.*?)\)(.*)$/uB= $1
ABresult
0X0
100
111
79 # Format:
80 # (tag1=t1 value|tag2|...|tagN=tNp)
81 # Symbols ()|= cannot appear in the tag names and values.
82 233 $tagspec = $1;
83 233 ▶ my $rest = ($2) ? $2 : '';
Branch: 1 branch
BranchTrueFalseTotal
$2 ? : 227 6 233
84 233 my @tags = split(/\|/, $tagspec);
85  
86 # Parse each tag.
87 233 for my $tag (@tags) {
88 334 ▶ if ($tag =~ /^(.*)=(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /^(.*)=(.*)$/u) { } 174 160 334
89 # Tag with value.
90 174 $self->add_tag($1, $2);
91 } else {
92 # Tag without value.
93 160 $self->add_tag($tag, undef);
94 }
95 }
96 233 return $rest;
97 }
98 5024 return;
99 }
100  
101 5251 ▶sub parse_symbolspec {
Subroutine parse_symbolspec: called CC=11 SCAR=24.3
Pod undocumented
102 5251 my ($self, $symbolspec, %opts) = @_;
103 5251 my $symbol;
104 my $symbol_templ;
105 5251 my $symbol_quoted;
106 5251 my $rest;
107  
108 5251 ▶ if (defined($symbol = $self->parse_tagspec($symbolspec))) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined($symbol = $self->parse_tagspec($symbolspec))) { } 227 5024 5251
elsif ($symbolspec =~ /^(\S+)(.*)$/u) { } 5024 0 5024
109 # Format:
110 # (tag1=t1 value|tag2|...|tagN=tNp)"Foo::Bar::foobar()"@Base 1.0 1
111 # Symbols ()|= cannot appear in the tag names and values.
112  
113 # If the tag specification exists, symbol name template might be
114 # quoted too.
115 227 ▶ if ($symbol =~ /^(['"])/ && $symbol =~ /^($1)(.*?)$1(.*)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($symbol =~ /^(['"])/u and $symbol =~ /^($1)(.*?)$1(.*)$/u) { } 59 168 227
elsif ($symbol =~ /^(\S+)(.*)$/u) { } 168 0 168
Condition66%2/3
$symbol =~ /^(['"])/u and $symbol =~ /^($1)(.*?)$1(.*)$/u
!ll&&!rl&&r
168059
MC/DC50%1/2
$symbol =~ /^(['"])/u and $symbol =~ /^($1)(.*?)$1(.*)$/u
$symbol =~ /^(['"])/u $symbol =~ /^($1)(.*?)$1(.*)$/u
Truth table66%2/3
A and B
A= $symbol =~ /^(['"])/uB= $symbol =~ /^($1)(.*?)$1(.*)$/u
ABresult
0X0
100
111
116 59 $symbol_quoted = $1;
117 59 $symbol_templ = $2;
118 59 $symbol = $2;
119 59 $rest = $3;
120 } elsif ($symbol =~ m/^(\S+)(.*)$/) {
121 168 $symbol_templ = $1;
122 168 $symbol = $1;
123 168 $rest = $2;
124 }
125 227 ▶ error(g_('symbol name unspecified: %s'), $symbolspec) if (! $symbol);
Branch: 1 branch
BranchTrueFalseTotal
unless $symbol 0 227 227
126 } elsif ($symbolspec =~ m/^(\S+)(.*)$/) {
127 # Format:
128 # foobarsymbol@Base 1.0 1
129 # No tag specification. Symbol name is up to the first space.
130 5024 $symbol = $1;
131 5024 $rest = $2;
132 } else {
133 0 return 0;
134 }
135 5251 $self->{symbol} = $symbol;
136 5251 $self->{symbol_templ} = $symbol_templ;
137 5251 ▶ $self->{symbol_quoted} = $symbol_quoted if ($symbol_quoted);
Branch: 1 branch
BranchTrueFalseTotal
if $symbol_quoted 59 5192 5251
138  
139 # Now parse "the rest" (minver and dep_id).
140 5251 ▶ if ($rest =~ /^\s(\S+)(?:\s(\d+))?/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rest =~ /^\s(\S+)(?:\s(\d+))?/u) { } 5250 1 5251
elsif (defined $opts{'default_minver'}) { } 1 0 1
141 5250 $self->{minver} = $1;
142 5250 ▶ $self->{dep_id} = $2 // 0;
Condition100%2/2
$2 // 0
l!l
165234
MC/DC100%1/1
$2 // 0
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
143 } elsif (defined $opts{default_minver}) {
144 1 $self->{minver} = $opts{default_minver};
145 1 $self->{dep_id} = 0;
146 } else {
147 0 return 0;
148 }
149 5251 return 1;
150 }
151  
152 # A hook for symbol initialization (typically processing of tags). The code
153 # here may even change symbol name. Called from
154 # Dpkg::Shlibs::SymbolFile::create_symbol().
155 5251 ▶sub initialize {
Subroutine initialize: called CC=11 SCAR=24.3
Pod undocumented
156 5251 my $self = shift;
157  
158 # Look for tags marking symbol patterns. The pattern may match multiple
159 # real symbols.
160 5251 my $type;
161 5251 ▶ if ($self->has_tag('c++')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_tag("c++")) 71 5180 5251
162 # The raw symbol name is always demangled to the same alias, while
163 # demangled symbol name cannot be reliably converted back to raw
164 # symbol name. Therefore, we can use a hash for mapping.
165 71 $type = 'alias-c++';
166 }
167  
168 # Support old style wildcard syntax. That is a symver with an optional tag.
169 5251 ▶ if ($self->get_symbolname() =~ /^\*@(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_symbolname =~ /^\*@(.*)$/u) 3 5248 5251
170 3 warning(g_('deprecated wildcard syntax in "%s"; use "%s" instead'),
171 $self->get_symbolname(), "(symver|optional)$1");
172 3 ▶ $self->add_tag('symver') unless $self->has_tag('symver');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_tag("symver") 3 0 3
173 3 ▶ $self->add_tag('optional') unless $self->has_tag('optional');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_tag("optional") 3 0 3
174 3 $self->{symbol} = $1;
175 }
176  
177 5251 ▶ if ($self->has_tag('symver')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_tag("symver")) 27 5224 5251
178 # Each symbol is matched against its version rather than full
179 # name@version string.
180 27 ▶ $type = (defined $type) ? 'generic' : 'alias-symver';
Branch: 1 branch
BranchTrueFalseTotal
defined $type ? : 12 15 27
181 27 ▶ if ($self->get_symbolname() =~ /@/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_symbolname =~ /@/u) 0 27 27
182 0 warning(g_('symver tag with versioned symbol will not match: %s'),
183 $self->get_symbolspec(1));
184 }
185 27 ▶ if ($self->get_symbolname() eq 'Base') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_symbolname eq "Base") 0 27 27
186 0 error(g_('cannot use symver tag to match unversioned symbols: %s'),
187 $self->get_symbolspec(1));
188 }
189 }
190  
191 # As soon as "regex" is involved, we need to match each real symbol
192 # against each pattern (aka 'generic' pattern).
193 5251 ▶ if ($self->has_tag('regex')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_tag("regex")) 25 5226 5251
194 25 $type = 'generic';
195 # Pre-compile regular expression for better performance.
196 25 my $regex = $self->get_symbolname();
197 25 $self->{pattern}{regex} = qr/$regex/;
198 }
199 5251 ▶ if (defined $type) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) 86 5165 5251
200 86 $self->init_pattern($type);
201 }
202 }
203  
204 61739 ▶sub get_symbolname {
Subroutine get_symbolname: called CC=1 SCAR=0.0
Pod undocumented
205 61739 my $self = shift;
206  
207 61739 return $self->{symbol};
208 }
209  
210 272126 ▶sub get_symboltempl {
Subroutine get_symboltempl: called CC=2 SCAR=7.1
Pod undocumented
211 272126 my $self = shift;
212  
213 272126 ▶ return $self->{symbol_templ} || $self->{symbol};
Condition66%2/3
$self->{'symbol_templ'} || $self->{'symbol'}
l!l&&r!l&&!r
12342708920
MC/DC0%0/2
$self->{'symbol_templ'} || $self->{'symbol'}
$self->{'symbol_templ'} $self->{'symbol'}
Truth table66%2/3
A || B
A= $self->{'symbol_templ'}B= $self->{'symbol'}
ABresult
1X1
011
000
214 }
215  
216 195 ▶sub set_symbolname {
Subroutine set_symbolname: called CC=8 SCAR=27.2
Pod undocumented
217 195 my ($self, $name, $templ, $quoted) = @_;
218  
219 195 ▶ $name //= $self->{symbol};
Condition33%1/3
$name //= $self->{"symbol"}
l!l&&r!l&&!r
01950
MC/DC0%0/2
$name //= $self->{"symbol"}
$name $self->{"symbol"}
Truth table33%1/3
A //= B
A= $nameB= $self->{"symbol"}
ABresult
1X1
011
000
220 195 ▶ if (! defined $templ && $name =~ /\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $templ and $name =~ /\s/u) 0 195 195
Condition33%1/3
not defined $templ and $name =~ /\s/u
!ll&&!rl&&r
01950
MC/DC0%0/2
not defined $templ and $name =~ /\s/u
not defined $templ $name =~ /\s/u
Truth table33%1/3
not(A) and B
A= not defined $templB= $name =~ /\s/u
ABresult
0X0
100
111
221 0 $templ = $name;
222 }
223 195 ▶ if (! defined $quoted && defined $templ && $templ =~ /\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $quoted and defined $templ and $templ =~ /\s/u) 0 195 195
Condition33%2/6
not defined $quoted and defined $templ and $templ =~ /\s/u
!ll&&!rl&&r
19500
not defined $quoted and defined $templ
!ll&&!rl&&r
01950
MC/DC0%0/3
not defined $quoted and defined $templ and $templ =~ /\s/u
not defined $quoted defined $templ $templ =~ /\s/u
Truth table25%1/4
not(A) and B and C
A= not defined $quotedB= defined $templC= $templ =~ /\s/u
ABCresult
0XX0
10X0
1100
1111
224 0 $quoted = '"';
225 }
226 195 $self->{symbol} = $name;
227 195 $self->{symbol_templ} = $templ;
228 195 ▶ if ($quoted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quoted) { } 0 195 195
229 0 $self->{symbol_quoted} = $quoted;
230 } else {
231 195 delete $self->{symbol_quoted};
232 }
233 }
234  
235 162 ▶sub has_tags {
Subroutine has_tags: called CC=1 SCAR=0.0
Pod undocumented
236 162 my $self = shift;
237 162 return scalar (@{$self->{tagorder}});
238 }
239  
240 340 ▶sub add_tag {
Subroutine add_tag: called CC=2 SCAR=6.9
Pod undocumented
241 340 my ($self, $tagname, $tagval) = @_;
242 340 ▶ if (exists $self->{tags}{$tagname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'tags'}{$tagname}) { } 6 334 340
243 6 $self->{tags}{$tagname} = $tagval;
244 6 return 0;
245 } else {
246 334 $self->{tags}{$tagname} = $tagval;
247 334 push @{$self->{tagorder}}, $tagname;
248 }
249 334 return 1;
250 }
251  
252 6 ▶sub delete_tag {
Subroutine delete_tag: called CC=2 SCAR=6.9
Pod undocumented
253 6 my ($self, $tagname) = @_;
254 6 ▶ if (exists $self->{tags}{$tagname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"tags"}{$tagname}) 2 4 6
255 2 delete $self->{tags}{$tagname};
256 2 $self->{tagorder} = [ grep { $_ ne $tagname } @{$self->{tagorder}} ];
257 2 return 1;
258 }
259 4 return 0;
260 }
261  
262 25316 ▶sub has_tag {
Subroutine has_tag: called CC=1 SCAR=0.0
Pod undocumented
263 25316 my ($self, $tag) = @_;
264 25316 return exists $self->{tags}{$tag};
265 }
266  
267 0 ▶sub get_tag_value {
Subroutine get_tag_value: not called CC=1 SCAR=6.9
Pod undocumented
268 0 my ($self, $tag) = @_;
269 0 return $self->{tags}{$tag};
270 }
271  
272 # Checks if the symbol is equal to another one, by name and optionally,
273 # tag sets, versioning info (minver and depid).
274 116 ▶sub equals {
Subroutine equals: called CC=16 SCAR=32.2
Pod undocumented
275 116 my ($self, $other, %opts) = @_;
276 116 ▶ $opts{versioning} //= 1;
Condition100%2/2
$opts{"versioning"} //= 1
l!l
1151
MC/DC100%1/1
$opts{"versioning"} //= 1
$opts{"versioning"}
Truth table100%2/2
A
A= $opts{"versioning"}
Aresult
11
00
277 116 ▶ $opts{tags} //= 1;
Condition50%1/2
$opts{"tags"} //= 1
l!l
0116
MC/DC0%0/1
$opts{"tags"} //= 1
$opts{"tags"}
Truth table50%1/2
A
A= $opts{"tags"}
Aresult
11
00
278  
279 116 ▶ return 0 if $self->{symbol} ne $other->{symbol};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"symbol"} ne $other->{"symbol"} 68 48 116
280  
281 48 ▶ if ($opts{versioning}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"versioning"}) 1 47 48
282 1 ▶ return 0 if $self->{minver} ne $other->{minver};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"minver"} ne $other->{"minver"} 0 1 1
283 1 ▶ return 0 if $self->{dep_id} ne $other->{dep_id};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dep_id"} ne $other->{"dep_id"} 0 1 1
284 }
285  
286 48 ▶ if ($opts{tags}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"tags"}) 48 0 48
287 48 ▶ return 0 if scalar(@{$self->{tagorder}}) != scalar(@{$other->{tagorder}});
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$self->{"tagorder"};} != scalar @{$other->{"tagorder"};} 0 48 48
288  
289 48 for my $i (0 .. scalar(@{$self->{tagorder}}) - 1) {
290 99 my $tag = $self->{tagorder}->[$i];
291 99 ▶ return 0 if $tag ne $other->{tagorder}->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $tag ne $other->{"tagorder"}[$i] 0 99 99
292 99 ▶ if (defined $self->{tags}{$tag} && defined $other->{tags}{$tag}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'tags'}{$tag} and defined $other->{'tags'}{$tag}) { } 0 99 99
elsif (defined $self->{'tags'}{$tag} or defined $other->{'tags'}{$tag}) { } 0 99 99
Condition33%1/3
defined $self->{"tags"}{$tag} and defined $other->{"tags"}{$tag}
!ll&&!rl&&r
9900
MC/DC0%0/2
defined $self->{"tags"}{$tag} and defined $other->{"tags"}{$tag}
defined $self->{"tags"}{$tag} defined $other->{"tags"}{$tag}
Truth table33%1/3
A and B
A= defined $self->{"tags"}{$tag}B= defined $other->{"tags"}{$tag}
ABresult
0X0
100
111
293 0 ▶ return 0 if $self->{tags}{$tag} ne $other->{tags}{$tag};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tags"}{$tag} ne $other->{"tags"}{$tag} 0 0 0
294 ▶ } elsif (defined $self->{tags}{$tag} || defined $other->{tags}{$tag}) {
Condition33%1/3
defined $self->{"tags"}{$tag} or defined $other->{"tags"}{$tag}
l!l&&r!l&&!r
0099
MC/DC0%0/2
defined $self->{"tags"}{$tag} or defined $other->{"tags"}{$tag}
defined $self->{"tags"}{$tag} defined $other->{"tags"}{$tag}
Truth table33%1/3
A or B
A= defined $self->{"tags"}{$tag}B= defined $other->{"tags"}{$tag}
ABresult
1X1
011
000
295 0 return 0;
296 }
297 }
298 }
299  
300 48 return 1;
301 }
302  
303  
304 9541 ▶sub is_optional {
Subroutine is_optional: called CC=1 SCAR=0.0
Pod undocumented
305 9541 my $self = shift;
306 9541 return $self->has_tag('optional');
307 }
308  
309 0 ▶sub is_arch_specific {
Subroutine is_arch_specific: not called CC=1 SCAR=6.9
Pod undocumented
310 0 my $self = shift;
311 0 return $self->has_tag('arch');
312 }
313  
314 41430 ▶sub arch_is_concerned {
Subroutine arch_is_concerned: called CC=10 SCAR=23.1
Pod undocumented
315 41430 my ($self, $arch) = @_;
316 41430 my $arches = $self->{tags}{arch};
317  
318 41430 ▶ return 0 if defined $arch && defined $arches &&
Branch: 1 branch
BranchTrueFalseTotal
if defined $arch and defined $arches and not debarch_is_concerned($arch, split(/[\s,]+/u, $arches, 0)) 102 41328 41430
Condition83%5/6
defined $arch and defined $arches and not debarch_is_concerned($arch, split(/[\s,]+/u, $arches, 0))
!ll&&!rl&&r
4126464102
defined $arch and defined $arches
!ll&&!rl&&r
041264166
MC/DC66%2/3
defined $arch and defined $arches and not debarch_is_concerned($arch, split(/[\s,]+/u, $arches, 0))
defined $arch defined $arches not debarch_is_concerned($arch, split(/[\s,]+/u, $arches, 0))
Truth table75%3/4
A and B and not(C)
A= defined $archB= defined $archesC= not debarch_is_concerned($arch, split(/[\s,]+/u, $arches, 0))
ABCresult
0XX0
10X0
1100
1111
319 ! debarch_is_concerned($arch, split /[\s,]+/, $arches);
320  
321 41328 my ($bits, $endian) = debarch_to_abiattrs($arch);
322 return 0 if defined $bits && defined $self->{tags}{'arch-bits'} &&
323 41328 ▶ $bits ne $self->{tags}{'arch-bits'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $bits and defined $self->{"tags"}{"arch-bits"} and $bits ne $self->{"tags"}{"arch-bits"} 42 41286 41328
Condition83%5/6
defined $bits and defined $self->{"tags"}{"arch-bits"} and $bits ne $self->{"tags"}{"arch-bits"}
!ll&&!rl&&r
412048242
defined $bits and defined $self->{"tags"}{"arch-bits"}
!ll&&!rl&&r
041204124
MC/DC66%2/3
defined $bits and defined $self->{"tags"}{"arch-bits"} and $bits ne $self->{"tags"}{"arch-bits"}
defined $bits defined $self->{"tags"}{"arch-bits"} $bits ne $self->{"tags"}{"arch-bits"}
Truth table75%3/4
A and B and C
A= defined $bitsB= defined $self->{"tags"}{"arch-bits"}C= $bits ne $self->{"tags"}{"arch-bits"}
ABCresult
0XX0
10X0
1100
1111
324 return 0 if defined $endian && defined $self->{tags}{'arch-endian'} &&
325 41286 ▶ $endian ne $self->{tags}{'arch-endian'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $endian and defined $self->{"tags"}{"arch-endian"} and $endian ne $self->{"tags"}{"arch-endian"} 38 41248 41286
Condition83%5/6
defined $endian and defined $self->{"tags"}{"arch-endian"} and $endian ne $self->{"tags"}{"arch-endian"}
!ll&&!rl&&r
411688038
defined $endian and defined $self->{"tags"}{"arch-endian"}
!ll&&!rl&&r
041168118
MC/DC66%2/3
defined $endian and defined $self->{"tags"}{"arch-endian"} and $endian ne $self->{"tags"}{"arch-endian"}
defined $endian defined $self->{"tags"}{"arch-endian"} $endian ne $self->{"tags"}{"arch-endian"}
Truth table75%3/4
A and B and C
A= defined $endianB= defined $self->{"tags"}{"arch-endian"}C= $endian ne $self->{"tags"}{"arch-endian"}
ABCresult
0XX0
10X0
1100
1111
326  
327 41248 return 1;
328 }
329  
330 # Get reference to the pattern the symbol matches (if any).
331 626 ▶sub get_pattern {
Subroutine get_pattern: called CC=1 SCAR=0.0
Pod undocumented
332 626 my $self = shift;
333  
334 626 return $self->{matching_pattern};
335 }
336  
337 ## Pattern subroutines.
338 #
339 # Note: The subroutines below require (or initialize) $self to be a pattern.
340  
341 # Initializes this symbol as a pattern of the specified type.
342 86 ▶sub init_pattern {
Subroutine init_pattern: called CC=1 SCAR=0.0
Pod undocumented
343 86 my ($self, $type) = @_;
344  
345 86 $self->{pattern}{type} = $type;
346 # To be filled with references to symbols matching this pattern.
347 86 $self->{pattern}{matches} = [];
348 }
349  
350 # Is this symbol a pattern or not?
351 24015 ▶sub is_pattern {
Subroutine is_pattern: called CC=1 SCAR=0.0
Pod undocumented
352 24015 my $self = shift;
353  
354 24015 return exists $self->{pattern};
355 }
356  
357 # Get pattern type if this symbol is a pattern.
358 760 ▶sub get_pattern_type {
Subroutine get_pattern_type: called CC=2 SCAR=7.2
Pod undocumented
359 760 my $self = shift;
360  
361 760 ▶ return $self->{pattern}{type} // '';
Condition50%1/2
$self->{"pattern"}{"type"} // ""
l!l
7600
MC/DC0%0/1
$self->{"pattern"}{"type"} // ""
$self->{"pattern"}{"type"}
Truth table50%1/2
A
A= $self->{"pattern"}{"type"}
Aresult
11
00
362 }
363  
364 # Get (sub)type of the alias pattern. Returns empty string if current
365 # pattern is not alias.
366 713 ▶sub get_alias_type {
Subroutine get_alias_type: called CC=3 SCAR=11.1
Pod undocumented
367 713 my $self = shift;
368  
369 713 ▶ return ($self->get_pattern_type() =~ /^alias-(.+)/ && $1) || '';
Condition80%4/5
$self->get_pattern_type =~ /^alias-(.+)/u && $1 || ''
l!l
63380
$self->get_pattern_type =~ /^alias-(.+)/u and $1
!ll&&!rl&&r
800633
MC/DC50%1/2
$self->get_pattern_type =~ /^alias-(.+)/u && $1 || ''
$self->get_pattern_type =~ /^alias-(.+)/u $1
Truth table66%2/3
A and B
A= $self->get_pattern_type =~ /^alias-(.+)/uB= $1
ABresult
111
0X0
100
370 }
371  
372 # Get a list of symbols matching this pattern if this symbol is a pattern.
373 53 ▶sub get_pattern_matches {
Subroutine get_pattern_matches: called CC=1 SCAR=0.0
Pod undocumented
374 53 my $self = shift;
375  
376 53 return @{$self->{pattern}{matches}};
377 }
378  
379 # Create a new symbol based on the pattern (i.e. $self) and add it to the
380 # pattern matches list.
381 195 ▶sub create_pattern_match {
Subroutine create_pattern_match: called CC=2 SCAR=6.9
Pod undocumented
382 195 my $self = shift;
383 195 ▶ return unless $self->is_pattern();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_pattern 0 195 195
384  
385 # Leave out 'pattern' subfield while deep-cloning.
386 195 my $pattern_stuff = $self->{pattern};
387 195 delete $self->{pattern};
388 195 my $newsym = $self->clone(@_);
389 195 $self->{pattern} = $pattern_stuff;
390  
391 # Clean up symbol name related internal fields.
392 195 $newsym->set_symbolname();
393  
394 # Set newsym pattern reference, add to pattern matches list.
395 195 $newsym->{matching_pattern} = $self;
396 195 push @{$self->{pattern}{matches}}, $newsym;
397 195 return $newsym;
398 }
399  
400 ## End of pattern subroutines.
401  
402 # Given a raw symbol name the call returns its alias according to the rules of
403 # the current pattern ($self). Returns undef if the supplied raw name is not
404 # transformable to alias.
405 896 ▶sub convert_to_alias {
Subroutine convert_to_alias: called CC=7 SCAR=21.2
Pod undocumented
406 896 my ($self, $rawname, $type) = @_;
407 896 ▶ $type = $self->get_alias_type() unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 545 351 896
408  
409 896 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 896 0 896
410 896 ▶ if ($type eq 'symver') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'symver') { } 445 451 896
elsif ($rawname =~ /^_Z/u and $type eq 'c++') { } 451 0 451
411 # In case of symver, alias is symbol version. Extract it from the
412 # rawname.
413 445 ▶ return "$1" if ($rawname =~ /\@([^@]+)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $rawname =~ /\@([^\@]+)$/u 445 0 445
414 ▶ } elsif ($rawname =~ /^_Z/ && $type eq 'c++') {
Condition33%1/3
$rawname =~ /^_Z/u and $type eq "c++"
!ll&&!rl&&r
00451
MC/DC0%0/2
$rawname =~ /^_Z/u and $type eq "c++"
$rawname =~ /^_Z/u $type eq "c++"
Truth table33%1/3
A and B
A= $rawname =~ /^_Z/uB= $type eq "c++"
ABresult
0X0
100
111
415 451 return cppfilt_demangle_cpp($rawname);
416 }
417 }
418 0 return;
419 }
420  
421 40 ▶sub get_tagspec {
Subroutine get_tagspec: called CC=4 SCAR=14.0
Pod undocumented
422 40 my $self = shift;
423 40 ▶ if ($self->has_tags()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_tags) 40 0 40
424 40 my @tags;
425 40 for my $tagname (@{$self->{tagorder}}) {
426 56 my $tagval = $self->{tags}{$tagname};
427 56 ▶ if (defined $tagval) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tagval) { } 28 28 56
428 28 push @tags, $tagname . '=' . $tagval;
429 } else {
430 28 push @tags, $tagname;
431 }
432 }
433 40 return '(' . join('|', @tags) . ')';
434 }
435 0 return '';
436 }
437  
438 13906 ▶sub get_symbolspec {
Subroutine get_symbolspec: called CC=6 SCAR=17.9
Pod undocumented
439 13906 my $self = shift;
440 13906 my $template_mode = shift;
441 13906 my $spec = '';
442 13906 ▶ $spec .= "#MISSING: $self->{deprecated}#" if $self->{deprecated};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"deprecated"} 132 13774 13906
443 13906 $spec .= ' ';
444 13906 ▶ if ($template_mode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($template_mode) { } 122 13784 13906
445 122 ▶ if ($self->has_tags()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_tags) { } 40 82 122
446 $spec .= sprintf('%s%3$s%s%3$s', $self->get_tagspec(),
447 40 ▶ $self->get_symboltempl(), $self->{symbol_quoted} // '');
Condition100%2/2
$self->{"symbol_quoted"} // ""
l!l
1228
MC/DC100%1/1
$self->{"symbol_quoted"} // ""
$self->{"symbol_quoted"}
Truth table100%2/2
A
A= $self->{"symbol_quoted"}
Aresult
11
00
448 } else {
449 82 $spec .= $self->get_symboltempl();
450 }
451 } else {
452 13784 $spec .= $self->get_symbolname();
453 }
454 13906 $spec .= " $self->{minver}";
455 13906 ▶ $spec .= " $self->{dep_id}" if $self->{dep_id};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dep_id"} 20 13886 13906
456 13906 return $spec;
457 }
458  
459 # Sanitize the symbol when it is confirmed to be found in the
460 # respective library.
461 9026 ▶sub mark_found_in_library {
Subroutine mark_found_in_library: called CC=6 SCAR=18.0
Pod undocumented
462 9026 my ($self, $minver, $arch) = @_;
463  
464 9026 ▶ if ($self->{deprecated}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'deprecated'}) { } 3 9023 9026
elsif (&version_compare($minver, $self->{'minver'}) < 0) { } 0 9023 9023
465 # Symbol reappeared somehow.
466 3 $self->{deprecated} = 0;
467 3 ▶ $self->{minver} = $minver if (not $self->is_optional());
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_optional 1 2 3
468 } elsif (version_compare($minver, $self->{minver}) < 0) {
469 # We assume that the right dependency information is already there.
470 0 $self->{minver} = $minver;
471 }
472 # Never remove arch tags from patterns.
473 9026 ▶ if (not $self->is_pattern()) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->is_pattern) 8831 195 9026
474 8831 ▶ if (not $self->arch_is_concerned($arch)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->arch_is_concerned($arch)) 2 8829 8831
475 # Remove arch tags because they are incorrect.
476 2 $self->delete_tag('arch');
477 2 $self->delete_tag('arch-bits');
478 2 $self->delete_tag('arch-endian');
479 }
480 }
481 }
482  
483 # Sanitize the symbol when it is confirmed NOT to be found in the
484 # respective library.
485 # Mark as deprecated those that are no longer provided (only if the
486 # minver is later than the version where the symbol was introduced).
487 170 ▶sub mark_not_found_in_library {
Subroutine mark_not_found_in_library: called CC=5 SCAR=16.3
Pod undocumented
488 170 my ($self, $minver, $arch) = @_;
489  
490 # Ignore symbols from a foreign arch.
491 170 ▶ return if not $self->arch_is_concerned($arch);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->arch_is_concerned($arch) 56 114 170
492  
493 114 ▶ if ($self->{deprecated}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'deprecated'}) { } 2 112 114
elsif (&version_compare($minver, $self->{'minver'}) > 0) { } 112 0 112
494 # Bump deprecated if the symbol is optional so that it keeps
495 # reappearing in the diff while it is missing.
496 2 ▶ $self->{deprecated} = $minver if $self->is_optional();
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_optional 2 0 2
497 } elsif (version_compare($minver, $self->{minver}) > 0) {
498 112 $self->{deprecated} = $minver;
499 }
500 }
501  
502 # Checks if the symbol (or pattern) is legitimate as a real symbol for the
503 # specified architecture.
504 18318 ▶sub is_legitimate {
Subroutine is_legitimate: called CC=2 SCAR=6.9
Pod undocumented
505 18318 my ($self, $arch) = @_;
506 return ! $self->{deprecated} &&
507 18318 ▶ $self->arch_is_concerned($arch);
Condition100%3/3
!$self->{'deprecated'} && $self->arch_is_concerned($arch)
!ll&&!rl&&r
964018182
MC/DC100%2/2
!$self->{'deprecated'} && $self->arch_is_concerned($arch)
!$self->{'deprecated'} $self->arch_is_concerned($arch)
Truth table100%3/3
not(A) && B
A= !$self->{'deprecated'}B= $self->arch_is_concerned($arch)
ABresult
0X0
100
111
508 }
509  
510 # Determine whether a supplied raw symbol name matches against current ($self)
511 # symbol or pattern.
512 267 ▶sub matches_rawname {
Subroutine matches_rawname: called CC=8 SCAR=20.8
Pod undocumented
513 267 my ($self, $rawname) = @_;
514 267 my $target = $rawname;
515 267 my $ok = 1;
516 267 my $do_eq_match = 1;
517  
518 267 ▶ if ($self->is_pattern()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_pattern) 267 0 267
519 # Process pattern tags in the order they were specified.
520 267 for my $tag (@{$self->{tagorder}}) {
521 573 ▶ if (any { $tag eq $_ } ALIAS_TYPES) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
BranchTrueFalseTotal
if (&any(sub { $tag eq $_; } , ('c++', 'symver'))) { } 351 222 573
elsif ($tag eq 'regex') { } 183 39 222
522 351 $ok = not not ($target = $self->convert_to_alias($target, $tag));
523 } elsif ($tag eq 'regex') {
524 # Symbol name is a regex. Match it against the target.
525 183 $do_eq_match = 0;
526 183 $ok = ($target =~ $self->{pattern}{regex});
527 }
528 573 ▶ last if not $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 84 489 573
529 }
530 }
531  
532 # Equality match by default.
533 267 ▶ if ($ok && $do_eq_match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and $do_eq_match) 84 183 267
Condition100%3/3
$ok and $do_eq_match
!ll&&!rl&&r
849984
MC/DC100%2/2
$ok and $do_eq_match
$ok $do_eq_match
Truth table100%3/3
A and B
A= $okB= $do_eq_match
ABresult
0X0
100
111
534 84 $ok = $target eq $self->get_symbolname();
535 }
536 267 return $ok;
537 }
538  
539 =head1 CHANGES
540  
541 =head2 Version 0.xx
542  
543 This is a private module.
544  
545 =cut
546  
547 2 1;
« Dpkg/Path.pm ↑ Summary Dpkg/Color.pm »