Author Topic: Console app run/debugging for MacOSX  (Read 11271 times)

Offline bnilsson

  • Almost regular
  • **
  • Posts: 184
Console app run/debugging for MacOSX
« on: November 29, 2006, 09:45:44 pm »
How is the progress on run/debug a console apps from CB on MacOSX?
The xterm launch is not, as we all know, working here.
It would be very handy for number crunching programs that wants input without GUI.
Will it be difficult to fix?

I guess it needs to be interfaced to the regular Terminal program.
Or is there any other solution?

-- Ingnorance should not be taken for stupidity --

HW: PowerMac Dual PowerPC G5 2.3Ghz, 1GB RAM OS: MacOSX 10.4.10 Compiler: powerpc-apple-darwin8-gcc-4.0.1

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #1 on: November 29, 2006, 09:59:29 pm »
Will it be difficult to fix?

It's done, just not fully tested/integrated yet.
http://developer.berlios.de/bugs/?func=detailbug&bug_id=8987&group_id=5358

Quote
I guess it needs to be interfaced to the regular Terminal program.

For a preview of it, here is the patch to apply:
http://developer.berlios.de/patch/?func=detailpatch&patch_id=1667&group_id=5358

And yes, it sends an AppleScript to Terminal.app
« Last Edit: November 29, 2006, 10:03:39 pm by afb »

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #2 on: November 29, 2006, 10:02:10 pm »
The xterm launch is not, as we all know, working here.

BTW: xterm launch should be working on Mac OS X, but it does assume you
have X11.app running and that /usr/X11R6/bin/xterm is in your PATH...

The code I did will use Terminal.app for wxMac and X11.app/xterm for wxGTK.

Offline bnilsson

  • Almost regular
  • **
  • Posts: 184
Re: Console app run/debugging for MacOSX
« Reply #3 on: November 29, 2006, 11:54:00 pm »
xterm is not working from CB for me.
Trying to "run" a console app called "dxfcnv" with X11 running and the path to xterm in my normal environment:

Quote
Checking for existence: /Users/bnilsson/Documents/Programming/Active/CB_projects/dxfcnv/dxfcnv
Executing: xterm -T 'dxfcnv' -e 'LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH "/Users/bnilsson/Documents/Programming/Active/CB_projects/dxfcnv/dxfcnv" ' (in /Users/bnilsson/Documents/Programming/Active/CB_projects/dxfcnv/.)
Process terminated with status 255 (0 minutes, 0 seconds)

