Index: soclib/lib/iss_memchecker/metadata/iss_memchecker.sd
===================================================================
--- soclib/lib/iss_memchecker/metadata/iss_memchecker.sd	(revision 830)
+++ soclib/lib/iss_memchecker/metadata/iss_memchecker.sd	(working copy)
@@ -15,7 +15,7 @@
 	Uses('common:iss2'),
 	Uses('common:mapping_table'),
 	Uses('common:exception'),
-	Uses('common:elf_loader'),
+	Uses('common:elf_file_loader'),
 	],
 	   extensions = [
 	'dsx:cpu=wrapper:iss_memchecker_t',
Index: soclib/lib/iss_memchecker/include/iss_memchecker.h
===================================================================
--- soclib/lib/iss_memchecker/include/iss_memchecker.h	(revision 830)
+++ soclib/lib/iss_memchecker/include/iss_memchecker.h	(working copy)
@@ -97,7 +97,7 @@
     }
 
     static void init( const soclib::common::MappingTable &mt,
-                      const soclib::common::ElfLoader &loader,
+                      const soclib::common::BinaryFileLoader &loader,
                       const std::string &exclusions = "" );
 
 private:
Index: soclib/lib/iss_memchecker/src/iss_memchecker.cpp
===================================================================
--- soclib/lib/iss_memchecker/src/iss_memchecker.cpp	(revision 830)
+++ soclib/lib/iss_memchecker/src/iss_memchecker.cpp	(working copy)
@@ -35,7 +35,7 @@
 #include "exception.h"
 
 #include "soclib_endian.h"
-#include "elf_loader.h"
+#include "binary_file_loader.h"
 
 namespace soclib { namespace common {
 
@@ -433,7 +433,7 @@
 
 class MemoryState
 {
-    ElfLoader m_binary;
+    BinaryFileLoader m_binary;
 
     typedef std::map<uint32_t, ContextState *> context_map_t;
     typedef std::map<uint32_t, std::vector<AddressInfo> *> region_map_t;
@@ -446,7 +446,7 @@
     ContextState * const unknown_context;
 
     MemoryState( const soclib::common::MappingTable &mt,
-                 const soclib::common::ElfLoader &loader,
+                 const soclib::common::BinaryFileLoader &loader,
                  const std::string &exclusions )
         : m_binary(loader),
           m_contexts(),
@@ -458,7 +458,7 @@
         unknown_context->ref();
 
         const std::list<Segment> &segments = mt.getAllSegmentList();
-        ElfLoader::section_list_t sections = loader.sections();
+        BinaryFileLoader::section_list_t sections = loader.sections();
 
         std::string exclusion_list = ",";
         exclusion_list += exclusions + ",";
@@ -478,7 +478,7 @@
             m_regions[i->baseAddress()] = rm;
         }
 
-        for ( ElfLoader::section_list_t::const_iterator i = sections.begin();
+        for ( BinaryFileLoader::section_list_t::const_iterator i = sections.begin();
               i != sections.end();
               ++i ) {
 
@@ -511,10 +511,11 @@
                 info_for_address( i->baseAddress()+j )->do_write();
         }
 
-        uintptr_t comm_addr = loader.get_symbol_addr( "soclib_iss_memchecker_addr" );
-        if ( comm_addr ) {
-            std::cout << "Binary file defined IssMemchecker communication address to " << comm_addr << std::endl;
-            m_comm_address = comm_addr;
+        const BinaryFileSymbol *sym = loader.get_symbol_by_name( "soclib_iss_memchecker_addr" );
+        if ( sym ) {
+            m_comm_address = sym->address();
+            std::cout << "Binary file defined IssMemchecker communication address to "
+                      << m_comm_address << std::endl;
         }
     }
 
@@ -585,9 +586,9 @@
         std::vector<AddressInfo> &r = *(i->second);
         if ( region_base <= address && word_no < r.size() )
             return &r[word_no];
-        std::cout << "Warning: address " << std::hex << address
-                  << " " << std::dec << (r.size()-word_no) << " words beyond "
-                  << r[r.size()-1] << std::endl;
+//         std::cout << "Warning: address " << std::hex << address
+//                   << " " << std::dec << (r.size()-word_no) << " words beyond "
+//                   << r[r.size()-1] << std::endl;
         return &m_default_address;
     }
 
@@ -623,9 +624,9 @@
             info_for_address(a)->region_set(nri);
     }
  
-    std::string get_symbol( uintptr_t addr ) const
+    BinaryFileSymbolOffset get_symbol( uintptr_t addr ) const
     {
-        return m_binary.get_symbol(addr);
+        return m_binary.get_symbol_by_addr(addr);
     }
 };
 
