예제 #1
0
void InitScreen( void )
{
    if( setpgid( 0, 0 ) != 0 && errno != EPERM ) {
        StartupErr( "unable to create new process group" );
    }
    if( TryTTY() ) {
        ConMode = C_TTY;
    } else if( TryVC() ) {
        ConMode = C_VC;
    } else if( TryXWindows() ) {
        ConMode = C_XWIN;
    } else {
        /* backup: just use the current terminal */
        ConMode = C_CURTTY;
        DbgConHandle = -1;
    }
    _Free( DbgTerminal );
    DbgTerminal = NULL;
    if ( DbgConHandle != -1 ) {
        fcntl( DbgConHandle, F_SETFD, (int)FD_CLOEXEC );
        UIConFile = fdopen( DbgConHandle, "w+" );
        UIConHandle = DbgConHandle;
    }
    if( !uistart() ) {
        StartupErr( "unable to initialize user interface" );
    }
    if( _IsOn( SW_USE_MOUSE ) ) {
        GUIInitMouse( 1 );
    }
    DebugScreen();
}
예제 #2
0
static void Initialize( void )
{
    const char  *err;

    _DBG(("About to remote link in initialize.\n" ));
    err = RemoteLinkX( "\0", TRUE );
    _DBG(( "Back from PM remote link\n" ));
    if( err != NULL ) {
        _DBG(( "ERROR! '%s'\n", err ));
    }
    if( err != NULL ) {
    #ifdef ACAD
        for( ;; ) ads_link( RSERR );
    #else
        StartupErr( err );
    #endif
    }
    RWBuff[0] = '\0';
    _DBG(( "No Remote link error. About to TrapInit." ));
    TrapVer = TrapInit( "", RWBuff, FALSE );
    if( RWBuff[0] != '\0' ) {
// NO, NO, NO!  RemoteUnLinkX();
        StartupErr( RWBuff );
    }
    _DBG(( "No TrapInit error. Initialize complete" ));
    Out[0].len = sizeof( RWBuff );
    Out[0].ptr = RWBuff;
}
예제 #3
0
void InitScreen( void )
{
    if( setpgid( 0, 0 ) != 0 && errno != EPERM ) {
        StartupErr( "unable to create new process group" );
    }
    if( TryTTY() ) {
        ConMode = C_TTY;
    } else if( TryQConsole() ) {
        ConMode = C_QCON;
    } else if( TryXWindows() ) {
        ConMode = C_XWIN;
    } else {
        StartupErr( "unable to initialize debugger screen" );
    }
    _Free( DbgTerminal );
    DbgTerminal = NULL;
    fcntl( DbgConHandle, F_SETFD, (int)FD_CLOEXEC );
    UIConHandle = DbgConHandle;
    if( !uistart() ) {
        StartupErr( "unable to initialize user interface" );
    }
    if( _IsOn( SW_USE_MOUSE ) )
        GUIInitMouse( 1 );
    DebugScreen();
}
예제 #4
0
void GUImain( void )
{
#if defined(__OSI__) || __WATCOMC__ < 1000
    {
    long    result;

#if defined(__OSI__)
    _Extender = 1;
#endif
    result = DPMIAllocateLDTDescriptors( 1 );
    if( result < 0 ) {
        StartupErr( LIT( Unable_to_get_rm_sel ) );
    }
    _ExtenderRealModeSelector = result & 0xffff;
    if( DPMISetSegmentLimit( _ExtenderRealModeSelector, 0xfffff ) ) {
        StartupErr( LIT( Unable_to_get_rm_sel ) );
    }
    }
#endif
    SaveOrigVectors();
    Orig28.a = MyGetRMVector( 0x28 );

    RMData.a = DPMIAllocateDOSMemoryBlock( _NBPARAS( RMSegEnd - RMSegStart ) );
    if( RMData.s.pm == 0 ) {
        StartupErr( LIT( Unable_to_alloc_DOS_mem ) );
    }
    PMData = MK_FP( RMData.s.pm, 0 );
    _fmemcpy( PMData, RMSegStart, RMSegEnd - RMSegStart );
    if( _osmajor == 2 ) {
        PMData->fail = 0;
    } else {
        PMData->fail = 3;
    }
    DebugMain();
}
예제 #5
0
bool ParseCommandLine( const char *cmdline, char *trapparms, char *servparms, bool *oneshot )
/*******************************************************************************************/
{
    const char  *start;
    const char  *ptr;
    char        *buff;

    *oneshot = FALSE;
    *trapparms = '\0';
    *servparms = '\0';
#if defined(__AXP__) && defined(__NT__)
    //NYI: temp until we can get all the unaligned stuff straightened out.
    SetErrorMode( SEM_NOALIGNMENTFAULTEXCEPT );
#endif
    ptr = SkipSpaces( cmdline );
    if( WantUsage( ptr ) ) {
        StartupErr( ServUsage );
        return( FALSE );
    }
    while( IS_OPTION( *ptr ) ) {
        ptr = SkipSpaces( ptr + 1 );
        start = ptr;
        #undef isalpha
        while( isalpha( *ptr ) )
            ++ptr;
        if( ptr == start ) {
            StartupErr( TRP_ERR_expect_option );
            return( FALSE );
        } else if( strnicmp( "trap", start, ptr - start ) == 0 ) {
            ptr = SkipSpaces( ptr );
            if( *ptr != '=' && *ptr != '#' ) {
                StartupErr( TRP_ERR_expect_equal );
                return( FALSE );
            }
            ptr = SkipSpaces( GetFilename( ptr + 1, trapparms ) );
            if( *ptr == TRAP_PARM_SEPARATOR ) {
                buff = trapparms + strlen( trapparms );
                *buff++ = TRAP_PARM_SEPARATOR;
                ptr = CollectTrapParm( SkipSpaces( ptr + 1 ), buff );
            } else if( *ptr == '{'/*}*/ ) {
                buff = trapparms + strlen( trapparms );
                *buff++ = TRAP_PARM_SEPARATOR;
                ptr = CollectTrapParm( ptr, buff );
            }
        } else if( strnicmp( "once", start, ptr - start ) == 0 ) {
            *oneshot = TRUE;
        }
        ptr = SkipSpaces( ptr );
    }
    CollectTrapParm( ptr, servparms );
    TrapVersion.remote = TRUE;
    return( TRUE );
}
예제 #6
0
static bool TryQConsole( void )
{
    struct _psinfo              psinfo;
    struct _sidinfo             info;
    struct _dev_info_entry      dev;
    char                        *ptr;
    const char                  *term;

    if( qnx_psinfo( PROC_PID, getpid(), &psinfo, 0, 0 ) != getpid() ) {
        StartupErr( "unable to obtain process information" );
    }
    if( qnx_sid_query( PROC_PID, psinfo.sid, &info ) != psinfo.sid ) {
        StartupErr( "unable to obtain console name" );
    }
    ptr = info.tty_name + strlen( info.tty_name );
    for( ;; ) {
        --ptr;
        if( *ptr < '0' || *ptr > '9' ) {
            break;
        }
    }
    if( DbgConsole != 0 ) {
        ptr[1] = '0' + DbgConsole / 10;
        ptr[2] = '0' + DbgConsole % 10;
        ptr += 2;
    }
    ptr[1] = NULLCHAR;
    DbgConHandle = open( info.tty_name, O_RDWR );
    if( DbgConHandle == -1 ) {
        StartupErr( "unable to open system console" );
    }
    term = getenv( "TERM" );
    if( term != NULL && strcmp( term, "qnxw" ) == 0 ) {
        /* in QNX windows */
#define PROP_STRING     "\033\"pwd\""
        write( DbgConHandle, PROP_STRING, sizeof( PROP_STRING ) - 1 );
    }

    ConCtrl = console_open( DbgConHandle, O_WRONLY );
    if( ConCtrl == NULL ) {
        close( DbgConHandle );
        return( false );
    }
    if( dev_info( DbgConHandle, &dev ) == -1 ) {
        StartupErr( "unable to obtain console information" );
    }
    DbgConsole = dev.unit;
    console_size( ConCtrl, DbgConsole, 0, 0, &PrevLines, &PrevColumns );
    console_size( ConCtrl, DbgConsole, DbgLines, DbgColumns, 0, 0 );
    InitConsole = console_active( ConCtrl, -1 );
    return( true );
}
예제 #7
0
/*
 * ProcAppl - receives server specific messages for the main window
 */
