Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve backtrace #5312

Merged
merged 1 commit into from
Nov 8, 2023
Merged

Conversation

tmoerschell
Copy link
Contributor

I noticed that the "better stacktrace" in the error logs was just the same as the original one. I found out that the argument passed to addr2line wasn't correct (it expects the section offset, not the runtime function address).

I used a regex to extract the section offset.
I set addr2line to output demangled function names (-fC + p to write in on one line).
Even found a memory leak in the function, which I couldn't just let slide.

This will now print source files and line numbers for calls that are from within the xournalpp executable. I haven't found out how to add information for external libraries, should debug information be provided (or at least how to demangle the function names).

I'm open to formatting changes. I didn't want to make too many changes, but if we have the source call location for a stack frame, I'd say we could drop the original message (which is still printed out in the log file anyways).

I hope this can be useful!

@rolandlo rolandlo requested a review from Febbe November 2, 2023 17:25
@rolandlo
Copy link
Member

rolandlo commented Nov 3, 2023

Just tried it out, by introducing a segfault into the plugin execution code. It's awesome! I get the exact line number in the code where the segfault happened in the "better st(r)acktrace". That's huge for debugging! Great job!

I'm wondering though, why are the lines like ?? ??:0 printed. Any idea?

Maybe the numbering could also be fixed, so that the original stacktrace and the better stacktrace both begin counting with 1.

Date: Fri Nov  3 19:16:06 2023
Error: signal 11
Xournal++ version 1.2.2+dev
Git commit fd7823d1 from rolandlo/pr/tmoerschell/5312
Gtk version 3.24.38

[bt]: (0) install/bin/xournalpp(+0x4263c5) [0x5648b31c23c5]
[bt]: (1) /lib/x86_64-linux-gnu/libc.so.6(+0x42910) [0x7ff35fe42910]
[bt]: (2) install/bin/xournalpp(+0x6543d0) [0x5648b33f03d0]
[bt]: (3) install/bin/xournalpp(+0x654415) [0x5648b33f0415]
[bt]: (4) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_closure_invoke+0x140) [0x7ff360918130]
[bt]: (5) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(+0x424ac) [0x7ff3609454ac]
[bt]: (6) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(+0x339b1) [0x7ff3609369b1]
[bt]: (7) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_signal_emit_valist+0x36) [0x7ff360936bd6]
[bt]: (8) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_signal_emit+0x93) [0x7ff360936c93]
[bt]: (9) /lib/x86_64-linux-gnu/libgio-2.0.so.0(+0xe8bbd) [0x7ff360a7bbbd]
[bt]: (10) /lib/x86_64-linux-gnu/libgtk-3.so.0(+0x20a216) [0x7ff36120a216]
[bt]: (11) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_closure_invoke+0x140) [0x7ff360918130]
[bt]: (12) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(+0x424ac) [0x7ff3609454ac]
[bt]: (13) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(+0x339b1) [0x7ff3609369b1]
[bt]: (14) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_signal_emit_valist+0x36) [0x7ff360936bd6]
[bt]: (15) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_signal_emit+0x93) [0x7ff360936c93]
[bt]: (16) /lib/x86_64-linux-gnu/libgtk-3.so.0(gtk_widget_activate+0x7c) [0x7ff36134284c]
[bt]: (17) /lib/x86_64-linux-gnu/libgtk-3.so.0(gtk_menu_shell_activate_item+0xe6) [0x7ff36120d636]
[bt]: (18) /lib/x86_64-linux-gnu/libgtk-3.so.0(+0x20d969) [0x7ff36120d969]
[bt]: (19) /lib/x86_64-linux-gnu/libgtk-3.so.0(+0x980d8) [0x7ff3610980d8]
[bt]: (20) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(+0x33add) [0x7ff360936add]
[bt]: (21) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_signal_emit_valist+0x36) [0x7ff360936bd6]
[bt]: (22) /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_signal_emit+0x93) [0x7ff360936c93]
[bt]: (23) /lib/x86_64-linux-gnu/libgtk-3.so.0(+0x34f154) [0x7ff36134f154]
[bt]: (24) /lib/x86_64-linux-gnu/libgtk-3.so.0(+0x1f7b1e) [0x7ff3611f7b1e]
[bt]: (25) /lib/x86_64-linux-gnu/libgtk-3.so.0(gtk_main_do_event+0x986) [0x7ff3611f85f6]
[bt]: (26) /lib/x86_64-linux-gnu/libgdk-3.so.0(+0x398b7) [0x7ff3618a28b7]
[bt]: (27) /lib/x86_64-linux-gnu/libgdk-3.so.0(+0x8fb16) [0x7ff3618f8b16]
[bt]: (28) /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x5ab2c) [0x7ff360e34b2c]
[bt]: (29) /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0xb646f) [0x7ff360e9046f]
[bt]: (30) /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x30) [0x7ff360e32d20]
[bt]: (31) /lib/x86_64-linux-gnu/libgio-2.0.so.0(g_application_run+0x16d) [0x7ff360a74b5d]
[bt]: (32) install/bin/xournalpp(_ZN11XournalMain3runEiPPc+0x86b) [0x5648b31cb7c4]
[bt]: (33) install/bin/xournalpp(main+0x29) [0x5648b31c1f82]
[bt]: (34) /lib/x86_64-linux-gnu/libc.so.6(+0x280d0) [0x7ff35fe280d0]
[bt]: (35) /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x89) [0x7ff35fe28189]
[bt]: (36) install/bin/xournalpp(_start+0x25) [0x5648b31c1e95]


