19#pragma GCC visibility push(hidden)
24#pragma GCC visibility pop
26typedef struct _libtrace_data
39 .base_names = TRUE, .syms =
nullptr, .abfd =
nullptr, .section =
nullptr, };
43typedef struct _sym_info
55static int translate_addresses (bfd *abfd, asection *section,
void *addr,
char *buf_func,
size_t buf_func_len,
56 char *buf_file,
size_t buf_file_len);
62 const char *errmsg = bfd_errmsg(bfd_get_error());
65 fprintf(stderr,
"%s: %s: %s\n",
program_name,
string, errmsg);
73 vfprintf(stderr,
format, args);
93 if (stat(file_name, &statbuf) < 0) {
95 non_fatal(
"'%s': No such file", file_name);
97 non_fatal(
"Warning: could not locate '%s'. reason: %s", file_name, strerror(errno));
98 }
else if (!S_ISREG (statbuf.st_mode))
99 non_fatal(
"Warning: '%s' is not an ordinary file", file_name);
101 return statbuf.st_size;
114 fprintf(stderr,
"%s: Matching formats: ",
program_name);
116 fprintf(stderr,
" %s", *p++);
128 const char *target = TARGET;
130 if (!bfd_set_default_target(target)) {
131 non_fatal(
"can't set BFD default target to `%s': %s", target, bfd_errmsg(bfd_get_error()));
144 if ((bfd_get_file_flags(abfd) & HAS_SYMS) == 0)
170 if ((bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0)
173 vma = bfd_get_section_vma(abfd, section);
177 size = bfd_get_section_size(section);
178 if (psi->
pc >= vma +
size)
193 if ((bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0)
196 size = bfd_get_section_size(section);
206static int translate_addresses (bfd *abfd, asection *section,
void *xaddr,
char *buf_func,
size_t buf_func_len,
207 char *buf_file,
size_t buf_file_len)
209#define ADDR_BUF_LEN ((CHAR_BIT/4)*(sizeof(void*))+1)
213 sprintf(addr,
"%p", xaddr);
214 si.
pc = bfd_scan_vma(addr,
nullptr, 16);
223 if (buf_func !=
nullptr)
224 snprintf(buf_func, buf_func_len,
"%s ??:0",
m_libtrace_data.with_functions ?
"??" :
"");
229 char *alloc =
nullptr;
232 if (
name ==
nullptr || *
name ==
'\0')
235 alloc = bfd_demangle(abfd,
name, DMGL_ANSI | DMGL_PARAMS);
236 if (alloc !=
nullptr)
240 if (buf_func !=
nullptr)
241 snprintf(buf_func, buf_func_len,
"%s",
name);
247 char *h = strrchr(si.
filename,
'/');
252 if (buf_file !=
nullptr)
265int libtrace_init (
const char *file_name,
const char *section_name,
const char *target)
267 char **matching =
nullptr;
282 non_fatal(
"%s: cannot get addresses from archive", file_name);
286 if (!bfd_check_format_matches(
m_libtrace_data.abfd, bfd_object, &matching)) {
288 if (bfd_get_error() == bfd_error_file_ambiguously_recognized) {
295 if (section_name !=
nullptr) {
298 non_fatal(
"%s: cannot find section %s", file_name, section_name);
318int libtrace_resolve (
void *addr,
char *buf_func,
size_t buf_func_len,
char *buf_file,
size_t buf_file_len, ...)
346int main (
int argc,
char **argv)
348 const char *file_name =
nullptr;
349 const char *section_name =
nullptr;
350 char *target =
nullptr;
352#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
353 setlocale (LC_MESSAGES,
"");
355#if defined (HAVE_SETLOCALE)
356 setlocale (LC_CTYPE,
"");
368#define FUNC_MAX (PATH_MAX)
372 char func[FUNC_MAX + 1] = { 0 };
373 char file[PATH_MAX + 1] = { 0 };
375 for (
i = argc - 2;
i < argc;
i++) {
376 sscanf(argv[
i],
"%p", &sym);
378 printf(
"%s [%s]\n", func, file);
int libtrace_resolve(void *addr, char *buf_func, size_t buf_func_len, char *buf_file, size_t buf_file_len,...)
void bfd_nonfatal(const char *string)
void list_matching_formats(char **p)
static void find_offset_in_section(bfd *, asection *, sym_info *)
static void find_address_in_section(bfd *, asection *, void *)
off_t get_file_size(const char *file_name)
static libtrace_data m_libtrace_data
int libtrace_init(const char *file_name, const char *section_name, const char *target)
static int slurp_symtab(bfd *)
void set_default_bfd_target(void)
void non_fatal(const char *format,...)
static const char * program_name
void report(const char *format, va_list args)
static int translate_addresses(bfd *abfd, asection *section, void *addr, char *buf_func, size_t buf_func_len, char *buf_file, size_t buf_file_len)
int main(int argc, char **argv)
The entry point for linux server and client. Initializes the program and calls Qcommon_Frame in an in...
void format(__printf__, 1, 2)))
QGL_EXTERN GLsizei const GLvoid * data
QGL_EXTERN GLsizei const GLvoid GLenum usage
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
bfd_boolean unwind_inlines
bfd_boolean with_functions
const char * functionname