• Namhyung Kim's avatar
    perf dwarf-aux: Handle type transfer for memory access · 437683a9
    Namhyung Kim authored
    We want to track type states as instructions are executed.  Each
    instruction can access compound types like struct or union and load/
    store its members to a different location.
    
    The die_deref_ptr_type() is to find a type of memory access with a
    pointer variable.  If it points to a compound type like struct, the
    target memory is a member in the struct.  The access will happen with an
    offset indicating which member it refers.  Let's follow the DWARF info
    to figure out the type of the pointer target.
    
    For example, say we have the following code.
    
      struct foo {
        int a;
        int b;
      };
    
      struct foo *p = malloc(sizeof(*p));
      p->b = 0;
    
    The last pointer access should produce x86 asm like below:
    
      mov  0x0, 4(%rbx)
    
    And we know %rbx register has a pointer to struct foo.  Then offset 4
    should return the debug info of member 'b'.
    
    Also variables of compound types can be accessed directly without a
    pointer.  The die_get_member_type() is to handle a such case.
    Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
    Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Stephane Eranian <eranian@google.com>
    Link: https://lore.kernel.org/r/20240319055115.4063940-4-namhyung@kernel.org
    [ Check if die_get_real_type() returned NULL ]
    Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    437683a9
dwarf-aux.c 50 KB