]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Initialize d_off, some nits
authorPetr Machata <pmachata@redhat.com>
Tue, 11 Aug 2009 14:45:41 +0000 (16:45 +0200)
committerPetr Machata <pmachata@redhat.com>
Tue, 11 Aug 2009 14:45:41 +0000 (16:45 +0200)
libdw/c++/dwarf_output
libdw/c++/output-shape.cc

index 605e43f08f7d3f86b206028c5c7ae4751ec57b41..305e037c30312b675bd3c9baac18dcd1b6174803 100644 (file)
@@ -87,6 +87,7 @@ namespace elfutils
 
     inline void more ()
     {
+      off_t off = _m_data == NULL ? 0 : _m_data->d_off + _m_data->d_size;
       _m_data = elf_newdata (_m_scn);
       if (_m_data == NULL)
        throw std::runtime_error (std::string ("Error while creating section data: ")
@@ -97,6 +98,7 @@ namespace elfutils
       _m_data->d_type = ELF_T_BYTE;
       _m_data->d_align = 1;
       _m_data->d_size = 0;
+      _m_data->d_off = off;
     }
 
   public:
@@ -104,14 +106,15 @@ namespace elfutils
     typedef value_type const &const_reference;
 
     section_appender (Elf_Scn *scn, size_t alloc_unit)
-      : _m_alloc_unit (alloc_unit)
+      : _m_data (NULL)
+      , _m_alloc_unit (alloc_unit)
       , _m_scn (scn)
       , _m_totsize (0)
     {
       more ();
     }
 
-    unsigned char *alloc(size_t a_size)
+    unsigned char *alloc (size_t a_size)
     {
       size_t ns = _m_data->d_size + a_size;
       if (ns > _m_alloc_unit)
index 021b8c43c469f0a8b22236773baedaf79f04c2fd..8f80211781083cfda033479dd546de9559c2d7ca 100644 (file)
@@ -604,9 +604,8 @@ dwarf_output::output_debug_info (section_appender &appender,
       // Remember where the unit started for back-patching of size.
       size_t cu_start = appender.size ();
 
-      // Unit length.  Put zeroes for now, patch later.
-      unsigned char *length_data = appender.alloc (4);
-      ::dw_write<4> (length_data, 0, big_endian);
+      // Unit length.
+      gap length_gap (appender, 4 /*XXX dwarf64*/, big_endian);
 
       // Version.
       ::dw_write<2> (appender.alloc (2), 3, big_endian);
@@ -615,7 +614,7 @@ dwarf_output::output_debug_info (section_appender &appender,
       // emit at offset 0.
       ::dw_write<4> (appender.alloc (4), 0, big_endian);
 
-      // XXX size in bytes of an address on the target architecture.
+      // Size in bytes of an address on the target architecture.
       *inserter++ = addr_64 ? 8 : 4;
 
       die_off_map die_off;
@@ -635,6 +634,6 @@ dwarf_output::output_debug_info (section_appender &appender,
       /* Back-patch length.  */
       size_t length = appender.size () - cu_start - 4; // -4 for length info. XXX dwarf64
       assert (length < (uint32_t)-1); // XXX temporary XXX dwarf64
-      ::dw_write<4> (length_data, length, big_endian); // XXX dwarf64
+      length_gap.patch (length);
     }
 }