Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
 
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
Line 98... Line 128...
98
 
128
 
99
int dwarf2 = 0;
129
int dwarf2 = 0;
100
 
130
 
101
long dw_info_start;
131
long dw_info_start;
102
long dw_text_start;
132
long dw_text_start;
103
 
133
 
104
static long statprog_start;	/* compilation unit level label */
134
static long statprog_start;	/* compilation unit level label */
105
static long statprog_end;
135
static long statprog_end;
106
static long text_end;
136
static long text_end;
107
 
137
 
108
 
138
 
109
void dw_out_path
139
void
110
    PROTO_N ( (f, w) )
-
 
111
    PROTO_T ( dg_filename f X int w )
140
dw_out_path(dg_filename f, int w)
112
{
141
{
113
  char * com;
142
	char *com;
114
  if (!w && f->file_path[0] && f->file_path[0] != '/')
143
	if (!w && f->file_path[0] && f->file_path[0]!= '/') {
115
    dw_at_string (f->file_path);
144
		dw_at_string(f->file_path);
116
  else {
145
	} else {
117
    size_t n = strlen (f->file_path) + strlen (f->file_host) + 2;
146
		size_t n = strlen(f->file_path) + strlen(f->file_host) + 2;
118
    if (w)
147
		if (w) {
119
      n += (strlen (f->file_name) + 1);
148
			n += (strlen(f->file_name) + 1);
-
 
149
		}
120
    com = (char *)xmalloc (n);
150
		com = (char *)xmalloc(n);
121
    IGNORE strcat (strcat (strcpy (com, f->file_host), ":"), f->file_path);
151
		IGNORE strcat(strcat(strcpy(com, f->file_host), ":"),
-
 
152
			      f->file_path);
122
    if (w) {
153
		if (w) {
123
      if (f->file_path[0] != '/')
154
			if (f->file_path[0]!= '/') {
124
	IGNORE strcpy (com, f->file_path);
155
				IGNORE strcpy(com, f->file_path);
-
 
156
			}
125
      IGNORE strcat (strcat (com, "/"), f->file_name);
157
			IGNORE strcat(strcat(com, "/"), f->file_name);
126
    }
158
		}
127
    dw_at_string (com);
159
		dw_at_string(com);
128
    xfree ((void *)com);
160
		xfree((void *)com);
129
  }
161
	}
130
  return;
162
	return;
131
}
163
}
132
 
164
 
133
 
165
 
134
void init_dwarf2
-
 
135
    PROTO_Z ()
-
 
136
	/* Prepare to read diag unit information */
166
/* Prepare to read diag unit information */
-
 
167
void
-
 
168
init_dwarf2(void)
137
{
169
{
138
  init_dw_entries ();
170
	init_dw_entries();
139
  return;
171
	return;
140
}
172
}
141
 
173
 
142
 
174
 
143
void dwarf2_prelude
-
 
144
    PROTO_Z ()
-
 
145
	/* called from text segment */
175
/* called from text segment */
-
 
176
void
-
 
177
dwarf2_prelude(void)
146
{
178
{
147
  static int dw_started = 0;
179
	static int dw_started = 0;
148
  if (dw_started) {
180
	if (dw_started) {
149
    failer ("DWARF output not compatible with separate units");
181
		failer("DWARF output not compatible with separate units");
150
  }
182
	}
151
  dw_started = 1;
183
	dw_started = 1;
152
 
184
 
153
  dw_info_start = next_dwarf_label ();
185
	dw_info_start = next_dwarf_label();
154
  do_compunit_header ();
186
	do_compunit_header();
155
  statprog_start = next_dwarf_label ();
187
	statprog_start = next_dwarf_label();
156
  statprog_end = next_dwarf_label ();
188
	statprog_end = next_dwarf_label();
157
  do_statprog_prologue (statprog_start, statprog_end);
189
	do_statprog_prologue(statprog_start, statprog_end);
158
 
190
 
-
 
191
	/* we may need to separate these */
159
  dw_text_start = set_dw_text_label ();	/* we may need to separate these */
192
	dw_text_start = set_dw_text_label();
-
 
193
 
160
  text_end = next_dwarf_label ();	/* for multiple compilation units */
194
	/* for multiple compilation units */
-
 
195
	text_end = next_dwarf_label();
161
 
196
 
162
  init_dw_locdata ();
197
	init_dw_locdata();
163
  return;
198
	return;
164
}
199
}
165
 
200
 
166
 
201
 
167
static int item_present
202
static int
168
    PROTO_N ( (item) )
-
 
169
    PROTO_T ( dg_name item )
