static gpointer profiler_calloc (gsize n_blocks, gsize n_block_bytes) { gsize l = n_blocks * n_block_bytes; gsize *p; #ifdef G_ENABLE_DEBUG if (g_trap_malloc_size == l) G_BREAKPOINT (); #endif /* G_ENABLE_DEBUG */ p = calloc (1, sizeof (gsize) * 2 + l); if (p) { p[0] = 0; /* free count */ p[1] = l; /* length */ profiler_log (PROFILER_ALLOC | PROFILER_ZINIT, l, TRUE); p += 2; } else { profiler_log (PROFILER_ALLOC | PROFILER_ZINIT, l, FALSE); g_mem_profile (); } return p; }
static void profiler_free (gpointer mem) { gsize *p = mem; p -= 2; if (p[0]) /* free count */ { g_warning ("free(%p): memory has been freed %"G_GSIZE_FORMAT" times already", p + 2, p[0]); profiler_log (PROFILER_FREE, p[1], /* length */ FALSE); } else { #ifdef G_ENABLE_DEBUG if (g_trap_free_size == p[1]) G_BREAKPOINT (); #endif /* G_ENABLE_DEBUG */ profiler_log (PROFILER_FREE, p[1], /* length */ TRUE); memset (p + 2, 0xaa, p[1]); /* for all those that miss free (p); in this place, yes, * we do leak all memory when profiling, and that is intentional * to catch double frees. patch submissions are futile. */ } p[0] += 1; }
static JSBool gjs_breakpoint(JSContext *context, unsigned argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); if (!gjs_parse_args(context, "breakpoint", "", argc, argv)) return JS_FALSE; G_BREAKPOINT(); return JS_TRUE; }
static void glade_log_handler (const char *domain, GLogLevelFlags level, const char *message, gpointer data) { static volatile int want_breakpoint = 0; /* Ignore this message */ if (g_strcmp0 ("gdk_window_set_composited called but compositing is not supported", message) != 0) g_log_default_handler (domain, level, message, data); if (want_breakpoint && ((level & (G_LOG_LEVEL_CRITICAL /* | G_LOG_LEVEL_WARNING */ )) != 0)) G_BREAKPOINT (); }
static gpointer profiler_try_realloc (gpointer mem, gsize n_bytes) { gsize *p = mem; p -= 2; #ifdef G_ENABLE_DEBUG if (g_trap_realloc_size == n_bytes) G_BREAKPOINT (); #endif /* G_ENABLE_DEBUG */ if (mem && p[0]) /* free count */ { g_warning ("realloc(%p, %"G_GSIZE_FORMAT"): " "memory has been freed %"G_GSIZE_FORMAT" times already", p + 2, (gsize) n_bytes, p[0]); profiler_log (PROFILER_ALLOC | PROFILER_RELOC, n_bytes, FALSE); return NULL; } else { p = realloc (mem ? p : NULL, sizeof (gsize) * 2 + n_bytes); if (p) { if (mem) profiler_log (PROFILER_FREE | PROFILER_RELOC, p[1], TRUE); p[0] = 0; p[1] = n_bytes; profiler_log (PROFILER_ALLOC | PROFILER_RELOC, p[1], TRUE); p += 2; } else profiler_log (PROFILER_ALLOC | PROFILER_RELOC, n_bytes, FALSE); return p; } }
EXPORT_C void g_on_error_stack_trace (const gchar *prg_name) { #if defined(G_OS_UNIX) || defined(G_OS_BEOS) pid_t pid; gchar buf[16]; gchar *args[4] = { "gdb", NULL, NULL, NULL }; int status; if (!prg_name) return; _g_sprintf (buf, "%u", (guint) getpid ()); args[1] = (gchar*) prg_name; args[2] = buf; pid = fork (); if (pid == 0) { stack_trace (args); _exit (0); } else if (pid == (pid_t) -1) { perror ("unable to fork gdb"); return; } waitpid (pid, &status, 0); #elif defined(__SYMBIAN32__) abort(); #else if (IsDebuggerPresent ()) G_BREAKPOINT (); else abort (); #endif }
static gpointer profiler_try_malloc (gsize n_bytes) { gsize *p; #ifdef G_ENABLE_DEBUG if (g_trap_malloc_size == n_bytes) G_BREAKPOINT (); #endif /* G_ENABLE_DEBUG */ p = malloc (sizeof (gsize) * 2 + n_bytes); if (p) { p[0] = 0; /* free count */ p[1] = n_bytes; /* length */ profiler_log (PROFILER_ALLOC, n_bytes, TRUE); p += 2; } else profiler_log (PROFILER_ALLOC, n_bytes, FALSE); return p; }
void g_logv (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args1) { gboolean was_fatal = (log_level & G_LOG_FLAG_FATAL) != 0; gboolean was_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0; gint i; log_level &= G_LOG_LEVEL_MASK; if (!log_level) return; for (i = g_bit_nth_msf (log_level, -1); i >= 0; i = g_bit_nth_msf (log_level, i)) { register GLogLevelFlags test_level; test_level = 1 << i; if (log_level & test_level) { guint depth = GPOINTER_TO_UINT (g_private_get (g_log_depth)); GLogDomain *domain; GLogFunc log_func; GLogLevelFlags domain_fatal_mask; gpointer data = NULL; gboolean masquerade_fatal = FALSE; if (was_fatal) test_level |= G_LOG_FLAG_FATAL; if (was_recursion) test_level |= G_LOG_FLAG_RECURSION; /* check recursion and lookup handler */ g_mutex_lock (g_messages_lock); domain = g_log_find_domain_L (log_domain ? log_domain : ""); if (depth) test_level |= G_LOG_FLAG_RECURSION; depth++; domain_fatal_mask = domain ? domain->fatal_mask : G_LOG_FATAL_MASK; if ((domain_fatal_mask | g_log_always_fatal) & test_level) test_level |= G_LOG_FLAG_FATAL; if (test_level & G_LOG_FLAG_RECURSION) log_func = _g_log_fallback_handler; else log_func = g_log_domain_get_handler_L (domain, test_level, &data); domain = NULL; g_mutex_unlock (g_messages_lock); g_private_set (g_log_depth, GUINT_TO_POINTER (depth)); /* had to defer debug initialization until we can keep track of recursion */ if (!(test_level & G_LOG_FLAG_RECURSION) && !_g_debug_initialized) { GLogLevelFlags orig_test_level = test_level; _g_debug_init (); if ((domain_fatal_mask | g_log_always_fatal) & test_level) test_level |= G_LOG_FLAG_FATAL; if (test_level != orig_test_level) { /* need a relookup, not nice, but not too bad either */ g_mutex_lock (g_messages_lock); domain = g_log_find_domain_L (log_domain ? log_domain : ""); log_func = g_log_domain_get_handler_L (domain, test_level, &data); domain = NULL; g_mutex_unlock (g_messages_lock); } } if (test_level & G_LOG_FLAG_RECURSION) { /* we use a stack buffer of fixed size, since we're likely * in an out-of-memory situation */ gchar buffer[1025]; gsize size; va_list args2; G_VA_COPY (args2, args1); size = _g_vsnprintf (buffer, 1024, format, args2); va_end (args2); log_func (log_domain, test_level, buffer, data); } else { gchar *msg; va_list args2; G_VA_COPY (args2, args1); msg = g_strdup_vprintf (format, args2); va_end (args2); log_func (log_domain, test_level, msg, data); if ((test_level & G_LOG_FLAG_FATAL) && !(test_level & G_LOG_LEVEL_ERROR)) { masquerade_fatal = fatal_log_func && !fatal_log_func (log_domain, test_level, msg, data); } g_free (msg); } gchar *locale_msg2 = g_locale_from_utf8 (fatal_msg_buf, -1, NULL, NULL, NULL); MessageBox (NULL, locale_msg2, L"G_LOGV", MB_ICONERROR|MB_SETFOREGROUND); if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal) { #ifdef G_OS_WIN32 gchar *locale_msg = g_locale_from_utf8 (fatal_msg_buf, -1, NULL, NULL, NULL); MessageBox (NULL, locale_msg, NULL, MB_ICONERROR|MB_SETFOREGROUND); #ifndef G_PLATFORM_WIN32_CE if (IsDebuggerPresent () && !(test_level & G_LOG_FLAG_RECURSION)) G_BREAKPOINT (); else abort (); #else abort (); #endif #else #if defined (G_ENABLE_DEBUG) && defined (SIGTRAP) if (!(test_level & G_LOG_FLAG_RECURSION)) G_BREAKPOINT (); else abort (); #else /* !G_ENABLE_DEBUG || !SIGTRAP */ abort (); #endif /* !G_ENABLE_DEBUG || !SIGTRAP */ #endif /* !G_OS_WIN32 */ } depth--; g_private_set (g_log_depth, GUINT_TO_POINTER (depth)); } } }
/** * cinnamon_breakpoint: * * Using G_BREAKPOINT(), interrupt the current process. This is useful * in conjunction with a debugger such as gdb. */ void cinnamon_breakpoint (void) { G_BREAKPOINT (); }
/** * shell_global_breakpoint: * @global: A #ShellGlobal * * Using G_BREAKPOINT(), interrupt the current process. This is useful * in conjunction with a debugger such as gdb. */ void shell_global_breakpoint (ShellGlobal *global) { G_BREAKPOINT (); }
/** \brief Retrieve different information. \author Peter G. Baum **/ int gnoclInfoCmd ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] ) { static const char *cmd[] = { "version", "gtkVersion", "hasGnomeSupport", "allStockItems", "breakpoint", NULL }; enum optIdx { VersionIdx, GtkVersionIdx, HasGnomeIdx, AllStockItems, BreakpointIdx }; int idx; if ( objc != 2 ) { Tcl_WrongNumArgs ( interp, 1, objv, "option" ); return TCL_ERROR; } if ( Tcl_GetIndexFromObj ( interp, objv[1], cmd, "option", TCL_EXACT, &idx ) != TCL_OK ) return TCL_ERROR; switch ( idx ) { case VersionIdx: Tcl_SetObjResult ( interp, Tcl_NewStringObj ( VERSION, -1 ) ); break; case GtkVersionIdx: { char buffer[128]; sprintf ( buffer, "%d.%d.%d", gtk_major_version, gtk_minor_version, gtk_micro_version ); Tcl_SetObjResult ( interp, Tcl_NewStringObj ( buffer, -1 ) ); } break; case HasGnomeIdx: Tcl_SetObjResult ( interp, Tcl_NewBooleanObj ( #ifdef GNOCL_USE_GNOME 1 #else 0 #endif ) ); break; case AllStockItems: { Tcl_Obj *res = Tcl_NewListObj ( 0, NULL ); GSList *ids = gtk_stock_list_ids(); GSList *p; for ( p = ids; p != NULL; p = p->next ) { char *txt = p->data; int skip = 0; /* FIXME: gtk-missing-image, gtk-dnd-multiple and gtk-dnd fail lookup, why? { GtkStockItem sp; printf( "%s lookup: %d\n", txt, gtk_stock_lookup( txt, &sp ) ); } **/ /* see createStockName and gnoclGetStockName */ if ( strncmp ( txt, "gtk", 3 ) == 0 ) skip = 3; #ifdef GNOCL_USE_GNOME else if ( strncmp ( txt, "gnome-stock", 11 ) == 0 ) skip = 11; #endif if ( skip > 0 ) { GString *name = g_string_new ( NULL ); char *tp = txt + skip; for ( ; *tp; ++tp ) { if ( *tp == '-' ) { ++tp; g_string_append_c ( name, toupper ( *tp ) ); } else g_string_append_c ( name, *tp ); } Tcl_ListObjAppendElement ( interp, res, Tcl_NewStringObj ( name->str, -1 ) ); /* printf( "%s -> %s\n", (char *)p->data, name->str ); */ g_string_free ( name, 1 ); } else Tcl_ListObjAppendElement ( interp, res, Tcl_NewStringObj ( txt, -1 ) ); g_free ( p->data ); } g_slist_free ( ids ); Tcl_SetObjResult ( interp, res ); } break; case BreakpointIdx: /* this is only for debugging */ G_BREAKPOINT(); break; } return TCL_OK; }
static void log_handler(const char *log_domain, GLogLevelFlags log_level, const char *message, void *user_data) { const char *prefix; GString *gstr; if (log_level & G_LOG_FLAG_RECURSION) { g_print("bigboard-buttons: log recursed\n"); return; } switch (log_level & G_LOG_LEVEL_MASK) { case G_LOG_LEVEL_DEBUG: if (!log_debug_messages) return; prefix = "DEBUG: "; break; case G_LOG_LEVEL_WARNING: prefix = "WARNING: "; break; case G_LOG_LEVEL_CRITICAL: prefix = "CRITICAL: "; break; case G_LOG_LEVEL_ERROR: prefix = "ERROR: "; break; case G_LOG_LEVEL_INFO: prefix = "INFO: "; break; case G_LOG_LEVEL_MESSAGE: prefix = "MESSAGE: "; break; default: prefix = ""; break; } gstr = g_string_new(log_domain); g_string_append(gstr, " "); g_string_append(gstr, prefix); g_string_append(gstr, message); /* no newline here, the print_debug_func is supposed to add it */ if (gstr->str[gstr->len - 1] == '\n') { g_string_erase(gstr, gstr->len - 1, 1); } #ifdef GUI_LOG log_to_text_view(gstr->str); #else g_printerr("%s\n", gstr->str); #endif g_string_free(gstr, TRUE); #ifdef G_OS_WIN32 // glib will do this for us, but if we abort in our own code which has // debug symbols, visual studio gets less confused about the backtrace. // at least, that's my experience. if (log_level & G_LOG_FLAG_FATAL) { if (IsDebuggerPresent()) G_BREAKPOINT(); abort(); } #endif }
static void stub_debugger_agent_user_break (void) { G_BREAKPOINT (); }