Author Topic: No console output window while debugging console app on Mac OS X  (Read 31268 times)

Offline edwin

  • Multiple posting newcomer
  • *
  • Posts: 38
Hello,

If I may, I would like to ask for help in getting a console window displayed while debugging a simple console app on OS X.


More info…

I am developing a console application (driver app) that is used to test/verify a Window/Linux/OS X porting package I am developing for a VOIP project.

The porting package and the console app development is going well. I use CodeBlocks SVN 6215 (built from the sources) on Mac OS X Snow Leopard 10.6.3.

Question 1:
Is it possible while debugging to get a console output window displayed?

I searched this forum to see if I was missing some simple configuration setting. I did see the following post:

Console app run/debugging for MacOSX:
http://forums.codeblocks.org/index.php?topic=4608.0

…but I still am not able to get the debugged console app’s console window displayed while debugging. Hmmm… strange….

I am aware of the settings in the “Setting->Environment dialog named:

“Shell to run command in:”
“Terminal to launch console programs:”


They are currently set to:

/bin/sh -c
osascript -e 'tell app "Terminal" to do script "$SCRIPT"'

It is probably some simple error I am making that is causing the apps console window to not display while I am debugging but I can’t seem to figure it out.


Thank you for your help,

edwin



Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: No console output window while debugging console app on Mac OS X
« Reply #1 on: June 04, 2010, 09:13:14 pm »
Do you see the console when you hit the run button?
If yes, can you provide the debugger's debug log!

This log is shown by going to Settings -> Compiler & Debugger -> Debugger -> Display debugger's log...

Also you should check if you debugger (gdb from apple probably) supports the tty command...
C::B should have executed the:
> tty /dev/pts/2
(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 edwin

  • Multiple posting newcomer
  • *
  • Posts: 38
Re: No console output window while debugging console app on Mac OS X
« Reply #2 on: June 04, 2010, 09:25:29 pm »
Hi oBFusCATed,

Thank you for your quick reply.

I do not see the console when I hit the run button (when I run the consol app target using CodeBlocks).

Other than the console window not being displayed, everything else seems normal for the debug sessions.

I can get you whatever info you might need if you can help…


edwin



Offline edwin

  • Multiple posting newcomer
  • *
  • Posts: 38
Re: No console output window while debugging console app on Mac OS X
« Reply #3 on: June 04, 2010, 09:39:38 pm »
Hi oBFusCATed,

I enabled the debugger log and ran the console app within the debugger again…

The log was generated but I do not see any tty “gdb commands”… should I?



Other Info:

Here is the result of “gdb –version”:

GNU gdb 6.3.50-20050815 (Apple version gdb-1461.2) (Fri Mar  5 04:43:10 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".


Looks like gdb supports the –tty command line switch. Here is some of the text of “man gdb” from the Mac box:

SYNOPSIS
       gdb    [-help] [-nx] [-q] [-batch] [-cd=dir] [-f] [-b bps] [-tty=dev] [-s symfile]
   [-e prog] [-se prog] [-c core] [-x cmds] [-d dir] [prog[core|procID]]



edwin


Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: No console output window while debugging console app on Mac OS X
« Reply #4 on: June 04, 2010, 09:45:01 pm »
I am aware of the settings in the “Setting->Environment dialog named:

“Shell to run command in:”
“Terminal to launch console programs:”


They are currently set to:

/bin/sh -c
osascript -e 'tell app "Terminal" to do script "$SCRIPT"'

The default setting is:
Code
osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "$SCRIPT"' -e 'end tell'

The only difference is that it also tells it to "activate",
i.e. bring the window to the front.

It should still have launched, just in the background...

Quote
It is probably some simple error I am making that is causing the apps console window to not display while I am debugging but I can’t seem to figure it out.

In the build log you should have a line like "Executing:"

You could try running that yourself, in a Terminal window.

Offline edwin

  • Multiple posting newcomer
  • *
  • Posts: 38
Re: No console output window while debugging console app on Mac OS X
« Reply #5 on: June 04, 2010, 10:26:42 pm »
Hi oBFusCATed,

If I go to a console window and execute the command:

osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "$SCRIPT"' -e 'end tell'

An new console window gets created and the “value” contained in $SCRIPT is executed. For the test, the $SCRIPT value contains nothing.


I did look over the debug log. Hmmm….. I do not see any line with text “Execuing”.

Do you think I should post the log to this thread for you to look at?


Thank you,


edwin



Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: No console output window while debugging console app on Mac OS X
« Reply #6 on: June 04, 2010, 10:47:00 pm »
1. Post both logs.
2. Does the "Run" command show the terminal?  (executed with Build -> Run) ?
If it doesn't this means that it is not a debugger problem, but something else.
(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 afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: No console output window while debugging console app on Mac OS X
« Reply #7 on: June 04, 2010, 10:56:10 pm »
An new console window gets created and the “value” contained in $SCRIPT is executed. For the test, the $SCRIPT value contains nothing.

$SCRIPT is a variable with the program to run, possibly with environment and arguments

Quote
I did look over the debug log. Hmmm….. I do not see any line with text “Execuing”.

It should be in the Build log, not the Debug log (you did hit Build/Run, yes ? not Debug/Start)

Offline edwin

  • Multiple posting newcomer
  • *
  • Posts: 38
Re: No console output window while debugging console app on Mac OS X
« Reply #8 on: June 07, 2010, 05:45:50 pm »

Hi oBFusCATed and afb,

Thank you for your help so far.

I understand what you are both suggesting…. I performed a few tests since last Friday. I am performing all of these tests with my project’s Debug build.


Build->Run (Fails from within the IDE if there are spaces in the path to the executable)
I tried performing a “Build->Run” and two terminal windows were displayed. The shell echoed an error that “the path could not be found”. Instantly it looked like “spaces in the path” issues from what I saw.

I specified a new output path in the build project that contained no spaces and the “Build->Run” then did function properly.


Long story short –I then performed “Build->Run” and “Debug->Start” tests. Here are the results:


Build->Run test:

1)
Removed spaces from the executabe's path.

2)
Rebuilt the Debug image.

3) Performed a "Build->Run". Everything worked:

Build Log:
 
Checking for existence: /Development/VOIPMediaEngine/PortingLayerTest/bin/DebugMac32/PortingLayerTest
Executing: osascript -e 'tell app "Terminal"' -e 'activate' -e 'do script "/Development/VOIPMediaEngine/PortingLayerTest/bin/DebugMac32/PortingLayerTest "' -e 'end tell'  (in /Development/VOIPMediaEngine/PortingLayerTest/bin/DebugMac32)
Process terminated with status 0 (0 minutes, 0 seconds)


Debugger Log:

Contained nothing.



Debug->Start test:

1)
Performed a "Debug->Start". This did not work – No terminal window was displayed


Build Log:

-------------- Build: Debug Mac32 in PortingLayerTest ---------------
Target is up to date. Nothing to be done. 


Debugger Log:

DYLD_LIBRARY_PATH=.:
Command-line: /usr/bin/gdb -nx -fullname  -quiet -args bin/DebugMac32/PortingLayerTest
Working dir : /Development/VOIPMediaEngine/PortingLayerTest/
> set prompt >>>>>>cb_gdb:
Reading symbols for shared libraries ... done
(gdb) >>>>>>cb_gdb:
> show version
GNU gdb 6.3.50-20050815 (Apple version gdb-1461.2) (Fri Mar  5 04:43:10 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".
>>>>>>cb_gdb:
> set confirm off
>>>>>>cb_gdb:
> set width 0
>>>>>>cb_gdb:
> set height 0
>>>>>>cb_gdb:
> set breakpoint pending on
>>>>>>cb_gdb:
> set print asm-demangle on
>>>>>>cb_gdb:
> set unwindonsignal on
>>>>>>cb_gdb:
> set disassembly-flavor intel
>>>>>>cb_gdb:
> catch throw
Catchpoint 1 (throw)
>>>>>>cb_gdb:
> source /Applications/AppNew/CodeBlocks.app/Contents/Resources/share/codeblocks/scripts/stl-views-1.0.3.gdb
>>>>>>cb_gdb:
> cd bin/DebugMac32
>>>>>>cb_gdb:
> directory /Development/VOIPMediaEngine/PortingLayerTest/
>>>>>>cb_gdb:
> directory /Development/VOIPMediaEngine/
>>>>>>cb_gdb:
> run
Reading symbols for shared libraries +
+
. done
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Program exited normally.
>>>>>>cb_gdb:
> quit



I can run additional tests if needed.

Thank you both,

edwin



Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: No console output window while debugging console app on Mac OS X
« Reply #9 on: June 07, 2010, 07:48:47 pm »
I've looked at the code and the tty thing is compiled only for wxgtk = linux/freebsd

Code

   #ifdef __WXGTK__
    // create xterm and issue tty "/dev/pts/#" to GDB where
    // # is the tty for the newly created xterm
    m_bIsConsole = (target && target->GetTargetType() == ttConsoleOnly);
    if (m_bIsConsole)
    {
        if (RunNixConsole() > 0 )
        {   wxString gdbTtyCmd;
            gdbTtyCmd << wxT("tty ") << m_ConsoleTty;
            m_State.GetDriver()->QueueCommand(new DebuggerCmd(m_State.GetDriver(), gdbTtyCmd, true));
            DebugLog(wxString::Format( _("Queued:[%s]"), gdbTtyCmd.c_str()) );
        }
    }//if
   #endif//def __WXGTK__


An easy fix (if it works) is to replace
#ifdef __WXGTK__
with
#ifndef __WXMSW__

or to use if (!platform::windows)

But I can test it, because I don't have a osx running...
(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 afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: No console output window while debugging console app on Mac OS X
« Reply #10 on: June 07, 2010, 08:58:42 pm »
I've looked at the code and the tty thing is compiled only for wxgtk = linux/freebsd

Yeah, it would need porting. The AppleScript thing is only for Build/Run, not Debug/Start.

Quote
An easy fix (if it works) is to replace
#ifdef __WXGTK__
with
#ifndef __WXMSW__

The code would look more like /dev/ttyp#, than /dev/pts/# (a little BSD vs. GNU thing)


Most likely the current wxGTK code is broken on FreeBSD too, as it seems to be rather Linux-specific ?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: No console output window while debugging console app on Mac OS X
« Reply #11 on: June 07, 2010, 09:04:32 pm »
I've never tried it on freebsd and no one has reported that is broken (at least recently)
(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 edwin

  • Multiple posting newcomer
  • *
  • Posts: 38
Re: No console output window while debugging console app on Mac OS X
« Reply #12 on: June 07, 2010, 09:41:09 pm »
Thanks to both of you for posting this additional information…

If you two gents would like me to modify the source code and run a few tests, I can certainly make an effort to squeeze it in to my schedule to try to verify an update/fix. I would need your suggested code changes for testing seeing I am not completely up to speed with all the CodeBlocks source code and internal logic yet.

Thank you,

edwin


Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: No console output window while debugging console app on Mac OS X
« Reply #13 on: June 08, 2010, 08:35:43 am »
I've never tried it on freebsd and no one has reported that is broken (at least recently)

I spoke too soon, /dev/pts/ was mostly in the comments - it should be fine with /dev/ttyp:

Code
ps x -o tty,pid,command

So the suggested fix should be good (haven't tried it yet).

Offline edwin

  • Multiple posting newcomer
  • *
  • Posts: 38
Re: No console output window while debugging console app on Mac OS X
« Reply #14 on: June 08, 2010, 01:28:02 pm »
I can test a possible change/fix if either of you can spoon feed me a bit more…

So if I implement the following change:

Quote
An easy fix (if it works) is to replace
#ifdef __WXGTK__
with
#ifndef __WXMSW__

…that is our best bet to get the debug terminal window working on OS X and that would also not break the build for Windows and Linux using the same code base?

I have a build environment all ready to go and could test a change as soon as I can squeeze it in.

Thank you for your efforts. Supurb support.

edwin


Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: No console output window while debugging console app on Mac OS X
« Reply #15 on: June 08, 2010, 02:12:24 pm »
…that is our best bet to get the debug terminal window working on OS X and that would also not break the build for Windows and Linux using the same code base?

It needs a little more work, since it only handles "xterm -T" and not "osascript".

But that's definitely it, it is not setting the right gdb tty on the wxMac platform...


Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: No console output window while debugging console app on Mac OS X
« Reply #16 on: June 08, 2010, 02:47:06 pm »
Fixed, r6336.

Offline edwin

  • Multiple posting newcomer
  • *
  • Posts: 38
Re: No console output window while debugging console app on Mac OS X
« Reply #17 on: June 08, 2010, 04:51:29 pm »
Hi afb,

Whoooaa… I will check this out immediately. This fix will certainly help the Mac debug cycles.

You are indeed awesome sir…

edwin


Offline afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: No console output window while debugging console app on Mac OS X
« Reply #18 on: June 08, 2010, 05:04:29 pm »
Whoooaa… I will check this out immediately. This fix will certainly help the Mac debug cycles.

You are indeed awesome sir…

Even awesomer would have been to catch these before the release...

But I guess we can put up some plugin fixes (keybinder and debugger)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: No console output window while debugging console app on Mac OS X
« Reply #19 on: June 08, 2010, 08:38:37 pm »
afb: probably you could provide nightlies or an rc1 build for the next release...
But I don't know how hard it is to build them :)

Thanks for the fix, hopefully Morten, wouldn't have too much problems merging the fix with the debugger branch changes.

(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 afb

  • Developer
  • Lives here!
  • *****
  • Posts: 884
Re: No console output window while debugging console app on Mac OS X
« Reply #20 on: June 08, 2010, 09:27:37 pm »
afb: probably you could provide nightlies or an rc1 build for the next release...
But I don't know how hard it is to build them :)

Nobody uses the nightlies... At least nothing compared to the releases.

So it's more likely to be a 10.5-p1 "patch" instead. Or maybe just plugins ?

But it's not hard, more like tedious. Takes a few hours and like 5 gigs or so.

Quote
Thanks for the fix, hopefully Morten, wouldn't have too much problems merging the fix with the debugger branch changes.

Don't think so, it's just a couple of lines. So, similar to how it was before.

Offline edwin

  • Multiple posting newcomer
  • *
  • Posts: 38
Re: No console output window while debugging console app on Mac OS X
« Reply #21 on: June 11, 2010, 07:58:52 pm »
Hi afb,

I was briefly diverted to other tasks…

I checked out and built CodeBlocks SVN 6336. The console terminal window is now being displayed during debugger sessions – I can now see the console app’s standard output.

Thanks very much for your effort. It will be a great help in moving forward. Thanks also oBFusCATed.

---------------------------

Other Info:
I have been working with CodeBlocks for a while now on the Mac platform. I have performed “usage type” testing as I have been developing real production code with the IDE. I have made notes regarding what works and appears stable and what seems to have a few hiccups. I use the functionality that works and shy away from the rest.  :)

Currently I am now running a pretty stable configuration of CodeBlocks on the Mac. It is in fact stable enough for me that I am productive using CodeBlock on Mac’s OS X 10.6.3. Exactly the original intended goal. I mean – I am really getting productive.

Note for anyone else reading this: The Windows and especially the Linux builds of CodeBlocks are excellent.


If I may, there are only three issues that – if resolved – would make a big difference immediately for the Mac build:

1)
Editor keyboard input is especially slow.

I don’t know why this is. As soon as I can free up a bit of time, I will try look into this under the debugger. If this could be resolved, it would be very, very good and would immediately impact the user’s productivity. Hopefully this is high on the Mac ToDo list of “things” to investigate.

I have not seen any editor related crashes and everything else about the editor appears stable.


2)
The code completion plugin appears to be related to 2 CodeBlocks crashes I have witnessed.

Two instances of crashing I have seen:

1)
Closing a workspace with the code completion plugin loaded and enabled will crash C::B. This “crash” is repeatable. I have looked over the crash dumps and I can see what led up to the termination. Also, when exiting C::B, the same crash occurs.

2)
When saving configuration settings, CodeBlocks will crash. It appears the code completion plugin is also related to this. Hmmm…..

