cppit / jucipp

A lightweight & cross-platform IDE supporting the most recent C++ standards. This project has moved to https://gitlab.com/cppit/jucipp.
https://gitlab.com/cppit/jucipp
MIT License
882 stars 98 forks source link

Crash when closing open files #383

Closed kzampog closed 6 years ago

kzampog commented 6 years ago

The IDE occasionally crashes when I close open file tabs. This appears to happen at random, roughly one in eight times. It does not seem to matter how many tabs I have open.

Crashes happen on 2 machines, both running Linux Mint 18.3, fully up-to-date. Please let me know where I should look to provide further logs/info.

Thanks!

eidheim commented 6 years ago

Thank you for reporting this.

I can't reproduce this on other Linux distributions. Are you using latest jucipp master? Which file types are you closing when the crash happen?

If you receive a core dump, please post the backtrace here.

eidheim commented 6 years ago

I also did test Mint Cinnamon 18.3, without being able to reproduce the crash. Could you also give me additional information about your setup? Also, are the files you open and close on local disk or elsewhere?

eidheim commented 6 years ago

Additionally, have you made any changes to your preference file?

jagannatharjun commented 6 years ago

i did experience some segmentation faults on msys2

i changed the font size and theme in prefereneces

eidheim commented 6 years ago

Thank you @jagannatharjun . Do you have a reliable way to reproduce this segmentation fault?

jagannatharjun commented 6 years ago

i feel like they are random and also #382 exists for quite a time and was using a very bad fix for that until yesterday

but juci always print this (juci:7652): glibmm-CRITICAL **: 18:37:58.760: Class::register_derived_type(): base_query.type_name is NULL. and sometimes more then once

eidheim commented 6 years ago

@kzampog I just pushed https://github.com/cppit/jucipp/commit/06f2caca8e09b70dc8d62a46aba4fde948ab7b51 to master to avoid undefined behaviour on read/write of an bool value on different threads (found this issue using llvm's thread sanitizer). Does this fix your crash?

kzampog commented 6 years ago

Hi again!

I rebuilt the latest commit, but, unfortunately, the crashes are still there.

Additional info:

GDB backtrace of a debug build:

GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./juci...done.
[New LWP 8594]
[New LWP 8489]
[New LWP 8561]
[New LWP 8382]
[New LWP 8557]
[New LWP 8552]
[New LWP 8508]
[New LWP 8582]
[New LWP 8383]
[New LWP 8499]
[New LWP 8381]
[New LWP 8610]
[New LWP 8568]
[New LWP 8560]
[New LWP 8494]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./juci'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f1a5bcc8e81 in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
[Current thread is 1 (Thread 0x7f19b7fff700 (LWP 8594))]
(gdb) bt
#0  0x00007f1a5bcc8e81 in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#1  0x00007f1a5bcc9e22 in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#2  0x00007f1a5bcd1879 in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#3  0x00007f1a5bcc9e8b in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#4  0x00007f1a5bcca0c5 in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#5  0x00007f1a5bcca66d in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#6  0x00007f1a5bcd21a4 in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#7  0x00007f1a5bcca1a3 in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#8  0x00007f1a5bcca66d in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#9  0x00007f1a5bccdfcd in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#10 0x00007f1a5bcce0f6 in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#11 0x00007f1a5bcca1a3 in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#12 0x00007f1a5bcca66d in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#13 0x00007f1a5bccdfcd in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#14 0x00007f1a5bcce0f6 in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#15 0x00007f1a5bcca1a3 in ?? () from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#16 0x00007f1a5bcd3384 in clang_visitChildren ()
   from /usr/lib/llvm-4.0/lib/libclang-4.0.so.1
#17 0x0000000000a906f7 in clangmm::Tokens::Tokens (this=0x7f19ff8afa80, 
    cx_tu=@0x235f9e0: 0x7f1a04001030, range=..., annotate_tokens=true)
    at /home/kzampog/Applications/jucipp/libclangmm/src/tokens.cc:77
#18 0x0000000000a939c6 in clangmm::TranslationUnit::get_tokens (
    this=0x235f9e0, 
    path="/home/kzampog/Coding/cilantro/include/cilantro/connected_component_segmentation.hpp", start_offset=0, end_offset=24234)
    at /home/kzampog/Applications/jucipp/libclangmm/src/translation_unit.cc:108
