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/01/21 10:30:07 $
34
$Revision: 1.2 $
35
$Log: dw2_lines.c,v $
36
 * Revision 1.2  1998/01/21  10:30:07  pwe
37
 * labdiff change
38
 *
39
 * Revision 1.1.1.1  1998/01/17  15:55:48  release
40
 * First version to be checked into rolling release.
41
 *
42
 * Revision 1.8  1997/12/08  16:37:07  pwe
43
 * abbrev key & directory names
44
 *
45
 * Revision 1.7  1997/12/04  19:41:40  pwe
46
 * ANDF-DE V1.9
47
 *
48
 * Revision 1.6  1997/11/06  09:22:21  pwe
49
 * ANDF-DE V1.8
50
 *
51
 * Revision 1.5  1997/10/28  10:14:30  pwe
52
 * local location corrections
53
 *
54
 * Revision 1.4  1997/10/23  09:27:48  pwe
55
 * ANDF-DE v1.7, extra diags
56
 *
57
 * Revision 1.3  1997/08/23  13:36:51  pwe
58
 * initial ANDF-DE
59
 *
60
 * Revision 1.2  1997/04/17  11:50:32  pwe
61
 * Sparc and 80x86 support
62
 *
63
 * Revision 1.1  1997/03/20  16:09:24  pwe
64
 * first version
65
 *
66
**********************************************************************/
67
 
68
#include "config.h"
69
#include <time.h>
70
#include "common_types.h"
71
#include "dg_globs.h"
72
#include "dw2_config.h"
73
#include "dw2_lines.h"
74
#include "szs_als.h"
75
#include "dw2_codes.h"
76
#include "dw2_basic.h"
77
#include "dw2_iface.h"
78
 
79
 
80
/* values used in statement program prologue */
81
 
82
#define n_statprog_ops 9
83
static short statprog_op_args [n_statprog_ops] = {
84
	0, 1, 1, 1, 1, 0, 0, 0, 1
85
};
86
 
87
#define default_is_stmt 0
88
#define opcode_base (n_statprog_ops + 1)
89
 
90
/* VARIABLES */
91
 
92
static long current_ad_label = -1;
93
static long current_ad_count = -1;
94
static long current_file = 1;
95
static long current_line = 1;
96
static long current_col = 0;
97
static long current_is_stmt = 0;
98
static long prev_ad_label = -1;
99
static long prev_ad_count = -1;
100
static long prev_file = 1;
101
static long prev_line = 1;
102
static long prev_col = 0;
103
static long prev_is_stmt = default_is_stmt;
104
 
105
static char * sep = ", ";
106
 
107
 
108
void do_statprog_prologue
109
    PROTO_N ( (l_start, l_end) )
110
    PROTO_T ( long l_start X long l_end )
111
{
112
  dg_filename f_list = all_files;
113
  dg_filename f_trace;
114
  int i;
115
  long prologue_end = next_dwarf_label();
116
  enter_section ("debug_line");
117
  outnl_comment ("Statement Program Prologue");
118
  out_dwf_label (l_start, 1);
119
  out32 (); out_dwf_dist_to_label (l_end); d_outnl ();
120
  out16 (); outn ((long)DWARF_MOD_VERSION); d_outnl ();
121
  out32 (); out_dwf_dist_to_label (prologue_end); d_outnl ();
122
  out8 (); outn ((long)min_instr_size); d_outnl ();
123
  out8 (); outn ((long)default_is_stmt); d_outnl ();
124
  out8 (); outn ((long)dw_line_base); d_outnl ();
125
  out8 (); outn ((long)dw_line_range); d_outnl ();
126
  out8 (); outn ((long)opcode_base); d_outnl ();
127
  out8 ();
128
  for (i=1 ;; i++) {
129
    outn ((long)statprog_op_args[i-1]);
130
    if (i == n_statprog_ops)
131
      break;
132
    outs (sep);
133
  }
134
  d_outnl ();
135
  f_list = all_files;
136
  i = 0;
137
  while (f_list) {	/* output directories */
138
    f_trace = all_files;
139
    while (f_trace != f_list) {
140
      if (!strcmp (f_list->file_path, f_trace->file_path) &&
141
	  !strcmp (f_list->file_host, f_trace->file_host))
142
	break;
143
      f_trace = f_trace->another;
144
    }
145
    if (f_trace == f_list) {
146
      if (f_list->file_path[0] || f_list->file_host[0]) {
147
	dw_out_path (f_list, 0);
148
	f_list->index = ++i;
149
      }
150
      else
151
	f_list->index = 0;
152
    }
153
    else
154
      f_list->index = f_trace->index;
155
    f_list = f_list->another;
156
  }
157
  out_string ("");	/* end of directories */
158
  f_list = all_files;
159
  i = 0;
160
  while (f_list) {	/* output file names */
161
    if (f_list->file_name[0]) {
162
      time_t t = (time_t) f_list->file_dat;
163
      out_string (f_list->file_name);
164
      out8 (); uleb128 ((unsigned long)f_list->index);	/* directory */
165
      d_outnl ();
166
      out8 (); uleb128 ((unsigned long)(f_list->file_dat));
167
      outnl_comment (ctime (&t));
168
      out8 (); uleb128 ((unsigned long)0);	/* unknown length */
169
      d_outnl ();
170
      f_list->index = ++i;
171
    }
172
    else
173
      f_list->index = 0;
174
    f_list = f_list->another;
175
  }
176
  out_string ("");	/* end of file names */
177
  out_dwf_label (prologue_end, 1);
178
  exit_section ();
179
  dw2_cie ();
180
  return;
181
}
182
 
