Remove recursion from FindModuleForAddress. NFC.
@@ -163,29 +163,42 @@ bool Symbolizer::FindModuleNameAndOffsetForAddress(uptr address,
return true;
}
-const LoadedModule *Symbolizer::FindModuleForAddress(uptr address) {
- bool modules_were_reloaded = false;
- if (!modules_fresh_) {
+void Symbolizer::RefreshModules() {
modules_.init();
RAW_CHECK(modules_.size() > 0);
modules_fresh_ = true;
- modules_were_reloaded = true;
}
- for (uptr i = 0; i < modules_.size(); i++) {
- if (modules_[i].containsAddress(address)) {
- return &modules_[i];
+
+static const LoadedModule *SearchForModule(const ListOfModules &modules,
+ uptr address) {
+ for (uptr i = 0; i < modules.size(); i++) {
+ if (modules[i].containsAddress(address)) {
+ return &modules[i];
+ }
}
+ return nullptr;
}
+
+const LoadedModule *Symbolizer::FindModuleForAddress(uptr address) {
+ bool modules_were_reloaded = false;
+ if (!modules_fresh_) {
+ RefreshModules();
+ modules_were_reloaded = true;
+ }
+ const LoadedModule *module = SearchForModule(modules_, address);
+ if (module) return module;
+
// dlopen/dlclose interceptors invalidate the module list, but when
// interception is disabled, we need to retry if the lookup fails in
// case the module list changed.
#if !SANITIZER_INTERCEPT_DLOPEN_DLCLOSE
if (!modules_were_reloaded) {
- modules_fresh_ = false;
- return FindModuleForAddress(address);
+ RefreshModules();
+ module = SearchForModule(modules_, address);
+ if (module) return module;
}
#endif
- return 0;
+ return module;
}
// For now we assume the following protocol:
