#define MAX_PATH_LEN 256
#define MAX_PROBES 128
+#define MAX_PROBE_ARGS 128
/* Session management structure */
static struct {
char *events[MAX_PROBES];
} session;
-static void semantic_error(const char *msg)
-{
- fprintf(stderr, "Semantic error: %s\n", msg);
- exit(1);
-}
-
-static void perror_exit(const char *msg)
-{
- perror(msg);
- exit(1);
-}
-
-#define MAX_PROBE_ARGS 128
+#define semantic_error(msg ...) die("Semantic error :" msg)
static int parse_probepoint(const struct option *opt __used,
const char *str, int unset __used)
/* Duplicate the argument */
argv[argc] = strndup(s, str - s);
if (argv[argc] == NULL)
- perror_exit("strndup");
+ die("strndup");
if (++argc == MAX_PROBE_ARGS)
semantic_error("Too many arguments");
debug("argv[%d]=%s\n", argc, argv[argc - 1]);
if (pp->nr_args > 0) {
pp->args = (char **)malloc(sizeof(char *) * pp->nr_args);
if (!pp->args)
- perror_exit("malloc");
+ die("malloc");
memcpy(pp->args, &argv[2], sizeof(char *) * pp->nr_args);
}
printf("Adding new event: %s\n", buf);
ret = write(fd, buf, strlen(buf));
if (ret <= 0)
- perror("Error: Failed to create event");
+ die("failed to create event.");
return ret;
}
int i, len, ret;
pp->probes[0] = buf = (char *)calloc(MAX_CMDLEN, sizeof(char));
if (!buf)
- perror_exit("calloc");
+ die("calloc");
ret = snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset);
if (ret <= 0 || ret >= MAX_CMDLEN)
goto error;
ret = synthesize_probepoint(&session.probes[j]);
if (ret == -E2BIG)
semantic_error("probe point is too long.");
- else if (ret < 0) {
- perror("snprintf");
- return -1;
- }
+ else if (ret < 0)
+ die("snprintf");
}
#ifndef NO_LIBDWARF
fd = open(session.vmlinux, O_RDONLY);
else
fd = open_default_vmlinux();
- if (fd < 0) {
- perror("vmlinux/module file open");
- return -1;
- }
+ if (fd < 0)
+ die("vmlinux/module file open");
/* Searching probe points */
for (j = 0; j < session.nr_probe; j++) {
lseek(fd, SEEK_SET, 0);
ret = find_probepoint(fd, pp);
- if (ret <= 0) {
- fprintf(stderr, "Error: No probe point found.\n");
- return -1;
- }
+ if (ret <= 0)
+ die("No probe point found.\n");
debug("probe event %s found\n", session.events[j]);
}
close(fd);
/* Settng up probe points */
snprintf(buf, MAX_CMDLEN, "%s/../kprobe_events", debugfs_path);
fd = open(buf, O_WRONLY, O_APPEND);
- if (fd < 0) {
- perror("kprobe_events open");
- return -1;
- }
+ if (fd < 0)
+ die("kprobe_events open");
for (j = 0; j < session.nr_probe; j++) {
pp = &session.probes[j];
if (pp->found == 1) {
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
+
+#include "util.h"
#include "probe-finder.h"
static Dwarf_Debug __dw_debug;
static Dwarf_Error __dw_error;
-static void msg_exit(int ret, const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- fprintf(stderr, "Error: ");
- vfprintf(stderr, fmt, ap);
- va_end(ap);
-
- fprintf(stderr, "\n");
- exit(ret);
-}
-
-
/*
* Generic dwarf analysis helpers
*/
}
/* Compare diename and tname */
-static int die_compare_name(Dwarf_Die die, const char *tname)
+static int die_compare_name(Dwarf_Die dw_die, const char *tname)
{
char *name;
int ret;
- ret = dwarf_diename(die, &name, &__dw_error);
+ ret = dwarf_diename(dw_die, &name, &__dw_error);
ERR_IF(ret == DW_DLV_ERROR);
if (ret == DW_DLV_OK) {
ret = strcmp(tname, name);
}
/* Check the die is inlined function */
-static Dwarf_Bool die_inlined_subprogram(Dwarf_Die die)
+static Dwarf_Bool die_inlined_subprogram(Dwarf_Die dw_die)
{
/* TODO: check strictly */
Dwarf_Bool inl;
int ret;
- ret = dwarf_hasattr(die, DW_AT_inline, &inl, &__dw_error);
+ ret = dwarf_hasattr(dw_die, DW_AT_inline, &inl, &__dw_error);
ERR_IF(ret == DW_DLV_ERROR);
return inl;
}
/* Get the offset of abstruct_origin */
-static Dwarf_Off die_get_abstract_origin(Dwarf_Die die)
+static Dwarf_Off die_get_abstract_origin(Dwarf_Die dw_die)
{
Dwarf_Attribute attr;
Dwarf_Off cu_offs;
int ret;
- ret = dwarf_attr(die, DW_AT_abstract_origin, &attr, &__dw_error);
+ ret = dwarf_attr(dw_die, DW_AT_abstract_origin, &attr, &__dw_error);
ERR_IF(ret != DW_DLV_OK);
ret = dwarf_formref(attr, &cu_offs, &__dw_error);
ERR_IF(ret != DW_DLV_OK);
}
/* Get entry pc(or low pc, 1st entry of ranges) of the die */
-static Dwarf_Addr die_get_entrypc(Dwarf_Die die)
+static Dwarf_Addr die_get_entrypc(Dwarf_Die dw_die)
{
Dwarf_Attribute attr;
Dwarf_Addr addr;
int ret;
/* Try to get entry pc */
- ret = dwarf_attr(die, DW_AT_entry_pc, &attr, &__dw_error);
+ ret = dwarf_attr(dw_die, DW_AT_entry_pc, &attr, &__dw_error);
ERR_IF(ret == DW_DLV_ERROR);
if (ret == DW_DLV_OK) {
ret = dwarf_formaddr(attr, &addr, &__dw_error);
}
/* Try to get low pc */
- ret = dwarf_lowpc(die, &addr, &__dw_error);
+ ret = dwarf_lowpc(dw_die, &addr, &__dw_error);
ERR_IF(ret == DW_DLV_ERROR);
if (ret == DW_DLV_OK)
return addr;
/* Try to get ranges */
- ret = dwarf_attr(die, DW_AT_ranges, &attr, &__dw_error);
+ ret = dwarf_attr(dw_die, DW_AT_ranges, &attr, &__dw_error);
ERR_IF(ret != DW_DLV_OK);
ret = dwarf_formref(attr, &offs, &__dw_error);
ERR_IF(ret != DW_DLV_OK);
} else if (op == DW_OP_regx) {
regn = loc->lr_number;
} else
- msg_exit(-EINVAL, "Dwarf_OP %d is not supported.\n", op);
+ die("Dwarf_OP %d is not supported.\n", op);
regs = get_arch_regstr(regn);
if (!regs)
- msg_exit(-EINVAL, "%lld exceeds max register number.\n", regn);
+ die("%lld exceeds max register number.\n", regn);
if (deref)
ret = snprintf(pf->buf, pf->len,
dwarf_dealloc(__dw_debug, attr, DW_DLA_ATTR);
return ;
error:
- msg_exit(-1, "Failed to find the location of %s at this address.\n"
- " Perhaps, it was optimized out.\n", pf->var);
+ die("Failed to find the location of %s at this address.\n"
+ " Perhaps, it has been optimized out.\n", pf->var);
}
static int variable_callback(struct die_link *dlink, void *data)
/* Search child die for local variables and parameters. */
ret = search_die_from_children(sp_die, variable_callback, pf);
if (!ret)
- msg_exit(-1, "Failed to find '%s' in this function.\n",
- pf->var);
+ die("Failed to find '%s' in this function.\n", pf->var);
}
/* Get a frame base on the address */
/* Search a real subprogram including this line, */
ret = search_die_from_children(cu_die, probeaddr_callback, pf);
if (ret == 0)
- msg_exit(-1,
- "Probe point is not found in subprograms.\n");
+ die("Probe point is not found in subprograms.\n");
/* Continuing, because target line might be inlined. */
}
dwarf_srclines_dealloc(__dw_debug, lines, cnt);
!die_inlined_subprogram(lk->die))
goto found;
}
- msg_exit(-1, "Failed to find real subprogram.\n");
+ die("Failed to find real subprogram.\n");
found:
/* Get offset from subprogram */
ret = die_within_subprogram(lk->die, pf->addr, &offs);
ret = dwarf_init(fd, DW_DLC_READ, 0, 0, &__dw_debug, &__dw_error);
if (ret != DW_DLV_OK)
- msg_exit(-1, "Failed to call dwarf_init(). "
- "Maybe, not a dwarf file?\n");
+ die("Failed to call dwarf_init(). Maybe, not a dwarf file.\n");
pp->found = 0;
while (++cu_number) {