11def ParseNm(nm_lines):
12 """Parse nm output, returning data for all relevant (to binary size)
13 symbols and ignoring the rest.
14
15 Args:
16 nm_lines: an iterable over lines of nm output.
17
18 Yields:
19 (symbol name, symbol type, symbol size, source file path).
20
21 Path may be None if nm couldn't figure out the source file.
22 """
23
24
25 sym_re = re.compile(r'^([0-9a-f]{8,}) '
26 '([0-9a-f]{8,}) '
27 '(.) '
28 '([^\t]+)'
29 '(?:\t(.*):[\d\?]+)?.*$')
30
31 addr_re = re.compile(r'^[0-9a-f]{8,} (.) ([^\t]+)(?:\t.*)?$')
32
33 noaddr_re = re.compile(r'^ {8,} (.) (.*)$')
34
35 addr_only_re = re.compile(r'^[0-9a-f]{8,} (.)$')
36
37 seen_lines = set()
38 for line in nm_lines:
39 line = line.rstrip()
40 if line in seen_lines:
41
42
43 continue
44 seen_lines.add(line)
45 match = sym_re.match(line)
46 if match:
47 address, size, sym_type, sym = match.groups()[0:4]
49 if sym_type in ('B', 'b'):
50 continue
51 path = match.group(5)
52 yield sym, sym_type, size, path, address
53 continue
54 match = addr_re.match(line)
55 if match:
56
57 continue
58 match = noaddr_re.match(line)
59 if match:
60 sym_type, sym = match.groups()
61 if sym_type in ('U', 'w'):
62 continue
63 match = addr_only_re.match(line)
64 if match:
65 continue
66
67
68
69 logging.warning('nm output parser failed to parse: %s', repr(line))
Type::kYUV Type::kRGBA() int(0.7 *637)