• Wang Nan's avatar
    perf symbols: Fix symbols searching for module in buildid-cache · e7ee4047
    Wang Nan authored
    Before this patch, if a sample is triggered inside a module not in
    /lib/modules/`uname -r`/, even if the module is in buildid-cache, 'perf
    report' will still be unable to find the correct symbol.  For example:
    
      # rm -rf ~/.debug/
      # perf buildid-cache -a ./mymodule.ko
      # perf probe -m ./mymodule.ko -a get_mymodule_val
      Added new event:
        probe:get_mymodule_val (on get_mymodule_val in mymodule)
    
      You can now use it in all perf tools, such as:
    
     	perf record -e probe:get_mymodule_val -aR sleep 1
    
      # perf record -e probe:get_mymodule_val cat /proc/mymodule
      mymodule:3
      [ perf record: Woken up 1 times to write data ]
      [ perf record: Captured and wrote 0.011 MB perf.data (1 samples) ]
    
      # perf report --stdio
      [SNIP]
      #
      # Overhead  Command  Shared Object     Symbol
      # ........  .......  ................  ......................
      #
        100.00%  cat      [mymodule]        [k] 0x0000000000000001
    
      # perf report -vvvv --stdio
      dso__load_sym: adjusting symbol: st_value: 0 sh_addr: 0 sh_offset: 0x70
      symbol__new: get_mymodule_val 0x70-0x8a
      [SNIP]
    
    This is caused by dso__load() -> dso__load_sym(). In dso__load(), kmod
    is true only when its file is found in some well know directories. All
    files loaded from buildid-cache are treated as user programs. Following
    dso__load_sym() set map->pgoff incorrectly.
    
    This patch gives kernel modules in buildid-cache a chance to adjust
    value of kmod. After dso__load() get the type of symbols, if it is
    buildid, check the last 3 chars of original filename against '.ko', and
    adjust the value of kmod if the file is a kernel module.
    Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexei Starovoitov <ast@kernel.org>
    Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
    Cc: Cody P Schafer <dev@codyps.com>
    Cc: He Kuang <hekuang@huawei.com>
    Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kirill Smelkov <kirr@nexedi.com>
    Cc: Li Zefan <lizefan@huawei.com>
    Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: pi3orama@163.com
    Link: http://lkml.kernel.org/r/1454680939-24963-3-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    e7ee4047
build-id.h 1.36 KB