📄 browsio.c
字号:
sizeof( section_header_template ) );
}
return 0;
}
//---------------------------------------------------------------------------
static void dw_write( dw_sectnum section, const void *block, dw_size_t len )
/********************************************************************/
{
unsigned bufnum;
unsigned endbufnum;
C_DW_SECTION *dwsect;
char **newbufptrs;
unsigned bufsize;
char *bufptr;
dwsect = &DWSections[section];
#ifdef __DD__
//int i;
printf( "\nDW_WRITE(%d:%d): offset: %d len: %d ",
section,
dwsect->length,
dwsect->offset,
len );
//for( i = 0 ; i < len; i++ ) {
// printf( "%02x ", (int)((char *)block)[i] );
//}
#endif
bufnum = dwsect->offset / C_DWARF_BUFSIZE;
endbufnum = (dwsect->offset + len) / C_DWARF_BUFSIZE;
if( endbufnum >= dwsect->bufcount ) {
newbufptrs = (char**)CMemAlloc( (endbufnum + 1) * sizeof(char**) );
if( dwsect->bufptrs != NULL ) {
memcpy( newbufptrs,
dwsect->bufptrs,
dwsect->bufcount * sizeof(char**) );
CMemFree( dwsect->bufptrs );
}
dwsect->bufptrs = newbufptrs;
dwsect->bufcount = endbufnum + 1;
}
bufsize = C_DWARF_BUFSIZE - (dwsect->offset % C_DWARF_BUFSIZE);
dwsect->offset += len;
if( dwsect->offset > dwsect->length ) {
dwsect->length = dwsect->offset;
}
while( len != 0 ) {
bufptr = dwsect->bufptrs[bufnum];
if( bufptr == NULL ) {
bufptr = (char *)CMemAlloc( C_DWARF_BUFSIZE );
dwsect->bufptrs[bufnum] = bufptr;
}
bufptr += C_DWARF_BUFSIZE - bufsize;
if( len < bufsize ) bufsize = len;
memcpy( bufptr, block, bufsize );
block = (char *)block + bufsize;
len -= bufsize;
++bufnum; // advance to next buffer
bufsize = C_DWARF_BUFSIZE; // buffer is full size
}
}
static long dw_tell( dw_sectnum section )
/*********************************/
{
#ifdef __DD__
printf( "DW_TELL (%d:%d): %d\n", section,
DWSections[section].length,
DWSections[section].offset );
#endif
return DWSections[section].offset;
}
static void dw_reloc( dw_sectnum section, dw_relocs reloc_type, ... )
/********************************************************/
{
va_list args;
dw_targ_addr targ_data;
dw_targ_seg seg_data;
uint_32 u32_data;
uint sect;
SYMPTR sym;
va_start( args, reloc_type );
switch( reloc_type ) {
case DW_W_LABEL:
case DW_W_DEFAULT_FUNCTION:
case DW_W_ARANGE_ADDR:
case DW_W_LOW_PC:
u32_data = 0; // NOTE: assumes little-endian byte order
dw_write( section, &u32_data, TARGET_NEAR_POINTER );
break;
case DW_W_HIGH_PC:
u32_data = 1; // NOTE: assumes little-endian byte order
dw_write( section, &u32_data, TARGET_NEAR_POINTER );
break;
case DW_W_UNIT_SIZE:
u32_data = 1;
dw_write( section, &u32_data, sizeof( u32_data ) );
break;
case DW_W_STATIC:
sym = va_arg( args, SYMPTR );
targ_data = 0;
dw_write( section, &targ_data, sizeof( targ_data ) );
break;
case DW_W_SEGMENT:
sym = va_arg( args, SYMPTR );
seg_data = SymSegId( sym );
dw_write( section, &seg_data, sizeof( seg_data ) );
break;
case DW_W_SECTION_POS:
sect = va_arg( args, uint );
u32_data = dw_tell( sect );
dw_write( section, &u32_data, sizeof( u32_data ) );
break;
default:
break;
}
va_end( args );
}
static void dw_seek( dw_sectnum section, long offset, uint mode )
/*********************************************************/
{
unsigned long ofs = offset;
switch( mode ) {
case DW_SEEK_SET:
break;
case DW_SEEK_CUR:
ofs = DWSections[section].offset + offset;
break;
case DW_SEEK_END:
ofs = DWSections[section].length - offset;
break;
}
#ifdef __DD__
printf( "DW_SEEK (%d:%d): offset: %d\n",
section,
DWSections[section].length,
ofs );
#endif
if( DWSections[section].offset != ofs ) {
DWSections[section].offset = ofs;
if( DWSections[section].offset > DWSections[section].length ) {
DWSections[section].length = DWSections[section].offset;
}
}
}
static void *dw_alloc( size_t size )
/**********************************/
{
char *p;
p = CMemAlloc( size );
memset( p, 0xA5, size );
return( p );
}
static void dw_free( void *ptr )
/******************************/
{
CMemFree( ptr );
}
dw_client DwarfInit( void )
/********************/
{
dw_client client;
dw_init_info info;
dw_cu_info cu;
unsigned incsize;
char *inclist;
char *fname;
static const dw_funcs cli_funcs = {
dw_reloc,
dw_write,
dw_seek,
dw_tell,
dw_alloc,
dw_free
};
DWSectInit();
info.language = DWLANG_C;
info.compiler_options = DW_CM_BROWSER;
info.producer_name = "WATCOM C V10";
memcpy( info.exception_handler, Environment, sizeof( jmp_buf ) );
info.funcs = cli_funcs;
relocValues[ DW_W_LOW_PC ] = 0x0;
relocValues[ DW_W_HIGH_PC ] = 0x1;
relocValues[ DW_W_UNIT_SIZE ] = 0x1;
client = DWInit( &info );
if( client == NULL ) {
CFatal( "dwarf: error in DWInit()" );
}
fname = FNameFullPath( FNames );
incsize = 0;
inclist = NULL;
#if 0
if( HFileList != NULL ) {
char *p;
incsize = strlen( HFileList ) + 1;
inclist = CMemAlloc( incsize );
strcpy( inclist, HFileList );
// need to handle the case where there are multiple ';' in a row
for( p = inclist; *p; p++ ) {
if( *p == ';' ) *p = '\0';
}
if( inclist[ incsize - 2 ] == '\0' ) --incsize; /* 27-may-94 */
}
#endif
cu.source_filename = fname;
cu.directory = "";
cu.flags = 1;
cu.offset_size = TARGET_NEAR_POINTER;
cu.segment_size = 0;
cu.model = DW_MODEL_NONE;
cu.inc_list = inclist;
cu.inc_list_len = incsize;
cu.dbg_pch = 0;
DWBeginCompileUnit( client, &cu );
CMemFree( inclist );
DWDeclFile( client, fname );
return( client );
}
void DwarfFini( dw_client client )
/********************/
{
FILE *out_file;
DWEndCompileUnit( client );
DWFini( client );
out_file = OpenBrowseFile();
if( out_file != NULL ) {
// concatenate files
createBrowseFile( out_file,
&DWSections[DW_DEBUG_ABBREV],
&DWSections[DW_DEBUG_INFO],
&DWSections[DW_DEBUG_REF],
&DWSections[DW_DEBUG_LINE],
&DWSections[DW_DEBUG_MACINFO] );
fclose( out_file );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -