| 1 |
/* |
| 2 |
Copyright (C) 2000-2006 Silicon Graphics, Inc. All Rights Reserved. |
| 3 |
Portions Copyright 2007-2010 Sun Microsystems, Inc. All rights reserved. |
| 4 |
Portions Copyright 2009-2018 SN Systems Ltd. All rights reserved. |
| 5 |
Portions Copyright 2008-2020 David Anderson. All rights reserved. |
| 6 |
Portions Copyright 2015-2015 Google, Inc. All Rights Reserved |
| 7 |
|
| 8 |
This program is free software; you can redistribute it and/or |
| 9 |
modify it under the terms of version 2 of the GNU General |
| 10 |
Public License as published by the Free Software Foundation. |
| 11 |
|
| 12 |
This program is distributed in the hope that it would be |
| 13 |
useful, but WITHOUT ANY WARRANTY; without even the implied |
| 14 |
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 15 |
PURPOSE. |
| 16 |
|
| 17 |
Further, this software is distributed without any warranty |
| 18 |
that it is free of the rightful claim of any third person |
| 19 |
regarding infringement or the like. Any license provided |
| 20 |
herein, whether implied or otherwise, applies only to this |
| 21 |
software file. Patent licenses, if any, provided herein |
| 22 |
do not apply to combinations of this program with other |
| 23 |
software, or any other product whatsoever. |
| 24 |
|
| 25 |
You should have received a copy of the GNU General Public |
| 26 |
License along with this program; if not, write the Free |
| 27 |
Software Foundation, Inc., 51 Franklin Street - Fifth Floor, |
| 28 |
Boston MA 02110-1301, USA. |
| 29 |
*/ |
| 30 |
|
| 31 |
#include <config.h> |
| 32 |
|
| 33 |
#include <string.h> /* strcmp() strlen() */ |
| 34 |
#include <time.h> /* ctime() */ |
| 35 |
#include <stdio.h> /* FILE decl for dd_esb.h, printf etc */ |
| 36 |
|
| 37 |
#include "dwarf.h" |
| 38 |
#include "libdwarf.h" |
| 39 |
#include "libdwarf_private.h" |
| 40 |
#include "dd_defined_types.h" |
| 41 |
#include "dd_checkutil.h" |
| 42 |
#include "dd_glflags.h" |
| 43 |
#include "dd_globals.h" |
| 44 |
#include "dd_naming.h" |
| 45 |
#include "dd_esb.h" |
| 46 |
#include "dd_esb_using_functions.h" |
| 47 |
#include "dd_sanitized.h" |
| 48 |
#include "dd_uri.h" |
| 49 |
|
| 50 |
#include "print_sections.h" |
| 51 |
|
| 52 |
/* |
| 53 |
Print line number information: |
| 54 |
[line] [address] <new statement> |
| 55 |
new basic-block |
| 56 |
filename |
| 57 |
*/ |
| 58 |
|
| 59 |
#define DW_LINE_VERSION5 5 |
| 60 |
|
| 61 |
static void |
| 62 |
print_source_intro(Dwarf_Debug dbg,Dwarf_Die cu_die) |
| 63 |
{ |
| 64 |
int ores = 0; |
| 65 |
Dwarf_Off off = 0; |
| 66 |
Dwarf_Error src_err = 0; |
| 67 |
|
| 68 |
ores = dwarf_dieoffset(cu_die, &off, &src_err); |
| 69 |
if (ores == DW_DLV_OK) { |
| 70 |
int lres = 0; |
| 71 |
const char *sec_name = 0; |
| 72 |
|
| 73 |
lres = dwarf_get_die_section_name_b(cu_die, |
| 74 |
&sec_name,&src_err); |
| 75 |
if (lres != DW_DLV_OK || !sec_name || !strlen(sec_name)) { |
| 76 |
sec_name = ".debug_info"; |
| 77 |
} |
| 78 |
printf("Source lines (from CU-DIE at %s offset 0x%" |
| 79 |
DW_PR_XZEROS DW_PR_DUx "):\n", |
| 80 |
sec_name, |
| 81 |
(Dwarf_Unsigned) off); |
| 82 |
DROP_ERROR_INSTANCE(dbg,lres,src_err); |
| 83 |
} else { |
| 84 |
DROP_ERROR_INSTANCE(dbg,ores,src_err); |
| 85 |
printf("Source lines (for the CU-DIE at unknown" |
| 86 |
" location):\n"); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
static void |
| 91 |
print_common_line_error(const char *where, Dwarf_Error line_err) |
| 92 |
{ |
| 93 |
if (checking_this_compiler()) { |
| 94 |
struct esb_s tmp_buff; |
| 95 |
char buftmp[ESB_FIXED_ALLOC_SIZE]; |
| 96 |
|
| 97 |
esb_constructor_fixed(&tmp_buff,buftmp,sizeof(buftmp)); |
| 98 |
esb_append_printf_s(&tmp_buff, |
| 99 |
"Error getting line details calling %s", |
| 100 |
where); |
| 101 |
esb_append_printf_s(&tmp_buff, |
| 102 |
" dwarf error is %s", |
| 103 |
dwarf_errmsg(line_err)); |
| 104 |
DWARF_CHECK_ERROR(lines_result,esb_get_string(&tmp_buff)); |
| 105 |
esb_destructor(&tmp_buff); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
static void |
| 110 |
check_last_line_of_table(Dwarf_Addr pc, |
| 111 |
Dwarf_Addr elf_max_address, |
| 112 |
const char * sec_name) |
| 113 |
{ |
| 114 |
/* Ignore those PU that have been stripped |
| 115 |
by the linker; their low_pc values are |
| 116 |
set to -1 (snc linker only) */ |
| 117 |
/* It is perfectly sensible for a compiler |
| 118 |
to leave a few bytes of NOP or other stuff |
| 119 |
after the last instruction in a subprogram, |
| 120 |
for cache-alignment or other purposes, so |
| 121 |
a mismatch here is not necessarily |
| 122 |
an error. */ |
| 123 |
|
| 124 |
if (glflags.gf_check_lines && |
| 125 |
checking_this_compiler()) { |
| 126 |
DWARF_CHECK_COUNT(lines_result,1); |
| 127 |
if ((pc != glflags.PU_high_address) && |
| 128 |
(glflags.PU_base_address != |
| 129 |
elf_max_address)) { |
| 130 |
char addr_tmp[140]; |
| 131 |
struct esb_s cm; |
| 132 |
|
| 133 |
esb_constructor_fixed(&cm,addr_tmp, |
| 134 |
sizeof(addr_tmp)); |
| 135 |
esb_append_printf_s(&cm, |
| 136 |
"%s: Address",sanitized(sec_name)); |
| 137 |
esb_append_printf_u(&cm, |
| 138 |
" 0x%" DW_PR_XZEROS DW_PR_DUx |
| 139 |
" DW_LNE_end_sequence address" |
| 140 |
" does not exactly match",pc); |
| 141 |
esb_append_printf_u(&cm, |
| 142 |
" high function addr: " |
| 143 |
" 0x%" DW_PR_XZEROS DW_PR_DUx, |
| 144 |
glflags.PU_high_address); |
| 145 |
DWARF_CHECK_ERROR(lines_result, |
| 146 |
esb_get_string(&cm)); |
| 147 |
esb_destructor(&cm); |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
static int |
| 153 |
process_line_table(Dwarf_Debug dbg, |
| 154 |
const char *sec_name, |
| 155 |
Dwarf_Line *linebuf, |
| 156 |
Dwarf_Signed linecount, |
| 157 |
Dwarf_Bool is_logicals_table, |
| 158 |
Dwarf_Bool is_actuals_table, |
| 159 |
Dwarf_Error *lt_err) |
| 160 |
{ |
| 161 |
char *padding = 0; |
| 162 |
Dwarf_Signed i = 0; |
| 163 |
Dwarf_Addr pc = 0; |
| 164 |
Dwarf_Unsigned lineno = 0; |
| 165 |
Dwarf_Unsigned logicalno = 0; |
| 166 |
Dwarf_Unsigned column = 0; |
| 167 |
Dwarf_Unsigned call_context = 0; |
| 168 |
char* subprog_name = 0; |
| 169 |
char* subprog_filename = 0; |
| 170 |
Dwarf_Unsigned subprog_line = 0; |
| 171 |
|
| 172 |
Dwarf_Bool newstatement = 0; |
| 173 |
Dwarf_Bool lineendsequence = 0; |
| 174 |
Dwarf_Bool new_basic_block = 0; |
| 175 |
int sres = 0; |
| 176 |
int ares = 0; |
| 177 |
int lires = 0; |
| 178 |
int cores = 0; |
| 179 |
char lastsrc_tmp[ESB_FIXED_ALLOC_SIZE]; |
| 180 |
struct esb_s lastsrc; |
| 181 |
Dwarf_Addr elf_max_address = 0; |
| 182 |
Dwarf_Bool SkipRecord = FALSE; |
| 183 |
|
| 184 |
esb_constructor_fixed(&lastsrc,lastsrc_tmp,sizeof(lastsrc_tmp)); |
| 185 |
glflags.current_section_id = DEBUG_LINE; |
| 186 |
/* line_flag is TRUE */ |
| 187 |
get_address_size_and_max(dbg,0,&elf_max_address,lt_err); |
| 188 |
/* Padding for a nice layout */ |
| 189 |
padding = glflags.gf_line_print_pc ? " " : ""; |
| 190 |
if (glflags.gf_do_print_dwarf) { |
| 191 |
/* Check if print of <pc> address is needed. */ |
| 192 |
printf("\n"); |
| 193 |
if (is_logicals_table) { |
| 194 |
printf("Logicals Table:\n"); |
| 195 |
printf("%sNS new statement, PE prologue end, " |
| 196 |
"EB epilogue begin\n",padding); |
| 197 |
printf("%sDI=val discriminator value\n", |
| 198 |
padding); |
| 199 |
printf("%sCC=val context, SB=val subprogram\n", |
| 200 |
padding); |
| 201 |
} else if (is_actuals_table) { |
| 202 |
printf("Actuals Table:\n"); |
| 203 |
printf("%sBB new basic block, ET end of text sequence\n" |
| 204 |
"%sIS=val ISA number\n",padding,padding); |
| 205 |
|
| 206 |
} else { |
| 207 |
/* Standard DWARF line table. */ |
| 208 |
printf("%sNS new statement, BB new basic block, " |
| 209 |
"ET end of text sequence\n",padding); |
| 210 |
printf("%sPE prologue end, EB epilogue begin\n",padding); |
| 211 |
printf("%sIS=val ISA number, " |
| 212 |
"DI=val discriminator value\n", |
| 213 |
padding); |
| 214 |
} |
| 215 |
if (is_logicals_table || is_actuals_table) { |
| 216 |
printf("[ row] "); |
| 217 |
} |
| 218 |
if (glflags.gf_line_print_pc) { |
| 219 |
printf("<pc> "); |
| 220 |
} |
| 221 |
if (is_logicals_table) { |
| 222 |
printf("[lno,col] NS PE EB DI= CC= SB= uri:" |
| 223 |
" \"filepath\"\n"); |
| 224 |
} else if (is_actuals_table) { |
| 225 |
printf("[logical] BB ET IS=\n"); |
| 226 |
} else { |
| 227 |
printf("[lno,col] NS BB ET PE EB IS= DI= uri:" |
| 228 |
" \"filepath\"\n"); |
| 229 |
} |
| 230 |
} |
| 231 |
for (i = 0; i < linecount; i++) { |
| 232 |
Dwarf_Line line = linebuf[i]; |
| 233 |
char* lsrc_filename = 0; |
| 234 |
int nsres = 0; |
| 235 |
Dwarf_Bool found_line_error = FALSE; |
| 236 |
Dwarf_Bool has_is_addr_set = FALSE; |
| 237 |
char *where = NULL; |
| 238 |
|
| 239 |
if (glflags.gf_check_decl_file && checking_this_compiler()) { |
| 240 |
/* A line record with addr=0 was detected */ |
| 241 |
if (SkipRecord) { |
| 242 |
/* Skip records that do not have is_addr_set */ |
| 243 |
ares = dwarf_line_is_addr_set(line, |
| 244 |
&has_is_addr_set, lt_err); |
| 245 |
if (ares == DW_DLV_OK && has_is_addr_set) { |
| 246 |
SkipRecord = FALSE; |
| 247 |
} |
| 248 |
else { |
| 249 |
/* Keep ignoring records until we have |
| 250 |
one with 'is_addr_set' */ |
| 251 |
continue; |
| 252 |
} |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
if (glflags.gf_check_lines && checking_this_compiler()) { |
| 257 |
DWARF_CHECK_COUNT(lines_result,1); |
| 258 |
} |
| 259 |
|
| 260 |
/* NO. lsrc_filename is a DW_DLA_STRING, do not assign |
| 261 |
a static string. |
| 262 |
lsrc_filename = "<unknown>"; |
| 263 |
*/ |
| 264 |
if (!is_actuals_table) { |
| 265 |
Dwarf_Error aterr = 0; |
| 266 |
|
| 267 |
sres = dwarf_linesrc(line, &lsrc_filename, &aterr); |
| 268 |
if (sres == DW_DLV_ERROR) { |
| 269 |
/* Do not terminate processing */ |
| 270 |
if (glflags.gf_do_check_dwarf && |
| 271 |
checking_this_compiler()) { |
| 272 |
where = "dwarf_linesrc()"; |
| 273 |
print_common_line_error(where,aterr); |
| 274 |
found_line_error = TRUE; |
| 275 |
} |
| 276 |
DROP_ERROR_INSTANCE(dbg,sres,aterr); |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
pc = 0; |
| 281 |
ares = dwarf_lineaddr(line, &pc, lt_err); |
| 282 |
|
| 283 |
if (ares == DW_DLV_ERROR) { |
| 284 |
/* Do not terminate processing */ |
| 285 |
if (glflags.gf_do_check_dwarf && |
| 286 |
checking_this_compiler()) { |
| 287 |
where = "dwarf_lineaddr()"; |
| 288 |
print_common_line_error(where,*lt_err); |
| 289 |
found_line_error = TRUE; |
| 290 |
} |
| 291 |
pc = 0; |
| 292 |
DROP_ERROR_INSTANCE(dbg,ares,*lt_err); |
| 293 |
} |
| 294 |
if (ares == DW_DLV_NO_ENTRY) { |
| 295 |
pc = 0; |
| 296 |
} |
| 297 |
|
| 298 |
if (is_actuals_table) { |
| 299 |
lires = dwarf_linelogical(line, &logicalno, lt_err); |
| 300 |
if (lires == DW_DLV_ERROR) { |
| 301 |
/* Do not terminate processing */ |
| 302 |
if (glflags.gf_do_check_dwarf && |
| 303 |
checking_this_compiler()) { |
| 304 |
where = "dwarf_linelogical()"; |
| 305 |
print_common_line_error(where,*lt_err); |
| 306 |
found_line_error = TRUE; |
| 307 |
} |
| 308 |
DROP_ERROR_INSTANCE(dbg,lires,*lt_err); |
| 309 |
} |
| 310 |
if (lires == DW_DLV_NO_ENTRY) { |
| 311 |
logicalno = 0; |
| 312 |
} |
| 313 |
column = 0; |
| 314 |
} else { |
| 315 |
lires = dwarf_lineno(line, &lineno, lt_err); |
| 316 |
if (lires == DW_DLV_ERROR) { |
| 317 |
/* Do not terminate processing */ |
| 318 |
where = "dwarf_lineno()"; |
| 319 |
print_common_line_error(where,*lt_err); |
| 320 |
found_line_error = TRUE; |
| 321 |
DROP_ERROR_INSTANCE(dbg,lires,*lt_err); |
| 322 |
} |
| 323 |
if (lires == DW_DLV_NO_ENTRY) { |
| 324 |
lineno = 0; |
| 325 |
} |
| 326 |
cores = dwarf_lineoff_b(line, &column, lt_err); |
| 327 |
if (cores == DW_DLV_ERROR) { |
| 328 |
/* Do not terminate processing */ |
| 329 |
if (glflags.gf_do_check_dwarf && |
| 330 |
checking_this_compiler()) { |
| 331 |
where = "dwarf_lineoff()"; |
| 332 |
print_common_line_error(where,*lt_err); |
| 333 |
found_line_error = TRUE; |
| 334 |
} |
| 335 |
DROP_ERROR_INSTANCE(dbg,cores,*lt_err); |
| 336 |
} |
| 337 |
if (cores == DW_DLV_NO_ENTRY) { |
| 338 |
/* Zero was always the correct default, meaning |
| 339 |
the left edge. DWARF2/3/4 spec sec 6.2.2 */ |
| 340 |
column = 0; |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
/* Process any possible error condition, though |
| 345 |
we won't be at the first such error. */ |
| 346 |
if ((glflags.gf_check_decl_file || |
| 347 |
glflags.gf_check_lines) && |
| 348 |
checking_this_compiler()) { |
| 349 |
DWARF_CHECK_COUNT(decl_file_result,1); |
| 350 |
if (found_line_error) { |
| 351 |
/* DWARF_CHECK already issued. */ |
| 352 |
#if 0 |
| 353 |
DWARF_CHECK_ERROR2(decl_file_result,where, |
| 354 |
dwarf_errmsg(lt_err); |
| 355 |
#endif |
| 356 |
|
| 357 |
} else if (glflags.gf_do_check_dwarf) { |
| 358 |
/* Check the address lies with a |
| 359 |
valid [lowPC:highPC] |
| 360 |
in the .text section*/ |
| 361 |
if (IsValidInBucketGroup(glflags.pRangesInfo,pc)) { |
| 362 |
/* Valid values; do nothing */ |
| 363 |
} else { |
| 364 |
/* At this point may be we are dealing with |
| 365 |
a linkonce symbol. The problem we have here |
| 366 |
is we have consumed the .debug_info section |
| 367 |
and we are dealing just with the records |
| 368 |
from the .debug_line, so no PU_name is |
| 369 |
available and no high_pc. |
| 370 |
Traverse the linkonce table if try to |
| 371 |
match the pc value with one of those ranges. |
| 372 |
*/ |
| 373 |
if (glflags.gf_check_lines && |
| 374 |
checking_this_compiler()) { |
| 375 |
DWARF_CHECK_COUNT(lines_result,1); |
| 376 |
} |
| 377 |
if (FindAddressInBucketGroup( |
| 378 |
glflags.pLinkonceInfo,pc)){ |
| 379 |
/* Valid values; do nothing */ |
| 380 |
} else { |
| 381 |
/* The SN Systems Linker generates |
| 382 |
line records |
| 383 |
with addr=0, when dealing with linkonce |
| 384 |
symbols and no stripping */ |
| 385 |
if (pc) { |
| 386 |
if (glflags.gf_check_lines && |
| 387 |
checking_this_compiler()) { |
| 388 |
char abuf[50]; |
| 389 |
struct esb_s atm; |
| 390 |
|
| 391 |
esb_constructor_fixed(&atm, |
| 392 |
abuf,sizeof(abuf)); |
| 393 |
esb_append_printf_s(&atm, |
| 394 |
"%s: Address", |
| 395 |
sanitized(sec_name)); |
| 396 |
esb_append_printf_u(&atm, |
| 397 |
" 0x%" DW_PR_XZEROS DW_PR_DUx |
| 398 |
" outside a valid .text range", |
| 399 |
pc); |
| 400 |
DWARF_CHECK_ERROR(lines_result, |
| 401 |
esb_get_string(&atm)); |
| 402 |
esb_destructor(&atm); |
| 403 |
} |
| 404 |
} else { |
| 405 |
SkipRecord = TRUE; |
| 406 |
} |
| 407 |
} |
| 408 |
} /* end not in bucket group */ |
| 409 |
/* Check the last record for the .debug_line, |
| 410 |
the one created by DW_LNE_end_sequence, |
| 411 |
is the same as the high_pc |
| 412 |
address for the last known user program |
| 413 |
unit (PU). |
| 414 |
There is no real reason */ |
| 415 |
if ((i + 1 == linecount) && |
| 416 |
glflags.seen_PU_high_address && |
| 417 |
!is_logicals_table) { |
| 418 |
check_last_line_of_table(pc, |
| 419 |
elf_max_address,sec_name); |
| 420 |
}/* end seen_PU_high_address */ |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
/* Display the error information */ |
| 425 |
if (found_line_error || glflags.gf_record_dwarf_error) { |
| 426 |
if (glflags.gf_check_verbose_mode && PRINTING_UNIQUE) { |
| 427 |
/* Print the record number for better |
| 428 |
error description */ |
| 429 |
printf("Record = %" DW_PR_DUu |
| 430 |
" Addr = 0x%" DW_PR_XZEROS DW_PR_DUx |
| 431 |
" [%4" DW_PR_DUu ",%2" DW_PR_DUu "] '%s'\n", |
| 432 |
i, pc,lineno,column, |
| 433 |
lsrc_filename?sanitized(lsrc_filename):""); |
| 434 |
/* The compilation unit was already printed */ |
| 435 |
if (!glflags.gf_check_decl_file) { |
| 436 |
PRINT_CU_INFO(); |
| 437 |
} |
| 438 |
} |
| 439 |
glflags.gf_record_dwarf_error = FALSE; |
| 440 |
/* Due to a fatal error, skip current record */ |
| 441 |
if (found_line_error) { |
| 442 |
dwarf_dealloc(dbg, lsrc_filename, DW_DLA_STRING); |
| 443 |
lsrc_filename = 0; |
| 444 |
continue; |
| 445 |
} |
| 446 |
} |
| 447 |
if (glflags.gf_do_print_dwarf) { |
| 448 |
if (is_logicals_table || is_actuals_table) { |
| 449 |
printf("[%4" DW_PR_DUu "] ", i + 1); |
| 450 |
} |
| 451 |
/* Check if print of <pc> address is needed. */ |
| 452 |
if (glflags.gf_line_print_pc) { |
| 453 |
printf("0x%" DW_PR_XZEROS DW_PR_DUx " ", pc); |
| 454 |
} |
| 455 |
if (is_actuals_table) { |
| 456 |
printf("[%7" DW_PR_DUu "]", logicalno); |
| 457 |
} else { |
| 458 |
printf("[%4" DW_PR_DUu ",%2" DW_PR_DUu "]", |
| 459 |
lineno, column); |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
if (!is_actuals_table) { |
| 464 |
nsres = dwarf_linebeginstatement(line, |
| 465 |
&newstatement, lt_err); |
| 466 |
if (nsres == DW_DLV_OK) { |
| 467 |
if (newstatement && glflags.gf_do_print_dwarf) { |
| 468 |
printf(" %s","NS"); |
| 469 |
} |
| 470 |
} else if (nsres == DW_DLV_ERROR) { |
| 471 |
struct esb_s m; |
| 472 |
esb_constructor(&m); |
| 473 |
esb_append_printf_u(&m, |
| 474 |
"\nERROR: dwarf_linebeginstatement failed" |
| 475 |
" on linebuf index %u ",i); |
| 476 |
esb_append_printf_u(&m, |
| 477 |
"of %u line records in the linebuf.", |
| 478 |
linecount); |
| 479 |
simple_err_return_action(nsres, |
| 480 |
esb_get_string(&m)); |
| 481 |
esb_destructor(&m); |
| 482 |
dwarf_dealloc(dbg, lsrc_filename, DW_DLA_STRING); |
| 483 |
lsrc_filename = 0; |
| 484 |
return nsres; |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
if (!is_logicals_table) { |
| 489 |
nsres = dwarf_lineblock(line, |
| 490 |
&new_basic_block, lt_err); |
| 491 |
if (nsres == DW_DLV_OK) { |
| 492 |
if (new_basic_block && glflags.gf_do_print_dwarf) { |
| 493 |
printf(" %s","BB"); |
| 494 |
} |
| 495 |
} else if (nsres == DW_DLV_ERROR) { |
| 496 |
struct esb_s m; |
| 497 |
esb_constructor(&m); |
| 498 |
esb_append_printf_u(&m, |
| 499 |
"\nERROR: dwarf_lineblock failed" |
| 500 |
" on linebuf index %u ",i); |
| 501 |
esb_append_printf_u(&m, |
| 502 |
"of %u line records in the linebuf.", |
| 503 |
linecount); |
| 504 |
simple_err_return_action(nsres, |
| 505 |
esb_get_string(&m)); |
| 506 |
esb_destructor(&m); |
| 507 |
dwarf_dealloc(dbg, lsrc_filename, DW_DLA_STRING); |
| 508 |
lsrc_filename = 0; |
| 509 |
return nsres; |
| 510 |
} |
| 511 |
nsres = dwarf_lineendsequence(line, |
| 512 |
&lineendsequence, lt_err); |
| 513 |
if (nsres == DW_DLV_OK) { |
| 514 |
if (lineendsequence && |
| 515 |
glflags.gf_do_print_dwarf) { |
| 516 |
printf(" %s", "ET"); |
| 517 |
} |
| 518 |
} else if (nsres == DW_DLV_ERROR) { |
| 519 |
struct esb_s m; |
| 520 |
esb_constructor(&m); |
| 521 |
esb_append_printf_u(&m, |
| 522 |
"\nERROR: dwarf_lineendsequence failed" |
| 523 |
" on linebuf index %u ",i); |
| 524 |
esb_append_printf_u(&m, |
| 525 |
"of %u line records in the linebuf.", |
| 526 |
linecount); |
| 527 |
simple_err_return_action(nsres, |
| 528 |
esb_get_string(&m)); |
| 529 |
esb_destructor(&m); |
| 530 |
dwarf_dealloc(dbg, lsrc_filename, DW_DLA_STRING); |
| 531 |
lsrc_filename = 0; |
| 532 |
return nsres; |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
if (glflags.gf_do_print_dwarf) { |
| 537 |
Dwarf_Bool prologue_end = 0; |
| 538 |
Dwarf_Bool epilogue_begin = 0; |
| 539 |
Dwarf_Unsigned isa = 0; |
| 540 |
Dwarf_Unsigned discriminator = 0; |
| 541 |
int disres = dwarf_prologue_end_etc(line, |
| 542 |
&prologue_end,&epilogue_begin, |
| 543 |
&isa,&discriminator,lt_err); |
| 544 |
if (disres == DW_DLV_ERROR) { |
| 545 |
struct esb_s m; |
| 546 |
esb_constructor(&m); |
| 547 |
esb_append_printf_u(&m, |
| 548 |
"\nERROR: dwarf_prologue_end_etc() failed" |
| 549 |
" on linebuf index %u ",i); |
| 550 |
esb_append_printf_u(&m, |
| 551 |
"of %u line records in the linebuf.", |
| 552 |
linecount); |
| 553 |
simple_err_return_action(nsres, |
| 554 |
esb_get_string(&m)); |
| 555 |
esb_destructor(&m); |
| 556 |
dwarf_dealloc(dbg, lsrc_filename, DW_DLA_STRING); |
| 557 |
lsrc_filename = 0; |
| 558 |
return disres; |
| 559 |
} |
| 560 |
if (prologue_end && !is_actuals_table) { |
| 561 |
printf(" PE"); |
| 562 |
} |
| 563 |
if (epilogue_begin && !is_actuals_table) { |
| 564 |
printf(" EB"); |
| 565 |
} |
| 566 |
if (isa && !is_logicals_table) { |
| 567 |
printf(" IS=0x%" DW_PR_DUx, isa); |
| 568 |
} |
| 569 |
if (discriminator && !is_actuals_table) { |
| 570 |
printf(" DI=0x%" DW_PR_DUx, discriminator); |
| 571 |
} |
| 572 |
if (is_logicals_table) { |
| 573 |
call_context = 0; |
| 574 |
disres = dwarf_linecontext(line, |
| 575 |
&call_context, lt_err); |
| 576 |
if (disres == DW_DLV_ERROR) { |
| 577 |
struct esb_s m; |
| 578 |
esb_constructor(&m); |
| 579 |
esb_append_printf_u(&m, |
| 580 |
"\nERROR: dwarf_linecontext() failed" |
| 581 |
" on linebuf index %u ",i); |
| 582 |
esb_append_printf_u(&m, |
| 583 |
"of %u line records in the linebuf.", |
| 584 |
linecount); |
| 585 |
simple_err_return_action(nsres, |
| 586 |
esb_get_string(&m)); |
| 587 |
esb_destructor(&m); |
| 588 |
dwarf_dealloc(dbg, lsrc_filename, DW_DLA_STRING); |
| 589 |
lsrc_filename = 0; |
| 590 |
return disres; |
| 591 |
} |
| 592 |
if (call_context) { |
| 593 |
printf(" CC=%" DW_PR_DUu, call_context); |
| 594 |
} |
| 595 |
{ |
| 596 |
Dwarf_Unsigned subprogno = 0; |
| 597 |
disres = dwarf_line_subprogno(line, |
| 598 |
&subprogno,0); |
| 599 |
if (disres == DW_DLV_OK) { |
| 600 |
/* The validity of subprogno |
| 601 |
is actually used&checked in |
| 602 |
dwarf_line_subprog() |
| 603 |
(called next) |
| 604 |
so we need not check it here. */ |
| 605 |
} else { |
| 606 |
printf("ERROR: dwarf_line_subprogno()" |
| 607 |
" impossibly! " |
| 608 |
"fails. with result %d\n",disres); |
| 609 |
glflags.gf_count_major_errors++; |
| 610 |
} |
| 611 |
} |
| 612 |
subprog_name = 0; |
| 613 |
disres = dwarf_line_subprog(line, |
| 614 |
&subprog_name, |
| 615 |
&subprog_filename, |
| 616 |
&subprog_line, lt_err); |
| 617 |
if (disres == DW_DLV_ERROR) { |
| 618 |
struct esb_s m; |
| 619 |
esb_constructor(&m); |
| 620 |
esb_append_printf_u(&m, |
| 621 |
"\nERROR: dwarf_line_subprog() failed" |
| 622 |
" on linebuf index %u ",i); |
| 623 |
esb_append_printf_u(&m, |
| 624 |
"of %u line records in the linebuf.", |
| 625 |
linecount); |
| 626 |
simple_err_return_action(nsres, |
| 627 |
esb_get_string(&m)); |
| 628 |
esb_destructor(&m); |
| 629 |
dwarf_dealloc(dbg, lsrc_filename, DW_DLA_STRING); |
| 630 |
lsrc_filename = 0; |
| 631 |
return disres; |
| 632 |
} |
| 633 |
if (subprog_name && strlen(subprog_name)) { |
| 634 |
/* We do not print an empty name. |
| 635 |
Clutters things up. */ |
| 636 |
printf(" SB=\"%s\"", sanitized(subprog_name)); |
| 637 |
} |
| 638 |
dwarf_dealloc(dbg,subprog_filename, DW_DLA_STRING); |
| 639 |
subprog_filename = 0; |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
if (!is_actuals_table) { |
| 644 |
if (i == 0 || glflags.verbose > 2 || |
| 645 |
strcmp(lsrc_filename?lsrc_filename:"", |
| 646 |
esb_get_string(&lastsrc))) { |
| 647 |
struct esb_s urs; |
| 648 |
char atmp2[ESB_FIXED_ALLOC_SIZE]; |
| 649 |
|
| 650 |
esb_constructor_fixed(&urs,atmp2,sizeof(atmp2)); |
| 651 |
esb_append(&urs, " uri: \""); |
| 652 |
translate_to_uri(lsrc_filename? |
| 653 |
lsrc_filename:"", |
| 654 |
&urs); |
| 655 |
esb_append(&urs,"\""); |
| 656 |
if (glflags.gf_do_print_dwarf) { |
| 657 |
printf("%s",esb_get_string(&urs)); |
| 658 |
} |
| 659 |
esb_destructor(&urs); |
| 660 |
esb_empty_string(&lastsrc); |
| 661 |
esb_append(&lastsrc, |
| 662 |
lsrc_filename?lsrc_filename:""); |
| 663 |
} else { |
| 664 |
/* Do not print name, it is the same |
| 665 |
as the last name printed. */ |
| 666 |
} |
| 667 |
} |
| 668 |
if (glflags.gf_do_print_dwarf) { |
| 669 |
printf("\n"); |
| 670 |
} |
| 671 |
dwarf_dealloc(dbg,lsrc_filename, DW_DLA_STRING); |
| 672 |
lsrc_filename = 0; |
| 673 |
} |
| 674 |
esb_destructor(&lastsrc); |
| 675 |
return DW_DLV_OK; |
| 676 |
} |
| 677 |
|
| 678 |
/* Here we test the interfaces into Dwarf_Line_Context. */ |
| 679 |
static int |
| 680 |
print_line_context_record(Dwarf_Line_Context line_context, |
| 681 |
Dwarf_Error *err) |
| 682 |
{ |
| 683 |
int vres = 0; |
| 684 |
Dwarf_Unsigned lsecoff = 0; |
| 685 |
Dwarf_Unsigned version = 0; |
| 686 |
Dwarf_Signed dir_count = 0; |
| 687 |
Dwarf_Signed baseindex = 0; |
| 688 |
Dwarf_Signed file_count = 0; |
| 689 |
Dwarf_Signed endindex = 0; |
| 690 |
Dwarf_Signed i = 0; |
| 691 |
Dwarf_Signed subprog_count = 0; |
| 692 |
const char *name = 0; |
| 693 |
Dwarf_Small table_count = 0; |
| 694 |
struct esb_s bufr; |
| 695 |
Dwarf_Signed include_dir_base = 1; /* DWARF2.3,4 */ |
| 696 |
Dwarf_Signed include_dir_limit = 0; /* set below */ |
| 697 |
char bufr_tmp[ESB_FIXED_ALLOC_SIZE]; |
| 698 |
|
| 699 |
esb_constructor_fixed(&bufr,bufr_tmp,sizeof(bufr_tmp)); |
| 700 |
printf("Line Context data\n"); |
| 701 |
vres = dwarf_srclines_table_offset(line_context,&lsecoff, |
| 702 |
err); |
| 703 |
if (vres != DW_DLV_OK) { |
| 704 |
simple_err_return_action(vres, |
| 705 |
"\nERROR: dwarf_srclines_table_offset() failed" |
| 706 |
". Something broken"); |
| 707 |
return vres; |
| 708 |
} |
| 709 |
printf(" Line Section Offset 0x%" |
| 710 |
DW_PR_XZEROS DW_PR_DUx "\n", lsecoff); |
| 711 |
vres = dwarf_srclines_version(line_context,&version, |
| 712 |
&table_count, err); |
| 713 |
if (vres != DW_DLV_OK) { |
| 714 |
simple_err_return_action(vres, |
| 715 |
"\nERROR: dwarf_srclines_version() failed" |
| 716 |
". Something broken"); |
| 717 |
return vres; |
| 718 |
} |
| 719 |
printf(" version number 0x%" DW_PR_DUx |
| 720 |
" %" DW_PR_DUu "\n", |
| 721 |
version,version); |
| 722 |
printf(" number of line tables %d.\n", table_count); |
| 723 |
vres = dwarf_srclines_comp_dir(line_context,&name,err); |
| 724 |
if (vres != DW_DLV_OK) { |
| 725 |
simple_err_return_action(vres, |
| 726 |
"\nERROR: dwarf_srclines_comp_dir() failed" |
| 727 |
". Something broken"); |
| 728 |
return vres; |
| 729 |
} |
| 730 |
if (name) { |
| 731 |
printf(" Compilation directory: %s\n",name); |
| 732 |
} else { |
| 733 |
printf(" Compilation directory: <unknown" |
| 734 |
" no DW_AT_comp_dir>\n"); |
| 735 |
} |
| 736 |
|
| 737 |
vres = dwarf_srclines_include_dir_count(line_context, |
| 738 |
&dir_count,err); |
| 739 |
if (vres != DW_DLV_OK) { |
| 740 |
simple_err_return_action(vres, |
| 741 |
"\nERROR: dwarf_srclines_comp_dir() failed" |
| 742 |
". Something broken"); |
| 743 |
return vres; |
| 744 |
} |
| 745 |
printf(" include directory count 0x%" |
| 746 |
DW_PR_DUx " %" DW_PR_DSd "\n", |
| 747 |
(Dwarf_Unsigned)dir_count,dir_count); |
| 748 |
if (version == DW_LINE_VERSION5) { |
| 749 |
include_dir_base = 0; |
| 750 |
include_dir_limit = dir_count; |
| 751 |
} else { |
| 752 |
include_dir_base = 1; |
| 753 |
include_dir_limit = dir_count+1; |
| 754 |
} |
| 755 |
for (i = include_dir_base; i < include_dir_limit; ++i) { |
| 756 |
vres = dwarf_srclines_include_dir_data(line_context,i, |
| 757 |
&name,err); |
| 758 |
if (vres != DW_DLV_OK) { |
| 759 |
struct esb_s m; |
| 760 |
|
| 761 |
esb_constructor(&m); |
| 762 |
esb_append_printf_i(&m, |
| 763 |
"\nERROR: Error accessing include directory " |
| 764 |
" %d ",i); |
| 765 |
esb_append_printf_i(&m, |
| 766 |
"(max allowed index is %d).",dir_count); |
| 767 |
simple_err_return_action(vres, |
| 768 |
esb_get_string(&m)); |
| 769 |
esb_destructor(&m); |
| 770 |
return vres; |
| 771 |
} |
| 772 |
printf(" [%2" DW_PR_DSd "] \"%s\"\n",i,name); |
| 773 |
} |
| 774 |
|
| 775 |
vres = dwarf_srclines_files_indexes(line_context, |
| 776 |
&baseindex,&file_count,&endindex,err); |
| 777 |
if (vres != DW_DLV_OK) { |
| 778 |
simple_err_return_action(vres, |
| 779 |
"\nERROR: Error accessing files indexes"); |
| 780 |
return vres; |
| 781 |
} |
| 782 |
printf( " files count 0x%" |
| 783 |
DW_PR_DUx " %" DW_PR_DUu "\n", |
| 784 |
file_count,file_count); |
| 785 |
/* Set up so just one loop control needed |
| 786 |
for all versions of line tables. */ |
| 787 |
for (i = baseindex; i < endindex; ++i) { |
| 788 |
Dwarf_Unsigned dirindex = 0; |
| 789 |
Dwarf_Unsigned modtime = 0; |
| 790 |
Dwarf_Unsigned flength = 0; |
| 791 |
Dwarf_Form_Data16 *md5data = 0; |
| 792 |
|
| 793 |
vres = dwarf_srclines_files_data_b(line_context,i, |
| 794 |
&name,&dirindex, &modtime,&flength, |
| 795 |
&md5data,err); |
| 796 |
if (vres != DW_DLV_OK) { |
| 797 |
struct esb_s m; |
| 798 |
|
| 799 |
esb_constructor(&m); |
| 800 |
esb_append_printf_i(&m, |
| 801 |
"\nERROR: Error accessing line_context " |
| 802 |
" calling dwarf_srclines_files_data_b() " |
| 803 |
"with index %d ",i); |
| 804 |
esb_append_printf_i(&m, |
| 805 |
"(end index is %d).",endindex); |
| 806 |
simple_err_return_action(vres, |
| 807 |
esb_get_string(&m)); |
| 808 |
esb_destructor(&m); |
| 809 |
return vres; |
| 810 |
} |
| 811 |
esb_empty_string(&bufr); |
| 812 |
if (name) { |
| 813 |
esb_empty_string(&bufr); |
| 814 |
esb_append(&bufr,"\""); |
| 815 |
esb_append(&bufr,name); |
| 816 |
esb_append(&bufr,"\""); |
| 817 |
} else { |
| 818 |
esb_append(&bufr,"<ERROR:NULL name in files list>"); |
| 819 |
} |
| 820 |
printf(" [%2" DW_PR_DSd "] %-24s ,", |
| 821 |
i,esb_get_string(&bufr)); |
| 822 |
printf(" directory index %2" DW_PR_DUu ,dirindex); |
| 823 |
printf(", file length %2" DW_PR_DUu ,flength); |
| 824 |
if (md5data) { |
| 825 |
char *c = (char *)md5data; |
| 826 |
char *end = c+sizeof(*md5data); |
| 827 |
printf(", file md5 value 0x"); |
| 828 |
while(c < end) { |
| 829 |
printf("%02x",0xff&*c); |
| 830 |
++c; |
| 831 |
} |
| 832 |
printf(" "); |
| 833 |
} |
| 834 |
if (modtime) { |
| 835 |
time_t tt3 = (time_t)modtime; |
| 836 |
|
| 837 |
/* ctime supplies newline */ |
| 838 |
printf( "file mod time 0x%lx %s", (unsigned long)tt3, |
| 839 |
ctime(&tt3)); |
| 840 |
} else { |
| 841 |
printf(" file mod time 0\n"); |
| 842 |
} |
| 843 |
} |
| 844 |
esb_destructor(&bufr); |
| 845 |
|
| 846 |
vres = dwarf_srclines_subprog_count(line_context,&subprog_count, |
| 847 |
err); |
| 848 |
if (vres != DW_DLV_OK) { |
| 849 |
simple_err_return_msg_either_action(vres, |
| 850 |
"ERROR: dwarf_srclines_subprog_count() on a " |
| 851 |
"line_context fails"); |
| 852 |
return vres; |
| 853 |
} |
| 854 |
if (subprog_count == 0) { |
| 855 |
return DW_DLV_OK; |
| 856 |
} |
| 857 |
/* The following is for the experimental table |
| 858 |
which is only DWARF4 so far, so no need for |
| 859 |
a dwarf_srclines_subprog_indexes() function. Yet. */ |
| 860 |
printf(" subprograms count (experimental) 0x%" |
| 861 |
DW_PR_DUx " %" DW_PR_DUu "\n", |
| 862 |
subprog_count,subprog_count); |
| 863 |
for (i = 1; i <= subprog_count; ++i) { |
| 864 |
Dwarf_Unsigned decl_file = 0; |
| 865 |
Dwarf_Unsigned decl_line = 0; |
| 866 |
vres = dwarf_srclines_subprog_data(line_context,i, |
| 867 |
&name,&decl_file, &decl_line,err); |
| 868 |
if (vres != DW_DLV_OK) { |
| 869 |
struct esb_s m; |
| 870 |
|
| 871 |
esb_constructor(&m); |
| 872 |
esb_append_printf_i(&m, |
| 873 |
"\nERROR: Error accessing line_context " |
| 874 |
" calling dwarf_srclines_subprog_data() " |
| 875 |
"with index %d ",i); |
| 876 |
esb_append_printf_i(&m, |
| 877 |
"(end index is %d).",subprog_count); |
| 878 |
simple_err_return_action(vres, |
| 879 |
esb_get_string(&m)); |
| 880 |
esb_destructor(&m); |
| 881 |
return vres; |
| 882 |
} |
| 883 |
printf(" [%2" DW_PR_DSd "] \"%s\"" |
| 884 |
", fileindex %2" DW_PR_DUu |
| 885 |
", lineindex %2" DW_PR_DUu |
| 886 |
"\n", |
| 887 |
i,name,decl_file,decl_line); |
| 888 |
} |
| 889 |
return DW_DLV_OK; |
| 890 |
} |
| 891 |
|
| 892 |
int |
| 893 |
print_line_numbers_this_cu(Dwarf_Debug dbg, Dwarf_Die cu_die, |
| 894 |
char **srcfiles, |
| 895 |
Dwarf_Signed srcf_count, |
| 896 |
Dwarf_Error *err) |
| 897 |
{ |
| 898 |
Dwarf_Unsigned lineversion = 0; |
| 899 |
Dwarf_Signed linecount = 0; |
| 900 |
Dwarf_Line *linebuf = NULL; |
| 901 |
Dwarf_Signed linecount_actuals = 0; |
| 902 |
Dwarf_Line *linebuf_actuals = NULL; |
| 903 |
Dwarf_Small table_count = 0; |
| 904 |
int lres = 0; |
| 905 |
int line_errs = 0; |
| 906 |
Dwarf_Line_Context line_context = 0; |
| 907 |
const char *sec_name = 0; |
| 908 |
Dwarf_Off cudie_local_offset = 0; |
| 909 |
Dwarf_Off dieprint_cu_goffset = 0; |
| 910 |
int atres = 0; |
| 911 |
|
| 912 |
glflags.current_section_id = DEBUG_LINE; |
| 913 |
|
| 914 |
/* line_flag is TRUE */ |
| 915 |
|
| 916 |
lres = dwarf_get_line_section_name_from_die(cu_die, |
| 917 |
&sec_name,err); |
| 918 |
if (lres != DW_DLV_OK || !sec_name || !strlen(sec_name)) { |
| 919 |
sec_name = ".debug_line"; |
| 920 |
} |
| 921 |
DROP_ERROR_INSTANCE(dbg,lres,*err); |
| 922 |
|
| 923 |
/* The offsets will be zero if it fails. Let it pass. */ |
| 924 |
atres = dwarf_die_offsets(cu_die,&dieprint_cu_goffset, |
| 925 |
&cudie_local_offset,err); |
| 926 |
DROP_ERROR_INSTANCE(dbg,atres,*err); |
| 927 |
|
| 928 |
if (glflags.gf_do_print_dwarf) { |
| 929 |
struct esb_s truename; |
| 930 |
char buf[ESB_FIXED_ALLOC_SIZE]; |
| 931 |
|
| 932 |
esb_constructor_fixed(&truename,buf,sizeof(buf)); |
| 933 |
get_true_section_name(dbg,".debug_line", |
| 934 |
&truename,FALSE); /* Ignore the COMPRESSED flags */ |
| 935 |
printf("\n%s: line number info for a single cu\n", |
| 936 |
sanitized(esb_get_string(&truename))); |
| 937 |
esb_destructor(&truename); |
| 938 |
} else { |
| 939 |
/* We are checking, not printing. */ |
| 940 |
Dwarf_Half tag = 0; |
| 941 |
int tres = dwarf_tag(cu_die, &tag, err); |
| 942 |
if (tres != DW_DLV_OK) { |
| 943 |
/* Something broken here. */ |
| 944 |
struct esb_s m; |
| 945 |
esb_constructor(&m); |
| 946 |
esb_append(&m, |
| 947 |
"\nERROR: Unable to get CU DIE dwarf tag " |
| 948 |
"attempting to print line numbers for a CU "); |
| 949 |
if (tres == DW_DLV_ERROR) { |
| 950 |
esb_append(&m,dwarf_errmsg(*err)); |
| 951 |
} |
| 952 |
simple_err_return_msg_either_action(tres, |
| 953 |
esb_get_string(&m)); |
| 954 |
esb_destructor(&m); |
| 955 |
return tres; |
| 956 |
} else if (tag == DW_TAG_type_unit) { |
| 957 |
/* Not checking since type units missing |
| 958 |
address or range in CU header. */ |
| 959 |
return DW_DLV_NO_ENTRY; |
| 960 |
} |
| 961 |
} |
| 962 |
|
| 963 |
if (glflags.verbose > 1) { |
| 964 |
int errcount = 0; |
| 965 |
Dwarf_Bool attr_dup = FALSE; |
| 966 |
int lresv = 0; |
| 967 |
print_source_intro(dbg,cu_die); |
| 968 |
lresv = print_one_die(dbg, cu_die, |
| 969 |
dieprint_cu_goffset, |
| 970 |
/* print_information= */ 1, |
| 971 |
/* indent level */0, |
| 972 |
srcfiles,srcf_count, |
| 973 |
&attr_dup, |
| 974 |
/* ignore_die_stack= */TRUE, |
| 975 |
err); |
| 976 |
if (lresv == DW_DLV_ERROR) { |
| 977 |
return lresv; |
| 978 |
} |
| 979 |
DWARF_CHECK_COUNT(lines_result,1); |
| 980 |
lresv = dwarf_print_lines(cu_die, err,&errcount); |
| 981 |
if (errcount > 0) { |
| 982 |
DWARF_ERROR_COUNT(lines_result,errcount); |
| 983 |
DWARF_CHECK_COUNT(lines_result,(errcount-1)); |
| 984 |
} |
| 985 |
if (lresv == DW_DLV_ERROR) { |
| 986 |
print_error_and_continue("Failed to print CU lines", |
| 987 |
lresv, *err); |
| 988 |
} |
| 989 |
return lresv; |
| 990 |
} |
| 991 |
|
| 992 |
if (glflags.gf_check_lines && checking_this_compiler()) { |
| 993 |
int lres2 = 0; |
| 994 |
|
| 995 |
DWARF_CHECK_COUNT(lines_result,1); |
| 996 |
lres2 = dwarf_check_lineheader_b(cu_die,&line_errs, |
| 997 |
err); |
| 998 |
if (lres2 == DW_DLV_ERROR) { |
| 999 |
print_error_and_continue( |
| 1000 |
"dwarf_check_lineheader_b found a serious error", |
| 1001 |
lres2, *err); |
| 1002 |
dwarf_dealloc(dbg,*err,DW_DLA_ERROR); |
| 1003 |
*err = 0; |
| 1004 |
} |
| 1005 |
if (line_errs > 0) { |
| 1006 |
/* does glflags.check_error++; */ |
| 1007 |
/* sets glflags.gf_record_dwarf_error = TRUE; */ |
| 1008 |
DWARF_CHECK_ERROR_PRINT_CU(); |
| 1009 |
DWARF_ERROR_COUNT(lines_result,line_errs); |
| 1010 |
DWARF_CHECK_COUNT(lines_result,(line_errs-1)); |
| 1011 |
} |
| 1012 |
} |
| 1013 |
/* The following is complicated by a desire to test |
| 1014 |
various line table interface functions. Hence |
| 1015 |
we test line_flag_selection. |
| 1016 |
|
| 1017 |
Normal code should pick an interface |
| 1018 |
(for most the best choice is what we here call |
| 1019 |
glflags.gf_line_flag_selection == singledw5) |
| 1020 |
and use just that interface set. |
| 1021 |
|
| 1022 |
Sorry about the length of the code that |
| 1023 |
results from having so many interfaces. */ |
| 1024 |
if (glflags.gf_line_flag_selection == singledw5) { |
| 1025 |
lres = dwarf_srclines_b(cu_die,&lineversion, |
| 1026 |
&table_count,&line_context, |
| 1027 |
err); |
| 1028 |
if (lres == DW_DLV_OK) { |
| 1029 |
lres = dwarf_srclines_from_linecontext(line_context, |
| 1030 |
&linebuf, &linecount,err); |
| 1031 |
} |
| 1032 |
} else { |
| 1033 |
lres = dwarf_srclines_b(cu_die,&lineversion, |
| 1034 |
&table_count,&line_context, |
| 1035 |
err); |
| 1036 |
if (lres == DW_DLV_OK) { |
| 1037 |
lres = dwarf_srclines_two_level_from_linecontext( |
| 1038 |
line_context, |
| 1039 |
&linebuf, &linecount, |
| 1040 |
&linebuf_actuals, &linecount_actuals, |
| 1041 |
err); |
| 1042 |
} |
| 1043 |
} |
| 1044 |
if (lres == DW_DLV_ERROR) { |
| 1045 |
/* Do not terminate processing */ |
| 1046 |
if (glflags.gf_check_decl_file || |
| 1047 |
glflags.gf_check_lines) { |
| 1048 |
DWARF_CHECK_COUNT(decl_file_result,1); |
| 1049 |
DWARF_CHECK_ERROR2(decl_file_result,"dwarf_srclines", |
| 1050 |
dwarf_errmsg(*err)); |
| 1051 |
/* Clear error condition */ |
| 1052 |
glflags.gf_record_dwarf_error = FALSE; |
| 1053 |
} else { |
| 1054 |
print_error_and_continue("dwarf_srclines", |
| 1055 |
lres, *err); |
| 1056 |
} |
| 1057 |
DROP_ERROR_INSTANCE(dbg,lres,*err); |
| 1058 |
return DW_DLV_OK; |
| 1059 |
} else if (lres == DW_DLV_NO_ENTRY) { |
| 1060 |
/* no line information is included */ |
| 1061 |
} else if (table_count > 0) { |
| 1062 |
/* lres DW_DLV_OK */ |
| 1063 |
if (glflags.gf_do_print_dwarf) { |
| 1064 |
if (line_context && glflags.verbose) { |
| 1065 |
lres = print_line_context_record(line_context,err); |
| 1066 |
if (lres != DW_DLV_OK){ |
| 1067 |
/* Should we issue message |
| 1068 |
about this call? */ |
| 1069 |
dwarf_srclines_dealloc_b(line_context); |
| 1070 |
return lres; |
| 1071 |
} |
| 1072 |
} |
| 1073 |
print_source_intro(dbg,cu_die); |
| 1074 |
if (glflags.verbose) { |
| 1075 |
int dres = 0; |
| 1076 |
Dwarf_Bool attr_dup = FALSE; |
| 1077 |
/* FIXME */ |
| 1078 |
dres = print_one_die(dbg, cu_die, |
| 1079 |
dieprint_cu_goffset, |
| 1080 |
/* print_information= */ TRUE, |
| 1081 |
/* indent_level= */ 0, |
| 1082 |
/* srcfiles= */ 0, /* cnt= */ 0, |
| 1083 |
|
| 1084 |
&attr_dup, |
| 1085 |
/* ignore_die_stack= */TRUE,err); |
| 1086 |
if (dres == DW_DLV_ERROR) { |
| 1087 |
dwarf_srclines_dealloc_b(line_context); |
| 1088 |
return dres; |
| 1089 |
} |
| 1090 |
} |
| 1091 |
} |
| 1092 |
if (glflags.gf_line_flag_selection == singledw5 || |
| 1093 |
glflags.gf_line_flag_selection == s2l) { |
| 1094 |
/* This now *all* cases possible when |
| 1095 |
the table_count > 0. */ |
| 1096 |
int ltres = 0; |
| 1097 |
|
| 1098 |
if (table_count == 0 || table_count == 1) { |
| 1099 |
/* ASSERT: is_single_table == true */ |
| 1100 |
Dwarf_Bool is_logicals = FALSE; |
| 1101 |
Dwarf_Bool is_actuals = FALSE; |
| 1102 |
|
| 1103 |
ltres = process_line_table(dbg,sec_name, |
| 1104 |
linebuf, linecount, |
| 1105 |
is_logicals,is_actuals,err); |
| 1106 |
if (ltres == DW_DLV_ERROR) { |
| 1107 |
/* what if NO_ENTRY? */ |
| 1108 |
dwarf_srclines_dealloc_b(line_context); |
| 1109 |
return ltres; |
| 1110 |
} |
| 1111 |
} else { |
| 1112 |
Dwarf_Bool is_logicals = TRUE; |
| 1113 |
Dwarf_Bool is_actuals = FALSE; |
| 1114 |
|
| 1115 |
ltres = process_line_table(dbg,sec_name, |
| 1116 |
linebuf, linecount, |
| 1117 |
is_logicals, is_actuals,err); |
| 1118 |
if (ltres != DW_DLV_OK) { |
| 1119 |
dwarf_srclines_dealloc_b(line_context); |
| 1120 |
return ltres; |
| 1121 |
} |
| 1122 |
ltres = process_line_table(dbg,sec_name, |
| 1123 |
linebuf_actuals, |
| 1124 |
linecount_actuals, |
| 1125 |
!is_logicals, !is_actuals,err); |
| 1126 |
if (ltres != DW_DLV_OK) { |
| 1127 |
dwarf_srclines_dealloc_b(line_context); |
| 1128 |
return ltres; |
| 1129 |
} |
| 1130 |
} |
| 1131 |
dwarf_srclines_dealloc_b(line_context); |
| 1132 |
line_context = 0; |
| 1133 |
linebuf = 0; |
| 1134 |
} |
| 1135 |
/* end, table_count > 0 */ |
| 1136 |
} else { /* table_count == 0 */ |
| 1137 |
/* lres DW_DLV_OK */ |
| 1138 |
/* table_count == 0. no lines in table. |
| 1139 |
Just a line table header. */ |
| 1140 |
if (glflags.gf_do_print_dwarf) { |
| 1141 |
int ores = 0; |
| 1142 |
Dwarf_Unsigned off = 0; |
| 1143 |
|
| 1144 |
print_source_intro(dbg,cu_die); |
| 1145 |
if (glflags.verbose) { |
| 1146 |
int dpres = 0; |
| 1147 |
Dwarf_Bool attr_dup = FALSE; |
| 1148 |
|
| 1149 |
/* FIXME */ |
| 1150 |
dpres = print_one_die(dbg, cu_die, |
| 1151 |
dieprint_cu_goffset, |
| 1152 |
/* print_information= */ TRUE, |
| 1153 |
/* indent_level= */ 0, |
| 1154 |
/* srcfiles= */ 0, /* cnt= */ 0, |
| 1155 |
&attr_dup, |
| 1156 |
/* ignore_die_stack= */TRUE, |
| 1157 |
err); |
| 1158 |
if (dpres == DW_DLV_ERROR) { |
| 1159 |
dwarf_srclines_dealloc_b(line_context); |
| 1160 |
return dpres; |
| 1161 |
} |
| 1162 |
} |
| 1163 |
if (line_context) { |
| 1164 |
if (glflags.verbose > 2) { |
| 1165 |
ores = print_line_context_record( |
| 1166 |
line_context,err); |
| 1167 |
if (ores != DW_DLV_OK) { |
| 1168 |
simple_err_return_msg_either_action( |
| 1169 |
ores, |
| 1170 |
"ERROR: line context record " |
| 1171 |
" where table count is 0 has a" |
| 1172 |
" problem"); |
| 1173 |
dwarf_srclines_dealloc_b(line_context); |
| 1174 |
return ores; |
| 1175 |
} |
| 1176 |
} |
| 1177 |
ores = dwarf_srclines_table_offset( |
| 1178 |
line_context, |
| 1179 |
&off,err); |
| 1180 |
if (ores != DW_DLV_OK) { |
| 1181 |
simple_err_return_msg_either_action( |
| 1182 |
ores, |
| 1183 |
"ERROR: line context table_offset " |
| 1184 |
" where table count is 0 has a" |
| 1185 |
" problem"); |
| 1186 |
dwarf_srclines_dealloc_b(line_context); |
| 1187 |
return ores; |
| 1188 |
} else { |
| 1189 |
printf(" Line table is present (offset 0x%" |
| 1190 |
DW_PR_XZEROS DW_PR_DUx |
| 1191 |
") but no lines present\n", off); |
| 1192 |
} |
| 1193 |
} else { |
| 1194 |
printf(" Line table is present but" |
| 1195 |
" no lines present\n"); |
| 1196 |
} |
| 1197 |
} |
| 1198 |
if (glflags.gf_line_flag_selection == singledw5 || |
| 1199 |
glflags.gf_line_flag_selection == s2l) { |
| 1200 |
/* Now this is all cases... |
| 1201 |
also deletes the linebuf... */ |
| 1202 |
dwarf_srclines_dealloc_b(line_context); |
| 1203 |
line_context = 0; |
| 1204 |
linebuf = 0; |
| 1205 |
} |
| 1206 |
/* end, linecounttotal == 0 */ |
| 1207 |
} |
| 1208 |
if (line_context) { |
| 1209 |
/* also deletes the linebuf... */ |
| 1210 |
dwarf_srclines_dealloc_b(line_context); |
| 1211 |
line_context = 0; |
| 1212 |
linebuf = 0; |
| 1213 |
} |
| 1214 |
return DW_DLV_OK; |
| 1215 |
} |