Consolidate debugging in midori_debug()/ MIDORI_DEBUG

This commit is contained in:
Christian Dywan 2012-07-19 20:04:25 +02:00
parent d8de8285ef
commit 5998b6b0ea
9 changed files with 61 additions and 39 deletions

View File

@ -53,9 +53,9 @@ If the problem is a warning and not a crash, try this:
If you are interested in HTTP communication, try this:
'MIDORI_SOUP_DEBUG=2 _build/default/midori/midori'
'MIDORI_DEBUG=soup:2 _build/default/midori/midori'
Where '2' can be a level between 0 and 3.
Where '2' can be a level between 1 and 3.
If you are interested in (non-) touchscreen behaviour, try this:

View File

@ -29,7 +29,7 @@
(__filter[4] != '-' && __filter[5] != '-')
#ifdef G_ENABLE_DEBUG
#define adblock_debug(dmsg, darg1, darg2) \
do { if (debug == 1) g_debug (dmsg, darg1, darg2); } while (0)
do { if (midori_debug ("adblock:1")) g_debug (dmsg, darg1, darg2); } while (0)
#else
#define adblock_debug(dmsg, darg1, darg2) /* nothing */
#endif
@ -41,9 +41,6 @@ static GHashTable* urlcache = NULL;
static GHashTable* blockcssprivate = NULL;
static GHashTable* navigationwhitelist = NULL;
static GString* blockcss = NULL;
#ifdef G_ENABLE_DEBUG
static guint debug;
#endif
static gboolean
adblock_parse_file (gchar* path);
@ -884,7 +881,7 @@ adblock_resource_request_starting_cb (WebKitWebView* web_view,
}
#ifdef G_ENABLE_DEBUG
if (debug == 2)
if (midori_debug ("adblock:2"))
g_test_timer_start ();
#endif
if (adblock_is_matched (req_uri, page_uri))
@ -895,7 +892,7 @@ adblock_resource_request_starting_cb (WebKitWebView* web_view,
g_object_set_data (G_OBJECT (web_view), "blocked-uris", blocked_uris);
}
#ifdef G_ENABLE_DEBUG
if (debug == 2)
if (midori_debug ("adblock:2"))
g_debug ("match: %f%s", g_test_timer_elapsed (), "seconds");
#endif
@ -1587,25 +1584,9 @@ static void
adblock_activate_cb (MidoriExtension* extension,
MidoriApp* app)
{
#ifdef G_ENABLE_DEBUG
const gchar* debug_mode;
#endif
KatzeArray* browsers;
MidoriBrowser* browser;
#ifdef G_ENABLE_DEBUG
debug_mode = g_getenv ("MIDORI_ADBLOCK");
if (debug_mode)
{
if (*debug_mode == '1')
debug = 1;
else if (*debug_mode == '2')
debug = 2;
else
debug = 0;
}
#endif
adblock_reload_rules (extension, FALSE);
browsers = katze_object_get_object (app, "browsers");

View File

@ -207,7 +207,7 @@ katze_http_cookies_sqlite_jar_changed_cb (SoupCookieJar* jar,
}
}
if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL)
if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies"))
http_cookies->counter++;
if (old_cookie) {

View File

@ -211,7 +211,7 @@ katze_http_cookies_update_jar (KatzeHttpCookies* http_cookies)
goto failed;
g_free (temporary_filename);
if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL)
if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies"))
{
g_print ("KatzeHttpCookies: %d cookies changed\n", http_cookies->counter);
http_cookies->counter = 0;
@ -223,7 +223,7 @@ failed:
fclose (f);
g_unlink (temporary_filename);
g_free (temporary_filename);
if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL)
if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies"))
g_print ("KatzeHttpCookies: Failed to write '%s'\n",
http_cookies->filename);
return FALSE;
@ -263,7 +263,7 @@ katze_http_cookies_jar_changed_cb (SoupCookieJar* jar,
}
}
if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL)
if (!g_strcmp0 (g_getenv ("MIDORI_DEBUG"), "cookies"))
http_cookies->counter++;
if (!http_cookies->timeout && (old_cookie || new_cookie->expires))

View File

