dwarflint/expected-at.cc dwarflint/expected.hh \
dwarflint/coverage.cc dwarflint/coverage.h \
dwarflint/readctx.c dwarflint/readctx.h \
+ dwarflint/pri.cc dwarflint/pri.h \
dwarflint/messages.cc dwarflint/messages.h \
dwarflint/where.c dwarflint/where.h \
dwarflint/config.cc dwarflint/config.h \
#include <dwarf.h>
#include "../libdw/known-dwarf.h"
#include "dwarfstrings.h"
+#include "pri.hh"
#include <sstream>
#include "checks-high.hh"
#include "dwarfstrings.h"
#include "all-dies-it.hh"
+#include "pri.hh"
#include <map>
using elfutils::dwarf;
#include "checks-high.hh"
#include "coverage.hh"
-#include "dwarfstrings.h"
+#include "pri.hh"
using elfutils::dwarf;
{
runoff = true;
wr_error (wh)
- << ": attribute `"
- << dwarf_attr_string ((*at).first)
- << "': PC range " << range_fmt (start, end)
+ << ": attribute `" << pri::attr ((*at).first)
+ << "': PC range " << pri::range (start, end)
<< " outside containing scope." << std::endl;
}
}
#include "checks-low.hh"
#include "low.h"
#include "config.h"
+#include "pri.hh"
#include <map>
#include <sstream>
#include <cstring>
if (shdr == NULL)
{
invalid_elf:
- wr_error (NULL, "Broken ELF.\n");
+ wr_error () << "Broken ELF." << std::endl;
return false;
}
goto invalid_elf;
if (!address_aligned (shdr->sh_addr, shdr->sh_addralign))
- {
- std::ostringstream s;
- s << "Base address of section " << scnname << ", "
- << "0x" << std::hex << shdr->sh_addr
- << ", should have an alignment of "
- << std::dec << shdr->sh_addralign;
- wr_error (NULL, "%s\n", s.str ().c_str ());
- }
+ wr_error ()
+ << "Base address of section " << scnname << ", "
+ << pri::addr (shdr->sh_addr) << ", should have an alignment of "
+ << shdr->sh_addralign << std::endl;
secentry *entry = secinfo.get (scnname);
cursec->scn = scn;
if (entry != NULL)
{
if (unlikely (entry->secndx != 0))
- wr_error (NULL, "Multiple occurrences of section %s.\n", scnname);
+ wr_error ()
+ << "Multiple occurrences of section " << scnname << std::endl;
else
{
/* Haven't seen a section of that name yet. */
if (relocated != NULL)
{
if (relocated->reldata != NULL)
- wr_error (NULL,
- "Several relocation sections for debug section %s."
- " Ignoring %s.\n",
- relocated_scnname, scnname);
+ wr_error ()
+ << "Several relocation sections for debug section "
+ << relocated_scnname << ". Ignoring " << scnname
+ << "." << std::endl;
else
{
relocated->reldata = elf_getdata (scn, NULL);
if (unlikely (relocated->reldata == NULL
|| relocated->reldata->d_buf == NULL))
{
- wr_error (NULL,
- "Data-less relocation section %s.\n", scnname);
+ wr_error ()
+ << "Data-less relocation section " << scnname
+ << "." << std::endl;
relocated->reldata = NULL;
}
else
if (reloc_symtab == NULL)
reloc_symtab = symtab_scn;
else if (reloc_symtab != symtab_scn)
- wr_error (NULL,
- "Relocation sections use multiple symbol tables.\n");
+ wr_error ()
+ << "Relocation sections use multiple symbol tables."
+ << std::endl;
}
}
}
if (reloc_symdata == NULL)
/* Not a show stopper, we can check a lot of stuff even
without a symbol table. */
- wr_error (NULL,
- "Couldn't obtain symtab data.\n");
+ wr_error () << "Couldn't obtain symtab data." << std::endl;
}
/* Check relocation sections that we've got. */
struct sec *sec = file->sec + cur->secndx;
sec->rel.type = cur->reltype;
if (sec->data == NULL)
- {
- where wh = WHERE (sec->id, NULL);
- wr_error (&wh,
- ": this data-less section has a relocation section.\n");
- }
+ wr_error (WHERE (sec->id, NULL))
+ << "this data-less section has a relocation section."
+ << std::endl;
else if (read_rel (file, sec, cur->reldata, file->addr_64))
sec->rel.symdata = reloc_symdata;
}
if (secentry *str = secinfo.get (".debug_str"))
if (str->reldata != NULL)
- {
- where wh = WHERE (sec_str, NULL);
- wr_message (mc_impact_2 | mc_elf, &wh,
- ": there's a relocation section associated with this section.\n");
- }
+ wr_message (WHERE (sec_str, NULL), cat (mc_impact_2, mc_elf))
+ << "there's a relocation section associated with this section."
+ << std::endl;
}
return true;
wr_message (WHERE (secid, NULL),
cat (mc_impact_4, mc_acc_suboptimal, mc_elf,
secid_to_cat (secid)))
- << "data not found." << std::endl;
+ << "data not found." << std::endl;
throw check_base::failed ();
}
#endif
#include "coverage.hh"
+#include "pri.hh"
#include <stdbool.h>
#include <assert.h>
}
}
-std::string
-range_fmt (uint64_t start, uint64_t end)
-{
- std::ostringstream os;
- os << std::hex << "[0x" << start << ", 0x" << end << ")";
- return os.str ();
-}
-
char *
range_fmt (char *buf, size_t buf_size, uint64_t start, uint64_t end)
{
- std::string s = range_fmt (start, end);
+ std::stringstream ss;
+ ss << pri::range (start, end);
+ std::string s = ss.str ();
strncpy (buf, s.c_str (), buf_size);
return buf;
}
ret = true;
return ret;
}
+
+bool
+cov::_format_base::fmt (uint64_t start, uint64_t length)
+{
+ if (_m_seen)
+ _m_os << _m_delim;
+ _m_os << pri::range (start, start + length);
+ _m_seen = true;
+ return true;
+}
+
+bool
+cov::_format_base::wrap_fmt (uint64_t start, uint64_t length, void *data)
+{
+ _format_base *self = static_cast <_format_base *> (data);
+ return self->fmt (start, length);
+}
+
+cov::_format_base::_format_base (std::string const &delim)
+ : _m_delim (delim),
+ _m_seen (false)
+{}
+
+cov::format_ranges::format_ranges (coverage const &cov,
+ std::string const &delim)
+ : _format_base (delim)
+{
+ coverage_find_ranges (&cov, &wrap_fmt, this);
+}
+
+cov::format_holes::format_holes (coverage const &cov,
+ uint64_t start, uint64_t length,
+ std::string const &delim)
+ : _format_base (delim)
+{
+ coverage_find_holes (&cov, start, length, &wrap_fmt, this);
+}
#ifdef __cplusplus
}
-
-#include <string>
-std::string range_fmt (uint64_t start, uint64_t end);
#endif
#endif//DWARFLINT_COVERAGE_H
#include <sstream>
#include "coverage.h"
-std::string range_fmt (uint64_t start, uint64_t end);
-
namespace cov
{
class _format_base
std::ostringstream _m_os;
bool _m_seen;
- inline bool fmt (uint64_t start, uint64_t length)
- {
- if (_m_seen)
- _m_os << _m_delim;
- _m_os << range_fmt (start, start + length);
- _m_seen = true;
- return true;
- }
-
- static bool
- wrap_fmt (uint64_t start, uint64_t length, void *data)
- {
- _format_base *self = static_cast <_format_base *> (data);
- return self->fmt (start, length);
- }
-
- _format_base (std::string const &delim)
- : _m_delim (delim),
- _m_seen (false)
- {
- _m_os << std::hex;
- }
+ inline bool fmt (uint64_t start, uint64_t length);
+ static bool wrap_fmt (uint64_t start, uint64_t length, void *data);
+ _format_base (std::string const &delim);
public:
- operator std::string () const
+ inline operator std::string () const
{
return _m_os.str ();
}
struct format_ranges
: public _format_base
{
- format_ranges (coverage const &cov, std::string const &delim = ", ")
- : _format_base (delim)
- {
- coverage_find_ranges (&cov, &wrap_fmt, this);
- }
+ format_ranges (coverage const &cov, std::string const &delim = ", ");
};
struct format_holes
: public _format_base
{
format_holes (coverage const &cov, uint64_t start, uint64_t length,
- std::string const &delim = ", ")
- : _format_base (delim)
- {
- coverage_find_holes (&cov, start, length, &wrap_fmt, this);
- }
+ std::string const &delim = ", ");
};
}
}
std::ostream &
-wr_warning (where const &wh)
+wr_warning ()
{
++error_count;
- return get_stream () << gettext ("warning: ") << wh << ": ";
+ return get_stream () << gettext ("warning: ");
}
std::ostream &
-wr_error (where const &wh)
+wr_error ()
{
++error_count;
- return get_stream () << gettext ("error: ") << wh << ": ";
+ return get_stream () << gettext ("error: ");
}
std::ostream &
-wr_message (where const &wh, message_category category)
+wr_message (message_category category)
{
if (!message_accept (&warning_criteria, category))
return nostr;
else if (message_accept (&error_criteria, category))
- return wr_error (wh);
+ return wr_error ();
else
- return wr_warning (wh);
+ return wr_warning ();
+}
+
+std::ostream &
+wr_warning (where const &wh)
+{
+ return wr_warning () << wh << ": ";
+}
+
+std::ostream &
+wr_error (where const &wh)
+{
+ return wr_error () << wh << ": ";
+}
+
+std::ostream &
+wr_message (where const &wh, message_category category)
+{
+ return wr_message (category) << wh << ": ";
}
void
wh, start, end,
"unreferenced non-zero bytes");
}
-
-std::ostream &
-pri::operator << (std::ostream &os, pri::pribase const &obj)
-{
- return os << obj.m_a << obj.m_b << obj.m_c;
-}
-
-std::ostream &
-pri::operator << (std::ostream &os, pri::ref const &obj)
-{
- std::stringstream ss;
- ss << std::hex << "DIE " << obj.off;
- return os << ss.str ();
-}
}
std::ostream &wr_warning (where const &wh);
+std::ostream &wr_warning ();
std::ostream &wr_error (where const &wh);
+std::ostream &wr_error ();
std::ostream &wr_message (where const &wh, message_category cat);
-
-namespace pri
-{
- class pribase
- {
- std::string const &m_a;
- std::string const &m_b;
- std::string const &m_c;
-
- protected:
- pribase (std::string const &a,
- std::string const &b = "",
- std::string const &c = "")
- : m_a (a), m_b (b), m_c (c)
- {}
- friend std::ostream &operator << (std::ostream &os, pribase const &obj);
- };
- std::ostream &operator << (std::ostream &os, pribase const &obj);
-
- struct not_enough
- : public pribase
- {
- not_enough (std::string const &what)
- : pribase ("not enough data for ", what)
- {}
- };
-
- struct lacks_relocation
- : public pribase
- {
- lacks_relocation (std::string const &what)
- : pribase (what, " seems to lack a relocation")
- {}
- };
-
- class ref
- {
- Dwarf_Off off;
- public:
- template <class T>
- ref (T const &die)
- : off (die.offset ())
- {}
- friend std::ostream &operator << (std::ostream &os, ref const &obj);
- };
- std::ostream &operator << (std::ostream &os, ref const &obj);
-}
+std::ostream &wr_message (message_category cat);
#endif
#endif//DWARFLINT_MESSAGES_H
--- /dev/null
+#include "dwarfstrings.h"
+#include "pri.hh"
+#include <sstream>
+
+pri::attr::attr (int attr_name)
+ : pribase (dwarf_attr_string (attr_name))
+{}
+
+std::ostream &
+pri::operator << (std::ostream &os, pri::pribase const &obj)
+{
+ return os << obj.m_a << obj.m_b << obj.m_c;
+}
+
+std::ostream &
+pri::operator << (std::ostream &os, pri::ref const &obj)
+{
+ std::stringstream ss;
+ ss << std::hex << "DIE " << obj.off;
+ return os << ss.str ();
+}
+
+std::ostream &
+pri::operator << (std::ostream &os, pri::addr const &obj)
+{
+ std::stringstream ss;
+ ss << std::hex << "0x" << obj.off;
+ return os << ss.str ();
+}
+
+std::ostream &
+pri::operator << (std::ostream &os, pri::range const &obj)
+{
+ return os << "[" << pri::addr (obj.start)
+ << ", " << pri::addr (obj.end) << ")";
+}
--- /dev/null
+#ifndef DWARFLINT_PRI_H
+#define DWARFLINT_PRI_H
+
+#include <libdw.h>
+#include <string>
+
+namespace pri
+{
+ class pribase
+ {
+ std::string const &m_a;
+ std::string const &m_b;
+ std::string const &m_c;
+
+ protected:
+ pribase (std::string const &a,
+ std::string const &b = "",
+ std::string const &c = "")
+ : m_a (a), m_b (b), m_c (c)
+ {}
+ friend std::ostream &operator << (std::ostream &os, pribase const &obj);
+ };
+ std::ostream &operator << (std::ostream &os, pribase const &obj);
+
+ struct not_enough
+ : public pribase
+ {
+ not_enough (std::string const &what)
+ : pribase ("not enough data for ", what)
+ {}
+ };
+
+ struct lacks_relocation
+ : public pribase
+ {
+ lacks_relocation (std::string const &what)
+ : pribase (what, " seems to lack a relocation")
+ {}
+ };
+
+ struct attr
+ : public pribase
+ {
+ attr (int attr_name);
+ };
+
+ class ref
+ {
+ Dwarf_Off off;
+ public:
+ template <class T>
+ ref (T const &die)
+ : off (die.offset ())
+ {}
+ friend std::ostream &operator << (std::ostream &os, ref const &obj);
+ };
+ std::ostream &operator << (std::ostream &os, ref const &obj);
+
+ class addr
+ {
+ Dwarf_Off off;
+ public:
+ addr (Dwarf_Off a_off)
+ : off (a_off)
+ {}
+ friend std::ostream &operator << (std::ostream &os, addr const &obj);
+ };
+ std::ostream &operator << (std::ostream &os, addr const &obj);
+
+ class range
+ {
+ Dwarf_Off start;
+ Dwarf_Off end;
+ public:
+ range (Dwarf_Off a_start, Dwarf_Off a_end)
+ : start (a_start), end (a_end)
+ {}
+ friend std::ostream &operator << (std::ostream &os, range const &obj);
+ };
+ std::ostream &operator << (std::ostream &os, range const &obj);
+}
+
+#endif//DWARFLINT_PRI_H