#19 0x0000000000a40c1d in Usages::Clang::cache (project_path=..., 
    build_path=..., path=..., before_parse_time=1527534514, 
    project_paths_in_use=std::set with 1 elements = {...}, 
    translation_unit=0x235f9e0, tokens=0x7f1a080008c0)
    at /home/kzampog/Applications/jucipp/src/usages_clang.cc:334
#20 0x00000000009b91d2 in Source::ClangView::<lambda()>::operator()(void) const
    (__closure=0x264bf58)
    at /home/kzampog/Applications/jucipp/src/source_clang.cc:1850
#21 0x00000000009c963a in std::_Bind_simple<Source::ClangView::async_delete()::<lambda()>()>::_M_invoke<>(std::_Index_tuple<>) (this=0x264bf58)
    at /usr/include/c++/5/functional:1531
#22 0x00000000009c949c in std::_Bind_simple<Source::ClangView::async_delete()::<lambda()>()>::operator()(void) (this=0x264bf58)
    at /usr/include/c++/5/functional:1520
#23 0x00000000009c936c in std::thread::_Impl<std::_Bind_simple<Source::ClangView::async_delete()::<lambda()>()> >::_M_run(void) (this=0x264bf40)
    at /usr/include/c++/5/thread:115
#24 0x00007f1a5b553c80 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#25 0x00007f1a5b8246ba in start_thread (arg=0x7f19b7fff700)
    at pthread_create.c:333
#26 0x00007f1a5acb941d in clone ()
    at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
(gdb) quit

Config file:

