perf tests: Stop reading if objdump output crossed sections
authorJan Stancek <jstancek@redhat.com>
Wed, 2 Sep 2015 08:19:16 +0000 (10:19 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 14 Sep 2015 15:50:12 +0000 (12:50 -0300)
objdump output can span across multiple sections:

  Disassembly of section .text:
    0000000000000008 <crc32c+0x8>:
       8:       48 89 e5                mov    %rsp,%rbp
       b:       53                      push   %rbx
       c:       8b 01                   mov    (%rcx),%eax
    <snip>
      6b:       90                      nop

  Disassembly of section .init.text:
    0000000000000008 <init_module+0x8>:
       8:       00 00                   add    %al,(%rax)
       a:       00 00                   add    %al,(%rax)
       c:       48 89 e5

Stop further reading if an address starts going backwards, assuming we
crossed sections.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/9d1ea95e5f9884fdff1be6f761a2feabef37412c.1441181335.git.jstancek@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/code-reading.c

index c409409d77653d928b3c66ec618a452add37ab40..8145c67fb43acbc8450194f54bb2d231fab11f86 100644 (file)
@@ -79,7 +79,7 @@ static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
        size_t line_len, off_last = 0;
        ssize_t ret;
        int err = 0;
-       u64 addr;
+       u64 addr, last_addr = start_addr;
 
        while (off_last < *len) {
                size_t off, read_bytes, written_bytes;
@@ -101,6 +101,11 @@ static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
 
                if (sscanf(line, "%"PRIx64, &addr) != 1)
                        continue;
+               if (addr < last_addr) {
+                       pr_debug("addr going backwards, read beyond section?\n");
+                       break;
+               }
+               last_addr = addr;
 
                /* copy it from temporary buffer to 'buf' according
                 * to address on current objdump line */