Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[logging] Add enablers for exposing call stack
When debugging complex issues it can be helpful know also which thread is
emitting the diagnostic message and the code path that led to the situation.

This is meant to be used as a development time debugging feature and thus
requires enabling during build time - otherwise all related code is excluded
from usb-moded binary.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Feb 20, 2019
1 parent 0facd5b commit 0a81774
Show file tree
Hide file tree
Showing 24 changed files with 845 additions and 7 deletions.
22 changes: 22 additions & 0 deletions src/usb_moded-android.c
Expand Up @@ -63,6 +63,8 @@ static int android_probed = -1;
static bool
android_write_file(const char *path, const char *text)
{
LOG_REGISTER_CONTEXT;

bool ack = false;

if( !path || !text )
Expand All @@ -86,6 +88,8 @@ android_write_file(const char *path, const char *text)
bool
android_in_use(void)
{
LOG_REGISTER_CONTEXT;

if( android_probed < 0 )
log_debug("android_in_use() called before android_probe()");

Expand All @@ -95,6 +99,8 @@ android_in_use(void)
static bool
android_probe(void)
{
LOG_REGISTER_CONTEXT;

if( android_probed <= 0 ) {
android_probed = access(ANDROID0_ENABLE, F_OK) == 0;
log_warning("ANDROID0 %sdetected", android_probed ? "" : "not ");
Expand All @@ -108,6 +114,8 @@ android_probe(void)
gchar *
android_get_serial(void)
{
LOG_REGISTER_CONTEXT;

static const char path[] = "/proc/cmdline";
static const char find[] = "androidboot.serialno=";
static const char pbrk[] = " \t\r\n,";
Expand Down Expand Up @@ -157,6 +165,8 @@ android_get_serial(void)
bool
android_init_values(void)
{
LOG_REGISTER_CONTEXT;

gchar *text;

if( !android_probe() )
Expand Down Expand Up @@ -217,6 +227,8 @@ android_init_values(void)
bool
android_set_enabled(bool enable)
{
LOG_REGISTER_CONTEXT;

bool ack = false;
if( android_in_use() ) {
const char *val = enable ? "1" : "0";
Expand All @@ -233,6 +245,8 @@ android_set_enabled(bool enable)
bool
android_set_charging_mode(void)
{
LOG_REGISTER_CONTEXT;

bool ack = false;

if( !android_in_use() )
Expand Down Expand Up @@ -262,6 +276,8 @@ android_set_charging_mode(void)
bool
android_set_function(const char *function)
{
LOG_REGISTER_CONTEXT;

bool ack = false;

if( !function )
Expand Down Expand Up @@ -293,6 +309,8 @@ android_set_function(const char *function)
bool
android_set_productid(const char *id)
{
LOG_REGISTER_CONTEXT;

bool ack = false;

if( id && android_in_use() ) {
Expand All @@ -316,6 +334,8 @@ android_set_productid(const char *id)
bool
android_set_vendorid(const char *id)
{
LOG_REGISTER_CONTEXT;

bool ack = false;
if( id && android_in_use() ) {
char str[16];
Expand All @@ -338,6 +358,8 @@ android_set_vendorid(const char *id)
bool
android_set_attr(const char *function, const char *attr, const char *value)
{
LOG_REGISTER_CONTEXT;

bool ack = false;

if( function && attr && value && android_in_use() ) {
Expand Down
18 changes: 18 additions & 0 deletions src/usb_moded-appsync-dbus.c
Expand Up @@ -64,6 +64,8 @@ static gboolean dbus_connection_disc = FALSE; // got disconnected

static void dbusappsync_release_name(void)
{
LOG_REGISTER_CONTEXT;

/* Drop the service name - if we have it */
if( dbus_connection_ses && dbus_connection_name )
{
Expand Down Expand Up @@ -96,6 +98,8 @@ static void dbusappsync_release_name(void)

static gboolean dbusappsync_obtain_name(void)
{
LOG_REGISTER_CONTEXT;

DBusError error = DBUS_ERROR_INIT;

int ret;
Expand Down Expand Up @@ -150,6 +154,8 @@ static gboolean dbusappsync_obtain_name(void)

static DBusHandlerResult dbusappsync_msg_handler(DBusConnection *const connection, DBusMessage *const msg, gpointer const user_data)
{
LOG_REGISTER_CONTEXT;

DBusHandlerResult status = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
int type = dbus_message_get_type(msg);
const char *interface = dbus_message_get_interface(msg);
Expand Down Expand Up @@ -221,6 +227,8 @@ static DBusHandlerResult dbusappsync_msg_handler(DBusConnection *const connectio
*/
static DBusHandlerResult dbusappsync_handle_disconnect(DBusConnection *conn, DBusMessage *msg, void *user_data)
{
LOG_REGISTER_CONTEXT;

if( dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected") )
{
log_warning("disconnected from session bus - expecting restart/stop soon\n");
Expand All @@ -235,6 +243,8 @@ static DBusHandlerResult dbusappsync_handle_disconnect(DBusConnection *conn, DBu
*/
static void dbusappsync_cleanup_connection(void)
{
LOG_REGISTER_CONTEXT;

if( dbus_connection_ses != 0 )
{
/* Remove message filters */
Expand All @@ -259,6 +269,8 @@ static void dbusappsync_cleanup_connection(void)
*/
gboolean dbusappsync_init_connection(void)
{
LOG_REGISTER_CONTEXT;

gboolean result = FALSE;
DBusError error = DBUS_ERROR_INIT;

Expand Down Expand Up @@ -316,6 +328,8 @@ gboolean dbusappsync_init_connection(void)
*/
gboolean dbusappsync_init(void)
{
LOG_REGISTER_CONTEXT;

gboolean status = FALSE;

if( !dbusappsync_init_connection() )
Expand All @@ -336,6 +350,8 @@ gboolean dbusappsync_init(void)
*/
void dbusappsync_cleanup(void)
{
LOG_REGISTER_CONTEXT;

dbusappsync_cleanup_connection();
// NOP
}
Expand All @@ -345,6 +361,8 @@ void dbusappsync_cleanup(void)
*/
int dbusappsync_launch_app(char *launch)
{
LOG_REGISTER_CONTEXT;

int ret = -1; // assume failure

if( dbus_connection_ses == 0 )
Expand Down
30 changes: 30 additions & 0 deletions src/usb_moded-appsync.c
Expand Up @@ -82,6 +82,8 @@ static int appsync_no_dbus = 1; // always disabled

static void appsync_free_elem(list_elem_t *elem)
{
LOG_REGISTER_CONTEXT;

g_free(elem->name);
g_free(elem->launch);
g_free(elem->mode);
Expand All @@ -90,12 +92,16 @@ static void appsync_free_elem(list_elem_t *elem)

static void appsync_free_elem_cb(gpointer elem, gpointer user_data)
{
LOG_REGISTER_CONTEXT;

(void)user_data;
appsync_free_elem(elem);
}

void appsync_free_appsync_list(void)
{
LOG_REGISTER_CONTEXT;

if( appsync_sync_list != 0 )
{
/*g_list_free_full(appsync_sync_list, appsync_free_elem); */
Expand All @@ -108,11 +114,15 @@ void appsync_free_appsync_list(void)

static gint appsync_list_sort_func(gconstpointer a, gconstpointer b)
{
LOG_REGISTER_CONTEXT;

return strcasecmp( (char*)a, (char*)b );
}

void appsync_read_list(int diag)
{
LOG_REGISTER_CONTEXT;

GDir *confdir = 0;

const gchar *dirname;
Expand Down Expand Up @@ -160,6 +170,8 @@ void appsync_read_list(int diag)

static list_elem_t *appsync_read_file(const gchar *filename, int diag)
{
LOG_REGISTER_CONTEXT;

gchar *full_filename = NULL;
GKeyFile *settingsfile = NULL;
list_elem_t *list_item = NULL;
Expand Down Expand Up @@ -215,6 +227,8 @@ static list_elem_t *appsync_read_file(const gchar *filename, int diag)
/* @return 0 on succes, 1 if there is a failure */
int appsync_activate_sync(const char *mode)
{
LOG_REGISTER_CONTEXT;

GList *iter;
int count = 0;

Expand Down Expand Up @@ -316,6 +330,8 @@ int appsync_activate_sync(const char *mode)

int appsync_activate_sync_post(const char *mode)
{
LOG_REGISTER_CONTEXT;

GList *iter;

log_debug("activate post sync");
Expand Down Expand Up @@ -374,6 +390,8 @@ int appsync_activate_sync_post(const char *mode)

int appsync_mark_active(const gchar *name, int post)
{
LOG_REGISTER_CONTEXT;

int ret = -1; // assume name not found
int missing = 0;

Expand Down Expand Up @@ -417,6 +435,8 @@ int appsync_mark_active(const gchar *name, int post)
#ifdef APP_SYNC_DBUS
static gboolean appsync_enumerate_usb_cb(gpointer data)
{
LOG_REGISTER_CONTEXT;

(void)data;
appsync_enumerate_usb_id = 0;
log_debug("handling enumeration timeout");
Expand All @@ -427,6 +447,8 @@ static gboolean appsync_enumerate_usb_cb(gpointer data)

static void appsync_start_enumerate_usb_timer(void)
{
LOG_REGISTER_CONTEXT;

log_debug("scheduling enumeration timeout");
if( appsync_enumerate_usb_id )
g_source_remove(appsync_enumerate_usb_id), appsync_enumerate_usb_id = 0;
Expand All @@ -441,6 +463,8 @@ static void appsync_start_enumerate_usb_timer(void)

static void appsync_cancel_enumerate_usb_timer(void)
{
LOG_REGISTER_CONTEXT;

if( appsync_enumerate_usb_id )
{
log_debug("canceling enumeration timeout");
Expand All @@ -450,6 +474,8 @@ static void appsync_cancel_enumerate_usb_timer(void)

static void appsync_enumerate_usb(void)
{
LOG_REGISTER_CONTEXT;

struct timeval tv;

log_debug("Enumerating");
Expand All @@ -469,6 +495,8 @@ static void appsync_enumerate_usb(void)

void appsync_stop_apps(int post)
{
LOG_REGISTER_CONTEXT;

GList *iter = 0;

for( iter = appsync_sync_list; iter; iter = g_list_next(iter) )
Expand All @@ -487,6 +515,8 @@ void appsync_stop_apps(int post)

int appsync_stop(gboolean force)
{
LOG_REGISTER_CONTEXT;

/* If force arg is used, stop all applications that
* could have been started by usb-moded */
if(force)
Expand Down

0 comments on commit 0a81774

Please sign in to comment.