This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

getting source locations ....


Hello All,

I am interested in getting the source location (at least the start
source file, linenumber, and possibly column number and end source
file, linenumber, ...) of

a GIMPLE/SSA tree (I want the corresponding source location, I very
much realize that the source location might not exist)

a basic block

a cgraph node


So far, for the GIMPLE/SSA tree, I'm doing something like


################################################################
/***
 * return true if a (GIMPLE/SSA) tree TR has a position 
 * and in that case fill the PFILENAME and PLINENO
 ***/
bool comprobe_get_position(tree tr, char**pfilename, int* plineno) 
{
  if (EXPR_P (tr))
    {
      const char **pfile = expr_filename (tr);
      if (pfile)
	{
	  *pfilename = *pfile;
	  *plineno = EXPR_LINENO (tr);
	  return;
	}
    }
  else if (GIMPLE_STMT_P (tr))
    {
      const char **pfile = expr_filename (tr);
      if (pfile)
	{
	  *pffilename = *pfile;
	  *plineno = EXPR_LINENO (tr);
	}
    }
  else if (GIMPLE_TUPLE_P (tr) && GIMPLE_TUPLE_HAS_LOCUS_P (tr))
    {
#warning dont know how to get location of a tuple
      gcc_unreachable ();
    }
  if (TREE_CODE (tr) == STATEMENT_LIST)
	{
	  tree_stmt_iterator iter;
	  tree tr_stmt;
	  for (iter = tsi_start (tr_body); !tsi_end_p (iter);
	       tsi_next (&iter))
	    {
	      tr_stmt = tsi_stmt (iter);
	      if (comprobe_get_position(tr_stmt, pfilename, plineno))
		return TRUE;
	    }
	}
  return FALSE;
}
################################################################

For a basic block, I don't know how to handle it

for a cgraph (cgr), since I'm interested in getting the location of the body of functions, I would do something like
  tree tr_body = DECL_SAVED_TREE(cgr->decl);
  return  comprobe_get_position(trbody, pfilename, plineno)

I welcome any comments or advices.... Notice that I don't know how to
get location of tuple trees.

I do know that this position information is not always available, but
I also know that the debugging information which is output with the -g
option is usually quite smart on this, so the information is somehow
"usually" available.

(I'm?working on the compiler probe idea, and on static analysis, so I
am interested in being able to show various infered properties about
gimple trees, and later to produce possible warnings about them).


I wish a very happy New Year 2007 to evryone!

Regards
-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 
8, rue de la Faïencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]