Ejemplo n.º 1
0
static void
gimp_eek (const gchar *reason,
          const gchar *message,
          gboolean     use_handler)
{
#ifndef G_OS_WIN32
    g_printerr ("%s: %s: %s\n", gimp_filename_to_utf8 (full_prog_name),
                reason, message);

    if (use_handler)
    {
        switch (stack_trace_mode)
        {
        case GIMP_STACK_TRACE_NEVER:
            break;

        case GIMP_STACK_TRACE_QUERY:
        {
            sigset_t sigset;

            sigemptyset (&sigset);
            sigprocmask (SIG_SETMASK, &sigset, NULL);

            if (the_errors_gimp)
                gimp_gui_ungrab (the_errors_gimp);

            g_on_error_query (full_prog_name);
        }
        break;

        case GIMP_STACK_TRACE_ALWAYS:
        {
            sigset_t sigset;

            sigemptyset (&sigset);
            sigprocmask (SIG_SETMASK, &sigset, NULL);

            g_on_error_stack_trace (full_prog_name);
        }
        break;

        default:
            break;
        }
    }
#else

    /* g_on_error_* don't do anything reasonable on Win32. */

    MessageBox (NULL, g_strdup_printf ("%s: %s", reason, message),
                full_prog_name, MB_OK|MB_ICONERROR);

#endif /* ! G_OS_WIN32 */

    exit (EXIT_FAILURE);
}
Ejemplo n.º 2
0
static void
mp_start_entry(gpointer entry, gsize size)
{
  gdouble ts;
  MpNode *node;
  
  if (!size)
    return;
  
  ts = mp_get_timestamp();
  node = (MpNode *)entry;
  node->cookie = MP_COOKIE;
  node->next = node->prev = NULL;
  node->size = size;
  node->ts = ts;
  mp_list_insert_entry (node);
  mp_log_usage(ts);

  if( size == mp_trace_size) {
    if (mp_trace_interactive) {
      gpointer trace[MP_BACKTRACE_DEPTH];
      gint i, count = backtrace (trace, MP_BACKTRACE_DEPTH);
      gchar **strings = backtrace_symbols (trace, count);

      printf ("Allocating %d byte(s) at %lf sec\n", size, ts);
      for (i = 0; i < count; i++)
        printf ("  %s\n", strings[i]);
      free (strings);
      g_on_error_query (NULL);
      // I don't get meaningful backtraces from this :/
      //G_BREAKPOINT();
    }
    else {
      FILE *log;

      if ((log = fopen (MP_BT_LOG,"at"))) {
        gpointer trace[MP_BACKTRACE_DEPTH];
        gint i, count = backtrace (trace, MP_BACKTRACE_DEPTH);

        fprintf (log,"%p", trace[0]);
        for (i = 1; i < count; i++)
          fprintf (log,", %p", trace[i]);
        fprintf (log,"\n", trace[i]);
        fclose(log);
      }
    }
  }
}
Ejemplo n.º 3
0
int
main (int   arg,
      char *argv[])
{
  GModule *module_self, *module_a, *module_b;
  gchar *string;
  gchar *plugin_a, *plugin_b;
  SimpleFunc f_a, f_b, f_self;
  GModuleFunc gmod_f;

  string = g_get_current_dir ();
  g_print ("testgmodule (%s):\n", string);

#if (G_MODULE_IMPL == G_MODULE_IMPL_WIN32)
  plugin_a = g_strconcat (string, "\\libgplugin_a.dll", NULL);
  plugin_b = g_strconcat (string, "\\libgplugin_b.dll", NULL);
#elif (G_MODULE_IMPL == G_MODULE_IMPL_DLD)
  plugin_a = g_strconcat (string, "/.libs/", "libgplugin_a.sl", NULL);
  plugin_b = g_strconcat (string, "/.libs/", "libgplugin_b.sl", NULL);
#else /* neither DLD nor WIN32 */
  plugin_a = g_strconcat (string, "/.libs/", "libgplugin_a.so", NULL);
  plugin_b = g_strconcat (string, "/.libs/", "libgplugin_b.so", NULL);
#endif
  g_free (string);

  /* module handles
   */
  g_print ("get main module handle\n");
  module_self = g_module_open (NULL, G_MODULE_BIND_LAZY);
  if (!module_self)
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("check that not yet bound symbols in shared libraries of main module are retrievable:\n");
  string = "g_module_close";
  g_print ("retrive symbol `%s' from \"%s\":\n", string, g_basename (g_module_name (module_self)));
  if (!g_module_symbol (module_self, string, (gpointer) &f_self))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("retrived symbol `%s' as %p\n", string, f_self);
  g_print ("load plugin from \"%s\"\n", plugin_a);
  module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
  if (!module_a)
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("load plugin from \"%s\"\n", plugin_b);
  module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
  if (!module_b)
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }

  /* get plugin specific symbols and call them
   */
  string = "gplugin_a_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
  if (!g_module_symbol (module_a, string, (gpointer) &f_a))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  string = "gplugin_b_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
  if (!g_module_symbol (module_b, string, (gpointer) &f_b))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("call plugin function(%p) A: ", f_a);
  f_a ();
  g_print ("call plugin function(%p) B: ", f_b);
  f_b ();

  /* get and call globally clashing functions
   */
  string = "g_clash_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_self)));
  if (!g_module_symbol (module_self, string, (gpointer) &f_self))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
  if (!g_module_symbol (module_a, string, (gpointer) &f_a))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
  if (!g_module_symbol (module_b, string, (gpointer) &f_b))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("call plugin function(%p) self: ", f_self);
  f_self ();
  g_print ("call plugin function(%p) A: ", f_a);
  f_a ();
  g_print ("call plugin function(%p) B: ", f_b);
  f_b ();

  /* get and call clashing plugin functions
   */
  string = "gplugin_clash_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_self)));
  if (!g_module_symbol (module_self, string, (gpointer) &f_self))
    f_self = NULL;
  g_print ("retrived function `%s' from self: %p\n", string, f_self);
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
  if (!g_module_symbol (module_a, string, (gpointer) &f_a))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
  if (!g_module_symbol (module_b, string, (gpointer) &f_b))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("call plugin function(%p) A: ", f_a);
  plugin_clash_func = f_a;
  plugin_clash_func ();
  g_print ("call plugin function(%p) B: ", f_b);
  plugin_clash_func = f_b;
  plugin_clash_func ();

  /* call gmodule function form A
   */
  string = "gplugin_a_module_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
  if (!g_module_symbol (module_a, string, (gpointer) &gmod_f))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("call plugin A's module function(%p):\n{\n", gmod_f);
  gmod_f (module_b);
  g_print ("}\n");

  
  /* unload plugins
   */
  g_print ("unload plugin A:\n");
  if (!g_module_close (module_a))
    g_print ("error: %s\n", g_module_error ());
  g_print ("unload plugin B:\n");
  if (!g_module_close (module_b))
    g_print ("error: %s\n", g_module_error ());

#if 0
  g_log_set_fatal_mask ("GModule", G_LOG_FATAL_MASK|G_LOG_LEVEL_WARNING);
  g_module_symbol (0, 0, 0);
  g_warning("jahooo");
  g_on_error_query (".libs/testgmodule");
#endif
  
  return 0;
}