On Tue, 2010-08-10 at 12:22 -0700, Roland McGrath wrote:
> The testwriter -T variants of this test fail with:
> terminate called after throwing an instance of 'std::logic_error'
> what(): basic_string::_S_construct NULL not valid
>
> Because of the throw in entry_copier::populate
That is a re-throw, so the actual exception came from deeper in the soup.
In gdb, "catch throw" or "break __cxa_throw" are highly recommended.
The actual exception came from the dwarf_data::directory_table
constructor that takes a dwarf::directory_table. Because it tries to
convert the const char* directory strings from dwarf_getsrcdirs to
std::strings. But the first entry is the CU directory path which can be
NULL. If so the copy constructor throws because it cannot convert from
NULL to std::string.
Writing an explicit constructor that takes a NULL const char* into
account works around this:
template<typename table>
directory_table (const table &other)
- : _base (other.begin (), other.end ()) {}
+ {
+ typename table::const_iterator it;
+ for (it = other.begin (); it != other.end (); it++)
+ _base::push_back (*it != NULL ? std::string(*it) : "");
+ }
But then I get in similar trouble inside the subr::equal_to template
code. Specifically the elfutils::subr::equal_to<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, char
const*>::operator()
instance, which will crash and burn trying to compare the empty string
and the NULL. Still looking into that. Hints and tips for how to
generically deal with char*/std::string in C++ code appreciated.
Cheers,
mark