Hi, I am looking to change the edge instrumentation for gcov. Instead of just incrementing the edge count by 1, I want it to call an (external) function which determines whether it should increment, and depending on the answer, increment the edge.
I modified the tree_gen_edge_profiler function in tree-profile.c as follows in gcc-4.4, (changed lines prefixed by [*]) : (to instrument: temp = function_return_value(); /* function returns 0 or 1 */ edge_count = edge_count + temp; ) static void tree_gen_edge_profiler (int edgeno, edge e) { tree ref, one; gimple stmt1, stmt2, stmt3; [*] gimple call; [*] tree lhs, decl, should_gcov_name, should_gcov_type; /* We share one temporary variable declaration per function. This gets re-set in tree_profiling. */ if (gcov_type_tmp_var == NULL_TREE) gcov_type_tmp_var = create_tmp_var (gcov_type_node, "PROF_edge_counter"); ref = tree_coverage_counter_ref (GCOV_COUNTER_ARCS, edgeno); one = build_int_cst (gcov_type_node, 1); [*] should_gcov_name = get_identifier("__should_gcov"); [*] should_gcov_type = build_function_type(gcov_type_node, NULL_TREE /* no args */); [*] decl = build_decl(FUNCTION_DECL, should_gcov_name, should_gcov_type); [*] lhs = create_tmp_var (TREE_TYPE (TREE_TYPE (decl)), NULL); [*] call = gimple_build_call (decl, 0); [*] gimple_call_set_lhs (call, lhs); stmt1 = gimple_build_assign (gcov_type_tmp_var, ref); stmt2 = gimple_build_assign_with_ops (PLUS_EXPR, gcov_type_tmp_var, gcov_type_tmp_var, lhs); stmt3 = gimple_build_assign (unshare_expr (ref), gcov_type_tmp_var); [*] gsi_insert_on_edge (e, call); gsi_insert_on_edge (e, stmt1); gsi_insert_on_edge (e, stmt2); gsi_insert_on_edge (e, stmt3); } When I compile a program using this gcc and -fprofile-arcs, it does ask for the function __should_gcov. But when I use gcov to read the gcda file after running the program, there is some format error and it terminates stating buffer overflow. Hence, the format of the gcda file is somehow corrupt. Is there some other place I should modify because of my changes, like the number of basic blocks etc? (I don't care about the branch probability etc options -- I just want the line execution count) . Thanks, Hayawardh