]> granicus.if.org Git - yasm/commitdiff
Remove indent_level global by passing it as a parameter.
authorPeter Johnson <peter@tortall.net>
Sat, 26 Oct 2002 19:50:08 +0000 (19:50 -0000)
committerPeter Johnson <peter@tortall.net>
Sat, 26 Oct 2002 19:50:08 +0000 (19:50 -0000)
svn path=/trunk/yasm/; revision=786

34 files changed:
libyasm/arch.c
libyasm/arch.h
libyasm/bytecode.c
libyasm/bytecode.h
libyasm/linemgr.c
libyasm/linemgr.h
libyasm/objfmt.h
libyasm/section.c
libyasm/section.h
libyasm/symrec.c
libyasm/symrec.h
modules/arch/x86/x86arch.h
modules/arch/x86/x86bc.c
modules/objfmts/bin/bin-objfmt.c
modules/objfmts/coff/coff-objfmt.c
modules/objfmts/dbg/dbg-objfmt.c
src/arch.c
src/arch.h
src/arch/x86/x86arch.h
src/arch/x86/x86bc.c
src/bytecode.c
src/bytecode.h
src/globals.c
src/globals.h
src/linemgr.c
src/linemgr.h
src/objfmt.h
src/objfmts/bin/bin-objfmt.c
src/objfmts/coff/coff-objfmt.c
src/objfmts/dbg/dbg-objfmt.c
src/section.c
src/section.h
src/symrec.c
src/symrec.h

index 4242ce30fdacbdf0fe6e905aa98365c209371cdb..bf46b3c050d9829900daf22fd341664dc872046a 100644 (file)
@@ -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);
 }
index 3e0295ed05e4966f6fa53df46c28a3b17879b3fb..02f93db6fe1137c3b392d97a3fed24df7aae1be4 100644 (file)
@@ -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
index 8c2103675cd040a5a84a359d83c5faa2748dde15..0aedd6d076cb0bc82c26d1522119b47096007b68 100644 (file)
@@ -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;
 
index 128ec04b88345834f9029f0934b959284d069ddc..6ad5bb38d8b41f70ad4accfb3cc12c3d19ed5323 100644 (file)
@@ -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
index 6955051e4ca6f8b0a899d1f360d3b3abf3f150ba..61763af5b85af560b3eafd1c02615ce3f2c6e479 100644 (file)
@@ -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)
 {
index 00cc28dfbea7390815cf8d7e2141205bf843a4f3..a38ed352ad85634d2f4ec23c53f4ea4f2d15724b 100644 (file)
@@ -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);
index b2e29ad58deeb49478433e2ad9a13fb55d16c408..24f9b93596c441e5b1240ba68280fc2f07cd1e8c 100644 (file)
@@ -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 */
index dd7cdb19b079461533cb54b73ebc51e53ef68110..88d10fff3ae4c27411ea5c3af3ca44762cf0c306 100644 (file)
@@ -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, &sect->bc);
-       indent_level--;
+       bcs_print(f, indent_level+1, &sect->bc);
     }
 }
index 20776a8cc3bdfadea5391a6e91c7759f6bd82628..7645e40c494b47d52384400234553468d8219f2c 100644 (file)
@@ -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
index 6efb7dba6066fb1e9f22f221744d25bd1caf6420..876c1c32a28aef5221fa24bc656ae0903f807f73 100644 (file)
@@ -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);
index 5a4f006319b63fe6b3ef72d58c5d1c8567dd064f..49ac2b917f3146b249130d24f381041b66199c18 100644 (file)
@@ -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
index 48c026df63540d0f5eb9ea03c4af428e0293b165..824912b0713bca098105df61c3fe88c04905bd02 100644 (file)
@@ -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
index bf65ec64f684d56de7e112ea4f13368612c1a1c5..d6aa652c3f56577aa57dae7a9592e49ebac30920 100644 (file)
@@ -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:
index 15b70dce32294f7071a8ab881531ed1a2f634e4f..2e5f0ed95c34c78f1276037ca28ec7c11ab02f39 100644 (file)
@@ -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));
 }
