Clean up debug features

Introduce a GTK_DEBUG_CHECK() macro and use it to check for
GTK_DEBUG flags everywhere. Also guard all such places by
This commit is contained in:
Matthias Clasen 2015-09-08 22:48:44 -04:00
parent 1b15588732
commit 3526b08e01
13 changed files with 107 additions and 72 deletions

View File

@ -752,7 +752,7 @@ _gtk_builder_construct (GtkBuilder *builder,
g_object_set_property (obj, param->name, &param->value);
#if G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_BUILDER)
if (GTK_DEBUG_CHECK (BUILDER))
{
gchar *str = g_strdup_value_contents ((const GValue*)&param->value);
g_print ("set %s: %s = %s\n", info->id, param->name, str);
@ -816,7 +816,7 @@ _gtk_builder_apply_properties (GtkBuilder *builder,
g_object_set_property (info->object, param->name, &param->value);
#if G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_BUILDER)
if (GTK_DEBUG_CHECK (BUILDER))
{
gchar *str = g_strdup_value_contents ((const GValue*)&param->value);
g_print ("set %s: %s = %s\n", info->id, param->name, str);

View File

@ -926,7 +926,7 @@ start_element (GMarkupParseContext *context,
ParserData *data = (ParserData*)user_data;
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_BUILDER)
if (GTK_DEBUG_CHECK (BUILDER))
{
GString *tags = g_string_new ("");
int i;

View File

@ -1265,8 +1265,10 @@ gtk_css_node_validate_internal (GtkCssNode *cssnode,
* Note that this also completely revalidates child widgets all
* the time.
*/
if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_NO_CSS_CACHE))
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (NO_CSS_CACHE))
cssnode->pending_changes |= GTK_CSS_CHANGE_ANY;
#endif
if (!cssnode->invalid)
return;

View File

@ -59,12 +59,15 @@ typedef enum {
#ifdef G_ENABLE_DEBUG
#define GTK_NOTE(type,action) G_STMT_START { \
if (gtk_get_debug_flags () & GTK_DEBUG_##type) \
#define GTK_DEBUG_CHECK(type) G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_##type)
#define GTK_NOTE(type,action) G_STMT_START { \
if (GTK_DEBUG_CHECK (type)) \
{ action; }; } G_STMT_END
#else /* !G_ENABLE_DEBUG */
#define GTK_DEBUG_CHECK(type) 0
#define GTK_NOTE(type, action)
#endif /* G_ENABLE_DEBUG */

View File

@ -122,8 +122,7 @@ _gtk_icon_cache_new_for_path (const gchar *path)
/* Verify cache is uptodate */
if (st.st_mtime < path_st.st_mtime)
{
GTK_NOTE (ICONTHEME,
g_print ("cache outdated\n"));
GTK_NOTE (ICONTHEME, g_print ("cache outdated\n"));
goto done;
}
@ -133,7 +132,7 @@ _gtk_icon_cache_new_for_path (const gchar *path)
goto done;
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_ICONTHEME)
if (GTK_DEBUG_CHECK (ICONTHEME))
{
CacheInfo info;

View File

@ -185,7 +185,7 @@ _gtk_pixel_cache_create_surface_if_needed (GtkPixelCache *cache,
double red, green, blue, alpha;
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_NO_PIXEL_CACHE)
if (GTK_DEBUG_CHECK (NO_PIXEL_CACHE))
return;
#endif
@ -363,7 +363,7 @@ _gtk_pixel_cache_repaint (GtkPixelCache *cache,
cairo_restore (backing_cr);
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_PIXEL_CACHE)
if (GTK_DEBUG_CHECK (PIXEL_CACHE))
{
GdkRGBA colors[] = {
{ 1, 0, 0, 0.08},

View File

@ -489,9 +489,10 @@ gtk_print_job_get_surface (GtkPrintJob *job,
fchmod (fd, S_IRUSR | S_IWUSR);
#ifdef G_ENABLE_DEBUG
#ifdef G_ENABLE_DEBUG
/* If we are debugging printing don't delete the tmp files */
if (!(gtk_get_debug_flags () & GTK_DEBUG_PRINTING))
if (GTK_DEBUG_CHECK (PRINTING)) ;
else
#endif /* G_ENABLE_DEBUG */
g_unlink (filename);
g_free (filename);

View File

@ -35,7 +35,7 @@ static inline void _fixup_validation (GtkRBTree *tree,
GtkRBNode *node);
static inline void _fixup_total_count (GtkRBTree *tree,
GtkRBNode *node);
#ifdef G_ENABLE_DEBUG
#ifdef G_ENABLE_DEBUG
static void _gtk_rbtree_test (const gchar *where,
GtkRBTree *tree);
static void _gtk_rbtree_debug_spew (GtkRBTree *tree);
@ -74,7 +74,7 @@ static void
_gtk_rbnode_free (GtkRBNode *node)
{
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_TREE)
if (GTK_DEBUG_CHECK (TREE))
{
node->left = (gpointer) 0xdeadbeef;
node->right = (gpointer) 0xdeadbeef;
@ -391,10 +391,10 @@ gtk_rbnode_adjust (GtkRBTree *tree,
void
_gtk_rbtree_remove (GtkRBTree *tree)
{
#ifdef G_ENABLE_DEBUG
#ifdef G_ENABLE_DEBUG
GtkRBTree *tmp_tree;
if (gtk_get_debug_flags () & GTK_DEBUG_TREE)
if (GTK_DEBUG_CHECK (TREE))
_gtk_rbtree_test (G_STRLOC, tree);
#endif
@ -408,14 +408,14 @@ _gtk_rbtree_remove (GtkRBTree *tree)
- (int) tree->root->total_count,
- tree->root->offset);
#ifdef G_ENABLE_DEBUG
#ifdef G_ENABLE_DEBUG
tmp_tree = tree->parent_tree;
#endif
_gtk_rbtree_free (tree);
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_TREE)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TREE))
_gtk_rbtree_test (G_STRLOC, tmp_tree);
#endif
}
@ -430,14 +430,14 @@ _gtk_rbtree_insert_after (GtkRBTree *tree,
GtkRBNode *node;
gboolean right = TRUE;
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_TREE)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TREE))
{
g_print ("\n\n_gtk_rbtree_insert_after: %p\n", current);
_gtk_rbtree_debug_spew (tree);
_gtk_rbtree_test (G_STRLOC, tree);
}
#endif /* G_ENABLE_DEBUG */
#endif
if (current != NULL && !_gtk_rbtree_is_nil (current->right))
{
@ -475,15 +475,15 @@ _gtk_rbtree_insert_after (GtkRBTree *tree,
_gtk_rbtree_insert_fixup (tree, node);
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_TREE)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TREE))
{
g_print ("_gtk_rbtree_insert_after finished...\n");
_gtk_rbtree_debug_spew (tree);
g_print ("\n\n");
_gtk_rbtree_test (G_STRLOC, tree);
}
#endif /* G_ENABLE_DEBUG */
#endif
return node;
}
@ -497,15 +497,15 @@ _gtk_rbtree_insert_before (GtkRBTree *tree,
GtkRBNode *node;
gboolean left = TRUE;
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_TREE)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TREE))
{
g_print ("\n\n_gtk_rbtree_insert_before: %p\n", current);
_gtk_rbtree_debug_spew (tree);
_gtk_rbtree_test (G_STRLOC, tree);
}
#endif /* G_ENABLE_DEBUG */
#endif
if (current != NULL && !_gtk_rbtree_is_nil (current->left))
{
current = current->left;
@ -543,16 +543,16 @@ _gtk_rbtree_insert_before (GtkRBTree *tree,
_gtk_rbtree_insert_fixup (tree, node);
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_TREE)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TREE))
{
g_print ("_gtk_rbtree_insert_before finished...\n");
_gtk_rbtree_debug_spew (tree);
g_print ("\n\n");
_gtk_rbtree_test (G_STRLOC, tree);
}
#endif /* G_ENABLE_DEBUG */
#endif
return node;
}
@ -590,8 +590,8 @@ _gtk_rbtree_node_set_height (GtkRBTree *tree,
gtk_rbnode_adjust (tree, node, 0, 0, diff);
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_TREE)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TREE))
_gtk_rbtree_test (G_STRLOC, tree);
#endif
}
@ -1117,21 +1117,21 @@ _gtk_rbtree_remove_node (GtkRBTree *tree,
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_TREE)
if (GTK_DEBUG_CHECK (TREE))
{
g_print ("\n\n_gtk_rbtree_remove_node: %p\n", node);
_gtk_rbtree_debug_spew (tree);
_gtk_rbtree_test (G_STRLOC, tree);
}
#endif /* G_ENABLE_DEBUG */
#endif
/* make sure we're deleting a node that's actually in the tree */
for (x = node; !_gtk_rbtree_is_nil (x->parent); x = x->parent)
;
g_return_if_fail (x == tree->root);
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_TREE)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TREE))
_gtk_rbtree_test (G_STRLOC, tree);
#endif
@ -1226,15 +1226,15 @@ _gtk_rbtree_remove_node (GtkRBTree *tree,
_gtk_rbnode_free (node);
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_TREE)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TREE))
{
g_print ("_gtk_rbtree_remove_node finished...\n");
_gtk_rbtree_debug_spew (tree);
g_print ("\n\n");
_gtk_rbtree_test (G_STRLOC, tree);
}
#endif /* G_ENABLE_DEBUG */
#endif
}
GtkRBNode *

