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