win32kprof: Consider the section alignment when estimating the image base.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Sun, 20 Jul 2008 14:32:00 +0000 (23:32 +0900)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Tue, 22 Jul 2008 00:45:32 +0000 (09:45 +0900)
bin/win32kprof.py

index b4f9ce95dcab627a6d7cc900e5a10a7d60803545..1876fbc0670c474a18b9804c559cbe061431dc3d 100755 (executable)
@@ -35,8 +35,6 @@ import struct
 
 __version__ = '0.1'
 
-verbose = False
-
 
 class ParseError(Exception):
        pass
@@ -211,7 +209,7 @@ class Profile:
                        if self.base_addr is None:
                                ref_addr = self.lookup_symbol('__debug_profile_reference2')
                                if ref_addr:
-                                       self.base_addr = addr - ref_addr
+                                       self.base_addr = (addr - ref_addr) & ~(options.align - 1)
                                else:
                                        self.base_addr = 0
                                #print hex(self.base_addr)
@@ -224,27 +222,27 @@ class Profile:
                        delta += stamp - last_stamp
 
                        if not exit:
-                               if verbose >= 2:
+                               if options.verbose >= 2:
                                        print "%10u >> 0x%08x" % (stamp, addr)
-                               if verbose:
+                               if options.verbose:
                                        print "%10u >> %s" % (stamp, name)
                                delta -= caller_overhead
                                stack.append((name, stamp, delta))
                                delta = 0
                        else:
-                               if verbose >= 2:
+                               if options.verbose >= 2:
                                        print "%10u << 0x%08x" % (stamp, addr)
                                if len(stack):
                                        self_time = delta - callee_overhead
                                        entry_name, entry_stamp, delta = stack.pop()
                                        if entry_name != name:
-                                               if verbose:
+                                               if options.verbose:
                                                        print "%10u << %s" % (stamp, name)
                                                #assert entry_name == name
                                                break
                                        total_time = stamp - entry_stamp
                                        self.functions[entry_name] = self.functions.get(entry_name, 0) + self_time
-                                       if verbose:
+                                       if options.verbose:
                                                print "%10u << %s %+u" % (stamp, name, self_time)
                                else:
                                        delta = 0
@@ -264,6 +262,10 @@ def main():
                parser = optparse.OptionParser(
                        usage="\n\t%prog [options] [file] ...",
                        version="%%prog %s" % __version__)
+               parser.add_option(
+                       '-a', '--align', metavar='NUMBER',
+                       type="int", dest="align", default=16,
+                       help="section alignment")
                parser.add_option(
                        '-m', '--map', metavar='FILE',
                        type="string", dest="map",
@@ -277,10 +279,9 @@ def main():
                        action="count",
                        dest="verbose", default=0,
                        help="verbose output")
-               (options, args) = parser.parse_args(sys.argv[1:])
 
-               global verbose
-               verbose = options.verbose
+               global options
+               (options, args) = parser.parse_args(sys.argv[1:])
 
                profile = Profile()
                if options.base is not None: