Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/**********************************************************************
32
$Author: pwe $
33
$Date: 1998/03/15 16:00:34 $
34
$Revision: 1.4 $
35
$Log: dw2_iface.c,v $
36
 * Revision 1.4  1998/03/15  16:00:34  pwe
37
 * regtrack dwarf dagnostics added
38
 *
39
 * Revision 1.3  1998/03/11  11:03:43  pwe
40
 * DWARF optimisation info
41
 *
42
 * Revision 1.2  1998/01/21  10:30:05  pwe
43
 * labdiff change
44
 *
45
 * Revision 1.1.1.1  1998/01/17  15:55:48  release
46
 * First version to be checked into rolling release.
47
 *
48
 * Revision 1.10  1998/01/09  09:31:28  pwe
49
 * prep restructure
50
 *
51
 * Revision 1.9  1997/12/08  16:37:04  pwe
52
 * abbrev key & directory names
53
 *
54
 * Revision 1.8  1997/12/04  19:41:26  pwe
55
 * ANDF-DE V1.9
56
 *
57
 * Revision 1.7  1997/11/06  09:22:07  pwe
58
 * ANDF-DE V1.8
59
 *
60
 * Revision 1.6  1997/10/23  09:27:36  pwe
61
 * ANDF-DE v1.7, extra diags
62
 *
63
 * Revision 1.5  1997/10/10  18:18:32  pwe
64
 * prep ANDF-DE revision
65
 *
66
 * Revision 1.4  1997/08/23  13:36:39  pwe
67
 * initial ANDF-DE
68
 *
69
 * Revision 1.3  1997/04/17  11:50:22  pwe
70
 * Sparc and 80x86 support
71
 *
72
 * Revision 1.2  1997/03/24  11:10:26  pwe
73
 * struct bitfields
74
 *
75
 * Revision 1.1  1997/03/20  16:09:12  pwe
76
 * first version
77
 *
78
**********************************************************************/
79
 
80
#include "config.h"
81
#include "common_types.h"
82
#include "basicread.h"
83
#include "dg_globs.h"
84
#include "tags.h"
85
#include "expmacs.h"
86
#include "dw2_config.h"
87
#include "dw2_iface.h"
88
#include "dw2_types.h"
89
#include "dw2_entries.h"
90
#include "dw2_codes.h"
91
#include "dw2_basic.h"
92
#include "dw2_lines.h"
93
#include "dw2_info.h"
94
#include "dw2_locdata.h"
95
#include "xalloc.h"
96
#include "diagglob.h"
97
 
98
 
99
int dwarf2 = 0;
100
 
101
long dw_info_start;
102
long dw_text_start;
103
 
104
static long statprog_start;	/* compilation unit level label */
105
static long statprog_end;
106
static long text_end;
107
 
108
 
109
void dw_out_path
110
    PROTO_N ( (f, w) )
111
    PROTO_T ( dg_filename f X int w )
112
{
113
  char * com;
114
  if (!w && f->file_path[0] && f->file_path[0] != '/')
115
    dw_at_string (f->file_path);
116
  else {
117
    size_t n = strlen (f->file_path) + strlen (f->file_host) + 2;
118
    if (w)
119
      n += (strlen (f->file_name) + 1);
120
    com = (char *)xmalloc (n);
121
    IGNORE strcat (strcat (strcpy (com, f->file_host), ":"), f->file_path);
122
    if (w) {
123
      if (f->file_path[0] != '/')
124
	IGNORE strcpy (com, f->file_path);
125
      IGNORE strcat (strcat (com, "/"), f->file_name);
126
    }
127
    dw_at_string (com);
128
    xfree ((void *)com);
129
  }
130
  return;
131
}
132
 
133
 
134
void init_dwarf2
135
    PROTO_Z ()
136
	/* Prepare to read diag unit information */
137
{
138
  init_dw_entries ();
139
  return;
140
}
141
 
142
 
143
void dwarf2_prelude
144
    PROTO_Z ()
145
	/* called from text segment */
146
{
147
  static int dw_started = 0;
148
  if (dw_started) {
149
    failer ("DWARF output not compatible with separate units");
150
  }
151
  dw_started = 1;
152
 
153
  dw_info_start = next_dwarf_label ();
154
  do_compunit_header ();
155
  statprog_start = next_dwarf_label ();
156
  statprog_end = next_dwarf_label ();
157
  do_statprog_prologue (statprog_start, statprog_end);
158
 
159
  dw_text_start = set_dw_text_label ();	/* we may need to separate these */
160
  text_end = next_dwarf_label ();	/* for multiple compilation units */
161
 
162
  init_dw_locdata ();
163
  return;
164
}
165
 
166
 
167
static int item_present
168
    PROTO_N ( (item) )
169
    PROTO_T ( dg_name item )
170
{
171
  UNUSED (item);
172
  return 1;
173
#if 0
174
  exp x;
175
  if (item->key == DGN_OBJECT)
176
    x = item->data.n_obj.obtain_val;
177
  else
178
  if (item->key == DGN_PROC)
179
    x = item->data.n_proc.obtain_val;
180
  else
181
    return 1;
182
  while (x && (name(x) == hold_tag || name(x) == name_tag ||
183
	name(x) == cont_tag || name(x) == reff_tag))
184
    x = son(x);
185
  if (x && name(x) == ident_tag)
186
    x = son(x);
187
  if (x) return 1;
188
  return 0;
189
#endif
190
}
191
 
