Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
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 94... Line 124...
94
 
124
 
95
 
125
 
96
#define entry_names_wanted
126
#define entry_names_wanted
97
#include "dw2_entries.h"
127
#include "dw2_entries.h"
98
#undef entry_names_wanted
128
#undef entry_names_wanted
99
 
129
 
100
 
130
 
101
static char * sep = ", ";
131
static char *sep = ", ";
102
 
132
 
103
 
133
 
104
void uleb128
134
void
105
    PROTO_N ( (value) )
-
 
106
    PROTO_T ( unsigned long value )
135
uleb128(unsigned long value)
107
{
136
{
108
  int byt;
137
	int byt;
109
  for (;;) {
138
	for (;;) {
110
    byt = value & 127;
139
		byt = value & 127;
111
    value >>= 7;
140
		value >>= 7;
112
    if (value == 0) {
141
		if (value == 0) {
113
      outn ((long)byt);
142
			outn((long)byt);
114
      return;
143
			return;
115
    }
144
		}
116
    outn ((long)byt | 128);
145
		outn((long)byt | 128);
117
    outs (sep);
146
		outs(sep);
118
  }
147
	}
119
}
148
}
-
 
149
 
120
 
150
 
121
int uleb128_length
151
int
122
    PROTO_N ( (value) )
-
 
123
    PROTO_T ( unsigned long value )
152
uleb128_length(unsigned long value)
124
{
153
{
125
  int op = 1;
154
	int op = 1;
126
  for (;;) {
155
	for (;;) {
127
    value >>= 7;
156
		value >>= 7;
128
    if (value == 0) {
157
		if (value == 0) {
129
      return op;
158
			return op;
130
    }
159
		}
131
    op++;
160
		op++;
132
  }
161
	}
133
}
162
}
-
 
163
 
134
 
164
 
135
void sleb128
165
void
136
    PROTO_N ( (value) )
-
 
137
    PROTO_T ( long value )
166
sleb128(long value)
138
{
167
{
139
  int negative = (value < 0);
168
	int negative = (value < 0);
140
  int byt;
169
	int byt;
141
  for (;;) {
170
	for (;;) {
142
    byt = (unsigned long) value & 127;
171
		byt = (unsigned long)value & 127;
143
    value >>= 7;
172
		value >>= 7;
144
    if (negative)
173
		if (negative) {
145
      /* sign extend, since C doesn't imply arithmetic shift */
174
			/* sign extend, since C doesn't imply arithmetic
-
 
175
			 * shift */
146
      value |= - (1 << ((sizeof(value)*8) - 7));
176
			value |= - (1 << ((sizeof(value) * 8) - 7));
-
 
177
		}
147
    /* sign bit of byte is 2nd high order bit (0x40) */
178
		/* sign bit of byte is 2nd high order bit (0x40) */
148
    if (value == - (long) ((byt & 0x40) != 0)) {
179
		if (value == - (long)((byt & 0x40) != 0)) {
149
      outn ((long)byt);
180
			outn((long)byt);
150
      return;
181
			return;
151
    }
182
		}
152
    outn ((long)byt | 128);
183
		outn((long)byt | 128);
153
    outs (sep);
184
		outs(sep);
154
  };
185
	}
155
}
186
}
-
 
187
 
156
 
188
 
157
int sleb128_length
189
int
158
    PROTO_N ( (value) )
-
 
159
    PROTO_T ( long value )
190
sleb128_length(long value)
160
{
191
{
161
  int op = 1;
192
	int op = 1;
162
  int negative = (value < 0);
193
	int negative = (value < 0);
163
  int byt;
194
	int byt;
164
  for (;;) {
195
	for (;;) {
165
    byt = (unsigned long) value & 127;
196
		byt = (unsigned long)value & 127;
166
    value >>= 7;
197
		value >>= 7;
167
    if (negative)
198
		if (negative) {
168
      /* sign extend, since C doesn't imply arithmetic shift */
199
			/* sign extend, since C doesn't imply arithmetic
-
 
200
			 * shift */
169
      value |= - (1 << ((sizeof(value)*8) - 7));
201
			value |= - (1 << ((sizeof(value) * 8) - 7));
-
 
202
		}
170
    if (value == - (long) ((byt & 0x40) != 0)) {
203
		if (value == - (long)((byt & 0x40) != 0)) {
171
      return op;
204
			return op;
172
    }
205
		}
173
    op++;
206
		op++;
174
  };
207
	}
175
}
208
}
-
 
209
 
176
 
210
 
177
void set_attribute
211
void
178
    PROTO_N ( (nm, form) )
-
 
179
    PROTO_T ( int nm X int form )
