c++gccg++gcc-pluginsgimple

print called function name using GCC plugin


I need to print the name of the called functions of a program using gcc plugins for this I created a pass that will be called after ssa pass, I already initiated the plugin and I can loop on its statements, using a gimple_stmt_iterator :

int read_calls(){
  unsigned i;
  const_tree str, op;
  basic_block bb;
  gimple stmt;
  tree fnt;
  FOR_EACH_BB_FN(bb, cfun) {
    gimple_stmt_iterator gsi;
    for (gsi=gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi))
    {
        stmt = gsi_stmt(gsi);
        if (is_gimple_call(stmt)){
          const char* name = THE_FUNCTION_I_NEED(stmt);
          cerr << " Function : " << name << " is called \n";
        }
    }
  }
  return 0;
}

How can I print the name of the called function using its gimple node ?? Can I also print other informations like the line number where it was called, the name of the function where it was called etc .. ?


Solution

  • I've been looking for the answer for hours, the answer is actually pretty easy : get_name(tree node)... I've been trying many functions since the documentation is really poor... I found it here : GCC Middle and Back End API Reference

    As you can see, there is no comments about what the functions does, and it quit the best documentation I found about gcc, anyway get_name(..) is working fine, bit I haven't find how to print the source line yet