예제 #1
0
int
mpiPi_query_pc (void *pc, char **filename, char **functname, int *lineno)
{
  int rc = 0;
  callsite_pc_cache_entry_t key;
  callsite_pc_cache_entry_t *csp;
  char addr_buf[24];

  key.pc = pc;
  /* do we have a cache entry for this pc? If so, use entry */
  if (h_search (callsite_pc_cache, &key, (void **) &csp) == NULL)
    {
      /* no cache entry: create, lookup, and insert */
      csp =
	(callsite_pc_cache_entry_t *)
	malloc (sizeof (callsite_pc_cache_entry_t));
      csp->pc = pc;
#if defined(ENABLE_BFD) || defined(USE_LIBDWARF)
      if (mpiP_find_src_loc (pc, filename, lineno, functname) == 0)
	{
	  if (*filename == NULL || strcmp (*filename, "??") == 0)
	    *filename = "[unknown]";

	  if (*functname == NULL)
	    *functname = "[unknown]";

	  mpiPi_msg_debug
	    ("Successful Source lookup for [%s]: %s, %d, %s\n",
	     mpiP_format_address (pc, addr_buf), *filename, *lineno,
	     *functname);

	  csp->filename = strdup (*filename);
	  csp->functname = strdup (*functname);
	  csp->line = *lineno;
	}
      else
	{
	  mpiPi_msg_debug ("Unsuccessful Source lookup for [%s]\n",
			   mpiP_format_address (pc, addr_buf));
	  csp->filename = strdup ("[unknown]");
	  csp->functname = strdup ("[unknown]");
	  csp->line = 0;
	}
#else /* ! ENABLE_BFD || USE_LIBDWARF */
      csp->filename = strdup ("[unknown]");
      csp->functname = strdup ("[unknown]");
      csp->line = 0;
#endif
      h_insert (callsite_pc_cache, csp);
    }

  *filename = csp->filename;
  *functname = csp->functname;
  *lineno = csp->line;

  if (*lineno == 0)
    rc = 1;			/* use this value to indicate a failed lookup */

  return rc;
}
예제 #2
0
int
mpiP_find_src_loc (void *i_addr_hex,
		   char **o_file_str, int *o_lineno, char **o_funct_str)
{
  const struct AddrToSourceInfo *addrToSrcMapping = NULL;
  const struct FunctionInfo *functionInfo = NULL;
  char addr_buf[24];


  /* initialize the out parameters */
  assert (o_file_str != NULL);
  assert (o_lineno != NULL);
  assert (o_funct_str != NULL);

  *o_file_str = NULL;
  *o_lineno = 0;
  *o_funct_str = NULL;

  /* determine if we have source line info for this address */
  addrToSrcMapping = AddrToSourceMap_Find (i_addr_hex);
  if (addrToSrcMapping != NULL)
    {

      *o_file_str = addrToSrcMapping->fileName;
      *o_lineno = addrToSrcMapping->lineNumber;

      if (mpiPi.baseNames == 0 && *o_file_str != NULL)
	{
	  char *h;
	  h = strrchr (*o_file_str, '/');
	  if (h != NULL)
	    *o_file_str = h + 1;
	}
    }
  else
    {
      mpiPi_msg_warn ("unable to find source line info for address 0x%p\n",
		      i_addr_hex);
      /*
       * the rest of the mpiP code seems to expect that the filename
       * will be set to "??" if we are unable to associate it with a file
       */
      *o_file_str = "??";
    }

  /* determine if we have function info for this address */
  functionInfo = FunctionMap_Find (i_addr_hex);
  if (functionInfo != NULL)
    {
      *o_funct_str = functionInfo->name;
    }
  else
    {
      mpiPi_msg_warn ("unable to find function info for address %s\n",
		      mpiP_format_address (i_addr_hex, addr_buf));
    }

  return (((addrToSrcMapping != NULL) || (functionInfo != NULL)) ? 0 : 1);
}