[Scummvm-cvs-logs] SF.net SVN: scummvm:[52547] scummvm/branches/gsoc2010-plugins/backends/ plugins

dhewg at users.sourceforge.net dhewg at users.sourceforge.net
Sun Sep 5 14:37:36 CEST 2010


Revision: 52547
          http://scummvm.svn.sourceforge.net/scummvm/?rev=52547&view=rev
Author:   dhewg
Date:     2010-09-05 12:37:36 +0000 (Sun, 05 Sep 2010)

Log Message:
-----------
PLUGINS: Cleanup includes and debug output.

Use the common debug functions instead of spamming #defines.

Modified Paths:
--------------
    scummvm/branches/gsoc2010-plugins/backends/plugins/arm-loader.cpp
    scummvm/branches/gsoc2010-plugins/backends/plugins/arm-loader.h
    scummvm/branches/gsoc2010-plugins/backends/plugins/elf-loader.cpp
    scummvm/branches/gsoc2010-plugins/backends/plugins/elf-loader.h
    scummvm/branches/gsoc2010-plugins/backends/plugins/elf-provider.cpp
    scummvm/branches/gsoc2010-plugins/backends/plugins/elf-provider.h
    scummvm/branches/gsoc2010-plugins/backends/plugins/mips-loader.cpp
    scummvm/branches/gsoc2010-plugins/backends/plugins/mips-loader.h
    scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.cpp
    scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.h

Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/arm-loader.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/arm-loader.cpp	2010-09-05 12:37:07 UTC (rev 52546)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/arm-loader.cpp	2010-09-05 12:37:36 UTC (rev 52547)
@@ -25,21 +25,11 @@
 
 #if defined(DYNAMIC_MODULES) && defined(ARM_TARGET)
 
-#include "backends/fs/ds/ds-fs.h"
-#include "elf-loader.h"
-#include "dsmain.h"
-#include "arm-loader.h"
+#include "backends/plugins/elf-loader.h"
+#include "backends/plugins/arm-loader.h"
 
-//#define __DEBUG_PLUGINS__
+#include "common/debug.h"
 
