• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  * Description: KernelSymbolsParser class define
16  */
17 #ifndef KERNEL_SYMBOLS_PARSER_H
18 #define KERNEL_SYMBOLS_PARSER_H
19 
20 #include <functional>
21 #include <string>
22 #include <vector> // for std::vector
23 #include "ftrace_namespace.h"
24 
25 FTRACE_NS_BEGIN
26 
27 struct KernelSymbol {
28     uint64_t addr = 0;
29     char type = 0;
30     std::string name;
31 };
32 
33 class KernelSymbolsParser {
34 public:
35     KernelSymbolsParser();
36     ~KernelSymbolsParser();
37 
38     bool Parse(const std::string& kallsyms);
39     void Accept(const std::function<void(const KernelSymbol&)>& visitor);
40 
41 private:
42     DISALLOW_COPY_AND_MOVE(KernelSymbolsParser);
43     static bool IsValidTextSymbol(const KernelSymbol& a);
44     static bool CompareSymbolInfo(const KernelSymbol& a, const KernelSymbol& b);
45 
46 private:
47     std::vector<KernelSymbol> kernelSymbols_;
48 };
49 FTRACE_NS_END
50 
51 #endif // KERNEL_SYMBOLS_PARSER_H
52