Beispiel #1
0
bool
find_function_entry_range_from_pc (CORE_ADDR pc, const char **name,
				   CORE_ADDR *address, CORE_ADDR *endaddr)
{
  const struct block *block;
  bool status = find_pc_partial_function (pc, name, address, endaddr, &block);

  if (status && block != nullptr && !BLOCK_CONTIGUOUS_P (block))
    {
      CORE_ADDR entry_pc = BLOCK_ENTRY_PC (block);

      for (int i = 0; i < BLOCK_NRANGES (block); i++)
        {
	  if (BLOCK_RANGE_START (block, i) <= entry_pc
	      && entry_pc < BLOCK_RANGE_END (block, i))
	    {
	      if (address != nullptr)
	        *address = BLOCK_RANGE_START (block, i);

	      if (endaddr != nullptr)
	        *endaddr = BLOCK_RANGE_END (block, i);

	      return status;
	    }
	}

      /* It's an internal error if we exit the above loop without finding
         the range.  */
      internal_error (__FILE__, __LINE__,
                      _("Entry block not found in find_function_entry_range_from_pc"));
    }

  return status;
}
Beispiel #2
0
/* Return a 1 if any of the address ranges for block BL begins with START
   and any of the address ranges for BL ends with END; return a 0 otherwise.  */
