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/01/21 10:30:07 $
64
$Revision: 1.2 $
65
$Log: dw2_lines.c,v $
66
 * Revision 1.2  1998/01/21  10:30:07  pwe
67
 * labdiff change
68
 *
69
 * Revision 1.1.1.1  1998/01/17  15:55:48  release
70
 * First version to be checked into rolling release.
71
 *
72
 * Revision 1.8  1997/12/08  16:37:07  pwe
73
 * abbrev key & directory names
74
 *
75
 * Revision 1.7  1997/12/04  19:41:40  pwe
76
 * ANDF-DE V1.9
77
 *
78
 * Revision 1.6  1997/11/06  09:22:21  pwe
79
 * ANDF-DE V1.8
80
 *
81
 * Revision 1.5  1997/10/28  10:14:30  pwe
82
 * local location corrections
83
 *
84
 * Revision 1.4  1997/10/23  09:27:48  pwe
85
 * ANDF-DE v1.7, extra diags
86
 *
87
 * Revision 1.3  1997/08/23  13:36:51  pwe
88
 * initial ANDF-DE
89
 *
90
 * Revision 1.2  1997/04/17  11:50:32  pwe
91
 * Sparc and 80x86 support
92
 *
93
 * Revision 1.1  1997/03/20  16:09:24  pwe
94
 * first version
95
 *
96
**********************************************************************/
97
 
98
#include "config.h"
99
#include <time.h>
100
#include "common_types.h"
101
#include "dg_globs.h"
102
#include "dw2_config.h"
103
#include "dw2_lines.h"
104
#include "szs_als.h"
105
#include "dw2_codes.h"
106
#include "dw2_basic.h"
107
#include "dw2_iface.h"
108
 
109
 
110
/* values used in statement program prologue */
111
 
112
#define n_statprog_ops 9
7 7u83 113
static short statprog_op_args[n_statprog_ops] = {
2 7u83 114
	0, 1, 1, 1, 1, 0, 0, 0, 1
115
};
116
 
117
#define default_is_stmt 0
7 7u83 118
#define opcode_base	(n_statprog_ops + 1)
2 7u83 119
 
120
/* VARIABLES */
121
 
122
static long current_ad_label = -1;
123
static long current_ad_count = -1;
124
static long current_file = 1;
125
static long current_line = 1;
126
static long current_col = 0;
127
static long current_is_stmt = 0;
128
static long prev_ad_label = -1;
129
static long prev_ad_count = -1;
130
static long prev_file = 1;
131
static long prev_line = 1;
132
static long prev_col = 0;
133
static long prev_is_stmt = default_is_stmt;
134
 
7 7u83 135
static char *sep = ", ";
2 7u83 136
 
137
 
7 7u83 138
void
139
do_statprog_prologue(long l_start, long l_end)
2 7u83 140
{
7 7u83 141
	dg_filename f_list = all_files;
142
	dg_filename f_trace;
143
	int i;
144
	long prologue_end = next_dwarf_label();
145
	enter_section("debug_line");
146
	outnl_comment("Statement Program Prologue");
147
	out_dwf_label(l_start, 1);
148
	out32();
149
	out_dwf_dist_to_label(l_end);
150
	d_outnl();
151
	out16();
152
	outn((long)DWARF_MOD_VERSION);
153
	d_outnl();
154
	out32();
155
	out_dwf_dist_to_label(prologue_end);
156
	d_outnl();
157
	out8();
158
	outn((long)min_instr_size);
159
	d_outnl();
160
	out8();
161
	outn((long)default_is_stmt);
162
	d_outnl();
163
	out8();
164
	outn((long)dw_line_base);
165
	d_outnl();
166
	out8();
167
	outn((long)dw_line_range);
168
	d_outnl();
169
	out8();
170
	outn((long)opcode_base);
171
	d_outnl();
172
	out8();
173
	for (i = 1 ;; i++) {
174
		outn((long)statprog_op_args[i-1]);
175
		if (i == n_statprog_ops) {
176
			break;
177
		}
178
		outs(sep);
179
	}
180
	d_outnl();
181
	f_list = all_files;
182
	i = 0;
183
	while (f_list) {
184
		/* output directories */
185
		f_trace = all_files;
186
		while (f_trace != f_list) {
187
			if (!strcmp(f_list->file_path, f_trace->file_path) &&
188
			    !strcmp(f_list->file_host, f_trace->file_host)) {
189
				break;
190
			}
191
			f_trace = f_trace->another;
192
		}
193
		if (f_trace == f_list) {
194
			if (f_list->file_path[0] || f_list->file_host[0]) {
195
				dw_out_path(f_list, 0);
196
				f_list->index = ++i;
197
			} else {
198
				f_list->index = 0;
199
			}
200
		} else {
201
			f_list->index = f_trace->index;
202
		}
203
		f_list = f_list->another;
204
	}
205
	/* end of directories */
206
	out_string ("");
207
	f_list = all_files;
208
	i = 0;
209
	while (f_list) {
210
		/* output file names */
211
		if (f_list->file_name[0]) {
212
			time_t t = (time_t)f_list->file_dat;
213
			out_string(f_list->file_name);
214
			out8();
215
			uleb128((unsigned long)f_list->index);	/* directory */
216
			d_outnl();
217
			out8();
218
			uleb128((unsigned long)(f_list->file_dat));
219
			outnl_comment(ctime(&t));
220
			out8();
221
			uleb128((unsigned long)0);	/* unknown length */
222
			d_outnl();
223
			f_list->index = ++i;
224
		} else {
225
			f_list->index = 0;
226
		}
227
		f_list = f_list->another;
228
	}
229
	/* end of file names */
230
	out_string ("");
231
	out_dwf_label(prologue_end, 1);
232
	exit_section();
233
	dw2_cie();
234
	return;
2 7u83 235
}
236
 
237
 
7 7u83 238
static void
239
ext_opcode(int op, long arg_length, long align_lab)
2 7u83 240
{
7 7u83 241
	out8();
242
	outn((long)0);
243
	outs(sep);
2 7u83 244
#ifdef NEEDS_DEBUG_ALIGN
7 7u83 245
	if (align_lab) {
246
		out_dwf_label(align_lab, 0);
247
		outs (" - . - 1");		/* OK for arg_length < 127 */
248
	} else
2 7u83 249
#endif
7 7u83 250
		uleb128((unsigned long)arg_length + 1);
251
	outs(sep);
252
	outn((long)op);
253
	d_outnl();
254
	UNUSED(align_lab);
2 7u83 255
}
256
 
257
 