212
set_attribute(int nm, int form)
180
{
213
{
-
 
214
	out8();
181
  out8 (); uleb128 ((unsigned long)nm);
215
	uleb128((unsigned long)nm);
182
  if (form || !nm) {
216
	if (form || !nm) {
-
 
217
		outs(sep);
183
    outs (sep); uleb128 ((unsigned long)form);
218
		uleb128((unsigned long) form);
184
  }
219
	}
185
  d_outnl ();
220
	d_outnl();
186
  return;
221
	return;
187
}
222
}
188
 
223
 
189
static long info_end;
224
static long info_end;
190
static long pubnames_end;
225
static long pubnames_end;
191
static long aranges_end;
226
static long aranges_end;
192
 
227
 
193
 
228
 
-
 
229
void
194
void do_compunit_header
230
do_compunit_header(void)
195
    PROTO_Z ()
-
 
196
{
231
{
197
  info_end = next_dwarf_label ();
232
	info_end = next_dwarf_label();
198
  pubnames_end = next_dwarf_label ();
233
	pubnames_end = next_dwarf_label();
199
  aranges_end = next_dwarf_label ();
234
	aranges_end = next_dwarf_label();
200
  enter_section ("debug_info");
235
	enter_section("debug_info");
201
  out_dwf_label (dw_info_start, 1);
236
	out_dwf_label(dw_info_start, 1);
202
  outnl_comment("Compilation Unit Header");
237
	outnl_comment("Compilation Unit Header");
-
 
238
	out32();
203
  out32 (); out_dwf_dist_to_label (info_end); d_outnl ();
239
	out_dwf_dist_to_label(info_end);
-
 
240
	d_outnl();
-
 
241
	out16();
204
  out16 (); outn ((long)DWARF_MOD_VERSION); d_outnl ();
242
	outn((long)DWARF_MOD_VERSION);
-
 
243
	d_outnl();
-
 
244
	out32();
205
  out32 (); outs (abbrev_name); d_outnl ();
245
	outs(abbrev_name);
-
 
246
	d_outnl();
-
 
247
	out8();
206
  out8 (); outn ((long)PTR_SZ/8); d_outnl ();
248
	outn((long)PTR_SZ/8);
-
 
249
	d_outnl();
207
  exit_section ();
250
	exit_section();
208
  enter_section ("debug_pubnames");
251
	enter_section("debug_pubnames");
-
 
252
	out32();
209
  out32 (); out_dwf_dist_to_label (pubnames_end); d_outnl ();
253
	out_dwf_dist_to_label(pubnames_end);
-
 
254
	d_outnl();
-
 
255
	out16();
210
  out16 (); outn ((long)DWARF_MOD_VERSION); d_outnl ();
256
	outn((long)DWARF_MOD_VERSION);
-
 
257
	d_outnl();
-
 
258
	out32();
211
  out32 (); out_dwf_label (dw_info_start, 0); d_outnl ();
259
	out_dwf_label(dw_info_start, 0);
-
 
260
	d_outnl();
-
 
261
	out32();
212
  out32 (); out_dwf_labdiff (dw_info_start, info_end); d_outnl ();
262
	out_dwf_labdiff(dw_info_start, info_end);
-
 
263
	d_outnl();
213
  exit_section ();
264
	exit_section();
214
  enter_section ("debug_aranges");
265
	enter_section("debug_aranges");
-
 
266
	out32();
215
  out32 (); out_dwf_dist_to_label (aranges_end); d_outnl ();
267
	out_dwf_dist_to_label(aranges_end);
-
 
268
	d_outnl();
-
 
269
	out16();
216
  out16 (); outn ((long)DWARF_MOD_VERSION); d_outnl ();
270
	outn((long)DWARF_MOD_VERSION);
-
 
271
	d_outnl();
-
 
272
	out32();
217
  out32 (); out_dwf_label (dw_info_start, 0); d_outnl ();
273
	out_dwf_label(dw_info_start, 0);
-
 
274
	d_outnl();
-
 
275
	out8();
218
  out8 (); outn ((long)PTR_SZ/8); d_outnl ();
276
	outn((long)PTR_SZ/8);
-
 
277
	d_outnl();
-
 
278
	out8();
219
  out8 (); outn ((long)0); d_outnl ();
279
	outn((long)0);
-
 
280
	d_outnl();
220
  dot_align (PTR_SZ/4);
281
	dot_align(PTR_SZ/4);
221
  exit_section ();
282
	exit_section();
222
  return;
283
	return;
223
}
284
}
224
 
285
 
-
 
286
 
-
 
287
void
225
void close_compunit_info
288
close_compunit_info(void)
226
    PROTO_Z ()
-
 