@@ -655,7 +656,7 @@
 
 template<typename iss_t>
 void IssMemchecker<iss_t>::init( const soclib::common::MappingTable &mt,
-                                 const soclib::common::ElfLoader &loader,
+                                 const soclib::common::BinaryFileLoader &loader,
                                  const std::string &exclusions )
 {
     s_memory_state = new MemoryState( mt, loader, exclusions );
Index: soclib/lib/elf_file_loader/metadata/elf_file_loader.sd
===================================================================
--- soclib/lib/elf_file_loader/metadata/elf_file_loader.sd	(revision 0)
+++ soclib/lib/elf_file_loader/metadata/elf_file_loader.sd	(revision 0)
@@ -0,0 +1,11 @@
+
+# -*- python -*-
+
+Module('common:elf_file_loader',
+	implementation_files = ['../src/elf_file_loader.cpp',
+							],
+	uses = [
+		Uses('common:exception'),
+		Uses('common:binary_file_loader'),
+		],
+)
Index: soclib/lib/elf_file_loader/src/elf_file_loader.cpp
===================================================================
--- soclib/lib/elf_file_loader/src/elf_file_loader.cpp	(revision 0)
+++ soclib/lib/elf_file_loader/src/elf_file_loader.cpp	(revision 0)
@@ -0,0 +1,204 @@
+/* -*- c++ -*-
+ *
+ * SOCLIB_LGPL_HEADER_BEGIN
+ * 
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ * 
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ * 
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ * 
+ * SOCLIB_LGPL_HEADER_END
+ *
+ * Copyright (c) UPMC, Lip6, SoC
+ *         Nicolas Pouillon <nipo@ssji.net>, 2009
+ */
+
+extern "C" {
+#include <bfd.h>
+
+/*
+To: "Robert Norton" <rnorton at broadcom dot com>
+Cc: binutils at sourceware dot org
+Subject: Re: BFD and Elf Symbol Size
+From: Ian Lance Taylor <iant at google dot com>
+Date: 19 Oct 2007 08:29:27 -0700
+In-Reply-To: <B0D822BFECD50F4991F2516EA50F273C030480A5 at NT-IRVA-0752 dot brcm dot ad dot broadcom dot com>
+Message-ID: <m33aw72kdk.fsf@localhost.localdomain>
+
+"Robert Norton" <rnorton@broadcom.com> writes:
+
+> Is there any way to get the size of an elf symbol via the BFD?
+
+In general I would have to recommend against using BFD as a general
+purpose library.
+
+That said, sure, you can do anything.  In this case,
+
+#include "elf-bfd.h"
+
+and then
+
+((elf_symbol_type *) symbol)->internal_elf_sym.st_size;
+
+Ian
+*/
+
+// Unfortunately, elf-bfd.h is not a distributed header, therefore
+// i'll copy here the only needed parts of the struct.
+
+struct elf_internal_sym {
+    bfd_vma	st_value;		/* Value of the symbol */
+    bfd_vma	st_size;		/* Associated symbol size */
+    // Other fields I skipped
+};
+
+typedef struct
+{
+    asymbol symbol;
+    struct elf_internal_sym internal_elf_sym;
+    // Other fields I skipped
+} elf_symbol_type;
+
+}
+
+#include <algorithm>
+#include <string.h>
+#include <sstream>
+#include <cassert>
+
+#include "exception.h"
+#include "static_init_code.h"
+#include "binary_file_loader.h"
+
+namespace soclib { namespace common { namespace {
+
+struct elf_state
+{
+    uintptr_t mask;
+	BinaryFileLoader *loader;
+};
+
+void add_section_cb(bfd *bfd, asection *sect, void *state_)
+{
+	struct elf_state *state = (struct elf_state*)state_;
+
+    if ( !(sect->flags & SEC_ALLOC) )
+        return;
+
+    bfd_byte *blob = 0;
+    if ( sect->flags & SEC_LOAD && sect->size ) {
+        int ret = bfd_malloc_and_get_section(bfd, sect, &blob);
+        if ( !ret || !blob )
+            throw soclib::exception::RunTimeError(
+                std::string("BFD failed: ") + bfd_errmsg(bfd_get_error()));
+    }
+
+    uint32_t flags = 0;
+    if ( sect->flags & SEC_LOAD ) flags |= BinaryFileSection::FLAG_LOAD;
+    if ( sect->flags & SEC_READONLY ) flags |= BinaryFileSection::FLAG_READONLY;
+    if ( sect->flags & SEC_CODE ) flags |= BinaryFileSection::FLAG_CODE;
+    if ( sect->flags & SEC_DATA ) flags |= BinaryFileSection::FLAG_DATA;
+
+    state->loader->addSection(
+		BinaryFileSection(
+			sect->name,
+			sect->vma & state->mask, sect->lma & state->mask,
+			flags,
+			sect->size, blob ));
+}
+
+void read_symbols(struct bfd *abfd, struct elf_state *state)
+{
+    long storage_needed;
+    asymbol **symbol_table;
+    long number_of_symbols;
+    long i;
+
+    storage_needed = bfd_get_symtab_upper_bound (abfd);
+
+    if (storage_needed <= 0)
+        return;
+
+    symbol_table = (asymbol**)malloc (storage_needed);
+    number_of_symbols =
+        bfd_canonicalize_symtab (abfd, symbol_table);
+
+    if (number_of_symbols < 0)
+        return;
+
+    for (i = 0; i < number_of_symbols; i++) {
+        asymbol *s = symbol_table[i];
+
+        size_t symsize = ((elf_symbol_type *) s)->internal_elf_sym.st_size;
+
+        if ( ! (s->flags & (BSF_FUNCTION|BSF_LOCAL|BSF_GLOBAL)) )
+            continue;
+
+        uintptr_t addr = ((s->section->lma & state->mask) + s->value);
+        state->loader->addSymbol(BinaryFileSymbol( s->name, addr, symsize ));
+    }
+    free(symbol_table);
+}
+
+bool elf_load( const std::string &filename, BinaryFileLoader &loader )
+{
+	static int s_refcount = 0;
+	if ( s_refcount == 0 )
+		bfd_init();
+	++s_refcount;
+
+	struct elf_state state;
+	state.loader = &loader;
+
+	struct bfd *a_bfd = bfd_openr(filename.c_str(), NULL);
+	if ( !(bool)a_bfd )
+		throw soclib::exception::RunTimeError(
+            std::string("Cant open binary image ")+filename);
+	
+	if ( !bfd_check_format(a_bfd, bfd_object)
+		 && !(a_bfd->flags & EXEC_P))
+		throw soclib::exception::RunTimeError(
+            std::string("Invalid ELF format in image ")+filename);
+
+    state.mask = (uintptr_t)-1;
+    if ( (size_t)bfd_get_arch_size(a_bfd) < sizeof(uintptr_t)*8 )
+        state.mask = ((uintptr_t)1<<bfd_get_arch_size(a_bfd))-1;
+
+	bfd_map_over_sections(a_bfd,
+                          &add_section_cb,
+                          &state);
+
+    read_symbols(a_bfd, &state);
+
+	if ( a_bfd )
+		bfd_close(a_bfd);
+
+	return true;
+}
+
+STATIC_INIT_CODE(
+	BinaryFileLoader::register_loader("elf", elf_load);
+)
+
+}}}
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+

Property changes on: soclib/lib/elf_file_loader/src/elf_file_loader.cpp
___________________________________________________________________
Name: svn:eol-style
   + native

Index: soclib/lib/elf_loader/metadata/elf_loader.sd
===================================================================
--- soclib/lib/elf_loader/metadata/elf_loader.sd	(revision 830)
+++ soclib/lib/elf_loader/metadata/elf_loader.sd	(working copy)
@@ -4,17 +4,16 @@
 Module('common:elf_loader',
 	classname = 'soclib::common::ElfLoader',
 	header_files = ['../include/elf_loader.h',],
-	implementation_files = ['../src/elf_loader.cpp',
-							'../src/elf_section.cpp',
-							],
 	   instance_parameters = [
 	parameter.String('binary', auto = 'env:binary'),
 	],
 	uses = [
-		Uses('common:exception'),
+		Uses('common:binary_file_loader'),
+		Uses('common:elf_file_loader'),
 		],
 	   extensions = [
 	'dsx:configurator',
 	'dsx:noname'
-	]
+	],
+	   deprecated = "Please use binary_file_loader now.",
 )
