Closed Silex closed 2 months ago
Hello, thanks for the bug report! I have tried the code locally and unfortunately I haven't been able to reproduce, though this definitely seems like a bug. It seems there's an issue with the internal handling of traces in the cpptrace exception objects as opposed to a problem with tracing directly, though I haven't been able to reproduce it with this code. There's also a small chance there could be some unexpected behavior from arm-linux-gnueabihf-g++
surrounding how an exception object is constructed on a throw.
What version of the library are you using?
Latest stable from git, here's how I build it:
# Build cpptrace
RUN git clone --branch v0.6.0 https://github.com/jeremy-rifkin/cpptrace.git && \
mkdir cpptrace/build && \
cd cpptrace/build && \
. /opt/axis/acapsdk/environment-setup* && \
cmake .. \
-D BUILD_SHARED_LIBS=1 \
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
-D CMAKE_INSTALL_PREFIX=$PREFIX \
-D CMAKE_CXX_COMPILER=${CXX%-g++*}-g++ \
-D CMAKE_CXX_FLAGS="${CXX#*-g++}" \
-D CMAKE_C_COMPILER=${CC%-gcc*}-gcc \
-D CMAKE_C_FLAGS="${CC#*-gcc}" && \
make -j$(nproc) && \
make install
Without BUILD_SHARED_LIBS
it would only build the static version (.a), and it resulted in undefined references at link time which I didn't understand why so I built the .so instead.
@jeremy-rifkin: given the normal trace works, is there a way to use that when throwing exception? I mean, disabling the "lazy-exception" mechanism?
If not, can you point me toward what I should modify if I want that?
Hey, thanks for your patience. I'd still like to solve this but I haven't been able to look into this further or reproduce yet.
As far as modifying the exception behavior, the way the library is setup the cpptrace::exception/error classes are meant to serve as a reference implementation for how something like this can be done. It should be easy to roll your own that skips the raw trace and just generates a full trace right off the bat, e.g.
class my_exception {
std::string message;
public
my_exception(
std::string message,
cpptrace::stacktrace trace = cpptrace::generate_trace()
) : message(message + "\n" + trace.to_string()) {}
const char* what() const noexcept {
return message.c_str();
}
};
(haven't tested but that should work)
Thanks. What I really liked in your lib is just replacing std::runtime_error
with cpptrace::runtime_error
(etc) and have the workflow like what you'd expect.
Of course I could quickly redo them like myapp::runtime_error
but the idea was to do some patching to cpptrace::exception
prior to building the lib so it'd behave like your snippet above.
I think I might have a fix which I've just pushed to jr/try-fix-134
. Do you think you could try 2e981c89a5af9d91e1367df3d4f141508d443a72 locally and see if this fixes things for you?
@jeremy-rifkin: thanks!
So, I discovered that cameras running on aarch64
don't have this problem (v0.6.0 works).
On armv7hf
, your fix works!
v0.6.0:
2024-06-13T07:49:28.324+00:00 axis-accc8ee2384f [ INFO ] arqivis[18940]: Application: run
2024-06-13T07:49:30.324+00:00 axis-accc8ee2384f [ INFO ] arqivis[18940]: Stack trace (most recent call first):
2024-06-13T07:49:30.324+00:00 axis-accc8ee2384f [ INFO ] arqivis[18940]: #0 0x0048774b in storage::subscribe(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) at /opt/app/storage.cpp:46:40
2024-06-13T07:49:30.324+00:00 axis-accc8ee2384f [ INFO ] arqivis[18940]: #1 0x004844f1 in application::setup_storage() at /opt/app/application.cpp:62:22
2024-06-13T07:49:30.324+00:00 axis-accc8ee2384f [ INFO ] arqivis[18940]: #2 0x00484683 in application::run() at /opt/app/application.cpp:27:16
2024-06-13T07:49:30.324+00:00 axis-accc8ee2384f [ INFO ] arqivis[18940]: #3 0x00483ce5 in main at /opt/app/main.cpp:54:12
2024-06-13T07:49:30.324+00:00 axis-accc8ee2384f [ INFO ] arqivis[18940]: #4 0x7682a549 at /usr/lib/libc.so.6
2024-06-13T07:49:30.324+00:00 axis-accc8ee2384f [ INFO ] arqivis[18940]: #5 0x7682a5e5 at /usr/lib/libc.so.6
2024-06-13T07:49:31.324+00:00 axis-accc8ee2384f [ ERR ] arqivis[18940]: Exception: oh noes
2024-06-13T07:49:31.324+00:00 axis-accc8ee2384f [ INFO ] arqivis[18940]: Stack trace (most recent call first):
2024-06-13T07:49:31.324+00:00 axis-accc8ee2384f [ INFO ] arqivis[18940]: <empty trace>
jr/try-fix-134:
2024-06-13T07:12:21.324+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: Application: run
2024-06-13T07:12:23.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: Stack trace (most recent call first):
2024-06-13T07:12:23.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: #0 0x00427749 in storage::subscribe(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) at /opt/app/storage.cpp:46:40
2024-06-13T07:12:23.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: #1 0x004244f1 in application::setup_storage() at /opt/app/application.cpp:62:22
2024-06-13T07:12:23.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: #2 0x00424683 in application::run() at /opt/app/application.cpp:27:16
2024-06-13T07:12:23.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: #3 0x00423ce5 in main at /opt/app/main.cpp:54:12
2024-06-13T07:12:23.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: #4 0x7685a549 at /usr/lib/libc.so.6
2024-06-13T07:12:23.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: #5 0x7685a5e5 at /usr/lib/libc.so.6
2024-06-13T07:12:24.323+00:00 axis-accc8ee2384f [ ERR ] arqivis[15220]: Exception: oh noes
2024-06-13T07:12:24.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: Stack trace (most recent call first):
2024-06-13T07:12:24.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: #0 0x004277c9 in storage::subscribe(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) at /opt/app/storage.cpp:48:3
2024-06-13T07:12:24.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: #1 0x004244f1 in application::setup_storage() at /opt/app/application.cpp:62:22
2024-06-13T07:12:24.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: #2 0x00424683 in application::run() at /opt/app/application.cpp:27:16
2024-06-13T07:12:24.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: #3 0x00423ce5 in main at /opt/app/main.cpp:54:12
2024-06-13T07:12:24.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: #4 0x7685a549 at /usr/lib/libc.so.6
2024-06-13T07:12:24.323+00:00 axis-accc8ee2384f [ INFO ] arqivis[15220]: #5 0x7685a5e5 at /usr/lib/libc.so.6
To be honest I really don't get why your fix works. Can you shed some light?
The only diff I can see is that armv7hf
is built with:
arm-linux-gnueabihf-g++ -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9
And that aarch64
is built with:
aarch64-linux-gnu-g++ -mcpu=cortex-a53 -march=armv8-a+crc+crypto -mbranch-protection=standard
Awesome! I am glad it works. The fix is very surprising, my best understanding is that under armv7hf unwinding tables are needed and when get_raw_trace_and_absorb
is noexcept unwind tables aren’t generated for the function. Credit to @easyaspi314 for this fix :)
I’ll go ahead and merge this into dev and it’ll be fixed in the next release.
Great! Yeah, for the explanation I don't fully get it but https://stackoverflow.com/questions/26079903/noexcept-stack-unwinding-and-performance helped me understand what it was about.
@jeremy-rifkin: any ETA for the next release?
I'll aim to do a patch release this weekend!
Thanks, ping me when it's done :-)
Apologies for the delay, release will be today
Release is now out, thanks for your patience!
Thanks!
Hello,
Thanks for the lib, I like the design.
I have a bug with the following snippet:
It produces the following output
As you see generating the trace works but not when catching exceptions.
This is a special environment: the code is cross-compiled for armv7hf/aarch64 (it runs on AXIS cameras).
Here is the command line that builds the application:
And attached is the
CMakeCache.txt
that was used to build cpptrace, so you can look at the CXXFLAGS etc.CMakeCache.txt