Require C++11 for building probe providers with C++ compiler
[lttng-ust.git] / liblttng-ust / lttng-ust-statedump.c
index 2fb8f34d9b4f4e34d803813498187273441fc487..040223d58409bd93b2ceedb9d8d8979e463beac1 100644 (file)
@@ -34,6 +34,8 @@
 #include "lttng-tracer-core.h"
 #include "lttng-ust-statedump.h"
 #include "jhash.h"
+#include "getenv.h"
+#include "compat.h"
 
 #define TRACEPOINT_DEFINE
 #include "ust_lib.h"                           /* Only define. */
@@ -245,6 +247,13 @@ void trace_debug_link_cb(struct lttng_session *session, void *priv)
                bin_data->dbg_file, bin_data->crc);
 }
 
+static
+void procname_cb(struct lttng_session *session, void *priv)
+{
+       char *procname = (char *) priv;
+       tracepoint(lttng_ust_statedump, procname, session, procname);
+}
+
 static
 void trace_start_cb(struct lttng_session *session, void *priv)
 {
@@ -413,6 +422,8 @@ void iter_end(struct dl_iterate_data *data, void *ip)
 {
        unsigned int i;
 
+       if (data->cancel)
+               goto end;
        /*
         * Iterate on hash table.
         * For each marked, traced, do nothing.
@@ -440,6 +451,7 @@ void iter_end(struct dl_iterate_data *data, void *ip)
                        }
                }
        }
+end:
        ust_unlock();
 }
 
@@ -548,9 +560,15 @@ void lttng_ust_dl_update(void *ip)
 {
        struct dl_iterate_data data;
 
-       if (getenv("LTTNG_UST_WITHOUT_BADDR_STATEDUMP"))
+       if (lttng_getenv("LTTNG_UST_WITHOUT_BADDR_STATEDUMP"))
                return;
 
+       /*
+        * Fixup lttng-ust TLS when called from dlopen/dlclose
+        * instrumentation.
+        */
+       lttng_ust_fixup_tls();
+
        data.exec_found = 0;
        data.first = true;
        data.cancel = false;
@@ -576,13 +594,23 @@ void lttng_ust_dl_update(void *ip)
 static
 int do_baddr_statedump(void *owner)
 {
-       if (getenv("LTTNG_UST_WITHOUT_BADDR_STATEDUMP"))
+       if (lttng_getenv("LTTNG_UST_WITHOUT_BADDR_STATEDUMP"))
                return 0;
        lttng_ust_dl_update(LTTNG_UST_CALLER_IP());
        ust_dl_table_statedump(owner);
        return 0;
 }
 
+static
+int do_procname_statedump(void *owner)
+{
+       if (lttng_getenv("LTTNG_UST_WITHOUT_PROCNAME_STATEDUMP"))
+               return 0;
+
+       trace_statedump_event(procname_cb, owner, lttng_ust_sockinfo_get_procname(owner));
+       return 0;
+}
+
 /*
  * Generate a statedump of a given traced application. A statedump is
  * delimited by start and end events. For a given (process, session)
@@ -590,12 +618,23 @@ int do_baddr_statedump(void *owner)
  * session, statedumps from different processes may be
  * interleaved. The vpid context should be used to identify which
  * events belong to which process.
+ *
+ * Grab the ust_lock outside of the RCU read-side lock because we
+ * perform synchronize_rcu with the ust_lock held, which can trigger
+ * deadlocks otherwise.
  */
 int do_lttng_ust_statedump(void *owner)
 {
+       ust_lock_nocheck();
        trace_statedump_start(owner);
+       ust_unlock();
+
+       do_procname_statedump(owner);
        do_baddr_statedump(owner);
+
+       ust_lock_nocheck();
        trace_statedump_end(owner);
+       ust_unlock();
 
        return 0;
 }
This page took 0.024588 seconds and 4 git commands to generate.