-#ifdef __DEBUG_PLUGINS__
-#define DBG(x,...) consolePrintf(x, ## __VA_ARGS__)
-#else
-#define DBG(x,...)
-#endif
-
-#define seterror(x,...) consolePrintf(x, ## __VA_ARGS__)
-
 /**
  * Follow the instruction of a relocation section.
  *
@@ -53,14 +43,14 @@
 
 	// Allocate memory for relocation table
 	if (!(rel = (Elf32_Rel *)malloc(size))) {
-		seterror("Out of memory.");
+		warning("elfloader: Out of memory.");
 		return false;
 	}
 
 	// Read in our relocation table
 	if (DLFile->seek(offset, SEEK_SET) < 0 ||
 	        DLFile->read(rel, size) != (ssize_t)size) {
-		seterror("Relocation table load failed.");
+		warning("elfloader: Relocation table load failed.");
 		free(rel);
 		return false;
 	}
@@ -68,7 +58,7 @@
 	// Treat each relocation entry. Loop over all of them
 	int cnt = size / sizeof(*rel);
 
-	DBG("Loaded relocation table. %d entries. base address=%p\n", cnt, relSegment);
+	debug(2, "elfloader: Loaded relocation table. %d entries. base address=%p", cnt, relSegment);
 
 	int a = 0;
 	unsigned int relocation = 0;
@@ -94,28 +84,28 @@
 
 				*target = relocation;
 
-				DBG("R_ARM_ABS32: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target);
+				debug(8, "elfloader: R_ARM_ABS32: i=%d, a=%x, origTarget=%x, target=%x", i, a, origTarget, *target);
 			}
 			break;
 
 		case R_ARM_THM_CALL:
-			DBG("R_ARM_THM_CALL: PC-relative jump, ld takes care of necessary relocation work for us.\n");
+			debug(8, "elfloader: R_ARM_THM_CALL: PC-relative jump, ld takes care of necessary relocation work for us.");
 			break;
 
 		case R_ARM_CALL:
-			DBG("R_ARM_CALL: PC-relative jump, ld takes care of necessary relocation work for us.\n");
+			debug(8, "elfloader: R_ARM_CALL: PC-relative jump, ld takes care of necessary relocation work for us.");
 			break;
 
 		case R_ARM_JUMP24:
-			DBG("R_ARM_JUMP24: PC-relative jump, ld takes care of all relocation work for us.\n");
+			debug(8, "elfloader: R_ARM_JUMP24: PC-relative jump, ld takes care of all relocation work for us.");
 			break;
 
 		case R_ARM_V4BX:
-			DBG("R_ARM_V4BX: No relocation calculation necessary.\n");
+			debug(8, "elfloader: R_ARM_V4BX: No relocation calculation necessary.");
 			break;
 
 		default:
-			seterror("Unknown relocation type %d.", REL_TYPE(rel[i].r_info));
+			warning("elfloader: Unknown relocation type %d.", REL_TYPE(rel[i].r_info));
 			free(rel);
 			return false;
 		}
@@ -140,7 +130,7 @@
 		        (shdr[curShdr->sh_info].sh_flags & SHF_ALLOC)) {  	// Check if relocated section resides in memory
 
 			if (curShdr->sh_type == SHT_RELA) {
-				seterror("RELA entries not supported yet!\n");
+				warning("elfloader: RELA entries not supported yet!");
 				return false;
 			}
 

Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/arm-loader.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/arm-loader.h	2010-09-05 12:37:07 UTC (rev 52546)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/arm-loader.h	2010-09-05 12:37:36 UTC (rev 52547)
@@ -25,9 +25,7 @@
 
 #if defined(DYNAMIC_MODULES) && defined(ARM_TARGET)
 
-#include "backends/fs/ds/ds-fs.h"
-#include "elf-loader.h"
-#include "dsmain.h"
+#include "backends/plugins/elf-loader.h"
 
 class ARMDLObject : public DLObject {
 protected:

Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/elf-loader.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/elf-loader.cpp	2010-09-05 12:37:07 UTC (rev 52546)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/elf-loader.cpp	2010-09-05 12:37:36 UTC (rev 52547)
@@ -27,18 +27,8 @@
 
 #include <string.h>
 #include <stdarg.h>
-#include <stdio.h>
-#include <malloc.h>	// for memalign() (Linux specific)
-#include <unistd.h>
-#include <sys/fcntl.h>
-#include <sys/_default_fcntl.h>	// FIXME: Why do we need this DevKitPro specific header?
 
-#include "common/file.h"
-#include "common/fs.h"
-#include "elf-loader.h"
-
 #ifdef __PSP__
-#include "backends/platform/psp/powerman.h"
 #include <psputils.h>
 #include <psputilsforkernel.h>
 #endif
@@ -47,16 +37,12 @@
 #include <nds.h>
 #endif
 
-#define __DEBUG_PLUGINS__
+#include "backends/plugins/elf-loader.h"
 
-#ifdef __DEBUG_PLUGINS__
-#define DBG(x,...) printf(x, ## __VA_ARGS__)
-#else
-#define DBG(x,...)
-#endif
+#include "common/debug.h"
+#include "common/file.h"
+#include "common/fs.h"
 
-#define seterror(x,...) printf(x, ## __VA_ARGS__)
-
 /**
  * Flushes the data cache (Platform Specific).
  */
@@ -106,12 +92,12 @@
 #endif
 	        ehdr->e_phentsize < sizeof(Elf32_Phdr)	 ||			// Check for size of program header
 	        ehdr->e_shentsize != sizeof(Elf32_Shdr)) {			// Check for size of section header
-		seterror("Invalid file type.");
+		warning("elfloader: Invalid file type.");
 		return false;
 	}
 
-	DBG("phoff = %d, phentsz = %d, phnum = %d\n",
-	    ehdr->e_phoff, ehdr->e_phentsize, ehdr->e_phnum);
+	debug(2, "elfloader: phoff = %d, phentsz = %d, phnum = %d",
+			ehdr->e_phoff, ehdr->e_phentsize, ehdr->e_phnum);
 
 	return true;
 }
@@ -120,18 +106,18 @@
 	// Read program header
 	if (DLFile->seek(ehdr->e_phoff + sizeof(*phdr)*num, SEEK_SET) < 0 ||
 	    DLFile->read(phdr, sizeof(*phdr)) != sizeof(*phdr)) {
-		seterror("Program header load failed.");
+		warning("elfloader: Program header load failed.");
 		return false;
 	}
 
 	// Check program header values
 	if (phdr->p_type != PT_LOAD  || phdr->p_filesz > phdr->p_memsz) {
-		seterror("Invalid program header.");
+		warning("elfloader: Invalid program header.");
 		return false;
 	}
 
