Debian Codegraph @

src/bin/dwarfdump/print_frames.c

raw
1 /*
2 Copyright (C) 2006 Silicon Graphics, Inc. All Rights Reserved.
3 Portions Copyright (C) 2011-2018 SN Systems Ltd. All Rights Reserved.
4 Portions Copyright (C) 2007-2020 David Anderson. All Rights Reserved.
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of version 2 of the GNU General
8 Public License as published by the Free Software Foundation.
9
10 This program is distributed in the hope that it would be
11 useful, but WITHOUT ANY WARRANTY; without even the implied
12 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE.
14
15 Further, this software is distributed without any warranty
16 that it is free of the rightful claim of any third person
17 regarding infringement or the like. Any license provided
18 herein, whether implied or otherwise, applies only to this
19 software file. Patent licenses, if any, provided herein
20 do not apply to combinations of this program with other
21 software, or any other product whatsoever.
22
23 You should have received a copy of the GNU General Public
24 License along with this program; if not, write the Free
25 Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
26 Boston MA 02110-1301, USA.
27 */
28
29 /* From 199x through 2010 print_frames relied on
30 the order of the fdes matching the order of the functions
31 in the CUs when it came to printing a function name with
32 an FDE. This sometimes worked for SGI/IRIX because of
33 the way the compiler often emitted things.
34 It always worked poorly
35 for gcc and other compilers.
36
37 As of 2010 the addrmap.h addrmap.h code provides help
38 in doing a better job when the tsearch functions (part of
39 POSIX) are available. */
40
41 #include <config.h>
42
43 #include <stdlib.h> /* exit() */
44 #include <string.h> /* strlen() */
45 #include <stdio.h> /* FILE decl for dd_esb.h, printf etc */
46
47 #include "dwarf.h"
48 #include "libdwarf.h"
49 #include "libdwarf_private.h"
50 #include "dd_defined_types.h"
51 #include "dd_checkutil.h"
52 #include "dd_glflags.h"
53 #include "dd_globals.h"
54 #include "dd_dwconf.h"
55 #include "dd_dwconf_using_functions.h"
56 #include "dd_esb.h"
57 #include "dd_esb_using_functions.h"
58 #include "dd_sanitized.h"
59 #include "dd_addrmap.h"
60 #include "dd_naming.h"
61 #include "dd_safe_strcpy.h"
62 #include "dd_glflags.h"
63 #include "print_frames.h"
64
65 #define TRUE 1
66 #define FALSE 0
67
68 #undef TESTOLDDW_OFFSET /* define only for a test. */
69
70 Dwarf_Sig8 zero_type_signature;
71 static void
72 print_one_frame_reg_col(Dwarf_Debug dbg,
73 Dwarf_Die die,
74 Dwarf_Unsigned rule_id,
75 Dwarf_Small value_type,
76 Dwarf_Unsigned reg_used,
77 Dwarf_Half addr_size,
78 Dwarf_Half offset_size,
79 Dwarf_Half version,
80 struct dwconf_s *config_data,
81 Dwarf_Signed offset_relevant,
82 Dwarf_Signed offset,
83 Dwarf_Block * block_ptr);
84
85 static void
86 print_frame_inst_bytes(Dwarf_Debug dbg,
87 Dwarf_Frame_Instr_Head instr_head,
88 Dwarf_Unsigned instr_array_len,
89 Dwarf_Die die,
90 Dwarf_Signed data_alignment_factor,
91 Dwarf_Unsigned code_alignment_factor,
92 Dwarf_Half addr_size,
93 Dwarf_Half offset_size,
94 Dwarf_Half version,
95 struct dwconf_s *config_data);
96
97 static void
98 dealloc_local_atlist(Dwarf_Debug dbg,
99 Dwarf_Attribute *atlist,
100 Dwarf_Signed atcnt)
101 {
102 Dwarf_Signed k = 0;
103
104 for (; k < atcnt; k++) {
105 dwarf_dealloc(dbg, atlist[k], DW_DLA_ATTR);
106 }
107 dwarf_dealloc(dbg, atlist, DW_DLA_LIST);
108 }
109
110 /* Executing this for a reporting side effect,
111 PRINT_CU_INFO() in dwarfdump.c. */
112 static void
113 load_CU_error_data(Dwarf_Debug dbg,Dwarf_Die cu_die)
114 {
115 Dwarf_Signed atcnt = 0;
116 Dwarf_Attribute *atlist = 0;
117 Dwarf_Half tag = 0;
118 char **srcfiles = 0;
119 Dwarf_Signed srccnt = 0;
120 int local_show_form_used = 0;
121 int local_verbose = 0;
122 int atres = 0;
123 Dwarf_Signed i = 0;
124 Dwarf_Signed k = 0;
125 Dwarf_Error loadcuerr = 0;
126 Dwarf_Off cu_die_goff = 0;
127
128 if (!cu_die) {
129 return;
130 }
131 atres = dwarf_attrlist(cu_die, &atlist, &atcnt, &loadcuerr);
132 if (atres != DW_DLV_OK) {
133 /* Something is seriously wrong if it is DW_DLV_ERROR. */
134 DROP_ERROR_INSTANCE(dbg,atres,loadcuerr);
135 return;
136 }
137 atres = dwarf_tag(cu_die, &tag, &loadcuerr);
138 if (atres != DW_DLV_OK) {
139 for (k = 0; k < atcnt; k++) {
140 dwarf_dealloc(dbg, atlist[k], DW_DLA_ATTR);
141 }
142 dealloc_local_atlist(dbg,atlist,atcnt);
143 /* Something is seriously wrong if it is DW_DLV_ERROR. */
144 DROP_ERROR_INSTANCE(dbg,atres,loadcuerr);
145 return;
146 }
147
148 /* The offsets will be zero if it fails. Let it pass. */
149 atres = dwarf_die_offsets(cu_die,&glflags.DIE_section_offset,
150 &glflags.DIE_offset,&loadcuerr);
151 cu_die_goff = glflags.DIE_section_offset;
152 DROP_ERROR_INSTANCE(dbg,atres,loadcuerr);
153
154 glflags.DIE_CU_overall_offset = glflags.DIE_section_offset;
155 glflags.DIE_CU_offset = glflags.DIE_offset;
156 for (i = 0; i < atcnt; i++) {
157 Dwarf_Half attr = 0;
158 int ares = 0;
159 Dwarf_Attribute attrib = atlist[i];
160
161 ares = dwarf_whatattr(attrib, &attr, &loadcuerr);
162 if (ares != DW_DLV_OK) {
163 for (k = 0; k < atcnt; k++) {
164 dwarf_dealloc(dbg, atlist[k], DW_DLA_ATTR);
165 }
166 dealloc_local_atlist(dbg,atlist,atcnt);
167 DROP_ERROR_INSTANCE(dbg,ares,loadcuerr);
168 return;
169 }
170 /* For now we will not fully deal with the complexity of
171 DW_AT_high_pc being an offset of low pc. */
172 switch(attr) {
173 case DW_AT_low_pc:
174 {
175 ares = dwarf_formaddr(attrib,
176 &glflags.CU_base_address, &loadcuerr);
177 DROP_ERROR_INSTANCE(dbg,ares,loadcuerr);
178 glflags.CU_low_address = glflags.CU_base_address;
179 }
180 break;
181 case DW_AT_high_pc:
182 {
183 /* This is wrong for DWARF4 instances where
184 the attribute is really an offset.
185 It's also useless for CU DIEs that do not
186 have the DW_AT_high_pc high so CU_high_address will
187 be zero*/
188 ares = dwarf_formaddr(attrib,
189 &glflags.CU_high_address, &loadcuerr);
190 DROP_ERROR_INSTANCE(dbg,ares,loadcuerr);
191 }
192 break;
193 case DW_AT_name:
194 case DW_AT_producer:
195 {
196 const char *name = 0;
197 struct esb_s namestr;
198
199 esb_constructor(&namestr);
200 ares = get_attr_value(dbg, tag, cu_die,
201 cu_die_goff,attrib, srcfiles, srccnt,
202 &namestr, local_show_form_used,local_verbose,
203 &loadcuerr);
204 DROP_ERROR_INSTANCE(dbg,ares,loadcuerr);
205 if (esb_string_len(&namestr)) {
206 name = esb_get_string(&namestr);
207 if (attr == DW_AT_name) {
208 dd_safe_strcpy(glflags.CU_name,
209 sizeof( glflags.CU_name),
210 name, strlen(name));
211 } else {
212 dd_safe_strcpy(glflags.CU_producer,
213 sizeof(glflags.CU_producer),
214 name,strlen(name));
215 }
216 }
217 esb_destructor(&namestr);
218 }
219 break;
220 default:
221 /* do nothing */
222 break;
223 }
224 }
225 dealloc_local_atlist(dbg,atlist,atcnt);
226 return;
227 }
228
229 /* For inlined functions, try to find name.
230 If we fail due to error we hide the error. For now.
231 Returns DW_DLV_OK or DW_DLV_NO_ENTRY for now. */
232 static int
233 get_abstract_origin_funcname(Dwarf_Debug dbg,
234 Dwarf_Die die, Dwarf_Attribute attr,
235 struct esb_s *name_out)
236 {
237 Dwarf_Off off = 0;
238 Dwarf_Die origin_die = 0;
239 Dwarf_Attribute *atlist = NULL;
240 Dwarf_Signed atcnt = 0;
241 Dwarf_Signed i = 0;
242 int dres = 0;
243 int atres = 0;
244 int name_found = 0;
245 int res = 0;
246 Dwarf_Error err = 0;
247 Dwarf_Bool is_info = dwarf_get_die_infotypes_flag(die);
248
249 res = dwarf_global_formref_b(attr,&off,&is_info,&err);
250 if (res == DW_DLV_ERROR) {
251 dwarf_dealloc(dbg,err,DW_DLA_ERROR);
252 return DW_DLV_NO_ENTRY;
253 }
254 if (res == DW_DLV_NO_ENTRY) {
255 return DW_DLV_NO_ENTRY;
256 }
257 dres = dwarf_offdie_b(dbg,off,is_info,&origin_die,&err);
258 if (dres == DW_DLV_ERROR) {
259 dwarf_dealloc(dbg,err,DW_DLA_ERROR);
260 return DW_DLV_NO_ENTRY;
261 }
262 if (dres == DW_DLV_NO_ENTRY) {
263 return DW_DLV_NO_ENTRY;
264 }
265 atres = dwarf_attrlist(origin_die, &atlist, &atcnt, &err);
266 if (atres == DW_DLV_ERROR) {
267 dwarf_dealloc(dbg,origin_die,DW_DLA_DIE);
268 dwarf_dealloc(dbg,err,DW_DLA_ERROR);
269 return DW_DLV_NO_ENTRY;
270 }
271 if (atres == DW_DLV_NO_ENTRY) {
272 dwarf_dealloc(dbg,origin_die,DW_DLA_DIE);
273 return DW_DLV_NO_ENTRY;
274 }
275 for (i = 0; i < atcnt; i++) {
276 Dwarf_Half lattr = 0;
277 int ares = 0;
278
279 ares = dwarf_whatattr(atlist[i], &lattr, &err);
280 if (ares == DW_DLV_ERROR) {
281 break;
282 } else if (ares == DW_DLV_OK) {
283 if (lattr == DW_AT_name) {
284 int sres = 0;
285 char* tempsl = 0;
286
287 sres = dwarf_formstring(atlist[i], &tempsl, &err);
288 if (sres == DW_DLV_OK) {
289 esb_append(name_out,tempsl);
290 name_found = TRUE;
291 break;
292 }
293 }
294 }
295 }
296 for (i = 0; i < atcnt; i++) {
297 dwarf_dealloc(dbg, atlist[i], DW_DLA_ATTR);
298 }
299 dwarf_dealloc(dbg, atlist, DW_DLA_LIST);
300 dwarf_dealloc(dbg,origin_die,DW_DLA_DIE);
301 if (!name_found) {
302 return DW_DLV_NO_ENTRY;
303 }
304 return DW_DLV_OK;
305 }
306 /*
307 Returns DW_DLV_OK if a proc with this low_pc found.
308 Else returns DW_DLV_NO_ENTRY.
309
310 From print_die.c this has no pcMap passed in,
311 we do not really have a sensible context, so this
312 really just looks at the current attributes for a name.
313
314 From print_frames.c we do have a pcMap.
315 */
316 int
317 get_proc_name_by_die(Dwarf_Debug dbg,
318 Dwarf_Die die,
319 Dwarf_Addr low_pc,
320 struct esb_s *proc_name,
321 Dwarf_Die * cu_die_for_print_frames,
322 void **pcMap,
323 Dwarf_Error *err)
324 {
325 Dwarf_Signed atcnt = 0;
326 Dwarf_Signed i = 0;
327 Dwarf_Attribute *atlist = NULL;
328 Dwarf_Addr low_pc_for_die = 0;
329 int atres = 0;
330 int funcpcfound = 0;
331 int funcres = DW_DLV_OK;
332 int funcnamefound = 0;
333 int loop_ok = TRUE;
334
335 if (pcMap) {
336 struct Addr_Map_Entry *ame = 0;
337 ame = addr_map_find(low_pc,pcMap);
338 if (ame && ame->mp_name) {
339 /* mp_name is NULL only if we ran out of heap space. */
340 esb_append(proc_name,ame->mp_name);
341 return DW_DLV_OK;
342 }
343 }
344 if (glflags.gf_all_cus_seen_search_by_address) {
345 return DW_DLV_NO_ENTRY;
346 }
347 if (glflags.gf_debug_addr_missing) {
348 return DW_DLV_NO_ENTRY;
349 }
350 atres = dwarf_attrlist(die, &atlist, &atcnt, err);
351 if (atres == DW_DLV_ERROR) {
352 load_CU_error_data(dbg,*cu_die_for_print_frames);
353 simple_err_only_return_action(atres,
354 "\nERROR: dwarf_attrlist call fails in attempt "
355 " to get a procedure/function name");
356 return atres;
357 }
358 if (atres == DW_DLV_NO_ENTRY) {
359 return atres;
360 }
361 for (i = 0; i < atcnt; i++) {
362 Dwarf_Half attr = 0;
363 int ares = 0;
364 char * temps = 0;
365 int sres = 0;
366 int dres = 0;
367
368 if (!loop_ok) {
369 break;
370 }
371 if (funcnamefound == 1 && funcpcfound == 1) {
372 /* stop as soon as both found */
373 break;
374 }
375 ares = dwarf_whatattr(atlist[i], &attr, err);
376 if (ares == DW_DLV_ERROR) {
377 struct esb_s m;
378 esb_constructor(&m);
379 load_CU_error_data(dbg,*cu_die_for_print_frames);
380 esb_append_printf_s(&m,
381 "\nERROR: dwarf_whatattr fails with %s",
382 dwarf_errmsg(*err));
383 simple_err_only_return_action(ares,
384 esb_get_string(&m));
385 esb_destructor(&m);
386 dealloc_local_atlist(dbg,atlist,atcnt);
387 return DW_DLV_ERROR;
388 } else if (ares == DW_DLV_OK) {
389 Dwarf_Error aterr = 0;
390 switch (attr) {
391 case DW_AT_specification:
392 case DW_AT_abstract_origin:
393 if (!funcnamefound) {
394 /* Only use this if we have not seen DW_AT_name
395 yet .*/
396 int aores = get_abstract_origin_funcname(dbg,
397 die,
398 atlist[i], proc_name);
399 if (aores == DW_DLV_OK) {
400 /* FOUND THE NAME */
401 funcnamefound = 1;
402 }
403 }
404 break;
405 case DW_AT_name:
406 /* Even if we saw DW_AT_abstract_origin, go ahead
407 and take DW_AT_name. */
408 sres = dwarf_formstring(atlist[i], &temps, &aterr);
409 if (sres == DW_DLV_ERROR) {
410 glflags.gf_count_major_errors++;
411 printf("\nERROR: "
412 "formstring in get_proc_name failed\n");
413 esb_append(proc_name,
414 "ERROR in dwarf_formstring!");
415 dwarf_dealloc(dbg,aterr,DW_DLA_ERROR);
416 aterr = 0;
417 } else if (sres == DW_DLV_NO_ENTRY) {
418 esb_append(proc_name,
419 "NO ENTRY on dwarf_formstring?!");
420 } else {
421 esb_append(proc_name,temps);
422 }
423 funcnamefound = 1; /* FOUND THE NAME (sort of,
424 if error) */
425 break;
426 case DW_AT_low_pc:
427 dres = dwarf_formaddr(atlist[i],
428 &low_pc_for_die, &aterr);
429 funcpcfound = 1;
430 if (dres == DW_DLV_ERROR) {
431 if (DW_DLE_MISSING_NEEDED_DEBUG_ADDR_SECTION ==
432 dwarf_errno(aterr)) {
433 glflags.gf_debug_addr_missing = 1;
434 } else {
435 glflags.gf_count_major_errors++;
436 printf("\nERROR: dwarf_formaddr() failed"
437 " in get_proc_name. %s\n",
438 dwarf_errmsg(aterr));
439 /* the long name is horrible */
440 if (!glflags.gf_error_code_search_by_address){
441 /* error codes never big numbers. */
442 glflags.gf_error_code_search_by_address=
443 (int)dwarf_errno(aterr);
444 }
445 }
446 dwarf_dealloc(dbg,aterr,DW_DLA_ERROR);
447 aterr = 0;
448 funcpcfound = 0;
449 low_pc_for_die = 0;
450 /* low_pc_for_die = ~low_pc; ??? */
451 loop_ok = FALSE;
452 /* ensure no match */
453 } else if (dres == DW_DLV_NO_ENTRY) {
454 funcpcfound = 0;
455 loop_ok = FALSE;
456 }
457 break;
458 default:
459 break;
460 } /* end switch */
461 } /* end DW_DLV_OK */
462 } /* end for loop on atcnt */
463 dealloc_local_atlist(dbg,atlist,atcnt);
464 if (funcnamefound && funcpcfound && pcMap ) {
465 /* Insert the name to map even if not
466 the low_pc we are looking for.
467 This version does extra work in that
468 early symbols in a CU will be inserted
469 multiple times (the extra times have no
470 effect). */
471 addr_map_insert(low_pc_for_die,esb_get_string(proc_name),
472 pcMap);
473 }
474 if (funcnamefound == 0 || funcpcfound == 0 ||
475 low_pc != low_pc_for_die) {
476 funcres = DW_DLV_NO_ENTRY;
477 }
478 return funcres;
479 }
480
481 /* Modified Depth First Search looking for the procedure:
482 a) only looks for children of subprogram.
483 b) With subprogram looks at current die *before* looking
484 for a child.
485
486 Needed since some languages, including SGI MP Fortran,
487 have nested functions.
488 Return 0 on failure, 1 on success.
489 */
490 static int
491 load_nested_proc_name(Dwarf_Debug dbg, Dwarf_Die die,
492 Dwarf_Addr low_pc,
493 struct esb_s *ret_name,
494 Dwarf_Die *cu_die_for_print_frames,
495 void **pcMap,
496 Dwarf_Error *err)
497 {
498 Dwarf_Die curdie = die;
499 int die_locally_gotten = 0;
500 Dwarf_Die prev_child = 0;
501 Dwarf_Die newchild = 0;
502 Dwarf_Die newsibling = 0;
503 Dwarf_Half tag;
504 int chres = DW_DLV_OK;
505 struct esb_s nestname;
506
507 esb_constructor(&nestname);
508 while (chres == DW_DLV_OK) {
509 int tres = 0;
510
511 esb_empty_string(&nestname);
512 tres = dwarf_tag(curdie, &tag, err);
513 newchild = 0;
514 if (tres == DW_DLV_OK) {
515 int lchres = 0;
516
517 if (tag == DW_TAG_subprogram) {
518 int gotit = 0;
519 Dwarf_Error locerr = 0;
520 gotit = get_proc_name_by_die(dbg, curdie, low_pc,
521 &nestname, cu_die_for_print_frames,
522 pcMap,&locerr);
523 if (gotit == DW_DLV_OK) {
524 if (die_locally_gotten) {
525 /* If we got this die from the parent, we do
526 not want to dealloc here! */
527 dwarf_dealloc(dbg, curdie, DW_DLA_DIE);
528 }
529 esb_append(ret_name,esb_get_string(&nestname));
530 esb_destructor(&nestname);
531 return DW_DLV_OK;
532 }
533 if (gotit == DW_DLV_ERROR) {
534 dwarf_dealloc(dbg,locerr,DW_DLA_ERROR);
535 locerr = 0;
536 }
537 /* Check children of subprograms recursively should
538 this really be check children of anything,
539 or just children of subprograms? */
540
541 lchres = dwarf_child(curdie, &newchild, err);
542 esb_empty_string(&nestname);
543 if (lchres == DW_DLV_OK) {
544 int newprog = 0;
545 Dwarf_Error innererr = 0;
546 /* look for inner subprogram */
547 newprog = load_nested_proc_name(dbg,
548 newchild, low_pc,
549 &nestname,
550 cu_die_for_print_frames,
551 pcMap,&innererr);
552 dwarf_dealloc(dbg, newchild, DW_DLA_DIE);
553 if (newprog == DW_DLV_OK) {
554 /* Found it. We could just take this
555 name or we could concatenate names
556 together. For now,
557 just take name */
558 if (die_locally_gotten) {
559 /* If we got this die from the parent,
560 we do not want to dealloc here! */
561 dwarf_dealloc(dbg, curdie, DW_DLA_DIE);
562 }
563 esb_append(ret_name,esb_get_string(
564 &nestname));
565 esb_destructor(&nestname);
566 return DW_DLV_OK;
567 } else if (newprog == DW_DLV_ERROR) {
568 dwarf_dealloc(dbg,innererr,DW_DLA_ERROR);
569 innererr = 0;
570 }
571 } else if (lchres == DW_DLV_NO_ENTRY) {
572 /* nothing to do */
573 } else {
574 load_CU_error_data(dbg,*cu_die_for_print_frames);
575 simple_err_only_return_action(lchres,
576 "\nERROR:load_nested_proc_name dwarf_child()"
577 " failed.");
578 if (die_locally_gotten) {
579 /* If we got this die from the parent, we do
580 not want to dealloc here! */
581 dwarf_dealloc(dbg, curdie, DW_DLA_DIE);
582 }
583 esb_destructor(&nestname);
584 return lchres;
585 }
586 } /* end if TAG_subprogram */
587 } else {
588 esb_empty_string(&nestname);
589 if (tres == DW_DLV_ERROR) {
590 struct esb_s m;
591
592 load_CU_error_data(dbg,*cu_die_for_print_frames);
593 esb_constructor(&m);
594 esb_append_printf_s(&m,
595 "\nERROR: load_nested_proc_name dwarf_tag failed:"
596 " trying to get proc name. "
597 "Error is %s.",dwarf_errmsg(*err));
598 simple_err_only_return_action(tres,
599 esb_get_string(&m));
600 esb_destructor(&m);
601 esb_destructor(&nestname);
602 return tres;
603 }
604 if (die_locally_gotten) {
605 /* If we got this die from the parent, we do not want
606 to dealloc here! */
607 dwarf_dealloc(dbg, curdie, DW_DLA_DIE);
608 }
609 esb_destructor(&nestname);
610 return DW_DLV_NO_ENTRY;
611 }
612 /* try next sibling */
613 prev_child = curdie;
614 esb_empty_string(&nestname);
615 #ifdef ORIGINAL_HEADER_API
616 chres = dwarf_siblingof_b(dbg, curdie,
617 dwarf_get_die_infotypes_flag(curdie),
618 &newsibling, err);
619 #else
620 chres = dwarf_siblingof_c(curdie,&newsibling,err);
621 #endif /* ORIGINAL_HEADER_API */
622 if (chres == DW_DLV_ERROR) {
623 struct esb_s m;
624
625 load_CU_error_data(dbg,*cu_die_for_print_frames);
626 esb_constructor(&m);
627 esb_append(&m,
628 "Looking for function name for "
629 "a frame. "
630 "dwarf_siblingof failed"
631 " trying to get the name. ");
632 print_error_and_continue(
633 esb_get_string(&m), chres,*err);
634 esb_destructor(&m);
635 DROP_ERROR_INSTANCE(dbg,chres,*err);
636 if (die_locally_gotten) {
637 /* If we got this die from the parent, we do not want
638 to dealloc here! */
639 dwarf_dealloc(dbg, curdie, DW_DLA_DIE);
640 }
641 esb_destructor(&nestname);
642 return DW_DLV_NO_ENTRY;
643 } else if (chres == DW_DLV_NO_ENTRY) {
644 if (die_locally_gotten) {
645 /* If we got this die from the parent, we do not want
646 to dealloc here! */
647 dwarf_dealloc(dbg, prev_child, DW_DLA_DIE);
648 prev_child = 0;
649 }
650 /* Not there at this level */
651 esb_destructor(&nestname);
652 return DW_DLV_NO_ENTRY;
653 }
654 /* DW_DLV_OK */
655 curdie = newsibling;
656 if (die_locally_gotten) {
657 /* If we got this die from the parent, we do not want
658 to dealloc here! */
659 dwarf_dealloc(dbg, prev_child, DW_DLA_DIE);
660 /* Clearing prev_child here gets coverity 330895
661 unused value warning.
662 prev_child = 0; */
663 }
664 die_locally_gotten = 1;
665 }
666 if (die_locally_gotten) {
667 /* If we got this die from the parent, we do not want to
668 dealloc here! */
669 dwarf_dealloc(dbg, curdie, DW_DLA_DIE);
670 }
671 esb_destructor(&nestname);
672 return DW_DLV_NO_ENTRY;
673 }
674
675 /* For SGI MP Fortran and other languages, functions
676 nest! As a result, we must dig thru all functions,
677 not just the top level.
678 This remembers the CU die and restarts each search at the start
679 of the current cu.
680 Return DW_DLV_OK means found name.
681 Return DW_DLV_NO_ENTRY means not found name.
682 Never returns DW_DLV_ERROR
683 */
684 static int
685 get_fde_proc_name_by_address(Dwarf_Debug dbg, Dwarf_Addr low_pc,
686 const char *frame_section_name,
687 struct esb_s *name,
688 Dwarf_Die *cu_die_for_print_frames,
689 void **pcMap,Dwarf_Error *err)
690 {
691 Dwarf_Unsigned cu_header_length = 0;
692 Dwarf_Unsigned abbrev_offset = 0;
693 Dwarf_Half version_stamp = 0;
694 Dwarf_Half address_size = 0;
695 Dwarf_Unsigned next_cu_offset = 0;
696 int cures = DW_DLV_OK;
697 int dres = DW_DLV_OK;
698 int chres = DW_DLV_OK;
699 struct Addr_Map_Entry *ame = 0;
700 Dwarf_Half length_size = 0;
701 Dwarf_Half extension_size = 0;
702 Dwarf_Sig8 type_signature;
703 Dwarf_Unsigned typeoffset = 0;
704 Dwarf_Half header_cu_type = 0;
705 Dwarf_Bool is_info = TRUE; /* An assumption, but
706 sensible as functions will not be in .debug_types */
707
708 type_signature = zero_type_signature;
709 ame = addr_map_find(low_pc,pcMap);
710 if (ame && ame->mp_name) {
711 esb_append(name,ame->mp_name);
712 return DW_DLV_OK;
713 }
714 if (glflags.gf_all_cus_seen_search_by_address) {
715 return DW_DLV_NO_ENTRY;
716 }
717 if (glflags.gf_debug_addr_missing) {
718 return DW_DLV_NO_ENTRY;
719 }
720 if (*cu_die_for_print_frames == NULL) {
721 /* Call depends on dbg->cu_context to know what to do. */
722 cures = dwarf_next_cu_header_e(dbg,
723 is_info,
724 cu_die_for_print_frames,
725 &cu_header_length,
726 &version_stamp, &abbrev_offset,
727 &address_size,
728 &length_size,
729 &extension_size,
730 &type_signature,
731 &typeoffset,
732 &next_cu_offset,
733 &header_cu_type,
734 err);
735 if (cures == DW_DLV_ERROR) {
736 /* If there is a serious error in DIE information
737 we just skip looking for a procedure name.
738 Perhaps we should report something? */
739 printf("\nERROR: Error getting next cu header "
740 "looking for a subroutine"
741 "/procedure name. Section %s. Err is %s\n",
742 sanitized(frame_section_name),
743 dwarf_errmsg(*err));
744 glflags.gf_count_major_errors++;
745 glflags.gf_all_cus_seen_search_by_address = 1;
746 DROP_ERROR_INSTANCE(dbg,cures,*err);
747 return DW_DLV_NO_ENTRY;
748 } else if (cures == DW_DLV_NO_ENTRY) {
749 /* loop thru the list again */
750 *cu_die_for_print_frames = 0;
751 } else { /* DW_DLV_OK */
752 #ifdef ORIGINAL_HEADER_API
753 dres = dwarf_siblingof_b(dbg, NULL,
754 is_info,
755 cu_die_for_print_frames,
756 err);
757 if (dres == DW_DLV_ERROR) {
758 /* If there is a serious error in DIE information
759 we just skip looking for a procedure name.
760 Perhaps we should report something? */
761 printf("\nERROR: Error getting "
762 "dwarf_siblingof when looking for"
763 " procedure name. "
764 "Section %s. Err is %s\n",
765 sanitized(frame_section_name),
766 dwarf_errmsg(*err));
767 glflags.gf_count_major_errors++;
768 DROP_ERROR_INSTANCE(dbg,dres,*err);
769 glflags.gf_all_cus_seen_search_by_address = 1;
770 return DW_DLV_NO_ENTRY;;
771 }
772 if (dres == DW_DLV_NO_ENTRY) {
773 /* No initial die? Something is wrong! */
774 return dres;
775 }
776 #endif /* ORIGINAL_HEADER_API */
777 }
778 }
779 if (dres == DW_DLV_OK) {
780 Dwarf_Die child = 0;
781
782 if (*cu_die_for_print_frames == 0) {
783 /* no information. Possibly a stripped file */
784 return DW_DLV_NO_ENTRY;
785 }
786 chres = dwarf_child(*cu_die_for_print_frames,
787 &child, err);
788 if (chres == DW_DLV_ERROR) {
789 printf("\nERROR: Error getting "
790 "dwarf_child(). "
791 "Section %s. Err is %s\n",
792 sanitized(frame_section_name),
793 dwarf_errmsg(*err));
794 DROP_ERROR_INSTANCE(dbg,chres,*err);
795 glflags.gf_count_major_errors++;
796 glflags.gf_all_cus_seen_search_by_address = 1;
797 return DW_DLV_NO_ENTRY;
798 } else if (chres == DW_DLV_NO_ENTRY) {
799 /* FALL THROUGH to look for more CU headers */
800 } else { /* DW_DLV_OK */
801 int gotname = 0;
802 gotname = load_nested_proc_name(dbg, child, low_pc, name,
803 cu_die_for_print_frames,
804 pcMap,err);
805 dwarf_dealloc(dbg, child, DW_DLA_DIE);
806 if (gotname == DW_DLV_OK) {
807 return DW_DLV_OK;
808 }
809 if (gotname == DW_DLV_ERROR) {
810 glflags.gf_all_cus_seen_search_by_address = 1;
811 DROP_ERROR_INSTANCE(dbg,gotname,*err);
812 return DW_DLV_NO_ENTRY;
813 }
814 child = 0;
815 }
816 }
817 for (;;) {
818 Dwarf_Die ldie = 0;
819
820 type_signature = zero_type_signature;
821 #ifdef ORIGINAL_HEADER_API
822
823 cures = dwarf_next_cu_header_d(dbg,
824 is_info, &cu_header_length,
825 &version_stamp, &abbrev_offset,
826 &address_size,
827 &length_size,&extension_size,
828 &type_signature,&typeoffset,
829 &next_cu_offset,
830 &header_cu_type,
831 err);
832 #else
833 cures = dwarf_next_cu_header_e(dbg,
834 is_info, &ldie, &cu_header_length,
835 &version_stamp, &abbrev_offset,
836 &address_size,
837 &length_size,&extension_size,
838 &type_signature,&typeoffset,
839 &next_cu_offset,
840 &header_cu_type,
841 err);
842 #endif
843 if (cures != DW_DLV_OK) {
844 if (cures == DW_DLV_ERROR) {
845 printf("\nERROR: Error getting "
846 "next_cu_header "
847 "Section %s. Err is %s\n",
848 sanitized(frame_section_name),
849 dwarf_errmsg(*err));
850 DROP_ERROR_INSTANCE(dbg,cures,*err);
851 glflags.gf_count_major_errors++;
852 glflags.gf_all_cus_seen_search_by_address = 1;
853 return DW_DLV_NO_ENTRY;
854 }
855 glflags.gf_all_cus_seen_search_by_address = 1;
856 break;
857 }
858
859 #ifdef ORIGINAL_HEADER_API
860 dres = dwarf_siblingof_b(dbg,NULL,is_info, &ldie, err);
861 #else
862 dres = DW_DLV_OK;
863 #endif
864 if (*cu_die_for_print_frames) {
865 dwarf_dealloc(dbg, *cu_die_for_print_frames,DW_DLA_DIE);
866 *cu_die_for_print_frames = 0;
867 }
868 #ifdef ORIGINAL_HEADER_API
869 if (dres == DW_DLV_ERROR) {
870 DROP_ERROR_INSTANCE(dbg,dres,*err);
871 glflags.gf_all_cus_seen_search_by_address = 1;
872 return dres;
873 } else if (dres == DW_DLV_NO_ENTRY) {
874 return dres;
875 }
876 #endif /* ORIGINAL_HEADER_API */
877 /* DW_DLV_OK
878 In normal processing (ie, when doing print_info()
879 we would call print_attribute for each die
880 including cu_die and thus get CU_base_address,
881 CU_high_address, PU_base_address, PU_high_address,
882 CU_name for PRINT_CU_INFO() in case of error. */
883 *cu_die_for_print_frames = ldie;
884 {
885 int chpfres = 0;
886 Dwarf_Die child = 0;
887
888 chpfres =
889 dwarf_child(*cu_die_for_print_frames, &child,
890 err);
891 if (chpfres == DW_DLV_ERROR) {
892 load_CU_error_data(dbg,*cu_die_for_print_frames);
893 glflags.gf_count_major_errors++;
894 printf("\nERROR: Getting procedure name "
895 "dwarf_child fails "
896 " %s\n",dwarf_errmsg(*err));
897 DROP_ERROR_INSTANCE(dbg,chpfres,*err);
898 glflags.gf_all_cus_seen_search_by_address = 1;
899 return DW_DLV_NO_ENTRY;
900 } else if (chpfres == DW_DLV_NO_ENTRY) {
901 /* FALL THROUGH to loop more */
902 } else {
903 /* DW_DLV_OK) */
904 int gotname = 0;
905
906 gotname = load_nested_proc_name(dbg, child,
907 low_pc, name,
908 cu_die_for_print_frames,
909 pcMap,err);
910 dwarf_dealloc(dbg, child, DW_DLA_DIE);
911 if (gotname == DW_DLV_OK) {
912 return gotname;
913 }
914 if (gotname == DW_DLV_ERROR) {
915 DROP_ERROR_INSTANCE(dbg,gotname,*err);
916 glflags.gf_all_cus_seen_search_by_address = 1;
917 return DW_DLV_NO_ENTRY;
918 }
919 }
920 }
921 reset_overall_CU_error_data();
922 }
923 return DW_DLV_NO_ENTRY;
924 }
925
926 /* Attempting to take care of overflows so we
927 only accept good as TRUE. */
928 static Dwarf_Bool
929 valid_fde_content(Dwarf_Small * fde_start,
930 Dwarf_Unsigned fde_length,
931 Dwarf_Small * data_ptr,
932 Dwarf_Unsigned data_ptr_length)
933 {
934 Dwarf_Small * fde_end = fde_start + fde_length;
935 Dwarf_Small * data_end = 0;
936
937 if (data_ptr < fde_start ||
938 data_ptr >= fde_end) {
939 return FALSE;
940 }
941 data_end = data_ptr + data_ptr_length;
942 if ( data_end < fde_start || data_end < data_ptr) {
943 return FALSE;
944 }
945 if ( data_end >= fde_end) {
946 return FALSE;
947 }
948 return TRUE;
949 }
950
951 static void
952 dd_check_fde_cie(Dwarf_Debug dbg,
953 Dwarf_Fde fde,
954 Dwarf_Signed cie_index,
955 Dwarf_Cie cie)
956 {
957 Dwarf_Error error;
958 Dwarf_Cie ret_cie = 0;
959 Dwarf_Signed ret_index = 0;
960 int res = 0;
961
962 if (!glflags.gf_check_functions) {
963 return;
964 }
965 DWARF_CHECK_COUNT(check_functions_result,1);
966 res = dwarf_get_cie_of_fde(fde,&ret_cie,&error);
967 if (res == DW_DLV_ERROR) {
968 DWARF_CHECK_ERROR2(check_functions_result,
969 "Error calling dwarf_get_cie_of_fde() "
970 "underlying error is:",
971 dwarf_errmsg(error));
972 DROP_ERROR_INSTANCE(dbg,res,error);
973 } else if (res == DW_DLV_NO_ENTRY) {
974 DWARF_CHECK_ERROR(check_functions_result,
975 "NO_ENTRY calling dwarf_get_cie_of_fde()");
976 } else { /* OK */
977 if ( ret_cie != cie) {
978 DWARF_CHECK_ERROR(check_functions_result,
979 "dwarf_get_cie_of_fde() returns "
980 "inconsistent cie");
981 }
982 }
983 res = dwarf_get_cie_index(cie,&ret_index,&error);
984 if (res == DW_DLV_ERROR) {
985 DWARF_CHECK_ERROR2(check_functions_result,
986 "Error calling dwarf_get_index() "
987 "underlying error is:",
988 dwarf_errmsg(error));
989 DROP_ERROR_INSTANCE(dbg,res,error);
990 } else if (res == DW_DLV_NO_ENTRY) {
991 DWARF_CHECK_ERROR(check_functions_result,
992 "NO_ENTRY calling dwarf_get_cie_index()");
993 } else { /* OK */
994 if ( ret_index != cie_index) {
995 DWARF_CHECK_ERROR(check_functions_result,
996 "dwarf_get_cie_index() returns"
997 " mismatched cie index");
998 }
999 }
1000 }
1001
1002 static void
1003 dd_check_retrieved_fde(Dwarf_Debug dbg,
1004 Dwarf_Fde *fde_data,
1005 Dwarf_Fde expected_fde,
1006 Dwarf_Addr pc)
1007 {
1008 int res = 0;
1009 Dwarf_Error error = 0;
1010 Dwarf_Fde returned_fde = 0;
1011 Dwarf_Addr lopc = 0;
1012 Dwarf_Addr hipc = 0;
1013
1014 DWARF_CHECK_COUNT(check_functions_result,1);
1015 res = dwarf_get_fde_at_pc(fde_data,pc,
1016 &returned_fde,&lopc,&hipc,&error);
1017 if (res == DW_DLV_ERROR) {
1018 DWARF_CHECK_ERROR2(check_functions_result,
1019 "Error calling dwarf_get_fde_at_pc() "
1020 "underlying error is:",
1021 dwarf_errmsg(error));
1022 DROP_ERROR_INSTANCE(dbg,res,error);
1023 } else if (res == DW_DLV_NO_ENTRY) {
1024 struct esb_s m;
1025
1026 esb_constructor(&m);
1027 esb_append_printf_u(&m,
1028 "NO_ENTRY calling dwarf_get_fde_at_pc()"
1029 " got NO ENTRY for pc 0x%"
1030 DW_PR_XZEROS DW_PR_DUx
1031 " which indicates corrupt dwarf",pc);
1032 DWARF_CHECK_ERROR(check_functions_result,
1033 esb_get_string(&m));
1034 esb_destructor(&m);
1035 } else { /* OK */
1036 if ( returned_fde != expected_fde) {
1037 DWARF_CHECK_ERROR(check_functions_result,
1038 "dwarf_get_fde_at_pc() returns"
1039 " mismatched fde index");
1040 }
1041 }
1042 }
1043 static const Dwarf_Block blockzero;
1044
1045 /* Gather the fde print logic here so the control logic
1046 determining what FDE to print is clearer. */
1047 static int
1048 print_one_fde(Dwarf_Debug dbg,
1049 const char *frame_section_name,
1050 Dwarf_Fde *fde_data,
1051 Dwarf_Signed fde_index,
1052 Dwarf_Cie * cie_data,
1053 Dwarf_Signed cie_element_count,
1054 Dwarf_Half address_size,
1055 Dwarf_Half offset_size,
1056 Dwarf_Half version,
1057 int is_eh,
1058 struct dwconf_s *config_data,
1059 void ** pcMap,
1060 void ** lowpcSet,
1061 Dwarf_Die *cu_die_for_print_frames,
1062 Dwarf_Error *err)
1063 {
1064 Dwarf_Addr j = 0;
1065 Dwarf_Addr low_pc = 0;
1066 Dwarf_Unsigned func_length = 0;
1067 Dwarf_Addr end_func_addr = 0;
1068 Dwarf_Small *fde_bytes = NULL;
1069 Dwarf_Unsigned fde_bytes_length = 0;
1070 Dwarf_Off cie_offset = 0;
1071 Dwarf_Signed cie_index = 0;
1072 Dwarf_Off fde_offset = 0;
1073 Dwarf_Signed eh_table_offset = 0;
1074 int fres = 0;
1075 int offres = 0;
1076 struct esb_s temps;
1077 int printed_intro_addr = 0;
1078 char local_buf[100];
1079 char temps_buf[200];
1080 Dwarf_Fde fde = 0;
1081 unsigned long fde_checking_count = 0;
1082
1083 fde = fde_data[fde_index];
1084 fres = dwarf_get_fde_range(fde,
1085 &low_pc, &func_length,
1086 &fde_bytes,
1087 &fde_bytes_length,
1088 &cie_offset, &cie_index,
1089 &fde_offset, err);
1090 if (fres == DW_DLV_ERROR) {
1091 glflags.gf_count_major_errors++;
1092 printf("ERROR: calling dwarf_get_fde_range() on "
1093 "index %" DW_PR_DUu "gets an error! Error is %s\n",
1094 fde_index,dwarf_errmsg(*err));
1095 return fres;
1096 }
1097 if (fres == DW_DLV_NO_ENTRY) {
1098 return DW_DLV_NO_ENTRY;
1099 }
1100 dd_check_fde_cie(dbg,fde,cie_index,cie_data[cie_index]);
1101 if (glflags.gf_cu_name_flag &&
1102 glflags.fde_offset_for_cu_low != DW_DLV_BADOFFSET &&
1103 (fde_offset < glflags.fde_offset_for_cu_low ||
1104 fde_offset > glflags.fde_offset_for_cu_high)) {
1105 return DW_DLV_NO_ENTRY;
1106 }
1107 /* eh_table_offset was IRIX ONLY. */
1108 fres = dwarf_get_fde_exception_info(fde,
1109 &eh_table_offset, err);
1110 if (fres == DW_DLV_ERROR) {
1111 glflags.gf_count_major_errors++;
1112 printf("ERROR: Got error looking for SGI-only "
1113 "exception table "
1114 "offset from fde! Error is %s\n",
1115 dwarf_errmsg(*err));
1116 return fres;
1117 }
1118 esb_constructor_fixed(&temps,temps_buf,sizeof(temps_buf));
1119 if (glflags.gf_suppress_nested_name_search) {
1120 /* do nothing. */
1121 } else {
1122 struct Addr_Map_Entry *mp = 0;
1123
1124 esb_empty_string(&temps);
1125 mp = addr_map_find(low_pc,lowpcSet);
1126 if (glflags.gf_check_frames ||
1127 glflags.gf_check_frames_extended) {
1128 DWARF_CHECK_COUNT(fde_duplication,1);
1129 }
1130 fres = get_fde_proc_name_by_address(dbg, low_pc,
1131 frame_section_name,
1132 &temps,
1133 cu_die_for_print_frames,
1134 pcMap,err);
1135 if (fres == DW_DLV_ERROR) {
1136 /* Failing to get the name is not a crucial
1137 thing. Do not error off.
1138 We should not get here as the
1139 invariant for get_fde_proc_name_by_address()
1140 says it never returns DW_DLV_ERROR; */
1141 DROP_ERROR_INSTANCE(dbg,fres,*err);
1142 fres = DW_DLV_NO_ENTRY;
1143 }
1144 /* If found the name is in temps now, or temps
1145 is the empty string. */
1146 if (mp) {
1147 if (glflags.gf_check_frames ||
1148 glflags.gf_check_frames_extended) {
1149 struct esb_s msg;
1150
1151 esb_constructor_fixed(&msg,
1152 local_buf,sizeof(local_buf));
1153 if (esb_string_len(&temps) > 0) {
1154 esb_append_printf_u(&msg,
1155 "An fde low pc of 0x%"
1156 DW_PR_DUx
1157 " is not the first fde with that pc. ",
1158 low_pc);
1159 esb_append_printf_s(&msg,
1160 "The first is named \"%s\"",
1161 sanitized(esb_get_string(&temps)));
1162 } else {
1163 esb_append_printf_u(&msg,
1164 "An fde low pc of 0x%"
1165 DW_PR_DUx
1166 " is not the first fde with that pc. "
1167 "The first is not named.",
1168 (Dwarf_Unsigned)low_pc);
1169 }
1170 DWARF_CHECK_ERROR(fde_duplication,
1171 esb_get_string(&msg));
1172 esb_destructor(&msg);
1173 }
1174 } else if (fres == DW_DLV_OK) {
1175 addr_map_insert(low_pc,0,lowpcSet);
1176 } /* Else we just don't know anything, so record nothing. */
1177 }
1178
1179 /* Do not print if in check mode */
1180 if (glflags.gf_do_print_dwarf) {
1181 /* Printing the FDE header. */
1182 printf("<%5" DW_PR_DSd ">"
1183 "<0x%" DW_PR_XZEROS DW_PR_DUx
1184 ":0x%" DW_PR_XZEROS DW_PR_DUx
1185 "><%s>"
1186 "<cie offset 0x%" DW_PR_XZEROS DW_PR_DUx ":"
1187 ":cie index %5" DW_PR_DUu ">"
1188 "<fde offset 0x%" DW_PR_XZEROS DW_PR_DUx
1189 " length: 0x%" DW_PR_XZEROS DW_PR_DUx ">",
1190 fde_index,
1191 (Dwarf_Unsigned)low_pc,
1192 (Dwarf_Unsigned)(low_pc + func_length),
1193 sanitized(esb_get_string(&temps)),
1194 (Dwarf_Unsigned)cie_offset,
1195 (Dwarf_Unsigned)cie_index,
1196 (Dwarf_Unsigned)fde_offset,
1197 fde_bytes_length);
1198 }
1199 esb_destructor(&temps);
1200 if (!is_eh) {
1201 /* IRIX used eh_table_offset. No one else uses it. */
1202 /* Do not print if in check mode */
1203 if (glflags.gf_do_print_dwarf) {
1204 if (eh_table_offset == DW_DLX_NO_EH_OFFSET) {
1205 printf("<eh offset %s>\n", "none");
1206 } else if (eh_table_offset ==
1207 DW_DLX_EH_OFFSET_UNAVAILABLE) {
1208 printf("<eh offset %s>\n", "unknown");
1209 } else {
1210 printf("<eh offset 0x%" DW_PR_XZEROS DW_PR_DUx
1211 ">\n", eh_table_offset);
1212 }
1213 }
1214 } else {
1215 /* Printing the .eh_frame header augmentation string,
1216 if any. */
1217 int ares = 0;
1218 Dwarf_Small *data = 0;
1219 Dwarf_Unsigned len = 0;
1220
1221 ares = dwarf_get_fde_augmentation_data(fde, &data, &len, err);
1222 if (ares == DW_DLV_ERROR) {
1223 glflags.gf_count_major_errors++;
1224 printf("ERROR: on getting augmentation data for an fde."
1225 " Error is %s\n",dwarf_errmsg(*err));
1226 return ares;
1227 }
1228 if (ares == DW_DLV_NO_ENTRY) {
1229 /* do nothing. */
1230 } else if (ares == DW_DLV_OK) {
1231 if (glflags.gf_do_print_dwarf) {
1232 printf("\n <eh aug data len 0x%"
1233 DW_PR_DUx, len);
1234 if (len) {
1235 if (!valid_fde_content(fde_bytes,fde_bytes_length,
1236 data,len) ) {
1237 glflags.gf_count_major_errors++;
1238 printf("ERROR:The .eh_frame augmentation "
1239 "data "
1240 "is too large to print");
1241 } else {
1242 Dwarf_Unsigned k2 = 0;
1243
1244 for (k2 = 0; k2 < len; ++k2) {
1245 if (k2 == 0) {
1246 printf(" bytes 0x");
1247 }
1248 printf("%02x ", (unsigned char) data[k2]);
1249 }
1250 }
1251 }
1252 printf(">");
1253 }
1254 }
1255 /* Do not print if in check mode */
1256 if (glflags.gf_do_print_dwarf) {
1257 printf("\n");
1258 }
1259 }
1260 end_func_addr = low_pc + func_length;
1261 for (j = low_pc; j < end_func_addr; j++) {
1262 Dwarf_Half k = 0;
1263 Dwarf_Addr cur_pc_in_table = 0;
1264
1265 cur_pc_in_table = j;
1266 if (glflags.gf_check_functions &&
1267 fde_checking_count < 100){ /* 100 is arbitrary */
1268 ++fde_checking_count;
1269 dd_check_retrieved_fde(dbg,fde_data,fde,cur_pc_in_table);
1270 }
1271 {
1272 Dwarf_Unsigned reg = 0;
1273 Dwarf_Unsigned offset_relevant = 0;
1274 Dwarf_Small value_type = 0;
1275 /* DWARF has always said the offset is signed
1276 in an offset(n) or val_offset(N) register rule.
1277 the API functions here are formally
1278 incorrect. So we cast the value returned
1279 to us to Dwarf_Signed at point of use. */
1280 Dwarf_Signed offset = 0;
1281 Dwarf_Block block;
1282 Dwarf_Addr row_pc = 0;
1283 Dwarf_Bool has_more_rows = 0;
1284 Dwarf_Addr subsequent_pc = 0;
1285 int fires = 0;
1286
1287 block = blockzero;
1288 #ifdef TESTOLDDW_OFFSET
1289 {
1290 Dwarf_Unsigned s = 0;
1291 fires = dwarf_get_fde_info_for_cfa_reg3_b(fde,
1292 j,
1293 &value_type,
1294 &offset_relevant,
1295 &reg,
1296 &s,
1297 &block,
1298 &row_pc,
1299 &has_more_rows,
1300 &subsequent_pc,
1301 err);
1302 offset = (Dwarf_Signed)s;
1303 }
1304 #else
1305 fires = dwarf_get_fde_info_for_cfa_reg3_c(fde,
1306 j,
1307 &value_type,
1308 &offset_relevant,
1309 &reg,
1310 &offset,
1311 &block,
1312 &row_pc,
1313 &has_more_rows,
1314 &subsequent_pc,
1315 err);
1316 #endif
1317 if (fires == DW_DLV_ERROR) {
1318 glflags.gf_count_major_errors++;
1319 printf("\nERROR: on getting fde details for "
1320 "fde row for address 0x%"
1321 DW_PR_XZEROS DW_PR_DUx ": %s\n",
1322 j,dwarf_errmsg(*err));
1323 return fires;
1324 }
1325 if (fires == DW_DLV_NO_ENTRY) {
1326 continue;
1327 }
1328 if (!has_more_rows) {
1329 j = low_pc+func_length-1;
1330 } else {
1331 if (subsequent_pc > j) {
1332 /* Loop head will increment j to make up
1333 for -1 here. */
1334 j = subsequent_pc -1;
1335
1336 }
1337 }
1338 /* Do not print if in check mode */
1339 if (!printed_intro_addr && glflags.gf_do_print_dwarf) {
1340 printf(" 0x%" DW_PR_XZEROS DW_PR_DUx
1341 ": ", (Dwarf_Unsigned)cur_pc_in_table);
1342 printed_intro_addr = 1;
1343 }
1344 print_one_frame_reg_col(dbg,
1345 *cu_die_for_print_frames,
1346 config_data->cf_cfa_reg,
1347 value_type,
1348 reg,
1349 address_size,
1350 offset_size,version,
1351 config_data,
1352 offset_relevant, offset, &block);
1353 }
1354 for (k = 0; k < config_data->cf_table_entry_count; k++) {
1355 Dwarf_Unsigned reg = 0;
1356 Dwarf_Unsigned offset_relevant = 0;
1357 int fires = 0;
1358 Dwarf_Small value_type = 0;
1359 Dwarf_Block block;
1360 Dwarf_Signed offset = 0;
1361 Dwarf_Addr row_pc = 0;
1362 Dwarf_Bool has_more_rows = FALSE;
1363 Dwarf_Addr subsequent_pc = 0;
1364
1365 block = blockzero;
1366 {
1367 #if TESTOLDDW_OFFSET
1368 Dwarf_Unsigned s = 0;
1369 fires = dwarf_get_fde_info_for_reg3_b(fde,
1370 k,
1371 cur_pc_in_table,
1372 &value_type,
1373 &offset_relevant,
1374 &reg,
1375 &s,
1376 &block,
1377 &row_pc, &has_more_rows,&subsequent_pc, err);
1378 offset = (Dwarf_Signed)s;
1379 #else
1380 fires = dwarf_get_fde_info_for_reg3_c(fde,
1381 k,
1382 cur_pc_in_table,
1383 &value_type,
1384 &offset_relevant,
1385 &reg,
1386 &offset,
1387 &block,
1388 &row_pc, &has_more_rows,&subsequent_pc, err);
1389 #endif
1390 }
1391 if (fires == DW_DLV_ERROR) {
1392 printf("\n");
1393 glflags.gf_count_major_errors++;
1394 printf("\nERROR: on getting fde details for "
1395 "row address 0x%" DW_PR_XZEROS DW_PR_DUx
1396 " table column %d.\n",
1397 j,k);
1398 return fires;
1399 }
1400 if (fires == DW_DLV_NO_ENTRY) {
1401 continue;
1402 }
1403 if (row_pc != cur_pc_in_table) {
1404 /* row_pc < cur_pc_in_table means this pc has no
1405 new register value, the last one found still
1406 applies hence this is a duplicate row.
1407 row_pc > j cannot happen, the libdwarf function
1408 will not return such. */
1409 continue;
1410 }
1411
1412 /* Do not print if in check mode */
1413 if (!printed_intro_addr && glflags.gf_do_print_dwarf) {
1414 printf(" 0x%" DW_PR_XZEROS DW_PR_DUx ": ",
1415 (Dwarf_Unsigned)j);
1416 printed_intro_addr = 1;
1417 }
1418 print_one_frame_reg_col(dbg,
1419 *cu_die_for_print_frames,
1420 k,
1421 value_type,
1422 reg,
1423 address_size,
1424 offset_size,version,
1425 config_data,
1426 offset_relevant, offset, &block);
1427 }
1428 if (printed_intro_addr) {
1429 printf("\n");
1430 printed_intro_addr = 0;
1431 }
1432 }
1433 if (glflags.verbose > 1) {
1434 Dwarf_Off fde_off = 0;
1435 Dwarf_Off cie_off = 0;
1436 int fderes = 0;
1437
1438 /* Get the fde instructions and print them in
1439 raw form. */
1440 Dwarf_Small * fde_instrs = 0;
1441 Dwarf_Unsigned fdeinstrslen = 0;
1442
1443 offres = dwarf_fde_section_offset(dbg, fde, &fde_off,
1444 &cie_off, err);
1445 if (offres == DW_DLV_ERROR) {
1446 glflags.gf_count_major_errors++;
1447 printf("\nERROR: on getting fde section offset"
1448 " of this fde\n");
1449 return offres;
1450 }
1451 if (offres == DW_DLV_NO_ENTRY) {
1452 glflags.gf_count_major_errors++;
1453 printf("\nERROR: Impossible, no fde offset or "
1454 " cie offset for "
1455 "fde index "
1456 "%" DW_PR_DUu "?\n",
1457 fde_index);
1458 return offres;
1459 }
1460 {
1461 /* Do not print if in check mode */
1462 if (glflags.gf_do_print_dwarf) {
1463 printf(" fde section offset %" DW_PR_DUu
1464 " 0x%" DW_PR_XZEROS DW_PR_DUx
1465 " cie offset for fde: %" DW_PR_DUu
1466 " 0x%" DW_PR_XZEROS DW_PR_DUx "\n",
1467 (Dwarf_Unsigned) fde_off,
1468 (Dwarf_Unsigned) fde_off,
1469 (Dwarf_Unsigned) cie_off,
1470 (Dwarf_Unsigned) cie_off);
1471 }
1472 }
1473 fderes = dwarf_get_fde_instr_bytes(fde,
1474 &fde_instrs,&fdeinstrslen,err);
1475 if (fderes == DW_DLV_ERROR) {
1476 printf("\nERROR: getting fde instructions "
1477 " failed %s \n",dwarf_errmsg(*err));
1478 glflags.gf_count_major_errors++;
1479 return offres;
1480 }
1481 /* fdeinstrslen will be zero if DW_DLV_NO_ENTRY. */
1482 {
1483 int cires = 0;
1484 Dwarf_Frame_Instr_Head ihead = 0;
1485 Dwarf_Unsigned iarraycount = 0;
1486 Dwarf_Unsigned cie_length = 0;
1487 Dwarf_Small cie_version = 0;
1488 char* augmenter = 0;
1489 Dwarf_Unsigned code_alignment_factor = 0;
1490 Dwarf_Signed data_alignment_factor = 0;
1491 Dwarf_Half return_address_register_rule = 0;
1492 Dwarf_Small * initial_instructions = 0;
1493 Dwarf_Unsigned initial_instructions_length = 0;
1494 Dwarf_Half cie_offset_size = 0;
1495
1496 if (cie_index >= cie_element_count) {
1497 glflags.gf_count_major_errors++;
1498 printf("\nERROR: Bad cie index %" DW_PR_DSd
1499 " with fde index %" DW_PR_DUu "! "
1500 "(table entry max %" DW_PR_DSd ")\n",
1501 cie_index, fde_index,
1502 cie_element_count);
1503 return DW_DLV_NO_ENTRY;
1504 }
1505 cires = dwarf_get_cie_info_b(cie_data[cie_index],
1506 &cie_length,
1507 &cie_version,
1508 &augmenter,
1509 &code_alignment_factor,
1510 &data_alignment_factor,
1511 &return_address_register_rule,
1512 &initial_instructions,
1513 &initial_instructions_length,
1514 &cie_offset_size,
1515 err);
1516 if (cires == DW_DLV_ERROR) {
1517 glflags.gf_count_major_errors++;
1518 printf("\nERROR: Bad cie index %" DW_PR_DSd
1519 " with fde index %" DW_PR_DUu "!\n",
1520 cie_index, fde_index);
1521 return cires;
1522 }
1523 if (cires == DW_DLV_NO_ENTRY) {
1524 /* Impossible. Do nothing. */
1525 glflags.gf_count_major_errors++;
1526 printf("\nERROR: Impossible: no cie info for "
1527 "cie index %" DW_PR_DUu "?\n", cie_index);
1528 return cires;
1529 }
1530 if (glflags.gf_do_print_dwarf) {
1531 int res = 0;
1532
1533 res = dwarf_expand_frame_instructions(
1534 cie_data[cie_index],
1535 fde_instrs,
1536 fdeinstrslen,
1537 &ihead,
1538 &iarraycount,
1539 err);
1540 if (res == DW_DLV_ERROR) {
1541 glflags.gf_count_major_errors++;
1542 printf("\nERROR: fail expanding instructions %"
1543 DW_PR_DSd
1544 " with fde index %" DW_PR_DUu "!\n",
1545 cie_index, fde_index);
1546 printf("%s\n",dwarf_errmsg(*err));
1547 return res;
1548 }
1549 if (res == DW_DLV_NO_ENTRY) {
1550 glflags.gf_count_major_errors++;
1551 printf("\nERROR: Impossible: no entry "
1552 "expanding instructions for "
1553 "cie index %" DW_PR_DUu "?\n", cie_index);
1554 return res;
1555 }
1556
1557 /* Do not print if in check mode */
1558 print_frame_inst_bytes(dbg,
1559 ihead,
1560 iarraycount,
1561 *cu_die_for_print_frames,
1562 data_alignment_factor,
1563 code_alignment_factor,
1564 address_size,
1565 cie_offset_size,
1566 cie_version, config_data);
1567 dwarf_dealloc_frame_instr_head(ihead);
1568 ihead = 0;
1569 }
1570 }
1571 }
1572 return DW_DLV_OK;
1573 } /* end: print_one_fde */
1574
1575 /* Print a cie. Gather the print logic here so the
1576 control logic deciding what to print
1577 is clearer.
1578 */
1579 int
1580 print_one_cie(Dwarf_Debug dbg,
1581 Dwarf_Die die,
1582 Dwarf_Cie cie,
1583 Dwarf_Unsigned cie_index,
1584 Dwarf_Half address_size,
1585 struct dwconf_s *config_data,
1586 Dwarf_Error *err)
1587 {
1588 int cires = 0;
1589 Dwarf_Unsigned cie_length = 0;
1590 Dwarf_Small version = 0;
1591 char* augmenter = "";
1592 Dwarf_Unsigned code_alignment_factor = 0;
1593 Dwarf_Signed data_alignment_factor = 0;
1594 Dwarf_Half return_address_register_rule = 0;
1595 Dwarf_Small *cie_initial_instructions = 0;
1596 Dwarf_Unsigned cie_initial_instructions_length = 0;
1597 Dwarf_Off cie_off = 0;
1598 Dwarf_Half offset_size = 0;
1599
1600 cires = dwarf_get_cie_info_b(cie,
1601 &cie_length,
1602 &version,
1603 &augmenter,
1604 &code_alignment_factor,
1605 &data_alignment_factor,
1606 &return_address_register_rule,
1607 &cie_initial_instructions,
1608 &cie_initial_instructions_length,&offset_size, err);
1609 if (cires == DW_DLV_ERROR) {
1610 glflags.gf_count_major_errors++;
1611 printf("ERROR: calling dwarf_get_cie_info_b() fails\n");
1612 return cires;
1613 }
1614 if (cires == DW_DLV_NO_ENTRY) {
1615 glflags.gf_count_major_errors++;
1616 printf("ERROR: Impossible DW_DLV_NO_ENTRY on cie %" DW_PR_DUu
1617 "\n", cie_index);
1618 return cires;
1619 }
1620 {
1621 if (glflags.gf_do_print_dwarf) {
1622 printf("<%5" DW_PR_DUu "> version %d\n",
1623 cie_index, version);
1624 cires = dwarf_cie_section_offset(dbg, cie, &cie_off, err);
1625 if (cires == DW_DLV_OK) {
1626 printf(" cie section offset %" DW_PR_DUu
1627 " 0x%" DW_PR_XZEROS DW_PR_DUx "\n",
1628 (Dwarf_Unsigned) cie_off,
1629 (Dwarf_Unsigned) cie_off);
1630 }
1631 /* This augmentation is from .debug_frame or
1632 eh_frame of a cie. . A string. */
1633 /* (" bytes of initial instructions %"*/
1634 printf(" augmentation %s\n",
1635 sanitized(augmenter));
1636 printf(" code_alignment_factor %"
1637 DW_PR_DUu "\n",
1638 code_alignment_factor);
1639 printf(" data_alignment_factor %"
1640 DW_PR_DSd "\n",
1641 data_alignment_factor);
1642 printf(" return_address_register %d\n",
1643 return_address_register_rule);
1644 }
1645
1646 {
1647 int ares = 0;
1648 Dwarf_Small *data = 0;
1649 Dwarf_Unsigned len = 0;
1650
1651 /* This call only returns DW_DLV_OK if the augmentation
1652 is cie aug from .eh_frame. The
1653 return is DW_DLV_OK only if there is eh_frame
1654 style augmentation bytes (its not a string). */
1655 ares = dwarf_get_cie_augmentation_data(cie, &data,
1656 &len, err);
1657 if (ares == DW_DLV_NO_ENTRY) {
1658 /* No Aug data (len zero) do nothing. */
1659 } else if (ares == DW_DLV_OK) {
1660 /* We have the gnu eh_frame aug data bytes. */
1661 if (glflags.gf_do_print_dwarf) {
1662 unsigned k2 = 0;
1663
1664 /* (" bytes of initial instructions %" */
1665 printf(" eh aug data len 0x%"
1666 DW_PR_DUx , len);
1667 for (k2 = 0; data && k2 < len; ++k2) {
1668 if (k2 == 0) {
1669 printf(" bytes 0x");
1670 }
1671 printf("%02x ", (unsigned char) data[k2]);
1672 }
1673 printf("\n");
1674 }
1675 } else { /* DW_DLV_ERROR */
1676 glflags.gf_count_major_errors++;
1677 printf("\nERROR: calling "
1678 "dwarf_get_cie_augmentation_data()"
1679 " fails.\n");
1680 printf("%s\n",dwarf_errmsg(*err));
1681 return ares;
1682 }
1683 }
1684
1685 /* Do not print if in check mode */
1686 if (glflags.gf_do_print_dwarf) {
1687 Dwarf_Frame_Instr_Head ihead = 0;
1688 Dwarf_Unsigned iarraycount = 0;
1689 int res = 0;
1690
1691 printf(" bytes of initial instructions %"
1692 DW_PR_DUu "\n",
1693 cie_initial_instructions_length);
1694 printf(" cie length %" DW_PR_DUu
1695 "\n", cie_length);
1696 /* For better layout */
1697 printf(" initial instructions\n");
1698 res = dwarf_expand_frame_instructions(
1699 cie,
1700 cie_initial_instructions,
1701 cie_initial_instructions_length,
1702 &ihead,
1703 &iarraycount,
1704 err);
1705 if (res == DW_DLV_ERROR) {
1706 glflags.gf_count_major_errors++;
1707 printf("\nERROR: fail expanding cie index %"
1708 DW_PR_DUu " instructions\n",
1709 cie_index);
1710 printf("%s\n",dwarf_errmsg(*err));
1711 return res;
1712 }
1713 if (res == DW_DLV_NO_ENTRY) {
1714 glflags.gf_count_major_errors++;
1715 printf("\nERROR: Impossible: no entry "
1716 "expanding instructions for "
1717 "cie index %"DW_PR_DUu "?\n", cie_index);
1718 return res;
1719 }
1720
1721 print_frame_inst_bytes(dbg,
1722 ihead,
1723 iarraycount,
1724 die,
1725 data_alignment_factor,
1726 code_alignment_factor,
1727 address_size,
1728 offset_size,version,config_data);
1729 dwarf_dealloc_frame_instr_head(ihead);
1730 ihead = 0;
1731 }
1732 }
1733 return DW_DLV_OK;
1734 } /* end: print_one_cie */
1735
1736 int
1737 print_expression_operations(Dwarf_Debug dbg,
1738 Dwarf_Die die,
1739 int die_indent_level,
1740 Dwarf_Small *bytes_in,
1741 Dwarf_Unsigned block_len,
1742 Dwarf_Half addr_size,
1743 Dwarf_Half offset_size,
1744 Dwarf_Half version,
1745 struct esb_s *out_string,
1746 Dwarf_Error *err)
1747 {
1748 Dwarf_Unsigned ulistlen = 0;
1749 int res2 = 0;
1750 /* See PRINTING_DIES macro in print_die.c */
1751
1752 {
1753 Dwarf_Loc_Head_c head = 0;
1754 Dwarf_Locdesc_c locentry = 0;
1755 int lres = 0;
1756 Dwarf_Unsigned lopc = 0;
1757 Dwarf_Unsigned hipc = 0;
1758 Dwarf_Unsigned ulocentry_count = 0;
1759 Dwarf_Unsigned section_offset = 0;
1760 Dwarf_Unsigned locdesc_offset = 0;
1761 Dwarf_Small lle_value = 0;
1762 Dwarf_Small loclist_source = 0;
1763 Dwarf_Addr rawlopc = 0;
1764 Dwarf_Addr rawhipc = 0;
1765 Dwarf_Bool debug_addr_unavailable = FALSE;
1766
1767 res2 = dwarf_loclist_from_expr_c(dbg,
1768 bytes_in,block_len,
1769 addr_size,
1770 offset_size,
1771 version,
1772 &head,
1773 &ulistlen,
1774 err);
1775 if (res2 == DW_DLV_NO_ENTRY) {
1776 return res2;
1777 }
1778 if (res2 == DW_DLV_ERROR) {
1779 glflags.gf_count_major_errors++;
1780 printf("\nERROR: calling dwarf_loclist_from_expr_c()");
1781 return res2;
1782 }
1783 lres = dwarf_get_locdesc_entry_d(head,
1784 0, /* Data from 0th LocDesc */
1785 &lle_value,
1786 &rawlopc, &rawhipc,
1787 &debug_addr_unavailable,
1788 &lopc, &hipc,
1789 &ulocentry_count,
1790 &locentry,
1791 &loclist_source,
1792 &section_offset,
1793 &locdesc_offset,
1794 err);
1795 if (lres == DW_DLV_ERROR) {
1796 dwarf_dealloc_loc_head_c(head);
1797 glflags.gf_count_major_errors++;
1798 printf("\nERROR: calling dwarf_get_locdesc_entry_d()"
1799 " on LocDesc 0");
1800 return lres;
1801 } else if (lres == DW_DLV_NO_ENTRY) {
1802 dwarf_dealloc_loc_head_c(head);
1803 return lres;
1804 }
1805 /* ASSERT: loclist_source == DW_LKIND_expression */
1806 /* ASSERT: lle_value == DW_LLE_start_end */
1807 lres = dwarfdump_print_expression_operations(dbg,
1808 die,
1809 die_indent_level,
1810 locentry,
1811 ulocentry_count,
1812 out_string,err);
1813 dwarf_dealloc_loc_head_c(head);
1814 return lres;
1815 }
1816 }
1817
1818 /* DW_CFA_nop may be omitted for alignment,
1819 so we do not flag that one. */
1820 static int
1821 lastop_pointless(int op)
1822 {
1823 if (op == DW_CFA_remember_state ||
1824 op == DW_CFA_MIPS_advance_loc8 ||
1825 op == DW_CFA_advance_loc ||
1826 op == DW_CFA_advance_loc4 ||
1827 op == DW_CFA_advance_loc2 ||
1828 op == DW_CFA_advance_loc1 ||
1829 op == DW_CFA_set_loc) {
1830 return TRUE;
1831 }
1832 /* The last op is hopefully useful. */
1833 return FALSE;
1834 }
1835
1836 #if 0
1837 /* iregion_start, iregion_end are the overall
1838 block of fde/cie instructions.
1839 idata, idata end are the area next to be read
1840 and they must lie within the iregion* range.
1841 The end address is one past the last byte.
1842
1843 We are decoding here, libdwarf has
1844 not decoded these bytes, so it is up to us to
1845 check for corrupt data in the frame section.
1846 */
1847 static int
1848 check_finstr_addrs(unsigned char *iregionstart,
1849 unsigned char *idata,
1850 unsigned char *idata_end,
1851 unsigned char *iregionend,
1852 const char *msg)
1853 {
1854 if ( idata > idata_end) {
1855 /* zero length allowed. But maybe overflow happened. */
1856 glflags.gf_count_major_errors++;
1857 printf("ERROR: frame instruction internal error reading %s\n",
1858 msg);
1859 return DW_DLV_ERROR;
1860 }
1861 if (idata < iregionstart) {
1862 glflags.gf_count_major_errors++;
1863 printf("\nERROR: frame instruction overflow(?) reading"
1864 " %s\n", msg);
1865 return DW_DLV_ERROR;
1866 }
1867 if (idata_end > iregionend) {
1868 Dwarf_Unsigned bytes_in = 0;
1869 bytes_in = idata - iregionstart;
1870 glflags.gf_count_major_errors++;
1871 printf("\nERROR: frame instruction reads off end"
1872 " %" DW_PR_DUu
1873 " bytes into instructions for %s\n",
1874 bytes_in,msg);
1875 return DW_DLV_ERROR;
1876 }
1877 return DW_DLV_OK;
1878 }
1879 #endif
1880
1881 static char exprstr_buf[1000];
1882 static int
1883 print_expression( Dwarf_Debug dbg,
1884 Dwarf_Die die,
1885 Dwarf_Block *expression_block,
1886 Dwarf_Half addr_size,
1887 Dwarf_Half offset_size,
1888 int version)
1889 {
1890 struct esb_s exprstring;
1891 Dwarf_Error cerr = 0;
1892 int gres = 0;
1893
1894 esb_constructor_fixed(&exprstring,
1895 exprstr_buf, sizeof(exprstr_buf));
1896 gres = print_expression_operations(dbg,
1897 die,
1898 /* indent */ 1,
1899 expression_block->bl_data,
1900 expression_block->bl_len,
1901 addr_size, offset_size,version,
1902 &exprstring,&cerr);
1903 if ( gres == DW_DLV_OK) {
1904 printf(" %s\n",
1905 sanitized(esb_get_string(&exprstring)));
1906 } else if (gres == DW_DLV_NO_ENTRY) {
1907 glflags.gf_count_major_errors++;
1908 printf("\nERROR: Unable to get string "
1909 "from"
1910 " expression block "
1911 "of length "
1912 " %" DW_PR_DUu " bytes.\n",
1913 expression_block->bl_len);
1914 } else {
1915 glflags.gf_count_major_errors++;
1916 printf("\nERROR: No string from"
1917 " expression block "
1918 "of length "
1919 " %" DW_PR_DSd " bytes.\n",
1920 expression_block->bl_len);
1921 printf("Error: %s\n",dwarf_errmsg(cerr));
1922 dwarf_dealloc(dbg,cerr,DW_DLA_ERROR);
1923 cerr = 0;
1924 }
1925 esb_destructor(&exprstring);
1926 return DW_DLV_OK;
1927 }
1928
1929 /* Print the frame instructions in detail
1930 for a glob of instructions.
1931 The frame data has not been checked by
1932 libdwarf as libdwarf has not
1933 transformed it into simple structs.
1934 We are reading the raw data.
1935 */
1936 /*ARGSUSED*/ static void
1937 print_frame_inst_bytes(Dwarf_Debug dbg,
1938 Dwarf_Frame_Instr_Head instr_head,
1939 Dwarf_Unsigned instr_array_len,
1940 Dwarf_Die die,
1941 Dwarf_Signed data_alignment_factor,
1942 Dwarf_Unsigned code_alignment_factor,
1943 Dwarf_Half addr_size,
1944 Dwarf_Half offset_size,
1945 Dwarf_Half version,
1946 struct dwconf_s *config_data)
1947 {
1948 Dwarf_Error error = 0;
1949 Dwarf_Half lastop = 0;
1950 Dwarf_Unsigned i = 0;
1951
1952 if (instr_array_len == 0) {
1953 return;
1954 }
1955 if (!instr_head) {
1956 /* Impossible */
1957 return;
1958 }
1959 for ( ; i < instr_array_len; ++i) {
1960 int res = 0;
1961 Dwarf_Unsigned instr_offset_in_instrs = 0;
1962 Dwarf_Small cfa_operation = 0;
1963 const char *fields= 0;
1964 Dwarf_Unsigned u0 = 0;
1965 Dwarf_Unsigned u1 = 0;
1966 Dwarf_Unsigned u2 = 0;
1967 Dwarf_Signed s0 = 0;
1968 Dwarf_Signed s1 = 0;
1969 Dwarf_Block expression_block;
1970 const char *op_name = 0;
1971
1972 if (!i) {
1973 printf(" [ ] offset name operands\n");
1974 }
1975 res = dwarf_get_frame_instruction_a(instr_head,
1976 i,&instr_offset_in_instrs, &cfa_operation,
1977 &fields, &u0,&u1,&u2,&s0,&s1,
1978 0,0, /* These alignment factors passed to us. */
1979 &expression_block,&error);
1980 if (res != DW_DLV_OK) {
1981 if (res == DW_DLV_ERROR) {
1982 dwarf_dealloc_error(dbg,error);
1983 error = 0;
1984 }
1985 return;
1986 }
1987 lastop = cfa_operation;
1988 res = dwarf_get_CFA_name(cfa_operation,&op_name);
1989 if (res == DW_DLV_NO_ENTRY) {
1990 op_name = "InstrOpUnknown";
1991 }
1992 printf(" [%2" DW_PR_DUu "] %2" DW_PR_DUu " %-23s ",i,
1993 instr_offset_in_instrs,op_name);
1994 switch(fields[0]) {
1995 case 'u': {
1996 if (!fields[1]) {
1997 printf("%" DW_PR_DUu "\n",u0);
1998 break;
1999 }
2000 if (fields[1] == 'c') {
2001 Dwarf_Unsigned final =
2002 u0*code_alignment_factor;
2003 printf("%" DW_PR_DUu ,final);
2004 if (glflags.verbose) {
2005 printf(" (%" DW_PR_DUu " * %" DW_PR_DUu
2006 ")",
2007 u0,code_alignment_factor);
2008
2009 }
2010 printf("\n");
2011 break;
2012 }
2013 }
2014 break;
2015 case 'r': {
2016 if (!fields[1]) {
2017 printreg(u0,config_data);
2018 printf("\n");
2019 break;
2020 }
2021 if (fields[1] == 'u') {
2022 if (!fields[2]) {
2023 printreg(u0,config_data);
2024 printf(" %" DW_PR_DUu ,u1);
2025 printf("\n");
2026 break;
2027 }
2028 if (fields[2] == 'd') {
2029 Dwarf_Signed final =
2030 (Dwarf_Signed)u1 *
2031 data_alignment_factor;
2032 printreg(u0,config_data);
2033 printf(" %" DW_PR_DSd ,final);
2034 if (glflags.verbose) {
2035 printf(" (%" DW_PR_DUu " * %" DW_PR_DSd
2036 ")",
2037 u1,data_alignment_factor);
2038 }
2039 printf("\n");
2040 break;
2041 }
2042 if (fields[2] == 'a') {
2043 printreg(u0,config_data);
2044 printf(" %" DW_PR_DUu ,u1);
2045 printf(" (%" DW_PR_DUu ", addrspace %"
2046 DW_PR_DUu ")",
2047 u1,u2);
2048 printf("\n");
2049 break;
2050 }
2051 }
2052 if (fields[1] == 'r') {
2053 printreg(u0,config_data);
2054 printf(" ");
2055 printreg(u1,config_data);
2056 printf("\n");
2057 break;
2058 }
2059 if (fields[1] == 's') {
2060 if (fields[2] == 'd') {
2061 Dwarf_Signed final = s1 * data_alignment_factor;
2062 printreg(u0,config_data);
2063 printf(" %" DW_PR_DSd , final);
2064 if (glflags.verbose) {
2065 printf(" (%" DW_PR_DSd " * %" DW_PR_DSd
2066 ")",
2067 s1,data_alignment_factor);
2068 }
2069 if (fields[3] == 'a') {
2070 printf(", addrspace %" DW_PR_DUu, u2);
2071 }
2072 printf("\n");
2073 break;
2074 }
2075 }
2076 if (fields[1] == 'b') {
2077 /* rb */
2078 printreg(u0,config_data);
2079 printf(" expr block len %" DW_PR_DUu "\n",
2080 expression_block.bl_len);
2081 dump_block(" ", expression_block.bl_data,
2082 (Dwarf_Signed) expression_block.bl_len);
2083 printf("\n");
2084 if (glflags.verbose) {
2085 print_expression(dbg,die,&expression_block,
2086 addr_size,offset_size,
2087 version);
2088 }
2089 break;
2090 }
2091 }
2092 break;
2093 case 's': {
2094 if (fields[1] == 'd') {
2095 Dwarf_Signed final = s0*data_alignment_factor;
2096
2097 printf(" %" DW_PR_DSd ,final);
2098 if (glflags.verbose) {
2099 printf(" (%" DW_PR_DSd " * %" DW_PR_DSd
2100 ")",
2101 s0,data_alignment_factor);
2102 }
2103 printf("\n");
2104 break;
2105 }
2106 }
2107 break;
2108 case 'b': {
2109 if (!fields[1]) {
2110 printf(" expr block len %" DW_PR_DUu "\n",
2111 expression_block.bl_len);
2112 dump_block(" ", expression_block.bl_data,
2113 (Dwarf_Signed) expression_block.bl_len);
2114 printf("\n");
2115 if (glflags.verbose) {
2116 print_expression(dbg,die,&expression_block,
2117 addr_size,offset_size,
2118 version);
2119 }
2120 break;
2121 }
2122 }
2123 break;
2124 case 0:
2125 printf("\n");
2126 break;
2127 default:
2128 printf("UNKNOWN FIELD 0x%x\n",fields[0]);
2129 }
2130 #if 0
2131 glflags.gf_count_major_errors++;
2132 printf("\nERROR: Unexpected frame instruction string"
2133 " \"%s\" not understood.\n",fields);
2134 #endif
2135 }
2136 if (lastop_pointless(lastop)) {
2137 printf(
2138 " Warning: Final FDE operator is useless "
2139 "but not an error. %s\n",
2140 get_CFA_name(lastop,TRUE));
2141 }
2142 }
2143
2144 /* Print our register names for the cases we have a name.
2145 Delegate to the configure code to actually do the print.
2146 */
2147 void
2148 printreg(Dwarf_Unsigned reg, struct dwconf_s *config_data)
2149 {
2150 print_reg_from_config_data(reg, config_data);
2151 }
2152
2153 /* Actually does the printing of a rule in the table.
2154 This may print something or may print nothing! */
2155 static void
2156 print_one_frame_reg_col(Dwarf_Debug dbg,
2157 Dwarf_Die die,
2158 Dwarf_Unsigned rule_id,
2159 Dwarf_Small value_type,
2160 Dwarf_Unsigned reg_used,
2161 Dwarf_Half addr_size,
2162 Dwarf_Half offset_size,
2163 Dwarf_Half version,
2164 struct dwconf_s *config_data,
2165 Dwarf_Signed offset_relevant,
2166 Dwarf_Signed offset,
2167 Dwarf_Block *block)
2168 {
2169 char *type_title = "";
2170 int print_type_title = 1;
2171
2172 if (!glflags.gf_do_print_dwarf) {
2173 return;
2174 }
2175 if (reg_used == config_data->cf_initial_rule_value &&
2176 (value_type == DW_EXPR_OFFSET ||
2177 value_type == DW_EXPR_VAL_OFFSET) ) {
2178 /* This is really an empty column. Nothing to do.
2179 Would be great if we could tell the caller
2180 the *next* column used here or something. */
2181 return;
2182 }
2183 switch (value_type) {
2184 case DW_EXPR_OFFSET:
2185 type_title = "off";
2186 goto preg2;
2187 case DW_EXPR_VAL_OFFSET:
2188 type_title = "valoff";
2189
2190 preg2:
2191 if (print_type_title)
2192 printf("<%s ", type_title);
2193 printreg(rule_id, config_data);
2194 printf("=");
2195 if (offset_relevant == 0) {
2196 printreg(reg_used, config_data);
2197 printf(" ");
2198 } else {
2199 printf("%02" DW_PR_DSd , offset);
2200 printf("(");
2201 printreg(reg_used, config_data);
2202 printf(") ");
2203 }
2204 if (print_type_title)
2205 printf("> ");
2206 break;
2207 case DW_EXPR_EXPRESSION:
2208 type_title = "expr";
2209 goto pexp2;
2210 case DW_EXPR_VAL_EXPRESSION:
2211 type_title = "valexpr";
2212
2213 pexp2:
2214 if (print_type_title) {
2215 printf("<%s ", type_title);
2216 }
2217 if (offset_relevant) {
2218 printf("ERROR: frame register type %s "
2219 "marked as offset_relevant "
2220 "but that is impossible, it has no such "
2221 "field.",type_title);
2222 glflags.gf_count_major_errors++;
2223 }
2224 printreg(rule_id, config_data);
2225 printf("=");
2226 printf("expr-block-len=%" DW_PR_DUu , block->bl_len);
2227 if (print_type_title) {
2228 printf("> ");
2229 }
2230 if (glflags.verbose) {
2231 printf("<");
2232 printf("%s",type_title);
2233 printf("bytes:");
2234 /* The data being dumped comes direct from
2235 libdwarf so libdwarf validated it. */
2236 dump_block("", block->bl_data, block->bl_len);
2237 printf("> ");
2238 {
2239 struct esb_s exprstring;
2240 char local_buf[300];
2241 int gres = 0;
2242 Dwarf_Error cerr = 0;
2243
2244 esb_constructor_fixed(&exprstring,local_buf,
2245 sizeof(local_buf));
2246 gres = print_expression_operations(dbg,
2247 die,
2248 /* indent */ 1,
2249 block->bl_data, block->bl_len,
2250 addr_size,
2251 offset_size,version,
2252 &exprstring,&cerr);
2253 if ( gres == DW_DLV_OK) {
2254 printf("<expr:%s>",sanitized(
2255 esb_get_string(&exprstring)));
2256 } else if (gres == DW_DLV_NO_ENTRY) {
2257 glflags.gf_count_major_errors++;
2258 printf("\nERROR: Unable to get string from"
2259 " DW_EXPR_VAL_EXPRESSION block of length "
2260 " %" DW_PR_DSd " bytes.\n" ,offset);
2261 } else {
2262 glflags.gf_count_major_errors++;
2263 printf("\nERROR: No string from"
2264 " DW_EXPR_VAL_EXPRESSION block of length "
2265 " %" DW_PR_DSd " bytes.\n" ,offset);
2266 printf("Error: %s\n",dwarf_errmsg(cerr));
2267 dwarf_dealloc_error(dbg,cerr);
2268 cerr = 0;
2269 }
2270 esb_destructor(&exprstring);
2271 }
2272 }
2273 break;
2274 default:
2275 printf("Internal error in libdwarf, value type %d\n",
2276 value_type);
2277 exit(EXIT_FAILURE);
2278 }
2279 return;
2280 }
2281
2282 static void
2283 dd_check_get_fde_n(Dwarf_Debug dbg,
2284 Dwarf_Fde *fde_data,
2285 Dwarf_Fde expected_fde,
2286 Dwarf_Signed index)
2287 {
2288 int res = 0;
2289 Dwarf_Error localerr = 0;
2290 Dwarf_Fde ret_fde = 0;
2291
2292 DWARF_CHECK_COUNT(check_functions_result,1);
2293 res = dwarf_get_fde_n(fde_data,
2294 (Dwarf_Unsigned)index,&ret_fde,&localerr);
2295 if (res == DW_DLV_ERROR) {
2296 DWARF_CHECK_ERROR2(check_functions_result,
2297 "dwarf_get_cie_index() returned DW_DLV_ERRORi "
2298 "underlying error is ",
2299 dwarf_errmsg(localerr));
2300 DROP_ERROR_INSTANCE(dbg,res,localerr);
2301 } else if (res == DW_DLV_NO_ENTRY) {
2302 DWARF_CHECK_ERROR(check_functions_result,
2303 "dwarf_get_cie_index() returned DW_DLV_NO_ENTRY ");
2304 } else {
2305 if (ret_fde != expected_fde) {
2306 DWARF_CHECK_ERROR(check_functions_result,
2307 "dwarf_get_cie_index() does not"
2308 " return the expected fde!");
2309 }
2310 }
2311 }
2312
2313 /* We do NOT want to free cie/fde data as we will
2314 use that in print_all_cies() */
2315 static int
2316 print_all_fdes(Dwarf_Debug dbg,
2317 const char *frame_section_name,
2318 Dwarf_Fde *fde_data,
2319 Dwarf_Signed fde_element_count,
2320 Dwarf_Cie *cie_data,
2321 Dwarf_Signed cie_element_count,
2322 Dwarf_Half address_size,
2323 Dwarf_Half offset_size,
2324 Dwarf_Half version,
2325 int is_eh,
2326 struct dwconf_s *config_data,
2327 void **map_lowpc_to_name,
2328 void **lowpcSet,
2329 Dwarf_Die *cu_die_for_print_frames,
2330 Dwarf_Error*err)
2331 {
2332 Dwarf_Signed i = 0;
2333 int frame_count = 0;
2334
2335 /* Do not print if in check mode */
2336 if (glflags.gf_do_print_dwarf) {
2337 struct esb_s truename;
2338 char buf[DWARF_SECNAME_BUFFER_SIZE];
2339 const char *stdsecname = 0;
2340
2341 if (!is_eh) {
2342 stdsecname=".debug_frame";
2343 } else {
2344 stdsecname=".eh_frame";
2345 }
2346 esb_constructor_fixed(&truename,buf,sizeof(buf));
2347 get_true_section_name(dbg,stdsecname,
2348 &truename,TRUE);
2349 printf("\n%s\n",sanitized(esb_get_string(&truename)));
2350 esb_destructor(&truename);
2351 printf("\nfde:\n");
2352 }
2353
2354 for (i = 0; i < fde_element_count; i++) {
2355 int fdres = 0;
2356 Dwarf_Fde fde = 0;
2357
2358 fde = fde_data[i];
2359 if (glflags.gf_check_functions) {
2360 dd_check_get_fde_n(dbg,fde_data,
2361 fde,i);
2362 }
2363 fdres = print_one_fde(dbg,
2364 frame_section_name,
2365 fde_data,i,
2366 cie_data, cie_element_count,
2367 address_size, offset_size, version,
2368 is_eh, config_data,
2369 map_lowpc_to_name,
2370 lowpcSet,
2371 cu_die_for_print_frames,
2372 err);
2373 if (fdres == DW_DLV_ERROR) {
2374 glflags.gf_count_major_errors++;
2375 printf("ERROR: Printing fde %" DW_PR_DSd
2376 " fails. Error %s\n",
2377 i,dwarf_errmsg(*err));
2378 return fdres;
2379 }
2380 if (fdres == DW_DLV_NO_ENTRY) {
2381 glflags.gf_count_major_errors++;
2382 printf("ERROR: Printing fde %" DW_PR_DSd
2383 " fails saying 'no entry'. Impossible.\n",
2384 i);
2385 return fdres;
2386 }
2387 ++frame_count;
2388 if (frame_count >= glflags.break_after_n_units) {
2389 break;
2390 }
2391 }
2392 return DW_DLV_OK;
2393 }
2394
2395 static int
2396 print_all_cies(Dwarf_Debug dbg,
2397 Dwarf_Cie *cie_data,
2398 Dwarf_Signed cie_element_count,
2399 Dwarf_Half address_size,
2400 struct dwconf_s *config_data,
2401 Dwarf_Die *cu_die_for_print_frames,
2402 Dwarf_Error*err)
2403 {
2404 /* Print the cie set. */
2405 /* Do not print if in check mode */
2406 Dwarf_Signed i = 0;
2407 Dwarf_Signed cie_count = 0;
2408
2409 if (glflags.gf_do_print_dwarf) {
2410 printf("\ncie:\n");
2411 }
2412 for (i = 0; i < cie_element_count; i++) {
2413 int cres = 0;
2414
2415 cres = print_one_cie(dbg,
2416 *cu_die_for_print_frames,
2417 cie_data[i], i, address_size,
2418 config_data,
2419 err);
2420 if (cres == DW_DLV_ERROR) {
2421 glflags.gf_count_major_errors++;
2422 printf("\nERROR: Printing cie %" DW_PR_DSd
2423 " fails. Error %s\n",
2424 i,dwarf_errmsg(*err));
2425 return cres;
2426 } else if (cres == DW_DLV_NO_ENTRY) {
2427 glflags.gf_count_major_errors++;
2428 printf("\nERROR: Printing cie %" DW_PR_DSd
2429 " fails. saying NO_ENTRY!\n",
2430 i);
2431 return cres;
2432 } else {
2433 ++cie_count;
2434 if (cie_count >= glflags.break_after_n_units) {
2435 break;
2436 }
2437 }
2438 }
2439 return DW_DLV_OK;
2440 }
2441 /* get all the data in .debug_frame (or .eh_frame).
2442 The '3' versions mean print using the dwarf3 new interfaces.
2443 The non-3 mean use the old interfaces.
2444 All combinations of requests are possible. */
2445 int
2446 print_frames(Dwarf_Debug dbg,
2447 int want_eh,
2448 struct dwconf_s *config_data,
2449 /* Pass these next 3 so preserved from .eh_frame
2450 to .debug_frame */
2451 Dwarf_Die * cu_die_for_print_frames,
2452 void ** map_lowpc_to_name,
2453 void ** lowpcSet,
2454 Dwarf_Error *err)
2455 {
2456 int fres = 0;
2457 Dwarf_Half address_size = 0;
2458 Dwarf_Half offset_size = 0;
2459 Dwarf_Half version = 0;
2460
2461 /* We only get here if a flag says we want to
2462 process the section (want_eh is either 0 or 1). */
2463 glflags.current_section_id = DEBUG_FRAME;
2464 /* Only in DWARF4 or later is there a real address
2465 size known in the frame data itself. If any DIE
2466 is known then a real address size can be gotten from
2467 dwarf_get_die_address_size(). */
2468 fres = dwarf_get_address_size(dbg, &address_size, err);
2469 if (fres != DW_DLV_OK) {
2470 glflags.gf_count_major_errors++;
2471 printf("ERROR: Unable to print frame section as "
2472 " we cannot get the address size\n");
2473 return fres;
2474 }
2475 {
2476 Dwarf_Cie *cie_data = NULL;
2477 Dwarf_Signed cie_element_count = 0;
2478 Dwarf_Fde *fde_data = NULL;
2479 Dwarf_Signed fde_element_count = 0;
2480 const char *frame_section_name = 0;
2481 int silent_if_missing = 0;
2482 int is_eh = 0;
2483
2484 if (!want_eh) {
2485 Dwarf_Error localerr = 0;
2486 glflags.current_section_id = DEBUG_FRAME;
2487 /* Do not free frame_section_name. */
2488 fres = dwarf_get_frame_section_name(dbg,
2489 &frame_section_name,&localerr);
2490 if (fres != DW_DLV_OK || !frame_section_name ||
2491 !strlen(frame_section_name)) {
2492 frame_section_name = ".debug_frame";
2493 if (fres == DW_DLV_ERROR) {
2494 dwarf_dealloc(dbg,localerr,DW_DLA_ERROR);
2495 localerr = 0;
2496 }
2497 }
2498
2499 /* Big question here is how to print all the info?
2500 Can print the logical matrix, but that is huge,
2501 though could skip lines that don't change.
2502 Either that, or print the instruction statement
2503 program that describes the changes. */
2504 fres = dwarf_get_fde_list(dbg, &cie_data,
2505 &cie_element_count,
2506 &fde_data, &fde_element_count, err);
2507 if (glflags.gf_check_harmless) {
2508 print_any_harmless_errors(dbg);
2509 }
2510 } else {
2511 /* want_eh */
2512 Dwarf_Error localerr = 0;
2513 glflags.current_section_id = DEBUG_FRAME_EH_GNU;
2514 is_eh = 1;
2515 /* This is gnu g++ exceptions in a .eh_frame section.
2516 Which is just like .debug_frame except that
2517 the empty, or 'special' CIE_id is 0, not -1
2518 (to distinguish fde from cie).
2519 And the augmentation is "eh". As of egcs-1.1.2
2520 anyway. A non-zero cie_id is in a fde and is the
2521 difference between the fde address and the
2522 beginning of the cie it belongs to.
2523 This makes sense as this is
2524 intended to be referenced at run time, and
2525 is part of the running image. For more on
2526 augmentation strings,
2527 see libdwarf/dwarf_frame.c. */
2528 /* Big question here is how to print all the info?
2529 Can print the logical matrix, but that is huge,
2530 though could skip lines that don't change.
2531 Either that, or print the instruction statement
2532 program that describes the changes. */
2533 silent_if_missing = 1;
2534 /* Do not free frame_section_name. */
2535 fres = dwarf_get_frame_section_name_eh_gnu(dbg,
2536 &frame_section_name,&localerr);
2537 if (fres != DW_DLV_OK || !frame_section_name ||
2538 !strlen(frame_section_name)) {
2539 frame_section_name = ".eh_frame";
2540 if (fres == DW_DLV_ERROR){
2541 dwarf_dealloc(dbg,localerr,DW_DLA_ERROR);
2542 localerr = 0;
2543 }
2544 }
2545 fres = dwarf_get_fde_list_eh(dbg, &cie_data,
2546 &cie_element_count, &fde_data,
2547 &fde_element_count, err);
2548 if (glflags.gf_check_harmless) {
2549 print_any_harmless_errors(dbg);
2550 }
2551 }
2552 if (fres == DW_DLV_ERROR) {
2553 const char *loc = "dwarf_get_fde_list";
2554 if (is_eh) {
2555 loc = "dwarf_get_fde_list_eh";
2556 }
2557 glflags.gf_count_major_errors++;
2558 printf("\nERROR: %s not loadable. %s %s\n",
2559 sanitized(frame_section_name),loc,
2560 dwarf_errmsg(*err));
2561 return fres;
2562 }
2563
2564 /* Do not print any frame info if in check mode */
2565 if (glflags.gf_check_frames) {
2566 if (fres == DW_DLV_OK) {
2567 dwarf_dealloc_fde_cie_list(dbg, cie_data,
2568 cie_element_count,
2569 fde_data, fde_element_count);
2570 }
2571 return DW_DLV_OK;
2572 }
2573
2574 if (fres == DW_DLV_NO_ENTRY) {
2575 if (!silent_if_missing) {
2576 printf("\n%s is not present\n",
2577 sanitized(frame_section_name));
2578 }
2579 /* no frame information */
2580 return fres;
2581 } else { /* DW_DLV_OK */
2582 int res = 0;
2583
2584 res = print_all_fdes(dbg,frame_section_name,fde_data,
2585 fde_element_count,
2586 cie_data, cie_element_count,
2587 address_size,offset_size,version,is_eh,
2588 config_data,map_lowpc_to_name,
2589 lowpcSet,
2590 cu_die_for_print_frames,
2591 err);
2592 if (res == DW_DLV_ERROR) {
2593 glflags.gf_count_major_errors++;
2594 printf("ERROR: printing fdes fails. %s "
2595 " Attempting to continue. \n",
2596 dwarf_errmsg(*err));
2597 dwarf_dealloc_error(dbg,*err);
2598 *err = 0;
2599 }
2600 res = print_all_cies(dbg,
2601 /* frame_section_name, */
2602 cie_data, cie_element_count,
2603 address_size,
2604 /* offset_size,version,is_eh, */
2605 config_data,
2606 /* map_lowpc_to_name, lowpcSet, */
2607 cu_die_for_print_frames,
2608 err);
2609 if (res == DW_DLV_ERROR) {
2610 glflags.gf_count_major_errors++;
2611 printf("ERROR: printing cies fails. %s "
2612 " Attempting to continue. \n",
2613 dwarf_errmsg(*err));
2614 dwarf_dealloc_error(dbg,*err);
2615 *err = 0;
2616 }
2617 /* Here we do the free. Not earlier. */
2618 dwarf_dealloc_fde_cie_list(dbg, cie_data,
2619 cie_element_count,
2620 fde_data, fde_element_count);
2621 } /* End inner scope, not a loop */
2622 } /* End inner scope, not a loop */
2623 return DW_DLV_OK;
2624 }