GDBus: Add `return' debug option

This prints all GDBusMethodInvocation API usage and is normally used
with the `incoming' option. Example:

 # G_DBUS_DEBUG=incoming,return ./polkitd --replace
 Entering main event loop
 Connected to the system bus
 Registering null backend at priority -10
 [...]
 Acquired the name org.freedesktop.PolicyKit1
 [...]

 ========================================================================
 GDBus-debug:Incoming:
  <<<< METHOD INVOCATION org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent()
       on object /org/freedesktop/PolicyKit1/Authority
       invoked by name :1.26
       serial 299
 ========================================================================
 GDBus-debug:Return:
  >>>> METHOD ERROR org.freedesktop.PolicyKit1.Error.Failed
       message `Cannot determine session the caller is in'
       in response to org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent()
       on object /org/freedesktop/PolicyKit1/Authority
       to name :1.26
       reply-serial 299

 [...]

 ========================================================================
 GDBus-debug:Incoming:
  <<<< METHOD INVOCATION org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent()
       on object /org/freedesktop/PolicyKit1/Authority
       invoked by name :1.2402
       serial 25
 ========================================================================
 GDBus-debug:Return:
  >>>> METHOD RETURN
       in response to org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent()
       on object /org/freedesktop/PolicyKit1/Authority
       to name :1.2402
       reply-serial 25

Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
David Zeuthen 2010-08-04 16:59:26 -04:00
parent 89a1b571ad
commit d52e1c33f7
5 changed files with 61 additions and 6 deletions

View File

@ -359,6 +359,10 @@
<term>incoming</term> <term>incoming</term>
<listitem><para>Show when an incoming D-Bus method call is received</para></listitem> <listitem><para>Show when an incoming D-Bus method call is received</para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>return</term>
<listitem><para>Show when a reply is returned via the #GDBusMethodInvocation API</para></listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>emission</term> <term>emission</term>
<listitem><para>Trace g_dbus_connection_emit_signal() API usage</para></listitem> <listitem><para>Trace g_dbus_connection_emit_signal() API usage</para></listitem>
@ -372,8 +376,10 @@
<listitem><para>Show information about D-Bus address lookups and autolaunching</para></listitem> <listitem><para>Show information about D-Bus address lookups and autolaunching</para></listitem>
</varlistentry> </varlistentry>
</variablelist> </variablelist>
The special value <literal>all</literal> can be used to turn on The special value <literal>all</literal> can be used to turn
all debug options. on all debug options. The special value
<literal>help</literal> can be used to print a list of
supported options to standard output.
</para> </para>
</formalpara> </formalpara>

View File

@ -5883,10 +5883,12 @@ distribute_method_call (GDBusConnection *connection,
"GDBus-debug:Incoming:\n" "GDBus-debug:Incoming:\n"
" <<<< METHOD INVOCATION %s.%s()\n" " <<<< METHOD INVOCATION %s.%s()\n"
" on object %s\n" " on object %s\n"
" invoked by name %s\n", " invoked by name %s\n"
" serial %d\n",
interface_name, member, interface_name, member,
path, path,
g_dbus_message_get_sender (message) != NULL ? g_dbus_message_get_sender (message) : "(none)"); g_dbus_message_get_sender (message) != NULL ? g_dbus_message_get_sender (message) : "(none)",
g_dbus_message_get_serial (message));
_g_dbus_debug_print_unlock (); _g_dbus_debug_print_unlock ();
} }

View File

@ -381,6 +381,23 @@ g_dbus_method_invocation_return_value (GDBusMethodInvocation *invocation,
g_variant_type_free (type); g_variant_type_free (type);
} }
if (G_UNLIKELY (_g_dbus_debug_return ()))
{
_g_dbus_debug_print_lock ();
g_print ("========================================================================\n"
"GDBus-debug:Return:\n"
" >>>> METHOD RETURN\n"
" in response to %s.%s()\n"
" on object %s\n"
" to name %s\n"
" reply-serial %d\n",
invocation->interface_name, invocation->method_name,
invocation->object_path,
invocation->sender,
g_dbus_message_get_serial (invocation->message));
_g_dbus_debug_print_unlock ();
}
reply = g_dbus_message_new_method_reply (invocation->message); reply = g_dbus_message_new_method_reply (invocation->message);
g_dbus_message_set_body (reply, parameters); g_dbus_message_set_body (reply, parameters);
error = NULL; error = NULL;
@ -560,6 +577,26 @@ g_dbus_method_invocation_return_dbus_error (GDBusMethodInvocation *invocation,
g_return_if_fail (error_name != NULL && g_dbus_is_name (error_name)); g_return_if_fail (error_name != NULL && g_dbus_is_name (error_name));
g_return_if_fail (error_message != NULL); g_return_if_fail (error_message != NULL);
if (G_UNLIKELY (_g_dbus_debug_return ()))
{
_g_dbus_debug_print_lock ();
g_print ("========================================================================\n"
"GDBus-debug:Return:\n"
" >>>> METHOD ERROR %s\n"
" message `%s'\n"
" in response to %s.%s()\n"
" on object %s\n"
" to name %s\n"
" reply-serial %d\n",
error_name,
error_message,
invocation->interface_name, invocation->method_name,
invocation->object_path,
invocation->sender,
g_dbus_message_get_serial (invocation->message));
_g_dbus_debug_print_unlock ();
}
reply = g_dbus_message_new_method_error_literal (invocation->message, reply = g_dbus_message_new_method_error_literal (invocation->message,
error_name, error_name,
error_message); error_message);