Try to get a better stracktrace...
[bt] #1 install/bin/xournalpp(+0x426b3d) [0x5648b31c2b3d]
crashHandler(int) bei /home/roland/dev/Reviews/xournalpp/src/core/control/CrashHandlerUnix.h:157
[bt] #2 /lib/x86_64-linux-gnu/libc.so.6(+0x42910) [0x7ff35fe42910]
?? ??:0
[bt] #3 install/bin/xournalpp(+0x6543d0) [0x5648b33f03d0]
Plugin::populateMenuSection(_GtkApplicationWindow*, unsigned long)::{lambda(_GSimpleAction*, _GVariant*, MenuEntry*)#1}::operator()(_GSimpleAction*, _GVariant*, MenuEntry*) const bei /home/roland/dev/Reviews/xournalpp/src/core/plugin/Plugin.cpp:101
[bt] #4 install/bin/xournalpp(+0x654415) [0x5648b33f0415]
Plugin::populateMenuSection(_GtkApplicationWindow*, unsigned long)::{lambda(_GSimpleAction*, _GVariant*, MenuEntry*)#1}::_FUN(_GSimpleAction*, _GVariant*, MenuEntry*) bei /home/roland/dev/Reviews/xournalpp/src/core/plugin/Plugin.cpp:101
[bt] #5 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_closure_invoke+0x140) [0x7ff360918130]
?? ??:0
[bt] #6 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(+0x424ac) [0x7ff3609454ac]
?? ??:0
[bt] #7 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(+0x339b1) [0x7ff3609369b1]
?? ??:0
[bt] #8 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_signal_emit_valist+0x36) [0x7ff360936bd6]
?? ??:0
[bt] #9 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_signal_emit+0x93) [0x7ff360936c93]
?? ??:0
[bt] #10 /lib/x86_64-linux-gnu/libgio-2.0.so.0(+0xe8bbd) [0x7ff360a7bbbd]
?? ??:0
[bt] #11 /lib/x86_64-linux-gnu/libgtk-3.so.0(+0x20a216) [0x7ff36120a216]
?? ??:0
[bt] #12 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_closure_invoke+0x140) [0x7ff360918130]
?? ??:0
[bt] #13 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(+0x424ac) [0x7ff3609454ac]
?? ??:0
[bt] #14 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(+0x339b1) [0x7ff3609369b1]
?? ??:0
[bt] #15 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_signal_emit_valist+0x36) [0x7ff360936bd6]
?? ??:0
[bt] #16 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_signal_emit+0x93) [0x7ff360936c93]
?? ??:0
[bt] #17 /lib/x86_64-linux-gnu/libgtk-3.so.0(gtk_widget_activate+0x7c) [0x7ff36134284c]
?? ??:0
[bt] #18 /lib/x86_64-linux-gnu/libgtk-3.so.0(gtk_menu_shell_activate_item+0xe6) [0x7ff36120d636]
?? ??:0
[bt] #19 /lib/x86_64-linux-gnu/libgtk-3.so.0(+0x20d969) [0x7ff36120d969]
?? ??:0
[bt] #20 /lib/x86_64-linux-gnu/libgtk-3.so.0(+0x980d8) [0x7ff3610980d8]
?? ??:0
[bt] #21 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(+0x33add) [0x7ff360936add]
?? ??:0
[bt] #22 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_signal_emit_valist+0x36) [0x7ff360936bd6]
?? ??:0
[bt] #23 /lib/x86_64-linux-gnu/libgobject-2.0.so.0(g_signal_emit+0x93) [0x7ff360936c93]
?? ??:0
[bt] #24 /lib/x86_64-linux-gnu/libgtk-3.so.0(+0x34f154) [0x7ff36134f154]
?? ??:0
[bt] #25 /lib/x86_64-linux-gnu/libgtk-3.so.0(+0x1f7b1e) [0x7ff3611f7b1e]
?? ??:0
[bt] #26 /lib/x86_64-linux-gnu/libgtk-3.so.0(gtk_main_do_event+0x986) [0x7ff3611f85f6]
?? ??:0
[bt] #27 /lib/x86_64-linux-gnu/libgdk-3.so.0(+0x398b7) [0x7ff3618a28b7]
?? ??:0
[bt] #28 /lib/x86_64-linux-gnu/libgdk-3.so.0(+0x8fb16) [0x7ff3618f8b16]
?? ??:0
[bt] #29 /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x5ab2c) [0x7ff360e34b2c]
?? ??:0
[bt] #30 /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0xb646f) [0x7ff360e9046f]
?? ??:0
[bt] #31 /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x30) [0x7ff360e32d20]
?? ??:0


Execution log:

DEBUG   : GLib-GIO :: Using cross-namespace EXTERNAL authentication (this will deadlock if server is GDBus < 2.73.3)
DEBUG   : GLib-GIO :: _g_io_module_get_default: Found default implementation gvfs (GDaemonVfs) for ‘gio-vfs’
DEBUG   : GLib :: unsetenv() is not thread-safe and should not be used after threads are created
MESSAGE : xopp :: TEXTDOMAINDIR = (null), Platform-specific locale dir = /home/roland/dev/Reviews/xournalpp/build/install/share/xournalpp/../locale, chosen directory = /home/roland/dev/Reviews/xournalpp/build/install/share/xournalpp/../locale
INFO    : xopp :: Loading plugins from: /home/roland/dev/Reviews/xournalpp/build/install/share/xournalpp/plugins
INFO    : xopp :: Loading plugins from: /home/roland/.config/xournalpp/plugins
MESSAGE : xopp :: Plugin "FunctionPlotter" UI initialized
MESSAGE : xopp :: Plugin "MigrateFontSizes" UI initialized
MESSAGE : xopp :: Plugin "ShortcutsPlugin" UI initialized
MESSAGE : xopp :: Plugin "Test" UI initialized
MESSAGE : xopp :: Add toolbar button with id: Plugin::MIRROR and icon: mytest
MESSAGE : xopp :: Add toolbar button with id: Plugin::FINE_BLACK_LINE and icon: document-edit
WARNING : xopp :: [Crash Handler] Crashed with signal 11
WARNING : xopp :: [Crash Handler] Wrote crash log to: /home/roland/.cache/xournalpp/errorlogs/errorlog.20231103-191606.log

@Febbe
Copy link
Collaborator

Febbe commented Nov 3, 2023

@rolandlo I think we want to merge this into 1.2 since it is mostly a bugfix. my approach refactores that, and replaces it with std::stacktrace.

@tmoerschell
Copy link
Contributor Author

tmoerschell commented Nov 4, 2023

?? ??:0 is printed when nothing is found at the given address in the given file (because it's not from the xournalpp executable). It can be improved a little by passing the correct executable as an argument, but not by much.
I noticed eu-addr2line (from elfutils) will give better results for library calls, while addr2line has better results for the rest.

Compare:

Details

using addr2line

[bt] #0 /home/Thomas/xournalpp/build/xournalpp(+0x33b609) [0x5581e8a5d609]
crashHandler(int) at /home/Thomas/xournalpp/src/core/control/CrashHandlerUnix.h:155
[bt] #1 /lib64/libc.so.6(+0x3f190) [0x7fd8de23f190]
?? ??:0
[bt] #2 /home/Thomas/xournalpp/build/xournalpp(+0x3431e4) [0x5581e8a651e4]
(anonymous namespace)::checkForEmergencySave(Control*) at /home/Thomas/xournalpp/src/core/control/XournalMain.cpp:217
[bt] #3 /home/Thomas/xournalpp/build/xournalpp(+0x340629) [0x5581e8a62629]
(anonymous namespace)::on_startup(_GApplication*, (anonymous namespace)::XournalMainPrivate*) at /home/Thomas/xournalpp/src/core/control/XournalMain.cpp:569
[bt] #4 /lib64/libgobject-2.0.so.0(g_closure_invoke+0x138) [0x7fd8dec59468]
g_closure_invoke at ??:?
[bt] #5 /lib64/libgobject-2.0.so.0(+0x2a61c) [0x7fd8dec6c61c]
?? ??:0
[bt] #6 /lib64/libgobject-2.0.so.0(+0x2c031) [0x7fd8dec6e031]
?? ??:0
[bt] #7 /lib64/libgobject-2.0.so.0(g_signal_emit_valist+0x32) [0x7fd8dec73ce2]
g_signal_emit_valist at ??:?
[bt] #8 /lib64/libgobject-2.0.so.0(g_signal_emit+0x8f) [0x7fd8dec73d8f]
g_signal_emit at ??:?
[bt] #9 /lib64/libgio-2.0.so.0(g_application_register+0x112) [0x7fd8dedb9e22]
g_application_register at ??:?
[bt] #10 /lib64/libgio-2.0.so.0(+0xe91ca) [0x7fd8dedba1ca]
?? ??:0
[bt] #11 /lib64/libgio-2.0.so.0(g_application_run+0x106) [0x7fd8dedba4e6]
g_application_run at ??:?
[bt] #12 /home/Thomas/xournalpp/build/xournalpp(_ZN11XournalMain3runEiPPc+0x817) [0x5581e8a60047]
XournalMain::run(int, char**) at /home/Thomas/xournalpp/src/core/control/XournalMain.cpp:731
[bt] #13 /home/Thomas/xournalpp/build/xournalpp(main+0x27) [0x5581e8a5c917]
main at /home/Thomas/xournalpp/src/exe/Xournalpp.cpp:52
[bt] #14 /lib64/libc.so.6(+0x281b0) [0x7fd8de2281b0]
?? ??:0
[bt] #15 /lib64/libc.so.6(__libc_start_main+0x8b) [0x7fd8de228279]
?? ??:0
[bt] #16 /home/Thomas/xournalpp/build/xournalpp(_start+0x27) [0x5581e8a5c825]
_start at /home/abuild/rpmbuild/BUILD/glibc-2.38/csu/../sysdeps/x86_64/start.S:117

using eu-addr2line:

[bt] #0 /home/Thomas/xournalpp/build/xournalpp(+0x33b609) [0x55a773105609]
crashHandler(int) at ??:0
[bt] #1 /lib64/libc.so.6(+0x3f190) [0x7f9603e3f190]
__restore_rt at ??:0
[bt] #2 /home/Thomas/xournalpp/build/xournalpp(+0x3431e4) [0x55a77310d1e4]
(anonymous namespace)::checkForEmergencySave(Control*) at ??:0
[bt] #3 /home/Thomas/xournalpp/build/xournalpp(+0x340629) [0x55a77310a629]
(anonymous namespace)::on_startup(_GApplication*, (anonymous namespace)::XournalMainPrivate*) at ??:0
[bt] #4 /lib64/libgobject-2.0.so.0(g_closure_invoke+0x138) [0x7f96049bf468]
closure_invoke_notifiers at /usr/src/debug/glib-2.78.1/x86_64-suse-linux/../gobject/gclosure.c:300:14
[bt] #5 /lib64/libgobject-2.0.so.0(+0x2a61c) [0x7f96049d261c]
accumulate at /usr/src/debug/glib-2.78.1/x86_64-suse-linux/../gobject/gsignal.c:3315:6
[bt] #6 /lib64/libgobject-2.0.so.0(+0x2c031) [0x7f96049d4031]
signal_emit_valist_unlocked at /usr/src/debug/glib-2.78.1/x86_64-suse-linux/../gobject/gsignal.c:3613:7
[bt] #7 /lib64/libgobject-2.0.so.0(g_signal_emit_valist+0x32) [0x7f96049d9ce2]
g_signal_emit_valist at /usr/src/debug/glib-2.78.1/x86_64-suse-linux/../gobject/gsignal.c:3355:6
[bt] #8 /lib64/libgobject-2.0.so.0(g_signal_emit+0x8f) [0x7f96049d9d8f]
g_signal_emit at /usr/src/debug/glib-2.78.1/x86_64-suse-linux/../gobject/gsignal.c:3677:1
[bt] #9 /lib64/libgio-2.0.so.0(g_application_register+0x112) [0x7f9604af2e22]
g_application_register at /usr/src/debug/glib-2.78.1/x86_64-suse-linux/../gio/gapplication.c:2219:15
[bt] #10 /lib64/libgio-2.0.so.0(+0xe91ca) [0x7f9604af31ca]
g_application_real_local_command_line at /usr/src/debug/glib-2.78.1/x86_64-suse-linux/../gio/gapplication.c:1119:6
[bt] #11 /lib64/libgio-2.0.so.0(g_application_run+0x106) [0x7f9604af34e6]
g_application_run at /usr/src/debug/glib-2.78.1/x86_64-suse-linux/../gio/gapplication.c:2546:6
[bt] #12 /home/Thomas/xournalpp/build/xournalpp(_ZN11XournalMain3runEiPPc+0x817) [0x55a773108047]
XournalMain::run(int, char**) at ??:0
[bt] #13 /home/Thomas/xournalpp/build/xournalpp(main+0x27) [0x55a773104917]
main at ??:0
[bt] #14 /lib64/libc.so.6(+0x281b0) [0x7f9603e281b0]
__libc_start_call_main at /usr/src/debug/glibc-2.38/csu/../sysdeps/nptl/libc_start_call_main.h:74:3
[bt] #15 /lib64/libc.so.6(__libc_start_main+0x8b) [0x7f9603e28279]
[bt] #16 /home/Thomas/xournalpp/build/xournalpp(_start+0x27) [0x55a773104825]
_start at /home/abuild/rpmbuild/BUILD/glibc-2.38/csu/../sysdeps/x86_64/start.S:117

Should we make a case distinction for that (use addr2line for xournalpp calls and eu-addr2line for library calls)?

I hadn't seen your work @Febbe. It looks very good as well. So your idea would be to put this PR into the next minor release and change to yours when it'll be done?

@rolandlo
Copy link
Member

rolandlo commented Nov 4, 2023

@rolandlo I think we want to merge this into 1.2 since it is mostly a bugfix. my approach refactores that, and replaces it with std::stacktrace.

I agree that this should be rebased onto release-1.2.

@rolandlo
Copy link
Member

rolandlo commented Nov 4, 2023

Should we make a case distinction for that (use addr2line for xournalpp calls and eu-addr2line for library calls)?

From the example that would make sense. How does this work out if you run xournalpp with preloading say a self-built Debug version of Gtk using LD_PRELOAD? Maybe you can add a commit that makes that change and we can experiment with it.

Copy link
Collaborator

@Febbe Febbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to just use libbacktrace directly. It uses libunwind instead of addr2line.

src/util/Stacktrace.cpp Outdated Show resolved Hide resolved
src/util/Stacktrace.cpp Outdated Show resolved Hide resolved
src/util/Stacktrace.cpp Outdated Show resolved Hide resolved
@Febbe
Copy link
Collaborator

Febbe commented Nov 4, 2023

Should we make a case distinction for that (use addr2line for xournalpp calls and eu-addr2line for library calls)?

There should be something else which is wrong.

I hadn't seen your work @Febbe. It looks very good as well. So your idea would be to put this PR into the next minor release and change to yours when it'll be done?

Yes your approach just improves/fixes the current behavior which has been broken by ASLR. My approach adds stacktraces to all OS's, by replacing the stacktrace backend, which is a refactoring.

@tmoerschell
Copy link
Contributor Author

libbacktrace looks very easy to use, but I can't figure out how to have it link correctly with cmake (I'm a complete novice to cmake). Also this would imply an additional dependency to build along with Xournal++ if I understand this right?

@rolandlo rolandlo mentioned this pull request Nov 5, 2023
@Febbe
Copy link
Collaborator

Febbe commented Nov 5, 2023

libbacktrace looks very easy to use, but I can't figure out how to have it link correctly with cmake (I'm a complete novice to cmake). Also this would imply an additional dependency to build along with Xournal++ if I understand this right?

Yeah, just was an idea, I would like to see the simpler solution from yourself merged.
But if you have interest, how to integrate such projects into CMake, take a look into my fbbe::stacktrace project. There, I use libbacktrace as backend for fbbe::/std::stacktrace.

@tmoerschell tmoerschell changed the base branch from master to release-1.2 November 5, 2023 22:28
@tmoerschell
Copy link
Contributor Author

Ok, so since we have to look up the object base load address anyways, we might as well use it directly up front, with no edgy text parsing. The pointer arithmetic isn't very pretty and if someone finds a better way to do that it'd be wonderful.

There is still a difference between addr2line and eu-addr2line. But I suspect that's because they load debug symbols in a different manner: eu-addr2line probably uses debuginfod, but can't find xournalpp's debug symbols (?!?), while addr2line won't find the separately installed library debug symbols. It will probably give complete results when using self-built debug libraries.

Note that Stacktrace::getExePath() isn't used inside Stacktrace anymore. Would it make sense to move it somewhere else?
Would it also make sense to remove reimpression of the backtrace_symbols() messages? We can print necessary information directly from what's returned by dladdr() (backtrace_symbols() itself uses dladdr()).

@rolandlo
Copy link
Member

rolandlo commented Nov 6, 2023

Note that Stacktrace::getExePath() isn't used inside Stacktrace anymore. Would it make sense to move it somewhere else?

I would move it to PathUtil.

@Febbe
Copy link
Collaborator

Febbe commented Nov 6, 2023

Note that Stacktrace::getExePath() isn't used inside Stacktrace anymore. Would it make sense to move it somewhere else?

I would move it to PathUtil

I think, I've already did that in my PR.

@tmoerschell
Copy link
Contributor Author

I think, I've already did that in my PR.

So does that mean no need to do it here?

@Febbe
Copy link
Collaborator

Febbe commented Nov 6, 2023

I think, I've already did that in my PR.

So does that mean no need to do it here?

Either that, or that you should move it exactly like I did.

src/util/Stacktrace.cpp Outdated Show resolved Hide resolved
@rolandlo
Copy link
Member

rolandlo commented Nov 7, 2023

There is still a difference between addr2line and eu-addr2line. But I suspect that's because they load debug symbols in a different manner: eu-addr2line probably uses debuginfod, but can't find xournalpp's debug symbols (?!?), while addr2line won't find the separately installed library debug symbols. It will probably give complete results when using self-built debug libraries.

I can confirm that the current version works fine with self-built debug libraries. See this example:

Crash log when preloading gtk, gdk, goject, glib and gio
Date: Tue Nov  7 03:07:02 2023
Error: signal 11
Xournal++ version 1.2.3~dev
Git commit bfa0c3a2 from rolandlo/pr/tmoerschell/5312
Gtk version 3.24.39

[bt]: (0) install/bin/xournalpp(+0x380375) [0x559a6e12c375]
[bt]: (1) /lib/x86_64-linux-gnu/libc.so.6(+0x42910) [0x7fb626642910]
[bt]: (2) install/bin/xournalpp(+0x58a786) [0x559a6e336786]
[bt]: (3) install/bin/xournalpp(+0x58a7cb) [0x559a6e3367cb]
[bt]: (4) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_cclosure_marshal_VOID__VARIANT+0xdf) [0x7fb6278ac87a]
[bt]: (5) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_closure_invoke+0x1e5) [0x7fb6278a6337]
[bt]: (6) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(+0x3d27f) [0x7fb6278ca27f]
[bt]: (7) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(+0x3bf72) [0x7fb6278c8f72]
[bt]: (8) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_signal_emit_valist+0x3f) [0x7fb6278c7b59]
[bt]: (9) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_signal_emit+0xbc) [0x7fb6278c952e]
[bt]: (10) /home/roland/dev/glib/build/gio/libgio-2.0.so(+0x14c820) [0x7fb62754c820]
[bt]: (11) /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_activate+0xdd) [0x7fb62754a908]
[bt]: (12) /home/roland/dev/glib/build/gio/libgio-2.0.so(+0x146863) [0x7fb627546863]
[bt]: (13) /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
[bt]: (14) /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
[bt]: (15) /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
[bt]: (16) /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
[bt]: (17) /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
[bt]: (18) /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
[bt]: (19) /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
[bt]: (20) /home/roland/dev/gtk/build/gtk/libgtk-3.so(+0x222466) [0x7fb627c22466]
[bt]: (21) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_cclosure_marshal_VOID__VOID+0xcc) [0x7fb6278aa5f1]
[bt]: (22) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_closure_invoke+0x1e5) [0x7fb6278a6337]
[bt]: (23) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(+0x3d27f) [0x7fb6278ca27f]
[bt]: (24) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(+0x3bf72) [0x7fb6278c8f72]
[bt]: (25) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_signal_emit_valist+0x3f) [0x7fb6278c7b59]
[bt]: (26) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_signal_emit+0xbc) [0x7fb6278c952e]
[bt]: (27) /home/roland/dev/gtk/build/gtk/libgtk-3.so(gtk_widget_activate+0x7c) [0x7fb627d5c34c]
[bt]: (28) /home/roland/dev/gtk/build/gtk/libgtk-3.so(gtk_menu_shell_activate_item+0xe6) [0x7fb627c1e816]
[bt]: (29) /home/roland/dev/gtk/build/gtk/libgtk-3.so(+0x21eb44) [0x7fb627c1eb44]
[bt]: (30) /home/roland/dev/gtk/build/gtk/libgtk-3.so(+0x9ac78) [0x7fb627a9ac78]
[bt]: (31) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(+0x19b52) [0x7fb6278a6b52]
[bt]: (32) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(+0x19656) [0x7fb6278a6656]
[bt]: (33) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(+0x3b20a) [0x7fb6278c820a]
[bt]: (34) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_signal_emit_valist+0x3f) [0x7fb6278c7b59]
[bt]: (35) /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_signal_emit+0xbc) [0x7fb6278c952e]
[bt]: (36) /home/roland/dev/gtk/build/gtk/libgtk-3.so(+0x359614) [0x7fb627d59614]
[bt]: (37) /home/roland/dev/gtk/build/gtk/libgtk-3.so(+0x208c3e) [0x7fb627c08c3e]
[bt]: (38) /home/roland/dev/gtk/build/gtk/libgtk-3.so(gtk_main_do_event+0x6ae) [0x7fb627c0a7fe]
[bt]: (39) /home/roland/dev/gtk/build/gdk/libgdk-3.so(+0x3ed39) [0x7fb62793ed39]
[bt]: (40) /home/roland/dev/gtk/build/gdk/libgdk-3.so(+0x6c966) [0x7fb62796c966]
[bt]: (41) /home/roland/dev/glib/build/glib/libglib-2.0.so(+0x72afc) [0x7fb627778afc]
[bt]: (42) /home/roland/dev/glib/build/glib/libglib-2.0.so(+0x73c7c) [0x7fb627779c7c]
[bt]: (43) /home/roland/dev/glib/build/glib/libglib-2.0.so(+0x73e43) [0x7fb627779e43]
[bt]: (44) /home/roland/dev/glib/build/glib/libglib-2.0.so(g_main_context_iteration+0x4e) [0x7fb627779f17]
[bt]: (45) /home/roland/dev/glib/build/gio/libgio-2.0.so(g_application_run+0x37c) [0x7fb62753faa2]
[bt]: (46) install/bin/xournalpp(_ZN11XournalMain3runEiPPc+0x7da) [0x559a6e13485d]
[bt]: (47) install/bin/xournalpp(main+0x29) [0x559a6e12bf32]
[bt]: (48) /lib/x86_64-linux-gnu/libc.so.6(+0x280d0) [0x7fb6266280d0]
[bt]: (49) /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x89) [0x7fb626628189]
[bt]: (50) install/bin/xournalpp(_start+0x25) [0x559a6e12be45]


