summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2008-09-11 22:35:15 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2008-09-11 22:35:15 -0400
commit50bc37446af59db2a4238551c3fa34fe4f0012a7 (patch)
tree7c0cdab740139b4dfe0b04dabf025fb0533db7fc
parent85696715849de7ab98e669664251e7f22cf7983f (diff)
show_asm: add doc & license
-rwxr-xr-xshow_asm60
1 files changed, 54 insertions, 6 deletions
diff --git a/show_asm b/show_asm
index 1ddbab4..5b108cf 100755
--- a/show_asm
+++ b/show_asm
@@ -1,8 +1,53 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2#
3# Copyright (c) 2008, Bjoern B. Brandenburg <bbb [at] cs.unc.edu>
4#
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are met:
9# * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# * Neither the name of the copyright holder nor the
15# names of its contributors may be used to endorse or promote products
16# derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29#
30
31"""
32Purpose: This tool displays the assembly code of all symbols matching a given
33 pattern in a given set of files. It is a quick&dirty wrapper around
34 the nm(1) and objdump(1) tools. Its main advantage is that it does not
35 require you to find out the addresses of a given set of symbols
36 manually. Also, it's considerably faster than just disassembling the
37 whole Linux kernel on slow systems.
38
39Example: show_asm printk vmlinux
40 Disassemble printk-related functions in the Linux kernel.
41
42 show_asm 'main|foo|bar' *.o
43 Disassemble all main, foo, and bar
44 functions in all object files in the current directory.
45"""
2 46
3from subprocess import Popen, PIPE, call 47from subprocess import Popen, PIPE, call
4import re 48import re
5import sys 49import sys
50import os
6 51
7NM_FORMAT = "([0-9a-f]+) *([0-9a-f]*) *([AaBbCcDdGgIiNnRrSsTtUuVvWw])" + \ 52NM_FORMAT = "([0-9a-f]+) *([0-9a-f]*) *([AaBbCcDdGgIiNnRrSsTtUuVvWw])" + \
8 " ([_a-zA-Z.0-9]+)" 53 " ([_a-zA-Z.0-9]+)"
@@ -31,7 +76,7 @@ def nm(file):
31 return p.stdout 76 return p.stdout
32 77
33def nm_filtered(file, symbol): 78def nm_filtered(file, symbol):
34 cmd = "nm -S %s | egrep %s " % (file, symbol) 79 cmd = "nm -S %s | egrep '%s' " % (file, symbol)
35 p = Popen(cmd, shell=True, stdout=PIPE) 80 p = Popen(cmd, shell=True, stdout=PIPE)
36 return p.stdout 81 return p.stdout
37 82
@@ -40,8 +85,8 @@ def objdump_symbol(file, addr):
40 % (addr[0], addr[0] + addr[1], file) 85 % (addr[0], addr[0] + addr[1], file)
41 filter_cmd = "egrep -v 'Disassembly of|file format|^$'" 86 filter_cmd = "egrep -v 'Disassembly of|file format|^$'"
42 pipe_cmd = "%s | %s" % (objdump_cmd, filter_cmd) 87 pipe_cmd = "%s | %s" % (objdump_cmd, filter_cmd)
43 print "=====[ %s (0x%x - 0x%x, type: %s) ]=====" % \ 88 print "=====[ %s:%s (0x%x - 0x%x, type: %s) ]=====" % \
44 (addr[3], addr[0], addr[0] + addr[1], addr[2]) 89 (file, addr[3], addr[0], addr[0] + addr[1], addr[2])
45 sys.stdout.flush() 90 sys.stdout.flush()
46 call(pipe_cmd, shell=True) 91 call(pipe_cmd, shell=True)
47 92
@@ -53,7 +98,10 @@ def get_address_ranges(file, symbol):
53 objdump_symbol(file, addr) 98 objdump_symbol(file, addr)
54 99
55if __name__ == "__main__": 100if __name__ == "__main__":
56 if len(sys.argv) != 2: 101 if len(sys.argv) < 3:
57 print "Usage: %s <symbol pattern>" % sys.argv[0] 102 name = os.path.basename(sys.argv[0])
103 print "Usage..: %s <symbol pattern> <object file>+" % name
104 print __doc__
58 else: 105 else:
59 get_address_ranges("vmlinux", sys.argv[1]) 106 for file in sys.argv[2:]:
107 get_address_ranges(file, sys.argv[1])