7 7u83 258
static void
259
update_statprog(void)
2 7u83 260
{
7 7u83 261
	long lineinc = current_line - prev_line;
262
	long ad_inc = 0;
263
	long special;
264
	if (current_ad_label < 0)
265
		return;
266
	enter_section("debug_line");
267
	if (prev_ad_label < 0) {
268
		long align_lab = 0;
2 7u83 269
#ifdef NEEDS_DEBUG_ALIGN
7 7u83 270
		align_lab = next_dwarf_label();
2 7u83 271
#endif
7 7u83 272
		ext_opcode(DW_LNE_set_address, (long)PTR_SZ / 8, align_lab);
273
		out32();
274
		out_dwf_label(current_ad_label, 0);
275
		if (current_ad_count) {
276
			outs(" + ");
277
			outn(current_ad_count * min_instr_size);
278
		}
279
		d_outnl();
2 7u83 280
#ifdef NEEDS_DEBUG_ALIGN
7 7u83 281
		out_dwf_label(align_lab, 1);
2 7u83 282
#endif
7 7u83 283
	} else if (prev_ad_label != current_ad_label) {
284
		out8();
285
		outn((long)DW_LNS_fixed_advance_pc);
286
		d_outnl();
287
		out16();
288
		out_dwf_label(current_ad_label, 0);
289
		outs(" - ");
290
		out_dwf_label(prev_ad_label, 0);
291
		if (current_ad_count != prev_ad_count) {
292
			outs(" + ");
293
			outn((current_ad_count - prev_ad_count) *
294
			     min_instr_size);
295
		}
296
		d_outnl();
297
	} else {
298
		ad_inc = current_ad_count - prev_ad_count;
299
	}
300
	prev_ad_label = current_ad_label;
301
	prev_ad_count = current_ad_count;
302
	if (current_file != prev_file) {
303
		out8();
304
		outn((long)DW_LNS_set_file);
305
		outs(sep);
306
		uleb128((unsigned long)current_file);
307
		d_outnl();
308
		prev_file = current_file;
309
	}
310
	if (current_is_stmt != prev_is_stmt) {
311
		out8();
312
		outn((long)DW_LNS_negate_stmt);
313
		d_outnl();
314
		prev_is_stmt = current_is_stmt;
315
	}
316
	if (current_col != prev_col) {
317
		out8();
318
		outn((long)DW_LNS_set_column);
319
		outs(sep);
320
		uleb128((unsigned long)current_col);
321
		d_outnl();
322
		prev_col = current_col;
323
	}
324
	if (lineinc < dw_line_base ||
325
	    lineinc >= (dw_line_base + dw_line_range)) {
326
		out8();
327
		outn((long)DW_LNS_advance_line);
328
		outs(sep);
329
		sleb128(lineinc);
330
		d_outnl();
331
		lineinc = 0;
332
	}
333
	special = (lineinc - dw_line_base) + (dw_line_range * ad_inc) +
334
	    opcode_base;
335
	if (special > 255) {
336
		out8();
337
		outn((long)DW_LNS_advance_pc);
338
		outs(sep);
339
		uleb128((unsigned long)ad_inc);
340
		d_outnl();
341
		special = (lineinc - dw_line_base) + opcode_base;
342
	}
343
	out8();
344
	if (special == (opcode_base - dw_line_base)) {
345
		outn((long)DW_LNS_copy);
346
	} else {
347
		outn(special);
348
	}
349
	outnl_comment_i("Line", current_line);
350
	prev_line = current_line;
351
	exit_section();
352
	return;
2 7u83 353
}
354
 
355
 
7 7u83 356
void
357
dw2_source_mark(short_sourcepos pos, int is_stmt)
2 7u83 358
{
7 7u83 359
	/* must be within text segment */
360
	long newlab = 0;
361
	if (current_ad_label < 0 || current_ad_label != last_text_label ||
362
	    instr_count < 0) {
363
		newlab = set_dw_text_label();
364
	}
365
	if (newlab || instr_count != current_ad_count ||
366
	    pos.file->index != current_file) {
367
		update_statprog();
368
	}
369
	if (newlab) {
370
		current_ad_label = newlab;
371
	}
372
	current_ad_count = instr_count;
373
	current_file = pos.file->index;
374
	current_line = pos.line;
375
	current_col = (long)pos.column;
376
	current_is_stmt = (long)is_stmt;
377
	return;
2 7u83 378
}
379
 
7 7u83 380
 
381
void
382
dw2_start_basic_block(void)
2 7u83 383
{
7 7u83 384
	/* must be within text segment */
385
	long newlab = 0;
386
	if (current_ad_label < 0 || current_ad_label != last_text_label ||
387
	    instr_count < 0) {
388
		newlab = set_dw_text_label();
389
	}
390
	if (newlab || instr_count) {
391
		update_statprog();
392
	}
393
	if (newlab) {
394
		current_ad_label = newlab;
395
	}
396
	current_ad_count = instr_count;
397
	enter_section("debug_line");
398
	out8();
399
	outn((long)DW_LNS_set_basic_block);
400
	d_outnl();
401
	exit_section();
402
	return;
2 7u83 403
}
404
 
405
 
7 7u83 406
void
407
close_statprog(long l_end)
2 7u83 408
{
7 7u83 409
	if (current_ad_label < 0 || current_ad_label != last_text_label ||
410
	    instr_count < 0) {
411
		current_ad_label = set_dw_text_label();
412
	}
413
	current_ad_count = instr_count;
414
	update_statprog();
415
	enter_section("debug_line");
416
	ext_opcode(DW_LNE_end_sequence, (long)0, (long)0);
417
	out_dwf_label(l_end, 1);
418
	exit_section();
419
	return;
2 7u83 420
}