| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
| |
Handle the new DW_FORM_implicit_const. The value of this form is embedded
in the abbrev data (as sleb128) and not in the info DIE data. This also
adds a new function dwarf_getabbrevattr_data which allows getting any
data/value associated with a form. eu-readelf will use this new function
to show the DW_FORM_implicit_const value.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This just makes sure we know how the new forms are encoded.
It doesn't yet handle them in the dwarf_form* functions.
But it does make it possible to skip them when reading DWARF5.
DW_FORM_implicit_const has zero size (the value is in the abbrev,
not in the info). DW_FORM_addrx[1234], DW_FORM_strx[1234],
DW_FORM_ref_sup[48] and DW_FORM_data16 have constant size.
DW_FORM_strp_sup and DW_FORM_line_strp are offset size.
DW_FORM_addrx, DW_FORM_strx, DW_FORM_loclistx and DW_FORM_rnglistx
encode a uleb128.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The dwarf_nextcu and dwarf_next_unit functions provide information to
construct the offset to construct the associated CU DIE using dwarf_offdie
or dwarf_offdie_types. This requires the user to know beforehand where
to DIE data is stored (in the .debug_info or .debug_types section).
For type units one also needs to use the type offset to create the actual
type DIE. In DWARF5 DIEs can come from even more data locations. And there
are also skeleton units which require the user to find the associated
split compile unit DIE (which would come from a different file).
The new dwarf_get_units function simplifies iterating over the units in
a DWARF file. It doesn't require the user to know where the DIE data is
stored, it will automagically iterate over all know data sources (sections)
returning the Dwarf_CU and the associated Dwarf_Die if requested. If the
user requests to know the associated "subdie" it will also be resolved.
This implementation returns the correct subdie for type units. A future
version will also handle skeleton units and return the associated skeleton
DIE and split unit DIE.
readelf has been adapted to use the new iterator and print the new DWARF5
unit header information (which it gets through dwarf_cu_die). The new
interface hides which section exactly to iterate on (by design). readelf
works around that by "cheating". It sets up a Dwarf_CU so that it gets
the data from the right section, using the (normally) internal data
structure.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
| |
Parse DWARF5 units, add the unit_type to the Dwarf_CU and generalize some
code calculating the header length and getting at the first DIE of a unit.
Unit headers can have different sizes depending on the unit type.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
| |
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
| |
In some containers our view of pids is confused. We see the container
pid namespace, but the core is generated using the host pid namespace.
Since tests are run in a new fresh directory any core here is most like
is ours.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
On some systems, at least on Fedora 27 ppc64le with glibc 2.26-24 and
kernel 4.14.18-300, including sys/ptrace.h late (after signal.h or
sys/wait.h for example) will cause issues and produce errors like:
In file included from /usr/include/asm/sigcontext.h:12:0,
from /usr/include/bits/sigcontext.h:30,
from /usr/include/signal.h:287,
from /usr/include/sys/wait.h:36,
from linux-pid-attach.c:38:
/usr/include/sys/ptrace.h:73:3: error: expected identifier before numeric constant
PTRACE_GETREGS = 12,
^
Swapping the include order fixes these issues.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Currently storing a lot of Dwarf_Dies might be inefficient since it
costs a lot of memory since the sizeof (Dwarf_Die) == 32 bytes on 64bit
arches. You can try storing just the Dwarf_Off from dwarf_dieoffset.
Which is just 8 bytes. But then you have to keep track of whether to
call dwarf_dieoffset, if the Dwarf_Die came from the main .debug_info,
or call dwarf_dieoffset_types, if it came from .debug_types. And you'll
have to keep track of whether it came from the main Dwarf or the alt
Dwarf (dwz multi file). With DWARF5 or GNU DebugFission split-dwarf
you will also need to know which split Dwarf file the original DIE
came from.
A Dwarf_Die consists of an addr pointer where the actual DIE data
comes from, a CU pointer that provides context (and has a pointer
to the Dwarf file the Die is associated with) and a (cached)
Dwarf_Abbrev pointer that is initialized when the Dwarf_Die is
first read and describes how to interpret the DIE data.
libdw already keeps track of the data pointers (sections) of a
Dwarf file and given an offset it can already reconstruct the
other Dwarf_Die fields. So this patch introduces dwarf_die_addr_die.
Given a Dwarf_Die addr dwarf_die_addr_die returns a (reconstructed)
Dwarf_Die, or NULL if the given addr didn't come from a valid
Dwarf_Die. In particular it will make sure that the correct Dwarf_CU
pointer is set for the Dwarf_Die, the Dwarf_Abbrev pointer will not
be set up yet (it will only be once the Dwarf_Die is used to read
attributes, children or siblings).
This functions can be used to keep a reference to a Dwarf_Die which
you want to refer to later. The addr, and the result of this function,
is only valid while the associated Dwarf is valid.
Since libdw already had to lookup the Dwarf_CU given an offset, this
function is as efficient as dwarf_dieoffset (or dwarf_dieoffset_types)
without having to know the original origin of the Dwarf_Die. It will
search both the .debug_info and .debug_types data sections from both
the main Dwarf or the alt Dwarf file. Once split dwarf support is added
it will also look in any split dwarf .dwo (or the .dwp) file.
The only limitation, compared to using a Dwarf_Off and dwarf_dieoffset,
is that it only works during runtime while the main Dwarf object is
valid (till dwarf_end has been called on it).
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Use __attribute__ ((fallthrough)) to indicate switch case fall through
instead of a comment. This ensures that the fallthrough warning is not
triggered even if the file is pre-processed (hence stripping the
comments) before it is compiled.
The actual fallback implementation is hidden behind a FALLBACK macro in
case the compiler doesn't support it.
Finally, the -Wimplict-fallthrough warning was upgraded to only allow
the attribute to satisfy it; a comment alone is no longer sufficient.
Signed-off-by: Joshua Watt <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Add a new alt_fd field to the Dwarf struct. This tracks whether we tried
to open the alt file ourselves. This is used in dwarf_getalt to see if
we should try to find and open the alt file ourselves (if the user hasn't
called dwarf_setalt yet). dwarf_formref_die and dwarf_formstring now call
dwarf_getalt instead of accessing the alt_dwarf Dwarf field directly.
For applications using libdwfl nothing changes (dwfl will find, set and
clean up the alt file). For programs that set the alt file themselves
already through other means, nothing changes. But for applications that
don't create the Dwarf through libdwfl and don't set the alt file already
libdw will now try to find and set it on first access. If found the
application will now not get errors for missing alt files.
Add a simple testcase based on the existing allfcts test which already
tries to set the alt file, but is too simplistic to find it in some
subdir (relative to the main debug file).
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
| |
Some gcc omptimization levels (-Og in particular) didn't see that when
symtabndx != 0, then symtabshdr was certain to be initialized. Change
the symtabndx == 0 check to symtabshdr == NULL and initialize symtabshdr
to work around that.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
| |
In print_debug_ranges_section and print_debug_loc_section we try to
get the associated CU through skip_listptr_hole for the first data data.
If no CU at all can be found (because the .debug_info section was bogus)
this would keep the Dwarf_CU uninitialized causing a crash later on
when it was compared to the last_cu and used because it was unequal.
Fix this by explicitly initializing cu to last_cu (which is NULL on
first use).
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The function dwarf_formsdata is used for decoding signed values, but
except for the variable-length DW_FORM_sdata, it uses unsigned
primitives to decode the value. This is not a problem for 64-bit values,
but the smaller values come decoded wrong. Fix by changing to signed
primitives for decoding the fixed-length forms.
Add a test case that uses dwarf_aggregate_size to determine an array
size whose lower bound is -1, encoded using DW_FORM_data1, and upper
bound 255 with DW_FORM_data2. When the -1 is decoded wrongly, it comes
back as 255, and the array size is 1. The correct array size should be
257.
Signed-off-by: Petr Machata <[email protected]>
|
|
|
|
|
|
|
|
| |
If we don't cache the attrcnt and use bitfields for the has_children and
code we can reduce the size of struct Dwarf Abbrev from 32 to 24 bytes on
64bit architectures and from 28 to 20 bytes on 32bit arches.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
| |
When creating a Dwarf_Abbrev in dwarf_getabbrev (__libdw_getabbrev) we
already check it is fully readable from the .debug_abbrev section. So
whenever we reread it later using the attrp pointer we don't have to
check it again. Introduce get_uleb128_unchecked to use for ulebs we
know are safe to read directly.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
| |
Use dwarf_form_name consistently to print forms. attr_callback was
using its own string conversion, print_debug_macro_section was using
dwarf_form_string instead of dwarf_form_name.
The difference between dwarf_form_string and dwarf_form_name is that
the first returns NULL if the form is unknown and the second returns
an hexadecimal string representation in that case.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
| |
If systemd-coredump is installed we have to use coredumpctl to extract
the core file to test. Unfortunately systemd-coredump/coredumpctl seem
to be somewhat fragile if multiple core dumps are generated/extracted
at the same time. So use a lock file to only run one core dump test at
a time (under make -j).
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
| |
That makes it so much easier to find the actual DIE offset in the output.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
| |
If a Dwarf_Die was requested from an offset into a section data that
didn't exist we would crash. Crashing is bad even if given bad input.
Just return an error in that case.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
| |
This exposes a bug in dwarf_formstring as detected by the dwarf-getmacros
test before we made sure to use the correct sec_idx for the CU.
Signed-off-by: Ulf Hermann <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The DIE (attribute) data might come from either the main .debug_info
section or for DWARFv4 from a separate .debug_types section. Or in
case of the fake_loc_cu from the .debug_loc section and in the case
of macros from the .debug_macinfo or .debug_macro section.
We didn't handle the last two "fake" CU cases correctly when sanity
checking offsets in __libdw_read_address and __libdw_read_offset.
Add an explicit sec_idx field to struct Dwarf_CU that is always set
to the actual section that the data came from.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
| |
There might be other sections or segments with ELF Notes that are
readable. Also adjust error message depending on whether or not we
actually got any data for the ELF Note segment or section.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
| |
Reserve memory for a new DIE first. The caller might not care, but it
isn't really nice to change the DIE the caller gave us.
See also https://sourceware.org/bugzilla/show_bug.cgi?id=22546#c5
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
If we have a multidimensional array of dimensions (a,b,c) the number of elements
should be a*b*c, but prior to this patch dwarf_aggregate_size() would report
a+b+c instead.
This patch fixes the bug and adds a test that demonstrates the bug (the test
fails without the functional part of this patch).
Fixes: https://sourceware.org/bugzilla/show_bug.cgi?id=22546
Signed-off-by: Dima Kogan <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
DW_OP_call2 and DW_OP_call4 didn't correctly advance the data pointer.
This caused print_ops to produce garbage operands. Also format the
arguments as DIE offsets. That makes it easier to follow the call to the
actual dwarf_procedure DIE.
Testcase from https://sourceware.org/bugzilla/show_bug.cgi?id=22532
The testcase only checks the eu-readelf output is correct for the
byte_size attribute. But it might be interesting to write a full
expression parser to check the actual sizes.
[ 3e] structure_type
name (strp) "pck__rec"
byte_size (exprloc)
[ 0] push_object_address
[ 1] deref_size 1
[ 3] call4 [ 95]
[ 8] plus_uconst 7
[ 10] const1s -4
[ 12] and
[ 95] dwarf_procedure
location (exprloc)
[ 0] dup
[ 1] lit1
[ 2] ne
[ 3] bra 10
[ 6] lit4
[ 7] skip 31
[ 10] dup
[ 11] lit4
[ 12] ne
[ 13] bra 20
[ 16] lit0
[ 17] skip 31
[ 20] dup
[ 21] lit3
[ 22] eq
[ 23] bra 30
[ 26] lit0
[ 27] skip 31
[ 30] lit4
[ 31] swap
[ 32] drop
The "answer" depends on the Discr value (first byte at object address),
and is rounded up to 4 or 8 bytes.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
| |
It was already possible to display the section groups using -a, but
the argp options didn't yet have an -g, --section-groups entry to
just display the section groups.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
| |
Also adjust the formatting for the resolved addresses to print them
on separate lines so they nicely line up even when the addresses are
resolved to symbol+offset names. And print the operands starting on
a new line.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
| |
Also adjust the formatting for the resolved addresses to print them
on separate lines so they nicely line up even when the addresses are
resolved to symbol+offset names.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
| |
When we see a DW_AT_decl_file or DW_AT_call_file attribute print the
actual file name. The current interface gives us a full (absolute) patch,
but we only want to show the file name for now to not clutter the output
too much. This helps a lot when trying to determine where something was
declared if you are just looking at the DIE tree. Otherwise you'll have
to cross match the number by hand with the corresponding line table entry.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
| |
If there is anything wrong with a DIE it is useful to know what the abbrev
code was so you can lookup the abbrev description.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
| |
Use only 2 spaces for index (there are never 10000, the most seen in the
wild is 64). Adjust re-indenting after GNU_entry_value.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The notes in a core file that contain the auxv entries might not be
naturally aligned. The code already tried to account for that, but
the GCC 8 undefined behaviour sanitizer found we were till dereferencing
the actual auxv entry pointer directly. Fix this by calculating all pointers
by hand and not use an array of auxv entries trick.
This makes make distcheck (which enables sanitize-undefined by default)
pass again using GCC8.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Now an error getting the attribute value will not only print the DIE offset
and the reason, but also the attribute name and form. e.g.
DIE [b] cannot get attribute 'ranges' (sec_offset) value: .debug_ranges
section missing
Also we don't abort, but try to print the other attributes of the DIE
anyway. It might just be one attribute whose value cannot be resolved.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
| |
When processing large files it is useful to know the DIE offset if
printing of attributes fails (especially when redirecting the output).
With this change the error message looks like:
eu-readelf: DIE [2aeb8ef1] cannot get attribute value: invalid DWARF
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
| |
We want to check whether the bias is zero, not whether we have dwarf
debug_frame cfi.
This triggered on a ppc64/ppc64le self-check since it has both
debug_frame and eh_frame cfi (other arches often only have eh_frame).
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
| |
Make sure the testcases (library functions they use) don't crash,
triggers self-check/asserts or leaks memory under valgrind. This
also helps making sure newer DWARF constructs are handled (when
building with -gdwarf-5).
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Handle DW_OP_GNU_variable_value in dwarf_getlocation[_attr,_die].
DW_OP_GNU_variable_value takes one argument a DIE reference that
describes a value given by a location of const_value attribute.
To test handling of the new operand the varlocs test is adapted
to print out all DIEs and attributes with expressions or location
lists (the original varlocs test only prints out variables and
arguments of function DIEs).
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
dwarf_getlocation has to know which attributes can contain a DWARF
expression or location list because the form alone might be ambiguous.
Since DWARF4 there is DW_FORM_exprloc so always accept that. But for older
DWARF or location lists we cannot just check for DW_FORM_sec_offset since
that could be a reference to diffent kinds of sections (based on attribute).
Update the attribute list based on the latest DWARF5 encodings table.
Note that DW_AT_call_origin wasn't added because that seems to be a
typo in the DWARF5 spec. http://dwarfstd.org/ShowIssue.php?issue=171103.1
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
| |
Also format both DW_OP_call_ref and DW_OP_GNU_variable_value argument
as a normal DIE reference.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
| |
Admin can place the real config file under /etc/sysctl.d as override.
https://bugzilla.redhat.com/show_bug.cgi?id=1506660
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
| |
The GCC8 -Wpacked-not-aligned warns if a structure field with explicit
padding in a packed structure will be misaligned. m68k prstatus core
notes are described by a packed structure which has such aligned structure
fields.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
| |
Only the testcase md5-sha1-test used them. So also remove that testcase.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
| |
For -k the argp parser could fail to find the modules after the kernel
itself was already found. Calling failure at this point closes the Dwfl,
which isn't necessary. Just warn about the missing modules and continue
with the kernel only Dwfl.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
| |
We won't use the e_shoff value in that case because we will set
elf->state.elf[64|32].scns.cnt to zero to indicate not to read
any section header data from the file.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
| |
Add ELF_E_INVALID_ELF which is set when the ELF file data is bad.
This is different from ELF_E_INVALID_FILE which is set when the file
could not be read.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
| |
dwarf_cfi_cie_p used DW_CIE_ID_64 from dwarf.h which meant you had
to include dwarf.h just to use the dwarf_cfi_cie_p macros. Just define
the constant as LIBDW_CIE_ID in libdw.h to keep it independent.
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
gcc defaults to using struct layouts that follow the native conventions,
even if __attribute__((packed)) is given. In order to get the layout we
expect, we need to tell gcc to always use the gcc struct layout, at
least for packed structs. To do this, we can use the gcc_struct
attribute.
This is important, not only for porting to windows, but also potentially
for other platforms, as the bugs resulting from struct layout
differences are rather subtle and hard to find.
Signed-off-by: Ulf Hermann <[email protected]>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When compiling with -O3 gcc finds an interesting error:
src/ar.c: In function ‘do_oper_insert’:
src/ar.c:1077:56: error: ‘%-*ld’ directive output may be truncated writing between 6 and 10 bytes into a region of size 7 [-Werror=format-truncation=]
snprintf (tmpbuf, sizeof (tmpbuf), ofmt ? "%-*lo" : "%-*ld", bufsize, val);
^~~~~
The problem is that the ar header values have to fit in a limited
(not zero terminated) string. We should check the snprintf return
value to see if the values are representable.
Also make ar valgrind and ubsan clean and add a minimal sanity test.
Reported-by: Matthias Klose <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
| |
Signed-off-by: Mark Wielaard <[email protected]>
|
|
|
|
|
|
|
| |
Replace horizontal tab '\v' with double line feed '\n\n' in doc strings.
Regenerate .po files.
Signed-off-by: Mark Wielaard <[email protected]>
|