20 Commits

Author SHA1 Message Date
4078b012ae mpers.awk: use stdint.h instead of inttypes.h
As <inttypes.h> is included in files generated by mpers.awk to obtain
definitions of uintNN_t types provided by <stdint.h>, replace the former
header with the latter.

* mpers.awk: Use <stdint.h> instead of <inttypes.h>.
* mpers_test.sh: Update expected output.
2018-02-24 20:42:03 +00:00
daaf8ab7fe Update copyright headers
Headers updated automatically using maint/update_copyright_years.sh
script.
2018-02-13 22:00:00 +00:00
Eugene Syromyatnikov
1b75ffef40 mpers: implement gawk 3 support
Some old systems that still make some sense to be supported have only
gawk 3, so let's support them for now.

In order to achieve that, multiple changes have been implemented:
 - Multidimensional arrays are replaced with single-dimensional ones.
   In most places it's a "][" -> ", " replacement, as awk allows some
   kind of emulation of multidimensional arrays that way, but in several
   occasions (specifically for storing name and special fields) we have
   to iterate over them later, so we store that information in
   additional arrays in order to get the keys.
 - "switch" statements are replaced with sets of "if ... else if ...
   else" statements.  This change is trivial, except we've added
   a temporary variable in what_is order to store expression value, for
   readability purposes.
 - No support for array iteration ordering.  This one is most ugly of
   them all.  Luckily, not that ugly, we've just had to process index a
   bit in order to make it lexicographically sortable and add two
   temporary arrays containing sorted indices in order to sort over them
   instead of those two arrays that we've added in order to work around
   lack of multidimensional array support.

