Skip to content

Commit

Permalink
stacktrace: Implement is_ignored function
Browse files Browse the repository at this point in the history
is_ignored function can be used to check whether the input `report` contains
any ignore string. Ignore string can be read from the given file. Each line
of the file is considered as ignore string. Ignore string could be function
name, library name as well as something you want.

Ignore file example:

  $ cat ignore.txt
  libfoo
  bar
  baz

Signed-off-by: Bojun Seo <[email protected]>
  • Loading branch information
Bojun-Seo committed Nov 24, 2024
1 parent 5155231 commit 748618d
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/stacktrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <map>
#include <sstream>
#include <vector>

#include <mutex>

#include "compiler.h"
Expand All @@ -33,9 +32,40 @@

std::map<stack_trace_t, stack_info_t> stackmap;
std::map<addr_t, object_info_t> addrmap;
std::vector<std::string> ignorevec;
bool ignorevec_initialized = false;

std::recursive_mutex container_mutex;

static void lazyinit_ignorevec()
{
if (ignorevec_initialized)
return;

opts.ignore = getenv("HEAPTRACE_IGNORE");
if (opts.ignore) {
std::ifstream file(opts.ignore);
if (file.is_open()) {
std::string line;
while (std::getline(file, line)) {
ignorevec.push_back(line);
}
file.close();
}
else {
pr_out("Failed to open file %s\n", opts.ignore);
}
}
ignorevec_initialized = true;
}

static bool is_ignored(const std::string &report)
{
lazyinit_ignorevec();
return std::any_of(ignorevec.begin(), ignorevec.end(), [&report](const std::string& s)
{ return report.find(s) != std::string::npos; });
}

// record_backtrace() is defined in stacktrace.h as an inline function.
void __record_backtrace(size_t size, void *addr, stack_trace_t &stack_trace, int nptrs)
{
Expand Down

0 comments on commit 748618d

Please sign in to comment.