Author Topic: Debugger Step-Into with multiple calls on same line  (Read 9471 times)

Offline vid512

  • Multiple posting newcomer
  • *
  • Posts: 36
Debugger Step-Into with multiple calls on same line
« on: December 14, 2011, 09:02:31 am »
Trying to debug code like following:
Code
      func1(func2());

I can't step into func1. Shift-F7 (the 'Step Into' command) only steps into func2, and upon return from it, the debugger goes right to the following line. What I would expect upon return from func2() is to remain at the same line in source, allowing to step into func1() as well.

Is this impossible in C::B, or am I missing something?

Using nightly C::B 7550 from 30th October, on Windows 7 64-bit, project is compiled with MS Visual C++, cdb.exe from 32-bit "Debugging Tools for Windows (x86)" is used as debugger.
« Last Edit: December 14, 2011, 09:05:37 am by vid512 »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Debugger Step-Into with multiple calls on same line
« Reply #1 on: December 14, 2011, 09:17:53 am »
I just use such code under MinGW GCC4.4.5+GDB(cvs)
There is no such problem, I first step into func2, then func1.

Code
void func1(int b)
{
    int a;
    a = b;
};

int func2()
{
    int a;
    a = 1;
    return a;
};

int main ()
{
    func1(func2());
}

So, it looks like cdb.exe has some problems.
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 vid512

  • Multiple posting newcomer
  • *
  • Posts: 36
Re: Debugger Step-Into with multiple calls on same line
« Reply #2 on: December 14, 2011, 09:21:31 am »
Thanks. I tested on Ubuntu/gcc/gdb now, and there everything works as expected. I'll try with MinGW, to see if this really is limitation of cdb (or of C::B usage of cdb).

Offline vid512

  • Multiple posting newcomer
  • *
  • Posts: 36
Re: Debugger Step-Into with multiple calls on same line
« Reply #3 on: December 14, 2011, 09:34:31 am »
Yep, definitively seems to be an issue related to cdb.exe. The debugging same project on same system with same C::B works fine with MinGW gdb, but errs as described with MS cdb.

Is there any other debugger C::B can use with MS Visual C++ produced files?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugger Step-Into with multiple calls on same line
« Reply #4 on: December 14, 2011, 09:41:51 am »
No, unfortunately. Have you tried the debugger branch nightly?
There were some fixes and improvements related to debugging in general and related to cdb, too.
I don't think this kind of bug has been reported or fixed unfortunately.

I'll check it as soon as possible.

