xref: /aosp_15_r20/external/stg/dwarf_processor.h (revision 9e3b08ae94a55201065475453d799e8b1378bea6)
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- mode: C++ -*-
3 //
4 // Copyright 2022 Google LLC
5 //
6 // Licensed under the Apache License v2.0 with LLVM Exceptions (the
7 // "License"); you may not use this file except in compliance with the
8 // License.  You may obtain a copy of the License at
9 //
10 //     https://llvm.org/LICENSE.txt
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 // Author: Aleksei Vetrov
19 
20 #ifndef STG_DWARF_PROCESSOR_H_
21 #define STG_DWARF_PROCESSOR_H_
22 
23 #include <elfutils/libdw.h>
24 
25 #include <cstddef>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 #include "dwarf_wrappers.h"
31 #include "filter.h"
32 #include "graph.h"
33 
34 namespace stg {
35 namespace dwarf {
36 
37 struct Types {
38   struct Symbol {
39     std::string scoped_name;
40     std::string linkage_name;
41     Address address;
42     Id type_id;
43   };
44 
45   size_t processed_entries = 0;
46   // Container for all named type IDs allocated during DWARF processing.
47   std::vector<Id> named_type_ids;
48   std::vector<Symbol> symbols;
49 };
50 
51 // Process every compilation unit from DWARF and returns processed STG along
52 // with information needed for matching to ELF symbols.
53 // If DWARF is missing, returns empty result.
54 Types Process(Dwarf* dwarf, bool is_little_endian_binary,
55               const std::unique_ptr<Filter>& file_filter, Graph& graph);
56 
57 }  // namespace dwarf
58 }  // namespace stg
59 
60 #endif  // STG_DWARF_PROCESSOR_H_
61