third_party/android_platform/development/scripts/symbol.py
def _CallObjdumpForSet(lib, unique_addrs, cpu_arch):
  """Use objdump to find out the names of the containing functions.

  Args:
    lib: library (or executable) pathname containing symbols
    unique_addrs: set of string hexidecimal addresses to find the functions for.
    cpu_arch: Target CPU architecture.

  Returns:
    A dictionary of the form {addr: (string symbol, offset)}.
  """
  if not lib:
    return None

  symbols = SYMBOLS_DIR + lib
  if not os.path.exists(symbols):
    return None

  symbols = SYMBOLS_DIR + lib
  if not os.path.exists(symbols):
    return None

  result = {}

  # Function lines look like:
  #   000177b0 <android::IBinder::~IBinder()+0x2c>:
  # We pull out the address and function first. Then we check for an optional
  # offset. This is tricky due to functions that look like "operator+(..)+0x2c"
  func_regexp = re.compile("(^[a-f0-9]*) \<(.*)\>:$")
  offset_regexp = re.compile("(.*)\+0x([a-f0-9]*)")

  # A disassembly line looks like:
  #   177b2:  b510        push  {r4, lr}
  asm_regexp = re.compile("(^[ a-f0-9]*):[ a-f0-0]*.*$")

  for target_addr in unique_addrs:
    start_addr_dec = str(_StripPC(int(target_addr, 16), cpu_arch))
    stop_addr_dec = str(_StripPC(int(target_addr, 16), cpu_arch) + 8)
    cmd = [host_paths.ToolPath("objdump", cpu_arch),
           "--section=.text",
           "--demangle",
           "--disassemble",
           "--start-address=" + start_addr_dec,
           "--stop-address=" + stop_addr_dec,
           symbols]

    current_symbol = None    # The current function symbol in the disassembly.
    current_symbol_addr = 0  # The address of the current function.

    stream = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout
    for line in stream:
      # Is it a function line like:
      #   000177b0 <android::IBinder::~IBinder()>:
      components = func_regexp.match(line)
      if components:
        # This is a new function, so record the current function and its
        # address.
        current_symbol_addr = int(components.group(1), 16)
        current_symbol = components.group(2)

        # Does it have an optional offset like: "foo(..)+0x2c"?
        components = offset_regexp.match(current_symbol)
        if components:
          current_symbol = components.group(1)
          offset = components.group(2)
          if offset:
            current_symbol_addr -= int(offset, 16)

      # Is it an disassembly line like:
      #   177b2:  b510        push  {r4, lr}
      components = asm_regexp.match(line)
      if components:
        addr = components.group(1)
        i_addr = int(addr, 16)
        i_target = _StripPC(int(target_addr, 16), cpu_arch)
        if i_addr == i_target:
          result[target_addr] = (current_symbol, i_target - current_symbol_addr)
    stream.close()

  return result
Use objdump to find out the names of the containing functions.

  Args:
    lib: library (or executable) pathname containing symbols
    unique_addrs: set of string hexidecimal addresses to find the functions for.
    cpu_arch: Target CPU architecture.

  Returns:
    A dictionary of the form {addr: (string symbol, offset)}.
  
Use objdump to find out the names of the containing functions.
Use objdump to find out the names of the containing functions .
def _CallObjdumpForSet(lib, unique_addrs, cpu_arch):
  if not lib:
    return None
  symbols = SYMBOLS_DIR + lib
  if not os.path.exists(symbols):
    return None
  symbols = SYMBOLS_DIR + lib
  if not os.path.exists(symbols):
    return None
  result = {}
  func_regexp = re.compile("(^[a-f0-9]*) \<(.*)\>:$")
  offset_regexp = re.compile("(.*)\+0x([a-f0-9]*)")
  asm_regexp = re.compile("(^[ a-f0-9]*):[ a-f0-0]*.*$")
  for target_addr in unique_addrs:
    start_addr_dec = str(_StripPC(int(target_addr, 16), cpu_arch))
    stop_addr_dec = str(_StripPC(int(target_addr, 16), cpu_arch) + 8)
    cmd = [host_paths.ToolPath("objdump", cpu_arch),
           "--section=.text",
           "--demangle",
           "--disassemble",
           "--start-address=" + start_addr_dec,
           "--stop-address=" + stop_addr_dec,
           symbols]
    current_symbol = None    
    current_symbol_addr = 0  
    stream = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout
    for line in stream:
      components = func_regexp.match(line)
      if components:
        current_symbol_addr = int(components.group(1), 16)
        current_symbol = components.group(2)
        components = offset_regexp.match(current_symbol)
        if components:
          current_symbol = components.group(1)
          offset = components.group(2)
          if offset:
            current_symbol_addr -= int(offset, 16)
      components = asm_regexp.match(line)
      if components:
        addr = components.group(1)
        i_addr = int(addr, 16)
        i_target = _StripPC(int(target_addr, 16), cpu_arch)
        if i_addr == i_target:
          result[target_addr] = (current_symbol, i_target - current_symbol_addr)
    stream.close()
  return result
