size_t GetSystemDir( char *buff, size_t buff_len ) /************************************************/ { // inst PRFPROFILE prof; size_t i; prof.cchUserName = 0L; prof.cchSysName = 0L; i = 0; if( PrfQueryProfile( GUIGetHAB(), &prof ) ) { if( prof.cchSysName > 0 ) { _AllocA( prof.pszSysName, prof.cchSysName ); _AllocA( prof.pszUserName, prof.cchUserName ); PrfQueryProfile( GUIGetHAB(), &prof ); } if( buff_len > prof.cchSysName ) buff_len = prof.cchSysName; memcpy( buff, prof.pszSysName, buff_len ); if( buff_len > 0 ) i = --buff_len; // reserve space for terminating null character while( i > 0 ) { if( buff[--i] == '\\' ) { break; } } } buff[i] = NULLCHAR; return( strlen( buff ) ); } /* _wpi_getinidirectory */
void ProfileInvoke( char *name ) { unsigned len; #if defined(__UNIX__) handle hndl; #endif len = strlen( name ); if( len != 0 ) { Invoke( name, len, NULL ); return; } /* default name search */ len = strlen( EXENAME ); _AllocA( name, len + 4 ); #if defined(__UNIX__) /* under QNX and Linux, look for .wdrc first */ name[0] = '.'; strcpy( &name[1], EXENAME ); strcat( name, "rc" ); strlwr( name ); hndl = LocalFullPathOpen( name, LIT( Empty ), TxtBuff, TXT_LEN ); if( hndl != NIL_HANDLE ) { DoInvoke( hndl, TxtBuff, NULL ); return; } #endif strcpy( name, EXENAME ); strlwr( name ); Invoke( name, len, NULL ); }
void FindLocalDebugInfo( const char *name ) { char *buff, *symfile; size_t len; file_handle fh; len = strlen( name ); _AllocA( buff, len + 1 + 4 + 2 ); _AllocA( symfile, len + 1 + 4 ); strcpy( buff, "@l" ); // If a .sym file is present, use it in preference to the executable fh = FullPathOpen( name, ExtPointer( name, OP_LOCAL ) - name, "sym", symfile, len + 4 ); if( fh != NIL_HANDLE ) { strcat( buff, symfile ); FileClose( fh ); } else { strcat( buff, name ); } InsertRing( RingEnd( &LocalDebugInfo ), buff, strlen( buff ), false ); }
void FindLocalDebugInfo( const char *name ) { char *buff, *symname; unsigned len; handle local; len = strlen( name ); _AllocA( buff, len + 1 + 4 + 2 ); _AllocA( symname, len + 1 + 4 ); strcpy( buff, "@l" ); // If a .sym file is present, use it in preference to the executable local = FullPathOpen( name, ExtPointer( name, OP_LOCAL ) - name, "sym", symname, len + 4 ); if( local != NIL_HANDLE ) { strcat( buff, symname ); FileClose( local ); } else { strcat( buff, name ); } InsertRing( RingEnd( &LocalDebugInfo ), buff, strlen( buff ), FALSE ); }
unsigned GetSystemDir( char *buff, int max ) /***********************************************/ { // inst PRFPROFILE prof; int i; char c; int len; prof.cchUserName = 0L; prof.cchSysName = 0L; if( PrfQueryProfile( GUIGetHAB(), &prof ) ) { if( prof.cchSysName > 0 ) { _AllocA( prof.pszSysName, prof.cchSysName ); _AllocA( prof.pszUserName, prof.cchUserName ); PrfQueryProfile( GUIGetHAB(), &prof ); } strcpy( buff, prof.pszSysName ); if( prof.cchSysName <= max ) { len = prof.cchSysName; } else { len = max; } for( i = len - 1; i >= 0; i-- ) { c = buff[i]; buff[i] = '\0'; if( c == '\\' ) { break; } } } else { buff[0] = '\0'; } return( strlen( buff ) ); } /* _wpi_getinidirectory */
static walk_result CheckFirstFile( cue_handle *ch, void *_d ) { cue_mod *d = _d; char *buff; unsigned len; len = CueFile( ch, NULL, 0 ) + 1; _AllocA( buff, len ); CueFile( ch, buff, len ); if( stricmp( buff, d->file ) == 0 ) { d->found = true; } return( WR_STOP ); }
extern void *WndAsmInspect( address addr ) { // used by examine/assembly command int i; char buff[256]; mad_disasm_data *dd; _AllocA( dd, MADDisasmDataSize() ); for( i = 0; i < 10; ++i ) { MADDisasm( dd, &addr, 0 ); MADDisasmFormat( dd, MDP_ALL, CurrRadix, buff, sizeof( buff ) ); InsMemRef( dd ); printf( "%-40s%s\n", buff, TxtBuff ); } return( NULL ); }
void Invoke( char *invfile, int len, char_ring *parmlist ) { char *invname; handle hndl; _AllocA( invname, len + 1 ); memcpy( invname, invfile, len ); invname[ len ] = '\0'; hndl = LocalFullPathOpen( invname, "dbg", TxtBuff, TXT_LEN ); if( hndl == NIL_HANDLE ) { MakeFileName( TxtBuff, invname, "dbg", 0 ); FreeRing( parmlist ); Error( ERR_NONE, LIT( ERR_FILE_NOT_OPEN ), TxtBuff ); } DoInvoke( hndl, TxtBuff, parmlist ); }
void GUImain( void ) { char *buff; int len; // fix up env vars if necessary watcom_setup_env(); SetErrorMode( ERR_MODE ); #if defined( _M_IX86 ) _8087 = 0; #endif len = _bgetcmd( NULL, 0 ); _AllocA( buff, len + 1 ); getcmd( buff ); CmdData = buff; DebugMain(); }
static void AsmSetFirst( a_window *wnd, address addr, bool use_first_source ) { int row,rows; asm_window *asw = WndAsm( wnd ); char chr; mad_disasm_data *dd; unsigned addr_len; DIPHDL( cue, ch ); _AllocA( dd, asw->ddsize ); if( IS_NIL_ADDR( addr ) || ProgPeek( addr, &chr, 1 ) != 1 ) { addr = NilAddr; } asw->ins[ 0 ].addr = addr; asw->ins[ 0 ].line = 0; addr_len = AddrToString( &addr, MAF_OFFSET, TxtBuff, TXT_LEN ) - TxtBuff; if( addr_len != asw->addr_len ) { asw->addr_len = addr_len; AsmResize( wnd ); // recusively calls this routine! WndZapped( wnd ); return; } rows = WndRows( wnd ); for( row = 0; row < rows; ++row ) { asw->ins[ row ].addr = addr; if( IS_NIL_ADDR( addr ) ) continue; if( ExactCueAt( asw, addr, ch ) ) { if( row != 0 || use_first_source ) { asw->ins[ row ].addr = addr; asw->ins[ row ].line = CueLine( ch ); ++row; if( row >= rows ) break; } } asw->ins[ row ].addr = addr; asw->ins[ row ].line = 0; if( MADDisasm( dd, &addr, 0 ) != MS_OK ) { addr = NilAddr; } } }
/* * ProcImgSymInfo -- initialize symbolic information * * Note: This function should try to open files locally first, for two * reasons: * 1) If a local file is open as remote, then local caching may interfere with * file operations (notably seeks with DIO_SEEK_CUR) * 2) Remote access goes through extra layer of indirection; this overhead * is completely unnecessary for local debugging. */ static bool ProcImgSymInfo( image_entry *image ) { file_handle fh; unsigned last; char buff[TXT_LEN]; char *symfile_name; const char *nopath; size_t len; image->deferred_symbols = false; if( _IsOff( SW_LOAD_SYMS ) ) return( NO_MOD ); if( image->symfile_name != NULL ) { last = DIP_PRIOR_MAX; fh = PathOpen( image->symfile_name, strlen( image->symfile_name ), "sym" ); if( fh == NIL_HANDLE ) { nopath = SkipPathInfo( image->symfile_name, OP_REMOTE ); fh = PathOpen( nopath, strlen( nopath ), "sym" ); if( fh == NIL_HANDLE ) { /* try the sym file without an added extension */ fh = FileOpen( image->symfile_name, OP_READ ); } } } else { last = DIP_PRIOR_EXPORTS - 1; fh = FileOpen( image->image_name, OP_READ ); if( fh == NIL_HANDLE ) { fh = FileOpen( image->image_name, OP_READ | OP_REMOTE ); } } if( fh != NIL_HANDLE ) { if( CheckLoadDebugInfo( image, fh, DIP_PRIOR_MIN, last ) ) { return( true ); } FileClose( fh ); } if( image->symfile_name != NULL ) return( false ); _AllocA( symfile_name, strlen( image->image_name ) + 1 ); strcpy( symfile_name, image->image_name ); symfile_name[ExtPointer( symfile_name, OP_REMOTE ) - symfile_name] = NULLCHAR; len = MakeFileName( buff, symfile_name, "sym", OP_REMOTE ); _Alloc( image->symfile_name, len + 1 ); if( image->symfile_name != NULL ) { memcpy( image->symfile_name, buff, len + 1 ); fh = FileOpen( image->symfile_name, OP_READ ); if( fh == NIL_HANDLE ) { fh = FileOpen( image->symfile_name, OP_READ | OP_REMOTE ); } if( fh == NIL_HANDLE ) { fh = PathOpen( image->symfile_name, strlen( image->symfile_name ), "" ); } if( fh != NIL_HANDLE ) { if( CheckLoadDebugInfo( image, fh, DIP_PRIOR_MIN, DIP_PRIOR_MAX ) ) { return( true ); } FileClose( fh ); } _Free( image->symfile_name ); } image->symfile_name = NULL; if( _IsOff( SW_NO_EXPORT_SYMS ) ) { if( _IsOn( SW_DEFER_SYM_LOAD ) ) { image->deferred_symbols = true; } else { fh = FileOpen( image->image_name, OP_READ | OP_REMOTE ); if( fh != NIL_HANDLE ) { if( CheckLoadDebugInfo( image, fh, DIP_PRIOR_EXPORTS - 1, DIP_PRIOR_MAX ) ) { return( true ); } FileClose( fh ); } } } return( false ); }
void *OpenSrcFile( cue_handle *ch ) { void *hndl; char_ring *path; char *p; char *d; char *rem_name; bool used_star; unsigned len; char *buff; len = CueFile( ch, NULL, 0 ) + 1; _AllocA( buff, len ); CueFile( ch, buff, len ); hndl = FOpenSource( buff, CueMod( ch ), CueFileId( ch ) ); if( hndl != NULL ) return( hndl ); for( path = SrcSpec; path != NULL; path = path->next ) { used_star = FALSE; d = TxtBuff; for( p = path->name; *p != '\0'; ++p ) { if( *p == '*' ) { used_star = TRUE; d += ModName( CueMod( ch ), d, TXT_LEN ); } else { *d++ = *p; } } *d = NULLCHAR; if( !used_star ) { #if 0 /* John can't remember why he put this code in, and it screws up when the user sets a source path of ".". If we find some case where it's required, we'll have to think harder about things. */ if( *ExtPointer( TxtBuff, 0 ) != '\0' ) { *SkipPathInfo( TxtBuff, 0 ) = '\0'; } #endif d = AppendPathDelim( TxtBuff, 0 ); if( !IsAbsolutePath( buff ) ) { StrCopy( buff, d ); hndl = FOpenSource( TxtBuff, CueMod( ch ), CueFileId( ch ) ); if( hndl != NULL ) return( hndl ); } /* We have a small problem here. We want to strip off the path information for the source file name, but we don't know if the file was compiled on the local system or the remote one. We'll kludge things by doing a local skip and then a remote one and seeing who takes off the most stuff. Don't even think about the case where the file has been compiled on a third, different type of file system. */ p = SkipPathInfo( buff, OP_LOCAL ); rem_name = SkipPathInfo( buff, OP_REMOTE ); if( rem_name > p ) p = rem_name; d = StrCopy( p, d ); *d = NULLCHAR; } hndl = FOpenSource( TxtBuff, CueMod( ch ), CueFileId( ch ) ); if( hndl != NULL ) return( hndl ); } return( NULL ); }
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 ); }
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 ); }