Subversion Repositories tendra.SVN

Rev

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

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