Exemplo n.º 1
0
    def parse_object(filename):
        """
      Simple NM parsing of an object file
      Given an object file, we call nm -aS file

      Next, we parse stdout and match symbol lines corresponding to types
      from nm_option_desc_map.

      Data are aggregated into a dict using the keys from nm_option_desc_map

      The keys are obtained from nm_option_desc_map and enforced inside the regex used
      See nm_re_type_expr, nm_re_str, and nm_re in the static fields of this class
    """
        p = subprocess.Popen(['nm', '-aS', filename], stdout=subprocess.PIPE)
        output = p.communicate()[0]

        nm_counts = dict()

        for line in output.split(b(os.linesep)):
            m = NMParser.nm_re.match(s(line))
            if m:
                nm_counts[m.group('type')] = nm_counts.get(m.group('type'),
                                                           0) + 1
        # return what we found
        return nm_counts
Exemplo n.º 2
0
def extractLinesMatchingSubstr(string_in, substr_in):
    #print("substr_in = '" + substr_in + "'")
    string_in = s(string_in)
    linesExtracted = ""
    for line in string_in.strip().splitlines():
        #print("line = '" + line + "'")
        if substr_in in line:
            #print("matched '" + substr_in + "'")
            linesExtracted += line + "\n"
    return linesExtracted
Exemplo n.º 3
0
def extractLinesMatchingRegex(string_in, regex_in):
    #print("regex_in = " + regex_in)
    string_in = s(string_in)
    reMatch = re.compile(regex_in)
    linesExtracted = ""
    for line in string_in.strip().splitlines():
        #print("line = '" + line + "'")
        matchObj = reMatch.match(line)
        #print("matchObj = " + matchObj)
        if matchObj:
            linesExtracted += line + "\n"
    return linesExtracted