| 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-2011 SN Systems Ltd. All rights reserved. |
| 5 |
Portions Copyright 2008-2020 David Anderson. All rights reserved. |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or |
| 8 |
modify it under the terms of version 2 of the GNU General |
| 9 |
Public License as published by the Free Software Foundation. |
| 10 |
|
| 11 |
This program is distributed in the hope that it would be |
| 12 |
useful, but WITHOUT ANY WARRANTY; without even the implied |
| 13 |
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
PURPOSE. |
| 15 |
|
| 16 |
Further, this software is distributed without any warranty |
| 17 |
that it is free of the rightful claim of any third person |
| 18 |
regarding infringement or the like. Any license provided |
| 19 |
herein, whether implied or otherwise, applies only to this |
| 20 |
software file. Patent licenses, if any, provided herein |
| 21 |
do not apply to combinations of this program with other |
| 22 |
software, or any other product whatsoever. |
| 23 |
|
| 24 |
You should have received a copy of the GNU General Public |
| 25 |
License along with this program; if not, write the Free |
| 26 |
Software Foundation, Inc., 51 Franklin Street - Fifth Floor, |
| 27 |
Boston MA 02110-1301, USA. |
| 28 |
|
| 29 |
*/ |
| 30 |
|
| 31 |
#include <config.h> |
| 32 |
|
| 33 |
#include <string.h> /* strlen() */ |
| 34 |
#include <stdio.h> /* FILE decl for dd_esb.h, printf etc */ |
| 35 |
|
| 36 |
#include "dwarf.h" |
| 37 |
#include "libdwarf.h" |
| 38 |
#include "libdwarf_private.h" |
| 39 |
#include "dd_defined_types.h" |
| 40 |
#include "dd_checkutil.h" |
| 41 |
#include "dd_glflags.h" |
| 42 |
#include "dd_globals.h" |
| 43 |
#include "dd_naming.h" |
| 44 |
#include "dd_esb.h" |
| 45 |
#include "dd_esb_using_functions.h" |
| 46 |
#include "print_sections.h" |
| 47 |
#include "dd_sanitized.h" |
| 48 |
|
| 49 |
static int |
| 50 |
print_all_pubnames_style_records(Dwarf_Debug dbg, |
| 51 |
const char *linetitle, |
| 52 |
const char * section_true_name, |
| 53 |
Dwarf_Global *globbuf, |
| 54 |
Dwarf_Signed count, |
| 55 |
Dwarf_Error *err); |
| 56 |
|
| 57 |
/* This unifies the code for some error checks to |
| 58 |
avoid code duplication. |
| 59 |
*/ |
| 60 |
static void |
| 61 |
check_info_offset_sanity( |
| 62 |
const char *sec, |
| 63 |
const char *field, |
| 64 |
char *global, |
| 65 |
Dwarf_Unsigned offset, Dwarf_Unsigned maxoff) |
| 66 |
{ |
| 67 |
if (maxoff == 0) { |
| 68 |
/* Lets make a heuristic check. */ |
| 69 |
if (offset > 0xffffffff) { |
| 70 |
printf("Warning: section %s %s %s offset 0x%" |
| 71 |
DW_PR_XZEROS DW_PR_DUx " " |
| 72 |
"exceptionally large \n", |
| 73 |
sec, field, global, offset); |
| 74 |
} |
| 75 |
return; |
| 76 |
} |
| 77 |
if (offset >= maxoff) { |
| 78 |
printf("Warning: section %s %s %s offset 0x%" |
| 79 |
DW_PR_XZEROS DW_PR_DUx " " |
| 80 |
"larger than max of 0x%" DW_PR_DUx "\n", |
| 81 |
sec, field, global, offset, maxoff); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
/* Unified pubnames style output. |
| 86 |
The error checking here against maxoff may be useless |
| 87 |
(in that libdwarf may return an error if the offset is bad |
| 88 |
and we will not get called here). |
| 89 |
But we leave it in nonetheless as it looks sensible. |
| 90 |
In at least one gigantic executable such offsets turned out wrong. |
| 91 |
*/ |
| 92 |
static int |
| 93 |
print_pubname_style_entry(Dwarf_Debug dbg, |
| 94 |
Dwarf_Signed globi, |
| 95 |
Dwarf_Signed globcount, |
| 96 |
const char *line_title, |
| 97 |
char *name, |
| 98 |
Dwarf_Half dietag, |
| 99 |
Dwarf_Unsigned global_die_off, |
| 100 |
Dwarf_Unsigned cu_die_off, |
| 101 |
Dwarf_Unsigned global_cuh_offset, |
| 102 |
Dwarf_Unsigned maxoff,Dwarf_Error *err) |
| 103 |
{ |
| 104 |
Dwarf_Die die = NULL; |
| 105 |
Dwarf_Off die_CU_off = 0; |
| 106 |
int dres = 0; |
| 107 |
int ddres = 0; |
| 108 |
int cudres = 0; |
| 109 |
Dwarf_Bool is_info = TRUE; |
| 110 |
Dwarf_Unsigned cu_local_die_offset = 0; |
| 111 |
|
| 112 |
if (global_die_off >= global_cuh_offset) { |
| 113 |
/* ASSERT: Always true. */ |
| 114 |
cu_local_die_offset = global_die_off - global_cuh_offset; |
| 115 |
} |
| 116 |
/* get die at global_die_off, a check |
| 117 |
on offset correctness. For this old section |
| 118 |
in DWARF only .debug_info could be appropriate, |
| 119 |
never .debug_types. Hence is_info = TRUE */ |
| 120 |
dres = dwarf_offdie_b(dbg, global_die_off, is_info, &die, err); |
| 121 |
/* Some llvm version puts the global die offset into |
| 122 |
pubnames with the result that |
| 123 |
we will get an error here but we just |
| 124 |
let that create an error, |
| 125 |
papering it over here by subtracting out |
| 126 |
the applicable debug_info CU header offset |
| 127 |
is problematic. */ |
| 128 |
if (dres != DW_DLV_OK) { |
| 129 |
struct esb_s details; |
| 130 |
esb_constructor(&details); |
| 131 |
esb_append(&details,line_title); |
| 132 |
esb_append(&details," dwarf_offdie_b : " |
| 133 |
"die offset does not reference valid DIE "); |
| 134 |
esb_append_printf_u(&details,"at offset 0x%" |
| 135 |
DW_PR_DUx, global_die_off); |
| 136 |
esb_append(&details,"."); |
| 137 |
print_error_and_continue( |
| 138 |
esb_get_string(&details), dres, *err); |
| 139 |
esb_destructor(&details); |
| 140 |
return dres; |
| 141 |
} |
| 142 |
|
| 143 |
/* get offset of die from its cu-header */ |
| 144 |
ddres = dwarf_die_CU_offset(die, &die_CU_off, err); |
| 145 |
if (ddres != DW_DLV_OK) { |
| 146 |
struct esb_s details; |
| 147 |
esb_constructor(&details); |
| 148 |
esb_append(&details,line_title); |
| 149 |
esb_append(&details," cannot get CU die offset"); |
| 150 |
print_error_and_continue( |
| 151 |
esb_get_string(&details), dres, *err); |
| 152 |
esb_destructor(&details); |
| 153 |
die_CU_off = 0; |
| 154 |
dwarf_dealloc(dbg, die, DW_DLA_DIE); |
| 155 |
return ddres; |
| 156 |
} |
| 157 |
|
| 158 |
/* Get die at offset cu_die_off to check its existence. */ |
| 159 |
{ |
| 160 |
Dwarf_Die cu_die = NULL; |
| 161 |
Dwarf_Error localerr = 0; |
| 162 |
cudres = dwarf_offdie_b(dbg, cu_die_off,is_info, |
| 163 |
&cu_die, &localerr); |
| 164 |
if (cudres != DW_DLV_OK) { |
| 165 |
printf("ERROR: dwarf_offdie_b called " |
| 166 |
" CU die offset 0x%" DW_PR_DUx |
| 167 |
" does not reference a valid CU DIE\n", |
| 168 |
cu_die_off); |
| 169 |
if (cudres == DW_DLV_ERROR) { |
| 170 |
dwarf_dealloc_error(dbg,localerr); |
| 171 |
localerr = 0; |
| 172 |
} |
| 173 |
glflags.gf_count_major_errors++; |
| 174 |
} else { |
| 175 |
/* It exists, all is well. */ |
| 176 |
dwarf_dealloc_die(cu_die); |
| 177 |
} |
| 178 |
} |
| 179 |
/* Display offsets */ |
| 180 |
if (glflags.gf_display_offsets) { |
| 181 |
/* Print 'name' at the end for better layout */ |
| 182 |
if (!globi) { |
| 183 |
printf(" %s data. %" DW_PR_DSd " %s\n", |
| 184 |
line_title,globcount, |
| 185 |
globcount==1?"entry":"entries"); |
| 186 |
#if 0 |
| 187 |
printf(" DIE DIE CU DIE CU DIE\n"); |
| 188 |
printf(" in sect in CU in sect in sect\n"); |
| 189 |
#endif |
| 190 |
|
| 191 |
printf(" CUhdr DIE CU DIE DIE\n"); |
| 192 |
printf(" in sect in CU in sect in sect\n"); |
| 193 |
} |
| 194 |
printf(" 0x%" DW_PR_XZEROS DW_PR_DUx |
| 195 |
" 0x%" DW_PR_XZEROS DW_PR_DUx |
| 196 |
" 0x%" DW_PR_XZEROS DW_PR_DUx |
| 197 |
" 0x%" DW_PR_XZEROS DW_PR_DUx , |
| 198 |
global_cuh_offset, |
| 199 |
cu_local_die_offset, |
| 200 |
cu_die_off,global_die_off); |
| 201 |
if (dietag) { |
| 202 |
const char * tagname = ""; |
| 203 |
dwarf_get_TAG_name(dietag,&tagname); |
| 204 |
printf(" %-18s",tagname); |
| 205 |
} |
| 206 |
#if 0 |
| 207 |
printf("%s die-in-sect 0x%" DW_PR_XZEROS DW_PR_DUx |
| 208 |
", cu-in-sect 0x%" DW_PR_XZEROS DW_PR_DUx "," |
| 209 |
" die-in-cu 0x%" DW_PR_XZEROS DW_PR_DUx |
| 210 |
", cu-header-in-sect 0x%" DW_PR_XZEROS DW_PR_DUx , |
| 211 |
line_title, |
| 212 |
global_die_off, cu_die_off, |
| 213 |
(Dwarf_Unsigned) die_CU_off, |
| 214 |
/* Following is absolute offset of the |
| 215 |
beginning of the cu */ |
| 216 |
global_cu_offset); |
| 217 |
#endif |
| 218 |
} |
| 219 |
|
| 220 |
#if 0 |
| 221 |
if (cu_local_die_offset != global_cuh_offset) { |
| 222 |
struct esb_s details; |
| 223 |
|
| 224 |
dwarf_dealloc(dbg, die, DW_DLA_DIE); |
| 225 |
esb_constructor(&details); |
| 226 |
esb_append(&details,"\nERROR: "); |
| 227 |
esb_append(&details,line_title); |
| 228 |
esb_append(&details,"has improper die offset:"); |
| 229 |
esb_append_printf_u(&details," global cu offset 0x%x ", |
| 230 |
global_cuh_offset); |
| 231 |
esb_append_printf_u(&details," does not match die_off 0x%x ", |
| 232 |
global_die_off); |
| 233 |
esb_append_printf_u(&details," minus die_CU_off 0x%x ", |
| 234 |
die_CU_off); |
| 235 |
esb_append(&details,"\n."); |
| 236 |
simple_err_return_msg_either_action(DW_DLV_ERROR, |
| 237 |
esb_get_string(&details)); |
| 238 |
return DW_DLV_NO_ENTRY; |
| 239 |
} |
| 240 |
#endif |
| 241 |
|
| 242 |
/* Print 'name' at the end for better layout */ |
| 243 |
printf(" '%s'\n",name); |
| 244 |
dwarf_dealloc(dbg, die, DW_DLA_DIE); |
| 245 |
check_info_offset_sanity(line_title, |
| 246 |
"die offset", name, global_die_off, maxoff); |
| 247 |
check_info_offset_sanity(line_title, |
| 248 |
"die cu offset", name, die_CU_off, maxoff); |
| 249 |
check_info_offset_sanity(line_title, |
| 250 |
"cu offset", name, |
| 251 |
cu_local_die_offset, maxoff); |
| 252 |
return DW_DLV_OK; |
| 253 |
} |
| 254 |
|
| 255 |
static void |
| 256 |
print_globals_header( |
| 257 |
Dwarf_Off pub_section_hdr_offset, |
| 258 |
Dwarf_Unsigned length_size, /* from pubnames header */ |
| 259 |
Dwarf_Unsigned length, /* from pubnames header */ |
| 260 |
Dwarf_Unsigned version, |
| 261 |
Dwarf_Off info_header_offset, |
| 262 |
Dwarf_Unsigned info_length) |
| 263 |
{ |
| 264 |
printf("Pub section offset 0x%" DW_PR_XZEROS DW_PR_DUx |
| 265 |
" (%" DW_PR_DUu ")\n", |
| 266 |
pub_section_hdr_offset,pub_section_hdr_offset); |
| 267 |
printf(" offset size 0x%" DW_PR_XZEROS DW_PR_DUx |
| 268 |
" (%" DW_PR_DUu ")\n", |
| 269 |
length_size, |
| 270 |
length_size); |
| 271 |
printf(" length 0x%" DW_PR_XZEROS DW_PR_DUx |
| 272 |
" (%" DW_PR_DUu ")\n", |
| 273 |
length, |
| 274 |
length); |
| 275 |
printf(" version 0x%" DW_PR_XZEROS DW_PR_DUx |
| 276 |
" (%" DW_PR_DUu ")\n", |
| 277 |
version, |
| 278 |
version); |
| 279 |
printf(" info hdr offset 0x%" DW_PR_XZEROS DW_PR_DUx |
| 280 |
" (%" DW_PR_DUu ")\n", |
| 281 |
info_header_offset, |
| 282 |
info_header_offset); |
| 283 |
printf(" info hdr length 0x%" DW_PR_XZEROS DW_PR_DUx |
| 284 |
" (%" DW_PR_DUu ")\n", |
| 285 |
info_length, |
| 286 |
info_length); |
| 287 |
} |
| 288 |
|
| 289 |
static const int secid[] = { |
| 290 |
DEBUG_PUBNAMES, |
| 291 |
DEBUG_PUBTYPES, |
| 292 |
DEBUG_FUNCNAMES, |
| 293 |
DEBUG_TYPENAMES, |
| 294 |
DEBUG_VARNAMES, |
| 295 |
DEBUG_WEAKNAMES |
| 296 |
}; |
| 297 |
static const char *typename[] = { |
| 298 |
"global", |
| 299 |
"pubtype", |
| 300 |
"static-func", |
| 301 |
"type", |
| 302 |
"static-var", |
| 303 |
"weakname", |
| 304 |
}; |
| 305 |
static const char *stdsecname[] = { |
| 306 |
".debug_pubnames", |
| 307 |
".debug_pubtypes", |
| 308 |
".debug_funcnames", |
| 309 |
".debug_typenames", |
| 310 |
".debug_varnames", |
| 311 |
".debug_weaknames" |
| 312 |
}; |
| 313 |
/* Get all the data in any .debug_pubnames style section. |
| 314 |
*/ |
| 315 |
int |
| 316 |
print_pubnames_style(Dwarf_Debug dbg, |
| 317 |
int category, |
| 318 |
Dwarf_Error *err) |
| 319 |
{ |
| 320 |
Dwarf_Global *globbuf = NULL; |
| 321 |
Dwarf_Signed count = 0; |
| 322 |
/* Offset to previous CU */ |
| 323 |
char tempsanbuf[ESB_FIXED_ALLOC_SIZE]; |
| 324 |
struct esb_s unsanitname; |
| 325 |
char tempsanbuf2[ESB_FIXED_ALLOC_SIZE]; |
| 326 |
struct esb_s unsanitname2; |
| 327 |
char sanbuf[ESB_FIXED_ALLOC_SIZE]; |
| 328 |
struct esb_s sanitname; |
| 329 |
int res = 0; |
| 330 |
int trueres = 0; |
| 331 |
int trueres2 = 0; |
| 332 |
const char *tname = 0; |
| 333 |
const char *stdsection = 0; |
| 334 |
|
| 335 |
if (category > DW_GL_WEAKS) { |
| 336 |
printf("ERROR: passing category to print_pubnames " |
| 337 |
"that is unusable and ignored: %d\n",category); |
| 338 |
return DW_DLV_OK; |
| 339 |
} |
| 340 |
glflags.current_section_id = secid[category]; |
| 341 |
tname = typename[category]; |
| 342 |
stdsection = stdsecname[category]; |
| 343 |
if (glflags.verbose) { |
| 344 |
/* For best testing! */ |
| 345 |
res = dwarf_return_empty_pubnames(dbg,1); |
| 346 |
if (res != DW_DLV_OK) { |
| 347 |
simple_err_return_msg_either_action(res, |
| 348 |
"ERROR: Erroneous " |
| 349 |
"libdwarf call " |
| 350 |
"of dwarf_return_empty_pubnames: " |
| 351 |
"dwarfdump internal error"); |
| 352 |
return res; |
| 353 |
} |
| 354 |
} |
| 355 |
/* Globals picks up global entries from the |
| 356 |
selected section as of 0.6.0 December 2022 */ |
| 357 |
esb_constructor_fixed(&unsanitname,tempsanbuf, |
| 358 |
sizeof(tempsanbuf)); |
| 359 |
esb_constructor_fixed(&unsanitname2,tempsanbuf2, |
| 360 |
sizeof(tempsanbuf2)); |
| 361 |
esb_constructor_fixed(&sanitname,sanbuf,sizeof(sanbuf)); |
| 362 |
trueres = get_true_section_name(dbg,stdsection, |
| 363 |
&unsanitname,TRUE); |
| 364 |
trueres2 = DW_DLV_NO_ENTRY; |
| 365 |
if (category == DW_GL_GLOBALS) { |
| 366 |
trueres2= get_true_section_name(dbg,".debug_names", |
| 367 |
&unsanitname2,TRUE); |
| 368 |
} |
| 369 |
if (trueres == DW_DLV_NO_ENTRY) { |
| 370 |
if (trueres2 == DW_DLV_NO_ENTRY) { |
| 371 |
/* unsanitname ok as is, nothing to print |
| 372 |
but the name of the empty section. */ |
| 373 |
} else { |
| 374 |
esb_empty_string(&unsanitname); |
| 375 |
esb_append(&unsanitname,esb_get_string(&unsanitname2)); |
| 376 |
} |
| 377 |
} else { |
| 378 |
if (trueres2 == DW_DLV_NO_ENTRY) { |
| 379 |
/* unsanitname ok as is, nothing to print |
| 380 |
but the name of the real section. */ |
| 381 |
} else { |
| 382 |
esb_append(&unsanitname," and "); |
| 383 |
esb_append(&unsanitname,esb_get_string(&unsanitname2)); |
| 384 |
} |
| 385 |
} |
| 386 |
esb_destructor(&unsanitname2); |
| 387 |
|
| 388 |
/* Sanitized cannot be safely reused,there is a static buffer, |
| 389 |
so we make a safe copy. */ |
| 390 |
esb_append(&sanitname,sanitized(esb_get_string(&unsanitname))); |
| 391 |
esb_destructor(&unsanitname); |
| 392 |
if (glflags.gf_check_functions) { |
| 393 |
DWARF_CHECK_COUNT(check_functions_result,1); |
| 394 |
/* For coverage of these two API functions, |
| 395 |
call directly. */ |
| 396 |
switch(category) { |
| 397 |
case DW_GL_GLOBALS: |
| 398 |
res = dwarf_get_globals(dbg, |
| 399 |
&globbuf, &count, err); |
| 400 |
break; |
| 401 |
case DW_GL_PUBTYPES: |
| 402 |
res = dwarf_get_pubtypes(dbg, |
| 403 |
&globbuf, &count, err); |
| 404 |
break; |
| 405 |
default: |
| 406 |
res = dwarf_globals_by_type(dbg,category, |
| 407 |
&globbuf, &count, err); |
| 408 |
break; |
| 409 |
} |
| 410 |
} else { |
| 411 |
res = dwarf_globals_by_type(dbg,category, |
| 412 |
&globbuf, &count, err); |
| 413 |
} |
| 414 |
if (res == DW_DLV_NO_ENTRY) { |
| 415 |
return res; |
| 416 |
} |
| 417 |
if (res == DW_DLV_OK && !count) { |
| 418 |
dwarf_globals_dealloc(dbg,globbuf,count); |
| 419 |
return res; |
| 420 |
} |
| 421 |
if (glflags.gf_do_print_dwarf) { |
| 422 |
printf("\n%s\n",esb_get_string(&sanitname)); |
| 423 |
} |
| 424 |
if (res == DW_DLV_ERROR) { |
| 425 |
esb_destructor(&sanitname); |
| 426 |
return res; |
| 427 |
} |
| 428 |
res = print_all_pubnames_style_records(dbg, |
| 429 |
tname, |
| 430 |
esb_get_string(&sanitname), |
| 431 |
globbuf,count,err); |
| 432 |
if (res == DW_DLV_ERROR) { |
| 433 |
struct esb_s m; |
| 434 |
|
| 435 |
dwarf_globals_dealloc(dbg,globbuf,count); |
| 436 |
esb_constructor(&m); |
| 437 |
esb_append(&m,"ERROR: " |
| 438 |
"failed reading pubnames style section "); |
| 439 |
esb_append_printf_s(&m,"%s ",stdsection); |
| 440 |
esb_append_printf_s(&m,"type %s ",tname); |
| 441 |
simple_err_return_msg_either_action(res, |
| 442 |
esb_get_string(&m)); |
| 443 |
esb_destructor(&sanitname); |
| 444 |
esb_destructor(&m); |
| 445 |
return res; |
| 446 |
} |
| 447 |
if (res == DW_DLV_NO_ENTRY) { |
| 448 |
dwarf_globals_dealloc(dbg,globbuf,count); |
| 449 |
esb_destructor(&sanitname); |
| 450 |
return res; |
| 451 |
} |
| 452 |
esb_destructor(&sanitname); |
| 453 |
dwarf_globals_dealloc(dbg,globbuf,count); |
| 454 |
dwarf_return_empty_pubnames(dbg,0); |
| 455 |
return res; |
| 456 |
} |
| 457 |
|
| 458 |
static void |
| 459 |
dd_check_globals_data(Dwarf_Debug dbg, |
| 460 |
Dwarf_Global glob, |
| 461 |
int nres, |
| 462 |
char *name, |
| 463 |
Dwarf_Off global_die_off) |
| 464 |
{ |
| 465 |
char *check_name = 0; |
| 466 |
Dwarf_Off cfglobal_die_offset = 0; |
| 467 |
Dwarf_Error cferr = 0; |
| 468 |
int rescf = 0; |
| 469 |
|
| 470 |
if (!glflags.gf_check_functions) { |
| 471 |
return; |
| 472 |
} |
| 473 |
DWARF_CHECK_COUNT(check_functions_result,1); |
| 474 |
rescf = dwarf_globname(glob, &check_name,&cferr); |
| 475 |
if (rescf == nres) { |
| 476 |
if (nres == DW_DLV_OK) { |
| 477 |
if (strcmp(name,check_name)) { |
| 478 |
/* FAIL */ |
| 479 |
DWARF_CHECK_ERROR(check_functions_result, |
| 480 |
"Name mistmatch with dwarf_globname"); |
| 481 |
} |
| 482 |
} |
| 483 |
} else { |
| 484 |
DWARF_CHECK_ERROR(check_functions_result, |
| 485 |
"DW_DLV mismatch with dwarf_globname"); |
| 486 |
} |
| 487 |
if (cferr) { |
| 488 |
DROP_ERROR_INSTANCE(dbg,rescf,cferr); |
| 489 |
} |
| 490 |
rescf = dwarf_global_die_offset(glob, |
| 491 |
&cfglobal_die_offset,&cferr); |
| 492 |
if (rescf == nres) { |
| 493 |
if (nres == DW_DLV_OK) { |
| 494 |
if (global_die_off != cfglobal_die_offset) { |
| 495 |
/* FAIL */ |
| 496 |
DWARF_CHECK_ERROR(check_functions_result, |
| 497 |
"Die offset mistmatch with " |
| 498 |
"dwarf_global_die_offset"); |
| 499 |
} |
| 500 |
} |
| 501 |
} else { |
| 502 |
DWARF_CHECK_ERROR(check_functions_result, |
| 503 |
"DW_DLV mismatch with " |
| 504 |
"dwarf_global_die_offset"); |
| 505 |
} |
| 506 |
if (cferr) { |
| 507 |
DROP_ERROR_INSTANCE(dbg,rescf,cferr); |
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
static void |
| 512 |
dd_check_pubname_attr(Dwarf_Debug dbg, |
| 513 |
const char *section_true_name, |
| 514 |
Dwarf_Signed i, |
| 515 |
Dwarf_Bool is_info, |
| 516 |
char *name, |
| 517 |
Dwarf_Off global_die_off, |
| 518 |
Dwarf_Off cu_die_off, |
| 519 |
Dwarf_Off *prev_cu_die_off) |
| 520 |
{ |
| 521 |
Dwarf_Bool has_attr = 0; |
| 522 |
int dres = 0; |
| 523 |
int ares = 0; |
| 524 |
Dwarf_Die die = 0; |
| 525 |
Dwarf_Error err = 0; |
| 526 |
|
| 527 |
if (!glflags.gf_check_pubname_attr) { |
| 528 |
return; |
| 529 |
} |
| 530 |
/* We are processing a new set of pubnames |
| 531 |
for a different CU; get the producer ID, |
| 532 |
at 'cu_off' to see if we need to skip |
| 533 |
these pubnames */ |
| 534 |
if (cu_die_off != *prev_cu_die_off) { |
| 535 |
char proname[100]; |
| 536 |
struct esb_s producername; |
| 537 |
Dwarf_Die lcudie = 0; |
| 538 |
|
| 539 |
/* Record offset for previous CU */ |
| 540 |
*prev_cu_die_off = cu_die_off; |
| 541 |
dres = dwarf_offdie_b(dbg, cu_die_off, |
| 542 |
is_info, &lcudie, &err); |
| 543 |
if (dres != DW_DLV_OK) { |
| 544 |
struct esb_s msge; |
| 545 |
|
| 546 |
esb_constructor(&msge); |
| 547 |
esb_append(&msge, |
| 548 |
"ERROR Accessing dwarf_offdie "); |
| 549 |
esb_append_printf_i(&msge, |
| 550 |
" f1df0or index %d in ",i); |
| 551 |
esb_append(&msge,section_true_name); |
| 552 |
esb_append(&msge,"."); |
| 553 |
simple_err_return_msg_either_action(dres, |
| 554 |
esb_get_string(&msge)); |
| 555 |
esb_destructor(&msge); |
| 556 |
DROP_ERROR_INSTANCE(dbg,dres,err); |
| 557 |
return; |
| 558 |
} |
| 559 |
/* Get producer name for this CU |
| 560 |
and update compiler list */ |
| 561 |
esb_constructor_fixed(&producername,proname, |
| 562 |
sizeof(proname)); |
| 563 |
dres = get_producer_name(dbg,lcudie,cu_die_off, |
| 564 |
&producername,&err); |
| 565 |
dwarf_dealloc(dbg,lcudie,DW_DLA_DIE); |
| 566 |
if (dres == DW_DLV_ERROR) { |
| 567 |
DROP_ERROR_INSTANCE(dbg,dres,err); |
| 568 |
return; |
| 569 |
} |
| 570 |
update_compiler_target( |
| 571 |
esb_get_string(&producername)); |
| 572 |
glflags.DIE_CU_overall_offset = cu_die_off; |
| 573 |
esb_destructor(&producername); |
| 574 |
} |
| 575 |
|
| 576 |
dres = dwarf_offdie_b(dbg, global_die_off, |
| 577 |
is_info, &die, &err); |
| 578 |
if (dres != DW_DLV_OK) { |
| 579 |
struct esb_s msge; |
| 580 |
|
| 581 |
esb_constructor(&msge); |
| 582 |
esb_append(&msge,"ERROR Accessing dwarf_offdie "); |
| 583 |
esb_append_printf_i(&msge," for index %d in ",i); |
| 584 |
esb_append(&msge,section_true_name); |
| 585 |
esb_append(&msge,". "); |
| 586 |
if (dres == DW_DLV_ERROR) { |
| 587 |
esb_append(&msge,dwarf_errmsg(err)); |
| 588 |
} else { |
| 589 |
esb_append(&msge,"offdie returned DW_DLV_NO_ENTRY"); |
| 590 |
} |
| 591 |
simple_err_return_msg_either_action(dres, |
| 592 |
esb_get_string(&msge)); |
| 593 |
esb_destructor(&msge); |
| 594 |
DROP_ERROR_INSTANCE(dbg,dres,err); |
| 595 |
return; |
| 596 |
} |
| 597 |
ares = |
| 598 |
dwarf_hasattr(die, DW_AT_external, |
| 599 |
&has_attr, &err); |
| 600 |
if (ares == DW_DLV_ERROR) { |
| 601 |
struct esb_s msgd; |
| 602 |
|
| 603 |
esb_constructor(&msgd); |
| 604 |
esb_append(&msgd,"ERROR: hasattr on DW_AT_external" |
| 605 |
" from "); |
| 606 |
esb_append(&msgd,section_true_name); |
| 607 |
esb_append(&msgd," fails."); |
| 608 |
dwarf_dealloc(dbg, die, DW_DLA_DIE); |
| 609 |
/* print_error does not return */ |
| 610 |
simple_err_return_msg_either_action(ares, |
| 611 |
esb_get_string(&msgd)); |
| 612 |
esb_destructor(&msgd); |
| 613 |
DROP_ERROR_INSTANCE(dbg,dres,err); |
| 614 |
return; |
| 615 |
} |
| 616 |
/* DW_DLV_NO_ENTRY is odd. Check that if checking. */ |
| 617 |
/* Check for specific compiler */ |
| 618 |
if (checking_this_compiler()) { |
| 619 |
DWARF_CHECK_COUNT(pubname_attr_result,1); |
| 620 |
if (ares == DW_DLV_OK && has_attr) { |
| 621 |
/* Should the value of flag be examined? */ |
| 622 |
} else { |
| 623 |
DWARF_CHECK_ERROR2(pubname_attr_result,name, |
| 624 |
"DIE pubname refers to does not have " |
| 625 |
"DW_AT_external"); |
| 626 |
} |
| 627 |
} |
| 628 |
dwarf_dealloc(dbg, die, DW_DLA_DIE); |
| 629 |
} |
| 630 |
|
| 631 |
static int |
| 632 |
print_all_pubnames_style_records(Dwarf_Debug dbg, |
| 633 |
const char *linetitle, |
| 634 |
const char * section_true_name, |
| 635 |
Dwarf_Global *globbuf, |
| 636 |
Dwarf_Signed count, |
| 637 |
Dwarf_Error *err) |
| 638 |
{ |
| 639 |
Dwarf_Unsigned maxoff = get_info_max_offset(dbg); |
| 640 |
Dwarf_Unsigned lastcudieoff = 0; |
| 641 |
Dwarf_Addr elf_max_address = 0; |
| 642 |
Dwarf_Signed i = 0; |
| 643 |
int ares = 0; |
| 644 |
Dwarf_Bool is_info = TRUE; |
| 645 |
Dwarf_Off prev_cu_die_off = elf_max_address; |
| 646 |
|
| 647 |
ares = get_address_size_and_max(dbg,0,&elf_max_address,err); |
| 648 |
if (ares != DW_DLV_OK) { |
| 649 |
simple_err_return_msg_either_action(ares, |
| 650 |
"ERROR: print_pubnames style call to get " |
| 651 |
"address size and max address" |
| 652 |
" fails."); |
| 653 |
return ares; |
| 654 |
} |
| 655 |
|
| 656 |
for (i = 0; i < count; i++) { |
| 657 |
int nres = 0; |
| 658 |
int cures3 = 0; |
| 659 |
Dwarf_Off global_die_off = 0; |
| 660 |
Dwarf_Off cu_die_off = 0; |
| 661 |
Dwarf_Off global_cuh_off = 0; |
| 662 |
char *name = 0; |
| 663 |
Dwarf_Global thisglobal = 0; |
| 664 |
|
| 665 |
/* Turns the cu-local die_off in globbuf |
| 666 |
entry into a global die_off. The cu_off |
| 667 |
returned is the offset of the CU DIE, |
| 668 |
not the CU header. */ |
| 669 |
thisglobal = globbuf[i]; |
| 670 |
nres = dwarf_global_name_offsets(thisglobal, |
| 671 |
&name, &global_die_off, &cu_die_off, |
| 672 |
err); |
| 673 |
dd_check_globals_data(dbg,thisglobal,nres, |
| 674 |
name,global_die_off); |
| 675 |
if (nres != DW_DLV_OK) { |
| 676 |
struct esb_s m; |
| 677 |
|
| 678 |
esb_constructor(&m); |
| 679 |
esb_append_printf_i(&m, |
| 680 |
"ERROR: dwarf_global_name_offsets for globals index " |
| 681 |
" %d ", i); |
| 682 |
esb_append_printf_i(&m," with globals count %d.", |
| 683 |
count); |
| 684 |
simple_err_return_msg_either_action(nres, |
| 685 |
esb_get_string(&m)); |
| 686 |
esb_destructor(&m); |
| 687 |
return nres; |
| 688 |
} |
| 689 |
if (glflags.verbose) { |
| 690 |
/* We know no global_die_off can be zero |
| 691 |
(except for the fake global created when |
| 692 |
the debug_pubnames for a CU has no actual entries) |
| 693 |
we do not need to check for i==0 to detect |
| 694 |
this is the initial global record and |
| 695 |
we want to print this pubnames section CU header. */ |
| 696 |
if (lastcudieoff != cu_die_off) { |
| 697 |
Dwarf_Off pub_section_hdr_offset = 0; |
| 698 |
Dwarf_Unsigned pub_offset_size = 0; |
| 699 |
Dwarf_Unsigned pub_length = 0; |
| 700 |
Dwarf_Unsigned pub_version = 0; |
| 701 |
Dwarf_Off info_header_offset = 0; |
| 702 |
Dwarf_Unsigned info_length = 0; |
| 703 |
int header_category = 0; |
| 704 |
|
| 705 |
nres = dwarf_get_globals_header(thisglobal, |
| 706 |
&header_category, |
| 707 |
&pub_section_hdr_offset, |
| 708 |
&pub_offset_size, |
| 709 |
&pub_length,&pub_version, |
| 710 |
&info_header_offset,&info_length,err); |
| 711 |
if (nres != DW_DLV_OK) { |
| 712 |
struct esb_s msge; |
| 713 |
|
| 714 |
esb_constructor(&msge); |
| 715 |
esb_append(&msge, |
| 716 |
"ERROR Access dwarf_get_globals_header "); |
| 717 |
esb_append_printf_i(&msge, |
| 718 |
" for index %d in ",i); |
| 719 |
esb_append(&msge,section_true_name); |
| 720 |
esb_append(&msge,"."); |
| 721 |
simple_err_return_msg_either_action(nres, |
| 722 |
esb_get_string(&msge)); |
| 723 |
esb_destructor(&msge); |
| 724 |
return nres; |
| 725 |
} |
| 726 |
if (glflags.gf_do_print_dwarf) { |
| 727 |
print_globals_header(pub_section_hdr_offset, |
| 728 |
pub_offset_size, |
| 729 |
pub_length, |
| 730 |
pub_version, |
| 731 |
info_header_offset, |
| 732 |
info_length); |
| 733 |
} |
| 734 |
} |
| 735 |
} |
| 736 |
lastcudieoff = cu_die_off; |
| 737 |
if (glflags.verbose) { |
| 738 |
/* If verbose we can see a zero die_off. */ |
| 739 |
if (!global_die_off && !strlen(name)) { |
| 740 |
/* A different and impossible cu die offset in case |
| 741 |
of an empty pubnames CU. */ |
| 742 |
continue; |
| 743 |
} |
| 744 |
} |
| 745 |
/* This gets the CU header offset, which |
| 746 |
is the offset that global_die_off needs to be added to |
| 747 |
to calculate the DIE offset. Note that |
| 748 |
dwarf_global_name_offsets already did that |
| 749 |
addition properly so this call is just so |
| 750 |
we can print the CU header offset. */ |
| 751 |
cures3 = dwarf_global_cu_offset(thisglobal, |
| 752 |
&global_cuh_off, err); |
| 753 |
if (cures3 != DW_DLV_OK) { |
| 754 |
struct esb_s msge; |
| 755 |
|
| 756 |
esb_constructor(&msge); |
| 757 |
esb_append(&msge,"ERROR Access dwarf_global_cu_offset "); |
| 758 |
esb_append_printf_i(&msge," for index %d in ",i); |
| 759 |
esb_append(&msge,section_true_name); |
| 760 |
esb_append(&msge,"."); |
| 761 |
simple_err_return_msg_either_action(cures3, |
| 762 |
esb_get_string(&msge)); |
| 763 |
esb_destructor(&msge); |
| 764 |
return cures3; |
| 765 |
} |
| 766 |
|
| 767 |
dd_check_pubname_attr(dbg, |
| 768 |
section_true_name,i, |
| 769 |
is_info,name,global_die_off, |
| 770 |
cu_die_off, &prev_cu_die_off); |
| 771 |
/* Now print name, after the test */ |
| 772 |
if (glflags.gf_do_print_dwarf || |
| 773 |
(glflags.gf_record_dwarf_error && |
| 774 |
glflags.gf_check_verbose_mode)) { |
| 775 |
int res = 0; |
| 776 |
Dwarf_Half dietag = |
| 777 |
dwarf_global_tag_number(thisglobal); |
| 778 |
|
| 779 |
res = print_pubname_style_entry(dbg, |
| 780 |
i,count, |
| 781 |
linetitle, |
| 782 |
name, |
| 783 |
dietag, |
| 784 |
global_die_off, cu_die_off, |
| 785 |
global_cuh_off, |
| 786 |
maxoff,err); |
| 787 |
if (res != DW_DLV_OK) { |
| 788 |
return res; |
| 789 |
} |
| 790 |
glflags.gf_record_dwarf_error = FALSE; |
| 791 |
} |
| 792 |
} |
| 793 |
return DW_DLV_OK; |
| 794 |
} |