227
{
289
{
228
  enter_section ("debug_info");
290
	enter_section("debug_info");
229
  out_dwf_label (info_end, 1);
291
	out_dwf_label(info_end, 1);
-
 
292
#ifdef NEEDS_DEBUG_ALIGN
-
 
293
	dot_align(4);
-
 
294
#endif
-
 
295
	exit_section();
-
 
296
	enter_section("debug_pubnames");
-
 
297
	out32();
-
 
298
	outn((long)0);
-
 
299
	d_outnl();
-
 
300
	out_dwf_label(pubnames_end, 1);
230
#ifdef NEEDS_DEBUG_ALIGN
301
#ifdef NEEDS_DEBUG_ALIGN
231
  dot_align (4);
302
	dot_align(4);
232
#endif
303
#endif
233
  exit_section ();
304
	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");
305
	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 ();
306
	out32();
270
  switch (lab.k) {
-
 
271
    case LAB_STR:
-
 
272
      outs (lab.u.s);
307
	outn((long)0);
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 ();
308
	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 ();
309
	out32();
335
  out_dwf_label (dt->abstract_lab, 0);
310
	outn((long)0);
336
  d_outnl ();
311
	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);
312
	out_dwf_label(aranges_end, 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);
313
	exit_section();
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
}
314
}
434
 
315
 
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
 
316
 
505
void dw_locate_reloffset
317
void
506
    PROTO_N ( (e) )
318
dw_sibling_end(void)
507
    PROTO_T ( exp e )
-
 
508
{
319
{
-
 
320
	out8();
-
 
321
	uleb128((unsigned long)0);
-
 
322
	outnl_comment("sibling end");
-
 
323
	return;
-
 
324
}
-
 
325
 
-
 
326
 
-
 
327
void
-
 
328
dw_at_address(long lab)
-
 
329
{
-
 
330
	out32();
-
 
331
	out_dwf_label(lab, 0);
-
 
332
	d_outnl();
-
 
333
	return;
-
 
334
}
-
 
335
 
-
 
336
 
-
 
337
void
-
 
338
dw_at_ext_lab(ext_lab lab)
-
 
339
{
-
 
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;
-
 
356
}
-
 
357
 
-
 
358
 
-
 
359
void
-
 
360
dw_set_ext_lab(ext_lab lab)
-
 
361
{
-
 
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;
-
 
373
}
-
 
374
 
-
 
375
 
-
 
376
void
-
 
377
dw_at_ext_address(dg_tag dt)
-
 
378
{
-
 
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;
-
 
385
}
-
 
386
 
-
 
387
 
-
 
388
void
-
 
389
set_ext_address(dg_tag dt)
-
 
390
{
-
 
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;
-
 
397
}
-
 
398
 
-
 
399
 
-
 
400
void
-
 
401
dw_at_abstract_lab(dg_tag dt)
-
 
402
{
-
 
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;
-
 
410
}
-
 
411
 
-
 
412
 
-
 
413
void
-
 
414
set_abstract_lab(dg_tag dt)
-
 
415
{
-
 
416
	if (!dt->abstract_lab) {
-
 
417
		dt->abstract_lab = next_dwarf_label();
-
 
418
	}
-
 
419
	out_dwf_label(dt->abstract_lab, 1);
-
 
420
	return;
-
 
421
}
-
 
422
 
-
 
423
 
-
 
424
void
-
 
425
dw_at_string(char* s)
-
 
426
{
-
 
427
	if (!s) {
-
 
428
		s = "";
-
 
429
	}
-
 
430
	out_string(s);
-
 
431
	return;
-
 
432
}
-
 
433
 
-
 
434
 
-
 
435
void
-
 
436
dw_at_form(int f)
-
 
437
{
-
 
438
	out8();
-
 
439
	uleb128((unsigned long)f);
-
 
440
	return;
-
 
441
}
-
 
442
 
-
 
443
 
-
 
444
void
-
 
445
dw_at_data(int n, long d)
-
 
446
{
-
 
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;
-
 
466
}
-
 
467
 
-
 
468
 
-
 
469
void
-
 
470
dw_at_udata(unsigned long n)
-
 
471
{
-
 
472
	out8();
-
 
473
	uleb128(n);
-
 
474
	d_outnl();
-
 
475
	return;
-
 
476
}
-
 
477
 
-
 
478
 
-
 
479
void
-
 
480
dw_at_sdata(long n)
-
 
481
{
-
 
482
	out8();
-
 
483
	sleb128(n);
-
 
484
	d_outnl();
-
 
485
	return;
-
 
486
}
-
 
487
 
-
 
488
 
-
 
489
void
-
 
490
dw_at_flag(int x)
-
 
491
{
-
 
492
	out8();
-
 
493
	outn((long)x);
-
 
494
	d_outnl();
-
 
495
	return;
-
 
496
}
-
 
497
 
-
 
498
 
-
 
499
void
-
 
500
dw_at_decl(short_sourcepos p)
-
 
501
{
-
 
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;
-
 
510
}
-
 
511
 
-
 
512
 
-
 
513
void
-
 
514
dw_no_locate(void)
-
 
515
{
-
 
516
	out8();
-
 
517
	outn((long)0);
-
 
518
	outnl_comment("discarded variable");
-
 
519
	return;
-
 
520
}
-
 
521
 
-
 
522
 
-
 
523
void
-
 
524
dw_locate_offset(int n)
-
 
525
{
-
 
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;
-
 
534
}
-
 
535
 
-
 
536
 
-
 
537
static char *bad_refloc = "unimplemented relative location";
-
 
538
 
-
 
539
static int
-
 
540
refloc_length(exp e, exp id)
-
 
541
{
-
 
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
	}
-
 
563
}
-
 
