tools/cygprofile/symbol_extractor.py
def _FromObjdumpLine(line):
  """Create a SymbolInfo by parsing a properly formatted objdump output line.

  Args:
    line: line from objdump

  Returns:
    An instance of SymbolInfo if the line represents a symbol, None otherwise.
  """
  m = _OBJDUMP_LINE_RE.match(line)
  if not m:
    return None

  # A symbol can be (g)lobal, (l)ocal, or neither (a space). Per objdump's
  # manpage, "A symbol can be neither local or global for a variety of reasons".
  assert m.group('assert_scope') in set(['g', 'l', ' ']), line
  assert m.group('assert_weak_or_strong') in set(['w', ' ']), line
  assert m.group('assert_tab') == '\t', line
  assert m.group('assert_4spaces') == ' ' * 4, line
  name = m.group('name')
  offset = int(m.group('offset'), 16)

  # Output the label that contains the earliest offset. It is needed later for
  # translating offsets from the profile dumps.
  if name == START_OF_TEXT_SYMBOL:
    return SymbolInfo(name=name, offset=offset, section='.text', size=0)

  # Check symbol type for validity and ignore some types.
  # From objdump manual page: The symbol is the name of a function (F) or a file
  # (f) or an object (O) or just a normal symbol (a space). The 'normal' symbols
  # seens so far has been function-local labels.
  symbol_type = m.group('symbol_type')
  if symbol_type == ' ':
    # Ignore local goto labels. Unfortunately, v8 builtins (like 'Builtins_.*')
    # are indistinguishable from labels of size 0 other than by name.
    return None
  # Guard against file symbols, since they are normally not seen in the
  # binaries we parse.
  assert symbol_type != 'f', line

  # Extract the size from the ELF field. This value sometimes does not reflect
  # the real size of the function. One reason for that is the '.size' directive
  # in the assembler. As a result, a few functions in .S files have the size 0.
  # They are not instrumented (yet), but maintaining their order in the
  # orderfile may be important in some cases.
  size = int(m.group('size'), 16)

  # Forbid ARM mapping symbols and other unexpected symbol names, but allow $
  # characters in a non-initial position, which can appear as a component of a
  # mangled name, e.g. Clang can mangle a lambda function to:
  # 02cd61e0 l     F .text  000000c0 _ZZL11get_globalsvENK3$_1clEv
  # The equivalent objdump line from GCC is:
  # 0325c58c l     F .text  000000d0 _ZZL11get_globalsvENKUlvE_clEv
  #
  # Also disallow .internal and .protected symbols (as well as other flags),
  # those have not appeared in the binaries we parse. Rejecting these extra
  # prefixes is done by disallowing spaces in symbol names.
  assert re.match('^[a-zA-Z0-9_.][a-zA-Z0-9_.$]*$', name), name

  return SymbolInfo(name=name, offset=offset, section=m.group('section'),
                    size=size)
Create a SymbolInfo by parsing a properly formatted objdump output line.

  Args:
    line: line from objdump

  Returns:
    An instance of SymbolInfo if the line represents a symbol, None otherwise.
  
Create a SymbolInfo by parsing a properly formatted objdump output line.
Create a SymbolInfo by parsing a properly formatted objdump output line .
def _FromObjdumpLine(line):
  m = _OBJDUMP_LINE_RE.match(line)
  if not m:
    return None
  assert m.group('assert_scope') in set(['g', 'l', ' ']), line
  assert m.group('assert_weak_or_strong') in set(['w', ' ']), line
  assert m.group('assert_tab') == '\t', line
  assert m.group('assert_4spaces') == ' ' * 4, line
  name = m.group('name')
  offset = int(m.group('offset'), 16)
  if name == START_OF_TEXT_SYMBOL:
    return SymbolInfo(name=name, offset=offset, section='.text', size=0)
  symbol_type = m.group('symbol_type')
  if symbol_type == ' ':
    return None
  assert symbol_type != 'f', line
  size = int(m.group('size'), 16)
   Also disallow .internal and .protected symbols (as well as other flags),
   those have not appeared in the binaries we parse. Rejecting these extra
   prefixes is done by disallowing spaces in symbol names.
  assert re.match('^[a-zA-Z0-9_.][a-zA-Z0-9_.$]*$', name), name
  return SymbolInfo(name=name, offset=offset, section=m.group('section'),
                    size=size)
def _FromObjdumpLine ( line ) : m = _OBJDUMP_LINE_RE . match ( line ) if not m : return None assert m . group ( 'assert_scope' ) in set ( [ 'g' , 'l' , ' ' ] ) , line assert m . group ( 'assert_weak_or_strong' ) in set ( [ 'w' , ' ' ] ) , line assert m . group ( 'assert_tab' ) == '\t' , line assert m . group ( 'assert_4spaces' ) == ' ' * 4 , line name = m . group ( 'name' ) offset = int ( m . group ( 'offset' ) , 16 ) if name == START_OF_TEXT_SYMBOL : return SymbolInfo ( name = name , offset = offset , section = '.text' , size = 0 ) symbol_type = m . group ( 'symbol_type' ) if symbol_type == ' ' : return None assert symbol_type != 'f' , line size = int ( m . group ( 'size' ) , 16 ) assert re . match ( '^[a-zA-Z0-9_.][a-zA-Z0-9_.$]*$' , name ) , name return SymbolInfo ( name = name , offset = offset , section = m . group ( 'section' ) , size = size )
Create a SymbolInfo by parsing a properly formatted objdump output line.
Create a SymbolInfo by parsing a properly formatted objdump output line .
"""Create a SymbolInfo by parsing a properly formatted objdump output line.

  Args:
    line: line from objdump

  Returns:
    An instance of SymbolInfo if the line represents a symbol, None otherwise.
  """ # A symbol can be (g)lobal, (l)ocal, or neither (a space). Per objdump's # manpage, "A symbol can be neither local or global for a variety of reasons". # Output the label that contains the earliest offset. It is needed later for # translating offsets from the profile dumps. # Check symbol type for validity and ignore some types. # From objdump manual page: The symbol is the name of a function (F) or a file # (f) or an object (O) or just a normal symbol (a space). The 'normal' symbols # seens so far has been function-local labels. # Ignore local goto labels. Unfortunately, v8 builtins (like 'Builtins_.*') # are indistinguishable from labels of size 0 other than by name. # Guard against file symbols, since they are normally not seen in the # binaries we parse. # Extract the size from the ELF field. This value sometimes does not reflect # the real size of the function. One reason for that is the '.size' directive # in the assembler. As a result, a few functions in .S files have the size 0. # They are not instrumented (yet), but maintaining their order in the # orderfile may be important in some cases. # Forbid ARM mapping symbols and other unexpected symbol names, but allow $ # characters in a non-initial position, which can appear as a component of a # mangled name, e.g. Clang can mangle a lambda function to: # 02cd61e0 l     F .text  000000c0 _ZZL11get_globalsvENK3$_1clEv # The equivalent objdump line from GCC is: # 0325c58c l     F .text  000000d0 _ZZL11get_globalsvENKUlvE_clEv # # Also disallow .internal and .protected symbols (as well as other flags), # those have not appeared in the binaries we parse. Rejecting these extra # prefixes is done by disallowing spaces in symbol names.
An instance of SymbolInfo if the line represents a symbol, None otherwise.
An instance of SymbolInfo if the line represents a symbol None otherwise .
line
line from objdump
line from objdump