summaryrefslogtreecommitdiff
path: root/nuttx/binfmt
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-09-07 12:09:30 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-09-07 13:47:01 -0600
commitfd27da194c956e624c9a6e69a368ececaa4b2b27 (patch)
tree8b7b6d83e05c5763e1b17d51d17c38cb27624b04 /nuttx/binfmt
parente125902a613e6cecbfe2520277610fbb8a0f3043 (diff)
downloadpx4-nuttx-fd27da194c956e624c9a6e69a368ececaa4b2b27.tar.gz
px4-nuttx-fd27da194c956e624c9a6e69a368ececaa4b2b27.tar.bz2
px4-nuttx-fd27da194c956e624c9a6e69a368ececaa4b2b27.zip
Improved binfmt debug output
Diffstat (limited to 'nuttx/binfmt')
-rw-r--r--nuttx/binfmt/binfmt_exec.c51
-rw-r--r--nuttx/binfmt/binfmt_loadmodule.c5
-rw-r--r--nuttx/binfmt/libelf/libelf_load.c1
3 files changed, 37 insertions, 20 deletions
diff --git a/nuttx/binfmt/binfmt_exec.c b/nuttx/binfmt/binfmt_exec.c
index 8760dd6ec..63bac45d2 100644
--- a/nuttx/binfmt/binfmt_exec.c
+++ b/nuttx/binfmt/binfmt_exec.c
@@ -102,6 +102,7 @@ int exec(FAR const char *filename, FAR char * const *argv,
#if defined(CONFIG_SCHED_ONEXIT) && defined(CONFIG_SCHED_HAVE_PARENT)
FAR struct binary_s *bin;
int pid;
+ int err;
int ret;
/* Allocate the load information */
@@ -109,8 +110,9 @@ int exec(FAR const char *filename, FAR char * const *argv,
bin = (FAR struct binary_s *)kmm_zalloc(sizeof(struct binary_s));
if (!bin)
{
- set_errno(ENOMEM);
- return ERROR;
+ bdbg("ERROR: Failed to allocate binary_s\n");
+ err = ENOMEM;
+ goto errout;
}
/* Load the module into memory */
@@ -123,9 +125,9 @@ int exec(FAR const char *filename, FAR char * const *argv,
ret = load_module(bin);
if (ret < 0)
{
- bdbg("ERROR: Failed to load program '%s'\n", filename);
- kmm_free(bin);
- return ERROR;
+ err = get_errno();
+ bdbg("ERROR: Failed to load program '%s': %d\n", filename, err);
+ goto errout_with_bin;
}
/* Disable pre-emption so that the executed module does
@@ -140,11 +142,9 @@ int exec(FAR const char *filename, FAR char * const *argv,
pid = exec_module(bin);
if (pid < 0)
{
- bdbg("ERROR: Failed to execute program '%s'\n", filename);
- sched_unlock();
- unload_module(bin);
- kmm_free(bin);
- return ERROR;
+ err = get_errno();
+ bdbg("ERROR: Failed to execute program '%s': %d\n", filename, err);
+ goto errout_with_lock;
}
/* Set up to unload the module (and free the binary_s structure)
@@ -154,13 +154,25 @@ int exec(FAR const char *filename, FAR char * const *argv,
ret = schedule_unload(pid, bin);
if (ret < 0)
{
- bdbg("ERROR: Failed to schedul unload '%s'\n", filename);
+ err = get_errno();
+ bdbg("ERROR: Failed to schedule unload '%s': %d\n", filename, err);
}
sched_unlock();
return pid;
+
+errout_with_lock:
+ sched_unlock();
+ unload_module(bin);
+errout_with_bin:
+ kmm_free(bin);
+errout:
+ set_errno(err);
+ return ERROR;
+
#else
struct binary_s bin;
+ int err;
int ret;
/* Load the module into memory */
@@ -173,8 +185,9 @@ int exec(FAR const char *filename, FAR char * const *argv,
ret = load_module(&bin);
if (ret < 0)
{
- bdbg("ERROR: Failed to load program '%s'\n", filename);
- return ERROR;
+ err = get_errno();
+ bdbg("ERROR: Failed to load program '%s': %d\n", filename, err);
+ goto errout;
}
/* Then start the module */
@@ -182,14 +195,20 @@ int exec(FAR const char *filename, FAR char * const *argv,
ret = exec_module(&bin);
if (ret < 0)
{
- bdbg("ERROR: Failed to execute program '%s'\n", filename);
- unload_module(&bin);
- return ERROR;
+ err = get_errno();
+ bdbg("ERROR: Failed to execute program '%s': %d\n", filename, err);
+ goto errout_with_module;
}
/* TODO: How does the module get unloaded in this case? */
return ret;
+
+errout_with_module:
+ unload_module(&bin);
+errout:
+ set_errno(err);
+ return ERROR;
#endif
}
diff --git a/nuttx/binfmt/binfmt_loadmodule.c b/nuttx/binfmt/binfmt_loadmodule.c
index 636c537d9..83868460a 100644
--- a/nuttx/binfmt/binfmt_loadmodule.c
+++ b/nuttx/binfmt/binfmt_loadmodule.c
@@ -120,7 +120,7 @@ static int load_absmodule(FAR struct binary_s *bin)
FAR struct binfmt_s *binfmt;
int ret = -ENOENT;
- bdbg("Loading %s\n", bin->filename);
+ bvdbg("Loading %s\n", bin->filename);
/* Disabling pre-emption should be sufficient protection while accessing
* the list of registered binary format handlers.
@@ -262,7 +262,7 @@ int load_module(FAR struct binary_s *bin)
if (ret < 0)
{
- bdbg("Returning errno %d\n", -ret);
+ bdbg("ERROR: Returning errno %d\n", -ret);
set_errno(-ret);
return ERROR;
}
@@ -271,4 +271,3 @@ int load_module(FAR struct binary_s *bin)
}
#endif /* CONFIG_BINFMT_DISABLE */
-
diff --git a/nuttx/binfmt/libelf/libelf_load.c b/nuttx/binfmt/libelf/libelf_load.c
index de3165606..5fd4ce570 100644
--- a/nuttx/binfmt/libelf/libelf_load.c
+++ b/nuttx/binfmt/libelf/libelf_load.c
@@ -61,7 +61,6 @@
#define ELF_ALIGNUP(a) (((unsigned long)(a) + ELF_ALIGN_MASK) & ~ELF_ALIGN_MASK)
#define ELF_ALIGNDOWN(a) ((unsigned long)(a) & ~ELF_ALIGN_MASK)
-
#ifndef MAX
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#endif