Try to get a better stacktrace...
[bt] #0 install/bin/xournalpp(+0x380aed) [0x559a6e12caed]
crashHandler(int) bei /home/roland/dev/Reviews/xournalpp/src/core/control/CrashHandlerUnix.h:157
[bt] #1 /lib/x86_64-linux-gnu/libc.so.6(+0x42910) [0x7fb626642910]
__restore_rt bei libc_sigaction.c:?
[bt] #2 install/bin/xournalpp(+0x58a786) [0x559a6e336786]
Plugin::populateMenuSection(_GtkApplicationWindow*, unsigned long)::{lambda(_GSimpleAction*, _GVariant*, MenuEntry*)#1}::operator()(_GSimpleAction*, _GVariant*, MenuEntry*) const bei /home/roland/dev/Reviews/xournalpp/src/core/plugin/Plugin.cpp:101
[bt] #3 install/bin/xournalpp(+0x58a7cb) [0x559a6e3367cb]
Plugin::populateMenuSection(_GtkApplicationWindow*, unsigned long)::{lambda(_GSimpleAction*, _GVariant*, MenuEntry*)#1}::_FUN(_GSimpleAction*, _GVariant*, MenuEntry*) bei /home/roland/dev/Reviews/xournalpp/src/core/plugin/Plugin.cpp:101
[bt] #4 /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_cclosure_marshal_VOID__VARIANT+0xdf) [0x7fb6278ac87a]
g_cclosure_marshal_VOID__VARIANT bei /home/roland/dev/glib/build/../gobject/gmarshal.c:1967
[bt] #5 /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_closure_invoke+0x1e5) [0x7fb6278a6337]
g_closure_invoke bei /home/roland/dev/glib/build/../gobject/gclosure.c:839
[bt] #6 /home/roland/dev/glib/build/gobject/libgobject-2.0.so(+0x3d27f) [0x7fb6278ca27f]
signal_emit_unlocked_R bei /home/roland/dev/glib/build/../gobject/gsignal.c:3892
[bt] #7 /home/roland/dev/glib/build/gobject/libgobject-2.0.so(+0x3bf72) [0x7fb6278c8f72]
signal_emit_valist_unlocked bei /home/roland/dev/glib/build/../gobject/gsignal.c:3520
[bt] #8 /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_signal_emit_valist+0x3f) [0x7fb6278c7b59]
g_signal_emit_valist bei /home/roland/dev/glib/build/../gobject/gsignal.c:3262 (discriminator 1)
[bt] #9 /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_signal_emit+0xbc) [0x7fb6278c952e]
g_signal_emit bei /home/roland/dev/glib/build/../gobject/gsignal.c:3584
[bt] #10 /home/roland/dev/glib/build/gio/libgio-2.0.so(+0x14c820) [0x7fb62754c820]
g_simple_action_activate bei /home/roland/dev/glib/build/../gio/gsimpleaction.c:217
[bt] #11 /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_activate+0xdd) [0x7fb62754a908]
g_action_activate bei /home/roland/dev/glib/build/../gio/gaction.c:392
[bt] #12 /home/roland/dev/glib/build/gio/libgio-2.0.so(+0x146863) [0x7fb627546863]
g_simple_action_group_activate bei /home/roland/dev/glib/build/../gio/gsimpleactiongroup.c:140
[bt] #13 /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
g_action_group_activate_action bei /home/roland/dev/glib/build/../gio/gactiongroup.c:625
[bt] #14 /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
g_action_group_activate_action bei /home/roland/dev/glib/build/../gio/gactiongroup.c:625
[bt] #15 /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
g_action_group_activate_action bei /home/roland/dev/glib/build/../gio/gactiongroup.c:625
[bt] #16 /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
g_action_group_activate_action bei /home/roland/dev/glib/build/../gio/gactiongroup.c:625
[bt] #17 /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
g_action_group_activate_action bei /home/roland/dev/glib/build/../gio/gactiongroup.c:625
[bt] #18 /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
g_action_group_activate_action bei /home/roland/dev/glib/build/../gio/gactiongroup.c:625
[bt] #19 /home/roland/dev/glib/build/gio/libgio-2.0.so(g_action_group_activate_action+0xff) [0x7fb627545837]
g_action_group_activate_action bei /home/roland/dev/glib/build/../gio/gactiongroup.c:625
[bt] #20 /home/roland/dev/gtk/build/gtk/libgtk-3.so(+0x222466) [0x7fb627c22466]
gtk_menu_tracker_item_activated bei /home/roland/dev/gtk/build/../gtk/gtkmenutrackeritem.c:801
[bt] #21 /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_cclosure_marshal_VOID__VOID+0xcc) [0x7fb6278aa5f1]
g_cclosure_marshal_VOID__VOID bei /home/roland/dev/glib/build/../gobject/gmarshal.c:119
[bt] #22 /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_closure_invoke+0x1e5) [0x7fb6278a6337]
g_closure_invoke bei /home/roland/dev/glib/build/../gobject/gclosure.c:839
[bt] #23 /home/roland/dev/glib/build/gobject/libgobject-2.0.so(+0x3d27f) [0x7fb6278ca27f]
signal_emit_unlocked_R bei /home/roland/dev/glib/build/../gobject/gsignal.c:3892
[bt] #24 /home/roland/dev/glib/build/gobject/libgobject-2.0.so(+0x3bf72) [0x7fb6278c8f72]
signal_emit_valist_unlocked bei /home/roland/dev/glib/build/../gobject/gsignal.c:3520
[bt] #25 /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_signal_emit_valist+0x3f) [0x7fb6278c7b59]
g_signal_emit_valist bei /home/roland/dev/glib/build/../gobject/gsignal.c:3262 (discriminator 1)
[bt] #26 /home/roland/dev/glib/build/gobject/libgobject-2.0.so(g_signal_emit+0xbc) [0x7fb6278c952e]
g_signal_emit bei /home/roland/dev/glib/build/../gobject/gsignal.c:3584
[bt] #27 /home/roland/dev/gtk/build/gtk/libgtk-3.so(gtk_widget_activate+0x7c) [0x7fb627d5c34c]
gtk_widget_activate bei /home/roland/dev/gtk/build/../gtk/gtkwidget.c:7851
[bt] #28 /home/roland/dev/gtk/build/gtk/libgtk-3.so(gtk_menu_shell_activate_item+0xe6) [0x7fb627c1e816]
gtk_menu_shell_activate_item bei /home/roland/dev/gtk/build/../gtk/gtkmenushell.c:1377 (discriminator 1)
[bt] #29 /home/roland/dev/gtk/build/gtk/libgtk-3.so(+0x21eb44) [0x7fb627c1eb44]
gtk_menu_shell_button_release bei /home/roland/dev/gtk/build/../gtk/gtkmenushell.c:871
[bt] #30 /home/roland/dev/gtk/build/gtk/libgtk-3.so(+0x9ac78) [0x7fb627a9ac78]
_gtk_marshal_BOOLEAN__BOXEDv bei /home/roland/dev/gtk/build/gtk/gtkmarshalers.c:133


Execution log:

DEBUG   : GLib-GIO :: Using cross-namespace EXTERNAL authentication (this will deadlock if server is GDBus < 2.73.3)
DEBUG   : GLib-GIO :: _g_io_module_get_default: Found default implementation local (GLocalVfs) for ‘gio-vfs’
DEBUG   : GLib-GIO :: _g_io_module_get_default: Found default implementation keyfile (GKeyfileSettingsBackend) for ‘gsettings-backend’
DEBUG   : GLib :: unsetenv() is not thread-safe and should not be used after threads are created
MESSAGE : xopp :: TEXTDOMAINDIR = (null), Platform-specific locale dir = /home/roland/dev/Reviews/xournalpp/build/install/share/xournalpp/../locale, chosen directory = /home/roland/dev/Reviews/xournalpp/build/install/share/xournalpp/../locale
INFO    : xopp :: Loading plugins from: /home/roland/dev/Reviews/xournalpp/build/install/share/xournalpp/plugins
INFO    : xopp :: Loading plugins from: /home/roland/.config/xournalpp/plugins
MESSAGE : xopp :: Plugin "FunctionPlotter" UI initialized
MESSAGE : xopp :: Plugin "MigrateFontSizes" UI initialized
MESSAGE : xopp :: Plugin "ShortcutsPlugin" UI initialized
MESSAGE : xopp :: Plugin "Test" UI initialized
MESSAGE : xopp :: Add toolbar button with id: Plugin::MIRROR and icon: mytest
MESSAGE : xopp :: Add toolbar button with id: Plugin::FINE_BLACK_LINE and icon: document-edit
WARNING : xopp :: [Crash Handler] Crashed with signal 11
WARNING : xopp :: [Crash Handler] Wrote crash log to: /home/roland/.cache/xournalpp/errorlogs/errorlog.20231107-030702.log

Copy link
Collaborator

@Febbe Febbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your awesome work.
Can you please stash all your changes?

src/util/include/util/safe_casts.h Outdated Show resolved Hide resolved
src/util/Stacktrace.cpp Show resolved Hide resolved
src/util/Stacktrace.cpp Outdated Show resolved Hide resolved
@Febbe
Copy link
Collaborator

Febbe commented Nov 7, 2023

@rolandlo thank you for the visual testing.

@tmoerschell
Copy link
Contributor Author

Thank you for your awesome work. Can you please stash all your changes?

Do you mean squash?

@Febbe
Copy link
Collaborator

Febbe commented Nov 7, 2023

squash

Yes :D

@tmoerschell
Copy link
Contributor Author

Ok, done. Thank you @Febbe and @rolandlo for the review and testing!

@Febbe
Copy link
Collaborator

Febbe commented Nov 8, 2023

@rolandlo when you are also fine with it, you can merge it directly, I'll do it otherwise in the late evening MET .

Copy link
Member

@rolandlo rolandlo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except of the obsolete header file includes this looks good to me.

src/util/Stacktrace.cpp Outdated Show resolved Hide resolved
@Febbe Febbe merged commit 0d97d71 into xournalpp:release-1.2 Nov 8, 2023
5 checks passed
@Febbe
Copy link
Collaborator

Febbe commented Nov 8, 2023

Thank you @tmoerschell, this hopefully helps to find more bugs and crashes.

@tmoerschell
Copy link
Contributor Author

It's always a pleasure to contribute! Thanks to you guys!

@tmoerschell tmoerschell deleted the improve-backtrace branch November 8, 2023 16:42
@bhennion bhennion added this to the v1.2.3 milestone Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants