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/03/15 16:00:32 $
34
$Revision: 1.4 $
35
$Log: dw2_basic.c,v $
36
 * Revision 1.4  1998/03/15  16:00:32  pwe
37
 * regtrack dwarf dagnostics added
38
 *
39
 * Revision 1.3  1998/03/11  11:03:37  pwe
40
 * DWARF optimisation info
41
 *
42
 * Revision 1.2  1998/01/21  10:30:04  pwe
43
 * labdiff change
44
 *
45
 * Revision 1.1.1.1  1998/01/17  15:55:48  release
46
 * First version to be checked into rolling release.
47
 *
48
 * Revision 1.11  1997/12/08  16:36:59  pwe
49
 * abbrev key & directory names
50
 *
51
 * Revision 1.10  1997/12/04  19:41:10  pwe
52
 * ANDF-DE V1.9
53
 *
54
 * Revision 1.9  1997/11/06  09:21:57  pwe
55
 * ANDF-DE V1.8
56
 *
57
 * Revision 1.8  1997/10/23  09:27:23  pwe
58
 * ANDF-DE v1.7, extra diags
59
 *
60
 * Revision 1.7  1997/10/10  18:18:19  pwe
61
 * prep ANDF-DE revision
62
 *
63
 * Revision 1.6  1997/08/23  13:36:31  pwe
64
 * initial ANDF-DE
65
 *
66
 * Revision 1.5  1997/05/13  08:02:25  pwe
67
 * Signed LEB128 corrected
68
 *
69
 * Revision 1.4  1997/04/17  11:50:11  pwe
70
 * Sparc and 80x86 support
71
 *
72
 * Revision 1.3  1997/04/01  17:19:33  pwe
73
 * diagnose pl_tests and locate -> platform specific
74
 *
75
 * Revision 1.2  1997/03/24  11:10:17  pwe
76
 * struct bitfields
77
 *
78
 * Revision 1.1  1997/03/20  16:08:59  pwe
79
 * first version
80
 *
81
**********************************************************************/
82
 
83
#include "config.h"
84
#include "common_types.h"
85
#include "dw2_config.h"
86
#include "dw2_basic.h"
87
#include "dw2_codes.h"
88
#include "dw2_iface.h"
89
#include "szs_als.h"
90
#include "expmacs.h"
91
#include "tags.h"
92
#include "basicread.h"
93
#include "dw2_abbrev_vn.h"
94
 
95
 
96
#define entry_names_wanted
97
#include "dw2_entries.h"
98
#undef entry_names_wanted
99
 
100
 
101
static char * sep = ", ";
102
 
103
 
104
void uleb128
105
    PROTO_N ( (value) )
106
    PROTO_T ( unsigned long value )
107
{
108
  int byt;
109
  for (;;) {
110
    byt = value & 127;
111
    value >>= 7;
112
    if (value == 0) {
113
      outn ((long)byt);
114
      return;
115
    }
116
    outn ((long)byt | 128);
117
    outs (sep);
118
  }
119
}
120
 
121
int uleb128_length
122
    PROTO_N ( (value) )
123
    PROTO_T ( unsigned long value )
124
{
125
  int op = 1;
126
  for (;;) {
127
    value >>= 7;
128
    if (value == 0) {
129
      return op;
130
    }
131
    op++;
132
  }
133
}
134
 
135
void sleb128
136
    PROTO_N ( (value) )
137
    PROTO_T ( long value )
138
{
139
  int negative = (value < 0);
140
  int byt;
141
  for (;;) {
142
    byt = (unsigned long) value & 127;
143
    value >>= 7;
144
    if (negative)
145
      /* sign extend, since C doesn't imply arithmetic shift */
146
      value |= - (1 << ((sizeof(value)*8) - 7));
147
    /* sign bit of byte is 2nd high order bit (0x40) */
148
    if (value == - (long) ((byt & 0x40) != 0)) {
149
      outn ((long)byt);
150
      return;
151
    }
152
    outn ((long)byt | 128);
153
    outs (sep);
154
  };
155
}
156
 
157
int sleb128_length
158
    PROTO_N ( (value) )
159
    PROTO_T ( long value )