Index: soclib/lib/elf_loader/include/elf_loader.h
===================================================================
--- soclib/lib/elf_loader/include/elf_loader.h	(revision 830)
+++ soclib/lib/elf_loader/include/elf_loader.h	(working copy)
@@ -28,109 +28,13 @@
 #ifndef SOCLIB_ELF_LOADER_H_
 #define SOCLIB_ELF_LOADER_H_
 
-#include <string>
-#include <vector>
-#include <map>
-#include "stdint.h"
+#include "binary_file_loader.h"
 
 namespace soclib { namespace common {
 
-class ElfSectionData;
-class ElfLoader;
+typedef BinaryFileSymbol ElfSymbol;
+typedef BinaryFileLoader ElfLoader;
 
-class ElfSection
-{
-    friend class ElfLoader;
-
-    ElfSectionData *m_data;
-    uint32_t m_flags;
-    std::string m_name;
-    uintptr_t m_vma;
-    uintptr_t m_lma;
-    size_t m_size;
-
-public:
-    bool load_overlap_in_buffer( void *buffer,
-                                 uintptr_t buffer_base_address,
-                                 uintptr_t buffer_size ) const;
-    void get_data( void *buffer ) const;
-
-    bool has_data() const;
-
-    bool flag_load() const;
-    bool flag_read_only() const;
-    bool flag_code() const;
-    bool flag_data() const;
-    const std::string& name() const;
-    uintptr_t vma() const;
-    uintptr_t lma() const;
-    size_t size() const;
-
-    ElfSection( const ElfSection & );
-    ~ElfSection();
-    ElfSection &operator=( const ElfSection & );
-    ElfSection();
-
-    void print( std::ostream &o ) const;
-
-    friend std::ostream &operator<<( std::ostream &o, const ElfSection &s )
-    {
-        s.print(o);
-        return o;
-    }
-
-private:
-    ElfSection( const std::string &name,
-                uintptr_t vma, uintptr_t lma,
-                uint32_t flags,
-                size_t data_size, void *given_data_ptr );
-};
-
-class ElfLoader
-{
-	static int s_refcount;
-public:
-    typedef std::vector<ElfSection> section_list_t;
-
-private:
-	std::string m_filename;
-	void *m_bfd_ptr;
-    section_list_t m_sections;
-    uintptr_t m_mask;
-    std::map<uintptr_t, std::pair<size_t, std::string> > m_symbol_table;
-
-    void read_symbols();
-
-    static void add_section_cb( void *bfd, void *sect, void *thisptr );
-    void add_section( void *bfd, void *sect );
-
-public:
-    std::vector<ElfSection> sections() const;
-
-	ElfLoader( const ElfLoader &ref );
-	ElfLoader( const std::string &filename );
-	void load( void *buffer, uintptr_t address, size_t length );
-	~ElfLoader();
-
-    std::string arch() const;
-
-    void print( std::ostream &o ) const;
-
-    std::string get_symbol( uintptr_t addr ) const;
-    uintptr_t get_symbol_addr( const std::string & ) const;
-
-    inline const std::string & filename() const
-    {
-        return m_filename;
-    }
-
-    friend std::ostream &operator << (std::ostream &o, const ElfLoader &el)
-    {
-        el.print(o);
-        return o;
-    }
-};
-
 }}
 
 #endif /* SOCLIB_ELF_LOADER_H_ */
Index: soclib/lib/elf_loader/src/elf_loader.cpp
===================================================================
--- soclib/lib/elf_loader/src/elf_loader.cpp	(revision 830)
+++ soclib/lib/elf_loader/src/elf_loader.cpp	(working copy)
@@ -1,311 +0,0 @@
-/* -*- c++ -*-
- *
- * SOCLIB_LGPL_HEADER_BEGIN
- * 
- * This file is part of SoCLib, GNU LGPLv2.1.
- * 
- * SoCLib is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; version 2.1 of the License.
- * 
- * SoCLib is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with SoCLib; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- * 
- * SOCLIB_LGPL_HEADER_END
- *
- * Copyright (c) UPMC, Lip6, SoC
- *         Nicolas Pouillon <nipo@ssji.net>, 2007
- */
-
-extern "C" {
-#include <bfd.h>
-
-// To: "Robert Norton" <rnorton at broadcom dot com>
-// Cc: binutils at sourceware dot org
-// Subject: Re: BFD and Elf Symbol Size
-// From: Ian Lance Taylor <iant at google dot com>
-// Date: 19 Oct 2007 08:29:27 -0700
-// In-Reply-To: <B0D822BFECD50F4991F2516EA50F273C030480A5 at NT-IRVA-0752 dot brcm dot ad dot broadcom dot com>
-// Message-ID: <m33aw72kdk.fsf@localhost.localdomain>
-// 
-// "Robert Norton" <rnorton@broadcom.com> writes:
-// 
-// > Is there any way to get the size of an elf symbol via the BFD?
-// 
-// In general I would have to recommend against using BFD as a general
-// purpose library.
-// 
-// That said, sure, you can do anything.  In this case,
-// 
-// #include "elf-bfd.h"
-// 
-// and then
-// 
-// ((elf_symbol_type *) symbol)->internal_elf_sym.st_size;
-// 
-// Ian
-
-// Unfortunately, elf-bfd.h is not a distributed header, therefore
-// i'll copy here the only needed parts of the struct.
-
-struct elf_internal_sym {
-    bfd_vma	st_value;		/* Value of the symbol */
-    bfd_vma	st_size;		/* Associated symbol size */
-    // Other fields I skipped
-};
-
-typedef struct
-{
-    asymbol symbol;
-    struct elf_internal_sym internal_elf_sym;
-    // Other fields I skipped
-} elf_symbol_type;
-
-}
-
-#include <algorithm>
-#include <string.h>
-#include <sstream>
-#include <cassert>
-
-#include "exception.h"
-#include "elf_loader.h"
-
-namespace soclib { namespace common {
-
-int ElfLoader::s_refcount = 0;
-
-void ElfLoader::add_section_cb(void *bfd, void *_sect, void *thisptr)
-{
-    static_cast<ElfLoader*>(thisptr)->add_section(bfd, _sect);
-}
-
-void ElfLoader::add_section(void *_bfd, void *_sect)
-{
-    bfd *a_bfd = (bfd*)_bfd;
-    asection *sect = (asection*)_sect;
-
-    if ( !(sect->flags & SEC_ALLOC) )
-        return;
-
-    bfd_byte *blob = 0;
-    if ( sect->flags & SEC_LOAD && sect->size ) {
-        int ret = bfd_malloc_and_get_section(a_bfd, sect, &blob);
-        if ( !ret || !blob )
-            throw soclib::exception::RunTimeError(
-                std::string("BFD failed: ") + bfd_errmsg(bfd_get_error()));
-    }
-
-    m_sections.push_back(ElfSection(
-                             sect->name,
-                             sect->vma & m_mask, sect->lma & m_mask,
-                             sect->flags,
-                             sect->size, blob ));
-}
-
-void ElfLoader::read_symbols()
-{
-    struct bfd *abfd = (struct bfd*)m_bfd_ptr;
-    long storage_needed;
-    asymbol **symbol_table;
-    long number_of_symbols;
-    long i;
-
-    storage_needed = bfd_get_symtab_upper_bound (abfd);
-
-    if (storage_needed <= 0)
-        return;
-
-    symbol_table = (asymbol**)malloc (storage_needed);
-    number_of_symbols =
-        bfd_canonicalize_symtab (abfd, symbol_table);
-
-    if (number_of_symbols < 0)
-        return;
-
-    for (i = 0; i < number_of_symbols; i++) {
-        asymbol *s = symbol_table[i];
-
-        size_t symsize = ((elf_symbol_type *) s)->internal_elf_sym.st_size;
-
-        if ( ! (s->flags & (BSF_FUNCTION|BSF_LOCAL|BSF_GLOBAL)) )
-            continue;
-
-        uintptr_t addr = ((s->section->lma & m_mask) + s->value);
-        m_symbol_table[addr] = std::pair<size_t, std::string>(symsize, std::string(s->name));
-    }
-    free(symbol_table);
-}
-
-ElfLoader::ElfLoader( const std::string &filename )
-	: m_filename(filename)
-{
-	if ( s_refcount == 0 )
-		bfd_init();
-	++s_refcount;
-
-	struct bfd *a_bfd = bfd_openr(m_filename.c_str(), NULL);
-	if ( !(bool)a_bfd )
-		throw soclib::exception::RunTimeError(
-            std::string("Cant open binary image ")+m_filename);
-	
-	if ( !bfd_check_format(a_bfd, bfd_object)
-		 && !(a_bfd->flags & EXEC_P))
-		throw soclib::exception::RunTimeError(
-            std::string("Invalid ELF format in image ")+m_filename);
-	m_bfd_ptr = (void*)a_bfd;
-
-    m_mask = (uintptr_t)-1;
-    if ( (size_t)bfd_get_arch_size(a_bfd) < sizeof(uintptr_t)*8 )
-        m_mask = ((uintptr_t)1<<bfd_get_arch_size(a_bfd))-1;
-
-    m_sections.reserve(a_bfd->section_count);
-
-	bfd_map_over_sections(a_bfd,
-                          (void(*)(bfd*, asection*, void*))
-                          &ElfLoader::add_section_cb,
-                          this);
-
-    read_symbols();
-}
-
-ElfLoader::ElfLoader( const ElfLoader &ref )
-	: m_filename(ref.m_filename),
-      m_sections(ref.m_sections),
-      m_mask(ref.m_mask),
-      m_symbol_table(ref.m_symbol_table)
-{
-	if ( s_refcount == 0 )
-		bfd_init();
-	++s_refcount;
-
-	struct bfd *a_bfd = bfd_openr(m_filename.c_str(), NULL);
-	if ( !(bool)a_bfd )
-		throw soclib::exception::RunTimeError(
-            std::string("Cant open binary image ")+m_filename);
-	
-	if ( !bfd_check_format(a_bfd, bfd_object)
-		 && !(a_bfd->flags & EXEC_P))
-		throw soclib::exception::RunTimeError(
-            std::string("Invalid ELF format in image ")+m_filename);
-	m_bfd_ptr = (void*)a_bfd;
-}
-
-void ElfLoader::load( void *buffer, uintptr_t address, size_t length )
-{
-    std::cout
-        << std::showbase << std::hex
-        << "Loading at " << address
-        << " size " << std::dec << length
-        << ": ";
-    bool one = false;
-    for ( section_list_t::const_iterator i = m_sections.begin();
-          i != m_sections.end();
-          ++i ) {
-        if ( i->load_overlap_in_buffer( buffer, address, length ) ) {
-            one = true;
-            std::cout << i->name() << " ";
-        }
-    }
-    if ( !one )
-        std::cout << "nothing";
-    std::cout << std::endl;
-}
-
-void ElfLoader::print( std::ostream &o ) const
-{
-    struct bfd* a_bfd = (struct bfd*)m_bfd_ptr;
-	o << "<ElfLoader " << m_filename << std::endl
-      << " target: " << arch() << std::endl
-      << " endianness: " << a_bfd->xvec->byteorder << std::endl;
-    for ( section_list_t::const_iterator i = m_sections.begin();
-          i != m_sections.end();
-          ++i )
-        o << " " << *i << std::endl;
-    o << ">" << std::endl;
-}
-
-std::string ElfLoader::arch() const
-{
-    struct bfd *a_bfd = (struct bfd*)m_bfd_ptr;
-    enum bfd_architecture arch = bfd_get_arch (a_bfd);
-    std::cout << "Arch " << (int)arch << std::endl;
-    switch(arch) {
-    case bfd_arch_mips:
-        return "mipsel";
-    case bfd_arch_powerpc:
-        return "powerpc";
-    default:
-        return "unknown";
-    }
-}
-
-ElfLoader::~ElfLoader()
-{
-    struct bfd* a_bfd = (struct bfd*)m_bfd_ptr;
-	if ( a_bfd )
-		bfd_close(a_bfd);
-
-// 	if ( --s_refcount == 0 )
-// 		bfd_fini();
-}
-
-std::vector<ElfSection> ElfLoader::sections() const
-{
-    return m_sections;
-}
-
-std::string ElfLoader::get_symbol( uintptr_t addr ) const
-{
-    addr &= m_mask;
-    std::map<uintptr_t, std::pair<size_t, std::string> >::const_iterator i =
-        m_symbol_table.lower_bound( addr );
-
-    if ( i != m_symbol_table.end()
-         && i != m_symbol_table.begin()
-         && i->first > addr )
-        --i;
-
-    std::ostringstream o;
-    o << "[@" << std::showbase << std::hex
-      << addr << ": ";
-    if ( i == m_symbol_table.end() || ( i->second.first != 0 && i->first+i->second.first <= addr ) ) {
-        o << "<unknown>";
-    } else {
-        ptrdiff_t d = addr - i->first;
-        o << '(' << i->second.second << " + " << d << ')';
-    }
-    o << "]";
-    return o.str();
-}
-
-uintptr_t ElfLoader::get_symbol_addr( const std::string &sym ) const
-{
-    std::map<uintptr_t, std::pair<size_t, std::string> >::const_iterator i;
-    for ( i = m_symbol_table.begin();
-          i != m_symbol_table.end();
-          ++i ) {
-        if ( i->second.second == sym )
-            return i->first;
-    }
-    return 0;
-}
-
-}}
-
-// Local Variables:
-// tab-width: 4
-// c-basic-offset: 4
-// c-file-offsets:((innamespace . 0)(inline-open . 0))
-// indent-tabs-mode: nil
-// End:
-
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
-
Index: soclib/lib/binary_file_loader/metadata/binary_file_section.sd
===================================================================
--- soclib/lib/binary_file_loader/metadata/binary_file_section.sd	(revision 0)
+++ soclib/lib/binary_file_loader/metadata/binary_file_section.sd	(revision 0)
@@ -0,0 +1,9 @@
+
+# -*- python -*-
+
+Module('common:binary_file_section',
+	classname = 'soclib::common::BinaryFileSection',
+	header_files = ['../include/binary_file_section.h',],
+	implementation_files = ['../src/binary_file_section.cpp',
+							],
+)
Index: soclib/lib/binary_file_loader/metadata/binary_file_symbol.sd
===================================================================
--- soclib/lib/binary_file_loader/metadata/binary_file_symbol.sd	(revision 0)
+++ soclib/lib/binary_file_loader/metadata/binary_file_symbol.sd	(revision 0)
@@ -0,0 +1,9 @@
+
+# -*- python -*-
+
+Module('common:binary_file_symbol',
+	classname = 'soclib::common::BinaryFileSymbol',
+	header_files = ['../include/binary_file_symbol.h',],
+	implementation_files = ['../src/binary_file_symbol.cpp',
+							],
+)
Index: soclib/lib/binary_file_loader/metadata/binary_file_loader.sd
===================================================================
--- soclib/lib/binary_file_loader/metadata/binary_file_loader.sd	(revision 0)
+++ soclib/lib/binary_file_loader/metadata/binary_file_loader.sd	(revision 0)
@@ -0,0 +1,21 @@
+
+# -*- python -*-
+
+Module('common:binary_file_loader',
+	classname = 'soclib::common::BinaryFileLoader',
+	header_files = ['../include/binary_file_loader.h',],
+	implementation_files = ['../src/binary_file_loader.cpp',
+							],
+	   instance_parameters = [
+	parameter.String('binary', auto = 'env:binary'),
+	],
+	uses = [
+		Uses('common:exception'),
+		Uses('common:binary_file_section'),
+		Uses('common:binary_file_symbol'),
+		],
+	   extensions = [
+	'dsx:configurator',
+	'dsx:noname'
+	]
+)
Index: soclib/lib/binary_file_loader/include/binary_file_loader.h
===================================================================
--- soclib/lib/binary_file_loader/include/binary_file_loader.h	(revision 0)
+++ soclib/lib/binary_file_loader/include/binary_file_loader.h	(revision 0)
@@ -0,0 +1,95 @@
+/* -*- c++ -*-
+ *
+ * SOCLIB_LGPL_HEADER_BEGIN
+ * 
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ * 
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ * 
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ * 
+ * SOCLIB_LGPL_HEADER_END
+ *
+ * Copyright (c) UPMC, Lip6, SoC
+ *         Nicolas Pouillon <nipo@ssji.net>, 2009
+ *
+ * Maintainers: nipo
+ */
+#ifndef SOCLIB_BINARY_LOADER_H_
+#define SOCLIB_BINARY_LOADER_H_
+
+#include <string>
+#include <vector>
+#include <map>
+#include "stdint.h"
+
+#include "binary_file_symbol.h"
+#include "binary_file_section.h"
+
+namespace soclib { namespace common {
+
+class BinaryFileLoader
+{
+public:
+    typedef std::vector<BinaryFileSection> section_list_t;
+	typedef bool (*binary_loader_t)( const std::string &desc_str, BinaryFileLoader &loader );
+
+private:
+	typedef std::map<std::string, binary_loader_t> loader_registry_t;
+
+    section_list_t m_sections;
+    uintptr_t m_mask;
+    std::map<uintptr_t, BinaryFileSymbol> m_symbol_table;
+
+	void load_file(const std::string &desc_str);
+
+	static loader_registry_t &registry();
+public:
+	static void register_loader( const std::string &name,
+								 binary_loader_t loader );
+
+    section_list_t sections() const;
+
+	void addSection( const BinaryFileSection &section );
+	void addSymbol( const BinaryFileSymbol &symbol );
+
+	BinaryFileLoader( const BinaryFileLoader &ref );
+	BinaryFileLoader( const std::string &filename );
+	void load( void *buffer, uintptr_t address, size_t length );
+	~BinaryFileLoader();
+
+    void print( std::ostream &o ) const;
+
+    BinaryFileSymbolOffset get_symbol_by_addr( uintptr_t addr ) const;
+    const BinaryFileSymbol *get_symbol_by_name( const std::string & ) const;
+
+    friend std::ostream &operator << (std::ostream &o, const BinaryFileLoader &el)
+    {
+        el.print(o);
+        return o;
+    }
+};
+
+}}
+
+#endif /* SOCLIB_BINARY_LOADER_H_ */
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+

Property changes on: soclib/lib/binary_file_loader/include/binary_file_loader.h
___________________________________________________________________
Name: svn:eol-style
   + native

Index: soclib/lib/binary_file_loader/include/binary_file_section.h
===================================================================
--- soclib/lib/binary_file_loader/include/binary_file_section.h	(revision 0)
+++ soclib/lib/binary_file_loader/include/binary_file_section.h	(revision 0)
@@ -0,0 +1,109 @@
+/* -*- c++ -*-
+ *
+ * SOCLIB_LGPL_HEADER_BEGIN
+ * 
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ * 
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ * 
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ * 
+ * SOCLIB_LGPL_HEADER_END
+ *
+ * Copyright (c) UPMC, Lip6, SoC
+ *         Nicolas Pouillon <nipo@ssji.net>, 2007
+ *
+ * Maintainers: nipo
+ */
+#ifndef SOCLIB_BINARY_FILE_SECTION_H_
+#define SOCLIB_BINARY_FILE_SECTION_H_
+
+#include <string>
+#include <ios>
+
+#include "stdint.h"
+
+#include "binary_file_section.h"
+
+namespace soclib { namespace common {
+
+class BinarySectionData;
+class BinaryFileLoader;
+
+class BinaryFileSection
+{
+    friend class BinaryFileLoader;
+
+    BinarySectionData *m_data;
+    uint32_t m_flags;
+    std::string m_name;
+    uintptr_t m_vma;
+    uintptr_t m_lma;
+    size_t m_size;
+
+public:
+	enum flags {
+		FLAG_LOAD = 1,
+		FLAG_DATA = 2,
+		FLAG_READONLY = 4,
+		FLAG_CODE = 8,
+	};
+
+    bool load_overlap_in_buffer( void *buffer,
+                                 uintptr_t buffer_base_address,
+                                 uintptr_t buffer_size ) const;
+    void get_data( void *buffer ) const;
+
+    bool has_data() const;
+
+    bool flag_load() const;
+    bool flag_read_only() const;
+    bool flag_code() const;
+    bool flag_data() const;
+    const std::string& name() const;
+    uintptr_t vma() const;
+    uintptr_t lma() const;
+    size_t size() const;
+
+    BinaryFileSection( const BinaryFileSection & );
+    ~BinaryFileSection();
+    BinaryFileSection &operator=( const BinaryFileSection & );
+    BinaryFileSection();
+
+    void print( std::ostream &o ) const;
+
+    friend std::ostream &operator<<( std::ostream &o, const BinaryFileSection &s )
+    {
+        s.print(o);
+        return o;
+    }
+
+    BinaryFileSection( const std::string &name,
+				   uintptr_t vma, uintptr_t lma,
+				   uint32_t flags,
+				   size_t data_size, void *given_data_ptr );
+};
+
+}}
+
+#endif /* SOCLIB_BINARY_FILE_SECTION_H_ */
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+

Property changes on: soclib/lib/binary_file_loader/include/binary_file_section.h
___________________________________________________________________
Name: svn:eol-style
   + native

Index: soclib/lib/binary_file_loader/include/binary_file_symbol.h
===================================================================
--- soclib/lib/binary_file_loader/include/binary_file_symbol.h	(revision 0)
+++ soclib/lib/binary_file_loader/include/binary_file_symbol.h	(revision 0)
@@ -0,0 +1,100 @@
+/* -*- c++ -*-
+ *
+ * SOCLIB_LGPL_HEADER_BEGIN
+ * 
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ * 
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ * 
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ * 
+ * SOCLIB_LGPL_HEADER_END
+ *
+ * Copyright (c) UPMC, Lip6, SoC
+ *         Nicolas Pouillon <nipo@ssji.net>, 2009
+ *
+ * Maintainers: nipo
+ */
+#ifndef SOCLIB_BINARY_FILE_SYMBOL_H_
+#define SOCLIB_BINARY_FILE_SYMBOL_H_
+
+#include <string>
+#include "stdint.h"
+#include <ios>
+
+namespace soclib { namespace common {
+
+class BinaryFileSymbol
+{
+    std::string m_name;
+    uintptr_t m_address;
+    size_t m_size;
+public:
+    const std::string &name() const
+    {
+        return m_name;
+    }
+
+    const uintptr_t address() const
+    {
+        return m_address;
+    }
+
+    const size_t size() const
+    {
+        return m_size;
+    }
+
+    BinaryFileSymbol( const std::string &name, uintptr_t address, size_t size );
+
+    BinaryFileSymbol( const BinaryFileSymbol &ref );
+
+    BinaryFileSymbol();
+
+    const BinaryFileSymbol& operator=( const BinaryFileSymbol &ref );
+
+    bool contains( uintptr_t addr ) const;
+};
+
+class BinaryFileSymbolOffset
+{
+    const BinaryFileSymbol m_sym;
+    const ptrdiff_t m_addr;
+
+public:
+    BinaryFileSymbolOffset( const BinaryFileSymbol sym, const ptrdiff_t addr );
+
+    BinaryFileSymbolOffset( const BinaryFileSymbolOffset &ref );
+
+    void print( std::ostream &o ) const;
+    
+    friend std::ostream & operator<<( std::ostream &o, const BinaryFileSymbolOffset &so )
+    {
+        so.print(o);
+        return o;
+    }
+};
+
+}}
+
+#endif /* SOCLIB_BINARY_LOADER_H_ */
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+

Property changes on: soclib/lib/binary_file_loader/include/binary_file_symbol.h
___________________________________________________________________
Name: svn:eol-style
   + native

