1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
|
/*
Copyright (C) 2018-2020 David Anderson. All Rights Reserved.
This program is free software; you can redistribute it
and/or modify it under the terms of version 2.1 of the
GNU Lesser General Public License as published by the
Free Software Foundation.
This program is distributed in the hope that it would
be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Further, this software is distributed without any warranty
that it is free of the rightful claim of any third person
regarding infringement or the like. Any license provided
herein, whether implied or otherwise, applies only to
this software file. Patent licenses, if any, provided
herein do not apply to combinations of this program with
other software, or any other product whatsoever.
You should have received a copy of the GNU Lesser General
Public License along with this program; if not, write
the Free Software Foundation, Inc., 51 Franklin Street -
Fifth Floor, Boston MA 02110-1301, USA.
*/
#include "config.h"
#include <stdio.h>
#include "dwarf_incl.h"
#include "dwarf_alloc.h"
#include "dwarf_error.h"
#include "dwarf_util.h"
#include "dwarfstring.h"
#include "dwarf_str_offsets.h"
#include "dwarf_loc.h"
#include "dwarf_rnglists.h"
#define TRUE 1
#define FALSE 0
static int
load_xu_loclists_into_cucontext(Dwarf_Debug dbg,
Dwarf_CU_Context cu_context,
struct Dwarf_Debug_Fission_Per_CU_s*fsd,
UNUSEDARG const char * xu_type,
int fsd_index,
UNUSEDARG Dwarf_Error *error)
{
Dwarf_Unsigned size = 0;
Dwarf_Unsigned soff_hdroffset = 0;
Dwarf_Unsigned soff_size = 0;
struct Dwarf_Loclists_Context_s localcontxt;
Dwarf_Loclists_Context buildhere = &localcontxt;
Dwarf_Unsigned nextset = 0;
int res = 0;
size = fsd->pcu_size[fsd_index];
soff_hdroffset = fsd->pcu_offset[fsd_index];
soff_size = dbg->de_debug_loclists.dss_size;
if (!soff_size) {
return DW_DLV_NO_ENTRY;
}
if (soff_hdroffset >= soff_size) {
/* Something is badly wrong. Ignore it here. */
return DW_DLV_NO_ENTRY;
}
memset(buildhere,0,sizeof(localcontxt));
res = _dwarf_internal_read_loclists_header(dbg,
0,soff_size,
dbg->de_debug_loclists.dss_data,
dbg->de_debug_loclists.dss_data +soff_size,
soff_hdroffset,
buildhere,
&nextset,error);
if (res != DW_DLV_OK) {
return res;
}
cu_context->cc_loclists_base_present = TRUE;
cu_context->cc_loclists_base_contr_size = size;
cu_context->cc_loclists_base =
buildhere->lc_offsets_off_in_sect;
return DW_DLV_OK;
}
/* ASSERT: cc_str_offsets_base_present FALSE
ASSERT: cc_str_offsets_header_length_present FALSE
If .debug_cu_index or
.debug_tu_index is present it might help us find
the offset for this CU's .debug_str_offsets.
*/
static int
load_xu_str_offsets_into_cucontext(Dwarf_Debug dbg,
Dwarf_CU_Context cu_context,
struct Dwarf_Debug_Fission_Per_CU_s*fsd,
UNUSEDARG const char * xu_type,
int fsd_index,
UNUSEDARG Dwarf_Error *error)
{
Dwarf_Small *soff_secptr = 0;
Dwarf_Small *soff_hdrptr = 0;
Dwarf_Unsigned soff_hdroffset = 0;
Dwarf_Unsigned soff_size = 0;
Dwarf_Small *soff_eptr = 0;
int res = 0;
res = _dwarf_load_section(dbg, &dbg->de_debug_str_offsets,
error);
if (res != DW_DLV_OK) {
return res;
}
soff_hdroffset = fsd->pcu_offset[fsd_index];
soff_secptr = dbg->de_debug_str_offsets.dss_data;
soff_size = dbg->de_debug_str_offsets.dss_size;
soff_eptr = soff_secptr + soff_size;
soff_hdrptr = soff_secptr + soff_hdroffset;
if (soff_hdroffset >= soff_size) {
/* Something is badly wrong. Ignore it here. */
return DW_DLV_NO_ENTRY;
}
{
Dwarf_Unsigned length = 0;
Dwarf_Half offset_size = 0;
Dwarf_Half extension_size = 0;
Dwarf_Half version = 0;
Dwarf_Half padding = 0;
Dwarf_Unsigned header_length = 0;
res = _dwarf_read_str_offsets_header(dbg,
soff_hdrptr,
soff_size - soff_hdroffset,
soff_eptr,
cu_context,
&length,&offset_size,
&extension_size,&version,&padding,
&header_length,
error);
if (res != DW_DLV_OK) {
if (res == DW_DLV_ERROR) {
dwarf_dealloc_error(dbg,*error);
*error = 0;
}
res = DW_DLV_NO_ENTRY;
return res;
}
cu_context->cc_str_offsets_base_present = TRUE;
cu_context->cc_str_offsets_header_length_present = TRUE;
cu_context->cc_str_offsets_header_offset = soff_hdroffset;
cu_context->cc_str_offsets_base = soff_hdroffset +
header_length;
cu_context->cc_str_offsets_header_length = header_length;
cu_context->cc_str_offsets_offset_size = offset_size;
return DW_DLV_OK;
}
return DW_DLV_NO_ENTRY;
}
static int
load_xu_debug_macro_into_cucontext(Dwarf_Debug dbg,
Dwarf_CU_Context cu_context,
struct Dwarf_Debug_Fission_Per_CU_s*fsd,
UNUSEDARG const char * xu_type,
int fsd_index,
UNUSEDARG Dwarf_Error *error)
{
Dwarf_Unsigned size = 0;
Dwarf_Unsigned soff_hdroffset = 0;
Dwarf_Unsigned soff_size = 0;
int res = 0;
res = _dwarf_load_section(dbg, &dbg->de_debug_macro,
error);
if (res != DW_DLV_OK) {
return res;
}
size = fsd->pcu_size[fsd_index];
soff_hdroffset = fsd->pcu_offset[fsd_index];
soff_size = dbg->de_debug_macro.dss_size;
if (!soff_size) {
return DW_DLV_NO_ENTRY;
}
if (soff_hdroffset >= soff_size) {
/* Something is badly wrong. Ignore it here. */
return DW_DLV_NO_ENTRY;
}
/* Presently assuming that DW_AT_macros
and the fission entry both
indicate the beginning
of a .debug_macro sectiom macro header.
(not true for str_offsets or for loclists!)
*/
cu_context->cc_macro_base_present = TRUE;
cu_context->cc_macro_base_contr_size = size;
cu_context->cc_macro_base = soff_hdroffset;
/* FIXME cc_macro_header_length_present? */
return DW_DLV_OK;
}
static int
load_xu_rnglists_into_cucontext(Dwarf_Debug dbg,
Dwarf_CU_Context cu_context,
struct Dwarf_Debug_Fission_Per_CU_s*fsd,
UNUSEDARG const char * xu_type,
int fsd_index,
UNUSEDARG Dwarf_Error *error)
{
Dwarf_Unsigned size = 0;
Dwarf_Unsigned soff_hdroffset = 0;
Dwarf_Unsigned soff_size = 0;
struct Dwarf_Rnglists_Context_s builddata;
Dwarf_Rnglists_Context buildhere = &builddata;
Dwarf_Unsigned nextoffset = 0;
int res = 0;
res = _dwarf_load_section(dbg, &dbg->de_debug_rnglists,
error);
if (res != DW_DLV_OK) {
return res;
}
size = fsd->pcu_size[fsd_index];
soff_hdroffset = fsd->pcu_offset[fsd_index];
soff_size = dbg->de_debug_rnglists.dss_size;
if (!soff_size) {
return DW_DLV_NO_ENTRY;
}
if (soff_hdroffset >= soff_size) {
/* Something is badly wrong. Ignore it here. */
return DW_DLV_NO_ENTRY;
}
memset(buildhere,0,sizeof(builddata));
res = _dwarf_internal_read_rnglists_header(dbg,
0,soff_size,
dbg->de_debug_rnglists.dss_data,
dbg->de_debug_rnglists.dss_data+soff_size,
soff_hdroffset,buildhere,
&nextoffset,error);
if (res != DW_DLV_OK) {
return res;
}
cu_context->cc_rnglists_base =
buildhere->rc_offsets_off_in_sect;
cu_context->cc_rnglists_base_present = TRUE;
cu_context->cc_rnglists_base_contr_size = size;
/* FIXME cc_rnglists_header_length_present? */
return DW_DLV_OK;
}
static const char *keylist[2] = {
"cu",
"tu"
};
/* ASSERT: The context has a signature.
_dwarf_make_CU_Context() calls
finish_up_cu_context_from_cudie() which calls
us here.
Then, _dwarf_make_CU_Context() calls
_dwarf_merge_all_base_attrs_of_cu_die() if there
is a tied (executable) object known.
*/
int
_dwarf_find_all_offsets_via_fission(Dwarf_Debug dbg,
Dwarf_CU_Context cu_context,
Dwarf_Error *error)
{
struct Dwarf_Debug_Fission_Per_CU_s fission_data;
struct Dwarf_Debug_Fission_Per_CU_s*fsd = 0;
int si = 0;
int smax = 2;
int fdres = 0;
int res = 0;
fsd = &fission_data;
for(si = 0; si < smax ; ++si) {
int sec_index = 0;
memset(&fission_data,0,sizeof(fission_data));
fdres = dwarf_get_debugfission_for_key(dbg,
&cu_context->cc_signature,
keylist[si],
fsd,error);
if (fdres == DW_DLV_NO_ENTRY) {
continue;
}
if (fdres == DW_DLV_ERROR) {
dwarf_dealloc_error(dbg,*error);
*error = 0;
continue;
}
for (sec_index = 1; sec_index < DW_FISSION_SECT_COUNT;
++sec_index) {
if (!fsd->pcu_size[sec_index]) {
continue;
}
res = DW_DLV_OK;
switch(sec_index) {
/* these handled elsewhere, such
as by _dwarf_get_dwp_extra_offset()
_dwarf_get_fission_addition_die()
case DW_SECT_INFO:
case DW_SECT_ABBREV:
case DW_SECT_LINE:
*/
case DW_SECT_LOCLISTS:
res = load_xu_loclists_into_cucontext(dbg,
cu_context,
fsd,keylist[si],sec_index,error);
break;
case DW_SECT_STR_OFFSETS:
res = load_xu_str_offsets_into_cucontext(dbg,
cu_context,
fsd,keylist[si],sec_index,error);
break;
case DW_SECT_MACRO:
res = load_xu_debug_macro_into_cucontext(dbg,
cu_context,
fsd,keylist[si],sec_index,error);
break;
case DW_SECT_RNGLISTS:
res = load_xu_rnglists_into_cucontext(dbg,
cu_context,
fsd,keylist[si],sec_index,error);
break;
default:
res = DW_DLV_OK;
break;
}
if (res == DW_DLV_ERROR) {
return res;
}
}
}
return DW_DLV_OK;
}
|