rdwarf 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,235 @@
|
|
1
|
+
To build libdwarf.a, type
|
2
|
+
./configure
|
3
|
+
make
|
4
|
+
To build libdwarf.so, type
|
5
|
+
./configure --enable-shared --disable-nonshared
|
6
|
+
make
|
7
|
+
To build both, type
|
8
|
+
./configure --enable-shared
|
9
|
+
make
|
10
|
+
|
11
|
+
January 30, 2013: libdwarf.h is no longer in the distribution,
|
12
|
+
but libdwarf.h.in is identical to libdwarf.h. 'configure'
|
13
|
+
copies libdwarf.h.in to libdwarf.h and whether libelf.h defines
|
14
|
+
'struct _Elf' or 'struct Elf' configure attempts to create
|
15
|
+
libdwarf.h appropriately.
|
16
|
+
|
17
|
+
No real install target is provided here, so 'make install' does
|
18
|
+
not do much. One can copy either or both of libdwarf.a libdwarf.so
|
19
|
+
to somewhere fairly standard (but intended for software you build)
|
20
|
+
like '/usr/local/lib'. Or anywhere else you want to copy it.
|
21
|
+
|
22
|
+
To use dwarf or libdwarf, you may want to copy dwarf.h and
|
23
|
+
a generated libdwarf.h somewhere convenient
|
24
|
+
(possibly /usr/local/include),
|
25
|
+
and you may need to copy the libdwarf to a convenient spot
|
26
|
+
(/usr/local/lib is a traditional place for libraries one builds
|
27
|
+
oneself on Unix and Linux).
|
28
|
+
This copying is not needed to build dwarfdump.
|
29
|
+
|
30
|
+
|
31
|
+
Multi Threading, or using threads with libdwarf (Thread Safety):
|
32
|
+
Nothing in libdwarf does any locking. Every Dwarf_Debug
|
33
|
+
(such as returned by dwarf_init()) is fully independent
|
34
|
+
of all other Dwarf_Debug-s. However, calls to libdwarf can
|
35
|
+
change a Dwarf_Debug. So it is unsafe to have two different
|
36
|
+
threads accessing a single Dwarf_Debug simultaneously.
|
37
|
+
It is therefore sufficient to ensure than any one Dwarf_Debug
|
38
|
+
is only accessed from a single thread.
|
39
|
+
|
40
|
+
Warnings like
|
41
|
+
"warning: cast from pointer to integer of different size"
|
42
|
+
at compile time are to be expected in dwarf_frame.c and
|
43
|
+
dwarf_frame2.c. Do not be alarmed.
|
44
|
+
|
45
|
+
Warnings like
|
46
|
+
"warning: passing argument 1 of ‘dbg->de_callback_func_c’
|
47
|
+
discards ‘const’ qualifier from pointer target type
|
48
|
+
[enabled by default]" at compile time are to be expected in
|
49
|
+
some pro*.c source files. Fixing the public prototype could
|
50
|
+
cause some producer-library user's code to fail to compile
|
51
|
+
so we live with the warnings for now.
|
52
|
+
|
53
|
+
|
54
|
+
If your headers are not in the expected places,
|
55
|
+
use the make command line to add flags and include directories.
|
56
|
+
For example
|
57
|
+
./configure
|
58
|
+
PREINCS="-I /usr/local/share/include" POSTINCS="-I /home/x/include" make
|
59
|
+
PREINCS content is inserted before CFLAGS as make(1) is running.
|
60
|
+
POSTINCS content is added after the CFLAGS value.
|
61
|
+
|
62
|
+
To set LDFLAGS (which is used when building a .so and
|
63
|
+
in building gennames to create some source here),
|
64
|
+
do so at configure time, for example:
|
65
|
+
./configure LDFLAGS="-L /var/tmp"
|
66
|
+
Or use PRELIBS and/or POSTLIBS at 'make' time similar to the use
|
67
|
+
of PREINCS and POSTINCS.
|
68
|
+
|
69
|
+
If you are using the old frame interfaces and depend on
|
70
|
+
the use of DW_FRAME_CFA_COL you must add --enable-oldframecol
|
71
|
+
to the ./configure options to configure libdwarf.
|
72
|
+
See NEWS and libdwarf2.1.mm/pdf .
|
73
|
+
|
74
|
+
To generate SGI IRIX 64 bit offsets (in the producer code)
|
75
|
+
configure with --enable-dwarf-format-sgi-irix.
|
76
|
+
To configure with only 32bit offsets (aka DWARF2) configure
|
77
|
+
with --enable-dwarf-format-strict-32bit.
|
78
|
+
By default the producer now generates 32bit offsets by default
|
79
|
+
but one can turn on DWARF3 64bit offset generation at runtime by ORing
|
80
|
+
DW_DLC_OFFSET_SIZE_64 onto the flags in the call to
|
81
|
+
dwarf_producer_init() (or dwarf_producer_init_b) [when the
|
82
|
+
address size is specified as 64 bit].
|
83
|
+
|
84
|
+
Mac OSX (June 2010): Since MacOSX does not use elf, there is no elf.h
|
85
|
+
header in the headers provided on MacOSX.
|
86
|
+
Use a search engine (like google) to find an elf.h you can use.
|
87
|
+
http://www.rockbox.org/tracker/9006?getfile=16683
|
88
|
+
might be useful.
|
89
|
+
In addition, the archive (ar) program on MacOSX does not
|
90
|
+
automatically generate some data so modify the generated
|
91
|
+
Makefile to add -s to the options to ar.
|
92
|
+
|
93
|
+
To enable dection of Windows pathnames as full paths
|
94
|
+
add --enable-windowspath. Doing this does mean things like
|
95
|
+
A:foo and \anything are treated as full paths (these are
|
96
|
+
unlikely path names on a POSIX system but are legal
|
97
|
+
POSIX partial paths).
|
98
|
+
|
99
|
+
It is possible to request a shared library (libdwarf.so) build with
|
100
|
+
--enable-shared
|
101
|
+
To turn off the build of the archive library (libdwarf.a) specify
|
102
|
+
--disable-nonshared
|
103
|
+
but in this case you must specify --enable-shared or nothing will
|
104
|
+
build!
|
105
|
+
|
106
|
+
TARGET DEPENDENCIES of .debug_frame:
|
107
|
+
dwarf.h
|
108
|
+
These should be revised if you have more than the defined
|
109
|
+
63 'normal' registers. It's not harmful to have these too large!
|
110
|
+
Too small will lead to errors reading .debug_frame and .eh_frame.
|
111
|
+
DW_FRAME_HIGHEST_NORMAL_REGISTER
|
112
|
+
DW_FRAME_LAST_REG_NUM
|
113
|
+
|
114
|
+
These you might revise, but can safely ignore if simply
|
115
|
+
using dwarfdump. If using the producer code you will want
|
116
|
+
to get these exactly right for your architecture.
|
117
|
+
DW_FRAME_RA_COL
|
118
|
+
DW_FRAME_STATIC_LINK
|
119
|
+
DW_FRAME_CFA_COL
|
120
|
+
|
121
|
+
libdwarf.h
|
122
|
+
The DW_FRAME_REG_INITIAL_VALUE #define should be set to
|
123
|
+
the value appropriate to your architecture. See libdwarf.h
|
124
|
+
for details.
|
125
|
+
|
126
|
+
If DW_REG_TABLE_SIZE is not set large enough attempts to
|
127
|
+
fill in the .debug_frame tables will get an error.
|
128
|
+
Should be at least as large as DW_FRAME_LAST_REG_NUM.
|
129
|
+
If it's too large nothing is harmed (but some extra space taken
|
130
|
+
at run time).
|
131
|
+
|
132
|
+
If your printf does not support C standard %llx etc,
|
133
|
+
(such as MSWindows with long long), configure
|
134
|
+
option --enable-nonstandardprintf
|
135
|
+
and defines like DW_PR_DUx etc in libdwarf.h
|
136
|
+
provide a way to configure for that relatively easily.
|
137
|
+
|
138
|
+
|
139
|
+
The .debug_frame is so very architecture dependent
|
140
|
+
and because the host (where libdwarf/dwarfdump are executed)
|
141
|
+
and target (the objects read) could be different.
|
142
|
+
It's currently not supported to have dwarfdump/libdwarf determine
|
143
|
+
the architecture on-the-fly and do-the-right-thing.
|
144
|
+
Just setting DW_FRAME_LAST_REG_NUM and DW_FRAME_HIGHEST_NORMAL_REGISTER
|
145
|
+
and DW_REG_TABLE_SIZE high enough will likely suffice for most
|
146
|
+
purposes and most compilers/architectures..
|
147
|
+
See comments in dwarf.h/libdwarf.h.
|
148
|
+
|
149
|
+
It's perfectly safe to ignore the above suggestions as long
|
150
|
+
as libdwarf does not get a DW_DLE_DF_REG_NUM_TOO_HIGH error.
|
151
|
+
(which would only happen on reading .debug_frame or .eh_frame data).
|
152
|
+
|
153
|
+
If you intend to use the libdwarf dwarf-producer code
|
154
|
+
for .debug_frame information
|
155
|
+
you must do a thorough analysys and revise dwarf.h
|
156
|
+
substantially to match the output target architecture.
|
157
|
+
|
158
|
+
In general, in the producer code, numbers are copied from and
|
159
|
+
to integers with memcpy(). In case of endianness problems,
|
160
|
+
constants set in dwarf_producer_init() can fix the problems.
|
161
|
+
If one wants to produce a *different-endian* output the best
|
162
|
+
solution is to change the integer memcpy calls to call thru a
|
163
|
+
new dbg-based function pointer and have it 'do the right thing'
|
164
|
+
to adjust endianness. Set the function pointer correctly in
|
165
|
+
dwarf_producer_init() and the rest of the code will just call
|
166
|
+
thru the function pointer. Tedious work to find and change the
|
167
|
+
memcpy calls to be dbg->de_memcpy(), but once done the code is
|
168
|
+
no longer endian dependent (right now there is no way to ask
|
169
|
+
for cross-endian: a new flag needed or ?).
|
170
|
+
|
171
|
+
leb128 numbers are endian-independent, so nothing need be
|
172
|
+
done with those for cross-endian support (the storage
|
173
|
+
of leb128 on disk is always little-endian).
|
174
|
+
|
175
|
+
The .ps files are postscript. So those who cannot deal with mm
|
176
|
+
format files but do have a postscript printer (or have
|
177
|
+
ghostscript) can print the documents.
|
178
|
+
This form was chosen before pdf format existed...
|
179
|
+
|
180
|
+
libdwarf2.1.pdf documents a way for a debugger to read dwarf information.
|
181
|
+
libdwarf2p.1.pdf documents a way for a compiler to generate dwarf information.
|
182
|
+
mips_extensions.ps documents the mips/sgi extensions to dwarf.
|
183
|
+
|
184
|
+
See the Makefile for the commands used to build pdf files
|
185
|
+
libdwarf.2.1.pdf and libdwarf1p.1.pdf.
|
186
|
+
|
187
|
+
pic is a picture processing tool (ATT command).
|
188
|
+
tbl is a table-processing tool.
|
189
|
+
(part of Documentor's Work Bench on ATT-like systems).
|
190
|
+
tbl and pic are available on linux.
|
191
|
+
|
192
|
+
psroff is a name for a troff-like processor, part of
|
193
|
+
Documentor's Work Bench on IRIX. Substitute a
|
194
|
+
troff-like or nroff-like processor (GNU groff works fine).
|
195
|
+
|
196
|
+
To use dwarf or libdwarf, you may want to install dwarf.h and
|
197
|
+
libdwarf.h somewhere convenient.
|
198
|
+
|
199
|
+
You will also need libelf (libelf.a and/or libelf.so) and
|
200
|
+
libelf.h installed. These are available from GNU repositories
|
201
|
+
and from the normal Linux repositories for Linux releases.
|
202
|
+
On Ubuntu Linux for example:
|
203
|
+
sudo apt-get install libelf-dev libelf1
|
204
|
+
|
205
|
+
Compiler warnings:
|
206
|
+
A few Warnings like:
|
207
|
+
dwarf_frame.c:715:29: warning: cast from pointer to integer of different size [-
|
208
|
+
Wpointer-to-int-cast]
|
209
|
+
dwarf_arange.c:113:13: warning: variable ‘local_extension_size’ set but not used
|
210
|
+
[-Wunused-but-set-variable]
|
211
|
+
are considered normal.
|
212
|
+
|
213
|
+
|
214
|
+
As of January 2013 the code compiles with gcc without
|
215
|
+
problems with -Wall and -Wsign-compare
|
216
|
+
aside from the warnings hinted at above.
|
217
|
+
|
218
|
+
The following gcc/clang options
|
219
|
+
have not all been tried as of January 2013,
|
220
|
+
but will be as time permits.
|
221
|
+
-Wsystem-headers
|
222
|
+
-Wall -Wsign-compare
|
223
|
+
-Wno-format-y2k -W
|
224
|
+
-Wno-unused-parameter -Wstrict-prototypes
|
225
|
+
-Wmissing-prototypes -Wpointer-arith
|
226
|
+
-Wreturn-type -Wcast-qual -Wwrite-strings
|
227
|
+
-Wswitch -Wshadow -Wunused-parameter
|
228
|
+
-Wcast-align -Wchar-subscripts -Winline
|
229
|
+
-Wnested-externs -Wredundant-decls
|
230
|
+
-Wold-style-definition -Wno-pointer-sign
|
231
|
+
|
232
|
+
|
233
|
+
$Source: /home/davea/dwarf/dwarf-working/trunk/libdwarf/README,v $
|
234
|
+
$Revision: 1.1 $
|
235
|
+
$Date: 2009/11/23 17:15:37 $
|
@@ -0,0 +1,1179 @@
|
|
1
|
+
|
2
|
+
/* The following are taken from libdwarf2.1.mm
|
3
|
+
to verify there are no silly tographical errors
|
4
|
+
in that document.
|
5
|
+
|
6
|
+
These should not be built routinely nor
|
7
|
+
should it every be executed.
|
8
|
+
|
9
|
+
The code here is what user code should be,
|
10
|
+
hence the code typed here is
|
11
|
+
PUBLIC DOMAIN.
|
12
|
+
This file is not part of libdwarf, though
|
13
|
+
it appears in the same directory as libdwarf.
|
14
|
+
*/
|
15
|
+
|
16
|
+
|
17
|
+
#include "dwarf.h"
|
18
|
+
#include "libdwarf.h"
|
19
|
+
|
20
|
+
#define NULL 0
|
21
|
+
|
22
|
+
void example1(Dwarf_Die somedie)
|
23
|
+
{
|
24
|
+
Dwarf_Debug dbg = 0;
|
25
|
+
Dwarf_Signed atcount;
|
26
|
+
Dwarf_Attribute *atlist;
|
27
|
+
Dwarf_Error error = 0;
|
28
|
+
Dwarf_Signed i = 0;
|
29
|
+
int errv;
|
30
|
+
|
31
|
+
errv = dwarf_attrlist(somedie, &atlist,&atcount, &error);
|
32
|
+
if (errv == DW_DLV_OK) {
|
33
|
+
for (i = 0; i < atcount; ++i) {
|
34
|
+
/* use atlist[i] */
|
35
|
+
dwarf_dealloc(dbg, atlist[i], DW_DLA_ATTR);
|
36
|
+
}
|
37
|
+
dwarf_dealloc(dbg, atlist, DW_DLA_LIST);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
void example2(Dwarf_Debug dbg, Dwarf_Debug tieddbg)
|
42
|
+
{
|
43
|
+
Dwarf_Error error = 0;
|
44
|
+
int res = 0;
|
45
|
+
|
46
|
+
/* Do the dwarf_init() or dwarf_elf_init
|
47
|
+
calls to set
|
48
|
+
dbg, tieddbg at this point. Then: */
|
49
|
+
res = dwarf_set_tied_dbg(dbg,tieddbg,&error);
|
50
|
+
if (res != DW_DLV_OK) {
|
51
|
+
/* Something went wrong*/
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
void example3(Dwarf_Debug dbg)
|
56
|
+
{
|
57
|
+
Dwarf_Error error = 0;
|
58
|
+
int res = 0;
|
59
|
+
res = dwarf_set_tied_dbg(dbg,NULL,&error);
|
60
|
+
if (res != DW_DLV_OK) {
|
61
|
+
/* Something went wrong*/
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
void example4(Dwarf_Debug dbg,Dwarf_Die in_die,Dwarf_Bool is_info)
|
66
|
+
{
|
67
|
+
Dwarf_Die return_sib = 0;
|
68
|
+
Dwarf_Error error = 0;
|
69
|
+
int res = 0;
|
70
|
+
|
71
|
+
/* in_die might be NULL or a valid Dwarf_Die */
|
72
|
+
res = dwarf_siblingof_b(dbg,in_die,is_info,&return_sib, &error);
|
73
|
+
if (res == DW_DLV_OK) {
|
74
|
+
/* Use return_sib here. */
|
75
|
+
dwarf_dealloc(dbg, return_sib, DW_DLA_DIE);
|
76
|
+
/* return_sib is no longer usable for anything, we
|
77
|
+
ensure we do not use it accidentally with: */
|
78
|
+
return_sib = 0;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
void example5(Dwarf_Debug dbg,Dwarf_Die in_die)
|
84
|
+
{
|
85
|
+
Dwarf_Die return_kid = 0;
|
86
|
+
Dwarf_Error error = 0;
|
87
|
+
int res = 0;
|
88
|
+
|
89
|
+
res = dwarf_child(in_die,&return_kid, &error);
|
90
|
+
if (res == DW_DLV_OK) {
|
91
|
+
/* Use return_kid here. */
|
92
|
+
dwarf_dealloc(dbg, return_kid, DW_DLA_DIE);
|
93
|
+
/* return_die is no longer usable for anything, we
|
94
|
+
ensure we do not use it accidentally with: */
|
95
|
+
return_kid = 0;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
void example6(Dwarf_Debug dbg,Dwarf_Off die_offset,Dwarf_Bool is_info)
|
100
|
+
{
|
101
|
+
Dwarf_Error error = 0;
|
102
|
+
Dwarf_Die return_die = 0;
|
103
|
+
int res = 0;
|
104
|
+
|
105
|
+
res = dwarf_offdie_b(dbg,die_offset,is_info,&return_die, &error);
|
106
|
+
if (res == DW_DLV_OK) {
|
107
|
+
/* Use return_die here. */
|
108
|
+
dwarf_dealloc(dbg, return_die, DW_DLA_DIE);
|
109
|
+
/* return_die is no longer usable for anything, we
|
110
|
+
ensure we do not use it accidentally with: */
|
111
|
+
return_die = 0;
|
112
|
+
} else {
|
113
|
+
/* res could be NO ENTRY or ERROR, so no
|
114
|
+
dealloc necessary. */
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
void example7(Dwarf_Debug dbg, Dwarf_Die in_die,Dwarf_Bool is_info)
|
119
|
+
{
|
120
|
+
int res = 0;
|
121
|
+
Dwarf_Off cudieoff = 0;
|
122
|
+
Dwarf_Die cudie = 0;
|
123
|
+
Dwarf_Error error = 0;
|
124
|
+
|
125
|
+
print_die_data(dbg,in_die);
|
126
|
+
res = dwarf_CU_dieoffset_given_die(in_die,&cudieoff,&error);
|
127
|
+
if(res != DW_DLV_OK) {
|
128
|
+
/* FAIL */
|
129
|
+
return;
|
130
|
+
}
|
131
|
+
res = dwarf_offdie_b(dbg,cudieoff,is_info,&cudie,&error);
|
132
|
+
if(res != DW_DLV_OK) {
|
133
|
+
/* FAIL */
|
134
|
+
return;
|
135
|
+
}
|
136
|
+
print_die_data(dbg,cudie);
|
137
|
+
dwarf_dealloc(dbg,cudie, DW_DLA_DIE);
|
138
|
+
}
|
139
|
+
|
140
|
+
|
141
|
+
void example8(Dwarf_Debug dbg, Dwarf_Die somedie)
|
142
|
+
{
|
143
|
+
Dwarf_Signed atcount = 0;
|
144
|
+
Dwarf_Attribute *atlist = 0;
|
145
|
+
Dwarf_Error error = 0;
|
146
|
+
int errv = 0;
|
147
|
+
|
148
|
+
errv = dwarf_attrlist(somedie, &atlist,&atcount, &error);
|
149
|
+
if (errv == DW_DLV_OK) {
|
150
|
+
Dwarf_Signed i = 0;
|
151
|
+
|
152
|
+
for (i = 0; i < atcount; ++i) {
|
153
|
+
/* use atlist[i] */
|
154
|
+
dwarf_dealloc(dbg, atlist[i], DW_DLA_ATTR);
|
155
|
+
}
|
156
|
+
dwarf_dealloc(dbg, atlist, DW_DLA_LIST);
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
void
|
161
|
+
example_loclistc(Dwarf_Debug dbg,Dwarf_Attribute someattr)
|
162
|
+
{
|
163
|
+
Dwarf_Unsigned lcount = 0;
|
164
|
+
Dwarf_Loc_Head_c loclist_head = 0;
|
165
|
+
Dwarf_Error error = 0;
|
166
|
+
int lres = 0;
|
167
|
+
|
168
|
+
lres = dwarf_get_loclist_c(someattr,&loclist_head,&lcount,&error);
|
169
|
+
if (lres == DW_DLV_OK) {
|
170
|
+
Dwarf_Unsigned i = 0;
|
171
|
+
Dwarf_Locdesc_c locentry = 0;
|
172
|
+
|
173
|
+
/* Before any return remember to call
|
174
|
+
dwarf_loc_head_c_dealloc(loclist_head); */
|
175
|
+
for (i = 0; i < lcount; ++i) {
|
176
|
+
Dwarf_Small loclist_source = 0;
|
177
|
+
Dwarf_Small lle_value = 0; /* DWARF5 */
|
178
|
+
Dwarf_Addr lopc = 0;
|
179
|
+
Dwarf_Addr hipc = 0;
|
180
|
+
Dwarf_Unsigned ulocentry_count = 0;
|
181
|
+
Dwarf_Locdesc_c locentry = 0;
|
182
|
+
|
183
|
+
/* section_offset is the section offset of the expression, not
|
184
|
+
the location description prefix. */
|
185
|
+
Dwarf_Unsigned section_offset = 0;
|
186
|
+
|
187
|
+
/* locdesc_offset is the section offset of the
|
188
|
+
location description prefix. */
|
189
|
+
Dwarf_Unsigned locdesc_offset = 0;
|
190
|
+
|
191
|
+
lres = dwarf_get_locdesc_entry_c(loclist_head,
|
192
|
+
i,
|
193
|
+
&lle_value,&lopc,&hipc,
|
194
|
+
&ulocentry_count,
|
195
|
+
&locentry,
|
196
|
+
&loclist_source,
|
197
|
+
§ion_offset,
|
198
|
+
&locdesc_offset,
|
199
|
+
&error);
|
200
|
+
if (lres == DW_DLV_OK) {
|
201
|
+
/* Here, use loclist_source and
|
202
|
+
lle_value to determine what
|
203
|
+
sort of loclist it is and what to do with
|
204
|
+
the values. locentry_count will only be
|
205
|
+
more than zero if there is a set of location
|
206
|
+
operators.
|
207
|
+
One must use lle_value to determine how
|
208
|
+
to interpret lopc,hipc as sometimes they
|
209
|
+
are a target address and sometimes an
|
210
|
+
index into .debug_addr or even a length. */
|
211
|
+
Dwarf_Unsigned j = 0;
|
212
|
+
int opres = 0;
|
213
|
+
Dwarf_Small op = 0;
|
214
|
+
|
215
|
+
for (j = 0; i < ulocentry_count; ++i) {
|
216
|
+
Dwarf_Unsigned opd1 = 0;
|
217
|
+
Dwarf_Unsigned opd2 = 0;
|
218
|
+
Dwarf_Unsigned opd3 = 0;
|
219
|
+
Dwarf_Unsigned offsetforbranch = 0;
|
220
|
+
|
221
|
+
opres = dwarf_get_location_op_value_c(locentry,
|
222
|
+
j,&op,&opd1, &opd2,&opd3,&offsetforbranch,
|
223
|
+
&error);
|
224
|
+
if (opres == DW_DLV_OK) {
|
225
|
+
/* Do something with the operators. */
|
226
|
+
} else {
|
227
|
+
/*Something is wrong. */
|
228
|
+
}
|
229
|
+
}
|
230
|
+
} else {
|
231
|
+
/* Something is wrong. Do something. */
|
232
|
+
}
|
233
|
+
}
|
234
|
+
/* In case of error or any other situation where one
|
235
|
+
is giving up one can call dwarf_loc_head_c_dealloc()
|
236
|
+
to free all the memory associated with loclist_head. */
|
237
|
+
dwarf_loc_head_c_dealloc(loclist_head);
|
238
|
+
loclist_head = 0;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
void
|
242
|
+
example_locexprc(Dwarf_Debug dbg,Dwarf_Ptr expr_bytes,
|
243
|
+
Dwarf_Unsigned expr_len,
|
244
|
+
Dwarf_Half addr_size,
|
245
|
+
Dwarf_Half offset_size,
|
246
|
+
Dwarf_Half version)
|
247
|
+
{
|
248
|
+
Dwarf_Loc_Head_c head = 0;
|
249
|
+
Dwarf_Locdesc_c locentry = 0;
|
250
|
+
int res2 = 0;
|
251
|
+
Dwarf_Unsigned lopc = 0;
|
252
|
+
Dwarf_Unsigned hipc = 0;
|
253
|
+
Dwarf_Unsigned ulistlen = 0;
|
254
|
+
Dwarf_Unsigned ulocentry_count = 0;
|
255
|
+
Dwarf_Unsigned section_offset = 0;
|
256
|
+
Dwarf_Unsigned locdesc_offset = 0;
|
257
|
+
Dwarf_Small lle_value = 0;
|
258
|
+
Dwarf_Small loclist_source = 0;
|
259
|
+
Dwarf_Unsigned i = 0;
|
260
|
+
Dwarf_Error error = 0;
|
261
|
+
|
262
|
+
res2 = dwarf_loclist_from_expr_c(dbg,
|
263
|
+
expr_bytes,expr_len,
|
264
|
+
addr_size,
|
265
|
+
offset_size,
|
266
|
+
version,
|
267
|
+
&head,
|
268
|
+
&ulistlen,
|
269
|
+
&error);
|
270
|
+
if(res2 == DW_DLV_NO_ENTRY) {
|
271
|
+
return;
|
272
|
+
}
|
273
|
+
if(res2 == DW_DLV_ERROR) {
|
274
|
+
return;
|
275
|
+
}
|
276
|
+
/* These are a location expression, not loclist.
|
277
|
+
So we just need the 0th entry. */
|
278
|
+
res2 = dwarf_get_locdesc_entry_c(head,
|
279
|
+
0, /* Data from 0th LocDesc */
|
280
|
+
&lle_value,
|
281
|
+
&lopc, &hipc,
|
282
|
+
&ulocentry_count,
|
283
|
+
&locentry,
|
284
|
+
&loclist_source,
|
285
|
+
§ion_offset,
|
286
|
+
&locdesc_offset,
|
287
|
+
&error);
|
288
|
+
if (res2 == DW_DLV_ERROR) {
|
289
|
+
dwarf_loc_head_c_dealloc(head);
|
290
|
+
return;
|
291
|
+
} else if (res2 == DW_DLV_NO_ENTRY) {
|
292
|
+
dwarf_loc_head_c_dealloc(head);
|
293
|
+
return;
|
294
|
+
}
|
295
|
+
/* ASSERT: ulistlen == 1 */
|
296
|
+
for (i = 0; i < ulocentry_count;++i) {
|
297
|
+
Dwarf_Small op = 0;
|
298
|
+
Dwarf_Unsigned opd1 = 0;
|
299
|
+
Dwarf_Unsigned opd2 = 0;
|
300
|
+
Dwarf_Unsigned opd3 = 0;
|
301
|
+
Dwarf_Unsigned offsetforbranch = 0;
|
302
|
+
|
303
|
+
res2 = dwarf_get_location_op_value_c(locentry,
|
304
|
+
i, &op,&opd1,&opd2,&opd3,&offsetforbranch,
|
305
|
+
&error);
|
306
|
+
/* Do something with the expression operator and operands */
|
307
|
+
if (res2 != DW_DLV_OK) {
|
308
|
+
dwarf_loc_head_c_dealloc(head);
|
309
|
+
return;
|
310
|
+
}
|
311
|
+
}
|
312
|
+
dwarf_loc_head_c_dealloc(head);
|
313
|
+
}
|
314
|
+
|
315
|
+
void
|
316
|
+
example9(Dwarf_Debug dbg,Dwarf_Attribute someattr)
|
317
|
+
{
|
318
|
+
Dwarf_Signed lcount = 0;
|
319
|
+
Dwarf_Locdesc **llbuf = 0;
|
320
|
+
Dwarf_Error error = 0;
|
321
|
+
int lres = 0;
|
322
|
+
|
323
|
+
lres = dwarf_loclist_n(someattr, &llbuf,&lcount,&error);
|
324
|
+
if (lres == DW_DLV_OK) {
|
325
|
+
Dwarf_Signed i = 0;
|
326
|
+
for (i = 0; i < lcount; ++i) {
|
327
|
+
/* Use llbuf[i]. Both Dwarf_Locdesc and the
|
328
|
+
array of Dwarf_Loc it points to are
|
329
|
+
defined in libdwarf.h: they are
|
330
|
+
not opaque structs. */
|
331
|
+
dwarf_dealloc(dbg, llbuf[i]->ld_s, DW_DLA_LOC_BLOCK);
|
332
|
+
dwarf_dealloc(dbg,llbuf[i], DW_DLA_LOCDESC);
|
333
|
+
}
|
334
|
+
dwarf_dealloc(dbg, llbuf, DW_DLA_LIST);
|
335
|
+
}
|
336
|
+
}
|
337
|
+
|
338
|
+
|
339
|
+
void examplea(Dwarf_Debug dbg,Dwarf_Attribute someattr)
|
340
|
+
{
|
341
|
+
Dwarf_Signed lcount = 0;
|
342
|
+
Dwarf_Locdesc *llbuf = 0;
|
343
|
+
Dwarf_Error error = 0;
|
344
|
+
int lres = 0;
|
345
|
+
|
346
|
+
lres = dwarf_loclist(someattr, &llbuf,&lcount,&error);
|
347
|
+
if (lres == DW_DLV_OK) {
|
348
|
+
/* lcount is always 1, (and has always been 1) */
|
349
|
+
/* Use llbuf here. */
|
350
|
+
|
351
|
+
dwarf_dealloc(dbg, llbuf->ld_s, DW_DLA_LOC_BLOCK);
|
352
|
+
dwarf_dealloc(dbg, llbuf, DW_DLA_LOCDESC);
|
353
|
+
}
|
354
|
+
}
|
355
|
+
|
356
|
+
void exampleb(Dwarf_Debug dbg,Dwarf_Ptr data, Dwarf_Unsigned len)
|
357
|
+
{
|
358
|
+
Dwarf_Signed lcount = 0;
|
359
|
+
Dwarf_Locdesc *llbuf = 0;
|
360
|
+
Dwarf_Error error = 0;
|
361
|
+
int lres = 0;
|
362
|
+
|
363
|
+
lres = dwarf_loclist_from_expr(dbg,data,len, &llbuf,&lcount, &error);
|
364
|
+
if (lres == DW_DLV_OK) {
|
365
|
+
/* lcount is always 1 */
|
366
|
+
/* Use llbuf here.*/
|
367
|
+
|
368
|
+
dwarf_dealloc(dbg, llbuf->ld_s, DW_DLA_LOC_BLOCK);
|
369
|
+
dwarf_dealloc(dbg, llbuf, DW_DLA_LOCDESC);
|
370
|
+
}
|
371
|
+
}
|
372
|
+
|
373
|
+
|
374
|
+
void examplec(Dwarf_Die cu_die)
|
375
|
+
{
|
376
|
+
/* EXAMPLE: DWARF5 style access. */
|
377
|
+
Dwarf_Line *linebuf = 0;
|
378
|
+
Dwarf_Signed linecount = 0;
|
379
|
+
Dwarf_Line *linebuf_actuals = 0;
|
380
|
+
Dwarf_Signed linecount_actuals = 0;
|
381
|
+
Dwarf_Line_Context line_context = 0;
|
382
|
+
Dwarf_Signed linecount_total = 0;
|
383
|
+
Dwarf_Small table_count = 0;
|
384
|
+
Dwarf_Unsigned lineversion = 0;
|
385
|
+
Dwarf_Error err = 0;
|
386
|
+
int sres = 0;
|
387
|
+
/* ... */
|
388
|
+
/* we use 'return' here to signify we can do nothing more
|
389
|
+
at this point in the code. */
|
390
|
+
sres = dwarf_srclines_b(cu_die,&lineversion,
|
391
|
+
&table_count,&line_context,&err);
|
392
|
+
if (sres != DW_DLV_OK) {
|
393
|
+
/* Handle the DW_DLV_NO_ENTRY or DW_DLV_ERROR
|
394
|
+
No memory was allocated so there nothing
|
395
|
+
to dealloc. */
|
396
|
+
return;
|
397
|
+
}
|
398
|
+
if (table_count == 0) {
|
399
|
+
/* A line table with no actual lines. */
|
400
|
+
/*...do something, see dwarf_srclines_files_count()
|
401
|
+
etc below. */
|
402
|
+
|
403
|
+
dwarf_srclines_dealloc_b(line_context);
|
404
|
+
/* All the memory is released, the line_context
|
405
|
+
and linebuf zeroed now
|
406
|
+
as a reminder they are stale. */
|
407
|
+
linebuf = 0;
|
408
|
+
line_context = 0;
|
409
|
+
} else if (table_count == 1) {
|
410
|
+
Dwarf_Signed i = 0;
|
411
|
+
/* Standard dwarf 2,3,4, or 5 line table */
|
412
|
+
/* Do something. */
|
413
|
+
/* For this case where we have a line table we will likely
|
414
|
+
wish to get the line details: */
|
415
|
+
sres = dwarf_srclines_from_linecontext(line_context,
|
416
|
+
&linebuf,&linecount,
|
417
|
+
&err);
|
418
|
+
if (sres != DW_DLV_OK) {
|
419
|
+
/* Error. Clean up the context information. */
|
420
|
+
dwarf_srclines_dealloc_b(line_context);
|
421
|
+
return;
|
422
|
+
}
|
423
|
+
/* The lines are normal line table lines. */
|
424
|
+
for (i = 0; i < linecount; ++i) {
|
425
|
+
/* use linebuf[i] */
|
426
|
+
}
|
427
|
+
dwarf_srclines_dealloc_b(line_context);
|
428
|
+
/* All the memory is released, the line_context
|
429
|
+
and linebuf zeroed now as a reminder they are stale */
|
430
|
+
linebuf = 0;
|
431
|
+
line_context = 0;
|
432
|
+
linecount = 0;
|
433
|
+
} else {
|
434
|
+
Dwarf_Signed i = 0;
|
435
|
+
/* ASSERT: table_count == 2,
|
436
|
+
Experimental two-level line table. Version 0xf006
|
437
|
+
We do not define the meaning of this non-standard
|
438
|
+
set of tables here. */
|
439
|
+
|
440
|
+
/* For 'something C' (two-level line tables)
|
441
|
+
one codes something like this
|
442
|
+
Note that we do not define the meaning or use of two-level line
|
443
|
+
tables as these are experimental, not standard DWARF. */
|
444
|
+
sres = dwarf_srclines_two_level_from_linecontext(line_context,
|
445
|
+
&linebuf,&linecount,
|
446
|
+
&linebuf_actuals,&linecount_actuals,
|
447
|
+
&err);
|
448
|
+
if (sres == DW_DLV_OK) {
|
449
|
+
for (i = 0; i < linecount; ++i) {
|
450
|
+
/* use linebuf[i], these are the 'logicals' entries. */
|
451
|
+
}
|
452
|
+
for (i = 0; i < linecount_actuals; ++i) {
|
453
|
+
/* use linebuf_actuals[i], these are the actuals entries */
|
454
|
+
}
|
455
|
+
dwarf_srclines_dealloc_b(line_context);
|
456
|
+
line_context = 0;
|
457
|
+
linebuf = 0;
|
458
|
+
linecount = 0;
|
459
|
+
linebuf_actuals = 0;
|
460
|
+
linecount_actuals = 0;
|
461
|
+
} else if (sres == DW_DLV_NO_ENTRY) {
|
462
|
+
/* This should be impossible, but do something. */
|
463
|
+
/* Then Free the line_context */
|
464
|
+
dwarf_srclines_dealloc_b(line_context);
|
465
|
+
line_context = 0;
|
466
|
+
linebuf = 0;
|
467
|
+
linecount = 0;
|
468
|
+
linebuf_actuals = 0;
|
469
|
+
linecount_actuals = 0;
|
470
|
+
} else {
|
471
|
+
/* ERROR, show the error or something.
|
472
|
+
Free the line_context. */
|
473
|
+
dwarf_srclines_dealloc_b(line_context);
|
474
|
+
line_context = 0;
|
475
|
+
linebuf = 0;
|
476
|
+
linecount = 0;
|
477
|
+
linebuf_actuals = 0;
|
478
|
+
linecount_actuals = 0;
|
479
|
+
}
|
480
|
+
}
|
481
|
+
}
|
482
|
+
|
483
|
+
void exampled(Dwarf_Debug dbg,Dwarf_Die somedie)
|
484
|
+
{
|
485
|
+
Dwarf_Signed count = 0;
|
486
|
+
Dwarf_Line *linebuf = 0;
|
487
|
+
Dwarf_Signed i = 0;
|
488
|
+
Dwarf_Error error = 0;
|
489
|
+
int sres = 0;
|
490
|
+
|
491
|
+
sres = dwarf_srclines(somedie, &linebuf,&count, &error);
|
492
|
+
if (sres == DW_DLV_OK) {
|
493
|
+
for (i = 0; i < count; ++i) {
|
494
|
+
/* use linebuf[i] */
|
495
|
+
}
|
496
|
+
dwarf_srclines_dealloc(dbg, linebuf, count);
|
497
|
+
}
|
498
|
+
}
|
499
|
+
|
500
|
+
void examplee(Dwarf_Debug dbg,Dwarf_Die somedie)
|
501
|
+
{
|
502
|
+
Dwarf_Signed count = 0;
|
503
|
+
char **srcfiles = 0;
|
504
|
+
Dwarf_Signed i = 0;
|
505
|
+
Dwarf_Error error = 0;
|
506
|
+
int res = 0;
|
507
|
+
|
508
|
+
res = dwarf_srcfiles(somedie, &srcfiles,&count,&error);
|
509
|
+
if (res == DW_DLV_OK) {
|
510
|
+
for (i = 0; i < count; ++i) {
|
511
|
+
/* use srcfiles[i] */
|
512
|
+
dwarf_dealloc(dbg, srcfiles[i], DW_DLA_STRING);
|
513
|
+
}
|
514
|
+
dwarf_dealloc(dbg, srcfiles, DW_DLA_LIST);
|
515
|
+
}
|
516
|
+
}
|
517
|
+
|
518
|
+
void examplef(Dwarf_Debug dbg)
|
519
|
+
{
|
520
|
+
Dwarf_Signed count = 0;
|
521
|
+
Dwarf_Global *globs = 0;
|
522
|
+
Dwarf_Signed i = 0;
|
523
|
+
Dwarf_Error error = 0;
|
524
|
+
int res = 0;
|
525
|
+
|
526
|
+
res = dwarf_get_globals(dbg, &globs,&count, &error);
|
527
|
+
if (res == DW_DLV_OK) {
|
528
|
+
for (i = 0; i < count; ++i) {
|
529
|
+
/* use globs[i] */
|
530
|
+
}
|
531
|
+
dwarf_globals_dealloc(dbg, globs, count);
|
532
|
+
}
|
533
|
+
}
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
void exampleg(Dwarf_Debug dbg)
|
538
|
+
{
|
539
|
+
Dwarf_Error error = 0;
|
540
|
+
Dwarf_Signed count = 0;
|
541
|
+
Dwarf_Type *types = 0;
|
542
|
+
Dwarf_Signed i = 0;
|
543
|
+
int res = 0;
|
544
|
+
|
545
|
+
res = dwarf_get_pubtypes(dbg, &types,&count, &error);
|
546
|
+
if (res == DW_DLV_OK) {
|
547
|
+
for (i = 0; i < count; ++i) {
|
548
|
+
/* use types[i] */
|
549
|
+
}
|
550
|
+
dwarf_types_dealloc(dbg, types, count);
|
551
|
+
}
|
552
|
+
}
|
553
|
+
|
554
|
+
void exampleh(Dwarf_Debug dbg)
|
555
|
+
{
|
556
|
+
Dwarf_Error error = 0;
|
557
|
+
Dwarf_Signed count = 0;
|
558
|
+
Dwarf_Weak *weaks = 0;
|
559
|
+
Dwarf_Signed i = 0;
|
560
|
+
int res = 0;
|
561
|
+
|
562
|
+
res = dwarf_get_weaks(dbg, &weaks, &count, &error);
|
563
|
+
if (res == DW_DLV_OK) {
|
564
|
+
for (i = 0; i < count; ++i) {
|
565
|
+
/* use weaks[i] */
|
566
|
+
}
|
567
|
+
dwarf_weaks_dealloc(dbg, weaks, count);
|
568
|
+
}
|
569
|
+
}
|
570
|
+
|
571
|
+
void examplei(Dwarf_Debug dbg)
|
572
|
+
{
|
573
|
+
Dwarf_Error error = 0;
|
574
|
+
Dwarf_Signed count = 0;
|
575
|
+
Dwarf_Weak *weaks = 0;
|
576
|
+
Dwarf_Signed i = 0;
|
577
|
+
int res = 0;
|
578
|
+
|
579
|
+
res = dwarf_get_weaks(dbg, &weaks, &count, &error);
|
580
|
+
if (res == DW_DLV_OK) {
|
581
|
+
/* OBSOLETE: do not use dealloc for this.
|
582
|
+
See above */
|
583
|
+
for (i = 0; i < count; ++i) {
|
584
|
+
/* use weaks[i] */
|
585
|
+
dwarf_dealloc(dbg, weaks[i], DW_DLA_WEAK);
|
586
|
+
}
|
587
|
+
dwarf_dealloc(dbg, weaks, DW_DLA_LIST);
|
588
|
+
}
|
589
|
+
}
|
590
|
+
|
591
|
+
void examplej(Dwarf_Debug dbg)
|
592
|
+
{
|
593
|
+
Dwarf_Error error = 0;
|
594
|
+
Dwarf_Signed count = 0;
|
595
|
+
Dwarf_Func *funcs = 0;
|
596
|
+
Dwarf_Signed i = 0;
|
597
|
+
int fres = 0;
|
598
|
+
|
599
|
+
fres = dwarf_get_funcs(dbg, &funcs, &count, &error);
|
600
|
+
if (fres == DW_DLV_OK) {
|
601
|
+
for (i = 0; i < count; ++i) {
|
602
|
+
/* use funcs[i] */
|
603
|
+
}
|
604
|
+
dwarf_funcs_dealloc(dbg, funcs, count);
|
605
|
+
}
|
606
|
+
}
|
607
|
+
|
608
|
+
void examplek(Dwarf_Debug dbg)
|
609
|
+
{
|
610
|
+
Dwarf_Error error = 0;
|
611
|
+
Dwarf_Func *funcs = 0;
|
612
|
+
Dwarf_Signed count = 0;
|
613
|
+
Dwarf_Signed i = 0;
|
614
|
+
int fres = 0;
|
615
|
+
|
616
|
+
fres = dwarf_get_funcs(dbg, &funcs,&count, &error);
|
617
|
+
if (fres == DW_DLV_OK) {
|
618
|
+
/* OBSOLETE: see dwarf_funcs_dealloc() above */
|
619
|
+
for (i = 0; i < count; ++i) {
|
620
|
+
/* use funcs[i] */
|
621
|
+
dwarf_dealloc(dbg, funcs[i], DW_DLA_FUNC);
|
622
|
+
}
|
623
|
+
dwarf_dealloc(dbg, funcs, DW_DLA_LIST);
|
624
|
+
}
|
625
|
+
}
|
626
|
+
|
627
|
+
void examplel(Dwarf_Debug dbg)
|
628
|
+
{
|
629
|
+
Dwarf_Error error = 0;
|
630
|
+
Dwarf_Signed count = 0;
|
631
|
+
Dwarf_Type *types = 0;
|
632
|
+
Dwarf_Signed i = 0;
|
633
|
+
int res = 0;
|
634
|
+
|
635
|
+
res = dwarf_get_types(dbg, &types,&count, &error);
|
636
|
+
if (res == DW_DLV_OK) {
|
637
|
+
for (i = 0; i < count; ++i) {
|
638
|
+
/* use types[i] */
|
639
|
+
}
|
640
|
+
dwarf_types_dealloc(dbg, types, count);
|
641
|
+
}
|
642
|
+
}
|
643
|
+
|
644
|
+
void examplem(Dwarf_Debug dbg)
|
645
|
+
{
|
646
|
+
Dwarf_Error error = 0;
|
647
|
+
Dwarf_Signed count = 0;
|
648
|
+
Dwarf_Type *types = 0;
|
649
|
+
Dwarf_Signed i = 0;
|
650
|
+
int res = 0;
|
651
|
+
|
652
|
+
/* OBSOLETE: see dwarf_types_dealloc() above */
|
653
|
+
res = dwarf_get_types(dbg, &types,&count, &error);
|
654
|
+
if (res == DW_DLV_OK) {
|
655
|
+
for (i = 0; i < count; ++i) {
|
656
|
+
/* use types[i] */
|
657
|
+
dwarf_dealloc(dbg, types[i], DW_DLA_TYPENAME);
|
658
|
+
}
|
659
|
+
dwarf_dealloc(dbg, types, DW_DLA_LIST);
|
660
|
+
}
|
661
|
+
}
|
662
|
+
|
663
|
+
void examplen(Dwarf_Debug dbg)
|
664
|
+
{
|
665
|
+
Dwarf_Error error = 0;
|
666
|
+
Dwarf_Signed count = 0;
|
667
|
+
Dwarf_Var *vars = 0;
|
668
|
+
Dwarf_Signed i = 0;
|
669
|
+
int res = 0;
|
670
|
+
res = dwarf_get_vars(dbg, &vars,&count,&error);
|
671
|
+
if (res == DW_DLV_OK) {
|
672
|
+
for (i = 0; i < count; ++i) {
|
673
|
+
/* use vars[i] */
|
674
|
+
}
|
675
|
+
dwarf_vars_dealloc(dbg, vars, count);
|
676
|
+
}
|
677
|
+
}
|
678
|
+
|
679
|
+
|
680
|
+
void exampleo(Dwarf_Debug dbg)
|
681
|
+
{
|
682
|
+
Dwarf_Error error = 0;
|
683
|
+
Dwarf_Signed count = 0;
|
684
|
+
Dwarf_Var *vars = 0;
|
685
|
+
Dwarf_Signed i = 0;
|
686
|
+
int res = 0;
|
687
|
+
res = dwarf_get_vars(dbg, &vars,&count,&error);
|
688
|
+
if (res == DW_DLV_OK) {
|
689
|
+
/* DO NOT USE: see dwarf_vars_dealloc() above */
|
690
|
+
for (i = 0; i < count; ++i) {
|
691
|
+
/* use vars[i] */
|
692
|
+
dwarf_dealloc(dbg, vars[i], DW_DLA_VAR);
|
693
|
+
}
|
694
|
+
dwarf_dealloc(dbg, vars, DW_DLA_LIST);
|
695
|
+
}
|
696
|
+
}
|
697
|
+
|
698
|
+
|
699
|
+
|
700
|
+
void examplep(Dwarf_Debug dbg, Dwarf_Off cur_off)
|
701
|
+
{
|
702
|
+
Dwarf_Error error = 0;
|
703
|
+
Dwarf_Signed count = 0;
|
704
|
+
Dwarf_Macro_Details *maclist = 0;
|
705
|
+
Dwarf_Signed i = 0;
|
706
|
+
Dwarf_Unsigned max = 500000; /* sanity limit */
|
707
|
+
int errv = 0;
|
708
|
+
|
709
|
+
/* Given an offset from a compilation unit,
|
710
|
+
start at that offset (from DW_AT_macroinfo)
|
711
|
+
and get its macro details. */
|
712
|
+
errv = dwarf_get_macro_details(dbg, cur_off,max,
|
713
|
+
&count,&maclist,&error);
|
714
|
+
if (errv == DW_DLV_OK) {
|
715
|
+
for (i = 0; i < count; ++i) {
|
716
|
+
/* use maclist[i] */
|
717
|
+
}
|
718
|
+
dwarf_dealloc(dbg, maclist, DW_DLA_STRING);
|
719
|
+
}
|
720
|
+
/* Loop through all the compilation units macro info from zero.
|
721
|
+
This is not guaranteed to work because DWARF does not
|
722
|
+
guarantee every byte in the section is meaningful:
|
723
|
+
there can be garbage between the macro info
|
724
|
+
for CUs. But this loop will sometimes work.
|
725
|
+
*/
|
726
|
+
cur_off = 0;
|
727
|
+
while((errv = dwarf_get_macro_details(dbg, cur_off,max,
|
728
|
+
&count,&maclist,&error))== DW_DLV_OK) {
|
729
|
+
for (i = 0; i < count; ++i) {
|
730
|
+
/* use maclist[i] */
|
731
|
+
}
|
732
|
+
cur_off = maclist[count-1].dmd_offset + 1;
|
733
|
+
dwarf_dealloc(dbg, maclist, DW_DLA_STRING);
|
734
|
+
}
|
735
|
+
}
|
736
|
+
|
737
|
+
void exampleq(Dwarf_Debug dbg)
|
738
|
+
{
|
739
|
+
Dwarf_Cie *cie_data = 0;
|
740
|
+
Dwarf_Signed cie_count = 0;
|
741
|
+
Dwarf_Fde *fde_data = 0;
|
742
|
+
Dwarf_Signed fde_count = 0;
|
743
|
+
Dwarf_Error error = 0;
|
744
|
+
int fres = 0;
|
745
|
+
|
746
|
+
fres = dwarf_get_fde_list(dbg,&cie_data,&cie_count,
|
747
|
+
&fde_data,&fde_count,&error);
|
748
|
+
if (fres == DW_DLV_OK) {
|
749
|
+
dwarf_fde_cie_list_dealloc(dbg, cie_data, cie_count,
|
750
|
+
fde_data,fde_count);
|
751
|
+
}
|
752
|
+
}
|
753
|
+
|
754
|
+
/* OBSOLETE EXAMPLE */
|
755
|
+
void exampleqb(Dwarf_Debug dbg)
|
756
|
+
{
|
757
|
+
Dwarf_Signed count = 0;
|
758
|
+
Dwarf_Cie *cie_data = 0;
|
759
|
+
Dwarf_Signed cie_count = 0;
|
760
|
+
Dwarf_Fde *fde_data = 0;
|
761
|
+
Dwarf_Signed fde_count = 0;
|
762
|
+
Dwarf_Error error = 0;
|
763
|
+
Dwarf_Signed i = 0;
|
764
|
+
int fres = 0;
|
765
|
+
|
766
|
+
fres = dwarf_get_fde_list(dbg,&cie_data,&cie_count,
|
767
|
+
&fde_data,&fde_count,&error);
|
768
|
+
if (fres == DW_DLV_OK) {
|
769
|
+
for (i = 0; i < cie_count; ++i) {
|
770
|
+
/* use cie[i] */
|
771
|
+
dwarf_dealloc(dbg, cie_data[i], DW_DLA_CIE);
|
772
|
+
}
|
773
|
+
for (i = 0; i < fde_count; ++i) {
|
774
|
+
/* use fde[i] */
|
775
|
+
dwarf_dealloc(dbg, fde_data[i], DW_DLA_FDE);
|
776
|
+
}
|
777
|
+
dwarf_dealloc(dbg, cie_data, DW_DLA_LIST);
|
778
|
+
dwarf_dealloc(dbg, fde_data, DW_DLA_LIST);
|
779
|
+
}
|
780
|
+
}
|
781
|
+
|
782
|
+
|
783
|
+
void exampler(Dwarf_Debug dbg,Dwarf_Addr mypcval)
|
784
|
+
{
|
785
|
+
/* Given a pc value
|
786
|
+
for a function find the FDE and CIE data for
|
787
|
+
the function.
|
788
|
+
Example shows basic access to FDE/CIE plus
|
789
|
+
one way to access details given a PC value.
|
790
|
+
dwarf_get_fde_n() allows accessing all FDE/CIE
|
791
|
+
data so one could build up an application-specific
|
792
|
+
table of information if that is more useful. */
|
793
|
+
Dwarf_Signed count = 0;
|
794
|
+
Dwarf_Cie *cie_data = 0;
|
795
|
+
Dwarf_Signed cie_count = 0;
|
796
|
+
Dwarf_Fde *fde_data = 0;
|
797
|
+
Dwarf_Signed fde_count = 0;
|
798
|
+
Dwarf_Error error = 0;
|
799
|
+
int fres = 0;
|
800
|
+
|
801
|
+
fres = dwarf_get_fde_list_eh(dbg,&cie_data,&cie_count,
|
802
|
+
&fde_data,&fde_count,&error);
|
803
|
+
if (fres == DW_DLV_OK) {
|
804
|
+
Dwarf_Fde myfde = 0;
|
805
|
+
Dwarf_Addr low_pc = 0;
|
806
|
+
Dwarf_Addr high_pc = 0;
|
807
|
+
fres = dwarf_get_fde_at_pc(fde_data,mypcval,
|
808
|
+
&myfde,&low_pc,&high_pc,
|
809
|
+
&error);
|
810
|
+
if (fres == DW_DLV_OK) {
|
811
|
+
Dwarf_Cie mycie = 0;
|
812
|
+
fres = dwarf_get_cie_of_fde(myfde,&mycie,&error);
|
813
|
+
if (fres == DW_DLV_OK) {
|
814
|
+
/* Now we can access a range of information
|
815
|
+
about the fde and cie applicable. */
|
816
|
+
}
|
817
|
+
}
|
818
|
+
dwarf_fde_cie_list_dealloc(dbg, cie_data, cie_count,
|
819
|
+
fde_data,fde_count);
|
820
|
+
}
|
821
|
+
/* ERROR or NO ENTRY. Do something */
|
822
|
+
}
|
823
|
+
|
824
|
+
void examples(Dwarf_Debug dbg,Dwarf_Cie cie,
|
825
|
+
Dwarf_Ptr instruction,Dwarf_Unsigned len)
|
826
|
+
{
|
827
|
+
Dwarf_Signed count = 0;
|
828
|
+
Dwarf_Frame_Op *frameops = 0;
|
829
|
+
Dwarf_Error error = 0;
|
830
|
+
int res = 0;
|
831
|
+
|
832
|
+
res = dwarf_expand_frame_instructions(cie,instruction,len,
|
833
|
+
&frameops,&count, &error);
|
834
|
+
if (res == DW_DLV_OK) {
|
835
|
+
Dwarf_Signed i = 0;
|
836
|
+
|
837
|
+
for (i = 0; i < count; ++i) {
|
838
|
+
/* use frameops[i] */
|
839
|
+
}
|
840
|
+
dwarf_dealloc(dbg, frameops, DW_DLA_FRAME_BLOCK);
|
841
|
+
}
|
842
|
+
}
|
843
|
+
|
844
|
+
void examplet(Dwarf_Debug dbg,Dwarf_Unsigned offset)
|
845
|
+
{
|
846
|
+
/* Looping through the dwarf_loc section finding loclists:
|
847
|
+
an example. */
|
848
|
+
int res;
|
849
|
+
Dwarf_Unsigned next_entry = 0;
|
850
|
+
Dwarf_Addr hipc_off = 0;
|
851
|
+
Dwarf_Addr lowpc_off = 0;
|
852
|
+
Dwarf_Ptr data = 0;
|
853
|
+
Dwarf_Unsigned entry_len = 0;
|
854
|
+
Dwarf_Error err = 0;
|
855
|
+
|
856
|
+
for(;;) {
|
857
|
+
res = dwarf_get_loclist_entry(dbg,offset,&hipc_off,
|
858
|
+
&lowpc_off, &data, &entry_len,&next_entry,&err);
|
859
|
+
if (res == DW_DLV_OK) {
|
860
|
+
/* A valid entry. */
|
861
|
+
offset = next_entry;
|
862
|
+
continue;
|
863
|
+
} else if (res ==DW_DLV_NO_ENTRY) {
|
864
|
+
/* Done! */
|
865
|
+
break;
|
866
|
+
} else {
|
867
|
+
/* Error! */
|
868
|
+
break;
|
869
|
+
}
|
870
|
+
}
|
871
|
+
}
|
872
|
+
|
873
|
+
void exampleu(Dwarf_Debug dbg)
|
874
|
+
{
|
875
|
+
Dwarf_Signed count = 0;
|
876
|
+
Dwarf_Arange *arang = 0;
|
877
|
+
int res = 0;
|
878
|
+
Dwarf_Error error = 0;
|
879
|
+
|
880
|
+
res = dwarf_get_aranges(dbg, &arang,&count, &error);
|
881
|
+
if (res == DW_DLV_OK) {
|
882
|
+
Dwarf_Signed i = 0;
|
883
|
+
|
884
|
+
for (i = 0; i < count; ++i) {
|
885
|
+
/* use arang[i] */
|
886
|
+
dwarf_dealloc(dbg, arang[i], DW_DLA_ARANGE);
|
887
|
+
}
|
888
|
+
dwarf_dealloc(dbg, arang, DW_DLA_LIST);
|
889
|
+
}
|
890
|
+
}
|
891
|
+
void examplev(Dwarf_Debug dbg,Dwarf_Unsigned offset,Dwarf_Die die)
|
892
|
+
{
|
893
|
+
Dwarf_Signed count = 0;
|
894
|
+
Dwarf_Ranges *ranges = 0;
|
895
|
+
Dwarf_Unsigned bytes = 0;
|
896
|
+
Dwarf_Error error = 0;
|
897
|
+
int res = 0;
|
898
|
+
res = dwarf_get_ranges_a(dbg,offset,die,
|
899
|
+
&ranges,&count,&bytes,&error);
|
900
|
+
if (res == DW_DLV_OK) {
|
901
|
+
Dwarf_Signed i;
|
902
|
+
for( i = 0; i < count; ++i ) {
|
903
|
+
Dwarf_Ranges *cur = ranges+i;
|
904
|
+
/* Use cur. */
|
905
|
+
}
|
906
|
+
dwarf_ranges_dealloc(dbg,ranges,count);
|
907
|
+
}
|
908
|
+
}
|
909
|
+
void examplew(Dwarf_Debug dbg,Dwarf_Unsigned offset,Dwarf_Die die)
|
910
|
+
{
|
911
|
+
Dwarf_Gdbindex gindexptr = 0;
|
912
|
+
Dwarf_Unsigned version = 0;
|
913
|
+
Dwarf_Unsigned cu_list_offset = 0;
|
914
|
+
Dwarf_Unsigned types_cu_list_offset = 0;
|
915
|
+
Dwarf_Unsigned address_area_offset = 0;
|
916
|
+
Dwarf_Unsigned symbol_table_offset = 0;
|
917
|
+
Dwarf_Unsigned constant_pool_offset = 0;
|
918
|
+
Dwarf_Unsigned section_size = 0;
|
919
|
+
Dwarf_Unsigned reserved = 0;
|
920
|
+
Dwarf_Error error = 0;
|
921
|
+
const char * section_name = 0;
|
922
|
+
int res = 0;
|
923
|
+
res = dwarf_gdbindex_header(dbg,&gindexptr,
|
924
|
+
&version,&cu_list_offset, &types_cu_list_offset,
|
925
|
+
&address_area_offset,&symbol_table_offset,
|
926
|
+
&constant_pool_offset, §ion_size,
|
927
|
+
&reserved,§ion_name,&error);
|
928
|
+
if (res == DW_DLV_NO_ENTRY) {
|
929
|
+
return;
|
930
|
+
} else if (res == DW_DLV_ERROR) {
|
931
|
+
return;
|
932
|
+
}
|
933
|
+
{
|
934
|
+
/* do something with the data */
|
935
|
+
Dwarf_Unsigned length = 0;
|
936
|
+
Dwarf_Unsigned typeslength = 0;
|
937
|
+
Dwarf_Unsigned i = 0;
|
938
|
+
res = dwarf_gdbindex_culist_array(gindexptr,
|
939
|
+
&length,&error);
|
940
|
+
/* Example actions. */
|
941
|
+
if (res == DW_DLV_OK) {
|
942
|
+
for(i = 0; i < length; ++i) {
|
943
|
+
Dwarf_Unsigned cuoffset = 0;
|
944
|
+
Dwarf_Unsigned culength = 0;
|
945
|
+
res = dwarf_gdbindex_culist_entry(gindexptr,
|
946
|
+
i,&cuoffset,&culength,&error);
|
947
|
+
if (res == DW_DLV_OK) {
|
948
|
+
/* Do something with cuoffset, culength */
|
949
|
+
}
|
950
|
+
}
|
951
|
+
}
|
952
|
+
res = dwarf_gdbindex_types_culist_array(gindexptr,
|
953
|
+
&typeslength,&error);
|
954
|
+
if (res == DW_DLV_OK) {
|
955
|
+
for(i = 0; i < typeslength; ++i) {
|
956
|
+
Dwarf_Unsigned cuoffset = 0;
|
957
|
+
Dwarf_Unsigned tuoffset = 0;
|
958
|
+
Dwarf_Unsigned culength = 0;
|
959
|
+
Dwarf_Unsigned type_signature = 0;
|
960
|
+
res = dwarf_gdbindex_types_culist_entry(gindexptr,
|
961
|
+
i,&cuoffset,&tuoffset,&type_signature,&error);
|
962
|
+
if (res == DW_DLV_OK) {
|
963
|
+
/* Do something with cuoffset etc. */
|
964
|
+
}
|
965
|
+
}
|
966
|
+
}
|
967
|
+
dwarf_gdbindex_free(gindexptr);
|
968
|
+
}
|
969
|
+
}
|
970
|
+
void examplewgdbindex(Dwarf_Gdbindex gdbindex)
|
971
|
+
{
|
972
|
+
Dwarf_Unsigned list_len = 0;
|
973
|
+
Dwarf_Unsigned i = 0;
|
974
|
+
int res = 0;
|
975
|
+
Dwarf_Error err = 0;
|
976
|
+
|
977
|
+
res = dwarf_gdbindex_addressarea(gdbindex, &list_len,&err);
|
978
|
+
if (res != DW_DLV_OK) {
|
979
|
+
/* Something wrong, ignore the addressarea */
|
980
|
+
}
|
981
|
+
/* Iterate through the address area. */
|
982
|
+
for( i = 0; i < list_len; i++) {
|
983
|
+
Dwarf_Unsigned lowpc = 0;
|
984
|
+
Dwarf_Unsigned highpc = 0;
|
985
|
+
Dwarf_Unsigned cu_index,
|
986
|
+
res = dwarf_gdbindex_addressarea_entry(gdbindex,i,
|
987
|
+
&lowpc,&highpc,
|
988
|
+
&cu_index,
|
989
|
+
&err);
|
990
|
+
if (res != DW_DLV_OK) {
|
991
|
+
/* Something wrong, ignore the addressarea */
|
992
|
+
return;
|
993
|
+
}
|
994
|
+
/* We have a valid address area entry, do something
|
995
|
+
with it. */
|
996
|
+
}
|
997
|
+
}
|
998
|
+
void examplex(Dwarf_Gdbindex gdbindex)
|
999
|
+
{
|
1000
|
+
Dwarf_Unsigned symtab_list_length = 0;
|
1001
|
+
Dwarf_Unsigned i = 0;
|
1002
|
+
Dwarf_Error err = 0;
|
1003
|
+
int res = 0;
|
1004
|
+
|
1005
|
+
res = dwarf_gdbindex_symboltable_array(gdbindex,
|
1006
|
+
&symtab_list_length,&err);
|
1007
|
+
if (res != DW_DLV_OK) {
|
1008
|
+
return;
|
1009
|
+
}
|
1010
|
+
for( i = 0; i < symtab_list_length; i++) {
|
1011
|
+
Dwarf_Unsigned symnameoffset = 0;
|
1012
|
+
Dwarf_Unsigned cuvecoffset = 0;
|
1013
|
+
Dwarf_Unsigned cuvec_len = 0;
|
1014
|
+
Dwarf_Unsigned ii = 0;
|
1015
|
+
const char *name = 0;
|
1016
|
+
res = dwarf_gdbindex_symboltable_entry(gdbindex,i,
|
1017
|
+
&symnameoffset,&cuvecoffset,
|
1018
|
+
&err);
|
1019
|
+
if (res != DW_DLV_OK) {
|
1020
|
+
return;
|
1021
|
+
}
|
1022
|
+
res = dwarf_gdbindex_string_by_offset(gdbindex,
|
1023
|
+
symnameoffset,&name,&err);
|
1024
|
+
if(res != DW_DLV_OK) {
|
1025
|
+
return;
|
1026
|
+
}
|
1027
|
+
res = dwarf_gdbindex_cuvector_length(gdbindex,
|
1028
|
+
cuvecoffset,&cuvec_len,&err);
|
1029
|
+
if( res != DW_DLV_OK) {
|
1030
|
+
return;
|
1031
|
+
}
|
1032
|
+
for(ii = 0; ii < cuvec_len; ++ii ) {
|
1033
|
+
Dwarf_Unsigned attributes = 0;
|
1034
|
+
Dwarf_Unsigned cu_index = 0;
|
1035
|
+
Dwarf_Unsigned reserved1 = 0;
|
1036
|
+
Dwarf_Unsigned symbol_kind = 0;
|
1037
|
+
Dwarf_Unsigned is_static = 0;
|
1038
|
+
|
1039
|
+
res = dwarf_gdbindex_cuvector_inner_attributes(
|
1040
|
+
gdbindex,cuvecoffset,ii,
|
1041
|
+
&attributes,&err);
|
1042
|
+
if( res != DW_DLV_OK) {
|
1043
|
+
return;
|
1044
|
+
}
|
1045
|
+
/* 'attributes' is a value with various internal
|
1046
|
+
fields so we expand the fields. */
|
1047
|
+
res = dwarf_gdbindex_cuvector_instance_expand_value(gdbindex,
|
1048
|
+
attributes, &cu_index,&reserved1,&symbol_kind, &is_static,
|
1049
|
+
&err);
|
1050
|
+
if( res != DW_DLV_OK) {
|
1051
|
+
return;
|
1052
|
+
}
|
1053
|
+
/* Do something with the attributes. */
|
1054
|
+
}
|
1055
|
+
}
|
1056
|
+
}
|
1057
|
+
|
1058
|
+
void exampley(Dwarf_Debug dbg, const char *type)
|
1059
|
+
{
|
1060
|
+
/* type is "tu" or "cu" */
|
1061
|
+
int res = 0;
|
1062
|
+
Dwarf_Xu_Index_Header xuhdr = 0;
|
1063
|
+
Dwarf_Unsigned version_number = 0;
|
1064
|
+
Dwarf_Unsigned offsets_count = 0; /*L */
|
1065
|
+
Dwarf_Unsigned units_count = 0; /* M */
|
1066
|
+
Dwarf_Unsigned hash_slots_count = 0; /* N */
|
1067
|
+
Dwarf_Error err = 0;
|
1068
|
+
const char * ret_type = 0;
|
1069
|
+
const char * section_name = 0;
|
1070
|
+
|
1071
|
+
res = dwarf_get_xu_index_header(dbg,
|
1072
|
+
type,
|
1073
|
+
&xuhdr,
|
1074
|
+
&version_number,
|
1075
|
+
&offsets_count,
|
1076
|
+
&units_count,
|
1077
|
+
&hash_slots_count,
|
1078
|
+
§ion_name,
|
1079
|
+
&err);
|
1080
|
+
if (res == DW_DLV_NO_ENTRY) {
|
1081
|
+
/* No such section. */
|
1082
|
+
return;
|
1083
|
+
}
|
1084
|
+
if (res == DW_DLV_ERROR) {
|
1085
|
+
/* Something wrong. */
|
1086
|
+
return;
|
1087
|
+
}
|
1088
|
+
/* Do something with the xuhdr here . */
|
1089
|
+
dwarf_xu_header_free(xuhdr);
|
1090
|
+
}
|
1091
|
+
|
1092
|
+
void examplez( Dwarf_Xu_Index_Header xuhdr,
|
1093
|
+
Dwarf_Unsigned hash_slots_count)
|
1094
|
+
{
|
1095
|
+
/* hash_slots_count returned by
|
1096
|
+
dwarf_get_xu_index_header(), see above. */
|
1097
|
+
static Dwarf_Sig8 zerohashval;
|
1098
|
+
|
1099
|
+
Dwarf_Error err = 0;
|
1100
|
+
Dwarf_Unsigned h = 0;
|
1101
|
+
|
1102
|
+
for( h = 0; h < hash_slots_count; h++) {
|
1103
|
+
Dwarf_Sig8 hashval;
|
1104
|
+
Dwarf_Unsigned index = 0;
|
1105
|
+
Dwarf_Unsigned col = 0;
|
1106
|
+
int res = 0;
|
1107
|
+
|
1108
|
+
res = dwarf_get_xu_hash_entry(xuhdr,h,
|
1109
|
+
&hashval,&index,&err);
|
1110
|
+
if (res == DW_DLV_ERROR) {
|
1111
|
+
/* Oops. hash_slots_count wrong. */
|
1112
|
+
return;
|
1113
|
+
} else if (res == DW_DLV_NO_ENTRY) {
|
1114
|
+
/* Impossible */
|
1115
|
+
return;
|
1116
|
+
} else if (!memcmp(&hashval,&zerohashval,sizeof(Dwarf_Sig8))
|
1117
|
+
&& index == 0 ) {
|
1118
|
+
/* An unused hash slot */
|
1119
|
+
continue;
|
1120
|
+
}
|
1121
|
+
/* Here, hashval and index (a row index into offsets and lengths)
|
1122
|
+
are valid. */
|
1123
|
+
}
|
1124
|
+
}
|
1125
|
+
|
1126
|
+
void exampleza(Dwarf_Xu_Index_Header xuhdr,
|
1127
|
+
Dwarf_Unsigned offsets_count, Dwarf_Unsigned index )
|
1128
|
+
{
|
1129
|
+
Dwarf_Error err = 0;
|
1130
|
+
Dwarf_Unsigned col = 0;
|
1131
|
+
/* We use 'offsets_count' returned by
|
1132
|
+
a dwarf_get_xu_index_header() call.
|
1133
|
+
We use 'index' returned by a
|
1134
|
+
dwarf_get_xu_hash_entry() call. */
|
1135
|
+
for (col = 0; col < offsets_count; col++) {
|
1136
|
+
Dwarf_Unsigned off = 0;
|
1137
|
+
Dwarf_Unsigned len = 0;
|
1138
|
+
const char * name = 0;
|
1139
|
+
Dwarf_Unsigned num = 0;
|
1140
|
+
int res = 0;
|
1141
|
+
|
1142
|
+
res = dwarf_get_xu_section_names(xuhdr,
|
1143
|
+
col,&num,&name,&err);
|
1144
|
+
if (res != DW_DLV_OK) {
|
1145
|
+
break;
|
1146
|
+
}
|
1147
|
+
res = dwarf_get_xu_section_offset(xuhdr,
|
1148
|
+
index,col,&off,&len,&err);
|
1149
|
+
if (res != DW_DLV_OK) {
|
1150
|
+
break;
|
1151
|
+
}
|
1152
|
+
/* Here we have the DW_SECT_ name and number
|
1153
|
+
and the base offset and length of the
|
1154
|
+
section data applicable to the hash
|
1155
|
+
that got us here.
|
1156
|
+
Use the values.*/
|
1157
|
+
}
|
1158
|
+
}
|
1159
|
+
|
1160
|
+
void examplezb(void)
|
1161
|
+
{
|
1162
|
+
const char * out = 0;
|
1163
|
+
int res = 0;
|
1164
|
+
|
1165
|
+
/* The following is wrong, do not do it! */
|
1166
|
+
res = dwarf_get_ACCESS_name(DW_TAG_entry_point,&out);
|
1167
|
+
/* Nothing one does here with 'res' or 'out'
|
1168
|
+
is meaningful. */
|
1169
|
+
|
1170
|
+
/* The following is meaningful.*/
|
1171
|
+
res = dwarf_get_TAG_name(DW_TAG_entry_point,&out);
|
1172
|
+
if( res == DW_DLV_OK) {
|
1173
|
+
/* Here 'out' is a pointer one can use which
|
1174
|
+
points to the string "DW_TAG_entry_point". */
|
1175
|
+
} else {
|
1176
|
+
/* Here 'out' has not been touched, it is
|
1177
|
+
uninitialized. Do not use it. */
|
1178
|
+
}
|
1179
|
+
}
|