160
{
161
  int op = 1;
162
  int negative = (value < 0);
163
  int byt;
164
  for (;;) {
165
    byt = (unsigned long) value & 127;
166
    value >>= 7;
167
    if (negative)
168
      /* sign extend, since C doesn't imply arithmetic shift */
169
      value |= - (1 << ((sizeof(value)*8) - 7));
170
    if (value == - (long) ((byt & 0x40) != 0)) {
171
      return op;
172
    }
173
    op++;
174
  };
175
}
176
 
177
void set_attribute
178
    PROTO_N ( (nm, form) )
179
    PROTO_T ( int nm X int form )
180
{
181
  out8 (); uleb128 ((unsigned long)nm);
182
  if (form || !nm) {
183
    outs (sep); uleb128 ((unsigned long)form);
184
  }
185
  d_outnl ();
186
  return;
187
}
188
 
189
static long info_end;
190
static long pubnames_end;
191
static long aranges_end;
192
 
193
 
194
void do_compunit_header
195
    PROTO_Z ()
196
{
197
  info_end = next_dwarf_label ();
198
  pubnames_end = next_dwarf_label ();
199
  aranges_end = next_dwarf_label ();
200
  enter_section ("debug_info");
201
  out_dwf_label (dw_info_start, 1);
202
  outnl_comment("Compilation Unit Header");
203
  out32 (); out_dwf_dist_to_label (info_end); d_outnl ();
204
  out16 (); outn ((long)DWARF_MOD_VERSION); d_outnl ();
205
  out32 (); outs (abbrev_name); d_outnl ();
206
  out8 (); outn ((long)PTR_SZ/8); d_outnl ();
207
  exit_section ();
208
  enter_section ("debug_pubnames");
209
  out32 (); out_dwf_dist_to_label (pubnames_end); d_outnl ();
210
  out16 (); outn ((long)DWARF_MOD_VERSION); d_outnl ();
211
  out32 (); out_dwf_label (dw_info_start, 0); d_outnl ();
212
  out32 (); out_dwf_labdiff (dw_info_start, info_end); d_outnl ();
213
  exit_section ();
214
  enter_section ("debug_aranges");
215
  out32 (); out_dwf_dist_to_label (aranges_end); d_outnl ();
216
  out16 (); outn ((long)DWARF_MOD_VERSION); d_outnl ();
217
  out32 (); out_dwf_label (dw_info_start, 0); d_outnl ();
218
  out8 (); outn ((long)PTR_SZ/8); d_outnl ();
219
  out8 (); outn ((long)0); d_outnl ();
220
  dot_align (PTR_SZ/4);
221
  exit_section ();
222
  return;
223
}
224
 
225
void close_compunit_info
226
    PROTO_Z ()
227
{
228
  enter_section ("debug_info");
229
  out_dwf_label (info_end, 1);
230
#ifdef NEEDS_DEBUG_ALIGN
231
  dot_align (4);
232
#endif
233
  exit_section ();
234
  enter_section ("debug_pubnames");
235
  out32 (); outn ((long)0); d_outnl ();
236
  out_dwf_label (pubnames_end, 1);
237
#ifdef NEEDS_DEBUG_ALIGN
238
  dot_align (4);
239
#endif
240
  exit_section ();
241
  enter_section ("debug_aranges");
242
  out32 (); outn ((long)0); d_outnl ();
243
  out32 (); outn ((long)0); d_outnl ();
244
  out_dwf_label (aranges_end, 1);
245
  exit_section ();
246
}
247
 
248
 
249
void dw_sibling_end
250
    PROTO_Z ()
251
{
252
  out8 (); uleb128 ((unsigned long)0); 
253
  outnl_comment ("sibling end");
254
  return;
255
}
256
 
257
void dw_at_address
258
    PROTO_N ( (lab) )
259
    PROTO_T ( long lab )
260
{
261
  out32 (); out_dwf_label (lab, 0); d_outnl ();
262
  return;
263
}
264
 
265
void dw_at_ext_lab
266
    PROTO_N ( (lab) )
267
    PROTO_T ( ext_lab lab )
268
{
269
  out32 ();
270
  switch (lab.k) {
271
    case LAB_STR:
272
      outs (lab.u.s);
273
      break;
274
    case LAB_CODE:
275
      out_code_label (lab.u.l);
276
      break;
277
    case LAB_D:
278
      out_dwf_label (lab.u.l, 0);
279
      break;
280
    default:
281
      failer ("unset label");
282
  }
283
  d_outnl ();
284
  return;
285
}
286
 
