summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPetr Machata <[email protected]>2014-12-02 21:22:14 +0100
committerPetr Machata <[email protected]>2014-12-10 16:10:34 +0100
commitedb079a596b25379828836e501d003f20afdb879 (patch)
tree1c1a4335d134e24b2e5d054f5ebf625d01e592bb /tests
parentd0070a982cfddbff9c3f744b518b4cde539e5e65 (diff)
Change calling convention of dwarf_getmacros to allow opcode 0xff
We now require callers to pass DWARF_GETMACROS_START to start the iteration. 0 is still accepted, but signals to libdw that the iteration request comes from an old-style caller, and that opcode 0xff should be rejected when iterating .debug_macro, to avoid confusion. Signed-off-by: Petr Machata <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog10
-rw-r--r--tests/dwarf-getmacros.c27
-rwxr-xr-xtests/run-dwarf-getmacros.sh11
-rwxr-xr-xtests/testfile-macros-0xff.bz2bin0 -> 2844 bytes
-rw-r--r--tests/testfile-macros-0xff.s153
5 files changed, 195 insertions, 6 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 87a453db..c22ed8a1 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,13 @@
+2014-12-02 Petr Machata <[email protected]>
+
+ * dwarf-getmacros.c (mac): Skip over DW_MACINFO_undef,
+ DW_MACRO_GNU_undef_indirect opcodes. Add a default branch.
+ (main): Initialize off to DWARF_GETMACROS_START when an extra
+ command line argument is passed.
+ * testfile-macros-0xff.bz2: New test case.
+ * testfile-macros-0xff.s: New file (source for the above).
+ * run-dwarf-getmacros.sh: Add two tests.
+
2014-11-27 Mark Wielaard <[email protected]>
* vdsosyms.c (main): Call dwfl_linux_proc_attach.
diff --git a/tests/dwarf-getmacros.c b/tests/dwarf-getmacros.c
index f203d5bb..92e093ca 100644
--- a/tests/dwarf-getmacros.c
+++ b/tests/dwarf-getmacros.c
@@ -34,9 +34,9 @@ mac (Dwarf_Macro *macro, void *dbg)
{
static int level = 0;
- switch (({ unsigned int opcode;
- dwarf_macro_opcode (macro, &opcode);
- opcode; }))
+ unsigned int opcode;
+ dwarf_macro_opcode (macro, &opcode);
+ switch (opcode)
{
case DW_MACRO_GNU_transparent_include:
{
@@ -50,7 +50,7 @@ mac (Dwarf_Macro *macro, void *dbg)
printf ("%*sinclude %#" PRIx64 "\n", level, "", w);
++level;
- include (dbg, w, 0);
+ include (dbg, w, DWARF_GETMACROS_START);
--level;
printf ("%*s/include\n", level, "");
break;
@@ -88,6 +88,19 @@ mac (Dwarf_Macro *macro, void *dbg)
printf ("%*s%s\n", level, "", value);
break;
}
+
+ case DW_MACINFO_undef:
+ case DW_MACRO_GNU_undef_indirect:
+ break;
+
+ default:
+ {
+ size_t paramcnt;
+ dwarf_macro_getparamcnt (macro, &paramcnt);
+ printf ("%*sopcode %u with %zd arguments\n",
+ level, "", opcode, paramcnt);
+ break;
+ }
}
return DWARF_CB_ABORT;
@@ -105,17 +118,19 @@ include (Dwarf *dbg, Dwarf_Off macoff, ptrdiff_t token)
}
int
-main (int argc __attribute__ ((unused)), char *argv[])
+main (int argc, char *argv[])
{
+ assert (argc >= 3);
const char *name = argv[1];
ptrdiff_t cuoff = strtol (argv[2], NULL, 0);
+ bool new_style = argc > 3;
int fd = open (name, O_RDONLY);
Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
Dwarf_Die cudie_mem, *cudie = dwarf_offdie (dbg, cuoff, &cudie_mem);
- for (ptrdiff_t off = 0;
+ for (ptrdiff_t off = new_style ? DWARF_GETMACROS_START : 0;
(off = dwarf_getmacros (cudie, mac, dbg, off)); )
if (off == -1)
{
diff --git a/tests/run-dwarf-getmacros.sh b/tests/run-dwarf-getmacros.sh
index 8f7c4a80..0a488fa3 100755
--- a/tests/run-dwarf-getmacros.sh
+++ b/tests/run-dwarf-getmacros.sh
@@ -696,4 +696,15 @@ file /home/mark/src/tests/macro.c
/file
EOF
+testfiles testfile-macros-0xff
+testrun_compare ${abs_builddir}/dwarf-getmacros testfile-macros-0xff 0xb <<\EOF
+invalid opcode
+EOF
+testrun_compare ${abs_builddir}/dwarf-getmacros testfile-macros-0xff 0xb '' <<\EOF
+opcode 255 with 0 arguments
+file /home/petr/proj/elfutils/master/elfutils/x.c
+ FOO 0
+/file
+EOF
+
exit 0
diff --git a/tests/testfile-macros-0xff.bz2 b/tests/testfile-macros-0xff.bz2
new file mode 100755
index 00000000..a19662a3
--- /dev/null
+++ b/tests/testfile-macros-0xff.bz2
Binary files differ
diff --git a/tests/testfile-macros-0xff.s b/tests/testfile-macros-0xff.s
new file mode 100644
index 00000000..7fdd35c2
--- /dev/null
+++ b/tests/testfile-macros-0xff.s
@@ -0,0 +1,153 @@
+ .file "x.c"
+ .text
+.Ltext0:
+ .globl main
+ .type main, @function
+main:
+.LFB0:
+ .file 1 "x.c"
+ .loc 1 3 0
+ .cfi_startproc
+ pushq %rbp
+ .cfi_def_cfa_offset 16
+ .cfi_offset 6, -16
+ movq %rsp, %rbp
+ .cfi_def_cfa_register 6
+ .loc 1 3 0
+ movl $0, %eax
+ popq %rbp
+ .cfi_def_cfa 7, 8
+ ret
+ .cfi_endproc
+.LFE0:
+ .size main, .-main
+.Letext0:
+ .section .debug_info,"",@progbits
+.Ldebug_info0:
+ .long 0x52
+ .value 0x4
+ .long .Ldebug_abbrev0
+ .byte 0x8
+ .uleb128 0x1
+ .long .LASF244
+ .byte 0x4
+ .string "x.c"
+ .long .LASF245
+ .quad .Ltext0
+ .quad .Letext0-.Ltext0
+ .long .Ldebug_line0
+ .long .Ldebug_macro0
+ .uleb128 0x2
+ .long .LASF246
+ .byte 0x1
+ .byte 0x3
+ .long 0x4e
+ .quad .LFB0
+ .quad .LFE0-.LFB0
+ .uleb128 0x1
+ .byte 0x9c
+ .uleb128 0x3
+ .byte 0x4
+ .byte 0x5
+ .string "int"
+ .byte 0
+ .section .debug_abbrev,"",@progbits
+.Ldebug_abbrev0:
+ .uleb128 0x1
+ .uleb128 0x11
+ .byte 0x1
+ .uleb128 0x25
+ .uleb128 0xe
+ .uleb128 0x13
+ .uleb128 0xb
+ .uleb128 0x3
+ .uleb128 0x8
+ .uleb128 0x1b
+ .uleb128 0xe
+ .uleb128 0x11
+ .uleb128 0x1
+ .uleb128 0x12
+ .uleb128 0x7
+ .uleb128 0x10
+ .uleb128 0x17
+ .uleb128 0x2119
+ .uleb128 0x17
+ .byte 0
+ .byte 0
+ .uleb128 0x2
+ .uleb128 0x2e
+ .byte 0
+ .uleb128 0x3f
+ .uleb128 0x19
+ .uleb128 0x3
+ .uleb128 0xe
+ .uleb128 0x3a
+ .uleb128 0xb
+ .uleb128 0x3b
+ .uleb128 0xb
+ .uleb128 0x49
+ .uleb128 0x13
+ .uleb128 0x11
+ .uleb128 0x1
+ .uleb128 0x12
+ .uleb128 0x7
+ .uleb128 0x40
+ .uleb128 0x18
+ .uleb128 0x2117
+ .uleb128 0x19
+ .byte 0
+ .byte 0
+ .uleb128 0x3
+ .uleb128 0x24
+ .byte 0
+ .uleb128 0xb
+ .uleb128 0xb
+ .uleb128 0x3e
+ .uleb128 0xb
+ .uleb128 0x3
+ .uleb128 0x8
+ .byte 0
+ .byte 0
+ .byte 0
+ .section .debug_aranges,"",@progbits
+ .long 0x2c
+ .value 0x2
+ .long .Ldebug_info0
+ .byte 0x8
+ .byte 0
+ .value 0
+ .value 0
+ .quad .Ltext0
+ .quad .Letext0-.Ltext0
+ .quad 0
+ .quad 0
+ .section .debug_macro,"",@progbits
+.Ldebug_macro0:
+ .value 0x4
+ .byte 0x6
+ .long .Ldebug_line0
+ .byte 0x1
+ .byte 0xff
+ .uleb128 0
+ .byte 0xff
+ .byte 0x3
+ .uleb128 0
+ .uleb128 0x1
+ .byte 0x5
+ .uleb128 0x1
+ .long .LASF243
+ .byte 0x4
+ .byte 0
+ .section .debug_line,"",@progbits
+.Ldebug_line0:
+ .section .debug_str,"MS",@progbits,1
+.LASF245:
+ .string "/home/petr/proj/elfutils/master/elfutils"
+.LASF244:
+ .string "GNU C++ 4.9.0 20140422 (Red Hat 4.9.0-1) -mtune=generic -march=x86-64 -g3"
+.LASF243:
+ .string "FOO 0"
+.LASF246:
+ .string "main"
+ .ident "GCC: (GNU) 4.9.0 20140422 (Red Hat 4.9.0-1)"
+ .section .note.GNU-stack,"",@progbits