[hellogcc] [PATCH] Add -finstrument-functions-include-function-list=

  • From: Mingjie Xing <mingjie.xing@xxxxxxxxx>
  • To: hellogcc@xxxxxxxxxxxxx
  • Date: Fri, 17 Jun 2011 13:52:08 +0800

这个patch是基于trunk生成的,但是感觉实现的不是很完善,提进去未必好。所以先发这里,仅供参阅。

问题出在,现有的 -finstrument-functions-include-function-list= 和
-finstrument-functions-include-file-list= 采用 strstr 函数进行字符串匹配,现在
-finstrument-functions-include-function-list=
似乎应该使用strcmp进行匹配更好些。这可以根据个人需要,进行修改,我也没有找到完善的方法。

xmj
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi     (revision 175074)
+++ doc/invoke.texi     (working copy)
@@ -932,6 +932,8 @@ See S/390 and zSeries Options.
 -finhibit-size-directive  -finstrument-functions @gol
 -finstrument-functions-exclude-function-list=@var{sym},@var{sym},@dots{} @gol
 -finstrument-functions-exclude-file-list=@var{file},@var{file},@dots{} @gol
+-finstrument-functions-include-function-list=@var{sym},@var{sym},@dots{} @gol
+-finstrument-functions-include-file-list=@var{file},@var{file},@dots{} @gol
 -fno-common  -fno-ident @gol
 -fpcc-struct-return  -fpic  -fPIC -fpie -fPIE @gol
 -fno-jump-tables @gol
@@ -18139,6 +18141,19 @@ of the function name, it is considered t
 extended identifiers, the function name must be given in UTF-8, not
 using universal character names.
 
+@item -finstrument-functions-include-file-list=@var{file},@var{file},@dots{}
+@itemx -finstrument-functions-include-function-list=@var{sym},@var{sym},@dots{}
+@opindex finstrument-functions-include-file-list
+@opindex finstrument-functions-include-function-list
+
+These are similar to @code{-finstrument-functions-exclude-file-list} and
+@code{-finstrument-functions-exclude-function-list}, but they set the list
+of functions that are included from instrumentation.
+
 @item -fstack-check
 @opindex fstack-check
 Generate code to verify that you do not go beyond the boundary of the
Index: common.opt
===================================================================
--- common.opt  (revision 175074)
+++ common.opt  (working copy)
@@ -84,7 +84,7 @@ int flag_gen_aux_info = 0
 Variable
 int flag_shlib
 
-; These two are really VEC(char_p,heap) *.
+; These four are really VEC(char_p,heap) *.
 
 Variable
 void *flag_instrument_functions_exclude_functions
@@ -92,6 +92,12 @@ void *flag_instrument_functions_exclude_
 Variable
 void *flag_instrument_functions_exclude_files
 
+Variable
+void *flag_instrument_functions_include_functions
+
+Variable
+void *flag_instrument_functions_include_files
+
 ; Generic structs (e.g. templates not explicitly specialized)
 ; may not have a compilation unit associated with them, and so
 ; may need to be treated differently from ordinary structs.
@@ -1259,6 +1265,14 @@ finstrument-functions-exclude-file-list=
 Common RejectNegative Joined
 -finstrument-functions-exclude-file-list=filename,...  Do not instrument 
functions listed in files
 
+finstrument-functions-include-function-list=
+Common RejectNegative Joined
+-finstrument-functions-include-function-list=name,...  Instrument listed 
functions
+
+finstrument-functions-include-file-list=
+Common RejectNegative Joined
+-finstrument-functions-include-file-list=filename,...  Instrument functions 
listed in files
+
 fipa-cp
 Common Report Var(flag_ipa_cp) Optimization
 Perform Interprocedural constant propagation
Index: gimplify.c
===================================================================
--- gimplify.c  (revision 175074)
+++ gimplify.c  (working copy)
@@ -7853,6 +7853,46 @@ flag_instrument_functions_exclude_p (tre
   return false;
 }
 
+/* Return whether we should include FNDECL from instrumentation.  */
+
+static bool
+flag_instrument_functions_include_p (tree fndecl)
+{
+  VEC(char_p,heap) *vec_1, *vec_2;
+
+  vec_1 = (VEC(char_p,heap) *) flag_instrument_functions_include_functions;
+  vec_2 = (VEC(char_p,heap) *) flag_instrument_functions_include_files;
+
+  if (VEC_length (char_p, vec_1) == 0 && VEC_length (char_p, vec_2) == 0)
+    return true;
+
+  if (VEC_length (char_p, vec_1) > 0)
+    {
+      const char *name;
+      int i;
+      char *s;
+
+      name = lang_hooks.decl_printable_name (fndecl, 0);
+      FOR_EACH_VEC_ELT (char_p, vec_1, i, s)
+       if (strstr (name, s) != NULL)
+         return true;
+    }
+
+  if (VEC_length (char_p, vec_2) > 0)
+    {
+      const char *name;
+      int i;
+      char *s;
+
+      name = DECL_SOURCE_FILE (fndecl);
+      FOR_EACH_VEC_ELT (char_p, vec_2, i, s)
+       if (strstr (name, s) != NULL)
+         return true;
+    }
+
+  return false;
+}
+
 /* Entry point to the gimplification pass.  FNDECL is the FUNCTION_DECL
    node for the function we want to gimplify.
 
@@ -7907,6 +7947,7 @@ gimplify_function_tree (tree fndecl)
   /* ??? Add some way to ignore exceptions for this TFE.  */
   if (flag_instrument_function_entry_exit
       && !DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl)
+      && flag_instrument_functions_include_p (fndecl)
       && !flag_instrument_functions_exclude_p (fndecl))
     {
       tree x;
Index: opts.c
===================================================================
--- opts.c      (revision 175074)
+++ opts.c      (working copy)
@@ -1515,6 +1515,16 @@ common_handle_option (struct gcc_options
        (&opts->x_flag_instrument_functions_exclude_files, arg);
       break;
 
+    case OPT_finstrument_functions_include_function_list_:
+      add_comma_separated_to_vector
+       (&opts->x_flag_instrument_functions_include_functions, arg);
+      break;
+
+    case OPT_finstrument_functions_include_file_list_:
+      add_comma_separated_to_vector
+       (&opts->x_flag_instrument_functions_include_files, arg);
+      break;
+
     case OPT_fmessage_length_:
       pp_set_line_maximum_length (dc->printer, value);
       break;
/* { dg-do compile } */
/* { dg-options "-finstrument-functions 
-finstrument-functions-include-function-list=fn" } */

void fn () { }

/* { dg-final { scan-assembler "__cyg_profile_func_enter" } } */
/* { dg-final { scan-assembler "__cyg_profile_func_exit" } } */
/* { dg-do compile } */
/* { dg-options "-finstrument-functions 
-finstrument-functions-include-file-list=instrument-5.c" } */

void fn () { }

/* { dg-final { scan-assembler "__cyg_profile_func_enter" } } */
/* { dg-final { scan-assembler "__cyg_profile_func_exit" } } */

Other related posts:

  • » [hellogcc] [PATCH] Add -finstrument-functions-include-function-list= - Mingjie Xing