* mpers.awk (compare_indices): Remove unused function.
(array_get, update_upper_bound, /^DW_AT_data_member_location/,
/^DW_AT_byte_size/, /^DW_AT_encoding/): Replace multidimensional array
access with comma-concatenated index.
(norm_idx): New function.
(array_seq): Replace multidimensional array access with
comma-concatenated index.  Use comma-concatenated pair of (array_idx,
"seq") in order to check presence of the item in an array.
(what_is): Add enc and i local variables.  Store the value of
array[what_idx, "encoding"] in it.  Replace "switch" statements with
sets of "if ... else if ... else" statements.  Replace multidimensional
array access with comma-concatenated index. Use for (... ; ...; ...)
iteration over aparents_keys instead of iteration over array.
(/^<[[:xdigit:]]+>/): Store idx as norm_idx(matches[2]).  Replace
multidimensional array access with comma-concatenated index.  Store an
additional flag in array_names array.
(/^DW_AT_name/): Replace multidimensional array access with
comma-concatenated index.  Add a flag to array_names for that idx.
(/^DW_AT_type/): Do not capture "0x" as a part of a group, normalise
the captured group.  Replace multidimensional array access with
comma-concatenated index.
(/^Abbrev Number:[^(]+\(DW_TAG_/): Replace multidimensional array access
with comma-concatenated index.  Store additional flags in
array_special and array_parents arrays.
(END): Remove PROCINFO["sorted_in"] setup.  Sort array_parents.  Replace
multidimensional array access with comma-concatenated index.  Iterate
over array_special to go over all the items that have "special" field.
Iterate over array_names to go over all items that have "name" field.
* NEWS: Mention it.
2018-01-21 01:46:04 +00:00
03766d6640 mpers.awk: avoid redefinition of mpers_ptr_t
Older versions of gcc like those found in RHEL6 fail with the following
diagnostics:

  In file included from block.c:32:
  ./mpers-m32/struct_blk_user_trace_setup.h:2: error: redefinition of typedef ‘mpers_ptr_t’
  mpers_type.h:44: note: previous declaration of ‘mpers_ptr_t’ was here

* mpers.awk (END): Add #ifndef guard to mpers_ptr_t typedef.
* mpers_test.sh: Update expected output.
2018-01-19 17:50:09 +00:00
874b1943f0 mpers.awk: fix regression introduced by the previous cleanup
* mpers.awk (what_is): Remove returned_size from local variables.

Fixes: v4.18-308-gfd3447b5 ("mpers.awk: declare local variables consistently")
2017-09-01 17:30:13 +00:00
fd3447b51e mpers.awk: declare local variables consistently
* mpers.awk (compare_indices): Make c1 and c2 variables local.
(enter): Make item variable local.
(what_is): Make loc_diff, returned_size, and to_return local.
2017-08-31 09:54:24 +00:00
bfe513073d mpers.awk: separate local variables from real parameters by newline
* mpers.awk (array_get, update_upper_bound): Separate local variables
from real parameters by newline.
2017-08-30 09:48:51 +00:00
Eugene Syromyatnikov
9d095c7860 Add copyright headers 2017-05-22 17:33:51 +00:00
Eugene Syromyatnikov
490b1caa52 mpers.awk: add support for multidimensional arrays
* mpers.awk (update_upper_bound): New function, which maintains new "count"
property for storing total element count and updates "upper_bound"
property which now contains string with array dimensions.
(/^DW_AT_upper_bound/, /^DW_AT_count/): Use it.
(what_is) <case "array_type">: Use "count" property in order to calculate
returned_size, do not embody returned string in square brackets.
* mpers_test.sh: Add checks for multidimensional arrays.
2017-04-04 03:10:07 +00:00
a12c6a014b mpers.awk: prepare for adding support of multidimensional arrays
* mpers.awk (what_is) <case "structure_type", case "union_type">:
Move formatting of array upper_bound ...
<case "array_type">: ... here.
2017-04-04 02:42:26 +00:00
Elvira Khabirova
27a1a3f3eb mpers.awk: relax union member name absence check
This fixes mpersing of unions containing nameless members,
e.g. struct btrfs_ioctl_vol_args_v2.

* mpers.awk (what_is): Print names of union_type members as is.
2016-08-29 15:30:21 +00:00
Elvira Khabirova
a840a14f1f mpers.awk: remove unnecessary type attribute retrieval
* mpers.awk (what_is): Do not retrieve "type" attribute
for "enumeration_type".
2016-06-06 18:07:04 +00:00
cc902e3272 mpers.awk: add support for DWARF files generated by clang
* mpers.awk: Define default_pointer_size.  Initialize byte_size
for DW_TAG_pointer_type to default_pointer_size.  Set parent
for DW_TAG_member only.  Handle DW_AT_count as an alternative
to DW_AT_upper_bound.
2016-01-13 02:38:59 +00:00
38a34c9349 Add copyright headers to some files which lack them
Before this change, all files that exist since 20th century had
copyright headers, while most files that appeared later didn't.  This
change fixes the inconsistency by adding missing copyright headers.

It doesn't mean that copyright headers became maintained.  In my view,
git history provides much better information on this subject and is much
more accurate than copyright headers.
2015-12-17 17:56:48 +00:00
d2bcb1639e mpers.awk: add support for DWARF version 2 format
* mpers.awk: Handle DW_AT_data_member_location in DWARF v2 format.
2015-12-16 01:25:10 +00:00
c4afd6dc7a mpers.awk: make fillers added to the output structure more predictable
* mpers.awk (array_seq): New function.
(what_is): Use it for printing filler names.  Tweak return types.
* mpers_test.sh: Use a more complicated sample type to test mpers
machinery.
2015-12-15 23:33:34 +00:00
54d18a279a Robustify mpers.awk against input containing index loops
Make mpers.awk check for potential index loops.  Such loops should not
normally happen, but mpers.awk will not go into infinite recursion if
they do.

* mpers.awk (enter, leave): New functions.
(what_is): Use them.
2015-12-15 03:35:26 +00:00
59992183a6 Robustify mpers.awk against invalid input
Make mpers.awk check that accessed elements of the main array that
are expected to have non-empty values really meet this requirement.

* mpers.awk (array_get): New function.
(what_is, END): Use it.
* mpers_test.sh: Use a more complicated type to test mpers machinery.

Reported-by: Mike Frysinger <vapier@gentoo.org>
2015-12-15 02:04:38 +00:00
Elvira Khabirova
a5ffa18f13 mpers: fix compound types with arbitrary member alignments
* mpers.sh: Compound types are now represented as packed
with character arrays as explicit fillers inbetween members
and at the end.
2015-11-26 01:37:34 +00:00
Elvira Khabirova
092942206c Add mpers support
Add a subsystem for semi-automatical definition of how parsers should
work with personality-dependent (mpers) types of tracee's data.  Create
auxiliary libraries containing mpers syscall parsers and printer
functions, one library for each possible nonnative target personality.

Currently some parsers do not handle differences in definitions of data
types between personalities, namely LP64 and ILP32.  When
this is the case, long integers, pointers, and all compound
types containing long and pointer members may be printed incorrectly,
because of differences in sizes, offsets and alignments.

Since in most cases these are the only differences in desired behaviour
of parsers and printers for different personalities, a correct way
would be to compile one source code into multiple parsers, differing
only in definitions of mpers types.

To get a definition of a given type for nonnative personality
a very basic .c file containing a declaration of a variable of this type
is being compiled for this personality (using -m32 or -mx32 compiler
flag).  Information about the type is then being extracted from
this binary's DWARF debug info with an awk script and put
into a corresponding header file.  Resulting headers are being used to
compile mpers variations of syscall parsers and printer functions.

In addition to syscall parsers, there can occur a need to create mpers
printing functions, which then can be called from many places
in the code (for example, printsiginfo_at).  Such functions (printers)
are marked in a special manner.

For each possible nonnative target personality a library is being
created, containing mpers variations of syscall parsers and printers.
Only syscall parsers from files marked in a special manner and specially
marked functions from such files are being recompiled and included
in these libraries.

generate_mpers_am.sh is called by bootstrap to find the files
from strace_SOURCES which include MPERS_DEFS.  During compilation,
these files are being inspected for inclusions of DEF_MPERS_TYPE,
and nonnative variations of each included type are being generated
by an awk script.

Mpers parser names are being modified during inclusions of syscallent
headers for nonnative personalities.  Pointers to printers are
being stored in structs struct_printers, and a master
pointer printers is being updated on every set_personality.

* README-mpers: New README explaining how to use mpers support.
* empty.h: New empty file.
* generate_mpers_am.sh: New file.
* mpers.awk: Likewise.
* mpers.sh: Likewise.
* mpers_test.sh: Likewise.
* mpers_type.h: Likewise.
* Makefile.am (strace_SOURCES): Add empty.h and mpers_type.h.
(strace_CPPFLAGS, strace_LDFLAGS, strace_LDADD): Move to the beginning
of the file.
(strace_LDADD, noinst_LIBRARIES): Add libmpers-%.a.
(EXTRA_DIST): Add mpers.awk, mpers.sh, mpers_test.sh.
(BUILT_SOURCES, CLEANFILES): Add new generated files:
native_printer_decls.h, native_printer_defs.h, printers.h,
[HAVE_M32_MPERS] $(mpers_m32_targets), and [HAVE_MX32_MPERS]
$(mpers_mx32_targets).
(mpers_NAME, mpers_PREFIX, mpers_DEFS, mpers_INCLUDES, mpers_CPPFLAGS,
mpers_sh_opts, libmpers_CPPFLAGS, libmpers_m[x]32_a_SOURCES,
libmpers_m[x]32_a_CPPFLAGS, mpers_m[x]32_targets): New variables.
(mpers-m[x]32.stamp, m[x]32_defs.h, m[x]32_funcs.h, printers.h,
%_printer_decls.h, %_printer_defs.h, clean-local,
native_printer_decls.h, native_printer_defs.h, $mpers_m[x]32_targets):
New targets.
* bootstrap: Add generate_mpers_am.sh.
* configure.ac: Add AC_PROG_RANLIB.
* m4/mpers.m4: Add HAVE_MPERS variable.  Add $st_cv_mpers checks.
* defs.h: Include mpers_type.h.
Include printers.h, native_printer_decls.h, define MPERS_PRINTER_NAME.
Redefine SYS_FUNC_NAME.  Define MPERS_PRINTER_DECL.
[HAVE_M32_MPERS]: define PERSONALITY1_INCLUDE_FUNCS,
PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS
for X86_64, X32.
[HAVE_MX32_MPERS]: define PERSONALITY2_INCLUDE_FUNCS,
PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS
for X86_64.
Add fallback definitions of
PERSONALITY1_INCLUDE_FUNCS, PERSONALITY2_INCLUDE_FUNCS,
PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS,
PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS,
PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS.
* syscall.c: Include PERSONALITY1_INCLUDE_FUNCS,
PERSONALITY2_INCLUDE_FUNCS,
PERSONALITY0_INCLUDE_PRINTERS_DECLS, PERSONALITY0_INCLUDE_PRINTERS_DEFS,
PERSONALITY1_INCLUDE_PRINTERS_DECLS, PERSONALITY1_INCLUDE_PRINTERS_DEFS,
PERSONALITY2_INCLUDE_PRINTERS_DECLS, PERSONALITY2_INCLUDE_PRINTERS_DEFS.
(printers): New struct.  Update it when needed.
* .gitignore: Add libmpers-m32.a, libmpers-mx32.a, m32_defs.h,
m32_funcs.h, m32_printer_decls.h, m32_printer_defs.h, mpers-m32,
mpers-m32.stamp, mpers-mx32, mpers-mx32.stamp, mpers.am, mx32_defs.h,
mx32_funcs.h, mx32_printer_decls.h, mx32_printer_defs.h,
native_printer_decls.h, native_printer_defs.h, and printers.h.
2015-08-28 08:46:23 +00:00