Author Topic: Can't debug programs from Code::Blocks on Mac OSX  (Read 26853 times)

Offline Yannick Semail

  • Single posting newcomer
  • *
  • Posts: 2
Can't debug programs from Code::Blocks on Mac OSX
« on: June 20, 2013, 10:24:51 pm »
Here is the setup:
Code::Blocks 12.11
Gcc/g++ 4.7.3 from Macports installed in /opt/local/bin
ggdb 7.6 (updated gdb) from Macports installed in /opt/local/bin

Changed the debugger in Code::Blocks/Settings/Debugger/Default/Executable path: /opt/local/bin/ggdb

Kept the default Environment setting Terminal to launch console program to:
osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "$SCRIPT"' -e 'end tell'

Any C/C++ program that is being debugged stalls with gdb not stopping at breakpoints:

Here is a debugging log:
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: /Users/yannick/Dropbox/0.Development/SFML.Working.Example/
Adding source dir: /Users/yannick/Dropbox/0.Development/SFML.Working.Example/
Adding file: /Users/yannick/Dropbox/0.Development/SFML.Working.Example/SFMLapplication
Changing directory to: /Users/yannick/Dropbox/0.Development/SFML.Working.Example/.
Set variable: DYLD_LIBRARY_PATH=.:
Starting debugger: /opt/local/bin/ggdb -nx -fullname  -quiet  -args /Users/yannick/Dropbox/0.Development/SFML.Working.Example/SFMLapplication
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Can't launch console (osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script ""' -e 'end tell' sleep 80006888)
Debugger name and version: GNU gdb (GDB) 7.6

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #1 on: June 20, 2013, 10:30:21 pm »
Can't launch console (osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script ""' -e 'end tell' sleep 80006888)
As far as I know the command used to launch the terminal has changed, but I have no mac where I can set the proper command.
Please experiment and tell me which it is.
(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 phisch2

  • Single posting newcomer
  • *
  • Posts: 6
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #2 on: January 13, 2014, 04:20:46 pm »
Can a developer indicate what steps need to be taken to troubleshoot this problem?  I need to get the debugger working on Mac for my class.  I have a Mac and can run whatever tests are needed.  FWIW, the included command to activate the terminal works fine to open the terminal for a regular run, just not for debug sessions.  The debugger process does seem to be running, but when the terminal opens the program being debugged is not running in that terminal window.  Some sort of debugger attachment issue?
Thanks,

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #3 on: January 13, 2014, 07:38:44 pm »
Can you do the following test:

Start several terminals, then use ps in a terminal to see how many executables there are?
Also how many terminals do you have when the terminal fails. Try to close them all and repeat the procedure.

Also check if debugging a GUI project works. See the details in the other topic you've started.
(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 SteveBerl

  • Single posting newcomer
  • *
  • Posts: 3
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #4 on: February 24, 2014, 03:27:51 am »
Can you do the following test:

Start several terminals, then use ps in a terminal to see how many executables there are?
Also how many terminals do you have when the terminal fails. Try to close them all and repeat the procedure.

Also check if debugging a GUI project works. See the details in the other topic you've started.

New to Code::Blocks, but found this thread and tried what you asked. The number of bash processes is always the same as the number of terminal windows I open.

Each time I attempt to debug my HelloWorld.cpp console program, a new terminal window opens and gives a shell prompt, but the debug window in Code::Blocks complains that it Can't open console. The debugger seems to be live, and talking to my program. I can see a gdb process running. From the Code::Blocks window I can step through my code. But the terminal window doesn't seem to be connected to it.

When I can get one to build, I will try to debug a GUI project also and see how that goes.


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #5 on: February 24, 2014, 09:28:30 am »
The number of bash processes is always the same as the number of terminal windows I open.
I'm not interested in the number of bash processes, but the number of terminal processes (whatever it the proper name).
If the terminal app is reusing processes, then you have to build latest C::B and report if the bug is fixed.
We tried to fix similar problem on linux, but it happened after the release.
(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 SteveBerl

  • Single posting newcomer
  • *
  • Posts: 3
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #6 on: February 24, 2014, 07:53:37 pm »
There is 1 Terminal process. It spawns a login process for each window. That login process then spawns a bash shell for each window.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #7 on: February 24, 2014, 08:29:51 pm »
Then you need to build from latest sources or wait for the next release.
Another option is to use another terminal that doesn't do the single process thing.
(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 SteveBerl

  • Single posting newcomer
  • *
  • Posts: 3
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #8 on: February 24, 2014, 09:21:26 pm »
I guess that implies that there are no nightly builds for Mac these days :-(
I will try building from latest source when I get a few minutes.

A bit off topic, does anyone know for sure what version of wxwidgets I need to install for a GUI app on my ma running Mac OS 10.9.1 (Mavericks)?

-steve

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #9 on: February 24, 2014, 10:20:01 pm »
There are no nightlies, because there is no dev using OSX lately, sorry.

About wx, cb is not very stable running wx30, so wx2.8 is recommented, but on OSX wx2.8 is not that usable...
(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 Isa

  • Single posting newcomer
  • *
  • Posts: 3
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #10 on: March 21, 2014, 11:34:43 am »
Hi,
I used to use Code::Blocks on Windows but have to use Mac OS for working and have problem using C::B on this OS.
I have a silly question:

I do not know what should be in the Settings/Debugger/Default/Executable path for me??
(nothing was written by default)

For info: I am using Code::Blocks 12.11
Mac OS X version 10.9.2
In Settings/Compiler/Toolchain executables/Compiler's installation directory, I have: /usr
Compiling and run any "Hello World!" or other programs works, but when I am trying to use the debugger, it does not work and I have the following message:
ERROR: You need to specify a debugger program in the debuggers's settings.
(For GCC compilers, it's 'gdb' (without the quotes))

Thanks!






Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #11 on: March 21, 2014, 08:23:33 pm »
You need to install gdb and use the path to it.
I don't know if it is still provided by Apple or you need to use some other means to install it.
(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 Isa

  • Single posting newcomer
  • *
  • Posts: 3
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #12 on: March 24, 2014, 11:35:34 am »
Indeed, many thanks!
Just for beginners like ma, this web page was really useful:
http://wiki.lazarus.freepascal.org/GDB_on_OS_X_Mavericks_and_Xcode_5

But however, now I have the same problem as Yannick who began this post...:

Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: /Users/Isabelle/Desktop/These/TROLL/essais_simulations/esssssai/
Adding source dir: /Users/Isabelle/Desktop/These/TROLL/essais_simulations/esssssai/
Adding file: /Users/Isabelle/Desktop/These/TROLL/essais_simulations/esssssai/bin/Debug/esssssai
Changing directory to: /Users/Isabelle/Desktop/These/TROLL/essais_simulations/esssssai/.
Set variable: DYLD_LIBRARY_PATH=.:
Starting debugger: /usr/local/bin/gdb -nx -fullname  -quiet  -args /Users/Isabelle/Desktop/These/TROLL/essais_simulations/esssssai/bin/Debug/esssssai
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Can't launch console (osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script ""' -e 'end tell'  sleep 80000336)
Debugger name and version: GNU gdb (GDB) 7.7
Debugger finished with status 1


I have difficulties to finally sort out if you found any solutions to this;

"Can't launch console (osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script ""' -e 'end tell'  sleep 80000336)" problem....

Thanks a lot again!

Offline Isa

  • Single posting newcomer
  • *
  • Posts: 3
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #13 on: March 24, 2014, 01:52:36 pm »
for info:
when I try to execute this:
osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script ""' -e 'end tell' sleep 80000255
in a terminal,
it opens a new terminal window,
as said here:
http://forums.codeblocks.org/index.php?topic=17681.0



Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #14 on: March 24, 2014, 09:10:23 pm »
I think this is fixed in the latest trunk code, but no one has made a build to test it.

We had similar problems with newer linux terminal emulators and now there it works perfectly.
(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!]

sswater

  • Guest
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #15 on: March 29, 2014, 06:30:22 pm »
Exactly the same problem! It can RUN but cannot DEBUG.

When RUN, it seems that the $SCRIPT in ( osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "$SCRIPT"' -e 'end tell' ) is successfully passed in, while when DEBUG, the $SCRIPT is empty.

Offline ridge

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Can't debug programs from Code::Blocks on Mac OSX
« Reply #16 on: January 11, 2017, 10:52:24 am »
[SOLVED] Debugging works on Mac OSX using xterm.

OSX Version: 10.11 (El Capitan)
CodeBlocks Version: 13.12

Start Terminal from /Applications/Utilities.

Install homebrew
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install debugger
$ brew install gdb

Codesign the gdb binary and kill taskgated:
Guide: https://sourceware.org/gdb/wiki/BuildingOnDarwin
(Note: You must make sure that taskgated is killed when following the guide.
Then, you should get a pop-up when using gdb within codeblocks the first
time, asking for credentials.)

In Terminal:
$ /usr/local/bin/gdb -v    (make sure it works)
(You could prepend your PATH with /usr/local/bin in your .bash_profile.
However, note that codeblocks won't see your PATH.)

Install XQuartz
Browser: https://www.xquartz.org/
(click on the .dmg, double-click after download, follow instructions)
Reboot (you could just log-out and log-in but the reboot should solve the taskgated issue, too)
First, start XQuartz from /Applications/Utilities.
In Terminal:
$ /opt/X11/bin/xterm   (make sure it works)
If you get the "Xt error: Can't open display" problem, you probably didn't reboot or log out.

In CodeBlocks: Settings->Debugger
Click Default
Set Executable path: /usr/local/bin/gdb

In CodeBlocks: Settings->Environment
Set Terminal to launch console programs: /opt/X11/bin/xterm -e $SCRIPT
Ignore the warning in the xterm window (the debugger seems to work fine):
warning: GDB: Failed to set controlling terminal: Operation not permitted
« Last Edit: January 12, 2017, 09:46:03 pm by ridge »