3)
Menu keyboard shortcuts have some “teething pains”. All of the keyboard shortcut issues have a work around so this is not mission critical. I am just thinking about development productivity – that’s all.

I am a long time keyboard guy and it slows me down whenever I have to grab for the mouse.  :)


In closing:
Right now, I use a minimal set of the plugins. I am working around the code completion plugin related issues – I enable/disable code completion depending on what I need to do. Normally I leave code completion ON because of the productivity boost it yields.

The keyboard input rate is pretty important. I think this is the most important thing to resolve.

I am sure the CodeBlocks development team is aware of this “stuff”. I hope this information is useful non-the-less.

As usual, kudos to the entire development team and great work on this IDE.
Simply wonderful.


Thank you,

edwin



Offline whpatton

  • Single posting newcomer
  • *
  • Posts: 2
Re: No console output window while debugging console app on Mac OS X
« Reply #22 on: July 08, 2010, 06:29:38 am »

http://forums.codeblocks.org/index.php/topic,12678.15.html

RE: codeblocks-10.05-src.tar.bz2 8 June 2010  Berlios download.

The routine \codeblocks-10.05\src\plugins\debuggergdb\debuggergdb.cpp

Needs some more #ifndef __WXMSW__  replacements of   #ifdef __WXGTK__
around the other 2 "linux" specific blocks.
    #ifdef __WXGTK__
    // kill any linux console


