summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2012-12-18 20:52:18 +1100
committerChris Johns <chrisj@rtems.org>2012-12-18 20:52:18 +1100
commit07c8f5fd4ef93a1b0860e044369398535cbc752c (patch)
tree591b859c3e312d3cde59adb09502a143ccdadd6e
parent07e1f228ea5f1dd88642be943d78465b2e8c0558 (diff)
Add object::get_section.
Add a method to return a section given the ELF section index. Add more trace output for debugging.
-rw-r--r--rld-files.cpp38
-rw-r--r--rld-files.h7
2 files changed, 32 insertions, 13 deletions
diff --git a/rld-files.cpp b/rld-files.cpp
index 5996c95..75860ba 100644
--- a/rld-files.cpp
+++ b/rld-files.cpp
@@ -363,7 +363,7 @@ namespace rld
if (path.empty ())
throw rld::error ("No file name", "open:" + path);
- if (rld::verbose () >= RLD_VERBOSE_TRACE)
+ if (rld::verbose () >= RLD_VERBOSE_TRACE_FILE)
std::cout << "image::open: " << name (). full ()
<< " refs:" << references_ + 1
<< " writable:" << (char*) (writable_ ? "yes" : "no")
@@ -394,7 +394,7 @@ namespace rld
{
if (references_ > 0)
{
- if (rld::verbose () >= RLD_VERBOSE_TRACE)
+ if (rld::verbose () >= RLD_VERBOSE_TRACE_FILE)
std::cout << "image::close: " << name ().full ()
<< " refs:" << references_ << std::endl;
@@ -822,7 +822,7 @@ namespace rld
void
archive::create (object_list& objects)
{
- if (rld::verbose () >= RLD_VERBOSE_INFO)
+ if (rld::verbose () >= RLD_VERBOSE_DETAILS)
std::cout << "archive::create: " << name ().full ()
<< ", objects: " << objects.size () << std::endl;
@@ -1041,7 +1041,7 @@ namespace rld
* Begin a session.
*/
- if (rld::verbose () >= RLD_VERBOSE_TRACE)
+ if (rld::verbose () >= RLD_VERBOSE_TRACE_FILE)
std::cout << "object:begin: " << name ().full () << " in-archive:"
<< ((char*) (archive_ ? "yes" : "no")) << std::endl;
@@ -1096,7 +1096,7 @@ namespace rld
void
object::end ()
{
- if (rld::verbose () >= RLD_VERBOSE_TRACE)
+ if (rld::verbose () >= RLD_VERBOSE_TRACE_FILE)
std::cout << "object:end: " << name ().full () << std::endl;
elf ().end ();
@@ -1111,14 +1111,14 @@ namespace rld
void
object::load_symbols (rld::symbols::table& symbols, bool local)
{
- if (rld::verbose () >= RLD_VERBOSE_TRACE)
+ if (rld::verbose () >= RLD_VERBOSE_TRACE_SYMS)
std::cout << "object:load-sym: " << name ().full () << std::endl;
rld::symbols::pointers syms;
elf ().get_symbols (syms, false, local);
- if (rld::verbose () >= RLD_VERBOSE_TRACE)
+ if (rld::verbose () >= RLD_VERBOSE_TRACE_SYMS)
std::cout << "object:load-sym: exported: total "
<< syms.size () << std::endl;
@@ -1129,11 +1129,7 @@ namespace rld
symbols::symbol& sym = *(*si);
if (rld::verbose () >= RLD_VERBOSE_TRACE_SYMS)
- {
- std::cout << "object:load-sym: exported: ";
- sym.output (std::cout);
- std::cout << std::endl;
- }
+ std::cout << "object:load-sym: exported: " << sym << std::endl;
sym.set_object (*this);
symbols[sym.name ()] = &sym;
@@ -1142,7 +1138,7 @@ namespace rld
elf ().get_symbols (syms, true);
- if (rld::verbose () >= RLD_VERBOSE_TRACE)
+ if (rld::verbose () >= RLD_VERBOSE_TRACE_SYMS)
std::cout << "object:load-sym: unresolved: total "
<< syms.size () << std::endl;
@@ -1269,6 +1265,22 @@ namespace rld
}
}
+ const section&
+ object::get_section (int index) const
+ {
+ for (sections::const_iterator si = secs.begin ();
+ si != secs.end ();
+ ++si)
+ {
+ const section& sec = *si;
+ if (sec.index == index)
+ return sec;
+ }
+
+ throw rld::error ("Section index '" + rld::to_string (index) +
+ "' not found: " + name ().full (), "object::get-section");
+ }
+
cache::cache ()
: opened (false)
{
diff --git a/rld-files.h b/rld-files.h
index 36dcc9b..f579626 100644
--- a/rld-files.h
+++ b/rld-files.h
@@ -734,6 +734,13 @@ namespace rld
*/
void get_sections (sections& filtered_secs, const std::string& name);
+ /**
+ * Get a section given an index number.
+ *
+ * @param index The section index to search for.
+ */
+ const section& get_section (int index) const;
+
private:
archive* archive_; //< Points to the archive if part of an
// archive.