Backtrace.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Types.h>
  8. #include <LibCoreDump/Reader.h>
  9. #include <LibDebug/DebugInfo.h>
  10. #include <LibELF/CoreDump.h>
  11. namespace CoreDump {
  12. struct ELFObjectInfo {
  13. ELFObjectInfo(NonnullRefPtr<MappedFile> file, NonnullOwnPtr<Debug::DebugInfo>&& debug_info)
  14. : file(move(file))
  15. , debug_info(move(debug_info))
  16. {
  17. }
  18. NonnullRefPtr<MappedFile> file;
  19. NonnullOwnPtr<Debug::DebugInfo> debug_info;
  20. };
  21. class Backtrace {
  22. public:
  23. struct Entry {
  24. FlatPtr eip;
  25. String object_name;
  26. String function_name;
  27. Debug::DebugInfo::SourcePositionWithInlines source_position_with_inlines;
  28. String to_string(bool color = false) const;
  29. };
  30. Backtrace(const Reader&, const ELF::Core::ThreadInfo&);
  31. ~Backtrace();
  32. const ELF::Core::ThreadInfo thread_info() const { return m_thread_info; }
  33. const Vector<Entry> entries() const { return m_entries; }
  34. private:
  35. void add_entry(const Reader&, FlatPtr eip);
  36. ELFObjectInfo const* object_info_for_region(ELF::Core::MemoryRegionInfo const&);
  37. ELF::Core::ThreadInfo m_thread_info;
  38. Vector<Entry> m_entries;
  39. HashMap<String, NonnullOwnPtr<ELFObjectInfo>> m_debug_info_cache;
  40. };
  41. }