287
void dw_set_ext_lab
288
    PROTO_N ( (lab) )
289
    PROTO_T ( ext_lab lab )
290
{
291
  switch (lab.k) {
292
    case LAB_STR:
293
      out_ext_label (lab.u.s);
294
      break;
295
    case LAB_D:
296
      out_dwf_label (lab.u.l, 1);
297
      break;
298
    default:
299
      failer ("unexpected set label");
300
  }
301
  return;
302
}
303
 
304
void dw_at_ext_address
305
    PROTO_N ( (dt) )
306
    PROTO_T ( dg_tag dt )
307
{
308
  if (dt->outref.k == NO_LAB) {
309
    dt->outref.k = LAB_D;
310
    dt->outref.u.l = next_dwarf_label ();
311
  }
312
  dw_at_ext_lab (dt->outref);
313
  return;
314
}
315
 
316
void set_ext_address
317
    PROTO_N ( (dt) )
318
    PROTO_T ( dg_tag dt )
319
{
320
  if (dt->outref.k == NO_LAB) {
321
    dt->outref.k = LAB_D;
322
    dt->outref.u.l = next_dwarf_label ();
323
  }
324
  dw_set_ext_lab (dt->outref);
325
  return;
326
}
327
 
328
void dw_at_abstract_lab
329
    PROTO_N ( (dt) )
330
    PROTO_T ( dg_tag dt )
331
{
332
  if (!dt->abstract_lab)
333
    dt->abstract_lab = next_dwarf_label ();
334
  out32 ();
335
  out_dwf_label (dt->abstract_lab, 0);
336
  d_outnl ();
337
  return;
338
}
339
 
340
void set_abstract_lab
341
    PROTO_N ( (dt) )
342
    PROTO_T ( dg_tag dt )
343
{
344
  if (!dt->abstract_lab)
345
    dt->abstract_lab = next_dwarf_label ();
346
  out_dwf_label (dt->abstract_lab, 1);
347
  return;
348
}
349
 
350
void dw_at_string
351
    PROTO_N ( (s) )
352
    PROTO_T ( char* s )
353
{
354
  if (!s) s = "";
355
  out_string (s);
356
  return;
357
}
358
 
359
void dw_at_form
360
    PROTO_N ( (f) )
361
    PROTO_T ( int f )
362
{
363
  out8 ();
364
  uleb128 ((unsigned long)f);
365
  return;
366
}
367
 
368
void dw_at_data
369
    PROTO_N ( (n, d) )
370
    PROTO_T ( int n X long d )
371
{
372
  switch (n) {
373
    case 1: {
374
      out8 ();
375
      break;
376
    }
377
    case 2: {
378
      out16 ();
379
      break;
380
    }
381
    case 4: {
382
      out32 ();
383
      break;
384
    }
385
    default:
386
      failer ("dwarf data size not supported");
387
  }
388
  outn (d); d_outnl ();
389
  return;
390
}
391
 
392
void dw_at_udata
393
    PROTO_N ( (n) )
394
    PROTO_T ( unsigned long n )
395
{
396
  out8 (); uleb128 (n); d_outnl ();
397
  return;
398
}
399
 
400
void dw_at_sdata
401
    PROTO_N ( (n) )
402
    PROTO_T ( long n )
403
{
404
  out8 (); sleb128 (n); d_outnl ();
405
  return;
406
}
407
 
408
void dw_at_flag
409
    PROTO_N ( (x) )
410
    PROTO_T ( int x )
411
{
412
  out8 (); outn ((long)x); d_outnl ();
413
  return;
414
}
415
 
416
void dw_at_decl
417
    PROTO_N ( (p) )
418
    PROTO_T ( short_sourcepos p )
419
{
420
  out8 (); uleb128 ((unsigned long)(p.file ? p.file->index : 0));
421
  outs(sep); uleb128 ((unsigned long)p.line);
422
  outs(sep); uleb128 ((unsigned long)p.column);
423
  d_outnl ();
424
  return;
425
}
426
 
427
void dw_no_locate
428
    PROTO_Z ()
429
{
430
  out8 (); outn ((long)0);
431
  outnl_comment ("discarded variable");
432
  return;
433
}
434
 
