Author Topic: linux Debug Console race condition  (Read 5341 times)

Offline whpatton

  • Single posting newcomer
  • *
  • Posts: 2
linux Debug Console race condition
« on: July 04, 2010, 10:33:30 pm »

Issue linux Debug Console race condition.
   Ubuntu 8.04 portable coLinux  http://sourceforge.net/projects/portableubuntu/
   Code::Blocks Release 10.05 rev 6282    wx2.8.10  (Linux, unicode) - 32 bit

Please add an item to Compiler and debugger settings ->
        Debugger initialization commands ->
                Wait time for debug console to attach ( seconds)  5

   instance variable debug_console_attach_delay  for Debugger to use for wait.
                     
The current wait is too short for the above kind of slow configuration.
A new xterm seems to take about 3 seconds to start probably due to the windows Xserver
and context switching in the coLinux.

I think this happens sporadically to other linux users:
        erratic debug window
        http://forums.codeblocks.org/index.php/topic,11890.msg80807.html#msg80807
        and various others who sometimes do not get debug to start a console.
                  PS result: tty1      4221 xterm -hold -wf -T Program Console -e sleep 84096
I cannot tell if it might happen to programs that load lots of big dll's.
Related - http://forums.codeblocks.org/index.php/topic,11760.msg79838.html#msg79838
   http://forums.codeblocks.org/index.php/topic,9722.msg71299.html#msg71299

       
At issue is the single sleep in routine
\codeblocks-10.05\src\plugins\debuggergdb\debuggergdb.cpp

int DebuggerGDB::RunNixConsole()
{
#ifndef __WXMSW__
..
    //start xterm -e sleep {some unique # of seconds}
    m_nConsolePid = wxExecute(cmd, wxEXEC_ASYNC);
    if (m_nConsolePid <= 0) return -1;

    // 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);
    if (not m_ConsoleTty.IsEmpty() )
   
    ...
xxxxxxxxxxxxxxxxxxxxxxxxx   
 I am asking for the ::wxSleep(1);   to use an externally configured variable for the delay.
 
 It would be better to restructure the delay to loop for at most that many seconds
      by polling ps every (half) second with the yield;sleep;
 until m_ConsoleTty  succeeds or time expires.
 
 
 It might be possible to fix this earlier in the debugger by pre creating a permanent debug terminal
 associated with the IDE.  Then GDB could instead start the main exe  rather than attach to the tty.
 This is probably trickier.  However it is nearly what happens now because the
 MAGIC ID for the process name is effectively bound to the IDE instance and does not change.
        cmd << wxString::Format(wxT("%d"),80000 + ::wxGetProcessId());
 
 
Here is a possibly slightly annotated? log from a successful session
Executing: xterm -hold -wf -T 'Program Console' -e sleep 83514
    // pass user init-commands
Executing: ps x -o tty,pid,command
PS result: tty1      4012 ps x -o tty,pid,command
PS result: pts/1     4011 sleep 83514

Breakpoint 4 at 0x80487d9: file /home/pubuntu/Documents/Tutorial/tutprog/main.cpp, line 10.
>>>>>>cb_gdb:
Executing: ps x -o tty,pid,command
PS result: tty1      4003 ps x -o tty,pid,command
PS result: pts/1     4002 sleep 83514
TTY is[/dev/pts/1]
GetConsoleTTY[/dev/pts/1]ConsolePid[4001]
> tty /dev/pts/1
Queued:[tty /dev/pts/1]
>>>>>>cb_gdb:


xxxxxxxxxxxx
and a clean log from a failed session. The key log message is
Console Execution error:failed to find console tty.

xxxxxxxxx
LD_LIBRARY_PATH=.:
Command-line: /usr/bin/gdb -nx -fullname  -quiet -args bin/Debug/tutprog
Working dir : /home/pubuntu/Documents/Tutorial/tutprog/
(gdb)
> set prompt >>>>>>cb_gdb:
Executing: xterm -hold -wf -T 'Program Console' -e sleep 84096
Executing: ps x -o tty,pid,command
>>>>>>cb_gdb:
> show version
PS result: tty1      4222 ps x -o tty,pid,command
PS result: tty1      4221 xterm -hold -wf -T Program Console -e sleep 84096
PS result: tty1      4220 /usr/bin/gdb -nx -fullname -quiet -args bin/Debug/tutprog
PS result: tty1      4096 codeblocks
PS result: pts/0     4042 bash
PS result: tty1      4041 gnome-pty-helper
PS result: tty1      4039 gnome-terminal
PS result: tty1      4036 gksu -g /usr/sbin/synaptic
PS result: tty1      3469 gedit /home/pubuntu/cpp_course/src/Makefile.in
PS result: tty1      3391 nautilus --no-desktop file:///etc/portable_ubuntu
PS result: ?         3197 /usr/lib/gnome-applets/mixer_applet2 --oaf-activate-iid=OAFIID:GNOME_MixerApplet_Factory --oaf-ior-fd=17
PS result: ?         3183 /usr/lib/bonobo-activation/bonobo-activation-server --ac-activate --ior-output-fd=15
PS result: tty1      3181 /usr/lib/libgconf2-4/gconfd-2 12
PS result: tty1      3179 gnome-panel
PS result: tty1      3178 gnome-settings-daemon
PS result: ?         3177 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
PS result: tty1      3153 -bash
PS result: TT         PID COMMAND
Console Execution error:failed to find console tty.
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
>>>>>>cb_gdb:
> set confirm off
>>>>>>cb_gdb:

Thank you. I hope this will help some others who cannot debug
console cpp projects on some slow netbook or something.