[rtems-tools commit] rtemstoolkit: Add an address table of symbols key by the symbol address.

Chris Johns chrisj at rtems.org
Sun Apr 3 05:44:02 UTC 2016


Module:    rtems-tools
Branch:    master
Commit:    2e973519a4e71a6a41b3a11e4ea1d3b94476ebb3
Changeset: http://git.rtems.org/rtems-tools/commit/?id=2e973519a4e71a6a41b3a11e4ea1d3b94476ebb3

Author:    Chris Johns <chrisj at rtems.org>
Date:      Sun Apr  3 15:38:14 2016 +1000

rtemstoolkit: Add an address table of symbols key by the symbol address.

This is useful if you need to look up a symbol based on its address.

---

 rtemstoolkit/rld-symbols.cpp | 36 ++++++++++++++++++++++++++++++++++++
 rtemstoolkit/rld-symbols.h   | 26 ++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/rtemstoolkit/rld-symbols.cpp b/rtemstoolkit/rld-symbols.cpp
index 081d3e1..92803d8 100644
--- a/rtemstoolkit/rld-symbols.cpp
+++ b/rtemstoolkit/rld-symbols.cpp
@@ -362,6 +362,42 @@ namespace rld
     }
 
     void
+    table::globals (addrtab& addresses)
+    {
+      for (symtab::iterator gi = globals_.begin ();
+           gi != globals_.end ();
+           ++gi)
+      {
+        symbol& sym = *((*gi).second);
+        addresses[sym.value ()] = (*gi).second;
+      }
+    }
+
+    void
+    table::weaks (addrtab& addresses)
+    {
+      for (symtab::iterator wi = weaks_.begin ();
+           wi != weaks_.end ();
+           ++wi)
+      {
+        symbol& sym = *((*wi).second);
+        addresses[sym.value ()] = (*wi).second;
+      }
+    }
+
+    void
+    table::locals (addrtab& addresses)
+    {
+      for (symtab::iterator li = locals_.begin ();
+           li != locals_.end ();
+           ++li)
+      {
+        symbol& sym = *((*li).second);
+        addresses[sym.value ()] = (*li).second;
+      }
+    }
+
+    void
     load (bucket& bucket_, table& table_)
     {
       for (bucket::iterator sbi = bucket_.begin ();
diff --git a/rtemstoolkit/rld-symbols.h b/rtemstoolkit/rld-symbols.h
index 02a41a3..c8a61f4 100644
--- a/rtemstoolkit/rld-symbols.h
+++ b/rtemstoolkit/rld-symbols.h
@@ -45,6 +45,11 @@ namespace rld
   namespace symbols
   {
     /**
+     * Use a local type for the address.
+     */
+    typedef elf::elf_addr address;
+
+    /**
      * A symbol.
      */
     class symbol
@@ -205,6 +210,12 @@ namespace rld
     typedef std::map < std::string, symbol* > symtab;
 
     /**
+     * An address table is a map container of symbols based on address. Should
+     * always point to symbols held in a bucket.
+     */
+    typedef std::map < address, symbol* > addrtab;
+
+    /**
      * A symbols contains a symbol table of global, weak and local symbols.
      */
     class table
@@ -270,6 +281,21 @@ namespace rld
        */
       const symtab& locals () const;
 
+      /**
+       * Return the globals symbol table keyed by address.
+       */
+      void globals (addrtab& addresses);
+
+      /**
+       * Return the weak symbol table keyed by address.
+       */
+      void weaks (addrtab& addresses);
+
+      /**
+       * Return the local symbol table keyed by address.
+       */
+      void locals (addrtab& addresses);
+
     private:
 
       /**




More information about the vc mailing list