mirror of
https://git.rtems.org/rtems-tools/
synced 2025-10-24 23:08:15 +08:00
rtemstoolkit/elf,files: Catch exceptions in destructors.
Catch exceptions in destructures and print a message to avoid an unhandled exception happening in an exception stack unwind.
This commit is contained in:
@@ -435,7 +435,21 @@ namespace rld
|
|||||||
|
|
||||||
file::~file ()
|
file::~file ()
|
||||||
{
|
{
|
||||||
end ();
|
try
|
||||||
|
{
|
||||||
|
end ();
|
||||||
|
}
|
||||||
|
catch (rld::error re)
|
||||||
|
{
|
||||||
|
std::cerr << "error: rld::elf::file::~file: "
|
||||||
|
<< re.where << ": " << re.what
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::cerr << "error: rld::elf::file::~file: unhandled exception"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -447,7 +461,8 @@ namespace rld
|
|||||||
void
|
void
|
||||||
file::reference_release ()
|
file::reference_release ()
|
||||||
{
|
{
|
||||||
--refs;
|
if (refs > 0)
|
||||||
|
--refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -525,16 +540,14 @@ namespace rld
|
|||||||
if (archive_ && (ek != ELF_K_ELF))
|
if (archive_ && (ek != ELF_K_ELF))
|
||||||
throw rld::error ("File format in archive not ELF",
|
throw rld::error ("File format in archive not ELF",
|
||||||
"elf:file:begin: " + name__);
|
"elf:file:begin: " + name__);
|
||||||
|
|
||||||
|
if (ek == ELF_K_AR)
|
||||||
|
archive = true;
|
||||||
|
else if (ek == ELF_K_ELF)
|
||||||
|
archive = false;
|
||||||
else
|
else
|
||||||
{
|
throw rld::error ("File format not ELF or archive",
|
||||||
if (ek == ELF_K_AR)
|
"elf:file:begin: " + name__);
|
||||||
archive = true;
|
|
||||||
else if (ek == ELF_K_ELF)
|
|
||||||
archive = false;
|
|
||||||
else
|
|
||||||
throw rld::error ("File format not ELF or archive",
|
|
||||||
"elf:file:begin: " + name__);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!writable_)
|
if (!writable_)
|
||||||
{
|
{
|
||||||
@@ -545,7 +558,7 @@ namespace rld
|
|||||||
if (ek == ELF_K_ELF)
|
if (ek == ELF_K_ELF)
|
||||||
{
|
{
|
||||||
oclass = ::gelf_getclass (elf__);
|
oclass = ::gelf_getclass (elf__);
|
||||||
ident_str = elf_getident (elf__, &ident_size);
|
ident_str = ::elf_getident (elf__, &ident_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,15 +580,6 @@ namespace rld
|
|||||||
if (refs > 0)
|
if (refs > 0)
|
||||||
throw rld::error ("References still held", "elf:file:end: " + name_);
|
throw rld::error ("References still held", "elf:file:end: " + name_);
|
||||||
|
|
||||||
if (elf_)
|
|
||||||
{
|
|
||||||
if (rld::verbose () >= RLD_VERBOSE_FULL_DEBUG)
|
|
||||||
std::cout << "libelf::end: " << elf_
|
|
||||||
<< ' ' << name_ << std::endl;
|
|
||||||
::elf_end (elf_);
|
|
||||||
elf_ = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fd_ >= 0)
|
if (fd_ >= 0)
|
||||||
{
|
{
|
||||||
if (!writable)
|
if (!writable)
|
||||||
@@ -595,12 +599,21 @@ namespace rld
|
|||||||
fd_ = -1;
|
fd_ = -1;
|
||||||
name_.clear ();
|
name_.clear ();
|
||||||
archive = false;
|
archive = false;
|
||||||
elf_ = 0;
|
|
||||||
oclass = 0;
|
oclass = 0;
|
||||||
ident_str = 0;
|
ident_str = 0;
|
||||||
ident_size = 0;
|
ident_size = 0;
|
||||||
writable = false;
|
writable = false;
|
||||||
|
|
||||||
secs.clear ();
|
secs.clear ();
|
||||||
|
|
||||||
|
if (elf_)
|
||||||
|
{
|
||||||
|
if (rld::verbose () >= RLD_VERBOSE_FULL_DEBUG)
|
||||||
|
std::cout << "libelf::end: " << elf_
|
||||||
|
<< ' ' << name_ << std::endl;
|
||||||
|
::elf_end (elf_);
|
||||||
|
elf_ = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -256,10 +256,12 @@ namespace rld
|
|||||||
image::~image ()
|
image::~image ()
|
||||||
{
|
{
|
||||||
if (references_)
|
if (references_)
|
||||||
std::cerr << "rtl:file:image: references when destructing";
|
std::cerr << "rtl:file:image: references when destructing" << std::endl;
|
||||||
|
|
||||||
if (fd_ >= 0)
|
if (fd_ >= 0)
|
||||||
{
|
{
|
||||||
::close (fd_);
|
::close (fd_);
|
||||||
|
fd_= -1;
|
||||||
if (writable && remove)
|
if (writable && remove)
|
||||||
{
|
{
|
||||||
if (rld::verbose () >= RLD_VERBOSE_INFO)
|
if (rld::verbose () >= RLD_VERBOSE_INFO)
|
||||||
@@ -268,6 +270,22 @@ namespace rld
|
|||||||
::unlink (name_.path ().c_str ());
|
::unlink (name_.path ().c_str ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
elf_.end ();
|
||||||
|
}
|
||||||
|
catch (rld::error re)
|
||||||
|
{
|
||||||
|
std::cerr << "error: rld::files::image:::~image: "
|
||||||
|
<< re.where << ": " << re.what
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::cerr << "error: rld::files::image:::~image: unhandled exception"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -537,8 +555,22 @@ namespace rld
|
|||||||
|
|
||||||
archive::~archive ()
|
archive::~archive ()
|
||||||
{
|
{
|
||||||
end ();
|
try
|
||||||
close ();
|
{
|
||||||
|
end ();
|
||||||
|
close ();
|
||||||
|
}
|
||||||
|
catch (rld::error re)
|
||||||
|
{
|
||||||
|
std::cerr << "error: rld::files::archive::~archive: "
|
||||||
|
<< re.where << ": " << re.what
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::cerr << "error: rld::files::archive::~archive: unhandled exception"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -960,8 +992,22 @@ namespace rld
|
|||||||
|
|
||||||
object::~object ()
|
object::~object ()
|
||||||
{
|
{
|
||||||
end ();
|
try
|
||||||
close ();
|
{
|
||||||
|
end ();
|
||||||
|
close ();
|
||||||
|
}
|
||||||
|
catch (rld::error re)
|
||||||
|
{
|
||||||
|
std::cerr << "error: rld::files::object::~object: "
|
||||||
|
<< re.where << ": " << re.what
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::cerr << "error: rld::files::object::~object: unhandled exception"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1318,7 +1364,21 @@ namespace rld
|
|||||||
|
|
||||||
cache::~cache ()
|
cache::~cache ()
|
||||||
{
|
{
|
||||||
close ();
|
try
|
||||||
|
{
|
||||||
|
close ();
|
||||||
|
}
|
||||||
|
catch (rld::error re)
|
||||||
|
{
|
||||||
|
std::cerr << "error: rld::files:cache::~cache: "
|
||||||
|
<< re.where << ": " << re.what
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::cerr << "error: rld::files::cache::~cache: unhandled exception"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user