Author Topic: Macro expansion infinite loop.  (Read 27176 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5370
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Macro expansion infinite loop.
« Reply #45 on: March 14, 2015, 09:20:55 am »
...
I suggest a patch like this:
Code
@@ -1812,13 +1812,18 @@ bool Tokenizer::ReplaceBufferText(const wxString& target)
     if (m_RepeatReplaceCount > 0)
     {
         if (m_RepeatReplaceCount >= s_MaxRepeatReplaceCount)
         {
             m_TokenIndex = m_BufferLen - m_FirstRemainingLength;
+
+            // Reset undo token
+            m_SavedTokenIndex   = m_UndoTokenIndex = m_TokenIndex;
+            m_SavedLineNumber   = m_UndoLineNumber = m_LineNumber;
+            m_SavedNestingLevel = m_UndoNestLevel  = m_NestLevel;
+
             m_PeekAvailable = false;
-            SkipToEOL(false);
-            return false;
+            return true; // NOTE: we have to skip the problem token by returning true.
         }
         else
             ++m_RepeatReplaceCount;
     }
     else  // Set replace parsing state, and save first replace token index
Hi, Huki, after debug and reading the source code for a while, and found your patch is great!
I have committed to trunk with many description added as commit log. Thanks.
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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
Re: Macro expansion infinite loop.
« Reply #46 on: March 16, 2015, 08:55:58 pm »
Have rebuilt my work cb to the latest revision and it seems the bug has been fixed without the need to use the separate patches.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5370
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Macro expansion infinite loop.
« Reply #47 on: March 17, 2015, 12:31:29 am »
Have rebuilt my work cb to the latest revision and it seems the bug has been fixed without the need to use the separate patches.
Yes, the broken token which cause infinite loop is skipped, this is a workaround to avoid the infinite loop, but does not follow the preprocessor' rules. My patches follow the rules, and won't expand the used macros .  ;)
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9615
Re: Macro expansion infinite loop.
« Reply #48 on: March 18, 2015, 07:49:42 am »
I am getting crashes like the following now:
Code
C:\Devel\CodeBlocks\codeblocks.exe caused an Access Violation at location 6275ce54 in module C:\Devel\CodeBlocks\wxmsw28u_gcc_custom.dll Reading from location 00003a2e.

Registers:
eax=0028ed0c ebx=61a82e24 ecx=0028ed0c edx=00003a3a esi=62c92074 edi=0ae23720
eip=6275ce54 esp=0028ec20 ebp=0028ec78 iopl=0         nv up ei pl nz ac po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010216

