• Namhyung Kim's avatar
    perf annotate-data: Support global variables · 5f7cdde8
    Namhyung Kim authored
    Global variables are accessed using PC-relative address so it needs to
    be handled separately.  The PC-rel addressing is detected by using
    DWARF_REG_PC.  On x86, %rip register would be used.
    
    The address can be calculated using the ip and offset in the
    instruction.  But it should start from the next instruction so add
    calculate_pcrel_addr() to do it properly.
    
    But global variables defined in a different file would only have a
    declaration which doesn't include a location list.  So it first tries
    to get the type info using the address, and then looks up the variable
    declarations using name.  The name of global variables should be get
    from the symbol table.  The declaration would have the type info.
    
    So extend find_var_type() to take both address and name for global
    variables.
    
    The stat is now looks like:
    
      Annotate data type stats:
      total 294, ok 153 (52.0%), bad 141 (48.0%)
      -----------------------------------------------------------
              30 : no_sym
              32 : no_mem_ops
              61 : no_var
              10 : no_typeinfo
               8 : bad_offset
    Reviewed-by: default avatarIan Rogers <irogers@google.com>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Link: https://lore.kernel.org/r/20240117062657.985479-7-namhyung@kernel.orgSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
    5f7cdde8
annotate.h 13 KB