babeltrace/trace-debuginfo.h \
babeltrace/dwarf.h \
babeltrace/so-info.h \
+ babeltrace/utils.h \
babeltrace/ctf-ir/metadata.h \
babeltrace/ctf/events-internal.h \
babeltrace/ctf/metadata.h \
--- /dev/null
+#ifndef _BABELTRACE_DEBUG_INFO_UTILS_H
+#define _BABELTRACE_DEBUG_INFO_UTILS_H
+
+/*
+ * Babeltrace - Debug Info Utilities
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/babeltrace-internal.h>
+
+/*
+ * Return the location of a path's file (the last element of the path).
+ * Returns the original path on error.
+ */
+BT_HIDDEN
+const char *get_filename_from_path(const char *path);
+
+#endif /* _BABELTRACE_DEBUG_INFO_UTILS_H */
noinst_LTLIBRARIES = libdebuginfo.la
libdebuginfo_la_SOURCES = debuginfo.c \
- so-info.c \
- dwarf.c \
- crc32.c
+ so-info.c \
+ dwarf.c \
+ crc32.c \
+ utils.c
libdebuginfo_la_LDFLAGS = -lelf -ldw
endif
#include <babeltrace/debuginfo.h>
#include <babeltrace/so-info.h>
#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/utils.h>
struct proc_debug_info_sources {
/*
g_free(debug_info_src);
}
-/*
- * Returns the location of a path's file (the last element of the path).
- * Returns the original path on error.
- */
-static
-const char *get_filename_from_path(const char *path)
-{
- size_t i = strlen(path);
-
- if (i == 0) {
- goto end;
- }
-
- if (path[i - 1] == '/') {
- /*
- * Path ends with a trailing slash, no filename to return.
- * Return the original path.
- */
- goto end;
- }
-
- while (i-- > 0) {
- if (path[i] == '/') {
- path = &path[i + 1];
- goto end;
- }
- }
-end:
- return path;
-}
-
static
struct debug_info_source *debug_info_source_create_from_so(struct so_info *so,
uint64_t ip)
#include <babeltrace/so-info.h>
#include <babeltrace/crc32.h>
#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/utils.h>
/*
* An address printed in hex is at most 20 bytes (16 for 64-bits +
}
BT_HIDDEN
-int so_info_lookup_function_name(struct so_info *so, uint64_t addr,
+int so_info_lookup_function_name(struct so_info *so, uint64_t ip,
char **func_name)
{
int ret = 0;
char *_func_name = NULL;
+ uint64_t relative_addr;
if (!so || !func_name) {
goto error;
}
}
- if (!so_info_has_address(so, addr)) {
+ if (!so_info_has_address(so, ip)) {
goto error;
}
+ relative_addr = ip - so->low_addr;
/*
* Addresses in ELF and DWARF are relative to base address for
* PIC, so make the address argument relative too if needed.
*/
- if (so->is_pic) {
- addr -= so->low_addr;
- }
-
if (so->is_elf_only) {
- ret = so_info_lookup_elf_function_name(so, addr, &_func_name);
+ ret = so_info_lookup_elf_function_name(so,
+ so->is_pic ? relative_addr : ip,
+ &_func_name);
} else {
- ret = so_info_lookup_dwarf_function_name(so, addr, &_func_name);
+ ret = so_info_lookup_dwarf_function_name(so,
+ so->is_pic ? relative_addr : ip,
+ &_func_name);
}
if (ret) {
goto error;
}
- if (_func_name) {
- *func_name = _func_name;
+ if (!_func_name) {
+ /*
+ * Can't map to a function; fallback to a generic output of the
+ * form binary+/@address.
+ *
+ * FIXME check position independence flag.
+ */
+ const char *binary_name = get_filename_from_path(so->elf_path);
+
+ ret = asprintf(&_func_name, "%s+%#0" PRIx64, binary_name,
+ relative_addr);
+ if (!_func_name) {
+ goto error;
+ }
}
+ *func_name = _func_name;
return 0;
error:
--- /dev/null
+/*
+ * Babeltrace - Debug info utilities
+ *
+ * Copyright (c) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/utils.h>
+
+BT_HIDDEN
+const char *get_filename_from_path(const char *path)
+{
+ size_t i = strlen(path);
+
+ if (i == 0) {
+ goto end;
+ }
+
+ if (path[i - 1] == '/') {
+ /*
+ * Path ends with a trailing slash, no filename to return.
+ * Return the original path.
+ */
+ goto end;
+ }
+
+ while (i-- > 0) {
+ if (path[i] == '/') {
+ path = &path[i + 1];
+ goto end;
+ }
+ }
+end:
+ return path;
+}