-	DBG("offs = %x, filesz = %x, memsz = %x, align = %x\n",
-	    phdr->p_offset, phdr->p_filesz, phdr->p_memsz, phdr->p_align);
+	debug(2, "elfloader: offs = %x, filesz = %x, memsz = %x, align = %x",
+			phdr->p_offset, phdr->p_filesz, phdr->p_memsz, phdr->p_align);
 
 	return true;
 }
@@ -141,14 +127,14 @@
 
 	// Attempt to allocate memory for segment
 	int extra = phdr->p_vaddr % phdr->p_align;	// Get extra length TODO: check logic here
-	DBG("extra mem is %x\n", extra);
+	debug(2, "elfloader: Extra mem is %x", extra);
 
 	if (!(_segment = (char *)memalign(phdr->p_align, phdr->p_memsz + extra))) {
-		seterror("Out of memory.\n");
+		warning("elfloader: Out of memory.");
 		return false;
 	}
 
-	DBG("allocated segment @ %p\n", _segment);
+	debug(2, "elfloader: Allocated segment @ %p", _segment);
 
 	// Get offset to load segment into
 	baseAddress = (char *)_segment + phdr->p_vaddr;
@@ -156,20 +142,20 @@
 
 	// Set bss segment to 0 if necessary (assumes bss is at the end)
 	if (phdr->p_memsz > phdr->p_filesz) {
-		DBG("Setting %p to %p to 0 for bss\n", baseAddress + phdr->p_filesz, baseAddress + phdr->p_memsz);
+		debug(2, "elfloader: Setting %p to %p to 0 for bss", baseAddress + phdr->p_filesz, baseAddress + phdr->p_memsz);
 		memset(baseAddress + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz);
 	}
 
-	DBG("Reading the segment into memory\n");
+	debug(2, "elfloader: Reading the segment into memory");
 
 	// Read the segment into memory
 	if (DLFile->seek(phdr->p_offset, SEEK_SET) < 0 ||
 	        DLFile->read(baseAddress, phdr->p_filesz) != phdr->p_filesz) {
-		seterror("Segment load failed.");
+		warning("elfloader: Segment load failed.");
 		return false;
 	}
 
-	DBG("Segment has been read into memory\n");
+	debug(2, "elfloader: Segment has been read into memory");
 
 	return true;
 }
@@ -179,7 +165,7 @@
 
 	// Allocate memory for section headers
 	if (!(shdr = (Elf32_Shdr *)malloc(ehdr->e_shnum * sizeof(*shdr)))) {
-		seterror("Out of memory.");
+		warning("elfloader: Out of memory.");
 		return NULL;
 	}
 
@@ -187,7 +173,7 @@
 	if (DLFile->seek(ehdr->e_shoff, SEEK_SET) < 0 ||
 	        DLFile->read(shdr, ehdr->e_shnum * sizeof(*shdr)) !=
 	        ehdr->e_shnum * sizeof(*shdr)) {
-		seterror("Section headers load failed.");
+		warning("elfloader: Section headers load failed.");
 		return NULL;
 	}
 
@@ -208,15 +194,15 @@
 
 	// Check for no symbol table
 	if (_symtab_sect < 0) {
-		seterror("No symbol table.");
+		warning("elfloader: No symbol table.");
 		return -1;
 	}
 
-	DBG("Symbol section at section %d, size %x\n", _symtab_sect, shdr[_symtab_sect].sh_size);
+	debug(2, "elfloader: Symbol section at section %d, size %x", _symtab_sect, shdr[_symtab_sect].sh_size);
 
 	// Allocate memory for symbol table
 	if (!(_symtab = malloc(shdr[_symtab_sect].sh_size))) {
-		seterror("Out of memory.");
+		warning("elfloader: Out of memory.");
 		return -1;
 	}
 
@@ -224,13 +210,13 @@
 	if (DLFile->seek(shdr[_symtab_sect].sh_offset, SEEK_SET) < 0 ||
 	        DLFile->read(_symtab, shdr[_symtab_sect].sh_size) !=
 	        shdr[_symtab_sect].sh_size) {
-		seterror("Symbol table load failed.");
+		warning("elfloader: Symbol table load failed.");
 		return -1;
 	}
 
 	// Set number of symbols
 	_symbol_cnt = shdr[_symtab_sect].sh_size / sizeof(Elf32_Sym);
