| 1 |
June 22, 2021. |
| 2 |
If ./configure is absent type |
| 3 |
./autogen.sh |
| 4 |
(you will need to have installed autoconf, automake |
| 5 |
and libtool for autogen.sh to work) |
| 6 |
To build libdwarf.a, type |
| 7 |
./configure |
| 8 |
make |
| 9 |
To build libdwarf.so, type |
| 10 |
./configure --enable-shared --disable-static |
| 11 |
make |
| 12 |
To build both, type |
| 13 |
./configure --enable-shared |
| 14 |
make |
| 15 |
|
| 16 |
======= |
| 17 |
April 16, 2017: Some people have had build problems, getting |
| 18 |
errors like: |
| 19 |
"dwarf_elf_access.c:238:21: warning: assignment makes |
| 20 |
pointer from integer without a cast [enabled by default] |
| 21 |
if ((ehdr_ident = elf_getident(elf, NULL)) == NULL) {" |
| 22 |
That suggests that the libelf headers needed are missing. |
| 23 |
On Ubuntu the command 'sudo apt-get install libelf-dev' |
| 24 |
should solve this problem. |
| 25 |
|
| 26 |
|
| 27 |
January 30, 2013: libdwarf.h is no longer in the distribution, |
| 28 |
but libdwarf.h.in is identical to libdwarf.h. 'configure' |
| 29 |
copies libdwarf.h.in to libdwarf.h and whether libelf.h defines |
| 30 |
'struct _Elf' or 'struct Elf' configure attempts to create |
| 31 |
libdwarf.h appropriately. |
| 32 |
|
| 33 |
No real install target is provided here, so 'make install' does |
| 34 |
not do much. One can copy either or both of libdwarf.a libdwarf.so |
| 35 |
to somewhere fairly standard (but intended for software you build) |
| 36 |
like '/usr/local/lib'. Or anywhere else you want to copy it. |
| 37 |
|
| 38 |
To use dwarf or libdwarf, you may want to copy dwarf.h and |
| 39 |
a generated libdwarf.h somewhere convenient |
| 40 |
(possibly /usr/local/include), |
| 41 |
and you may need to copy the libdwarf to a convenient spot |
| 42 |
(/usr/local/lib is a traditional place for libraries one builds |
| 43 |
oneself on Unix and Linux). |
| 44 |
This copying is not needed to build dwarfdump. |
| 45 |
|
| 46 |
|
| 47 |
Multi Threading, or using threads with libdwarf (Thread Safety): |
| 48 |
Nothing in libdwarf does any locking. Every Dwarf_Debug |
| 49 |
(such as returned by dwarf_init()) is fully independent |
| 50 |
of all other Dwarf_Debug-s. However, calls to libdwarf can |
| 51 |
change a Dwarf_Debug. So it is unsafe to have two different |
| 52 |
threads accessing a single Dwarf_Debug simultaneously. |
| 53 |
It is therefore sufficient to ensure than any one Dwarf_Debug |
| 54 |
is only accessed from a single thread. |
| 55 |
|
| 56 |
Warnings like |
| 57 |
"warning: cast from pointer to integer of different size" |
| 58 |
at compile time are to be expected in dwarf_frame.c and |
| 59 |
dwarf_frame2.c. Do not be alarmed. |
| 60 |
|
| 61 |
Warnings like |
| 62 |
"warning: passing argument 1 of ‘dbg->de_callback_func_c’ |
| 63 |
discards ‘const’ qualifier from pointer target type |
| 64 |
[enabled by default]" at compile time are to be expected in |
| 65 |
some pro*.c source files. Fixing the public prototype could |
| 66 |
cause some producer-library user's code to fail to compile |
| 67 |
so we live with the warnings. |
| 68 |
|
| 69 |
When cross-compiling, gennames has to be built by the |
| 70 |
native compiler. So try |
| 71 |
make HOSTCC=cc gennames |
| 72 |
as a first step before the normal make. |
| 73 |
|
| 74 |
|
| 75 |
If your headers are not in the expected places, |
| 76 |
use the make command line to add flags and include directories. |
| 77 |
For example |
| 78 |
./configure |
| 79 |
PREINCS="-I /usr/local/share/include" POSTINCS="-I /home/x/include" make |
| 80 |
PREINCS content is inserted before CFLAGS as make(1) is running. |
| 81 |
POSTINCS content is added after the CFLAGS value. |
| 82 |
|
| 83 |
To set LDFLAGS (which is used when building a .so and |
| 84 |
in building gennames to create some source here), |
| 85 |
do so at configure time, for example: |
| 86 |
./configure LDFLAGS="-L /var/tmp" |
| 87 |
Or use PRELIBS and/or POSTLIBS at 'make' time similar to the use |
| 88 |
of PREINCS and POSTINCS. |
| 89 |
|
| 90 |
Windows (February 2016): Those wishing to read DWARF2 or |
| 91 |
later from Windows PE files (using Mingw) should take a look at |
| 92 |
https://github.com/jrfonseca/drmingw/tree/master/src/mgwhelp |
| 93 |
which shows simple LGPL code that implements the necessary object |
| 94 |
reading interfaces for PE objects. dwarf_pe.cpp |
| 95 |
fills out the Dwarf_Obj_Access_Methods |
| 96 |
object interface and opens an object |
| 97 |
(see dwarf_object_init()) |
| 98 |
using the PE object access making the full libdwarf API |
| 99 |
available. |
| 100 |
To enable dection of Windows pathnames as full paths |
| 101 |
add --enable-windowspath. Doing this does mean things like |
| 102 |
A:foo and \anything are treated as full paths (these are |
| 103 |
unlikely path names on a POSIX system but are legal |
| 104 |
POSIX partial paths). |
| 105 |
|
| 106 |
Back to Linux/Unix: |
| 107 |
It is possible to request a shared library (libdwarf.so) build with |
| 108 |
--enable-shared |
| 109 |
To turn off the build of the archive library (libdwarf.a) specify |
| 110 |
--disable-nonshared |
| 111 |
but in this case you must specify --enable-shared or nothing will |
| 112 |
build! |
| 113 |
|
| 114 |
TARGET DEPENDENCIES of .debug_frame: |
| 115 |
dwarf.h |
| 116 |
These should be revised if you have more than the defined |
| 117 |
63 'normal' registers. It's not harmful to have these too large! |
| 118 |
Too small will lead to errors reading .debug_frame and .eh_frame. |
| 119 |
DW_FRAME_HIGHEST_NORMAL_REGISTER |
| 120 |
DW_FRAME_LAST_REG_NUM |
| 121 |
|
| 122 |
These you might revise, but can safely ignore if simply |
| 123 |
using dwarfdump. If using the producer code you will want |
| 124 |
to get these exactly right for your architecture. |
| 125 |
DW_FRAME_RA_COL |
| 126 |
DW_FRAME_STATIC_LINK |
| 127 |
DW_FRAME_CFA_COL |
| 128 |
|
| 129 |
libdwarf.h |
| 130 |
The DW_FRAME_REG_INITIAL_VALUE #define should be set to |
| 131 |
the value appropriate to your architecture. See libdwarf.h |
| 132 |
for details. |
| 133 |
|
| 134 |
If DW_REG_TABLE_SIZE is not set large enough attempts to |
| 135 |
fill in the .debug_frame tables will get an error. |
| 136 |
Should be at least as large as DW_FRAME_LAST_REG_NUM. |
| 137 |
If it's too large nothing is harmed (but some extra space taken |
| 138 |
at run time). |
| 139 |
|
| 140 |
If your printf does not support C standard %llx etc, |
| 141 |
(such as MSWindows with long long), configure |
| 142 |
option --enable-nonstandardprintf |
| 143 |
and defines like DW_PR_DUx etc in libdwarf.h |
| 144 |
provide a way to configure for that relatively easily. |
| 145 |
|
| 146 |
|
| 147 |
The .debug_frame is so very architecture dependent |
| 148 |
and because the host (where libdwarf/dwarfdump are executed) |
| 149 |
and target (the objects read) could be different. |
| 150 |
It's currently not supported to have dwarfdump/libdwarf determine |
| 151 |
the architecture on-the-fly and do-the-right-thing. |
| 152 |
Just setting DW_FRAME_LAST_REG_NUM and DW_FRAME_HIGHEST_NORMAL_REGISTER |
| 153 |
and DW_REG_TABLE_SIZE high enough will likely suffice for most |
| 154 |
purposes and most compilers/architectures.. |
| 155 |
See comments in dwarf.h/libdwarf.h. |
| 156 |
|
| 157 |
It's perfectly safe to ignore the above suggestions as long |
| 158 |
as libdwarf does not get a DW_DLE_DF_REG_NUM_TOO_HIGH error. |
| 159 |
(which would only happen on reading .debug_frame or .eh_frame data). |
| 160 |
|
| 161 |
If you intend to use the libdwarf dwarf-producer code |
| 162 |
for .debug_frame information |
| 163 |
you must do a thorough analysys and revise dwarf.h |
| 164 |
substantially to match the output target architecture. |
| 165 |
|
| 166 |
In general, in the producer code, numbers are copied from and |
| 167 |
to integers with memcpy(). In case of endianness problems, |
| 168 |
constants set in dwarf_producer_init() can fix the problems. |
| 169 |
If one wants to produce a *different-endian* output the best |
| 170 |
solution is to change the integer memcpy calls to call thru a |
| 171 |
new dbg-based function pointer and have it 'do the right thing' |
| 172 |
to adjust endianness. Set the function pointer correctly in |
| 173 |
dwarf_producer_init() and the rest of the code will just call |
| 174 |
thru the function pointer. Tedious work to find and change the |
| 175 |
memcpy calls to be dbg->de_memcpy(), but once done the code is |
| 176 |
no longer endian dependent (right now there is no way to ask |
| 177 |
for cross-endian: a new flag needed or ?). |
| 178 |
|
| 179 |
leb128 numbers are endian-independent, so nothing need be |
| 180 |
done with those for cross-endian support (the storage |
| 181 |
of leb128 on disk is always little-endian). |
| 182 |
|
| 183 |
The .ps files are postscript. So those who cannot deal with mm |
| 184 |
format files but do have a postscript printer (or have |
| 185 |
ghostscript) can print the documents. |
| 186 |
This form was chosen before pdf format existed... |
| 187 |
|
| 188 |
libdwarf2.1.pdf documents a way for a debugger to read dwarf information. |
| 189 |
libdwarf2p.1.pdf documents a way for a compiler to generate dwarf information. |
| 190 |
mips_extensions.ps documents the mips/sgi extensions to dwarf. |
| 191 |
|
| 192 |
See the Makefile for the commands used to build pdf files |
| 193 |
libdwarf.2.1.pdf and libdwarf1p.1.pdf. |
| 194 |
|
| 195 |
pic is a picture processing tool (ATT command). |
| 196 |
tbl is a table-processing tool. |
| 197 |
(part of Documentor's Work Bench on ATT-like systems). |
| 198 |
tbl and pic are available on linux. |
| 199 |
|
| 200 |
psroff is a name for a troff-like processor, part of |
| 201 |
Documentor's Work Bench on IRIX. Substitute a |
| 202 |
troff-like or nroff-like processor (GNU groff works fine). |
| 203 |
|
| 204 |
To use dwarf or libdwarf, you may want to install dwarf.h and |
| 205 |
libdwarf.h somewhere convenient. |
| 206 |
|
| 207 |
You will also need libelf (libelf.a and/or libelf.so) and |
| 208 |
libelf.h installed. These are available from GNU repositories |
| 209 |
and from the normal Linux repositories for Linux releases. |
| 210 |
On Ubuntu Linux for example: |
| 211 |
sudo apt-get install libelf-dev libelf1 |
| 212 |
|
| 213 |
Compiler warnings: |
| 214 |
A few Warnings like: |
| 215 |
dwarf_frame.c:715:29: warning: cast from pointer to integer of different size [- |
| 216 |
Wpointer-to-int-cast] |
| 217 |
dwarf_arange.c:113:13: warning: variable ‘local_extension_size’ set but not used |
| 218 |
[-Wunused-but-set-variable] |
| 219 |
are considered normal. |
| 220 |
|
| 221 |
|
| 222 |
As of January 2013 the code compiles with gcc without |
| 223 |
problems with -Wall and -Wsign-compare |
| 224 |
aside from the warnings hinted at above. |
| 225 |
|
| 226 |
The following gcc/clang options |
| 227 |
have not all been tried as of January 2013, |
| 228 |
but will be as time permits. |
| 229 |
-Wsystem-headers |
| 230 |
-Wall -Wsign-compare |
| 231 |
-Wno-format-y2k -W |
| 232 |
-Wno-unused-parameter -Wstrict-prototypes |
| 233 |
-Wmissing-prototypes -Wpointer-arith |
| 234 |
-Wreturn-type -Wcast-qual -Wwrite-strings |
| 235 |
-Wswitch -Wshadow -Wunused-parameter |
| 236 |
-Wcast-align -Wchar-subscripts -Winline |
| 237 |
-Wnested-externs -Wredundant-decls |
| 238 |
-Wold-style-definition -Wno-pointer-sign |