rdwarf 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +28 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/ext/rdwarf/depend +5 -0
- data/ext/rdwarf/extconf.rb +29 -0
- data/ext/rdwarf/libdwarf/CHANGES +102 -0
- data/ext/rdwarf/libdwarf/CODINGSTYLE +71 -0
- data/ext/rdwarf/libdwarf/COPYING +28 -0
- data/ext/rdwarf/libdwarf/ChangeLog +619 -0
- data/ext/rdwarf/libdwarf/ChangeLog2006 +835 -0
- data/ext/rdwarf/libdwarf/ChangeLog2007 +217 -0
- data/ext/rdwarf/libdwarf/ChangeLog2008 +263 -0
- data/ext/rdwarf/libdwarf/ChangeLog2009 +348 -0
- data/ext/rdwarf/libdwarf/ChangeLog2010 +175 -0
- data/ext/rdwarf/libdwarf/ChangeLog2011 +297 -0
- data/ext/rdwarf/libdwarf/ChangeLog2012 +131 -0
- data/ext/rdwarf/libdwarf/ChangeLog2013 +238 -0
- data/ext/rdwarf/libdwarf/ChangeLog2014 +399 -0
- data/ext/rdwarf/libdwarf/LGPL.txt +504 -0
- data/ext/rdwarf/libdwarf/LIBDWARFCOPYRIGHT +40 -0
- data/ext/rdwarf/libdwarf/Makefile.in +220 -0
- data/ext/rdwarf/libdwarf/NEWS +535 -0
- data/ext/rdwarf/libdwarf/README +235 -0
- data/ext/rdwarf/libdwarf/checkexamples.c +1179 -0
- data/ext/rdwarf/libdwarf/cmplrs/dwarf_addr_finder.h +55 -0
- data/ext/rdwarf/libdwarf/common.c +62 -0
- data/ext/rdwarf/libdwarf/common.h +38 -0
- data/ext/rdwarf/libdwarf/config.h.in +146 -0
- data/ext/rdwarf/libdwarf/configure +5581 -0
- data/ext/rdwarf/libdwarf/configure.in +167 -0
- data/ext/rdwarf/libdwarf/dw-linetableheader.txt +39 -0
- data/ext/rdwarf/libdwarf/dwarf.h +1342 -0
- data/ext/rdwarf/libdwarf/dwarf_abbrev.c +291 -0
- data/ext/rdwarf/libdwarf/dwarf_abbrev.h +45 -0
- data/ext/rdwarf/libdwarf/dwarf_addr_finder.c +676 -0
- data/ext/rdwarf/libdwarf/dwarf_alloc.c +685 -0
- data/ext/rdwarf/libdwarf/dwarf_alloc.h +38 -0
- data/ext/rdwarf/libdwarf/dwarf_arange.c +595 -0
- data/ext/rdwarf/libdwarf/dwarf_arange.h +62 -0
- data/ext/rdwarf/libdwarf/dwarf_base_types.h +157 -0
- data/ext/rdwarf/libdwarf/dwarf_die_deliv.c +1802 -0
- data/ext/rdwarf/libdwarf/dwarf_die_deliv.h +46 -0
- data/ext/rdwarf/libdwarf/dwarf_elf_access.c +1348 -0
- data/ext/rdwarf/libdwarf/dwarf_elf_access.h +46 -0
- data/ext/rdwarf/libdwarf/dwarf_error.c +492 -0
- data/ext/rdwarf/libdwarf/dwarf_error.h +53 -0
- data/ext/rdwarf/libdwarf/dwarf_form.c +1302 -0
- data/ext/rdwarf/libdwarf/dwarf_frame.c +2454 -0
- data/ext/rdwarf/libdwarf/dwarf_frame.h +418 -0
- data/ext/rdwarf/libdwarf/dwarf_frame2.c +1533 -0
- data/ext/rdwarf/libdwarf/dwarf_frame3.c +282 -0
- data/ext/rdwarf/libdwarf/dwarf_funcs.c +123 -0
- data/ext/rdwarf/libdwarf/dwarf_funcs.h +33 -0
- data/ext/rdwarf/libdwarf/dwarf_gdbindex.c +520 -0
- data/ext/rdwarf/libdwarf/dwarf_gdbindex.h +97 -0
- data/ext/rdwarf/libdwarf/dwarf_global.c +612 -0
- data/ext/rdwarf/libdwarf/dwarf_global.h +117 -0
- data/ext/rdwarf/libdwarf/dwarf_harmless.c +228 -0
- data/ext/rdwarf/libdwarf/dwarf_harmless.h +31 -0
- data/ext/rdwarf/libdwarf/dwarf_incl.h +61 -0
- data/ext/rdwarf/libdwarf/dwarf_init_finish.c +1263 -0
- data/ext/rdwarf/libdwarf/dwarf_leb.c +159 -0
- data/ext/rdwarf/libdwarf/dwarf_line.c +1822 -0
- data/ext/rdwarf/libdwarf/dwarf_line.h +446 -0
- data/ext/rdwarf/libdwarf/dwarf_line2.c +98 -0
- data/ext/rdwarf/libdwarf/dwarf_line_table_reader_common.c +1583 -0
- data/ext/rdwarf/libdwarf/dwarf_loc.c +1525 -0
- data/ext/rdwarf/libdwarf/dwarf_loc.h +149 -0
- data/ext/rdwarf/libdwarf/dwarf_loc2.c +833 -0
- data/ext/rdwarf/libdwarf/dwarf_macro.c +479 -0
- data/ext/rdwarf/libdwarf/dwarf_macro.h +35 -0
- data/ext/rdwarf/libdwarf/dwarf_opaque.h +778 -0
- data/ext/rdwarf/libdwarf/dwarf_original_elf_init.c +219 -0
- data/ext/rdwarf/libdwarf/dwarf_print_lines.c +631 -0
- data/ext/rdwarf/libdwarf/dwarf_pubtypes.c +132 -0
- data/ext/rdwarf/libdwarf/dwarf_query.c +1594 -0
- data/ext/rdwarf/libdwarf/dwarf_ranges.c +194 -0
- data/ext/rdwarf/libdwarf/dwarf_reloc_arm.h +308 -0
- data/ext/rdwarf/libdwarf/dwarf_reloc_mips.h +117 -0
- data/ext/rdwarf/libdwarf/dwarf_reloc_ppc.h +242 -0
- data/ext/rdwarf/libdwarf/dwarf_reloc_ppc64.h +272 -0
- data/ext/rdwarf/libdwarf/dwarf_reloc_x86_64.h +127 -0
- data/ext/rdwarf/libdwarf/dwarf_sort_line.c +665 -0
- data/ext/rdwarf/libdwarf/dwarf_string.c +82 -0
- data/ext/rdwarf/libdwarf/dwarf_stubs.c +38 -0
- data/ext/rdwarf/libdwarf/dwarf_tied.c +423 -0
- data/ext/rdwarf/libdwarf/dwarf_tsearch.h +125 -0
- data/ext/rdwarf/libdwarf/dwarf_tsearchhash.c +675 -0
- data/ext/rdwarf/libdwarf/dwarf_types.c +121 -0
- data/ext/rdwarf/libdwarf/dwarf_types.h +32 -0
- data/ext/rdwarf/libdwarf/dwarf_util.c +913 -0
- data/ext/rdwarf/libdwarf/dwarf_util.h +324 -0
- data/ext/rdwarf/libdwarf/dwarf_vars.c +125 -0
- data/ext/rdwarf/libdwarf/dwarf_vars.h +29 -0
- data/ext/rdwarf/libdwarf/dwarf_weaks.c +123 -0
- data/ext/rdwarf/libdwarf/dwarf_weaks.h +29 -0
- data/ext/rdwarf/libdwarf/dwarf_xu_index.c +579 -0
- data/ext/rdwarf/libdwarf/dwarf_xu_index.h +68 -0
- data/ext/rdwarf/libdwarf/dwgetopt.c +181 -0
- data/ext/rdwarf/libdwarf/dwgetopt.h +51 -0
- data/ext/rdwarf/libdwarf/gennames.c +531 -0
- data/ext/rdwarf/libdwarf/install.sh +119 -0
- data/ext/rdwarf/libdwarf/libdwarf.h.in +3746 -0
- data/ext/rdwarf/libdwarf/libdwarf2.1.mm +9805 -0
- data/ext/rdwarf/libdwarf/libdwarf2.1.pdf +0 -0
- data/ext/rdwarf/libdwarf/libdwarf2p.1.mm +2807 -0
- data/ext/rdwarf/libdwarf/libdwarf2p.1.pdf +0 -0
- data/ext/rdwarf/libdwarf/libdwarfdefs.h +81 -0
- data/ext/rdwarf/libdwarf/malloc_check.c +327 -0
- data/ext/rdwarf/libdwarf/malloc_check.h +52 -0
- data/ext/rdwarf/libdwarf/mips_extensions.mm +1266 -0
- data/ext/rdwarf/libdwarf/mips_extensions.pdf +0 -0
- data/ext/rdwarf/libdwarf/pro_alloc.c +179 -0
- data/ext/rdwarf/libdwarf/pro_alloc.h +33 -0
- data/ext/rdwarf/libdwarf/pro_arange.c +310 -0
- data/ext/rdwarf/libdwarf/pro_arange.h +51 -0
- data/ext/rdwarf/libdwarf/pro_die.c +431 -0
- data/ext/rdwarf/libdwarf/pro_die.h +59 -0
- data/ext/rdwarf/libdwarf/pro_encode_nm.c +108 -0
- data/ext/rdwarf/libdwarf/pro_encode_nm.h +39 -0
- data/ext/rdwarf/libdwarf/pro_error.c +96 -0
- data/ext/rdwarf/libdwarf/pro_error.h +43 -0
- data/ext/rdwarf/libdwarf/pro_expr.c +575 -0
- data/ext/rdwarf/libdwarf/pro_expr.h +36 -0
- data/ext/rdwarf/libdwarf/pro_finish.c +45 -0
- data/ext/rdwarf/libdwarf/pro_forms.c +1271 -0
- data/ext/rdwarf/libdwarf/pro_frame.c +572 -0
- data/ext/rdwarf/libdwarf/pro_frame.h +120 -0
- data/ext/rdwarf/libdwarf/pro_funcs.c +50 -0
- data/ext/rdwarf/libdwarf/pro_incl.h +91 -0
- data/ext/rdwarf/libdwarf/pro_init.c +327 -0
- data/ext/rdwarf/libdwarf/pro_line.c +373 -0
- data/ext/rdwarf/libdwarf/pro_line.h +112 -0
- data/ext/rdwarf/libdwarf/pro_macinfo.c +457 -0
- data/ext/rdwarf/libdwarf/pro_macinfo.h +31 -0
- data/ext/rdwarf/libdwarf/pro_opaque.h +513 -0
- data/ext/rdwarf/libdwarf/pro_pubnames.c +60 -0
- data/ext/rdwarf/libdwarf/pro_reloc.c +253 -0
- data/ext/rdwarf/libdwarf/pro_reloc.h +38 -0
- data/ext/rdwarf/libdwarf/pro_reloc_stream.c +256 -0
- data/ext/rdwarf/libdwarf/pro_reloc_stream.h +52 -0
- data/ext/rdwarf/libdwarf/pro_reloc_symbolic.c +245 -0
- data/ext/rdwarf/libdwarf/pro_reloc_symbolic.h +45 -0
- data/ext/rdwarf/libdwarf/pro_section.c +2233 -0
- data/ext/rdwarf/libdwarf/pro_section.h +100 -0
- data/ext/rdwarf/libdwarf/pro_types.c +274 -0
- data/ext/rdwarf/libdwarf/pro_types.h +34 -0
- data/ext/rdwarf/libdwarf/pro_util.h +38 -0
- data/ext/rdwarf/libdwarf/pro_vars.c +52 -0
- data/ext/rdwarf/libdwarf/pro_weaks.c +51 -0
- data/ext/rdwarf/rdwarf.c +765 -0
- data/ext/rdwarf/rdwarf.h +52 -0
- data/ext/rdwarf/rdwarf_names_gen.rb +109 -0
- data/lib/rdwarf.rb +181 -0
- data/lib/rdwarf/version.rb +3 -0
- data/rdwarf.gemspec +30 -0
- metadata +251 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#ifndef DWARF_XU_INDEX_H
|
|
2
|
+
#define DWARF_XU_INDEX_H
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2014-2014 David Anderson. All Rights Reserved.
|
|
6
|
+
|
|
7
|
+
This program is free software; you can redistribute it and/or modify it
|
|
8
|
+
under the terms of version 2.1 of the GNU Lesser General Public License
|
|
9
|
+
as published by the Free Software Foundation.
|
|
10
|
+
|
|
11
|
+
This program is distributed in the hope that it would be useful, but
|
|
12
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
14
|
+
|
|
15
|
+
Further, this software is distributed without any warranty that it is
|
|
16
|
+
free of the rightful claim of any third person regarding infringement
|
|
17
|
+
or the like. Any license provided herein, whether implied or
|
|
18
|
+
otherwise, applies only to this software file. Patent licenses, if
|
|
19
|
+
any, provided herein do not apply to combinations of this program with
|
|
20
|
+
other software, or any other product whatsoever.
|
|
21
|
+
|
|
22
|
+
You should have received a copy of the GNU Lesser General Public
|
|
23
|
+
License along with this program; if not, write the Free Software
|
|
24
|
+
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
|
|
25
|
+
USA.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/* The following is based on
|
|
33
|
+
The gdb online documentation at
|
|
34
|
+
https://gcc.gnu.org/wiki/DebugFissionDWP
|
|
35
|
+
and the draft DWARF5 standard.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
struct Dwarf_Xu_Index_Header_s {
|
|
40
|
+
Dwarf_Debug gx_dbg;
|
|
41
|
+
Dwarf_Small * gx_section_data;
|
|
42
|
+
Dwarf_Unsigned gx_section_length;
|
|
43
|
+
|
|
44
|
+
Dwarf_Unsigned gx_version;
|
|
45
|
+
Dwarf_Unsigned gx_column_count_sections; /* L */
|
|
46
|
+
Dwarf_Unsigned gx_units_in_index; /* N */
|
|
47
|
+
Dwarf_Unsigned gx_slots_in_hash; /* M */
|
|
48
|
+
Dwarf_Unsigned gx_hash_table_offset;
|
|
49
|
+
Dwarf_Unsigned gx_index_table_offset;
|
|
50
|
+
Dwarf_Unsigned gx_section_offsets_offset;
|
|
51
|
+
Dwarf_Unsigned gx_section_sizes_offset;
|
|
52
|
+
|
|
53
|
+
/* "tu" or "cu" without the quotes, of course. NUL terminated. */
|
|
54
|
+
char gx_type[4];
|
|
55
|
+
|
|
56
|
+
/* Do not free gx_section_name. */
|
|
57
|
+
const char * gx_section_name;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
#endif /* DWARF_XU_INDEX_H */
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/* $NetBSD: getopt.c,v 1.1 2009/03/22 22:33:13 joerg Exp $*/
|
|
2
|
+
/* Modified by David Anderson to work with GNU/Linux and freebsd.
|
|
3
|
+
Added {} for clarity.
|
|
4
|
+
Switched to standard dwarfdump formatting.
|
|
5
|
+
Treatment of : modified so that :: gets dwoptarg NULL
|
|
6
|
+
if space follows the letter
|
|
7
|
+
(the dwoptarg is set to null).
|
|
8
|
+
renamed to make it clear this is a private version.
|
|
9
|
+
*/
|
|
10
|
+
/*
|
|
11
|
+
* Copyright (c) 1987, 1993, 1994
|
|
12
|
+
* The Regents of the University of California. All rights reserved.
|
|
13
|
+
*
|
|
14
|
+
* Redistribution and use in source and binary forms, with or without
|
|
15
|
+
* modification, are permitted provided that the following conditions
|
|
16
|
+
* are met:
|
|
17
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
18
|
+
* notice, this list of conditions and the following disclaimer.
|
|
19
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
20
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
21
|
+
* documentation and/or other materials provided with the distribution.
|
|
22
|
+
* 3. Neither the name of the University nor the names of its contributors
|
|
23
|
+
* may be used to endorse or promote products derived from this software
|
|
24
|
+
* without specific prior written permission.
|
|
25
|
+
*
|
|
26
|
+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
27
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
28
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
29
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
30
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
31
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
32
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
33
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
34
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
35
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
36
|
+
* SUCH DAMAGE.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/* This does not presently handle the option string
|
|
40
|
+
leading + or leading - features. Such are not used
|
|
41
|
+
by by libdwarfdump. Nor does it understand the
|
|
42
|
+
GNU Env var POSIXLY_CORRECT .
|
|
43
|
+
It does know of the leading ":" in the option string.
|
|
44
|
+
See BADCH below.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
#include <stdio.h>
|
|
48
|
+
#include <stdlib.h> /* For exit() */
|
|
49
|
+
#include <string.h> /* For strchr */
|
|
50
|
+
|
|
51
|
+
#define STRIP_OFF_CONSTNESS(a) ((void *)(size_t)(const void *)(a))
|
|
52
|
+
|
|
53
|
+
int dwopterr = 1, /* if error message should be printed */
|
|
54
|
+
dwoptind = 1, /* index into parent argv vector */
|
|
55
|
+
dwoptopt, /* character checked for validity */
|
|
56
|
+
dwoptreset; /* reset getopt */
|
|
57
|
+
char *dwoptarg; /* argument associated with option */
|
|
58
|
+
|
|
59
|
+
#define BADCH (int)'?'
|
|
60
|
+
#define BADARG (int)':'
|
|
61
|
+
#define EMSG ""
|
|
62
|
+
|
|
63
|
+
/* Use for testing dwgetopt only.
|
|
64
|
+
Not a standard function. */
|
|
65
|
+
void
|
|
66
|
+
dwgetoptresetfortestingonly()
|
|
67
|
+
{
|
|
68
|
+
dwopterr = 1;
|
|
69
|
+
dwoptind = 1;
|
|
70
|
+
dwoptopt = 0;
|
|
71
|
+
dwoptreset = 0;
|
|
72
|
+
dwoptarg = 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/*
|
|
76
|
+
* getopt --
|
|
77
|
+
* Parse argc/argv argument vector.
|
|
78
|
+
* a: means
|
|
79
|
+
* -afoo
|
|
80
|
+
* -a foo
|
|
81
|
+
* and 'foo' is returned in dwoptarg
|
|
82
|
+
* b:: means
|
|
83
|
+
* -b
|
|
84
|
+
* and dwoptarg is null
|
|
85
|
+
* -bother
|
|
86
|
+
* and dwoptarg is 'other'
|
|
87
|
+
*/
|
|
88
|
+
int
|
|
89
|
+
dwgetopt(int nargc, char * const nargv[], const char *ostr)
|
|
90
|
+
{
|
|
91
|
+
static const char *place = EMSG;/* option letter processing */
|
|
92
|
+
char *oli; /* option letter list index */
|
|
93
|
+
|
|
94
|
+
if (dwoptreset || *place == 0) { /* update scanning pointer */
|
|
95
|
+
dwoptreset = 0;
|
|
96
|
+
place = nargv[dwoptind];
|
|
97
|
+
if (dwoptind >= nargc || *place++ != '-') {
|
|
98
|
+
/* Argument is absent or is not an option */
|
|
99
|
+
place = EMSG;
|
|
100
|
+
return (-1);
|
|
101
|
+
}
|
|
102
|
+
dwoptopt = *place++;
|
|
103
|
+
if (dwoptopt == '-' && *place == 0) {
|
|
104
|
+
/* "--" => end of options */
|
|
105
|
+
++dwoptind;
|
|
106
|
+
place = EMSG;
|
|
107
|
+
return (-1);
|
|
108
|
+
}
|
|
109
|
+
if (dwoptopt == 0) {
|
|
110
|
+
/* Solitary '-', treat as a '-' option
|
|
111
|
+
if the program (eg su) is looking for it. */
|
|
112
|
+
place = EMSG;
|
|
113
|
+
if (strchr(ostr, '-') == NULL) {
|
|
114
|
+
return -1;
|
|
115
|
+
}
|
|
116
|
+
dwoptopt = '-';
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
dwoptopt = *place++;
|
|
120
|
+
}
|
|
121
|
+
/* See if option letter is one the caller wanted... */
|
|
122
|
+
if (dwoptopt == ':' || (oli = strchr(ostr, dwoptopt)) == NULL) {
|
|
123
|
+
if (*place == 0) {
|
|
124
|
+
++dwoptind;
|
|
125
|
+
}
|
|
126
|
+
if (dwopterr && *ostr != ':') {
|
|
127
|
+
(void)fprintf(stderr,
|
|
128
|
+
"%s: invalid option -- '%c'\n",
|
|
129
|
+
nargv[0]?nargv[0]:"",
|
|
130
|
+
dwoptopt);
|
|
131
|
+
}
|
|
132
|
+
return (BADCH);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* Does this option need an argument? */
|
|
136
|
+
if (oli[1] != ':') {
|
|
137
|
+
/* don't need argument */
|
|
138
|
+
dwoptarg = NULL;
|
|
139
|
+
if (*place == 0) {
|
|
140
|
+
++dwoptind;
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
int reqnextarg = 1;
|
|
144
|
+
if (oli[1] && (oli[2] == ':')) {
|
|
145
|
+
/* Pair of :: means special treatment of dwoptarg */
|
|
146
|
+
reqnextarg = 0;
|
|
147
|
+
}
|
|
148
|
+
/* Option-argument is either the rest of this argument or the
|
|
149
|
+
entire next argument. */
|
|
150
|
+
if (*place ) {
|
|
151
|
+
/* Whether : or :: */
|
|
152
|
+
dwoptarg = STRIP_OFF_CONSTNESS(place);
|
|
153
|
+
} else if (reqnextarg) {
|
|
154
|
+
/* ! *place */
|
|
155
|
+
if (nargc > (++dwoptind)) {
|
|
156
|
+
dwoptarg = nargv[dwoptind];
|
|
157
|
+
} else {
|
|
158
|
+
place=EMSG;
|
|
159
|
+
/* Next arg required, but is missing */
|
|
160
|
+
if (*ostr == ':') {
|
|
161
|
+
/* Leading : in ostr calls for BADARG return. */
|
|
162
|
+
return (BADARG);
|
|
163
|
+
}
|
|
164
|
+
if (dwopterr) {
|
|
165
|
+
(void)fprintf(stderr,
|
|
166
|
+
"%s: option requires an argument. -- '%c'\n",
|
|
167
|
+
nargv[0]?nargv[0]:"",
|
|
168
|
+
dwoptopt);
|
|
169
|
+
}
|
|
170
|
+
return (BADCH);
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
/* ! *place */
|
|
174
|
+
/* The key part of :: treatment. */
|
|
175
|
+
dwoptarg = NULL;
|
|
176
|
+
}
|
|
177
|
+
place = EMSG;
|
|
178
|
+
++dwoptind;
|
|
179
|
+
}
|
|
180
|
+
return (dwoptopt); /* return option letter */
|
|
181
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* $NetBSD: getopt.c,v 1.1 2009/03/22 22:33:13 joerg Exp $*/
|
|
2
|
+
/* Modified by David Anderson to work with GNU/Linux and freebsd.
|
|
3
|
+
Added {} for clarity.
|
|
4
|
+
Switched to standard dwarfdump formatting.
|
|
5
|
+
Treatment of : modified so that :: gets dwoptarg NULL
|
|
6
|
+
if space follows the letter
|
|
7
|
+
(the dwoptarg is set to null).
|
|
8
|
+
*/
|
|
9
|
+
/*
|
|
10
|
+
* Copyright (c) 1987, 1993, 1994
|
|
11
|
+
* The Regents of the University of California. All rights reserved.
|
|
12
|
+
*
|
|
13
|
+
* Redistribution and use in source and binary forms, with or without
|
|
14
|
+
* modification, are permitted provided that the following conditions
|
|
15
|
+
* are met:
|
|
16
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
17
|
+
* notice, this list of conditions and the following disclaimer.
|
|
18
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
19
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
20
|
+
* documentation and/or other materials provided with the distribution.
|
|
21
|
+
* 3. Neither the name of the University nor the names of its contributors
|
|
22
|
+
* may be used to endorse or promote products derived from this software
|
|
23
|
+
* without specific prior written permission.
|
|
24
|
+
*
|
|
25
|
+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
26
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
27
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
28
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
29
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
30
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
31
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
32
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
33
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
34
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
35
|
+
* SUCH DAMAGE.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
#ifdef __cplusplus
|
|
39
|
+
extern "C" {
|
|
40
|
+
#endif /* __cplusplus */
|
|
41
|
+
extern int dwopterr;
|
|
42
|
+
extern int dwoptind;
|
|
43
|
+
extern int dwoptopt;
|
|
44
|
+
extern int dwoptreset;
|
|
45
|
+
extern char *dwoptarg;
|
|
46
|
+
|
|
47
|
+
int dwgetopt(int nargc, char * const nargv[], const char *ostr);
|
|
48
|
+
|
|
49
|
+
#ifdef __cplusplus
|
|
50
|
+
}
|
|
51
|
+
#endif /* __cplusplus */
|
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2009-2010 SN Systems Ltd. All rights reserved.
|
|
3
|
+
Portions Copyright 2009-2011 David Anderson. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This program is free software; you can redistribute it and/or modify it
|
|
6
|
+
under the terms of version 2.1 of the GNU Lesser General Public License
|
|
7
|
+
as published by the Free Software Foundation.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it would be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
|
|
13
|
+
Further, this software is distributed without any warranty that it is
|
|
14
|
+
free of the rightful claim of any third person regarding infringement
|
|
15
|
+
or the like. Any license provided herein, whether implied or
|
|
16
|
+
otherwise, applies only to this software file. Patent licenses, if
|
|
17
|
+
any, provided herein do not apply to combinations of this program with
|
|
18
|
+
other software, or any other product whatsoever.
|
|
19
|
+
|
|
20
|
+
You should have received a copy of the GNU Lesser General Public
|
|
21
|
+
License along with this program; if not, write the Free Software
|
|
22
|
+
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
|
|
23
|
+
USA.
|
|
24
|
+
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
#include <stdio.h>
|
|
28
|
+
#include <stdlib.h> /* For exit() declaration etc. */
|
|
29
|
+
#include <errno.h> /* For errno declaration. */
|
|
30
|
+
#include <ctype.h>
|
|
31
|
+
#include <string.h>
|
|
32
|
+
#include <unistd.h>
|
|
33
|
+
#include "dwarf.h"
|
|
34
|
+
#include "common.h"
|
|
35
|
+
#include "dwgetopt.h"
|
|
36
|
+
|
|
37
|
+
/* gennames.c
|
|
38
|
+
Prints routines to return constant name for the associated value
|
|
39
|
+
(such as the TAG name string for a particular tag).
|
|
40
|
+
|
|
41
|
+
The input is dwarf.h
|
|
42
|
+
For each set of names with a common prefix, we create a routine
|
|
43
|
+
to return the name given the value.
|
|
44
|
+
Also print header file that gives prototypes of routines.
|
|
45
|
+
To handle cases where there are multiple names for a single
|
|
46
|
+
value (DW_AT_* has some due to ambiguities in the DWARF2 spec)
|
|
47
|
+
we take the first of a given value as the definitive name.
|
|
48
|
+
TAGs, Attributes, etc are given distinct checks.
|
|
49
|
+
|
|
50
|
+
There are multiple output files as some people find one
|
|
51
|
+
form more pleasant than the other.
|
|
52
|
+
|
|
53
|
+
The doprinting argument is so that when used by tag_tree.c,
|
|
54
|
+
and tag_attr.c that we don't get irritating messages on stderr
|
|
55
|
+
when those dwarfdump built-time applications are run.
|
|
56
|
+
|
|
57
|
+
Some compilers generate better code for switch statements than
|
|
58
|
+
others, so the -s and -t options let the user decide which
|
|
59
|
+
is better for their compiler (when building dwarfdump):
|
|
60
|
+
a simple switch or code doing binary search.
|
|
61
|
+
This choice affects the runtime speed of dwarfdump. */
|
|
62
|
+
|
|
63
|
+
typedef int boolean;
|
|
64
|
+
#define TRUE 1
|
|
65
|
+
#define FALSE 0
|
|
66
|
+
#define FAILED 1
|
|
67
|
+
|
|
68
|
+
static void OpenAllFiles(void);
|
|
69
|
+
static void WriteFileTrailers(void);
|
|
70
|
+
static void CloseAllFiles(void);
|
|
71
|
+
static void GenerateInitialFileLines(void);
|
|
72
|
+
static void GenerateOneSet(void);
|
|
73
|
+
#ifdef TRACE_ARRAY
|
|
74
|
+
static void PrintArray(void);
|
|
75
|
+
#endif /* TRACE_ARRAY */
|
|
76
|
+
static boolean is_skippable_line(char *pLine);
|
|
77
|
+
static void ParseDefinitionsAndWriteOutput(void);
|
|
78
|
+
|
|
79
|
+
/* We don't need really long lines: the input file is simple. */
|
|
80
|
+
#define MAX_LINE_SIZE 1000
|
|
81
|
+
/* We don't need a variable array size, it just has to be big enough. */
|
|
82
|
+
#define ARRAY_SIZE 300
|
|
83
|
+
|
|
84
|
+
/* To store entries from dwarf.h */
|
|
85
|
+
typedef struct {
|
|
86
|
+
char name[64]; /* short name */
|
|
87
|
+
unsigned value; /* value */
|
|
88
|
+
} array_data;
|
|
89
|
+
|
|
90
|
+
/* A group_array is a grouping from dwarf.h.
|
|
91
|
+
All the TAGs are one group, all the
|
|
92
|
+
FORMs are another group, and so on. */
|
|
93
|
+
static array_data group_array[ARRAY_SIZE];
|
|
94
|
+
static unsigned array_count = 0;
|
|
95
|
+
|
|
96
|
+
typedef int (*compfn)(const void *,const void *);
|
|
97
|
+
static int Compare(array_data *,array_data *);
|
|
98
|
+
|
|
99
|
+
static const char *prefix_root = "DW_";
|
|
100
|
+
static const unsigned prefix_root_len = 3;
|
|
101
|
+
|
|
102
|
+
/* f_dwarf_in is the input dwarf.h. The others are output files. */
|
|
103
|
+
static FILE *f_dwarf_in;
|
|
104
|
+
static FILE *f_names_h;
|
|
105
|
+
static FILE *f_names_c;
|
|
106
|
+
static FILE *f_names_enum_h;
|
|
107
|
+
static FILE *f_names_new_h;
|
|
108
|
+
|
|
109
|
+
/* Size unchecked, but large enough. */
|
|
110
|
+
static char prefix[200] = "";
|
|
111
|
+
|
|
112
|
+
static const char *usage[] = {
|
|
113
|
+
"Usage: gennames <options>",
|
|
114
|
+
" -i input-table-path",
|
|
115
|
+
" -o output-table-path",
|
|
116
|
+
" -s use 'switch' in generation",
|
|
117
|
+
" -t use 'tables' in generation",
|
|
118
|
+
"",
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
char *program_name = 0;
|
|
122
|
+
static char *input_name = 0;
|
|
123
|
+
static char *output_name = 0;
|
|
124
|
+
static boolean use_switch = TRUE;
|
|
125
|
+
static boolean use_tables = FALSE;
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
/* process arguments */
|
|
129
|
+
static void
|
|
130
|
+
process_args(int argc, char *argv[])
|
|
131
|
+
{
|
|
132
|
+
int c = 0;
|
|
133
|
+
boolean usage_error = FALSE;
|
|
134
|
+
|
|
135
|
+
program_name = argv[0];
|
|
136
|
+
|
|
137
|
+
while ((c = dwgetopt(argc, argv, "i:o:st")) != EOF) {
|
|
138
|
+
switch (c) {
|
|
139
|
+
case 'i':
|
|
140
|
+
input_name = dwoptarg;
|
|
141
|
+
break;
|
|
142
|
+
case 'o':
|
|
143
|
+
output_name = dwoptarg;
|
|
144
|
+
break;
|
|
145
|
+
case 's':
|
|
146
|
+
use_switch = TRUE;
|
|
147
|
+
use_tables = FALSE;
|
|
148
|
+
break;
|
|
149
|
+
case 't':
|
|
150
|
+
use_switch = FALSE;
|
|
151
|
+
use_tables = TRUE;
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
usage_error = TRUE;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (usage_error || 1 == dwoptind || dwoptind != argc) {
|
|
160
|
+
print_usage_message(usage);
|
|
161
|
+
exit(FAILED);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
int
|
|
166
|
+
main(int argc,char **argv)
|
|
167
|
+
{
|
|
168
|
+
print_version(argv[0]);
|
|
169
|
+
process_args(argc,argv);
|
|
170
|
+
print_args(argc,argv);
|
|
171
|
+
OpenAllFiles();
|
|
172
|
+
GenerateInitialFileLines();
|
|
173
|
+
ParseDefinitionsAndWriteOutput();
|
|
174
|
+
WriteFileTrailers();
|
|
175
|
+
CloseAllFiles();
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/* Print the array used to hold the tags, attributes values */
|
|
180
|
+
#ifdef TRACE_ARRAY
|
|
181
|
+
static void
|
|
182
|
+
PrintArray(void)
|
|
183
|
+
{
|
|
184
|
+
int i;
|
|
185
|
+
for (i = 0; i < array_count; ++i) {
|
|
186
|
+
printf("%d: Name %s_%s, Value 0x%04x\n",
|
|
187
|
+
i,prefix,
|
|
188
|
+
array[i].name,
|
|
189
|
+
array[i].value);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
#endif /* TRACE_ARRAY */
|
|
193
|
+
|
|
194
|
+
static int
|
|
195
|
+
Compare(array_data *elem1,array_data *elem2)
|
|
196
|
+
{
|
|
197
|
+
if (elem1->value < elem2->value) {
|
|
198
|
+
return -1;
|
|
199
|
+
}
|
|
200
|
+
if (elem1->value > elem2->value) {
|
|
201
|
+
return 1;
|
|
202
|
+
}
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static FILE *
|
|
207
|
+
open_path(const char *base, const char *file, const char *direction)
|
|
208
|
+
{
|
|
209
|
+
FILE *f = 0;
|
|
210
|
+
/* POSIX PATH_MAX would suffice, normally stdio BUFSIZ is larger
|
|
211
|
+
than PATH_MAX */
|
|
212
|
+
char path_name[BUFSIZ];
|
|
213
|
+
snprintf(path_name,sizeof(path_name),"%s/%s",base,file);
|
|
214
|
+
f = fopen(path_name,direction);
|
|
215
|
+
if (!f) {
|
|
216
|
+
printf("Error openning '%s'\n",path_name);
|
|
217
|
+
exit(1);
|
|
218
|
+
}
|
|
219
|
+
return f;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/* Open files and write the basic headers */
|
|
223
|
+
static void
|
|
224
|
+
OpenAllFiles(void)
|
|
225
|
+
{
|
|
226
|
+
const char *dwarf_h = "dwarf.h";
|
|
227
|
+
const char *names_h = "dwarf_names.h";
|
|
228
|
+
const char *names_c = "dwarf_names.c";
|
|
229
|
+
const char *names_enum_h = "dwarf_names_enum.h";
|
|
230
|
+
const char *names_new_h = "dwarf_names_new.h";
|
|
231
|
+
|
|
232
|
+
f_dwarf_in = open_path(input_name,dwarf_h,"r");
|
|
233
|
+
f_names_enum_h = open_path(output_name,names_enum_h,"w");
|
|
234
|
+
f_names_new_h = open_path(output_name,names_new_h,"w");
|
|
235
|
+
f_names_h = open_path(output_name,names_h,"w");
|
|
236
|
+
f_names_c = open_path(output_name,names_c,"w");
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
static void
|
|
240
|
+
GenerateInitialFileLines(void)
|
|
241
|
+
{
|
|
242
|
+
/* Generate entries for 'dwarf_names_enum.h' */
|
|
243
|
+
fprintf(f_names_enum_h,"/* Automatically generated, do not edit. */\n");
|
|
244
|
+
fprintf(f_names_enum_h,"/* Generated on %s %s */\n",__DATE__,__TIME__);
|
|
245
|
+
fprintf(f_names_enum_h,"\n/* BEGIN FILE */\n\n");
|
|
246
|
+
fprintf(f_names_enum_h,"#ifndef __DWARF_NAMES_ENUM_H__\n");
|
|
247
|
+
fprintf(f_names_enum_h,"#define __DWARF_NAMES_ENUM_H__\n");
|
|
248
|
+
|
|
249
|
+
/* Generate entries for 'dwarf_names_new.h' */
|
|
250
|
+
fprintf(f_names_new_h,"/* Automatically generated, do not edit. */\n");
|
|
251
|
+
fprintf(f_names_new_h,"/* Generated on %s %s */\n",__DATE__,__TIME__);
|
|
252
|
+
fprintf(f_names_new_h,"\n/* BEGIN FILE */\n\n");
|
|
253
|
+
fprintf(f_names_new_h,"/* define DWARF_PRINT_PREFIX before this\n");
|
|
254
|
+
fprintf(f_names_new_h," point if you wish to. */\n");
|
|
255
|
+
fprintf(f_names_new_h,"#ifndef DWARF_PRINT_PREFIX\n");
|
|
256
|
+
fprintf(f_names_new_h,"#define DWARF_PRINT_PREFIX dwarf_\n");
|
|
257
|
+
fprintf(f_names_new_h,"#endif\n");
|
|
258
|
+
fprintf(f_names_new_h,"#define dw_glue(x,y) x##y\n");
|
|
259
|
+
fprintf(f_names_new_h,"#define dw_glue2(x,y) dw_glue(x,y)\n");
|
|
260
|
+
fprintf(f_names_new_h,"#define DWPREFIX(x) dw_glue2(DWARF_PRINT_PREFIX,x)\n");
|
|
261
|
+
|
|
262
|
+
/* Generate entries for 'dwarf_names.h' */
|
|
263
|
+
fprintf(f_names_h,"/* Generated routines, do not edit. */\n");
|
|
264
|
+
fprintf(f_names_h,"/* Generated on %s %s */\n",__DATE__,__TIME__);
|
|
265
|
+
fprintf(f_names_h,"\n/* BEGIN FILE */\n\n");
|
|
266
|
+
|
|
267
|
+
/* Generate entries for 'dwarf_names.c' */
|
|
268
|
+
fprintf(f_names_c,"/* Generated routines, do not edit. */\n");
|
|
269
|
+
fprintf(f_names_c,"/* Generated on %s %s */\n",__DATE__,__TIME__);
|
|
270
|
+
fprintf(f_names_c,"\n/* BEGIN FILE */\n\n");
|
|
271
|
+
fprintf(f_names_c,"#include \"dwarf.h\"\n\n");
|
|
272
|
+
fprintf(f_names_c,"#include \"libdwarf.h\"\n\n");
|
|
273
|
+
|
|
274
|
+
if (use_tables) {
|
|
275
|
+
fprintf(f_names_c,"typedef struct Names_Data {\n");
|
|
276
|
+
fprintf(f_names_c," const char *l_name; \n");
|
|
277
|
+
fprintf(f_names_c," unsigned value; \n");
|
|
278
|
+
fprintf(f_names_c,"} Names_Data;\n\n");
|
|
279
|
+
|
|
280
|
+
/* Generate code to find an entry */
|
|
281
|
+
fprintf(f_names_c,"/* Use standard binary search to get entry */\n");
|
|
282
|
+
fprintf(f_names_c,"static int\nfind_entry(Names_Data *table,"
|
|
283
|
+
"const int last,unsigned value, const char **s_out)\n");
|
|
284
|
+
fprintf(f_names_c,"{\n");
|
|
285
|
+
fprintf(f_names_c," int low = 0;\n");
|
|
286
|
+
fprintf(f_names_c," int high = last;\n");
|
|
287
|
+
fprintf(f_names_c," int mid;\n");
|
|
288
|
+
fprintf(f_names_c,"\n");
|
|
289
|
+
fprintf(f_names_c," while (low < high) {\n");
|
|
290
|
+
fprintf(f_names_c," mid = low + ((high - low) / 2);\n");
|
|
291
|
+
fprintf(f_names_c," if (table[mid].value < value) {\n");
|
|
292
|
+
fprintf(f_names_c," low = mid + 1;\n");
|
|
293
|
+
fprintf(f_names_c," }\n");
|
|
294
|
+
fprintf(f_names_c," else {\n");
|
|
295
|
+
fprintf(f_names_c," high = mid;\n");
|
|
296
|
+
fprintf(f_names_c," }\n");
|
|
297
|
+
fprintf(f_names_c," }\n");
|
|
298
|
+
fprintf(f_names_c,"\n");
|
|
299
|
+
fprintf(f_names_c," if (low < last && table[low].value == value) {\n");
|
|
300
|
+
fprintf(f_names_c," /* Found: low is the entry */\n");
|
|
301
|
+
fprintf(f_names_c," *s_out = table[low].l_name;\n");
|
|
302
|
+
fprintf(f_names_c," return DW_DLV_OK;\n");
|
|
303
|
+
fprintf(f_names_c," }\n");
|
|
304
|
+
fprintf(f_names_c," return DW_DLV_NO_ENTRY;\n");
|
|
305
|
+
fprintf(f_names_c,"}\n");
|
|
306
|
+
fprintf(f_names_c,"\n");
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/* Close files and write basic trailers */
|
|
311
|
+
static void
|
|
312
|
+
WriteFileTrailers(void)
|
|
313
|
+
{
|
|
314
|
+
/* Generate entries for 'dwarf_names_enum.h' */
|
|
315
|
+
fprintf(f_names_enum_h,"#endif /* __DWARF_NAMES_ENUM_H__ */\n");
|
|
316
|
+
fprintf(f_names_enum_h,"\n/* END FILE */\n");
|
|
317
|
+
|
|
318
|
+
/* Generate entries for 'dwarf_names_new.h' */
|
|
319
|
+
fprintf(f_names_new_h,"\n/* END FILE */\n");
|
|
320
|
+
|
|
321
|
+
/* Generate entries for 'dwarf_names.h' */
|
|
322
|
+
fprintf(f_names_h,"\n/* END FILE */\n");
|
|
323
|
+
|
|
324
|
+
/* Generate entries for 'dwarf_names.c' */
|
|
325
|
+
fprintf(f_names_c,"\n/* END FILE */\n");
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
static void
|
|
329
|
+
CloseAllFiles(void)
|
|
330
|
+
{
|
|
331
|
+
fclose(f_dwarf_in);
|
|
332
|
+
fclose(f_names_enum_h);
|
|
333
|
+
fclose(f_names_new_h);
|
|
334
|
+
fclose(f_names_h);
|
|
335
|
+
fclose(f_names_c);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/* Write the table and code for a common set of names */
|
|
339
|
+
static void
|
|
340
|
+
GenerateOneSet(void)
|
|
341
|
+
{
|
|
342
|
+
unsigned u;
|
|
343
|
+
unsigned prev_value = 0;
|
|
344
|
+
size_t len;
|
|
345
|
+
char *prefix_id = prefix + prefix_root_len;
|
|
346
|
+
|
|
347
|
+
#ifdef TRACE_ARRAY
|
|
348
|
+
printf("List before sorting:\n");
|
|
349
|
+
PrintArray();
|
|
350
|
+
#endif /* TRACE_ARRAY */
|
|
351
|
+
|
|
352
|
+
/* Sort the array, because the values in 'libdwarf.h' are not in
|
|
353
|
+
ascending order; if we use '-t' we must be sure the values are
|
|
354
|
+
sorted, for the binary search to work properly */
|
|
355
|
+
qsort((void *)&group_array,array_count,sizeof(array_data),(compfn)Compare);
|
|
356
|
+
|
|
357
|
+
#ifdef TRACE_ARRAY
|
|
358
|
+
printf("\nList after sorting:\n");
|
|
359
|
+
PrintArray();
|
|
360
|
+
#endif /* TRACE_ARRAY */
|
|
361
|
+
|
|
362
|
+
/* Generate entries for 'dwarf_names_enum.h' */
|
|
363
|
+
fprintf(f_names_enum_h,"\nenum Dwarf_%s_e {\n",prefix_id);
|
|
364
|
+
|
|
365
|
+
/* Generate entries for 'dwarf_names_new.h' */
|
|
366
|
+
fprintf(f_names_new_h,"int DWPREFIX(get_%s_name) (unsigned int, const char **);\n",prefix_id);
|
|
367
|
+
|
|
368
|
+
/* Generate entries for 'dwarf_names.h' and libdwarf.h */
|
|
369
|
+
fprintf(f_names_h,"extern int dwarf_get_%s_name(unsigned int /*val_in*/, const char ** /*s_out */);\n",prefix_id);
|
|
370
|
+
|
|
371
|
+
/* Generate code for 'dwarf_names.c' */
|
|
372
|
+
fprintf(f_names_c,"/* ARGSUSED */\n");
|
|
373
|
+
fprintf(f_names_c,"int\n");
|
|
374
|
+
fprintf(f_names_c,"dwarf_get_%s_name (unsigned int val,const char ** s_out)\n",prefix_id);
|
|
375
|
+
fprintf(f_names_c,"{\n");
|
|
376
|
+
if (use_tables) {
|
|
377
|
+
fprintf(f_names_c," static Names_Data Dwarf_%s_n[] = {\n",prefix_id);
|
|
378
|
+
} else {
|
|
379
|
+
fprintf(f_names_c," switch (val) {\n");
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
for (u = 0; u < array_count; ++u) {
|
|
383
|
+
/* Check if value already dumped */
|
|
384
|
+
if (u > 0 && group_array[u].value == prev_value) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
prev_value = group_array[u].value;
|
|
388
|
+
|
|
389
|
+
len = 39 - strlen(prefix);
|
|
390
|
+
fprintf(f_names_enum_h," %s_%-*s = 0x%04x",
|
|
391
|
+
prefix,(int)len,group_array[u].name,group_array[u].value);
|
|
392
|
+
fprintf(f_names_enum_h,(u + 1 < array_count) ? ",\n" : "\n");
|
|
393
|
+
|
|
394
|
+
/* Generate entries for 'dwarf_names.c' */
|
|
395
|
+
if (use_tables) {
|
|
396
|
+
/* The 20 just makes nice formatting in the output. */
|
|
397
|
+
len = 20 - strlen(group_array[u].name);
|
|
398
|
+
fprintf(f_names_c," {/* %3d */ \"%s_%s\", ",
|
|
399
|
+
u,prefix,group_array[u].name);
|
|
400
|
+
fprintf(f_names_c," %s_%s}", prefix,group_array[u].name);
|
|
401
|
+
fprintf(f_names_c,(u + 1 < array_count) ? ",\n" : "\n");
|
|
402
|
+
} else {
|
|
403
|
+
fprintf(f_names_c," case %s_%s:\n",
|
|
404
|
+
prefix,group_array[u].name);
|
|
405
|
+
fprintf(f_names_c," *s_out = \"%s_%s\";\n",
|
|
406
|
+
prefix,group_array[u].name);
|
|
407
|
+
fprintf(f_names_c," return DW_DLV_OK;\n");
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/* Closing entries for 'dwarf_names_enum.h' */
|
|
412
|
+
fprintf(f_names_enum_h,"};\n");
|
|
413
|
+
|
|
414
|
+
if (use_tables) {
|
|
415
|
+
/* Closing entries for 'dwarf_names.c' */
|
|
416
|
+
fprintf(f_names_c," };\n\n");
|
|
417
|
+
|
|
418
|
+
/* Closing code for 'dwarf_names.c' */
|
|
419
|
+
fprintf(f_names_c," const int last_entry = %d;\n",array_count);
|
|
420
|
+
fprintf(f_names_c," /* find the entry */\n");
|
|
421
|
+
fprintf(f_names_c," int r = find_entry(Dwarf_%s_n,last_entry,val,s_out);\n",prefix_id);
|
|
422
|
+
fprintf(f_names_c," return r; \n");
|
|
423
|
+
fprintf(f_names_c,"}\n");
|
|
424
|
+
} else {
|
|
425
|
+
fprintf(f_names_c," }\n");
|
|
426
|
+
fprintf(f_names_c," return DW_DLV_NO_ENTRY;\n");
|
|
427
|
+
fprintf(f_names_c,"}\n");
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/* Mark the group_array as empty */
|
|
431
|
+
array_count = 0;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/* Detect empty lines (and other lines we do not want to read) */
|
|
435
|
+
static boolean
|
|
436
|
+
is_skippable_line(char *pLine)
|
|
437
|
+
{
|
|
438
|
+
boolean empty = TRUE;
|
|
439
|
+
|
|
440
|
+
for (; *pLine && empty; ++pLine) {
|
|
441
|
+
empty = isspace(*pLine);
|
|
442
|
+
}
|
|
443
|
+
return empty;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
static void
|
|
447
|
+
safe_strncpy(char *out, unsigned out_len,
|
|
448
|
+
char *in,unsigned in_len)
|
|
449
|
+
{
|
|
450
|
+
if(in_len >= out_len) {
|
|
451
|
+
fprintf(stderr,"Impossible input line from dwarf.h. Giving up. \n");
|
|
452
|
+
fprintf(stderr,"Length %u is too large, limited to %u.\n",
|
|
453
|
+
in_len,out_len);
|
|
454
|
+
exit(1);
|
|
455
|
+
}
|
|
456
|
+
strncpy(out,in,in_len);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
/* Parse the 'dwarf.h' file and generate the tables */
|
|
461
|
+
static void
|
|
462
|
+
ParseDefinitionsAndWriteOutput(void)
|
|
463
|
+
{
|
|
464
|
+
char new_prefix[64];
|
|
465
|
+
char *second_underscore = NULL;
|
|
466
|
+
char type[1000];
|
|
467
|
+
char name[1000];
|
|
468
|
+
char value[1000];
|
|
469
|
+
char extra[1000];
|
|
470
|
+
char line_in[MAX_LINE_SIZE];
|
|
471
|
+
int pending = FALSE;
|
|
472
|
+
int prefix_len = 0;
|
|
473
|
+
|
|
474
|
+
/* Process each line from 'dwarf.h' */
|
|
475
|
+
while (!feof(f_dwarf_in)) {
|
|
476
|
+
/* errno is cleared here so printing errno after
|
|
477
|
+
the fgets is showing errno as set by fgets. */
|
|
478
|
+
char *fgbad = 0;
|
|
479
|
+
errno = 0;
|
|
480
|
+
fgbad = fgets(line_in,sizeof(line_in),f_dwarf_in);
|
|
481
|
+
if(!fgbad) {
|
|
482
|
+
if(feof(f_dwarf_in)) {
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
/* Is error. errno must be set. */
|
|
486
|
+
fprintf(stderr,"Error reading dwarf.h!. Errno %d\n",errno);
|
|
487
|
+
exit(1);
|
|
488
|
+
}
|
|
489
|
+
if (is_skippable_line(line_in)) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
sscanf(line_in,"%s %s %s %s",type,name,value,extra);
|
|
493
|
+
if (strcmp(type,"#define") ||
|
|
494
|
+
strncmp(name,prefix_root,prefix_root_len)) {
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
second_underscore = strchr(name + prefix_root_len,'_');
|
|
499
|
+
prefix_len = (int)(second_underscore - name);
|
|
500
|
+
safe_strncpy(new_prefix,sizeof(new_prefix),name,prefix_len);
|
|
501
|
+
new_prefix[prefix_len] = 0;
|
|
502
|
+
|
|
503
|
+
/* Check for new prefix set */
|
|
504
|
+
if (strcmp(prefix,new_prefix)) {
|
|
505
|
+
if (pending) {
|
|
506
|
+
/* Generate current prefix set */
|
|
507
|
+
GenerateOneSet();
|
|
508
|
+
}
|
|
509
|
+
pending = TRUE;
|
|
510
|
+
strcpy(prefix,new_prefix);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/* Be sure we have a valid entry */
|
|
514
|
+
if (array_count >= ARRAY_SIZE) {
|
|
515
|
+
printf("Too many entries for current group_array size");
|
|
516
|
+
exit(1);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/* Move past the second underscore */
|
|
520
|
+
++second_underscore;
|
|
521
|
+
|
|
522
|
+
/* Record current entry */
|
|
523
|
+
strcpy(group_array[array_count].name,second_underscore);
|
|
524
|
+
group_array[array_count].value = strtoul(value,NULL,16);
|
|
525
|
+
++array_count;
|
|
526
|
+
}
|
|
527
|
+
if (pending) {
|
|
528
|
+
/* Generate final prefix set */
|
|
529
|
+
GenerateOneSet();
|
|
530
|
+
}
|
|
531
|
+
}
|