Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/tendra5-amd64/src/installers/common/dwarf2/dw2_basic.c – Rev 6

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