-	DBG("Loaded %d symbols.\n", _symbol_cnt);
+	debug(2, "elfloader: Loaded %d symbols.", _symbol_cnt);
 
 	return _symtab_sect;
 }
@@ -240,7 +226,7 @@
 
 	// Allocate memory for string table
 	if (!(_strtab = (char *)malloc(shdr[string_sect].sh_size))) {
-		seterror("Out of memory.");
+		warning("elfloader: Out of memory.");
 		return false;
 	}
 
@@ -248,7 +234,7 @@
 	if (DLFile->seek(shdr[string_sect].sh_offset, SEEK_SET) < 0 ||
 	        DLFile->read(_strtab, shdr[string_sect].sh_size) !=
 	        shdr[string_sect].sh_size) {
-		seterror("Symbol table strings load failed.");
+		warning("elfloader: Symbol table strings load failed.");
 		return false;
 	}
 
@@ -263,7 +249,7 @@
 		if (s->st_shndx < SHN_LOPROC) {
 				s->st_value += offset;
 				if (s->st_value < (Elf32_Addr)_segment || s->st_value > (Elf32_Addr)_segment + _segmentSize)
-					seterror("Symbol out of bounds! st_value = %x\n", s->st_value);
+					warning("elfloader: Symbol out of bounds! st_value = %x", s->st_value);
 		}
 	}
 }
@@ -279,7 +265,7 @@
 	}
 
 	for (int i = 0; i < ehdr.e_phnum; i++) {	//Load our segments
-		DBG("Loading segment %d\n", i);
+		debug(2, "elfloader: Loading segment %d", i);
 
 		if (readProgramHeaders(DLFile, &ehdr, &phdr, i) == false)
 			return false;
@@ -312,16 +298,16 @@
 	Common::SeekableReadStream* DLFile;
 	void *ctors_start, *ctors_end;
 
-	DBG("open(\"%s\")\n", path);
+	debug(2, "elfloader: open(\"%s\")", path);
 
 	Common::FSNode file(path);
 
 	if (!(DLFile = file.createReadStream())) {
-		seterror("%s not found.", path);
+		warning("elfloader: %s not found.", path);
 		return false;
 	}
 
-	DBG("%s found!\n", path);
+	debug(2, "elfloader: %s found!", path);
 
 	/*Try to load and relocate*/
 	if (!load(DLFile)) {
@@ -329,7 +315,7 @@
 		return false;
 	}
 
-	DBG("loaded!/n");
+	debug(2, "elfloader: Loaded!");
 
 	flushDataCache(_segment, _segmentSize);
 
@@ -340,17 +326,17 @@
 
 	if (ctors_start == NULL || ctors_end == NULL || _dtors_start == NULL ||
 	        _dtors_end == NULL) {
-		seterror("Missing ctors/dtors.");
+		warning("elfloader: Missing ctors/dtors.");
 		_dtors_start = _dtors_end = NULL;
 		unload();
 		return false;
 	}
 
-	DBG("Calling constructors.\n");
+	debug(2, "elfloader: Calling constructors.");
 	for (void (**f)(void) = (void (**)(void))ctors_start; f != ctors_end; f++)
 		(**f)();
 
-	DBG("%s opened ok.\n", path);
+	debug(2, "elfloader: %s opened ok.", path);
 
 	return true;
 }
@@ -365,10 +351,10 @@
 }
 
 void *DLObject::symbol(const char *name) {
-	DBG("symbol(\"%s\")\n", name);
+	debug(2, "elfloader: Symbol(\"%s\")", name);
 
 	if (_symtab == NULL || _strtab == NULL || _symbol_cnt < 1) {
-		seterror("No symbol table loaded.");
+		warning("elfloader: No symbol table loaded.");
 		return NULL;
 	}
 
@@ -379,12 +365,12 @@
 		       !strcmp(name, _strtab + s->st_name)) {
 
 			// We found the symbol
-			DBG("=> %p\n", (void*)s->st_value);
+			debug(2, "elfloader: => %p", (void*)s->st_value);
 			return (void*)s->st_value;
 		}
 
 	// We didn't find the symbol
