9#ifndef INCLUDED_BALST_RESOLVER_DWARFREADER
10#define INCLUDED_BALST_RESOLVER_DWARFREADER
78#include <balscm_version.h>
94#include <bsl_cstddef.h>
95#include <bsl_cstring.h>
96#include <bsl_string.h>
101#if defined(BALST_OBJECTFILEFORMAT_RESOLVER_DWARF)
107class Resolver_DwarfReader {
110 typedef bdls::FilesystemUtil::Offset Offset;
127 void reset(Offset offset = 0, Offset size = 0);
133 enum { k_SCRATCH_BUF_LEN = 32 * 1024 - 64 };
160 e_DW_AT_sibling = 0x01,
161 e_DW_AT_location = 0x02,
163 e_DW_AT_ordering = 0x09,
164 e_DW_AT_byte_size = 0x0b,
165 e_DW_AT_bit_offset = 0x0c,
166 e_DW_AT_bit_size = 0x0d,
167 e_DW_AT_stmt_list = 0x10,
168 e_DW_AT_low_pc = 0x11,
169 e_DW_AT_high_pc = 0x12,
170 e_DW_AT_language = 0x13,
171 e_DW_AT_discr = 0x15,
172 e_DW_AT_discr_value = 0x16,
173 e_DW_AT_visibility = 0x17,
174 e_DW_AT_import = 0x18,
175 e_DW_AT_string_length = 0x19,
176 e_DW_AT_common_reference = 0x1a,
177 e_DW_AT_comp_dir = 0x1b,
178 e_DW_AT_const_value = 0x1c,
179 e_DW_AT_containing_type = 0x1d,
180 e_DW_AT_default_value = 0x1e,
181 e_DW_AT_inline = 0x20,
182 e_DW_AT_is_optional = 0x21,
183 e_DW_AT_lower_bound = 0x22,
184 e_DW_AT_producer = 0x25,
185 e_DW_AT_prototyped = 0x27,
186 e_DW_AT_return_addr = 0x2a,
187 e_DW_AT_start_scope = 0x2c,
188 e_DW_AT_bit_stride = 0x2e,
189 e_DW_AT_upper_bound = 0x2f,
190 e_DW_AT_abstract_origin = 0x31,
191 e_DW_AT_accessibility = 0x32,
192 e_DW_AT_address_class = 0x33,
193 e_DW_AT_artificial = 0x34,
194 e_DW_AT_base_types = 0x35,
195 e_DW_AT_calling_convention = 0x36,
196 e_DW_AT_count = 0x37,
197 e_DW_AT_data_member_location = 0x38,
198 e_DW_AT_decl_column = 0x39,
199 e_DW_AT_decl_file = 0x3a,
200 e_DW_AT_decl_line = 0x3b,
201 e_DW_AT_declaration = 0x3c,
202 e_DW_AT_discr_list = 0x3d,
203 e_DW_AT_encoding = 0x3e,
204 e_DW_AT_external = 0x3f,
205 e_DW_AT_frame_base = 0x40,
206 e_DW_AT_friend = 0x41,
207 e_DW_AT_identifier_case = 0x42,
208 e_DW_AT_macro_info = 0x43,
209 e_DW_AT_namelist_item = 0x44,
210 e_DW_AT_priority = 0x45,
211 e_DW_AT_segment = 0x46,
212 e_DW_AT_specification = 0x47,
213 e_DW_AT_static_link = 0x48,
215 e_DW_AT_use_location = 0x4a,
216 e_DW_AT_variable_parameter = 0x4b,
217 e_DW_AT_virtuality = 0x4c,
218 e_DW_AT_vtable_elem_location = 0x4d,
219 e_DW_AT_allocated = 0x4e,
220 e_DW_AT_associated = 0x4f,
221 e_DW_AT_data_location = 0x50,
222 e_DW_AT_byte_stride = 0x51,
223 e_DW_AT_entry_pc = 0x52,
224 e_DW_AT_use_UTF8 = 0x53,
225 e_DW_AT_extension = 0x54,
226 e_DW_AT_ranges = 0x55,
227 e_DW_AT_trampoline = 0x56,
228 e_DW_AT_call_column = 0x57,
229 e_DW_AT_call_file = 0x58,
230 e_DW_AT_call_line = 0x59,
231 e_DW_AT_description = 0x5a,
232 e_DW_AT_binary_scale = 0x5b,
233 e_DW_AT_decimal_scale = 0x5c,
234 e_DW_AT_small = 0x5d,
235 e_DW_AT_decimal_sign = 0x5e,
236 e_DW_AT_digit_count = 0x5f,
237 e_DW_AT_picture_string = 0x60,
238 e_DW_AT_mutable = 0x61,
239 e_DW_AT_threads_scaled = 0x62,
240 e_DW_AT_explicit = 0x63,
241 e_DW_AT_object_pointer = 0x64,
242 e_DW_AT_endianity = 0x65,
243 e_DW_AT_elemental = 0x66,
245 e_DW_AT_recursive = 0x68,
247 e_DW_CHILDREN_no = 0x00,
248 e_DW_CHILDREN_yes = 0x01,
250 e_DW_FORM_addr = 0x01,
251 e_DW_FORM_block2 = 0x03,
252 e_DW_FORM_block4 = 0x04,
253 e_DW_FORM_data2 = 0x05,
254 e_DW_FORM_data4 = 0x06,
255 e_DW_FORM_data8 = 0x07,
256 e_DW_FORM_string = 0x08,
257 e_DW_FORM_block = 0x09,
258 e_DW_FORM_block1 = 0x0a,
259 e_DW_FORM_data1 = 0x0b,
260 e_DW_FORM_flag = 0x0c,
261 e_DW_FORM_sdata = 0x0d,
262 e_DW_FORM_strp = 0x0e,
263 e_DW_FORM_udata = 0x0f,
264 e_DW_FORM_ref_addr = 0x10,
265 e_DW_FORM_ref1 = 0x11,
266 e_DW_FORM_ref2 = 0x12,
267 e_DW_FORM_ref4 = 0x13,
268 e_DW_FORM_ref8 = 0x14,
269 e_DW_FORM_ref_udata = 0x15,
270 e_DW_FORM_indirect = 0x16,
271 e_DW_FORM_line_strp = 0x1f,
273 e_DW_INL_declared_inlined = 0x03,
275 e_DW_LNCT_path = 0x01,
276 e_DW_LNCT_directory_index = 0x02,
277 e_DW_LNCT_timestamp = 0x03,
278 e_DW_LNCT_size = 0x04,
279 e_DW_LNCT_MD5 = 0x05,
280 e_DW_LNCT_lo_user = 0x2000,
281 e_DW_LNCT_hi_user = 0x3fff,
283 e_DW_LNE_end_sequence = 0x01,
284 e_DW_LNE_set_address = 0x02,
285 e_DW_LNE_define_file = 0x03,
287 e_DW_LNS_copy = 0x01,
288 e_DW_LNS_advance_pc = 0x02,
289 e_DW_LNS_advance_line = 0x03,
290 e_DW_LNS_set_file = 0x04,
291 e_DW_LNS_set_column = 0x05,
292 e_DW_LNS_negate_stmt = 0x06,
293 e_DW_LNS_set_basic_block = 0x07,
294 e_DW_LNS_const_add_pc = 0x08,
295 e_DW_LNS_fixed_advance_pc = 0x09,
296 e_DW_LNS_set_prologue_end = 0x0a,
297 e_DW_LNS_set_epilogue_begin = 0x0b,
298 e_DW_LNS_set_isa = 0x0c,
300 e_DW_TAG_array_type = 0x01,
301 e_DW_TAG_class_type = 0x02,
302 e_DW_TAG_entry_point = 0x03,
303 e_DW_TAG_enumeration_type = 0x04,
304 e_DW_TAG_formal_parameter = 0x05,
305 e_DW_TAG_imported_declaration = 0x08,
306 e_DW_TAG_label = 0x0a,
307 e_DW_TAG_lexical_block = 0x0b,
308 e_DW_TAG_member = 0x0d,
309 e_DW_TAG_pointer_type = 0x0f,
310 e_DW_TAG_reference_type = 0x10,
311 e_DW_TAG_compile_unit = 0x11,
312 e_DW_TAG_string_type = 0x12,
313 e_DW_TAG_structure_type = 0x13,
314 e_DW_TAG_subroutine_type = 0x15,
315 e_DW_TAG_typedef = 0x16,
316 e_DW_TAG_union_type = 0x17,
317 e_DW_TAG_unspecified_parameters = 0x18,
318 e_DW_TAG_variant = 0x19,
319 e_DW_TAG_common_block = 0x1a,
320 e_DW_TAG_common_inclusion = 0x1b,
321 e_DW_TAG_inheritance = 0x1c,
322 e_DW_TAG_inlined_subroutine = 0x1d,
323 e_DW_TAG_module = 0x1e,
324 e_DW_TAG_ptr_to_member_type = 0x1f,
325 e_DW_TAG_set_type = 0x20,
326 e_DW_TAG_subrange_type = 0x21,
327 e_DW_TAG_with_stmt = 0x22,
328 e_DW_TAG_access_declaration = 0x23,
329 e_DW_TAG_base_type = 0x24,
330 e_DW_TAG_catch_block = 0x25,
331 e_DW_TAG_const_type = 0x26,
332 e_DW_TAG_constant = 0x27,
333 e_DW_TAG_enumerator = 0x28,
334 e_DW_TAG_file_type = 0x29,
335 e_DW_TAG_friend = 0x2a,
336 e_DW_TAG_namelist = 0x2b,
337 e_DW_TAG_namelist_item = 0x2c,
338 e_DW_TAG_packed_type = 0x2d,
339 e_DW_TAG_subprogram = 0x2e,
340 e_DW_TAG_template_type_parameter = 0x2f,
341 e_DW_TAG_template_value_parameter = 0x30,
342 e_DW_TAG_thrown_type = 0x31,
343 e_DW_TAG_try_block = 0x32,
344 e_DW_TAG_variant_part = 0x33,
345 e_DW_TAG_variable = 0x34,
346 e_DW_TAG_volatile_type = 0x35,
347 e_DW_TAG_dwarf_procedure = 0x36,
348 e_DW_TAG_restrict_type = 0x37,
349 e_DW_TAG_interface_type = 0x38,
350 e_DW_TAG_namespace = 0x39,
351 e_DW_TAG_imported_module = 0x3a,
352 e_DW_TAG_unspecified_type = 0x3b,
353 e_DW_TAG_partial_unit = 0x3c,
354 e_DW_TAG_imported_unit = 0x3d,
355 e_DW_TAG_condition = 0x3f,
356 e_DW_TAG_shared_type = 0x40,
357 e_DW_TAG_lo_user = 0x4080,
358 e_DW_TAG_hi_user = 0xffff
364 e_DW_AT_signature = 0x69,
365 e_DW_AT_main_subprogram = 0x6a,
366 e_DW_AT_data_bit_offset = 0x6b,
367 e_DW_AT_const_expr = 0x6c,
368 e_DW_AT_enum_class = 0x6d,
369 e_DW_AT_linkage_name = 0x6e,
370 e_DW_AT_lo_user = 0x2000,
371 e_DW_AT_hi_user = 0x3fff,
373 e_DW_FORM_sec_offset = 0x17,
374 e_DW_FORM_exprloc = 0x18,
375 e_DW_FORM_flag_present = 0x19,
376 e_DW_FORM_ref_sig8 = 0x20,
378 e_DW_LNE_set_discriminator = 0x04,
380 e_DW_TAG_mutable_type = 0x3e,
381 e_DW_TAG_type_unit = 0x41,
382 e_DW_TAG_rvalue_reference_type = 0x42,
383 e_DW_TAG_template_alias = 0x43
387 e_DW_UT_compile = 0x1,
389 e_DW_UT_partial = 0x3,
390 e_DW_UT_skeleton = 0x4,
391 e_DW_UT_split_compile = 0x5,
392 e_DW_UT_split_type = 0x6,
393 e_DW_UT_lo_user = 0x80,
394 e_DW_UT_hi_user = 0xff
399 balst::Resolver_FileHelper *d_helper_p;
407 Offset d_beginOffset;
411 const char *d_readPtr;
414 const char *d_endPtr;
425 Resolver_DwarfReader(
const Resolver_DwarfReader&);
426 Resolver_DwarfReader& operator=(
const Resolver_DwarfReader&);
436 int needBytes(bsl::size_t numBytes);
442 int reload(bsl::size_t numBytes);
447 const char *stringForAt(
unsigned id);
451 const char *stringForForm(
unsigned id);
455 const char *stringForInlineState(
unsigned inlineState);
460 const char *stringForLNCT(
unsigned id);
464 const char *stringForLNE(
unsigned id);
468 const char *stringForLNS(
unsigned id);
472 const char *stringForTag(
unsigned tag);
478 Resolver_DwarfReader();
481 ~Resolver_DwarfReader() =
default;
493 int init(balst::Resolver_FileHelper *fileHelper,
495 const Section& section,
496 Offset libraryFileSize);
502 int readAddress(UintPtr *dst);
506 int readAddress(UintPtr *dst,
unsigned form);
512 int readAddressSize();
527 int readInitialLength(Offset *dst);
531 template <
class TYPE>
532 int readLEB128(TYPE *dst);
536 template <
class TYPE>
537 int readULEB128(TYPE *dst);
543 int readOffset(Offset *dst,
544 bsl::size_t offsetSize);
549 int readOffsetFromForm(Offset *dst,
556 int readSectionOffset(Offset *dst);
578 Resolver_DwarfReader *strReader,
579 Resolver_DwarfReader *lineStrReader,
584 template <
class TYPE>
585 int readValue(TYPE *dst);
590 int setAddressSize(
unsigned size);
593 int setEndOffset(Offset newOffset);
596 int skipBytes(Offset bytes);
603 int skipForm(
unsigned form);
607 int skipTo(Offset offset);
616 int addressSize()
const;
620 bool atEndOfSection()
const;
623 Offset offset()
const;
627 Offset offsetSize()
const;
630 bool isEnabled()
const;
635int Resolver_DwarfReader::needBytes(bsl::size_t numBytes)
637 IntPtr diff = d_endPtr - d_readPtr;
639 if (diff <
static_cast<IntPtr
>(numBytes)) {
642 return reload(numBytes);
649int Resolver_DwarfReader::readLEB128(TYPE *dst)
657 unsigned char u = 0x80;
659 enum { k_MAX_SHIFT =
sizeof(*dst) * 8 };
672 const Uint64 masked = 0x7f & u;
674 tmpDst |= masked << shift;
677 if (
static_cast<TYPE
>(-1) < 0) {
680 const Uint64 negFlag =
static_cast<Uint64
>(0x40) << shift;
681 if (negFlag & tmpDst) {
682 tmpDst |= ~(negFlag - 1);
686 *dst =
static_cast<TYPE
>(tmpDst);
692int Resolver_DwarfReader::readULEB128(TYPE *dst)
696 unsigned char u = 0x80;
699 for (; (0x80 & u); shift += 7) {
700 int rc = readValue(&u);
709 const Uint64 masked = 0x7f & u;
710 tmpDst |= masked << shift;
712#if defined(BSLS_ASSERT_LEVEL_ASSERT_SAFE)
713 if (shift >=
sizeof(*dst) * 8 + 7) {
722 *dst =
static_cast<TYPE
>(tmpDst);
729int Resolver_DwarfReader::readValue(TYPE *dst)
731 int rc = needBytes(
sizeof(*dst));
740 bsl::memcpy(dst, d_readPtr,
sizeof(*dst));
741 d_readPtr +=
sizeof(*dst);
747int Resolver_DwarfReader::skipBytes(Offset bytes)
751 if (bytes > d_endPtr - d_readPtr) {
752 Offset off = offset();
754 if (off < d_beginOffset) {
757 if (off + bytes > d_endOffset) {
764 d_offset += bytes + (d_readPtr - d_buffer_p);
765 d_readPtr = d_buffer_p;
766 d_endPtr = d_readPtr;
776int Resolver_DwarfReader::skipString()
779 int rc = needBytes(1);
783 }
while (*d_readPtr++);
790int Resolver_DwarfReader::addressSize()
const
792 return d_addressSize;
796bool Resolver_DwarfReader::atEndOfSection()
const
798 return d_readPtr == d_endPtr &&
799 d_endOffset - d_offset == d_readPtr - d_buffer_p;
803Resolver_DwarfReader::Offset
804Resolver_DwarfReader::offset()
const
806 return d_offset + (d_readPtr - d_buffer_p);
810Resolver_DwarfReader::Offset
811Resolver_DwarfReader::offsetSize()
const
817bool Resolver_DwarfReader::isEnabled()
const
819 return 0 != d_buffer_p;
Definition bslstl_string.h:1281
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition balst_objectfileformat.h:161
void reset(TYPE *object)
Reset the value of the specified object to its default value.
std::size_t UintPtr
Definition bsls_types.h:126
unsigned long long Uint64
Definition bsls_types.h:137
std::ptrdiff_t IntPtr
Definition bsls_types.h:130