| 1 |
#!/usr/bin/python |
| 2 |
|
| 3 |
# Copyright (C) 2008 Red Hat Inc. |
| 4 |
# |
| 5 |
# This file is part of systemtap, and is free software. You can |
| 6 |
# redistribute it and/or modify it under the terms of the GNU General |
| 7 |
# Public License (GPL); either version 2, or (at your option) any |
| 8 |
# later version. |
| 9 |
|
| 10 |
import re |
| 11 |
import sys |
| 12 |
import os |
| 13 |
#import pickle |
| 14 |
import subprocess |
| 15 |
from config_opts import config_opts |
| 16 |
|
| 17 |
# Read the output of eu-readelf on vmlinux |
| 18 |
(sysname, nodename, release, version, machine) = os.uname() |
| 19 |
cmd = "eu-readelf --symbols /usr/lib/debug/lib/modules/%s/vmlinux" % release |
| 20 |
print "Running", cmd |
| 21 |
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) |
| 22 |
lines = p.stdout.readlines() |
| 23 |
p.wait() |
| 24 |
if p.returncode != 0: |
| 25 |
print >>sys.stderr, "Error: eu-readelf failed." |
| 26 |
sys.exit(p.returncode) |
| 27 |
|
| 28 |
# Parse the output |
| 29 |
kprobes_text_start = 0 |
| 30 |
kprobes_text_end = 0 |
| 31 |
syms = dict() |
| 32 |
func_re = re.compile("^\s*\d+:\s+([0-9a-f]+)\s+\d+\s+FUNC\s+\S+\s+\S+\s+\d+\s+(\S+)$") |
| 33 |
notype_re = re.compile("^\s*\d+:\s+([0-9a-f]+)\s+\d+\s+NOTYPE\s+\S+\s+\S+\s+\d+\s+(\S+)$") |
| 34 |
for line in lines: |
| 35 |
match = notype_re.match(line) |
| 36 |
if match: |
| 37 |
addr = match.group(1) |
| 38 |
name = match.group(2) |
| 39 |
if name == "__kprobes_text_start": |
| 40 |
kprobes_text_start = long(addr, 16) |
| 41 |
elif name == "__kprobes_text_end": |
| 42 |
kprobes_text_end = long(addr, 16) |
| 43 |
continue |
| 44 |
|
| 45 |
match = func_re.match(line) |
| 46 |
if match: |
| 47 |
addr = match.group(1) |
| 48 |
name = match.group(2) |
| 49 |
syms[name] = long(addr, 16) |
| 50 |
|
| 51 |
# Now we've parsed everything. Now we need to go back and remove all |
| 52 |
# symbols between '__kprobes_text_start' and '__kprobes_text_end', |
| 53 |
# since they are already protected from kprobes. We couldn't do this |
| 54 |
# in the loop above, since we might encounter symbols that need to be |
| 55 |
# removed before we found the start/end of the kprobes section. |
| 56 |
if kprobes_text_start == 0 or kprobes_text_end == 0: |
| 57 |
print "Error - didn't find kprobes_test_start(%d) or kprobes_text_end(%d)" \ |
| 58 |
% (kprobes_text_start, kprobes_text_end) |
| 59 |
sys.exit(1) |
| 60 |
|
| 61 |
for name in syms.keys(): |
| 62 |
if syms[name] >= kprobes_text_start and syms[name] < kprobes_text_end: |
| 63 |
print "deleting", name |
| 64 |
del syms[name] |
| 65 |
|
| 66 |
## Save data |
| 67 |
#f = open('%s.syms' % (release), 'w') |
| 68 |
#p = pickle.Pickler(f) |
| 69 |
#p.dump(syms) |
| 70 |
#f.close() |
| 71 |
|
| 72 |
# Write the data out in text format |
| 73 |
f = open(config_opts['probes_all'], 'w') |
| 74 |
for name in syms.keys(): |
| 75 |
print >>f, name |
| 76 |
f.close() |