I also tried adding "/usr/X11R6/bin" to Compiler and.. Settings -> Programs -> Additional Paths and there was a difference:
(I need to have "/opt/local/bin" there, otherwise wx-config don't run. Strange, but true.)
Quote
Checking for existence: /Users/bnilsson/Documents/Programming/Active/CB_projects/dxfcnv/dxfcnv
Executing: xterm -T 'dxfcnv' -e 'LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH "/Users/bnilsson/Documents/Programming/Active/CB_projects/dxfcnv/dxfcnv" ' (in /Users/bnilsson/Documents/Programming/Active/CB_projects/dxfcnv/.)
Process terminated with status 1 (0 minutes, 0 seconds)

I do not know the difference between 255 and 1 in this case. Anyway, no activity was seen in the running X11 application.

I will try the Terminal patch and see what's happens.
-- Ingnorance should not be taken for stupidity --

HW: PowerMac Dual PowerPC G5 2.3Ghz, 1GB RAM OS: MacOSX 10.4.10 Compiler: powerpc-apple-darwin8-gcc-4.0.1

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #4 on: November 30, 2006, 12:06:30 am »
You need to have three things:
  • /usr/X11R6/bin in your $PATH
  • :0.0 in your $DISPLAY
  • X11.app up and running


With that, you should be able to do:
Code: [Select]
xterm -e 'read'and it should open an X11 xterm ?

Note: you might want to get xterm going by itself, before trying to use it from within Code::Blocks ? (i.e. the xterm commands that C::B is executing should be working if you run them in a Terminal)

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #5 on: November 30, 2006, 12:34:23 am »
On second thought, it might not be possible to do that in the wxMac version of Code::Blocks - you might need to run the wxGTK version of it, or just apply/wait for the Terminal.app patch.

Offline bnilsson

  • Almost regular
  • **
  • Posts: 184
Re: Console app run/debugging for MacOSX
« Reply #6 on: November 30, 2006, 10:25:05 pm »
I guess what might be missing for me is that CB is not aware of any $DISPLAY.
Can I set this somewhere?
"Compiler..Settings -> Custom variables" is not doing the trick.

(And the patch did not do any difference, still xterm)
Quote
Checking for existence: /Users/bnilsson/Documents/Programming/Active/CB_projects/dxfcnv/dxfcnv
Executing: xterm -T 'dxfcnv' -e DYLD_LIBRARY_PATH=.:$DYLD_LIBRARY_PATH "&quote&"/Users/bnilsson/Documents/Programming/Active/CB_projects/dxfcnv/dxfcnv"&quote&"  (in /Users/bnilsson/Documents/Programming/Active/CB_projects/dxfcnv/.)
Process terminated with status 1 (0 minutes, 0 seconds)
-- Ingnorance should not be taken for stupidity --

HW: PowerMac Dual PowerPC G5 2.3Ghz, 1GB RAM OS: MacOSX 10.4.10 Compiler: powerpc-apple-darwin8-gcc-4.0.1

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #7 on: November 30, 2006, 11:37:17 pm »
I guess what might be missing for me is that CB is not aware of any $DISPLAY.
Can I set this somewhere?
"Compiler..Settings -> Custom variables" is not doing the trick.

I set it in /etc/profile.

Quote
(And the patch did not do any difference, still xterm)

It's a preference, so if you have an old setting of xterm
you probably want to change it to the new "osascript..."

Offline bnilsson

  • Almost regular
  • **
  • Posts: 184
Re: Console app run/debugging for MacOSX
« Reply #8 on: December 01, 2006, 07:38:41 am »
Non comprendo:
Quote
It's a preference, so if you have an old setting of xterm
you probably want to change it to the new "osascript..."
Please explain?
-- Ingnorance should not be taken for stupidity --

HW: PowerMac Dual PowerPC G5 2.3Ghz, 1GB RAM OS: MacOSX 10.4.10 Compiler: powerpc-apple-darwin8-gcc-4.0.1

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #9 on: December 01, 2006, 09:44:15 am »
In the C::B Settings > Environment dialog:
("Terminal to launch console programs in:")

For wxMac (patched), this should be:
Code: [Select]
osascript -e 'tell app "Terminal" to do script "$SCRIPT"'
For wxGTK (e.g. linux), it is instead:
Code: [Select]
xterm -T $TITLE -e
Worst case, wiping the preferences works.

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #10 on: December 01, 2006, 09:49:03 am »
Also, I revised the wxMac code to not use AppleScript quotes ("&quote&") unless your command actually contains $SCRIPT.

Offline bnilsson

  • Almost regular
  • **
  • Posts: 184
Re: Console app run/debugging for MacOSX
« Reply #11 on: December 01, 2006, 03:30:23 pm »
As usual, I feel a bit stupid, but this is what I get using Terminal...
Quote
Last login: Fri Dec  1 15:27:09 on ttyp6
Welcome to Darwin!
You have mail.
$SCRIPT
executing /etc/profile...
executing /etc/bashrc...
executing .bash_login...
mc2-p039:~ bnilsson$ $SCRIPT
mc2-p039:~ bnilsson$
-- Ingnorance should not be taken for stupidity --

HW: PowerMac Dual PowerPC G5 2.3Ghz, 1GB RAM OS: MacOSX 10.4.10 Compiler: powerpc-apple-darwin8-gcc-4.0.1

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #12 on: December 01, 2006, 03:41:37 pm »
the code snippets above was for Code::Blocks.
$TITLE then gets replaced with the projects title,
and $SCRIPT gets replaced with an AppleScript

Unless you have some complex settings, the
easiest is probably to move away the old folder
at ~/Library/Application\ Support/CodeBlocks ?

Offline bnilsson

  • Almost regular
  • **
  • Posts: 184
Re: Console app run/debugging for MacOSX
« Reply #13 on: December 01, 2006, 04:02:46 pm »
Sorry if I was not clear.
The quote was from the Terminal output when I had introduced
Quote
osascript -e 'tell app "Terminal" to do script "$SCRIPT"'
in the Environment settings and done "run" of my console app from within Code::Blocks.

Removing ~/Library/Application \Support/codeblocks did not make any difference.
« Last Edit: December 01, 2006, 04:06:19 pm by bnilsson »
-- Ingnorance should not be taken for stupidity --

HW: PowerMac Dual PowerPC G5 2.3Ghz, 1GB RAM OS: MacOSX 10.4.10 Compiler: powerpc-apple-darwin8-gcc-4.0.1

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #14 on: December 01, 2006, 04:08:53 pm »
You did install the patch, right ?

Anyway, leave it for now and make another try when it's in the trunk...

Offline bnilsson

  • Almost regular
  • **
  • Posts: 184
Re: Console app run/debugging for MacOSX
« Reply #15 on: December 01, 2006, 04:42:21 pm »
Oh dear..
I started with this at home yesterday, applying the patch.
Today I continued at some spare time at work, forgetting that the patch was not applied here. Sorry!
Now "run" works fine with Terminal, but not debug. Maybe debug/Terminal is not working yet?
-- Ingnorance should not be taken for stupidity --

HW: PowerMac Dual PowerPC G5 2.3Ghz, 1GB RAM OS: MacOSX 10.4.10 Compiler: powerpc-apple-darwin8-gcc-4.0.1

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #16 on: December 01, 2006, 04:45:25 pm »
There is a debug/Terminal ?  :-o OK, will add that too then :-)

