chrome_unwind_info_android.cc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/profiler/chrome_unwind_info_android.h"
  5. #include "base/containers/buffer_iterator.h"
  6. namespace base {
  7. ChromeUnwindInfoAndroid::ChromeUnwindInfoAndroid(
  8. span<const uint8_t> unwind_instruction_table,
  9. span<const uint8_t> function_offset_table,
  10. span<const FunctionTableEntry> function_table,
  11. span<const uint32_t> page_table)
  12. : unwind_instruction_table(unwind_instruction_table),
  13. function_offset_table(function_offset_table),
  14. function_table(function_table),
  15. page_table(page_table) {}
  16. ChromeUnwindInfoAndroid::~ChromeUnwindInfoAndroid() = default;
  17. ChromeUnwindInfoAndroid::ChromeUnwindInfoAndroid(
  18. const ChromeUnwindInfoAndroid& other) = default;
  19. ChromeUnwindInfoAndroid& ChromeUnwindInfoAndroid::operator=(
  20. const ChromeUnwindInfoAndroid& other) = default;
  21. ChromeUnwindInfoAndroid::ChromeUnwindInfoAndroid(
  22. ChromeUnwindInfoAndroid&& other) = default;
  23. ChromeUnwindInfoAndroid& ChromeUnwindInfoAndroid::operator=(
  24. ChromeUnwindInfoAndroid&& other) = default;
  25. ChromeUnwindInfoAndroid CreateChromeUnwindInfoAndroid(
  26. span<const uint8_t> data) {
  27. BufferIterator<const uint8_t> data_iterator(data);
  28. const auto* header = data_iterator.Object<ChromeUnwindInfoHeaderAndroid>();
  29. DCHECK(header);
  30. data_iterator.Seek(header->page_table_byte_offset);
  31. const auto page_table =
  32. data_iterator.Span<uint32_t>(header->page_table_entries);
  33. DCHECK(!page_table.empty());
  34. data_iterator.Seek(header->function_offset_table_byte_offset);
  35. const auto function_offset_table =
  36. data_iterator.Span<uint8_t>(header->function_offset_table_size_in_bytes);
  37. DCHECK(!function_offset_table.empty());
  38. data_iterator.Seek(header->function_table_byte_offset);
  39. const auto function_table =
  40. data_iterator.Span<FunctionTableEntry>(header->function_table_entries);
  41. DCHECK(!function_table.empty());
  42. data_iterator.Seek(header->unwind_instruction_table_byte_offset);
  43. const auto unwind_instruction_table = data_iterator.Span<uint8_t>(
  44. header->unwind_instruction_table_size_in_bytes);
  45. DCHECK(!unwind_instruction_table.empty());
  46. return ChromeUnwindInfoAndroid{unwind_instruction_table,
  47. function_offset_table, function_table,
  48. page_table};
  49. }
  50. } // namespace base