#ifndef BASE_PROFILER_NATIVE_UNWINDER_ANDROID_H_
#define BASE_PROFILER_NATIVE_UNWINDER_ANDROID_H_
#include <memory>
#include <vector>
#include "base/base_export.h"
#include "base/memory/raw_ptr.h"
#include "base/profiler/unwinder.h"
#include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/DexFiles.h"
#include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/Memory.h"
namespace base {
class NativeUnwinderAndroidMapDelegate;
class NativeUnwinderAndroidMemoryRegionsMap;
class NativeUnwinderAndroidMemoryRegionsMapImpl;
class BASE_EXPORT UnwindStackMemoryAndroid : public unwindstack::Memory {
public:
UnwindStackMemoryAndroid(uintptr_t stack_ptr, uintptr_t stack_top);
~UnwindStackMemoryAndroid() override;
size_t Read(uint64_t addr, void* dst, size_t size) override;
private:
const uintptr_t stack_ptr_;
const uintptr_t stack_top_;
};
class BASE_EXPORT NativeUnwinderAndroid
: public Unwinder,
public ModuleCache::AuxiliaryModuleProvider {
public:
static std::unique_ptr<NativeUnwinderAndroidMemoryRegionsMap>
CreateMemoryRegionsMap(bool use_updatable_maps = false);
NativeUnwinderAndroid(uintptr_t exclude_module_with_base_address,
NativeUnwinderAndroidMapDelegate* map_delegate);
~NativeUnwinderAndroid() override;
NativeUnwinderAndroid(const NativeUnwinderAndroid&) = delete;
NativeUnwinderAndroid& operator=(const NativeUnwinderAndroid&) = delete;
void InitializeModules() override;
bool CanUnwindFrom(const Frame& current_frame) const override;
UnwindResult TryUnwind(UnwinderStateCapture* capture_state,
RegisterContext* thread_context,
uintptr_t stack_top,
std::vector<Frame>* stack) override;
std::unique_ptr<const ModuleCache::Module> TryCreateModuleForAddress(
uintptr_t address) override;
private:
unwindstack::DexFiles* GetOrCreateDexFiles(unwindstack::ArchEnum arch);
void EmitDexFrame(uintptr_t dex_pc,
unwindstack::ArchEnum,
std::vector<Frame>* stack);
std::unique_ptr<unwindstack::DexFiles> dex_files_;
const uintptr_t exclude_module_with_base_address_;
raw_ptr<NativeUnwinderAndroidMapDelegate> map_delegate_;
const raw_ptr<NativeUnwinderAndroidMemoryRegionsMapImpl> memory_regions_map_;
const std::vector<std::string> search_libs_ = {"libart.so", "libartd.so"};
};
}
#endif