Author Topic: [Bug report] CodeBlocks crash when adding file to the project  (Read 14700 times)

Offline AdrianB

  • Multiple posting newcomer
  • *
  • Posts: 12
[Bug report] CodeBlocks crash when adding file to the project
« on: September 03, 2016, 03:07:03 pm »
Hi all,

I'm new in CB. I started to use it trying different IDE. CB seems to be what I need.
Unfortunately I notice few crashes. The most annoying one is when I'm trying to add a file in the project.
I'm working to develop different daemons in Quagga. When I'm trying to import vtysh/vtysh_cmd.c file CB crashes with Segmentation Fault.

I'm using Debian OS with CB 16.01
I've attached the gdb output of CodeBlocks when is crashing and also the file which is causing the crash.

Kind regards,
Adrian

Offline White-Tiger

  • Multiple posting newcomer
  • *
  • Posts: 83
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #1 on: September 03, 2016, 05:00:44 pm »
my C::B often crashes when I try to add a file... either at the very moment I've added it to the project, or shortly after...

And since you've started a thread for it.. here's also one of my crash logs :P
Windoze 8.1 x86_64 16GiB RAM, wxWidgets-2.8x (latest,trunk), MinGW-builds (latest, posix-threads)
Code::Blocks (x86 , latest , selection length patch , build option fixes/additions , toggle comments)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #2 on: September 04, 2016, 09:01:27 am »
my C::B often crashes when I try to add a file... either at the very moment I've added it to the project, or shortly after...

And since you've started a thread for it.. here's also one of my crash logs :P
Look at the crash stack of your codeblocks.RPT, it is definitely a CodeCompletion bug.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #3 on: September 04, 2016, 11:04:54 am »
@AdrianB: The rar file only contains a .c file, but I can't reproduce the crash, I guess the header files are needed to reproduce the crash?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline AdrianB

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #4 on: September 04, 2016, 01:52:06 pm »
Hi ollydbg,

Indeed if I'm creating a new project and I'm trying to add the file is working.
But when I'm trying to add to my original project is crashing.
That's very strange.

Can you give me some tips to rebuild the CodeBlocks from scratch?

--enable-debug is enough to rebuilt the sources and report more info about the crash?

Kind regards

Offline AdrianB

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #5 on: September 04, 2016, 02:11:17 pm »
Hi ollydbg,

Found the situation. I've created 2 Build Targets based on Debug: lib (Debug) and vtysh (Debug).
Because Quagga is a multiple executable project I've created for each lib/exec one Build Target.
So I've added recursive files from directory lib/ to target lib (Debug).
Then I've tried to add only vtysh_cmd.c to vtysh (Debug) target and CB crashed like my project.
vtysh_cmd.c is created by extract.pl file, so by default is not available in Quagga sources. You have to do ./configure and then make the sources in vtysh to obtain the file, or the file I've uploaded in the thread.

Now I'm trying to see if I can recompile CB with more debug.

Kind regards,
Adrian

Offline AdrianB

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #6 on: September 04, 2016, 11:43:50 pm »
I've recompiled CB with -g -O0 and I did a gdb on it.
I've attached the GDB output.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #7 on: September 05, 2016, 12:42:21 am »
Hi, thanks for the effort to build c::b, and it looks like you have build it successfully.

Code
#6  0x00007fffc0b9e3b4 in Tokenizer::Lex (this=this@entry=0x7fffb01164d0) at parser/tokenizer.cpp:976
#7  0x00007fffc0ba20dc in Tokenizer::DoGetToken (this=this@entry=0x7fffb01164d0) at parser/tokenizer.cpp:936
#8  0x00007fffc0ba251f in Tokenizer::GetToken (this=this@entry=0x7fffb01164d0) at parser/tokenizer.cpp:843
#9  0x00007fffc0b8af79 in ParserThread::SkipToOneOfChars (this=this@entry=0x7fffb01164c0, chars=..., supportNesting=supportNesting@entry=false, singleCharToken=singleCharToken@entry=true) at parser/parserthread.cpp:238
#10 0x00007fffc0b949be in ParserThread::DoParse (this=this@entry=0x7fffb01164c0) at parser/parserthread.cpp:906
#11 0x00007fffc0b9833c in ParserThread::HandleClass (this=this@entry=0x7fffb01164c0, ct=ct@entry=ParserThread::ctStructure) at parser/parserthread.cpp:2114
#12 0x00007fffc0b948b3 in ParserThread::DoParse (this=this@entry=0x7fffb01164c0) at parser/parserthread.cpp:956
#13 0x00007fffc0b9833c in ParserThread::HandleClass (this=this@entry=0x7fffb01164c0, ct=ct@entry=ParserThread::ctStructure) at parser/parserthread.cpp:2114
#14 0x00007fffc0b948b3 in ParserThread::DoParse (this=this@entry=0x7fffb01164c0) at parser/parserthread.cpp:956
#15 0x00007fffc0b9833c in ParserThread::HandleClass (this=this@entry=0x7fffb01164c0, ct=ct@entry=ParserThread::ctStructure) at parser/parserthread.cpp:2114
#16 0x00007fffc0b948b3 in ParserThread::DoParse (this=this@entry=0x7fffb01164c0) at parser/parserthread.cpp:956
#17 0x00007fffc0b9833c in ParserThread::HandleClass (this=this@entry=0x7fffb01164c0, ct=ct@entry=ParserThread::ctStructure) at parser/parserthread.cpp:2114
#18 0x00007fffc0b948b3 in ParserThread::DoParse (this=this@entry=0x7fffb01164c0) at parser/parserthread.cpp:956
#19 0x00007fffc0b9833c in ParserThread::HandleClass (this=this@entry=0x7fffb01164c0, ct=ct@entry=ParserThread::ctStructure) at parser/parserthread.cpp:2114
...

