Fix: lttng: initialize sessions pointer to NULL
[lttng-tools.git] / src / bin / lttng / commands / list.c
index 5816a05de36783f7250ed992244c20ce69399081..65d8ea6f5c45424444262f87dd4ff7c7e38bbb70 100644 (file)
@@ -24,6 +24,7 @@
 #include <assert.h>
 
 #include <common/mi-lttng.h>
+#include <common/time.h>
 #include <lttng/constant.h>
 
 #include "../command.h"
@@ -249,6 +250,82 @@ end:
        return exclusion_msg;
 }
 
+static void print_userspace_probe_location(struct lttng_event *event)
+{
+       const struct lttng_userspace_probe_location *location;
+       const struct lttng_userspace_probe_location_lookup_method *lookup_method;
+       enum lttng_userspace_probe_location_lookup_method_type lookup_type;
+
+       location = lttng_event_get_userspace_probe_location(event);
+       if (!location) {
+               MSG("Event has no userspace probe location");
+               return;
+       }
+
+       lookup_method = lttng_userspace_probe_location_get_lookup_method(location);
+       if (!lookup_method) {
+               MSG("Event has no userspace probe location lookup method");
+               return;
+       }
+
+       MSG("%s%s (type: userspace-probe)%s", indent6, event->name, enabled_string(event->enabled));
+
+       lookup_type = lttng_userspace_probe_location_lookup_method_get_type(lookup_method);
+
+       switch (lttng_userspace_probe_location_get_type(location)) {
+       case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_UNKNOWN:
+               MSG("%sType: Unknown", indent8);
+               break;
+       case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_FUNCTION:
+       {
+               const char *function_name;
+               const char *binary_path;
+
+               MSG("%sType: Function", indent8);
+               function_name = lttng_userspace_probe_location_function_get_function_name(location);
+               binary_path = realpath(lttng_userspace_probe_location_function_get_binary_path(location), NULL);
+
+               MSG("%sBinary path:   %s", indent8, binary_path ? binary_path : "NULL");
+               MSG("%sFunction:      %s()", indent8, function_name ? function_name : "NULL");
+               switch (lookup_type) {
+               case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF:
+                       MSG("%sLookup method: ELF", indent8);
+                       break;
+               case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_DEFAULT:
+                       MSG("%sLookup method: default", indent8);
+                       break;
+               default:
+                       MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8);
+                       break;
+               }
+               break;
+       }
+       case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT:
+       {
+               const char *probe_name, *provider_name;
+               const char *binary_path;
+
+               MSG("%sType: Tracepoint", indent8);
+               probe_name = lttng_userspace_probe_location_tracepoint_get_probe_name(location);
+               provider_name = lttng_userspace_probe_location_tracepoint_get_provider_name(location);
+               binary_path = realpath(lttng_userspace_probe_location_tracepoint_get_binary_path(location), NULL);
+               MSG("%sBinary path:   %s", indent8, binary_path ? binary_path : "NULL");
+               MSG("%sTracepoint:    %s:%s", indent8, provider_name ? provider_name : "NULL", probe_name ? probe_name : "NULL");
+               switch (lookup_type) {
+               case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT:
+                       MSG("%sLookup method: SDT", indent8);
+                       break;
+               default:
+                       MSG("%sLookup method: INVALID LOOKUP TYPE ENCOUNTERED", indent8);
+                       break;
+               }
+               break;
+       }
+       default:
+               ERR("Invalid probe type encountered");
+       }
+}
+
 /*
  * Pretty print single event.
  */
@@ -324,6 +401,9 @@ static void print_events(struct lttng_event *event)
                        MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
                }
                break;
+       case LTTNG_EVENT_USERSPACE_PROBE:
+               print_userspace_probe_location(event);
+               break;
        case LTTNG_EVENT_FUNCTION_ENTRY:
                MSG("%s%s (type: function)%s%s", indent6,
                                event->name, enabled_string(event->enabled),
@@ -343,6 +423,8 @@ static void print_events(struct lttng_event *event)
                                safe_string(filter_msg));
                break;
        case LTTNG_EVENT_ALL:
+               /* Fall-through. */
+       default:
                /* We should never have "all" events in list. */
                assert(0);
                break;
