File: elf.cc

package info (click to toggle)
libelfin 0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 668 kB
  • sloc: cpp: 4,883; makefile: 189; python: 139; sh: 129; ansic: 10
file content (54 lines) | stat: -rw-r--r-- 1,479 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2013 Austin T. Clements. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.

#include "dwarf++.hh"

#include <cstring>

using namespace std;

DWARFPP_BEGIN_NAMESPACE

static const struct
{
        const char *name;
        section_type type;
} sections[] = {
        {".debug_abbrev",   section_type::abbrev},
        {".debug_aranges",  section_type::aranges},
        {".debug_frame",    section_type::frame},
        {".debug_info",     section_type::info},
        {".debug_line",     section_type::line},
        {".debug_loc",      section_type::loc},
        {".debug_macinfo",  section_type::macinfo},
        {".debug_pubnames", section_type::pubnames},
        {".debug_pubtypes", section_type::pubtypes},
        {".debug_ranges",   section_type::ranges},
        {".debug_str",      section_type::str},
        {".debug_types",    section_type::types},
};

bool
elf::section_name_to_type(const char *name, section_type *out)
{
        for (auto &sec : sections) {
                if (strcmp(sec.name, name) == 0) {
                        *out = sec.type;
                        return true;
                }
        }
        return false;
}

const char *
elf::section_type_to_name(section_type type)
{
        for (auto &sec : sections) {
                if (sec.type == type)
                        return sec.name;
        }
        return nullptr;
}

DWARFPP_END_NAMESPACE