File: llvm-objdump-filter.py

package info (click to toggle)
mame 0.286%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 930,472 kB
  • sloc: cpp: 5,499,413; xml: 2,250,892; ansic: 752,116; sh: 34,431; lisp: 19,643; python: 17,598; makefile: 13,246; java: 8,492; yacc: 8,152; javascript: 7,147; cs: 6,013; asm: 4,786; ada: 1,681; pascal: 1,191; lex: 1,174; perl: 585; ruby: 373
file content (44 lines) | stat: -rwxr-xr-x 1,447 bytes parent folder | download
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
#!/usr/bin/python3
##
## license:BSD-3-Clause
## copyright-holders:Vas Crabb

import re
import subprocess
import sys


# identify .text section
sec_pattern = re.compile(' *(0|[1-9][0-9]*) +\\.text +[0-9a-f]+ +[0-9a-f]+ +[^ ].+')
sections = []
with subprocess.Popen(('objdump', '--section-headers', sys.argv[1]), stdout=subprocess.PIPE) as proc:
    for line in proc.stdout:
        text = line.decode('utf-8')
        match = sec_pattern.match(text)
        if match:
            sections.append(int(match.group(1)) + 1)
    proc.wait()
    if proc.returncode != 0:
        sys.exit(proc.returncode)
    sections = frozenset(sections)

# filter symbols from other sections
sym_pattern = re.compile('^\\[ *(0|[1-9][0-9]*)\\]\\(sec +(-?[1-9][0-9]*)\\).+')
aux_pattern = re.compile('^[A-Z]+ +.+')
with subprocess.Popen(('objdump', '--syms', '--demangle', sys.argv[1]), stdout=subprocess.PIPE) as proc:
    ignored_section = False
    for line in proc.stdout:
        text = line.decode('utf-8')
        match = sym_pattern.match(text)
        if match:
            if int(match.group(2)) in sections:
                ignored_section = False
                sys.stdout.write(text)
            else:
                ignored_section = True
        else:
            match = aux_pattern.match(text)
            if (not match) or (not ignored_section):
                sys.stdout.write(text)
    if proc.returncode != 0:
        sys.exit(proc.returncode)