Agetian:
Have your string variables being initialized?
Do you have python enabled gdb or non-python gdb?
Have you installed any pretty printers?
Can you post the full log from the debugger? (you have to enabled full logging)
1) Yes, the string variables are initialized. This is easily tested even on a simple "std::string s = "Test";" line.
2) I believe it's a Python-enabled gdb (it references python27.dll), but I'm not sure how to tell you with bigger degree of certainty.
3) No, at least not that I'm aware of it - nothing out of the ordinary, just stock C::B SVN and stock MinGW/GDB, with whatever configuration they both came with. If you're interested, MinGW 4.7.1 came from this source: http://sourceforge.net/projects/mingwbuilds/
4) Sure thing, I think this is what you meant about full log, but if I'm wrong, please tell me where to obtain the correct thing:
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: D:\cppclasstest\
Adding source dir: D:\cppclasstest\
Adding file: D:\cppclasstest\bin\Debug\cppclasstest.exe
Changing directory to: D:/cppclasstest/.
[debug]PATH=.;D:\mingw-4.7.1\bin;D:\mingw-4.7.1;C:\Program Files\NVIDIA Corporation\PhysX\Common;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Windows Live\Shared;D:\mingw-TDD-4.6.1\bin;C:\Program Files\Calibre2;C:\D\dmd\windows\bin;C:\D\dmd2\windows\bin;C:\D\dm\bin;C:\Program Files\TortoiseSVN\bin
[debug]Command-line: D:\mingw-4.7.1\bin\gdb.exe -nx -fullname -quiet -args D:/cppclasstest/bin/Debug/cppclasstest.exe
[debug]Working dir : D:\cppclasstest
Starting debugger: D:\mingw-4.7.1\bin\gdb.exe -nx -fullname -quiet -args D:/cppclasstest/bin/Debug/cppclasstest.exe
done
[debug]> set prompt >>>>>>cb_gdb:
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
[debug]Reading symbols from D:/cppclasstest/bin/Debug/cppclasstest.exe...
[debug]done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.4.1
[debug]Copyright (C) 2012 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law. Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "i686-w64-mingw32".
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off
Debugger name and version: GNU gdb (GDB) 7.4.1
[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source D:\CB_Portable\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory D:/cppclasstest/
[debug]>>>>>>cb_gdb:
[debug]> break "D:/cppclasstest/main.cpp:15"
[debug]Breakpoint 2 at 0x401394: file D:\cppclasstest\main.cpp, line 15.
[debug]>>>>>>cb_gdb:
[debug]> run
Child process PID: 3968
[debug][New Thread 3968.0x16a4]
[debug]Breakpoint 2, main () at D:\cppclasstest\main.cpp:15
[debug]D:\cppclasstest\main.cpp:15:188:beg:0x401394
[debug]>>>>>>cb_gdb:
At D:\cppclasstest\main.cpp:15
[debug]> bt 30
[debug]#0 main () at D:\cppclasstest\main.cpp:15
[debug]>>>>>>cb_gdb:
[debug]> next
[debug]D:\cppclasstest\main.cpp:17:214:beg:0x4013c3
[debug]>>>>>>cb_gdb:
At D:\cppclasstest\main.cpp:17
[debug]> bt 30
[debug]#0 main () at D:\cppclasstest\main.cpp:17
[debug]>>>>>>cb_gdb:
[debug]> whatis s
[debug]type = std::string
[debug]>>>>>>cb_gdb:
[debug]> output &s
[debug](std::string *) 0x22fef0>>>>>>cb_gdb:
[debug]> output s.c_str()[0]@s.size()
[debug]The program being debugged was signaled while in a function called from GDB.
[debug]GDB has restored the context to what it was before the call.
[debug]To change this behavior use "set unwindonsignal off".
[debug]Evaluation of the expression containing the function
[debug](std::string::size() const) will be abandoned.
[debug]Program received signal SIGSEGV, Segmentation fault.
[debug]0x00412f42 in std::string::size() const ()
[debug]>>>>>>cb_gdb:
Program received signal SIGSEGV, Segmentation fault.
In std::string::size() const () ()
[debug]> whatis s
[debug]type = std::string
[debug]>>>>>>cb_gdb:
[debug]> output s.c_str()[0]@s.size()
[debug]The program being debugged was signaled while in a function called from GDB.
[debug]GDB has restored the context to what it was before the call.
[debug]To change this behavior use "set unwindonsignal off".
[debug]Evaluation of the expression containing the function
[debug](std::string::size() const) will be abandoned.
[debug]Program received signal SIGSEGV, Segmentation fault.
[debug]0x00412f42 in std::string::size() const ()
[debug]>>>>>>cb_gdb:
[debug]> bt 30
Program received signal SIGSEGV, Segmentation fault.
[debug]> bt 30
[debug]#0 main () at D:\cppclasstest\main.cpp:17
[debug]>>>>>>cb_gdb:#0 main () at D:\cppclasstest\main.cpp:17
[debug]>>>>>>cb_gdb:
This was done with a breakpoint set on a line that said:
std::string s = "Test";
I used the "Next line (F7)" command to go over this line to ensure that "s" was initialized, and then hovered the mouse over s to get its value, upon which it segfaulted.
Putting a breakpoint on the initialization line is not a good idea.
Can you try to put a breakpoint only on the next line?
Also can you disable the watch scripts and post the log again?
Another thing to try is to execute the commands: "p s.size()" and "p s.c_str()" in the debug log window.
Putting a breakpoint on the next line remedies the segfault but still doesn't resolve the problem completely:
With the watch scripts disabled, no segfault occurs and the proper value is shown when I hover the mouse over "s", but doing "p s.c_str()" and "p s.size()" both yield a strange outcome in the form of the message "Cannot evaluate function - may be inlined". Here's the full output:
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: D:\cppclasstest\
Adding source dir: D:\cppclasstest\
Adding file: D:\cppclasstest\bin\Debug\cppclasstest.exe
Changing directory to: D:/cppclasstest/.
[debug]PATH=.;D:\MinGW-4.7.1\bin;D:\MinGW-4.7.1;C:\Program Files\NVIDIA Corporation\PhysX\Common;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Windows Live\Shared;D:\MinGW-TDD-4.6.1\bin;C:\Program Files\Calibre2;C:\D\dmd\windows\bin;C:\D\dmd2\windows\bin;C:\D\dm\bin;C:\Program Files\TortoiseSVN\bin
[debug]Command-line: D:\MinGW-4.7.1\bin\gdb.exe -nx -fullname -quiet -args D:/cppclasstest/bin/Debug/cppclasstest.exe
[debug]Working dir : D:\cppclasstest
Starting debugger: D:\MinGW-4.7.1\bin\gdb.exe -nx -fullname -quiet -args D:/cppclasstest/bin/Debug/cppclasstest.exe
done
[debug]> set prompt >>>>>>cb_gdb:
[debug]Skip initializing the scripting!
Setting breakpoints
[debug]Reading symbols from D:/cppclasstest/bin/Debug/cppclasstest.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.4.1
[debug]Copyright (C) 2012 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law. Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "i686-w64-mingw32".
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off
Debugger name and version: GNU gdb (GDB) 7.4.1
[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Function "__cxa_throw" not defined.
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> directory D:/cppclasstest/
[debug]>>>>>>cb_gdb:
[debug]> break "D:/cppclasstest/main.cpp:17"
[debug]Breakpoint 2 at 0x401638: file D:\cppclasstest\main.cpp, line 17.
[debug]>>>>>>cb_gdb:
[debug]> run
Child process PID: 4036
[debug][New Thread 4036.0x548]
[debug]Breakpoint 2, main () at D:\cppclasstest\main.cpp:17
[debug]D:\cppclasstest\main.cpp:17:214:beg:0x401638
[debug]>>>>>>cb_gdb:
At D:\cppclasstest\main.cpp:17
[debug]> bt 30
[debug]#0 main () at D:\cppclasstest\main.cpp:17
[debug]>>>>>>cb_gdb:
> p s.c_str()
[debug]> p s.c_str()
[debug]Cannot evaluate function -- may be inlined
[debug]>>>>>>cb_gdb:
Cannot evaluate function -- may be inlined
Cannot evaluate function -- may be inlined
> p s.size()
[debug]> p s.size()
[debug]Cannot evaluate function -- may be inlined
[debug]>>>>>>cb_gdb:
Cannot evaluate function -- may be inlined
Cannot evaluate function -- may be inlined
With the watch scripts enabled, the same thing happens with both "p s.size()" and "p s.c_str()" but also the proper value is not shown in the watch window or when hovering the mouse over "s" - instead, the message "Cannot evaluate function -- may be inlined" also shows up in the watch window. Here's the full output with watch scripts enabled:
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: D:\cppclasstest\
Adding source dir: D:\cppclasstest\
Adding file: D:\cppclasstest\bin\Debug\cppclasstest.exe
Changing directory to: D:/cppclasstest/.
[debug]PATH=.;D:\MinGW-4.7.1\bin;D:\MinGW-4.7.1;C:\Program Files\NVIDIA Corporation\PhysX\Common;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Windows Live\Shared;D:\MinGW-TDD-4.6.1\bin;C:\Program Files\Calibre2;C:\D\dmd\windows\bin;C:\D\dmd2\windows\bin;C:\D\dm\bin;C:\Program Files\TortoiseSVN\bin
[debug]Command-line: D:\MinGW-4.7.1\bin\gdb.exe -nx -fullname -quiet -args D:/cppclasstest/bin/Debug/cppclasstest.exe
[debug]Working dir : D:\cppclasstest
Starting debugger: D:\MinGW-4.7.1\bin\gdb.exe -nx -fullname -quiet -args D:/cppclasstest/bin/Debug/cppclasstest.exe
done
[debug]> set prompt >>>>>>cb_gdb:
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
[debug]Reading symbols from D:/cppclasstest/bin/Debug/cppclasstest.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.4.1
[debug]Copyright (C) 2012 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law. Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "i686-w64-mingw32".
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off
Debugger name and version: GNU gdb (GDB) 7.4.1
[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Function "__cxa_throw" not defined.
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source D:\CB_Portable\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory D:/cppclasstest/
[debug]>>>>>>cb_gdb:
[debug]> break "D:/cppclasstest/main.cpp:17"
[debug]Breakpoint 2 at 0x401638: file D:\cppclasstest\main.cpp, line 17.
[debug]>>>>>>cb_gdb:
[debug]> run
Child process PID: 4380
[debug][New Thread 4380.0x11b0]
[debug]Breakpoint 2, main () at D:\cppclasstest\main.cpp:17
[debug]D:\cppclasstest\main.cpp:17:214:beg:0x401638
[debug]>>>>>>cb_gdb:
At D:\cppclasstest\main.cpp:17
[debug]> bt 30
[debug]#0 main () at D:\cppclasstest\main.cpp:17
[debug]>>>>>>cb_gdb:
[debug]> whatis s
[debug]type = std::string
[debug]>>>>>>cb_gdb:
[debug]> output &s
[debug](std::string *) 0x22fe80>>>>>>cb_gdb:
[debug]> output s.c_str()[0]@s.size()
[debug]Cannot evaluate function -- may be inlined
[debug]>>>>>>cb_gdb:
Cannot evaluate function -- may be inlined
> p s.c_str()
[debug]> p s.c_str()
[debug]Cannot evaluate function -- may be inlined
[debug]>>>>>>cb_gdb:
Cannot evaluate function -- may be inlined
Cannot evaluate function -- may be inlined
> p s.size()
[debug]> p s.size()
[debug]Cannot evaluate function -- may be inlined
[debug]>>>>>>cb_gdb:
Cannot evaluate function -- may be inlined
Hope this helps.
@Agetian (http://forums.codeblocks.org/index.php?action=profile;u=30592), I think it is a gdb bug or gcc bug, as you can see, print a value/expression does not work under the command line.
Yeah, it might as well be - I'll retry with some older revisions of MinGW (I have old binaries for 4.5 and 4.6 series) and see if that solves the issue, I'll keep you posted. Thanks!
EDIT: Yeah, definitely works after reverting to MinGW v4.6.1 - so, could be related to some gdb bug in the 4.7 series. Looks like this is not C::B-related.
Can you provide your project (maybe put it on some web space)?
I will look into the issue to see whether its related with gcc/gdb.
Sure thing, it's really a very simple test though, the entire test project that works as a test case consists of one file which is as follows:
#include <iostream>
using namespace std;
int main()
{
string s = "Test";
cout << s << endl;
return 0;
}
The breakpoint is set on the "cout << s << endl" line. I think it most surely is a gcc/gdb/mingw issue though, cause 4.6.1 works fine and 4.7.1 doesn't. I have, in addition to everything else, made double sure that I'm generating debugging symbols and that no optimizations are set, so it looks like a bug in gcc/gdb... Thanks for your desire to look into it!
To whom it may concern, on my Linux Debian wheezy machine I had to modify two files, Makefile.am and configure.in to make it compile.
Makefile.am
--- /svn_code/CodeBlocks/Makefile.am (revision 8281)
+++ /svn_code/CodeBlocks/Makefile.am (working copy)
@@ -12,6 +12,8 @@
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = codeblocks.pc
+ACLOCAL_AMFLAGS = -I m4
+
EXTRA_DIST = $(top_srcdir)/bootstrap \
codeblocks.spec \
codeblocks.plist \
configure.in
Index: /home/stefanos/svn_code/CodeBlocks/configure.in
===================================================================
--- /svn_code/CodeBlocks/configure.in (revision 8281)
+++ /svn_code/CodeBlocks/configure.in (working copy)
@@ -7,6 +7,9 @@
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([dist-bzip2 no-dist-gzip])
+
+AC_CONFIG_MACRO_DIR([m4])
+
AC_CONFIG_HEADER([src/include/config.h])
CODEBLOCKS_CHECK_DEBUG
Jens, I think was with you I had a conversation about it in a nightly version?
#include <iostream>
using namespace std;
int main()
{
string s = "Test";
cout << s << endl;
return 0;
}
Regarding this, I'm also using MinGWBuilds 4.7.1 32-bit building (http://sourceforge.net/projects/mingwbuilds/) with Code::Blocks 8248. I entered the above code, set a breakpoint on "return 0" Tried a watch on the variable "s" and I got the message: "Cannot evaluate function -- may be inlined" No crashes, I can resume the debugger and program after attempting to check the s variable. Other variables, like int x, I can get the proper values out of. Tried putting a "#include <string>" at the beginning of the file, tried initializing the string like "string s("Test");", no dice.
Since a few nightlies ago (I'm not sure how long this has been present) processing of #if statements appears to be inverted when using equality.
The following works fine:
#if 0
dont_do_this();
#endif
But the following highlights the code not being compiled:
#define OPT1 1
#define OPT2 2
#define OPTION OPT1
#if OPTION == OPT1
option1();
#else
dont_process_me();
#endif
On Windows XP SP3 - SVN 8248 (This nightly)
Hopefully it's a quick fix. Thanks for keeping up the good work guys, I'm using Code::Blocks every day at work for some decent size codebases. Thanks! :D
I am not sure if this is new or not, but I feel the need to share.
In debug watches window, a numeric array is shown like this:
array
[0] 1 <repeats 23 times>
[1] 5
[2] 3 <repeats 4 times>
On strings this is useful, but on numeric arrays it might be a little bit confusing.
And in the debug watches window, if you want to rename a variable, you will see that the selection is not highlighted.