instrumentation: include functions with specific calls (#202)
* instrumentation: include functions with specific calls Add the option `--caller-include <regex>` or environment variable `OMNITRACE_REGEX_CALLER_INCLUDE` to instrument functions which contain call to a set of functions, E.g. `--caller-include foo` instruments any function which calls `foo`. * Serialize caller include information * Add test for caller include * Tweak to the caller include test - tweak environment - tweak pass regexes * Set rewrite caller example to debug , to avoid optimizing out the call expressions that it relies on. Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
This commit is contained in:
committato da
GitHub
parent
654beef6ab
commit
1b8f09aa2d
@@ -208,6 +208,7 @@ extern regexvec_t file_include;
|
||||
extern regexvec_t file_exclude;
|
||||
extern regexvec_t file_restrict;
|
||||
extern regexvec_t func_restrict;
|
||||
extern regexvec_t caller_include;
|
||||
extern CodeCoverageMode coverage_mode;
|
||||
|
||||
// logging
|
||||
|
||||
@@ -333,7 +333,7 @@ module_function::is_user_included() const
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return contains_user_callsite();
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -534,6 +534,27 @@ module_function::contains_dynamic_callsites() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
module_function::contains_user_callsite() const
|
||||
{
|
||||
if(caller_include.empty()) return false;
|
||||
|
||||
bpvector_t<BPatch_point*> call_points;
|
||||
function->getCallPoints(call_points);
|
||||
for(const auto& call_point : call_points)
|
||||
{
|
||||
if(check_regex_restrictions(
|
||||
std::string(get_name(call_point->getCalledFunction())), caller_include))
|
||||
{
|
||||
messages.emplace_back(2, "Forcing", "function", "caller-include-regex",
|
||||
function_name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
module_function::is_dynamic_callsite_forced() const
|
||||
{
|
||||
|
||||
@@ -112,6 +112,7 @@ private:
|
||||
bool is_loop_address_range_constrained() const; // checks loop addr range constraint
|
||||
bool contains_dynamic_callsites() const;
|
||||
bool should_instrument(bool _coverage) const;
|
||||
bool contains_user_callsite() const; // checks user caller regexes
|
||||
|
||||
public:
|
||||
template <typename ArchiveT>
|
||||
@@ -198,6 +199,7 @@ module_function::serialize(ArchiveT& ar, const unsigned)
|
||||
cereal::make_nvp("is_routine_constrained", is_routine_constrained()),
|
||||
cereal::make_nvp("is_user_restricted", is_user_restricted()),
|
||||
cereal::make_nvp("is_user_included", is_user_included()),
|
||||
cereal::make_nvp("contains_user_callsite", contains_user_callsite()),
|
||||
cereal::make_nvp("is_user_excluded", is_user_excluded()),
|
||||
cereal::make_nvp("is_overlapping_constrained", is_overlapping_constrained()),
|
||||
cereal::make_nvp("is_entry_trap_constrained", is_entry_trap_constrained()),
|
||||
|
||||
@@ -124,6 +124,7 @@ regexvec_t file_include = {};
|
||||
regexvec_t file_exclude = {};
|
||||
regexvec_t file_restrict = {};
|
||||
regexvec_t func_restrict = {};
|
||||
regexvec_t caller_include = {};
|
||||
CodeCoverageMode coverage_mode = CODECOV_NONE;
|
||||
|
||||
std::unique_ptr<std::ofstream> log_ofs = {};
|
||||
@@ -633,6 +634,9 @@ main(int argc, char** argv)
|
||||
parser.add_argument({ "-R", "--function-restrict" },
|
||||
"Regex(es) for restricting functions only to those "
|
||||
"that match the provided regular-expressions");
|
||||
parser.add_argument({ "--caller-include" },
|
||||
"Regex(es) for including functions that call the "
|
||||
"listed functions (despite heuristics)");
|
||||
parser.add_argument({ "-MI", "--module-include" },
|
||||
"Regex(es) for selecting modules/files/libraries "
|
||||
"(despite heuristics)");
|
||||
@@ -1101,6 +1105,8 @@ main(int argc, char** argv)
|
||||
add_regex(func_include, tim::get_env<string_t>("OMNITRACE_REGEX_INCLUDE", ""));
|
||||
add_regex(func_exclude, tim::get_env<string_t>("OMNITRACE_REGEX_EXCLUDE", ""));
|
||||
add_regex(func_restrict, tim::get_env<string_t>("OMNITRACE_REGEX_RESTRICT", ""));
|
||||
add_regex(caller_include,
|
||||
tim::get_env<string_t>("OMNITRACE_REGEX_CALLER_INCLUDE"));
|
||||
|
||||
add_regex(file_include,
|
||||
tim::get_env<string_t>("OMNITRACE_REGEX_MODULE_INCLUDE", ""));
|
||||
@@ -1123,6 +1129,7 @@ main(int argc, char** argv)
|
||||
_parse_regex_option("function-include", func_include);
|
||||
_parse_regex_option("function-exclude", func_exclude);
|
||||
_parse_regex_option("function-restrict", func_restrict);
|
||||
_parse_regex_option("caller-include", caller_include);
|
||||
_parse_regex_option("module-include", file_include);
|
||||
_parse_regex_option("module-exclude", file_exclude);
|
||||
_parse_regex_option("module-restrict", file_restrict);
|
||||
|
||||
Fai riferimento in un nuovo problema
Block a user