203
item_present(dg_name item)
170
{
204
{
171
  UNUSED (item);
205
	UNUSED(item);
172
  return 1;
206
	return 1;
173
#if 0
207
#if 0
174
  exp x;
208
	exp x;
175
  if (item->key == DGN_OBJECT)
209
	if (item->key == DGN_OBJECT)
176
    x = item->data.n_obj.obtain_val;
210
		x = item->data.n_obj.obtain_val;
177
  else
211
	else
178
  if (item->key == DGN_PROC)
212
		if (item->key == DGN_PROC)
179
    x = item->data.n_proc.obtain_val;
213
			x = item->data.n_proc.obtain_val;
180
  else
214
		else
181
    return 1;
215
			return 1;
182
  while (x && (name(x) == hold_tag || name(x) == name_tag ||
216
	while (x && (name(x) == hold_tag || name(x) == name_tag ||
183
	name(x) == cont_tag || name(x) == reff_tag))
217
		     name(x) == cont_tag || name(x) == reff_tag))
184
    x = son(x);
218
		x = son(x);
185
  if (x && name(x) == ident_tag)
219
	if (x && name(x) == ident_tag)
186
    x = son(x);
220
		x = son(x);
187
  if (x) return 1;
221
	if (x) return 1;
188
  return 0;
222
	return 0;
189
#endif
223
#endif
190
}
224
}
191
 
225
 
192
 
226
 
193
static char * sep = ", ";
227
static char *sep = ", ";
-
 
228
 
-
 
229
static void
-
 
230
out_macros(dg_macro_list macs)
-
 
231
{
-
 
232
	int i;
-
 
233
	for (i = 0; i < macs.len; i++) {
-
 
234
		dg_macro m;
-
 
235
		m = macs.array[0];
-
 
236
		switch (m.key) {
-
 
237
		case DGM_FN: {
-
 
238
			int j;
-
 
239
			out8();
-
 
240
			outn((long)DW_MACINFO_define);
-
 
241
			outs(sep);
-
 
242
			uleb128((unsigned long)m.pos.line);
-
 
243
			d_outnl();
-
 
244
			start_string(m.u.d.nam);
-
 
245
			outs("(");
-
 
246
			for (j = 0; j < m.u.d.pms.len; j++) {
-
 
247
				if (j) {
-
 
248
					outs("'");
-
 
249
				}
-
 
250
				outs(m.u.d.pms.array[j]);
-
 
251
			}
-
 
252
			outs(") ");
-
 
253
			outs(m.u.d.defn);
-
 
254
			end_string();
-
 
255
			break;
-
 
256
		}
-
 
257
		case DGM_OBJ:
-
 
258
			out8();
-
 
259
			outn((long)DW_MACINFO_define);
-
 
260
			outs(sep);
-
 
261
			uleb128((unsigned long)m.pos.line);
-
 
262
			d_outnl();
-
 
263
			start_string(m.u.d.nam);
-
 
264
			outs(" ");
-
 
265
			outs(m.u.d.defn);
-
 
266
			end_string();
-
 
267
			break;
-
 
268
		case DGM_UNDEF:
-
 
269
			out8();
-
 
270
			outn((long)DW_MACINFO_undef);
-
 
271
			outs(sep);
-
 
272
			uleb128((unsigned long)m.pos.line);
-
 
273
			d_outnl();
-
 
274
			out_string(m.u.d.nam);
-
 
275
			break;
-
 
276
		case DGM_INC:
-
 
277
			out8();
-
 
278
			outn((long)DW_MACINFO_start_file);
-
 
279
			outs(sep);
-
 
280
			uleb128((unsigned long)m.pos.line);
-
 
281
			outs(sep);
-
 
282
			uleb128((unsigned long)(m.u.i.file->index));
-
 
283
			d_outnl();
-
 
284
			out_macros(m.u.i.macs);
-
 
285
			dw_at_data(1, (long)DW_MACINFO_end_file);
-
 
286
			break;
-
 
287
		}
-
 
288
	}
-
 
289
	return;
-
 
290
}
-
 
291
 
194
 
292
 
195
static void out_macros
293
/* called from text segment */
196
    PROTO_N ( (macs) )
294
void
197
    PROTO_T ( dg_macro_list macs )
