[PATCH v3 12/22] rtemstoolkit/dwarf: Change the address source line to signed so valid() works.

Chris Johns chrisj at rtems.org
Mon Jun 18 02:29:10 UTC 2018


Also add a check to valid where there must be source to be valid.
---
 rtemstoolkit/rld-dwarf.cpp | 45 ++++++++++++++++++++++++---------------------
 rtemstoolkit/rld-dwarf.h   |  4 ++--
 2 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/rtemstoolkit/rld-dwarf.cpp b/rtemstoolkit/rld-dwarf.cpp
index ed135d9..15cf8e2 100644
--- a/rtemstoolkit/rld-dwarf.cpp
+++ b/rtemstoolkit/rld-dwarf.cpp
@@ -63,24 +63,26 @@ namespace rld
         block (false),
         end_sequence (false)
     {
-        dwarf_error de;
-        int         dr;
-        dr = ::dwarf_lineaddr(line, &addr, &de);
-        libdwarf_error_check ("address::address", dr, de);
-        dr = ::dwarf_line_srcfileno(line, &source_index, &de);
-        libdwarf_error_check ("address::address", dr, de);
-        dr = ::dwarf_lineno(line, &source_line, &de);
-        libdwarf_error_check ("address::address", dr, de);
-        dwarf_bool b;
-        dr = ::dwarf_linebeginstatement(line, &b, &de);
-        libdwarf_error_check ("address::address", dr, de);
-        begin_statement = b ? true : false;
-        dr = ::dwarf_lineblock(line, &b, &de);
-        libdwarf_error_check ("address::address", dr, de);
-        block = b ? true : false;
-        dr = ::dwarf_lineendsequence(line, &b, &de);
-        libdwarf_error_check ("address::address", dr, de);
-        end_sequence = b ? true : false;
+      dwarf_error de;
+      int         dr;
+      dr = ::dwarf_lineaddr(line, &addr, &de);
+      libdwarf_error_check ("address::address", dr, de);
+      dr = ::dwarf_line_srcfileno(line, &source_index, &de);
+      libdwarf_error_check ("address::address", dr, de);
+      dwarf_unsigned src_line;
+      dr = ::dwarf_lineno(line, &src_line, &de);
+      libdwarf_error_check ("address::address", dr, de);
+      source_line = src_line;
+      dwarf_bool b;
+      dr = ::dwarf_linebeginstatement(line, &b, &de);
+      libdwarf_error_check ("address::address", dr, de);
+      begin_statement = b ? true : false;
+      dr = ::dwarf_lineblock(line, &b, &de);
+      libdwarf_error_check ("address::address", dr, de);
+      block = b ? true : false;
+      dr = ::dwarf_lineendsequence(line, &b, &de);
+      libdwarf_error_check ("address::address", dr, de);
+      end_sequence = b ? true : false;
     }
 
     address::address (const address& orig)
@@ -108,12 +110,13 @@ namespace rld
     address::~address ()
     {
       source = nullptr;
+      source_line = -1;
     }
 
     bool
     address::valid () const
     {
-      return source_line > 0;
+      return source != nullptr && source_line > 0;
     }
 
     dwarf_address
@@ -155,7 +158,7 @@ namespace rld
     }
 
     address&
-    address::operator = (address& rhs)
+    address::operator = (const address& rhs)
     {
       if (this != &rhs)
       {
@@ -612,7 +615,7 @@ namespace rld
                                   address&            addr_line)
     {
       if (addr_lines_.find (addr) == addr_lines_.end ())
-        return false;
+          return false;
       addr_line = addr_lines_[addr];
       return true;
     }
diff --git a/rtemstoolkit/rld-dwarf.h b/rtemstoolkit/rld-dwarf.h
index 8a61755..c69cb9d 100644
--- a/rtemstoolkit/rld-dwarf.h
+++ b/rtemstoolkit/rld-dwarf.h
@@ -88,14 +88,14 @@ namespace rld
       /**
        * Assigment operator.
        */
-      address& operator = (address& rhs);
+      address& operator = (const address& rhs);
 
     private:
 
       dwarf_address  addr;
       sources const* source;
       dwarf_unsigned source_index;
-      dwarf_unsigned source_line;
+      dwarf_signed   source_line;
       bool           begin_statement;
       bool           block;
       bool           end_sequence;
-- 
2.15.1




More information about the devel mailing list