Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Tarassov2014-01-15 14:22:31 -0500
committerEugene Tarassov2014-01-15 14:22:31 -0500
commit1a00032a8432020e3bb792dcdfae1e31b7a36d43 (patch)
tree2a6a14e25ce570f578729bd2309506bfafe374ec
parent98112a0769a396d7f8e75468fc34e970749ca896 (diff)
downloadorg.eclipse.tcf.agent-1a00032a8432020e3bb792dcdfae1e31b7a36d43.tar.gz
org.eclipse.tcf.agent-1a00032a8432020e3bb792dcdfae1e31b7a36d43.tar.xz
org.eclipse.tcf.agent-1a00032a8432020e3bb792dcdfae1e31b7a36d43.zip
TCF Agent: better diagnostic of leaked channel locks
-rw-r--r--agent/tcf/framework/channel.c51
-rw-r--r--agent/tcf/framework/channel.h8
-rw-r--r--agent/tcf/framework/channel_pipe.c3
-rw-r--r--agent/tcf/framework/channel_tcp.c3
-rw-r--r--agent/tcf/framework/proxy.c18
-rw-r--r--agent/tcf/services/diagnostics.c8
-rw-r--r--agent/tcf/services/linenumbers_proxy.c6
-rw-r--r--agent/tcf/services/processes.c10
-rw-r--r--agent/tcf/services/symbols_proxy.c6
-rw-r--r--agent/tcf/services/terminals.c6
10 files changed, 70 insertions, 49 deletions
diff --git a/agent/tcf/framework/channel.c b/agent/tcf/framework/channel.c
index 61c43c7c..831ed009 100644
--- a/agent/tcf/framework/channel.c
+++ b/agent/tcf/framework/channel.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -51,6 +51,7 @@ typedef struct ChannelLock {
LINK link;
const char * msg;
unsigned cnt;
+ unsigned timer;
} ChannelLock;
static void trigger_channel_shutdown(ShutdownInfo * obj);
@@ -251,6 +252,39 @@ void channel_unlock(Channel * c) {
c->unlock(c);
}
+#ifndef NDEBUG
+static int lock_timer_posted = 0;
+
+static void lock_timer_event(void * args) {
+ unsigned cnt = 0;
+ LINK * l = channel_root.next;
+ assert(lock_timer_posted);
+ while (l != &channel_root) {
+ Channel * c = chanlink2channelp(l);
+ if (is_channel_closed(c) && c->locks.next != NULL) {
+ LINK * p = c->locks.next;
+ while (p != &c->locks) {
+ ChannelLock * cl = chan2lock(p);
+ assert(cl->cnt > 0);
+ if (cl->timer >= 2) {
+ trace(LOG_ALWAYS, "Invalid channel lock: %s, count %d", cl->msg, cl->cnt);
+ }
+ cl->timer++;
+ p = p->next;
+ cnt++;
+ }
+ }
+ l = l->next;
+ }
+ if (cnt > 0) {
+ post_event_with_delay(lock_timer_event, NULL, 2000000);
+ }
+ else {
+ lock_timer_posted = 0;
+ }
+}
+#endif
+
void channel_lock_with_msg(Channel * c, const char * msg) {
c->lock(c);
#ifndef NDEBUG
@@ -276,6 +310,10 @@ void channel_lock_with_msg(Channel * c, const char * msg) {
l->msg = msg;
l->cnt = 1;
list_add_first(&l->link, &c->locks);
+ if (!lock_timer_posted) {
+ post_event_with_delay(lock_timer_event, NULL, 2000000);
+ lock_timer_posted = 1;
+ }
}
}
#endif
@@ -309,17 +347,6 @@ void channel_unlock_with_msg(Channel * c, const char * msg) {
c->unlock(c);
}
-void check_channel_locks(Channel * c) {
-#ifndef NDEBUG
- if (c->locks.next != NULL) {
- LINK * p;
- for (p = c->locks.next; p != &c->locks; p = p->next) {
- trace(LOG_ALWAYS, "Invalid channel lock: %s", chan2lock(p)->msg);
- }
- }
-#endif
-}
-
int is_channel_closed(Channel * c) {
return c->is_closed(c);
}
diff --git a/agent/tcf/framework/channel.h b/agent/tcf/framework/channel.h
index ae1f9703..1e875885 100644
--- a/agent/tcf/framework/channel.h
+++ b/agent/tcf/framework/channel.h
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -213,12 +213,6 @@ extern void channel_lock_with_msg(Channel *, const char *);
extern void channel_unlock_with_msg(Channel *, const char *);
/*
- * Check for leaked channel locks. The function is called by
- * channel implementation after the channel is disconnected.
- */
-extern void check_channel_locks(Channel *);
-
-/*
* Return 1 if channel is closed, otherwise return 0.
*/
extern int is_channel_closed(Channel *);
diff --git a/agent/tcf/framework/channel_pipe.c b/agent/tcf/framework/channel_pipe.c
index 94d571bb..d3e9be3f 100644
--- a/agent/tcf/framework/channel_pipe.c
+++ b/agent/tcf/framework/channel_pipe.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2013 Wind River Systems, Inc. and others.
+ * Copyright (c) 2010, 2014 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -431,7 +431,6 @@ static void pipe_read_done(void * x) {
pipe_post_read(&c->ibuf, c->obuf, sizeof(c->obuf));
}
else {
- check_channel_locks(&c->chan);
pipe_unlock(&c->chan);
}
}
diff --git a/agent/tcf/framework/channel_tcp.c b/agent/tcf/framework/channel_tcp.c
index 8f1ea8fc..465f8e73 100644
--- a/agent/tcf/framework/channel_tcp.c
+++ b/agent/tcf/framework/channel_tcp.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -792,7 +792,6 @@ static void tcp_channel_read_done(void * x) {
tcp_post_read(&c->ibuf, c->obuf, sizeof(c->obuf));
}
else {
- check_channel_locks(&c->chan);
tcp_unlock(&c->chan);
}
}
diff --git a/agent/tcf/framework/proxy.c b/agent/tcf/framework/proxy.c
index cd4f5d09..9cf43531 100644
--- a/agent/tcf/framework/proxy.c
+++ b/agent/tcf/framework/proxy.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -46,6 +46,8 @@ static int redirection_listeners_cnt = 0;
static ProxyLogFilterListener proxy_log_filter_listener;
+static const char * channel_lock_msg = "Proxy lock";
+
static void proxy_update(Channel * c1, Channel * c2);
static void proxy_connecting(Channel * c) {
@@ -84,8 +86,8 @@ static void command_redirect_done (Channel * c, void * client_data, int error) {
write_stream(&info->host->out, MARKER_EOM);
}
- channel_unlock(info->host);
- loc_free (info);
+ channel_unlock_with_msg(info->host, channel_lock_msg);
+ loc_free(info);
}
static void read_peer_attr(InputStream * inp, const char * name, void * x) {
@@ -109,7 +111,7 @@ static void command_locator_redirect(char * token, Channel * c, void * args) {
json_test_char(&c->inp, MARKER_EOA);
json_test_char(&c->inp, MARKER_EOM);
- channel_lock(c);
+ channel_lock_with_msg(c, channel_lock_msg);
info->host = c;
strlcpy(info->token, token, sizeof(info->token));
@@ -180,8 +182,8 @@ static void proxy_disconnected(Channel * c) {
proxy[1].c->client_data = NULL;
protocol_release(proxy[0].proto);
protocol_release(proxy[1].proto);
- channel_unlock(proxy[0].c);
- channel_unlock(proxy[1].c);
+ channel_unlock_with_msg(proxy[0].c, channel_lock_msg);
+ channel_unlock_with_msg(proxy[1].c, channel_lock_msg);
loc_free(proxy);
}
else {
@@ -383,14 +385,14 @@ void proxy_create(Channel * c1, Channel * c2) {
assert(c2->state == ChannelStateStartWait);
/* Host */
- channel_lock(c1);
+ channel_lock_with_msg(c1, channel_lock_msg);
proxy[0].c = c1;
proxy[0].proto = protocol_alloc();
proxy[0].other = 1;
proxy[0].instance = instance;
/* Target */
- channel_lock(c2);
+ channel_lock_with_msg(c2, channel_lock_msg);
proxy[1].c = c2;
proxy[1].proto = protocol_alloc();
proxy[1].other = -1;
diff --git a/agent/tcf/services/diagnostics.c b/agent/tcf/services/diagnostics.c
index 32f5cd12..2f265543 100644
--- a/agent/tcf/services/diagnostics.c
+++ b/agent/tcf/services/diagnostics.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -168,7 +168,7 @@ static void run_test_done(int error, Context * ctx, void * arg) {
else if (ctx != NULL) {
terminate_debug_context(ctx);
}
- channel_unlock(c);
+ channel_unlock_with_msg(c, DIAGNOSTICS);
loc_free(data);
}
#endif
@@ -186,10 +186,10 @@ static void command_run_test(char * token, Channel * c) {
RunTestDoneArgs * data = (RunTestDoneArgs *)loc_alloc_zero(sizeof(RunTestDoneArgs));
data->c = c;
strcpy(data->token, token);
- channel_lock(c);
+ channel_lock_with_msg(c, DIAGNOSTICS);
if (run_test_process(run_test_done, data) == 0) return;
err = errno;
- channel_unlock(c);
+ channel_unlock_with_msg(c, DIAGNOSTICS);
loc_free(data);
#else
err = EINVAL;
diff --git a/agent/tcf/services/linenumbers_proxy.c b/agent/tcf/services/linenumbers_proxy.c
index 20bc712e..ab5c804a 100644
--- a/agent/tcf/services/linenumbers_proxy.c
+++ b/agent/tcf/services/linenumbers_proxy.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 Wind River Systems, Inc. and others.
+ * Copyright (c) 2011, 2014 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -107,7 +107,7 @@ static void free_line_numbers_cache(LineNumbersCache * cache) {
free_cache_entry(cache2entry(cache->link_entries[i].next));
}
}
- channel_unlock(cache->channel);
+ channel_unlock_with_msg(cache->channel, LINENUMBERS);
list_remove(&cache->link_root);
loc_free(cache);
}
@@ -134,7 +134,7 @@ static LineNumbersCache * get_line_numbers_cache(void) {
for (i = 0; i < HASH_SIZE; i++) {
list_init(cache->link_entries + i);
}
- channel_lock(c);
+ channel_lock_with_msg(c, LINENUMBERS);
for (i = 0; i < c->peer_service_cnt; i++) {
if (strcmp(c->peer_service_list[i], LINENUMBERS) == 0) cache->service_available = 1;
}
diff --git a/agent/tcf/services/processes.c b/agent/tcf/services/processes.c
index feb4e479..8b00c047 100644
--- a/agent/tcf/services/processes.c
+++ b/agent/tcf/services/processes.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -463,7 +463,7 @@ static void attach_done(int error, Context * ctx, void * arg) {
write_errno(&c->out, error);
write_stream(&c->out, MARKER_EOM);
}
- channel_unlock(c);
+ channel_unlock_with_msg(c, PROCESSES[0]);
loc_free(data);
}
@@ -489,7 +489,7 @@ static void command_attach(char * token, Channel * c) {
data->c = c;
strcpy(data->token, token);
if (context_attach(pid, attach_done, data, 0) == 0) {
- channel_lock(c);
+ channel_lock_with_msg(c, PROCESSES[0]);
return;
}
err = errno;
@@ -664,7 +664,7 @@ static void start_done(int error, Context * ctx, void * arg) {
write_stream(&c->out, MARKER_EOM);
}
- channel_unlock(c);
+ channel_unlock_with_msg(c, PROCESSES[0]);
loc_free(data);
}
@@ -1641,7 +1641,7 @@ static void command_start(char * token, Channel * c, void * x) {
if (selfattach) mode |= CONTEXT_ATTACH_SELF;
pending = context_attach(prs->pid, start_done, data, mode) == 0;
if (pending) {
- channel_lock(c);
+ channel_lock_with_msg(c, PROCESSES[0]);
}
else {
err = errno;
diff --git a/agent/tcf/services/symbols_proxy.c b/agent/tcf/services/symbols_proxy.c
index c0683fe9..945425d0 100644
--- a/agent/tcf/services/symbols_proxy.c
+++ b/agent/tcf/services/symbols_proxy.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -319,7 +319,7 @@ static SymbolsCache * get_symbols_cache(void) {
list_init(syms->link_address + i);
list_init(syms->link_location + i);
}
- channel_lock(c);
+ channel_lock_with_msg(c, SYMBOLS);
for (i = 0; i < c->peer_service_cnt; i++) {
if (strcmp(c->peer_service_list[i], SYMBOLS) == 0) syms->service_available = 1;
}
@@ -501,7 +501,7 @@ static void free_symbols_cache(SymbolsCache * syms) {
free_location_info_cache(syms2location(syms->link_location[i].next));
}
}
- channel_unlock(syms->channel);
+ channel_unlock_with_msg(syms->channel, SYMBOLS);
list_remove(&syms->link_root);
loc_free(syms);
}
diff --git a/agent/tcf/services/terminals.c b/agent/tcf/services/terminals.c
index e2dc1c2a..f05e283d 100644
--- a/agent/tcf/services/terminals.c
+++ b/agent/tcf/services/terminals.c
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2014 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -286,7 +286,7 @@ static void terminal_exited(void * args) {
}
list_remove(&term->link);
- channel_unlock(term->channel);
+ channel_unlock_with_msg(term->channel, TERMINALS);
loc_free(term);
}
@@ -462,7 +462,7 @@ static void command_launch(char * token, Channel * c) {
if (!err) {
term->bcg = c->bcg;
- channel_lock(term->channel = c);
+ channel_lock_with_msg(term->channel = c, TERMINALS);
strlcpy(term->pty_type, pty_type, sizeof(term->pty_type));
strlcpy(term->encoding, encoding, sizeof(term->encoding));
list_add_first(&term->link, &terms_list);

Back to the top