[runtime] Improve tracing of process name lookup functions.
authorRodrigo Kumpera <kumpera@gmail.com>
Thu, 16 Mar 2017 18:23:20 +0000 (11:23 -0700)
committerRodrigo Kumpera <kumpera@gmail.com>
Wed, 5 Apr 2017 21:18:25 +0000 (14:18 -0700)
mono/metadata/w32process-unix-default.c
mono/metadata/w32process-unix.c

index 50384b8424431d01e92ef16a28539efe994486d5..3bc10906b8cf008b7dfeac476ec147708730d5e7 100644 (file)
@@ -152,8 +152,10 @@ mono_w32process_get_modules (pid_t pid)
        guint64 device;
 
        fp = open_process_map (pid, "r");
-       if (!fp)
+       if (!fp) {
+               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't open process map file for pid %d", __func__, pid);
                return NULL;
+       }
 
        while (fgets (buf, sizeof(buf), fp)) {
                p = buf;
index 642f77a7ac05941f27fb9ce4bb95adc15234b00c..8f1cc374c26b88e065dbe5318fde1089d7e0bdcf 100644 (file)
@@ -1171,10 +1171,10 @@ mono_w32process_module_get_filename (gpointer process, gpointer module, gunichar
        bytes += 2;
 
        if (size < bytes) {
-               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d smaller than needed (%ld); truncating", __func__, size, bytes);
+               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d smaller than needed (%zd); truncating", __func__, size, bytes);
                memcpy (basename, proc_path, size);
        } else {
-               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d larger than needed (%ld)", __func__, size, bytes);
+               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d larger than needed (%zd)", __func__, size, bytes);
                memcpy (basename, proc_path, bytes);
        }
 
@@ -1197,8 +1197,8 @@ mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 *b
        char *pname = NULL;
        gboolean res;
 
-       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Getting module base name, process handle %p module %p",
-                  __func__, process, module);
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Getting module base name, process handle %p module %p basename %p size %d",
+                  __func__, process, module, basename, size);
 
        size = size * sizeof (gunichar2); /* adjust for unicode characters */
 
@@ -1236,11 +1236,14 @@ mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 *b
        }
 
        if (procname_ext == NULL) {
+               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't find procname_ext from procmods %p", __func__, process);
                /* If it's *still* null, we might have hit the
                 * case where reading /proc/$pid/maps gives an
                 * empty file for this user.
                 */
                procname_ext = mono_w32process_get_name (pid);
+               if (!procname_ext)
+                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't find procname_ext from proc_get_name %p pid %d", __func__, process, pid);
        }
 
        g_slist_free (mods);
@@ -1252,6 +1255,7 @@ mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 *b
 
                procname = mono_unicode_from_external (procname_ext, &bytes);
                if (procname == NULL) {
+                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't get procname %p", __func__, process);
                        /* bugger */
                        g_free (procname_ext);
                        return 0;
@@ -1263,11 +1267,11 @@ mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 *b
                bytes += 2;
 
                if (size < bytes) {
-                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d smaller than needed (%ld); truncating", __func__, size, bytes);
+                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d smaller than needed (%zd); truncating", __func__, size, bytes);
 
                        memcpy (basename, procname, size);
                } else {
-                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d larger than needed (%ld)",
+                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d larger than needed (%zd)",
                                   __func__, size, bytes);
 
                        memcpy (basename, procname, bytes);
@@ -1279,6 +1283,7 @@ mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 *b
                return len;
        }
 
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't find procname_ext %p", __func__, process);
        return 0;
 }