Can you past the debugger's debug log (not the normal log but the raw log with the output from cdb.exe).
To enable this log go to 'settings -> compiler & debugger -> debugger -> something about debugger's log'.
(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 vid512

  • Multiple posting newcomer
  • *
  • Posts: 36
Re: Debugger Step-Into with multiple calls on same line
« Reply #5 on: December 14, 2011, 10:12:29 am »
Tried the debugger nightly (7550) for the first time now. I can't make it work, that's probably another unrelated problem. The Global Compiler Settings dialog, compiler "Microsoft Visual C++ 2010", tab "Toolchain executables", instead of letting me specify debugger name (cdb.exe), only has list of two options "--- Invalid debugger ---" and "GDB". This may be caused by some bad heuristics, when one uses MS Visual C++ Express (which doesn't have cdb.exe), and cdb.exe from separate package "Debugging Tools for Windows (x86)". My guess would be, there is some checking for existence of cdb.exe only in Compiler's installation directory, not in Additional paths.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugger Step-Into with multiple calls on same line
« Reply #6 on: December 14, 2011, 10:58:59 am »
You have to add a debug config for CDB in the Settings->Debugger for the GDB debugger.
Then you can choose it in the toolchain settings.
(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 vid512

  • Multiple posting newcomer
  • *
  • Posts: 36
Re: Debugger Step-Into with multiple calls on same line
« Reply #7 on: December 14, 2011, 01:52:33 pm »
Still, the debugger in lastest nigthly debugger branch doesn't work for me. It issues following command to CDB:
Code
> bu-1 /1 `F:/_temp/test_cb/testdbg/main.cpp:16`
The "bu-1" makes CDB try to set breakpoint at 0xFFFFFFFF.

Full debugger log:
Code
PATH=.;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE;c:\Program Files (x86)\Debugging Tools for Windows (x86);c:\Program Files\Microsoft SDKs\Windows\v7.1\Bin;C:\Program Files (x86)\CollabNet\Subversion Client;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;f:\dev\_tools\_path;C:\Program Files\Microsoft Windows Performance Toolkit\;C:\Program Files (x86)\doxygen\bin;f:\dev\_tools\python
Command-line: C:\Program Files (x86)\Debugging Tools for Windows (x86)\cdb.exe -G -lines -2 -y F:/_temp/test_cb/testdbg/; -srcpath F:/_temp/test_cb/testdbg/; F:/_temp/test_cb/testdbg/testdbg.exe
Working dir : F:\_temp\test_cb\testdbg
Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.
CommandLine: F:/_temp/test_cb/testdbg/testdbg.exe
Symbol search path is: F:/_temp/test_cb/testdbg/;srv*f:\dev\_tools\winsym*http://msdl.microsoft.com/download/symbols
Executable search path is:
ModLoad: 01050000 01055000   testdbg.exe
ModLoad: 77770000 778f0000   ntdll.dll
ModLoad: 76090000 761a0000   C:\Windows\syswow64\kernel32.dll
ModLoad: 76ac0000 76b06000   C:\Windows\syswow64\KERNELBASE.dll
(f38.eb8): Break instruction exception - code 80000003 (first chance)
eax=00000000 ebx=00000000 ecx=008c0000 edx=000fe2b8 esi=fffffffe edi=00000000
eip=77810f3b esp=0027f6c8 ebp=0027f6f4 iopl=0         nv up ei pl zr na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000246
ntdll!LdrpDoDebuggerBreak+0x2c:
77810f3b cc              int     3
0:000>
> |.
.  0 id: f38 create name: testdbg.exe
0:000>
> bc *
0:000>
> bu-1 /1 `F:/_temp/test_cb/testdbg/main.cpp:16`
*** WARNING: Unable to verify checksum for testdbg.exe
0:000>
> l+t
Source options are 1:
     1/t - Step/trace by source line
0:000>
> l+s
Source options are 5:
     1/t - Step/trace by source line
     4/s - List source code at prompt
0:000>
> l+o
Source options are d:
     1/t - Step/trace by source line
     4/s - List source code at prompt
     8/o - Only show source code at prompt
0:000>
> g
Unable to insert breakpoint 0 at ffffffff, Win32 error 0n299
    "Only part of a ReadProcessMemory or WriteProcessMemory request was completed."
bp0 at ffffffff failed
WaitForEvent failed, Win32 error 0n299
    "Only part of a ReadProcessMemory or WriteProcessMemory request was completed."
ntdll!LdrpDoDebuggerBreak+0x2d:
77810f3c 8975fc          mov     dword ptr [ebp-4],esi ss:002b:0027f6f0=00000000
0:000>
> k n
 # ChildEBP RetAddr 
00 0027f6f4 777f1323 ntdll!LdrpDoDebuggerBreak+0x2d
01 0027f870 777c0bda ntdll!LdrpInitializeProcess+0x12cc
02 0027f8c0 777a9e59 ntdll!_LdrpInitialize+0x78
03 0027f8d0 00000000 ntdll!LdrInitializeThunk+0x10
0:000>
> k n
 # ChildEBP RetAddr 
00 0027f6f4 777f1323 ntdll!LdrpDoDebuggerBreak+0x2d
01 0027f870 777c0bda ntdll!LdrpInitializeProcess+0x12cc
02 0027f8c0 777a9e59 ntdll!_LdrpInitialize+0x78
03 0027f8d0 00000000 ntdll!LdrInitializeThunk+0x10
0:000>

Attached is the CodeBlocks project and source, on which latest debugger nightly (7550) fails as described.

[attachment deleted by admin]

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugger Step-Into with multiple calls on same line
« Reply #8 on: December 14, 2011, 03:05:37 pm »
So it doesn't work at all or the problem is the same as the normal nightly build?

Can you post the same log from the normal nightly build?

p.s. keep in mind that debugging 64bit executables with 32bit cdb.exe will fail miserably, at least it failed for me.
(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 vid512

  • Multiple posting newcomer
  • *
  • Posts: 36
Re: Debugger Step-Into with multiple calls on same line
« Reply #9 on: December 14, 2011, 04:20:35 pm »
On nightly debug branch, debugging with CDB doesn't work at all, it issues the "bu-1" command which causes error (as can be seen in the last log), and even the error returned by CDB is handled badly by C::B (Displays nonsensical error with something like "File name:").

In regular nightly, debugging with CDB works, but I have the problem with multiple function calls on same line.

Following is debugger log showing the original problem from this thread (post #1, #2) on regular (not debug) C::B nightly. What I did to get this log: I skip to to line with two function calls (F4), step into func2 (shift-F7), get out of func2 (ctrl-shift-F7). Here I'd expect to still be on same line and be given chance to enter also func1, but instead I am on following line. You can see that Code::Blocks explicitly issues "p" command after "gu", which is probably the source of problem.

Code
PATH=.;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE;c:\Program Files (x86)\Debugging Tools for Windows (x86);c:\Program Files\Microsoft SDKs\Windows\v7.1\Bin;C:\Program Files (x86)\CollabNet\Subversion Client;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;f:\dev\_tools\_path;C:\Program Files\Microsoft Windows Performance Toolkit\;C:\Program Files (x86)\doxygen\bin;f:\dev\_tools\python
Command-line: c:\Program Files (x86)\Debugging Tools for Windows (x86)\cdb.exe -G -lines -y F:/_temp/test_cb/testdbg/; -srcpath F:/_temp/test_cb/testdbg/; testdbg.exe
Working dir : F:\_temp\test_cb\testdbg\
> bc *
Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.
CommandLine: testdbg.exe
Symbol search path is: F:/_temp/test_cb/testdbg/;srv*f:\dev\_tools\winsym*http://msdl.microsoft.com/download/symbols
Executable search path is:
ModLoad: 003a0000 003a5000   testdbg.exe
ModLoad: 77770000 778f0000   ntdll.dll
ModLoad: 76090000 761a0000   C:\Windows\syswow64\kernel32.dll
ModLoad: 76ac0000 76b06000   C:\Windows\syswow64\KERNELBASE.dll
(b48.e14): Break instruction exception - code 80000003 (first chance)
eax=00000000 ebx=00000000 ecx=75070000 edx=000de248 esi=fffffffe edi=00000000
eip=77810f3b esp=002af70c ebp=002af738 iopl=0         nv up ei pl zr na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000246
ntdll!LdrpDoDebuggerBreak+0x2c:
77810f3b cc              int     3
0:000> 0:000>
> bu1 /1 `F:/_temp/test_cb/testdbg/main.cpp:16`
*** WARNING: Unable to verify checksum for testdbg.exe
0:000>
> l+t
Source options are 1:
     1/t - Step/trace by source line
0:000>
> l+s
Source options are 5:
     1/t - Step/trace by source line
     4/s - List source code at prompt
0:000>
> l+o
Source options are d:
     1/t - Step/trace by source line
     4/s - List source code at prompt
     8/o - Only show source code at prompt
0:000>
> g
ModLoad: 73540000 7358c000   C:\Windows\SysWOW64\apphelp.dll
Breakpoint 1 hit
>   16:     func1(func2());
0:000>
> dv
0:000>
> k n
 # ChildEBP RetAddr  
00 002afb8c 760a339a testdbg!main+0x3 [f:\_temp\test_cb\testdbg\main.cpp @ 16]
01 002afb98 777a9ed2 kernel32!BaseThreadInitThunk+0xe
02 002afbd8 777a9ea5 ntdll!__RtlUserThreadStart+0x70
03 002afbf0 00000000 ntdll!_RtlUserThreadStart+0x1b
0:000>
> dv
0:000>
> k n
 # ChildEBP RetAddr  
00 002afb8c 760a339a testdbg!main+0x3 [f:\_temp\test_cb\testdbg\main.cpp @ 16]
01 002afb98 777a9ed2 kernel32!BaseThreadInitThunk+0xe
02 002afbd8 777a9ea5 ntdll!__RtlUserThreadStart+0x70
03 002afbf0 00000000 ntdll!_RtlUserThreadStart+0x1b
0:000>
> t
testdbg!ILT+5(?func2YAHXZ):
003a100a e931000000      jmp     testdbg!func2 (003a1040)
0:000>
> p
>    8: {
0:000>
> k n 1
 # ChildEBP RetAddr  
00 002afb84 003a1068 testdbg!func2 [f:\_temp\test_cb\testdbg\main.cpp @ 8]
0:000>
> dv
              a = 0
0:000>
> k n
 # ChildEBP RetAddr  
00 002afb84 003a1068 testdbg!func2 [f:\_temp\test_cb\testdbg\main.cpp @ 8]
01 002afb8c 760a339a testdbg!main+0x8 [f:\_temp\test_cb\testdbg\main.cpp @ 16]
02 002afb98 777a9ed2 kernel32!BaseThreadInitThunk+0xe
03 002afbd8 777a9ea5 ntdll!__RtlUserThreadStart+0x70
04 002afbf0 00000000 ntdll!_RtlUserThreadStart+0x1b
0:000>
> gu
>   16:     func1(func2());
0:000>
> p
>   17:     return 5;
0:000>
> k n 1
 # ChildEBP RetAddr  
00 002afb8c 760a339a testdbg!main+0x11 [f:\_temp\test_cb\testdbg\main.cpp @ 17]
0:000>
> dv
0:000>
> k n
 # ChildEBP RetAddr  
00 002afb8c 760a339a testdbg!main+0x11 [f:\_temp\test_cb\testdbg\main.cpp @ 17]
01 002afb98 777a9ed2 kernel32!BaseThreadInitThunk+0xe
02 002afbd8 777a9ea5 ntdll!__RtlUserThreadStart+0x70
03 002afbf0 00000000 ntdll!_RtlUserThreadStart+0x1b
0:000>

Of course, I am using 32-bit Code::Blocks, 32-bit Visual C++, 32-bit CDB and building 32-bit executable.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugger Step-Into with multiple calls on same line
« Reply #10 on: December 14, 2011, 04:51:22 pm »
OK, I'll see what I can do about this problem.
(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 vid512

  • Multiple posting newcomer
  • *
  • Posts: 36
Re: Debugger Step-Into with multiple calls on same line
« Reply #11 on: December 14, 2011, 04:57:38 pm »
Thanks in advance. Should you need more info, just let me know.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugger Step-Into with multiple calls on same line
« Reply #12 on: December 15, 2011, 12:57:41 am »
OK, I think I've fixed both bugs:

- the bu-1 bug was an regression caused by a recent redesign of the breakpoints code;
- the step out was doing an explicit step, thus it was going to the next line;

Can I ask you to try to build a C::B version from the debugger's branch and see if the bugs are really fixed.
I rarely test the CDB driver, so more regression or similar bugs are possible.
(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 vid512

  • Multiple posting newcomer
  • *
  • Posts: 36
Re: Debugger Step-Into with multiple calls on same line
« Reply #13 on: December 15, 2011, 04:24:41 am »
I will try, but as it is the first time, I expect some problems I won't be able to solve on my own. The "debugger branch" is "wxpropgrid_debugger" as stated here, I hope. I will keep you posted in this thread.

Are the fixes going to appear in next "regular" nightly build as well?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Debugger Step-Into with multiple calls on same line
« Reply #14 on: December 15, 2011, 10:37:39 am »
I don't know, you are the mercy of Morten, if he thinks it is safe to merge them back in trunk, they'll appear.
The interesting commit is r7638.

But keep in mind that there were many improvements to debugging and especially to CDB's support.
Also the debugger branch nightly has all the features of the normal nightly :)
(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!]