Call stack:
6275CE54  C:\Devel\CodeBlocks\wxmsw28u_gcc_custom.dll:6275CE54  _ZN12wxStringBaseaSERKS_
618034E1  C:\Devel\CodeBlocks\codeblocks.dll:618034E1  _ZN9CCManager13OnShowCallTipER15CodeBlocksEvent
61A82E7F  C:\Devel\CodeBlocks\codeblocks.dll:61A82E7F  _ZN14cbEventFunctorI9CCManager15CodeBlocksEventE4CallERS1_
6188CB4E  C:\Devel\CodeBlocks\codeblocks.dll:6188CB4E  _ZN7Manager12ProcessEventER15CodeBlocksEvent
61802827  C:\Devel\CodeBlocks\codeblocks.dll:61802827  _ZN9CCManager12OnEditorHookEP8cbEditorR16wxScintillaEvent
61AEF324  C:\Devel\CodeBlocks\codeblocks.dll:61AEF324  _ZNK11EditorHooks11HookFunctorI9CCManagerE4CallEP8cbEditorR16wxScintillaEvent
618431D5  C:\Devel\CodeBlocks\codeblocks.dll:618431D5  _ZN11EditorHooks9CallHooksEP8cbEditorR16wxScintillaEvent
617E1AB8  C:\Devel\CodeBlocks\codeblocks.dll:617E1AB8  _ZN8cbEditor16OnScintillaEventER16wxScintillaEvent
617E07F8  C:\Devel\CodeBlocks\codeblocks.dll:617E07F8  _ZN8cbEditor17OnEditorCharAddedER16wxScintillaEvent
62701262  C:\Devel\CodeBlocks\wxmsw28u_gcc_custom.dll:62701262  _ZNK12wxAppConsole11HandleEventEP12wxEvtHandlerMS0_FvR7wxEventES3_
62926CB8  C:\Devel\CodeBlocks\wxmsw28u_gcc_custom.dll:62926CB8  _ZN12wxWindowBase9TryParentER7wxEvent
61912F28  C:\Devel\CodeBlocks\codeblocks.dll:61912F28  _ZN11wxScintilla12NotifyParentEP14SCNotification
61915A91  C:\Devel\CodeBlocks\codeblocks.dll:61915A91  _ZN11ScintillaWX12NotifyParentE14SCNotification
619B8818  C:\Devel\CodeBlocks\codeblocks.dll:619B8818  _ZN6Editor10NotifyCharEi
619B621B  C:\Devel\CodeBlocks\codeblocks.dll:619B621B  _ZN6Editor10AddCharUTFEPKcjb
619D277A  C:\Devel\CodeBlocks\codeblocks.dll:619D277A  _ZN13ScintillaBase10AddCharUTFEPKcjb
61918645  C:\Devel\CodeBlocks\codeblocks.dll:61918645  _ZN11ScintillaWX9DoAddCharEi
61912059  C:\Devel\CodeBlocks\codeblocks.dll:61912059  _ZN11wxScintilla6OnCharER10wxKeyEvent
62701262  C:\Devel\CodeBlocks\wxmsw28u_gcc_custom.dll:62701262  _ZNK12wxAppConsole11HandleEventEP12wxEvtHandlerMS0_FvR7wxEventES3_
62701262  C:\Devel\CodeBlocks\wxmsw28u_gcc_custom.dll:62701262  _ZNK12wxAppConsole11HandleEventEP12wxEvtHandlerMS0_FvR7wxEventES3_
6280D82D  C:\Devel\CodeBlocks\wxmsw28u_gcc_custom.dll:6280D82D  _ZN8wxWindow10HandleCharEjlb
62811BB8  C:\Devel\CodeBlocks\wxmsw28u_gcc_custom.dll:62811BB8  _ZN8wxWindow13MSWWindowProcEjjl
628092B6  C:\Devel\CodeBlocks\wxmsw28u_gcc_custom.dll:628092B6  [email protected]
752C62FA  C:\Windows\syswow64\USER32.dll:752C62FA  gapfnScSendMessage
752C6D3A  C:\Windows\syswow64\USER32.dll:752C6D3A  GetThreadDesktop
752C77C4  C:\Windows\syswow64\USER32.dll:752C77C4  CharPrevW
752C788A  C:\Windows\syswow64\USER32.dll:752C788A  DispatchMessageW
752EC81F  C:\Windows\syswow64\USER32.dll:752EC81F  IsDialogMessageW
6280823D  C:\Devel\CodeBlocks\wxmsw28u_gcc_custom.dll:6280823D  _ZN8wxWindow17MSWProcessMessageEP6tagMSG
627E3AFD  C:\Devel\CodeBlocks\wxmsw28u_gcc_custom.dll:627E3AFD  _ZN11wxEventLoop17PreProcessMessageEP6tagMSG
627E386D  C:\Devel\CodeBlocks\wxmsw28u_gcc_custom.dll:627E386D  _ZN11wxEventLoop8DispatchEv
...resolved:
Code
******************************
* Found (another) call stack *
******************************
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\wxmsw28u_gcc_custom.dll 6275CE54:
Error for: C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\wxmsw28u_gcc_custom.dll 6275CE54
:C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe: C:\Devel\CodeBlocks\src\devel\wxmsw28u_gcc_custom.dll: File truncated
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 618034E1:
C:\Devel\CodeBlocks\codeblocks.dll[618034E1]:
C:/Devel/CodeBlocks/src/sdk/ccmanager.cpp:882
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 61A82E7F:
C:\Devel\CodeBlocks\codeblocks.dll[61A82E7F]:
C:/Devel/CodeBlocks/src/include/cbfunctor.h:49
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 6188CB4E:
C:\Devel\CodeBlocks\codeblocks.dll[6188CB4E]:
C:/Devel/CodeBlocks/src/sdk/manager.cpp:263
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 61802827:
C:\Devel\CodeBlocks\codeblocks.dll[61802827]:
C:/Devel/CodeBlocks/src/sdk/ccmanager.cpp:722
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 61AEF324:
C:\Devel\CodeBlocks\codeblocks.dll[61AEF324]:
C:\Devel\CodeBlocks\src/include/editor_hooks.h:61
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 618431D5:
C:\Devel\CodeBlocks\codeblocks.dll[618431D5]:
C:/Devel/CodeBlocks/src/sdk/editor_hooks.cpp:122
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 617E1AB8:
C:\Devel\CodeBlocks\codeblocks.dll[617E1AB8]:
C:/Devel/CodeBlocks/src/sdk/cbeditor.cpp:3440
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 617E07F8:
C:\Devel\CodeBlocks\codeblocks.dll[617E07F8]:
C:/Devel/CodeBlocks/src/sdk/cbeditor.cpp:3172
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\wxmsw28u_gcc_custom.dll 62701262:
Error for: C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\wxmsw28u_gcc_custom.dll 62701262
:C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe: C:\Devel\CodeBlocks\src\devel\wxmsw28u_gcc_custom.dll: File truncated
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\wxmsw28u_gcc_custom.dll 62926CB8:
Error for: C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\wxmsw28u_gcc_custom.dll 62926CB8
:C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe: C:\Devel\CodeBlocks\src\devel\wxmsw28u_gcc_custom.dll: File truncated
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 61912F28:
C:\Devel\CodeBlocks\codeblocks.dll[61912F28]:
C:/Devel/CodeBlocks/src/sdk/wxscintilla/src/wxscintilla.cpp:5750
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 61915A91:
C:\Devel\CodeBlocks\codeblocks.dll[61915A91]:
C:/Devel/CodeBlocks/src/sdk/wxscintilla/src/ScintillaWX.cpp:534
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 619B8818:
C:\Devel\CodeBlocks\codeblocks.dll[619B8818]:
C:/Devel/CodeBlocks/src/sdk/wxscintilla/src/scintilla/src/Editor.cxx:2240
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 619B621B:
C:\Devel\CodeBlocks\codeblocks.dll[619B621B]:
C:/Devel/CodeBlocks/src/sdk/wxscintilla/src/scintilla/src/Editor.cxx:1898
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 619D277A:
C:\Devel\CodeBlocks\codeblocks.dll[619D277A]:
C:/Devel/CodeBlocks/src/sdk/wxscintilla/src/scintilla/src/ScintillaBase.cxx:83
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 61918645:
C:\Devel\CodeBlocks\codeblocks.dll[61918645]:
C:/Devel/CodeBlocks/src/sdk/wxscintilla/src/ScintillaWX.cpp:1197
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\codeblocks.dll 61912059:
C:\Devel\CodeBlocks\codeblocks.dll[61912059]:
C:/Devel/CodeBlocks/src/sdk/wxscintilla/src/wxscintilla.cpp:5462
----------------------------------------
C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\wxmsw28u_gcc_custom.dll 62701262:
Error for: C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe -e C:\Devel\CodeBlocks\src\devel\wxmsw28u_gcc_custom.dll 62701262
:C:\Devel\CodeBlocks\MinGW\bin\addr2line.exe: C:\Devel\CodeBlocks\src\devel\wxmsw28u_gcc_custom.dll: File truncated