{
    "version": "1.4.3",
    "gtk_theme": {
        "name_comment": "Use \"\" for default theme, At least these two exist on all systems: Adwaita, Raleigh",
        "name": "",
        "variant_comment": "Use \"\" for default variant, and \"dark\" for dark theme variant. Note that not all themes support dark variant, but for instance Adwaita does",
        "variant": ""
    },
    "source": {
        "style_comment": "Use \"\" for default style, and for instance juci-dark or juci-dark-blue together with dark gtk_theme variant. Styles from normal gtksourceview install: classic, cobalt, kate, oblivion, solarized-dark, solarized-light, tango",
        "style": "monokai",
        "font_comment": "Use \"\" for default font, and for instance \"Monospace 12\" to also set size",
        "font": "Source Code Pro",
        "cleanup_whitespace_characters_comment": "Remove trailing whitespace characters on save, and add trailing newline if missing",
        "cleanup_whitespace_characters": "false",
        "show_whitespace_characters_comment": "Determines what kind of whitespaces should be drawn. Use comma-separated list of: space, tab, newline, nbsp, leading, text, trailing or all",
        "show_whitespace_characters": "",
        "format_style_on_save_comment": "Performs clang-format on save for C\/C++ and other curly-bracket languages supported by clang-format",
        "format_style_on_save": "false",
        "format_style_on_save_if_style_file_found_comment": "Format style if format file is found, even if format_style_on_save is false",
        "format_style_on_save_if_style_file_found": "false",
        "smart_brackets_comment": "If smart_inserts is enabled, this option is automatically enabled. When inserting an already closed bracket, the cursor might instead be moved, avoiding the need of arrow keys after autocomplete",
        "smart_brackets": "true",
        "smart_inserts_comment": "When for instance inserting (, () gets inserted. Applies to: (), [], \", '. Also enables pressing ; inside an expression before a final ) to insert ; at the end of line, and deletions of empty insertions",
        "smart_inserts": "true",
        "show_map": "true",
        "map_font_size": "1",
        "show_git_diff": "true",
        "show_background_pattern": "false",
        "show_right_margin": "true",
        "right_margin_position": "120",
        "spellcheck_language_comment": "Use \"\" to set language from your locale settings",
        "spellcheck_language": "en_US",
        "auto_tab_char_and_size_comment": "Use false to always use default tab char and size",
        "auto_tab_char_and_size": "true",
        "default_tab_char_comment": "Use \"\t\" for regular tab",
        "default_tab_char": " ",
        "default_tab_size": "4",
        "tab_indents_line": "false",
        "wrap_lines": "false",
        "highlight_current_line": "true",
        "show_line_numbers": "true",
        "enable_multiple_cursors": "false",
        "auto_reload_changed_files": "false",
        "clang_format_style_comment": "IndentWidth, AccessModifierOffset and UseTab are set automatically. See http:\/\/clang.llvm.org\/docs\/ClangFormatStyleOptions.html",
        "clang_format_style": "ColumnLimit: 0, MaxEmptyLinesToKeep: 2, SpaceBeforeParens: Never, NamespaceIndentation: All, BreakBeforeBraces: Custom, BraceWrapping: {BeforeElse: true, BeforeCatch: true}",
        "clang_usages_threads_comment": "The number of threads used in finding usages in unparsed files. -1 corresponds to the number of cores available, and 0 disables the search",
        "clang_usages_threads": "-1"
    },
    "terminal": {
        "history_size": "1000",
        "font_comment": "Use \"\" to use source.font with slightly smaller size",
        "font": ""
    },
    "keybindings": {
        "preferences": "<primary>comma",
        "quit": "<primary>q",
        "file_new_file": "<primary>n",
        "file_new_folder": "<primary><shift>n",
        "file_open_file": "<primary>o",
        "file_open_folder": "<primary><shift>o",
        "file_reload_file": "",
        "file_save": "<primary>s",
        "file_save_as": "<primary><shift>s",
        "file_print": "",
        "edit_undo": "<primary>z",
        "edit_redo": "<primary><shift>z",
        "edit_cut": "<primary>x",
        "edit_copy": "<primary>c",
        "edit_paste": "<primary>v",
        "edit_find": "<primary>f",
        "source_spellcheck": "",
        "source_spellcheck_clear": "",
        "source_spellcheck_next_error": "<primary><shift>e",
        "source_git_next_diff": "<primary>k",
        "source_git_show_diff": "<alt>k",
        "source_indentation_set_buffer_tab": "",
        "source_indentation_auto_indent_buffer": "<primary><shift>i",
        "source_goto_line": "<primary>g",
        "source_center_cursor": "<primary>l",
        "source_cursor_history_back": "<alt>Left",
        "source_cursor_history_forward": "<alt>Right",
        "source_show_completion_comment": "Add completion keybinding to disable interactive autocompletion",
        "source_show_completion": "",
        "source_find_file": "<primary>p",
        "source_find_symbol": "<primary><shift>f",
        "source_comments_toggle": "<primary>slash",
        "source_comments_add_documentation": "<primary><alt>slash",
        "source_find_documentation": "<primary><shift>d",
        "source_goto_declaration": "<primary>d",
        "source_goto_type_declaration": "<alt><shift>d",
        "source_goto_implementation": "<primary>i",
        "source_goto_usage": "<primary>u",
        "source_goto_method": "<primary>m",
        "source_rename": "<primary>r",
        "source_implement_method": "<primary><shift>m",
        "source_goto_next_diagnostic": "<primary>e",
        "source_apply_fix_its": "<control>space",
        "project_set_run_arguments": "",
        "project_compile_and_run": "<primary>Return",
        "project_compile": "<primary><shift>Return",
        "project_run_command": "<alt>Return",
        "project_kill_last_running": "<primary>Escape",
        "project_force_kill_last_running": "<primary><shift>Escape",
        "debug_set_run_arguments": "",
        "debug_start_continue": "<primary>y",
        "debug_stop": "<primary><shift>y",
        "debug_kill": "<primary><shift>k",
        "debug_step_over": "<primary>j",
        "debug_step_into": "<primary>t",
        "debug_step_out": "<primary><shift>t",
        "debug_backtrace": "<primary><shift>j",
        "debug_show_variables": "<primary><shift>b",
        "debug_run_command": "<alt><shift>Return",
        "debug_toggle_breakpoint": "<primary>b",
        "debug_goto_stop": "<primary><shift>l",
        "window_next_tab": "<primary>Tab",
        "window_previous_tab": "<primary><shift>Tab",
        "window_close_tab": "<primary>w",
        "window_toggle_split": "",
        "window_toggle_full_screen": "F11",
        "window_toggle_tabs": "",
        "window_clear_terminal": ""
    },
    "project": {
        "default_build_path_comment": "Use <project_directory_name> to insert the project top level directory name",
        "default_build_path": ".\/build",
        "debug_build_path_comment": "Use <project_directory_name> to insert the project top level directory name, and <default_build_path> to insert your default_build_path setting.",
        "debug_build_path": "<default_build_path>\/debug",
        "cmake": {
            "command": "cmake",
            "compile_command": "cmake --build . -- -j 32"
        },
        "meson": {
            "command": "meson",
            "compile_command": "ninja"
        },
        "save_on_compile_or_run": "true",
        "clear_terminal_on_compile": "true",
        "ctags_command": "ctags",
        "python_command": "PYTHONUNBUFFERED=1 python"
    },
    "documentation_searches": {
        "clang": {
            "separator": "::",
            "queries": {
                "@empty": "https:\/\/www.google.com\/search?btnI&q=c%2B%2B+",
                "std": "https:\/\/www.google.com\/search?btnI&q=site:http:\/\/www.cplusplus.com\/reference\/+",
                "boost": "https:\/\/www.google.com\/search?btnI&q=site:http:\/\/www.boost.org\/doc\/libs\/1_59_0\/+",
                "Gtk": "https:\/\/www.google.com\/search?btnI&q=site:https:\/\/developer.gnome.org\/gtkmm\/stable\/+",
                "@any": "https:\/\/www.google.com\/search?btnI&q="
            }
        }
    }
}
eidheim commented 6 years ago