Index: soclib/lib/binary_file_loader/src/binary_file_section.cpp
===================================================================
--- soclib/lib/binary_file_loader/src/binary_file_section.cpp	(revision 0)
+++ soclib/lib/binary_file_loader/src/binary_file_section.cpp	(revision 0)
@@ -0,0 +1,304 @@
+/* -*- c++ -*-
+ *
+ * SOCLIB_LGPL_HEADER_BEGIN
+ * 
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ * 
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ * 
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ * 
+ * SOCLIB_LGPL_HEADER_END
+ *
+ * Copyright (c) UPMC, Lip6, SoC
+ *         Nicolas Pouillon <nipo@ssji.net>, 2009
+ */
+
+#include <algorithm>
+#include <string.h>
+#include <cassert>
+
+#include <iostream>
+
+#include "binary_file_section.h"
+
+namespace soclib { namespace common {
+
+class BinarySectionData
+{
+    uint32_t m_refcount;
+    size_t m_size;
+    void *m_data;
+public:
+    BinarySectionData( size_t size, void *data )
+        : m_refcount(0),
+          m_size(size),
+          m_data(data)
+    {}
+
+    ~BinarySectionData()
+    {
+        free(m_data);
+    }
+
+    void *data() const
+    {
+        return m_data;
+    }
+
+    size_t size() const
+    {
+        return m_size;
+    }
+
+    void ref()
+    {
+        m_refcount++;
+    }
+
+    void check() const
+    {
+        assert(m_refcount);
+    }
+
+    void unref()
+    {
+        if ( --m_refcount == 0 )
+            delete this;
+    }
+
+    void print( std::ostream &o ) const
+    {
+        o << "<BinarySectionData " << std::dec
+          << m_size << " bytes"
+          << ", refcount=" << m_refcount
+          << ">";
+    }
+
+    friend std::ostream &operator << (std::ostream &o, const BinarySectionData &d)
+    {
+        d.print(o);
+        return o;
+    }
+
+};
+
+const std::string & BinaryFileSection::name() const
+{
+	return m_name;
+}
+
+uintptr_t BinaryFileSection::vma() const
+{
+	return m_vma;
+}
+
+uintptr_t BinaryFileSection::lma() const
+{
+	return m_lma;
+}
+
+size_t BinaryFileSection::size() const
+{
+    return m_size;
+}
+
+bool BinaryFileSection::has_data() const
+{
+    return m_data;
+}
+
+bool BinaryFileSection::flag_load() const
+{
+    return m_flags & FLAG_LOAD;
+}
+
+bool BinaryFileSection::flag_read_only() const
+{
+    return m_flags & FLAG_READONLY;
+}
+
+bool BinaryFileSection::flag_code() const
+{
+    return m_flags & FLAG_CODE;
+}
+
+bool BinaryFileSection::flag_data() const
+{
+    return m_flags & FLAG_DATA;
+}
+
+BinaryFileSection::BinaryFileSection( const std::string &name,
+                        uintptr_t vma, uintptr_t lma,
+                        uint32_t flags, size_t size,
+						void *blob )
+    : m_data( blob ? new BinarySectionData( size, blob ) : 0 ),
+      m_flags(flags),
+      m_name(name),
+      m_vma(vma),
+      m_lma(lma),
+      m_size(size)
+{
+	if ( m_data )
+		m_data->ref();
+    if ( m_data )
+        m_data->check();
+
+//    std::cout << "New BinaryFileSection " << *this << std::endl;
+}
+
+bool BinaryFileSection::load_overlap_in_buffer( 
+    void *buffer,
+    uintptr_t buffer_base_address,
+    size_t buffer_size ) const
+{
+	if ( !m_data )
+		return false;
+
+    void *src, *dst;
+    size_t copy_size;
+    if ( buffer_base_address < m_lma ) {
+        size_t dest_buffer_offset = m_lma - buffer_base_address;
+
+        dst = (void*)((uintptr_t)buffer + dest_buffer_offset);
+        src = m_data->data();
+        if ( dest_buffer_offset > buffer_size )
+            copy_size = 0;
+        else
+            copy_size = buffer_size - dest_buffer_offset;
+        if ( copy_size > m_data->size() )
+            copy_size = m_data->size();
+    } else {
+        size_t src_data_offset = buffer_base_address - m_lma;
+
+        dst = buffer;
+        src = (void*)((uintptr_t)m_data->data() + src_data_offset);
+        if ( src_data_offset > m_data->size() )
+            copy_size = 0;
+        else
+            copy_size = m_data->size() - src_data_offset;
+        if ( copy_size > buffer_size )
+            copy_size = buffer_size;
+    }
+    if ( copy_size == 0 )
+        return false;
+    if ( m_data )
+        m_data->check();
+    memcpy( dst, src, copy_size );
+	return true;
+}
+
+void BinaryFileSection::print( std::ostream &o ) const
+{
+	o << "<Section "
+	  << std::showbase << m_name
+	  << ", vma: " << std::hex << m_vma
+	  << ", lma: " << std::hex << m_lma
+	  << ", size: " << std::dec << m_size << " bytes";
+	if ( m_data ) {
+        m_data->check();
+		o << ", " << *m_data;
+	} else {
+		o << ", no data";
+	}
+	o << ", flags: ";
+	if ( flag_load() )
+		o << "L,";
+	if ( flag_read_only() )
+		o << "RO,";
+	if ( flag_code() )
+		o << "C";
+	if ( flag_data() )
+		o << "D";
+	o << ">";
+}
+
+void BinaryFileSection::get_data( void *buffer ) const
+{
+	if ( !m_data )
+		return;
+    m_data->check();
+    memcpy( buffer, m_data->data(), m_data->size() );
+}
+
+BinaryFileSection::~BinaryFileSection()
+{
+//    std::cout << "Deleted BinaryFileSection " << *this << std::endl;
+    if ( m_data )
+        m_data->check();
+    if ( m_data )
+        m_data->unref();
+}
+
+BinaryFileSection::BinaryFileSection( const BinaryFileSection &ref )
+    : m_data(0),
+      m_flags(0),
+      m_name("To be copied"),
+      m_vma(0),
+      m_lma(0),
+      m_size(0)
+{
+//    std::cout << "New BinaryFileSection " << *this << " copied from " << ref << std::endl;
+    (*this) = ref;
+}
+
+BinaryFileSection::BinaryFileSection()
+    : m_data(0),
+      m_flags(0),
+      m_name("Empty section"),
+      m_vma(0),
+      m_lma(0),
+      m_size(0)
+{
+//    std::cout << "New empty BinaryFileSection " << *this << std::endl;
+}
+
+BinaryFileSection & BinaryFileSection::operator=( const BinaryFileSection &ref )
+{
+    if ( &ref == this )
+        return *this;
+
+//    std::cout << "Copying " << ref << " to " << *this << std::endl;
+
+    if ( m_data ) {
+        m_data->check();
+        m_data->unref();
+    }
+	if ( ref.m_data ) {
+		m_data = ref.m_data;
+		m_data->ref();
+        m_data->check();
+	} else {
+        m_data = 0;
+    }
+    m_flags = ref.m_flags;
+    m_name = ref.m_name;
+    m_vma = ref.m_vma;
+    m_lma = ref.m_lma;
+    m_size = ref.m_size;
+
+	return *this;
+}
+
+
+}}
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+

Property changes on: soclib/lib/binary_file_loader/src/binary_file_section.cpp
___________________________________________________________________
Name: svn:eol-style
   + native

