drd/tests/tsan_unittest: Avoid that this test reads from uninitialized memory
[valgrind.git] / coregrind / m_debuginfo / readdwarf.c
blob0b1f6535ba50266359d3f8c2090b3b0b88653a62
1 /* -*- mode: C; c-basic-offset: 3; -*- */
3 /*--------------------------------------------------------------------*/
4 /*--- Read DWARF1/2/3/4 debug info. readdwarf.c ---*/
5 /*--------------------------------------------------------------------*/
7 /*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
11 Copyright (C) 2000-2017 Julian Seward
12 jseward@acm.org
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307, USA.
29 The GNU General Public License is contained in the file COPYING.
32 #if defined(VGO_linux) || defined(VGO_darwin) || defined(VGO_solaris)
34 #include "pub_core_basics.h"
35 #include "pub_core_debuginfo.h"
36 #include "pub_core_libcbase.h"
37 #include "pub_core_libcassert.h"
38 #include "pub_core_libcprint.h"
39 #include "pub_core_options.h"
40 #include "pub_core_xarray.h"
41 #include "pub_core_tooliface.h" /* VG_(needs) */
42 #include "priv_misc.h" /* dinfo_zalloc/free/strdup */
43 #include "priv_image.h"
44 #include "priv_d3basics.h"
45 #include "priv_tytypes.h"
46 #include "priv_storage.h"
47 #include "priv_readdwarf.h" /* self */
50 /*------------------------------------------------------------*/
51 /*--- ---*/
52 /*--- Read line number and CFI info from DWARF1, DWARF2 ---*/
53 /*--- and to some extent DWARF3 sections. ---*/
54 /*--- ---*/
55 /*------------------------------------------------------------*/
57 /* The below "safe_*ix" functions allow to resist to malformed dwarf info:
58 if dwarf info contains wrong file or dirname indexes, these are (silently!)
59 ignored. */
61 /* if xa_ix is a valid index in fndn_ix_xa,
62 return the element (i.e. the UInt indexing in fndnpool).
63 If xa_ix is invalid, return 0 (i.e. the "null" element in fndnpool). */
64 static UInt safe_fndn_ix (XArray* fndn_ix_xa, Int xa_ix)
66 if (xa_ix < 0) return 0;
67 if (xa_ix >= VG_(sizeXA) (fndn_ix_xa)) return 0;
68 return *(UInt*)VG_(indexXA) ( fndn_ix_xa, xa_ix );
71 /* if xa_ix is a valid index in dirname_xa,
72 return the element (i.e. the HChar*).
73 If xa_ix is invalid, return NULL. */
74 static const HChar* safe_dirname_ix (XArray* dirname_xa, Int xa_ix)
76 if (xa_ix < 0) return NULL;
77 if (xa_ix >= VG_(sizeXA) (dirname_xa)) return NULL;
78 return *(HChar**)VG_(indexXA) ( dirname_xa, xa_ix );
81 /*------------------------------------------------------------*/
82 /*--- Read DWARF2 format line number info. ---*/
83 /*------------------------------------------------------------*/
85 /* Structure holding info extracted from the a .debug_line
86 section. */
87 typedef struct
89 ULong li_length;
90 UShort li_version;
91 ULong li_header_length;
92 UChar li_min_insn_length;
93 UChar li_max_ops_per_insn;
94 Int li_line_base;
95 UChar li_line_range;
96 UChar li_opcode_base;
98 DebugLineInfo;
100 /* Structure holding additional infos found from a .debug_info
101 * compilation unit block */
102 typedef struct
104 /* Feel free to add more members here if you need ! */
105 DiCursor compdir; /* Compilation directory - points to .debug_info */
106 DiCursor name; /* Main file name - points to .debug_info */
107 ULong stmt_list; /* Offset in .debug_line */
108 Bool dw64; /* 64-bit Dwarf? */
110 UnitInfo;
112 /* Line number opcodes. */
113 enum dwarf_line_number_ops
115 DW_LNS_extended_op = 0,
116 DW_LNS_copy = 1,
117 DW_LNS_advance_pc = 2,
118 DW_LNS_advance_line = 3,
119 DW_LNS_set_file = 4,
120 DW_LNS_set_column = 5,
121 DW_LNS_negate_stmt = 6,
122 DW_LNS_set_basic_block = 7,
123 DW_LNS_const_add_pc = 8,
124 DW_LNS_fixed_advance_pc = 9,
125 /* DWARF 3. */
126 DW_LNS_set_prologue_end = 10,
127 DW_LNS_set_epilogue_begin = 11,
128 DW_LNS_set_isa = 12
131 /* Line number extended opcodes. */
132 enum dwarf_line_number_x_ops
134 DW_LNE_end_sequence = 1,
135 DW_LNE_set_address = 2,
136 DW_LNE_define_file = 3,
137 DW_LNE_set_discriminator = 4
140 typedef struct
142 /* Information for the last statement boundary.
143 * Needed to calculate statement lengths. */
144 Addr last_address;
145 UInt last_file;
146 UInt last_line;
148 Addr address;
149 UInt file;
150 UInt line;
151 UInt column;
152 Int basic_block;
153 UChar end_sequence;
154 } LineSMR;
157 /* FIXME: duplicated in readdwarf3.c */
158 /* Read a 'leb128' and advance *data accordingly. */
159 static ULong step_leb128 ( DiCursor* data, Int sign )
161 ULong result = 0;
162 Int shift = 0;
163 UChar byte;
165 vg_assert(sign == 0 || sign == 1);
167 do {
168 byte = ML_(cur_step_UChar)(data);
169 result |= ((ULong)(byte & 0x7f)) << shift;
170 shift += 7;
172 while (byte & 0x80);
174 if (sign && (shift < 64) && (byte & 0x40))
175 result |= -(1ULL << shift);
177 return result;
180 /* FIXME: duplicated in readdwarf3.c */
181 static ULong step_leb128U( DiCursor* data ) {
182 return step_leb128( data, 0 );
185 /* FIXME: duplicated in readdwarf3.c */
186 static Long step_leb128S( DiCursor* data ) {
187 return step_leb128( data, 1 );
190 /* Read what the DWARF3 spec calls an "initial length field". This
191 uses up either 4 or 12 bytes of the input and produces a 32-bit or
192 64-bit number respectively.
194 Read 32-bit value from p. If it is 0xFFFFFFFF, instead read a
195 64-bit bit value from p+4. This is used in 64-bit dwarf to encode
196 some table lengths. Advance the cursor (p) accordingly.
198 XXX this is a hack: the endianness of the initial length field is
199 specified by the DWARF we're reading. This happens to work only
200 because we don't do cross-arch jitting, hence this code runs on a
201 platform of the same endianness as the DWARF it is reading. Same
202 applies for initial lengths for CIE/FDEs and probably in zillions
203 of other places -- to be precise, exactly the places where
204 binutils/dwarf.c calls byte_get().
206 static
207 ULong step_initial_length_field ( DiCursor* p_img, /*OUT*/Bool* is64 )
209 UInt w32 = ML_(cur_step_UInt)(p_img);
210 if (w32 == 0xFFFFFFFF) {
211 *is64 = True;
212 return ML_(cur_step_ULong)(p_img);
213 } else {
214 *is64 = False;
215 return (ULong)w32;
219 static
220 ULong read_initial_length_field ( DiCursor p_img, /*OUT*/Bool* is64 )
222 /* Something of a roundabout approach .. the modification to p_img
223 is abandoned. */
224 return step_initial_length_field( &p_img, is64 );
228 static LineSMR state_machine_regs;
230 static
231 void reset_state_machine ( void )
233 if (0) VG_(printf)("smr.a := %p (reset)\n", NULL );
234 state_machine_regs.last_address = 0;
235 state_machine_regs.last_file = 1;
236 state_machine_regs.last_line = 1;
237 state_machine_regs.address = 0;
238 state_machine_regs.file = 1;
239 state_machine_regs.line = 1;
240 state_machine_regs.column = 0;
241 state_machine_regs.basic_block = 0;
242 state_machine_regs.end_sequence = 0;
245 ////////////////////////////////////////////////////////////////////
246 ////////////////////////////////////////////////////////////////////
248 /* Handled an extended line op starting at *data, and advance *data
249 accordingly. */
250 static
251 void process_extended_line_op( struct _DebugInfo* di,
252 XArray* fndn_ix_xa,
253 DiCursor* data )
255 UInt len = step_leb128U(data);
256 if (len == 0) {
257 VG_(message)(Vg_UserMsg,
258 "Warning: DWARF2 reader: "
259 "Badly formed extended line op encountered\n");
260 return;
263 UChar op_code = ML_(cur_step_UChar)(data);
264 if (0) VG_(printf)("dwarf2: ext OPC: %d\n", op_code);
266 switch (op_code) {
267 case DW_LNE_end_sequence:
268 if (0) VG_(printf)("1001: si->o %#lx, smr.a %#lx\n",
269 (UWord)di->text_debug_bias,
270 state_machine_regs.address );
271 /* JRS: added for compliance with spec; is pointless due to
272 reset_state_machine below */
273 state_machine_regs.end_sequence = 1;
275 if (state_machine_regs.last_address) {
276 ML_(addLineInfo)(
278 safe_fndn_ix(fndn_ix_xa,
279 state_machine_regs.last_file),
280 di->text_debug_bias + state_machine_regs.last_address,
281 di->text_debug_bias + state_machine_regs.address,
282 state_machine_regs.last_line, 0
285 reset_state_machine();
286 if (di->ddump_line)
287 VG_(printf)(" Extended opcode %d: End of Sequence\n\n",
288 (Int)op_code);
289 break;
291 case DW_LNE_set_address: {
292 Addr adr = ML_(cur_step_Addr)(data);
293 state_machine_regs.address = adr;
294 if (di->ddump_line)
295 VG_(printf)(" Extended opcode %d: set Address to 0x%lx\n",
296 (Int)op_code, (Addr)adr);
297 break;
300 case DW_LNE_define_file: {
301 HChar* name = ML_(cur_step_strdup)(data, "di.pelo.1");
302 UInt fndn_ix = ML_(addFnDn) (di, name, NULL);
303 VG_(addToXA) (fndn_ix_xa, &fndn_ix);
304 ML_(dinfo_free)(name);
305 (void)step_leb128U(data); // ignored: dir index
306 (void)step_leb128U(data); // ignored: mod time
307 (void)step_leb128U(data); // ignored: file size
308 if (di->ddump_line)
309 VG_(printf)(" DWARF2-line: set_address\n");
310 break;
313 case DW_LNE_set_discriminator:
314 (void)step_leb128U(data); // ignored: new 'discriminator' value
315 break;
317 default:
318 if (di->ddump_line)
319 VG_(printf)("process_extended_line_op:default\n");
320 break;
324 ////////////////////////////////////////////////////////////////////
325 ////////////////////////////////////////////////////////////////////
327 /* read a .debug_line section block for a compilation unit
329 * Input: - theBlock must point to the start of the block
330 * for the given compilation unit
331 * - ui contains additional info like the compilation dir
332 * for this unit
334 * Output: - si debug info structures get updated
336 static
337 void read_dwarf2_lineblock ( struct _DebugInfo* di,
338 const UnitInfo* ui,
339 DiCursor theBlock, /* IMAGE */
340 Int noLargerThan )
342 Int i;
343 DebugLineInfo info;
344 Bool is64;
345 XArray* fndn_ix_xa; /* xarray of UInt fndn_ix */
346 UInt fndn_ix;
347 XArray* dirname_xa; /* xarray of const HChar* dirname */
348 const HChar* dirname;
350 DiCursor external = theBlock;
351 DiCursor data = theBlock;
353 /* fndn_ix_xa is an xarray of fndn_ix (indexes in di->fndnpool) which
354 are build from file names harvested from the DWARF2
355 info. Entry [0] is the "null" pool index and is never referred to
356 by the state machine.
358 Similarly, dirname_xa is an xarray of directory names. Entry [0]
359 is also NULL and denotes "we don't know what the path is", since
360 that is different from "the path is the empty string". Unlike
361 the fndn_ix_xa table, the state machine does refer to entry [0],
362 which basically means "." ("the current directory of the
363 compilation", whatever that means, according to the DWARF3
364 spec.)
367 /* Fails due to gcc padding ...
368 vg_assert(sizeof(DWARF2_External_LineInfo)
369 == sizeof(DWARF2_Internal_LineInfo));
372 dirname_xa = VG_(newXA) (ML_(dinfo_zalloc), "di.rd2l.1", ML_(dinfo_free),
373 sizeof(HChar*) );
374 fndn_ix_xa = VG_(newXA) (ML_(dinfo_zalloc), "di.rd2l.2", ML_(dinfo_free),
375 sizeof(UInt) );
377 /* DWARF2 starts numbering filename entries at 1, so we need to
378 add a dummy zeroth entry to the table. */
379 fndn_ix = 0; // 0 is the "null" index in a fixed pool.
380 VG_(addToXA) (fndn_ix_xa, &fndn_ix);
382 if (ML_(cur_is_valid)(ui->compdir))
383 dirname = ML_(addStrFromCursor)(di, ui->compdir);
384 else
385 dirname = ML_(addStr)(di, ".", -1);
386 VG_(addToXA) (dirname_xa, &dirname);
388 info.li_length = step_initial_length_field( &external, &is64 );
389 if (di->ddump_line)
390 VG_(printf)(" Length: %llu\n",
391 info.li_length);
393 /* Check the length of the block. */
394 if (info.li_length > noLargerThan) {
395 ML_(symerr)(di, True,
396 "DWARF line info appears to be corrupt "
397 "- the section is too small");
398 goto out;
401 /* Check its version number. */
402 info.li_version = ML_(cur_step_UShort)(&external);
403 if (di->ddump_line)
404 VG_(printf)(" DWARF Version: %d\n",
405 (Int)info.li_version);
407 if (info.li_version != 2 && info.li_version != 3 && info.li_version != 4) {
408 ML_(symerr)(di, True,
409 "Only DWARF version 2, 3 and 4 line info "
410 "is currently supported.");
411 goto out;
414 info.li_header_length = is64 ? ML_(cur_step_ULong)(&external)
415 : (ULong)(ML_(cur_step_UInt)(&external));
416 if (di->ddump_line)
417 VG_(printf)(" Prologue Length: %llu\n",
418 info.li_header_length);
420 info.li_min_insn_length = ML_(cur_step_UChar)(&external);
421 if (di->ddump_line)
422 VG_(printf)(" Minimum Instruction Length: %d\n",
423 (Int)info.li_min_insn_length);
425 /* We only support machines with one opcode per instruction
426 for now. If we ever want to support VLIW machines there is
427 code to handle multiple opcodes per instruction in the
428 patch attached to BZ#233595.
430 if (info.li_version >= 4) {
431 info.li_max_ops_per_insn = ML_(cur_step_UChar)(&external);
432 if (info.li_max_ops_per_insn != 1) {
433 ML_(symerr)(di, True,
434 "Invalid Maximum Ops Per Insn in line info.");
435 goto out;
437 if (di->ddump_line)
438 VG_(printf)(" Maximum Ops Per Insn: %d\n",
439 (Int)info.li_max_ops_per_insn);
440 } else {
441 info.li_max_ops_per_insn = 1;
444 /* Register is_stmt is not tracked as we are interested only
445 in pc -> line info mapping and not other debugger features. */
446 /* default_is_stmt = */ ML_(cur_step_UChar)(&external);
448 /* JRS: changed (UInt*) to (UChar*) */
449 info.li_line_base = ML_(cur_step_UChar)(&external);
450 info.li_line_base = (Int)(Char)info.li_line_base;
451 if (di->ddump_line)
452 VG_(printf)(" Line Base: %d\n",
453 info.li_line_base);
455 info.li_line_range = ML_(cur_step_UChar)(&external);
456 if (di->ddump_line)
457 VG_(printf)(" Line Range: %d\n",
458 (Int)info.li_line_range);
460 info.li_opcode_base = ML_(cur_step_UChar)(&external);
461 if (di->ddump_line)
462 VG_(printf)(" Opcode Base: %d\n\n",
463 info.li_opcode_base);
465 if (0) VG_(printf)("dwarf2: line base: %d, range %d, opc base: %d\n",
466 (Int)info.li_line_base,
467 (Int)info.li_line_range,
468 (Int)info.li_opcode_base);
470 DiCursor end_of_sequence
471 = ML_(cur_plus)(data, info.li_length + (is64 ? 12 : 4));
473 reset_state_machine();
475 /* Read the contents of the Opcodes table. */
476 DiCursor standard_opcodes = external;
477 if (di->ddump_line) {
478 VG_(printf)(" Opcodes:\n");
479 for (i = 1; i < (Int)info.li_opcode_base; i++) {
480 VG_(printf)(" Opcode %d has %d args\n",
481 i, (Int)ML_(cur_read_UChar)(
482 ML_(cur_plus)(standard_opcodes,
483 (i-1) * sizeof(UChar)) ));
485 VG_(printf)("\n");
487 /* skip over "standard_opcode_lengths" */
488 data = ML_(cur_plus)(standard_opcodes, info.li_opcode_base - 1);
490 /* Read the contents of the Directory table. */
491 if (di->ddump_line)
492 VG_(printf)(" The Directory Table%s\n",
493 ML_(cur_read_UChar)(data) == 0 ? " is empty." : ":" );
495 while (ML_(cur_read_UChar)(data) != 0) {
497 HChar* data_str = ML_(cur_read_strdup)(data, "di.rd2l.1");
498 if (di->ddump_line)
499 VG_(printf)(" %s\n", data_str);
501 /* If data[0] is '/', then 'data' is an absolute path and we
502 don't mess with it. Otherwise, construct the
503 path 'ui->compdir' ++ "/" ++ 'data'. */
505 if (data_str[0] != '/'
506 /* not an absolute path */
507 && ML_(cur_is_valid)(ui->compdir)
508 /* actually got something sensible for compdir */
509 && ML_(cur_strlen)(ui->compdir))
511 HChar* compdir_str = ML_(cur_read_strdup)(ui->compdir, "di.rd2l.1b");
512 SizeT len = VG_(strlen)(compdir_str) + 1 + VG_(strlen)(data_str);
513 HChar *buf = ML_(dinfo_zalloc)("di.rd2l.1c", len + 1);
515 VG_(strcpy)(buf, compdir_str);
516 VG_(strcat)(buf, "/");
517 VG_(strcat)(buf, data_str);
519 dirname = ML_(addStr)(di, buf, len);
520 VG_(addToXA) (dirname_xa, &dirname);
521 if (0) VG_(printf)("rel path %s\n", buf);
522 ML_(dinfo_free)(compdir_str);
523 ML_(dinfo_free)(buf);
524 } else {
525 /* just use 'data'. */
526 dirname = ML_(addStr)(di,data_str,-1);
527 VG_(addToXA) (dirname_xa, &dirname);
528 if (0) VG_(printf)("abs path %s\n", data_str);
531 data = ML_(cur_plus)(data, VG_(strlen)(data_str) + 1);
532 ML_(dinfo_free)(data_str);
535 if (di->ddump_line)
536 VG_(printf)("\n");
538 if (ML_(cur_read_UChar)(data) != 0) {
539 ML_(symerr)(di, True,
540 "can't find NUL at end of DWARF2 directory table");
541 goto out;
543 data = ML_(cur_plus)(data, 1);
545 /* Read the contents of the File Name table. This produces a bunch
546 of fndn_ix in fndn_ix_xa. */
547 if (di->ddump_line) {
548 VG_(printf)(" The File Name Table:\n");
549 VG_(printf)(" Entry Dir Time Size Name\n");
552 i = 1;
553 while (ML_(cur_read_UChar)(data) != 0) {
554 HChar* name = ML_(cur_step_strdup)(&data, "di.rd2l.2");
555 Int diridx = step_leb128U(&data);
556 Int uu_time = step_leb128U(&data); /* unused */
557 Int uu_size = step_leb128U(&data); /* unused */
559 dirname = safe_dirname_ix( dirname_xa, diridx );
560 fndn_ix = ML_(addFnDn) (di, name, dirname);
561 VG_(addToXA) (fndn_ix_xa, &fndn_ix);
562 if (0) VG_(printf)("file %s diridx %d\n", name, diridx );
563 if (di->ddump_line)
564 VG_(printf)(" %d\t%d\t%d\t%d\t%s\n",
565 i, diridx, uu_time, uu_size, name);
566 i++;
567 ML_(dinfo_free)(name);
570 if (di->ddump_line)
571 VG_(printf)("\n");
573 if (ML_(cur_read_UChar)(data) != 0) {
574 ML_(symerr)(di, True,
575 "can't find NUL at end of DWARF2 file name table");
576 goto out;
578 data = ML_(cur_plus)(data, 1);
580 if (di->ddump_line)
581 VG_(printf)(" Line Number Statements:\n");
583 /* Now display the statements. */
585 while (ML_(cur_cmpLT)(data, end_of_sequence)) {
586 UChar op_code = ML_(cur_step_UChar)(&data);
588 if (0) VG_(printf)("dwarf2: OPC: %d\n", op_code);
590 if (op_code >= info.li_opcode_base) {
591 op_code -= info.li_opcode_base;
592 Word adv = (op_code / info.li_line_range)
593 * info.li_min_insn_length;
594 Int advAddr = adv;
595 state_machine_regs.address += adv;
597 if (0) VG_(printf)("smr.a += %#lx\n", (UWord)adv );
598 adv = (op_code % info.li_line_range) + info.li_line_base;
599 if (0) VG_(printf)("1002: di->o %#lx, smr.a %#lx\n",
600 (UWord)di->text_debug_bias,
601 state_machine_regs.address );
602 state_machine_regs.line += adv;
604 if (di->ddump_line)
605 VG_(printf)(" Special opcode %d: advance Address by %d "
606 "to 0x%lx and Line by %d to %d\n",
607 (Int)op_code, advAddr, state_machine_regs.address,
608 (Int)adv, (Int)state_machine_regs.line );
610 /* only add a statement if there was a previous boundary */
611 if (state_machine_regs.last_address) {
612 ML_(addLineInfo)(
614 safe_fndn_ix(fndn_ix_xa,
615 state_machine_regs.last_file),
616 di->text_debug_bias + state_machine_regs.last_address,
617 di->text_debug_bias + state_machine_regs.address,
618 state_machine_regs.last_line,
622 state_machine_regs.last_address = state_machine_regs.address;
623 state_machine_regs.last_file = state_machine_regs.file;
624 state_machine_regs.last_line = state_machine_regs.line;
627 else { /* ! (op_code >= info.li_opcode_base) */
629 switch (op_code) {
630 case DW_LNS_extended_op:
631 process_extended_line_op(di, fndn_ix_xa, &data);
632 break;
634 case DW_LNS_copy:
635 if (0) VG_(printf)("1002: di->o %#lx, smr.a %#lx\n",
636 (UWord)di->text_debug_bias,
637 state_machine_regs.address );
638 /* only add a statement if there was a previous boundary */
639 if (state_machine_regs.last_address) {
640 ML_(addLineInfo)(
642 safe_fndn_ix(fndn_ix_xa,
643 state_machine_regs.last_file),
644 di->text_debug_bias + state_machine_regs.last_address,
645 di->text_debug_bias + state_machine_regs.address,
646 state_machine_regs.last_line,
650 state_machine_regs.last_address = state_machine_regs.address;
651 state_machine_regs.last_file = state_machine_regs.file;
652 state_machine_regs.last_line = state_machine_regs.line;
653 state_machine_regs.basic_block = 0; /* JRS added */
654 if (di->ddump_line)
655 VG_(printf)(" Copy\n");
656 break;
658 case DW_LNS_advance_pc: {
659 UWord adv = info.li_min_insn_length * step_leb128U(&data);
660 state_machine_regs.address += adv;
661 if (0) VG_(printf)("smr.a += %#lx\n", adv );
662 if (di->ddump_line)
663 VG_(printf)(" Advance PC by %lu to 0x%lx\n",
664 adv, state_machine_regs.address);
665 break;
667 case DW_LNS_advance_line: {
668 Word adv = step_leb128S(&data);
669 state_machine_regs.line += adv;
670 if (di->ddump_line)
671 VG_(printf)(" Advance Line by %ld to %d\n",
672 adv, (Int)state_machine_regs.line);
673 break;
675 case DW_LNS_set_file: {
676 Word adv = step_leb128U(&data);
677 state_machine_regs.file = adv;
678 if (di->ddump_line)
679 VG_(printf)(" Set File Name to entry %ld in the "
680 "File Name Table\n", adv);
681 break;
683 case DW_LNS_set_column: {
684 Word adv = step_leb128U(&data);
685 state_machine_regs.column = adv;
686 if (di->ddump_line)
687 VG_(printf)(" Set column to %ld\n", adv);
688 break;
690 case DW_LNS_negate_stmt: {
691 if (di->ddump_line)
692 VG_(printf)(" DWARF2-line: negate_stmt\n");
693 break;
695 case DW_LNS_set_basic_block: {
696 state_machine_regs.basic_block = 1;
697 if (di->ddump_line)
698 VG_(printf)(" DWARF2-line: set_basic_block\n");
699 break;
701 case DW_LNS_const_add_pc: {
702 Word adv = (((255 - info.li_opcode_base) / info.li_line_range)
703 * info.li_min_insn_length);
704 state_machine_regs.address += adv;
705 if (0) VG_(printf)("smr.a += %#lx\n", (UWord)adv );
706 if (di->ddump_line)
707 VG_(printf)(" Advance PC by constant %ld to 0x%lx\n",
708 adv, (Addr)state_machine_regs.address);
709 break;
711 case DW_LNS_fixed_advance_pc: {
712 /* XXX: Need something to get 2 bytes */
713 UWord adv = ML_(cur_step_UShort)(&data);
714 state_machine_regs.address += adv;
715 if (0) VG_(printf)("smr.a += %#lx\n", adv );
716 if (di->ddump_line)
717 VG_(printf)(" DWARF2-line: fixed_advance_pc\n");
718 break;
720 case DW_LNS_set_prologue_end:
721 if (di->ddump_line)
722 VG_(printf)(" DWARF2-line: set_prologue_end\n");
723 break;
725 case DW_LNS_set_epilogue_begin:
726 if (di->ddump_line)
727 VG_(printf)(" DWARF2-line: set_epilogue_begin\n");
728 break;
730 case DW_LNS_set_isa:
731 (void)step_leb128U(&data);
732 if (di->ddump_line)
733 VG_(printf)(" DWARF2-line: set_isa\n");
734 break;
736 default: {
737 Int j;
738 for (j = (Int)ML_(cur_read_UChar)(
739 ML_(cur_plus)(standard_opcodes,
740 (op_code-1) * sizeof(UChar)));
741 j > 0 ; --j) {
742 step_leb128U(&data);
744 if (di->ddump_line)
745 VG_(printf)(" Unknown opcode %d\n", (Int)op_code);
746 break;
748 } /* switch (op_code) */
750 } /* if (op_code >= info.li_opcode_base) */
752 } /* while (data < end_of_sequence) */
754 if (di->ddump_line)
755 VG_(printf)("\n");
757 out:
758 VG_(deleteXA)(dirname_xa);
759 VG_(deleteXA)(fndn_ix_xa);
762 ////////////////////////////////////////////////////////////////////
763 ////////////////////////////////////////////////////////////////////
765 /* Return abbrev for given code
766 * Returned cursor points to the tag
767 * */
768 static DiCursor lookup_abbrev( DiCursor p, ULong acode )
770 while (1) {
771 ULong code = step_leb128U(&p);
772 if (code == acode)
773 return p;
774 (void)step_leb128U(&p); /* skip tag */
775 p = ML_(cur_plus)(p,1); /* skip has_children flag */
776 ULong name;
777 do {
778 name = step_leb128U(&p); /* name */
779 (void)step_leb128U(&p); /* form */
781 while (name != 0); /* until name == form == 0 */
785 /* Read general information for a particular compile unit block in
786 * the .debug_info section. In particular read the name, compdir and
787 * stmt_list needed to parse the line number information.
789 * Input: - unitblock is the start of a compilation
790 * unit block in .debuginfo section
791 * - debugabbrev is start of .debug_abbrev section
792 * - debugstr is start of .debug_str section
793 * - debugstr_alt_img is start of .debug_str section in alt debug file
795 * Output: Fill members of ui pertaining to the compilation unit:
796 * - ui->name is the name of the compilation unit
797 * - ui->compdir is the compilation unit directory
798 * - ui->stmt_list is the offset in .debug_line section
799 * for the dbginfos of this compilation unit
801 * Note : the output strings are not allocated and point
802 * directly to the memory-mapped section.
804 static
805 void read_unitinfo_dwarf2( /*OUT*/UnitInfo* ui,
806 DiCursor unitblock_img,
807 DiCursor debugabbrev_img,
808 DiCursor debugstr_img,
809 DiCursor debugstr_alt_img )
811 UInt acode, abcode;
812 ULong atoffs, blklen;
813 UShort ver;
815 UChar addr_size;
816 DiCursor p = unitblock_img;
817 DiCursor end_img;
818 DiCursor abbrev_img;
820 VG_(memset)( ui, 0, sizeof( UnitInfo ) );
821 ui->stmt_list = -1LL;
823 /* Read the compilation unit header in .debug_info section - See p 70 */
825 /* This block length */
826 blklen = step_initial_length_field( &p, &ui->dw64 );
828 /* version should be 2, 3 or 4 */
829 ver = ML_(cur_step_UShort)(&p);
831 /* get offset in abbrev */
832 atoffs = ui->dw64 ? ML_(cur_step_ULong)(&p)
833 : (ULong)(ML_(cur_step_UInt)(&p));
835 /* Address size */
836 addr_size = ML_(cur_step_UChar)(&p);
838 /* End of this block */
839 end_img = ML_(cur_plus)(unitblock_img, blklen + (ui->dw64 ? 12 : 4));
841 /* Abbreviation data for this block */
842 abbrev_img = ML_(cur_plus)(debugabbrev_img, atoffs);
844 /* Read the compilation unit entry - this is always the first DIE.
845 * See DWARF4 para 7.5. */
846 if (ML_(cur_cmpLT)(p, end_img)) {
847 UInt tag;
849 acode = step_leb128U( &p ); /* abbreviation code */
851 /* Read abbreviation header */
852 abcode = step_leb128U( &abbrev_img ); /* abbreviation code */
853 if ( acode != abcode ) {
854 /* This isn't illegal, but somewhat unlikely. Normally the
855 * first abbrev describes the first DIE, the compile_unit.
856 * But maybe this abbreviation data is shared with another
857 * or it is a NULL entry used for padding. See para 7.5.3. */
858 abbrev_img = lookup_abbrev( ML_(cur_plus)(debugabbrev_img, atoffs),
859 acode );
862 tag = step_leb128U( &abbrev_img );
864 if ( tag != 0x0011 /*TAG_compile_unit*/ )
865 return; /* Not a compile unit (might be partial) or broken DWARF. */
867 /* DW_CHILDREN_yes or DW_CHILDREN_no */
868 abbrev_img = ML_(cur_plus)(abbrev_img, 1);
870 /* And loop on entries */
871 for ( ; ; ) {
872 /* Read entry definition */
873 ULong cval = -1LL; /* Constant value read */
874 DiCursor sval = DiCursor_INVALID; /* String value read */
875 UInt name = step_leb128U( &abbrev_img );
876 UInt form = step_leb128U( &abbrev_img );
877 if (name == 0)
878 break;
880 /* Read data */
881 /* Attributes encoding explained p 71 */
882 if ( form == 0x16 /* FORM_indirect */ )
883 form = step_leb128U( &p );
884 /* Decode form. For most kinds, Just skip the amount of data since
885 we don't use it for now */
886 /* JRS 9 Feb 06: This now handles 64-bit DWARF too. In
887 64-bit DWARF, lineptr (and loclistptr,macptr,rangelistptr
888 classes) use FORM_data8, not FORM_data4. Also,
889 FORM_ref_addr and FORM_strp are 64-bit values, not 32-bit
890 values. */
891 /* TJH 27 Apr 10: in DWARF 4 lineptr (and loclistptr,macptr,
892 rangelistptr classes) use FORM_sec_offset which is 64 bits
893 in 64 bit DWARF and 32 bits in 32 bit DWARF. */
894 /* JRS 20 Apr 11: LLVM-2.9 encodes DW_AT_stmt_list using
895 FORM_addr rather than the FORM_data4 that GCC uses. Hence
896 handle FORM_addr too. */
897 switch( form ) {
898 /* Those cases extract the data properly */
899 case 0x05: /* FORM_data2 */
900 cval = ML_(cur_step_UShort)(&p);
901 break;
902 case 0x06: /* FORM_data4 */
903 cval = ML_(cur_step_UInt)(&p);
904 break;
905 case 0x0e: /* FORM_strp */ /* pointer in .debug_str */
906 /* 2006-01-01: only generate a value if a debug_str
907 section was found) */
908 if (ML_(cur_is_valid)(debugstr_img) && !ui->dw64)
909 sval = ML_(cur_plus)(debugstr_img, ML_(cur_read_UInt)(p));
910 if (ML_(cur_is_valid)(debugstr_img) && ui->dw64)
911 sval = ML_(cur_plus)(debugstr_img, ML_(cur_read_ULong)(p));
912 p = ML_(cur_plus)(p, ui->dw64 ? 8 : 4);
913 break;
914 case 0x08: /* FORM_string */
915 sval = p;
916 p = ML_(cur_plus)(p, ML_(cur_strlen)(p) + 1);
917 break;
918 case 0x0b: /* FORM_data1 */
919 cval = ML_(cur_step_UChar)(&p);
920 break;
921 case 0x17: /* FORM_sec_offset */
922 if (ui->dw64) {
923 cval = ML_(cur_step_ULong)(&p);
924 } else {
925 cval = ML_(cur_step_UInt)(&p);
927 break;
928 case 0x07: /* FORM_data8 */
929 if (ui->dw64) cval = ML_(cur_read_ULong)(p);
930 p = ML_(cur_plus)(p, 8);
931 /* perhaps should assign unconditionally to cval? */
932 break;
933 /* TODO : Following ones just skip data - implement if you need */
934 case 0x01: /* FORM_addr */
935 p = ML_(cur_plus)(p, addr_size);
936 break;
937 case 0x03: /* FORM_block2 */
938 p = ML_(cur_plus)(p, ML_(cur_read_UShort)(p) + 2);
939 break;
940 case 0x04: /* FORM_block4 */
941 p = ML_(cur_plus)(p, ML_(cur_read_UInt)(p) + 4);
942 break;
943 case 0x09: /* FORM_block */ /* fallthrough */
944 case 0x18: { /* FORM_exprloc */
945 ULong block_len = step_leb128U(&p);
946 p = ML_(cur_plus)(p, block_len);
947 break;
949 case 0x0a: /* FORM_block1 */
950 p = ML_(cur_plus)(p, ML_(cur_read_UChar)(p) + 1);
951 break;
952 case 0x0c: /* FORM_flag */
953 p = ML_(cur_plus)(p, 1);
954 break;
955 case 0x0d: /* FORM_sdata */
956 (void)step_leb128S(&p);
957 break;
958 case 0x0f: /* FORM_udata */
959 (void)step_leb128U(&p);
960 break;
961 case 0x10: /* FORM_ref_addr */
962 p = ML_(cur_plus)(p, (ver == 2) ? addr_size
963 : (ui->dw64 ? 8 : 4));
964 break;
965 case 0x11: /* FORM_ref1 */
966 p = ML_(cur_plus)(p, 1);
967 break;
968 case 0x12: /* FORM_ref2 */
969 p = ML_(cur_plus)(p, 2);
970 break;
971 case 0x13: /* FORM_ref4 */
972 p = ML_(cur_plus)(p, 4);
973 break;
974 case 0x14: /* FORM_ref8 */
975 p = ML_(cur_plus)(p, 8);
976 break;
977 case 0x15: /* FORM_ref_udata */
978 (void)step_leb128U(&p);
979 break;
980 case 0x19: /* FORM_flag_present */
981 break;
982 case 0x20: /* FORM_ref_sig8 */
983 p = ML_(cur_plus)(p, 8);
984 break;
985 case 0x1f20: /* FORM_GNU_ref_alt */
986 p = ML_(cur_plus)(p, ui->dw64 ? 8 : 4);
987 break;
988 case 0x1f21: /* FORM_GNU_strp_alt */
989 if (ML_(cur_is_valid)(debugstr_alt_img) && !ui->dw64)
990 sval = ML_(cur_plus)(debugstr_alt_img,
991 ML_(cur_read_UInt)(p));
992 if (ML_(cur_is_valid)(debugstr_alt_img) && ui->dw64)
993 sval = ML_(cur_plus)(debugstr_alt_img,
994 ML_(cur_read_ULong)(p));
995 p = ML_(cur_plus)(p, ui->dw64 ? 8 : 4);
996 break;
998 default:
999 VG_(printf)( "### unhandled dwarf2 abbrev form code 0x%x\n",
1000 form );
1001 break;
1004 /* Now store the members we need in the UnitInfo structure */
1005 if ( tag == 0x0011 /*TAG_compile_unit*/ ) {
1006 if ( name == 0x03 ) ui->name = sval; /* DW_AT_name */
1007 else if ( name == 0x1b ) ui->compdir = sval; /* DW_AT_compdir */
1008 else if ( name == 0x10 ) ui->stmt_list = cval; /* DW_AT_stmt_list */
1011 } /* Just read the first DIE, if that wasn't the compile_unit then
1012 * this might have been a partial unit or broken DWARF info.
1013 * That's enough info for us, and we are not gdb ! */
1017 ////////////////////////////////////////////////////////////////////
1018 ////////////////////////////////////////////////////////////////////
1020 /* Collect the debug info from DWARF3 debugging sections
1021 * of a given module.
1023 * Inputs: given .debug_xxx sections
1024 * Output: update di to contain all the DWARF3 debug infos
1026 void ML_(read_debuginfo_dwarf3)
1027 ( struct _DebugInfo* di,
1028 DiSlice escn_debug_info, /* .debug_info */
1029 DiSlice escn_debug_types, /* .debug_types */
1030 DiSlice escn_debug_abbv, /* .debug_abbrev */
1031 DiSlice escn_debug_line, /* .debug_line */
1032 DiSlice escn_debug_str, /* .debug_str */
1033 DiSlice escn_debug_str_alt ) /* .debug_str */
1035 UnitInfo ui;
1036 UShort ver;
1037 ULong blklen;
1038 Bool blklen_is_64;
1040 /* Make sure we at least have a header for the first block */
1041 if (escn_debug_info.szB < 4) {
1042 ML_(symerr)( di, True,
1043 "Last block truncated in .debug_info; ignoring" );
1044 return;
1047 DiCursor block_img = DiCursor_INVALID;
1048 DiCursor end1_img = ML_(cur_plus)( ML_(cur_from_sli)(escn_debug_info),
1049 escn_debug_info.szB );
1050 Int blklen_len = 0;
1052 /* Iterate on all the blocks we find in .debug_info */
1053 for ( block_img = ML_(cur_from_sli)(escn_debug_info);
1054 ML_(cur_cmpLT)(block_img, ML_(cur_plus)(end1_img, -(DiOffT)4));
1055 block_img = ML_(cur_plus)(block_img, blklen + blklen_len) ) {
1057 /* Read the compilation unit header in .debug_info section - See
1058 p 70 */
1059 /* This block length */
1060 blklen = read_initial_length_field( block_img, &blklen_is_64 );
1061 blklen_len = blklen_is_64 ? 12 : 4;
1063 if (ML_(cur_cmpGT)( ML_(cur_plus)(block_img, blklen + blklen_len),
1064 end1_img )) {
1065 ML_(symerr)( di, True,
1066 "Last block truncated in .debug_info; ignoring" );
1067 return;
1070 /* version should be 2 */
1071 ver = ML_(cur_read_UShort)( ML_(cur_plus)(block_img, blklen_len) );
1072 if ( ver != 2 && ver != 3 && ver != 4 ) {
1073 ML_(symerr)( di, True,
1074 "Ignoring non-Dwarf2/3/4 block in .debug_info" );
1075 continue;
1078 /* Fill ui with offset in .debug_line and compdir */
1079 if (0)
1080 VG_(printf)(
1081 "Reading UnitInfo at 0x%llx.....\n",
1082 (ULong)ML_(cur_minus)( block_img,
1083 ML_(cur_from_sli)(escn_debug_info)) );
1084 read_unitinfo_dwarf2( &ui, block_img,
1085 ML_(cur_from_sli)(escn_debug_abbv),
1086 ML_(cur_from_sli)(escn_debug_str),
1087 ML_(cur_from_sli)(escn_debug_str_alt) );
1088 if (0) {
1089 HChar* str_name = ML_(cur_read_strdup)(ui.name, "di.rdd3.1");
1090 HChar* str_compdir = ML_(cur_read_strdup)(ui.compdir, "di.rdd3.2");
1091 VG_(printf)( " => LINES=0x%llx NAME=%s DIR=%s\n",
1092 ui.stmt_list, str_name, str_compdir );
1093 ML_(dinfo_free)(str_name);
1094 ML_(dinfo_free)(str_compdir);
1097 /* Ignore blocks with no .debug_line associated block */
1098 if ( ui.stmt_list == -1LL )
1099 continue;
1101 if (0) {
1102 HChar* str_name = ML_(cur_read_strdup)(ui.name, "di.rdd3.3");
1103 VG_(printf)("debug_line_sz %llu, ui.stmt_list %llu %s\n",
1104 escn_debug_line.szB, ui.stmt_list, str_name );
1105 ML_(dinfo_free)(str_name);
1108 /* Read the .debug_line block for this compile unit */
1109 read_dwarf2_lineblock(
1110 di, &ui,
1111 ML_(cur_plus)(ML_(cur_from_sli)(escn_debug_line), ui.stmt_list),
1112 escn_debug_line.szB - ui.stmt_list
1118 ////////////////////////////////////////////////////////////////////
1119 ////////////////////////////////////////////////////////////////////
1121 /*------------------------------------------------------------*/
1122 /*--- Read DWARF1 format line number info. ---*/
1123 /*------------------------------------------------------------*/
1125 /* DWARF1 appears to be redundant, but nevertheless the Lahey Fortran
1126 compiler generates it.
1129 /* The following three enums (dwarf_tag, dwarf_form, dwarf_attribute)
1130 are taken from the file include/elf/dwarf.h in the GNU gdb-6.0
1131 sources, which are Copyright 1992, 1993, 1995, 1999 Free Software
1132 Foundation, Inc and naturally licensed under the GNU General Public
1133 License version 2 or later.
1136 /* Tag names and codes. */
1138 enum dwarf_tag {
1139 TAG_padding = 0x0000,
1140 TAG_array_type = 0x0001,
1141 TAG_class_type = 0x0002,
1142 TAG_entry_point = 0x0003,
1143 TAG_enumeration_type = 0x0004,
1144 TAG_formal_parameter = 0x0005,
1145 TAG_global_subroutine = 0x0006,
1146 TAG_global_variable = 0x0007,
1147 /* 0x0008 -- reserved */
1148 /* 0x0009 -- reserved */
1149 TAG_label = 0x000a,
1150 TAG_lexical_block = 0x000b,
1151 TAG_local_variable = 0x000c,
1152 TAG_member = 0x000d,
1153 /* 0x000e -- reserved */
1154 TAG_pointer_type = 0x000f,
1155 TAG_reference_type = 0x0010,
1156 TAG_compile_unit = 0x0011,
1157 TAG_string_type = 0x0012,
1158 TAG_structure_type = 0x0013,
1159 TAG_subroutine = 0x0014,
1160 TAG_subroutine_type = 0x0015,
1161 TAG_typedef = 0x0016,
1162 TAG_union_type = 0x0017,
1163 TAG_unspecified_parameters = 0x0018,
1164 TAG_variant = 0x0019,
1165 TAG_common_block = 0x001a,
1166 TAG_common_inclusion = 0x001b,
1167 TAG_inheritance = 0x001c,
1168 TAG_inlined_subroutine = 0x001d,
1169 TAG_module = 0x001e,
1170 TAG_ptr_to_member_type = 0x001f,
1171 TAG_set_type = 0x0020,
1172 TAG_subrange_type = 0x0021,
1173 TAG_with_stmt = 0x0022,
1175 /* GNU extensions */
1177 TAG_format_label = 0x8000, /* for FORTRAN 77 and Fortran 90 */
1178 TAG_namelist = 0x8001, /* For Fortran 90 */
1179 TAG_function_template = 0x8002, /* for C++ */
1180 TAG_class_template = 0x8003 /* for C++ */
1183 /* Form names and codes. */
1185 enum dwarf_form {
1186 FORM_ADDR = 0x1,
1187 FORM_REF = 0x2,
1188 FORM_BLOCK2 = 0x3,
1189 FORM_BLOCK4 = 0x4,
1190 FORM_DATA2 = 0x5,
1191 FORM_DATA4 = 0x6,
1192 FORM_DATA8 = 0x7,
1193 FORM_STRING = 0x8
1196 /* Attribute names and codes. */
1198 enum dwarf_attribute {
1199 AT_sibling = (0x0010|FORM_REF),
1200 AT_location = (0x0020|FORM_BLOCK2),
1201 AT_name = (0x0030|FORM_STRING),
1202 AT_fund_type = (0x0050|FORM_DATA2),
1203 AT_mod_fund_type = (0x0060|FORM_BLOCK2),
1204 AT_user_def_type = (0x0070|FORM_REF),
1205 AT_mod_u_d_type = (0x0080|FORM_BLOCK2),
1206 AT_ordering = (0x0090|FORM_DATA2),
1207 AT_subscr_data = (0x00a0|FORM_BLOCK2),
1208 AT_byte_size = (0x00b0|FORM_DATA4),
1209 AT_bit_offset = (0x00c0|FORM_DATA2),
1210 AT_bit_size = (0x00d0|FORM_DATA4),
1211 /* (0x00e0|FORM_xxxx) -- reserved */
1212 AT_element_list = (0x00f0|FORM_BLOCK4),
1213 AT_stmt_list = (0x0100|FORM_DATA4),
1214 AT_low_pc = (0x0110|FORM_ADDR),
1215 AT_high_pc = (0x0120|FORM_ADDR),
1216 AT_language = (0x0130|FORM_DATA4),
1217 AT_member = (0x0140|FORM_REF),
1218 AT_discr = (0x0150|FORM_REF),
1219 AT_discr_value = (0x0160|FORM_BLOCK2),
1220 /* (0x0170|FORM_xxxx) -- reserved */
1221 /* (0x0180|FORM_xxxx) -- reserved */
1222 AT_string_length = (0x0190|FORM_BLOCK2),
1223 AT_common_reference = (0x01a0|FORM_REF),
1224 AT_comp_dir = (0x01b0|FORM_STRING),
1225 AT_const_value_string = (0x01c0|FORM_STRING),
1226 AT_const_value_data2 = (0x01c0|FORM_DATA2),
1227 AT_const_value_data4 = (0x01c0|FORM_DATA4),
1228 AT_const_value_data8 = (0x01c0|FORM_DATA8),
1229 AT_const_value_block2 = (0x01c0|FORM_BLOCK2),
1230 AT_const_value_block4 = (0x01c0|FORM_BLOCK4),
1231 AT_containing_type = (0x01d0|FORM_REF),
1232 AT_default_value_addr = (0x01e0|FORM_ADDR),
1233 AT_default_value_data2 = (0x01e0|FORM_DATA2),
1234 AT_default_value_data4 = (0x01e0|FORM_DATA4),
1235 AT_default_value_data8 = (0x01e0|FORM_DATA8),
1236 AT_default_value_string = (0x01e0|FORM_STRING),
1237 AT_friends = (0x01f0|FORM_BLOCK2),
1238 AT_inline = (0x0200|FORM_STRING),
1239 AT_is_optional = (0x0210|FORM_STRING),
1240 AT_lower_bound_ref = (0x0220|FORM_REF),
1241 AT_lower_bound_data2 = (0x0220|FORM_DATA2),
1242 AT_lower_bound_data4 = (0x0220|FORM_DATA4),
1243 AT_lower_bound_data8 = (0x0220|FORM_DATA8),
1244 AT_private = (0x0240|FORM_STRING),
1245 AT_producer = (0x0250|FORM_STRING),
1246 AT_program = (0x0230|FORM_STRING),
1247 AT_protected = (0x0260|FORM_STRING),
1248 AT_prototyped = (0x0270|FORM_STRING),
1249 AT_public = (0x0280|FORM_STRING),
1250 AT_pure_virtual = (0x0290|FORM_STRING),
1251 AT_return_addr = (0x02a0|FORM_BLOCK2),
1252 AT_abstract_origin = (0x02b0|FORM_REF),
1253 AT_start_scope = (0x02c0|FORM_DATA4),
1254 AT_stride_size = (0x02e0|FORM_DATA4),
1255 AT_upper_bound_ref = (0x02f0|FORM_REF),
1256 AT_upper_bound_data2 = (0x02f0|FORM_DATA2),
1257 AT_upper_bound_data4 = (0x02f0|FORM_DATA4),
1258 AT_upper_bound_data8 = (0x02f0|FORM_DATA8),
1259 AT_virtual = (0x0300|FORM_STRING),
1261 /* GNU extensions. */
1263 AT_sf_names = (0x8000|FORM_DATA4),
1264 AT_src_info = (0x8010|FORM_DATA4),
1265 AT_mac_info = (0x8020|FORM_DATA4),
1266 AT_src_coords = (0x8030|FORM_DATA4),
1267 AT_body_begin = (0x8040|FORM_ADDR),
1268 AT_body_end = (0x8050|FORM_ADDR)
1271 /* end of enums taken from gdb-6.0 sources */
1272 #if 0
1273 void ML_(read_debuginfo_dwarf1) (
1274 struct _DebugInfo* di,
1275 UChar* dwarf1d, Int dwarf1d_sz,
1276 UChar* dwarf1l, Int dwarf1l_sz )
1278 UInt stmt_list;
1279 Bool stmt_list_found;
1280 Int die_offset, die_szb, at_offset;
1281 UShort die_kind, at_kind;
1282 UChar* at_base;
1283 HChar* src_filename;
1285 if (0)
1286 VG_(printf)("read_debuginfo_dwarf1 ( %p, %d, %p, %d )\n",
1287 dwarf1d, dwarf1d_sz, dwarf1l, dwarf1l_sz );
1289 /* This loop scans the DIEs. */
1290 die_offset = 0;
1291 while (True) {
1292 if (die_offset >= dwarf1d_sz) break;
1294 die_szb = ML_(read_Int)(dwarf1d + die_offset);
1295 die_kind = ML_(read_UShort)(dwarf1d + die_offset + 4);
1297 /* We're only interested in compile_unit DIEs; ignore others. */
1298 if (die_kind != TAG_compile_unit) {
1299 die_offset += die_szb;
1300 continue;
1303 if (0)
1304 VG_(printf)("compile-unit DIE: offset %d, tag 0x%x, size %d\n",
1305 die_offset, (Int)die_kind, die_szb );
1307 /* We've got a compile_unit DIE starting at (dwarf1d +
1308 die_offset+6). Try and find the AT_name and AT_stmt_list
1309 attributes. Then, finally, we can read the line number info
1310 for this source file. */
1312 /* The next 3 are set as we find the relevant attrs. */
1313 src_filename = NULL;
1314 stmt_list_found = False;
1315 stmt_list = 0;
1317 /* This loop scans the Attrs inside compile_unit DIEs. */
1318 at_base = dwarf1d + die_offset + 6;
1319 at_offset = 0;
1320 while (True) {
1321 if (at_offset >= die_szb-6) break;
1323 at_kind = ML_(read_UShort)(at_base + at_offset);
1324 if (0) VG_(printf)("atoffset %d, attag 0x%x\n",
1325 at_offset, (Int)at_kind );
1326 at_offset += 2; /* step over the attribute itself */
1327 /* We have to examine the attribute to figure out its
1328 length. */
1329 switch (at_kind) {
1330 case AT_stmt_list:
1331 case AT_language:
1332 case AT_sibling:
1333 if (at_kind == AT_stmt_list) {
1334 stmt_list_found = True;
1335 stmt_list = ML_(read_Int)(at_base+at_offset);
1337 at_offset += 4; break;
1338 case AT_high_pc:
1339 case AT_low_pc:
1340 at_offset += sizeof(void*); break;
1341 case AT_name:
1342 case AT_producer:
1343 case AT_comp_dir:
1344 /* Zero terminated string, step over it. */
1345 if (at_kind == AT_name)
1346 src_filename = (HChar *)(at_base + at_offset);
1347 while (at_offset < die_szb-6 && at_base[at_offset] != 0)
1348 at_offset++;
1349 at_offset++;
1350 break;
1351 default:
1352 VG_(printf)("Unhandled DWARF-1 attribute 0x%x\n",
1353 (Int)at_kind );
1354 VG_(core_panic)("Unhandled DWARF-1 attribute");
1355 } /* switch (at_kind) */
1356 } /* looping over attributes */
1358 /* So, did we find the required stuff for a line number table in
1359 this DIE? If yes, read it. */
1360 if (stmt_list_found /* there is a line number table */
1361 && src_filename != NULL /* we know the source filename */
1363 /* Table starts:
1364 Length:
1365 4 bytes, includes the entire table
1366 Base address:
1367 unclear (4? 8?), assuming native pointer size here.
1368 Then a sequence of triples
1369 (source line number -- 32 bits
1370 source line column -- 16 bits
1371 address delta -- 32 bits)
1373 Addr base;
1374 Int len;
1375 HChar* curr_filenm;
1376 UChar* ptr;
1377 UInt prev_line, prev_delta;
1379 curr_filenm = ML_(addStr) ( di, src_filename, -1 );
1380 prev_line = prev_delta = 0;
1382 ptr = dwarf1l + stmt_list;
1383 len = ML_(read_Int)(ptr); ptr += sizeof(Int);
1384 base = ML_(read_Addr)(ptr); ptr += sizeof(void*);
1385 len -= (sizeof(Int) + sizeof(void*));
1386 while (len > 0) {
1387 UInt line;
1388 UShort col;
1389 UInt delta;
1390 line = ML_(read_UInt)(ptr); ptr += sizeof(UInt);
1391 col = ML_(read_UShort)(ptr); ptr += sizeof(UShort);
1392 delta = ML_(read_UInt)(ptr); ptr += sizeof(UInt);
1393 if (0) VG_(printf)("line %d, col %d, delta %d\n",
1394 line, (Int)col, delta );
1395 len -= (sizeof(UInt) + sizeof(UShort) + sizeof(UInt));
1397 if (delta > 0 && prev_line > 0) {
1398 if (0) VG_(printf) (" %d %d-%d\n",
1399 prev_line, prev_delta, delta-1);
1400 ML_(addLineInfo) ( di, curr_filenm, NULL,
1401 base + prev_delta, base + delta,
1402 prev_line, 0 );
1404 prev_line = line;
1405 prev_delta = delta;
1409 /* Move on the next DIE. */
1410 die_offset += die_szb;
1412 } /* Looping over DIEs */
1415 #endif
1417 /*------------------------------------------------------------*/
1418 /*--- Read call-frame info from an .eh_frame section ---*/
1419 /*------------------------------------------------------------*/
1421 /* Sources of info:
1423 The DWARF3 spec, available from http://www.dwarfstd.org/Download.php
1425 This describes how to read CFA data from .debug_frame sections.
1426 So as to maximise everybody's annoyance and confusion, .eh_frame
1427 sections are almost the same as .debug_frame sections, but differ
1428 in a few subtle and ill documented but important aspects.
1430 Generic ELF Specification, sections 7.5 (DWARF Extensions) and 7.6
1431 (Exception Frames), available from
1433 http://www.linux-foundation.org/spec/book/ELF-generic/ELF-generic.html
1435 This really does describe .eh_frame, at least the aspects that
1436 differ from standard DWARF3. It's better than guessing, and
1437 (marginally) more fun than reading the gdb source code.
1440 /* Useful info ..
1442 In general:
1443 gdb-6.3/gdb/dwarf2-frame.c
1445 gdb-6.3/gdb/i386-tdep.c:
1447 DWARF2/GCC uses the stack address *before* the function call as a
1448 frame's CFA. [jrs: I presume this means %esp before the call as
1449 the CFA].
1451 JRS: on amd64, the dwarf register numbering is, as per
1452 gdb-6.3/gdb/amd64-tdep.c and also amd64-abi-0.98.pdf:
1454 0 1 2 3 4 5 6 7
1455 RAX RDX RCX RBX RSI RDI RBP RSP
1457 8 ... 15
1458 R8 ... R15
1460 16 is the return address (RIP)
1461 "The table defines Return Address to have a register number,
1462 even though the address is stored in 0(%rsp) and not in a
1463 physical register."
1465 17 ... 24
1466 XMM0 ... XMM7
1468 25 ... 32
1469 XMM8 ... XMM15
1471 33 ... 40
1472 ST0 ... ST7
1474 41 ... 48
1475 MM0 ... MM7
1477 49 RFLAGS
1478 50,51,52,53,54,55 ES,CS,SS,DS,FS,GS
1479 58 FS.BASE (what's that?)
1480 59 GS.BASE (what's that?)
1481 62 TR (task register)
1482 63 LDTR (LDT register)
1483 64 MXCSR
1484 65 FCW (x87 control word)
1485 66 FSW (x86 status word)
1487 On x86 I cannot find any documentation. It _appears_ to be the
1488 actual instruction encoding, viz:
1490 0 1 2 3 4 5 6 7
1491 EAX ECX EDX EBX ESP EBP ESI EDI
1493 8 is the return address (EIP) */
1496 /* Comments re DW_CFA_set_loc, 16 Nov 06.
1498 JRS:
1499 Someone recently sent me a libcrypto.so.0.9.8 as distributed with
1500 Ubuntu of some flavour, compiled with gcc 4.1.2 on amd64. It
1501 causes V's CF reader to complain a lot:
1503 >> --19976-- DWARF2 CFI reader: unhandled CFI instruction 0:24
1504 >> --19976-- DWARF2 CFI reader: unhandled CFI instruction 0:24
1505 >> --19976-- DWARF2 CFI reader: unhandled CFI instruction 0:24
1506 >> --19976-- DWARF2 CFI reader: unhandled CFI instruction 0:24
1507 >> --19976-- DWARF2 CFI reader: unhandled CFI instruction 0:48
1508 >> --19976-- DWARF2 CFI reader: unhandled CFI instruction 0:24
1510 After chasing this around a bit it seems that the CF bytecode
1511 parser lost sync at a DW_CFA_set_loc, which has a single argument
1512 denoting an address.
1514 As it stands that address is extracted by read_Addr(). On amd64
1515 that just fetches 8 bytes regardless of anything else.
1517 read_encoded_Addr() is more sophisticated. This appears to take
1518 into account some kind of encoding flag. When I replace the uses
1519 of read_Addr by read_encoded_Addr for DW_CFA_set_loc, the
1520 complaints go away, there is no loss of sync, and the parsed CF
1521 instructions are the same as shown by readelf --debug-dump=frames.
1523 So it seems a plausible fix. The problem is I looked in the DWARF3
1524 spec and completely failed to figure out whether or not the arg to
1525 DW_CFA_set_loc is supposed to be encoded in a way suitable for
1526 read_encoded_Addr, nor for that matter any description of what it
1527 is that read_encoded_Addr is really decoding.
1529 TomH:
1530 The problem is that the encoding is not standard - the eh_frame
1531 section uses the same encoding as the dwarf_frame section except
1532 for a few small changes, and this is one of them. So this is not
1533 something the DWARF standard covers.
1535 There is an augmentation string to indicate what is going on though
1536 so that programs can recognise it.
1538 What we are doing seems to match what gdb 6.5 and libdwarf 20060614
1539 do though. I'm not sure about readelf though.
1541 (later): Well dwarfdump barfs on it:
1543 dwarfdump ERROR: dwarf_get_fde_info_for_reg:
1544 DW_DLE_DF_FRAME_DECODING_ERROR(193) (193)
1546 I've looked at binutils as well now, and the code in readelf agrees
1547 with your patch - ie it treats set_loc as having an encoded address
1548 if there is a zR augmentation indicating an encoding.
1550 Quite why gdb and libdwarf don't understand this is an interesting
1551 question...
1553 Final outcome: all uses of read_Addr were replaced by
1554 read_encoded_Addr. A new type AddressDecodingInfo was added to
1555 make it relatively clean to plumb through the extra info needed by
1556 read_encoded_Addr.
1559 /* More badness re address encoding, 12 Jan 07.
1561 Most gcc provided CIEs have a "zR" augmentation, which means they
1562 supply their own address encoding, and that works fine. However,
1563 some icc9 supplied CIEs have no augmentation, which means they use
1564 the default_Addr_encoding(). That says to use a machine-word sized
1565 value, literally unmodified.
1567 Since .so's are, in general, relocated when loaded, having absolute
1568 addresses in the CFI data makes no sense when read_encoded_Addr is
1569 used to find the initial location for a FDE. The resulting saga:
1571 TomH:
1572 > I'm chasing a stack backtrace failure for an amd64 .so which was
1573 > created I believe by icc 9.1. After a while I wound up looking at
1574 > this: (readdwarf.c)
1576 > 5083 tom static UChar default_Addr_encoding ( void )
1577 > 3584 tom {
1578 > 3584 tom switch (sizeof(Addr)) {
1579 > 3584 tom case 4: return DW_EH_PE_udata4;
1580 > 3584 tom case 8: return DW_EH_PE_udata8;
1581 > 3584 tom default: vg_assert(0);
1582 > 3584 tom }
1583 > 3584 tom }
1585 > If a CIE does not have an "augmentation string" (typically "zR") then
1586 > addresses are decoded as described by default_Addr_encoding. If there
1587 > is an 'R' in the augmentation string then the encoding to use
1588 > is specified by the CIE itself, which works fine with GCC compiled code
1589 > since that always appears to specify zR.
1591 Correct.
1593 > Problem is this .so has no augmentation string and so uses the
1594 > default encoding, viz DW_EH_PE_udata8. That appears to mean
1595 > "read a 64 bit number" and use that as-is (for the starting value
1596 > of the program counter when running the CFA program).
1598 Strictly speaking the default is DW_EH_PE_absptr, but that amounts
1599 to either udata4 or udata8 depending on the platform's pointer size
1600 which is a shortcut I used.
1602 > For this .so that gives nonsense (very small) PCs which are later
1603 > rejected by the sanity check which ensures PC ranges fall inside
1604 > the mapped text segment. It seems like the .so expects to have the
1605 > start VMA of the text segment added on. This would correspond to
1607 > static UChar default_Addr_encoding ( void )
1609 > switch (sizeof(Addr)) {
1610 > case 4: return DW_EH_PE_textrel + DW_EH_PE_udata4;
1611 > case 8: return DW_EH_PE_textrel + DW_EH_PE_udata8;
1612 > default: vg_assert(0);
1616 The problem you're seeing is that you have absolute pointers inside
1617 a shared library, which obviously makes little sense on the face of
1618 things as how would the linker know where the library will be
1619 loaded?
1621 The answer of course is that it doesn't, so if it points absolute
1622 pointers in the frame unwind data is has to include relocations for
1623 them, and I'm betting that if you look at the relocations in the
1624 library you will there are some for that data.
1626 That is fine of course when ld.so maps the library - it will
1627 relocate the eh_frame data as it maps it (or prelinking will
1628 already have done so) and when the g++ exception code kicks in and
1629 unwinds the stack it will see relocated data.
1631 We of course are mapping the section from the ELF file ourselves
1632 and are not applying the relocations, hence the problem you are
1633 seeing.
1635 Strictly speaking we should apply the relocations but the cheap
1636 solution is essentially to do what you've done - strictly speaking
1637 you should adjust by the difference between the address the library
1638 was linked for and the address it has been loaded at, but a shared
1639 library will normally be linked for address zero I believe. It's
1640 possible that prelinking might change that though?
1642 JRS:
1643 That all syncs with what I am seeing.
1645 So what I am inclined to do is:
1647 - Leave default_Addr_encoding as it is
1649 - Change read_encoded_Addr's handling of "case DW_EH_PE_absptr" so
1650 it sets base to, as you say, the difference between the address
1651 the library was linked for and the address it has been loaded at
1652 (== the SegInfo's text_bias)
1654 Does that sound sane? I think it should even handle the prelinked
1655 case.
1657 (JRS, later)
1659 Hmm. Plausible as it sounds, it doesn't work. It now produces
1660 bogus backtraces for locations inside the (statically linked)
1661 memcheck executable.
1663 Besides, there are a couple of other places where read_encoded_Addr
1664 is used -- one of which is used to establish the length of the
1665 address range covered by the current FDE:
1667 fde_arange = read_encoded_Addr(&nbytes, &adi, data);
1669 and it doesn't seem to make any sense for read_encoded_Addr to add
1670 on the text segment bias in that context. The DWARF3 spec says
1671 that both the initial_location and address_range (length) fields
1672 are encoded the same way ("target address"), so it is unclear at
1673 what stage in the process it would be appropriate to relocate the
1674 former but not the latter.
1676 One unprincipled kludge that does work is the following: just
1677 before handing one of the address range fragments off to
1678 ML_(addDiCfSI) for permanent storage, check its start address. If
1679 that is very low (less than 2 M), and is far below the mapped text
1680 segment, and adding the text bias would move the fragment entirely
1681 inside the mapped text segment, then do so. A kind of kludged
1682 last-minute relocation, if you like.
1684 12 Jan 07: committing said kludge (see kludge_then_addDiCfSI). If
1685 the situation clarifies, it can easily enough be backed out and
1686 replaced by a better fix.
1689 /* --------------- Decls --------------- */
1691 #if defined(VGP_x86_linux) || defined(VGP_x86_solaris)
1692 # define FP_REG 5
1693 # define SP_REG 4
1694 # define RA_REG_DEFAULT 8
1695 #elif defined(VGP_amd64_linux) || defined(VGP_amd64_solaris)
1696 # define FP_REG 6
1697 # define SP_REG 7
1698 # define RA_REG_DEFAULT 16
1699 #elif defined(VGP_ppc32_linux)
1700 # define FP_REG 1
1701 # define SP_REG 1
1702 # define RA_REG_DEFAULT 65
1703 #elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
1704 # define FP_REG 1
1705 # define SP_REG 1
1706 # define RA_REG_DEFAULT 65
1707 #elif defined(VGP_arm_linux)
1708 # define FP_REG 12
1709 # define SP_REG 13
1710 # define RA_REG_DEFAULT 14
1711 #elif defined(VGP_arm64_linux)
1712 # define FP_REG 29
1713 # define SP_REG 31
1714 # define RA_REG_DEFAULT 30
1715 #elif defined(VGP_x86_darwin)
1716 # define FP_REG 5
1717 # define SP_REG 4
1718 # define RA_REG_DEFAULT 8
1719 #elif defined(VGP_amd64_darwin)
1720 # define FP_REG 6
1721 # define SP_REG 7
1722 # define RA_REG_DEFAULT 16
1723 #elif defined(VGP_s390x_linux)
1724 # define FP_REG 11 // sometimes s390 has a frame pointer in r11
1725 # define SP_REG 15 // stack is always r15
1726 # define RA_REG_DEFAULT 14 // the return address is in r14
1727 #elif defined(VGP_mips32_linux)
1728 # define FP_REG 30
1729 # define SP_REG 29
1730 # define RA_REG_DEFAULT 31
1731 #elif defined(VGP_mips64_linux)
1732 # define FP_REG 30
1733 # define SP_REG 29
1734 # define RA_REG_DEFAULT 31
1735 #else
1736 # error "Unknown platform"
1737 #endif
1739 /* The number of regs we are prepared to unwind. The number for
1740 arm-linux (320) seems ludicrously high, but the ARM IHI 0040A page
1741 7 (DWARF for the ARM Architecture) specifies that values up to 320
1742 might exist, for Neon/VFP-v3. */
1743 #if defined(VGP_ppc32_linux) || defined(VGP_ppc64be_linux) \
1744 || defined(VGP_ppc64le_linux) || defined(VGP_mips32_linux) \
1745 || defined(VGP_mips64_linux)
1746 # define N_CFI_REGS 72
1747 #elif defined(VGP_arm_linux)
1748 # define N_CFI_REGS 320
1749 #elif defined(VGP_arm64_linux)
1750 # define N_CFI_REGS 128
1751 #elif defined(VGP_s390x_linux)
1752 # define N_CFI_REGS 66
1753 #else
1754 # define N_CFI_REGS 20
1755 #endif
1757 /* Instructions for the automaton */
1758 enum dwarf_cfa_primary_ops
1760 DW_CFA_use_secondary = 0,
1761 DW_CFA_advance_loc = 1,
1762 DW_CFA_offset = 2,
1763 DW_CFA_restore = 3
1766 enum dwarf_cfa_secondary_ops
1768 DW_CFA_nop = 0x00,
1769 DW_CFA_set_loc = 0x01,
1770 DW_CFA_advance_loc1 = 0x02,
1771 DW_CFA_advance_loc2 = 0x03,
1772 DW_CFA_advance_loc4 = 0x04,
1773 DW_CFA_offset_extended = 0x05,
1774 DW_CFA_restore_extended = 0x06,
1775 DW_CFA_undefined = 0x07,
1776 DW_CFA_same_value = 0x08,
1777 DW_CFA_register = 0x09,
1778 DW_CFA_remember_state = 0x0a,
1779 DW_CFA_restore_state = 0x0b,
1780 DW_CFA_def_cfa = 0x0c,
1781 DW_CFA_def_cfa_register = 0x0d,
1782 DW_CFA_def_cfa_offset = 0x0e,
1783 DW_CFA_def_cfa_expression = 0x0f, /* DWARF3 only */
1784 DW_CFA_expression = 0x10, /* DWARF3 only */
1785 DW_CFA_offset_extended_sf = 0x11, /* DWARF3 only */
1786 DW_CFA_def_cfa_sf = 0x12, /* DWARF3 only */
1787 DW_CFA_def_cfa_offset_sf = 0x13, /* DWARF3 only */
1788 DW_CFA_val_offset = 0x14, /* DWARF3 only */
1789 DW_CFA_val_offset_sf = 0x15, /* DWARF3 only */
1790 DW_CFA_val_expression = 0x16, /* DWARF3 only */
1791 DW_CFA_lo_user = 0x1c,
1792 DW_CFA_GNU_window_save = 0x2d, /* GNU extension */
1793 DW_CFA_GNU_args_size = 0x2e, /* GNU extension */
1794 DW_CFA_GNU_negative_offset_extended = 0x2f, /* GNU extension */
1795 DW_CFA_ORCL_arg_loc = 0x30, /* Oracle extension */
1796 DW_CFA_hi_user = 0x3f
1799 #define DW_EH_PE_absptr 0x00
1800 #define DW_EH_PE_omit 0xff
1802 #define DW_EH_PE_uleb128 0x01
1803 #define DW_EH_PE_udata2 0x02
1804 #define DW_EH_PE_udata4 0x03
1805 #define DW_EH_PE_udata8 0x04
1806 #define DW_EH_PE_sleb128 0x09
1807 #define DW_EH_PE_sdata2 0x0A
1808 #define DW_EH_PE_sdata4 0x0B
1809 #define DW_EH_PE_sdata8 0x0C
1810 #define DW_EH_PE_signed 0x08
1812 #define DW_EH_PE_pcrel 0x10
1813 #define DW_EH_PE_textrel 0x20
1814 #define DW_EH_PE_datarel 0x30
1815 #define DW_EH_PE_funcrel 0x40
1816 #define DW_EH_PE_aligned 0x50
1818 #define DW_EH_PE_indirect 0x80
1821 /* RegRule and UnwindContext are used temporarily to do the unwinding.
1822 The result is then summarised into a sequence of CfiSIs, if
1823 possible. UnwindContext effectively holds the state of the
1824 abstract machine whilst it is running.
1826 The CFA can either be a signed offset from a register,
1827 or an expression:
1829 CFA = cfa_reg + cfa_off when UnwindContext.cfa_is_regoff==True
1830 | [[ cfa_expr_id ]]
1832 When .cfa_is_regoff == True, cfa_expr_id must be zero
1833 When .cfa_is_regoff == False, cfa_reg must be zero
1834 and cfa_off must be zero
1836 RegRule describes, for each register, how to get its
1837 value in the previous frame, where 'cfa' denotes the cfa
1838 for the frame as a whole:
1840 RegRule = RR_Undef -- undefined
1841 | RR_Same -- same as in previous frame
1842 | RR_CFAOff arg -- is at * ( cfa + arg )
1843 | RR_CFAValOff arg -- is ( cfa + arg )
1844 | RR_Reg arg -- is in register 'arg'
1845 | RR_Expr arg -- is at * [[ arg ]]
1846 | RR_ValExpr arg -- is [[ arg ]]
1848 Note that RR_Expr is redundant since the same can be represented
1849 using RR_ValExpr with an explicit dereference (CfiExpr_Deref) at
1850 the outermost level.
1852 All expressions are stored in exprs in the containing
1853 UnwindContext. Since the UnwindContext gets reinitialised for each
1854 new FDE, summarise_context needs to copy out any expressions it
1855 wants to keep into the cfsi_exprs field of the containing SegInfo.
1857 typedef
1858 struct {
1859 enum { RR_Undef, RR_Same, RR_CFAOff, RR_CFAValOff,
1860 RR_Reg, /*RR_Expr,*/ RR_ValExpr } tag;
1861 /* meaning: int offset for CFAoff/CFAValOff
1862 reg # for Reg
1863 expr index for Expr/ValExpr */
1864 Int arg;
1866 RegRule;
1868 static void ppRegRule ( const XArray* exprs, const RegRule* rrule )
1870 vg_assert(exprs);
1871 switch (rrule->tag) {
1872 case RR_Undef: VG_(printf)("u "); break;
1873 case RR_Same: VG_(printf)("s "); break;
1874 case RR_CFAOff: VG_(printf)("c%d ", rrule->arg); break;
1875 case RR_CFAValOff: VG_(printf)("v%d ", rrule->arg); break;
1876 case RR_Reg: VG_(printf)("dwReg%d ", rrule->arg); break;
1877 case RR_ValExpr: VG_(printf)("ve{");
1878 ML_(ppCfiExpr)( exprs, rrule->arg );
1879 VG_(printf)("} ");
1880 break;
1881 default: VG_(core_panic)("ppRegRule");
1886 /* Size of the stack of register unwind rules. This is only
1887 exceedingly rarely used, so a stack of size 1 should actually work
1888 with almost all compiler-generated CFA. */
1889 #define N_RR_STACK 4
1891 typedef
1892 struct {
1893 /* Read-only fields (set by the CIE) */
1894 Int code_a_f;
1895 Int data_a_f;
1896 Addr initloc;
1897 Int ra_reg;
1898 /* The rest of these fields can be modified by
1899 run_CF_instruction. */
1900 /* The LOC entry */
1901 Addr loc;
1902 /* We need a stack of these in order to handle
1903 DW_CFA_{remember,restore}_state. */
1904 struct UnwindContextState {
1905 /* The CFA entry. This can be either reg+/-offset or an expr. */
1906 Bool cfa_is_regoff; /* True=>is reg+offset; False=>is expr */
1907 Int cfa_reg;
1908 Int cfa_off; /* in bytes */
1909 Int cfa_expr_ix; /* index into cfa_exprs */
1910 /* Register unwind rules. */
1911 RegRule reg[N_CFI_REGS];
1913 state[N_RR_STACK];
1914 Int state_sp; /* 0 <= state_sp < N_RR_STACK; points at the
1915 currently-in-use rule set. */
1916 /* array of CfiExpr, shared by reg[] and cfa_expr_ix */
1917 XArray* exprs;
1919 UnwindContext;
1921 static void ppUnwindContext ( const UnwindContext* ctx )
1923 Int j, i;
1924 VG_(printf)("0x%llx: ", (ULong)ctx->loc);
1925 for (j = 0; j <= ctx->state_sp; j++) {
1926 const struct UnwindContextState* ctxs = &ctx->state[j];
1927 VG_(printf)("%s[%d]={ ", j > 0 ? " " : "", j);
1928 if (ctxs->cfa_is_regoff) {
1929 VG_(printf)("%d(r%d) ", ctxs->cfa_off, ctxs->cfa_reg);
1930 } else {
1931 vg_assert(ctx->exprs);
1932 VG_(printf)("{");
1933 ML_(ppCfiExpr)( ctx->exprs, ctxs->cfa_expr_ix );
1934 VG_(printf)("} ");
1936 VG_(printf)("{ ");
1937 for (i = 0; i < N_CFI_REGS; i++)
1938 ppRegRule(ctx->exprs, &ctxs->reg[i]);
1939 VG_(printf)("}");
1941 VG_(printf)("\n");
1944 static void initUnwindContext ( /*OUT*/UnwindContext* ctx )
1946 Int j, i;
1947 VG_(memset)(ctx, 0, sizeof(*ctx));
1948 /* ctx->code_a_f = 0;
1949 ctx->data_a_f = 0;
1950 ctx->initloc = 0; */
1951 ctx->ra_reg = RA_REG_DEFAULT;
1952 /* ctx->loc = 0;
1953 ctx->exprs = NULL;
1954 ctx->state_sp = 0; */
1955 for (j = 0; j < N_RR_STACK; j++) {
1956 ctx->state[j].cfa_is_regoff = True;
1957 /* ctx->state[j].cfa_reg = 0;
1958 ctx->state[j].cfa_off = 0;
1959 ctx->state[j].cfa_expr_ix = 0; */
1960 for (i = 0; i < N_CFI_REGS; i++) {
1961 if (RR_Undef != 0)
1962 ctx->state[j].reg[i].tag = RR_Undef;
1963 /* ctx->state[j].reg[i].arg = 0; */
1965 # if defined(VGA_arm)
1966 /* All callee-saved registers (or at least the ones we are
1967 summarising for) should start out as RR_Same, on ARM. */
1968 ctx->state[j].reg[11].tag = RR_Same;
1969 /* ctx->state[j].reg[13].tag = RR_Same; */
1970 ctx->state[j].reg[14].tag = RR_Same;
1971 ctx->state[j].reg[12].tag = RR_Same;
1972 ctx->state[j].reg[7].tag = RR_Same;
1973 /* this can't be right though: R12 (IP) isn't callee saved. */
1974 # elif defined(VGA_arm64)
1975 /* Callee-saved registers (that we are interested in) should
1976 start out as RR_Same. */
1977 ctx->state[j].reg[29/*FP*/].tag = RR_Same;
1978 ctx->state[j].reg[30/*LR*/].tag = RR_Same;
1979 # endif
1984 /* A structure which holds information needed by read_encoded_Addr().
1986 typedef
1987 struct {
1988 UChar encoding;
1989 DiCursor ehframe_image;
1990 Addr ehframe_avma;
1991 Addr text_bias;
1992 Addr got_avma;
1994 AddressDecodingInfo;
1997 /* ------------ Deal with summary-info records ------------ */
1999 /* --------------- Summarisation --------------- */
2001 /* Forward */
2002 static
2003 Int copy_convert_CfiExpr_tree ( XArray* dst, const UnwindContext* srcuc,
2004 Int nd );
2006 /* Summarise ctx into si, if possible. Returns True if successful.
2007 This is taken to be just after ctx's loc advances; hence the
2008 summary is up to but not including the current loc. This works
2009 on both x86 and amd64.
2011 static Bool summarise_context(/*OUT*/Addr* base,
2012 /*OUT*/UInt* len,
2013 /*OUT*/DiCfSI_m* si_m,
2014 Addr loc_start,
2015 const UnwindContext* ctx,
2016 DebugInfo* debuginfo )
2018 Int why = 0;
2019 const struct UnwindContextState* ctxs;
2021 *base = 0;
2022 *len = 0;
2023 VG_(bzero_inline)(si_m, sizeof(*si_m));
2025 /*const*/ Bool is_s390x_linux = False;
2026 # if defined(VGP_s390x_linux)
2027 is_s390x_linux = True;
2028 # endif
2030 /* Guard against obviously stupid settings of the reg-rule stack
2031 pointer. */
2032 if (ctx->state_sp < 0) { why = 8; goto failed; }
2033 if (ctx->state_sp >= N_RR_STACK) { why = 9; goto failed; }
2034 ctxs = &ctx->state[ctx->state_sp];
2036 /* First, summarise the method for generating the CFA */
2037 if (!ctxs->cfa_is_regoff) {
2038 /* it was set by DW_CFA_def_cfa_expression; try to convert */
2039 XArray *src, *dst;
2040 Int conv;
2041 src = ctx->exprs;
2042 dst = debuginfo->cfsi_exprs;
2043 if (src && (VG_(sizeXA)(src) > 0) && (!dst)) {
2044 dst = VG_(newXA)( ML_(dinfo_zalloc), "di.ccCt.1", ML_(dinfo_free),
2045 sizeof(CfiExpr) );
2046 debuginfo->cfsi_exprs = dst;
2048 conv = copy_convert_CfiExpr_tree
2049 ( dst, ctx, ctxs->cfa_expr_ix );
2050 vg_assert(conv >= -1);
2051 if (conv == -1) { why = 6; goto failed; }
2052 si_m->cfa_how = CFIC_EXPR;
2053 si_m->cfa_off = conv;
2054 if (0 && debuginfo->ddump_frames)
2055 ML_(ppCfiExpr)(dst, conv);
2057 else
2058 if (ctxs->cfa_is_regoff && ctxs->cfa_reg == SP_REG) {
2059 si_m->cfa_off = ctxs->cfa_off;
2060 # if defined(VGA_x86) || defined(VGA_amd64) || defined(VGA_s390x) \
2061 || defined(VGA_mips32) || defined(VGA_mips64)
2062 si_m->cfa_how = CFIC_IA_SPREL;
2063 # elif defined(VGA_arm)
2064 si_m->cfa_how = CFIC_ARM_R13REL;
2065 # elif defined(VGA_arm64)
2066 si_m->cfa_how = CFIC_ARM64_SPREL;
2067 # else
2068 si_m->cfa_how = 0; /* invalid */
2069 # endif
2071 else
2072 if (ctxs->cfa_is_regoff && ctxs->cfa_reg == FP_REG) {
2073 si_m->cfa_off = ctxs->cfa_off;
2074 # if defined(VGA_x86) || defined(VGA_amd64) || defined(VGA_s390x) \
2075 || defined(VGA_mips32) || defined(VGA_mips64)
2076 si_m->cfa_how = CFIC_IA_BPREL;
2077 # elif defined(VGA_arm)
2078 si_m->cfa_how = CFIC_ARM_R12REL;
2079 # elif defined(VGA_arm64)
2080 si_m->cfa_how = CFIC_ARM64_X29REL;
2081 # else
2082 si_m->cfa_how = 0; /* invalid */
2083 # endif
2085 # if defined(VGA_arm)
2086 else
2087 if (ctxs->cfa_is_regoff && ctxs->cfa_reg == 11/*??_REG*/) {
2088 si_m->cfa_how = CFIC_ARM_R11REL;
2089 si_m->cfa_off = ctxs->cfa_off;
2091 else
2092 if (ctxs->cfa_is_regoff && ctxs->cfa_reg == 7/*??_REG*/) {
2093 si_m->cfa_how = CFIC_ARM_R7REL;
2094 si_m->cfa_off = ctxs->cfa_off;
2096 # elif defined(VGA_arm64)
2097 // do we need any arm64 specifics here?
2098 # endif
2099 else {
2100 why = 1;
2101 goto failed;
2104 # define SUMMARISE_HOW(_how, _off, _ctxreg) \
2105 _how = CFIR_UNKNOWN; /* install safe initial values */ \
2106 _off = 0; \
2107 switch (_ctxreg.tag) { \
2108 case RR_Undef: \
2109 _how = CFIR_UNKNOWN; _off = 0; break; \
2110 case RR_Same: \
2111 _how = CFIR_SAME; _off = 0; break; \
2112 case RR_CFAOff: \
2113 _how = CFIR_MEMCFAREL; _off = _ctxreg.arg; break; \
2114 case RR_CFAValOff: \
2115 _how = CFIR_CFAREL; _off = _ctxreg.arg; break; \
2116 case RR_ValExpr: { \
2117 XArray *src, *dst; \
2118 Int conv; \
2119 src = ctx->exprs; \
2120 dst = debuginfo->cfsi_exprs; \
2121 if (src && (VG_(sizeXA)(src) > 0) && (!dst)) { \
2122 dst = VG_(newXA)( ML_(dinfo_zalloc), \
2123 "di.ccCt.2", \
2124 ML_(dinfo_free), \
2125 sizeof(CfiExpr) ); \
2126 debuginfo->cfsi_exprs = dst; \
2128 conv = copy_convert_CfiExpr_tree \
2129 ( dst, ctx, _ctxreg.arg ); \
2130 vg_assert(conv >= -1); \
2131 if (conv == -1) { why = 7; goto failed; } \
2132 _how = CFIR_EXPR; \
2133 _off = conv; \
2134 if (0 && debuginfo->ddump_frames) \
2135 ML_(ppCfiExpr)(dst, conv); \
2136 break; \
2138 case RR_Reg: \
2139 if (is_s390x_linux) { \
2140 if (_ctxreg.arg == 16/*dwarf reg 16 is %f0*/) { \
2141 _how = CFIR_S390X_F0; \
2142 _off = 0; \
2143 break; \
2145 else if (_ctxreg.arg == 17/*dwarf reg 17 is %f2*/) { \
2146 _how = CFIR_S390X_F2; \
2147 _off = 0; \
2148 break; \
2150 else if (_ctxreg.arg == 18/*dwarf reg 18 is %f4*/) { \
2151 _how = CFIR_S390X_F4; \
2152 _off = 0; \
2153 break; \
2155 else if (_ctxreg.arg == 19/*dwarf reg 19 is %f6*/) { \
2156 _how = CFIR_S390X_F6; \
2157 _off = 0; \
2158 break; \
2160 else if (_ctxreg.arg == 20/*dwarf reg 20 is %f1*/) { \
2161 _how = CFIR_S390X_F1; \
2162 _off = 0; \
2163 break; \
2165 else if (_ctxreg.arg == 21/*dwarf reg 21 is %f3*/) { \
2166 _how = CFIR_S390X_F3; \
2167 _off = 0; \
2168 break; \
2170 else if (_ctxreg.arg == 22/*dwarf reg 22 is %f5*/) { \
2171 _how = CFIR_S390X_F5; \
2172 _off = 0; \
2173 break; \
2175 else if (_ctxreg.arg == 23/*dwarf reg 23 is %f7*/) { \
2176 _how = CFIR_S390X_F7; \
2177 _off = 0; \
2178 break; \
2181 /* Currently we only support RR_Reg for s390. */ \
2182 why = 2; goto failed; \
2183 default: \
2184 why = 2; goto failed; /* otherwise give up */ \
2188 # if defined(VGA_x86) || defined(VGA_amd64)
2190 /* --- entire tail of this fn specialised for x86/amd64 --- */
2192 SUMMARISE_HOW(si_m->ra_how, si_m->ra_off,
2193 ctxs->reg[ctx->ra_reg] );
2194 SUMMARISE_HOW(si_m->bp_how, si_m->bp_off,
2195 ctxs->reg[FP_REG] );
2197 /* on x86/amd64, it seems the old %{e,r}sp value before the call is
2198 always the same as the CFA. Therefore ... */
2199 si_m->sp_how = CFIR_CFAREL;
2200 si_m->sp_off = 0;
2202 /* also, gcc says "Undef" for %{e,r}bp when it is unchanged. So
2203 .. */
2204 if (ctxs->reg[FP_REG].tag == RR_Undef)
2205 si_m->bp_how = CFIR_SAME;
2207 /* knock out some obviously stupid cases */
2208 if (si_m->ra_how == CFIR_SAME)
2209 { why = 3; goto failed; }
2211 /* bogus looking range? Note, we require that the difference is
2212 representable in 32 bits. */
2213 if (loc_start >= ctx->loc)
2214 { why = 4; goto failed; }
2215 if (ctx->loc - loc_start > 10000000 /* let's say */)
2216 { why = 5; goto failed; }
2218 *base = loc_start + ctx->initloc;
2219 *len = (UInt)(ctx->loc - loc_start);
2221 return True;
2223 # elif defined(VGA_arm)
2225 /* ---- entire tail of this fn specialised for arm ---- */
2227 SUMMARISE_HOW(si_m->r14_how, si_m->r14_off,
2228 ctxs->reg[14] );
2230 //SUMMARISE_HOW(si_m->r13_how, si_m->r13_off,
2231 // ctxs->reg[13] );
2233 SUMMARISE_HOW(si_m->r12_how, si_m->r12_off,
2234 ctxs->reg[FP_REG] );
2236 SUMMARISE_HOW(si_m->r11_how, si_m->r11_off,
2237 ctxs->reg[11/*FP_REG*/] );
2239 SUMMARISE_HOW(si_m->r7_how, si_m->r7_off,
2240 ctxs->reg[7] );
2242 if (ctxs->reg[14/*LR*/].tag == RR_Same
2243 && ctx->ra_reg == 14/*as we expect it always to be*/) {
2244 /* Generate a trivial CfiExpr, which merely says "r14". First
2245 ensure this DebugInfo has a cfsi_expr array in which to park
2246 it. */
2247 if (!debuginfo->cfsi_exprs)
2248 debuginfo->cfsi_exprs = VG_(newXA)( ML_(dinfo_zalloc),
2249 "di.ccCt.2a",
2250 ML_(dinfo_free),
2251 sizeof(CfiExpr) );
2252 si_m->ra_off = ML_(CfiExpr_CfiReg)( debuginfo->cfsi_exprs,
2253 Creg_ARM_R14);
2254 si_m->ra_how = CFIR_EXPR;
2255 } else {
2256 /* Just summarise it in the normal way */
2257 SUMMARISE_HOW(si_m->ra_how, si_m->ra_off,
2258 ctxs->reg[ctx->ra_reg] );
2261 /* on arm, it seems the old r13 (SP) value before the call is
2262 always the same as the CFA. Therefore ... */
2263 si_m->r13_how = CFIR_CFAREL;
2264 si_m->r13_off = 0;
2266 /* bogus looking range? Note, we require that the difference is
2267 representable in 32 bits. */
2268 if (loc_start >= ctx->loc)
2269 { why = 4; goto failed; }
2270 if (ctx->loc - loc_start > 10000000 /* let's say */)
2271 { why = 5; goto failed; }
2273 *base = loc_start + ctx->initloc;
2274 *len = (UInt)(ctx->loc - loc_start);
2276 return True;
2278 # elif defined(VGA_arm64)
2280 /* --- entire tail of this fn specialised for arm64 --- */
2282 SUMMARISE_HOW(si_m->x30_how, si_m->x30_off, ctxs->reg[30/*LR*/]);
2283 SUMMARISE_HOW(si_m->x29_how, si_m->x29_off, ctxs->reg[29/*FP*/]);
2285 if (ctxs->reg[30/*LR*/].tag == RR_Same
2286 && ctx->ra_reg == 30/*as we expect it always to be*/) {
2287 /* Generate a trivial CfiExpr, which merely says "x30". First
2288 ensure this DebugInfo has a cfsi_expr array in which to park
2289 it. */
2290 if (!debuginfo->cfsi_exprs)
2291 debuginfo->cfsi_exprs = VG_(newXA)( ML_(dinfo_zalloc),
2292 "di.ccCt.2a-arm64",
2293 ML_(dinfo_free),
2294 sizeof(CfiExpr) );
2295 si_m->ra_off = ML_(CfiExpr_CfiReg)( debuginfo->cfsi_exprs,
2296 Creg_ARM64_X30);
2297 si_m->ra_how = CFIR_EXPR;
2298 } else {
2299 /* Just summarise it in the normal way */
2300 SUMMARISE_HOW(si_m->ra_how, si_m->ra_off, ctxs->reg[ctx->ra_reg]);
2303 /* on arm64, it seems the old SP value before the call is always
2304 the same as the CFA. Therefore ... */
2305 si_m->sp_how = CFIR_CFAREL;
2306 si_m->sp_off = 0;
2308 /* bogus looking range? Note, we require that the difference is
2309 representable in 32 bits. */
2310 if (loc_start >= ctx->loc)
2311 { why = 4; goto failed; }
2312 if (ctx->loc - loc_start > 10000000 /* let's say */)
2313 { why = 5; goto failed; }
2315 *base = loc_start + ctx->initloc;
2316 *len = (UInt)(ctx->loc - loc_start);
2318 return True;
2320 # elif defined(VGA_s390x)
2322 /* --- entire tail of this fn specialised for s390 --- */
2324 SUMMARISE_HOW(si_m->ra_how, si_m->ra_off,
2325 ctxs->reg[ctx->ra_reg] );
2326 SUMMARISE_HOW(si_m->fp_how, si_m->fp_off,
2327 ctxs->reg[FP_REG] );
2328 SUMMARISE_HOW(si_m->sp_how, si_m->sp_off,
2329 ctxs->reg[SP_REG] );
2330 SUMMARISE_HOW(si_m->f0_how, si_m->f0_off,
2331 ctxs->reg[16/*%f0*/]);
2332 SUMMARISE_HOW(si_m->f2_how, si_m->f2_off,
2333 ctxs->reg[17/*%f2*/]);
2334 SUMMARISE_HOW(si_m->f4_how, si_m->f4_off,
2335 ctxs->reg[18/*%f4*/]);
2336 SUMMARISE_HOW(si_m->f6_how, si_m->f6_off,
2337 ctxs->reg[19/*%f6*/]);
2338 SUMMARISE_HOW(si_m->f1_how, si_m->f1_off,
2339 ctxs->reg[20/*%f1*/]);
2340 SUMMARISE_HOW(si_m->f3_how, si_m->f3_off,
2341 ctxs->reg[21/*%f3*/]);
2342 SUMMARISE_HOW(si_m->f5_how, si_m->f5_off,
2343 ctxs->reg[22/*%f5*/]);
2344 SUMMARISE_HOW(si_m->f7_how, si_m->f7_off,
2345 ctxs->reg[23/*%f7*/]);
2347 /* change some defaults to consumable values */
2348 if (si_m->sp_how == CFIR_UNKNOWN)
2349 si_m->sp_how = CFIR_SAME;
2351 if (si_m->fp_how == CFIR_UNKNOWN)
2352 si_m->fp_how = CFIR_SAME;
2354 if (si_m->cfa_how == CFIR_UNKNOWN) {
2355 si_m->cfa_how = CFIC_IA_SPREL;
2356 si_m->cfa_off = 160;
2359 if (si_m->ra_how == CFIR_UNKNOWN) {
2360 if (!debuginfo->cfsi_exprs)
2361 debuginfo->cfsi_exprs = VG_(newXA)( ML_(dinfo_zalloc),
2362 "di.ccCt.2a",
2363 ML_(dinfo_free),
2364 sizeof(CfiExpr) );
2365 si_m->ra_how = CFIR_EXPR;
2366 si_m->ra_off = ML_(CfiExpr_CfiReg)( debuginfo->cfsi_exprs,
2367 Creg_S390_LR);
2370 if (si_m->f0_how == CFIR_UNKNOWN)
2371 si_m->f0_how = CFIR_SAME;
2373 if (si_m->f1_how == CFIR_UNKNOWN)
2374 si_m->f1_how = CFIR_SAME;
2376 if (si_m->f2_how == CFIR_UNKNOWN)
2377 si_m->f2_how = CFIR_SAME;
2379 if (si_m->f3_how == CFIR_UNKNOWN)
2380 si_m->f3_how = CFIR_SAME;
2382 if (si_m->f4_how == CFIR_UNKNOWN)
2383 si_m->f4_how = CFIR_SAME;
2385 if (si_m->f5_how == CFIR_UNKNOWN)
2386 si_m->f5_how = CFIR_SAME;
2388 if (si_m->f6_how == CFIR_UNKNOWN)
2389 si_m->f6_how = CFIR_SAME;
2391 if (si_m->f7_how == CFIR_UNKNOWN)
2392 si_m->f7_how = CFIR_SAME;
2394 /* knock out some obviously stupid cases */
2395 if (si_m->ra_how == CFIR_SAME)
2396 { why = 3; goto failed; }
2398 /* bogus looking range? Note, we require that the difference is
2399 representable in 32 bits. */
2400 if (loc_start >= ctx->loc)
2401 { why = 4; goto failed; }
2402 if (ctx->loc - loc_start > 10000000 /* let's say */)
2403 { why = 5; goto failed; }
2405 *base = loc_start + ctx->initloc;
2406 *len = (UInt)(ctx->loc - loc_start);
2408 return True;
2410 # elif defined(VGA_mips32) || defined(VGA_mips64)
2412 /* --- entire tail of this fn specialised for mips --- */
2414 SUMMARISE_HOW(si_m->ra_how, si_m->ra_off,
2415 ctxs->reg[ctx->ra_reg] );
2416 SUMMARISE_HOW(si_m->fp_how, si_m->fp_off,
2417 ctxs->reg[FP_REG] );
2418 SUMMARISE_HOW(si_m->sp_how, si_m->sp_off,
2419 ctxs->reg[SP_REG] );
2420 si_m->sp_how = CFIR_CFAREL;
2421 si_m->sp_off = 0;
2423 if (si_m->fp_how == CFIR_UNKNOWN)
2424 si_m->fp_how = CFIR_SAME;
2425 if (si_m->cfa_how == CFIR_UNKNOWN) {
2426 si_m->cfa_how = CFIC_IA_SPREL;
2427 si_m->cfa_off = 160;
2429 if (si_m->ra_how == CFIR_UNKNOWN) {
2430 if (!debuginfo->cfsi_exprs)
2431 debuginfo->cfsi_exprs = VG_(newXA)( ML_(dinfo_zalloc),
2432 "di.ccCt.2a",
2433 ML_(dinfo_free),
2434 sizeof(CfiExpr) );
2435 si_m->ra_how = CFIR_EXPR;
2436 si_m->ra_off = ML_(CfiExpr_CfiReg)( debuginfo->cfsi_exprs,
2437 Creg_MIPS_RA);
2440 if (si_m->ra_how == CFIR_SAME)
2441 { why = 3; goto failed; }
2443 if (loc_start >= ctx->loc)
2444 { why = 4; goto failed; }
2445 if (ctx->loc - loc_start > 10000000 /* let's say */)
2446 { why = 5; goto failed; }
2448 *base = loc_start + ctx->initloc;
2449 *len = (UInt)(ctx->loc - loc_start);
2451 return True;
2452 # elif defined(VGA_ppc32) || defined(VGA_ppc64be) || defined(VGA_ppc64le)
2453 /* These don't use CFI based unwinding (is that really true?) */
2455 # else
2456 # error "Unknown arch"
2457 # endif
2459 /* --- non-specialised code after this point --- */
2461 # undef SUMMARISE_HOW
2463 failed:
2464 if (VG_(clo_verbosity) > 2 || debuginfo->trace_cfi) {
2465 VG_(message)(Vg_DebugMsg,
2466 "summarise_context(loc_start = %#lx)"
2467 ": cannot summarise(why=%d): \n", loc_start, why);
2468 ppUnwindContext(ctx);
2470 return False;
2473 /* Copy the tree rooted at srcuc->exprs node srcix to dstxa, on the
2474 way converting any DwReg regs (regs numbered using the Dwarf scheme
2475 defined by each architecture's ABI) into CfiRegs, which are
2476 platform independent. If the conversion isn't possible because
2477 there is no equivalent register, return -1. This has the
2478 undesirable side effect of de-dagifying the input; oh well. */
2479 static Int copy_convert_CfiExpr_tree ( XArray* dstxa,
2480 const UnwindContext* srcuc,
2481 Int srcix )
2483 CfiExpr* src;
2484 Int cpL, cpR, cpA;
2485 XArray* srcxa = srcuc->exprs;
2486 vg_assert(srcxa);
2487 vg_assert(dstxa);
2488 vg_assert(srcix >= 0 && srcix < VG_(sizeXA)(srcxa));
2490 src = VG_(indexXA)( srcxa, srcix );
2491 switch (src->tag) {
2492 case Cex_Undef:
2493 return ML_(CfiExpr_Undef)( dstxa );
2494 case Cex_Deref:
2495 cpA = copy_convert_CfiExpr_tree( dstxa, srcuc, src->Cex.Deref.ixAddr );
2496 if (cpA == -1)
2497 return -1; /* propagate failure */
2498 return ML_(CfiExpr_Deref)( dstxa, cpA );
2499 case Cex_Const:
2500 return ML_(CfiExpr_Const)( dstxa, src->Cex.Const.con );
2501 case Cex_Binop:
2502 cpL = copy_convert_CfiExpr_tree( dstxa, srcuc, src->Cex.Binop.ixL );
2503 cpR = copy_convert_CfiExpr_tree( dstxa, srcuc, src->Cex.Binop.ixR );
2504 vg_assert(cpL >= -1 && cpR >= -1);
2505 if (cpL == -1 || cpR == -1)
2506 return -1; /* propagate failure */
2507 return ML_(CfiExpr_Binop)( dstxa, src->Cex.Binop.op, cpL, cpR );
2508 case Cex_CfiReg:
2509 /* should not see these in input (are created only by this
2510 conversion step!) */
2511 VG_(core_panic)("copy_convert_CfiExpr_tree: CfiReg in input");
2512 case Cex_DwReg: {
2513 /* This is the only place where the conversion can fail. */
2514 Int dwreg __attribute__((unused));
2515 dwreg = src->Cex.DwReg.reg;
2516 # if defined(VGA_x86) || defined(VGA_amd64)
2517 if (dwreg == SP_REG)
2518 return ML_(CfiExpr_CfiReg)( dstxa, Creg_IA_SP );
2519 if (dwreg == FP_REG)
2520 return ML_(CfiExpr_CfiReg)( dstxa, Creg_IA_BP );
2521 if (dwreg == srcuc->ra_reg)
2522 return ML_(CfiExpr_CfiReg)( dstxa, Creg_IA_IP ); /* correct? */
2523 # elif defined(VGA_arm)
2524 if (dwreg == SP_REG)
2525 return ML_(CfiExpr_CfiReg)( dstxa, Creg_ARM_R13 );
2526 if (dwreg == FP_REG)
2527 return ML_(CfiExpr_CfiReg)( dstxa, Creg_ARM_R12 );
2528 if (dwreg == srcuc->ra_reg)
2529 return ML_(CfiExpr_CfiReg)( dstxa, Creg_ARM_R15 ); /* correct? */
2530 # elif defined(VGA_s390x)
2531 if (dwreg == SP_REG)
2532 return ML_(CfiExpr_CfiReg)( dstxa, Creg_S390_SP );
2533 if (dwreg == FP_REG)
2534 return ML_(CfiExpr_CfiReg)( dstxa, Creg_S390_FP );
2535 if (dwreg == srcuc->ra_reg)
2536 return ML_(CfiExpr_CfiReg)( dstxa, Creg_S390_IA );
2537 # elif defined(VGA_mips32) || defined(VGA_mips64)
2538 if (dwreg == SP_REG)
2539 return ML_(CfiExpr_CfiReg)( dstxa, Creg_IA_SP );
2540 if (dwreg == FP_REG)
2541 return ML_(CfiExpr_CfiReg)( dstxa, Creg_IA_BP );
2542 if (dwreg == srcuc->ra_reg)
2543 return ML_(CfiExpr_CfiReg)( dstxa, Creg_IA_IP );
2544 # elif defined(VGA_arm64)
2545 I_die_here;
2546 # elif defined(VGA_ppc32) || defined(VGA_ppc64be) \
2547 || defined(VGA_ppc64le)
2548 # else
2549 # error "Unknown arch"
2550 # endif
2551 /* else we must fail - can't represent the reg */
2552 return -1;
2554 default:
2555 VG_(core_panic)("copy_convert_CfiExpr_tree: default");
2560 static void ppUnwindContext_summary ( const UnwindContext* ctx )
2562 const struct UnwindContextState* ctxs = &ctx->state[ctx->state_sp];
2564 VG_(printf)("0x%llx-1: ", (ULong)ctx->loc);
2566 if (ctxs->cfa_reg == SP_REG) {
2567 VG_(printf)("SP/CFA=%d+SP ", ctxs->cfa_off);
2568 } else
2569 if (ctxs->cfa_reg == FP_REG) {
2570 VG_(printf)("SP/CFA=%d+FP ", ctxs->cfa_off);
2571 } else {
2572 VG_(printf)("SP/CFA=unknown ");
2575 VG_(printf)("RA=");
2576 ppRegRule( ctx->exprs, &ctxs->reg[ctx->ra_reg] );
2578 VG_(printf)("FP=");
2579 ppRegRule( ctx->exprs, &ctxs->reg[FP_REG] );
2580 VG_(printf)("\n");
2584 /* ------------ Pick apart DWARF2 byte streams ------------ */
2586 static ULong step_le_u_encoded_literal ( DiCursor* data, UInt size )
2588 switch (size) {
2589 case 8: return (ULong)ML_(cur_step_ULong)( data );
2590 case 4: return (ULong)ML_(cur_step_UInt)( data );
2591 case 2: return (ULong)ML_(cur_step_UShort)( data );
2592 case 1: return (ULong)ML_(cur_step_UChar)( data );
2593 default: vg_assert(0); /*NOTREACHED*/ return 0;
2597 static Long step_le_s_encoded_literal ( DiCursor* data, UInt size )
2599 ULong u64 = step_le_u_encoded_literal( data, size );
2600 Long s64;
2601 switch (size) {
2602 case 8: s64 = u64; break;
2603 case 4: s64 = u64 << 32; s64 >>= 32; break;
2604 case 2: s64 = u64 << 48; s64 >>= 48; break;
2605 case 1: s64 = u64 << 56; s64 >>= 56; break;
2606 default: vg_assert(0); /*NOTREACHED*/ return 0;
2608 return s64;
2611 static UChar default_Addr_encoding ( void )
2613 switch (sizeof(Addr)) {
2614 case 4: return DW_EH_PE_udata4;
2615 case 8: return DW_EH_PE_udata8;
2616 default: vg_assert(0);
2620 static UInt size_of_encoded_Addr ( UChar encoding )
2622 if (encoding == DW_EH_PE_omit)
2623 return 0;
2625 switch (encoding & 0x07) {
2626 case DW_EH_PE_absptr: return sizeof(Addr);
2627 case DW_EH_PE_udata2: return sizeof(UShort);
2628 case DW_EH_PE_udata4: return sizeof(UInt);
2629 case DW_EH_PE_udata8: return sizeof(ULong);
2630 default: vg_assert(0);
2634 static Addr step_encoded_Addr ( const AddressDecodingInfo* adi,
2635 /*MOD*/DiCursor* data )
2637 /* Regarding the handling of DW_EH_PE_absptr. DWARF3 says this
2638 denotes an absolute address, hence you would think 'base' is
2639 zero. However, that is nonsensical (unless relocations are to
2640 be applied to the unwind data before reading it, which sounds
2641 unlikely). My interpretation is that DW_EH_PE_absptr indicates
2642 an address relative to where the object was loaded (technically,
2643 relative to its stated load VMA, hence the use of text_bias
2644 rather than text_avma). Hmm, should we use text_bias or
2645 text_avma here? Not sure.
2647 This view appears to be supported by DWARF3 spec sec 7.3
2648 "Executable Objects and Shared Objects":
2650 This requirement makes the debugging information for shared
2651 objects position independent. Virtual addresses in a shared
2652 object may be calculated by adding the offset to the base
2653 address at which the object was attached. This offset is
2654 available in the run-time linker's data structures.
2656 Addr base;
2657 Word offset;
2658 UChar encoding = adi->encoding;
2659 DiCursor ehframe_image = adi->ehframe_image;
2660 Addr ehframe_avma = adi->ehframe_avma;
2661 Addr got_avma = adi->got_avma;
2663 vg_assert((encoding & DW_EH_PE_indirect) == 0);
2665 switch (encoding & 0x70) {
2666 case DW_EH_PE_absptr:
2667 base = adi->text_bias;
2668 break;
2669 case DW_EH_PE_pcrel:
2670 base = ehframe_avma + ML_(cur_minus)(*data, ehframe_image);
2671 break;
2672 case DW_EH_PE_datarel:
2673 base = got_avma;
2674 break;
2675 case DW_EH_PE_textrel:
2676 vg_assert(0);
2677 base = /* text base address */ 0;
2678 break;
2679 case DW_EH_PE_funcrel:
2680 base = 0;
2681 break;
2682 case DW_EH_PE_aligned:
2683 base = 0;
2684 offset = ML_(cur_minus)(*data, ehframe_image);
2685 if ((offset % sizeof(Addr)) != 0) {
2686 Word nbytes = sizeof(Addr) - (offset % sizeof(Addr));
2687 *data = ML_(cur_plus)(*data, nbytes);
2689 break;
2690 default:
2691 vg_assert(0);
2694 if ((encoding & 0x07) == 0x00)
2695 encoding |= default_Addr_encoding();
2697 switch (encoding & 0x0f) {
2698 case DW_EH_PE_udata2:
2699 return base + ML_(cur_step_UShort)(data);
2700 case DW_EH_PE_udata4:
2701 return base + ML_(cur_step_UInt)(data);
2702 case DW_EH_PE_udata8:
2703 return base + ML_(cur_step_ULong)(data);
2704 case DW_EH_PE_sdata2:
2705 return base + ML_(cur_step_Short)(data);
2706 case DW_EH_PE_sdata4:
2707 return base + ML_(cur_step_Int)(data);
2708 case DW_EH_PE_sdata8:
2709 return base + ML_(cur_step_Long)(data);
2710 default:
2711 vg_assert2(0, "read encoded address %d\n", encoding & 0x0f);
2716 /* ------------ Run/show DWARF3 expressions ---------- */
2718 /* Convert the DWARF3 expression in expr[0 .. exprlen-1] into a dag
2719 (of CfiExprs) stored in ctx->exprs, and return the index in
2720 ctx->exprs of the root node. Or fail in which case return -1. */
2721 /* IMPORTANT: when adding expression forms here, also remember to
2722 add suitable evaluation code in evalCfiExpr in debuginfo.c. */
2723 static Int dwarfexpr_to_dag ( const UnwindContext* ctx,
2724 DiCursor expr, Int exprlen,
2725 Bool push_cfa_at_start,
2726 Bool ddump_frames )
2728 # define N_EXPR_STACK 20
2730 # define PUSH(_arg) \
2731 do { \
2732 vg_assert(sp >= -1 && sp < N_EXPR_STACK); \
2733 if (sp == N_EXPR_STACK-1) \
2734 return -1; \
2735 sp++; \
2736 stack[sp] = (_arg); \
2737 } while (0)
2739 # define POP(_lval) \
2740 do { \
2741 vg_assert(sp >= -1 && sp < N_EXPR_STACK); \
2742 if (sp == -1) \
2743 return -1; \
2744 _lval = stack[sp]; \
2745 sp--; \
2746 } while (0)
2748 Int ix, ix2, reg;
2749 UChar opcode;
2750 Word sw;
2751 UWord uw;
2752 CfiUnop uop;
2753 CfiBinop bop;
2754 const HChar* opname;
2756 Int sp; /* # of top element: valid is -1 .. N_EXPR_STACK-1 */
2757 Int stack[N_EXPR_STACK]; /* indices into ctx->exprs */
2758 const struct UnwindContextState* ctxs = &ctx->state[ctx->state_sp];
2760 XArray* dst = ctx->exprs;
2761 DiCursor limit = ML_(cur_plus)(expr, exprlen);
2763 vg_assert(dst);
2764 vg_assert(exprlen >= 0);
2766 sp = -1; /* empty */
2768 /* Synthesise the CFA as a CfiExpr */
2769 if (push_cfa_at_start) {
2770 if (ctxs->cfa_is_regoff) {
2771 /* cfa is reg +/- offset */
2772 ix = ML_(CfiExpr_Binop)( dst,
2773 Cbinop_Add,
2774 ML_(CfiExpr_DwReg)( dst, ctxs->cfa_reg ),
2775 ML_(CfiExpr_Const)( dst, (UWord)(Word)ctxs->cfa_off )
2777 PUSH(ix);
2778 } else {
2779 /* CFA is already an expr; use its root node */
2780 PUSH(ctxs->cfa_expr_ix);
2784 while (True) {
2786 vg_assert(sp >= -1 && sp < N_EXPR_STACK);
2788 if (ML_(cur_cmpGT)(expr, limit)) /* "expr > limit" */
2789 return -1; /* overrun - something's wrong */
2791 if (ML_(cur_cmpEQ)(expr, limit)) { /* "expr == limit" */
2792 /* end of expr - return expr on the top of stack. */
2793 if (sp == -1)
2794 return -1; /* stack empty. Bad. */
2795 else
2796 break;
2799 uop = 0; bop = 0; opname = NULL; /* excessively conservative */
2801 opcode = ML_(cur_step_UChar)(&expr);
2802 switch (opcode) {
2804 case DW_OP_lit0 ... DW_OP_lit31:
2805 /* push: literal 0 .. 31 */
2806 sw = (Word)opcode - (Word)DW_OP_lit0;
2807 vg_assert(sw >= 0 && sw <= 31);
2808 PUSH( ML_(CfiExpr_Const)( dst, (UWord)sw ) );
2809 if (ddump_frames)
2810 VG_(printf)("DW_OP_lit%ld", sw);
2811 break;
2813 case DW_OP_breg0 ... DW_OP_breg31:
2814 /* push: reg + sleb128 */
2815 reg = (Int)opcode - (Int)DW_OP_breg0;
2816 vg_assert(reg >= 0 && reg <= 31);
2817 sw = step_leb128S( &expr );
2818 ix = ML_(CfiExpr_Binop)( dst,
2819 Cbinop_Add,
2820 ML_(CfiExpr_DwReg)( dst, reg ),
2821 ML_(CfiExpr_Const)( dst, (UWord)sw )
2823 PUSH(ix);
2824 if (ddump_frames)
2825 VG_(printf)("DW_OP_breg%d: %ld", reg, sw);
2826 break;
2828 case DW_OP_reg0 ... DW_OP_reg31:
2829 /* push: reg */
2830 reg = (Int)opcode - (Int)DW_OP_reg0;
2831 vg_assert(reg >= 0 && reg <= 31);
2832 ix = ML_(CfiExpr_DwReg)( dst, reg );
2833 PUSH(ix);
2834 if (ddump_frames)
2835 VG_(printf)("DW_OP_reg%d", reg);
2836 break;
2838 case DW_OP_plus_uconst:
2839 uw = step_leb128U( &expr );
2840 PUSH( ML_(CfiExpr_Const)( dst, uw ) );
2841 POP( ix );
2842 POP( ix2 );
2843 PUSH( ML_(CfiExpr_Binop)( dst, Cbinop_Add, ix2, ix ) );
2844 if (ddump_frames)
2845 VG_(printf)("DW_OP_plus_uconst: %lu", uw);
2846 break;
2848 case DW_OP_const4s:
2849 /* push: 32-bit signed immediate */
2850 sw = step_le_s_encoded_literal( &expr, 4 );
2851 PUSH( ML_(CfiExpr_Const)( dst, (UWord)sw ) );
2852 if (ddump_frames)
2853 VG_(printf)("DW_OP_const4s: %ld", sw);
2854 break;
2856 case DW_OP_const2s:
2857 /* push: 16-bit signed immediate */
2858 sw = step_le_s_encoded_literal( &expr, 2 );
2859 PUSH( ML_(CfiExpr_Const)( dst, (UWord)sw ) );
2860 if (ddump_frames)
2861 VG_(printf)("DW_OP_const2s: %ld", sw);
2862 break;
2864 case DW_OP_const1s:
2865 /* push: 8-bit signed immediate */
2866 sw = step_le_s_encoded_literal( &expr, 1 );
2867 PUSH( ML_(CfiExpr_Const)( dst, (UWord)sw ) );
2868 if (ddump_frames)
2869 VG_(printf)("DW_OP_const1s: %ld", sw);
2870 break;
2872 case DW_OP_const1u:
2873 /* push: 8-bit unsigned immediate */
2874 uw = step_le_u_encoded_literal( &expr, 1 );
2875 PUSH( ML_(CfiExpr_Const)( dst, uw ) );
2876 if (ddump_frames)
2877 VG_(printf)("DW_OP_const1: %lu", uw);
2878 break;
2880 case DW_OP_const2u:
2881 /* push: 16-bit unsigned immediate */
2882 uw = step_le_u_encoded_literal( &expr, 2 );
2883 PUSH( ML_(CfiExpr_Const)( dst, uw ) );
2884 if (ddump_frames)
2885 VG_(printf)("DW_OP_const2: %lu", uw);
2886 break;
2888 case DW_OP_const4u:
2889 /* push: 32-bit unsigned immediate */
2890 uw = step_le_u_encoded_literal( &expr, 4 );
2891 PUSH( ML_(CfiExpr_Const)( dst, uw ) );
2892 if (ddump_frames)
2893 VG_(printf)("DW_OP_const4: %lu", uw);
2894 break;
2896 case DW_OP_abs:
2897 uop = Cunop_Abs; opname = "abs"; goto unop;
2898 case DW_OP_neg:
2899 uop = Cunop_Neg; opname = "neg"; goto unop;
2900 case DW_OP_not:
2901 uop = Cunop_Not; opname = "not"; goto unop;
2902 unop:
2903 POP( ix );
2904 PUSH( ML_(CfiExpr_Unop)( dst, uop, ix ) );
2905 if (ddump_frames)
2906 VG_(printf)("DW_OP_%s", opname);
2907 break;
2909 case DW_OP_minus:
2910 bop = Cbinop_Sub; opname = "minus"; goto binop;
2911 case DW_OP_plus:
2912 bop = Cbinop_Add; opname = "plus"; goto binop;
2913 case DW_OP_and:
2914 bop = Cbinop_And; opname = "and"; goto binop;
2915 case DW_OP_mul:
2916 bop = Cbinop_Mul; opname = "mul"; goto binop;
2917 case DW_OP_shl:
2918 bop = Cbinop_Shl; opname = "shl"; goto binop;
2919 case DW_OP_shr:
2920 bop = Cbinop_Shr; opname = "shr"; goto binop;
2921 case DW_OP_eq:
2922 bop = Cbinop_Eq; opname = "eq"; goto binop;
2923 case DW_OP_ge:
2924 bop = Cbinop_Ge; opname = "ge"; goto binop;
2925 case DW_OP_gt:
2926 bop = Cbinop_Gt; opname = "gt"; goto binop;
2927 case DW_OP_le:
2928 bop = Cbinop_Le; opname = "le"; goto binop;
2929 case DW_OP_lt:
2930 bop = Cbinop_Lt; opname = "lt"; goto binop;
2931 case DW_OP_ne:
2932 bop = Cbinop_Ne; opname = "ne"; goto binop;
2933 binop:
2934 POP( ix );
2935 POP( ix2 );
2936 PUSH( ML_(CfiExpr_Binop)( dst, bop, ix2, ix ) );
2937 if (ddump_frames)
2938 VG_(printf)("DW_OP_%s", opname);
2939 break;
2941 case DW_OP_deref:
2942 POP( ix );
2943 PUSH( ML_(CfiExpr_Deref)( dst, ix ) );
2944 if (ddump_frames)
2945 VG_(printf)("DW_OP_deref");
2946 break;
2948 case DW_OP_drop:
2949 POP( ix );
2950 if (ddump_frames)
2951 VG_(printf)("DW_OP_drop");
2952 break;
2954 default:
2955 if (!VG_(clo_xml))
2956 VG_(message)(Vg_DebugMsg,
2957 "Warning: DWARF2 CFI reader: unhandled DW_OP_ "
2958 "opcode 0x%x\n", (Int)opcode);
2959 return -1;
2962 if (ML_(cur_cmpLT)(expr, limit) && ddump_frames)
2963 VG_(printf)("; ");
2967 vg_assert(sp >= -1 && sp < N_EXPR_STACK);
2968 if (sp == -1)
2969 return -1;
2971 if (0 && ddump_frames)
2972 ML_(ppCfiExpr)( dst, stack[sp] );
2973 return stack[sp];
2975 # undef POP
2976 # undef PUSH
2977 # undef N_EXPR_STACK
2981 /* ------------ Run/show CFI instructions ------------ */
2983 /* Run a CFI instruction, and also return its length.
2984 Returns 0 if the instruction could not be executed.
2986 static Int run_CF_instruction ( /*MOD*/UnwindContext* ctx,
2987 DiCursor instrIN,
2988 const UnwindContext* restore_ctx,
2989 const AddressDecodingInfo* adi,
2990 const DebugInfo* di )
2992 Int off, reg, reg2, len, j;
2993 UInt delta;
2994 Addr printing_bias = ((Addr)ctx->initloc) - ((Addr)di->text_bias);
2995 struct UnwindContextState* ctxs;
2997 DiCursor instr = instrIN;
2998 UChar instr_0 = ML_(cur_step_UChar)(&instr);
2999 UChar hi2 = (instr_0 >> 6) & 3;
3000 UChar lo6 = instr_0 & 0x3F;
3002 if (ctx->state_sp < 0 || ctx->state_sp >= N_RR_STACK)
3003 return 0; /* bogus reg-rule stack pointer */
3005 ctxs = &ctx->state[ctx->state_sp];
3006 if (hi2 == DW_CFA_advance_loc) {
3007 delta = (UInt)lo6;
3008 delta *= ctx->code_a_f;
3009 ctx->loc += delta;
3010 if (di->ddump_frames)
3011 VG_(printf)(" DW_CFA_advance_loc: %d to %08lx\n",
3012 (Int)delta, (Addr)ctx->loc + printing_bias);
3013 return ML_(cur_minus)(instr, instrIN);
3016 if (hi2 == DW_CFA_offset) {
3017 /* Set rule for reg 'lo6' to CFAOff(off * data_af) */
3018 off = step_leb128( &instr, 0 );
3019 reg = (Int)lo6;
3020 if (reg < 0 || reg >= N_CFI_REGS)
3021 return 0; /* fail */
3022 ctxs->reg[reg].tag = RR_CFAOff;
3023 ctxs->reg[reg].arg = off * ctx->data_a_f;
3024 if (di->ddump_frames)
3025 VG_(printf)(" DW_CFA_offset: r%d at cfa%s%d\n",
3026 (Int)reg,
3027 ctxs->reg[reg].arg < 0 ? "" : "+",
3028 (Int)ctxs->reg[reg].arg );
3029 return ML_(cur_minus)(instr, instrIN);
3032 if (hi2 == DW_CFA_restore) {
3033 reg = (Int)lo6;
3034 if (reg < 0 || reg >= N_CFI_REGS)
3035 return 0; /* fail */
3036 if (restore_ctx == NULL)
3037 return 0; /* fail */
3038 ctxs->reg[reg] = restore_ctx->state[restore_ctx->state_sp].reg[reg];
3039 if (di->ddump_frames)
3040 VG_(printf)(" DW_CFA_restore: r%d\n", (Int)reg);
3041 return ML_(cur_minus)(instr, instrIN);
3044 vg_assert(hi2 == DW_CFA_use_secondary);
3046 switch (lo6) {
3047 case DW_CFA_nop:
3048 if (di->ddump_frames)
3049 VG_(printf)(" DW_CFA_nop\n");
3050 break;
3051 case DW_CFA_set_loc:
3052 /* WAS:
3053 ctx->loc = read_Addr(&instr[i]) - ctx->initloc; i+= sizeof(Addr);
3054 Was this ever right? */
3055 /* 2007 Feb 23: No. binutils/dwarf.c treats it as an encoded
3056 address and that appears to be in accordance with the
3057 DWARF3 spec. */
3058 ctx->loc = step_encoded_Addr(adi, &instr);
3059 if (di->ddump_frames)
3060 VG_(printf)(" rci:DW_CFA_set_loc\n");
3061 break;
3062 case DW_CFA_advance_loc1:
3063 delta = (UInt)ML_(cur_step_UChar)(&instr);
3064 delta *= ctx->code_a_f;
3065 ctx->loc += delta;
3066 if (di->ddump_frames)
3067 VG_(printf)(" DW_CFA_advance_loc1: %d to %08lx\n",
3068 (Int)delta, (Addr)ctx->loc + printing_bias);
3069 break;
3070 case DW_CFA_advance_loc2:
3071 delta = (UInt)ML_(cur_step_UShort)(&instr);
3072 delta *= ctx->code_a_f;
3073 ctx->loc += delta;
3074 if (di->ddump_frames)
3075 VG_(printf)(" DW_CFA_advance_loc2: %d to %08lx\n",
3076 (Int)delta, (Addr)ctx->loc + printing_bias);
3077 break;
3078 case DW_CFA_advance_loc4:
3079 delta = (UInt)ML_(cur_step_UInt)(&instr);
3080 delta *= ctx->code_a_f;
3081 ctx->loc += delta;
3082 if (di->ddump_frames)
3083 VG_(printf)(" DW_CFA_advance_loc4: %d to %08lx\n",
3084 (Int)delta, (Addr)ctx->loc + printing_bias);
3085 break;
3087 case DW_CFA_def_cfa:
3088 reg = step_leb128( &instr, 0 );
3089 off = step_leb128( &instr, 0 );
3090 if (reg < 0 || reg >= N_CFI_REGS)
3091 return 0; /* fail */
3092 ctxs->cfa_is_regoff = True;
3093 ctxs->cfa_expr_ix = 0;
3094 ctxs->cfa_reg = reg;
3095 ctxs->cfa_off = off;
3096 if (di->ddump_frames)
3097 VG_(printf)(" DW_CFA_def_cfa: r%d ofs %d\n", (Int)reg, (Int)off);
3098 break;
3100 case DW_CFA_def_cfa_sf:
3101 reg = step_leb128( &instr, 0 );
3102 off = step_leb128( &instr, 1 );
3103 if (reg < 0 || reg >= N_CFI_REGS)
3104 return 0; /* fail */
3105 ctxs->cfa_is_regoff = True;
3106 ctxs->cfa_expr_ix = 0;
3107 ctxs->cfa_reg = reg;
3108 ctxs->cfa_off = off * ctx->data_a_f;
3109 if (di->ddump_frames)
3110 VG_(printf)(" rci:DW_CFA_def_cfa_sf\n");
3111 break;
3113 case DW_CFA_register:
3114 reg = step_leb128( &instr, 0 );
3115 reg2 = step_leb128( &instr, 0 );
3116 if (reg < 0 || reg >= N_CFI_REGS)
3117 return 0; /* fail */
3118 if (reg2 < 0 || reg2 >= N_CFI_REGS)
3119 return 0; /* fail */
3120 ctxs->reg[reg].tag = RR_Reg;
3121 ctxs->reg[reg].arg = reg2;
3122 if (di->ddump_frames)
3123 VG_(printf)(" DW_CFA_register: r%d in r%d\n",
3124 (Int)reg, (Int)reg2);
3125 break;
3127 case DW_CFA_offset_extended:
3128 reg = step_leb128( &instr, 0 );
3129 off = step_leb128( &instr, 0 );
3130 if (reg < 0 || reg >= N_CFI_REGS)
3131 return 0; /* fail */
3132 ctxs->reg[reg].tag = RR_CFAOff;
3133 ctxs->reg[reg].arg = off * ctx->data_a_f;
3134 if (di->ddump_frames)
3135 VG_(printf)(" rci:DW_CFA_offset_extended\n");
3136 break;
3138 case DW_CFA_offset_extended_sf:
3139 reg = step_leb128( &instr, 0 );
3140 off = step_leb128( &instr, 1 );
3141 if (reg < 0 || reg >= N_CFI_REGS)
3142 return 0; /* fail */
3143 ctxs->reg[reg].tag = RR_CFAOff;
3144 ctxs->reg[reg].arg = off * ctx->data_a_f;
3145 if (di->ddump_frames)
3146 VG_(printf)(" DW_CFA_offset_extended_sf: r%d at cfa%s%d\n",
3147 reg,
3148 ctxs->reg[reg].arg < 0 ? "" : "+",
3149 (Int)ctxs->reg[reg].arg);
3150 break;
3152 case DW_CFA_GNU_negative_offset_extended:
3153 reg = step_leb128( &instr, 0 );
3154 off = step_leb128( &instr, 0 );
3155 if (reg < 0 || reg >= N_CFI_REGS)
3156 return 0; /* fail */
3157 ctxs->reg[reg].tag = RR_CFAOff;
3158 ctxs->reg[reg].arg = (-off) * ctx->data_a_f;
3159 if (di->ddump_frames)
3160 VG_(printf)(" rci:DW_CFA_GNU_negative_offset_extended\n");
3161 break;
3163 case DW_CFA_restore_extended:
3164 reg = step_leb128( &instr, 0 );
3165 if (reg < 0 || reg >= N_CFI_REGS)
3166 return 0; /* fail */
3167 if (restore_ctx == NULL)
3168 return 0; /* fail */
3169 ctxs->reg[reg] = restore_ctx->state[restore_ctx->state_sp].reg[reg];
3170 if (di->ddump_frames)
3171 VG_(printf)(" rci:DW_CFA_restore_extended\n");
3172 break;
3174 case DW_CFA_val_offset:
3175 reg = step_leb128( &instr, 0 );
3176 off = step_leb128( &instr, 0 );
3177 if (reg < 0 || reg >= N_CFI_REGS)
3178 return 0; /* fail */
3179 ctxs->reg[reg].tag = RR_CFAValOff;
3180 ctxs->reg[reg].arg = off * ctx->data_a_f;
3181 if (di->ddump_frames)
3182 VG_(printf)(" rci:DW_CFA_val_offset\n");
3183 break;
3185 case DW_CFA_val_offset_sf:
3186 reg = step_leb128( &instr, 0 );
3187 off = step_leb128( &instr, 1 );
3188 if (reg < 0 || reg >= N_CFI_REGS)
3189 return 0; /* fail */
3190 ctxs->reg[reg].tag = RR_CFAValOff;
3191 ctxs->reg[reg].arg = off * ctx->data_a_f;
3192 if (di->ddump_frames)
3193 VG_(printf)(" rci:DW_CFA_val_offset_sf\n");
3194 break;
3196 case DW_CFA_def_cfa_register:
3197 reg = step_leb128( &instr, 0);
3198 if (reg < 0 || reg >= N_CFI_REGS)
3199 return 0; /* fail */
3200 ctxs->cfa_is_regoff = True;
3201 ctxs->cfa_expr_ix = 0;
3202 ctxs->cfa_reg = reg;
3203 /* ->cfa_off unchanged */
3204 if (di->ddump_frames)
3205 VG_(printf)(" DW_CFA_def_cfa_register: r%d\n", (Int)reg );
3206 break;
3208 case DW_CFA_def_cfa_offset:
3209 off = step_leb128( &instr, 0);
3210 ctxs->cfa_is_regoff = True;
3211 ctxs->cfa_expr_ix = 0;
3212 /* ->reg is unchanged */
3213 ctxs->cfa_off = off;
3214 if (di->ddump_frames)
3215 VG_(printf)(" DW_CFA_def_cfa_offset: %d\n", (Int)off);
3216 break;
3218 case DW_CFA_def_cfa_offset_sf:
3219 off = step_leb128( &instr, 1);
3220 ctxs->cfa_is_regoff = True;
3221 ctxs->cfa_expr_ix = 0;
3222 /* ->reg is unchanged */
3223 ctxs->cfa_off = off * ctx->data_a_f;
3224 if (di->ddump_frames)
3225 VG_(printf)(" DW_CFA_def_cfa_offset_sf: %d\n", ctxs->cfa_off);
3226 break;
3228 case DW_CFA_undefined:
3229 reg = step_leb128( &instr, 0);
3230 if (reg < 0 || reg >= N_CFI_REGS)
3231 return 0; /* fail */
3232 ctxs->reg[reg].tag = RR_Undef;
3233 ctxs->reg[reg].arg = 0;
3234 if (di->ddump_frames)
3235 VG_(printf)(" rci:DW_CFA_undefined\n");
3236 break;
3238 case DW_CFA_same_value:
3239 reg = step_leb128( &instr, 0);
3240 if (reg < 0 || reg >= N_CFI_REGS)
3241 return 0; /* fail */
3242 ctxs->reg[reg].tag = RR_Same;
3243 ctxs->reg[reg].arg = 0;
3244 if (di->ddump_frames)
3245 VG_(printf)(" rci:DW_CFA_same_value\n");
3246 break;
3248 case DW_CFA_GNU_args_size:
3249 /* No idea what is supposed to happen. gdb-6.3 simply
3250 ignores these. */
3251 /*off = */ (void)step_leb128( &instr, 0 );
3252 if (di->ddump_frames)
3253 VG_(printf)(" rci:DW_CFA_GNU_args_size (ignored)\n");
3254 break;
3256 case DW_CFA_expression: {
3257 /* Identical to DW_CFA_val_expression except that the value
3258 computed is an address and so needs one final
3259 dereference. */
3260 DiCursor expr;
3261 reg = step_leb128( &instr, 0 );
3262 len = step_leb128( &instr, 0 );
3263 expr = instr;
3264 instr = ML_(cur_plus)(instr, len);
3265 if (reg < 0 || reg >= N_CFI_REGS)
3266 return 0; /* fail */
3267 if (di->ddump_frames)
3268 VG_(printf)(" DW_CFA_expression: r%d (",
3269 (Int)reg);
3270 /* Convert the expression into a dag rooted at ctx->exprs index j,
3271 or fail. */
3272 j = dwarfexpr_to_dag ( ctx, expr, len, True/*push CFA at start*/,
3273 di->ddump_frames);
3274 if (di->ddump_frames)
3275 VG_(printf)(")\n");
3276 vg_assert(j >= -1);
3277 if (j >= 0) {
3278 vg_assert(ctx->exprs);
3279 vg_assert( j < VG_(sizeXA)(ctx->exprs) );
3281 if (j == -1)
3282 return 0; /* fail */
3283 /* Add an extra dereference */
3284 j = ML_(CfiExpr_Deref)( ctx->exprs, j );
3285 ctxs->reg[reg].tag = RR_ValExpr;
3286 ctxs->reg[reg].arg = j;
3287 break;
3290 case DW_CFA_val_expression: {
3291 DiCursor expr;
3292 reg = step_leb128( &instr, 0 );
3293 len = step_leb128( &instr, 0 );
3294 expr = instr;
3295 instr = ML_(cur_plus)(instr, len);
3296 if (reg < 0 || reg >= N_CFI_REGS)
3297 return 0; /* fail */
3298 if (di->ddump_frames)
3299 VG_(printf)(" DW_CFA_val_expression: r%d (",
3300 (Int)reg);
3301 /* Convert the expression into a dag rooted at ctx->exprs index j,
3302 or fail. */
3303 j = dwarfexpr_to_dag ( ctx, expr, len, True/*push CFA at start*/,
3304 di->ddump_frames);
3305 if (di->ddump_frames)
3306 VG_(printf)(")\n");
3307 vg_assert(j >= -1);
3308 if (j >= 0) {
3309 vg_assert(ctx->exprs);
3310 vg_assert( j < VG_(sizeXA)(ctx->exprs) );
3312 if (j == -1)
3313 return 0; /* fail */
3314 ctxs->reg[reg].tag = RR_ValExpr;
3315 ctxs->reg[reg].arg = j;
3316 break;
3319 case DW_CFA_def_cfa_expression: {
3320 DiCursor expr;
3321 len = step_leb128( &instr, 0 );
3322 expr = instr;
3323 instr = ML_(cur_plus)(instr, len);
3324 if (di->ddump_frames)
3325 VG_(printf)(" DW_CFA_def_cfa_expression (");
3326 /* Convert the expression into a dag rooted at ctx->exprs index j,
3327 or fail. */
3328 j = dwarfexpr_to_dag ( ctx, expr, len, False/*!push CFA at start*/,
3329 di->ddump_frames);
3330 if (di->ddump_frames)
3331 VG_(printf)(")\n");
3332 ctxs->cfa_is_regoff = False;
3333 ctxs->cfa_reg = 0;
3334 ctxs->cfa_off = 0;
3335 ctxs->cfa_expr_ix = j;
3336 break;
3339 case DW_CFA_GNU_window_save:
3340 /* Ignored. This appears to be sparc-specific; quite why it
3341 turns up in SuSE-supplied x86 .so's beats me. */
3342 if (di->ddump_frames)
3343 VG_(printf)(" DW_CFA_GNU_window_save\n");
3344 break;
3346 case DW_CFA_remember_state:
3347 if (di->ddump_frames)
3348 VG_(printf)(" DW_CFA_remember_state\n");
3349 /* we just checked this at entry, so: */
3350 vg_assert(ctx->state_sp >= 0 && ctx->state_sp < N_RR_STACK);
3351 ctx->state_sp++;
3352 if (ctx->state_sp == N_RR_STACK) {
3353 /* stack overflow. We're hosed. */
3354 VG_(message)(Vg_DebugMsg, "DWARF2 CFI reader: N_RR_STACK is "
3355 "too low; increase and recompile.");
3356 return 0; /* indicate failure */
3357 } else {
3358 VG_(memcpy)(/*dst*/&ctx->state[ctx->state_sp],
3359 /*src*/&ctx->state[ctx->state_sp - 1],
3360 sizeof(ctx->state[ctx->state_sp]) );
3362 break;
3364 case DW_CFA_restore_state:
3365 if (di->ddump_frames)
3366 VG_(printf)(" DW_CFA_restore_state\n");
3367 /* we just checked this at entry, so: */
3368 vg_assert(ctx->state_sp >= 0 && ctx->state_sp < N_RR_STACK);
3369 if (ctx->state_sp == 0) {
3370 /* stack undefflow. Give up. */
3371 return 0; /* indicate failure */
3372 } else {
3373 /* simply fall back to previous entry */
3374 ctx->state_sp--;
3376 break;
3378 case DW_CFA_ORCL_arg_loc:
3379 if (di->ddump_frames)
3380 VG_(printf)(" DW_CFA_ORCL_arg_loc\n");
3381 break;
3383 default:
3384 VG_(message)(Vg_DebugMsg, "DWARF2 CFI reader: unhandled CFI "
3385 "instruction 0:%d\n", (Int)lo6);
3386 if (di->ddump_frames)
3387 VG_(printf)(" rci:run_CF_instruction:default\n");
3388 return 0; /* failure */
3389 /*NOTREACHED*/
3392 return ML_(cur_minus)(instr, instrIN);
3396 /* Show a CFI instruction, and also return its length. Show it as
3397 close as possible (preferably identical) to how GNU binutils
3398 readelf --debug-dump=frames would. */
3400 static Int show_CF_instruction ( DiCursor instrIN,
3401 const AddressDecodingInfo* adi,
3402 Int code_a_f, Int data_a_f )
3404 Int off, coff, reg, reg2, len;
3405 UInt delta;
3406 Addr loc;
3407 DiCursor instr = instrIN;
3408 UChar instr_0 = ML_(cur_step_UChar)(&instr);
3409 UChar hi2 = (instr_0 >> 6) & 3;
3410 UChar lo6 = instr_0 & 0x3F;
3412 if (0) {
3413 DiCursor tmpi = instrIN;
3414 UInt i_0 = ML_(cur_step_UChar)(&tmpi);
3415 UInt i_1 = ML_(cur_step_UChar)(&tmpi);
3416 UInt i_2 = ML_(cur_step_UChar)(&tmpi);
3417 UInt i_3 = ML_(cur_step_UChar)(&tmpi);
3418 UInt i_4 = ML_(cur_step_UChar)(&tmpi);
3419 UInt i_5 = ML_(cur_step_UChar)(&tmpi);
3420 UInt i_6 = ML_(cur_step_UChar)(&tmpi);
3421 UInt i_7 = ML_(cur_step_UChar)(&tmpi);
3422 VG_(printf)("raw:%x/%x:%x:%x:%x:%x:%x:%x:%x:%x\n",
3423 hi2, lo6, i_0, i_1, i_2, i_3, i_4, i_5, i_6, i_7);
3426 if (hi2 == DW_CFA_advance_loc) {
3427 VG_(printf)(" sci:DW_CFA_advance_loc(%d)\n", (Int)lo6);
3428 return ML_(cur_minus)(instr, instrIN);
3431 if (hi2 == DW_CFA_offset) {
3432 off = step_leb128( &instr, 0 );
3433 coff = off * data_a_f;
3434 VG_(printf)(" DW_CFA_offset: r%d at cfa%s%d\n",
3435 (Int)lo6, coff < 0 ? "" : "+", (Int)coff );
3436 return ML_(cur_minus)(instr, instrIN);
3439 if (hi2 == DW_CFA_restore) {
3440 VG_(printf)(" sci:DW_CFA_restore(r%d)\n", (Int)lo6);
3441 return ML_(cur_minus)(instr, instrIN);
3444 vg_assert(hi2 == DW_CFA_use_secondary);
3446 switch (lo6) {
3448 case DW_CFA_nop:
3449 VG_(printf)(" DW_CFA_nop\n");
3450 break;
3452 case DW_CFA_set_loc:
3453 /* WAS: loc = read_Addr(&instr[i]); i+= sizeof(Addr);
3454 (now known to be incorrect -- the address is encoded) */
3455 loc = step_encoded_Addr(adi, &instr);
3456 VG_(printf)(" sci:DW_CFA_set_loc(%#lx)\n", loc);
3457 break;
3459 case DW_CFA_advance_loc1:
3460 delta = (UInt)ML_(cur_step_UChar)(&instr);
3461 VG_(printf)(" sci:DW_CFA_advance_loc1(%u)\n", delta);
3462 break;
3464 case DW_CFA_advance_loc2:
3465 delta = (UInt)ML_(cur_step_UShort)(&instr);
3466 VG_(printf)(" sci:DW_CFA_advance_loc2(%u)\n", delta);
3467 break;
3469 case DW_CFA_advance_loc4:
3470 delta = (UInt)ML_(cur_step_UInt)(&instr);
3471 VG_(printf)(" DW_CFA_advance_loc4(%u)\n", delta);
3472 break;
3474 case DW_CFA_def_cfa:
3475 reg = step_leb128( &instr, 0 );
3476 off = step_leb128( &instr, 0 );
3477 VG_(printf)(" DW_CFA_def_cfa: r%d ofs %d\n", reg, off);
3478 break;
3480 case DW_CFA_def_cfa_sf:
3481 reg = step_leb128( &instr, 0 );
3482 off = step_leb128( &instr, 1 );
3483 VG_(printf)(" DW_CFA_def_cfa_sf: r%d ofs %d\n",
3484 reg, off * data_a_f);
3485 break;
3487 case DW_CFA_register:
3488 reg = step_leb128( &instr, 0);
3489 reg2 = step_leb128( &instr, 0);
3490 VG_(printf)(" sci:DW_CFA_register(r%d, r%d)\n", reg, reg2);
3491 break;
3493 case DW_CFA_def_cfa_register:
3494 reg = step_leb128( &instr, 0);
3495 VG_(printf)(" sci:DW_CFA_def_cfa_register(r%d)\n", reg);
3496 break;
3498 case DW_CFA_def_cfa_offset:
3499 off = step_leb128( &instr, 0);
3500 VG_(printf)(" sci:DW_CFA_def_cfa_offset(%d)\n", off);
3501 break;
3503 case DW_CFA_def_cfa_offset_sf:
3504 off = step_leb128( &instr, 1);
3505 VG_(printf)(" sci:DW_CFA_def_cfa_offset_sf(%d)\n", off);
3506 break;
3508 case DW_CFA_restore_extended:
3509 reg = step_leb128( &instr, 0);
3510 VG_(printf)(" sci:DW_CFA_restore_extended(r%d)\n", reg);
3511 break;
3513 case DW_CFA_undefined:
3514 reg = step_leb128( &instr, 0);
3515 VG_(printf)(" sci:DW_CFA_undefined(r%d)\n", reg);
3516 break;
3518 case DW_CFA_same_value:
3519 reg = step_leb128( &instr, 0);
3520 VG_(printf)(" sci:DW_CFA_same_value(r%d)\n", reg);
3521 break;
3523 case DW_CFA_remember_state:
3524 VG_(printf)(" sci:DW_CFA_remember_state\n");
3525 break;
3527 case DW_CFA_restore_state:
3528 VG_(printf)(" sci:DW_CFA_restore_state\n");
3529 break;
3531 case DW_CFA_GNU_args_size:
3532 off = step_leb128( &instr, 0 );
3533 VG_(printf)(" sci:DW_CFA_GNU_args_size(%d)\n", off );
3534 break;
3536 case DW_CFA_def_cfa_expression:
3537 len = step_leb128( &instr, 0 );
3538 instr = ML_(cur_plus)(instr, len);
3539 VG_(printf)(" sci:DW_CFA_def_cfa_expression(length %d)\n", len);
3540 break;
3542 case DW_CFA_expression:
3543 reg = step_leb128( &instr, 0 );
3544 len = step_leb128( &instr, 0 );
3545 instr = ML_(cur_plus)(instr, len);
3546 VG_(printf)(" sci:DW_CFA_expression(r%d, length %d)\n", reg, len);
3547 break;
3549 case DW_CFA_val_expression:
3550 reg = step_leb128( &instr, 0 );
3551 len = step_leb128( &instr, 0 );
3552 instr = ML_(cur_plus)(instr, len);
3553 VG_(printf)(" sci:DW_CFA_val_expression(r%d, length %d)\n", reg, len);
3554 break;
3556 case DW_CFA_offset_extended:
3557 reg = step_leb128( &instr, 0 );
3558 off = step_leb128( &instr, 0 );
3559 VG_(printf)(" sci:DW_CFA_offset_extended(r%d, "
3560 "off %d x data_af)\n", reg, off);
3561 break;
3563 case DW_CFA_offset_extended_sf:
3564 reg = step_leb128( &instr, 0 );
3565 off = step_leb128( &instr, 1 );
3566 coff = (Int)(off * data_a_f);
3567 VG_(printf)(" DW_CFA_offset_extended_sf: r%d at cfa%s%d\n",
3568 reg, coff < 0 ? "" : "+", coff);
3569 break;
3571 case DW_CFA_GNU_negative_offset_extended:
3572 reg = step_leb128( &instr, 0 );
3573 off = step_leb128( &instr, 0 );
3574 VG_(printf)(" sci:DW_CFA_GNU_negative_offset_extended"
3575 "(r%d, off %d x data_af)\n", reg, -off);
3576 break;
3578 case DW_CFA_val_offset:
3579 reg = step_leb128( &instr, 0 );
3580 off = step_leb128( &instr, 0 );
3581 VG_(printf)(" sci:DW_CFA_val_offset(r%d, off %d x data_af)\n",
3582 reg, off);
3583 break;
3585 case DW_CFA_val_offset_sf:
3586 reg = step_leb128( &instr, 0 );
3587 off = step_leb128( &instr, 1 );
3588 VG_(printf)(" sci:DW_CFA_val_offset_sf(r%d, off %d x data_af)\n",
3589 reg, off);
3590 break;
3592 case DW_CFA_GNU_window_save:
3593 VG_(printf)(" sci:DW_CFA_GNU_window_save\n");
3594 break;
3596 case DW_CFA_ORCL_arg_loc:
3597 reg = step_leb128( &instr, 0 );
3598 len = step_leb128( &instr, 0 );
3599 VG_(printf)(" sci:DW_CFA_ORCL_arg_loc(%d, length %d)\n", reg, len);
3600 break;
3602 default:
3603 VG_(printf)(" sci:0:%d\n", (Int)lo6);
3604 break;
3607 return ML_(cur_minus)(instr, instrIN);
3611 /* Show the instructions in instrs[0 .. ilen-1]. */
3612 static void show_CF_instructions ( DiCursor instrs, Int ilen,
3613 const AddressDecodingInfo* adi,
3614 Int code_a_f, Int data_a_f )
3616 Int i = 0;
3617 while (True) {
3618 if (i >= ilen) break;
3619 i += show_CF_instruction( ML_(cur_plus)(instrs, i),
3620 adi, code_a_f, data_a_f );
3625 /* Run the CF instructions in instrs[0 .. ilen-1], until the end is
3626 reached, or until there is a failure. Return True iff success.
3628 static
3629 Bool run_CF_instructions ( DebugInfo* di,
3630 Bool record,
3631 UnwindContext* ctx, DiCursor instrs, Int ilen,
3632 UWord fde_arange,
3633 const UnwindContext* restore_ctx,
3634 const AddressDecodingInfo* adi )
3636 Addr base;
3637 UInt len;
3638 DiCfSI_m cfsi_m;
3639 Bool summ_ok;
3640 Int j, i = 0;
3641 Addr loc_prev;
3642 if (0) ppUnwindContext(ctx);
3643 if (0) ppUnwindContext_summary(ctx);
3644 while (True) {
3645 loc_prev = ctx->loc;
3646 if (i >= ilen) break;
3647 if (0) (void)show_CF_instruction( ML_(cur_plus)(instrs,i), adi,
3648 ctx->code_a_f, ctx->data_a_f );
3649 j = run_CF_instruction( ctx, ML_(cur_plus)(instrs,i),
3650 restore_ctx, adi, di );
3651 if (j == 0)
3652 return False; /* execution failed */
3653 i += j;
3654 if (0) ppUnwindContext(ctx);
3655 if (record && loc_prev != ctx->loc) {
3656 summ_ok = summarise_context ( &base, &len, &cfsi_m,
3657 loc_prev, ctx, di );
3658 if (summ_ok) {
3659 ML_(addDiCfSI)(di, base, len, &cfsi_m);
3660 if (di->trace_cfi)
3661 ML_(ppDiCfSI)(di->cfsi_exprs, base, len, &cfsi_m);
3665 if (ctx->loc < fde_arange) {
3666 loc_prev = ctx->loc;
3667 ctx->loc = fde_arange;
3668 if (record) {
3669 summ_ok = summarise_context ( &base, &len, &cfsi_m,
3670 loc_prev, ctx, di );
3671 if (summ_ok) {
3672 ML_(addDiCfSI)(di, base, len, &cfsi_m);
3673 if (di->trace_cfi)
3674 ML_(ppDiCfSI)(di->cfsi_exprs, base, len, &cfsi_m);
3678 return True;
3682 /* ------------ Main entry point for CFI reading ------------ */
3684 typedef
3685 struct {
3686 /* This gives the CIE an identity to which FDEs will refer. */
3687 ULong offset;
3688 /* Code, data factors. */
3689 Int code_a_f;
3690 Int data_a_f;
3691 /* Return-address pseudo-register. */
3692 Int ra_reg;
3693 UChar address_encoding;
3694 /* Where are the instrs? */
3695 DiCursor instrs;
3696 Int ilen;
3697 /* God knows .. don't ask */
3698 Bool saw_z_augmentation;
3700 CIE;
3702 static void init_CIE ( CIE* cie )
3704 cie->offset = 0;
3705 cie->code_a_f = 0;
3706 cie->data_a_f = 0;
3707 cie->ra_reg = 0;
3708 cie->address_encoding = 0;
3709 cie->instrs = DiCursor_INVALID;
3710 cie->ilen = 0;
3711 cie->saw_z_augmentation = False;
3714 static CIE *the_CIEs = NULL;
3715 static SizeT N_CIEs = 0;
3717 /* Read, summarise and store CFA unwind info from .eh_frame and
3718 .debug_frame sections. is_ehframe tells us which kind we are
3719 dealing with -- they are slightly different. */
3720 void ML_(read_callframe_info_dwarf3)
3721 ( /*OUT*/struct _DebugInfo* di,
3722 DiSlice escn_frame, Addr frame_avma, Bool is_ehframe )
3724 const HChar* how = NULL;
3725 Int n_CIEs = 0;
3726 DiCursor frame_image = ML_(cur_from_sli)(escn_frame); /* fixed */
3727 DiOffT frame_size = escn_frame.szB;
3728 DiCursor data = frame_image;
3729 UWord cfsi_used_orig;
3731 /* If we're dealing with a .debug_frame, assume zero frame_avma. */
3732 if (!is_ehframe)
3733 vg_assert(frame_avma == 0);
3735 # if defined(VGP_ppc32_linux) || defined(VGP_ppc64be_linux) \
3736 || defined(VGP_ppc64le_linux)
3737 /* These targets don't use CFI-based stack unwinding. */
3738 return;
3739 # endif
3741 /* If we read more than one .debug_frame or .eh_frame for this
3742 DebugInfo*, the second and subsequent reads should only add FDEs
3743 for address ranges not already covered by the FDEs already
3744 present. To be able to quickly check which address ranges are
3745 already present, any existing records (DiCFSIs) must be sorted,
3746 so we can binary-search them in the code below. We also record
3747 di->cfsi_used so that we know where the boundary is between
3748 existing and new records. */
3749 if (di->cfsi_used > 0) {
3750 ML_(canonicaliseCFI) ( di );
3752 cfsi_used_orig = di->cfsi_used;
3754 if (di->trace_cfi) {
3755 VG_(printf)("\n-----------------------------------------------\n");
3756 VG_(printf)("CFI info: szB %llu, _avma %#lx\n",
3757 escn_frame.szB, frame_avma );
3758 VG_(printf)("CFI info: name %s\n", di->fsm.filename );
3761 /* Loop over CIEs/FDEs */
3763 /* Conceptually, the frame info is a sequence of FDEs, one for each
3764 function. Inside an FDE is a miniature program for a special
3765 state machine, which, when run, produces the stack-unwinding
3766 info for that function.
3768 Because the FDEs typically have much in common, and because the
3769 DWARF designers appear to have been fanatical about space
3770 saving, the common parts are factored out into so-called CIEs.
3771 That means that what we traverse is a sequence of structs, each
3772 of which is either a FDE (usually) or a CIE (occasionally).
3773 Each FDE has a field indicating which CIE is the one pertaining
3774 to it.
3776 The following loop traverses the sequence. FDEs are dealt with
3777 immediately; once we harvest the useful info in an FDE, it is
3778 then forgotten about. By contrast, CIEs are validated and
3779 dumped into an array, because later FDEs may refer to any
3780 previously-seen CIE.
3782 while (True) {
3783 DiCursor ciefde_start;
3784 ULong ciefde_len;
3785 ULong cie_pointer;
3786 Bool dw64;
3788 /* Are we done? */
3789 if (ML_(cur_cmpEQ)(data, ML_(cur_plus)(frame_image, frame_size)))
3790 return;
3792 /* Overshot the end? Means something is wrong */
3793 if (ML_(cur_cmpGT)(data, ML_(cur_plus)(frame_image, frame_size))) {
3794 how = "overran the end of .eh_frame";
3795 goto bad;
3798 /* Ok, we must be looking at the start of a new CIE or FDE.
3799 Figure out which it is. */
3801 ciefde_start = data;
3802 if (di->trace_cfi)
3803 VG_(printf)("\ncie/fde.start = (frame_image + 0x%llx)\n",
3804 (ULong)ML_(cur_minus)(ciefde_start, frame_image));
3806 ciefde_len = (ULong)ML_(cur_step_UInt)(&data);
3807 if (di->trace_cfi)
3808 VG_(printf)("cie/fde.length = %llu\n", ciefde_len);
3810 /* Apparently, if the .length field is zero, we are at the end
3811 of the sequence. This is stated in the Generic Elf
3812 Specification (see comments far above here) and is one of the
3813 places where .eh_frame and .debug_frame data differ. */
3814 if (ciefde_len == 0) {
3815 if (di->ddump_frames)
3816 VG_(printf)("%08llx ZERO terminator\n\n",
3817 (ULong)ML_(cur_minus)(ciefde_start, frame_image));
3818 return;
3821 /* If the .length field is 0xFFFFFFFF then we're dealing with
3822 64-bit DWARF, and the real length is stored as a 64-bit
3823 number immediately following it. */
3824 dw64 = False;
3825 if (ciefde_len == 0xFFFFFFFFUL) {
3826 dw64 = True;
3827 ciefde_len = ML_(cur_step_ULong)(&data);
3830 /* Now get the CIE ID, whose size depends on the DWARF 32 vs
3831 64-ness. */
3832 if (dw64) {
3833 /* see XXX below */
3834 cie_pointer = ML_(cur_step_ULong)(&data);
3835 } else {
3836 /* see XXX below */
3837 cie_pointer = (ULong)ML_(cur_step_UInt)(&data);
3840 if (di->trace_cfi)
3841 VG_(printf)("cie.pointer = %llu\n", cie_pointer);
3843 /* If cie_pointer is zero for .eh_frame or all ones for .debug_frame,
3844 we've got a CIE; else it's an FDE. */
3845 if (cie_pointer == (is_ehframe ? 0ULL
3846 : dw64 ? 0xFFFFFFFFFFFFFFFFULL : 0xFFFFFFFFULL)) {
3848 Int this_CIE;
3849 UChar cie_version;
3850 DiCursor cie_augmentation;
3852 /* --------- CIE --------- */
3853 if (di->trace_cfi)
3854 VG_(printf)("------ new CIE #%d ------\n", n_CIEs);
3856 /* Allocate a new CIE record. */
3857 vg_assert(n_CIEs >= 0);
3858 if (n_CIEs == N_CIEs) {
3859 N_CIEs += 1000;
3860 the_CIEs = ML_(dinfo_realloc)("di.rcid3.2", the_CIEs,
3861 N_CIEs * sizeof the_CIEs[0]);
3864 this_CIE = n_CIEs;
3865 n_CIEs++;
3866 init_CIE( &the_CIEs[this_CIE] );
3868 /* Record its offset. This is how we will find it again
3869 later when looking at an FDE. */
3870 the_CIEs[this_CIE].offset
3871 = (ULong)ML_(cur_minus)(ciefde_start, frame_image);
3873 if (di->ddump_frames)
3874 VG_(printf)("%08lx %08lx %08lx CIE\n",
3875 (Addr)ML_(cur_minus)(ciefde_start, frame_image),
3876 (Addr)ciefde_len,
3877 (Addr)(UWord)cie_pointer );
3879 cie_version = ML_(cur_step_UChar)(&data);
3880 if (di->trace_cfi)
3881 VG_(printf)("cie.version = %d\n", (Int)cie_version);
3882 if (di->ddump_frames)
3883 VG_(printf)(" Version: %d\n", (Int)cie_version);
3884 if (cie_version != 1 && cie_version != 3 && cie_version != 4) {
3885 how = "unexpected CIE version (not 1 nor 3 nor 4)";
3886 goto bad;
3889 cie_augmentation = data;
3890 data = ML_(cur_plus)(data, 1 + ML_(cur_strlen)(cie_augmentation));
3892 if (di->trace_cfi || di->ddump_frames) {
3893 HChar* str = ML_(cur_read_strdup)(cie_augmentation, "di.rcid3.1");
3894 if (di->trace_cfi)
3895 VG_(printf)("cie.augment = \"%s\"\n", str);
3896 if (di->ddump_frames)
3897 VG_(printf)(" Augmentation: \"%s\"\n", str);
3898 ML_(dinfo_free)(str);
3901 if (ML_(cur_read_UChar)(cie_augmentation) == 'e'
3902 && ML_(cur_read_UChar)
3903 (ML_(cur_plus)(cie_augmentation, 1)) == 'h') {
3904 data = ML_(cur_plus)(data, sizeof(Addr));
3905 cie_augmentation = ML_(cur_plus)(cie_augmentation, 2);
3908 if (cie_version >= 4) {
3909 if (ML_(cur_step_UChar)(&data) != sizeof(Addr)) {
3910 how = "unexpected address size";
3911 goto bad;
3913 if (ML_(cur_step_UChar)(&data) != 0) {
3914 how = "unexpected non-zero segment size";
3915 goto bad;
3919 the_CIEs[this_CIE].code_a_f = step_leb128( &data, 0);
3920 if (di->trace_cfi)
3921 VG_(printf)("cie.code_af = %d\n",
3922 the_CIEs[this_CIE].code_a_f);
3923 if (di->ddump_frames)
3924 VG_(printf)(" Code alignment factor: %d\n",
3925 (Int)the_CIEs[this_CIE].code_a_f);
3927 the_CIEs[this_CIE].data_a_f = step_leb128( &data, 1);
3928 if (di->trace_cfi)
3929 VG_(printf)("cie.data_af = %d\n",
3930 the_CIEs[this_CIE].data_a_f);
3931 if (di->ddump_frames)
3932 VG_(printf)(" Data alignment factor: %d\n",
3933 (Int)the_CIEs[this_CIE].data_a_f);
3935 if (cie_version == 1) {
3936 the_CIEs[this_CIE].ra_reg = (Int)ML_(cur_step_UChar)(&data);
3937 } else {
3938 the_CIEs[this_CIE].ra_reg = step_leb128( &data, 0);
3940 if (di->trace_cfi)
3941 VG_(printf)("cie.ra_reg = %d\n",
3942 the_CIEs[this_CIE].ra_reg);
3943 if (di->ddump_frames)
3944 VG_(printf)(" Return address column: %d\n",
3945 (Int)the_CIEs[this_CIE].ra_reg);
3947 if (the_CIEs[this_CIE].ra_reg < 0
3948 || the_CIEs[this_CIE].ra_reg >= N_CFI_REGS) {
3949 how = "cie.ra_reg has implausible value";
3950 goto bad;
3953 the_CIEs[this_CIE].saw_z_augmentation
3954 = ML_(cur_read_UChar)(cie_augmentation) == 'z';
3955 if (the_CIEs[this_CIE].saw_z_augmentation) {
3956 UInt length = step_leb128( &data, 0);
3957 the_CIEs[this_CIE].instrs = ML_(cur_plus)(data, length);
3958 cie_augmentation = ML_(cur_plus)(cie_augmentation, 1);
3959 if (di->ddump_frames) {
3960 UInt i;
3961 VG_(printf)(" Augmentation data: ");
3962 for (i = 0; i < length; i++)
3963 VG_(printf)(" %02x", (UInt)ML_(cur_read_UChar)
3964 (ML_(cur_plus)(data, i)));
3965 VG_(printf)("\n");
3967 } else {
3968 the_CIEs[this_CIE].instrs = DiCursor_INVALID;
3971 the_CIEs[this_CIE].address_encoding = default_Addr_encoding();
3973 while (ML_(cur_read_UChar)(cie_augmentation)) {
3974 switch (ML_(cur_read_UChar)(cie_augmentation)) {
3975 case 'L':
3976 data = ML_(cur_plus)(data, 1);
3977 cie_augmentation = ML_(cur_plus)(cie_augmentation, 1);
3978 break;
3979 case 'R':
3980 the_CIEs[this_CIE].address_encoding
3981 = ML_(cur_step_UChar)(&data);
3982 cie_augmentation = ML_(cur_plus)(cie_augmentation, 1);
3983 break;
3984 case 'P':
3985 data = ML_(cur_plus)(data, size_of_encoded_Addr(
3986 ML_(cur_read_UChar)(data) ));
3987 data = ML_(cur_plus)(data, 1);
3988 cie_augmentation = ML_(cur_plus)(cie_augmentation, 1);
3989 break;
3990 case 'S':
3991 cie_augmentation = ML_(cur_plus)(cie_augmentation, 1);
3992 break;
3993 default:
3994 if (!ML_(cur_is_valid)(the_CIEs[this_CIE].instrs)) {
3995 how = "unhandled cie.augmentation";
3996 goto bad;
3998 data = the_CIEs[this_CIE].instrs;
3999 goto done_augmentation;
4003 done_augmentation:
4005 if (di->trace_cfi)
4006 VG_(printf)("cie.encoding = 0x%x\n",
4007 the_CIEs[this_CIE].address_encoding);
4009 the_CIEs[this_CIE].instrs = data;
4010 the_CIEs[this_CIE].ilen = ML_(cur_minus)(ciefde_start, data)
4011 + (Long)ciefde_len + (Long)sizeof(UInt);
4012 if (di->trace_cfi) {
4013 //VG_(printf)("cie.instrs = %p\n", the_CIEs[this_CIE].instrs);
4014 VG_(printf)("cie.ilen = %d\n", the_CIEs[this_CIE].ilen);
4017 if (the_CIEs[this_CIE].ilen < 0
4018 || the_CIEs[this_CIE].ilen > frame_size) {
4019 how = "implausible # cie initial insns";
4020 goto bad;
4023 data = ML_(cur_plus)(data, the_CIEs[this_CIE].ilen);
4025 /* Show the CIE's instructions (the preamble for each FDE
4026 that uses this CIE). */
4027 if (di->ddump_frames)
4028 VG_(printf)("\n");
4030 if (di->trace_cfi || di->ddump_frames) {
4031 AddressDecodingInfo adi;
4032 adi.encoding = the_CIEs[this_CIE].address_encoding;
4033 adi.ehframe_image = frame_image;
4034 adi.ehframe_avma = frame_avma;
4035 adi.text_bias = di->text_debug_bias;
4036 adi.got_avma = di->got_avma;
4037 show_CF_instructions( the_CIEs[this_CIE].instrs,
4038 the_CIEs[this_CIE].ilen, &adi,
4039 the_CIEs[this_CIE].code_a_f,
4040 the_CIEs[this_CIE].data_a_f );
4043 if (di->ddump_frames)
4044 VG_(printf)("\n");
4046 } else {
4048 AddressDecodingInfo adi;
4049 UnwindContext ctx, restore_ctx;
4050 Int cie;
4051 ULong look_for;
4052 Bool ok;
4053 Addr fde_initloc;
4054 UWord fde_arange;
4055 DiCursor fde_instrs;
4056 Int fde_ilen;
4058 /* --------- FDE --------- */
4060 /* Find the relevant CIE. The CIE we want is located
4061 cie_pointer bytes back from here. */
4063 /* re sizeof(UInt) / sizeof(ULong), matches XXX above. */
4064 if (is_ehframe)
4065 look_for = ML_(cur_minus)(data, frame_image)
4066 - (dw64 ? sizeof(ULong) : sizeof(UInt))
4067 - cie_pointer;
4068 else
4069 look_for = cie_pointer;
4071 for (cie = 0; cie < n_CIEs; cie++) {
4072 if (0) VG_(printf)("look for %llu %llu\n",
4073 look_for, the_CIEs[cie].offset );
4074 if (the_CIEs[cie].offset == look_for)
4075 break;
4077 vg_assert(cie >= 0 && cie <= n_CIEs);
4078 if (cie == n_CIEs) {
4079 how = "FDE refers to not-findable CIE";
4080 goto bad;
4083 adi.encoding = the_CIEs[cie].address_encoding;
4084 adi.ehframe_image = frame_image;
4085 adi.ehframe_avma = frame_avma;
4086 adi.text_bias = di->text_debug_bias;
4087 adi.got_avma = di->got_avma;
4088 fde_initloc = step_encoded_Addr(&adi, &data);
4089 if (di->trace_cfi)
4090 VG_(printf)("fde.initloc = %#lx\n", fde_initloc);
4092 adi.encoding = the_CIEs[cie].address_encoding & 0xf;
4093 adi.ehframe_image = frame_image;
4094 adi.ehframe_avma = frame_avma;
4095 adi.text_bias = di->text_debug_bias;
4096 adi.got_avma = di->got_avma;
4098 /* WAS (incorrectly):
4099 fde_arange = read_encoded_Addr(&nbytes, &adi, data);
4100 data += nbytes;
4101 The following corresponds to what binutils/dwarf.c does:
4103 { UInt ptr_size = size_of_encoded_Addr( adi.encoding );
4104 switch (ptr_size) {
4105 case 8: case 4: case 2: case 1:
4106 fde_arange
4107 = (UWord)step_le_u_encoded_literal(&data, ptr_size);
4108 break;
4109 default:
4110 how = "unknown arange field encoding in FDE";
4111 goto bad;
4115 if (di->trace_cfi)
4116 VG_(printf)("fde.arangec = %#lx\n", fde_arange);
4118 if (di->ddump_frames)
4119 VG_(printf)("%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
4120 (Addr)ML_(cur_minus)(ciefde_start, frame_image),
4121 (Addr)ciefde_len,
4122 (Addr)(UWord)cie_pointer,
4123 (Addr)look_for,
4124 ((Addr)fde_initloc) - di->text_debug_bias,
4125 ((Addr)fde_initloc) - di->text_debug_bias + fde_arange);
4127 if (the_CIEs[cie].saw_z_augmentation) {
4128 UInt length = step_leb128( &data, 0);
4129 if (di->ddump_frames && (length > 0)) {
4130 UInt i;
4131 VG_(printf)(" Augmentation data: ");
4132 for (i = 0; i < length; i++)
4133 VG_(printf)(" %02x", (UInt)ML_(cur_read_UChar)
4134 (ML_(cur_plus)(data, i)));
4135 VG_(printf)("\n\n");
4137 data = ML_(cur_plus)(data, length);
4140 fde_instrs = data;
4141 fde_ilen = ML_(cur_minus)(ciefde_start, data)
4142 + (Long)ciefde_len + (Long)sizeof(UInt);
4143 if (di->trace_cfi) {
4144 //VG_(printf)("fde.instrs = %p\n", fde_instrs);
4145 VG_(printf)("fde.ilen = %d\n", (Int)fde_ilen);
4148 if (fde_ilen < 0 || fde_ilen > frame_size) {
4149 how = "implausible # fde insns";
4150 goto bad;
4153 data = ML_(cur_plus)(data, fde_ilen);
4155 /* If this object's DebugInfo* had some DiCFSIs from a
4156 previous .eh_frame or .debug_frame read, we must check
4157 that we're not adding a duplicate. */
4158 if (cfsi_used_orig > 0) {
4159 Addr a_mid_lo, a_mid_hi;
4160 Word mid, size,
4161 lo = 0,
4162 hi = cfsi_used_orig-1;
4163 while (True) {
4164 /* current unsearched space is from lo to hi, inclusive. */
4165 if (lo > hi) break; /* not found */
4166 mid = (lo + hi) / 2;
4167 a_mid_lo = di->cfsi_rd[mid].base;
4168 size = di->cfsi_rd[mid].len;
4169 a_mid_hi = a_mid_lo + size - 1;
4170 vg_assert(a_mid_hi >= a_mid_lo);
4171 if (fde_initloc + fde_arange <= a_mid_lo) {
4172 hi = mid-1; continue;
4174 if (fde_initloc > a_mid_hi) { lo = mid+1; continue; }
4175 break;
4178 /* The range this .debug_frame FDE covers has been already
4179 covered in .eh_frame section. Don't add it from .debug_frame
4180 section again. */
4181 if (lo <= hi)
4182 continue;
4185 adi.encoding = the_CIEs[cie].address_encoding;
4186 adi.ehframe_image = frame_image;
4187 adi.ehframe_avma = frame_avma;
4188 adi.text_bias = di->text_debug_bias;
4189 adi.got_avma = di->got_avma;
4191 if (di->trace_cfi)
4192 show_CF_instructions( fde_instrs, fde_ilen, &adi,
4193 the_CIEs[cie].code_a_f,
4194 the_CIEs[cie].data_a_f );
4196 initUnwindContext(&ctx);
4197 ctx.code_a_f = the_CIEs[cie].code_a_f;
4198 ctx.data_a_f = the_CIEs[cie].data_a_f;
4199 ctx.initloc = fde_initloc;
4200 ctx.ra_reg = the_CIEs[cie].ra_reg;
4201 ctx.exprs = VG_(newXA)( ML_(dinfo_zalloc), "di.rcid.1",
4202 ML_(dinfo_free),
4203 sizeof(CfiExpr) );
4205 /* Run the CIE's instructions. Ugly hack: if
4206 --debug-dump=frames is in effect, suppress output for
4207 these instructions since they will already have been shown
4208 at the time the CIE was first encountered. Note, not
4209 thread safe - if this reader is ever made threaded, should
4210 fix properly. */
4211 { Bool hack = di->ddump_frames;
4212 di->ddump_frames = False;
4213 initUnwindContext(&restore_ctx);
4214 ok = run_CF_instructions(
4215 di, False, &ctx, the_CIEs[cie].instrs,
4216 the_CIEs[cie].ilen, 0, NULL, &adi
4218 di->ddump_frames = hack;
4220 /* And now run the instructions for the FDE, starting from
4221 the state created by running the CIE preamble
4222 instructions. */
4223 if (ok) {
4224 restore_ctx = ctx;
4225 ok = run_CF_instructions(
4226 di, True, &ctx, fde_instrs, fde_ilen, fde_arange,
4227 &restore_ctx, &adi
4229 if (di->ddump_frames)
4230 VG_(printf)("\n");
4233 VG_(deleteXA)( ctx.exprs );
4237 return;
4239 bad:
4240 if (!VG_(clo_xml) && VG_(clo_verbosity) > 1)
4241 VG_(message)(Vg_UserMsg,
4242 "Warning: %s in DWARF2 CFI reading\n", how);
4243 return;
4246 #endif // defined(VGO_linux) || defined(VGO_darwin) || defined(VGO_solaris)
4248 /*--------------------------------------------------------------------*/
4249 /*--- end ---*/
4250 /*--------------------------------------------------------------------*/