1/* This file is debug.c
2   Copyright 1987, 1988, 1989, 1990, 1991, 1992, 2000, 2006
3   Free Software Foundation, Inc.
4
5   This file is part of GAS, the GNU Assembler.
6
7   GAS is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12   GAS is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with GAS; see the file COPYING.  If not, write to
19   the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
20
21/* Routines for debug use only.  */
22
23#include "as.h"
24#include "subsegs.h"
25
26dmp_frags ()
27{
28  asection *s;
29  frchainS *chp;
30  char *p;
31
32  for (s = stdoutput->sections; s; s = s->next)
33    for (chp = seg_info (s)->frchainP; chp; chp = chp->frch_next)
34      {
35	switch (s)
36	  {
37	  case SEG_DATA:
38	    p = "Data";
39	    break;
40	  case SEG_TEXT:
41	    p = "Text";
42	    break;
43	  default:
44	    p = "???";
45	    break;
46	  }
47	printf ("\nSEGMENT %s %d\n", p, chp->frch_subseg);
48	dmp_frag (chp->frch_root, "\t");
49      }
50}
51
52dmp_frag (fp, indent)
53     struct frag *fp;
54     char *indent;
55{
56  for (; fp; fp = fp->fr_next)
57    {
58      printf ("%sFRAGMENT @ 0x%x\n", indent, fp);
59      switch (fp->fr_type)
60	{
61	case rs_align:
62	  printf ("%srs_align(%d)\n", indent, fp->fr_offset);
63	  break;
64	case rs_fill:
65	  printf ("%srs_fill(%d)\n", indent, fp->fr_offset);
66	  printf ("%s", indent);
67	  var_chars (fp, fp->fr_var + fp->fr_fix);
68	  printf ("%s\t repeated %d times,", indent, fp->fr_offset);
69	  printf (" fixed length if # chars == 0)\n");
70	  break;
71	case rs_org:
72	  printf ("%srs_org(%d+sym @0x%x)\n", indent,
73		  fp->fr_offset, fp->fr_symbol);
74	  printf ("%sfill with ", indent);
75	  var_chars (fp, 1);
76	  printf ("\n");
77	  break;
78	case rs_machine_dependent:
79	  printf ("%smachine_dep\n", indent);
80	  break;
81	default:
82	  printf ("%sunknown type\n", indent);
83	  break;
84	}
85      printf ("%saddr=%d(0x%x)\n", indent, fp->fr_address, fp->fr_address);
86      printf ("%sfr_fix=%d\n", indent, fp->fr_fix);
87      printf ("%sfr_var=%d\n", indent, fp->fr_var);
88      printf ("%sfr_offset=%d\n", indent, fp->fr_offset);
89      printf ("%schars @ 0x%x\n", indent, fp->fr_literal);
90      printf ("\n");
91    }
92}
93
94var_chars (fp, n)
95     struct frag *fp;
96     int n;
97{
98  unsigned char *p;
99
100  for (p = (unsigned char *) fp->fr_literal; n; n--, p++)
101    {
102      printf ("%02x ", *p);
103    }
104}
105
106/* end of debug.c */
107