| 1 |
/* Copyright (C) 2000-2006 Silicon Graphics, Inc. All Rights Reserved. |
| 2 |
Portions Copyright (C) 2007-2020 David Anderson. All Rights Reserved. |
| 3 |
Portions Copyright (C) 2010-2012 SN Systems Ltd. All Rights Reserved. |
| 4 |
Portions Copyright (C) 2015-2015 Google, Inc. All Rights Reserved. |
| 5 |
|
| 6 |
This program is free software; you can redistribute it |
| 7 |
and/or modify it under the terms of version 2.1 of the |
| 8 |
GNU Lesser General Public License as published by the Free |
| 9 |
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 Lesser General |
| 25 |
Public License along with this program; if not, write |
| 26 |
the Free Software Foundation, Inc., 51 Franklin Street - |
| 27 |
Fifth Floor, Boston MA 02110-1301, USA. |
| 28 |
|
| 29 |
*/ |
| 30 |
|
| 31 |
#include <config.h> |
| 32 |
|
| 33 |
#ifdef HAVE_STDINT_H |
| 34 |
#include <stdint.h> /* uintptr_t */ |
| 35 |
#endif /* HAVE_STDINT_H */ |
| 36 |
#include <stdlib.h> /* free() malloc() realloc() */ |
| 37 |
#include <string.h> /* memset() strlen() */ |
| 38 |
|
| 39 |
#if defined(_WIN32) && defined(HAVE_STDAFX_H) |
| 40 |
#include "stdafx.h" |
| 41 |
#endif /* HAVE_STDAFX_H */ |
| 42 |
|
| 43 |
#include "dwarf.h" |
| 44 |
#include "libdwarf.h" |
| 45 |
#include "libdwarf_private.h" |
| 46 |
#include "dwarf_base_types.h" |
| 47 |
#include "dwarf_safe_strcpy.h" |
| 48 |
#include "dwarf_opaque.h" |
| 49 |
#include "dwarf_alloc.h" |
| 50 |
#include "dwarf_error.h" |
| 51 |
#include "dwarf_util.h" |
| 52 |
#include "dwarf_line.h" |
| 53 |
#include "dwarf_string.h" |
| 54 |
#include "dwarf_debuglink.h" |
| 55 |
|
| 56 |
/* Line Register Set initial conditions. */ |
| 57 |
static struct Dwarf_Line_Registers_s |
| 58 |
_dwarf_line_table_regs_default_values = { |
| 59 |
/* Dwarf_Addr lr_address */ 0, |
| 60 |
/* Dwarf_Unsigned lr_file */ 1, |
| 61 |
/* Dwarf_Unsigned lr_line */ 1, |
| 62 |
/* Dwarf_Unsigned lr_column */ 0, |
| 63 |
/* Dwarf_Bool lr_is_stmt */ FALSE, |
| 64 |
/* Dwarf_Bool lr_basic_block */ FALSE, |
| 65 |
/* Dwarf_Bool lr_end_sequence */ FALSE, |
| 66 |
/* Dwarf_Bool lr_prologue_end */ FALSE, |
| 67 |
/* Dwarf_Bool lr_epilogue_begin */ FALSE, |
| 68 |
/* Dwarf_Small lr_isa */ 0, |
| 69 |
/* Dwarf_Unsigned lr_op_index */ 0, |
| 70 |
/* Dwarf_Unsigned lr_discriminator */ 0, |
| 71 |
/* Dwarf_Unsigned lr_call_context */ 0, |
| 72 |
/* Dwarf_Unsigned lr_subprogram */ 0, |
| 73 |
}; |
| 74 |
|
| 75 |
void |
| 76 |
_dwarf_set_line_table_regs_default_values(Dwarf_Line_Registers regs, |
| 77 |
unsigned lineversion, |
| 78 |
Dwarf_Bool is_stmt) |
| 79 |
{ |
| 80 |
(void)lineversion; |
| 81 |
*regs = _dwarf_line_table_regs_default_values; |
| 82 |
/* Remember that 0xf006 is the version of |
| 83 |
the experimental line table */ |
| 84 |
if (lineversion == DW_LINE_VERSION5) { |
| 85 |
/* DWARF5 Section 2.14 says default 0 for line table |
| 86 |
file numbering.. |
| 87 |
DWARF5 Table 6.4 says the line table file |
| 88 |
register defaults to 1 (as did DWARF2,3,4). |
| 89 |
|
| 90 |
gcc 11.2.0 uses line register |
| 91 |
default 1, while correctly numbering files from 0. |
| 92 |
it sets file 0 and file 2 to the file of the CU |
| 93 |
and file 1 applies to an included file |
| 94 |
so things work when the first line table |
| 95 |
entries needed come from an included file |
| 96 |
(such as a static inline function definition). |
| 97 |
See regressiontests/issue137gh/README |
| 98 |
|
| 99 |
clang 14 entirely avoids use of the default |
| 100 |
file register value, it always uses |
| 101 |
DW_LNS_set_file in the line table. */ |
| 102 |
regs->lr_file = 1; |
| 103 |
} |
| 104 |
regs->lr_is_stmt = is_stmt; |
| 105 |
} |
| 106 |
|
| 107 |
/* Detect Windows full paths as well as Unix/Linux. |
| 108 |
ASSERT: fname != NULL */ |
| 109 |
Dwarf_Bool |
| 110 |
_dwarf_file_name_is_full_path(Dwarf_Small *fname) |
| 111 |
{ |
| 112 |
Dwarf_Small firstc = *fname; |
| 113 |
/* Not relative path if |
| 114 |
- path begins with \\ (UNC path) |
| 115 |
- path begins with ?:\, with ? being a letter |
| 116 |
- path bagins with \ |
| 117 |
see |
| 118 |
https://docs.microsoft.com/en-us/windows/win32/\ |
| 119 |
fileio/naming-a-file#paths */ |
| 120 |
if (!firstc) { |
| 121 |
return FALSE; |
| 122 |
} |
| 123 |
if (firstc == '/') { |
| 124 |
return TRUE; |
| 125 |
} |
| 126 |
if (firstc == '\\') { |
| 127 |
return TRUE; |
| 128 |
} |
| 129 |
/* We assume anything starting with c: (etc) |
| 130 |
is a genuine Windows name. That turns out |
| 131 |
to be important as we dump PE objects on |
| 132 |
linux! It's safe too, as a specially crafted |
| 133 |
file might have add path output, but would |
| 134 |
not break anything. */ |
| 135 |
if (((firstc >= 'a') && (firstc <= 'z')) || |
| 136 |
((firstc >= 'A') && (firstc <= 'Z'))) { |
| 137 |
if (fname[1] == ':') { |
| 138 |
/* Some test cases use /, some \\ */ |
| 139 |
if (fname[2] == '\\') { |
| 140 |
return TRUE; |
| 141 |
} |
| 142 |
if (fname[2] == '/') { |
| 143 |
return TRUE; |
| 144 |
} |
| 145 |
/* This is a relative path to the current |
| 146 |
directory on the drive named. |
| 147 |
Windows has a 'current directory' |
| 148 |
with each drive letter in use. */ |
| 149 |
} |
| 150 |
} |
| 151 |
return FALSE; |
| 152 |
} |
| 153 |
#include "dwarf_line_table_reader_common.h" |
| 154 |
|
| 155 |
/* Used for a short time in the next two functions. |
| 156 |
Not saved. If multithreading ever allowed this |
| 157 |
will have to change to be function local |
| 158 |
non-static buffers. */ |
| 159 |
static char targbuf[300]; |
| 160 |
static char nbuf[300]; |
| 161 |
|
| 162 |
static int |
| 163 |
ret_simple_full_path(Dwarf_Debug dbg, |
| 164 |
char *file_name, |
| 165 |
char ** name_ptr_out, |
| 166 |
Dwarf_Error *error) |
| 167 |
{ |
| 168 |
char *tmp = 0; |
| 169 |
char * mstr = 0; |
| 170 |
size_t mlen = 0; |
| 171 |
dwarfstring targ; |
| 172 |
dwarfstring nxt; |
| 173 |
|
| 174 |
dwarfstring_constructor_static(&targ, |
| 175 |
targbuf,sizeof(targbuf)); |
| 176 |
dwarfstring_constructor_static(&nxt, |
| 177 |
nbuf,sizeof(nbuf)); |
| 178 |
|
| 179 |
dwarfstring_append(&nxt,file_name); |
| 180 |
_dwarf_pathjoinl(&targ,&nxt); |
| 181 |
mstr= dwarfstring_string(&targ); |
| 182 |
mlen = dwarfstring_strlen(&targ) +1; |
| 183 |
tmp = (char *) _dwarf_get_alloc(dbg, DW_DLA_STRING, |
| 184 |
(Dwarf_Unsigned)mlen); |
| 185 |
if (tmp) { |
| 186 |
_dwarf_safe_strcpy(tmp,mlen, mstr,mlen-1); |
| 187 |
*name_ptr_out = tmp; |
| 188 |
dwarfstring_destructor(&targ); |
| 189 |
dwarfstring_destructor(&nxt); |
| 190 |
return DW_DLV_OK; |
| 191 |
} |
| 192 |
dwarfstring_destructor(&targ); |
| 193 |
dwarfstring_destructor(&nxt); |
| 194 |
_dwarf_error_string(dbg,error,DW_DLE_ALLOC_FAIL, |
| 195 |
"DW_DLE_ALLOC_FAIL: " |
| 196 |
"Allocation of space for a simple full path " |
| 197 |
"from line table header data fails." ); |
| 198 |
return DW_DLV_ERROR; |
| 199 |
} |
| 200 |
|
| 201 |
static void |
| 202 |
_dwarf_dirno_string(Dwarf_Line_Context line_context, |
| 203 |
Dwarf_Unsigned dirno, |
| 204 |
unsigned include_dir_offset, |
| 205 |
dwarfstring *dwstr_out) |
| 206 |
{ |
| 207 |
if ((dirno - include_dir_offset) >= |
| 208 |
line_context->lc_include_directories_count) { |
| 209 |
|
| 210 |
/* Corrupted data. We try to continue. |
| 211 |
Make the text look like a full-path */ |
| 212 |
dwarfstring_append_printf_u(dwstr_out, |
| 213 |
"/ERROR<corrupt include directory index %u" |
| 214 |
" unusable,", |
| 215 |
dirno); |
| 216 |
dwarfstring_append_printf_u(dwstr_out, |
| 217 |
" only %u directories present>", |
| 218 |
line_context->lc_include_directories_count); |
| 219 |
return; |
| 220 |
} |
| 221 |
{ |
| 222 |
char *inc_dir_name = |
| 223 |
(char *)line_context->lc_include_directories[ |
| 224 |
dirno - include_dir_offset]; |
| 225 |
if (!inc_dir_name) { |
| 226 |
/* This should never ever happen except in case |
| 227 |
of a corrupted object file. |
| 228 |
Make the text look like a full-path */ |
| 229 |
inc_dir_name = |
| 230 |
"/ERROR<erroneous NULL include dir pointer>"; |
| 231 |
} |
| 232 |
dwarfstring_append(dwstr_out,inc_dir_name); |
| 233 |
} |
| 234 |
return; |
| 235 |
} |
| 236 |
|
| 237 |
/* With this routine we ensure the file full path |
| 238 |
is calculated identically for |
| 239 |
dwarf_srcfiles() and _dwarf_filename() |
| 240 |
|
| 241 |
As of March 14 2020 this *always* |
| 242 |
does an allocation for the string. dwarf_dealloc |
| 243 |
is crucial to do no matter what. |
| 244 |
So we have consistency. |
| 245 |
|
| 246 |
dwarf_finish() will do the dealloc if nothing else does. |
| 247 |
Unless the calling application did the call |
| 248 |
dwarf_set_de_alloc_flag(0). |
| 249 |
|
| 250 |
The treatment of DWARF5 differs from DWARF < 5 |
| 251 |
as the line table header in DW5 lists the |
| 252 |
compilation directory directly. 10 August 2023. |
| 253 |
|
| 254 |
_dwarf_pathjoinl() takes care of / and Windows \ |
| 255 |
*/ |
| 256 |
static int |
| 257 |
create_fullest_file_path(Dwarf_Debug dbg, |
| 258 |
Dwarf_File_Entry fe, |
| 259 |
Dwarf_Line_Context line_context, |
| 260 |
char ** name_ptr_out, |
| 261 |
Dwarf_Error *error) |
| 262 |
{ |
| 263 |
Dwarf_Unsigned dirno = 0; |
| 264 |
char *full_name = 0; |
| 265 |
char *file_name = 0; |
| 266 |
/* Large enough that almost never will any malloc |
| 267 |
be needed by dwarfstring. Arbitrary size. */ |
| 268 |
dwarfstring targ; |
| 269 |
unsigned linetab_version = line_context->lc_version_number; |
| 270 |
|
| 271 |
file_name = (char *) fe->fi_file_name; |
| 272 |
if (!file_name) { |
| 273 |
_dwarf_error(dbg, error, DW_DLE_NO_FILE_NAME); |
| 274 |
return DW_DLV_ERROR; |
| 275 |
} |
| 276 |
if (_dwarf_file_name_is_full_path((Dwarf_Small *)file_name)) { |
| 277 |
int res = 0; |
| 278 |
|
| 279 |
res = ret_simple_full_path(dbg, |
| 280 |
file_name, |
| 281 |
name_ptr_out, |
| 282 |
error); |
| 283 |
return res; |
| 284 |
} |
| 285 |
{ |
| 286 |
int need_dir = FALSE; |
| 287 |
unsigned include_dir_offset = 1; |
| 288 |
static char compdirbuf[300]; |
| 289 |
static char filenamebuf[300]; |
| 290 |
dwarfstring compdir; |
| 291 |
dwarfstring incdir; |
| 292 |
dwarfstring filename; |
| 293 |
|
| 294 |
dwarfstring_constructor_static(&targ, |
| 295 |
targbuf,sizeof(targbuf)); |
| 296 |
dwarfstring_constructor_static(&compdir, |
| 297 |
compdirbuf,sizeof(compdirbuf)); |
| 298 |
dwarfstring_constructor_fixed(&incdir,300); |
| 299 |
dwarfstring_constructor_static(&filename, |
| 300 |
filenamebuf,sizeof(filenamebuf)); |
| 301 |
if (line_context->lc_compilation_directory) { |
| 302 |
char * comp_dir_name = |
| 303 |
(char *)line_context->lc_compilation_directory; |
| 304 |
dwarfstring_append(&compdir,comp_dir_name); |
| 305 |
} |
| 306 |
need_dir = FALSE; |
| 307 |
dirno = fe->fi_dir_index; |
| 308 |
include_dir_offset = 0; |
| 309 |
/* Remember that 0xf006 is the version of |
| 310 |
the experimental line table */ |
| 311 |
if (linetab_version == DW_LINE_VERSION5) { |
| 312 |
/* DWARF5 */ |
| 313 |
need_dir = TRUE; |
| 314 |
include_dir_offset = 0; |
| 315 |
} else { |
| 316 |
/* EXPERIMENTAL_LINE_TABLES_VERSION or 2,3, or 4 */ |
| 317 |
if (dirno) { |
| 318 |
need_dir = TRUE; |
| 319 |
include_dir_offset = 1; |
| 320 |
}/* else, no dirno, need_dir = FALSE |
| 321 |
Take directory from DW_AT_comp_dir */ |
| 322 |
} |
| 323 |
|
| 324 |
if (dirno > line_context->lc_include_directories_count) { |
| 325 |
/* This is quite corrupted. */ |
| 326 |
dwarfstring_destructor(&targ); |
| 327 |
dwarfstring_destructor(&compdir); |
| 328 |
dwarfstring_destructor(&filename); |
| 329 |
dwarfstring_reset(&incdir); |
| 330 |
dwarfstring_append_printf_u(&incdir, |
| 331 |
"DW_DLE_INCL_DIR_NUM_BAD: " |
| 332 |
"corrupt include directory index %u" |
| 333 |
" unusable,", dirno); |
| 334 |
dwarfstring_append_printf_u(&incdir, |
| 335 |
" only %u directories present.", |
| 336 |
line_context->lc_include_directories_count); |
| 337 |
_dwarf_error_string(dbg, error, DW_DLE_INCL_DIR_NUM_BAD, |
| 338 |
dwarfstring_string(&incdir)); |
| 339 |
dwarfstring_destructor(&incdir); |
| 340 |
return DW_DLV_ERROR; |
| 341 |
} |
| 342 |
if (need_dir ) { |
| 343 |
_dwarf_dirno_string(line_context,dirno, |
| 344 |
include_dir_offset,&incdir); |
| 345 |
} |
| 346 |
dwarfstring_append(&filename,file_name); |
| 347 |
if (dwarfstring_strlen(&incdir) > 0 && |
| 348 |
_dwarf_file_name_is_full_path( |
| 349 |
(Dwarf_Small*)dwarfstring_string(&incdir))) { |
| 350 |
|
| 351 |
/* incdir is full path,Ignore DW_AT_comp_dir |
| 352 |
and (for DWARF5 include_dir[0]) */ |
| 353 |
_dwarf_pathjoinl(&targ,&incdir); |
| 354 |
_dwarf_pathjoinl(&targ,&filename); |
| 355 |
} else { |
| 356 |
/* Join two or all three strings, |
| 357 |
ignoring empty/irrelevant ones. */ |
| 358 |
/* Remember that 0xf006 is the version of |
| 359 |
the experimental line table */ |
| 360 |
if (linetab_version != DW_LINE_VERSION5) { |
| 361 |
if (dwarfstring_strlen(&compdir) > 0) { |
| 362 |
_dwarf_pathjoinl(&targ,&compdir); |
| 363 |
} |
| 364 |
} else if (!include_dir_offset && dirno) { |
| 365 |
/* Don't do this if DW5 and dirno |
| 366 |
was zero, doing 0 here will |
| 367 |
duplicate the comp dir */ |
| 368 |
dwarfstring_reset(&compdir); |
| 369 |
_dwarf_dirno_string(line_context,0, |
| 370 |
include_dir_offset,&compdir); |
| 371 |
if (dwarfstring_strlen(&compdir) > 0) { |
| 372 |
_dwarf_pathjoinl(&targ,&compdir); |
| 373 |
} |
| 374 |
} |
| 375 |
if (dwarfstring_strlen(&incdir) > 0) { |
| 376 |
_dwarf_pathjoinl(&targ,&incdir); |
| 377 |
} |
| 378 |
_dwarf_pathjoinl(&targ,&filename); |
| 379 |
} |
| 380 |
{ |
| 381 |
char *mname = dwarfstring_string(&targ); |
| 382 |
size_t mlen = dwarfstring_strlen(&targ)+1; |
| 383 |
full_name = (char *) _dwarf_get_alloc(dbg, DW_DLA_STRING, |
| 384 |
(Dwarf_Unsigned)mlen); |
| 385 |
if (!full_name) { |
| 386 |
dwarfstring_destructor(&targ); |
| 387 |
dwarfstring_destructor(&incdir); |
| 388 |
dwarfstring_destructor(&compdir); |
| 389 |
dwarfstring_destructor(&filename); |
| 390 |
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 391 |
return DW_DLV_ERROR; |
| 392 |
} |
| 393 |
_dwarf_safe_strcpy(full_name,mlen,mname,mlen-1); |
| 394 |
} |
| 395 |
*name_ptr_out = full_name; |
| 396 |
dwarfstring_destructor(&targ); |
| 397 |
dwarfstring_destructor(&incdir); |
| 398 |
dwarfstring_destructor(&compdir); |
| 399 |
dwarfstring_destructor(&filename); |
| 400 |
} |
| 401 |
return DW_DLV_OK; |
| 402 |
} |
| 403 |
|
| 404 |
static void |
| 405 |
report_bogus_stmt_list_form(Dwarf_Debug dbg, |
| 406 |
Dwarf_Half attrform, Dwarf_Error *error) |
| 407 |
{ |
| 408 |
dwarfstring m; /* OK constructor_fixed */ |
| 409 |
dwarfstring f; /* Ok constructor_static */ |
| 410 |
char buf[32]; |
| 411 |
const char *formname = 0; |
| 412 |
|
| 413 |
buf[0] = 0; |
| 414 |
dwarfstring_constructor_static(&f,buf,sizeof(buf)); |
| 415 |
dwarf_get_FORM_name(attrform,&formname); |
| 416 |
if (!formname) { |
| 417 |
dwarfstring_append_printf_u(&f,"Invalid Form Code " |
| 418 |
" 0x" DW_PR_DUx,attrform); |
| 419 |
} else { |
| 420 |
dwarfstring_append(&f,(char *)formname); |
| 421 |
} |
| 422 |
dwarfstring_constructor_fixed(&m,200); |
| 423 |
dwarfstring_append_printf_s(&m, |
| 424 |
"DW_DLE_LINE_OFFSET_WRONG_FORM: form %s " |
| 425 |
"instead of an allowed section offset form.", |
| 426 |
dwarfstring_string(&f)); |
| 427 |
_dwarf_error_string(dbg, error, DW_DLE_LINE_OFFSET_WRONG_FORM, |
| 428 |
dwarfstring_string(&m)); |
| 429 |
dwarfstring_destructor(&m); |
| 430 |
dwarfstring_destructor(&f); |
| 431 |
} |
| 432 |
|
| 433 |
/* Although source files is supposed to return the |
| 434 |
source files in the compilation-unit, it does |
| 435 |
not look for any in the statement program. In |
| 436 |
other words, it ignores those defined using the |
| 437 |
extended opcode DW_LNE_define_file. |
| 438 |
We do not know of a producer that uses DW_LNE_define_file. |
| 439 |
|
| 440 |
In DWARF2,3,4 the array of sourcefiles is represented |
| 441 |
differently than DWARF5. |
| 442 |
DWARF 2,3,4, and experimental line table: |
| 443 |
Subtract 1 from the DW_AT_decl_file etc |
| 444 |
to index into the array of names. |
| 445 |
zero means there is no file. |
| 446 |
DWARF 5: |
| 447 |
DW_AT_decl_file etc numbers should be directly |
| 448 |
used to index into the array of names. |
| 449 |
Do not subtract anything. |
| 450 |
For further information |
| 451 |
see the discussion of dwarf_srcfiles() in |
| 452 |
libdwarf2.1.pdf version 3.16 and later, Section |
| 453 |
6.14 around page 117. |
| 454 |
*/ |
| 455 |
int |
| 456 |
dwarf_srcfiles(Dwarf_Die die, |
| 457 |
char ***srcfiles, |
| 458 |
Dwarf_Signed * srcfilecount, |
| 459 |
Dwarf_Error * error) |
| 460 |
{ |
| 461 |
/* This pointer is used to scan the portion of the .debug_line |
| 462 |
section for the current cu. */ |
| 463 |
Dwarf_Small *line_ptr = 0; |
| 464 |
|
| 465 |
/* Pointer to a DW_AT_stmt_list attribute |
| 466 |
in case it exists in the die. */ |
| 467 |
Dwarf_Attribute stmt_list_attr = 0; |
| 468 |
|
| 469 |
const char * const_comp_name = 0; |
| 470 |
/* Pointer to name of compilation directory. */ |
| 471 |
const char * const_comp_dir = 0; |
| 472 |
Dwarf_Small *comp_dir = 0; |
| 473 |
|
| 474 |
/* Offset into .debug_line specified by a DW_AT_stmt_list |
| 475 |
attribute. */ |
| 476 |
Dwarf_Unsigned line_offset = 0; |
| 477 |
|
| 478 |
/* This points to a block of char *'s, each of which points to a |
| 479 |
file name. */ |
| 480 |
char **ret_files = 0; |
| 481 |
|
| 482 |
/* The Dwarf_Debug this die belongs to. */ |
| 483 |
Dwarf_Debug dbg = 0; |
| 484 |
Dwarf_CU_Context context = 0; |
| 485 |
Dwarf_Line_Context line_context = 0; |
| 486 |
|
| 487 |
/* Used to chain the file names. */ |
| 488 |
Dwarf_Chain curr_chain = NULL; |
| 489 |
Dwarf_Chain head_chain = NULL; |
| 490 |
Dwarf_Chain * plast = &head_chain; |
| 491 |
|
| 492 |
Dwarf_Half attrform = 0; |
| 493 |
int resattr = DW_DLV_ERROR; |
| 494 |
int lres = DW_DLV_ERROR; |
| 495 |
unsigned i = 0; |
| 496 |
int res = DW_DLV_ERROR; |
| 497 |
Dwarf_Small *section_start = 0; |
| 498 |
|
| 499 |
/* ***** BEGIN CODE ***** */ |
| 500 |
/* Reset error. */ |
| 501 |
|
| 502 |
if (error != NULL) { |
| 503 |
*error = NULL; |
| 504 |
} |
| 505 |
|
| 506 |
CHECK_DIE(die, DW_DLV_ERROR); |
| 507 |
context = die->di_cu_context; |
| 508 |
dbg = context->cc_dbg; |
| 509 |
|
| 510 |
resattr = dwarf_attr(die, DW_AT_stmt_list, |
| 511 |
&stmt_list_attr, error); |
| 512 |
if (resattr != DW_DLV_OK) { |
| 513 |
return resattr; |
| 514 |
} |
| 515 |
|
| 516 |
if (dbg->de_debug_line.dss_index == 0) { |
| 517 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 518 |
_dwarf_error(dbg, error, DW_DLE_DEBUG_LINE_NULL); |
| 519 |
return DW_DLV_ERROR; |
| 520 |
} |
| 521 |
|
| 522 |
res = _dwarf_load_section(dbg, &dbg->de_debug_line,error); |
| 523 |
if (res != DW_DLV_OK) { |
| 524 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 525 |
return res; |
| 526 |
} |
| 527 |
if (!dbg->de_debug_line.dss_size) { |
| 528 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 529 |
return DW_DLV_NO_ENTRY; |
| 530 |
} |
| 531 |
section_start = dbg->de_debug_line.dss_data; |
| 532 |
|
| 533 |
lres = dwarf_whatform(stmt_list_attr,&attrform,error); |
| 534 |
if (lres != DW_DLV_OK) { |
| 535 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 536 |
return lres; |
| 537 |
} |
| 538 |
if (attrform == DW_FORM_addr) { |
| 539 |
Dwarf_Addr addr = 0; |
| 540 |
/* DW_AT_producer |
| 541 |
4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2.9) |
| 542 |
generated DW_FORM_addr for DW_AT_stmt_list! */ |
| 543 |
lres = dwarf_formaddr(stmt_list_attr,&addr,error); |
| 544 |
if (lres != DW_DLV_OK) { |
| 545 |
if (lres == DW_DLV_ERROR) { |
| 546 |
report_bogus_stmt_list_form(dbg, |
| 547 |
attrform,error); |
| 548 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 549 |
} |
| 550 |
return lres; |
| 551 |
} |
| 552 |
line_offset = (Dwarf_Unsigned)addr; |
| 553 |
} else if (attrform != DW_FORM_data4 && |
| 554 |
attrform != DW_FORM_data8 && |
| 555 |
attrform != DW_FORM_sec_offset && |
| 556 |
attrform != DW_FORM_GNU_ref_alt) { |
| 557 |
report_bogus_stmt_list_form(dbg, |
| 558 |
attrform,error); |
| 559 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 560 |
return DW_DLV_ERROR; |
| 561 |
} else { |
| 562 |
/* standard setup. */ |
| 563 |
lres = dwarf_global_formref(stmt_list_attr, |
| 564 |
&line_offset, error); |
| 565 |
if (lres != DW_DLV_OK) { |
| 566 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 567 |
return lres; |
| 568 |
} |
| 569 |
} |
| 570 |
if (line_offset >= dbg->de_debug_line.dss_size) { |
| 571 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 572 |
_dwarf_error(dbg, error, DW_DLE_LINE_OFFSET_BAD); |
| 573 |
return DW_DLV_ERROR; |
| 574 |
} |
| 575 |
line_ptr = dbg->de_debug_line.dss_data + line_offset; |
| 576 |
{ |
| 577 |
Dwarf_Unsigned fission_offset = 0; |
| 578 |
Dwarf_Unsigned fission_size = 0; |
| 579 |
int resl = _dwarf_get_fission_addition_die(die, DW_SECT_LINE, |
| 580 |
&fission_offset,&fission_size,error); |
| 581 |
if (resl != DW_DLV_OK) { |
| 582 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 583 |
return resl; |
| 584 |
} |
| 585 |
line_ptr += fission_offset; |
| 586 |
if (line_ptr > dbg->de_debug_line.dss_data + |
| 587 |
dbg->de_debug_line.dss_size) { |
| 588 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 589 |
_dwarf_error(dbg, error, DW_DLE_FISSION_ADDITION_ERROR); |
| 590 |
return DW_DLV_ERROR; |
| 591 |
} |
| 592 |
} |
| 593 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 594 |
stmt_list_attr = 0; |
| 595 |
|
| 596 |
resattr = _dwarf_internal_get_die_comp_dir(die, &const_comp_dir, |
| 597 |
&const_comp_name,error); |
| 598 |
if (resattr == DW_DLV_ERROR) { |
| 599 |
return resattr; |
| 600 |
} |
| 601 |
|
| 602 |
/* Horrible cast away const to match historical interfaces. */ |
| 603 |
comp_dir = (Dwarf_Small *)const_comp_dir; |
| 604 |
line_context = (Dwarf_Line_Context) |
| 605 |
_dwarf_get_alloc(dbg, DW_DLA_LINE_CONTEXT, 1); |
| 606 |
if (line_context == NULL) { |
| 607 |
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 608 |
return DW_DLV_ERROR; |
| 609 |
} |
| 610 |
line_context->lc_new_style_access = FALSE; |
| 611 |
/* We are in dwarf_srcfiles() */ |
| 612 |
{ |
| 613 |
Dwarf_Small *line_ptr_out = 0; |
| 614 |
int dres = 0; |
| 615 |
|
| 616 |
dres = _dwarf_read_line_table_header(dbg, |
| 617 |
context, |
| 618 |
section_start, |
| 619 |
line_ptr, |
| 620 |
dbg->de_debug_line.dss_size, |
| 621 |
&line_ptr_out, |
| 622 |
line_context, |
| 623 |
NULL, NULL,error, |
| 624 |
0); |
| 625 |
|
| 626 |
if (dres == DW_DLV_ERROR) { |
| 627 |
dwarf_dealloc(dbg, line_context, DW_DLA_LINE_CONTEXT); |
| 628 |
line_context = 0; |
| 629 |
return dres; |
| 630 |
} |
| 631 |
if (dres == DW_DLV_NO_ENTRY) { |
| 632 |
dwarf_dealloc(dbg, line_context, DW_DLA_LINE_CONTEXT); |
| 633 |
line_context = 0; |
| 634 |
return dres; |
| 635 |
} |
| 636 |
} |
| 637 |
/* For DWARF5, use of DW_AT_comp_dir not needed. |
| 638 |
Line table file names and directories |
| 639 |
start with comp_dir and name. */ |
| 640 |
line_context->lc_compilation_directory = comp_dir; |
| 641 |
/* We are in dwarf_srcfiles() */ |
| 642 |
{ |
| 643 |
Dwarf_File_Entry fe = 0; |
| 644 |
Dwarf_File_Entry fe2 =line_context->lc_file_entries; |
| 645 |
Dwarf_Signed baseindex = 0; |
| 646 |
Dwarf_Signed file_count = 0; |
| 647 |
Dwarf_Signed endindex = 0; |
| 648 |
Dwarf_Signed ifp = 0; |
| 649 |
|
| 650 |
res = dwarf_srclines_files_indexes(line_context, &baseindex, |
| 651 |
&file_count, &endindex, error); |
| 652 |
if (res != DW_DLV_OK) { |
| 653 |
return res; |
| 654 |
} |
| 655 |
for (ifp = baseindex; ifp < endindex; |
| 656 |
++ifp,fe2 = fe->fi_next ) { |
| 657 |
int sres = 0; |
| 658 |
char *name_out = 0; |
| 659 |
|
| 660 |
fe = fe2; |
| 661 |
sres = create_fullest_file_path(dbg,fe,line_context, |
| 662 |
&name_out,error); |
| 663 |
if (sres != DW_DLV_OK) { |
| 664 |
dwarf_dealloc(dbg, line_context, DW_DLA_LINE_CONTEXT); |
| 665 |
/* This can leak some strings */ |
| 666 |
return sres; |
| 667 |
} |
| 668 |
curr_chain = |
| 669 |
(Dwarf_Chain) _dwarf_get_alloc(dbg, DW_DLA_CHAIN, 1); |
| 670 |
if (curr_chain == NULL) { |
| 671 |
dwarf_dealloc(dbg,name_out,DW_DLA_STRING); |
| 672 |
dwarf_dealloc(dbg, line_context, DW_DLA_LINE_CONTEXT); |
| 673 |
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 674 |
return DW_DLV_ERROR; |
| 675 |
} |
| 676 |
curr_chain->ch_item = name_out; |
| 677 |
(*plast) = curr_chain; |
| 678 |
plast = &(curr_chain->ch_next); |
| 679 |
} |
| 680 |
} |
| 681 |
if (!head_chain) { |
| 682 |
dwarf_dealloc(dbg, line_context, DW_DLA_LINE_CONTEXT); |
| 683 |
*srcfiles = NULL; |
| 684 |
*srcfilecount = 0; |
| 685 |
return DW_DLV_NO_ENTRY; |
| 686 |
} |
| 687 |
|
| 688 |
/* We are in dwarf_srcfiles() */ |
| 689 |
if (line_context->lc_file_entry_count == 0) { |
| 690 |
dwarf_dealloc(dbg, line_context, DW_DLA_LINE_CONTEXT); |
| 691 |
*srcfiles = NULL; |
| 692 |
*srcfilecount = 0; |
| 693 |
return DW_DLV_NO_ENTRY; |
| 694 |
} |
| 695 |
|
| 696 |
ret_files = (char **) |
| 697 |
_dwarf_get_alloc(dbg, DW_DLA_LIST, |
| 698 |
line_context->lc_file_entry_count); |
| 699 |
if (ret_files == NULL) { |
| 700 |
dwarf_dealloc(dbg, line_context, DW_DLA_LINE_CONTEXT); |
| 701 |
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 702 |
return DW_DLV_ERROR; |
| 703 |
} |
| 704 |
|
| 705 |
curr_chain = head_chain; |
| 706 |
for (i = 0; i < line_context->lc_file_entry_count; i++) { |
| 707 |
Dwarf_Chain prev = 0; |
| 708 |
*(ret_files + i) = curr_chain->ch_item; |
| 709 |
curr_chain->ch_item = 0; |
| 710 |
prev = curr_chain; |
| 711 |
curr_chain = curr_chain->ch_next; |
| 712 |
dwarf_dealloc(dbg, prev, DW_DLA_CHAIN); |
| 713 |
} |
| 714 |
/* Our chain is not recorded in the line_context so |
| 715 |
the line_context destructor will not destroy our |
| 716 |
list of strings or our strings. |
| 717 |
Our caller has to do the deallocations. */ |
| 718 |
{ |
| 719 |
Dwarf_Signed srccount = |
| 720 |
(Dwarf_Signed)line_context->lc_file_entry_count; |
| 721 |
if (srccount < 0) { |
| 722 |
/* Impossible corruption! */ |
| 723 |
_dwarf_error_string(dbg,error,DW_DLE_LINE_COUNT_WRONG, |
| 724 |
"DW_DLE_LINE_COUNT_WRONG " |
| 725 |
"Call to dwarf_srcfiles finds an impossible " |
| 726 |
"source files count"); |
| 727 |
return DW_DLV_ERROR; |
| 728 |
} |
| 729 |
*srcfiles = ret_files; |
| 730 |
*srcfilecount = srccount; |
| 731 |
} |
| 732 |
dwarf_dealloc(dbg, line_context, DW_DLA_LINE_CONTEXT); |
| 733 |
return DW_DLV_OK; |
| 734 |
} |
| 735 |
|
| 736 |
/* Return DW_DLV_OK if ok. else DW_DLV_NO_ENTRY or DW_DLV_ERROR |
| 737 |
doaddrs is true iff this is being called for |
| 738 |
SGI IRIX rqs processing |
| 739 |
(ie, not a normal libdwarf dwarf_srclines or |
| 740 |
two-level user call at all). |
| 741 |
dolines is true iff this is called by a dwarf_srclines call. |
| 742 |
|
| 743 |
In case of error or NO_ENTRY in this code we use the |
| 744 |
dwarf_srcline_dealloc(line_context) |
| 745 |
and dealloc of DW_DLA_LINE_CONTEXT |
| 746 |
from the new interface for uniformity here. |
| 747 |
*/ |
| 748 |
int |
| 749 |
_dwarf_internal_srclines(Dwarf_Die die, |
| 750 |
Dwarf_Bool is_new_interface, |
| 751 |
Dwarf_Unsigned * version, |
| 752 |
Dwarf_Small * table_count, /* returns 0,1, or 2 */ |
| 753 |
Dwarf_Line_Context *line_context_out, |
| 754 |
Dwarf_Line ** linebuf, |
| 755 |
Dwarf_Signed * linecount, |
| 756 |
Dwarf_Line ** linebuf_actuals, |
| 757 |
Dwarf_Signed * linecount_actuals, |
| 758 |
Dwarf_Bool doaddrs, |
| 759 |
Dwarf_Bool dolines, |
| 760 |
Dwarf_Error * error) |
| 761 |
{ |
| 762 |
/* This pointer is used to scan the portion of the .debug_line |
| 763 |
section for the current cu. */ |
| 764 |
Dwarf_Small *line_ptr = 0; |
| 765 |
|
| 766 |
/* This points to the last byte of the |
| 767 |
.debug_line portion for the current cu. */ |
| 768 |
Dwarf_Small *line_ptr_end = 0; |
| 769 |
|
| 770 |
/* For two-level line tables, this points to the |
| 771 |
first byte of the |
| 772 |
actuals table (and the end of the logicals table) |
| 773 |
for the current cu. */ |
| 774 |
Dwarf_Small *line_ptr_actuals = 0; |
| 775 |
Dwarf_Small *section_start = 0; |
| 776 |
Dwarf_Small *section_end = 0; |
| 777 |
|
| 778 |
/* Pointer to a DW_AT_stmt_list attribute in case |
| 779 |
it exists in the die. */ |
| 780 |
Dwarf_Attribute stmt_list_attr = 0; |
| 781 |
|
| 782 |
const char * const_comp_name = 0; |
| 783 |
/* Pointer to name of compilation directory. */ |
| 784 |
const char * const_comp_dir = NULL; |
| 785 |
Dwarf_Small *comp_dir = NULL; |
| 786 |
|
| 787 |
/* Offset into .debug_line specified by a DW_AT_stmt_list |
| 788 |
attribute. */ |
| 789 |
Dwarf_Unsigned line_offset = 0; |
| 790 |
|
| 791 |
/* Pointer to a Dwarf_Line_Context_s structure that contains the |
| 792 |
context such as file names and include directories for the set |
| 793 |
of lines being generated. |
| 794 |
This is always recorded on an |
| 795 |
DW_LNS_end_sequence operator, |
| 796 |
on all special opcodes, and on DW_LNS_copy. |
| 797 |
*/ |
| 798 |
Dwarf_Line_Context line_context = 0; |
| 799 |
Dwarf_CU_Context cu_context = 0; |
| 800 |
Dwarf_Unsigned fission_offset = 0; |
| 801 |
|
| 802 |
/* The Dwarf_Debug this die belongs to. */ |
| 803 |
Dwarf_Debug dbg = 0; |
| 804 |
int resattr = DW_DLV_ERROR; |
| 805 |
int lres = DW_DLV_ERROR; |
| 806 |
Dwarf_Half address_size = 0; |
| 807 |
Dwarf_Small * orig_line_ptr = 0; |
| 808 |
|
| 809 |
int res = DW_DLV_ERROR; |
| 810 |
|
| 811 |
/* ***** BEGIN CODE ***** */ |
| 812 |
if (error != NULL) { |
| 813 |
*error = NULL; |
| 814 |
} |
| 815 |
|
| 816 |
CHECK_DIE(die, DW_DLV_ERROR); |
| 817 |
cu_context = die->di_cu_context; |
| 818 |
dbg = cu_context->cc_dbg; |
| 819 |
|
| 820 |
res = _dwarf_load_section(dbg, &dbg->de_debug_line,error); |
| 821 |
if (res != DW_DLV_OK) { |
| 822 |
return res; |
| 823 |
} |
| 824 |
if (!dbg->de_debug_line.dss_size) { |
| 825 |
return DW_DLV_NO_ENTRY; |
| 826 |
} |
| 827 |
|
| 828 |
address_size = (Dwarf_Half)_dwarf_get_address_size(dbg, die); |
| 829 |
resattr = dwarf_attr(die, DW_AT_stmt_list, &stmt_list_attr, |
| 830 |
error); |
| 831 |
if (resattr != DW_DLV_OK) { |
| 832 |
return resattr; |
| 833 |
} |
| 834 |
lres = dwarf_global_formref(stmt_list_attr, &line_offset, error); |
| 835 |
if (lres != DW_DLV_OK) { |
| 836 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 837 |
return lres; |
| 838 |
} |
| 839 |
|
| 840 |
if (line_offset >= dbg->de_debug_line.dss_size) { |
| 841 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 842 |
_dwarf_error(dbg, error, DW_DLE_LINE_OFFSET_BAD); |
| 843 |
return DW_DLV_ERROR; |
| 844 |
} |
| 845 |
section_start = dbg->de_debug_line.dss_data; |
| 846 |
section_end = section_start +dbg->de_debug_line.dss_size; |
| 847 |
line_ptr = dbg->de_debug_line.dss_data + line_offset; |
| 848 |
{ |
| 849 |
Dwarf_Unsigned fission_size = 0; |
| 850 |
int resf = _dwarf_get_fission_addition_die(die, DW_SECT_LINE, |
| 851 |
&fission_offset,&fission_size,error); |
| 852 |
if (resf != DW_DLV_OK) { |
| 853 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 854 |
return resf; |
| 855 |
} |
| 856 |
|
| 857 |
/* fission_offset may be 0, and adding 0 to a null pointer |
| 858 |
is undefined behavior with some compilers. */ |
| 859 |
if (fission_offset) { |
| 860 |
line_ptr += fission_offset; |
| 861 |
} |
| 862 |
if (line_ptr > section_end) { |
| 863 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 864 |
_dwarf_error_string(dbg, error, |
| 865 |
DW_DLE_FISSION_ADDITION_ERROR, |
| 866 |
"DW_DLE_FISSION_ADDITION_ERROR: " |
| 867 |
"on retrieving the fission addition value for " |
| 868 |
"adding that into the line table offset " |
| 869 |
"results in running off " |
| 870 |
"the end of the line table. Corrupt DWARF."); |
| 871 |
return DW_DLV_ERROR; |
| 872 |
} |
| 873 |
} |
| 874 |
section_start = dbg->de_debug_line.dss_data; |
| 875 |
section_end = section_start +dbg->de_debug_line.dss_size; |
| 876 |
orig_line_ptr = section_start + line_offset + fission_offset; |
| 877 |
line_ptr = orig_line_ptr; |
| 878 |
dwarf_dealloc(dbg, stmt_list_attr, DW_DLA_ATTR); |
| 879 |
if ((line_offset + fission_offset) > |
| 880 |
dbg->de_debug_line.dss_size) { |
| 881 |
_dwarf_error(dbg, error, DW_DLE_LINE_OFFSET_BAD); |
| 882 |
return DW_DLV_ERROR; |
| 883 |
} |
| 884 |
if (line_ptr > section_end) { |
| 885 |
_dwarf_error(dbg, error, DW_DLE_LINE_OFFSET_BAD); |
| 886 |
return DW_DLV_ERROR; |
| 887 |
} |
| 888 |
|
| 889 |
/* If die has DW_AT_comp_dir attribute, get the string that names |
| 890 |
the compilation directory. */ |
| 891 |
resattr = _dwarf_internal_get_die_comp_dir(die, &const_comp_dir, |
| 892 |
&const_comp_name,error); |
| 893 |
if (resattr == DW_DLV_ERROR) { |
| 894 |
return resattr; |
| 895 |
} |
| 896 |
/* Horrible cast to match historic interfaces. */ |
| 897 |
comp_dir = (Dwarf_Small *)const_comp_dir; |
| 898 |
line_context = (Dwarf_Line_Context) |
| 899 |
_dwarf_get_alloc(dbg, DW_DLA_LINE_CONTEXT, 1); |
| 900 |
if (line_context == NULL) { |
| 901 |
_dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); |
| 902 |
return DW_DLV_ERROR; |
| 903 |
} |
| 904 |
line_context->lc_new_style_access = |
| 905 |
(unsigned char)is_new_interface; |
| 906 |
line_context->lc_compilation_directory = comp_dir; |
| 907 |
/* We are in dwarf_internal_srclines() */ |
| 908 |
{ |
| 909 |
Dwarf_Small *newlinep = 0; |
| 910 |
int resp = _dwarf_read_line_table_header(dbg, |
| 911 |
cu_context, |
| 912 |
section_start, |
| 913 |
line_ptr, |
| 914 |
dbg->de_debug_line.dss_size, |
| 915 |
&newlinep, |
| 916 |
line_context, |
| 917 |
NULL,NULL, |
| 918 |
error, |
| 919 |
0); |
| 920 |
|
| 921 |
if (resp == DW_DLV_ERROR) { |
| 922 |
if (is_new_interface) { |
| 923 |
dwarf_srclines_dealloc_b(line_context); |
| 924 |
} else { |
| 925 |
dwarf_dealloc(dbg,line_context,DW_DLA_LINE_CONTEXT); |
| 926 |
} |
| 927 |
return resp; |
| 928 |
} |
| 929 |
if (resp == DW_DLV_NO_ENTRY) { |
| 930 |
if (is_new_interface) { |
| 931 |
dwarf_srclines_dealloc_b(line_context); |
| 932 |
} else { |
| 933 |
dwarf_dealloc(dbg,line_context,DW_DLA_LINE_CONTEXT); |
| 934 |
} |
| 935 |
return resp; |
| 936 |
} |
| 937 |
line_ptr_end = line_context->lc_line_ptr_end; |
| 938 |
line_ptr = newlinep; |
| 939 |
if (line_context->lc_actuals_table_offset > 0) { |
| 940 |
line_ptr_actuals = line_context->lc_line_prologue_start + |
| 941 |
line_context->lc_actuals_table_offset; |
| 942 |
} |
| 943 |
} |
| 944 |
|
| 945 |
if (line_ptr_actuals == 0) { |
| 946 |
/* ASSERT: lc_table_count == 1 or lc_table_count == 0 */ |
| 947 |
int err_count_out = 0; |
| 948 |
/* Normal style (single level) line table. */ |
| 949 |
Dwarf_Bool is_actuals_table = FALSE; |
| 950 |
Dwarf_Bool local_is_single_table = TRUE; |
| 951 |
res = read_line_table_program(dbg, |
| 952 |
line_ptr, line_ptr_end, orig_line_ptr, |
| 953 |
section_start, |
| 954 |
line_context, |
| 955 |
address_size, doaddrs, dolines, |
| 956 |
local_is_single_table, |
| 957 |
is_actuals_table, |
| 958 |
error, |
| 959 |
&err_count_out); |
| 960 |
if (res != DW_DLV_OK) { |
| 961 |
if (is_new_interface) { |
| 962 |
dwarf_srclines_dealloc_b(line_context); |
| 963 |
} else { |
| 964 |
dwarf_dealloc(dbg,line_context,DW_DLA_LINE_CONTEXT); |
| 965 |
} |
| 966 |
return res; |
| 967 |
} |
| 968 |
if (linebuf) { |
| 969 |
*linebuf = line_context->lc_linebuf_logicals; |
| 970 |
} |
| 971 |
if (linecount) { |
| 972 |
Dwarf_Signed lcl = |
| 973 |
(Dwarf_Signed)line_context->lc_linecount_logicals; |
| 974 |
if (lcl < 0) { |
| 975 |
_dwarf_error_string(dbg,error,DW_DLE_LINE_COUNT_WRONG, |
| 976 |
"DW_DLE_LINE_COUNT_WRONG " |
| 977 |
"Call to dwarf_srclines finds an impossible " |
| 978 |
"lines count"); |
| 979 |
return DW_DLV_ERROR; |
| 980 |
} |
| 981 |
*linecount = lcl; |
| 982 |
} |
| 983 |
if (linebuf_actuals) { |
| 984 |
*linebuf_actuals = NULL; |
| 985 |
} |
| 986 |
if (linecount_actuals) { |
| 987 |
*linecount_actuals = 0; |
| 988 |
} |
| 989 |
} else { |
| 990 |
Dwarf_Bool is_actuals_table = FALSE; |
| 991 |
Dwarf_Bool local2_is_single_table = FALSE; |
| 992 |
int err_count_out = 0; |
| 993 |
|
| 994 |
line_context->lc_is_single_table = FALSE; |
| 995 |
/* Two-level line table. |
| 996 |
First read the logicals table. */ |
| 997 |
res = read_line_table_program(dbg, |
| 998 |
line_ptr, line_ptr_actuals, orig_line_ptr, |
| 999 |
section_start, |
| 1000 |
line_context, |
| 1001 |
address_size, doaddrs, dolines, |
| 1002 |
local2_is_single_table, |
| 1003 |
is_actuals_table, error, |
| 1004 |
&err_count_out); |
| 1005 |
if (res != DW_DLV_OK) { |
| 1006 |
if (is_new_interface) { |
| 1007 |
dwarf_srclines_dealloc_b(line_context); |
| 1008 |
} else { |
| 1009 |
dwarf_dealloc(dbg,line_context,DW_DLA_LINE_CONTEXT); |
| 1010 |
} |
| 1011 |
return res; |
| 1012 |
} |
| 1013 |
|
| 1014 |
if (linecount) { |
| 1015 |
Dwarf_Signed lcl = |
| 1016 |
(Dwarf_Signed)line_context->lc_linecount_logicals; |
| 1017 |
if (lcl < 0) { |
| 1018 |
_dwarf_error_string(dbg,error,DW_DLE_LINE_COUNT_WRONG, |
| 1019 |
"DW_DLE_LINE_COUNT_WRONG " |
| 1020 |
"Call to dwarf_srclines finds an Impossible " |
| 1021 |
"lines count"); |
| 1022 |
return DW_DLV_ERROR; |
| 1023 |
} |
| 1024 |
*linecount = lcl; |
| 1025 |
} |
| 1026 |
if (linebuf) { |
| 1027 |
*linebuf = line_context->lc_linebuf_logicals; |
| 1028 |
} |
| 1029 |
if (is_new_interface) { |
| 1030 |
/* ASSERT: linebuf_actuals == NULL */ |
| 1031 |
is_actuals_table = TRUE; |
| 1032 |
/* The call requested an actuals table |
| 1033 |
and one is present. So now read that one. */ |
| 1034 |
res = read_line_table_program(dbg, |
| 1035 |
|
| 1036 |
line_ptr_actuals, line_ptr_end, orig_line_ptr, |
| 1037 |
section_start, |
| 1038 |
line_context, |
| 1039 |
address_size, doaddrs, dolines, |
| 1040 |
local2_is_single_table, |
| 1041 |
is_actuals_table, error, |
| 1042 |
&err_count_out); |
| 1043 |
if (res != DW_DLV_OK) { |
| 1044 |
dwarf_srclines_dealloc_b(line_context); |
| 1045 |
return res; |
| 1046 |
} |
| 1047 |
if (linebuf_actuals) { |
| 1048 |
*linebuf_actuals = line_context->lc_linebuf_actuals; |
| 1049 |
} |
| 1050 |
if (linecount_actuals) { |
| 1051 |
Dwarf_Signed lca = |
| 1052 |
(Dwarf_Signed)line_context->lc_linecount_actuals; |
| 1053 |
if (lca < 0) { |
| 1054 |
_dwarf_error_string(dbg,error, |
| 1055 |
DW_DLE_LINE_COUNT_WRONG, |
| 1056 |
"DW_DLE_LINE_COUNT_WRONG " |
| 1057 |
"Call to dwarf_srclines finds an Impossible " |
| 1058 |
"lines count"); |
| 1059 |
return DW_DLV_ERROR; |
| 1060 |
} |
| 1061 |
*linecount_actuals = lca; |
| 1062 |
} |
| 1063 |
} |
| 1064 |
} |
| 1065 |
if (!is_new_interface && linecount && |
| 1066 |
(linecount == 0 ||*linecount == 0) && |
| 1067 |
(linecount_actuals == 0 || *linecount_actuals == 0)) { |
| 1068 |
/* Here we have no actual lines of any kind. In other words, |
| 1069 |
it looks like a debugfission |
| 1070 |
(now called split dwarf) line table skeleton or |
| 1071 |
a caller not prepared for skeletons or two-level reading.. |
| 1072 |
In that case there are no line entries so the context |
| 1073 |
had nowhere to be recorded. Hence we have to delete it |
| 1074 |
else we would leak the context. */ |
| 1075 |
dwarf_dealloc(dbg, line_context, DW_DLA_LINE_CONTEXT); |
| 1076 |
line_context = 0; |
| 1077 |
return DW_DLV_OK; |
| 1078 |
} |
| 1079 |
*table_count = line_context->lc_table_count; |
| 1080 |
if (version != NULL) { |
| 1081 |
*version = line_context->lc_version_number; |
| 1082 |
} |
| 1083 |
*line_context_out = line_context; |
| 1084 |
return DW_DLV_OK; |
| 1085 |
} |
| 1086 |
|
| 1087 |
int |
| 1088 |
dwarf_get_ranges_section_name(Dwarf_Debug dbg, |
| 1089 |
const char **section_name_out, |
| 1090 |
Dwarf_Error * error) |
| 1091 |
{ |
| 1092 |
struct Dwarf_Section_s *sec = 0; |
| 1093 |
if (error != NULL) { |
| 1094 |
*error = NULL; |
| 1095 |
} |
| 1096 |
CHECK_DBG(dbg,error,"dwarf_get_ranges_section_name()"); |
| 1097 |
sec = &dbg->de_debug_ranges; |
| 1098 |
if (sec->dss_size == 0) { |
| 1099 |
/* We don't have such a section at all. */ |
| 1100 |
return DW_DLV_NO_ENTRY; |
| 1101 |
} |
| 1102 |
*section_name_out = sec->dss_name; |
| 1103 |
return DW_DLV_OK; |
| 1104 |
} |
| 1105 |
|
| 1106 |
int |
| 1107 |
dwarf_get_aranges_section_name(Dwarf_Debug dbg, |
| 1108 |
const char **section_name_out, |
| 1109 |
Dwarf_Error * error) |
| 1110 |
{ |
| 1111 |
struct Dwarf_Section_s *sec = 0; |
| 1112 |
|
| 1113 |
CHECK_DBG(dbg,error,"dwarf_get_aranges_section_name()"); |
| 1114 |
if (error != NULL) { |
| 1115 |
*error = NULL; |
| 1116 |
} |
| 1117 |
sec = &dbg->de_debug_aranges; |
| 1118 |
if (sec->dss_size == 0) { |
| 1119 |
/* We don't have such a section at all. */ |
| 1120 |
return DW_DLV_NO_ENTRY; |
| 1121 |
} |
| 1122 |
*section_name_out = sec->dss_name; |
| 1123 |
return DW_DLV_OK; |
| 1124 |
} |
| 1125 |
int |
| 1126 |
dwarf_get_line_section_name(Dwarf_Debug dbg, |
| 1127 |
const char **section_name_out, |
| 1128 |
Dwarf_Error * error) |
| 1129 |
{ |
| 1130 |
struct Dwarf_Section_s *sec = 0; |
| 1131 |
|
| 1132 |
CHECK_DBG(dbg,error,"dwarf_get_line_section_name)"); |
| 1133 |
if (error != NULL) { |
| 1134 |
*error = NULL; |
| 1135 |
} |
| 1136 |
sec = &dbg->de_debug_line; |
| 1137 |
if (sec->dss_size == 0) { |
| 1138 |
/* We don't have such a section at all. */ |
| 1139 |
return DW_DLV_NO_ENTRY; |
| 1140 |
} |
| 1141 |
*section_name_out = sec->dss_name; |
| 1142 |
return DW_DLV_OK; |
| 1143 |
} |
| 1144 |
|
| 1145 |
int |
| 1146 |
dwarf_get_line_section_name_from_die(Dwarf_Die die, |
| 1147 |
const char **section_name_out, |
| 1148 |
Dwarf_Error * error) |
| 1149 |
{ |
| 1150 |
/* The Dwarf_Debug this die belongs to. */ |
| 1151 |
Dwarf_Debug dbg = 0; |
| 1152 |
struct Dwarf_Section_s *sec = 0; |
| 1153 |
|
| 1154 |
/* ***** BEGIN CODE ***** */ |
| 1155 |
if (error) { |
| 1156 |
*error = NULL; |
| 1157 |
} |
| 1158 |
|
| 1159 |
CHECK_DIE(die, DW_DLV_ERROR); |
| 1160 |
dbg = die->di_cu_context->cc_dbg; |
| 1161 |
sec = &dbg->de_debug_line; |
| 1162 |
if (sec->dss_size == 0) { |
| 1163 |
/* We don't have such a section at all. */ |
| 1164 |
return DW_DLV_NO_ENTRY; |
| 1165 |
} |
| 1166 |
*section_name_out = sec->dss_name; |
| 1167 |
return DW_DLV_OK; |
| 1168 |
} |
| 1169 |
|
| 1170 |
int |
| 1171 |
dwarf_get_string_section_name(Dwarf_Debug dbg, |
| 1172 |
const char **section_name_out, |
| 1173 |
Dwarf_Error * error) |
| 1174 |
{ |
| 1175 |
struct Dwarf_Section_s *sec = 0; |
| 1176 |
|
| 1177 |
CHECK_DBG(dbg,error,"dwarf_get_string_section_name()"); |
| 1178 |
/* ***** BEGIN CODE ***** */ |
| 1179 |
if (error != NULL) { |
| 1180 |
*error = NULL; |
| 1181 |
} |
| 1182 |
sec = &dbg->de_debug_str; |
| 1183 |
if (sec->dss_size == 0) { |
| 1184 |
/* We don't have such a section at all. */ |
| 1185 |
return DW_DLV_NO_ENTRY; |
| 1186 |
} |
| 1187 |
*section_name_out = sec->dss_name; |
| 1188 |
return DW_DLV_OK; |
| 1189 |
} |
| 1190 |
|
| 1191 |
/* New October 2015. */ |
| 1192 |
int |
| 1193 |
dwarf_srclines_b(Dwarf_Die die, |
| 1194 |
Dwarf_Unsigned * version_out, |
| 1195 |
Dwarf_Small * table_count, |
| 1196 |
Dwarf_Line_Context * line_context, |
| 1197 |
Dwarf_Error * error) |
| 1198 |
{ |
| 1199 |
Dwarf_Signed linecount_actuals = 0; |
| 1200 |
Dwarf_Line *linebuf = 0; |
| 1201 |
Dwarf_Line *linebuf_actuals = 0; |
| 1202 |
Dwarf_Signed linecount = 0; |
| 1203 |
Dwarf_Bool is_new_interface = TRUE; |
| 1204 |
int res = 0; |
| 1205 |
Dwarf_Unsigned tcount = 0; |
| 1206 |
|
| 1207 |
res = _dwarf_internal_srclines(die, |
| 1208 |
is_new_interface, |
| 1209 |
version_out, |
| 1210 |
table_count, |
| 1211 |
line_context, |
| 1212 |
&linebuf, |
| 1213 |
&linecount, |
| 1214 |
&linebuf_actuals, |
| 1215 |
&linecount_actuals, |
| 1216 |
/* addrlist= */ FALSE, |
| 1217 |
/* linelist= */ TRUE, |
| 1218 |
error); |
| 1219 |
if (res == DW_DLV_OK) { |
| 1220 |
(*line_context)->lc_new_style_access = TRUE; |
| 1221 |
} |
| 1222 |
if (linecount_actuals) { |
| 1223 |
tcount++; |
| 1224 |
} |
| 1225 |
if (linecount) { |
| 1226 |
tcount++; |
| 1227 |
} |
| 1228 |
*table_count = (Dwarf_Small)tcount; |
| 1229 |
return res; |
| 1230 |
} |
| 1231 |
|
| 1232 |
/* New October 2015. */ |
| 1233 |
int |
| 1234 |
dwarf_srclines_from_linecontext(Dwarf_Line_Context line_context, |
| 1235 |
Dwarf_Line** linebuf, |
| 1236 |
Dwarf_Signed * linecount, |
| 1237 |
Dwarf_Error * error) |
| 1238 |
{ |
| 1239 |
if (!line_context || line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 1240 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_BOTCH); |
| 1241 |
return DW_DLV_ERROR; |
| 1242 |
} |
| 1243 |
if (!line_context->lc_new_style_access) { |
| 1244 |
_dwarf_error(line_context->lc_dbg, error, |
| 1245 |
DW_DLE_LINE_CONTEXT_BOTCH); |
| 1246 |
return DW_DLV_ERROR; |
| 1247 |
} |
| 1248 |
{ |
| 1249 |
Dwarf_Signed lc = |
| 1250 |
(Dwarf_Signed)line_context->lc_linecount_logicals; |
| 1251 |
if (lc < 0) { |
| 1252 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1253 |
DW_DLE_LINE_COUNT_WRONG, |
| 1254 |
"DW_DLE_LINE_COUNT_WRONG " |
| 1255 |
"Call to dwarf_srclines_from_linecontext " |
| 1256 |
"finds an Impossible " |
| 1257 |
"lines count"); |
| 1258 |
return DW_DLV_ERROR; |
| 1259 |
} |
| 1260 |
*linebuf = line_context->lc_linebuf_logicals; |
| 1261 |
*linecount = lc; |
| 1262 |
} |
| 1263 |
return DW_DLV_OK; |
| 1264 |
} |
| 1265 |
|
| 1266 |
/* New October 2015. */ |
| 1267 |
int |
| 1268 |
dwarf_srclines_two_level_from_linecontext( |
| 1269 |
Dwarf_Line_Context line_context, |
| 1270 |
Dwarf_Line** linebuf, |
| 1271 |
Dwarf_Signed * linecount, |
| 1272 |
Dwarf_Line** linebuf_actuals, |
| 1273 |
Dwarf_Signed * linecount_actuals, |
| 1274 |
Dwarf_Error * error) |
| 1275 |
{ |
| 1276 |
if (!line_context || line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 1277 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_BOTCH); |
| 1278 |
return DW_DLV_ERROR; |
| 1279 |
} |
| 1280 |
if (!line_context->lc_new_style_access) { |
| 1281 |
_dwarf_error(line_context->lc_dbg, error, |
| 1282 |
DW_DLE_LINE_CONTEXT_BOTCH); |
| 1283 |
return DW_DLV_ERROR; |
| 1284 |
} |
| 1285 |
{ |
| 1286 |
Dwarf_Signed lcl = |
| 1287 |
(Dwarf_Signed)line_context->lc_linecount_logicals; |
| 1288 |
Dwarf_Signed lca = |
| 1289 |
(Dwarf_Signed)line_context->lc_linecount_actuals; |
| 1290 |
if (lcl < 0) { |
| 1291 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1292 |
DW_DLE_LINE_COUNT_WRONG, |
| 1293 |
"DW_DLE_LINE_COUNT_WRONG " |
| 1294 |
"Call to dwarf_srclines_two_level_from_linecontext " |
| 1295 |
"finds an Impossible " |
| 1296 |
"lines count"); |
| 1297 |
return DW_DLV_ERROR; |
| 1298 |
} |
| 1299 |
if (lca < 0) { |
| 1300 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1301 |
DW_DLE_LINE_COUNT_WRONG, |
| 1302 |
"DW_DLE_LINE_COUNT_WRONG " |
| 1303 |
"Call to dwarf_srclines_two_level_from_linecontext " |
| 1304 |
"finds an Impossible " |
| 1305 |
"lines count"); |
| 1306 |
return DW_DLV_ERROR; |
| 1307 |
} |
| 1308 |
|
| 1309 |
*linebuf = line_context->lc_linebuf_logicals; |
| 1310 |
*linecount = line_context->lc_linecount_logicals; |
| 1311 |
*linebuf_actuals = line_context->lc_linebuf_actuals; |
| 1312 |
*linecount_actuals = line_context->lc_linecount_actuals; |
| 1313 |
} |
| 1314 |
return DW_DLV_OK; |
| 1315 |
} |
| 1316 |
|
| 1317 |
/* New October 2015. */ |
| 1318 |
int |
| 1319 |
dwarf_srclines_table_offset(Dwarf_Line_Context line_context, |
| 1320 |
Dwarf_Unsigned * offset, |
| 1321 |
Dwarf_Error * error) |
| 1322 |
{ |
| 1323 |
if (!line_context ){ |
| 1324 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_BOTCH); |
| 1325 |
return DW_DLV_ERROR; |
| 1326 |
} |
| 1327 |
if ( line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 1328 |
_dwarf_error(NULL, error, |
| 1329 |
DW_DLE_LINE_CONTEXT_BOTCH); |
| 1330 |
return DW_DLV_ERROR; |
| 1331 |
} |
| 1332 |
*offset = line_context->lc_section_offset; |
| 1333 |
return DW_DLV_OK; |
| 1334 |
} |
| 1335 |
|
| 1336 |
/* New October 2015. */ |
| 1337 |
/* If the CU DIE has no DW_AT_comp_dir then |
| 1338 |
the pointer pushed back to *compilation_directory |
| 1339 |
will be NULL. |
| 1340 |
For DWARF5 the line table header has the compilation |
| 1341 |
directory. */ |
| 1342 |
int |
| 1343 |
dwarf_srclines_comp_dir(Dwarf_Line_Context line_context, |
| 1344 |
const char ** compilation_directory, |
| 1345 |
Dwarf_Error * error) |
| 1346 |
{ |
| 1347 |
if (!line_context ){ |
| 1348 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_BOTCH); |
| 1349 |
return DW_DLV_ERROR; |
| 1350 |
} |
| 1351 |
if (line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 1352 |
_dwarf_error(NULL, error, |
| 1353 |
DW_DLE_LINE_CONTEXT_BOTCH); |
| 1354 |
return DW_DLV_ERROR; |
| 1355 |
} |
| 1356 |
*compilation_directory = |
| 1357 |
(const char *)line_context->lc_compilation_directory; |
| 1358 |
return DW_DLV_OK; |
| 1359 |
} |
| 1360 |
|
| 1361 |
/* New October 2015. */ |
| 1362 |
int |
| 1363 |
dwarf_srclines_subprog_count(Dwarf_Line_Context line_context, |
| 1364 |
Dwarf_Signed * count_out, |
| 1365 |
Dwarf_Error * error) |
| 1366 |
{ |
| 1367 |
if (!line_context ){ |
| 1368 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_BOTCH); |
| 1369 |
return DW_DLV_ERROR; |
| 1370 |
} |
| 1371 |
if (line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 1372 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_BOTCH); |
| 1373 |
return DW_DLV_ERROR; |
| 1374 |
} |
| 1375 |
if (count_out) { |
| 1376 |
Dwarf_Signed co = |
| 1377 |
(Dwarf_Signed) line_context->lc_subprogs_count; |
| 1378 |
if (co < 0) { |
| 1379 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1380 |
DW_DLE_LINE_COUNT_WRONG, |
| 1381 |
"DW_DLE_LINE_COUNT_WRONG " |
| 1382 |
"Call to dwarf_srclines_subprog_count " |
| 1383 |
"finds an Impossible " |
| 1384 |
"subprogs count"); |
| 1385 |
return DW_DLV_ERROR; |
| 1386 |
} |
| 1387 |
*count_out = co; |
| 1388 |
} |
| 1389 |
return DW_DLV_OK; |
| 1390 |
} |
| 1391 |
/* New October 2015. */ |
| 1392 |
/* Index says which to return. Valid indexes are |
| 1393 |
1-lc_subprogs_count |
| 1394 |
*/ |
| 1395 |
int |
| 1396 |
dwarf_srclines_subprog_data(Dwarf_Line_Context line_context, |
| 1397 |
Dwarf_Signed index_in, |
| 1398 |
const char ** name, |
| 1399 |
Dwarf_Unsigned *decl_file, |
| 1400 |
Dwarf_Unsigned *decl_line, |
| 1401 |
Dwarf_Error *error) |
| 1402 |
{ |
| 1403 |
Dwarf_Unsigned index = 0; |
| 1404 |
Dwarf_Subprog_Entry sub = 0; |
| 1405 |
/* Negative values not sensible. Leaving traditional |
| 1406 |
signed interfaces. */ |
| 1407 |
if (index_in < 0) { |
| 1408 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1409 |
DW_DLE_LINE_INDEX_WRONG, |
| 1410 |
"DW_DLE_LINE_INDEX_WRONG " |
| 1411 |
"Call to dwarf_srclines_subprog_data " |
| 1412 |
"finds an Impossible " |
| 1413 |
"index argument value"); |
| 1414 |
return DW_DLV_ERROR; |
| 1415 |
} |
| 1416 |
index = (Dwarf_Unsigned)index_in; |
| 1417 |
if (!line_context || line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 1418 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_BOTCH); |
| 1419 |
return DW_DLV_ERROR; |
| 1420 |
} |
| 1421 |
if (index < 1 || index > line_context->lc_subprogs_count) { |
| 1422 |
_dwarf_error(line_context->lc_dbg, error, |
| 1423 |
DW_DLE_LINE_CONTEXT_INDEX_WRONG); |
| 1424 |
return DW_DLV_ERROR; |
| 1425 |
} |
| 1426 |
sub = line_context->lc_subprogs + (index-1); |
| 1427 |
*name = (const char *)sub->ds_subprog_name; |
| 1428 |
*decl_file = sub->ds_decl_file; |
| 1429 |
*decl_line = sub->ds_decl_line; |
| 1430 |
return DW_DLV_OK; |
| 1431 |
} |
| 1432 |
|
| 1433 |
/* New March 2018 making iteration through file names. */ |
| 1434 |
int |
| 1435 |
dwarf_srclines_files_indexes(Dwarf_Line_Context line_context, |
| 1436 |
Dwarf_Signed *baseindex, |
| 1437 |
Dwarf_Signed *file_count, |
| 1438 |
Dwarf_Signed *endindex, |
| 1439 |
Dwarf_Error * error) |
| 1440 |
{ |
| 1441 |
if (line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 1442 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_BOTCH); |
| 1443 |
return DW_DLV_ERROR; |
| 1444 |
} |
| 1445 |
{ |
| 1446 |
Dwarf_Signed bi = |
| 1447 |
(Dwarf_Signed)line_context->lc_file_entry_baseindex; |
| 1448 |
Dwarf_Signed fc = |
| 1449 |
(Dwarf_Signed)line_context->lc_file_entry_count; |
| 1450 |
Dwarf_Signed ei = |
| 1451 |
(Dwarf_Signed)line_context->lc_file_entry_endindex; |
| 1452 |
if (bi < 0) { |
| 1453 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1454 |
DW_DLE_LINE_INDEX_WRONG, |
| 1455 |
"DW_DLE_LINE_INDEX_WRONG " |
| 1456 |
"Call to dwarf_srclines_subprog_data " |
| 1457 |
"finds an Impossible " |
| 1458 |
"file entry index value"); |
| 1459 |
return DW_DLV_ERROR; |
| 1460 |
} |
| 1461 |
if (fc < 0) { |
| 1462 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1463 |
DW_DLE_LINE_COUNT_WRONG, |
| 1464 |
"DW_DLE_LINE_COUNT_WRONG " |
| 1465 |
"Call to dwarf_srclines_subprog_data " |
| 1466 |
"finds an Impossible " |
| 1467 |
"file count index value"); |
| 1468 |
return DW_DLV_ERROR; |
| 1469 |
} |
| 1470 |
if (ei < 0) { |
| 1471 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1472 |
DW_DLE_LINE_INDEX_WRONG, |
| 1473 |
"DW_DLE_LINE_INDEX_WRONG " |
| 1474 |
"Call to dwarf_srclines_subprog_data " |
| 1475 |
"finds an Impossible " |
| 1476 |
"endindex value"); |
| 1477 |
return DW_DLV_ERROR; |
| 1478 |
} |
| 1479 |
*baseindex = bi; |
| 1480 |
*file_count = fc; |
| 1481 |
*endindex = ei; |
| 1482 |
} |
| 1483 |
return DW_DLV_OK; |
| 1484 |
} |
| 1485 |
|
| 1486 |
int |
| 1487 |
dwarf_srclines_files_data_b(Dwarf_Line_Context line_context, |
| 1488 |
Dwarf_Signed index_in, |
| 1489 |
const char ** name, |
| 1490 |
Dwarf_Unsigned * directory_index, |
| 1491 |
Dwarf_Unsigned * last_mod_time, |
| 1492 |
Dwarf_Unsigned * file_length, |
| 1493 |
Dwarf_Form_Data16 ** data16ptr, |
| 1494 |
Dwarf_Error * error) |
| 1495 |
{ |
| 1496 |
Dwarf_File_Entry fi = 0; |
| 1497 |
Dwarf_Signed i =0; |
| 1498 |
Dwarf_Signed baseindex = 0; |
| 1499 |
Dwarf_Signed file_count = 0; |
| 1500 |
Dwarf_Signed endindex = 0; |
| 1501 |
/* Negative values not sensible. Leaving traditional |
| 1502 |
signed interfaces. */ |
| 1503 |
Dwarf_Signed index = index_in; |
| 1504 |
int res = 0; |
| 1505 |
|
| 1506 |
if (index_in < 0) { |
| 1507 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1508 |
DW_DLE_LINE_INDEX_WRONG, |
| 1509 |
"DW_DLE_LINE_INDEX_WRONG " |
| 1510 |
"Call to dwarf_srclines_files_data_b " |
| 1511 |
"passes an Impossible " |
| 1512 |
"index argument value"); |
| 1513 |
return DW_DLV_ERROR; |
| 1514 |
} |
| 1515 |
if (!line_context || line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 1516 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_BOTCH); |
| 1517 |
return DW_DLV_ERROR; |
| 1518 |
} |
| 1519 |
|
| 1520 |
/* Special accommodation of the special gnu experimental |
| 1521 |
version number (a high number) so we cannot just |
| 1522 |
say '5 or greater'. This is awkward, but at least |
| 1523 |
if there is a version 6 or later it still allows |
| 1524 |
the experimental table. */ |
| 1525 |
res = dwarf_srclines_files_indexes(line_context, &baseindex, |
| 1526 |
&file_count, &endindex, error); |
| 1527 |
if (res != DW_DLV_OK) { |
| 1528 |
return res; |
| 1529 |
} |
| 1530 |
fi = line_context->lc_file_entries; |
| 1531 |
if (baseindex < 0) { |
| 1532 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1533 |
DW_DLE_LINE_INDEX_WRONG, |
| 1534 |
"DW_DLE_LINE_INDEX_WRONG " |
| 1535 |
"Call to dwarf_srclines_file_data_b " |
| 1536 |
"finds an Impossible " |
| 1537 |
"file entry index value"); |
| 1538 |
return DW_DLV_ERROR; |
| 1539 |
} |
| 1540 |
if (file_count < 0) { |
| 1541 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1542 |
DW_DLE_LINE_COUNT_WRONG, |
| 1543 |
"DW_DLE_LINE_COUNT_WRONG " |
| 1544 |
"Call to dwarf_srclines_file_data_b " |
| 1545 |
"finds an Impossible " |
| 1546 |
"file count value"); |
| 1547 |
return DW_DLV_ERROR; |
| 1548 |
} |
| 1549 |
if (endindex < 0) { |
| 1550 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1551 |
DW_DLE_LINE_INDEX_WRONG, |
| 1552 |
"DW_DLE_LINE_INDEX_WRONG " |
| 1553 |
"Call to dwarf_srclines_file_data_b " |
| 1554 |
"finds an Impossible " |
| 1555 |
"endindex value"); |
| 1556 |
return DW_DLV_ERROR; |
| 1557 |
} |
| 1558 |
|
| 1559 |
if (index < baseindex || index >= endindex) { |
| 1560 |
_dwarf_error(line_context->lc_dbg, error, |
| 1561 |
DW_DLE_LINE_CONTEXT_INDEX_WRONG); |
| 1562 |
return DW_DLV_ERROR; |
| 1563 |
} |
| 1564 |
for ( i = baseindex;i < index; i++) { |
| 1565 |
fi = fi->fi_next; |
| 1566 |
if (!fi) { |
| 1567 |
_dwarf_error(line_context->lc_dbg, error, |
| 1568 |
DW_DLE_LINE_HEADER_CORRUPT); |
| 1569 |
return DW_DLV_ERROR; |
| 1570 |
} |
| 1571 |
} |
| 1572 |
|
| 1573 |
if (name) { |
| 1574 |
*name = (const char *)fi->fi_file_name; |
| 1575 |
} |
| 1576 |
if (directory_index) { |
| 1577 |
*directory_index = fi->fi_dir_index; |
| 1578 |
} |
| 1579 |
if (last_mod_time) { |
| 1580 |
*last_mod_time = fi->fi_time_last_mod; |
| 1581 |
} |
| 1582 |
if (file_length) { |
| 1583 |
*file_length = fi->fi_file_length; |
| 1584 |
} |
| 1585 |
if (data16ptr) { |
| 1586 |
if (fi->fi_md5_present) { |
| 1587 |
*data16ptr = &fi->fi_md5_value; |
| 1588 |
} else { |
| 1589 |
*data16ptr = 0; |
| 1590 |
} |
| 1591 |
} |
| 1592 |
return DW_DLV_OK; |
| 1593 |
} |
| 1594 |
|
| 1595 |
/* New October 2015. */ |
| 1596 |
int |
| 1597 |
dwarf_srclines_include_dir_count(Dwarf_Line_Context line_context, |
| 1598 |
Dwarf_Signed * count, |
| 1599 |
Dwarf_Error * error) |
| 1600 |
{ |
| 1601 |
Dwarf_Signed scount = 0; |
| 1602 |
if (!line_context || line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 1603 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_BOTCH); |
| 1604 |
return DW_DLV_ERROR; |
| 1605 |
} |
| 1606 |
scount = (Dwarf_Signed)line_context->lc_include_directories_count; |
| 1607 |
if (scount < 0) { |
| 1608 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1609 |
DW_DLE_LINE_COUNT_WRONG, |
| 1610 |
"DW_DLE_LINE_COUNT_WRONG " |
| 1611 |
"Call to dwarf_srclines_include_dir_count " |
| 1612 |
"finds an Impossible " |
| 1613 |
"include directories count"); |
| 1614 |
return DW_DLV_ERROR; |
| 1615 |
} |
| 1616 |
*count = scount; |
| 1617 |
return DW_DLV_OK; |
| 1618 |
} |
| 1619 |
|
| 1620 |
/* New October 2015. */ |
| 1621 |
int |
| 1622 |
dwarf_srclines_include_dir_data(Dwarf_Line_Context line_context, |
| 1623 |
Dwarf_Signed index_in, |
| 1624 |
const char ** name, |
| 1625 |
Dwarf_Error * error) |
| 1626 |
{ |
| 1627 |
/* It never made sense that the srclines used a signed count. |
| 1628 |
But that cannot be fixed in interfaces for compatibility. |
| 1629 |
So we adjust here. */ |
| 1630 |
Dwarf_Unsigned index = (Dwarf_Unsigned)index_in; |
| 1631 |
unsigned int version = 0; |
| 1632 |
|
| 1633 |
if (index_in < 0) { |
| 1634 |
_dwarf_error_string(line_context->lc_dbg,error, |
| 1635 |
DW_DLE_LINE_INDEX_WRONG, |
| 1636 |
"DW_DLE_LINE_INDEX_WRONG " |
| 1637 |
"Call to dwarf_srclines_include_dir_data " |
| 1638 |
"finds an Impossible " |
| 1639 |
"include directories count"); |
| 1640 |
return DW_DLV_ERROR; |
| 1641 |
} |
| 1642 |
if (!line_context || line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 1643 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_BOTCH); |
| 1644 |
return DW_DLV_ERROR; |
| 1645 |
} |
| 1646 |
version = line_context->lc_version_number; |
| 1647 |
/* Remember that 0xf006 is the version of |
| 1648 |
the experimental line table */ |
| 1649 |
if (version == DW_LINE_VERSION5) { |
| 1650 |
if (index >= line_context->lc_include_directories_count) { |
| 1651 |
_dwarf_error(line_context->lc_dbg, error, |
| 1652 |
DW_DLE_LINE_CONTEXT_INDEX_WRONG); |
| 1653 |
return DW_DLV_ERROR; |
| 1654 |
} |
| 1655 |
*name = (const char *) |
| 1656 |
(line_context->lc_include_directories[index]); |
| 1657 |
} else { |
| 1658 |
if (index < 1 || |
| 1659 |
index > line_context->lc_include_directories_count) { |
| 1660 |
_dwarf_error(line_context->lc_dbg, error, |
| 1661 |
DW_DLE_LINE_CONTEXT_INDEX_WRONG); |
| 1662 |
return DW_DLV_ERROR; |
| 1663 |
} |
| 1664 |
*name = (const char *) |
| 1665 |
(line_context->lc_include_directories[index-1]); |
| 1666 |
} |
| 1667 |
return DW_DLV_OK; |
| 1668 |
} |
| 1669 |
|
| 1670 |
/* New October 2015. */ |
| 1671 |
int |
| 1672 |
dwarf_srclines_version(Dwarf_Line_Context line_context, |
| 1673 |
Dwarf_Unsigned *version_out, |
| 1674 |
Dwarf_Small *table_count_out, |
| 1675 |
Dwarf_Error *error) |
| 1676 |
{ |
| 1677 |
if (!line_context || line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 1678 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_BOTCH); |
| 1679 |
return DW_DLV_ERROR; |
| 1680 |
} |
| 1681 |
*version_out = line_context->lc_version_number; |
| 1682 |
*table_count_out = line_context->lc_table_count; |
| 1683 |
return DW_DLV_OK; |
| 1684 |
} |
| 1685 |
|
| 1686 |
/* Every line table entry (except DW_DLE_end_sequence, |
| 1687 |
which is returned using dwarf_lineendsequence()) |
| 1688 |
potentially has the begin-statement |
| 1689 |
flag marked 'on'. This returns thru *return_bool, |
| 1690 |
the begin-statement flag. */ |
| 1691 |
|
| 1692 |
int |
| 1693 |
dwarf_linebeginstatement(Dwarf_Line line, |
| 1694 |
Dwarf_Bool * return_bool, Dwarf_Error * error) |
| 1695 |
{ |
| 1696 |
if (line == NULL || return_bool == 0) { |
| 1697 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 1698 |
return DW_DLV_ERROR; |
| 1699 |
} |
| 1700 |
|
| 1701 |
*return_bool = (line->li_l_data.li_is_stmt); |
| 1702 |
return DW_DLV_OK; |
| 1703 |
} |
| 1704 |
|
| 1705 |
/* At the end of any contiguous line-table there may be |
| 1706 |
a DW_LNE_end_sequence operator. |
| 1707 |
This returns non-zero thru *return_bool |
| 1708 |
if and only if this 'line' entry was a DW_LNE_end_sequence. |
| 1709 |
|
| 1710 |
Within a compilation unit or function there may be multiple |
| 1711 |
line tables, each ending with a DW_LNE_end_sequence. |
| 1712 |
Each table describes a contiguous region. |
| 1713 |
Because compilers may split function code up in arbitrary ways |
| 1714 |
compilers may need to emit multiple contigous regions (ie |
| 1715 |
line tables) for a single function. |
| 1716 |
See the DWARF3 spec section 6.2. */ |
| 1717 |
int |
| 1718 |
dwarf_lineendsequence(Dwarf_Line line, |
| 1719 |
Dwarf_Bool * return_bool, |
| 1720 |
Dwarf_Error * error) |
| 1721 |
{ |
| 1722 |
if (line == NULL) { |
| 1723 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 1724 |
return DW_DLV_ERROR; |
| 1725 |
} |
| 1726 |
|
| 1727 |
*return_bool = (line->li_l_data.li_end_sequence); |
| 1728 |
return DW_DLV_OK; |
| 1729 |
} |
| 1730 |
|
| 1731 |
/* Each 'line' entry has a line-number. |
| 1732 |
If the entry is a DW_LNE_end_sequence the line-number is |
| 1733 |
meaningless (see dwarf_lineendsequence(), just above). */ |
| 1734 |
int |
| 1735 |
dwarf_lineno(Dwarf_Line line, |
| 1736 |
Dwarf_Unsigned * ret_lineno, Dwarf_Error * error) |
| 1737 |
{ |
| 1738 |
if (line == NULL || ret_lineno == 0) { |
| 1739 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 1740 |
return DW_DLV_ERROR; |
| 1741 |
} |
| 1742 |
|
| 1743 |
*ret_lineno = (line->li_l_data.li_line); |
| 1744 |
return DW_DLV_OK; |
| 1745 |
} |
| 1746 |
|
| 1747 |
/* Each 'line' entry has a file-number, an index |
| 1748 |
into the file table. |
| 1749 |
If the entry is a DW_LNE_end_sequence the index is |
| 1750 |
meaningless (see dwarf_lineendsequence(), just above). |
| 1751 |
The file number returned is an index into the file table |
| 1752 |
produced by dwarf_srcfiles(), but care is required: the |
| 1753 |
li_file begins with 1 for DWARF2,3,4 |
| 1754 |
files, so that the li_file returned here |
| 1755 |
is 1 greater than its index into the dwarf_srcfiles() |
| 1756 |
output array. |
| 1757 |
|
| 1758 |
And entries from DW_LNE_define_file don't appear in |
| 1759 |
the dwarf_srcfiles() output so file indexes from here may exceed |
| 1760 |
the size of the dwarf_srcfiles() output array size. |
| 1761 |
*/ |
| 1762 |
int |
| 1763 |
dwarf_line_srcfileno(Dwarf_Line line, |
| 1764 |
Dwarf_Unsigned * ret_fileno, Dwarf_Error * error) |
| 1765 |
{ |
| 1766 |
if (line == NULL || ret_fileno == 0) { |
| 1767 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 1768 |
return DW_DLV_ERROR; |
| 1769 |
} |
| 1770 |
/* li_file must be <= line->li_context->lc_file_entry_count else |
| 1771 |
it is trash. li_file 0 means not attributable to |
| 1772 |
any source file per dwarf2/3 spec. |
| 1773 |
For DWARF5, li_file < lc_file_entry_count */ |
| 1774 |
*ret_fileno = (line->li_l_data.li_file); |
| 1775 |
return DW_DLV_OK; |
| 1776 |
} |
| 1777 |
|
| 1778 |
/* Each 'line' entry has an is_addr_set attribute. |
| 1779 |
If the entry is a DW_LNE_set_address, return TRUE through |
| 1780 |
the *is_addr_set pointer. */ |
| 1781 |
int |
| 1782 |
dwarf_line_is_addr_set(Dwarf_Line line, |
| 1783 |
Dwarf_Bool *is_addr_set, Dwarf_Error * error) |
| 1784 |
{ |
| 1785 |
if (line == NULL) { |
| 1786 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 1787 |
return DW_DLV_ERROR; |
| 1788 |
} |
| 1789 |
|
| 1790 |
*is_addr_set = (line->li_l_data.li_is_addr_set); |
| 1791 |
return DW_DLV_OK; |
| 1792 |
} |
| 1793 |
|
| 1794 |
/* Each 'line' entry has a line-address. |
| 1795 |
If the entry is a DW_LNE_end_sequence the adddress |
| 1796 |
is one-beyond the last address this contigous region |
| 1797 |
covers, so the address is not inside the region, |
| 1798 |
but is just outside it. */ |
| 1799 |
int |
| 1800 |
dwarf_lineaddr(Dwarf_Line line, |
| 1801 |
Dwarf_Addr * ret_lineaddr, Dwarf_Error * error) |
| 1802 |
{ |
| 1803 |
if (line == NULL || ret_lineaddr == 0) { |
| 1804 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 1805 |
return DW_DLV_ERROR; |
| 1806 |
} |
| 1807 |
|
| 1808 |
*ret_lineaddr = (line->li_address); |
| 1809 |
return DW_DLV_OK; |
| 1810 |
} |
| 1811 |
|
| 1812 |
/* Each 'line' entry has a column-within-line (offset |
| 1813 |
within the line) where the |
| 1814 |
source text begins. |
| 1815 |
If the entry is a DW_LNE_end_sequence the line-number is |
| 1816 |
meaningless (see dwarf_lineendsequence(), just above). |
| 1817 |
Lines of text begin at column 1. The value 0 |
| 1818 |
means the line begins at the left edge of the line. |
| 1819 |
(See the DWARF3 spec, section 6.2.2). |
| 1820 |
So 0 and 1 mean essentially the same thing. |
| 1821 |
dwarf_lineoff_b() is new in December 2011. |
| 1822 |
*/ |
| 1823 |
int |
| 1824 |
dwarf_lineoff_b(Dwarf_Line line, |
| 1825 |
Dwarf_Unsigned * ret_lineoff, Dwarf_Error * error) |
| 1826 |
{ |
| 1827 |
if (line == NULL || ret_lineoff == 0) { |
| 1828 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 1829 |
return DW_DLV_ERROR; |
| 1830 |
} |
| 1831 |
|
| 1832 |
*ret_lineoff = line->li_l_data.li_column; |
| 1833 |
return DW_DLV_OK; |
| 1834 |
} |
| 1835 |
|
| 1836 |
static int |
| 1837 |
_dwarf_filename(Dwarf_Line_Context context, |
| 1838 |
Dwarf_Unsigned fileno_in, |
| 1839 |
char **ret_filename, |
| 1840 |
const char *callername, |
| 1841 |
Dwarf_Error *error) |
| 1842 |
{ |
| 1843 |
Dwarf_Signed i = 0; |
| 1844 |
Dwarf_File_Entry file_entry = 0; |
| 1845 |
Dwarf_Debug dbg = context->lc_dbg; |
| 1846 |
int res = 0; |
| 1847 |
Dwarf_Signed baseindex = 0; |
| 1848 |
Dwarf_Signed file_count = 0; |
| 1849 |
Dwarf_Signed endindex = 0; |
| 1850 |
/* Negative values not sensible. Leaving traditional |
| 1851 |
signed interfaces in place. */ |
| 1852 |
Dwarf_Signed fileno = (Dwarf_Signed)fileno_in; |
| 1853 |
unsigned linetab_version = context->lc_version_number; |
| 1854 |
|
| 1855 |
if (fileno < 0) { |
| 1856 |
dwarfstring m; |
| 1857 |
dwarfstring_constructor(&m); |
| 1858 |
dwarfstring_append_printf_s(&m, |
| 1859 |
"DW_DLE_LINE_COUNT_WRONG " |
| 1860 |
"Call to %s " |
| 1861 |
"finds an Impossible " |
| 1862 |
"file number ", |
| 1863 |
(char *)callername); |
| 1864 |
_dwarf_error_string(dbg,error, |
| 1865 |
DW_DLE_LINE_COUNT_WRONG, |
| 1866 |
dwarfstring_string(&m)); |
| 1867 |
dwarfstring_destructor(&m); |
| 1868 |
return DW_DLV_ERROR; |
| 1869 |
} |
| 1870 |
#if 0 /* erroneous correctness check. Ignore. */ |
| 1871 |
if (fileno_in >= context->lc_file_entry_count) { |
| 1872 |
_dwarf_error_string(dbg,error, DW_DLE_NO_FILE_NAME, |
| 1873 |
"DW_DLE_NO_FILE_NAME " |
| 1874 |
"A file number is too larg. Corrupt dwarf"); |
| 1875 |
return DW_DLV_ERROR; |
| 1876 |
} |
| 1877 |
#endif |
| 1878 |
res = dwarf_srclines_files_indexes(context, &baseindex, |
| 1879 |
&file_count, &endindex, error); |
| 1880 |
if (res != DW_DLV_OK) { |
| 1881 |
return res; |
| 1882 |
} |
| 1883 |
{ |
| 1884 |
Dwarf_Signed bi = |
| 1885 |
(Dwarf_Signed)context->lc_file_entry_baseindex; |
| 1886 |
Dwarf_Signed fc = |
| 1887 |
(Dwarf_Signed)context->lc_file_entry_count; |
| 1888 |
Dwarf_Signed ei = |
| 1889 |
(Dwarf_Signed)context->lc_file_entry_endindex; |
| 1890 |
if (bi < 0) { |
| 1891 |
dwarfstring m; |
| 1892 |
dwarfstring_constructor(&m); |
| 1893 |
dwarfstring_append_printf_s(&m, |
| 1894 |
"DW_DLE_LINE_INDEX_WRONG " |
| 1895 |
"Call to %s " |
| 1896 |
"finds an Impossible " |
| 1897 |
"base index ", |
| 1898 |
(char *)callername); |
| 1899 |
_dwarf_error_string(dbg,error, |
| 1900 |
DW_DLE_LINE_COUNT_WRONG, |
| 1901 |
dwarfstring_string(&m)); |
| 1902 |
dwarfstring_destructor(&m); |
| 1903 |
return DW_DLV_ERROR; |
| 1904 |
} |
| 1905 |
if (fc < 0) { |
| 1906 |
dwarfstring m; |
| 1907 |
dwarfstring_constructor(&m); |
| 1908 |
dwarfstring_append_printf_s(&m, |
| 1909 |
"DW_DLE_LINE_COUNT_WRONG " |
| 1910 |
"Call to %s " |
| 1911 |
"finds an Impossible " |
| 1912 |
"file entry count ", |
| 1913 |
(char *)callername); |
| 1914 |
_dwarf_error_string(dbg,error, |
| 1915 |
DW_DLE_LINE_COUNT_WRONG, |
| 1916 |
dwarfstring_string(&m)); |
| 1917 |
dwarfstring_destructor(&m); |
| 1918 |
return DW_DLV_ERROR; |
| 1919 |
} |
| 1920 |
if (ei < 0) { |
| 1921 |
dwarfstring m; |
| 1922 |
dwarfstring_constructor(&m); |
| 1923 |
dwarfstring_append_printf_s(&m, |
| 1924 |
"DW_DLE_LINE_INDEX_WRONG " |
| 1925 |
"Call to %s " |
| 1926 |
"finds an Impossible " |
| 1927 |
"end index ", |
| 1928 |
(char *)callername); |
| 1929 |
_dwarf_error_string(dbg,error, |
| 1930 |
DW_DLE_LINE_COUNT_WRONG, |
| 1931 |
dwarfstring_string(&m)); |
| 1932 |
dwarfstring_destructor(&m); |
| 1933 |
return DW_DLV_ERROR; |
| 1934 |
} |
| 1935 |
} |
| 1936 |
|
| 1937 |
/* FIXME: what about comparing to file_count? */ |
| 1938 |
if (fileno >= endindex) { |
| 1939 |
dwarfstring m; /* ok constructor_fixed */ |
| 1940 |
|
| 1941 |
dwarfstring_constructor_fixed(&m, 200); |
| 1942 |
dwarfstring_append_printf_i(&m, |
| 1943 |
"DW_DLE_NO_FILE_NAME: the file number is %d ", |
| 1944 |
fileno); |
| 1945 |
dwarfstring_append_printf_u(&m, |
| 1946 |
"( this is a DWARF 0x%x linetable)", |
| 1947 |
linetab_version); |
| 1948 |
dwarfstring_append_printf_i(&m, |
| 1949 |
" yet the highest allowed file name index is %d.", |
| 1950 |
endindex-1); |
| 1951 |
_dwarf_error_string(dbg, error, DW_DLE_NO_FILE_NAME, |
| 1952 |
dwarfstring_string(&m)); |
| 1953 |
dwarfstring_destructor(&m); |
| 1954 |
return DW_DLV_ERROR; |
| 1955 |
} else { |
| 1956 |
if (linetab_version <= DW_LINE_VERSION4 || |
| 1957 |
linetab_version == EXPERIMENTAL_LINE_TABLES_VERSION) { |
| 1958 |
if (!fileno) { |
| 1959 |
return DW_DLV_NO_ENTRY; |
| 1960 |
} else { |
| 1961 |
/* else ok */ |
| 1962 |
} |
| 1963 |
} else { |
| 1964 |
/* Remember that 0xf006 is the version of |
| 1965 |
the experimental line table */ |
| 1966 |
/* DW_LINE_VERSION5 so file index 0 is fine */ |
| 1967 |
} |
| 1968 |
} |
| 1969 |
|
| 1970 |
file_entry = context->lc_file_entries; |
| 1971 |
/* zero fileno allowed for DWARF5 table. For DWARF4, |
| 1972 |
zero fileno handled above. */ |
| 1973 |
for (i = baseindex; i < fileno ; i++) { |
| 1974 |
file_entry = file_entry->fi_next; |
| 1975 |
} |
| 1976 |
|
| 1977 |
res = create_fullest_file_path(dbg, |
| 1978 |
file_entry,context, ret_filename,error); |
| 1979 |
return res; |
| 1980 |
} |
| 1981 |
|
| 1982 |
int |
| 1983 |
dwarf_linesrc(Dwarf_Line line, char **ret_linesrc, |
| 1984 |
Dwarf_Error * error) |
| 1985 |
{ |
| 1986 |
if (line == NULL) { |
| 1987 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 1988 |
return DW_DLV_ERROR; |
| 1989 |
} |
| 1990 |
if (line->li_context == NULL) { |
| 1991 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_NULL); |
| 1992 |
return DW_DLV_ERROR; |
| 1993 |
} |
| 1994 |
return _dwarf_filename(line->li_context, |
| 1995 |
line->li_l_data.li_file, ret_linesrc, |
| 1996 |
"dwarf_linesrc",error); |
| 1997 |
} |
| 1998 |
|
| 1999 |
/* Every line table entry potentially has the basic-block-start |
| 2000 |
flag marked 'on'. This returns thru *return_bool, |
| 2001 |
the basic-block-start flag. |
| 2002 |
*/ |
| 2003 |
int |
| 2004 |
dwarf_lineblock(Dwarf_Line line, |
| 2005 |
Dwarf_Bool * return_bool, Dwarf_Error * error) |
| 2006 |
{ |
| 2007 |
if (line == NULL) { |
| 2008 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 2009 |
return DW_DLV_ERROR; |
| 2010 |
} |
| 2011 |
*return_bool = (line->li_l_data.li_basic_block); |
| 2012 |
return DW_DLV_OK; |
| 2013 |
} |
| 2014 |
|
| 2015 |
/* We gather these into one call as it's likely one |
| 2016 |
will want all or none of them. */ |
| 2017 |
int |
| 2018 |
dwarf_prologue_end_etc(Dwarf_Line line, |
| 2019 |
Dwarf_Bool * prologue_end, |
| 2020 |
Dwarf_Bool * epilogue_begin, |
| 2021 |
Dwarf_Unsigned * isa, |
| 2022 |
Dwarf_Unsigned * discriminator, |
| 2023 |
Dwarf_Error * error) |
| 2024 |
{ |
| 2025 |
if (line == NULL) { |
| 2026 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 2027 |
return DW_DLV_ERROR; |
| 2028 |
} |
| 2029 |
*prologue_end = line->li_l_data.li_prologue_end; |
| 2030 |
*epilogue_begin = |
| 2031 |
line->li_l_data.li_epilogue_begin; |
| 2032 |
*isa = line->li_l_data.li_isa; |
| 2033 |
*discriminator = line->li_l_data.li_discriminator; |
| 2034 |
return DW_DLV_OK; |
| 2035 |
} |
| 2036 |
|
| 2037 |
int |
| 2038 |
dwarf_linelogical(Dwarf_Line line, |
| 2039 |
Dwarf_Unsigned * logical, |
| 2040 |
Dwarf_Error* error) |
| 2041 |
{ |
| 2042 |
if (line == NULL) { |
| 2043 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 2044 |
return DW_DLV_ERROR; |
| 2045 |
} |
| 2046 |
*logical = line->li_l_data.li_line; |
| 2047 |
return DW_DLV_OK; |
| 2048 |
} |
| 2049 |
|
| 2050 |
int |
| 2051 |
dwarf_linecontext(Dwarf_Line line, |
| 2052 |
Dwarf_Unsigned * context, |
| 2053 |
Dwarf_Error* error) |
| 2054 |
{ |
| 2055 |
if (line == NULL) { |
| 2056 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 2057 |
return DW_DLV_ERROR; |
| 2058 |
} |
| 2059 |
*context = (line->li_l_data.li_call_context); |
| 2060 |
return DW_DLV_OK; |
| 2061 |
} |
| 2062 |
|
| 2063 |
int |
| 2064 |
dwarf_line_subprogno(Dwarf_Line line, |
| 2065 |
Dwarf_Unsigned * subprog, |
| 2066 |
Dwarf_Error * error) |
| 2067 |
{ |
| 2068 |
if (line == NULL) { |
| 2069 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 2070 |
return DW_DLV_ERROR; |
| 2071 |
} |
| 2072 |
*subprog = (line->li_l_data.li_subprogram); |
| 2073 |
return DW_DLV_OK; |
| 2074 |
} |
| 2075 |
|
| 2076 |
int |
| 2077 |
dwarf_line_subprog(Dwarf_Line line, |
| 2078 |
char ** subprog_name, |
| 2079 |
char ** decl_filename, |
| 2080 |
Dwarf_Unsigned * decl_line, |
| 2081 |
Dwarf_Error * error) |
| 2082 |
{ |
| 2083 |
Dwarf_Unsigned subprog_no; |
| 2084 |
Dwarf_Subprog_Entry subprog; |
| 2085 |
Dwarf_Debug dbg; |
| 2086 |
int res; |
| 2087 |
|
| 2088 |
if (line == NULL) { |
| 2089 |
_dwarf_error(NULL, error, DW_DLE_DWARF_LINE_NULL); |
| 2090 |
return DW_DLV_ERROR; |
| 2091 |
} |
| 2092 |
if (line->li_context == NULL) { |
| 2093 |
_dwarf_error(NULL, error, DW_DLE_LINE_CONTEXT_NULL); |
| 2094 |
return DW_DLV_ERROR; |
| 2095 |
} |
| 2096 |
dbg = line->li_context->lc_dbg; |
| 2097 |
subprog_no = line->li_l_data.li_subprogram; |
| 2098 |
if (subprog_no == 0) { |
| 2099 |
*subprog_name = NULL; |
| 2100 |
*decl_filename = NULL; |
| 2101 |
*decl_line = 0; |
| 2102 |
return DW_DLV_OK; |
| 2103 |
} |
| 2104 |
if (subprog_no > line->li_context->lc_subprogs_count) { |
| 2105 |
_dwarf_error(dbg, error, DW_DLE_NO_FILE_NAME); |
| 2106 |
return DW_DLV_ERROR; |
| 2107 |
} |
| 2108 |
/* Adjusting for 1 origin subprog no */ |
| 2109 |
subprog = &line->li_context->lc_subprogs[subprog_no - 1]; |
| 2110 |
*subprog_name = (char *)subprog->ds_subprog_name; |
| 2111 |
*decl_line = subprog->ds_decl_line; |
| 2112 |
res = _dwarf_filename(line->li_context, |
| 2113 |
subprog->ds_decl_file, |
| 2114 |
decl_filename, |
| 2115 |
"dwarf_line_subprog",error); |
| 2116 |
if (res != DW_DLV_OK) { |
| 2117 |
*decl_filename = NULL; |
| 2118 |
return res; |
| 2119 |
} |
| 2120 |
return DW_DLV_OK; |
| 2121 |
} |
| 2122 |
|
| 2123 |
/* This is another line_context_destructor. */ |
| 2124 |
static void |
| 2125 |
delete_line_context_itself(Dwarf_Line_Context context) |
| 2126 |
{ |
| 2127 |
|
| 2128 |
Dwarf_Debug dbg = 0; |
| 2129 |
Dwarf_File_Entry fe = 0; |
| 2130 |
|
| 2131 |
if (context->lc_magic != DW_CONTEXT_MAGIC) { |
| 2132 |
/* Something is wrong. */ |
| 2133 |
return; |
| 2134 |
} |
| 2135 |
dbg = context->lc_dbg; |
| 2136 |
fe = context->lc_file_entries; |
| 2137 |
while (fe) { |
| 2138 |
Dwarf_File_Entry fenext = fe->fi_next; |
| 2139 |
fe->fi_next = 0; |
| 2140 |
free(fe); |
| 2141 |
fe = fenext; |
| 2142 |
} |
| 2143 |
context->lc_file_entries = 0; |
| 2144 |
context->lc_file_entry_count = 0; |
| 2145 |
context->lc_file_entry_baseindex = 0; |
| 2146 |
context->lc_file_entry_endindex = 0; |
| 2147 |
if (context->lc_subprogs) { |
| 2148 |
free(context->lc_subprogs); |
| 2149 |
context->lc_subprogs = 0; |
| 2150 |
} |
| 2151 |
free(context->lc_directory_format_values); |
| 2152 |
context->lc_directory_format_values = 0; |
| 2153 |
free(context->lc_file_format_values); |
| 2154 |
context->lc_file_format_values = 0; |
| 2155 |
if (context->lc_include_directories) { |
| 2156 |
free(context->lc_include_directories); |
| 2157 |
context->lc_include_directories = 0; |
| 2158 |
} |
| 2159 |
context->lc_magic = 0xdead; |
| 2160 |
dwarf_dealloc(dbg, context, DW_DLA_LINE_CONTEXT); |
| 2161 |
} |
| 2162 |
|
| 2163 |
/* It's impossible for callers of dwarf_srclines() to get to and |
| 2164 |
free all the resources (in particular, the li_context and its |
| 2165 |
lc_file_entries). |
| 2166 |
So this function, new July 2005, does it. |
| 2167 |
|
| 2168 |
Those using standard DWARF should use |
| 2169 |
dwarf_srclines_b() and dwarf_srclines_dealloc_b() |
| 2170 |
instead of dwarf_srclines and dwarf_srclines_dealloc() |
| 2171 |
as that gives access to various bits of useful information. |
| 2172 |
|
| 2173 |
New October 2015. |
| 2174 |
This should be used to deallocate all |
| 2175 |
lines data that is |
| 2176 |
set up by dwarf_srclines_b(). |
| 2177 |
This and dwarf_srclines_b() are now (October 2015) |
| 2178 |
the preferred routine to use. */ |
| 2179 |
void |
| 2180 |
dwarf_srclines_dealloc_b(Dwarf_Line_Context line_context) |
| 2181 |
{ |
| 2182 |
Dwarf_Line *linestable = 0; |
| 2183 |
Dwarf_Signed linescount = 0; |
| 2184 |
Dwarf_Signed i = 0; |
| 2185 |
Dwarf_Debug dbg = 0; |
| 2186 |
|
| 2187 |
if (!line_context) { |
| 2188 |
return; |
| 2189 |
} |
| 2190 |
if (!line_context || line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 2191 |
/* Something is badly wrong here.*/ |
| 2192 |
return; |
| 2193 |
} |
| 2194 |
dbg = line_context->lc_dbg; |
| 2195 |
linestable = line_context->lc_linebuf_logicals; |
| 2196 |
if (linestable) { |
| 2197 |
linescount = line_context->lc_linecount_logicals; |
| 2198 |
if (linescount >= 0) { |
| 2199 |
for (i = 0; i < linescount ; ++i) { |
| 2200 |
dwarf_dealloc(dbg, linestable[i], DW_DLA_LINE); |
| 2201 |
} |
| 2202 |
} /* else bogus negative count. do not dealloc things. */ |
| 2203 |
dwarf_dealloc(dbg, linestable, DW_DLA_LIST); |
| 2204 |
} |
| 2205 |
line_context->lc_linebuf_logicals = 0; |
| 2206 |
line_context->lc_linecount_logicals = 0; |
| 2207 |
|
| 2208 |
linestable = line_context->lc_linebuf_actuals; |
| 2209 |
if (linestable) { |
| 2210 |
linescount = line_context->lc_linecount_actuals; |
| 2211 |
if (linescount >= 0) { |
| 2212 |
for (i = 0; i <linescount ; ++i) { |
| 2213 |
dwarf_dealloc(dbg, linestable[i], DW_DLA_LINE); |
| 2214 |
} |
| 2215 |
} /* else bogus negative count. do not dealloc things. */ |
| 2216 |
dwarf_dealloc(dbg, linestable, DW_DLA_LIST); |
| 2217 |
} |
| 2218 |
line_context->lc_linebuf_actuals = 0; |
| 2219 |
line_context->lc_linecount_actuals = 0; |
| 2220 |
delete_line_context_itself(line_context); |
| 2221 |
} |
| 2222 |
|
| 2223 |
/* There is an error, so count it. If we are printing |
| 2224 |
errors by command line option, print the details. */ |
| 2225 |
void |
| 2226 |
_dwarf_print_header_issue(Dwarf_Debug dbg, |
| 2227 |
const char *specific_msg, |
| 2228 |
Dwarf_Small *data_start, |
| 2229 |
Dwarf_Signed value, |
| 2230 |
unsigned index, |
| 2231 |
unsigned tabv, |
| 2232 |
unsigned linetabv, |
| 2233 |
int *err_count_out) |
| 2234 |
{ |
| 2235 |
if (!err_count_out) { |
| 2236 |
return; |
| 2237 |
} |
| 2238 |
/* Are we in verbose mode */ |
| 2239 |
if (dwarf_cmdline_options.check_verbose_mode){ |
| 2240 |
dwarfstring m1; |
| 2241 |
|
| 2242 |
dwarfstring_constructor(&m1); |
| 2243 |
dwarfstring_append(&m1, |
| 2244 |
"\n*** DWARF CHECK: " |
| 2245 |
".debug_line: "); |
| 2246 |
dwarfstring_append(&m1,(char *)specific_msg); |
| 2247 |
dwarfstring_append_printf_i(&m1, |
| 2248 |
" %" DW_PR_DSd,value); |
| 2249 |
if (index || tabv || linetabv) { |
| 2250 |
dwarfstring_append_printf_u(&m1, |
| 2251 |
"; Mismatch index %u",index); |
| 2252 |
dwarfstring_append_printf_u(&m1, |
| 2253 |
" stdval %u",tabv); |
| 2254 |
dwarfstring_append_printf_u(&m1, |
| 2255 |
" linetabval %u",linetabv); |
| 2256 |
} |
| 2257 |
if (data_start >= dbg->de_debug_line.dss_data && |
| 2258 |
(data_start < (dbg->de_debug_line.dss_data + |
| 2259 |
dbg->de_debug_line.dss_size))) { |
| 2260 |
Dwarf_Unsigned off = |
| 2261 |
data_start - dbg->de_debug_line.dss_data; |
| 2262 |
|
| 2263 |
dwarfstring_append_printf_u(&m1, |
| 2264 |
" at offset 0x%" DW_PR_XZEROS DW_PR_DUx,off); |
| 2265 |
dwarfstring_append_printf_u(&m1, |
| 2266 |
" ( %" DW_PR_DUu " ) ",off); |
| 2267 |
} else { |
| 2268 |
dwarfstring_append(&m1, |
| 2269 |
" (unknown section location) "); |
| 2270 |
} |
| 2271 |
dwarfstring_append(&m1,"***\n"); |
| 2272 |
_dwarf_printf(dbg,dwarfstring_string(&m1)); |
| 2273 |
dwarfstring_destructor(&m1); |
| 2274 |
} |
| 2275 |
*err_count_out += 1; |
| 2276 |
} |
| 2277 |
|
| 2278 |
void |
| 2279 |
_dwarf_report_bad_lnct( Dwarf_Debug dbg, |
| 2280 |
Dwarf_Unsigned ltype, |
| 2281 |
int dlecode, |
| 2282 |
const char *dlename, |
| 2283 |
Dwarf_Error *error) |
| 2284 |
{ |
| 2285 |
dwarfstring m; /* constructor_static ok */ |
| 2286 |
dwarfstring f2; /* constructor_static ok */ |
| 2287 |
const char *typename = 0; |
| 2288 |
char tnbuf[48]; |
| 2289 |
char mnbuf[100]; |
| 2290 |
|
| 2291 |
dwarfstring_constructor_static(&f2,tnbuf,sizeof(tnbuf)); |
| 2292 |
dwarf_get_LNCT_name((unsigned int)ltype,&typename); |
| 2293 |
if (!typename) { |
| 2294 |
dwarfstring_append_printf_u(&f2, |
| 2295 |
"Invalid attribute " |
| 2296 |
" 0x" DW_PR_DUx,ltype); |
| 2297 |
} else { |
| 2298 |
dwarfstring_append(&f2,(char *)typename); |
| 2299 |
} |
| 2300 |
dwarfstring_constructor_static(&m,mnbuf,sizeof(mnbuf)); |
| 2301 |
dwarfstring_append_printf_s(&m, |
| 2302 |
"%s: Unexpected DW_LNCT type",(char *)dlename); |
| 2303 |
dwarfstring_append_printf_s(&m, |
| 2304 |
" %s ", |
| 2305 |
dwarfstring_string(&f2)); |
| 2306 |
_dwarf_error_string(dbg, error, dlecode, |
| 2307 |
dwarfstring_string(&m)); |
| 2308 |
dwarfstring_destructor(&m); |
| 2309 |
dwarfstring_destructor(&f2); |
| 2310 |
} |
| 2311 |
|
| 2312 |
static void |
| 2313 |
report_ltype_form_issue(Dwarf_Debug dbg, |
| 2314 |
Dwarf_Half ltype, |
| 2315 |
Dwarf_Half form, |
| 2316 |
const char *splmsg, |
| 2317 |
Dwarf_Error *error) |
| 2318 |
{ |
| 2319 |
dwarfstring m; /* constructor_fixed ok */ |
| 2320 |
dwarfstring f2; /* construcot_static ok */ |
| 2321 |
dwarfstring f; /* construcot_static ok */ |
| 2322 |
const char *formname = 0; |
| 2323 |
const char *typename = 0; |
| 2324 |
char fnbuf[32]; |
| 2325 |
char f2buf[32]; |
| 2326 |
char mbuf[120]; |
| 2327 |
|
| 2328 |
dwarfstring_constructor_static(&f,fnbuf,sizeof(fnbuf)); |
| 2329 |
dwarfstring_constructor_static(&f2,f2buf,sizeof(f2buf)); |
| 2330 |
dwarf_get_LNCT_name(ltype,&typename); |
| 2331 |
if (!typename) { |
| 2332 |
dwarfstring_append_printf_u(&f2, |
| 2333 |
"Invalid DW_LNCT " |
| 2334 |
" 0x" DW_PR_DUx,ltype); |
| 2335 |
} else { |
| 2336 |
dwarfstring_append(&f2,(char *)typename); |
| 2337 |
} |
| 2338 |
dwarf_get_FORM_name(form,&formname); |
| 2339 |
if (!formname) { |
| 2340 |
dwarfstring_append_printf_u(&f, |
| 2341 |
"Invalid Form Code " |
| 2342 |
" 0x" DW_PR_DUx,form); |
| 2343 |
} else { |
| 2344 |
dwarfstring_append(&f,(char *)formname); |
| 2345 |
} |
| 2346 |
dwarfstring_constructor_static(&m,mbuf,sizeof(mbuf)); |
| 2347 |
dwarfstring_append_printf_s(&m, |
| 2348 |
"DW_DLE_LNCT_FORM_CODE_NOT_HANDLED: form %s " |
| 2349 |
"instead of a specifically " |
| 2350 |
"allowed offset form", |
| 2351 |
dwarfstring_string(&f)); |
| 2352 |
dwarfstring_append_printf_s(&m, |
| 2353 |
" on line type %s", |
| 2354 |
dwarfstring_string(&f2)); |
| 2355 |
if (splmsg) { |
| 2356 |
dwarfstring_append(&m," "); |
| 2357 |
dwarfstring_append(&m,(char *)splmsg); |
| 2358 |
} |
| 2359 |
_dwarf_error_string(dbg, error, |
| 2360 |
DW_DLE_LNCT_FORM_CODE_NOT_HANDLED, |
| 2361 |
dwarfstring_string(&m)); |
| 2362 |
dwarfstring_destructor(&m); |
| 2363 |
dwarfstring_destructor(&f); |
| 2364 |
dwarfstring_destructor(&f2); |
| 2365 |
} |
| 2366 |
|
| 2367 |
int |
| 2368 |
_dwarf_decode_line_string_form(Dwarf_Debug dbg, |
| 2369 |
Dwarf_Unsigned ltype, |
| 2370 |
Dwarf_Unsigned form, |
| 2371 |
Dwarf_Unsigned offset_size, |
| 2372 |
Dwarf_Small **line_ptr, |
| 2373 |
Dwarf_Small *line_ptr_end, |
| 2374 |
char **return_str, |
| 2375 |
Dwarf_Error * error) |
| 2376 |
{ |
| 2377 |
int res = 0; |
| 2378 |
|
| 2379 |
switch (form) { |
| 2380 |
case DW_FORM_line_strp: { |
| 2381 |
Dwarf_Small *secstart = 0; |
| 2382 |
Dwarf_Small *secend = 0; |
| 2383 |
Dwarf_Small *strptr = 0; |
| 2384 |
Dwarf_Unsigned offset = 0; |
| 2385 |
Dwarf_Small *offsetptr = *line_ptr; |
| 2386 |
|
| 2387 |
res = _dwarf_load_section(dbg, |
| 2388 |
&dbg->de_debug_line_str,error); |
| 2389 |
if (res != DW_DLV_OK) { |
| 2390 |
return res; |
| 2391 |
} |
| 2392 |
|
| 2393 |
secstart = dbg->de_debug_line_str.dss_data; |
| 2394 |
secend = secstart + dbg->de_debug_line_str.dss_size; |
| 2395 |
|
| 2396 |
READ_UNALIGNED_CK(dbg, offset, Dwarf_Unsigned, |
| 2397 |
offsetptr, offset_size, |
| 2398 |
error,line_ptr_end); |
| 2399 |
*line_ptr += offset_size; |
| 2400 |
strptr = secstart + offset; |
| 2401 |
res = _dwarf_check_string_valid(dbg, |
| 2402 |
secstart,strptr,secend, |
| 2403 |
DW_DLE_LINE_STRP_OFFSET_BAD,error); |
| 2404 |
if (res != DW_DLV_OK) { |
| 2405 |
return res; |
| 2406 |
} |
| 2407 |
*return_str = (char *) strptr; |
| 2408 |
return DW_DLV_OK; |
| 2409 |
} |
| 2410 |
case DW_FORM_string: { |
| 2411 |
Dwarf_Small *secend = line_ptr_end; |
| 2412 |
Dwarf_Small *strptr = *line_ptr; |
| 2413 |
|
| 2414 |
res = _dwarf_check_string_valid(dbg, |
| 2415 |
strptr ,strptr,secend, |
| 2416 |
DW_DLE_LINE_STRING_BAD,error); |
| 2417 |
if (res != DW_DLV_OK) { |
| 2418 |
return res; |
| 2419 |
} |
| 2420 |
*return_str = (char *)strptr; |
| 2421 |
*line_ptr += strlen((const char *)strptr) + 1; |
| 2422 |
return DW_DLV_OK; |
| 2423 |
} |
| 2424 |
default: |
| 2425 |
report_ltype_form_issue(dbg, (Dwarf_Half)ltype, |
| 2426 |
(Dwarf_Half)form,0,error); |
| 2427 |
return DW_DLV_ERROR; |
| 2428 |
} |
| 2429 |
} |
| 2430 |
|
| 2431 |
int |
| 2432 |
_dwarf_decode_line_udata_form(Dwarf_Debug dbg, |
| 2433 |
Dwarf_Unsigned ltype, |
| 2434 |
Dwarf_Unsigned form, |
| 2435 |
Dwarf_Small **line_ptr, |
| 2436 |
Dwarf_Unsigned *return_val, |
| 2437 |
Dwarf_Small *line_end_ptr, |
| 2438 |
Dwarf_Error * error) |
| 2439 |
{ |
| 2440 |
Dwarf_Unsigned val = 0; |
| 2441 |
Dwarf_Small * lp = *line_ptr; |
| 2442 |
const char *splmsg = 0; |
| 2443 |
|
| 2444 |
/* We will not get here for DW_LNCT_MD5, |
| 2445 |
no need to consider DW_FORM_data16. */ |
| 2446 |
switch (form) { |
| 2447 |
case DW_FORM_udata: |
| 2448 |
if (ltype != DW_LNCT_directory_index && |
| 2449 |
ltype != DW_LNCT_timestamp && |
| 2450 |
ltype != DW_LNCT_GNU_decl_file && |
| 2451 |
ltype != DW_LNCT_GNU_decl_line && |
| 2452 |
ltype != DW_LNCT_size) { |
| 2453 |
break; |
| 2454 |
} |
| 2455 |
DECODE_LEB128_UWORD_CK(lp, val,dbg,error,line_end_ptr); |
| 2456 |
*return_val = val; |
| 2457 |
*line_ptr = lp; |
| 2458 |
return DW_DLV_OK; |
| 2459 |
case DW_FORM_data1: |
| 2460 |
if (ltype != DW_LNCT_directory_index && |
| 2461 |
ltype != DW_LNCT_GNU_decl_file && |
| 2462 |
ltype != DW_LNCT_GNU_decl_line && |
| 2463 |
ltype != DW_LNCT_size) { |
| 2464 |
break; |
| 2465 |
} |
| 2466 |
*return_val = *lp; |
| 2467 |
*line_ptr = lp+1; |
| 2468 |
return DW_DLV_OK; |
| 2469 |
case DW_FORM_data2: |
| 2470 |
if (ltype != DW_LNCT_directory_index && |
| 2471 |
ltype != DW_LNCT_GNU_decl_file && |
| 2472 |
ltype != DW_LNCT_GNU_decl_line && |
| 2473 |
ltype != DW_LNCT_size) { |
| 2474 |
break; |
| 2475 |
} |
| 2476 |
READ_UNALIGNED_CK(dbg, val, Dwarf_Unsigned, |
| 2477 |
lp,DWARF_HALF_SIZE, |
| 2478 |
error,line_end_ptr); |
| 2479 |
*return_val = val; |
| 2480 |
*line_ptr = lp + DWARF_HALF_SIZE; |
| 2481 |
return DW_DLV_OK; |
| 2482 |
case DW_FORM_data4: |
| 2483 |
if (ltype != DW_LNCT_timestamp && |
| 2484 |
ltype != DW_LNCT_GNU_decl_file && |
| 2485 |
ltype != DW_LNCT_GNU_decl_line && |
| 2486 |
ltype != DW_LNCT_size) { |
| 2487 |
break; |
| 2488 |
} |
| 2489 |
READ_UNALIGNED_CK(dbg, val, Dwarf_Unsigned, |
| 2490 |
lp,DWARF_32BIT_SIZE, |
| 2491 |
error,line_end_ptr); |
| 2492 |
*return_val = val; |
| 2493 |
*line_ptr = lp + DWARF_32BIT_SIZE; |
| 2494 |
return DW_DLV_OK; |
| 2495 |
case DW_FORM_block: { |
| 2496 |
Dwarf_Unsigned leblen = 0; |
| 2497 |
Dwarf_Unsigned length = 0; |
| 2498 |
Dwarf_Small *dataptr = 0; |
| 2499 |
|
| 2500 |
if (ltype != DW_LNCT_timestamp) { |
| 2501 |
break; |
| 2502 |
} |
| 2503 |
DECODE_LEB128_UWORD_LEN_CK(lp, length, leblen, |
| 2504 |
dbg,error,line_end_ptr); |
| 2505 |
dataptr = lp +leblen; |
| 2506 |
if (length > sizeof(Dwarf_Unsigned)) { |
| 2507 |
splmsg = "FORM_block length bigger than Dwarf_Unsigned"; |
| 2508 |
break; |
| 2509 |
} |
| 2510 |
if (dataptr >= line_end_ptr ) { |
| 2511 |
splmsg = "FORM_block data starts past end of data"; |
| 2512 |
break; |
| 2513 |
} |
| 2514 |
if ((dataptr + length) > line_end_ptr) { |
| 2515 |
splmsg = "FORM_block data runs past end of data"; |
| 2516 |
break; |
| 2517 |
} |
| 2518 |
READ_UNALIGNED_CK(dbg, val, Dwarf_Unsigned, |
| 2519 |
dataptr,length, |
| 2520 |
error,line_end_ptr); |
| 2521 |
*return_val = val; |
| 2522 |
*line_ptr = dataptr+length; |
| 2523 |
return DW_DLV_OK; |
| 2524 |
} |
| 2525 |
|
| 2526 |
case DW_FORM_data8: |
| 2527 |
if (ltype != DW_LNCT_size && |
| 2528 |
ltype != DW_LNCT_timestamp) { |
| 2529 |
break; |
| 2530 |
} |
| 2531 |
READ_UNALIGNED_CK(dbg, val, Dwarf_Unsigned, |
| 2532 |
lp,DWARF_64BIT_SIZE, |
| 2533 |
error,line_end_ptr); |
| 2534 |
*return_val = val; |
| 2535 |
*line_ptr = lp + DWARF_64BIT_SIZE; |
| 2536 |
return DW_DLV_OK; |
| 2537 |
default: break; |
| 2538 |
} |
| 2539 |
report_ltype_form_issue(dbg, (Dwarf_Half)ltype, |
| 2540 |
(Dwarf_Half)form,splmsg,error); |
| 2541 |
return DW_DLV_ERROR; |
| 2542 |
} |
| 2543 |
|
| 2544 |
void |
| 2545 |
_dwarf_update_chain_list( Dwarf_Chain chain_line, |
| 2546 |
Dwarf_Chain *head_chain, Dwarf_Chain *curr_chain) |
| 2547 |
{ |
| 2548 |
if (*head_chain == NULL) { |
| 2549 |
*head_chain = chain_line; |
| 2550 |
} else { |
| 2551 |
(*curr_chain)->ch_next = chain_line; |
| 2552 |
} |
| 2553 |
*curr_chain = chain_line; |
| 2554 |
} |
| 2555 |
|
| 2556 |
void |
| 2557 |
_dwarf_free_chain_entries(Dwarf_Debug dbg,Dwarf_Chain head, |
| 2558 |
Dwarf_Unsigned count) |
| 2559 |
{ |
| 2560 |
Dwarf_Unsigned i = 0; |
| 2561 |
Dwarf_Chain curr_chain = head; |
| 2562 |
for (i = 0; i < count; i++) { |
| 2563 |
Dwarf_Chain t = curr_chain; |
| 2564 |
void *item = t->ch_item; |
| 2565 |
int itype = t->ch_itemtype; |
| 2566 |
|
| 2567 |
if (item && itype) { /* valid DW_DLA types are never 0 */ |
| 2568 |
dwarf_dealloc(dbg,item,itype); |
| 2569 |
t->ch_item = 0; |
| 2570 |
} |
| 2571 |
curr_chain = curr_chain->ch_next; |
| 2572 |
dwarf_dealloc(dbg, t, DW_DLA_CHAIN); |
| 2573 |
} |
| 2574 |
} |
| 2575 |
|
| 2576 |
int |
| 2577 |
_dwarf_add_to_files_list(Dwarf_Line_Context context, |
| 2578 |
Dwarf_File_Entry fe) |
| 2579 |
{ |
| 2580 |
unsigned int version = context->lc_version_number; |
| 2581 |
if (!context->lc_file_entries) { |
| 2582 |
context->lc_file_entries = fe; |
| 2583 |
} else { |
| 2584 |
context->lc_last_entry->fi_next = fe; |
| 2585 |
} |
| 2586 |
context->lc_last_entry = fe; |
| 2587 |
context->lc_file_entry_count++; |
| 2588 |
/* Here we attempt to write code to make it easy to interate |
| 2589 |
though source file names without having to code specially |
| 2590 |
for DWARF2,3,4 vs DWARF5 */ |
| 2591 |
/* Remember that 0xf006 is the version of |
| 2592 |
the experimental line table */ |
| 2593 |
if (version == DW_LINE_VERSION5) { |
| 2594 |
context->lc_file_entry_baseindex = 0; |
| 2595 |
context->lc_file_entry_endindex = |
| 2596 |
context->lc_file_entry_count; |
| 2597 |
} else { |
| 2598 |
context->lc_file_entry_baseindex = 1; |
| 2599 |
context->lc_file_entry_endindex = |
| 2600 |
context->lc_file_entry_count +1; |
| 2601 |
} |
| 2602 |
return DW_DLV_OK; |
| 2603 |
} |
| 2604 |
|
| 2605 |
int |
| 2606 |
_dwarf_line_context_constructor(Dwarf_Debug dbg, void *m) |
| 2607 |
{ |
| 2608 |
Dwarf_Line_Context line_context = (Dwarf_Line_Context)m; |
| 2609 |
/* dwarf_get_alloc ensures the bytes are all zero |
| 2610 |
when m is passed to us. */ |
| 2611 |
line_context->lc_magic = DW_CONTEXT_MAGIC; |
| 2612 |
line_context->lc_dbg = dbg; |
| 2613 |
return DW_DLV_OK; |
| 2614 |
} |
| 2615 |
|
| 2616 |
/* This cleans up a contex record. |
| 2617 |
The lines tables (actuals and logicals) |
| 2618 |
are themselves items that will |
| 2619 |
be dealloc'd either manually |
| 2620 |
or, at closing the libdwarf dbg, |
| 2621 |
automatically. So we DO NOT |
| 2622 |
touch the lines tables here |
| 2623 |
See also: delete_line_context_itself() |
| 2624 |
*/ |
| 2625 |
void |
| 2626 |
_dwarf_line_context_destructor(void *m) |
| 2627 |
{ |
| 2628 |
Dwarf_Line_Context line_context = (Dwarf_Line_Context)m; |
| 2629 |
if (line_context->lc_magic != DW_CONTEXT_MAGIC) { |
| 2630 |
/* Nothing is safe, do nothing. */ |
| 2631 |
return; |
| 2632 |
} |
| 2633 |
if (line_context->lc_include_directories) { |
| 2634 |
free(line_context->lc_include_directories); |
| 2635 |
line_context->lc_include_directories = 0; |
| 2636 |
line_context->lc_include_directories_count = 0; |
| 2637 |
} |
| 2638 |
if (line_context->lc_file_entries) { |
| 2639 |
Dwarf_File_Entry fe = line_context->lc_file_entries; |
| 2640 |
while(fe) { |
| 2641 |
Dwarf_File_Entry t = fe; |
| 2642 |
fe = t->fi_next; |
| 2643 |
t->fi_next = 0; |
| 2644 |
free(t); |
| 2645 |
} |
| 2646 |
line_context->lc_file_entries = 0; |
| 2647 |
line_context->lc_last_entry = 0; |
| 2648 |
line_context->lc_file_entry_count = 0; |
| 2649 |
line_context->lc_file_entry_baseindex = 0; |
| 2650 |
line_context->lc_file_entry_endindex = 0; |
| 2651 |
} |
| 2652 |
free(line_context->lc_directory_format_values); |
| 2653 |
line_context->lc_directory_format_values = 0; |
| 2654 |
free(line_context->lc_file_format_values); |
| 2655 |
line_context->lc_file_format_values = 0; |
| 2656 |
|
| 2657 |
if (line_context->lc_subprogs) { |
| 2658 |
free(line_context->lc_subprogs); |
| 2659 |
line_context->lc_subprogs = 0; |
| 2660 |
line_context->lc_subprogs_count = 0; |
| 2661 |
} |
| 2662 |
line_context->lc_magic = 0; |
| 2663 |
return; |
| 2664 |
} |