-#define SO_MEMSZ 0x400000
-#define FUNC_FOO_ADDR 0x4014ee
-#define FUNC_FOO_LINE_NO 8
-#define FUNC_FOO_FILENAME "/efficios/libhello.c"
-#define FUNC_FOO_TP_ADDR 0x4014d3
-#define FUNC_FOO_TP_LINE_NO 7
-#define FUNC_FOO_TP_FILENAME "/efficios/libhello.c"
-#define FUNC_FOO_ADDR_ELF 0x4013ef
-#define FUNC_FOO_ADDR_DBG_LINK 0x40148e
-#define FUNC_FOO_NAME "foo+0xc3"
-#define FUNC_FOO_NAME_ELF "foo+0x24"
-#define BUILD_ID_LEN 20
-
-char *opt_debug_info_dir;
-char *opt_debug_info_target_prefix;
+/* Size of PIC address mapping */
+#define SO_MEMSZ 0x800000
+/* An address outside the PIC mapping */
+#define SO_INV_ADDR 0x200000
+
+#define BUILD_ID_HEX_LEN 20
+
+static uint64_t opt_func_foo_addr;
+static uint64_t opt_func_foo_printf_offset;
+static uint64_t opt_func_foo_printf_line_no;
+static uint64_t opt_func_foo_tp_offset;
+static uint64_t opt_func_foo_tp_line_no;
+static uint64_t opt_debug_link_crc;
+static gchar *opt_build_id;
+static gchar *opt_debug_info_dir;
+
+static uint64_t func_foo_printf_addr;
+static uint64_t func_foo_tp_addr;
+static char func_foo_printf_name[FUNC_FOO_NAME_LEN];
+static uint8_t build_id[BUILD_ID_HEX_LEN];
+
+static GOptionEntry entries[] = {
+ {"foo-addr", 0, 0, G_OPTION_ARG_INT64, &opt_func_foo_addr,
+ "Offset to printf in foo", "0xX"},
+ {"printf-offset", 0, 0, G_OPTION_ARG_INT64, &opt_func_foo_printf_offset,
+ "Offset to printf in foo", "0xX"},
+ {"printf-lineno", 0, 0, G_OPTION_ARG_INT64,
+ &opt_func_foo_printf_line_no, "Line number to printf in foo", "N"},
+ {"tp-offset", 0, 0, G_OPTION_ARG_INT64, &opt_func_foo_tp_offset,
+ "Offset to tp in foo", "0xX"},
+ {"tp-lineno", 0, 0, G_OPTION_ARG_INT64, &opt_func_foo_tp_line_no,
+ "Line number to tp in foo", "N"},
+ {"debug-link-crc", 0, 0, G_OPTION_ARG_INT64, &opt_debug_link_crc,
+ "Debug link CRC", "0xX"},
+ {"build-id", 0, 0, G_OPTION_ARG_STRING, &opt_build_id, "Build ID",
+ "XXXXXXXXXXXXXXX"},
+ {"debug-info-dir", 0, 0, G_OPTION_ARG_STRING, &opt_debug_info_dir,
+ "Debug info directory", NULL},
+ {NULL}};
+
+static
+int build_id_to_bin(void)
+{
+ int ret, len, i;
+
+ if (opt_build_id == NULL) {
+ goto error;
+ }
+
+ len = strnlen(opt_build_id, BUILD_ID_HEX_LEN * 2);
+ if (len != (BUILD_ID_HEX_LEN * 2)) {
+ goto error;
+ }
+
+ for (i = 0; i < (len / 2); i++) {
+ ret = sscanf(opt_build_id + 2 * i, "%02hhx", &build_id[i]);
+ if (ret != 1) {
+ goto error;
+ }
+ }
+
+ if (i != BUILD_ID_HEX_LEN) {
+ goto error;
+ }
+
+ return 0;
+error:
+ return -1;
+}