Backtrace.h 1.6 KB

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