-	seterror("Symbol \"%s\" not found.", name);
+	warning("elfloader: Symbol \"%s\" not found.", name);
 	return NULL;
 }
 

Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/elf-loader.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/elf-loader.h	2010-09-05 12:37:07 UTC (rev 52546)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/elf-loader.h	2010-09-05 12:37:36 UTC (rev 52547)
@@ -28,10 +28,11 @@
 #ifndef ELF_LOADER_H
 #define ELF_LOADER_H
 
-#include "elf32.h"
-#include "common/stream.h"
 #include "backends/plugins/dynamic-plugin.h"
+#include "backends/plugins/elf32.h"
 
+#include "common/stream.h"
+
 /**
  * DLObject
  *
@@ -49,7 +50,6 @@
 
     uint32 _segmentSize;
 
-    //void seterror(const char *fmt, ...);
     virtual void unload();
     virtual bool relocate(Common::SeekableReadStream* DLFile, unsigned long offset, unsigned long size, void *relSegment) = 0;
     bool load(Common::SeekableReadStream* DLFile);

Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/elf-provider.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/elf-provider.cpp	2010-09-05 12:37:07 UTC (rev 52546)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/elf-provider.cpp	2010-09-05 12:37:36 UTC (rev 52547)
@@ -27,10 +27,9 @@
 
 #include "backends/plugins/elf-provider.h"
 #include "backends/plugins/dynamic-plugin.h"
+
 #include "common/fs.h"
 
-#include "backends/plugins/elf-loader.h"
-
 DynamicPlugin::VoidFunc ELFPlugin::findSymbol(const char *symbol) {
 	void *func;
 	bool handleNull;
@@ -42,9 +41,9 @@
 	}
 	if (!func) {
 		if (handleNull) {
-			warning("Failed loading symbol '%s' from plugin '%s' (Handle is NULL)", symbol, _filename.c_str());
+			warning("elfloader: Failed loading symbol '%s' from plugin '%s' (Handle is NULL)", symbol, _filename.c_str());
 		} else {
-			warning("Failed loading symbol '%s' from plugin '%s'", symbol, _filename.c_str());
+			warning("elfloader: Failed loading symbol '%s' from plugin '%s'", symbol, _filename.c_str());
 		}
 	}
 
@@ -69,7 +68,7 @@
 		}
 
 		if (!_dlHandle) {
-			warning("Failed loading plugin '%s'", _filename.c_str());
+			warning("elfloader: Failed loading plugin '%s'", _filename.c_str());
 			return false;
 		}
 
@@ -80,13 +79,13 @@
 		}
 
 		return ret;
-};
+}
 
 void ELFPlugin::unloadPlugin() {
 	DynamicPlugin::unloadPlugin();
 	if (_dlHandle) {
 		if (!_dlHandle->close()) {
-			warning("Failed unloading plugin '%s'", _filename.c_str());
+			warning("elfloader: Failed unloading plugin '%s'", _filename.c_str());
 		}
 		delete _dlHandle;
 		_dlHandle = 0;

Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/elf-provider.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/elf-provider.h	2010-09-05 12:37:07 UTC (rev 52546)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/elf-provider.h	2010-09-05 12:37:36 UTC (rev 52547)
@@ -28,12 +28,10 @@
 #ifndef BACKENDS_PLUGINS_ELF_PROVIDER_H
 #define BACKENDS_PLUGINS_ELF_PROVIDER_H
 
-#include "base/plugins.h"
-#include "backends/plugins/dynamic-plugin.h"
-#include "common/fs.h"
-
 #include "backends/plugins/elf-loader.h"
 
+#include "common/fs.h"
+
 /**
  * ELFPlugin
  *

Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/mips-loader.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/mips-loader.cpp	2010-09-05 12:37:07 UTC (rev 52546)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/mips-loader.cpp	2010-09-05 12:37:36 UTC (rev 52547)
@@ -25,18 +25,10 @@
 
 #if defined(DYNAMIC_MODULES) && defined(MIPS_TARGET)
 
-#include "mips-loader.h"
+#include "backends/plugins/mips-loader.h"
 
-//#define __DEBUG_PLUGINS__
+#include "common/debug.h"
 
-#ifdef __DEBUG_PLUGINS__
-#define DBG(x,...) printf(x, ## __VA_ARGS__)
-#else
-#define DBG(x,...)
-#endif
-
-#define seterror(x,...) printf(x, ## __VA_ARGS__)
-
 /**
  * Follow the instruction of a relocation section.
  *
@@ -51,14 +43,14 @@
 
 	// Allocate memory for relocation table
 	if (!(rel = (Elf32_Rel *)malloc(size))) {
-		seterror("Out of memory.");
+		warning("elfloader: Out of memory.");
 		return false;
 	}
 
 	// Read in our relocation table
 	if (DLFile->seek(offset, SEEK_SET) < 0 ||
 	        DLFile->read(rel, size) != (ssize_t)size) {
-		seterror("Relocation table load failed.");
+		warning("elfloader: Relocation table load failed.");
 		free(rel);
 		return false;
 	}
@@ -66,7 +58,7 @@
 	// Treat each relocation entry. Loop over all of them
 	int cnt = size / sizeof(*rel);
 
-	DBG("Loaded relocation table. %d entries. base address=%p\n", cnt, relSegment);
+	debug(2, "elfloader: Loaded relocation table. %d entries. base address=%p", cnt, relSegment);
 
 	bool seenHi16 = false;	// For treating HI/LO16 commands
 	int firstHi16 = -1;		// Mark the point of the first hi16 seen
@@ -105,7 +97,7 @@
 				lastHiSymVal = sym->st_value;
 				hi16InShorts = (ShortsMan.inGeneralSegment((char *)sym->st_value)); // Fix for problem with switching btw segments
 				if (debugRelocs[0]++ < DEBUG_NUM)	// Print only a set number
-					DBG("R_MIPS_HI16: i=%d, offset=%x, ahl = %x, target = %x\n",
+					debug(8, "elfloader: R_MIPS_HI16: i=%d, offset=%x, ahl = %x, target = %x",
 					    i, rel[i].r_offset, ahl, *target);
 			}
 			break;
@@ -113,7 +105,7 @@
 		case R_MIPS_LO16:						// Absolute addressing. Needs a HI16 to come before it
 			if (sym->st_shndx < SHN_LOPROC) {		// Only shift for plugin section. (ie. has a real section index)
 				if (!seenHi16) {					// We MUST have seen HI16 first
-					seterror("R_MIPS_LO16 w/o preceding R_MIPS_HI16 at relocation %d!\n", i);
+					debug(8, "elfloader: R_MIPS_LO16 w/o preceding R_MIPS_HI16 at relocation %d!", i);
 					free(rel);
 					return false;
 				}
@@ -158,10 +150,10 @@
 				*target |= relocation & 0xffff;				// Take the lower 16 bits of the relocation
 
 				if (debugRelocs[1]++ < DEBUG_NUM)
-					DBG("R_MIPS_LO16: i=%d, offset=%x, a=%x, ahl = %x, lastTarget = %x, origt = %x, target = %x\n",
+					debug(8, "elfloader: R_MIPS_LO16: i=%d, offset=%x, a=%x, ahl = %x, lastTarget = %x, origt = %x, target = %x",
 					    i, rel[i].r_offset, a, ahl, *lastTarget, origTarget, *target);
 				if (lo16InShorts && debugRelocs[2]++ < DEBUG_NUM)
-					DBG("R_MIPS_LO16s: i=%d, offset=%x, a=%x, ahl = %x, lastTarget = %x, origt = %x, target = %x\n",
+					debug(8, "elfloader: R_MIPS_LO16s: i=%d, offset=%x, a=%x, ahl = %x, lastTarget = %x, origt = %x, target = %x",
 					    i, rel[i].r_offset, a, ahl, *lastTarget, origTarget, *target);
 			}
 			break;
@@ -175,11 +167,11 @@
 				*target |= (relocation & 0x03ffffff);
 
 				if (debugRelocs[3]++ < DEBUG_NUM)
-					DBG("R_MIPS_26: i=%d, offset=%x, symbol=%d, stinfo=%x, a=%x, origTarget=%x, target=%x\n",
+					debug(8, "elfloader: R_MIPS_26: i=%d, offset=%x, symbol=%d, stinfo=%x, a=%x, origTarget=%x, target=%x",
 					    i, rel[i].r_offset, REL_INDEX(rel[i].r_info), sym->st_info, a, origTarget, *target);
 			} else {
 				if (debugRelocs[4]++ < DEBUG_NUM)
-					DBG("R_MIPS_26: i=%d, offset=%x, symbol=%d, stinfo=%x, a=%x, origTarget=%x, target=%x\n",
+					debug(8, "elfloader: R_MIPS_26: i=%d, offset=%x, symbol=%d, stinfo=%x, a=%x, origTarget=%x, target=%x",
 					    i, rel[i].r_offset, REL_INDEX(rel[i].r_info), sym->st_info, a, origTarget, *target);
 			}
 			break;
@@ -196,7 +188,7 @@
 				*target |= relocation & 0xffff;
 
 				if (debugRelocs[5]++ < DEBUG_NUM)
-					DBG("R_MIPS_GPREL16: i=%d, a=%x, gpVal=%x, origTarget=%x, target=%x, offset=%x\n",
+					debug(8, "elfloader: R_MIPS_GPREL16: i=%d, a=%x, gpVal=%x, origTarget=%x, target=%x, offset=%x",
 					    i, a, _gpVal, origTarget, *target, _shortsSegment->getOffset());
 			}
 
@@ -213,18 +205,18 @@
 				*target = relocation;
 
 				if (debugRelocs[6]++ < DEBUG_NUM)
-					DBG("R_MIPS_32: i=%d, a=%x, origTarget=%x, target=%x\n", i, a, origTarget, *target);
+					debug("8, elfloader: R_MIPS_32: i=%d, a=%x, origTarget=%x, target=%x", i, a, origTarget, *target);
 			}
 			break;
 
 		default:
-			seterror("Unknown relocation type %x at relocation %d.\n", REL_TYPE(rel[i].r_info), i);
+			warning("elfloader: Unknown relocation type %x at relocation %d.", REL_TYPE(rel[i].r_info), i);
 			free(rel);
 			return false;
 		}
 	}
 
-	DBG("Done with relocation. extendedHi16=%d\n\n", extendedHi16);
+	debug(2, "elfloader: Done with relocation. extendedHi16=%d", extendedHi16);
 
 	free(rel);
 	return true;
@@ -274,12 +266,12 @@
 				mainCount++;
 				s->st_value += offset;
 				if (s->st_value < (Elf32_Addr)_segment || s->st_value > (Elf32_Addr)_segment + _segmentSize)
-					seterror("Symbol out of bounds! st_value = %x\n", s->st_value);
+					warning("elfloader: Symbol out of bounds! st_value = %x", s->st_value);
 			} else {	// shorts section
 				shortsCount++;
 				s->st_value += _shortsSegment->getOffset();
 				if (!_shortsSegment->inSegment((char *)s->st_value))
-					seterror("Symbol out of bounds! st_value = %x\n", s->st_value);
+					warning("elfloader: Symbol out of bounds! st_value = %x", s->st_value);
 			}
 
 		}
@@ -295,15 +287,15 @@
 
 		// Attempt to allocate memory for segment
 		int extra = phdr->p_vaddr % phdr->p_align;	// Get extra length TODO: check logic here
-		DBG("extra mem is %x\n", extra);
+		debug(2, "elfloader: Extra mem is %x", extra);
 
 		if (phdr->p_align < 0x10000) phdr->p_align = 0x10000;	// Fix for wrong alignment on e.g. AGI
 
 		if (!(_segment = (char *)memalign(phdr->p_align, phdr->p_memsz + extra))) {
-			seterror("Out of memory.\n");
+			warning("elfloader: Out of memory.");
 			return false;
 		}
-		DBG("allocated segment @ %p\n", _segment);
+		debug(2, "elfloader: Allocated segment @ %p", _segment);
 
 		// Get offset to load segment into
 		baseAddress = (char *)_segment + phdr->p_vaddr;
@@ -312,26 +304,26 @@
 		_shortsSegment = ShortsMan.newSegment(phdr->p_memsz, (char *)phdr->p_vaddr);
 
 		baseAddress = _shortsSegment->getStart();
-		DBG("shorts segment @ %p to %p. Segment wants to be at %x. Offset=%x\n",
+		debug(2, "elfloader: Shorts segment @ %p to %p. Segment wants to be at %x. Offset=%x",
 		    _shortsSegment->getStart(), _shortsSegment->getEnd(), phdr->p_vaddr, _shortsSegment->getOffset());
 	}
 
 	// Set bss segment to 0 if necessary (assumes bss is at the end)
 	if (phdr->p_memsz > phdr->p_filesz) {
-		DBG("Setting %p to %p to 0 for bss\n", baseAddress + phdr->p_filesz, baseAddress + phdr->p_memsz);
+		debug(2, "elfloader: Setting %p to %p to 0 for bss", baseAddress + phdr->p_filesz, baseAddress + phdr->p_memsz);
 		memset(baseAddress + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz);
 	}
 
-	DBG("Reading the segment into memory\n");
+	debug(2, "elfloader: Reading the segment into memory");
 
 	// Read the segment into memory
 	if (DLFile->seek(phdr->p_offset, SEEK_SET) < 0 ||
 	        DLFile->read(baseAddress, phdr->p_filesz) != (ssize_t)phdr->p_filesz) {
-		seterror("Segment load failed.");
+		warning("elfloader: Segment load failed.");
 		return false;
 	}
 
-	DBG("Segment has been read into memory\n");
+	debug(2, "elfloader: Segment has been read into memory");
 
 	return true;
 }

Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/mips-loader.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/mips-loader.h	2010-09-05 12:37:07 UTC (rev 52546)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/mips-loader.h	2010-09-05 12:37:36 UTC (rev 52547)
@@ -26,8 +26,8 @@
 
 #if defined(DYNAMIC_MODULES) && defined(MIPS_TARGET)
 
-#include "elf-loader.h"
-#include "shorts-segment-manager.h"
+#include "backends/plugins/elf-loader.h"
+#include "backends/plugins/shorts-segment-manager.h"
 
 class MIPSDLObject : public DLObject {
 protected:

Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.cpp
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.cpp	2010-09-05 12:37:07 UTC (rev 52546)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.cpp	2010-09-05 12:37:36 UTC (rev 52547)
@@ -25,20 +25,14 @@
 
 #if defined(DYNAMIC_MODULES) && defined(MIPS_TARGET)
 
-#include "shorts-segment-manager.h"
+#include "backends/plugins/shorts-segment-manager.h"
 
+#include "common/debug.h"
+
 extern char __plugin_hole_start;	// Indicates start of hole in program file for shorts
 extern char __plugin_hole_end;		// Indicates end of hole in program file
 extern char _gp[];			// Value of gp register
 
-#ifdef DEBUG_PLUGINS
-#define DBG(x,...) printf(x, ## __VA_ARGS__)
-#else
-#define DBG(x,...)
-#endif
-
-#define seterror(x,...) printf(x, ## __VA_ARGS__)
-
 DECLARE_SINGLETON(ShortSegmentManager);	// For singleton
 
 ShortSegmentManager::ShortSegmentManager() {
@@ -63,7 +57,7 @@
 		lastAddress += 4 - ((Elf32_Addr)lastAddress & 3);	// Round up to multiple of 4
 
 	if (lastAddress + size > _shortsEnd) {
-		seterror("Error. No space in shorts segment for %x bytes. Last address is %p, max address is %p.\n",
+		warning("elfloader: No space in shorts segment for %x bytes. Last address is %p, max address is %p.",
 		         size, lastAddress, _shortsEnd);
 		return NULL;
 	}
@@ -74,14 +68,14 @@
 
 	_list.insert(i, seg);
 
-	DBG("Shorts segment size %x allocated. End = %p. Remaining space = %x. Highest so far is %p.\n",
+	debug(2, "elfloader: Shorts segment size %x allocated. End = %p. Remaining space = %x. Highest so far is %p.",
 	    size, lastAddress + size, _shortsEnd - _list.back()->getEnd(), _highestAddress);
 
 	return seg;
 }
 
 void ShortSegmentManager::deleteSegment(ShortSegmentManager::Segment *seg) {
-	DBG("Deleting shorts segment from %p to %p.\n\n", seg->getStart(), seg->getEnd());
+	debug(2, "elfloader: Deleting shorts segment from %p to %p.", seg->getStart(), seg->getEnd());
 	_list.remove(seg);
 	delete seg;
 }

Modified: scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.h
===================================================================
--- scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.h	2010-09-05 12:37:07 UTC (rev 52546)
+++ scummvm/branches/gsoc2010-plugins/backends/plugins/shorts-segment-manager.h	2010-09-05 12:37:36 UTC (rev 52547)
@@ -28,9 +28,10 @@
 #ifndef SHORTS_SEGMENT_MANAGER_H
 #define SHORTS_SEGMENT_MANAGER_H
 
+#include "backends/plugins/elf32.h"
+
 #include "common/singleton.h"
 #include "common/list.h"
-#include "elf32.h"
 
 #define ShortsMan ShortSegmentManager::instance()
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list