static image_entry *CreateImage( const char *exe, const char *symfile ) { image_entry *image; bool local; const char *curr_name; unsigned curr_len; const char *this_name; unsigned this_len; char_ring *curr; open_access ind; if( exe != NULL && symfile == NULL ) { local = false; this_name = SkipPathInfo( exe, OP_REMOTE ); this_len = ExtPointer( exe, OP_REMOTE ) - exe; for( curr = LocalDebugInfo; curr != NULL; curr = curr->next ) { curr_name = SkipPathInfo( curr->name, OP_LOCAL ); curr_name = RealFName( curr_name, &ind ); if( curr_name[0] == '@' && curr_name[1] == 'l' ) curr_name += 2; curr_len = ExtPointer( curr_name, OP_LOCAL ) - curr_name; local = ( this_len == curr_len && strnicmp( this_name, curr_name, this_len ) == 0 ); if( local ) { symfile = curr->name; break; } } } _SwitchOn( SW_ERROR_RETURNS ); image = DoCreateImage( exe, symfile ); _SwitchOff( SW_ERROR_RETURNS ); return( image ); }
static image_entry *CreateImage( const char *exe, const char *symfile ) { image_entry *image; bool local; const char *curr_name; unsigned curr_len; const char *this_name; unsigned this_len; char_ring *curr; obj_attrs oattrs; if( exe != NULL && symfile == NULL ) { local = false; this_name = SkipPathInfo( exe, OP_REMOTE ); this_len = ExtPointer( exe, OP_REMOTE ) - exe; for( curr = LocalDebugInfo; curr != NULL; curr = curr->next ) { oattrs = 0; curr_name = SkipPathInfo( curr->name, OP_LOCAL ); curr_name = RealFName( curr_name, &oattrs ); if( curr_name[0] == '@' && curr_name[1] == 'l' ) curr_name += 2; curr_len = ExtPointer( curr_name, OP_LOCAL ) - curr_name; local = ( this_len == curr_len && strnicmp( this_name, curr_name, this_len ) == 0 ); if( local ) { symfile = curr->name; break; } } } image = DoCreateImage( exe, symfile ); if( image == NULL ) { ErrorRet( ERR_NONE, LIT_ENG( ERR_NO_MEMORY_FOR_DEBUG ) ); } return( image ); }
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 ); }
/* * 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 ); }
void SetPointAddr( brkp *bp, address addr ) { DIPHDL( cue, ch ); image_entry *image; mod_handle mod; char const *start; bool ok; if( bp->status.b.unmapped ) return; _Free( bp->source_line ); bp->source_line = NULL; bp->loc.addr = addr; _Free( bp->mod_name ); bp->mod_name = NULL; _Free( bp->image_name ); bp->image_name = NULL; _Free( bp->sym_name ); bp->sym_name = NULL; bp->cue_diff = 0; bp->addr_diff = 0; if( !IS_BP_EXECUTE( bp->th ) ) { GetWPVal( bp ); } else if( DeAliasAddrMod( addr, &mod ) != SR_NONE ) { image = ImageEntry( mod ); if( image == NULL ) return; ModName( mod, TxtBuff, TXT_LEN ); bp->mod_name = DupStr( TxtBuff ); if( image->image_name != NULL ) { start = SkipPathInfo( image->image_name, OP_REMOTE ); bp->image_name = DupStrLen( start, ExtPointer( start, OP_REMOTE ) - start ); } else { bp->image_name = NULL; } switch( DeAliasAddrCue( NO_MOD, addr, ch ) ) { case SR_EXACT: bp->source_line = CopySourceLine( ch ); Format( TxtBuff, "%d", CueLine( ch ) ); bp->sym_name = DupStr( TxtBuff ); ok = GetBPSymAddr( bp, &addr ); break; case SR_CLOSEST: Format( TxtBuff, "%d", CueLine( ch ) ); bp->sym_name = DupStr( TxtBuff ); bp->addr_diff = addr.mach.offset - CueAddr( ch ).mach.offset; ok = GetBPSymAddr( bp, &addr ); break; default: ok = false; } if( !ok ) { _Free( bp->image_name ); _Free( bp->mod_name ); _Free( bp->sym_name ); bp->image_name = NULL; bp->mod_name = NULL; bp->sym_name = NULL; } } }