index a85068fa11394af64120602e99967e69c67b60ed..135d46fb34a9bcde8fd426d2f343586015ac14c8 100644 (file)
@@ -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;
 
index 7cc5f16db0ed46b083271f094cee42b0b3802d72..a50d5f49b321bbab3152f4b531c714508809ba44 100644 (file)
@@ -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);
index 4242ce30fdacbdf0fe6e905aa98365c209371cdb..bf46b3c050d9829900daf22fd341664dc872046a 100644 (file)
@@ -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);
 }
index 3e0295ed05e4966f6fa53df46c28a3b17879b3fb..02f93db6fe1137c3b392d97a3fed24df7aae1be4 100644 (file)
@@ -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
index 48c026df63540d0f5eb9ea03c4af428e0293b165..824912b0713bca098105df61c3fe88c04905bd02 100644 (file)
@@ -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
index bf65ec64f684d56de7e112ea4f13368612c1a1c5..d6aa652c3f56577aa57dae7a9592e49ebac30920 100644 (file)
@@ -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:
index 8c2103675cd040a5a84a359d83c5faa2748dde15..0aedd6d076cb0bc82c26d1522119b47096007b68 100644 (file)
@@ -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;
 
index 128ec04b88345834f9029f0934b959284d069ddc..6ad5bb38d8b41f70ad4accfb3cc12c3d19ed5323 100644 (file)
@@ -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
index 6955051e4ca6f8b0a899d1f360d3b3abf3f150ba..61763af5b85af560b3eafd1c02615ce3f2c6e479 100644 (file)
@@ -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)
 {
index 00cc28dfbea7390815cf8d7e2141205bf843a4f3..a38ed352ad85634d2f4ec23c53f4ea4f2d15724b 100644 (file)
@@ -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);
index 6955051e4ca6f8b0a899d1f360d3b3abf3f150ba..61763af5b85af560b3eafd1c02615ce3f2c6e479 100644 (file)
@@ -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)
 {
index 00cc28dfbea7390815cf8d7e2141205bf843a4f3..a38ed352ad85634d2f4ec23c53f4ea4f2d15724b 100644 (file)
@@ -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);
index b2e29ad58deeb49478433e2ad9a13fb55d16c408..24f9b93596c441e5b1240ba68280fc2f07cd1e8c 100644 (file)
@@ -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 */
index 15b70dce32294f7071a8ab881531ed1a2f634e4f..2e5f0ed95c34c78f1276037ca28ec7c11ab02f39 100644 (file)
@@ -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));
 }
index a85068fa11394af64120602e99967e69c67b60ed..135d46fb34a9bcde8fd426d2f343586015ac14c8 100644 (file)
@@ -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;
 
index 7cc5f16db0ed46b083271f094cee42b0b3802d72..a50d5f49b321bbab3152f4b531c714508809ba44 100644 (file)
@@ -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);
index dd7cdb19b079461533cb54b73ebc51e53ef68110..88d10fff3ae4c27411ea5c3af3ca44762cf0c306 100644 (file)
@@ -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, &sect->bc);
-       indent_level--;
+       bcs_print(f, indent_level+1, &sect->bc);
     }
 }
index 20776a8cc3bdfadea5391a6e91c7759f6bd82628..7645e40c494b47d52384400234553468d8219f2c 100644 (file)
@@ -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
index 6efb7dba6066fb1e9f22f221744d25bd1caf6420..876c1c32a28aef5221fa24bc656ae0903f807f73 100644 (file)
@@ -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);
index 5a4f006319b63fe6b3ef72d58c5d1c8567dd064f..49ac2b917f3146b249130d24f381041b66199c18 100644 (file)
@@ -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