Offline bnilsson

  • Almost regular
  • **
  • Posts: 184
Re: Console app run/debugging for MacOSX
« Reply #17 on: December 02, 2006, 04:34:12 pm »
Checking the "run" function at home, and the test was not successful:
Quote
[Tiger:~] bnilsson% DYLD_LIBRARY_PATH=.:$DYLD_LIBRARY_PATH "/Users/bnilsson/Documents/Programming/Active/CB_projects/dxfcnv/dxfcnv"
tcsh: DYLD_LIBRARY_PATH=.:/Users/bnilsson/lib: Command not found.
The only difference being that here I use /bin/tcsh and at work I use /bin/bash as shell in my user setup. After changing ny shell to /bin/bash it worked.

Seems it is sensitive to the shell used.
I tried different shells in the "Environment" setting "Shell to run commands in", but there was no difference.
Is it not active?

-- Ingnorance should not be taken for stupidity --

HW: PowerMac Dual PowerPC G5 2.3Ghz, 1GB RAM OS: MacOSX 10.4.10 Compiler: powerpc-apple-darwin8-gcc-4.0.1

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #18 on: December 02, 2006, 05:11:30 pm »
The only difference being that here I use /bin/tcsh and at work I use /bin/bash as shell in my user setup. After changing ny shell to /bin/bash it worked. Seems it is sensitive to the shell used.