int
block_starts_and_ends (struct block *bl, CORE_ADDR start, CORE_ADDR end)
{
  int retval;
  int start_found = 0;
  int end_found = 0;

  if (!BLOCK_RANGES (bl))
    retval = BLOCK_START (bl) == start && BLOCK_END (bl) == end;
  else
    {
      int i;
      for (i = 0;
           i < BLOCK_RANGES (bl)->nelts && !start_found && !end_found;
           i++)
	{
	  if (BLOCK_RANGE_START (bl, i) == start)
	    start_found = 1;
	  if (BLOCK_RANGE_END (bl, i) == end)
	    end_found = 1;
	}
      retval = start_found && end_found;
    }

  return retval;
}
Beispiel #3
0
int
block_contains_pc (const struct block *bl, CORE_ADDR pc)
{
  int i;
  int contains_pc = 0;

  if (! BLOCK_RANGES (bl))
    /* No range list; just a low & high address  */
    contains_pc = BLOCK_START (bl) <= pc && BLOCK_END (bl) > pc;
  else
    for (i = 0; i < BLOCK_RANGES (bl)->nelts && !contains_pc; i++)
      if (BLOCK_RANGE_START (bl, i) <= pc && BLOCK_RANGE_END (bl, i) > pc)
	contains_pc = 1;

  return contains_pc;
}
Beispiel #4
0
int
find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address,
			  CORE_ADDR *endaddr, const struct block **block)
{
  struct obj_section *section;
  struct symbol *f;
  struct bound_minimal_symbol msymbol;
  struct compunit_symtab *compunit_symtab = NULL;
  CORE_ADDR mapped_pc;

  /* To ensure that the symbol returned belongs to the correct setion
     (and that the last [random] symbol from the previous section
     isn't returned) try to find the section containing PC.  First try
     the overlay code (which by default returns NULL); and second try
     the normal section code (which almost always succeeds).  */
  section = find_pc_overlay (pc);
  if (section == NULL)
    section = find_pc_section (pc);

  mapped_pc = overlay_mapped_address (pc, section);

  if (mapped_pc >= cache_pc_function_low
      && mapped_pc < cache_pc_function_high
      && section == cache_pc_function_section)
    goto return_cached_value;

  msymbol = lookup_minimal_symbol_by_pc_section (mapped_pc, section);
  for (objfile *objfile : current_program_space->objfiles ())
    {
      if (objfile->sf)
	{
	  compunit_symtab
	    = objfile->sf->qf->find_pc_sect_compunit_symtab (objfile, msymbol,
							     mapped_pc,
							     section,
							     0);
	}
      if (compunit_symtab != NULL)
	break;
    }

  if (compunit_symtab != NULL)
    {
      /* Checking whether the msymbol has a larger value is for the
	 "pathological" case mentioned in stack.c:find_frame_funname.

	 We use BLOCK_ENTRY_PC instead of BLOCK_START_PC for this
	 comparison because the minimal symbol should refer to the
	 function's entry pc which is not necessarily the lowest
	 address of the function.  This will happen when the function
	 has more than one range and the entry pc is not within the
	 lowest range of addresses.  */
      f = find_pc_sect_function (mapped_pc, section);
      if (f != NULL
	  && (msymbol.minsym == NULL
	      || (BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (f))
		  >= BMSYMBOL_VALUE_ADDRESS (msymbol))))
	{
	  const struct block *b = SYMBOL_BLOCK_VALUE (f);

	  cache_pc_function_name = SYMBOL_LINKAGE_NAME (f);
	  cache_pc_function_section = section;
	  cache_pc_function_block = b;

	  /* For blocks occupying contiguous addresses (i.e. no gaps),
	     the low and high cache addresses are simply the start
	     and end of the block.

	     For blocks with non-contiguous ranges, we have to search
	     for the range containing mapped_pc and then use the start
	     and end of that range.

	     This causes the returned *ADDRESS and *ENDADDR values to
	     be limited to the range in which mapped_pc is found.  See
	     comment preceding declaration of find_pc_partial_function
	     in symtab.h for more information.  */

	  if (BLOCK_CONTIGUOUS_P (b))
	    {
	      cache_pc_function_low = BLOCK_START (b);
	      cache_pc_function_high = BLOCK_END (b);
	    }
	  else
	    {
	      int i;
	      for (i = 0; i < BLOCK_NRANGES (b); i++)
	        {
		  if (BLOCK_RANGE_START (b, i) <= mapped_pc
		      && mapped_pc < BLOCK_RANGE_END (b, i))
		    {
		      cache_pc_function_low = BLOCK_RANGE_START (b, i);
		      cache_pc_function_high = BLOCK_RANGE_END (b, i);
		      break;
		    }
		}
	      /* Above loop should exit via the break.  */
	      gdb_assert (i < BLOCK_NRANGES (b));
	    }


	  goto return_cached_value;
	}
    }

  /* Not in the normal symbol tables, see if the pc is in a known
     section.  If it's not, then give up.  This ensures that anything
     beyond the end of the text seg doesn't appear to be part of the
     last function in the text segment.  */

  if (!section)
    msymbol.minsym = NULL;

  /* Must be in the minimal symbol table.  */
  if (msymbol.minsym == NULL)
    {
      /* No available symbol.  */
      if (name != NULL)
	*name = 0;
      if (address != NULL)
	*address = 0;
      if (endaddr != NULL)
	*endaddr = 0;
      return 0;
    }

  cache_pc_function_low = BMSYMBOL_VALUE_ADDRESS (msymbol);
  cache_pc_function_name = MSYMBOL_LINKAGE_NAME (msymbol.minsym);
  cache_pc_function_section = section;
  cache_pc_function_high = minimal_symbol_upper_bound (msymbol);
  cache_pc_function_block = nullptr;

 return_cached_value:

  if (address)
    {
      if (pc_in_unmapped_range (pc, section))
	*address = overlay_unmapped_address (cache_pc_function_low, section);
      else
	*address = cache_pc_function_low;
    }

  if (name)
    *name = cache_pc_function_name;

  if (endaddr)
    {
      if (pc_in_unmapped_range (pc, section))
	{
	  /* Because the high address is actually beyond the end of
	     the function (and therefore possibly beyond the end of
	     the overlay), we must actually convert (high - 1) and
	     then add one to that.  */

	  *endaddr = 1 + overlay_unmapped_address (cache_pc_function_high - 1,
						   section);
	}
      else
	*endaddr = cache_pc_function_high;
    }

  if (block != nullptr)
    *block = cache_pc_function_block;

  return 1;
}
Beispiel #5
0
int
contained_in (const struct block *a, const struct block *b)
{
  int i, j;
  if (!a || !b)
    return 0;

  /* APPLE LOCAL begin address ranges  */
  if (BLOCK_RANGES (a) == NULL
      && BLOCK_RANGES (b) == NULL)
    {
 /* APPLE LOCAL end address ranges  */

      return BLOCK_START (a) >= BLOCK_START (b)
	&& BLOCK_END (a) <= BLOCK_END (b);

 /* APPLE LOCAL begin address ranges  */
    }
  else if (!BLOCK_RANGES (a))
    {
      /* Block A has a single contiguous address range, but block B
	 has multiple non-contiguous ranges.  A is contained in B
         if A's address range fits within ANY of B's address ranges. */

      for (i = 0; i < BLOCK_RANGES (b)->nelts; i++)
	if (BLOCK_START (a) >= BLOCK_RANGE_START (b, i)
	    && BLOCK_END (a) <= BLOCK_RANGE_END (b, i))
	  {
	    return 1;  /* A's scope fits within one of B's ranges */
	  }
      return 0; /* A's scope did not fit within any of B's ranges */
    }
  else if (!BLOCK_RANGES (b))
    {
      /* Block B has a single contiguous address range, but block A
	 has multiple non-contiguous ranges.  A is contained in B if
         ALL of A's address ranges fit within B's address range.  */

      for (i = 0; i < BLOCK_RANGES (a)->nelts; i++)
	if (BLOCK_RANGE_START (a, i) < BLOCK_START (b)
	    || BLOCK_RANGE_END (a, i) > BLOCK_END (b))
          {
	    return 0;  /* One of A's ranges is outside B's scope */
          }
      return 1; /* All of A's ranges are within B's scope */
    }
  else
    {
      /* Both block A and block B have non-contiguous address ranges.
         A is contained in B if all of A's address ranges fit within at
         least one of B's address ranges.  */

      int fits;
      for (i = 0; i < BLOCK_RANGES (a)->nelts; i++)
	{
	  fits = 0;
	  for (j = 0; j < BLOCK_RANGES (b)->nelts && !fits; j++)
	    if (BLOCK_RANGE_START (a, i) >= BLOCK_RANGE_START (b, j)
		&& BLOCK_RANGE_END (a, i) <= BLOCK_RANGE_END (b, j))
              {
	        fits = 1;
              }
          if (fits == 0)
            {
              /* One of A's ranges is is not contained within any B range */
              return 0;
            }
	}
      return 1;  /* All of A's ranges are contained within B's ranges */
    }
  /* APPLE LOCAL end address ranges  */
  return 0; /* notreached */
}