183
 
184
static void ext_opcode
185
    PROTO_N ( (op, arg_length, align_lab) )
186
    PROTO_T ( int op X long arg_length X long align_lab )
187
{
188
  out8 (); outn ((long)0); outs (sep);
189
#ifdef NEEDS_DEBUG_ALIGN
190
  if (align_lab) {
191
    out_dwf_label (align_lab, 0);
192
    outs (" - . - 1");		/* OK for arg_length < 127 */
193
  }
194
  else
195
#endif
196
    uleb128 ((unsigned long)arg_length + 1);
197
  outs (sep); outn ((long)op); d_outnl ();
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;
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);
218
    if (current_ad_count) {
219
      outs (" + "); outn (current_ad_count * min_instr_size);
220
    }
221
    d_outnl ();
222
#ifdef NEEDS_DEBUG_ALIGN
223
    out_dwf_label (align_lab, 1);
224
#endif
225
  }
226
  else
227
  if (prev_ad_label != current_ad_label) {
228
    out8 (); outn ((long)DW_LNS_fixed_advance_pc); d_outnl ();
229
    out16 (); out_dwf_label (current_ad_label, 0); outs (" - ");
230
	out_dwf_label (prev_ad_label, 0);
231
    if (current_ad_count != prev_ad_count) {
232
      outs (" + "); outn ((current_ad_count - prev_ad_count) * min_instr_size);
233
    }
234
    d_outnl ();
235
  }
236
  else
237
    ad_inc = current_ad_count - prev_ad_count;
238
  prev_ad_label = current_ad_label;
239
  prev_ad_count = current_ad_count;
240
  if (current_file != prev_file) {
241
    out8 (); outn ((long)DW_LNS_set_file);  outs (sep);
242
      uleb128 ((unsigned long)current_file); d_outnl ();
243
    prev_file = current_file;
244
  }
245
  if (current_is_stmt != prev_is_stmt) {
246
    out8 (); outn ((long)DW_LNS_negate_stmt); d_outnl ();
247
    prev_is_stmt = current_is_stmt;
248
  }
249
  if (current_col != prev_col) {
250
    out8 (); outn ((long)DW_LNS_set_column);  outs (sep);
251
      uleb128 ((unsigned long)current_col); d_outnl ();
252
    prev_col = current_col;
253
  }
254
  if (lineinc < dw_line_base || lineinc >= (dw_line_base + dw_line_range)) {
255
    out8 (); outn ((long)DW_LNS_advance_line);  outs (sep);
256
      sleb128 (lineinc); d_outnl ();
257
    lineinc = 0;
258
  }
259
  special = (lineinc - dw_line_base) + (dw_line_range * ad_inc) + opcode_base;
260
  if (special > 255) {
261
    out8 (); outn ((long)DW_LNS_advance_pc); outs (sep);
262
      uleb128 ((unsigned long)ad_inc); d_outnl ();
263
    special = (lineinc - dw_line_base) + opcode_base;
264
  }
265
  out8 ();
266
  if (special == (opcode_base - dw_line_base))
267
    outn ((long)DW_LNS_copy);
268
  else
269
    outn (special);
270
  outnl_comment_i ("Line", current_line);
271
  prev_line = current_line;
272
  exit_section ();
273
  return;
274
}
275
 
276
 
277
void dw2_source_mark
278
    PROTO_N ( (pos, is_stmt) )
279
    PROTO_T ( short_sourcepos pos X int is_stmt )
280
{
281
  /* must be within text segment */
282
  long newlab = 0;
283
  if (current_ad_label < 0 || current_ad_label != last_text_label || instr_count < 0)
284
    newlab = set_dw_text_label ();
285
  if (newlab || instr_count != current_ad_count || pos.file->index != current_file)
286
    update_statprog ();
287
  if (newlab)
288
    current_ad_label = newlab;
289
  current_ad_count = instr_count;
290
  current_file = pos.file->index;
291
  current_line = pos.line;
292
  current_col = (long)pos.column;
293
  current_is_stmt = (long)is_stmt;
294
  return;
295
}
296
 
297
void dw2_start_basic_block
298
    PROTO_Z ()
299
{
300
  /* must be within text segment */
301
  long newlab = 0;
302
  if (current_ad_label < 0 || current_ad_label != last_text_label || instr_count < 0)
303
    newlab = set_dw_text_label ();
304
  if (newlab || instr_count)
305
    update_statprog ();
306
  if (newlab)
307
    current_ad_label = newlab;
308
  current_ad_count = instr_count;
309
  enter_section ("debug_line");
310
  out8 (); outn ((long)DW_LNS_set_basic_block); d_outnl ();
311
  exit_section ();
312
  return;
313
}
314
 
315
 
316
void close_statprog
317
    PROTO_N ( (l_end) )
318
    PROTO_T ( long l_end )
319
{
320
  if (current_ad_label < 0 || current_ad_label != last_text_label || instr_count < 0)
321
    current_ad_label = set_dw_text_label ();
322
  current_ad_count = instr_count;
323
  update_statprog ();
324
  enter_section ("debug_line");
325
  ext_opcode (DW_LNE_end_sequence, (long)0, (long)0);
326
  out_dwf_label (l_end, 1);
327
  exit_section ();
328
  return;
329
}