Index: uspace/lib/c/generic/loader.c
===================================================================
--- uspace/lib/c/generic/loader.c	(revision c24b0dcbc89da1b8b0d83e5d3cd40cf5fcf3b37b)
+++ uspace/lib/c/generic/loader.c	(revision 3106054d4d858ffdc84fd8a04948c84f0832c541)
@@ -345,4 +345,27 @@
 }
 
+/** Instruct loader to execute the program and do not wait for reply.
+ *
+ * This function does not block even if the loaded task is stopped
+ * for debugging.
+ *
+ * After using this function, no further operations can be performed
+ * on the loader structure and it is deallocated.
+ *
+ * @param ldr Loader connection structure.
+ *
+ * @return Zero on success or an error code.
+ *
+ */
+void loader_run_nowait(loader_t *ldr)
+{
+	async_exch_t *exch = async_exchange_begin(ldr->sess);
+	async_msg_0(exch, LOADER_RUN);
+	async_exchange_end(exch);
+
+	async_hangup(ldr->sess);
+	free(ldr);
+}
+
 /** Cancel the loader session.
  *
Index: uspace/lib/c/generic/task.c
===================================================================
--- uspace/lib/c/generic/task.c	(revision c24b0dcbc89da1b8b0d83e5d3cd40cf5fcf3b37b)
+++ uspace/lib/c/generic/task.c	(revision 3106054d4d858ffdc84fd8a04948c84f0832c541)
@@ -35,4 +35,5 @@
  */
 
+#include <async.h>
 #include <task.h>
 #include <loader/loader.h>
@@ -46,4 +47,5 @@
 #include <ns.h>
 #include <stdlib.h>
+#include <udebug.h>
 #include <libc.h>
 #include "private/ns.h"
@@ -94,4 +96,5 @@
  * This is really just a convenience wrapper over the more complicated
  * loader API. Arguments are passed as a null-terminated array of strings.
+ * A debug session is created optionally.
  *
  * @param id   If not NULL, the ID of the task is stored here on success.
@@ -100,10 +103,12 @@
  * @param path Pathname of the binary to execute.
  * @param argv Command-line arguments.
- *
- * @return Zero on success or an error code.
- *
- */
-errno_t task_spawnv(task_id_t *id, task_wait_t *wait, const char *path,
-    const char *const args[])
+ * @param rsess   Place to store pointer to debug session or @c NULL
+ *                not to start a debug session
+ *
+ * @return Zero on success or an error code.
+ *
+ */
+errno_t task_spawnv_debug(task_id_t *id, task_wait_t *wait, const char *path,
+    const char *const args[], async_sess_t **rsess)
 {
 	/* Send default files */
@@ -125,28 +130,54 @@
 	}
 
-	return task_spawnvf(id, wait, path, args, fd_stdin, fd_stdout,
-	    fd_stderr);
+	return task_spawnvf_debug(id, wait, path, args, fd_stdin, fd_stdout,
+	    fd_stderr, rsess);
 }
 
 /** Create a new task by running an executable from the filesystem.
+ *
+ * This is really just a convenience wrapper over the more complicated
+ * loader API. Arguments are passed as a null-terminated array of strings.
+ *
+ * @param id   If not NULL, the ID of the task is stored here on success.
+ * @param wait If not NULL, setup waiting for task's return value and store
+ *             the information necessary for waiting here on success.
+ * @param path Pathname of the binary to execute.
+ * @param argv Command-line arguments.
+ *
+ * @return Zero on success or an error code.
+ *
+ */
+errno_t task_spawnv(task_id_t *id, task_wait_t *wait, const char *path,
+    const char *const args[])
+{
+	return task_spawnv_debug(id, wait, path, args, NULL);
+}
+
+/** Create a new task by loading an executable from the filesystem.
  *
  * This is really just a convenience wrapper over the more complicated
  * loader API. Arguments are passed as a null-terminated array of strings.
  * Files are passed as null-terminated array of pointers to fdi_node_t.
+ * A debug session is created optionally.
  *
  * @param id      If not NULL, the ID of the task is stored here on success.
- * @param wait    If not NULL, setup waiting for task's return value and store
+ * @param wait    If not NULL, setup waiting for task's return value and store.
  * @param path    Pathname of the binary to execute.
- * @param argv    Command-line arguments.
- * @param std_in  File to use as stdin.
- * @param std_out File to use as stdout.
- * @param std_err File to use as stderr.
- *
- * @return Zero on success or an error code.
- *
- */
-errno_t task_spawnvf(task_id_t *id, task_wait_t *wait, const char *path,
-    const char *const args[], int fd_stdin, int fd_stdout, int fd_stderr)
-{
+ * @param argv    Command-line arguments
+ * @param std_in  File to use as stdin
+ * @param std_out File to use as stdout
+ * @param std_err File to use as stderr
+ * @param rsess   Place to store pointer to debug session or @c NULL
+ *                not to start a debug session
+ *
+ * @return Zero on success or an error code
+ *
+ */
+errno_t task_spawnvf_debug(task_id_t *id, task_wait_t *wait,
+    const char *path, const char *const args[], int fd_stdin, int fd_stdout,
+    int fd_stderr, async_sess_t **rsess)
+{
+	async_sess_t *ksess = NULL;
+
 	/* Connect to a program loader. */
 	loader_t *ldr = loader_connect();
@@ -217,16 +248,39 @@
 	}
 
-	/* Run it. */
-	rc = loader_run(ldr);
-	if (rc != EOK)
-		goto error;
+	/* Start a debug session if requested */
+	if (rsess != NULL) {
+		ksess = async_connect_kbox(task_id);
+		if (ksess == NULL) {
+			/* Most likely debugging support is not compiled in */
+			rc = ENOTSUP;
+			goto error;
+		}
+
+		rc = udebug_begin(ksess);
+		if (rc != EOK)
+			goto error;
+
+		/*
+		 * Run it, not waiting for response. It would never come
+		 * as the loader is stopped.
+		 */
+		loader_run_nowait(ldr);
+	} else {
+		/* Run it. */
+		rc = loader_run(ldr);
+		if (rc != EOK)
+			goto error;
+	}
 
 	/* Success */
 	if (id != NULL)
 		*id = task_id;
-
+	if (rsess != NULL)
+		*rsess = ksess;
 	return EOK;
 
 error:
+	if (ksess != NULL)
+		async_hangup(ksess);
 	if (wait_initialized)
 		task_cancel_wait(wait);
@@ -235,4 +289,27 @@
 	loader_abort(ldr);
 	return rc;
+}
+
+/** Create a new task by running an executable from the filesystem.
+ *
+ * Arguments are passed as a null-terminated array of strings.
+ * Files are passed as null-terminated array of pointers to fdi_node_t.
+ *
+ * @param id      If not NULL, the ID of the task is stored here on success.
+ * @param wait    If not NULL, setup waiting for task's return value and store.
+ * @param path    Pathname of the binary to execute
+ * @param argv    Command-line arguments
+ * @param std_in  File to use as stdin
+ * @param std_out File to use as stdout
+ * @param std_err File to use as stderr
+ *
+ * @return Zero on success or an error code.
+ *
+ */
+errno_t task_spawnvf(task_id_t *id, task_wait_t *wait, const char *path,
+    const char *const args[], int fd_stdin, int fd_stdout, int fd_stderr)
+{
+	return task_spawnvf_debug(id, wait, path, args, fd_stdin, fd_stdout,
+	    fd_stderr, NULL);
 }
 