295
dwarf2_postlude(void)
198
{
296
{
199
  int i;
297
	int inside = 0;
-
 
298
	long maclab = 0;
-
 
299
	dg_compilation this_comp;
-
 
300
	complete_dw_locdata();
-
 
301
	this_comp = all_comp_units;
-
 
302
	while (this_comp) {
-
 
303
		dg_name item = this_comp->dn_list;
-
 
304
		abbrev_entry comp_dwe = dwe_comp_unit;
200
  for (i = 0; i < macs.len; i++) {
305
		while (item && !item_present(item)) {
-
 
306
			item = item->next;
-
 
307
		}
-
 
308
		if (item) {
-
 
309
			if (inside) {
-
 
310
				/* => in debug_info section */
-
 
311
				dw_sibling_end();
-
 
312
				exit_section();
-
 
313
			}
201
    dg_macro m;
314
			inside = 1;
-
 
315
			if (this_comp->macros.len) {
-
 
316
				/* comp unit has macros */
-
 
317
				comp_dwe = dwe_cmac_unit;
202
    m = macs.array[0];
318
				maclab = next_dwarf_label();
-
 
319
				enter_section("debug_macinfo");
-
 
320
				out_dwf_label(maclab, 1);
-
 
321
				out_macros(this_comp->macros);
-
 
322
				dw_at_data(1, (long)0);
203
    switch (m.key) {
323
				exit_section();
-
 
324
			}
-
 
325
			enter_section("debug_info");
-
 
326
			IGNORE dw_entry(comp_dwe, (long)0);
-
 
327
			dw_at_address(dw_text_start);
204
      case DGM_FN: {
328
			dw_at_address(text_end);
-
 
329
			if (this_comp->prim_file->file_path[0] &&
-
 
330
			    strcmp(this_comp->prim_file->file_path,
-
 
331
				   this_comp->comp_dir->file_path)) {
-
 
332
				dw_out_path(this_comp->prim_file, 1);
205
	int j;
333
			} else {
206
	out8(); outn ((long)DW_MACINFO_define); outs (sep);
334
				dw_at_string(this_comp->prim_file->file_name);
-
 
335
			}
207
	uleb128 ((unsigned long)m.pos.line); d_outnl ();
336
			dw_at_udata((unsigned long)(this_comp->language));
-
 
337
			dw_at_address(statprog_start);
-
 
338
			if (this_comp->macros.len) {
208
	start_string (m.u.d.nam);
339
				dw_at_address(maclab);
-
 
340
			}
-
 
341
			dw_out_path(this_comp->comp_dir, 0);
-
 
342
			out_producer(this_comp->producer);
-
 
343
			dw_at_data(1, (long)(this_comp->id_case));
209
	outs ("(");
344
			while (item) {
210
	for (j = 0; j < m.u.d.pms.len; j++) {
345
				if (item_present(item)) {
-
 
346
					dw2_out_name(item, GLOBAL_NAME);
-
 
347
				}
211
	  if (j) outs ("'");
348
				item = item->next;
-
 
349
			}
-
 
350
		}
212
	  outs (m.u.d.pms.array[j]);
351
		this_comp = this_comp->another;
213
	}
352
	}
214
	outs (") "); outs (m.u.d.defn);
-
 
215
	end_string ();
353
	if (inside) {
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 */
354
		/* back to text section */
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 ();
355
		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
  }
356
	}
300
  if (inside)
-
 
301
    exit_section ();	/* back to text section */
-
 
302
  return;
357
	return;
303
}
358
}
304
 
359
 
305
 
360
 
306
void end_dwarf2
-
 
307
    PROTO_Z ()
-
 
308
	/* Output type entries and close info */
361
/* Output type entries and close info */
-
 
362
void
-
 
363
end_dwarf2(void)
309
{
364
{
310
  enter_section ("debug_info");
365
	enter_section("debug_info");
311
  dw2_out_all_types ();
366
	dw2_out_all_types();
312
  complete_defaults ();
367
	complete_defaults();
313
  dw_sibling_end ();
368
	dw_sibling_end();
314
  exit_section ();
369
	exit_section();
315
  out_dwf_label (text_end, 1);
370
	out_dwf_label(text_end, 1);
316
  close_statprog (statprog_end);
371
	close_statprog(statprog_end);
317
  enter_section ("debug_aranges");
372
	enter_section("debug_aranges");
-
 
373
	out32();
318
  out32 (); out_dwf_label (dw_text_start, 0); d_outnl ();
374
	out_dwf_label(dw_text_start, 0);
-
 
375
	d_outnl();
-
 
376
	out32();
319
  out32 (); out_dwf_labdiff (dw_text_start, text_end); d_outnl ();
377
	out_dwf_labdiff(dw_text_start, text_end);
-
 
378
	d_outnl();
320
  exit_section ();
379
	exit_section();
321
  dw2_data_aranges ();
380
	dw2_data_aranges();
322
  close_compunit_info ();
381
	close_compunit_info();
323
  return;
382
	return;
324
}
383
}