Skip to content

Commit

Permalink
wv: cleanup location prefix handling code
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalak committed Aug 30, 2024
1 parent 046899f commit a3022a1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
29 changes: 18 additions & 11 deletions bld/wv/c/dbgcapt.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,27 @@
#include "dbginsp.h"


#define PREFIX_LEN 2
#define LOCPREFIX_LEN 2

static char FileName[PREFIX_LEN+8+1+3+1] = { '@', 'r' };
static char FileName[LOCPREFIX_LEN+8+1+3+1];
static unsigned FileNum = 0;
static bool CaptureOk;

static char *CreateUniqueFileName( void )
{
char *start;
char *p;
char *end;

end = FileName + sizeof( FileName );
start = SetFileLocPrefix( FileName, OP_REMOTE );
p = CnvULongHex( TaskId, start, end - start );
*p++ = RemFile.ext_separator;
end = CnvULongDec( FileNum++, p, end - p );
*end = NULLCHAR;
return( start );
}

void CaptureError( void )
{
CaptureOk = false;
Expand Down Expand Up @@ -87,20 +102,12 @@ void ProcCapture( void )
const char *start;
size_t len;
const char *old;
char *p;
char *end;

if( !ScanItem( false, &start, &len ) )
Error( ERR_NONE, LIT_ENG( ERR_WANT_COMMAND_LIST ) );
ReqEOC();
cmds = AllocCmdList( start, len );
end = FileName + sizeof( FileName );
p = FileName + PREFIX_LEN;
p = CnvULongHex( TaskId, p, end - p );
*p++ = RemFile.ext_separator;
p = CnvULongDec( FileNum++, p, end - p );
*p = NULLCHAR;
old = ReScan( FileName+PREFIX_LEN );
old = ReScan( CreateUniqueFileName() );
StdOutNew();
ReScan( old );
cmds->use++;
Expand Down
19 changes: 14 additions & 5 deletions bld/wv/c/dbgfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ static sys_error SysErrors[MAX_ERRORS];
static error_handle ErrRover;
static error_handle LastErr;

char *SetFileLocPrefix( char *buff, obj_attrs oattrs )
{
*buff++ = LOC_ESCAPE;
if( oattrs == OP_REMOTE ) {
*buff++ = REMOTE_LOC;
} else if( oattrs == OP_LOCAL ) {
*buff++ = LOCAL_LOC;
}
return( buff );
}

const char *RealFName( char const *name, obj_attrs *oattrs )
{
*oattrs &= ~(OP_REMOTE | OP_LOCAL);
Expand Down Expand Up @@ -423,14 +434,12 @@ static size_t MakeNameWithPath( obj_attrs oattrs,
const file_components *info;
char *p;

p = res;
if( oattrs & OP_REMOTE ) {
*p++ = LOC_ESCAPE;
*p++ = REMOTE_LOC;
p = SetFileLocPrefix( res, OP_REMOTE );
} else if( oattrs & OP_LOCAL ) {
*p++ = LOC_ESCAPE;
*p++ = LOCAL_LOC;
p = SetFileLocPrefix( res, OP_LOCAL );
} else {
p = res;
oattrs = DefaultLoc( oattrs );
}
if( path != NULL ) {
Expand Down
12 changes: 5 additions & 7 deletions bld/wv/c/dbgprog.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,16 @@ void FindLocalDebugInfo( const char *name )
file_handle fh;

len = strlen( name );
_AllocA( buff, len + 1 + 4 + 2 );
_AllocA( symfile, len + 1 + 4 );
strcpy( buff, "@l" );
_AllocA( buff, 2 + len + 4 + 1 ); /* prefix + name + extension + '\0' */
_AllocA( symfile, len + 4 + 1 ); /* name + extension + '\0' */
SetFileLocPrefix( buff, OP_LOCAL );
// 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 );
strcpy( buff + 2, symfile );
FileClose( fh );
} else {
strcat( buff, name );
strcpy( buff + 2, name );
}
InsertRing( RingEnd( &LocalDebugInfo ), buff, strlen( buff ), false );
}
Expand Down Expand Up @@ -508,8 +508,6 @@ static image_entry *CreateImage( const char *exe, const char *symfile )
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 ) {
Expand Down
3 changes: 2 additions & 1 deletion bld/wv/h/dbgio.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2023 The Open Watcom Contributors. All Rights Reserved.
* Copyright (c) 2023-2024 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -75,6 +75,7 @@ extern error_handle FileRemove( char const *, obj_attrs );
extern const char *FileLoc( char const *, obj_attrs * );
extern obj_attrs FileHandleInfo( file_handle );
extern sys_handle GetSystemHandle( file_handle );
extern char *SetFileLocPrefix( char *buff, obj_attrs oattrs );

extern char *SysErrMsg( error_handle, char *buff );
extern error_handle StashErrCode( sys_error, obj_attrs );
Expand Down

0 comments on commit a3022a1

Please sign in to comment.