435
void dw_locate_offset
436
    PROTO_N ( (n) )
437
    PROTO_T ( int n )
438
{
439
  out8(); outn ((long)(1 + uleb128_length((unsigned long)n))); outs(sep);
440
  outn ((long)DW_OP_plus_uconst); outs (sep);
441
  uleb128 ((unsigned long)n); d_outnl ();
442
  return;
443
}
444
 
445
static char* bad_refloc = "unimplemented relative location";
446
 
447
static int refloc_length
448
    PROTO_N ( (e, id) )
449
    PROTO_T ( exp e X exp id )
450
{
451
  switch (name(e)) {
452
    case name_tag: {
453
      if (son(e) != id)
454
	failer (bad_refloc);
455
      if (no(e) == 0)
456
	return (0);
457
      return (1 + uleb128_length((unsigned long)no(e)/8));
458
    }
459
    case cont_tag: {
460
      return (refloc_length (son(e), id) + 1);
461
    }
462
    case reff_tag: {
463
      if (no(e)<0)
464
	failer (bad_refloc);
465
      return (refloc_length (son(e), id) + 1 +
466
		uleb128_length((unsigned long)no(e)/8));
467
    }
468
    default: {
469
      failer (bad_refloc);
470
      return (0);
471
    }
472
  }
473
}
474
 
475
static void out_refloc
476
    PROTO_N ( (e, id) )
477
    PROTO_T ( exp e X exp id )
478
{
479
  switch (name(e)) {
480
    case name_tag: {
481
      if (son(e) != id)
482
	failer (bad_refloc);
483
      outs (sep); outn ((long)DW_OP_plus_uconst);
484
      outs (sep); uleb128 ((unsigned long)no(e)/8);
485
      return;
486
    }
487
    case cont_tag: {
488
      out_refloc (son(e), id);
489
      outs (sep); outn ((long)DW_OP_deref);
490
      return;
491
    }
492
    case reff_tag: {
493
      if (no(e)<0)
494
	failer (bad_refloc);
495
      out_refloc (son(e), id);
496
      outs (sep); outn ((long)DW_OP_plus_uconst);
497
      outs (sep); uleb128 ((unsigned long)no(e)/8);
498
      return;
499
    }
500
    default:
501
      failer (bad_refloc);
502
  }
503
}
504
 
505
void dw_locate_reloffset
506
    PROTO_N ( (e) )
507
    PROTO_T ( exp e )
508
{
509
  int length;
510
  if (name(e) != ident_tag) {
511
    failer (bad_refloc);
512
    return;
513
  }
514
  length = refloc_length (bro(son(e)), e);
515
  out8();
516
  if (length == 0) {
517
    outn ((long)1);
518
    outs(sep); outn ((long)DW_OP_nop);
519
  }
520
  else {
521
    outn ((long)length);
522
    out_refloc (bro(son(e)), e);
523
  }
524
  d_outnl ();
525
  return;
526
}
527
 
528
void dw_at_distance
529
    PROTO_N ( (lo, hi) )
530
    PROTO_T ( long lo X long hi )
531
{
532
  out16 (); out_dwf_labdiff (lo, hi); d_outnl ();
533
  return;
534
}
535
 
536
long last_text_label = 0;
537
 
538
long set_dw_text_label
539
    PROTO_Z ()
540
{
541
  if (any_output) {
542
    last_text_label = next_dwarf_label ();
543
    out_dwf_label (last_text_label, 1);
544
    reset_any_output;
545
  }
546
  return last_text_label;
547
}
548
 
549
void out_text_label
550
    PROTO_N ( (n) )
551
    PROTO_T ( long n )
552
{
553
  out_dwf_label (n, 1);
554
  last_text_label = n;
555
  return;
556
}
557
 
558
void out_loc_range
559
    PROTO_N ( (start, end, inclusive) )
560
    PROTO_T ( long start X long end X int inclusive )
561
{
562
  /* for location list */
563
  out32 (); out_dwf_labdiff (dw_text_start, start); d_outnl ();
564
  out32 (); out_dwf_labdiff (dw_text_start, end);
565
  if (inclusive) {
566
    outs (" + ");
567
    outn ((long)min_instr_size);
568
  }
569
  d_outnl ();
570
  return;
571
}