View File

@ -754,10 +754,12 @@ _gtk_text_btree_delete (GtkTextIter *start,
gtk_text_iter_order (start, end);
tree = _gtk_text_iter_get_btree (start);
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TEXT))
_gtk_text_btree_check (tree);
#endif
/* Broadcast the need for redisplay before we break the iterators */
DV (g_print ("invalidating due to deleting some text (%s)\n", G_STRLOC));
_gtk_text_btree_invalidate_region (tree, start, end, FALSE);
@ -1077,8 +1079,10 @@ _gtk_text_btree_delete (GtkTextIter *start,
chars_changed (tree);
segments_changed (tree);
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TEXT))
_gtk_text_btree_check (tree);
#endif
/* Re-initialize our iterators */
_gtk_text_btree_get_iter_at_line (tree, start, start_line, start_byte_offset);
@ -1359,8 +1363,10 @@ find_line_by_y (GtkTextBTree *tree, BTreeView *view,
{
gint current_y = 0;
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TEXT))
_gtk_text_btree_check (tree);
#endif
if (node->level == 0)
{
@ -2011,8 +2017,10 @@ _gtk_text_btree_tag (const GtkTextIter *start_orig,
queue_tag_redisplay (tree, tag, &start, &end);
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TEXT))
_gtk_text_btree_check (tree);
#endif
}
@ -2736,9 +2744,11 @@ real_set_mark (GtkTextBTree *tree,
iter = *where;
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TEXT))
_gtk_text_iter_check (&iter);
#endif
if (mark != NULL)
{
if (redraw_selections &&
@ -2793,9 +2803,11 @@ real_set_mark (GtkTextBTree *tree,
mark);
}
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TEXT))
_gtk_text_iter_check (&iter);
#endif
/* Link mark into new location */
gtk_text_btree_link_segment (mark, &iter);
@ -2808,12 +2820,14 @@ real_set_mark (GtkTextBTree *tree,
redisplay_mark_if_visible (mark);
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_iter_check (&iter);
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TEXT))
{
_gtk_text_iter_check (&iter);
_gtk_text_btree_check (tree);
}
#endif
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
_gtk_text_btree_check (tree);
return mark;
}
@ -4329,8 +4343,10 @@ _gtk_text_line_next_could_contain_tag (GtkTextLine *line,
g_return_val_if_fail (line != NULL, NULL);
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TEXT))
_gtk_text_btree_check (tree);
#endif
if (tag == NULL)
{
@ -4492,8 +4508,10 @@ _gtk_text_line_previous_could_contain_tag (GtkTextLine *line,
g_return_val_if_fail (line != NULL, NULL);
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TEXT))
_gtk_text_btree_check (tree);
#endif
if (tag == NULL)
{
@ -5264,8 +5282,10 @@ _gtk_text_btree_validate (GtkTextBTree *tree,
if (new_height)
*new_height = state.new_height;
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TEXT))
_gtk_text_btree_check (tree);
#endif
return TRUE;
}
@ -5973,8 +5993,10 @@ post_insert_fixup (GtkTextBTree *tree,
gtk_text_btree_rebalance (tree, node);
}
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TEXT))
_gtk_text_btree_check (tree);
#endif
}
static GtkTextTagInfo*
@ -6539,8 +6561,10 @@ gtk_text_btree_link_segment (GtkTextLineSegment *seg,
cleanup_line (line);
segments_changed (tree);
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (TEXT))
_gtk_text_btree_check (tree);
#endif
}
static void
@ -6634,7 +6658,7 @@ _gtk_toggle_segment_check_func (GtkTextLineSegment *segPtr,
/*
* Debug
*/
#ifdef G_ENABLE_DEBUG
static void
gtk_text_btree_node_view_check_consistency (GtkTextBTree *tree,
GtkTextBTreeNode *node,
@ -7081,6 +7105,7 @@ _gtk_text_btree_check (GtkTextBTree *tree)
seg->body.chars);
}
}
#endif /* G_ENABLE_DEBUG */
void _gtk_text_btree_spew_line (GtkTextBTree* tree, GtkTextLine* line);
void _gtk_text_btree_spew_segment (GtkTextBTree* tree, GtkTextLineSegment* seg);

