From caf89035f8d3bf0c5e4c93fdf590e62538c2d7ae Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 26 Oct 2002 19:50:08 +0000 Subject: [PATCH] Remove indent_level global by passing it as a parameter. svn path=/trunk/yasm/; revision=786 --- libyasm/arch.c | 10 +++--- libyasm/arch.h | 8 ++--- libyasm/bytecode.c | 28 +++++++--------- libyasm/bytecode.h | 8 ++--- libyasm/linemgr.c | 3 -- libyasm/linemgr.h | 3 -- libyasm/objfmt.h | 7 ++-- libyasm/section.c | 15 ++++----- libyasm/section.h | 5 +-- libyasm/symrec.c | 39 +++++++++++----------- libyasm/symrec.h | 4 +-- modules/arch/x86/x86arch.h | 4 +-- modules/arch/x86/x86bc.c | 20 ++++-------- modules/objfmts/bin/bin-objfmt.c | 2 +- modules/objfmts/coff/coff-objfmt.c | 22 ++++--------- modules/objfmts/dbg/dbg-objfmt.c | 52 +++++++++++++----------------- src/arch.c | 10 +++--- src/arch.h | 8 ++--- src/arch/x86/x86arch.h | 4 +-- src/arch/x86/x86bc.c | 20 ++++-------- src/bytecode.c | 28 +++++++--------- src/bytecode.h | 8 ++--- src/globals.c | 3 -- src/globals.h | 3 -- src/linemgr.c | 3 -- src/linemgr.h | 3 -- src/objfmt.h | 7 ++-- src/objfmts/bin/bin-objfmt.c | 2 +- src/objfmts/coff/coff-objfmt.c | 22 ++++--------- src/objfmts/dbg/dbg-objfmt.c | 52 +++++++++++++----------------- src/section.c | 15 ++++----- src/section.h | 5 +-- src/symrec.c | 39 +++++++++++----------- src/symrec.h | 4 +-- 34 files changed, 196 insertions(+), 270 deletions(-) diff --git a/libyasm/arch.c b/libyasm/arch.c index 4242ce30..bf46b3c0 100644 --- a/libyasm/arch.c +++ b/libyasm/arch.c @@ -99,7 +99,7 @@ operand_new_imm(/*@only@*/ expr *val) } void -operand_print(FILE *f, const insn_operand *op) +operand_print(FILE *f, int indent_level, const insn_operand *op) { switch (op->type) { case INSN_OPERAND_REG: @@ -114,9 +114,7 @@ operand_print(FILE *f, const insn_operand *op) break; case INSN_OPERAND_MEMORY: fprintf(f, "%*sMemory=\n", indent_level, ""); - indent_level++; - ea_print(f, op->data.ea); - indent_level--; + ea_print(f, indent_level, op->data.ea); break; case INSN_OPERAND_IMM: fprintf(f, "%*sImm=", indent_level, ""); @@ -164,10 +162,10 @@ ops_append(insn_operandhead *headp, /*@returned@*/ /*@null@*/ insn_operand *op) } void -ops_print(FILE *f, const insn_operandhead *headp) +ops_print(FILE *f, int indent_level, const insn_operandhead *headp) { insn_operand *cur; STAILQ_FOREACH (cur, headp, link) - operand_print(f, cur); + operand_print(f, indent_level, cur); } diff --git a/libyasm/arch.h b/libyasm/arch.h index 3e0295ed..02f93db6 100644 --- a/libyasm/arch.h +++ b/libyasm/arch.h @@ -129,7 +129,7 @@ struct arch { const int type_max; void (*bc_delete) (bytecode *bc); - void (*bc_print) (FILE *f, const bytecode *bc); + void (*bc_print) (FILE *f, int indent_level, const bytecode *bc); /* See bytecode.h comments on bc_resolve() */ bc_resolve_flags (*bc_resolve) (bytecode *bc, int save, @@ -166,7 +166,7 @@ struct arch { */ void (*ea_data_delete) (effaddr *ea); - void (*ea_data_print) (FILE *f, const effaddr *ea); + void (*ea_data_print) (FILE *f, int indent_level, const effaddr *ea); }; struct insn_operand { @@ -201,7 +201,7 @@ insn_operand *operand_new_segreg(unsigned long segreg); insn_operand *operand_new_mem(/*@only@*/ effaddr *ea); insn_operand *operand_new_imm(/*@only@*/ expr *val); -void operand_print(FILE *f, const insn_operand *op); +void operand_print(FILE *f, int indent_level, const insn_operand *op); #define ops_initialize(headp) STAILQ_INIT(headp) #define ops_first(headp) STAILQ_FIRST(headp) @@ -221,6 +221,6 @@ void ops_delete(insn_operandhead *headp, int content); /*@null@*/ insn_operand *ops_append(insn_operandhead *headp, /*@returned@*/ /*@null@*/ insn_operand *op); -void ops_print(FILE *f, const insn_operandhead *headp); +void ops_print(FILE *f, int indent_level, const insn_operandhead *headp); #endif diff --git a/libyasm/bytecode.c b/libyasm/bytecode.c index 8c210367..0aedd6d0 100644 --- a/libyasm/bytecode.c +++ b/libyasm/bytecode.c @@ -164,14 +164,14 @@ ea_delete(effaddr *ea) /*@-nullstate@*/ void -ea_print(FILE *f, const effaddr *ea) +ea_print(FILE *f, int indent_level, const effaddr *ea) { fprintf(f, "%*sDisp=", indent_level, ""); expr_print(f, ea->disp); fprintf(f, "\n%*sLen=%u\n", indent_level, "", (unsigned int)ea->len); fprintf(f, "%*sNoSplit=%u\n", indent_level, "", (unsigned int)ea->nosplit); if (cur_arch->ea_data_print) - cur_arch->ea_data_print(f, ea); + cur_arch->ea_data_print(f, indent_level, ea); } /*@=nullstate@*/ @@ -339,7 +339,7 @@ bc_delete(bytecode *bc) } void -bc_print(FILE *f, const bytecode *bc) +bc_print(FILE *f, int indent_level, const bytecode *bc) { const bytecode_data *data; const bytecode_reserve *reserve; @@ -356,13 +356,10 @@ bc_print(FILE *f, const bytecode *bc) case BC_DATA: data = (const bytecode_data *)bc; fprintf(f, "%*s_Data_\n", indent_level, ""); - indent_level++; - fprintf(f, "%*sFinal Element Size=%u\n", indent_level, "", + fprintf(f, "%*sFinal Element Size=%u\n", indent_level+1, "", (unsigned int)data->size); - fprintf(f, "%*sElements:\n", indent_level, ""); - indent_level++; - dvs_print(f, &data->datahead); - indent_level-=2; + fprintf(f, "%*sElements:\n", indent_level+1, ""); + dvs_print(f, indent_level+2, &data->datahead); break; case BC_RESERVE: reserve = (const bytecode_reserve *)bc; @@ -398,14 +395,15 @@ bc_print(FILE *f, const bytecode *bc) objfmt_data = (const bytecode_objfmt_data *)bc; fprintf(f, "%*s_ObjFmt_Data_\n", indent_level, ""); if (objfmt_data->of->bc_objfmt_data_print) - objfmt_data->of->bc_objfmt_data_print(f, objfmt_data->type, + objfmt_data->of->bc_objfmt_data_print(f, indent_level, + objfmt_data->type, objfmt_data->data); else fprintf(f, "%*sUNKNOWN\n", indent_level, ""); break; default: if (bc->type < cur_arch->bc.type_max) - cur_arch->bc.bc_print(f, bc); + cur_arch->bc.bc_print(f, indent_level, bc); else fprintf(f, "%*s_Unknown_\n", indent_level, ""); break; @@ -863,15 +861,13 @@ bcs_append(bytecodehead *headp, bytecode *bc) } void -bcs_print(FILE *f, const bytecodehead *headp) +bcs_print(FILE *f, int indent_level, const bytecodehead *headp) { bytecode *cur; STAILQ_FOREACH(cur, headp, link) { fprintf(f, "%*sNext Bytecode:\n", indent_level, ""); - indent_level++; - bc_print(f, cur); - indent_level--; + bc_print(f, indent_level+1, cur); } } @@ -946,7 +942,7 @@ dvs_append(datavalhead *headp, dataval *dv) } void -dvs_print(FILE *f, const datavalhead *head) +dvs_print(FILE *f, int indent_level, const datavalhead *head) { dataval *cur; diff --git a/libyasm/bytecode.h b/libyasm/bytecode.h index 128ec04b..6ad5bb38 100644 --- a/libyasm/bytecode.h +++ b/libyasm/bytecode.h @@ -49,7 +49,7 @@ void bc_initialize(arch *a); void ea_set_len(effaddr *ea, unsigned char len); void ea_set_nosplit(effaddr *ea, unsigned char nosplit); void ea_delete(/*@only@*/ effaddr *ea); -void ea_print(FILE *f, const effaddr *ea); +void ea_print(FILE *f, int indent_level, const effaddr *ea); void bc_set_multiple(bytecode *bc, /*@keep@*/ expr *e); @@ -66,7 +66,7 @@ void bc_set_multiple(bytecode *bc, /*@keep@*/ expr *e); void bc_delete(/*@only@*/ /*@null@*/ bytecode *bc); -void bc_print(FILE *f, const bytecode *bc); +void bc_print(FILE *f, int indent_level, const bytecode *bc); /* A common version of a calc_bc_dist function that should work for the final * stages of optimizers as well as in objfmt expr output functions. It takes @@ -146,7 +146,7 @@ void bcs_delete(bytecodehead *headp); /*@returned@*/ /*@only@*/ /*@null@*/ bytecode *bc); -void bcs_print(FILE *f, const bytecodehead *headp); +void bcs_print(FILE *f, int indent_level, const bytecodehead *headp); /* Calls func for each bytecode in the linked list of bytecodes pointed to by * headp. The data pointer d is passed to each func call. @@ -175,6 +175,6 @@ void dvs_delete(datavalhead *headp); /*@null@*/ dataval *dvs_append(datavalhead *headp, /*@returned@*/ /*@null@*/ dataval *dv); -void dvs_print(FILE *f, const datavalhead *head); +void dvs_print(FILE *f, int indent_level, const datavalhead *head); #endif diff --git a/libyasm/linemgr.c b/libyasm/linemgr.c index 6955051e..61763af5 100644 --- a/libyasm/linemgr.c +++ b/libyasm/linemgr.c @@ -57,9 +57,6 @@ static /*@only@*/ /*@null@*/ line_index_mapping_head *line_index_map = NULL; /* Global assembler options. */ unsigned int asm_options = 0; -/* Indentation level for assembler *_print() routines */ -int indent_level = 0; - static void filename_delete_one(/*@only@*/ void *d) { diff --git a/libyasm/linemgr.h b/libyasm/linemgr.h index 00cc28df..a38ed352 100644 --- a/libyasm/linemgr.h +++ b/libyasm/linemgr.h @@ -28,9 +28,6 @@ extern unsigned long line_index; /* Global assembler options. */ extern unsigned int asm_options; -/* Indentation level for assembler *_print() routines */ -extern int indent_level; - void line_set(const char *filename, unsigned long line, unsigned long line_inc); void line_shutdown(void); diff --git a/libyasm/objfmt.h b/libyasm/objfmt.h index b2e29ad5..24f9b935 100644 --- a/libyasm/objfmt.h +++ b/libyasm/objfmt.h @@ -82,7 +82,7 @@ struct objfmt { * May be NULL if no data is ever allocated in sections_switch(). */ void (*section_data_delete)(/*@only@*/ void *data); - void (*section_data_print)(FILE *f, void *data); + void (*section_data_print)(FILE *f, int indent_level, void *data); /* These functions should call symrec_set_of_data() to store data. * May be NULL if objfmt doesn't care about such declarations. @@ -96,7 +96,7 @@ struct objfmt { /* May be NULL if symrec_set_of_data() is never called. */ void (*symrec_data_delete)(/*@only@*/ void *data); - void (*symrec_data_print)(FILE *f, void *data); + void (*symrec_data_print)(FILE *f, int indent_level, void *data); /* Object format-specific directive support. Returns 1 if directive was * not recognized. Returns 0 if directive was recognized, even if it @@ -110,7 +110,8 @@ struct objfmt { * May be NULL if no BC_OBJFMT_DATA is ever allocated by the object format. */ void (*bc_objfmt_data_delete)(unsigned int type, /*@only@*/ void *data); - void (*bc_objfmt_data_print)(FILE *f, unsigned int type, const void *data); + void (*bc_objfmt_data_print)(FILE *f, int indent_level, unsigned int type, + const void *data); }; /* Generic functions for all object formats - implemented in src/objfmt.c */ diff --git a/libyasm/section.c b/libyasm/section.c index dd7cdb19..88d10fff 100644 --- a/libyasm/section.c +++ b/libyasm/section.c @@ -206,15 +206,13 @@ sections_delete(sectionhead *headp) } void -sections_print(FILE *f, const sectionhead *headp) +sections_print(FILE *f, int indent_level, const sectionhead *headp) { section *cur; STAILQ_FOREACH(cur, headp, link) { fprintf(f, "%*sSection:\n", indent_level, ""); - indent_level++; - section_print(f, cur, 1); - indent_level--; + section_print(f, indent_level+1, cur, 1); } } @@ -296,7 +294,7 @@ section_delete(section *sect) } void -section_print(FILE *f, const section *sect, int print_bcs) +section_print(FILE *f, int indent_level, const section *sect, int print_bcs) { if (!sect) { fprintf(f, "%*s(none)\n", indent_level, ""); @@ -312,7 +310,8 @@ section_print(FILE *f, const section *sect, int print_bcs) if (sect->data.general.of_data && sect->data.general.of) { objfmt *of = sect->data.general.of; if (of->section_data_print) - of->section_data_print(f, sect->data.general.of_data); + of->section_data_print(f, indent_level, + sect->data.general.of_data); else fprintf(f, "%*sUNKNOWN\n", indent_level, ""); } else @@ -330,8 +329,6 @@ section_print(FILE *f, const section *sect, int print_bcs) if (print_bcs) { fprintf(f, "%*sBytecodes:\n", indent_level, ""); - indent_level++; - bcs_print(f, §->bc); - indent_level--; + bcs_print(f, indent_level+1, §->bc); } } diff --git a/libyasm/section.h b/libyasm/section.h index 20776a8c..7645e40c 100644 --- a/libyasm/section.h +++ b/libyasm/section.h @@ -45,7 +45,7 @@ void section_set_of_data(section *sect, objfmt *of, void sections_delete(sectionhead *headp); -void sections_print(FILE *f, const sectionhead *headp); +void sections_print(FILE *f, int indent_level, const sectionhead *headp); /* Calls func for each section in the linked list of sections pointed to by * headp. The data pointer d is passed to each func call. @@ -68,5 +68,6 @@ void section_set_start(section *sect, unsigned long start); void section_delete(/*@only@*/ section *sect); -void section_print(FILE *f, /*@null@*/ const section *sect, int print_bcs); +void section_print(FILE *f, int indent_level, /*@null@*/ const section *sect, + int print_bcs); #endif diff --git a/libyasm/symrec.c b/libyasm/symrec.c index 6efb7dba..876c1c32 100644 --- a/libyasm/symrec.c +++ b/libyasm/symrec.c @@ -360,29 +360,34 @@ symrec_delete_all(void) } } +typedef struct symrec_print_data { + FILE *f; + int indent_level; +} symrec_print_data; + /*@+voidabstract@*/ static int symrec_print_wrapper(symrec *sym, /*@null@*/ void *d) { - FILE *f; - assert(d != NULL); - f = (FILE *)d; - fprintf(f, "%*sSymbol `%s'\n", indent_level, "", sym->name); - indent_level++; - symrec_print(f, sym); - indent_level--; + symrec_print_data *data = (symrec_print_data *)d; + assert(data != NULL); + fprintf(data->f, "%*sSymbol `%s'\n", data->indent_level, "", sym->name); + symrec_print(data->f, data->indent_level+1, sym); return 1; } void -symrec_print_all(FILE *f) +symrec_print_all(FILE *f, int indent_level) { - symrec_traverse(f, symrec_print_wrapper); + symrec_print_data data; + data.f = f; + data.indent_level = indent_level; + symrec_traverse(&data, symrec_print_wrapper); } /*@=voidabstract@*/ void -symrec_print(FILE *f, const symrec *sym) +symrec_print(FILE *f, int indent_level, const symrec *sym) { const char *filename; unsigned long line; @@ -400,16 +405,12 @@ symrec_print(FILE *f, const symrec *sym) case SYM_LABEL: fprintf(f, "%*s_Label_\n%*sSection:\n", indent_level, "", indent_level, ""); - indent_level++; - section_print(f, sym->value.label.sect, 0); - indent_level--; + section_print(f, indent_level+1, sym->value.label.sect, 0); if (!sym->value.label.bc) fprintf(f, "%*sFirst bytecode\n", indent_level, ""); else { fprintf(f, "%*sPreceding bytecode:\n", indent_level, ""); - indent_level++; - bc_print(f, sym->value.label.bc); - indent_level--; + bc_print(f, indent_level+1, sym->value.label.bc); } break; } @@ -444,12 +445,10 @@ symrec_print(FILE *f, const symrec *sym) if (sym->of_data && sym->of) { fprintf(f, "%*sObject format-specific data:\n", indent_level, ""); - indent_level++; if (sym->of->symrec_data_print) - sym->of->symrec_data_print(f, sym->of_data); + sym->of->symrec_data_print(f, indent_level+1, sym->of_data); else - fprintf(f, "%*sUNKNOWN\n", indent_level, ""); - indent_level--; + fprintf(f, "%*sUNKNOWN\n", indent_level+1, ""); } line_lookup(sym->line, &filename, &line); diff --git a/libyasm/symrec.h b/libyasm/symrec.h index 5a4f0063..49ac2b91 100644 --- a/libyasm/symrec.h +++ b/libyasm/symrec.h @@ -64,7 +64,7 @@ void symrec_parser_finalize(void); void symrec_delete_all(void); -void symrec_print_all(FILE *f); +void symrec_print_all(FILE *f, int indent_level); -void symrec_print(FILE *f, const symrec *sym); +void symrec_print(FILE *f, int indent_level, const symrec *sym); #endif diff --git a/modules/arch/x86/x86arch.h b/modules/arch/x86/x86arch.h index 48c026df..824912b0 100644 --- a/modules/arch/x86/x86arch.h +++ b/modules/arch/x86/x86arch.h @@ -115,7 +115,7 @@ bytecode *x86_bc_new_jmprel(x86_new_jmprel_data *d); extern unsigned char yasm_x86_LTX_mode_bits; void x86_bc_delete(bytecode *bc); -void x86_bc_print(FILE *f, const bytecode *bc); +void x86_bc_print(FILE *f, int indent_level, const bytecode *bc); bc_resolve_flags x86_bc_resolve(bytecode *bc, int save, const section *sect, calc_bc_dist_func calc_bc_dist); int x86_bc_tobytes(bytecode *bc, unsigned char **bufp, const section *sect, @@ -161,6 +161,6 @@ void x86_reg_print(FILE *f, unsigned long reg); void x86_segreg_print(FILE *f, unsigned long segreg); -void x86_ea_data_print(FILE *f, const effaddr *ea); +void x86_ea_data_print(FILE *f, int indent_level, const effaddr *ea); #endif diff --git a/modules/arch/x86/x86bc.c b/modules/arch/x86/x86bc.c index bf65ec64..d6aa652c 100644 --- a/modules/arch/x86/x86bc.c +++ b/modules/arch/x86/x86bc.c @@ -412,7 +412,7 @@ x86_bc_delete(bytecode *bc) } void -x86_ea_data_print(FILE *f, const effaddr *ea) +x86_ea_data_print(FILE *f, int indent_level, const effaddr *ea) { const x86_effaddr *x86_ea = (const x86_effaddr *)ea; fprintf(f, "%*sSegmentOv=%02x\n", indent_level, "", @@ -426,7 +426,7 @@ x86_ea_data_print(FILE *f, const effaddr *ea) } void -x86_bc_print(FILE *f, const bytecode *bc) +x86_bc_print(FILE *f, int indent_level, const bytecode *bc) { const x86_insn *insn; const x86_jmprel *jmprel; @@ -438,9 +438,7 @@ x86_bc_print(FILE *f, const bytecode *bc) fprintf(f, "%*sEffective Address:", indent_level, ""); if (insn->ea) { fprintf(f, "\n"); - indent_level++; - ea_print(f, (effaddr *)insn->ea); - indent_level--; + ea_print(f, indent_level+1, (effaddr *)insn->ea); } else fprintf(f, " (nil)\n"); fprintf(f, "%*sImmediate Value:", indent_level, ""); @@ -481,29 +479,25 @@ x86_bc_print(FILE *f, const bytecode *bc) fprintf(f, "%*sTarget=", indent_level, ""); expr_print(f, jmprel->target); fprintf(f, "\n%*sShort Form:\n", indent_level, ""); - indent_level++; if (jmprel->shortop.opcode_len == 0) - fprintf(f, "%*sNone\n", indent_level, ""); + fprintf(f, "%*sNone\n", indent_level+1, ""); else fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n", - indent_level, "", + indent_level+1, "", (unsigned int)jmprel->shortop.opcode[0], (unsigned int)jmprel->shortop.opcode[1], (unsigned int)jmprel->shortop.opcode[2], (unsigned int)jmprel->shortop.opcode_len); - indent_level--; fprintf(f, "%*sNear Form:\n", indent_level, ""); - indent_level++; if (jmprel->nearop.opcode_len == 0) - fprintf(f, "%*sNone\n", indent_level, ""); + fprintf(f, "%*sNone\n", indent_level+1, ""); else fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n", - indent_level, "", + indent_level+1, "", (unsigned int)jmprel->nearop.opcode[0], (unsigned int)jmprel->nearop.opcode[1], (unsigned int)jmprel->nearop.opcode[2], (unsigned int)jmprel->nearop.opcode_len); - indent_level--; fprintf(f, "%*sOpSel=", indent_level, ""); switch (jmprel->op_sel) { case JR_NONE: diff --git a/modules/objfmts/bin/bin-objfmt.c b/modules/objfmts/bin/bin-objfmt.c index 15b70dce..2e5f0ed9 100644 --- a/modules/objfmts/bin/bin-objfmt.c +++ b/modules/objfmts/bin/bin-objfmt.c @@ -448,7 +448,7 @@ bin_objfmt_directive(const char *name, valparamhead *valparams, } static void -bin_objfmt_section_data_print(FILE *f, void *data) +bin_objfmt_section_data_print(FILE *f, int indent_level, void *data) { fprintf(f, "%*salign=%ld\n", indent_level, "", *((unsigned long *)data)); } diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c index a85068fa..135d46fb 100644 --- a/modules/objfmts/coff/coff-objfmt.c +++ b/modules/objfmts/coff/coff-objfmt.c @@ -778,16 +778,14 @@ coff_objfmt_section_data_delete(/*@only@*/ void *data) } static void -coff_objfmt_section_data_print(FILE *f, void *data) +coff_objfmt_section_data_print(FILE *f, int indent_level, void *data) { coff_section_data *csd = (coff_section_data *)data; coff_reloc *reloc; unsigned long relocnum = 0; fprintf(f, "%*ssym=\n", indent_level, ""); - indent_level++; - symrec_print(f, csd->sym); - indent_level--; + symrec_print(f, indent_level+1, csd->sym); fprintf(f, "%*sscnum=%d\n", indent_level, "", csd->scnum); fprintf(f, "%*sflags=", indent_level, ""); switch (csd->flags) { @@ -810,15 +808,11 @@ coff_objfmt_section_data_print(FILE *f, void *data) fprintf(f, "%*srelptr=0x%lx\n", indent_level, "", csd->relptr); fprintf(f, "%*snreloc=%ld\n", indent_level, "", csd->nreloc); fprintf(f, "%*srelocs:\n", indent_level, ""); - indent_level++; STAILQ_FOREACH(reloc, &csd->relocs, link) { - fprintf(f, "%*sReloc %lu:\n", indent_level, "", relocnum++); - indent_level++; - fprintf(f, "%*ssym=\n", indent_level, ""); - indent_level++; - symrec_print(f, reloc->sym); - indent_level--; - fprintf(f, "%*stype=", indent_level, ""); + fprintf(f, "%*sReloc %lu:\n", indent_level+1, "", relocnum++); + fprintf(f, "%*ssym=\n", indent_level+2, ""); + symrec_print(f, indent_level+3, reloc->sym); + fprintf(f, "%*stype=", indent_level+2, ""); switch (reloc->type) { case COFF_RELOC_ADDR32: printf("Addr32\n"); @@ -827,9 +821,7 @@ coff_objfmt_section_data_print(FILE *f, void *data) printf("Rel32\n"); break; } - indent_level--; } - indent_level--; } static void @@ -858,7 +850,7 @@ coff_objfmt_symrec_data_delete(/*@only@*/ void *data) } static void -coff_objfmt_symrec_data_print(FILE *f, void *data) +coff_objfmt_symrec_data_print(FILE *f, int indent_level, void *data) { coff_symrec_data *csd = (coff_symrec_data *)data; diff --git a/modules/objfmts/dbg/dbg-objfmt.c b/modules/objfmts/dbg/dbg-objfmt.c index 7cc5f16d..a50d5f49 100644 --- a/modules/objfmts/dbg/dbg-objfmt.c +++ b/modules/objfmts/dbg/dbg-objfmt.c @@ -53,31 +53,29 @@ dbg_objfmt_initialize(const char *in_filename, const char *obj_filename, dbgfmt *df, arch *a) { dbg_objfmt_file = fopen(obj_filename, "wt"); - if (!dbg_objfmt_file) + if (!dbg_objfmt_file) { ErrorNow(_("could not open file `%s'"), obj_filename); + return; + } fprintf(dbg_objfmt_file, - "%*sinitialize(\"%s\", \"%s\", %s dbgfmt, %s arch)\n", indent_level, - "", in_filename, obj_filename, df->keyword, a->keyword); + "initialize(\"%s\", \"%s\", %s dbgfmt, %s arch)\n", + in_filename, obj_filename, df->keyword, a->keyword); } static void dbg_objfmt_output(/*@unused@*/ FILE *f, sectionhead *sections) { - fprintf(dbg_objfmt_file, "%*soutput(f, sections->\n", indent_level, ""); - indent_level++; - sections_print(dbg_objfmt_file, sections); - indent_level--; - fprintf(dbg_objfmt_file, "%*s)\n", indent_level, ""); - indent_level++; - fprintf(dbg_objfmt_file, "%*sSymbol Table:\n", indent_level, ""); - symrec_print_all(dbg_objfmt_file); - indent_level--; + fprintf(dbg_objfmt_file, "output(f, sections->\n"); + sections_print(dbg_objfmt_file, 1, sections); + fprintf(dbg_objfmt_file, ")\n"); + fprintf(dbg_objfmt_file, " Symbol Table:\n"); + symrec_print_all(dbg_objfmt_file, 1); } static void dbg_objfmt_cleanup(void) { - fprintf(dbg_objfmt_file, "%*scleanup()\n", indent_level, ""); + fprintf(dbg_objfmt_file, "cleanup()\n"); } static /*@observer@*/ /*@null@*/ section * @@ -89,7 +87,7 @@ dbg_objfmt_sections_switch(sectionhead *headp, valparamhead *valparams, section *retval; int isnew; - fprintf(dbg_objfmt_file, "%*ssections_switch(headp, ", indent_level, ""); + fprintf(dbg_objfmt_file, "sections_switch(headp, "); vps_print(dbg_objfmt_file, valparams); fprintf(dbg_objfmt_file, ", "); vps_print(dbg_objfmt_file, objext_valparams); @@ -112,13 +110,12 @@ dbg_objfmt_sections_switch(sectionhead *headp, valparamhead *valparams, static void dbg_objfmt_section_data_delete(/*@only@*/ void *data) { - fprintf(dbg_objfmt_file, "%*ssection_data_delete(%p)\n", indent_level, "", - data); + fprintf(dbg_objfmt_file, "section_data_delete(%p)\n", data); xfree(data); } static void -dbg_objfmt_section_data_print(FILE *f, /*@null@*/ void *data) +dbg_objfmt_section_data_print(FILE *f, int indent_level, /*@null@*/ void *data) { if (data) fprintf(f, "%*s%p\n", indent_level, "", data); @@ -130,8 +127,7 @@ static void dbg_objfmt_extern_declare(symrec *sym, /*@unused@*/ /*@null@*/ valparamhead *objext_valparams) { - fprintf(dbg_objfmt_file, "%*sextern_declare(\"%s\", ", indent_level, "", - symrec_get_name(sym)); + fprintf(dbg_objfmt_file, "extern_declare(\"%s\", ", symrec_get_name(sym)); vps_print(dbg_objfmt_file, objext_valparams); fprintf(dbg_objfmt_file, "), setting of_data=NULL\n"); symrec_set_of_data(sym, &yasm_dbg_LTX_objfmt, NULL); @@ -141,8 +137,7 @@ static void dbg_objfmt_global_declare(symrec *sym, /*@unused@*/ /*@null@*/ valparamhead *objext_valparams) { - fprintf(dbg_objfmt_file, "%*sglobal_declare(\"%s\", ", indent_level, "", - symrec_get_name(sym)); + fprintf(dbg_objfmt_file, "global_declare(\"%s\", ", symrec_get_name(sym)); vps_print(dbg_objfmt_file, objext_valparams); fprintf(dbg_objfmt_file, "), setting of_data=NULL\n"); symrec_set_of_data(sym, &yasm_dbg_LTX_objfmt, NULL); @@ -153,8 +148,7 @@ dbg_objfmt_common_declare(symrec *sym, /*@only@*/ expr *size, /*@unused@*/ /*@null@*/ valparamhead *objext_valparams) { assert(dbg_objfmt_file != NULL); - fprintf(dbg_objfmt_file, "%*scommon_declare(\"%s\", ", indent_level, "", - symrec_get_name(sym)); + fprintf(dbg_objfmt_file, "common_declare(\"%s\", ", symrec_get_name(sym)); expr_print(dbg_objfmt_file, size); fprintf(dbg_objfmt_file, ", "); vps_print(dbg_objfmt_file, objext_valparams); @@ -167,7 +161,7 @@ dbg_objfmt_common_declare(symrec *sym, /*@only@*/ expr *size, /*@unused@*/ static void dbg_objfmt_symrec_data_delete(/*@only@*/ void *data) { - fprintf(dbg_objfmt_file, "%*ssymrec_data_delete(", indent_level, ""); + fprintf(dbg_objfmt_file, "symrec_data_delete("); if (data) { expr_print(dbg_objfmt_file, data); expr_delete(data); @@ -176,7 +170,7 @@ dbg_objfmt_symrec_data_delete(/*@only@*/ void *data) } static void -dbg_objfmt_symrec_data_print(FILE *f, /*@null@*/ void *data) +dbg_objfmt_symrec_data_print(FILE *f, int indent_level, /*@null@*/ void *data) { if (data) { fprintf(f, "%*sSize=", indent_level, ""); @@ -192,7 +186,7 @@ dbg_objfmt_directive(const char *name, valparamhead *valparams, /*@null@*/ valparamhead *objext_valparams, /*@unused@*/ sectionhead *headp) { - fprintf(dbg_objfmt_file, "%*sdirective(\"%s\", ", indent_level, "", name); + fprintf(dbg_objfmt_file, "directive(\"%s\", ", name); vps_print(dbg_objfmt_file, valparams); fprintf(dbg_objfmt_file, ", "); vps_print(dbg_objfmt_file, objext_valparams); @@ -203,13 +197,13 @@ dbg_objfmt_directive(const char *name, valparamhead *valparams, static void dbg_objfmt_bc_objfmt_data_delete(unsigned int type, /*@only@*/ void *data) { - fprintf(dbg_objfmt_file, "%*ssymrec_data_delete(%u, %p)\n", indent_level, - "", type, data); + fprintf(dbg_objfmt_file, "symrec_data_delete(%u, %p)\n", type, data); xfree(data); } static void -dbg_objfmt_bc_objfmt_data_print(FILE *f, unsigned int type, const void *data) +dbg_objfmt_bc_objfmt_data_print(FILE *f, int indent_level, unsigned int type, + const void *data) { fprintf(f, "%*sType=%u\n", indent_level, "", type); fprintf(f, "%*sData=%p\n", indent_level, "", data); diff --git a/src/arch.c b/src/arch.c index 4242ce30..bf46b3c0 100644 --- a/src/arch.c +++ b/src/arch.c @@ -99,7 +99,7 @@ operand_new_imm(/*@only@*/ expr *val) } void -operand_print(FILE *f, const insn_operand *op) +operand_print(FILE *f, int indent_level, const insn_operand *op) { switch (op->type) { case INSN_OPERAND_REG: @@ -114,9 +114,7 @@ operand_print(FILE *f, const insn_operand *op) break; case INSN_OPERAND_MEMORY: fprintf(f, "%*sMemory=\n", indent_level, ""); - indent_level++; - ea_print(f, op->data.ea); - indent_level--; + ea_print(f, indent_level, op->data.ea); break; case INSN_OPERAND_IMM: fprintf(f, "%*sImm=", indent_level, ""); @@ -164,10 +162,10 @@ ops_append(insn_operandhead *headp, /*@returned@*/ /*@null@*/ insn_operand *op) } void -ops_print(FILE *f, const insn_operandhead *headp) +ops_print(FILE *f, int indent_level, const insn_operandhead *headp) { insn_operand *cur; STAILQ_FOREACH (cur, headp, link) - operand_print(f, cur); + operand_print(f, indent_level, cur); } diff --git a/src/arch.h b/src/arch.h index 3e0295ed..02f93db6 100644 --- a/src/arch.h +++ b/src/arch.h @@ -129,7 +129,7 @@ struct arch { const int type_max; void (*bc_delete) (bytecode *bc); - void (*bc_print) (FILE *f, const bytecode *bc); + void (*bc_print) (FILE *f, int indent_level, const bytecode *bc); /* See bytecode.h comments on bc_resolve() */ bc_resolve_flags (*bc_resolve) (bytecode *bc, int save, @@ -166,7 +166,7 @@ struct arch { */ void (*ea_data_delete) (effaddr *ea); - void (*ea_data_print) (FILE *f, const effaddr *ea); + void (*ea_data_print) (FILE *f, int indent_level, const effaddr *ea); }; struct insn_operand { @@ -201,7 +201,7 @@ insn_operand *operand_new_segreg(unsigned long segreg); insn_operand *operand_new_mem(/*@only@*/ effaddr *ea); insn_operand *operand_new_imm(/*@only@*/ expr *val); -void operand_print(FILE *f, const insn_operand *op); +void operand_print(FILE *f, int indent_level, const insn_operand *op); #define ops_initialize(headp) STAILQ_INIT(headp) #define ops_first(headp) STAILQ_FIRST(headp) @@ -221,6 +221,6 @@ void ops_delete(insn_operandhead *headp, int content); /*@null@*/ insn_operand *ops_append(insn_operandhead *headp, /*@returned@*/ /*@null@*/ insn_operand *op); -void ops_print(FILE *f, const insn_operandhead *headp); +void ops_print(FILE *f, int indent_level, const insn_operandhead *headp); #endif diff --git a/src/arch/x86/x86arch.h b/src/arch/x86/x86arch.h index 48c026df..824912b0 100644 --- a/src/arch/x86/x86arch.h +++ b/src/arch/x86/x86arch.h @@ -115,7 +115,7 @@ bytecode *x86_bc_new_jmprel(x86_new_jmprel_data *d); extern unsigned char yasm_x86_LTX_mode_bits; void x86_bc_delete(bytecode *bc); -void x86_bc_print(FILE *f, const bytecode *bc); +void x86_bc_print(FILE *f, int indent_level, const bytecode *bc); bc_resolve_flags x86_bc_resolve(bytecode *bc, int save, const section *sect, calc_bc_dist_func calc_bc_dist); int x86_bc_tobytes(bytecode *bc, unsigned char **bufp, const section *sect, @@ -161,6 +161,6 @@ void x86_reg_print(FILE *f, unsigned long reg); void x86_segreg_print(FILE *f, unsigned long segreg); -void x86_ea_data_print(FILE *f, const effaddr *ea); +void x86_ea_data_print(FILE *f, int indent_level, const effaddr *ea); #endif diff --git a/src/arch/x86/x86bc.c b/src/arch/x86/x86bc.c index bf65ec64..d6aa652c 100644 --- a/src/arch/x86/x86bc.c +++ b/src/arch/x86/x86bc.c @@ -412,7 +412,7 @@ x86_bc_delete(bytecode *bc) } void -x86_ea_data_print(FILE *f, const effaddr *ea) +x86_ea_data_print(FILE *f, int indent_level, const effaddr *ea) { const x86_effaddr *x86_ea = (const x86_effaddr *)ea; fprintf(f, "%*sSegmentOv=%02x\n", indent_level, "", @@ -426,7 +426,7 @@ x86_ea_data_print(FILE *f, const effaddr *ea) } void -x86_bc_print(FILE *f, const bytecode *bc) +x86_bc_print(FILE *f, int indent_level, const bytecode *bc) { const x86_insn *insn; const x86_jmprel *jmprel; @@ -438,9 +438,7 @@ x86_bc_print(FILE *f, const bytecode *bc) fprintf(f, "%*sEffective Address:", indent_level, ""); if (insn->ea) { fprintf(f, "\n"); - indent_level++; - ea_print(f, (effaddr *)insn->ea); - indent_level--; + ea_print(f, indent_level+1, (effaddr *)insn->ea); } else fprintf(f, " (nil)\n"); fprintf(f, "%*sImmediate Value:", indent_level, ""); @@ -481,29 +479,25 @@ x86_bc_print(FILE *f, const bytecode *bc) fprintf(f, "%*sTarget=", indent_level, ""); expr_print(f, jmprel->target); fprintf(f, "\n%*sShort Form:\n", indent_level, ""); - indent_level++; if (jmprel->shortop.opcode_len == 0) - fprintf(f, "%*sNone\n", indent_level, ""); + fprintf(f, "%*sNone\n", indent_level+1, ""); else fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n", - indent_level, "", + indent_level+1, "", (unsigned int)jmprel->shortop.opcode[0], (unsigned int)jmprel->shortop.opcode[1], (unsigned int)jmprel->shortop.opcode[2], (unsigned int)jmprel->shortop.opcode_len); - indent_level--; fprintf(f, "%*sNear Form:\n", indent_level, ""); - indent_level++; if (jmprel->nearop.opcode_len == 0) - fprintf(f, "%*sNone\n", indent_level, ""); + fprintf(f, "%*sNone\n", indent_level+1, ""); else fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n", - indent_level, "", + indent_level+1, "", (unsigned int)jmprel->nearop.opcode[0], (unsigned int)jmprel->nearop.opcode[1], (unsigned int)jmprel->nearop.opcode[2], (unsigned int)jmprel->nearop.opcode_len); - indent_level--; fprintf(f, "%*sOpSel=", indent_level, ""); switch (jmprel->op_sel) { case JR_NONE: diff --git a/src/bytecode.c b/src/bytecode.c index 8c210367..0aedd6d0 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -164,14 +164,14 @@ ea_delete(effaddr *ea) /*@-nullstate@*/ void -ea_print(FILE *f, const effaddr *ea) +ea_print(FILE *f, int indent_level, const effaddr *ea) { fprintf(f, "%*sDisp=", indent_level, ""); expr_print(f, ea->disp); fprintf(f, "\n%*sLen=%u\n", indent_level, "", (unsigned int)ea->len); fprintf(f, "%*sNoSplit=%u\n", indent_level, "", (unsigned int)ea->nosplit); if (cur_arch->ea_data_print) - cur_arch->ea_data_print(f, ea); + cur_arch->ea_data_print(f, indent_level, ea); } /*@=nullstate@*/ @@ -339,7 +339,7 @@ bc_delete(bytecode *bc) } void -bc_print(FILE *f, const bytecode *bc) +bc_print(FILE *f, int indent_level, const bytecode *bc) { const bytecode_data *data; const bytecode_reserve *reserve; @@ -356,13 +356,10 @@ bc_print(FILE *f, const bytecode *bc) case BC_DATA: data = (const bytecode_data *)bc; fprintf(f, "%*s_Data_\n", indent_level, ""); - indent_level++; - fprintf(f, "%*sFinal Element Size=%u\n", indent_level, "", + fprintf(f, "%*sFinal Element Size=%u\n", indent_level+1, "", (unsigned int)data->size); - fprintf(f, "%*sElements:\n", indent_level, ""); - indent_level++; - dvs_print(f, &data->datahead); - indent_level-=2; + fprintf(f, "%*sElements:\n", indent_level+1, ""); + dvs_print(f, indent_level+2, &data->datahead); break; case BC_RESERVE: reserve = (const bytecode_reserve *)bc; @@ -398,14 +395,15 @@ bc_print(FILE *f, const bytecode *bc) objfmt_data = (const bytecode_objfmt_data *)bc; fprintf(f, "%*s_ObjFmt_Data_\n", indent_level, ""); if (objfmt_data->of->bc_objfmt_data_print) - objfmt_data->of->bc_objfmt_data_print(f, objfmt_data->type, + objfmt_data->of->bc_objfmt_data_print(f, indent_level, + objfmt_data->type, objfmt_data->data); else fprintf(f, "%*sUNKNOWN\n", indent_level, ""); break; default: if (bc->type < cur_arch->bc.type_max) - cur_arch->bc.bc_print(f, bc); + cur_arch->bc.bc_print(f, indent_level, bc); else fprintf(f, "%*s_Unknown_\n", indent_level, ""); break; @@ -863,15 +861,13 @@ bcs_append(bytecodehead *headp, bytecode *bc) } void -bcs_print(FILE *f, const bytecodehead *headp) +bcs_print(FILE *f, int indent_level, const bytecodehead *headp) { bytecode *cur; STAILQ_FOREACH(cur, headp, link) { fprintf(f, "%*sNext Bytecode:\n", indent_level, ""); - indent_level++; - bc_print(f, cur); - indent_level--; + bc_print(f, indent_level+1, cur); } } @@ -946,7 +942,7 @@ dvs_append(datavalhead *headp, dataval *dv) } void -dvs_print(FILE *f, const datavalhead *head) +dvs_print(FILE *f, int indent_level, const datavalhead *head) { dataval *cur; diff --git a/src/bytecode.h b/src/bytecode.h index 128ec04b..6ad5bb38 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -49,7 +49,7 @@ void bc_initialize(arch *a); void ea_set_len(effaddr *ea, unsigned char len); void ea_set_nosplit(effaddr *ea, unsigned char nosplit); void ea_delete(/*@only@*/ effaddr *ea); -void ea_print(FILE *f, const effaddr *ea); +void ea_print(FILE *f, int indent_level, const effaddr *ea); void bc_set_multiple(bytecode *bc, /*@keep@*/ expr *e); @@ -66,7 +66,7 @@ void bc_set_multiple(bytecode *bc, /*@keep@*/ expr *e); void bc_delete(/*@only@*/ /*@null@*/ bytecode *bc); -void bc_print(FILE *f, const bytecode *bc); +void bc_print(FILE *f, int indent_level, const bytecode *bc); /* A common version of a calc_bc_dist function that should work for the final * stages of optimizers as well as in objfmt expr output functions. It takes @@ -146,7 +146,7 @@ void bcs_delete(bytecodehead *headp); /*@returned@*/ /*@only@*/ /*@null@*/ bytecode *bc); -void bcs_print(FILE *f, const bytecodehead *headp); +void bcs_print(FILE *f, int indent_level, const bytecodehead *headp); /* Calls func for each bytecode in the linked list of bytecodes pointed to by * headp. The data pointer d is passed to each func call. @@ -175,6 +175,6 @@ void dvs_delete(datavalhead *headp); /*@null@*/ dataval *dvs_append(datavalhead *headp, /*@returned@*/ /*@null@*/ dataval *dv); -void dvs_print(FILE *f, const datavalhead *head); +void dvs_print(FILE *f, int indent_level, const datavalhead *head); #endif diff --git a/src/globals.c b/src/globals.c index 6955051e..61763af5 100644 --- a/src/globals.c +++ b/src/globals.c @@ -57,9 +57,6 @@ static /*@only@*/ /*@null@*/ line_index_mapping_head *line_index_map = NULL; /* Global assembler options. */ unsigned int asm_options = 0; -/* Indentation level for assembler *_print() routines */ -int indent_level = 0; - static void filename_delete_one(/*@only@*/ void *d) { diff --git a/src/globals.h b/src/globals.h index 00cc28df..a38ed352 100644 --- a/src/globals.h +++ b/src/globals.h @@ -28,9 +28,6 @@ extern unsigned long line_index; /* Global assembler options. */ extern unsigned int asm_options; -/* Indentation level for assembler *_print() routines */ -extern int indent_level; - void line_set(const char *filename, unsigned long line, unsigned long line_inc); void line_shutdown(void); diff --git a/src/linemgr.c b/src/linemgr.c index 6955051e..61763af5 100644 --- a/src/linemgr.c +++ b/src/linemgr.c @@ -57,9 +57,6 @@ static /*@only@*/ /*@null@*/ line_index_mapping_head *line_index_map = NULL; /* Global assembler options. */ unsigned int asm_options = 0; -/* Indentation level for assembler *_print() routines */ -int indent_level = 0; - static void filename_delete_one(/*@only@*/ void *d) { diff --git a/src/linemgr.h b/src/linemgr.h index 00cc28df..a38ed352 100644 --- a/src/linemgr.h +++ b/src/linemgr.h @@ -28,9 +28,6 @@ extern unsigned long line_index; /* Global assembler options. */ extern unsigned int asm_options; -/* Indentation level for assembler *_print() routines */ -extern int indent_level; - void line_set(const char *filename, unsigned long line, unsigned long line_inc); void line_shutdown(void); diff --git a/src/objfmt.h b/src/objfmt.h index b2e29ad5..24f9b935 100644 --- a/src/objfmt.h +++ b/src/objfmt.h @@ -82,7 +82,7 @@ struct objfmt { * May be NULL if no data is ever allocated in sections_switch(). */ void (*section_data_delete)(/*@only@*/ void *data); - void (*section_data_print)(FILE *f, void *data); + void (*section_data_print)(FILE *f, int indent_level, void *data); /* These functions should call symrec_set_of_data() to store data. * May be NULL if objfmt doesn't care about such declarations. @@ -96,7 +96,7 @@ struct objfmt { /* May be NULL if symrec_set_of_data() is never called. */ void (*symrec_data_delete)(/*@only@*/ void *data); - void (*symrec_data_print)(FILE *f, void *data); + void (*symrec_data_print)(FILE *f, int indent_level, void *data); /* Object format-specific directive support. Returns 1 if directive was * not recognized. Returns 0 if directive was recognized, even if it @@ -110,7 +110,8 @@ struct objfmt { * May be NULL if no BC_OBJFMT_DATA is ever allocated by the object format. */ void (*bc_objfmt_data_delete)(unsigned int type, /*@only@*/ void *data); - void (*bc_objfmt_data_print)(FILE *f, unsigned int type, const void *data); + void (*bc_objfmt_data_print)(FILE *f, int indent_level, unsigned int type, + const void *data); }; /* Generic functions for all object formats - implemented in src/objfmt.c */ diff --git a/src/objfmts/bin/bin-objfmt.c b/src/objfmts/bin/bin-objfmt.c index 15b70dce..2e5f0ed9 100644 --- a/src/objfmts/bin/bin-objfmt.c +++ b/src/objfmts/bin/bin-objfmt.c @@ -448,7 +448,7 @@ bin_objfmt_directive(const char *name, valparamhead *valparams, } static void -bin_objfmt_section_data_print(FILE *f, void *data) +bin_objfmt_section_data_print(FILE *f, int indent_level, void *data) { fprintf(f, "%*salign=%ld\n", indent_level, "", *((unsigned long *)data)); } diff --git a/src/objfmts/coff/coff-objfmt.c b/src/objfmts/coff/coff-objfmt.c index a85068fa..135d46fb 100644 --- a/src/objfmts/coff/coff-objfmt.c +++ b/src/objfmts/coff/coff-objfmt.c @@ -778,16 +778,14 @@ coff_objfmt_section_data_delete(/*@only@*/ void *data) } static void -coff_objfmt_section_data_print(FILE *f, void *data) +coff_objfmt_section_data_print(FILE *f, int indent_level, void *data) { coff_section_data *csd = (coff_section_data *)data; coff_reloc *reloc; unsigned long relocnum = 0; fprintf(f, "%*ssym=\n", indent_level, ""); - indent_level++; - symrec_print(f, csd->sym); - indent_level--; + symrec_print(f, indent_level+1, csd->sym); fprintf(f, "%*sscnum=%d\n", indent_level, "", csd->scnum); fprintf(f, "%*sflags=", indent_level, ""); switch (csd->flags) { @@ -810,15 +808,11 @@ coff_objfmt_section_data_print(FILE *f, void *data) fprintf(f, "%*srelptr=0x%lx\n", indent_level, "", csd->relptr); fprintf(f, "%*snreloc=%ld\n", indent_level, "", csd->nreloc); fprintf(f, "%*srelocs:\n", indent_level, ""); - indent_level++; STAILQ_FOREACH(reloc, &csd->relocs, link) { - fprintf(f, "%*sReloc %lu:\n", indent_level, "", relocnum++); - indent_level++; - fprintf(f, "%*ssym=\n", indent_level, ""); - indent_level++; - symrec_print(f, reloc->sym); - indent_level--; - fprintf(f, "%*stype=", indent_level, ""); + fprintf(f, "%*sReloc %lu:\n", indent_level+1, "", relocnum++); + fprintf(f, "%*ssym=\n", indent_level+2, ""); + symrec_print(f, indent_level+3, reloc->sym); + fprintf(f, "%*stype=", indent_level+2, ""); switch (reloc->type) { case COFF_RELOC_ADDR32: printf("Addr32\n"); @@ -827,9 +821,7 @@ coff_objfmt_section_data_print(FILE *f, void *data) printf("Rel32\n"); break; } - indent_level--; } - indent_level--; } static void @@ -858,7 +850,7 @@ coff_objfmt_symrec_data_delete(/*@only@*/ void *data) } static void -coff_objfmt_symrec_data_print(FILE *f, void *data) +coff_objfmt_symrec_data_print(FILE *f, int indent_level, void *data) { coff_symrec_data *csd = (coff_symrec_data *)data; diff --git a/src/objfmts/dbg/dbg-objfmt.c b/src/objfmts/dbg/dbg-objfmt.c index 7cc5f16d..a50d5f49 100644 --- a/src/objfmts/dbg/dbg-objfmt.c +++ b/src/objfmts/dbg/dbg-objfmt.c @@ -53,31 +53,29 @@ dbg_objfmt_initialize(const char *in_filename, const char *obj_filename, dbgfmt *df, arch *a) { dbg_objfmt_file = fopen(obj_filename, "wt"); - if (!dbg_objfmt_file) + if (!dbg_objfmt_file) { ErrorNow(_("could not open file `%s'"), obj_filename); + return; + } fprintf(dbg_objfmt_file, - "%*sinitialize(\"%s\", \"%s\", %s dbgfmt, %s arch)\n", indent_level, - "", in_filename, obj_filename, df->keyword, a->keyword); + "initialize(\"%s\", \"%s\", %s dbgfmt, %s arch)\n", + in_filename, obj_filename, df->keyword, a->keyword); } static void dbg_objfmt_output(/*@unused@*/ FILE *f, sectionhead *sections) { - fprintf(dbg_objfmt_file, "%*soutput(f, sections->\n", indent_level, ""); - indent_level++; - sections_print(dbg_objfmt_file, sections); - indent_level--; - fprintf(dbg_objfmt_file, "%*s)\n", indent_level, ""); - indent_level++; - fprintf(dbg_objfmt_file, "%*sSymbol Table:\n", indent_level, ""); - symrec_print_all(dbg_objfmt_file); - indent_level--; + fprintf(dbg_objfmt_file, "output(f, sections->\n"); + sections_print(dbg_objfmt_file, 1, sections); + fprintf(dbg_objfmt_file, ")\n"); + fprintf(dbg_objfmt_file, " Symbol Table:\n"); + symrec_print_all(dbg_objfmt_file, 1); } static void dbg_objfmt_cleanup(void) { - fprintf(dbg_objfmt_file, "%*scleanup()\n", indent_level, ""); + fprintf(dbg_objfmt_file, "cleanup()\n"); } static /*@observer@*/ /*@null@*/ section * @@ -89,7 +87,7 @@ dbg_objfmt_sections_switch(sectionhead *headp, valparamhead *valparams, section *retval; int isnew; - fprintf(dbg_objfmt_file, "%*ssections_switch(headp, ", indent_level, ""); + fprintf(dbg_objfmt_file, "sections_switch(headp, "); vps_print(dbg_objfmt_file, valparams); fprintf(dbg_objfmt_file, ", "); vps_print(dbg_objfmt_file, objext_valparams); @@ -112,13 +110,12 @@ dbg_objfmt_sections_switch(sectionhead *headp, valparamhead *valparams, static void dbg_objfmt_section_data_delete(/*@only@*/ void *data) { - fprintf(dbg_objfmt_file, "%*ssection_data_delete(%p)\n", indent_level, "", - data); + fprintf(dbg_objfmt_file, "section_data_delete(%p)\n", data); xfree(data); } static void -dbg_objfmt_section_data_print(FILE *f, /*@null@*/ void *data) +dbg_objfmt_section_data_print(FILE *f, int indent_level, /*@null@*/ void *data) { if (data) fprintf(f, "%*s%p\n", indent_level, "", data); @@ -130,8 +127,7 @@ static void dbg_objfmt_extern_declare(symrec *sym, /*@unused@*/ /*@null@*/ valparamhead *objext_valparams) { - fprintf(dbg_objfmt_file, "%*sextern_declare(\"%s\", ", indent_level, "", - symrec_get_name(sym)); + fprintf(dbg_objfmt_file, "extern_declare(\"%s\", ", symrec_get_name(sym)); vps_print(dbg_objfmt_file, objext_valparams); fprintf(dbg_objfmt_file, "), setting of_data=NULL\n"); symrec_set_of_data(sym, &yasm_dbg_LTX_objfmt, NULL); @@ -141,8 +137,7 @@ static void dbg_objfmt_global_declare(symrec *sym, /*@unused@*/ /*@null@*/ valparamhead *objext_valparams) { - fprintf(dbg_objfmt_file, "%*sglobal_declare(\"%s\", ", indent_level, "", - symrec_get_name(sym)); + fprintf(dbg_objfmt_file, "global_declare(\"%s\", ", symrec_get_name(sym)); vps_print(dbg_objfmt_file, objext_valparams); fprintf(dbg_objfmt_file, "), setting of_data=NULL\n"); symrec_set_of_data(sym, &yasm_dbg_LTX_objfmt, NULL); @@ -153,8 +148,7 @@ dbg_objfmt_common_declare(symrec *sym, /*@only@*/ expr *size, /*@unused@*/ /*@null@*/ valparamhead *objext_valparams) { assert(dbg_objfmt_file != NULL); - fprintf(dbg_objfmt_file, "%*scommon_declare(\"%s\", ", indent_level, "", - symrec_get_name(sym)); + fprintf(dbg_objfmt_file, "common_declare(\"%s\", ", symrec_get_name(sym)); expr_print(dbg_objfmt_file, size); fprintf(dbg_objfmt_file, ", "); vps_print(dbg_objfmt_file, objext_valparams); @@ -167,7 +161,7 @@ dbg_objfmt_common_declare(symrec *sym, /*@only@*/ expr *size, /*@unused@*/ static void dbg_objfmt_symrec_data_delete(/*@only@*/ void *data) { - fprintf(dbg_objfmt_file, "%*ssymrec_data_delete(", indent_level, ""); + fprintf(dbg_objfmt_file, "symrec_data_delete("); if (data) { expr_print(dbg_objfmt_file, data); expr_delete(data); @@ -176,7 +170,7 @@ dbg_objfmt_symrec_data_delete(/*@only@*/ void *data) } static void -dbg_objfmt_symrec_data_print(FILE *f, /*@null@*/ void *data) +dbg_objfmt_symrec_data_print(FILE *f, int indent_level, /*@null@*/ void *data) { if (data) { fprintf(f, "%*sSize=", indent_level, ""); @@ -192,7 +186,7 @@ dbg_objfmt_directive(const char *name, valparamhead *valparams, /*@null@*/ valparamhead *objext_valparams, /*@unused@*/ sectionhead *headp) { - fprintf(dbg_objfmt_file, "%*sdirective(\"%s\", ", indent_level, "", name); + fprintf(dbg_objfmt_file, "directive(\"%s\", ", name); vps_print(dbg_objfmt_file, valparams); fprintf(dbg_objfmt_file, ", "); vps_print(dbg_objfmt_file, objext_valparams); @@ -203,13 +197,13 @@ dbg_objfmt_directive(const char *name, valparamhead *valparams, static void dbg_objfmt_bc_objfmt_data_delete(unsigned int type, /*@only@*/ void *data) { - fprintf(dbg_objfmt_file, "%*ssymrec_data_delete(%u, %p)\n", indent_level, - "", type, data); + fprintf(dbg_objfmt_file, "symrec_data_delete(%u, %p)\n", type, data); xfree(data); } static void -dbg_objfmt_bc_objfmt_data_print(FILE *f, unsigned int type, const void *data) +dbg_objfmt_bc_objfmt_data_print(FILE *f, int indent_level, unsigned int type, + const void *data) { fprintf(f, "%*sType=%u\n", indent_level, "", type); fprintf(f, "%*sData=%p\n", indent_level, "", data); diff --git a/src/section.c b/src/section.c index dd7cdb19..88d10fff 100644 --- a/src/section.c +++ b/src/section.c @@ -206,15 +206,13 @@ sections_delete(sectionhead *headp) } void -sections_print(FILE *f, const sectionhead *headp) +sections_print(FILE *f, int indent_level, const sectionhead *headp) { section *cur; STAILQ_FOREACH(cur, headp, link) { fprintf(f, "%*sSection:\n", indent_level, ""); - indent_level++; - section_print(f, cur, 1); - indent_level--; + section_print(f, indent_level+1, cur, 1); } } @@ -296,7 +294,7 @@ section_delete(section *sect) } void -section_print(FILE *f, const section *sect, int print_bcs) +section_print(FILE *f, int indent_level, const section *sect, int print_bcs) { if (!sect) { fprintf(f, "%*s(none)\n", indent_level, ""); @@ -312,7 +310,8 @@ section_print(FILE *f, const section *sect, int print_bcs) if (sect->data.general.of_data && sect->data.general.of) { objfmt *of = sect->data.general.of; if (of->section_data_print) - of->section_data_print(f, sect->data.general.of_data); + of->section_data_print(f, indent_level, + sect->data.general.of_data); else fprintf(f, "%*sUNKNOWN\n", indent_level, ""); } else @@ -330,8 +329,6 @@ section_print(FILE *f, const section *sect, int print_bcs) if (print_bcs) { fprintf(f, "%*sBytecodes:\n", indent_level, ""); - indent_level++; - bcs_print(f, §->bc); - indent_level--; + bcs_print(f, indent_level+1, §->bc); } } diff --git a/src/section.h b/src/section.h index 20776a8c..7645e40c 100644 --- a/src/section.h +++ b/src/section.h @@ -45,7 +45,7 @@ void section_set_of_data(section *sect, objfmt *of, void sections_delete(sectionhead *headp); -void sections_print(FILE *f, const sectionhead *headp); +void sections_print(FILE *f, int indent_level, const sectionhead *headp); /* Calls func for each section in the linked list of sections pointed to by * headp. The data pointer d is passed to each func call. @@ -68,5 +68,6 @@ void section_set_start(section *sect, unsigned long start); void section_delete(/*@only@*/ section *sect); -void section_print(FILE *f, /*@null@*/ const section *sect, int print_bcs); +void section_print(FILE *f, int indent_level, /*@null@*/ const section *sect, + int print_bcs); #endif diff --git a/src/symrec.c b/src/symrec.c index 6efb7dba..876c1c32 100644 --- a/src/symrec.c +++ b/src/symrec.c @@ -360,29 +360,34 @@ symrec_delete_all(void) } } +typedef struct symrec_print_data { + FILE *f; + int indent_level; +} symrec_print_data; + /*@+voidabstract@*/ static int symrec_print_wrapper(symrec *sym, /*@null@*/ void *d) { - FILE *f; - assert(d != NULL); - f = (FILE *)d; - fprintf(f, "%*sSymbol `%s'\n", indent_level, "", sym->name); - indent_level++; - symrec_print(f, sym); - indent_level--; + symrec_print_data *data = (symrec_print_data *)d; + assert(data != NULL); + fprintf(data->f, "%*sSymbol `%s'\n", data->indent_level, "", sym->name); + symrec_print(data->f, data->indent_level+1, sym); return 1; } void -symrec_print_all(FILE *f) +symrec_print_all(FILE *f, int indent_level) { - symrec_traverse(f, symrec_print_wrapper); + symrec_print_data data; + data.f = f; + data.indent_level = indent_level; + symrec_traverse(&data, symrec_print_wrapper); } /*@=voidabstract@*/ void -symrec_print(FILE *f, const symrec *sym) +symrec_print(FILE *f, int indent_level, const symrec *sym) { const char *filename; unsigned long line; @@ -400,16 +405,12 @@ symrec_print(FILE *f, const symrec *sym) case SYM_LABEL: fprintf(f, "%*s_Label_\n%*sSection:\n", indent_level, "", indent_level, ""); - indent_level++; - section_print(f, sym->value.label.sect, 0); - indent_level--; + section_print(f, indent_level+1, sym->value.label.sect, 0); if (!sym->value.label.bc) fprintf(f, "%*sFirst bytecode\n", indent_level, ""); else { fprintf(f, "%*sPreceding bytecode:\n", indent_level, ""); - indent_level++; - bc_print(f, sym->value.label.bc); - indent_level--; + bc_print(f, indent_level+1, sym->value.label.bc); } break; } @@ -444,12 +445,10 @@ symrec_print(FILE *f, const symrec *sym) if (sym->of_data && sym->of) { fprintf(f, "%*sObject format-specific data:\n", indent_level, ""); - indent_level++; if (sym->of->symrec_data_print) - sym->of->symrec_data_print(f, sym->of_data); + sym->of->symrec_data_print(f, indent_level+1, sym->of_data); else - fprintf(f, "%*sUNKNOWN\n", indent_level, ""); - indent_level--; + fprintf(f, "%*sUNKNOWN\n", indent_level+1, ""); } line_lookup(sym->line, &filename, &line); diff --git a/src/symrec.h b/src/symrec.h index 5a4f0063..49ac2b91 100644 --- a/src/symrec.h +++ b/src/symrec.h @@ -64,7 +64,7 @@ void symrec_parser_finalize(void); void symrec_delete_all(void); -void symrec_print_all(FILE *f); +void symrec_print_all(FILE *f, int indent_level); -void symrec_print(FILE *f, const symrec *sym); +void symrec_print(FILE *f, int indent_level, const symrec *sym); #endif -- 2.40.0