Branch data Line data Source code
1 : : /* Return section name.
2 : : Copyright (C) 2001, 2002, 2004 Red Hat, Inc.
3 : : This file is part of elfutils.
4 : : Written by Ulrich Drepper <drepper@redhat.com>, 2001.
5 : :
6 : : This file is free software; you can redistribute it and/or modify
7 : : it under the terms of either
8 : :
9 : : * the GNU Lesser General Public License as published by the Free
10 : : Software Foundation; either version 3 of the License, or (at
11 : : your option) any later version
12 : :
13 : : or
14 : :
15 : : * the GNU General Public License as published by the Free
16 : : Software Foundation; either version 2 of the License, or (at
17 : : your option) any later version
18 : :
19 : : or both in parallel, as here.
20 : :
21 : : elfutils is distributed in the hope that it will be useful, but
22 : : WITHOUT ANY WARRANTY; without even the implied warranty of
23 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : : General Public License for more details.
25 : :
26 : : You should have received copies of the GNU General Public License and
27 : : the GNU Lesser General Public License along with this program. If
28 : : not, see <http://www.gnu.org/licenses/>. */
29 : :
30 : : #ifdef HAVE_CONFIG_H
31 : : # include <config.h>
32 : : #endif
33 : :
34 : : #include <stdio.h>
35 : : #include <libeblP.h>
36 : :
37 : :
38 : : const char *
39 : 120326 : ebl_section_name (ebl, section, xsection, buf, len, scnnames, shnum)
40 : : Ebl *ebl;
41 : : int section;
42 : : int xsection;
43 : : char *buf;
44 : : size_t len;
45 : : const char *scnnames[];
46 : : size_t shnum;
47 : : {
48 : 240652 : const char *res = ebl != NULL ? ebl->section_name (section, xsection,
49 [ + - ]: 120326 : buf, len) : NULL;
50 : :
51 [ + - ]: 120326 : if (res == NULL)
52 : : {
53 [ + + ]: 120326 : if (section == SHN_UNDEF)
54 : : res = "UNDEF";
55 [ + + ]: 105804 : else if (section == SHN_ABS)
56 : : res = "ABS";
57 [ + - ]: 96500 : else if (section == SHN_COMMON)
58 : : res = "COMMON";
59 [ + - ]: 96500 : else if (section == SHN_BEFORE)
60 : : res = "BEFORE";
61 [ + - ]: 96500 : else if (section == SHN_AFTER)
62 : : res = "AFTER";
63 [ + - ]: 96500 : else if ((section < SHN_LORESERVE || section == SHN_XINDEX)
64 [ + - ]: 96500 : && (size_t) section < shnum)
65 : : {
66 [ - + ]: 96500 : int idx = section != SHN_XINDEX ? section : xsection;
67 : :
68 [ + + ]: 96500 : if (scnnames != NULL)
69 : 82103 : res = scnnames[idx];
70 : : else
71 : : {
72 : 14397 : snprintf (buf, len, "%d", idx);
73 : 14397 : res = buf;
74 : : }
75 : : }
76 : : else
77 : : {
78 : : /* Handle OS-specific section names. */
79 [ # # ]: 0 : if (section == SHN_XINDEX)
80 : 0 : snprintf (buf, len, "%s: %d", "XINDEX", xsection);
81 [ # # ]: 0 : else if (section >= SHN_LOOS && section <= SHN_HIOS)
82 : 0 : snprintf (buf, len, "LOOS+%x", section - SHN_LOOS);
83 : : /* Handle processor-specific section names. */
84 [ # # ]: 0 : else if (section >= SHN_LOPROC && section <= SHN_HIPROC)
85 : 0 : snprintf (buf, len, "LOPROC+%x", section - SHN_LOPROC);
86 [ # # ]: 0 : else if (section >= SHN_LORESERVE && section <= SHN_HIRESERVE)
87 : 0 : snprintf (buf, len, "LORESERVE+%x", section - SHN_LORESERVE);
88 : : else
89 : 0 : snprintf (buf, len, "%s: %d", gettext ("<unknown>"), section);
90 : :
91 : 0 : res = buf;
92 : : }
93 : : }
94 : :
95 : 120326 : return res;
96 : : }
|