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.
diff --git a/mpers.awk b/mpers.awk
new file mode 100644
index 0000000..2a2de59
--- /dev/null
+++ b/mpers.awk
@@ -0,0 +1,135 @@
+function compare_indices(i1, v1, i2, v2) {
+ c1 = strtonum(sprintf("%s", i1))
+ c2 = strtonum(sprintf("%s", i2))
+ if (c1 < c2)
+ return -1
+ return (c1 != c2)
+}
+function what_is(what_idx, type_idx, special, item)
+{
+ type_idx = array[what_idx]["type"]
+ special = array[what_idx]["special"]
+ switch (special) {
+ case "base_type":
+ switch (array[what_idx]["encoding"]) {
+ case 5: # signed
+ printf("%s ", "int" \
+ 8*array[what_idx]["byte_size"] "_t")
+ break
+ case 7: # unsigned
+ printf("%s ", "uint" \
+ 8*array[what_idx]["byte_size"] "_t")
+ break
+ default: # float, signed/unsigned char
+ printf("%s ", array[what_idx]["name"])
+ break
+ }
+ break
+ case "enumeration_type":
+ printf("%s ", "uint" 8*array[type_idx]["byte_size"] "_t")
+ break
+ case "pointer_type":
+ printf("%s", "mpers_ptr_t ")
+ break
+ case "array_type":
+ what_is(type_idx)
+ to_return = array[what_idx]["upper_bound"]
+ return to_return
+ break
+ case "structure_type":
+ case "union_type":
+ if (special == "structure_type") {
+ print "struct {"
+ } else {
+ print "union {"
+ }
+ for (item in array) {
+ if ("parent" in array[item] && array[item]["parent"] \
+ == what_idx) {
+ returned = what_is(item)
+ printf("%s", array[item]["name"])
+ if (returned) {
+ printf("%s", "[" returned "]")
+ }
+ print ";"
+ }
+ }
+ printf("%s", "} ")
+ break
+ case "typedef":
+ return what_is(type_idx)
+ break
+ case "member":
+ return what_is(type_idx)
+ break
+ default:
+ what_is(type_idx)
+ break
+ }
+ return 0
+}
+BEGIN {
+ print "#include <inttypes.h>"
+}
+/^<[[:xdigit:]]+>/ {
+ match($0, /([[:alnum:]]+)><([[:alnum:]]+)/, matches)
+ level = matches[1]
+ idx = "0x" matches[2]
+ array[idx]["idx"] = idx
+ parent[level] = idx
+ if (level > 1) {
+ array[idx]["parent"] = parent[level-1]
+ }
+}
+/^DW_AT_data_member_location/ {
+ match($0, /[[:digit:]]+/, temparray)
+ array[idx]["location"] = temparray[1]
+}
+/^DW_AT_name/ {
+ match($0, /:[[:space:]]+([[:alpha:]_][[:alnum:]_[:space:]]*)/, temparray)
+ array[idx]["name"] = temparray[1]
+}
+/^DW_AT_byte_size/ {
+ match($0, /[[:digit:]]+/, temparray)
+ array[idx]["byte_size"] = temparray[0]
+}
+/^DW_AT_encoding/ {
+ match($0, /[[:digit:]]+/, temparray)
+ array[idx]["encoding"] = temparray[0]
+}
+/^DW_AT_type/ {
+ match($0, /:[[:space:]]+<(0x[[:xdigit:]]*)>$/, temparray)
+ array[idx]["type"] = temparray[1]
+}
+/^DW_AT_upper_bound/ {
+ match($0, /[[:digit:]]+/, temparray)
+ array[parent[level-1]]["upper_bound"] = temparray[0] + 1
+}
+/^Abbrev Number:[^(]+\(DW_TAG_/ {
+ if (match($0, /typedef|union_type|structure_type|pointer_type\
+|enumeration_type|array_type|base_type|member/, temparray)) {
+ array[idx]["special"] = temparray[0]
+ }
+}
+END {
+ PROCINFO["sorted_in"] = "compare_indices"
+ for (item in array) {
+ if (array[item]["special"] == "pointer_type") {
+ print "typedef uint" \
+ 8*array[item]["byte_size"] "_t mpers_ptr_t;"
+ break
+ }
+ }
+ for (item in array) {
+ if (array[item]["name"] == VAR_NAME) {
+ type=array[item]["type"]
+ print "typedef"
+ what_is(array[item]["type"])
+ print ARCH_FLAG "_" array[type]["name"] ";"
+ print "#define MPERS_" \
+ ARCH_FLAG "_" array[type]["name"] " " \
+ ARCH_FLAG "_" array[type]["name"]
+ break
+ }
+ }
+}