This looks like an endless loop in the parser, so I need a way to reproduce this bug. Can you give me a minimal cbp project(with all the header files and source files in the project). Since I can't reproduce for a single source file.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline AdrianB

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #8 on: September 05, 2016, 09:54:55 am »
Hi ollydbg,

Of course. the problem is that the compressed files are about 360Kb so I can't upload them here.
I've put them on my web server: http://www.abtelecom.ro/documents/CB-quagga-bug.tar.xz

The file vtysh_cmd.c is not added in the project (obviously :) ) but the rest of the project is already prepared. Is a minimal project which crashed in my case.

Kind regards,
Adrian

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #9 on: September 05, 2016, 04:38:15 pm »
I can reproduce this crash issue, and I get a call stack which have 1686 frames!
So, there are some recursive calls.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline AdrianB

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #10 on: September 05, 2016, 06:03:56 pm »
Glad to hear this.
Also I have some random crashes (which I didn't catch them) but the situation is like trying to type something like printf(""); and CB is crashing.
I think is related to the same issue, not 100%.

Initially I thought that is a Debian issue with their 5 patches, but rebuilding from the scratch directly from the sources I notice the same behavior.

I hope you will find the issue and fix it  8).

Kind regards,
Adrian

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #11 on: September 07, 2016, 09:39:21 am »
OK, I correctly locate the bug, and please test this patch, I think it should fix the crash issue.

Code
From 06b24abc0710e6befcbcbb18ad353aa8ae8a334f Mon Sep 17 00:00:00 2001
From: asmwarrior <asmwarrior@gmail.com>
Date: Wed, 7 Sep 2016 14:46:48 +0800
Subject: * CC: fix a endless loop crash bug when parsing C99 designated
 initializer

Forum discussion is here:
http://forums.codeblocks.org/index.php/topic,21417.0.html

When parsing
struct AAA a1 = {.x = 1, .y=2}; // first line
struct AAA a2 = {.x = 1, .y=2}; // second line
When we see a "dot", we need to skip to "}", thus the close brace is
skipped, and the open brace is just start a function call of DoParse().
If we goes to the second line, we will call another DoParse(), so there
is recursive calls, and finally goes to crash.

Also, a cc test case is added

diff --git a/src/plugins/codecompletion/parser/parserthread.cpp b/src/plugins/codecompletion/parser/parserthread.cpp
index fc00985..3d81acf 100644
--- a/src/plugins/codecompletion/parser/parserthread.cpp
+++ b/src/plugins/codecompletion/parser/parserthread.cpp
@@ -2197,6 +2197,21 @@ void ParserThread::HandleClass(EClassType ct)
             break;
         }
         // -------------------------------------------------------------------
+        else if(next == ParserConsts::equals)
+        // -------------------------------------------------------------------
+        {
+            // some patterns like: struct AAA a = {.x = 1, .y=2};
+            // In (ANSI) C99, you can use a designated initializer to initialize a structure
+            if (!lastCurrent.IsEmpty() )
+            {
+                m_Str << lastCurrent << ParserConsts::space_chr;
+                DoAddToken(tkVariable, current, m_Tokenizer.GetLineNumber());
+            }
+            // so we have to eat the brace pair
+            SkipToOneOfChars(ParserConsts::semicolon, /* supportNesting*/ true, /*singleCharToken*/ true);
+            break;
+        }
+        // -------------------------------------------------------------------
         else
         // -------------------------------------------------------------------
         {
diff --git a/src/plugins/codecompletion/testing/cc_structs.cpp b/src/plugins/codecompletion/testing/cc_structs.cpp
new file mode 100644
index 0000000..82cd85a
--- /dev/null
+++ b/src/plugins/codecompletion/testing/cc_structs.cpp
@@ -0,0 +1,13 @@
+
+// parsing C99 designated initializer of struct
+// http://forums.codeblocks.org/index.php/topic,21417.0.html
+struct AAA
+{
+  int   x;
+  float y;
+};
+
+struct AAA a1 = {.x = 1, .y=0.2}; // first line
+struct AAA a2 = {.x = 1, .y=0.2}; // second line
+
+//a  //a1,a2
\ No newline at end of file
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline AdrianB

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #12 on: September 07, 2016, 03:07:49 pm »
Hi ollydbg,

The patch seems to work ok. I will do some intensive tests those days.

Kind regards,
Adrian

Offline AdrianB

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #13 on: September 07, 2016, 11:33:05 pm »
Hi ollydbg,

The issue is not more present, but I still have random crashes when I'm starting to type something and I believe is also related to code parser.
Do you want to open another thread or I can send you the debug information here?

Kind regards,
Adrian

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: [Bug report] CodeBlocks crash when adding file to the project
« Reply #14 on: September 08, 2016, 02:27:08 am »
Hi ollydbg,

The issue is not more present, but I still have random crashes when I'm starting to type something and I believe is also related to code parser.
Do you want to open another thread or I can send you the debug information here?

Kind regards,
Adrian
Thanks for the test.

For the crash issue, I would like you to report it to our Ticket system. If the problem is easy to fix, then post it in our forum is OK, but if the bug is hard to fix(usually it takes a lot of time to debug a multiply thread issue), the best place is the ticket system. Someone has already report similar crash issue here, is it the same as yours? See here: Code::Blocks / Tickets / #402 Segmentation Fault crash when code completion parsing

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.