Skip to content

Commit

Permalink
Implement missing symbol logic in address lookup function
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-ol committed Oct 24, 2022
1 parent f7aabd7 commit a3b4174
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
24 changes: 13 additions & 11 deletions src/codeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,20 @@ const char* CodeCache::binarySearch(const void* address, LinearAllocator* alloca
if (low > 0 && (_blobs[low - 1]._start == _blobs[low - 1]._end || _blobs[low - 1]._end == address)) {
return _blobs[low - 1]._name;
}

char buf[512];
// add 1 for the null terminator
int n;
char *allocated;
if (_add_build_ids && _build_id) {
char buf[512];
// add 1 for the null terminator
const int n = 1 + snprintf(buf, sizeof(buf), "%s %s+%p_[bid]", _name, _build_id, (void*)((char*)address - (char*)_min_address));
char *allocated;
// if snprintf didn't overflow, and we manage to allocate a suitable buffer (from the LinearAllocator, not malloc,
// since this is signal context and malloc can deadlock) - then use them.
if (n < sizeof(buf) && (allocated = (char*)allocator->alloc(n)) != NULL) {
memcpy(allocated, buf, n);
return allocated;
}
n = 1 + snprintf(buf, sizeof(buf), "(%s) %s+%p_[bid]", _name, _build_id, (void*)((char*)address - (char*)_min_address));
} else {
n = 1 + snprintf(buf, sizeof(buf), "(%s)", _name);
}
// if snprintf didn't overflow, and we manage to allocate a suitable buffer (from the LinearAllocator, not malloc,
// since this is signal context and malloc can deadlock) - then use them.
if (n < sizeof(buf) && (allocated = (char*)allocator->alloc(n)) != NULL) {
memcpy(allocated, buf, n);
return allocated;
}
return _name;
}
Expand Down
16 changes: 1 addition & 15 deletions src/frameName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ static inline bool isDigit(char c) {
return c >= '0' && c <= '9';
}

static bool endsWith(const std::string& s, const char* suffix, size_t suffixlen) {
size_t len = s.length();
return len >= suffixlen && s.compare(len - suffixlen, suffixlen, suffix) == 0;
}

Matcher::Matcher(const char* pattern) {
if (pattern[0] == '*') {
Expand Down Expand Up @@ -139,13 +135,6 @@ char* FrameName::truncate(char* name, int max_length) {

const char* FrameName::decodeNativeSymbol(const char* name) {
const char* lib_name = (_style & STYLE_LIB_NAMES) ? Profiler::instance()->getLibraryName(name) : NULL;
bool report_lib_name_from_symbol = false;
if (lib_name == NULL && !endsWith(name, "_[k]", 4)) {
if (Profiler::instance()->findLibraryByName(name) != NULL) {
lib_name = name;
report_lib_name_from_symbol = true;
}
}

if (name[0] == '_' && name[1] == 'Z') {
int status;
Expand All @@ -161,10 +150,7 @@ const char* FrameName::decodeNativeSymbol(const char* name) {
}
}

if (report_lib_name_from_symbol) {
snprintf(_buf, sizeof(_buf) - 1, "(%s)", lib_name);
return _buf;
} else if (lib_name != NULL) {
if (lib_name != NULL) {
snprintf(_buf, sizeof(_buf) - 1, "%s (%s)", name, lib_name);
return _buf;
} else {
Expand Down

0 comments on commit a3b4174

Please sign in to comment.