Skip to content

Commit 044dcf5

Browse files
committed
Fix root symbol detection
1 parent ace7e6c commit 044dcf5

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

ddprof-lib/src/main/cpp/codeCache.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ CodeBlob *CodeCache::findBlobByAddress(const void *address) {
190190
return NULL;
191191
}
192192

193-
const char *CodeCache::binarySearch(const void *address) {
193+
const void *CodeCache::binarySearch(const void *address, const char **name) {
194194
int low = 0;
195195
int high = _count - 1;
196196

@@ -201,7 +201,10 @@ const char *CodeCache::binarySearch(const void *address) {
201201
} else if (_blobs[mid]._start > address) {
202202
high = mid - 1;
203203
} else {
204-
return _blobs[mid]._name;
204+
if (name != NULL) {
205+
*name = _blobs[mid]._name;
206+
}
207+
return _blobs[mid]._start;
205208
}
206209
}
207210

@@ -210,7 +213,12 @@ const char *CodeCache::binarySearch(const void *address) {
210213
// point beyond the function.
211214
if (low > 0 && (_blobs[low - 1]._start == _blobs[low - 1]._end ||
212215
_blobs[low - 1]._end == address)) {
213-
return _blobs[low - 1]._name;
216+
217+
if (name != NULL) {
218+
*name = _blobs[low - 1]._name;
219+
}
220+
221+
return _blobs[low - 1]._start;
214222
}
215223
return _name;
216224
}

ddprof-lib/src/main/cpp/codeCache.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class CodeCache {
162162

163163
CodeBlob *findBlob(const char *name);
164164
CodeBlob *findBlobByAddress(const void *address);
165-
const char *binarySearch(const void *address);
165+
const void *binarySearch(const void *address, const char **name);
166166
const void *findSymbol(const char *name);
167167
const void *findSymbolByPrefix(const char *prefix);
168168
const void *findSymbolByPrefix(const char *prefix, int prefix_len);

ddprof-lib/src/main/cpp/profiler.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,11 @@ const char *Profiler::getLibraryName(const char *native_symbol) {
245245

246246
const char *Profiler::findNativeMethod(const void *address) {
247247
CodeCache *lib = _libs->findLibraryByAddress(address);
248-
return lib == NULL ? NULL : lib->binarySearch(address);
248+
const char *name = NULL;
249+
if (lib != NULL) {
250+
lib->binarySearch(address, &name);
251+
}
252+
return name;
249253
}
250254

251255
CodeBlob *Profiler::findRuntimeStub(const void *address) {

ddprof-lib/src/main/cpp/stackWalker.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,12 @@ int StackWalker::walkVM(void* ucontext, ASGCT_CallFrame* frames, int max_depth,
504504
if (cc == NULL || !cc->contains(pc)) {
505505
cc = libraries->findLibraryByAddress(pc);
506506
}
507-
const char *name = cc == NULL ? NULL : cc->binarySearch(pc);
507+
const char *name = NULL;
508+
const void* symbolPc = cc == NULL ? NULL : cc->binarySearch(pc, &name);
508509

509510
fillFrame(frames[depth++], BCI_NATIVE_FRAME, name);
510511

511-
if (Symbols::isRootSymbol(pc)) {
512+
if (symbolPc && Symbols::isRootSymbol(symbolPc)) {
512513
break;
513514
}
514515
prev_pc = pc;

ddprof-lib/src/main/cpp/symbols_linux.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,6 @@ void ElfParser::loadSymbols(bool use_debug) {
353353

354354
void ElfParser::addSymbol(const void *start, int length, const char *name, bool update_bounds) {
355355
_cc->add(start, length, name, update_bounds);
356-
if (strstr(name, "thread_native_entry")) {
357-
TEST_LOG("===> %s", name);
358-
}
359356
for (int i = 0; i < LAST_ROOT_SYMBOL_KIND; i++) {
360357
if (!strcmp(root_symbol_table[i].name, name)) {
361358
TEST_LOG("Adding root symbol %s: %p", name, start);

0 commit comments

Comments
 (0)