View File

@ -1178,8 +1178,9 @@ _g_dbus_worker_flush_sync (GDBusWorker *worker,
#define G_DBUS_DEBUG_CALL (1<<3) #define G_DBUS_DEBUG_CALL (1<<3)
#define G_DBUS_DEBUG_SIGNAL (1<<4) #define G_DBUS_DEBUG_SIGNAL (1<<4)
#define G_DBUS_DEBUG_INCOMING (1<<5) #define G_DBUS_DEBUG_INCOMING (1<<5)
#define G_DBUS_DEBUG_EMISSION (1<<6) #define G_DBUS_DEBUG_RETURN (1<<6)
#define G_DBUS_DEBUG_ADDRESS (1<<7) #define G_DBUS_DEBUG_EMISSION (1<<7)
#define G_DBUS_DEBUG_ADDRESS (1<<8)
static gint _gdbus_debug_flags = 0; static gint _gdbus_debug_flags = 0;
@ -1225,6 +1226,13 @@ _g_dbus_debug_incoming (void)
return (_gdbus_debug_flags & G_DBUS_DEBUG_INCOMING) != 0; return (_gdbus_debug_flags & G_DBUS_DEBUG_INCOMING) != 0;
} }
gboolean
_g_dbus_debug_return (void)
{
_g_dbus_initialize ();
return (_gdbus_debug_flags & G_DBUS_DEBUG_RETURN) != 0;
}
gboolean gboolean
_g_dbus_debug_emission (void) _g_dbus_debug_emission (void)
{ {
@ -1283,6 +1291,7 @@ _g_dbus_initialize (void)
{ "call", G_DBUS_DEBUG_CALL }, { "call", G_DBUS_DEBUG_CALL },
{ "signal", G_DBUS_DEBUG_SIGNAL }, { "signal", G_DBUS_DEBUG_SIGNAL },
{ "incoming", G_DBUS_DEBUG_INCOMING }, { "incoming", G_DBUS_DEBUG_INCOMING },
{ "return", G_DBUS_DEBUG_RETURN },
{ "emission", G_DBUS_DEBUG_EMISSION }, { "emission", G_DBUS_DEBUG_EMISSION },
{ "address", G_DBUS_DEBUG_ADDRESS } { "address", G_DBUS_DEBUG_ADDRESS }
}; };

View File

@ -85,6 +85,7 @@ gboolean _g_dbus_debug_payload (void);
gboolean _g_dbus_debug_call (void); gboolean _g_dbus_debug_call (void);
gboolean _g_dbus_debug_signal (void); gboolean _g_dbus_debug_signal (void);
gboolean _g_dbus_debug_incoming (void); gboolean _g_dbus_debug_incoming (void);
gboolean _g_dbus_debug_return (void);
gboolean _g_dbus_debug_emission (void); gboolean _g_dbus_debug_emission (void);
gboolean _g_dbus_debug_address (void); gboolean _g_dbus_debug_address (void);