~ubuntu-branches/ubuntu/quantal/lightning-extension/quantal-security

« back to all changes in this revision

Viewing changes to mozilla/build/autoconf/check_debug_ranges.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-05-21 16:09:39 UTC
  • mfrom: (1.3.1) (25.1.1 precise-security)
  • Revision ID: package-import@ubuntu.com-20120521160939-0702473a46xfq3tl
Tags: 1.5~b2+build1-0ubuntu1
New upstream release from the beta channel (CALENDAR_1_5b2_BUILD1)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ***** BEGIN LICENSE BLOCK *****
 
2
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
3
#
 
4
# The contents of this file are subject to the Mozilla Public License Version
 
5
# 1.1 (the "License"); you may not use this file except in compliance with
 
6
# the License. You may obtain a copy of the License at
 
7
# http://www.mozilla.org/MPL/
 
8
#
 
9
# Software distributed under the License is distributed on an "AS IS" basis,
 
10
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
11
# for the specific language governing rights and limitations under the
 
12
# License.
 
13
#
 
14
# The Original Code is mozilla.org
 
15
#
 
16
# The Initial Developer of the Original Code is
 
17
# the Mozilla Foundation
 
18
# Portions created by the Initial Developer are Copyright (C) 2011
 
19
# the Initial Developer. All Rights Reserved.
 
20
#
 
21
# Contributor(s):
 
22
# Mike Hommey <mh@glandium.org>
 
23
#
 
24
# Alternatively, the contents of this file may be used under the terms of
 
25
# either the GNU General Public License Version 2 or later (the "GPL"), or
 
26
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
27
# in which case the provisions of the GPL or the LGPL are applicable instead
 
28
# of those above. If you wish to allow use of your version of this file only
 
29
# under the terms of either the GPL or the LGPL, and not to allow others to
 
30
# use your version of this file under the terms of the MPL, indicate your
 
31
# decision by deleting the provisions above and replace them with the notice
 
32
# and other provisions required by the GPL or the LGPL. If you do not delete
 
33
# the provisions above, a recipient may use your version of this file under
 
34
# the terms of any one of the MPL, the GPL or the LGPL.
 
35
#
 
36
# ***** END LICENSE BLOCK *****
 
37
 
 
38
# This script returns the number of items for the DW_AT_ranges corresponding
 
39
# to a given compilation unit. This is used as a helper to find a bug in some
 
40
# versions of GNU ld.
 
41
 
 
42
import subprocess
 
43
import sys
 
44
import re
 
45
 
 
46
def get_range_for(compilation_unit, debug_info):
 
47
    '''Returns the range offset for a given compilation unit
 
48
       in a given debug_info.'''
 
49
    name = ranges = ''
 
50
    search_cu = False
 
51
    for nfo in debug_info.splitlines():
 
52
        if 'DW_TAG_compile_unit' in nfo:
 
53
            search_cu = True
 
54
        elif 'DW_TAG_' in nfo or not nfo.strip():
 
55
            if name == compilation_unit:
 
56
                return int(ranges, 16)
 
57
            name = ranges = ''
 
58
            search_cu = False
 
59
        if search_cu:
 
60
            if 'DW_AT_name' in nfo:
 
61
                name = nfo.rsplit(None, 1)[1]
 
62
            elif 'DW_AT_ranges' in nfo:
 
63
                ranges = nfo.rsplit(None, 1)[1]
 
64
    return None
 
65
 
 
66
def get_range_length(range, debug_ranges):
 
67
    '''Returns the number of items in the range starting at the
 
68
       given offset.'''
 
69
    length = 0
 
70
    for line in debug_ranges.splitlines():
 
71
        m = re.match('\s*([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)', line)
 
72
        if m and int(m.group(1), 16) == range:
 
73
            length += 1
 
74
    return length
 
75
 
 
76
def main(bin, compilation_unit):
 
77
    p = subprocess.Popen(['objdump', '-W', bin], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
 
78
    (out, err) = p.communicate()
 
79
    sections = re.split('\n(Contents of the|The section) ', out)
 
80
    debug_info = [s for s in sections if s.startswith('.debug_info')]
 
81
    debug_ranges = [s for s in sections if s.startswith('.debug_ranges')]
 
82
    if not debug_ranges or not debug_info:
 
83
        return 0
 
84
 
 
85
    range = get_range_for(compilation_unit, debug_info[0])
 
86
    if range is not None:
 
87
        return get_range_length(range, debug_ranges[0])
 
88
 
 
89
    return -1
 
90
 
 
91
 
 
92
if __name__ == '__main__':
 
93
    print main(*sys.argv[1:])