File: sym.c

package info (click to toggle)
systemtap 5.1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 47,964 kB
  • sloc: cpp: 80,838; ansic: 54,757; xml: 49,725; exp: 43,665; sh: 11,527; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (63 lines) | stat: -rw-r--r-- 1,621 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
struct task_struct;
#include "../sym.h"
#include <assert.h>
#include <elfutils/libdwfl.h>

typedef struct
{
  char *fn;
  unsigned long offset;
} module_args;


static int
module_callback (Dwfl_Module *mod, void **userdata __attribute__((unused)),
                 const char *name, Dwarf_Addr start, void *arg)
{
  module_args *modargs = (module_args*)arg;
  if (strcmp (modargs->fn, name) == 0)
    {
      modargs->offset += start;
      return DWARF_CB_ABORT;
    }

  return DWARF_CB_OK;
}


static unsigned long _stp_umodule_relocate(const char *path,
                                           unsigned long offset,
                                           struct task_struct *task)
{
  static char *debuginfo_path;
  static const Dwfl_Callbacks proc_callbacks =
    {
      .find_debuginfo = dwfl_standard_find_debuginfo,
      .debuginfo_path = &debuginfo_path,

      .find_elf = dwfl_linux_proc_find_elf,
    };
  Dwfl *dwfl = dwfl_begin (&proc_callbacks);
  if (dwfl == NULL)
    _stp_error ("dwfl_begin: %s", dwfl_errmsg (-1));

  int result = dwfl_linux_proc_report (dwfl, getpid());
  if (result < 0)
    _stp_error ("dwfl_linux_proc_report: %s", dwfl_errmsg (-1));
  else if (result > 0)
    _stp_error ("dwfl_linux_proc_report");

  if (dwfl_report_end (dwfl, NULL, NULL) != 0)
    _stp_error ("dwfl_report_end: %s", dwfl_errmsg (-1));

   module_args modargs =
     {
       .fn = (char*)path,
       .offset = offset
     };

   if (dwfl_getmodules (dwfl, module_callback, &modargs, 0) == -1)
     _stp_error ("dwfl_getmodules: %s", dwfl_errmsg (-1));
   dwfl_end (dwfl);
   return modargs.offset;
}