}
static
+int save_kernel_function_event(struct config_writer *writer,
+ struct ltt_kernel_event *event)
+{
+ int ret;
+
+ ret = config_writer_open_element(writer, config_element_function_attributes);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ ret = config_writer_write_element_string(writer, config_element_name,
+ event->event->u.ftrace.symbol_name);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ /* /function attributes */
+ ret = config_writer_close_element(writer);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+end:
+ return ret;
+}
+
+static
+int save_kernel_kprobe_event(struct config_writer *writer,
+ struct ltt_kernel_event *event)
+{
+ int ret;
+ const char *symbol_name;
+ uint64_t addr;
+ uint64_t offset;
+
+ switch (event->event->instrumentation) {
+ case LTTNG_KERNEL_KPROBE:
+ /*
+ * Comments in lttng-kernel.h mention that
+ * either addr or symbol_name are set, not both.
+ */
+ addr = event->event->u.kprobe.addr;
+ offset = event->event->u.kprobe.offset;
+ symbol_name = addr ? NULL : event->event->u.kprobe.symbol_name;
+ break;
+ case LTTNG_KERNEL_KRETPROBE:
+ addr = event->event->u.kretprobe.addr;
+ offset = event->event->u.kretprobe.offset;
+ symbol_name = event->event->u.kretprobe.symbol_name;
+ break;
+ default:
+ assert(1);
+ }
+
+ ret = config_writer_open_element(writer, config_element_probe_attributes);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ if (symbol_name) {
+ ret = config_writer_write_element_string(writer,
+ config_element_symbol_name, symbol_name);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+ }
+
+ if (addr) {
+ ret = config_writer_write_element_unsigned_int( writer,
+ config_element_address, addr);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+ }
+
+ if (offset) {
+ ret = config_writer_write_element_unsigned_int(writer,
+ config_element_offset, offset);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+ }
+
+ ret = config_writer_close_element(writer);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+end:
+ return ret;
+}
int save_kernel_event(struct config_writer *writer,
- struct ltt_kernel_event *event)
+ struct ltt_kernel_event *event)
{
int ret;
const char *instrumentation_type;
switch (event->event->instrumentation) {
case LTTNG_KERNEL_SYSCALL:
case LTTNG_KERNEL_FUNCTION:
- ret = config_writer_open_element(writer,
- config_element_function_attributes);
- if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
- goto end;
- }
-
- ret = config_writer_write_element_string(writer,
- config_element_name,
- event->event->u.ftrace.symbol_name);
+ ret = save_kernel_function_event(writer, event);
if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
- goto end;
- }
-
- /* /function attributes */
- ret = config_writer_close_element(writer);
- if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
}
break;
case LTTNG_KERNEL_KPROBE:
case LTTNG_KERNEL_KRETPROBE:
- {
- const char *symbol_name;
- uint64_t addr;
- uint64_t offset;
-
- if (event->event->instrumentation ==
- LTTNG_KERNEL_KPROBE) {
- /*
- * Comments in lttng-kernel.h mention that
- * either addr or symbol_name are set, not both.
- */
- addr = event->event->u.kprobe.addr;
- offset = event->event->u.kprobe.offset;
- symbol_name = addr ? NULL :
- event->event->u.kprobe.symbol_name;
- } else {
- symbol_name =
- event->event->u.kretprobe.symbol_name;
- addr = event->event->u.kretprobe.addr;
- offset = event->event->u.kretprobe.offset;
- }
-
- ret = config_writer_open_element(writer,
- config_element_probe_attributes);
+ ret = save_kernel_kprobe_event(writer, event);
if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
- goto end;
- }
-
- if (symbol_name) {
- ret = config_writer_write_element_string(writer,
- config_element_symbol_name,
- symbol_name);
- if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
- goto end;
- }
- }
-
- if (addr) {
- ret = config_writer_write_element_unsigned_int(
- writer, config_element_address, addr);
- if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
- goto end;
- }
- }
-
- if (offset) {
- ret = config_writer_write_element_unsigned_int(
- writer, config_element_offset, offset);
- if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
- goto end;
- }
- }
-
- ret = config_writer_close_element(writer);
- if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
}
break;
- }
default:
ERR("Unsupported kernel instrumentation type.");
ret = LTTNG_ERR_INVALID;