gccの-finstrument-functions
オプションを使用しています。オーバーヘッドを最小限に抑えるために、いくつかの関数のみを計測したいと考えています。ただし、gcc では関数をブラックリストに登録することしかできません (no_instrument_function
属性を使用するか、パスのリストを提供することによって)。関数をホワイトリストに登録することはできません。
instrument_function
そこで、属性を追加する小さな gcc プラグインを作成しました。これにより、特定の関数のインストルメンテーション「フラグ」を設定できます (または、インストルメンテーションなしフラグをクリアします)。
tree handle_instrument_function_attribute(
tree * node,
tree name,
tree args,
int flags,
bool * no_add_attrs)
{
tree decl = *node;
DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT(decl) = 0;
return NULL_TREE;
}
しかし、私の理解では、これは機能しません。gcc のソースを見ると、このフラグが実際に何かを行うには、 も使用する必要があります-finstrument-functions
。参照gcc/gimplify.c:14436
:
...
/* If we're instrumenting function entry/exit, then prepend the call to
the entry hook and wrap the whole function in a TRY_FINALLY_EXPR to
catch the exit hook. */
/* ??? Add some way to ignore exceptions for this TFE. */
if (flag_instrument_function_entry_exit
&& !DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl)
/* Do not instrument extern inline functions. */
&& !(DECL_DECLARED_INLINE_P (fndecl)
&& DECL_EXTERNAL (fndecl)
&& DECL_DISREGARD_INLINE_LIMITS (fndecl))
&& !flag_instrument_functions_exclude_p (fndecl))
...
まず、グローバル-finstrument-functions
フラグが有効になっていることを確認します。次に、特定の関数のフラグをチェックします。これは、私が理解していることから、デフォルトで有効になっています。したがって、my 属性を持たない他のすべての関数instrument_function
は引き続きインストルメント化されます。
最初にすべての関数のこのフラグをクリアしてから、instrument_function
属性を処理してそれらの関数のみにフラグを設定する方法はありますか?