I doubt it is related to the patch actually, probably just now it becomes visible.
Looks like another wxString thread instability...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5370
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Macro expansion infinite loop.
« Reply #49 on: March 18, 2015, 02:10:26 pm »
...
I doubt it is related to the patch actually, probably just now it becomes visible.
Looks like another wxString thread instability...
You mean the crash happens when you apply my "try to expand every identifier like macro token" patch?

To solve the wxString thread issue, let switch to wx3.x. ;)
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 Huki

  • Multiple posting newcomer
  • *
  • Posts: 95
Re: Macro expansion infinite loop.
« Reply #50 on: April 05, 2015, 08:05:57 pm »
Git patches attached against(rebased on) current svn trunk head.
It also fixes the "#" issue in my previous post. :)


[attachment deleted by admin]
Hi,
I'm interested in the CC macro serial patches (to do all macro expansion at the Tokenizer level), but the attachment happens to be deleted. Could you repost them?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9615
Re: Macro expansion infinite loop.
« Reply #51 on: April 05, 2015, 08:08:50 pm »
I believe it's in the git branch now. Check obfuscated's git repo and then the ollydbg branch. I am not sure if it is in sync with current svn trunk though.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5370
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Macro expansion infinite loop.
« Reply #52 on: April 06, 2015, 02:51:59 am »
Hi, Huki, I attach the git patch serials against the latest trunk rev 10182.
Comments are welcome  :)
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.