View File

@ -369,7 +369,7 @@ is_segment_start (GtkTextRealIter *real)
static void
check_invariants (const GtkTextIter *iter)
{
if (gtk_get_debug_flags () & GTK_DEBUG_TEXT)
if (GTK_DEBUG_CHECK (TEXT))
_gtk_text_iter_check (iter);
}
#else

View File

@ -6042,8 +6042,10 @@ cursor_blinks (GtkTextView *text_view)
#ifdef DEBUG_VALIDATION_AND_SCROLLING
return FALSE;
#endif
if (gtk_get_debug_flags () & GTK_DEBUG_UPDATES)
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (UPDATES))
return FALSE;
#endif
g_object_get (settings, "gtk-cursor-blink", &blink, NULL);

View File

@ -192,16 +192,19 @@ static void gtk_tree_store_move (GtkTreeStore *
gboolean before);
#ifdef G_ENABLE_DEBUG
static inline void
validate_tree (GtkTreeStore *tree_store)
{
if (gtk_get_debug_flags () & GTK_DEBUG_TREE)
if (GTK_DEBUG_CHECK (TREE))
{
g_assert (G_NODE (tree_store->priv->root)->parent == NULL);
validate_gnode (G_NODE (tree_store->priv->root));
}
}
#else
#define validate_tree(store)
#endif
G_DEFINE_TYPE_WITH_CODE (GtkTreeStore, gtk_tree_store, G_TYPE_OBJECT,
G_ADD_PRIVATE (GtkTreeStore)

View File

@ -5839,7 +5839,7 @@ gtk_widget_size_allocate_with_baseline (GtkWidget *widget,
gtk_widget_push_verify_invariants (widget);
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
if (GTK_DEBUG_CHECK (GEOMETRY))
{
gint depth;
GtkWidget *parent;
@ -5901,7 +5901,7 @@ gtk_widget_size_allocate_with_baseline (GtkWidget *widget,
}
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
if (GTK_DEBUG_CHECK (GEOMETRY))
{
if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
!GTK_IS_SCROLLABLE (widget))
@ -6845,7 +6845,7 @@ _gtk_widget_draw_internal (GtkWidget *widget,
&result);
#ifdef G_ENABLE_DEBUG
if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_BASELINES))
if (GTK_DEBUG_CHECK (BASELINES))
{
gint baseline = gtk_widget_get_allocated_baseline (widget);
gint width = gtk_widget_get_allocated_width (widget);
@ -15584,7 +15584,7 @@ gtk_widget_set_clip (GtkWidget *widget,
priv = widget->priv;
#ifdef G_ENABLE_DEBUG
if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
if (GTK_DEBUG_CHECK (GEOMETRY))
{
gint depth;
GtkWidget *parent;