def _CallObjdumpForSet ( lib , unique_addrs , cpu_arch ) : if not lib : return None symbols = SYMBOLS_DIR + lib if not os . path . exists ( symbols ) : return None symbols = SYMBOLS_DIR + lib if not os . path . exists ( symbols ) : return None result = { } func_regexp = re . compile ( "(^[a-f0-9]*) \<(.*)\>:$" ) offset_regexp = re . compile ( "(.*)\+0x([a-f0-9]*)" ) asm_regexp = re . compile ( "(^[ a-f0-9]*):[ a-f0-0]*.*$" ) for target_addr in unique_addrs : start_addr_dec = str ( _StripPC ( int ( target_addr , 16 ) , cpu_arch ) ) stop_addr_dec = str ( _StripPC ( int ( target_addr , 16 ) , cpu_arch ) + 8 ) cmd = [ host_paths . ToolPath ( "objdump" , cpu_arch ) , "--section=.text" , "--demangle" , "--disassemble" , "--start-address=" + start_addr_dec , "--stop-address=" + stop_addr_dec , symbols ] current_symbol = None current_symbol_addr = 0 stream = subprocess . Popen ( cmd , stdout = subprocess . PIPE ) . stdout for line in stream : components = func_regexp . match ( line ) if components : current_symbol_addr = int ( components . group ( 1 ) , 16 ) current_symbol = components . group ( 2 ) components = offset_regexp . match ( current_symbol ) if components : current_symbol = components . group ( 1 ) offset = components . group ( 2 ) if offset : current_symbol_addr -= int ( offset , 16 ) components = asm_regexp . match ( line ) if components : addr = components . group ( 1 ) i_addr = int ( addr , 16 ) i_target = _StripPC ( int ( target_addr , 16 ) , cpu_arch ) if i_addr == i_target : result [ target_addr ] = ( current_symbol , i_target - current_symbol_addr ) stream . close ( ) return result
Use objdump to find out the names of the containing functions.
Use objdump to find out the names of the containing functions .
"""Use objdump to find out the names of the containing functions.

  Args:
    lib: library (or executable) pathname containing symbols
    unique_addrs: set of string hexidecimal addresses to find the functions for.
    cpu_arch: Target CPU architecture.

  Returns:
    A dictionary of the form {addr: (string symbol, offset)}.
  """ # Function lines look like: #   000177b0 <android::IBinder::~IBinder()+0x2c>: # We pull out the address and function first. Then we check for an optional # offset. This is tricky due to functions that look like "operator+(..)+0x2c" # A disassembly line looks like: #   177b2:  b510        push  {r4, lr} # The current function symbol in the disassembly. # The address of the current function. # Is it a function line like: #   000177b0 <android::IBinder::~IBinder()>: # This is a new function, so record the current function and its # address. # Does it have an optional offset like: "foo(..)+0x2c"? # Is it an disassembly line like: #   177b2:  b510        push  {r4, lr}
A dictionary of the form {addr: (string symbol, offset)}.
A dictionary of the form { addr : ( string symbol offset ) } .
lib
library (or executable) pathname containing symbols
library ( or executable ) pathname containing symbols
unique_addrs
set of string hexidecimal addresses to find the functions for.
set of string hexidecimal addresses to find the functions for .
cpu_arch
Target CPU architecture.
Target CPU architecture .