Index: soclib/lib/binary_file_loader/src/binary_file_symbol.cpp
===================================================================
--- soclib/lib/binary_file_loader/src/binary_file_symbol.cpp	(revision 0)
+++ soclib/lib/binary_file_loader/src/binary_file_symbol.cpp	(revision 0)
@@ -0,0 +1,103 @@
+/* -*- c++ -*-
+ *
+ * SOCLIB_LGPL_HEADER_BEGIN
+ * 
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ * 
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ * 
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ * 
+ * SOCLIB_LGPL_HEADER_END
+ *
+ * Copyright (c) UPMC, Lip6, SoC
+ *         Nicolas Pouillon <nipo@ssji.net>, 2009
+ */
+
+#include <algorithm>
+#include <string.h>
+#include <cassert>
+
+#include <iostream>
+#include <iomanip>
+
+#include "binary_file_symbol.h"
+
+namespace soclib { namespace common {
+
+BinaryFileSymbol::BinaryFileSymbol( const std::string &name, uintptr_t address, size_t size )
+	: m_name(name),
+	  m_address(address),
+	  m_size(size)
+{}
+
+BinaryFileSymbol::BinaryFileSymbol( const BinaryFileSymbol &ref )
+    : m_name(ref.m_name),
+      m_address(ref.m_address),
+      m_size(ref.m_size)
+{}
+
+BinaryFileSymbol::BinaryFileSymbol()
+    : m_name("Unknown"),
+      m_address(0),
+      m_size(0)
+{}
+
+const BinaryFileSymbol& BinaryFileSymbol::operator=( const BinaryFileSymbol &ref )
+{
+    m_name = ref.m_name;
+    m_address = ref.m_address;
+    m_size = ref.m_size;
+    return *this;
+}
+
+bool BinaryFileSymbol::contains( uintptr_t addr ) const
+{
+    return addr >= m_address && addr < m_address+m_size;
+}
+
+BinaryFileSymbolOffset::BinaryFileSymbolOffset( const BinaryFileSymbol sym, const ptrdiff_t addr )
+    : m_sym(sym),
+      m_addr(addr)
+{
+}
+
+BinaryFileSymbolOffset::BinaryFileSymbolOffset( const BinaryFileSymbolOffset &ref )
+    : m_sym(ref.m_sym),
+      m_addr(ref.m_addr)
+{
+}
+
+void BinaryFileSymbolOffset::print( std::ostream &o ) const
+{
+    o << "[@" << std::showbase << std::hex
+      << m_addr << ": ";
+    ptrdiff_t d = m_addr - m_sym.address();
+    if ( d < m_sym.size() )
+        o << '(' << m_sym.name() << " + " << d << ')';
+    else
+        o << '(' << m_sym.name() << ", " << d-m_sym.size() << " bytes above)";
+    o << "]";
+}
+
+}}
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+

Property changes on: soclib/lib/binary_file_loader/src/binary_file_symbol.cpp
___________________________________________________________________
Name: svn:eol-style
   + native

Index: soclib/lib/binary_file_loader/src/binary_file_loader.cpp
===================================================================
--- soclib/lib/binary_file_loader/src/binary_file_loader.cpp	(revision 0)
+++ soclib/lib/binary_file_loader/src/binary_file_loader.cpp	(revision 0)
@@ -0,0 +1,169 @@
+/* -*- c++ -*-
+ *
+ * SOCLIB_LGPL_HEADER_BEGIN
+ * 
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ * 
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ * 
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ * 
+ * SOCLIB_LGPL_HEADER_END
+ *
+ * Copyright (c) UPMC, Lip6, SoC
+ *         Nicolas Pouillon <nipo@ssji.net>, 2009
+ */
+
+#include <algorithm>
+#include <string.h>
+#include <sstream>
+#include <cassert>
+
+#include "exception.h"
+#include "binary_file_loader.h"
+
+namespace soclib { namespace common {
+
+BinaryFileLoader::BinaryFileLoader( const std::string &filename )
+{
+	load_file(filename);
+}
+
+BinaryFileLoader::BinaryFileLoader( const BinaryFileLoader &ref )
+	: m_sections(ref.m_sections),
+      m_symbol_table(ref.m_symbol_table)
+{
+}
+
+void BinaryFileLoader::load( void *buffer, uintptr_t address, size_t length )
+{
+    std::cout
+        << std::showbase << std::hex
+        << "Loading at " << address
+        << " size " << std::dec << length
+        << ": ";
+    bool one = false;
+    for ( section_list_t::const_iterator i = m_sections.begin();
+          i != m_sections.end();
+          ++i ) {
+        if ( i->load_overlap_in_buffer( buffer, address, length ) ) {
+            one = true;
+            std::cout << i->name() << " ";
+        }
+    }
+    if ( !one )
+        std::cout << "nothing";
+    std::cout << std::endl;
+}
+
+void BinaryFileLoader::print( std::ostream &o ) const
+{
+	o << "<BinaryFileLoader " << std::endl;
+    for ( section_list_t::const_iterator i = m_sections.begin();
+          i != m_sections.end();
+          ++i )
+        o << " " << *i << std::endl;
+    o << ">" << std::endl;
+}
+
+BinaryFileLoader::~BinaryFileLoader()
+{
+}
+
+std::vector<BinaryFileSection> BinaryFileLoader::sections() const
+{
+    return m_sections;
+}
+
+BinaryFileSymbolOffset BinaryFileLoader::get_symbol_by_addr( uintptr_t addr ) const
+{
+    addr &= m_mask;
+    std::map<uintptr_t, BinaryFileSymbol>::const_iterator i =
+        m_symbol_table.lower_bound( addr );
+
+    while ( i != m_symbol_table.end()
+         && i != m_symbol_table.begin()
+         && i->first > addr )
+        --i;
+
+    if ( i->second.contains(addr) || i->second.size() == 0 )
+        return BinaryFileSymbolOffset(i->second, addr);
+    return BinaryFileSymbolOffset(BinaryFileSymbol("Unknown", addr, 1), addr);
+}
+
+const BinaryFileSymbol *BinaryFileLoader::get_symbol_by_name( const std::string &sym ) const
+{
+    std::map<uintptr_t, BinaryFileSymbol>::const_iterator i;
+    for ( i = m_symbol_table.begin();
+          i != m_symbol_table.end();
+          ++i ) {
+        if ( i->second.name() == sym )
+            return &(i->second);
+    }
+    return NULL;
+}
+
+BinaryFileLoader::loader_registry_t &
+BinaryFileLoader::registry()
+{
+	static loader_registry_t reg;
+	return reg;
+}
+
+void BinaryFileLoader::register_loader( const std::string &name,
+										binary_loader_t loader )
+{
+	loader_registry_t &reg = registry();
+
+	reg[name] = loader;
+}
+
+void BinaryFileLoader::load_file( const std::string &desc_str )
+{
+	loader_registry_t &reg = registry();
+	std::string tried;
+	for ( loader_registry_t::iterator i = reg.begin();
+		  i != reg.end();
+		  i++ ) {
+		if ( tried.size() )
+			tried += ", ";
+		tried += i->first;
+		if ( (i->second)( desc_str, *this ) )
+			return;
+	}
+	throw exception::RunTimeError(
+		std::string("Found no method able to load file ") +
+		desc_str + " even if tried: " + tried);
+}
+
+void BinaryFileLoader::addSection( const BinaryFileSection &section )
+{
+	m_sections.push_back(section);
+}
+
+void BinaryFileLoader::addSymbol( const BinaryFileSymbol &symbol )
+{
+	m_symbol_table[symbol.address()] = symbol;
+}
+
+}}
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+

Property changes on: soclib/lib/binary_file_loader/src/binary_file_loader.cpp
___________________________________________________________________
Name: svn:eol-style
   + native

