| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#include "config.h" |
| 15 |
|
| 16 |
#include <stdlib.h> |
| 17 |
#include <stdio.h> |
| 18 |
#include <sys/utsname.h> |
| 19 |
#ifdef HAVE_BFD_H |
| 20 |
#include <bfd.h> |
| 21 |
#endif |
| 22 |
#include <string.h> |
| 23 |
#include <unistd.h> |
| 24 |
#include <sys/types.h> |
| 25 |
#include <sys/stat.h> |
| 26 |
|
| 27 |
#include "lookup.h" |
| 28 |
|
| 29 |
#ifdef HAVE_BFD_H |
| 30 |
extern struct lookup_methods bfd_methods; |
| 31 |
#endif |
| 32 |
extern struct lookup_methods kallsym_methods; |
| 33 |
|
| 34 |
static int lookup_null_init(void) |
| 35 |
{ |
| 36 |
printf("Initializing null lookup method\n"); |
| 37 |
return 0; |
| 38 |
} |
| 39 |
|
| 40 |
static int lookup_null_sym(void *pc, struct loc_result *location) |
| 41 |
{ |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
return 1; |
| 46 |
} |
| 47 |
|
| 48 |
static struct lookup_methods null_methods = { |
| 49 |
lookup_null_init, |
| 50 |
lookup_null_sym, |
| 51 |
}; |
| 52 |
|
| 53 |
static struct lookup_methods *methods = NULL; |
| 54 |
|
| 55 |
int init_lookup(lookup_init_method_t method) |
| 56 |
{ |
| 57 |
int rc; |
| 58 |
switch (method) { |
| 59 |
case METHOD_NULL: |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
methods = &null_methods; |
| 66 |
break; |
| 67 |
case METHOD_AUTO: |
| 68 |
#ifdef HAVE_BFD_H |
| 69 |
methods = &bfd_methods; |
| 70 |
if (methods->lookup_init() == 0) |
| 71 |
return 0; |
| 72 |
#endif |
| 73 |
methods = &kallsym_methods; |
| 74 |
if (methods->lookup_init() == 0) |
| 75 |
return 0; |
| 76 |
methods = NULL; |
| 77 |
return -1; |
| 78 |
#ifdef HAVE_BFD_H |
| 79 |
case METHOD_DEBUGINFO: |
| 80 |
methods = &bfd_methods; |
| 81 |
break; |
| 82 |
#endif |
| 83 |
case METHOD_KALLSYMS: |
| 84 |
methods = &kallsym_methods; |
| 85 |
break; |
| 86 |
} |
| 87 |
|
| 88 |
rc = methods->lookup_init(); |
| 89 |
if (rc < 0) |
| 90 |
methods = NULL; |
| 91 |
return rc; |
| 92 |
} |
| 93 |
|
| 94 |
int lookup_symbol(void *pc, struct loc_result *loc) |
| 95 |
{ |
| 96 |
if (loc == NULL) |
| 97 |
return 1; |
| 98 |
return methods->get_symbol(pc, loc); |
| 99 |
} |