Coverage Report

Created: 2024-11-22 16:10

/root/doris/be/src/util/bfd_parser.h
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#ifndef PACKAGE
21
#define PACKAGE
22
#endif
23
24
#ifndef PACKAGE_VERSION
25
#define PACKAGE_VERSION
26
#endif
27
28
#include <bfd.h>
29
30
#include <mutex>
31
#include <string>
32
#include <vector>
33
34
namespace doris {
35
36
class BfdParser {
37
public:
38
    // Create parser for running process
39
    static BfdParser* create();
40
    static BfdParser* create(const std::string& file_name);
41
42
    BfdParser(const std::string& file_name);
43
    ~BfdParser();
44
    int parse();
45
46
    // Decode address to function_name file_name and line number
47
    // Call parse before call this function
48
    // Return 0 if found and fill file_name, function_name, lineno
49
    //  -1 otherwise
50
    int decode_address(const char* str, const char** end, std::string* file_name,
51
                       std::string* function_name, unsigned int* lineno);
52
53
0
    long num_symbols() const { return _num_symbols; }
54
55
    static void list_targets(std::vector<std::string>* targets);
56
    void list_sections(std::string* ss);
57
58
private:
59
    static void init_bfd();
60
61
    int open_bfd();
62
    int load_symbols();
63
64
    static std::mutex _bfd_mutex;
65
    static bool _is_bfd_inited;
66
67
    std::string _file_name;
68
    std::mutex _mutex;
69
    bfd* _abfd = nullptr;
70
    bfd_symbol** _syms = nullptr;
71
    long _num_symbols;
72
    unsigned int _symbol_size;
73
};
74
75
} // namespace doris