@ -31,19 +31,36 @@
# include "objfmt.h"
/*@dependent@*/ FILE * dbg_f ;
/* Note that the functions here write to debug_file. This is NOT legal for
* other object formats to do - - only the output ( ) function can write to a file ,
* and only the file it ' s passed in its f parameter !
*/
static void
dbg_objfmt_initialize ( const char * in_filename , const char * obj_filename )
{
fprintf ( debug_file , " %*sinitialize( \" %s \" , \" %s \" ) \n " , indent_level , " " ,
in_filename , obj_filename ) ;
}
static void
dbg_objfmt_initialize ( /*@dependent@*/ FILE * f )
dbg_objfmt_output ( FILE * f , sectionhead * sections )
{
dbg_f = f ;
fprintf ( dbg_f , " %*sinitialize(f) \n " , indent_level , " " ) ;
fprintf ( f , " %*soutput(f, sections-> \n " , indent_level , " " ) ;
indent_level + + ;
sections_print ( f , sections ) ;
indent_level - - ;
fprintf ( f , " %*s) \n " , indent_level , " " ) ;
indent_level + + ;
fprintf ( f , " %*sSymbol Table: \n " , indent_level , " " ) ;
symrec_print_all ( f ) ;
indent_level - - ;
}
static void
dbg_objfmt_finalize ( void )
dbg_objfmt_cleanup ( void )
{
fprintf ( dbg_f , " %*sfinalize() \n " , indent_level , " " ) ;
fprintf ( de bu g_file , " %*scleanup () \n " , indent_level , " " ) ;
}
static /*@dependent@*/ /*@null@*/ section *
@ -55,22 +72,22 @@ dbg_objfmt_sections_switch(sectionhead *headp, valparamhead *valparams,
section * retval ;
int isnew ;
fprintf ( dbg_f , " %*ssections_switch(headp, " , indent_level , " " ) ;
vps_print ( dbg_f , valparams ) ;
fprintf ( dbg_f , " , " ) ;
vps_print ( dbg_f , objext_valparams ) ;
fprintf ( dbg_f , " ), returning " ) ;
fprintf ( de bu g_file , " %*ssections_switch(headp, " , indent_level , " " ) ;
vps_print ( de bu g_file , valparams ) ;
fprintf ( de bu g_file , " , " ) ;
vps_print ( de bu g_file , objext_valparams ) ;
fprintf ( de bu g_file , " ), returning " ) ;
if ( ( vp = vps_first ( valparams ) ) & & ! vp - > param & & vp - > val ! = NULL ) {
retval = sections_switch_general ( headp , vp - > val , NULL , 0 , & isnew ) ;
if ( isnew ) {
fprintf ( dbg_f , " (new) " ) ;
fprintf ( de bu g_file , " (new) " ) ;
symrec_define_label ( vp - > val , retval , ( bytecode * ) NULL , 1 ) ;
}
fprintf ( dbg_f , " \" %s \" section \n " , vp - > val ) ;
fprintf ( de bu g_file , " \" %s \" section \n " , vp - > val ) ;
return retval ;
} else {
fprintf ( dbg_f , " NULL \n " ) ;
fprintf ( de bu g_file , " NULL \n " ) ;
return NULL ;
}
}
@ -78,7 +95,7 @@ dbg_objfmt_sections_switch(sectionhead *headp, valparamhead *valparams,
static void
dbg_objfmt_section_data_delete ( /*@only@*/ void * data )
{
fprintf ( dbg_f , " %*ssection_data_delete(%p) \n " , indent_level , " " , data ) ;
fprintf ( de bu g_file , " %*ssection_data_delete(%p) \n " , indent_level , " " , data ) ;
xfree ( data ) ;
}
@ -95,9 +112,9 @@ static /*@null@*/ void *
dbg_objfmt_extern_data_new ( const char * name , /*@unused@*/ /*@null@*/
valparamhead * objext_valparams )
{
fprintf ( dbg_f , " %*sextern_data_new( \" %s \" , " , indent_level , " " , name ) ;
vps_print ( dbg_f , objext_valparams ) ;
fprintf ( dbg_f , " ), returning NULL \n " ) ;
fprintf ( de bu g_file , " %*sextern_data_new( \" %s \" , " , indent_level , " " , name ) ;
vps_print ( de bu g_file , objext_valparams ) ;
fprintf ( de bu g_file , " ), returning NULL \n " ) ;
return NULL ;
}
@ -105,9 +122,9 @@ static /*@null@*/ void *
dbg_objfmt_global_data_new ( const char * name , /*@unused@*/ /*@null@*/
valparamhead * objext_valparams )
{
fprintf ( dbg_f , " %*sglobal_data_new( \" %s \" , " , indent_level , " " , name ) ;
vps_print ( dbg_f , objext_valparams ) ;
fprintf ( dbg_f , " ), returning NULL \n " ) ;
fprintf ( de bu g_file , " %*sglobal_data_new( \" %s \" , " , indent_level , " " , name ) ;
vps_print ( de bu g_file , objext_valparams ) ;
fprintf ( de bu g_file , " ), returning NULL \n " ) ;
return NULL ;
}
@ -116,13 +133,13 @@ dbg_objfmt_common_data_new(const char *name, /*@only@*/ expr *size,
/*@unused@*/ /*@null@*/
valparamhead * objext_valparams )
{
fprintf ( dbg_f , " %*scommon_data_new( \" %s \" , " , indent_level , " " , name ) ;
expr_print ( dbg_f , size ) ;
fprintf ( dbg_f , " , " ) ;
vps_print ( dbg_f , objext_valparams ) ;
fprintf ( dbg_f , " ), returning " ) ;
expr_print ( dbg_f , size ) ;
fprintf ( dbg_f , " \n " ) ;
fprintf ( de bu g_file , " %*scommon_data_new( \" %s \" , " , indent_level , " " , name ) ;
expr_print ( de bu g_file , size ) ;
fprintf ( de bu g_file , " , " ) ;
vps_print ( de bu g_file , objext_valparams ) ;
fprintf ( de bu g_file , " ), returning " ) ;
expr_print ( de bu g_file , size ) ;
fprintf ( de bu g_file , " \n " ) ;
return size ;
}
@ -131,29 +148,29 @@ dbg_objfmt_declare_data_copy(SymVisibility vis, /*@only@*/ void *data)
{
void * retval ;
fprintf ( dbg_f , " %*sdeclare_data_copy( " , indent_level , " " ) ;
fprintf ( de bu g_file , " %*sdeclare_data_copy( " , indent_level , " " ) ;
switch ( vis ) {
case SYM_LOCAL :
fprintf ( dbg_f , " Local, " ) ;
fprintf ( de bu g_file , " Local, " ) ;
break ;
case SYM_GLOBAL :
fprintf ( dbg_f , " Global, " ) ;
fprintf ( de bu g_file , " Global, " ) ;
break ;
case SYM_COMMON :
fprintf ( dbg_f , " Common, " ) ;
fprintf ( de bu g_file , " Common, " ) ;
break ;
case SYM_EXTERN :
fprintf ( dbg_f , " Extern, " ) ;
fprintf ( de bu g_file , " Extern, " ) ;
break ;
}
if ( vis = = SYM_COMMON ) {
expr_print ( dbg_f , data ) ;
expr_print ( de bu g_file , data ) ;
retval = expr_copy ( data ) ;
} else {
fprintf ( dbg_f , " %p " , data ) ;
fprintf ( de bu g_file , " %p " , data ) ;
InternalError ( _ ( " Trying to copy unrecognized objfmt data " ) ) ;
}
fprintf ( dbg_f , " ), returning copy \n " ) ;
fprintf ( de bu g_file , " ), returning copy \n " ) ;
return retval ;
}
@ -161,29 +178,29 @@ dbg_objfmt_declare_data_copy(SymVisibility vis, /*@only@*/ void *data)
static void
dbg_objfmt_declare_data_delete ( SymVisibility vis , /*@only@*/ void * data )
{
fprintf ( dbg_f , " %*sdeclare_data_delete( " , indent_level , " " ) ;
fprintf ( de bu g_file , " %*sdeclare_data_delete( " , indent_level , " " ) ;
switch ( vis ) {
case SYM_LOCAL :
fprintf ( dbg_f , " Local, " ) ;
fprintf ( de bu g_file , " Local, " ) ;
break ;
case SYM_GLOBAL :
fprintf ( dbg_f , " Global, " ) ;
fprintf ( de bu g_file , " Global, " ) ;
break ;
case SYM_COMMON :
fprintf ( dbg_f , " Common, " ) ;
fprintf ( de bu g_file , " Common, " ) ;
break ;
case SYM_EXTERN :
fprintf ( dbg_f , " Extern, " ) ;
fprintf ( de bu g_file , " Extern, " ) ;
break ;
}
if ( vis = = SYM_COMMON ) {
expr_print ( dbg_f , data ) ;
expr_print ( de bu g_file , data ) ;
expr_delete ( data ) ;
} else {
fprintf ( dbg_f , " %p " , data ) ;
fprintf ( de bu g_file , " %p " , data ) ;
xfree ( data ) ;
}
fprintf ( dbg_f , " ) \n " ) ;
fprintf ( de bu g_file , " ) \n " ) ;
}
static void
@ -203,11 +220,11 @@ static int
dbg_objfmt_directive ( const char * name , valparamhead * valparams ,
/*@null@*/ valparamhead * objext_valparams )
{
fprintf ( dbg_f , " %*sdirective( \" %s \" , " , indent_level , " " , name ) ;
vps_print ( dbg_f , valparams ) ;
fprintf ( dbg_f , " , " ) ;
vps_print ( dbg_f , objext_valparams ) ;
fprintf ( dbg_f , " ), returning 0 (recognized) \n " ) ;
fprintf ( de bu g_file , " %*sdirective( \" %s \" , " , indent_level , " " , name ) ;
vps_print ( de bu g_file , valparams ) ;
fprintf ( de bu g_file , " , " ) ;
vps_print ( de bu g_file , objext_valparams ) ;
fprintf ( de bu g_file , " ), returning 0 (recognized) \n " ) ;
return 0 ; /* dbg format "recognizes" all directives */
}
@ -219,7 +236,8 @@ objfmt dbg_objfmt = {
" .text " ,
32 ,
dbg_objfmt_initialize ,
dbg_objfmt_finalize ,
dbg_objfmt_output ,
dbg_objfmt_cleanup ,
dbg_objfmt_sections_switch ,
dbg_objfmt_section_data_delete ,
dbg_objfmt_section_data_print ,