Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 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
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
33
 
34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
49
 
50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
53
 
54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
/**********************************************************************
62
$Author: pwe $
63
$Date: 1998/03/15 16:00:34 $
64
$Revision: 1.4 $
65
$Log: dw2_iface.c,v $
66
 * Revision 1.4  1998/03/15  16:00:34  pwe
67
 * regtrack dwarf dagnostics added
68
 *
69
 * Revision 1.3  1998/03/11  11:03:43  pwe
70
 * DWARF optimisation info
71
 *
72
 * Revision 1.2  1998/01/21  10:30:05  pwe
73
 * labdiff change
74
 *
75
 * Revision 1.1.1.1  1998/01/17  15:55:48  release
76
 * First version to be checked into rolling release.
77
 *
78
 * Revision 1.10  1998/01/09  09:31:28  pwe
79
 * prep restructure
80
 *
81
 * Revision 1.9  1997/12/08  16:37:04  pwe
82
 * abbrev key & directory names
83
 *
84
 * Revision 1.8  1997/12/04  19:41:26  pwe
85
 * ANDF-DE V1.9
86
 *
87
 * Revision 1.7  1997/11/06  09:22:07  pwe
88
 * ANDF-DE V1.8
89
 *
90
 * Revision 1.6  1997/10/23  09:27:36  pwe
91
 * ANDF-DE v1.7, extra diags
92
 *
93
 * Revision 1.5  1997/10/10  18:18:32  pwe
94
 * prep ANDF-DE revision
95
 *
96
 * Revision 1.4  1997/08/23  13:36:39  pwe
97
 * initial ANDF-DE
98
 *
99
 * Revision 1.3  1997/04/17  11:50:22  pwe
100
 * Sparc and 80x86 support
101
 *
102
 * Revision 1.2  1997/03/24  11:10:26  pwe
103
 * struct bitfields
104
 *
105
 * Revision 1.1  1997/03/20  16:09:12  pwe
106
 * first version
107
 *
108
**********************************************************************/
109
 
110
#include "config.h"
111
#include "common_types.h"
112
#include "basicread.h"
113
#include "dg_globs.h"
114
#include "tags.h"
115
#include "expmacs.h"
116
#include "dw2_config.h"
117
#include "dw2_iface.h"
118
#include "dw2_types.h"
119
#include "dw2_entries.h"
120
#include "dw2_codes.h"
121
#include "dw2_basic.h"
122
#include "dw2_lines.h"
123
#include "dw2_info.h"
124
#include "dw2_locdata.h"
125
#include "xalloc.h"
126
#include "diagglob.h"
127
 
128
 
129
int dwarf2 = 0;
130
 
131
long dw_info_start;
132
long dw_text_start;
133
 
134
static long statprog_start;	/* compilation unit level label */
135
static long statprog_end;
136
static long text_end;
137
 
138
 
7 7u83 139
void
140
dw_out_path(dg_filename f, int w)
2 7u83 141
{
7 7u83 142
	char *com;
143
	if (!w && f->file_path[0] && f->file_path[0]!= '/') {
144
		dw_at_string(f->file_path);
145
	} else {
146
		size_t n = strlen(f->file_path) + strlen(f->file_host) + 2;
147
		if (w) {
148
			n += (strlen(f->file_name) + 1);
149
		}
150
		com = (char *)xmalloc(n);
151
		IGNORE strcat(strcat(strcpy(com, f->file_host), ":"),
152
			      f->file_path);
153
		if (w) {
154
			if (f->file_path[0]!= '/') {
155
				IGNORE strcpy(com, f->file_path);
156
			}
157
			IGNORE strcat(strcat(com, "/"), f->file_name);
158
		}
159
		dw_at_string(com);
160
		xfree((void *)com);
161
	}
162
	return;
2 7u83 163
}
164
 
165
 
7 7u83 166
/* Prepare to read diag unit information */
167
void
168
init_dwarf2(void)
2 7u83 169
{
7 7u83 170
	init_dw_entries();
171
	return;
2 7u83 172
}
173
 