Tcsh/csh is not supported at the moment. (I wouldn't recommend it to anyone, either)
However, if you supply the syntax it can be made into an Terminal syntax option or so ?

Code: Text
  1. setenv DYLD_LIBRARY_PATH ".:$DYLD_LIBRARY_PATH";
  2. "/Users/bnilsson/Documents/Programming/Active/CB_projects/dxfcnv/dxfcnv"

Quote
I tried different shells in the "Environment" setting "Shell to run commands in", but there was no difference.
Is it not active?

I believe the current "shell" setting is only used in variable expansion, running tools, etc.

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #19 on: December 04, 2006, 05:57:09 pm »
Would this (new) code work for you:
Code: [Select]
#if defined(__APPLE__) && defined(__MACH__)
    #define LIBRARY_ENVVAR "DYLD_LIBRARY_PATH"
#else
    #define LIBRARY_ENVVAR "LD_LIBRARY_PATH"
#endif
        wxString shell;
        wxGetEnv(_T("SHELL"), &shell);
        if (shell.Contains(_T("csh")))
            command << _T("'") << _T("setenv " LIBRARY_ENVVAR " .:$" LIBRARY_ENVVAR " &&") << _T(" ");
        else
            command << _T("'") << _T("" LIBRARY_ENVVAR "=.:$" LIBRARY_ENVVAR) << _T(" ");

It should use setenv for csh and tcsh.

Offline bnilsson

  • Almost regular
  • **
  • Posts: 184
Re: Console app run/debugging for MacOSX
« Reply #20 on: December 04, 2006, 06:41:03 pm »
I will try it.
However, the arguments against /bin/tcsh are strong, so I changed to /bin/bash.
But I will try it with /bin/tcsh, it's easy to switch.

Any progress with the console Terminal debugger?

-- Ingnorance should not be taken for stupidity --

HW: PowerMac Dual PowerPC G5 2.3Ghz, 1GB RAM OS: MacOSX 10.4.10 Compiler: powerpc-apple-darwin8-gcc-4.0.1

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #21 on: December 04, 2006, 07:51:06 pm »
I will try it.
However, the arguments against /bin/tcsh are strong, so I changed to /bin/bash.
But I will try it with /bin/tcsh, it's easy to switch.

Actually there are systems aside from Mac OS X 10.2 that ships with csh as their default shell (PC-BSD did, for instance), so it doesn't hurt to add a feature to support it. Just that I don't like it myself :-)

I'm normally using zsh, so a little choice never hurts.

Quote
Any progress with the console Terminal debugger?

I have Build > Run, and I have Debug > Start. What I am looking at for the "console debugger" ?

Did you have some simple steps to test/reproduce the issue, and I'm sure it could be fixed as well.

Offline bnilsson

  • Almost regular
  • **
  • Posts: 184
Re: Console app run/debugging for MacOSX
« Reply #22 on: December 17, 2006, 12:11:34 pm »
What I would ask for is the same behaviour as Run, i.e. to be able to communicate with the app via the Terminal keyboard, but being able to use breakpoints and watches to debug the session.

Right now, l if I start a debug session for a console app, no terminal window appears so I cannot use interactive mode in controlling the application.

 
-- Ingnorance should not be taken for stupidity --

HW: PowerMac Dual PowerPC G5 2.3Ghz, 1GB RAM OS: MacOSX 10.4.10 Compiler: powerpc-apple-darwin8-gcc-4.0.1

Offline bnilsson

  • Almost regular
  • **
  • Posts: 184
Re: Console app run/debugging for MacOSX
« Reply #23 on: December 17, 2006, 12:25:41 pm »
Regarding the above suggestion:
Quote
Would this (new) code work for you:
Could you please tell me exactly where to put this in?
I assume it is in compilergcc.cpp, but this file may be revised to the extent that the pattern does not look the same now, since I did not respond right away.
-- Ingnorance should not be taken for stupidity --

HW: PowerMac Dual PowerPC G5 2.3Ghz, 1GB RAM OS: MacOSX 10.4.10 Compiler: powerpc-apple-darwin8-gcc-4.0.1

Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: Console app run/debugging for MacOSX
« Reply #24 on: December 18, 2006, 12:36:12 pm »
I'll post a revised snippet, just a little busy with wx 2.8.0 first...

I think the support for Terminal.app and /bin/csh should be able
to go right in, but will update and test with a newer Code::Blocks