23

I'm programming using Code::Blocks. I set some breakpoints, but Code::Blocks seems to ignore them when I run the program.

By 'start the program' I mean simply clicking build_and_run (Build and run).

I checked under Debug and saw that F8 isn't available (Start / Continue):

Debug_Menu

The program compiles and runs fine, it just ignores breakpoints. Does anybody know how to solve this?

Note: I checked here and I think the suggested answer isn't relevant for me, because in Compiler settings I have just "C:\MinGW" under Compiler's installation directory.

edit:

I'm using Windows 8 (64bit), Code::Blocks 12.11

jpp
  • 159,742
  • 34
  • 281
  • 339
Alaa M.
  • 4,961
  • 10
  • 54
  • 95
  • On win7, the message says to set debugger not set, searching in the install dir, I had to set the debugger to this one (gdb32) codeblocks\mingw\gdb32\bin\gdb32.exe – mosh Apr 24 '18 at 16:28

7 Answers7

34

I guess you were trying to debug a standalone file (file not belonging to a project). Code::Blocks doesn't support debugging such files. Try including the file to be compiled as a part of an empty project or something.

Ciado
  • 1,996
  • 2
  • 17
  • 15
  • Worked for me. I was trying to debug a .cpp source code without creating a project in Code::Blocks. I created new project and now i can debug it – sy456 Nov 01 '15 at 14:05
  • nice. C::B is extremely useful for its ability to "no questions asked" just compile and run a single file, and I never bothered to add them to a project. now I know why the debugger was grayed out,. – d.Candela Jan 21 '16 at 02:20
21

In Code::Blocks, go into your Settings menu, then click Compiler. Make sure Global compiler settings is selected in the sidebar, then switch to the Toolchain executables tab. Your Debugger entry should say something like GDB/CDB debugger: default. If it does, OK out of this dialog.

Go back into the Settings menu and select Debugger. In the GDB/CDB debugger tree on the left, select Default. Make sure the Executable path textbox is set to your gdb.exe - in your case, the correct path will probably be something like C:\MinGW\bin\gdb.exe. Make sure the Debugger Type is set to GDB. Then hit OK.

Now your debugger (GDB) should be set up. Restart Code::Blocks if you like (I've had it glitch out before, crash, and lose whatever settings I changed since last restart), then go into the Debug menu and Start/Continue should be enabled.

cf-
  • 8,598
  • 9
  • 36
  • 58
  • 1
    OK the only thing that wasn't set as your details was the `Executable path` under debugger settings. So i set it to *C:\MinGW\bin\gdb.exe* as you said but it still isn't working. (i checked if i have a *gdb.exe* file in *c:\MinGW\bin*, and i do). – Alaa M. May 03 '14 at 09:06
  • @Alaa Is the `Start/Continue` menu option available now, at least? – cf- May 03 '14 at 09:07
  • No. Nothing seems to be changed – Alaa M. May 03 '14 at 09:07
  • Just to make sure - your project's path has no spaces in it, and you're building with symbols enabled (`-g`), right? – cf- May 03 '14 at 09:15
  • When i started coding i just opened an empty `New File` and not a `Project`. I saved the file in *C:\MinGW\bin* (so no spaces there). Regarding building with / without symbols, do you mean *Settings->Compiler->Produce Debuggin Symbols [-g]* ? If so then i have it disabled. But i just tried enabling it and nothing changed. – Alaa M. May 03 '14 at 09:25
  • 3
    Hmm. I suggest creating a project and seeing if that helps. I've not tried working with just a plain file. And I meant `Project` -> `Build Options` -> `Produce debugging symbols`, but `Settings` -> `Compiler` -> `Produce debugging symbols` works too (that's the global form of the setting). You want that to be checked, since it's not possible to debug a program without debug symbols. – cf- May 03 '14 at 09:28
  • Yeap, that's it, creating through project-wise settings and gestures will solve your issue as it brings closer to the standard uses of the tool. – GingerHead May 03 '14 at 09:38
3

remember about this: http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks#Path_with_spaces

Breakpoints could not work if the path/folder you've placed your project contains spaces or other special characters. To be safe use English letters, digits and '_'.

murison
  • 3,640
  • 2
  • 23
  • 36
0

Check out the following things:

  1. You do not have spaces included in your project path directory.
  2. You do not have spaces included in any of the project files.(eg. .cbp file, .c file)
  3. If you are running codeblock on ubuntu then make sure you are running it as superuser.(eg. >gksu codeblocks)

Instead of space, you can use underscore(_) character.

0

For my sitiuation, there were 2 difference gdp path to be selected in Settings -> Debugger. Exe was stopped when i debug in secound path was selected. So, i changed my debugger path to correct path where is codeblocks is installed.(first path).

It works :)

  1. C:\Program Files (x86)\CodeBlocks\MinGW\gdb32\bin
  2. C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin
Nikolas
  • 13
  • 1
  • 5
0

The best way to handle the problem is if you put the code on a project then the debugging tool will be available then

nebiyu
  • 1
0

I was facing the same problem. What worked for me is that after you have selected gdb in settings compiler and debugger menu, JUST CREATE A NEW PROJECT DO NOT CONTINUE WORKING ON THE CURRENT PROJECT debugging menu will be enabled.

Tariq
  • 1