Backtrace.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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, NonnullOwnPtr<ELF::Image> image)
  14. : file(move(file))
  15. , debug_info(move(debug_info))
  16. , image(move(image))
  17. {
  18. }
  19. NonnullRefPtr<MappedFile> file;
  20. NonnullOwnPtr<Debug::DebugInfo> debug_info;
  21. NonnullOwnPtr<ELF::Image> image;
  22. };
  23. class Backtrace {
  24. public:
  25. struct Entry {
  26. FlatPtr eip;
  27. String object_name;
  28. String function_name;
  29. Debug::DebugInfo::SourcePositionWithInlines source_position_with_inlines;
  30. String to_string(bool color = false) const;
  31. };
  32. Backtrace(const Reader&, const ELF::Core::ThreadInfo&);
  33. ~Backtrace();
  34. const ELF::Core::ThreadInfo thread_info() const { return m_thread_info; }
  35. const Vector<Entry> entries() const { return m_entries; }
  36. private:
  37. void add_entry(const Reader&, FlatPtr ip);
  38. ELFObjectInfo const* object_info_for_region(ELF::Core::MemoryRegionInfo const&);
  39. ELF::Core::ThreadInfo m_thread_info;
  40. Vector<Entry> m_entries;
  41. HashMap<String, NonnullOwnPtr<ELFObjectInfo>> m_debug_info_cache;
  42. };
  43. }