564
 
-
 
565
 
-
 
566
static void
-
 
567
out_refloc(exp e, exp id)
-
 
568
{
-
 
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
	}
-
 
597
}
-
 
598
 
-
 
599
 
-
 
600
void
-
 
601
dw_locate_reloffset(exp e)
-
 
602
{
509
  int length;
603
	int length;
510
  if (name(e) != ident_tag) {
604
	if (name(e) != ident_tag) {
511
    failer (bad_refloc);
605
		failer(bad_refloc);
512
    return;
606
		return;
513
  }
607
	}
514
  length = refloc_length (bro(son(e)), e);
608
	length = refloc_length(bro(son(e)), e);
515
  out8();
609
	out8();
516
  if (length == 0) {
610
	if (length == 0) {
517
    outn ((long)1);
611
		outn((long)1);
-
 
612
		outs(sep);
518
    outs(sep); outn ((long)DW_OP_nop);
613
		outn((long)DW_OP_nop);
519
  }
-
 
520
  else {
614
	} else {
521
    outn ((long)length);
615
		outn((long)length);
522
    out_refloc (bro(son(e)), e);
616
		out_refloc(bro(son(e)), e);
523
  }
617
	}
524
  d_outnl ();
618
	d_outnl();
525
  return;
619
	return;
526
}
620
}
-
 
621
 
527
 
622
 
-
 
623
void
528
void dw_at_distance
624
dw_at_distance(long lo, long hi)
-
 
625
{
-
 
626
	out16();
529
    PROTO_N ( (lo, hi) )
627
	out_dwf_labdiff(lo, hi);
-
 
628
	d_outnl();
-
 
629
	return;
-
 
630
}
-
 
631
 
-
 
632
 
-
 
633
long last_text_label = 0;
-
 
634
 
-
 
635
long
530
    PROTO_T ( long lo X long hi )
636
set_dw_text_label(void)
531
{
637
{
-
 
638
	if (any_output) {
-
 
639
		last_text_label = next_dwarf_label();
532
  out16 (); out_dwf_labdiff (lo, hi); d_outnl ();
640
		out_dwf_label(last_text_label, 1);
533
  return;
641
		reset_any_output;
-
 
642
	}
-
 
643
	return last_text_label;
534
}
644
}
535
 
645
 
536
long last_text_label = 0;
-
 
537
 
646
 
-
 
647
void
538
long set_dw_text_label
648
out_text_label(long n)
539
    PROTO_Z ()
-
 
540
{
649
{
541
  if (any_output) {
-
 
542
    last_text_label = next_dwarf_label ();
-
 
543
    out_dwf_label (last_text_label, 1);
650
	out_dwf_label(n, 1);
544
    reset_any_output;
651
	last_text_label = n;
545
  }
-
 
546
  return last_text_label;
652
	return;
547
}
653
}
548
 
654
 
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
 
655
 
558
void out_loc_range
656
void
559
    PROTO_N ( (start, end, inclusive) )
-
 
560
    PROTO_T ( long start X long end X int inclusive )
657
out_loc_range(long start, long end, int inclusive)
561
{
658
{
562
  /* for location list */
659
	/* for location list */
-
 
660
	out32();
563
  out32 (); out_dwf_labdiff (dw_text_start, start); d_outnl ();
661
	out_dwf_labdiff(dw_text_start, start);
-
 
662
	d_outnl();
-
 
663
	out32();
564
  out32 (); out_dwf_labdiff (dw_text_start, end);
664
	out_dwf_labdiff(dw_text_start, end);
565
  if (inclusive) {
665
	if (inclusive) {
566
    outs (" + ");
666
		outs(" + ");
567
    outn ((long)min_instr_size);
667
		outn((long)min_instr_size);
568
  }
668
	}
569
  d_outnl ();
669
	d_outnl();
570
  return;
670
	return;
571
}
671
}