192
 
193
static char * sep = ", ";
194
 
195
static void out_macros
196
    PROTO_N ( (macs) )
197
    PROTO_T ( dg_macro_list macs )
198
{
199
  int i;
200
  for (i = 0; i < macs.len; i++) {
201
    dg_macro m;
202
    m = macs.array[0];
203
    switch (m.key) {
204
      case DGM_FN: {
205
	int j;
206
	out8(); outn ((long)DW_MACINFO_define); outs (sep);
207
	uleb128 ((unsigned long)m.pos.line); d_outnl ();
208
	start_string (m.u.d.nam);
209
	outs ("(");
210
	for (j = 0; j < m.u.d.pms.len; j++) {
211
	  if (j) outs ("'");
212
	  outs (m.u.d.pms.array[j]);
213
	}
214
	outs (") "); outs (m.u.d.defn);
215
	end_string ();
216
	break;
217
      }
218
      case DGM_OBJ: {
219
	out8(); outn ((long)DW_MACINFO_define); outs (sep);
220
	uleb128 ((unsigned long)m.pos.line); d_outnl ();
221
	start_string (m.u.d.nam);
222
	outs (" "); outs (m.u.d.defn);
223
	end_string ();
224
	break;
225
      }
226
      case DGM_UNDEF: {
227
	out8(); outn ((long)DW_MACINFO_undef); outs (sep);
228
	uleb128 ((unsigned long)m.pos.line); d_outnl ();
229
	out_string (m.u.d.nam);
230
	break;
231
      }
232
      case DGM_INC: {
233
	out8(); outn ((long)DW_MACINFO_start_file); outs (sep);
234
	uleb128 ((unsigned long)m.pos.line); outs (sep);
235
	uleb128 ((unsigned long)(m.u.i.file->index)); d_outnl ();
236
	out_macros (m.u.i.macs);
237
	dw_at_data (1, (long)DW_MACINFO_end_file);
238
	break;
239
      }
240
    }
241
  }
242
  return;
243
}
244
 
245
 
246
void dwarf2_postlude
247
    PROTO_Z ()
248
	/* called from text segment */
249
{
250
  int inside = 0;
251
  long maclab = 0;
252
  dg_compilation this_comp;
253
  complete_dw_locdata ();
254
  this_comp = all_comp_units;
255
  while (this_comp) {
256
    dg_name item = this_comp->dn_list;
257
    abbrev_entry comp_dwe = dwe_comp_unit;
258
    while (item && !item_present(item))
259
      item = item -> next;
260
    if (item) {
261
      if (inside) {		/* => in debug_info section */
262
	dw_sibling_end ();
263
	exit_section ();
264
      }
265
      inside = 1;
266
      if (this_comp->macros.len) {	/* comp unit has macros */
267
	comp_dwe = dwe_cmac_unit;
268
	maclab = next_dwarf_label ();
269
	enter_section ("debug_macinfo");
270
	out_dwf_label (maclab, 1);
271
	out_macros (this_comp->macros);
272
	dw_at_data (1, (long)0);
273
	exit_section ();
274
      }
275
      enter_section ("debug_info");
276
      IGNORE dw_entry (comp_dwe, (long)0);
277
      dw_at_address (dw_text_start);
278
      dw_at_address (text_end);
279
      if (this_comp->prim_file->file_path[0] &&
280
		strcmp (this_comp->prim_file->file_path,
281
			this_comp->comp_dir->file_path) )
282
	dw_out_path (this_comp->prim_file, 1);
283
      else
284
        dw_at_string (this_comp->prim_file->file_name);
285
      dw_at_udata ((unsigned long)(this_comp->language));
286
      dw_at_address (statprog_start);
287
      if (this_comp->macros.len)
288
	dw_at_address (maclab);
289
      dw_out_path (this_comp->comp_dir, 0);
290
      out_producer (this_comp->producer);
291
      dw_at_data (1, (long)(this_comp->id_case));
292
      while (item) {
293
	if (item_present(item))
294
	  dw2_out_name (item, GLOBAL_NAME);
295
	item = item -> next;
296
      }
297
    }
298
    this_comp = this_comp->another;
299
  }
300
  if (inside)
301
    exit_section ();	/* back to text section */
302
  return;
303
}
304
 
305
 
306
void end_dwarf2
307
    PROTO_Z ()
308
	/* Output type entries and close info */
309
{
310
  enter_section ("debug_info");
311
  dw2_out_all_types ();
312
  complete_defaults ();
313
  dw_sibling_end ();
314
  exit_section ();
315
  out_dwf_label (text_end, 1);
316
  close_statprog (statprog_end);
317
  enter_section ("debug_aranges");
318
  out32 (); out_dwf_label (dw_text_start, 0); d_outnl ();
319
  out32 (); out_dwf_labdiff (dw_text_start, text_end); d_outnl ();
320
  exit_section ();
321
  dw2_data_aranges ();
322
  close_compunit_info ();
323
  return;
324
}