diff --git a/src/Exception-py.i b/src/Exception-py.i index 30686eec216..7d47627e4e4 100644 --- a/src/Exception-py.i +++ b/src/Exception-py.i @@ -32,20 +32,49 @@ /////////////////////////////////////////////////////////////////////////////// %{ +#include + +#include +#include + +#include "ord/OpenRoad.hh" +#include "utl/Logger.h" %} %exception { try { $function } catch (std::bad_alloc &) { fprintf(stderr, "Error: out of memory."); - exit(0); + abort(); } // This catches std::runtime_error (utl::error) and sta::Exception. catch (std::exception &excp) { + auto* openroad = ord::OpenRoad::openRoad(); + if (openroad != nullptr) { + auto* logger = openroad->getLogger(); + if (logger->debugCheck(utl::ORD, "trace", 1)) { + std::stringstream trace; + trace << boost::stacktrace::stacktrace(); + logger->report("Stack trace"); + logger->report(trace.str()); + } + } + PyErr_SetString(PyExc_RuntimeError, excp.what()); SWIG_fail; } catch (...) { + auto* openroad = ord::OpenRoad::openRoad(); + if (openroad != nullptr) { + auto* logger = openroad->getLogger(); + if (logger->debugCheck(utl::ORD, "trace", 1)) { + std::stringstream trace; + trace << boost::stacktrace::stacktrace(); + logger->report("Stack trace"); + logger->report(trace.str()); + } + } + PyErr_SetString(PyExc_Exception, "Unknown exception"); SWIG_fail; } diff --git a/src/Exception.i b/src/Exception.i index 91899547d9e..ecea128991e 100644 --- a/src/Exception.i +++ b/src/Exception.i @@ -16,16 +16,34 @@ %{ #include +#include + +#include +#include + +#include "ord/OpenRoad.hh" +#include "utl/Logger.h" %} %exception { try { $function } catch (std::bad_alloc &) { fprintf(stderr, "Error: out of memory."); - exit(1); + abort(); } // This catches std::runtime_error (utl::error) and sta::Exception. catch (std::exception &excp) { + auto* openroad = ord::OpenRoad::openRoad(); + if (openroad != nullptr) { + auto* logger = openroad->getLogger(); + if (logger->debugCheck(utl::ORD, "trace", 1)) { + std::stringstream trace; + trace << boost::stacktrace::stacktrace(); + logger->report("Stack trace"); + logger->report(trace.str()); + } + } + Tcl_ResetResult(interp); Tcl_AppendResult(interp, excp.what(), nullptr); return TCL_ERROR; diff --git a/src/dst/test/cpp/CMakeLists.txt b/src/dst/test/cpp/CMakeLists.txt index 0beb1e33b16..fbfe2aeded2 100644 --- a/src/dst/test/cpp/CMakeLists.txt +++ b/src/dst/test/cpp/CMakeLists.txt @@ -1,5 +1,6 @@ set(TEST_LIBS dst + dl ${TCL_LIBRARY} ) diff --git a/src/odb/src/swig/tcl/CMakeLists.txt b/src/odb/src/swig/tcl/CMakeLists.txt index 46eed4301b9..313cdf62251 100644 --- a/src/odb/src/swig/tcl/CMakeLists.txt +++ b/src/odb/src/swig/tcl/CMakeLists.txt @@ -25,16 +25,20 @@ target_link_libraries(odbtcl # Executable add_executable(odbtcl-bin main.cpp + stub.cpp ) target_include_directories(odbtcl-bin PUBLIC ${PROJECT_SOURCE_DIR}/include/odb + PRIVATE + ${OPENROAD_HOME}/include ) target_link_libraries(odbtcl-bin PUBLIC odbtcl + dl ) set_target_properties(odbtcl-bin diff --git a/src/odb/src/swig/tcl/stub.cpp b/src/odb/src/swig/tcl/stub.cpp new file mode 100644 index 00000000000..d7780e36037 --- /dev/null +++ b/src/odb/src/swig/tcl/stub.cpp @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// BSD 3-Clause License +// +// Copyright (c) 2024, The Regents of the University of California +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include "ord/OpenRoad.hh" + +namespace ord { + +OpenRoad* OpenRoad::openRoad() +{ + return nullptr; +} + +} // namespace ord diff --git a/src/par/CMakeLists.txt b/src/par/CMakeLists.txt index da78b853f76..dd274b9f315 100644 --- a/src/par/CMakeLists.txt +++ b/src/par/CMakeLists.txt @@ -154,6 +154,7 @@ if (Python3_FOUND AND BUILD_PYTHON) target_link_libraries(par_py PUBLIC par_lib + utl_lib ) endif()