@@ -1180,7 +1262,7 @@ void print_timer(const char *timer_name, uint32_t space_count, int64_t value)
        }
 
        if (value) {
-               MSG("%" PRId64 " µs", value);
+               MSG("%" PRId64 " %s", value, USEC_UNIT);
        } else {
                MSG("inactive");
        }
@@ -1237,7 +1319,8 @@ static void print_channel(struct lttng_channel *channel)
                if (blocking_timeout == -1) {
                        MSG("%sBlocking timeout: infinite", indent6);
                } else {
-                       MSG("%sBlocking timeout: %" PRId64 " µs", indent6, blocking_timeout);
+                       MSG("%sBlocking timeout: %" PRId64 " %s", indent6,
+                                       blocking_timeout, USEC_UNIT);
                }
        }
 
@@ -1535,7 +1618,7 @@ static enum cmd_error_code print_periodic_rotation_schedule(
                goto end;
        }
 
-       MSG("    timer period: %" PRIu64" µs", value);
+       MSG("    timer period: %" PRIu64" %s", value, USEC_UNIT);
        ret = CMD_SUCCESS;
 end:
        return ret;
@@ -1742,7 +1825,7 @@ static int list_sessions(const char *session_name)
        int ret = CMD_SUCCESS;
        int count, i;
        unsigned int session_found = 0;
-       struct lttng_session *sessions;
+       struct lttng_session *sessions = NULL;
 
        count = lttng_list_sessions(&sessions);
        DBG("Session count %d", count);
@@ -1755,7 +1838,7 @@ static int list_sessions(const char *session_name)
        if (lttng_opt_mi) {
                /* Mi */
                if (session_name == NULL) {
-                       /* List all session */
+                       /* List all sessions */
                        ret = mi_list_sessions(sessions, count);
                } else {
                        /* Note : this return an open session element */
@@ -1763,7 +1846,7 @@ static int list_sessions(const char *session_name)
                }
                if (ret) {
                        ret = CMD_ERROR;
-                       goto error;
+                       goto end;
                }
        } else {
                /* Pretty print */
@@ -1776,7 +1859,6 @@ static int list_sessions(const char *session_name)
                        MSG("Available tracing sessions:");
                }
 
-
                for (i = 0; i < count; i++) {
                        if (session_name != NULL) {
                                if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
@@ -1784,20 +1866,25 @@ static int list_sessions(const char *session_name)
                                        MSG("Tracing session %s: [%s%s]", session_name,
                                                        active_string(sessions[i].enabled),
                                                        snapshot_string(sessions[i].snapshot_mode));
-                                       MSG("%sTrace path: %s\n", indent4, sessions[i].path);
+                                       if (*sessions[i].path) {
+                                               MSG("%sTrace output: %s\n", indent4, sessions[i].path);
+                                       }
                                        memcpy(&listed_session, &sessions[i],
                                                        sizeof(listed_session));
                                        break;
                                }
                        } else {
-                               MSG("  %d) %s (%s) [%s%s]", i + 1,
-                                               sessions[i].name, sessions[i].path,
+                               MSG("  %d) %s [%s%s]", i + 1,
+                                               sessions[i].name,
                                                active_string(sessions[i].enabled),
                                                snapshot_string(sessions[i].snapshot_mode));
-                               MSG("%sTrace path: %s", indent4, sessions[i].path);
+                               if (*sessions[i].path) {
+                                       MSG("%sTrace output: %s", indent4, sessions[i].path);
+                               }
                                if (sessions[i].live_timer_interval != 0) {
-                                       MSG("%sLive timer interval: %u µs", indent4,
-                                                       sessions[i].live_timer_interval);
+                                       MSG("%sLive timer interval: %u %s", indent4,
+                                                       sessions[i].live_timer_interval,
+                                                       USEC_UNIT);
                                }
                                MSG("");
                        }
@@ -1806,7 +1893,7 @@ static int list_sessions(const char *session_name)
                if (!session_found && session_name != NULL) {
                        ERR("Session '%s' not found", session_name);
                        ret = CMD_ERROR;
-                       goto error;
+                       goto end;
                }
 
                if (session_name == NULL) {
@@ -1814,9 +1901,8 @@ static int list_sessions(const char *session_name)
                }
        }
 
-error:
-       free(sessions);
 end:
+       free(sessions);
        return ret;
 }
 
This page took 0.026545 seconds and 4 git commands to generate.