174
 
7 7u83 175
/* called from text segment */
176
void
177
dwarf2_prelude(void)
2 7u83 178
{
7 7u83 179
	static int dw_started = 0;
180
	if (dw_started) {
181
		failer("DWARF output not compatible with separate units");
182
	}
183
	dw_started = 1;
2 7u83 184
 
7 7u83 185
	dw_info_start = next_dwarf_label();
186
	do_compunit_header();
187
	statprog_start = next_dwarf_label();
188
	statprog_end = next_dwarf_label();
189
	do_statprog_prologue(statprog_start, statprog_end);
2 7u83 190
 
7 7u83 191
	/* we may need to separate these */
192
	dw_text_start = set_dw_text_label();
2 7u83 193
 
7 7u83 194
	/* for multiple compilation units */
195
	text_end = next_dwarf_label();
196
 
197
	init_dw_locdata();
198
	return;
2 7u83 199
}
200
 
201
 
7 7u83 202
static int
203
item_present(dg_name item)
2 7u83 204
{
7 7u83 205
	UNUSED(item);
206
	return 1;
2 7u83 207
#if 0
7 7u83 208
	exp x;
209
	if (item->key == DGN_OBJECT)
210
		x = item->data.n_obj.obtain_val;
211
	else
212
		if (item->key == DGN_PROC)
213
			x = item->data.n_proc.obtain_val;
214
		else
215
			return 1;
216
	while (x && (name(x) == hold_tag || name(x) == name_tag ||
217
		     name(x) == cont_tag || name(x) == reff_tag))
218
		x = son(x);
219
	if (x && name(x) == ident_tag)
220
		x = son(x);
221
	if (x) return 1;
222
	return 0;
2 7u83 223
#endif
224
}
225
 
226
 
7 7u83 227
static char *sep = ", ";
2 7u83 228
 
7 7u83 229
static void
230
out_macros(dg_macro_list macs)
2 7u83 231
{
7 7u83 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
		}
2 7u83 288
	}
7 7u83 289
	return;
2 7u83 290
}
291
 
292
 
7 7u83 293
/* called from text segment */
294
void
295
dwarf2_postlude(void)
2 7u83 296
{
7 7u83 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;
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
			}
314
			inside = 1;
315
			if (this_comp->macros.len) {
316
				/* comp unit has macros */
317
				comp_dwe = dwe_cmac_unit;
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);
323
				exit_section();
324
			}
325
			enter_section("debug_info");
326
			IGNORE dw_entry(comp_dwe, (long)0);
327
			dw_at_address(dw_text_start);
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);
333
			} else {
334
				dw_at_string(this_comp->prim_file->file_name);
335
			}
336
			dw_at_udata((unsigned long)(this_comp->language));
337
			dw_at_address(statprog_start);
338
			if (this_comp->macros.len) {
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));
344
			while (item) {
345
				if (item_present(item)) {
346
					dw2_out_name(item, GLOBAL_NAME);
347
				}
348
				item = item->next;
349
			}
350
		}
351
		this_comp = this_comp->another;
352
	}
353
	if (inside) {
354
		/* back to text section */
355
		exit_section();
356
	}
357
	return;
2 7u83 358
}
359
 
360
 
7 7u83 361
/* Output type entries and close info */
362
void
363
end_dwarf2(void)
2 7u83 364
{
7 7u83 365
	enter_section("debug_info");
366
	dw2_out_all_types();
367
	complete_defaults();
368
	dw_sibling_end();
369
	exit_section();
370
	out_dwf_label(text_end, 1);
371
	close_statprog(statprog_end);
372
	enter_section("debug_aranges");
373
	out32();
374
	out_dwf_label(dw_text_start, 0);
375
	d_outnl();
376
	out32();
377
	out_dwf_labdiff(dw_text_start, text_end);
378
	d_outnl();
379
	exit_section();
380
	dw2_data_aranges();
381
	close_compunit_info();
382
	return;
2 7u83 383
}