and
   #ifdef __WXGTK__
    // create xterm and issue tty "/dev/pts/#" to GDB where
    // # is the tty for the newly created xterm
   
    Also the fail case here needs to set something to suppress the start of GDB
    when a terminal failed to create. Namely, the case  RunNixConsole < 0.
    Currently if the terminal does not start but  GDB does anyway.
    Then it never terminates and does not respond to the Stop Debugger
    button on the menu. This propagates also out to a few more warnings about the
    dubgger not stopped even when closing the IDE.
   
    Possibly the thing to do is to test and return -1 if RunNixConsole is <0.
    This would match the case about 8 lines above after the  wxMilliSleep wait for 
        // start polling gdb's output
        ...
        if (!m_State.HasDriver())
        return -1;
   
 
 As in my prior message,http://forums.codeblocks.org/index.php/topic,12856.0.html
 I would like a conditionally longer wait for NiX terminal start.  - How about similar to the
 xwMillisleep wait above.
 
 replace: in routine int DebuggerGDB::RunNixConsole()
     // Issue the PS command to get the /dev/tty device name
     // First, wait for the xterm to settle down, else PS won't see the sleep task
     Manager::Yield();
     ::wxSleep(1);
     m_ConsoleTty = GetConsoleTty(m_nConsolePid);

with:
     // Issue the PS command to get the /dev/tty device name
     // First, wait for the xterm to settle down, else PS won't see the sleep task
    int i = 20;  // wait up to 20 ( half seconds ) for the terminal to start before failing
    while (i)
    {
        Manager::Yield();
        wxMilliSleep(500);  // half second
        Manager::Yield();
        --i;
        m_ConsoleTty = GetConsoleTty(m_nConsolePid);
        if (not m_ConsoleTty.IsEmpty() ) i = 0;
    }
 
 
 Thanks  William
   

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: No console output window while debugging console app on Mac OS X
« Reply #23 on: July 08, 2010, 08:58:06 am »
Thanks for the suggestions, I'll implement the waiting for the terminal some day,
but this will happen in the debugger branch, there the code is a bit different.
Of course patches against the debugger branch are welcome ( svn diff > file.patch).

Here is the branch: http://svn.berlios.de/wsvn/codeblocks/branches/wxpropgrid_debugger/?rev=6384&peg=6384#ab1bb068457ecc925a5b07fe41a91d401
If you can give some feedback it will be great.

p.s. Please use [ code ] [/ code ] tags, your post are hardly readable.
(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!]