@kzampog Thank you very much for the detailed report. At first look, the crash seems to happen in libclang. I did manage to reproduce the "libclang: crash detected while annotating tokens" messages. Will try Tomorrow with a newer version of llvm/libclang

eidheim commented 6 years ago

@kzampog I fixed an iterator bug here: https://github.com/cppit/libclangmm/compare/e8f8a04f98b2259468d50843759caac3c5922bfa...5a0195e1dd55d9b23851c8e2082feecb6e171b0f#diff-62d11623fb3b713711f2a0d394eb1224. The easiest way to try this fix out is to clone the jucipp repository again and compile from scratch: git clone --recursive .....

Also tried to compile the dependencies of the project you linked to in order to test a newer llvm/libclang version. But the compilation of Pangolin failed on Arch Linux. If you ever try a newer llvm/clang version, make sure to skip version 5, and try 6 instead. Version 5 is somewhat buggy.

kzampog commented 6 years ago

Thank you very much for investigating this!

I tried a clean clone/build, but it unfortunately still segfaults. If relevant, the "libclang: crash detected while annotating tokens" messages are still there. I also tried a fresh config (removed the ~/.juci folder), but the crashes were still there.

I would be more than happy to help with this. Please let me know of things I could try on my end.

eidheim commented 6 years ago

@kzampog I tried debian testing with llvm/clang version 6. I could not reproduce this issue, however, I got clang diagnostic errors opening some of the files in https://github.com/kzampog/cilantro. If you look into the errors and fix them, let me know. My guess is that there are some issues in the template code, for instance in the headers of cilantro/include/cilantro/connected_component_segmentation.hpp, that could cause previous versions of libclang to crash.

kzampog commented 6 years ago

Hi again!

I just gave it a try on an Ubuntu 18.04 VM (clean setup with Clang 6.0) and I was not able to reproduce the segfaults either! So it may be Clang 3.8/4.0 specific?

However, I encountered another strange behavior when working on my project. If you still have the code and some time, please give this a try:

At this point, one CPU thread will get stuck at 100% usage and closing the JuCi window will not end the process. This happens on both my host (Mint with Clang 3.8/4.0) and VM (Ubuntu 18.04 with Clang 6.0). Interestingly, exactly the same happens with Sublime 3 and EasyClangComplete (on both setups), and after some additional actions, Sublime actually hangs. This looks like a libclang related issue.

By the way, I would really appreciate it if you could point me to the diagnostic errors you mentioned or how to reproduce them (I am not getting any compilation errors/warnings with gcc or Clang).

Thanks again!

eidheim commented 6 years ago

@kzampog

I'll have a look at the hanging cpu thread, but most likely this is a libclang issue that should be reported:)

Regarding the clang diagnostic error: I got for instance use of undeclared identifier 'NearestNeighborSearchResultSet' when opening include/cilantro/connected_component_segmentation.hpp, and no template named 'Vector' in include/cilantro/kd_tree.hpp. But this may be due to me running Debian testing in a docker instance, and that my opengl setup there is a bit weird because it runs in docker.

kzampog commented 6 years ago

Thanks for the info! There must have been some CMake configuration error -- all declarations are there in the included headers.

I will be upgrading my setup to Clang 6.0 when Mint 19 comes out, so the crashes will no longer be an issue for me. Please keep us posted on the hanging thread issue!

Thanks again for your time and this awesome IDE!