[syslinux:firmware] module: convert to dprintf() to aid debugging

syslinux-bot for Matt Fleming matt.fleming at intel.com
Fri Jul 26 08:45:04 PDT 2013


Commit-ID:  0006a5e1bc8742fbbc6fbe52d1d12bab05eef311
Gitweb:     http://www.syslinux.org/commit/0006a5e1bc8742fbbc6fbe52d1d12bab05eef311
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Fri, 26 Jul 2013 16:35:59 +0100
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Fri, 26 Jul 2013 16:35:59 +0100

module: convert to dprintf() to aid debugging

dprintf() is much more useful than DBG_PRINT() when trying to figure out
where a module is failing to load because we can enable the debug
statements at runtime.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/lib/sys/module/common.c     | 25 ++++++++++++++-----------
 com32/lib/sys/module/elf_module.c |  9 +++++----
 com32/lib/sys/module/exec.c       |  5 ++++-
 3 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/com32/lib/sys/module/common.c b/com32/lib/sys/module/common.c
index a589f24..05a27e8 100644
--- a/com32/lib/sys/module/common.c
+++ b/com32/lib/sys/module/common.c
@@ -77,6 +77,7 @@ FILE *findpath(char *name)
 		snprintf(path, sizeof(path), "%s%s%s",
 			 entry->str, slash ? "/" : "", name);
 
+		dprintf("findpath: trying \"%s\"\n", path);
 		f = fopen(path, "rb");
 		if (f)
 			return f;
@@ -94,7 +95,7 @@ int image_load(struct elf_module *module)
 	module->u.l._file = findpath(module->name);
 
 	if (module->u.l._file == NULL) {
-		DBG_PRINT("Could not open object file '%s'\n", module->name);
+		dprintf("Could not open object file '%s'\n", module->name);
 		goto error;
 	}
 
@@ -225,30 +226,30 @@ int check_header_common(Elf_Ehdr *elf_hdr) {
 		elf_hdr->e_ident[EI_MAG2] != ELFMAG2 ||
 		elf_hdr->e_ident[EI_MAG3] != ELFMAG3) {
 
-		DBG_PRINT("The file is not an ELF object\n");
+		dprintf("The file is not an ELF object\n");
 		return -1;
 	}
 
 	if (elf_hdr->e_ident[EI_CLASS] != ELFCLASS32 &&
 	    elf_hdr->e_ident[EI_CLASS] != ELFCLASS64) {
-		DBG_PRINT("Invalid ELF class code\n");
+		dprintf("Invalid ELF class code\n");
 		return -1;
 	}
 
 	if (elf_hdr->e_ident[EI_DATA] != MODULE_ELF_DATA) {
-		DBG_PRINT("Invalid ELF data encoding\n");
+		dprintf("Invalid ELF data encoding\n");
 		return -1;
 	}
 
 	if (elf_hdr->e_ident[EI_VERSION] != MODULE_ELF_VERSION ||
 			elf_hdr->e_version != MODULE_ELF_VERSION) {
-		DBG_PRINT("Invalid ELF file version\n");
+		dprintf("Invalid ELF file version\n");
 		return -1;
 	}
 
 	if (elf_hdr->e_machine != EM_386 &&
 		elf_hdr->e_machine != EM_X86_64) {
-		DBG_PRINT("Invalid ELF architecture\n");
+		dprintf("Invalid ELF architecture\n");
 		return -1;
 	}
 
@@ -360,7 +361,7 @@ int check_symbols(struct elf_module *module)
 			// and ISOLINUX. See perform_relocations().
 			if (strong_count == 0 && weak_count == 0)
 			{
-				DBG_PRINT("Symbol %s is undefined\n", crt_name);
+				dprintf("Symbol %s is undefined\n", crt_name);
 				printf("Undef symbol FAIL: %s\n",crt_name);
 				return -1;
 			}
@@ -371,7 +372,7 @@ int check_symbols(struct elf_module *module)
 			{
 				// It's not an error - at relocation, the most recent symbol
 				// will be considered
-				DBG_PRINT("Info: Symbol %s is defined more than once\n", crt_name);
+				dprintf("Info: Symbol %s is defined more than once\n", crt_name);
 			}
 		}
 		//printf("symbol %s laoded from %d\n",crt_name,crt_sym->st_value);
@@ -393,7 +394,7 @@ int _module_unload(struct elf_module *module) {
 	struct module_dep *crt_dep, *tmp;
 	// Make sure nobody needs us
 	if (!module_unloadable(module)) {
-		DBG_PRINT("Module is required by other modules.\n");
+		dprintf("Module is required by other modules.\n");
 		return -1;
 	}
 
@@ -409,9 +410,11 @@ int _module_unload(struct elf_module *module) {
 	if (module->module_addr != NULL) {
 		elf_free(module->module_addr);
 
-		DBG_PRINT("%s MODULE %s UNLOADED\n", module->shallow ? "SHALLOW" : "",
+		dprintf("%s MODULE %s UNLOADED\n", module->shallow ? "SHALLOW" : "",
 				module->name);
 	}
+
+	dprintf("Unloading module %s\n", module->name);
 	// Release the module structure
 	free(module);
 
@@ -487,7 +490,7 @@ static Elf_Sym *module_find_symbol_gnu(const char *name, struct elf_module *modu
 	Elf_Word bitmask_nwords = *cr_word++;
 
 	if ((bitmask_nwords & (bitmask_nwords - 1)) != 0) {
-		DBG_PRINT("Invalid GNU Hash structure\n");
+		dprintf("Invalid GNU Hash structure\n");
 		return NULL;
 	}
 
diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c
index e3d9928..e09a540 100644
--- a/com32/lib/sys/module/elf_module.c
+++ b/com32/lib/sys/module/elf_module.c
@@ -29,12 +29,12 @@ static int check_header(Elf_Ehdr *elf_hdr) {
 		return res;
 
 	if (elf_hdr->e_type != MODULE_ELF_TYPE) {
-		DBG_PRINT("The ELF file must be a shared object\n");
+		dprintf("The ELF file must be a shared object\n");
 		return -1;
 	}
 
 	if (elf_hdr->e_phoff == 0x00000000) {
-		DBG_PRINT("PHT missing\n");
+		dprintf("PHT missing\n");
 		return -1;
 	}
 
@@ -188,7 +188,7 @@ int module_load(struct elf_module *module) {
 
 	// Do not allow duplicate modules
 	if (module_find(module->name) != NULL) {
-		DBG_PRINT("Module %s is already loaded.\n", module->name);
+		dprintf("Module %s is already loaded.\n", module->name);
 		return EEXIST;
 	}
 
@@ -196,6 +196,7 @@ int module_load(struct elf_module *module) {
 	res = image_load(module);
 
 	if (res < 0) {
+		dprintf("Image load failed for %s\n", module->name);
 		return res;
 	}
 
@@ -281,7 +282,7 @@ int module_load(struct elf_module *module) {
 	image_unload(module);
 
 	/*
-	DBG_PRINT("MODULE %s LOADED SUCCESSFULLY (main@%p, init@%p, exit@%p)\n",
+	dprintf("MODULE %s LOADED SUCCESSFULLY (main@%p, init@%p, exit@%p)\n",
 			module->name,
 			(module->main_func == NULL) ? NULL : *(module->main_func),
 			(module->init_func == NULL) ? NULL : *(module->init_func),
diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c
index 18c8306..84b96e0 100644
--- a/com32/lib/sys/module/exec.c
+++ b/com32/lib/sys/module/exec.c
@@ -169,6 +169,7 @@ int spawn_load(const char *name, int argc, char **argv)
 
 	if (get_module_type(module) == EXEC_MODULE) {
 		if (!argc || !argv || strcmp(argv[0], name)) {
+			dprintf("invalid args for %s\n", name);
 			res = -1;
 			goto out;
 		}
@@ -182,8 +183,10 @@ int spawn_load(const char *name, int argc, char **argv)
 	}
 
 	res = module_load(module);
-	if (res != 0)
+	if (res != 0) {
+		dprintf("failed to load module %s\n", module->name);
 		goto out;
+	}
 
 	type = get_module_type(module);
 


More information about the Syslinux-commits mailing list