@ -937,7 +937,7 @@ midori_soup_session_settings_accept_language_cb (SoupSession* session,
soup_uri_set_query (stripped_uri, NULL);
stripped_referer = soup_uri_to_string (stripped_uri, FALSE);
soup_uri_free (stripped_uri);
if (g_getenv ("MIDORI_SOUP_DEBUG"))
if (midori_debug ("soup"))
g_message ("Referer %s stripped to %s", referer, stripped_referer);
soup_message_headers_replace (msg->request_headers, "Referer",
stripped_referer);
@ -950,11 +950,15 @@ midori_soup_session_settings_accept_language_cb (SoupSession* session,
static void
midori_soup_session_debug (SoupSession* session)
{
const char* soup_debug = g_getenv ("MIDORI_SOUP_DEBUG");
if (soup_debug)
gint soup_debug_level = 0;
if (midori_debug ("soup:1"))
soup_debug_level = 1;
else if (midori_debug ("soup:2"))
soup_debug_level = 2;
else if (midori_debug ("soup:3"))
soup_debug_level = 3;
if (soup_debug_level > 0)
{
gint soup_debug_level = atoi (soup_debug);
SoupLogger* logger = soup_logger_new (soup_debug_level, -1);
soup_logger_attach (logger, session);
g_object_unref (logger);
@ -1327,7 +1331,7 @@ midori_load_extensions (gpointer data)
gchar** keys = g_object_get_data (G_OBJECT (app), "extensions");
KatzeArray* extensions;
#ifdef G_ENABLE_DEBUG
gboolean startup_timer = g_getenv ("MIDORI_STARTTIME") != NULL;
gboolean startup_timer = midori_debug ("startup");
GTimer* timer = startup_timer ? g_timer_new () : NULL;
#endif
@ -1396,7 +1400,7 @@ midori_load_session (gpointer data)
gint64 current;
gchar** command = g_object_get_data (G_OBJECT (app), "execute-command");
#ifdef G_ENABLE_DEBUG
gboolean startup_timer = g_getenv ("MIDORI_STARTTIME") != NULL;
gboolean startup_timer = midori_debug ("startup");
GTimer* timer = startup_timer ? g_timer_new () : NULL;
#endif
@ -1978,7 +1982,7 @@ main (int argc,
gint max_history_age;
gint clear_prefs = MIDORI_CLEAR_NONE;
#ifdef G_ENABLE_DEBUG
gboolean startup_timer = g_getenv ("MIDORI_STARTTIME") != NULL;
gboolean startup_timer = midori_debug ("startup");
#define midori_startup_timer(tmrmsg) if (startup_timer) \
g_debug (tmrmsg, (g_test_timer_last () - g_test_timer_elapsed ()) * -1)
#else

View File

@ -1527,3 +1527,37 @@ midori_app_setup (gchar** argument_vector)
#endif
}
gboolean
midori_debug (const gchar* token)
{
static const gchar* debug_token = NULL;
g_return_val_if_fail (token != NULL, FALSE);
if (debug_token == NULL)
{
const gchar* debug = g_getenv ("MIDORI_DEBUG");
const gchar* debug_tokens = "soup:1 soup:2 soup:3 cookies";
const gchar* full_debug_tokens = "adblock:1 adblock:2 startup bookmarks";
if (debug && strstr (full_debug_tokens, debug))
{
#ifdef G_ENABLE_DEBUG
debug_token = g_intern_static_string (debug);
#else
g_warning ("Value '%s' for MIDORI_DEBUG requires a full debugging build.", debug);
#endif
}
else if (debug && strstr (debug_tokens, debug))
debug_token = g_intern_static_string (debug);
else if (debug)
g_warning ("Unrecognized value '%s' for MIDORI_DEBUG.", debug);
else
debug_token = "NONE";
if (!debug_token)
{
debug_token = "INVALID";
g_print ("Supported values: %s\nWith full debugging: %s\n",
debug_tokens, full_debug_tokens);
}
}
return debug_token == g_intern_static_string (token);
}

View File

@ -94,6 +94,9 @@ midori_app_find_res_filename (const gchar* filename);
gchar*
midori_app_get_lib_path (const gchar* package);
gboolean
midori_debug (const gchar* token);
G_END_DECLS
#endif /* __MIDORI_APP_H__ */

View File

@ -160,7 +160,7 @@ midori_bookmarks_initialize (KatzeArray* array,
}
#ifdef G_ENABLE_DEBUG
if (g_getenv ("MIDORI_BOOKMARKS_DEBUG"))
if (midori_debug ("bookmarks")
sqlite3_trace (db, midori_bookmarks_dbtracer, NULL);
#endif

View File

@ -4232,7 +4232,7 @@ midori_view_set_uri (MidoriView* view,
#ifdef G_ENABLE_DEBUG
GTimer* timer = NULL;
if (g_getenv ("MIDORI_STARTTIME") != NULL)
if (midori_debug ("startup")
timer = g_timer_new ();
#endif
@ -4247,7 +4247,7 @@ midori_view_set_uri (MidoriView* view,
speeddial_markup ? speeddial_markup : "", "about:blank", NULL);
#ifdef G_ENABLE_DEBUG
if (g_getenv ("MIDORI_STARTTIME") != NULL)
if (midori_debug ("startup")
{
g_debug ("Speed Dial: \t%fs", g_timer_elapsed (timer, NULL));
g_timer_destroy (timer);