void ProcAppl( HWND windhandle, unsigned message, WORD worddata, LONG longdata )
{
    char        name[80];
    const char  *err;
    int         i;
    char        buff[80];

    windhandle = windhandle; message = message; longdata = longdata;
    switch( worddata ) {
    case SELECT_1:
        i = GetWindowTextLength( EditChild );
        if( i == 0 ) {
            Output( TRP_ERR_null_name );
            Output( "\r\n" );
        } else {
            *name = '\0';
            GetWindowText( EditChild, name, sizeof( name ) );
            if( RemoteLinkObtained )
                RemoteUnLink();
            err = RemoteLink( name, TRUE );
            if( err != NULL ) {
                StartupErr( err );
                RemoteLinkObtained = FALSE;
            } else {
                sprintf( buff, TRP_WIN_setting_name, name );
                Output( buff );
                Output( "\r\n" );
                RemoteLinkObtained = TRUE;
            } /* if */
        } /* if */
        break;
    } /* switch */

} /* ProcAppl */
예제 #8
0
static bool TryTTY( void )
{
    unsigned long       num;
    char                *end;

    if( DbgTerminal == NULL )
        return( false );
    num = strtoul( DbgTerminal, &end, 10 );
    if( *end == NULLCHAR && num < 100 ) {
        DbgConsole = num;
        return( false );
    }
    /* guy gave an explicit terminal name */
    end = strchr( DbgTerminal, ':' );
    if( end != NULL ) {
        /* and also told us the terminal type */
        *end = NULLCHAR;
        SetTermType( strdup( end + 1 ) );
    }
    DbgConHandle = open( DbgTerminal, O_RDWR );
    if( DbgConHandle == -1 ) {
        StartupErr( "unable to open system console" );
    }
    return( true );
}
예제 #9
0
void GetRawItem( char *start )
{
    unsigned num;

    SkipSpaces();
    if( CurrChar == '{' ) {
        NextChar();
        num = 1;
        for( ;; ) {
            if( CurrChar == ARG_TERMINATE ) {
                StartupErr( LIT_ENG( STARTUP_Expect_Brace ) );
            } else if( CurrChar == '{' ) {
                ++num;
            } else if( CurrChar == '}' ) {
                if( --num == 0 ) {
                    NextChar();
                    break;
                }
            }
            *start++ = CurrChar;
            NextChar();
        }
        *start = NULLCHAR;
    } else {
        DoGetItem( start, false );
    }
}
예제 #10
0
static const char *CollectTrapParm( const char *ptr, char *buff )
{
    unsigned    num;

    if( *ptr == '{' ) {
        ++ptr;
        num = 1;
        for( ;; ) {
            if( *ptr == '\0' ) {
                StartupErr( TRP_ERR_expect_brace );
            } else if( *ptr == '{' ) {
                ++num;
            } else if( *ptr == '}' ) {
                if( --num == 0 ) {
                    ++ptr;
                    break;
                }
            }
            *buff++ = *ptr++;
        }
        *buff = '\0';
    } else {
        ptr = GetFilename( ptr, buff );
    }
    return( ptr );
}
예제 #11
0
void DebugInit( void )
{
    NestedCallLevel = 0;
    UpdateFlags = 0;
    _SwitchOn( SW_ERROR_STARTUP );
    _SwitchOn( SW_CHECK_SOURCE_EXISTS );
    SET_NIL_ADDR( NilAddr );
    TxtBuff  = &DbgBuffers[0];
    *TxtBuff = '\0';
    NameBuff = &DbgBuffers[TXT_LEN+1];
    *NameBuff = '\0';
    CurrRadix = DefRadix = 10;
    DbgLevel = MIX;
    ActiveWindowLevel = MIX;
    _SwitchOn( SW_BELL );
    _SwitchOn( SW_FLIP );
    _SwitchOn( SW_RECURSE_CHECK );
    _SwitchOff( SW_ADDING_SYMFILE );
    _SwitchOff( SW_TASK_RUNNING );
    RecordInit();
    LogInit();
    InitMADInfo();
    InitMachState();
    PathInit();
    InitDbgInfo();
    InitTrap( TrapParms );
    if( !LangSetInit() ) {
        FiniTrap();
        StartupErr( LIT_ENG( STARTUP_Loading_PRS ) );
    }
    if( !InitCmd() ) {
        FiniTrap();
        StartupErr( LIT_ENG( ERR_NO_MEMORY ) );
    }
    InitScan();
    InitLook();
    InitBPs();
    InitSource();
    InitDLLList();
    DUIInit();
    InitHook();
    VarDisplayInit();
}
예제 #12
0
char *CheckForPowerBuilder( char *name )
{
    static char pid[20];

    if( _IsOff( SW_POWERBUILDER ) ) return( name );
    EnumWindows( FindPidPB, 0 );
    if( AlreadyRunning ) {
        StartupErr( LIT( PowerBuilder_Debugger_Already_Running ) );
        return( "" );
    }
    if( PidPB == 0 ) {
        StartupErr( LIT( PowerBuilder_Not_Running ) );
        return( "" );
    } else {
        pid[0] = '#';
        itoa( PidPB, pid+1, 16 );
        #ifdef __GUI__
            WndSetTitle( WndMain, LIT( The_WATCOM_Debugger_for_PowerBuilder ) );
        #else
            SetConsoleTitle( LIT( The_WATCOM_Debugger_for_PowerBuilder ) );
        #endif
        return( pid );
    }
}
예제 #13
0
void OptError( char *err )
{
    char        *curr;
    char        buff[CMD_LEN];
    char        token[CMD_LEN];

    curr = token;
    while( isalnum( CurrChar ) ) {
        *curr++ = CurrChar;
        NextChar();
    }
    if( curr == token ) {
        if( CurrChar == ARG_TERMINATE ) CurrChar = ' ';
        *curr++ = CurrChar;
    }
    *curr = NULLCHAR;
    Format( buff, err, token );
    StartupErr( buff );
}
예제 #14
0
void ReportMADFailure( mad_status ms )
{
    mad_handle  old;
    char        buff[TXT_LEN];

    if( SysConfig.mad == MAD_NIL ) {
        /* we're in deep do do */
        StartupErr( LIT_ENG( LMS_RECURSIVE_MAD_FAILURE ) );
    }
    old = SysConfig.mad;
    MADNameFile( old, buff, sizeof( buff ) );
    SysConfig.mad = MAD_NIL;
    /* this deregisters the MAD, and sets the active one to the dummy */
    MADRegister( old, NULL, NULL );
    _SwitchOn( SW_ERROR_RETURNS );
    switch( ms & ~MS_ERR ) {
    case MS_UNREGISTERED_MAD:
        Error( ERR_NONE, LIT_ENG( LMS_UNREGISTERED_MAD ), old );
        break;
    case MS_INVALID_MAD_VERSION:
        Error( ERR_NONE, LIT_ENG( LMS_INVALID_MAD_VERSION ), buff );
        break;
    case MS_INVALID_STATE:
        Error( ERR_INTERNAL, "MAD state" );
        break;
    case MS_FOPEN_FAILED:
        Error( ERR_NONE, LIT_ENG( ERR_FILE_NOT_OPEN ), buff );
        break;
    case MS_FREAD_FAILED:
    case MS_FSEEK_FAILED:
        Error( ERR_NONE, LIT_ENG( LMS_FREAD_FAILED ), buff );
        break;
    case MS_NO_MEM:
        Error( ERR_NONE, LIT_ENG( ERR_NO_MEMORY ) );
        break;
    case MS_INVALID_MAD:
    default:
        Error( ERR_NONE, LIT_ENG( LMS_INVALID_MAD ), buff );
        break;
    }
    _SwitchOff( SW_ERROR_RETURNS );
}
예제 #15
0
void Initialize( void )
{

    const char  *err;
    char        trapparms[PARMS_MAXLEN];
    char        cmdline[PARMS_MAXLEN];

#define servparms RWBuff

    getcmd( cmdline );
    ParseCommandLine( cmdline, trapparms, servparms, &OneShot );
    err = RemoteLink( servparms, TRUE );

#undef servparms

    if( err == NULL ) {
        err = LoadTrap( trapparms, RWBuff, &TrapVersion );
    }
    if( err != NULL ) {
        StartupErr( err );
    }
}
예제 #16
0
void InitMADInfo( void )
{
    if( MADInit() != MS_OK ) {
        StartupErr( LIT_ENG( STARTUP_MAD_Not_Init ) );
    }
}
예제 #17
0
static void TrapFailed( void )
{
    KillTrap();
    StartupErr( LIT( ERR_REMOTE_LINK_BROKEN ) );
}
예제 #18
0
void Error( dbg_err_flags flg, char *fmt, ... )
{
    char            buff[TXT_LEN];
    va_list         args;
    char            *ptr;
    invokes         *inv;
    input_stack     *inp;
    char            *where;
    bool            cmderror;

    va_start( args, fmt );
    ptr = buff;
    if( flg & ERR_INTERNAL ) {
        ptr = StrCopy( LIT_ENG( Internal_Error ), ptr );
    }
    ptr = FmtStr( ptr, fmt, args );
    ptr = StrCopy( ".", ptr );
    if( flg & ERR_LOC ) {
        ptr = StrCopy( "\n    ", ptr );
        switch( CurrToken ) {
        case T_CMD_SEPARATOR:
            ptr = StrCopy( LIT_ENG( ERR_NEAR_END_OF_COMMAND ), ptr );
            break;
        case T_LINE_SEPARATOR:
            ptr = StrCopy( LIT_ENG( ERR_NEAR_END_OF_LINE ), ptr );
            break;
        default:
            if( ScanLen() == 0 ) Scan();
            ptr = Format( ptr, LIT_ENG( ERR_NEAR_TOKEN ), ScanPos(), ScanLen() );
            break;
        }
    }
    SetProgStartHook( TRUE );
    UnFreezeRegs();
    ScanExpr( NULL );
    ExprPurge();
    PurgeSymHandles(); /* must be done after ExprPurge */
    DIPCancel();
    ScanSavePtr = 0; /* clean up previous ScanSave locations */

    if( _IsOff( SW_ERROR_PRESERVES_RADIX ) ) {
        RestoreRadix();
    }
    _SwitchOff( SW_CALL_FATAL );
    if( _IsOn( SW_ERROR_STARTUP ) ) {
        StartupErr( buff );
    }
    if( _IsOn( SW_ERR_IN_TXTBUFF ) ) {
        PurgeInpStack();
        StrCopy( buff, TxtBuff );
        DUIArrowCursor();
        Suicide();
    }
    if( (flg & ERR_SILENT) == 0 ) {
        where = LIT_ENG( ERR_EXECUTING_AT );
        for( inp = InpStack; inp != NULL; inp = inp->link ) {
            if( inp->type & INP_CMD_FILE ) {
                inv = inp->handle;
                ptr = StrCopy( "\n    ", ptr );
                ptr = Format( ptr, where, inv->line, inv->name );
                where = LIT_ENG( ERR_CALLED_FROM );
            }
        }
        DUIFlushKeys();
        DUIWndDebug();
        RingBell();
        DUIErrorBox( buff );
    }
    cmderror = FALSE;
    for( inp = InpStack; inp != NULL; inp = inp->link ) {
        if( inp->type & INP_BREAK_POINT ) {
            BrkCmdError();
        }
        if( inp->type & INP_CAPTURED ) {
            CaptureError();
        }
        if( inp->type & INP_DLG_CMD ) {
            cmderror = TRUE;
        }
    }
    PurgeInpStack();
    if( cmderror && fmt != LIT_ENG( ERR_DBG_INTERRUPT ) ) {
        DlgCmd();
        ProcInput();
    }
    if( _IsOn( SW_ERROR_RETURNS ) ) return;
    DUIArrowCursor();
    Suicide();
}
예제 #19
0
static void ProcOptList( int pass )
{
    char            buff[80];
    char            err_buff[CMD_LEN];
    char            *curr;
    unsigned long   mem;

    SetupChar(); /* initialize scanner */
    for( ;; ) {
        SkipSpaces();
        if( !OptDelim( CurrChar ) )
            break;
        NextChar();
        curr = buff;
#ifndef __GUI__
        if( CurrChar == '?' ) {
            PrintUsage( MSG_USAGE_BASE );
            StartupErr( "" );
        }
#endif
        while( isalnum( CurrChar ) ) {
            *curr++ = CurrChar;
            NextChar();
        }
        if( curr == buff ) {
            if( OptDelim( CurrChar ) ) {
                NextChar();
                SkipSpaces();
                break;
            }
            OptError( LIT_ENG( STARTUP_No_Recog_Optn ) );
        }
        switch( Lookup( OptNameTab, buff, curr - buff ) ) {
        case OPT_CONTINUE_UNEXPECTED_BREAK:
            _SwitchOn( SW_CONTINUE_UNEXPECTED_BREAK );
            break;
        case OPT_DEFERSYM:
            _SwitchOn( SW_DEFER_SYM_LOAD );
            break;
        case OPT_DOWNLOAD:
            DownLoadTask = true;
            break;
        case OPT_NOEXPORTS:
            _SwitchOn( SW_NO_EXPORT_SYMS );
            break;
        case OPT_LOCALINFO:
            if( pass == 2 ) {
                char *symfile = GetFileName( pass );
                FindLocalDebugInfo( symfile );
                _Free( symfile );
            }
            break;
        case OPT_INVOKE:
            if( pass == 2 )
                _Free( InvokeFile );
            InvokeFile = GetFileName( pass );
            break;
        case OPT_NOINVOKE:
            if( pass == 2 )
                _Free( InvokeFile );
            InvokeFile = NULL;
            break;
        case OPT_NOSOURCECHECK:
            _SwitchOff( SW_CHECK_SOURCE_EXISTS );
            break;
        case OPT_NOSYMBOLS:
            _SwitchOff( SW_LOAD_SYMS );
            break;
        case OPT_NOMOUSE:
            _SwitchOff( SW_USE_MOUSE );
            break;
        case OPT_DYNAMIC:
            mem = GetMemory();
            if( pass == 1 ) {
                if( mem < MIN_MEM_SIZE )
                    mem = MIN_MEM_SIZE;
                MemSize = mem;
            }
            break;
        case OPT_DIP:
            {
                int i;

                for( i = 0; DipFiles[i] != NULL; ++i )
                    ;
                DipFiles[i] = GetFileName( pass );
            }
            break;
        case OPT_TRAP:
            if( pass == 2 )
                _Free( TrapParms );
            TrapParms = GetFileName( pass );
            SkipSpaces();
            if( CurrChar == TRAP_PARM_SEPARATOR ) {
                NextChar();
                GetTrapParm( pass );
            } else if( CurrChar == '{' ) {
                GetTrapParm( pass );
            }
            break;
#ifdef ENABLE_TRAP_LOGGING
        case OPT_TRAP_DEBUG_FLUSH:
            if( pass == 2 )
                _Free( TrapTraceFileName );
            TrapTraceFileName = GetFileName( pass );
            TrapTraceFileFlush = true;
            break;
        case OPT_TRAP_DEBUG:
            if( pass == 2 )
                _Free( TrapTraceFileName );
            TrapTraceFileName = GetFileName( pass );
            TrapTraceFileFlush = false;
            break;
#endif
        case OPT_REMOTE_FILES:
            _SwitchOn( SW_REMOTE_FILES );
            break;
        case OPT_LINES:
            DUISetNumLines( GetValue() );
            break;
        case OPT_COLUMNS:
            DUISetNumColumns( GetValue() );
            break;
#ifdef BACKWARDS
        case OPT_NO_FPU:
        case OPT_NO_ALTSYM:
            break;
        case OPT_REGISTERS:
            GetValue();
            break;
#endif
        case OPT_INITCMD:
            GetInitCmd( pass );
            break;
        case OPT_POWERBUILDER:
            _SwitchOn( SW_POWERBUILDER );
            break;
        case OPT_HELP:
#ifndef __GUI__
            PrintUsage( MSG_USAGE_BASE );
            StartupErr( "" );
#endif
            break;
        default:
            if( !ProcSysOption( buff, curr - buff, pass ) && !DUIScreenOption( buff, curr - buff, pass ) ) {
                Format( err_buff, LIT_ENG( STARTUP_Invalid_Option ), buff, curr - buff );
                StartupErr( err_buff );
            }
            break;
        }
    }
}
예제 #20
0
static bool TryXWindows( void )
{
    int         slavefd;
    int         masterfd;
    char        buff[64];
    char        **argv;
    char        *p;
    char        *end;
    unsigned    argc;
    char        slavename[] = "/dev/pts/xxxxxx";
    int         unlock = 0;
    char        buf;
    int         res;
    struct termios termio;

    /* we're in the X (or helper)environment */
    if ( getenv( "DISPLAY" ) == NULL )
        return( false );
    masterfd = open( "/dev/ptmx", O_RDWR );
    if( masterfd < 0 )
        return( false );
    fcntl( masterfd, F_SETFD, 0 );
    ioctl( masterfd, TIOCGPTN, &slavefd ); /* slavefd = ptsname(masterfd); */
    ioctl( masterfd, TIOCSPTLCK, &unlock ); /* unlockpt(masterfd); */
    sprintf( slavename + 9, "%d", slavefd );
    slavefd = open( slavename, O_RDWR );
    DbgConHandle = slavefd;
    if( DbgConHandle == -1 ) {
        StartupErr( "unable to open debugger console" );
        return( false );
    }
    tcgetattr( slavefd, &termio );
    termio.c_lflag &= ~ECHO;
    tcsetattr( slavefd, TCSANOW, &termio );
    argc = 0;
    p = XConfig;
    for( ;; ) {
        while( isspace( *p ) )
            ++p;
        while( !isspace( *p ) && *p != '\0' )
            ++p;
        if( *p == '\0' )
            break;
        ++argc;
        *p++ = '\0';
    }
    end = p;
    _AllocA( argv, ( argc + 16 ) * sizeof( *argv ) );

    argv[0] = "xterm";
    argv[1] = "-title";
    argv[2] = "Open Watcom Debugger";
    argv[3] = "-ut";

    argc = 4;

    if( DbgLines != 0 || DbgColumns != 0 ) {
        argv[argc++] = "-geometry";
        if( DbgLines == 0 )
            DbgLines = 25;
        if( DbgColumns == 0 )
            DbgColumns = 80;
        p = Format( buff, "%ux%u+0+0", DbgColumns, DbgLines ) + 1;
        argv[argc++] = buff;
    }

    for( p = XConfig; p < end; p += strlen( p ) + 1 ) {
        while( isspace( *p ) )
            ++p;
        argv[argc++] = p;
    }
    Format( p, "-SXX%u", masterfd );
    argv[argc++] = p;
    argv[argc] = NULL;

    fcntl( slavefd, F_SETFD, FD_CLOEXEC );
    XTermPid = fork();
    if( XTermPid == 0 ) { /* child */
        setpgid( 0, 0 );
#if defined( __UNIX__ ) && !defined( __WATCOMC__ )
        execvp( argv[0], (char * const *)argv );
#else
        execvp( argv[0], (const char **)argv );
#endif
        exit( 1 );
    }
    if( XTermPid == (pid_t)-1 ) {
        StartupErr( "unable to create console helper process" );
    }
    do { /* xterm transmits a window ID -- ignore */
        res = read( slavefd, &buf, 1 );
    } while( res != -1 && buf != '\n' );
    termio.c_lflag |= ECHO;
    tcsetattr( slavefd, TCSANOW, &termio );

    /* make slavefd a controlling tty */
    setpgid( 0, XTermPid );
    setsid();
    ioctl( slavefd, TIOCSCTTY, 1 );

    signal( SIGHUP, &HupHandler );
    return( true );
}
예제 #21
0
static bool TryXWindows( void )
{
    char        xqsh_name[CMD_LEN];
    int         pip[2];
    char        buff[64];
    char        **argv;
    int         len;
    char        *p;
    char        *end;
    unsigned    argc;

    /* we're in the X Windows (or helper)environment */
    if( pipe( pip ) != 0 ) {
        StartupErr( "unable to create console control channel" );
    }
    fcntl( pip[0], F_SETFD, (int)FD_CLOEXEC );
    searchenv( "qnxterm", "PATH", xqsh_name );
    if( xqsh_name[0] == NULLCHAR ) {
        StartupErr( "qnxterm executable not in PATH" );
    }
    argc = 0;
    p = XConfig;
    for( ;; ) {
        while( isspace( *p ) )
            ++p;
        while( !isspace( *p ) && *p != NULLCHAR )
            ++p;
        if( *p == NULLCHAR )
            break;
        ++argc;
        *p++ = NULLCHAR;
    }
    end = p;
    _AllocA( argv, (argc + 10) * sizeof( *argv ) );

    argv[0] = xqsh_name;
    argv[1] = "-T";
    argv[2] = "WATCOM Debugger";

    argc = 3;

    if( DbgLines != 0 || DbgColumns != 0 ) {
        argv[argc++] = "-geometry";
        if( DbgLines == 0 )
            DbgLines = 25;
        if( DbgColumns == 0 )
            DbgColumns = 80;
        p = Format( buff, "%ux%u+0+0", DbgColumns, DbgLines ) + 1;
        argv[argc++] = buff;
    }

    for( p = XConfig; p < end; p += strlen( p ) + 1 ) {
        while( isspace( *p ) )
            ++p;
        argv[argc++] = p;
    }
    argv[argc++] = "-tty";
    Format( p, "%u", pip[1] );
    argv[argc++] = p;
    argv[argc] = NULL;

    XQshPid = qnx_spawn( 0, 0, 0, -1, -1, _SPAWN_NEWPGRP,
                argv[0], argv, environ, NULL, 0 );
    if( XQshPid == (pid_t)-1 ) {
        StartupErr( "unable to create console helper process" );
    }
    /* close the write pipe here so that the read fails if xqsh aborts */
    close( pip[1] );
    len = read( pip[0], buff, sizeof( buff ) );
    if( len == -1 ) {
        StartupErr( "console helper process unable to initialize" );
    }
    close( pip[0] );
    buff[len] = NULLCHAR;
    DbgConHandle = open( buff, O_RDWR );
    if( DbgConHandle == -1 ) {
        StartupErr( "unable to open debugger console" );
    }
    SetTermType( "qnx" );
    tcsetct( DbgConHandle, getpid() );
    signal( SIGHUP, &HupHandler );
    return( true );
}
예제 #22
0
void InitTrap( char *trap_file )
{
    mx_entry            in[1];
    mx_entry            out[2];
    connect_req         in_mx;
    connect_ret         out_mx;
    char                *error;
    trap_version        ver;
    char                buff[ TXT_LEN ];

#ifdef ENABLE_TRAP_LOGGING
    if( TrpDebugFile )
        OpenTrapTraceFile( TrpDebugFile, TrpDebugFileFlush );
#endif

/* Don't use TxtBuff except for error -- it may have a Finger message in it */

#if !defined( BUILD_RFX )
    TrapSetFailCallBack( TrapFailed );
#endif
    InitTrapError = FALSE;
    RestoreHandlers();
    ver.remote = FALSE;
#if !defined( BUILD_RFX )
    if( stricmp( trap_file, "dumb" ) == 0 ) {
        error = LoadDumbTrap( &ver );
    } else {
#endif
        error = LoadTrap( trap_file, buff, &ver );
#if !defined( BUILD_RFX )
    }
#endif
    GrabHandlers();
    if( error != NULL ) {
        strcpy( buff, error );
        InitTrapError = TRUE;
        StartupErr( buff );
    }
    in_mx.req = REQ_CONNECT;
    in_mx.ver.major = TRAP_MAJOR_VERSION;
    in_mx.ver.minor = TRAP_MINOR_VERSION;
    in_mx.ver.remote = FALSE;
    in[0].ptr = &in_mx;
    in[0].len = sizeof( in_mx );
    out[0].ptr = &out_mx;
    out[0].len = sizeof( out_mx );
    buff[0] = '\0';
    out[1].ptr = buff;
    out[1].len = MAX_ERR_MSG_SIZE;
    TrapAccess( 1, in, 2, out );
    MaxPacketLen = out_mx.max_msg_size;
    if( buff[0] != '\0' ) {
        KillTrap();
        InitTrapError = TRUE;
        StartupErr( buff );
    }
#if !defined( BUILD_RFX )
    if( !InitTrapError ) {
        InitSuppServices();
    }
#endif
    if( ver.remote ) {
        _SwitchOn( SW_REMOTE_LINK );
    } else {
        _SwitchOff( SW_REMOTE_LINK );
    }
}