dbgmoddwarf.cpp revision d1e9999d55e7ac80a28692c161710be98071fc00
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/* $Id$ */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** @file
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * IPRT - Debug Info Reader For DWARF.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/*
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2011-2012 Oracle Corporation
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync *
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * available from http://www.virtualbox.org. This file is free software;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * you can redistribute it and/or modify it under the terms of the GNU
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * General Public License (GPL) as published by the Free Software
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync *
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * The contents of this file may alternatively be used under the terms
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * of the Common Development and Distribution License Version 1.0
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * VirtualBox OSE distribution, in which case the provisions of the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * CDDL are applicable instead of those of the GPL.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync *
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * You may elect to license modified versions of this file under the
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * terms and conditions of either the GPL or the CDDL or both.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/*******************************************************************************
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync* Header Files *
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync*******************************************************************************/
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync#define LOG_GROUP RTLOGGROUP_DBG_DWARF
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#include <iprt/dbg.h>
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#include "internal/iprt.h"
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync#include <iprt/asm.h>
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#include <iprt/ctype.h>
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync#include <iprt/err.h>
e4bf6817370e1a71833a02285515694afcda7599vboxsync#include <iprt/list.h>
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync#include <iprt/log.h>
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#include <iprt/mem.h>
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#include <iprt/path.h>
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#include <iprt/string.h>
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync#include <iprt/strcache.h>
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#include "internal/dbgmod.h"
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/*******************************************************************************
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync* Defined Constants And Macros *
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync*******************************************************************************/
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/** @name Standard DWARF Line Number Opcodes
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @{ */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_extended UINT8_C(0x00)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_copy UINT8_C(0x01)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_advance_pc UINT8_C(0x02)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_advance_line UINT8_C(0x03)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_set_file UINT8_C(0x04)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_set_column UINT8_C(0x05)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_negate_stmt UINT8_C(0x06)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_set_basic_block UINT8_C(0x07)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_const_add_pc UINT8_C(0x08)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_fixed_advance_pc UINT8_C(0x09)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_set_prologue_end UINT8_C(0x0a)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_set_epilogue_begin UINT8_C(0x0b)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_set_isa UINT8_C(0x0c)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_LNS_what_question_mark UINT8_C(0x0d)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/** @} */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/** @name Extended DWARF Line Number Opcodes
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @{ */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_LNE_end_sequence UINT8_C(1)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_LNE_set_address UINT8_C(2)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_LNE_define_file UINT8_C(3)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_LNE_set_descriminator UINT8_C(4)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/** @} */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** @name DIE Tags.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @{ */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_array_type UINT16_C(0x0001)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_class_type UINT16_C(0x0002)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_entry_point UINT16_C(0x0003)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_enumeration_type UINT16_C(0x0004)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_formal_parameter UINT16_C(0x0005)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_imported_declaration UINT16_C(0x0008)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_label UINT16_C(0x000a)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_lexical_block UINT16_C(0x000b)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_member UINT16_C(0x000d)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_pointer_type UINT16_C(0x000f)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_reference_type UINT16_C(0x0010)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_compile_unit UINT16_C(0x0011)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_string_type UINT16_C(0x0012)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_structure_type UINT16_C(0x0013)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_subroutine_type UINT16_C(0x0015)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_typedef UINT16_C(0x0016)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_union_type UINT16_C(0x0017)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_unspecified_parameters UINT16_C(0x0018)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_variant UINT16_C(0x0019)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_common_block UINT16_C(0x001a)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_common_inclusion UINT16_C(0x001b)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_inheritance UINT16_C(0x001c)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_inlined_subroutine UINT16_C(0x001d)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_module UINT16_C(0x001e)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_ptr_to_member_type UINT16_C(0x001f)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_set_type UINT16_C(0x0020)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_subrange_type UINT16_C(0x0021)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_with_stmt UINT16_C(0x0022)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_access_declaration UINT16_C(0x0023)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_base_type UINT16_C(0x0024)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_catch_block UINT16_C(0x0025)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_const_type UINT16_C(0x0026)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_constant UINT16_C(0x0027)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_enumerator UINT16_C(0x0028)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_file_type UINT16_C(0x0029)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_friend UINT16_C(0x002a)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_namelist UINT16_C(0x002b)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_namelist_item UINT16_C(0x002c)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_packed_type UINT16_C(0x002d)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_subprogram UINT16_C(0x002e)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_template_type_parameter UINT16_C(0x002f)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_template_value_parameter UINT16_C(0x0030)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_thrown_type UINT16_C(0x0031)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_try_block UINT16_C(0x0032)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_variant_part UINT16_C(0x0033)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_variable UINT16_C(0x0034)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_volatile_type UINT16_C(0x0035)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_dwarf_procedure UINT16_C(0x0036)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_restrict_type UINT16_C(0x0037)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_interface_type UINT16_C(0x0038)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_namespace UINT16_C(0x0039)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_imported_module UINT16_C(0x003a)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_unspecified_type UINT16_C(0x003b)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_partial_unit UINT16_C(0x003c)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_imported_unit UINT16_C(0x003d)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_condition UINT16_C(0x003f)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_shared_type UINT16_C(0x0040)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_type_unit UINT16_C(0x0041)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_rvalue_reference_type UINT16_C(0x0042)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_template_alias UINT16_C(0x0043)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_lo_user UINT16_C(0x4080)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync#define DW_TAG_hi_user UINT16_C(0xffff)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** @} */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/** @name DIE Attributes.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @{ */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_sibling UINT16_C(0x0001)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_location UINT16_C(0x0002)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_name UINT16_C(0x0003)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_ordering UINT16_C(0x0009)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_byte_size UINT16_C(0x000b)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_bit_offset UINT16_C(0x000c)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_bit_size UINT16_C(0x000d)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_stmt_list UINT16_C(0x0010)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_low_pc UINT16_C(0x0011)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_high_pc UINT16_C(0x0012)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_language UINT16_C(0x0013)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_discr UINT16_C(0x0015)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_discr_value UINT16_C(0x0016)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_visibility UINT16_C(0x0017)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_import UINT16_C(0x0018)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_string_length UINT16_C(0x0019)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_common_reference UINT16_C(0x001a)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_comp_dir UINT16_C(0x001b)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_const_value UINT16_C(0x001c)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_containing_type UINT16_C(0x001d)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_default_value UINT16_C(0x001e)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_inline UINT16_C(0x0020)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_is_optional UINT16_C(0x0021)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_lower_bound UINT16_C(0x0022)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_producer UINT16_C(0x0025)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_prototyped UINT16_C(0x0027)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_return_addr UINT16_C(0x002a)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_start_scope UINT16_C(0x002c)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_bit_stride UINT16_C(0x002e)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_upper_bound UINT16_C(0x002f)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_abstract_origin UINT16_C(0x0031)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_accessibility UINT16_C(0x0032)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_address_class UINT16_C(0x0033)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_artificial UINT16_C(0x0034)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_base_types UINT16_C(0x0035)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_calling_convention UINT16_C(0x0036)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_count UINT16_C(0x0037)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_data_member_location UINT16_C(0x0038)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_decl_column UINT16_C(0x0039)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_decl_file UINT16_C(0x003a)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_decl_line UINT16_C(0x003b)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_declaration UINT16_C(0x003c)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_discr_list UINT16_C(0x003d)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_encoding UINT16_C(0x003e)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_external UINT16_C(0x003f)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_frame_base UINT16_C(0x0040)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_friend UINT16_C(0x0041)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_identifier_case UINT16_C(0x0042)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_macro_info UINT16_C(0x0043)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_namelist_item UINT16_C(0x0044)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_priority UINT16_C(0x0045)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_segment UINT16_C(0x0046)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_specification UINT16_C(0x0047)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_static_link UINT16_C(0x0048)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_type UINT16_C(0x0049)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_use_location UINT16_C(0x004a)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_variable_parameter UINT16_C(0x004b)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_virtuality UINT16_C(0x004c)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_vtable_elem_location UINT16_C(0x004d)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_allocated UINT16_C(0x004e)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_associated UINT16_C(0x004f)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_data_location UINT16_C(0x0050)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_byte_stride UINT16_C(0x0051)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_entry_pc UINT16_C(0x0052)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_use_UTF8 UINT16_C(0x0053)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_extension UINT16_C(0x0054)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_ranges UINT16_C(0x0055)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_trampoline UINT16_C(0x0056)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_call_column UINT16_C(0x0057)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_call_file UINT16_C(0x0058)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_call_line UINT16_C(0x0059)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_description UINT16_C(0x005a)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_binary_scale UINT16_C(0x005b)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_decimal_scale UINT16_C(0x005c)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_small UINT16_C(0x005d)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_decimal_sign UINT16_C(0x005e)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_digit_count UINT16_C(0x005f)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_picture_string UINT16_C(0x0060)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_mutable UINT16_C(0x0061)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_threads_scaled UINT16_C(0x0062)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_explicit UINT16_C(0x0063)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_object_pointer UINT16_C(0x0064)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_endianity UINT16_C(0x0065)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_elemental UINT16_C(0x0066)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_pure UINT16_C(0x0067)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_recursive UINT16_C(0x0068)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_signature UINT16_C(0x0069)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_main_subprogram UINT16_C(0x006a)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_data_bit_offset UINT16_C(0x006b)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_const_expr UINT16_C(0x006c)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_enum_class UINT16_C(0x006d)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_linkage_name UINT16_C(0x006e)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_lo_user UINT16_C(0x2000)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_AT_hi_user UINT16_C(0x3fff)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/** @} */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/** @name DIE Forms.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @{ */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_addr UINT16_C(0x01)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/* What was 0x02? */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_block2 UINT16_C(0x03)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_block4 UINT16_C(0x04)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_data2 UINT16_C(0x05)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_data4 UINT16_C(0x06)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_data8 UINT16_C(0x07)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_string UINT16_C(0x08)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_block UINT16_C(0x09)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_block1 UINT16_C(0x0a)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_data1 UINT16_C(0x0b)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_flag UINT16_C(0x0c)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_sdata UINT16_C(0x0d)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_strp UINT16_C(0x0e)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_udata UINT16_C(0x0f)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_ref_addr UINT16_C(0x10)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_ref1 UINT16_C(0x11)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_ref2 UINT16_C(0x12)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_ref4 UINT16_C(0x13)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_ref8 UINT16_C(0x14)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_ref_udata UINT16_C(0x15)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_indirect UINT16_C(0x16)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_sec_offset UINT16_C(0x17)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_exprloc UINT16_C(0x18)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_flag_present UINT16_C(0x19)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#define DW_FORM_ref_sig8 UINT16_C(0x20)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/** @} */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** @name Address classes.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @{ */
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define DW_ADDR_none UINT8_C(0)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define DW_ADDR_i386_near16 UINT8_C(1)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define DW_ADDR_i386_far16 UINT8_C(2)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define DW_ADDR_i386_huge16 UINT8_C(3)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define DW_ADDR_i386_near32 UINT8_C(4)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define DW_ADDR_i386_far32 UINT8_C(5)
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** @} */
e4bf6817370e1a71833a02285515694afcda7599vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/** @name Location Expression Opcodes
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @{ */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_addr UINT8_C(0x03) /**< 1 operand, a constant address (size target specific). */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_deref UINT8_C(0x06) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_const1u UINT8_C(0x08) /**< 1 operand, a 1-byte constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_const1s UINT8_C(0x09) /**< 1 operand, a 1-byte constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_const2u UINT8_C(0x0a) /**< 1 operand, a 2-byte constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_const2s UINT8_C(0x0b) /**< 1 operand, a 2-byte constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_const4u UINT8_C(0x0c) /**< 1 operand, a 4-byte constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_const4s UINT8_C(0x0d) /**< 1 operand, a 4-byte constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_const8u UINT8_C(0x0e) /**< 1 operand, a 8-byte constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_const8s UINT8_C(0x0f) /**< 1 operand, a 8-byte constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_constu UINT8_C(0x10) /**< 1 operand, a ULEB128 constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_consts UINT8_C(0x11) /**< 1 operand, a SLEB128 constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_dup UINT8_C(0x12) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_drop UINT8_C(0x13) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_over UINT8_C(0x14) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_pick UINT8_C(0x15) /**< 1 operands, a 1-byte stack index. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_swap UINT8_C(0x16) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_rot UINT8_C(0x17) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_xderef UINT8_C(0x18) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_abs UINT8_C(0x19) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_and UINT8_C(0x1a) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_div UINT8_C(0x1b) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_minus UINT8_C(0x1c) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_mod UINT8_C(0x1d) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_mul UINT8_C(0x1e) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_neg UINT8_C(0x1f) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_not UINT8_C(0x20) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_or UINT8_C(0x21) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_plus UINT8_C(0x22) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_plus_uconst UINT8_C(0x23) /**< 1 operands, a ULEB128 addend. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_shl UINT8_C(0x24) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_shr UINT8_C(0x25) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_shra UINT8_C(0x26) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_xor UINT8_C(0x27) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_skip UINT8_C(0x2f) /**< 1 signed 2-byte constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_bra UINT8_C(0x28) /**< 1 signed 2-byte constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_eq UINT8_C(0x29) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_ge UINT8_C(0x2a) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_gt UINT8_C(0x2b) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_le UINT8_C(0x2c) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_lt UINT8_C(0x2d) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_ne UINT8_C(0x2e) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_lit0 UINT8_C(0x30) /**< 0 operands - literals 0..31 */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_lit31 UINT8_C(0x4f) /**< last litteral. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_reg0 UINT8_C(0x50) /**< 0 operands - reg 0..31. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_reg31 UINT8_C(0x6f) /**< last register. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_breg0 UINT8_C(0x70) /**< 1 operand, a SLEB128 offset. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_breg31 UINT8_C(0x8f) /**< last branch register. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_regx UINT8_C(0x90) /**< 1 operand, a ULEB128 register. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_fbreg UINT8_C(0x91) /**< 1 operand, a SLEB128 offset. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_bregx UINT8_C(0x92) /**< 2 operands, a ULEB128 register followed by a SLEB128 offset. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_piece UINT8_C(0x93) /**< 1 operand, a ULEB128 size of piece addressed. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_deref_size UINT8_C(0x94) /**< 1 operand, a 1-byte size of data retrieved. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_xderef_size UINT8_C(0x95) /**< 1 operand, a 1-byte size of data retrieved. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_nop UINT8_C(0x96) /**< 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_lo_user UINT8_C(0xe0) /**< First user opcode */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#define DW_OP_hi_user UINT8_C(0xff) /**< Last user opcode. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/** @} */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/*******************************************************************************
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync* Structures and Typedefs *
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync*******************************************************************************/
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** Pointer to a DWARF section reader. */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFCURSOR *PRTDWARFCURSOR;
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** Pointer to an attribute descriptor. */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFATTRDESC const *PCRTDWARFATTRDESC;
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** Pointer to a DIE. */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFDIE *PRTDWARFDIE;
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** Pointer to a const DIE. */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFDIE const *PCRTDWARFDIE;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync/**
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * DWARF sections.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
5b0a093ca572a855886faa6747ad46df859dd041vboxsynctypedef enum krtDbgModDwarfSect
5b0a093ca572a855886faa6747ad46df859dd041vboxsync{
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_abbrev = 0,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_aranges,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_frame,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_info,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_inlined,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_line,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_loc,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_macinfo,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_pubnames,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_pubtypes,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_ranges,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_str,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_types,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** End of valid parts (exclusive). */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect_End
5b0a093ca572a855886faa6747ad46df859dd041vboxsync} krtDbgModDwarfSect;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/**
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Abbreviation cache entry.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsynctypedef struct RTDWARFABBREV
ad66a27959d7085aa31760f63ce082943be60e89vboxsync{
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Whether this entry is filled in or not. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync bool fFilled;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Whether there are children or not. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync bool fChildren;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** The tag. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint16_t uTag;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Offset into the abbrev section of the specification pairs. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t offSpec;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync} RTDWARFABBREV;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/** Pointer to an abbreviation cache entry. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsynctypedef RTDWARFABBREV *PRTDWARFABBREV;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/** Pointer to a const abbreviation cache entry. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsynctypedef RTDWARFABBREV const *PCRTDWARFABBREV;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/**
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * Structure for gathering segment info.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsynctypedef struct RTDBGDWARFSEG
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync{
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** The highest offset in the segment. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync uint64_t offHighest;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** Calculated base address. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync uint64_t uBaseAddr;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** Estimated The segment size. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync uint64_t cbSegment;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** Segment number (RTLDRSEG::Sel16bit). */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync RTSEL uSegment;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync} RTDBGDWARFSEG;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/** Pointer to segment info. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsynctypedef RTDBGDWARFSEG *PRTDBGDWARFSEG;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/**
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * The instance data of the DWARF reader.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsynctypedef struct RTDBGMODDWARF
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync{
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** The debug container containing doing the real work. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync RTDBGMOD hCnt;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync /** The image module (no reference). */
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync PRTDBGMODINT pImgMod;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync /** The debug info module (no reference). */
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync PRTDBGMODINT pDbgInfoMod;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync /** Nested image module (with reference ofc). */
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync PRTDBGMODINT pNestedMod;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** DWARF debug info sections. */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync struct
5b0a093ca572a855886faa6747ad46df859dd041vboxsync {
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** The file offset of the part. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync RTFOFF offFile;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** The size of the part. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync size_t cb;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** The memory mapping of the part. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync void const *pv;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** Set if present. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync bool fPresent;
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync /** The debug info ordinal number in the image file. */
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync uint32_t iDbgInfo;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync } aSections[krtDbgModDwarfSect_End];
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** The offset into the abbreviation section of the current cache. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t offCachedAbbrev;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** The number of cached abbreviations we've allocated space for. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t cCachedAbbrevsAlloced;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Used for range checking cache lookups. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t cCachedAbbrevs;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Array of cached abbreviations, indexed by code. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync PRTDWARFABBREV paCachedAbbrevs;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Used by rtDwarfAbbrev_Lookup when the result is uncachable. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync RTDWARFABBREV LookupAbbrev;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The list of compilation units (RTDWARFDIE). */
e961f5bfe1727c6816d3dad3805ebe21b6ba1c64vboxsync RTLISTANCHOR CompileUnitList;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** This is set to -1 if we're doing everything in one pass.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * Otherwise it's 1 or 2:
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * - In pass 1, we collect segment info.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * - In pass 2, we add debug info to the container.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * The two pass parsing is necessary for watcom generated symbol files as
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * these contains no information about the code and data segments in the
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * image. So we have to figure out some approximate stuff based on the
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * segments and offsets we encounter in the debug info. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync int8_t iWatcomPass;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** Segment index hint. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync uint16_t iSegHint;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** The number of segments in paSegs.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * (During segment copying, this is abused to count useful segments.) */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync uint32_t cSegs;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** Pointer to segments if iWatcomPass isn't -1. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync PRTDBGDWARFSEG paSegs;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync} RTDBGMODDWARF;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** Pointer to instance data of the DWARF reader. */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsynctypedef RTDBGMODDWARF *PRTDBGMODDWARF;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF cursor for reading byte data.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFCURSOR
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync /** The current position. */
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync uint8_t const *pb;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync /** The number of bytes left to read. */
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync size_t cbLeft;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /** The number of bytes left to read in the current unit. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync size_t cbUnitLeft;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /** The DWARF debug info reader instance. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync PRTDBGMODDWARF pDwarfMod;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync /** Set if this is 64-bit DWARF, clear if 32-bit. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync bool f64bitDwarf;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync /** Set if the format endian is native, clear if endian needs to be
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync * inverted. */
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync bool fNativEndian;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /** The size of a native address. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint8_t cbNativeAddr;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /** The cursor status code. This is VINF_SUCCESS until some error
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * occurs. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync int rc;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** The start of the area covered by the cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Used for repositioning the cursor relative to the start of a section. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint8_t const *pbStart;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** The section. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync krtDbgModDwarfSect enmSect;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync} RTDWARFCURSOR;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF line number program state.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsynctypedef struct RTDWARFLINESTATE
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** Virtual Line Number Machine Registers. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync struct
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync {
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint64_t uAddress;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint64_t idxOp;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint32_t iFile;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint32_t uLine;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint32_t uColumn;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync bool fIsStatement;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync bool fBasicBlock;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync bool fEndSequence;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync bool fPrologueEnd;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync bool fEpilogueBegin;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint32_t uIsa;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint32_t uDiscriminator;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync RTSEL uSegment;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync } Regs;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** @} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** Header. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync struct
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync {
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint32_t uVer;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint64_t offFirstOpcode;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint8_t cbMinInstr;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint8_t cMaxOpsPerInstr;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint8_t u8DefIsStmt;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync int8_t s8LineBase;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint8_t u8LineRange;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint8_t u8OpcodeBase;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint8_t const *pacStdOperands;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync } Hdr;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** @name Include Path Table (0-based)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @{ */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync const char **papszIncPaths;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint32_t cIncPaths;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** @} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** @name File Name Table (0-based, dummy zero entry)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @{ */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync char **papszFileNames;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint32_t cFileNames;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** @} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /** The DWARF debug info reader instance. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pDwarfMod;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync} RTDWARFLINESTATE;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** Pointer to a DWARF line number program state. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsynctypedef RTDWARFLINESTATE *PRTDWARFLINESTATE;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/**
e4bf6817370e1a71833a02285515694afcda7599vboxsync * Decodes an attribute and stores it in the specified DIE member field.
e4bf6817370e1a71833a02285515694afcda7599vboxsync *
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @returns IPRT status code.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @param pDie Pointer to the DIE structure.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @param pbMember Pointer to the first byte in the member.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @param pDesc The attribute descriptor.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @param uForm The data form.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @param pDataCursor The cursor to read data from.
e4bf6817370e1a71833a02285515694afcda7599vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef DECLCALLBACK(int) FNRTDWARFATTRDECODER(PRTDWARFDIE pDie, uint8_t *pbMember, PCRTDWARFATTRDESC pDesc,
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint32_t uForm, PRTDWARFCURSOR pCursor);
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** Pointer to an attribute decoder callback. */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef FNRTDWARFATTRDECODER *PFNRTDWARFATTRDECODER;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/**
e4bf6817370e1a71833a02285515694afcda7599vboxsync * Attribute descriptor.
e4bf6817370e1a71833a02285515694afcda7599vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFATTRDESC
e4bf6817370e1a71833a02285515694afcda7599vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The attribute. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint8_t uAttr;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The data member size and initialization method. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint8_t cbInit;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The data member offset. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint16_t off;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The decoder function. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync PFNRTDWARFATTRDECODER pfnDecoder;
e4bf6817370e1a71833a02285515694afcda7599vboxsync} RTDWARFATTRDESC;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** Define a attribute entry. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define ATTR_ENTRY(a_uAttr, a_Struct, a_Member, a_Init, a_pfnDecoder) \
e4bf6817370e1a71833a02285515694afcda7599vboxsync { \
e4bf6817370e1a71833a02285515694afcda7599vboxsync a_uAttr, \
e4bf6817370e1a71833a02285515694afcda7599vboxsync a_Init | ((uint8_t)RT_SIZEOFMEMB(a_Struct, a_Member) & ATTR_SIZE_MASK), \
e4bf6817370e1a71833a02285515694afcda7599vboxsync (uint16_t)RT_OFFSETOF(a_Struct, a_Member), \
e4bf6817370e1a71833a02285515694afcda7599vboxsync a_pfnDecoder\
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** @name Attribute size and init methods.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @{ */
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define ATTR_INIT_ZERO UINT8_C(0x00)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync#define ATTR_INIT_FFFS UINT8_C(0x80)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync#define ATTR_INIT_MASK UINT8_C(0x80)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define ATTR_SIZE_MASK UINT8_C(0x3f)
e4bf6817370e1a71833a02285515694afcda7599vboxsync#define ATTR_GET_SIZE(a_pAttrDesc) ((a_pAttrDesc)->cbInit & ATTR_SIZE_MASK)
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** @} */
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/**
e4bf6817370e1a71833a02285515694afcda7599vboxsync * DIE descriptor.
e4bf6817370e1a71833a02285515694afcda7599vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFDIEDESC
e4bf6817370e1a71833a02285515694afcda7599vboxsync{
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /** The size of the DIE. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync size_t cbDie;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The number of attributes. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync size_t cAttributes;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The */
e4bf6817370e1a71833a02285515694afcda7599vboxsync PCRTDWARFATTRDESC paAttributes;
e4bf6817370e1a71833a02285515694afcda7599vboxsync} RTDWARFDIEDESC;
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFDIEDESC const *PCRTDWARFDIEDESC;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync/** DIE descriptor initializer. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync#define DIE_DESC_INIT(a_Type, a_aAttrs) { sizeof(a_Type), RT_ELEMENTS(a_aAttrs), &a_aAttrs[0] }
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/**
e4bf6817370e1a71833a02285515694afcda7599vboxsync * DIE core structure, all inherits (starts with) this.
e4bf6817370e1a71833a02285515694afcda7599vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFDIE
e4bf6817370e1a71833a02285515694afcda7599vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** Pointer to the parent node. NULL if root unit. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync struct RTDWARFDIE *pParent;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** Our node in the sibling list. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync RTLISTNODE SiblingNode;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** List of children. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync RTLISTNODE ChildList;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The number of attributes successfully decoded. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint8_t cDecodedAttrs;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The number of unknown or otherwise unhandled attributes. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint8_t cUnhandledAttrs;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The date tag, indicating which union structure to use. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint16_t uTag;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** Offset of the abbreviation specification (within debug_abbrev). */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint32_t offSpec;
e4bf6817370e1a71833a02285515694afcda7599vboxsync} RTDWARFDIE;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/**
e4bf6817370e1a71833a02285515694afcda7599vboxsync * DWARF address structure.
e4bf6817370e1a71833a02285515694afcda7599vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFADDR
e4bf6817370e1a71833a02285515694afcda7599vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The address. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t uAddress;
e4bf6817370e1a71833a02285515694afcda7599vboxsync} RTDWARFADDR;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsynctypedef RTDWARFADDR *PRTDWARFADDR;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsynctypedef RTDWARFADDR const *PCRTDWARFADDR;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/**
e4bf6817370e1a71833a02285515694afcda7599vboxsync * DWARF address range.
e4bf6817370e1a71833a02285515694afcda7599vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFADDRRANGE
e4bf6817370e1a71833a02285515694afcda7599vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t uLowAddress;
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t uHighAddress;
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint8_t const *pbRanges; /* ?? */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync uint8_t cAttrs : 2;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync uint8_t fHaveLowAddress : 1;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync uint8_t fHaveHighAddress : 1;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync uint8_t fHaveRanges : 1;
e4bf6817370e1a71833a02285515694afcda7599vboxsync} RTDWARFADDRRANGE;
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef RTDWARFADDRRANGE *PRTDWARFADDRRANGE;
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef RTDWARFADDRRANGE const *PCRTDWARFADDRRANGE;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** What a RTDWARFREF is relative to. */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef enum krtDwarfRef
e4bf6817370e1a71833a02285515694afcda7599vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync krtDwarfRef_NotSet,
e4bf6817370e1a71833a02285515694afcda7599vboxsync krtDwarfRef_LineSection,
e4bf6817370e1a71833a02285515694afcda7599vboxsync krtDwarfRef_LocSection,
e4bf6817370e1a71833a02285515694afcda7599vboxsync krtDwarfRef_RangesSection,
e4bf6817370e1a71833a02285515694afcda7599vboxsync krtDwarfRef_InfoSection,
e4bf6817370e1a71833a02285515694afcda7599vboxsync krtDwarfRef_SameUnit,
e4bf6817370e1a71833a02285515694afcda7599vboxsync krtDwarfRef_TypeId64
e4bf6817370e1a71833a02285515694afcda7599vboxsync} krtDwarfRef;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/**
e4bf6817370e1a71833a02285515694afcda7599vboxsync * DWARF reference.
e4bf6817370e1a71833a02285515694afcda7599vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFREF
e4bf6817370e1a71833a02285515694afcda7599vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The offset. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t off;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** What the offset is relative to. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync krtDwarfRef enmWrt;
e4bf6817370e1a71833a02285515694afcda7599vboxsync} RTDWARFREF;
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef RTDWARFREF *PRTDWARFREF;
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef RTDWARFREF const *PCRTDWARFREF;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/**
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * DWARF Location state.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsynctypedef struct RTDWARFLOCST
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync{
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync /** The input cursor. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RTDWARFCURSOR Cursor;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync /** Points to the current top of the stack. Initial value -1. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync int32_t iTop;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync /** The value stack. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uint64_t auStack[64];
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync} RTDWARFLOCST;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/** Pointer to location state. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsynctypedef RTDWARFLOCST *PRTDWARFLOCST;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/*******************************************************************************
e4bf6817370e1a71833a02285515694afcda7599vboxsync* Internal Functions *
e4bf6817370e1a71833a02285515694afcda7599vboxsync*******************************************************************************/
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsyncstatic FNRTDWARFATTRDECODER rtDwarfDecode_Address;
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic FNRTDWARFATTRDECODER rtDwarfDecode_Bool;
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic FNRTDWARFATTRDECODER rtDwarfDecode_LowHighPc;
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic FNRTDWARFATTRDECODER rtDwarfDecode_Ranges;
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic FNRTDWARFATTRDECODER rtDwarfDecode_Reference;
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic FNRTDWARFATTRDECODER rtDwarfDecode_SectOff;
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic FNRTDWARFATTRDECODER rtDwarfDecode_String;
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic FNRTDWARFATTRDECODER rtDwarfDecode_UnsignedInt;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsyncstatic FNRTDWARFATTRDECODER rtDwarfDecode_SegmentLoc;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/*******************************************************************************
e4bf6817370e1a71833a02285515694afcda7599vboxsync* Global Variables *
e4bf6817370e1a71833a02285515694afcda7599vboxsync*******************************************************************************/
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync/** RTDWARFDIE description. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsyncstatic const RTDWARFDIEDESC g_CoreDieDesc = { sizeof(RTDWARFDIE), 0, NULL };
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/**
e4bf6817370e1a71833a02285515694afcda7599vboxsync * DW_TAG_compile_unit & DW_TAG_partial_unit.
e4bf6817370e1a71833a02285515694afcda7599vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef struct RTDWARFDIECOMPILEUNIT
e4bf6817370e1a71833a02285515694afcda7599vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The DIE core structure. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync RTDWARFDIE Core;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The unit name. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync const char *pszName;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The address range of the code belonging to this unit. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync RTDWARFADDRRANGE PcRange;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The language name. */
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync uint16_t uLanguage;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The identifier case. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint8_t uIdentifierCase;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** String are UTF-8 encoded. If not set, the encoding is
e4bf6817370e1a71833a02285515694afcda7599vboxsync * unknown. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync bool fUseUtf8;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The unit contains main() or equivalent. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync bool fMainFunction;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The line numbers for this unit. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync RTDWARFREF StmtListRef;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The macro information for this unit. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync RTDWARFREF MacroInfoRef;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** Reference to the base types. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync RTDWARFREF BaseTypesRef;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** Working directory for the unit. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync const char *pszCurDir;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The name of the compiler or whatever that produced this unit. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync const char *pszProducer;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** @name From the unit header.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @{ */
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The offset into debug_info of this unit (for references). */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t offUnit;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The length of this unit. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t cbUnit;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The offset into debug_abbrev of the abbreviation for this unit. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t offAbbrev;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The native address size. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint8_t cbNativeAddr;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** The DWARF version. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint8_t uDwarfVer;
e4bf6817370e1a71833a02285515694afcda7599vboxsync /** @} */
e4bf6817370e1a71833a02285515694afcda7599vboxsync} RTDWARFDIECOMPILEUNIT;
e4bf6817370e1a71833a02285515694afcda7599vboxsynctypedef RTDWARFDIECOMPILEUNIT *PRTDWARFDIECOMPILEUNIT;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** RTDWARFDIECOMPILEUNIT attributes. */
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic const RTDWARFATTRDESC g_aCompileUnitAttrs[] =
e4bf6817370e1a71833a02285515694afcda7599vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync ATTR_ENTRY(DW_AT_name, RTDWARFDIECOMPILEUNIT, pszName, ATTR_INIT_ZERO, rtDwarfDecode_String),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync ATTR_ENTRY(DW_AT_low_pc, RTDWARFDIECOMPILEUNIT, PcRange, ATTR_INIT_ZERO, rtDwarfDecode_LowHighPc),
e4bf6817370e1a71833a02285515694afcda7599vboxsync ATTR_ENTRY(DW_AT_high_pc, RTDWARFDIECOMPILEUNIT, PcRange, ATTR_INIT_ZERO, rtDwarfDecode_LowHighPc),
e4bf6817370e1a71833a02285515694afcda7599vboxsync ATTR_ENTRY(DW_AT_ranges, RTDWARFDIECOMPILEUNIT, PcRange, ATTR_INIT_ZERO, rtDwarfDecode_Ranges),
e4bf6817370e1a71833a02285515694afcda7599vboxsync ATTR_ENTRY(DW_AT_language, RTDWARFDIECOMPILEUNIT, uLanguage, ATTR_INIT_ZERO, rtDwarfDecode_UnsignedInt),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync ATTR_ENTRY(DW_AT_macro_info, RTDWARFDIECOMPILEUNIT, MacroInfoRef, ATTR_INIT_ZERO, rtDwarfDecode_SectOff),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync ATTR_ENTRY(DW_AT_stmt_list, RTDWARFDIECOMPILEUNIT, StmtListRef, ATTR_INIT_ZERO, rtDwarfDecode_SectOff),
e4bf6817370e1a71833a02285515694afcda7599vboxsync ATTR_ENTRY(DW_AT_comp_dir, RTDWARFDIECOMPILEUNIT, pszCurDir, ATTR_INIT_ZERO, rtDwarfDecode_String),
e4bf6817370e1a71833a02285515694afcda7599vboxsync ATTR_ENTRY(DW_AT_producer, RTDWARFDIECOMPILEUNIT, pszProducer, ATTR_INIT_ZERO, rtDwarfDecode_String),
e4bf6817370e1a71833a02285515694afcda7599vboxsync ATTR_ENTRY(DW_AT_identifier_case, RTDWARFDIECOMPILEUNIT, uIdentifierCase,ATTR_INIT_ZERO, rtDwarfDecode_UnsignedInt),
e4bf6817370e1a71833a02285515694afcda7599vboxsync ATTR_ENTRY(DW_AT_base_types, RTDWARFDIECOMPILEUNIT, BaseTypesRef, ATTR_INIT_ZERO, rtDwarfDecode_Reference),
e4bf6817370e1a71833a02285515694afcda7599vboxsync ATTR_ENTRY(DW_AT_use_UTF8, RTDWARFDIECOMPILEUNIT, fUseUtf8, ATTR_INIT_ZERO, rtDwarfDecode_Bool),
e4bf6817370e1a71833a02285515694afcda7599vboxsync ATTR_ENTRY(DW_AT_main_subprogram, RTDWARFDIECOMPILEUNIT, fMainFunction, ATTR_INIT_ZERO, rtDwarfDecode_Bool)
e4bf6817370e1a71833a02285515694afcda7599vboxsync};
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** RTDWARFDIECOMPILEUNIT description. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsyncstatic const RTDWARFDIEDESC g_CompileUnitDesc = DIE_DESC_INIT(RTDWARFDIECOMPILEUNIT, g_aCompileUnitAttrs);
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync/**
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * DW_TAG_subprogram.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsynctypedef struct RTDWARFDIESUBPROGRAM
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync{
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /** The DIE core structure. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync RTDWARFDIE Core;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /** The name. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync const char *pszName;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /** The linkage name. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync const char *pszLinkageName;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /** The address range of the code belonging to this unit. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync RTDWARFADDRRANGE PcRange;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /** The first instruction in the function. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync RTDWARFADDR EntryPc;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync /** Segment number (watcom). */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RTSEL uSegment;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync} RTDWARFDIESUBPROGRAM;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync/** Pointer to a DW_TAG_subprogram DIE. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsynctypedef RTDWARFDIESUBPROGRAM *PRTDWARFDIESUBPROGRAM;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync/** Pointer to a const DW_TAG_subprogram DIE. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsynctypedef RTDWARFDIESUBPROGRAM const *PCRTDWARFDIESUBPROGRAM;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync/** RTDWARFDIESUBPROGRAM attributes. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsyncstatic const RTDWARFATTRDESC g_aSubProgramAttrs[] =
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync{
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync ATTR_ENTRY(DW_AT_name, RTDWARFDIESUBPROGRAM, pszName, ATTR_INIT_ZERO, rtDwarfDecode_String),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync ATTR_ENTRY(DW_AT_linkage_name, RTDWARFDIESUBPROGRAM, pszLinkageName, ATTR_INIT_ZERO, rtDwarfDecode_String),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync ATTR_ENTRY(DW_AT_low_pc, RTDWARFDIESUBPROGRAM, PcRange, ATTR_INIT_ZERO, rtDwarfDecode_LowHighPc),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync ATTR_ENTRY(DW_AT_high_pc, RTDWARFDIESUBPROGRAM, PcRange, ATTR_INIT_ZERO, rtDwarfDecode_LowHighPc),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync ATTR_ENTRY(DW_AT_ranges, RTDWARFDIESUBPROGRAM, PcRange, ATTR_INIT_ZERO, rtDwarfDecode_Ranges),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync ATTR_ENTRY(DW_AT_entry_pc, RTDWARFDIESUBPROGRAM, EntryPc, ATTR_INIT_ZERO, rtDwarfDecode_Address),
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync ATTR_ENTRY(DW_AT_segment, RTDWARFDIESUBPROGRAM, uSegment, ATTR_INIT_ZERO, rtDwarfDecode_SegmentLoc)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync};
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync/** RTDWARFDIESUBPROGRAM description. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsyncstatic const RTDWARFDIEDESC g_SubProgramDesc = DIE_DESC_INIT(RTDWARFDIESUBPROGRAM, g_aSubProgramAttrs);
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/**
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * DW_TAG_label.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsynctypedef struct RTDWARFDIELABEL
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync{
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** The DIE core structure. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync RTDWARFDIE Core;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** The name. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync const char *pszName;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** The address of the first instruction. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync RTDWARFADDR Address;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** Segment number (watcom). */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync RTSEL uSegment;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** Externally visible? */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync bool fExternal;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync} RTDWARFDIELABEL;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/** Pointer to a DW_TAG_label DIE. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsynctypedef RTDWARFDIELABEL *PRTDWARFDIELABEL;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/** Pointer to a const DW_TAG_label DIE. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsynctypedef RTDWARFDIELABEL const *PCRTDWARFDIELABEL;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/** RTDWARFDIESUBPROGRAM attributes. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncstatic const RTDWARFATTRDESC g_aLabelAttrs[] =
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync{
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync ATTR_ENTRY(DW_AT_name, RTDWARFDIELABEL, pszName, ATTR_INIT_ZERO, rtDwarfDecode_String),
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync ATTR_ENTRY(DW_AT_low_pc, RTDWARFDIELABEL, Address, ATTR_INIT_ZERO, rtDwarfDecode_Address),
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync ATTR_ENTRY(DW_AT_segment, RTDWARFDIELABEL, uSegment, ATTR_INIT_ZERO, rtDwarfDecode_SegmentLoc),
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync ATTR_ENTRY(DW_AT_external, RTDWARFDIELABEL, fExternal, ATTR_INIT_ZERO, rtDwarfDecode_Bool)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync};
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/** RTDWARFDIESUBPROGRAM description. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncstatic const RTDWARFDIEDESC g_LabelDesc = DIE_DESC_INIT(RTDWARFDIELABEL, g_aLabelAttrs);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync/**
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * Tag names and descriptors.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsyncstatic const struct RTDWARFTAGDESC
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync{
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /** The tag value. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync uint16_t uTag;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /** The tag name as string. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync const char *pszName;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /** The DIE descriptor to use. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync PCRTDWARFDIEDESC pDesc;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync} g_aTagDescs[] =
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync{
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync#define TAGDESC(a_Name, a_pDesc) { DW_ ## a_Name, #a_Name, a_pDesc }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync#define TAGDESC_EMPTY() { 0, NULL, NULL }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync#define TAGDESC_CORE(a_Name) TAGDESC(a_Name, &g_CoreDieDesc)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_EMPTY(), /* 0x00 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_array_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_class_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_entry_point),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_enumeration_type), /* 0x04 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_formal_parameter),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_EMPTY(),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_EMPTY(),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_imported_declaration), /* 0x08 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_EMPTY(),
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync TAGDESC(TAG_label, &g_LabelDesc),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_lexical_block),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_EMPTY(), /* 0x0c */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_member),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_EMPTY(),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_pointer_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_reference_type), /* 0x10 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_compile_unit),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_string_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_structure_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_EMPTY(), /* 0x14 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_subroutine_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_typedef),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_union_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_unspecified_parameters), /* 0x18 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_variant),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_common_block),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_common_inclusion),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_inheritance), /* 0x1c */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_inlined_subroutine),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_module),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_ptr_to_member_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_set_type), /* 0x20 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_subrange_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_with_stmt),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_access_declaration),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_base_type), /* 0x24 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_catch_block),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_const_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_constant),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_enumerator), /* 0x28 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_file_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_friend),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_namelist),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_namelist_item), /* 0x2c */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_packed_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC(TAG_subprogram, &g_SubProgramDesc),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_template_type_parameter),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_template_value_parameter), /* 0x30 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_thrown_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_try_block),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_variant_part),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_variable), /* 0x34 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_volatile_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_dwarf_procedure),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_restrict_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_interface_type), /* 0x38 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_namespace),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_imported_module),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_unspecified_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_partial_unit), /* 0x3c */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_imported_unit),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_EMPTY(),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_condition),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_shared_type), /* 0x40 */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_type_unit),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_rvalue_reference_type),
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync TAGDESC_CORE(TAG_template_alias)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync#undef TAGDESC
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync#undef TAGDESC_EMPTY
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync#undef TAGDESC_CORE
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync};
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#if defined(LOG_ENABLED) || defined(RT_STRICT)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/**
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * Turns a tag value into a string for logging purposes.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync *
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @returns String name.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param uTag The tag.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsyncstatic const char *rtDwarfLog_GetTagName(uint32_t uTag)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync{
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (uTag < RT_ELEMENTS(g_aTagDescs))
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync const char *pszTag = g_aTagDescs[uTag].pszName;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (pszTag)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return pszTag;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync static char s_szStatic[32];
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RTStrPrintf(s_szStatic, sizeof(s_szStatic),"DW_TAG_%#x", uTag);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return s_szStatic;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync}
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/**
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * Turns an attributevalue into a string for logging purposes.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync *
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @returns String name.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param uAttr The attribute.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsyncstatic const char *rtDwarfLog_AttrName(uint32_t uAttr)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync{
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync switch (uAttr)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_sibling);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_location);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_name);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_ordering);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_byte_size);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_bit_offset);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_bit_size);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_stmt_list);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_low_pc);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_high_pc);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_language);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_discr);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_discr_value);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_visibility);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_import);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_string_length);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_common_reference);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_comp_dir);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_const_value);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_containing_type);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_default_value);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_inline);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_is_optional);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_lower_bound);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_producer);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_prototyped);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_return_addr);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_start_scope);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_bit_stride);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_upper_bound);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_abstract_origin);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_accessibility);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_address_class);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_artificial);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_base_types);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_calling_convention);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_count);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_data_member_location);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_decl_column);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_decl_file);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_decl_line);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_declaration);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_discr_list);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_encoding);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_external);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_frame_base);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_friend);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_identifier_case);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_macro_info);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_namelist_item);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_priority);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_segment);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_specification);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_static_link);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_type);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_use_location);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_variable_parameter);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_virtuality);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_vtable_elem_location);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_allocated);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_associated);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_data_location);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_byte_stride);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_entry_pc);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_use_UTF8);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_extension);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_ranges);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_trampoline);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_call_column);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_call_file);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_call_line);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_description);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_binary_scale);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_decimal_scale);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_small);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_decimal_sign);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_digit_count);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_picture_string);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_mutable);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_threads_scaled);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_explicit);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_object_pointer);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_endianity);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_elemental);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_pure);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_recursive);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_signature);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_main_subprogram);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_data_bit_offset);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_const_expr);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_enum_class);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_AT_linkage_name);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync static char s_szStatic[32];
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RTStrPrintf(s_szStatic, sizeof(s_szStatic),"DW_AT_%#x", uAttr);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return s_szStatic;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync}
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/**
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * Turns a form value into a string for logging purposes.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync *
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @returns String name.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param uForm The form.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsyncstatic const char *rtDwarfLog_FormName(uint32_t uForm)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync{
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync switch (uForm)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_addr);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_block2);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_block4);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_data2);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_data4);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_data8);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_string);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_block);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_block1);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_data1);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_flag);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_sdata);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_strp);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_udata);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_ref_addr);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_ref1);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_ref2);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_ref4);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_ref8);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_ref_udata);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_indirect);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_sec_offset);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_exprloc);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_flag_present);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RT_CASE_RET_STR(DW_FORM_ref_sig8);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync static char s_szStatic[32];
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RTStrPrintf(s_szStatic, sizeof(s_szStatic),"DW_FORM_%#x", uForm);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return s_szStatic;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync}
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#endif /* LOG_ENABLED || RT_STRICT */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @callback_method_impl{FNRTLDRENUMSEGS} */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarfScanSegmentsCallback(RTLDRMOD hLdrMod, PCRTLDRSEG pSeg, void *pvUser)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync{
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pvUser;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync Log(("Segment %.*s: LinkAddress=%#llx RVA=%#llx cb=%#llx\n",
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pSeg->cchName, pSeg->pchName, (uint64_t)pSeg->LinkAddress, (uint64_t)pSeg->RVA, pSeg->cb));
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync NOREF(hLdrMod);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /* Count relevant segments. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (pSeg->RVA != NIL_RTLDRADDR)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pThis->cSegs++;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return VINF_SUCCESS;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync}
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/** @callback_method_impl{FNRTLDRENUMSEGS} */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarfAddSegmentsCallback(RTLDRMOD hLdrMod, PCRTLDRSEG pSeg, void *pvUser)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pvUser;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync Log(("Segment %.*s: LinkAddress=%#llx RVA=%#llx cb=%#llx\n",
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pSeg->cchName, pSeg->pchName, (uint64_t)pSeg->LinkAddress, (uint64_t)pSeg->RVA, pSeg->cb));
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync NOREF(hLdrMod);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync AssertReturn(!pSeg->pchName[pSeg->cchName], VERR_DWARF_IPE);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync /* If the segment doesn't have a mapping, just add a dummy so the indexing
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync works out correctly (same as for the image). */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (pSeg->RVA == NIL_RTLDRADDR)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return RTDbgModSegmentAdd(pThis->hCnt, 0, 0, pSeg->pchName, 0 /*fFlags*/, NULL);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync /* The link address is 0 for all segments in a relocatable ELF image. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync RTLDRADDR cb = RT_MAX(pSeg->cb, pSeg->cbMapped);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return RTDbgModSegmentAdd(pThis->hCnt, pSeg->RVA, cb, pSeg->pchName, 0 /*fFlags*/, NULL);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Calls pfnSegmentAdd for each segment in the executable image.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * @param pThis The DWARF instance.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
d1e9999d55e7ac80a28692c161710be98071fc00vboxsyncstatic int rtDbgModDwarfAddSegmentsFromImage(PRTDBGMODDWARF pThis)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync AssertReturn(pThis->pImgMod && pThis->pImgMod->pImgVt, VERR_INTERNAL_ERROR_2);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync Assert(!pThis->cSegs);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync int rc = pThis->pImgMod->pImgVt->pfnEnumSegments(pThis->pImgMod, rtDbgModDwarfScanSegmentsCallback, pThis);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (RT_SUCCESS(rc))
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (pThis->cSegs == 0)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pThis->iWatcomPass = 1;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync else
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pThis->cSegs = 0;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pThis->iWatcomPass = -1;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync rc = pThis->pImgMod->pImgVt->pfnEnumSegments(pThis->pImgMod, rtDbgModDwarfAddSegmentsCallback, pThis);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return rc;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync}
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/**
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * Looks up a segment.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync *
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * @returns Pointer to the segment on success, NULL if not found.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * @param pThis The DWARF instance.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * @param uSeg The segment number / selector.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncstatic PRTDBGDWARFSEG rtDbgModDwarfFindSegment(PRTDBGMODDWARF pThis, RTSEL uSeg)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync{
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync uint32_t cSegs = pThis->cSegs;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync uint32_t iSeg = pThis->iSegHint;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync PRTDBGDWARFSEG paSegs = pThis->paSegs;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if ( iSeg < cSegs
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync && paSegs[iSeg].uSegment == uSeg)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return &paSegs[iSeg];
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync for (iSeg = 0; iSeg < cSegs; iSeg++)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (uSeg == paSegs[iSeg].uSegment)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pThis->iSegHint = iSeg;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return &paSegs[iSeg];
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync AssertFailed();
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return NULL;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync}
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/**
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * Record a segment:offset during pass 1.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync *
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * @returns IPRT status code.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * @param pThis The DWARF instance.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * @param uSeg The segment number / selector.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * @param offSeg The segment offset.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncstatic int rtDbgModDwarfRecordSegOffset(PRTDBGMODDWARF pThis, RTSEL uSeg, uint64_t offSeg)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync{
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /* Look up the segment. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync uint32_t cSegs = pThis->cSegs;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync uint32_t iSeg = pThis->iSegHint;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync PRTDBGDWARFSEG paSegs = pThis->paSegs;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if ( iSeg >= cSegs
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync || paSegs[iSeg].uSegment != uSeg)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync for (iSeg = 0; iSeg < cSegs; iSeg++)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (uSeg <= paSegs[iSeg].uSegment)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync break;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if ( iSeg >= cSegs
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync || paSegs[iSeg].uSegment != uSeg)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /* Add */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync void *pvNew = RTMemRealloc(paSegs, (pThis->cSegs + 1) * sizeof(paSegs[0]));
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (!pvNew)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return VERR_NO_MEMORY;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pThis->paSegs = paSegs = (PRTDBGDWARFSEG)pvNew;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (iSeg != cSegs)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync memmove(&paSegs[iSeg + 1], &paSegs[iSeg], (cSegs - iSeg) * sizeof(paSegs[0]));
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync paSegs[iSeg].offHighest = offSeg;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync paSegs[iSeg].uBaseAddr = 0;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync paSegs[iSeg].cbSegment = 0;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync paSegs[iSeg].uSegment = uSeg;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pThis->cSegs++;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pThis->iSegHint = iSeg;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /* Increase it's range? */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (paSegs[iSeg].offHighest < offSeg)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync Log3(("rtDbgModDwarfRecordSegOffset: iSeg=%d uSeg=%#06x offSeg=%#llx\n", iSeg, uSeg, offSeg));
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync paSegs[iSeg].offHighest = offSeg;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return VINF_SUCCESS;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync/**
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * Calls pfnSegmentAdd for each segment in the executable image.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync *
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * @returns IPRT status code.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * @param pThis The DWARF instance.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncstatic int rtDbgModDwarfAddSegmentsFromPass1(PRTDBGMODDWARF pThis)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync{
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync AssertReturn(pThis->cSegs, VERR_DWARF_BAD_INFO);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync uint32_t const cSegs = pThis->cSegs;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync PRTDBGDWARFSEG paSegs = pThis->paSegs;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /*
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * Are the segments assigned more or less in numerical order?
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if ( paSegs[0].uSegment < 16U
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync && paSegs[cSegs - 1].uSegment - paSegs[0].uSegment + 1U <= cSegs + 16U)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /** @todo heuristics, plase. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync AssertFailedReturn(VERR_DWARF_TODO);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /*
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * Assume DOS segmentation.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync else
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync paSegs[iSeg].uBaseAddr = (uint32_t)paSegs[iSeg].uSegment << 16;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync paSegs[iSeg].cbSegment = paSegs[iSeg].offHighest;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /*
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * Add them.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync Log3(("rtDbgModDwarfAddSegmentsFromPass1: Seg#%u: %#010llx LB %#llx uSegment=%#x\n",
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync iSeg, paSegs[iSeg].uBaseAddr, paSegs[iSeg].cbSegment, paSegs[iSeg].uSegment));
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync char szName[32];
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync RTStrPrintf(szName, sizeof(szName), "seg-%#04xh", paSegs[iSeg].uSegment);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync int rc = RTDbgModSegmentAdd(pThis->hCnt, paSegs[iSeg].uBaseAddr, paSegs[iSeg].cbSegment,
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync szName, 0 /*fFlags*/, NULL);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (RT_FAILURE(rc))
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return rc;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return VINF_SUCCESS;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync/**
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Loads a DWARF section from the image file.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync *
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * @returns IPRT status code.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * @param pThis The DWARF instance.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * @param enmSect The section to load.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
5b0a093ca572a855886faa6747ad46df859dd041vboxsyncstatic int rtDbgModDwarfLoadSection(PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync{
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /*
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Don't load stuff twice.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (pThis->aSections[enmSect].pv)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return VINF_SUCCESS;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /*
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Sections that are not present cannot be loaded, treat them like they
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * are empty
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (!pThis->aSections[enmSect].fPresent)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync {
5b0a093ca572a855886faa6747ad46df859dd041vboxsync Assert(pThis->aSections[enmSect].cb);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return VINF_SUCCESS;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync }
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (!pThis->aSections[enmSect].cb)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return VINF_SUCCESS;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /*
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Sections must be readable with the current image interface.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (pThis->aSections[enmSect].offFile < 0)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return VERR_OUT_OF_RANGE;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /*
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Do the job.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync return pThis->pDbgInfoMod->pImgVt->pfnMapPart(pThis->pDbgInfoMod,
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pThis->aSections[enmSect].iDbgInfo,
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pThis->aSections[enmSect].offFile,
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pThis->aSections[enmSect].cb,
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync &pThis->aSections[enmSect].pv);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync}
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
70aa086e9e9d2f85d2e997d0e69169018a001e54vboxsync#ifdef SOME_UNUSED_FUNCTION
5b0a093ca572a855886faa6747ad46df859dd041vboxsync/**
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Unloads a DWARF section previously mapped by rtDbgModDwarfLoadSection.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync *
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * @returns IPRT status code.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * @param pThis The DWARF instance.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * @param enmSect The section to unload.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
5b0a093ca572a855886faa6747ad46df859dd041vboxsyncstatic int rtDbgModDwarfUnloadSection(PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync{
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (!pThis->aSections[enmSect].pv)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return VINF_SUCCESS;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync int rc = pThis->pDbgInfoMod->pImgVt->pfnUnmapPart(pThis->pDbgInfoMod, pThis->aSections[enmSect].cb, &pThis->aSections[enmSect].pv);
d3dea25ec07f6546715fe3af943ea863294b392evboxsync AssertRC(rc);
d3dea25ec07f6546715fe3af943ea863294b392evboxsync return rc;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync}
70aa086e9e9d2f85d2e997d0e69169018a001e54vboxsync#endif
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync/**
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Converts to UTF-8 or otherwise makes sure it's valid UTF-8.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync *
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns IPRT status code.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pThis The DWARF instance.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param ppsz Pointer to the string pointer. May be
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * reallocated (RTStr*).
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDbgModDwarfStringToUtf8(PRTDBGMODDWARF pThis, char **ppsz)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync /** @todo DWARF & UTF-8. */
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync NOREF(pThis);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync RTStrPurgeEncoding(*ppsz);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return VINF_SUCCESS;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync/**
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Convers a link address into a segment+offset or RVA.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync *
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns IPRT status code.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pThis The DWARF instance.
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * @param uSegment The segment, 0 if not applicable.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param LinkAddress The address to convert..
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param piSeg The segment index.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param poffSeg Where to return the segment offset.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsyncstatic int rtDbgModDwarfLinkAddressToSegOffset(PRTDBGMODDWARF pThis, RTSEL uSegment, uint64_t LinkAddress,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGSEGIDX piSeg, PRTLDRADDR poffSeg)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (pThis->paSegs)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync PRTDBGDWARFSEG pSeg = rtDbgModDwarfFindSegment(pThis, uSegment);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (pSeg)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync *piSeg = pSeg - pThis->paSegs;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync *poffSeg = LinkAddress;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return VINF_SUCCESS;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync return pThis->pImgMod->pImgVt->pfnRvaToSegOffset(pThis->pImgMod, LinkAddress, piSeg, poffSeg);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync //return pThis->pImgMod->pImgVt->pfnLinkAddressToSegOffset(pThis->pImgMod, LinkAddress, piSeg, poffSeg);
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/*
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a 8-bit unsigned integer and advances the cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns 8-bit unsigned integer. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on read error.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint8_t rtDwarfCursor_GetU8(PRTDWARFCURSOR pCursor, uint8_t uErrValue)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (pCursor->cbUnitLeft < 1)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_UNEXPECTED_END;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync return uErrValue;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync }
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint8_t u8 = pCursor->pb[0];
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft -= 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= 1;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync return u8;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a 16-bit unsigned integer and advances the cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns 16-bit unsigned integer. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on read error.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint16_t rtDwarfCursor_GetU16(PRTDWARFCURSOR pCursor, uint16_t uErrValue)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (pCursor->cbUnitLeft < 2)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += pCursor->cbUnitLeft;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= pCursor->cbUnitLeft;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft = 0;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_UNEXPECTED_END;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync return uErrValue;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync }
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint16_t u16 = RT_MAKE_U16(pCursor->pb[0], pCursor->pb[1]);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += 2;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft -= 2;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= 2;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (!pCursor->fNativEndian)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync u16 = RT_BSWAP_U16(u16);
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync return u16;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a 32-bit unsigned integer and advances the cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns 32-bit unsigned integer. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on read error.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint32_t rtDwarfCursor_GetU32(PRTDWARFCURSOR pCursor, uint32_t uErrValue)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (pCursor->cbUnitLeft < 4)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += pCursor->cbUnitLeft;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= pCursor->cbUnitLeft;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft = 0;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_UNEXPECTED_END;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync return uErrValue;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync }
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint32_t u32 = RT_MAKE_U32_FROM_U8(pCursor->pb[0], pCursor->pb[1], pCursor->pb[2], pCursor->pb[3]);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += 4;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft -= 4;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= 4;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (!pCursor->fNativEndian)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync u32 = RT_BSWAP_U32(u32);
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync return u32;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a 64-bit unsigned integer and advances the cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns 64-bit unsigned integer. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on read error.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint64_t rtDwarfCursor_GetU64(PRTDWARFCURSOR pCursor, uint64_t uErrValue)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (pCursor->cbUnitLeft < 8)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += pCursor->cbUnitLeft;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= pCursor->cbUnitLeft;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft = 0;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_UNEXPECTED_END;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return uErrValue;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync }
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t u64 = RT_MAKE_U64_FROM_U8(pCursor->pb[0], pCursor->pb[1], pCursor->pb[2], pCursor->pb[3],
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb[4], pCursor->pb[5], pCursor->pb[6], pCursor->pb[7]);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += 8;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft -= 8;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= 8;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (!pCursor->fNativEndian)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync u64 = RT_BSWAP_U64(u64);
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync return u64;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads an unsigned LEB128 encoded number.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns unsigned 64-bit number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param uErrValue The value to return on error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint64_t rtDwarfCursor_GetULeb128(PRTDWARFCURSOR pCursor, uint64_t uErrValue)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (pCursor->cbUnitLeft < 1)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_UNEXPECTED_END;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return uErrValue;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Special case - single byte.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint8_t b = pCursor->pb[0];
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (!(b & 0x80))
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft -= 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return b;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Generic case.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Decode. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint32_t off = 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t u64Ret = b & 0x7f;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync do
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (off == pCursor->cbUnitLeft)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_UNEXPECTED_END;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync u64Ret = uErrValue;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync b = pCursor->pb[off];
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync u64Ret |= (b & 0x7f) << off * 7;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync off++;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync } while (b & 0x80);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Update the cursor. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += off;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft -= off;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= off;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Check the range. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint32_t cBits = off * 7;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (cBits > 64)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_LEB_OVERFLOW;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync u64Ret = uErrValue;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return u64Ret;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a signed LEB128 encoded number.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns signed 64-bit number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param sErrValue The value to return on error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int64_t rtDwarfCursor_GetSLeb128(PRTDWARFCURSOR pCursor, int64_t sErrValue)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (pCursor->cbUnitLeft < 1)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_UNEXPECTED_END;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return sErrValue;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Special case - single byte.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint8_t b = pCursor->pb[0];
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (!(b & 0x80))
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft -= 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (b & 0x40)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync b |= 0x80;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return (int8_t)b;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Generic case.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Decode it. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint32_t off = 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t u64Ret = b & 0x7f;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync do
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (off == pCursor->cbUnitLeft)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_UNEXPECTED_END;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync u64Ret = (uint64_t)sErrValue;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync b = pCursor->pb[off];
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync u64Ret |= (b & 0x7f) << off * 7;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync off++;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync } while (b & 0x80);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Update cursor. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += off;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft -= off;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= off;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Check the range. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint32_t cBits = off * 7;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (cBits > 64)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_LEB_OVERFLOW;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync u64Ret = (uint64_t)sErrValue;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /* Sign extend the value. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync else if (u64Ret & RT_BIT_64(cBits - 1))
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync u64Ret |= ~(RT_BIT_64(cBits - 1) - 1);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return (int64_t)u64Ret;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads an unsigned LEB128 encoded number, max 32-bit width.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns unsigned 32-bit number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param uErrValue The value to return on error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint32_t rtDwarfCursor_GetULeb128AsU32(PRTDWARFCURSOR pCursor, uint32_t uErrValue)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t u64 = rtDwarfCursor_GetULeb128(pCursor, uErrValue);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (u64 > UINT32_MAX)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_LEB_OVERFLOW;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return uErrValue;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return (uint32_t)u64;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a signed LEB128 encoded number, max 32-bit width.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns signed 32-bit number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param sErrValue The value to return on error.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int32_t rtDwarfCursor_GetSLeb128AsS32(PRTDWARFCURSOR pCursor, int32_t sErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync int64_t s64 = rtDwarfCursor_GetSLeb128(pCursor, sErrValue);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (s64 > INT32_MAX || s64 < INT32_MIN)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_LEB_OVERFLOW;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return sErrValue;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return (int32_t)s64;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Skips a LEB128 encoded number.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDwarfCursor_SkipLeb128(PRTDWARFCURSOR pCursor)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync if (RT_FAILURE(pCursor->rc))
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return pCursor->rc;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (pCursor->cbUnitLeft < 1)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return pCursor->rc = VERR_DWARF_UNEXPECTED_END;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint32_t offSkip = 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (pCursor->pb[0] & 0x80)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync do
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (offSkip == pCursor->cbUnitLeft)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_DWARF_UNEXPECTED_END;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync } while (pCursor->pb[offSkip++] & 0x80);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += offSkip;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft -= offSkip;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= offSkip;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return pCursor->rc;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Advances the cursor a given number of bytes.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync *
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @returns IPRT status code.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param pCursor The cursor.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param offSkip The number of bytes to advance.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsyncstatic int rtDwarfCursor_SkipBytes(PRTDWARFCURSOR pCursor, uint64_t offSkip)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync{
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync if (RT_FAILURE(pCursor->rc))
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return pCursor->rc;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync if (pCursor->cbUnitLeft < offSkip)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return pCursor->rc = VERR_DWARF_UNEXPECTED_END;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync size_t const offSkipSizeT = (size_t)offSkip;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync pCursor->cbUnitLeft -= offSkipSizeT;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync pCursor->cbLeft -= offSkipSizeT;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync pCursor->pb += offSkipSizeT;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return VINF_SUCCESS;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync}
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/**
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Reads a zero terminated string, advancing the cursor beyond the terminator.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync *
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns Pointer to the string.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pszErrValue What to return if the string isn't terminated
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * before the end of the unit.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic const char *rtDwarfCursor_GetSZ(PRTDWARFCURSOR pCursor, const char *pszErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync const char *pszRet = (const char *)pCursor->pb;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync for (;;)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (!pCursor->cbUnitLeft)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync {
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pCursor->rc = VERR_DWARF_BAD_STRING;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return pszErrValue;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft--;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft--;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (!*pCursor->pb++)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return pszRet;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Reads a 1, 2, 4 or 8 byte unsgined value.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync *
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @returns 64-bit unsigned value.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param pCursor The cursor.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param cbValue The value size.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param uErrValue The error value.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsyncstatic uint64_t rtDwarfCursor_GetVarSizedU(PRTDWARFCURSOR pCursor, size_t cbValue, uint64_t uErrValue)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync{
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync uint64_t u64Ret;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync switch (cbValue)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync {
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case 1: u64Ret = rtDwarfCursor_GetU8( pCursor, UINT8_MAX); break;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case 2: u64Ret = rtDwarfCursor_GetU16(pCursor, UINT16_MAX); break;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case 4: u64Ret = rtDwarfCursor_GetU32(pCursor, UINT32_MAX); break;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case 8: u64Ret = rtDwarfCursor_GetU64(pCursor, UINT64_MAX); break;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync default:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync pCursor->rc = VERR_DWARF_BAD_INFO;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return uErrValue;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync }
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync if (RT_FAILURE(pCursor->rc))
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return uErrValue;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return u64Ret;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync}
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#if 0 /* unused */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/**
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * Gets the pointer to a variable size block and advances the cursor.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync *
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @returns Pointer to the block at the current cursor location. On error
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * RTDWARFCURSOR::rc is set and NULL returned.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param pCursor The cursor.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param cbBlock The block size.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsyncstatic const uint8_t *rtDwarfCursor_GetBlock(PRTDWARFCURSOR pCursor, uint32_t cbBlock)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync{
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (cbBlock > pCursor->cbUnitLeft)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pCursor->rc = VERR_DWARF_UNEXPECTED_END;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return NULL;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uint8_t const *pb = &pCursor->pb[0];
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pCursor->pb += cbBlock;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pCursor->cbUnitLeft -= cbBlock;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pCursor->cbLeft -= cbBlock;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return pb;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync}
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#endif
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads an unsigned DWARF half number.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns The number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on error.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint16_t rtDwarfCursor_GetUHalf(PRTDWARFCURSOR pCursor, uint16_t uErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return rtDwarfCursor_GetU16(pCursor, uErrValue);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads an unsigned DWARF byte number.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns The number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on error.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint8_t rtDwarfCursor_GetUByte(PRTDWARFCURSOR pCursor, uint8_t uErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return rtDwarfCursor_GetU8(pCursor, uErrValue);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a signed DWARF byte number.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns The number. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on error.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int8_t rtDwarfCursor_GetSByte(PRTDWARFCURSOR pCursor, int8_t iErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return (int8_t)rtDwarfCursor_GetU8(pCursor, (uint8_t)iErrValue);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a unsigned DWARF offset value.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns The value. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on error.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint64_t rtDwarfCursor_GetUOff(PRTDWARFCURSOR pCursor, uint64_t uErrValue)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (pCursor->f64bitDwarf)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return rtDwarfCursor_GetU64(pCursor, uErrValue);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return rtDwarfCursor_GetU32(pCursor, (uint32_t)uErrValue);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Reads a unsigned DWARF native offset value.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns The value. On error RTDWARFCURSOR::rc is set and @a
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * uErrValue is returned.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param uErrValue What to return on error.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic uint64_t rtDwarfCursor_GetNativeUOff(PRTDWARFCURSOR pCursor, uint64_t uErrValue)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync switch (pCursor->cbNativeAddr)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync {
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync case 1: return rtDwarfCursor_GetU8(pCursor, (uint8_t )uErrValue);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync case 2: return rtDwarfCursor_GetU16(pCursor, (uint16_t)uErrValue);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync case 4: return rtDwarfCursor_GetU32(pCursor, (uint32_t)uErrValue);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync case 8: return rtDwarfCursor_GetU64(pCursor, uErrValue);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync default:
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pCursor->rc = VERR_INTERNAL_ERROR_2;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return uErrValue;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync }
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/**
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Gets the unit length, updating the unit length member and DWARF bitness
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * members of the cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync *
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns The unit length.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic uint64_t rtDwarfCursor_GetInitalLength(PRTDWARFCURSOR pCursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Read the initial length.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft = pCursor->cbLeft;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t cbUnit = rtDwarfCursor_GetU32(pCursor, 0);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (cbUnit != UINT32_C(0xffffffff))
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->f64bitDwarf = false;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync else
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->f64bitDwarf = true;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync cbUnit = rtDwarfCursor_GetU64(pCursor, 0);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Set the unit length, quitely fixing bad lengths.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft = (size_t)cbUnit;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if ( pCursor->cbUnitLeft > pCursor->cbLeft
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync || pCursor->cbUnitLeft != cbUnit)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft = pCursor->cbLeft;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return cbUnit;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/**
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Calculates the section offset corresponding to the current cursor position.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync *
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @returns 32-bit section offset. If out of range, RTDWARFCURSOR::rc will be
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * set and UINT32_MAX returned.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param pCursor The cursor.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsyncstatic uint32_t rtDwarfCursor_CalcSectOffsetU32(PRTDWARFCURSOR pCursor)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync{
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync size_t off = pCursor->pb - (uint8_t const *)pCursor->pDwarfMod->aSections[pCursor->enmSect].pv;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t offRet = (uint32_t)off;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (offRet != off)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync AssertFailed();
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pCursor->rc = VERR_OUT_OF_RANGE;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync offRet = UINT32_MAX;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return offRet;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync}
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync/**
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * Calculates an absolute cursor position from one relative to the current
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * cursor position.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync *
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * @returns The absolute cursor position.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * @param pCursor The cursor.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * @param offRelative The relative position. Must be a positive
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * offset.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync */
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsyncstatic uint8_t const *rtDwarfCursor_CalcPos(PRTDWARFCURSOR pCursor, size_t offRelative)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync{
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if (offRelative > pCursor->cbUnitLeft)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync {
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log(("rtDwarfCursor_CalcPos: bad position %#zx, cbUnitLeft=%#zu\n", offRelative, pCursor->cbUnitLeft));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pCursor->rc = VERR_DWARF_BAD_POS;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return NULL;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync }
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return pCursor->pb + offRelative;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync}
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync/**
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * Advances the cursor to the given position.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync *
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * @returns IPRT status code.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * @param pCursor The cursor.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * @param pbNewPos The new position - returned by
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * rtDwarfCursor_CalcPos().
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync */
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsyncstatic int rtDwarfCursor_AdvanceToPos(PRTDWARFCURSOR pCursor, uint8_t const *pbNewPos)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync{
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if (RT_FAILURE(pCursor->rc))
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return pCursor->rc;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync AssertPtr(pbNewPos);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if ((uintptr_t)pbNewPos < (uintptr_t)pCursor->pb)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync {
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log(("rtDwarfCursor_AdvanceToPos: bad position %p, current %p\n", pbNewPos, pCursor->pb));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return pCursor->rc = VERR_DWARF_BAD_POS;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync }
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uintptr_t cbAdj = (uintptr_t)pbNewPos - (uintptr_t)pCursor->pb;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if (RT_UNLIKELY(cbAdj > pCursor->cbUnitLeft))
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync {
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync AssertFailed();
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pCursor->rc = VERR_DWARF_BAD_POS;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync cbAdj = pCursor->cbUnitLeft;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync }
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pCursor->cbUnitLeft -= cbAdj;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pCursor->cbLeft -= cbAdj;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pCursor->pb += cbAdj;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return pCursor->rc;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync}
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Check if the cursor is at the end of the current DWARF unit.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @retval @c true if at the end or a cursor error is pending.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @retval @c false if not.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic bool rtDwarfCursor_IsAtEndOfUnit(PRTDWARFCURSOR pCursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return !pCursor->cbUnitLeft || RT_FAILURE(pCursor->rc);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Skips to the end of the current unit.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDwarfCursor_SkipUnit(PRTDWARFCURSOR pCursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb += pCursor->cbUnitLeft;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft -= pCursor->cbUnitLeft;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft = 0;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return pCursor->rc;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Check if the cursor is at the end of the section (or whatever the cursor is
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * processing).
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @retval @c true if at the end or a cursor error is pending.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @retval @c false if not.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic bool rtDwarfCursor_IsAtEnd(PRTDWARFCURSOR pCursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return !pCursor->cbLeft || RT_FAILURE(pCursor->rc);
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Initialize a section reader cursor.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync *
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync * @returns IPRT status code.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync * @param pThis The dwarf module.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param enmSect The name of the section to read.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDwarfCursor_Init(PRTDWARFCURSOR pCursor, PRTDBGMODDWARF pThis, krtDbgModDwarfSect enmSect)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync int rc = rtDbgModDwarfLoadSection(pThis, enmSect);
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync if (RT_FAILURE(rc))
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync return rc;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pCursor->enmSect = enmSect;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pCursor->pbStart = (uint8_t const *)pThis->aSections[enmSect].pv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pCursor->pb = pCursor->pbStart;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pCursor->cbLeft = pThis->aSections[enmSect].cb;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pCursor->cbUnitLeft = pCursor->cbLeft;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pCursor->pDwarfMod = pThis;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pCursor->f64bitDwarf = false;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /** @todo ask the image about the endian used as well as the address
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * width. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pCursor->fNativEndian = true;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pCursor->cbNativeAddr = 4;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pCursor->rc = VINF_SUCCESS;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync return VINF_SUCCESS;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/**
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Initialize a section reader cursor with an offset.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync *
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @returns IPRT status code.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param pCursor The cursor.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param pThis The dwarf module.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param enmSect The name of the section to read.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param offSect The offset into the section.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsyncstatic int rtDwarfCursor_InitWithOffset(PRTDWARFCURSOR pCursor, PRTDBGMODDWARF pThis,
ad66a27959d7085aa31760f63ce082943be60e89vboxsync krtDbgModDwarfSect enmSect, uint32_t offSect)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync{
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (offSect > pThis->aSections[enmSect].cb)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync {
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log(("rtDwarfCursor_InitWithOffset: offSect=%#x cb=%#x enmSect=%d\n", offSect, pThis->aSections[enmSect].cb, enmSect));
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return VERR_DWARF_BAD_POS;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync int rc = rtDwarfCursor_Init(pCursor, pThis, enmSect);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (RT_SUCCESS(rc))
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pCursor->pbStart += offSect;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pCursor->pb += offSect;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pCursor->cbLeft -= offSect;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pCursor->cbUnitLeft -= offSect;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return rc;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync}
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/**
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * Initialize a cursor for a block (subsection) retrieved from the given cursor.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync *
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * The parent cursor will be advanced past the block.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync *
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @returns IPRT status code.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param pCursor The cursor.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param pParent The parent cursor. Will be moved by @a cbBlock.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param cbBlock The size of the block the new cursor should
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * cover.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsyncstatic int rtDwarfCursor_InitForBlock(PRTDWARFCURSOR pCursor, PRTDWARFCURSOR pParent, uint32_t cbBlock)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync{
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (RT_FAILURE(pParent->rc))
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return pParent->rc;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (pParent->cbUnitLeft < cbBlock)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log(("rtDwarfCursor_InitForBlock: cbUnitLeft=%#x < cbBlock=%#x \n", pParent->cbUnitLeft, cbBlock));
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return VERR_DWARF_BAD_POS;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync *pCursor = *pParent;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pCursor->cbLeft = cbBlock;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pCursor->cbUnitLeft = cbBlock;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pParent->pb += cbBlock;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pParent->cbLeft -= cbBlock;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pParent->cbUnitLeft -= cbBlock;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return VINF_SUCCESS;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync}
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync/**
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Deletes a section reader initialized by rtDwarfCursor_Init.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync *
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @returns @a rcOther or RTDWARCURSOR::rc.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pCursor The section reader.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param rcOther Other error code to be returned if it indicates
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * error or if the cursor status is OK.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic int rtDwarfCursor_Delete(PRTDWARFCURSOR pCursor, int rcOther)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync /* ... and a drop of poison. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pb = NULL;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbLeft = ~(size_t)0;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->cbUnitLeft = ~(size_t)0;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->pDwarfMod = NULL;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (RT_FAILURE(pCursor->rc) && RT_SUCCESS(rcOther))
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rcOther = pCursor->rc;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pCursor->rc = VERR_INTERNAL_ERROR_4;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return rcOther;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync}
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/*
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Line Numbers.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Line Numbers.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Line Numbers.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Defines a file name.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pLnState The line number program state.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pszFilename The name of the file.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param idxInc The include path index.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic int rtDwarfLine_DefineFileName(PRTDWARFLINESTATE pLnState, const char *pszFilename, uint64_t idxInc)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /*
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Resize the array if necessary.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint32_t iFileName = pLnState->cFileNames;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync if ((iFileName % 2) == 0)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync {
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync void *pv = RTMemRealloc(pLnState->papszFileNames, sizeof(pLnState->papszFileNames[0]) * (iFileName + 2));
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync if (!pv)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return VERR_NO_MEMORY;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pLnState->papszFileNames = (char **)pv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync }
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /*
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Add the file name.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync if ( pszFilename[0] == '/'
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync || pszFilename[0] == '\\'
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync || (RT_C_IS_ALPHA(pszFilename[0]) && pszFilename[1] == ':') )
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pLnState->papszFileNames[iFileName] = RTStrDup(pszFilename);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync else if (idxInc < pLnState->cIncPaths)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pLnState->papszFileNames[iFileName] = RTPathJoinA(pLnState->papszIncPaths[idxInc], pszFilename);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync else
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return VERR_DWARF_BAD_LINE_NUMBER_HEADER;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync if (!pLnState->papszFileNames[iFileName])
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return VERR_NO_STR_MEMORY;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pLnState->cFileNames = iFileName + 1;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /*
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Sanitize the name.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync int rc = rtDbgModDwarfStringToUtf8(pLnState->pDwarfMod, &pLnState->papszFileNames[iFileName]);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync Log((" File #%02u = '%s'\n", iFileName, pLnState->papszFileNames[iFileName]));
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return rc;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync}
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Adds a line to the table and resets parts of the state (DW_LNS_copy).
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pLnState The line number program state.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param offOpCode The opcode offset (for logging
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * purposes).
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsyncstatic int rtDwarfLine_AddLine(PRTDWARFLINESTATE pLnState, uint32_t offOpCode)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync{
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync PRTDBGMODDWARF pThis = pLnState->pDwarfMod;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync int rc;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (pThis->iWatcomPass == 1)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = rtDbgModDwarfRecordSegOffset(pThis, pLnState->Regs.uSegment, pLnState->Regs.uAddress + 1);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync else
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync const char *pszFile = pLnState->Regs.iFile < pLnState->cFileNames
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync ? pLnState->papszFileNames[pLnState->Regs.iFile]
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync : "<bad file name index>";
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync NOREF(offOpCode);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync RTDBGSEGIDX iSeg;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync RTUINTPTR offSeg;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = rtDbgModDwarfLinkAddressToSegOffset(pLnState->pDwarfMod, pLnState->Regs.uSegment, pLnState->Regs.uAddress,
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync &iSeg, &offSeg); AssertRC(rc);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (RT_SUCCESS(rc))
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync Log2(("rtDwarfLine_AddLine: %x:%08llx (%#llx) %s(%d) [offOpCode=%08x]\n", iSeg, offSeg, pLnState->Regs.uAddress, pszFile, pLnState->Regs.uLine, offOpCode));
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = RTDbgModLineAdd(pLnState->pDwarfMod->hCnt, pszFile, pLnState->Regs.uLine, iSeg, offSeg, NULL);
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync /* Ignore address conflicts for now. */
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (rc == VERR_DBG_ADDRESS_CONFLICT)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = VINF_SUCCESS;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync }
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pLnState->Regs.fBasicBlock = false;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pLnState->Regs.fPrologueEnd = false;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pLnState->Regs.fEpilogueBegin = false;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pLnState->Regs.uDiscriminator = 0;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return rc;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/**
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Reset the program to the start-of-sequence state.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync *
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pLnState The line number program state.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic void rtDwarfLine_ResetState(PRTDWARFLINESTATE pLnState)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uAddress = 0;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.idxOp = 0;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.iFile = 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uLine = 1;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uColumn = 0;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.fIsStatement = RT_BOOL(pLnState->Hdr.u8DefIsStmt);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fBasicBlock = false;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fEndSequence = false;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fPrologueEnd = false;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fEpilogueBegin = false;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uIsa = 0;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uDiscriminator = 0;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pLnState->Regs.uSegment = 0;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/**
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Runs the line number program.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync *
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns IPRT status code.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pLnState The line number program state.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDwarfLine_RunProgram(PRTDWARFLINESTATE pLnState, PRTDWARFCURSOR pCursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LogFlow(("rtDwarfLine_RunProgram: cbUnitLeft=%zu\n", pCursor->cbUnitLeft));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync int rc = VINF_SUCCESS;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync rtDwarfLine_ResetState(pLnState);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync while (!rtDwarfCursor_IsAtEndOfUnit(pCursor))
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#ifdef LOG_ENABLED
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync uint32_t const offOpCode = rtDwarfCursor_CalcSectOffsetU32(pCursor);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#else
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync uint32_t const offOpCode = 0;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync#endif
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync uint8_t bOpCode = rtDwarfCursor_GetUByte(pCursor, DW_LNS_extended);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync if (bOpCode >= pLnState->Hdr.u8OpcodeBase)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Special opcode.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint8_t const bLogOpCode = bOpCode; NOREF(bLogOpCode);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync bOpCode -= pLnState->Hdr.u8OpcodeBase;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync int32_t const cLineDelta = bOpCode % pLnState->Hdr.u8LineRange + (int32_t)pLnState->Hdr.s8LineBase;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync bOpCode /= pLnState->Hdr.u8LineRange;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
cecb0b0ed75fde05db9e1958b7c813c572cf81fevboxsync uint64_t uTmp = bOpCode + pLnState->Regs.idxOp;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint64_t const cAddressDelta = uTmp / pLnState->Hdr.cMaxOpsPerInstr * pLnState->Hdr.cbMinInstr;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint64_t const cOpIndexDelta = uTmp % pLnState->Hdr.cMaxOpsPerInstr;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.uLine += cLineDelta;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.uAddress += cAddressDelta;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.idxOp += cOpIndexDelta;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW Special Opcode %#04x: uLine + %d => %u; uAddress + %#llx => %#llx; idxOp + %#llx => %#llx\n",
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync offOpCode, bLogOpCode, cLineDelta, pLnState->Regs.uLine, cAddressDelta, pLnState->Regs.uAddress,
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync cOpIndexDelta, pLnState->Regs.idxOp));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync rc = rtDwarfLine_AddLine(pLnState, offOpCode);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync else
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync switch (bOpCode)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Standard opcode.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_copy:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNS_copy\n", offOpCode));
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync rc = rtDwarfLine_AddLine(pLnState, offOpCode);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_advance_pc:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t u64Adv = rtDwarfCursor_GetULeb128(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.uAddress += (pLnState->Regs.idxOp + u64Adv) / pLnState->Hdr.cMaxOpsPerInstr
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * pLnState->Hdr.cbMinInstr;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.idxOp += (pLnState->Regs.idxOp + u64Adv) % pLnState->Hdr.cMaxOpsPerInstr;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNS_advance_pc: u64Adv=%#llx (%lld) )\n", offOpCode, u64Adv, u64Adv));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_advance_line:
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync {
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync int32_t cLineDelta = rtDwarfCursor_GetSLeb128AsS32(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.uLine += cLineDelta;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNS_advance_line: uLine + %d => %u\n", offOpCode, cLineDelta, pLnState->Regs.uLine));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_set_file:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.iFile = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNS_set_file: iFile=%u\n", offOpCode, pLnState->Regs.iFile));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_set_column:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uColumn = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNS_set_column\n", offOpCode));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_negate_stmt:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fIsStatement = !pLnState->Regs.fIsStatement;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNS_negate_stmt\n", offOpCode));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_set_basic_block:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fBasicBlock = true;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNS_set_basic_block\n", offOpCode));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_const_add_pc:
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.uAddress += (pLnState->Regs.idxOp + 255) / pLnState->Hdr.cMaxOpsPerInstr
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * pLnState->Hdr.cbMinInstr;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.idxOp += (pLnState->Regs.idxOp + 255) % pLnState->Hdr.cMaxOpsPerInstr;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNS_const_add_pc\n", offOpCode));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_fixed_advance_pc:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uAddress += rtDwarfCursor_GetUHalf(pCursor, 0);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.idxOp = 0;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNS_fixed_advance_pc\n", offOpCode));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_set_prologue_end:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fPrologueEnd = true;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNS_set_prologue_end\n", offOpCode));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_set_epilogue_begin:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fEpilogueBegin = true;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNS_set_epilogue_begin\n", offOpCode));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_set_isa:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uIsa = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNS_set_isa %#x\n", offOpCode, pLnState->Regs.uIsa));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync default:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync unsigned cOpsToSkip = pLnState->Hdr.pacStdOperands[bOpCode - 1];
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log(("rtDwarfLine_RunProgram: Unknown standard opcode %#x, %#x operands, at %08x.\n", bOpCode, cOpsToSkip, offOpCode));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync while (cOpsToSkip-- > 0)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync rc = rtDwarfCursor_SkipLeb128(pCursor);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Extended opcode.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_extended:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync /* The instruction has a length prefix. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t cbInstr = rtDwarfCursor_GetULeb128(pCursor, UINT64_MAX);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if (RT_FAILURE(pCursor->rc))
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return pCursor->rc;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (cbInstr > pCursor->cbUnitLeft)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return VERR_DWARF_BAD_LNE;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint8_t const * const pbEndOfInstr = rtDwarfCursor_CalcPos(pCursor, cbInstr);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync /* Get the opcode and deal with it if we know it. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync bOpCode = rtDwarfCursor_GetUByte(pCursor, 0);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync switch (bOpCode)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNE_end_sequence:
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync#if 0 /* No need for this, I think. */
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.fEndSequence = true;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync rc = rtDwarfLine_AddLine(pLnState, offOpCode);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync#endif
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rtDwarfLine_ResetState(pLnState);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNE_end_sequence\n", offOpCode));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNE_set_address:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync pLnState->Regs.uAddress = rtDwarfCursor_GetVarSizedU(pCursor, cbInstr - 1, UINT64_MAX);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync pLnState->Regs.idxOp = 0;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNE_set_address: %#llx\n", offOpCode, pLnState->Regs.uAddress));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNE_define_file:
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync {
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync const char *pszFilename = rtDwarfCursor_GetSZ(pCursor, NULL);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint32_t idxInc = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rtDwarfCursor_SkipLeb128(pCursor); /* st_mtime */
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rtDwarfCursor_SkipLeb128(pCursor); /* st_size */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNE_define_file: {%d}/%s\n", offOpCode, idxInc, pszFilename));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rc = rtDwarfCursor_AdvanceToPos(pCursor, pbEndOfInstr);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if (RT_SUCCESS(rc))
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rc = rtDwarfLine_DefineFileName(pLnState, pszFilename, idxInc);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync }
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync /*
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Note! Was defined in DWARF 4. But... Watcom used it
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * for setting the segment in DWARF 2, creating
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * an incompatibility with the newer standard.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNE_set_descriminator:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync if (pLnState->Hdr.uVer != 2)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync {
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Assert(pLnState->Hdr.uVer >= 4);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync pLnState->Regs.uDiscriminator = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log2(("%08x: DW_LNE_set_descriminator: %u\n", offOpCode, pLnState->Regs.uDiscriminator));
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync }
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync else
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync {
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync uint64_t uSeg = rtDwarfCursor_GetVarSizedU(pCursor, cbInstr - 1, UINT64_MAX);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log2(("%08x: DW_LNE_set_segment: %#llx, cbInstr=%#x - Watcom Extension\n", offOpCode, uSeg, cbInstr));
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pLnState->Regs.uSegment = (RTSEL)uSeg;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync AssertStmt(pLnState->Regs.uSegment == uSeg, rc = VERR_DWARF_BAD_INFO);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync }
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync default:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log(("rtDwarfLine_RunProgram: Unknown extended opcode %#x, length %#x at %08x\n", bOpCode, cbInstr, offOpCode));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync /* Advance the cursor to the end of the instruction . */
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rtDwarfCursor_AdvanceToPos(pCursor, pbEndOfInstr);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync /*
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync * Check the status before looping.
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync */
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if (RT_FAILURE(rc))
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return rc;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if (RT_FAILURE(pCursor->rc))
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return pCursor->rc;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return rc;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/**
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Reads the include directories for a line number unit.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync *
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns IPRT status code
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pLnState The line number program state.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDwarfLine_ReadFileNames(PRTDWARFLINESTATE pLnState, PRTDWARFCURSOR pCursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync int rc = rtDwarfLine_DefineFileName(pLnState, "/<bad-zero-file-name-entry>", 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if (RT_FAILURE(rc))
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return rc;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync for (;;)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync const char *psz = rtDwarfCursor_GetSZ(pCursor, NULL);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (!*psz)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync uint64_t idxInc = rtDwarfCursor_GetULeb128(pCursor, UINT64_MAX);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync rtDwarfCursor_SkipLeb128(pCursor); /* st_mtime */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync rtDwarfCursor_SkipLeb128(pCursor); /* st_size */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rc = rtDwarfLine_DefineFileName(pLnState, psz, idxInc);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (RT_FAILURE(rc))
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return rc;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return pCursor->rc;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/**
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Reads the include directories for a line number unit.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync *
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @returns IPRT status code
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pLnState The line number program state.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param pCursor The cursor.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDwarfLine_ReadIncludePaths(PRTDWARFLINESTATE pLnState, PRTDWARFCURSOR pCursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync const char *psz = ""; /* The zeroth is the unit dir. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync for (;;)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if ((pLnState->cIncPaths % 2) == 0)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync void *pv = RTMemRealloc(pLnState->papszIncPaths, sizeof(pLnState->papszIncPaths[0]) * (pLnState->cIncPaths + 2));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (!pv)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return VERR_NO_MEMORY;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->papszIncPaths = (const char **)pv;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log((" Path #%02u = '%s'\n", pLnState->cIncPaths, psz));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->papszIncPaths[pLnState->cIncPaths] = psz;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->cIncPaths++;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync psz = rtDwarfCursor_GetSZ(pCursor, NULL);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (!*psz)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return pCursor->rc;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Explodes the line number table for a compilation unit.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pThis The DWARF instance.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pCursor The cursor to read the line number information
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * via.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic int rtDwarfLine_ExplodeUnit(PRTDBGMODDWARF pThis, PRTDWARFCURSOR pCursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync{
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync RTDWARFLINESTATE LnState;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync RT_ZERO(LnState);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync LnState.pDwarfMod = pThis;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Parse the header.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rtDwarfCursor_GetInitalLength(pCursor);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.uVer = rtDwarfCursor_GetUHalf(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if ( LnState.Hdr.uVer < 2
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync || LnState.Hdr.uVer > 4)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return rtDwarfCursor_SkipUnit(pCursor);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.offFirstOpcode = rtDwarfCursor_GetUOff(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint8_t const * const pbFirstOpcode = rtDwarfCursor_CalcPos(pCursor, LnState.Hdr.offFirstOpcode);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.cbMinInstr = rtDwarfCursor_GetUByte(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if (LnState.Hdr.uVer >= 4)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.cMaxOpsPerInstr = rtDwarfCursor_GetUByte(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync else
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.cMaxOpsPerInstr = 1;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.u8DefIsStmt = rtDwarfCursor_GetUByte(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.s8LineBase = rtDwarfCursor_GetSByte(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.u8LineRange = rtDwarfCursor_GetUByte(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.u8OpcodeBase = rtDwarfCursor_GetUByte(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if ( !LnState.Hdr.u8OpcodeBase
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync || !LnState.Hdr.cMaxOpsPerInstr
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync || !LnState.Hdr.u8LineRange
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync || LnState.Hdr.u8DefIsStmt > 1)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return VERR_DWARF_BAD_LINE_NUMBER_HEADER;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DWARF Line number header:\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " uVer %d\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " offFirstOpcode %#llx\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " cbMinInstr %u\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " cMaxOpsPerInstr %u\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " u8DefIsStmt %u\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " s8LineBase %d\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " u8LineRange %u\n"
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync " u8OpcodeBase %u\n",
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.uVer, LnState.Hdr.offFirstOpcode, LnState.Hdr.cbMinInstr, LnState.Hdr.cMaxOpsPerInstr,
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.u8DefIsStmt, LnState.Hdr.s8LineBase, LnState.Hdr.u8LineRange, LnState.Hdr.u8OpcodeBase));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync LnState.Hdr.pacStdOperands = pCursor->pb;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync for (uint8_t iStdOpcode = 1; iStdOpcode < LnState.Hdr.u8OpcodeBase; iStdOpcode++)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync rtDwarfCursor_GetUByte(pCursor, 0);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync int rc = pCursor->rc;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if (RT_SUCCESS(rc))
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rc = rtDwarfLine_ReadIncludePaths(&LnState, pCursor);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (RT_SUCCESS(rc))
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync rc = rtDwarfLine_ReadFileNames(&LnState, pCursor);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Run the program....
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if (RT_SUCCESS(rc))
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rc = rtDwarfCursor_AdvanceToPos(pCursor, pbFirstOpcode);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync if (RT_SUCCESS(rc))
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync rc = rtDwarfLine_RunProgram(&LnState, pCursor);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Clean up.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync size_t i = LnState.cFileNames;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync while (i-- > 0)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync RTStrFree(LnState.papszFileNames[i]);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync RTMemFree(LnState.papszFileNames);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync RTMemFree(LnState.papszIncPaths);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync Assert(rtDwarfCursor_IsAtEndOfUnit(pCursor) || RT_FAILURE(rc));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync return rc;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync}
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
d3dea25ec07f6546715fe3af943ea863294b392evboxsync/**
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * Explodes the line number table.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync *
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * The line numbers are insered into the debug info container.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync *
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * @returns IPRT status code
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * @param pThis The DWARF instance.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic int rtDwarfLine_ExplodeAll(PRTDBGMODDWARF pThis)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync{
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync if (!pThis->aSections[krtDbgModDwarfSect_line].fPresent)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync return VINF_SUCCESS;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync RTDWARFCURSOR Cursor;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync int rc = rtDwarfCursor_Init(&Cursor, pThis, krtDbgModDwarfSect_line);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (RT_FAILURE(rc))
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return rc;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync while ( !rtDwarfCursor_IsAtEnd(&Cursor)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync && RT_SUCCESS(rc))
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync rc = rtDwarfLine_ExplodeUnit(pThis, &Cursor);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return rtDwarfCursor_Delete(&Cursor, rc);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync}
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/*
d3dea25ec07f6546715fe3af943ea863294b392evboxsync *
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * DWARF Abbreviations.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * DWARF Abbreviations.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * DWARF Abbreviations.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync *
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/**
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Deals with a cache miss in rtDwarfAbbrev_Lookup.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync *
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @returns Pointer to abbreviation cache entry (read only). May be rendered
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * invalid by subsequent calls to this function.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * @param pThis The DWARF instance.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param uCode The abbreviation code to lookup.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic PCRTDWARFABBREV rtDwarfAbbrev_LookupMiss(PRTDBGMODDWARF pThis, uint32_t uCode)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync{
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * There is no entry with code zero.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (!uCode)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return NULL;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Resize the cache array if the code is considered cachable.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync bool fFillCache = true;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (pThis->cCachedAbbrevsAlloced < uCode)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (uCode > _64K)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync fFillCache = false;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync else
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t cNew = RT_ALIGN(uCode, 64);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync void *pv = RTMemRealloc(pThis->paCachedAbbrevs, sizeof(pThis->paCachedAbbrevs[0]) * cNew);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (!pv)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync fFillCache = false;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync else
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pThis->cCachedAbbrevsAlloced = cNew;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pThis->paCachedAbbrevs = (PRTDWARFABBREV)pv;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Walk the abbreviations till we find the desired code.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync RTDWARFCURSOR Cursor;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync int rc = rtDwarfCursor_InitWithOffset(&Cursor, pThis, krtDbgModDwarfSect_abbrev, pThis->offCachedAbbrev);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (RT_FAILURE(rc))
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return NULL;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync PRTDWARFABBREV pRet = NULL;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (fFillCache)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Search for the entry and fill the cache while doing so.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync for (;;)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Read the 'header'. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t const uCurCode = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t const uCurTag = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint8_t const uChildren = rtDwarfCursor_GetU8(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (RT_FAILURE(Cursor.rc))
ad66a27959d7085aa31760f63ce082943be60e89vboxsync break;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if ( uCurTag > 0xffff
ad66a27959d7085aa31760f63ce082943be60e89vboxsync || uChildren > 1)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync Cursor.rc = VERR_DWARF_BAD_ABBREV;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync break;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Cache it? */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync if (uCurCode <= pThis->cCachedAbbrevsAlloced)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync PRTDWARFABBREV pEntry = &pThis->paCachedAbbrevs[uCurCode - 1];
ad66a27959d7085aa31760f63ce082943be60e89vboxsync while (pThis->cCachedAbbrevs < uCurCode)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pThis->paCachedAbbrevs[pThis->cCachedAbbrevs].fFilled = false;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pThis->cCachedAbbrevs++;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pEntry->fFilled = true;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pEntry->fChildren = RT_BOOL(uChildren);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pEntry->uTag = uCurTag;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pEntry->offSpec = rtDwarfCursor_CalcSectOffsetU32(&Cursor);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (uCurCode == uCode)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pRet = pEntry;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (uCurCode == pThis->cCachedAbbrevsAlloced)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync break;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Skip the specification. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t uAttr, uForm;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync do
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uAttr = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uForm = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync } while (uAttr != 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (RT_FAILURE(Cursor.rc))
ad66a27959d7085aa31760f63ce082943be60e89vboxsync break;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Done? (Maximize cache filling.) */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if ( pRet != NULL
ad66a27959d7085aa31760f63ce082943be60e89vboxsync && uCurCode >= pThis->cCachedAbbrevsAlloced)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync break;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync else
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Search for the entry with the desired code, no cache filling.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync for (;;)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Read the 'header'. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t const uCurCode = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t const uCurTag = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint8_t const uChildren = rtDwarfCursor_GetU8(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (RT_FAILURE(Cursor.rc))
ad66a27959d7085aa31760f63ce082943be60e89vboxsync break;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if ( uCurTag > 0xffff
ad66a27959d7085aa31760f63ce082943be60e89vboxsync || uChildren > 1)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync Cursor.rc = VERR_DWARF_BAD_ABBREV;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync break;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Do we have a match? */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (uCurCode == uCode)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pRet = &pThis->LookupAbbrev;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pRet->fFilled = true;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pRet->fChildren = RT_BOOL(uChildren);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pRet->uTag = uCurTag;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pRet->offSpec = rtDwarfCursor_CalcSectOffsetU32(&Cursor);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync break;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /* Skip the specification. */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t uAttr, uForm;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync do
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uAttr = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uForm = rtDwarfCursor_GetULeb128AsU32(&Cursor, 0);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync } while (uAttr != 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (RT_FAILURE(Cursor.rc))
ad66a27959d7085aa31760f63ce082943be60e89vboxsync break;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rtDwarfCursor_Delete(&Cursor, VINF_SUCCESS);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return pRet;
d3dea25ec07f6546715fe3af943ea863294b392evboxsync}
d3dea25ec07f6546715fe3af943ea863294b392evboxsync
d3dea25ec07f6546715fe3af943ea863294b392evboxsync
d3dea25ec07f6546715fe3af943ea863294b392evboxsync/**
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Looks up an abbreviation.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync *
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @returns Pointer to abbreviation cache entry (read only). May be rendered
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * invalid by subsequent calls to this function.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync * @param pThis The DWARF instance.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param uCode The abbreviation code to lookup.
d3dea25ec07f6546715fe3af943ea863294b392evboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic PCRTDWARFABBREV rtDwarfAbbrev_Lookup(PRTDBGMODDWARF pThis, uint32_t uCode)
d3dea25ec07f6546715fe3af943ea863294b392evboxsync{
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if ( uCode - 1 >= pThis->cCachedAbbrevs
ad66a27959d7085aa31760f63ce082943be60e89vboxsync || !pThis->paCachedAbbrevs[uCode - 1].fFilled)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return rtDwarfAbbrev_LookupMiss(pThis, uCode);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return &pThis->paCachedAbbrevs[uCode - 1];
ad66a27959d7085aa31760f63ce082943be60e89vboxsync}
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/**
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Sets the abbreviation offset of the current unit.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync *
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * This will flush the cached abbreviation entries if the offset differs from
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * the previous unit.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync *
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param pThis The DWARF instance.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param offAbbrev The offset into the abbreviation section.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsyncstatic void rtDwarfAbbrev_SetUnitOffset(PRTDBGMODDWARF pThis, uint32_t offAbbrev)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync{
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (pThis->offCachedAbbrev != offAbbrev)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pThis->offCachedAbbrev = offAbbrev;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pThis->cCachedAbbrevs = 0;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync}
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/*
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync *
e4bf6817370e1a71833a02285515694afcda7599vboxsync * DIE Attribute Parsers.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * DIE Attribute Parsers.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * DIE Attribute Parsers.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync *
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/**
e4bf6817370e1a71833a02285515694afcda7599vboxsync * Gets the compilation unit a DIE belongs to.
e4bf6817370e1a71833a02285515694afcda7599vboxsync *
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @returns The compilation unit DIE.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @param pDie Some DIE in the unit.
e4bf6817370e1a71833a02285515694afcda7599vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic PRTDWARFDIECOMPILEUNIT rtDwarfDie_GetCompileUnit(PRTDWARFDIE pDie)
e4bf6817370e1a71833a02285515694afcda7599vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync while (pDie->pParent)
e4bf6817370e1a71833a02285515694afcda7599vboxsync pDie = pDie->pParent;
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertReturn( pDie->uTag == DW_TAG_compile_unit
e4bf6817370e1a71833a02285515694afcda7599vboxsync || pDie->uTag == DW_TAG_partial_unit,
e4bf6817370e1a71833a02285515694afcda7599vboxsync NULL);
e4bf6817370e1a71833a02285515694afcda7599vboxsync return (PRTDWARFDIECOMPILEUNIT)pDie;
e4bf6817370e1a71833a02285515694afcda7599vboxsync}
e4bf6817370e1a71833a02285515694afcda7599vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/**
e4bf6817370e1a71833a02285515694afcda7599vboxsync * Resolves a string section (debug_str) reference.
e4bf6817370e1a71833a02285515694afcda7599vboxsync *
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @returns Pointer to the string (inside the string section).
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @param pThis The DWARF instance.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @param pCursor The cursor.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @param pszErrValue What to return on failure (@a
e4bf6817370e1a71833a02285515694afcda7599vboxsync * pCursor->rc is set).
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsyncstatic const char *rtDwarfDecodeHlp_GetStrp(PRTDBGMODDWARF pThis, PRTDWARFCURSOR pCursor, const char *pszErrValue)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t offDebugStr = rtDwarfCursor_GetUOff(pCursor, UINT64_MAX);
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (RT_FAILURE(pCursor->rc))
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pszErrValue;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (offDebugStr >= pThis->aSections[krtDbgModDwarfSect_str].cb)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync /* Ugly: Exploit the cursor status field for reporting errors. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync pCursor->rc = VERR_DWARF_BAD_INFO;
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pszErrValue;
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (!pThis->aSections[krtDbgModDwarfSect_str].pv)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync int rc = rtDbgModDwarfLoadSection(pThis, krtDbgModDwarfSect_str);
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (RT_FAILURE(rc))
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync /* Ugly: Exploit the cursor status field for reporting errors. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync pCursor->rc = rc;
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pszErrValue;
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync return (const char *)pThis->aSections[krtDbgModDwarfSect_str].pv + (size_t)offDebugStr;
e4bf6817370e1a71833a02285515694afcda7599vboxsync}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync/** @callback_method_impl{FNRTDWARFATTRDECODER} */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsyncstatic DECLCALLBACK(int) rtDwarfDecode_Address(PRTDWARFDIE pDie, uint8_t *pbMember, PCRTDWARFATTRDESC pDesc,
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync uint32_t uForm, PRTDWARFCURSOR pCursor)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync{
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync AssertReturn(ATTR_GET_SIZE(pDesc) == sizeof(RTDWARFADDR), VERR_INTERNAL_ERROR_3);
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync NOREF(pDie);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync uint64_t uAddr;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync switch (uForm)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case DW_FORM_addr: uAddr = rtDwarfCursor_GetNativeUOff(pCursor, 0); break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case DW_FORM_data1: uAddr = rtDwarfCursor_GetU8(pCursor, 0); break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case DW_FORM_data2: uAddr = rtDwarfCursor_GetU16(pCursor, 0); break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case DW_FORM_data4: uAddr = rtDwarfCursor_GetU32(pCursor, 0); break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case DW_FORM_data8: uAddr = rtDwarfCursor_GetU64(pCursor, 0); break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case DW_FORM_udata: uAddr = rtDwarfCursor_GetULeb128(pCursor, 0); break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync default:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync AssertMsgFailedReturn(("%#x (%s)\n", uForm, rtDwarfLog_FormName(uForm)), VERR_DWARF_UNEXPECTED_FORM);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (RT_FAILURE(pCursor->rc))
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync return pCursor->rc;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync PRTDWARFADDR pAddr = (PRTDWARFADDR)pbMember;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pAddr->uAddress = uAddr;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log4((" %-20s %#010llx [%s]\n", rtDwarfLog_AttrName(pDesc->uAttr), uAddr, rtDwarfLog_FormName(uForm)));
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync return VINF_SUCCESS;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync}
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** @callback_method_impl{FNRTDWARFATTRDECODER} */
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic DECLCALLBACK(int) rtDwarfDecode_Bool(PRTDWARFDIE pDie, uint8_t *pbMember, PCRTDWARFATTRDESC pDesc,
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint32_t uForm, PRTDWARFCURSOR pCursor)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertReturn(ATTR_GET_SIZE(pDesc) == sizeof(bool), VERR_INTERNAL_ERROR_3);
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync NOREF(pDie);
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync bool *pfMember = (bool *)pbMember;
e4bf6817370e1a71833a02285515694afcda7599vboxsync switch (uForm)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_flag:
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint8_t b = rtDwarfCursor_GetU8(pCursor, UINT8_MAX);
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (b > 1)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log(("Unexpected boolean value %#x\n", b));
e4bf6817370e1a71833a02285515694afcda7599vboxsync return RT_FAILURE(pCursor->rc) ? pCursor->rc : pCursor->rc = VERR_DWARF_BAD_INFO;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync *pfMember = RT_BOOL(b);
e4bf6817370e1a71833a02285515694afcda7599vboxsync break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_flag_present:
e4bf6817370e1a71833a02285515694afcda7599vboxsync *pfMember = true;
e4bf6817370e1a71833a02285515694afcda7599vboxsync break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync default:
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertMsgFailedReturn(("%#x\n", uForm), VERR_DWARF_UNEXPECTED_FORM);
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log4((" %-20s %RTbool [%s]\n", rtDwarfLog_AttrName(pDesc->uAttr), *pfMember, rtDwarfLog_FormName(uForm)));
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return VINF_SUCCESS;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** @callback_method_impl{FNRTDWARFATTRDECODER} */
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic DECLCALLBACK(int) rtDwarfDecode_LowHighPc(PRTDWARFDIE pDie, uint8_t *pbMember, PCRTDWARFATTRDESC pDesc,
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint32_t uForm, PRTDWARFCURSOR pCursor)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertReturn(ATTR_GET_SIZE(pDesc) == sizeof(RTDWARFADDRRANGE), VERR_INTERNAL_ERROR_3);
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertReturn(pDesc->uAttr == DW_AT_low_pc || pDesc->uAttr == DW_AT_high_pc, VERR_INTERNAL_ERROR_3);
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync NOREF(pDie);
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t uAddr;
e4bf6817370e1a71833a02285515694afcda7599vboxsync switch (uForm)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_addr: uAddr = rtDwarfCursor_GetNativeUOff(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_data1: uAddr = rtDwarfCursor_GetU8(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_data2: uAddr = rtDwarfCursor_GetU16(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_data4: uAddr = rtDwarfCursor_GetU32(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_data8: uAddr = rtDwarfCursor_GetU64(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_udata: uAddr = rtDwarfCursor_GetULeb128(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync default:
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertMsgFailedReturn(("%#x\n", uForm), VERR_DWARF_UNEXPECTED_FORM);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (RT_FAILURE(pCursor->rc))
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pCursor->rc;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync PRTDWARFADDRRANGE pRange = (PRTDWARFADDRRANGE)pbMember;
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (pDesc->uAttr == DW_AT_low_pc)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (pRange->fHaveLowAddress)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync Log(("rtDwarfDecode_LowHighPc: Duplicate DW_AT_low_pc\n"));
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync return pCursor->rc = VERR_DWARF_BAD_INFO;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync pRange->fHaveLowAddress = true;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pRange->uLowAddress = uAddr;
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync else
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (pRange->fHaveHighAddress)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync Log(("rtDwarfDecode_LowHighPc: Duplicate DW_AT_high_pc\n"));
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync return pCursor->rc = VERR_DWARF_BAD_INFO;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync pRange->fHaveHighAddress = true;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pRange->uHighAddress = uAddr;
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pRange->cAttrs++;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log4((" %-20s %#010llx [%s]\n", rtDwarfLog_AttrName(pDesc->uAttr), uAddr, rtDwarfLog_FormName(uForm)));
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return VINF_SUCCESS;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** @callback_method_impl{FNRTDWARFATTRDECODER} */
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic DECLCALLBACK(int) rtDwarfDecode_Ranges(PRTDWARFDIE pDie, uint8_t *pbMember, PCRTDWARFATTRDESC pDesc,
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint32_t uForm, PRTDWARFCURSOR pCursor)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertReturn(ATTR_GET_SIZE(pDesc) == sizeof(RTDWARFADDRRANGE), VERR_INTERNAL_ERROR_3);
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync AssertReturn(pDesc->uAttr == DW_AT_ranges, VERR_INTERNAL_ERROR_3);
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync NOREF(pDie);
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync /* Decode it. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t off;
e4bf6817370e1a71833a02285515694afcda7599vboxsync switch (uForm)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_addr: off = rtDwarfCursor_GetNativeUOff(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_data4: off = rtDwarfCursor_GetU32(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_data8: off = rtDwarfCursor_GetU64(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync default:
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertMsgFailedReturn(("%#x\n", uForm), VERR_DWARF_UNEXPECTED_FORM);
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (RT_FAILURE(pCursor->rc))
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pCursor->rc;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync /* Validate the offset and load the ranges. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync PRTDBGMODDWARF pThis = pCursor->pDwarfMod;
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (off >= pThis->aSections[krtDbgModDwarfSect_ranges].cb)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync Log(("rtDwarfDecode_Ranges: bad ranges off=%#llx\n", off));
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pCursor->rc = VERR_DWARF_BAD_POS;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (!pThis->aSections[krtDbgModDwarfSect_ranges].pv)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync int rc = rtDbgModDwarfLoadSection(pThis, krtDbgModDwarfSect_ranges);
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (RT_FAILURE(rc))
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pCursor->rc = rc;
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync /* Store the result. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync PRTDWARFADDRRANGE pRange = (PRTDWARFADDRRANGE)pbMember;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (pRange->fHaveRanges)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync Log(("rtDwarfDecode_Ranges: Duplicate DW_AT_ranges\n"));
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync return pCursor->rc = VERR_DWARF_BAD_INFO;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync pRange->fHaveRanges = true;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pRange->cAttrs++;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pRange->pbRanges = (uint8_t const *)pThis->aSections[krtDbgModDwarfSect_ranges].pv + (size_t)off;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log4((" %-20s TODO [%s]\n", rtDwarfLog_AttrName(pDesc->uAttr), rtDwarfLog_FormName(uForm)));
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return VINF_SUCCESS;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** @callback_method_impl{FNRTDWARFATTRDECODER} */
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic DECLCALLBACK(int) rtDwarfDecode_Reference(PRTDWARFDIE pDie, uint8_t *pbMember, PCRTDWARFATTRDESC pDesc,
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint32_t uForm, PRTDWARFCURSOR pCursor)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertReturn(ATTR_GET_SIZE(pDesc) == sizeof(RTDWARFREF), VERR_INTERNAL_ERROR_3);
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync /* Decode it. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t off;
e4bf6817370e1a71833a02285515694afcda7599vboxsync krtDwarfRef enmWrt = krtDwarfRef_InfoSection;
e4bf6817370e1a71833a02285515694afcda7599vboxsync switch (uForm)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_ref1: off = rtDwarfCursor_GetU8(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_ref2: off = rtDwarfCursor_GetU16(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_ref4: off = rtDwarfCursor_GetU32(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_ref8: off = rtDwarfCursor_GetU64(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_ref_udata: off = rtDwarfCursor_GetULeb128(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_ref_addr:
e4bf6817370e1a71833a02285515694afcda7599vboxsync enmWrt = krtDwarfRef_InfoSection;
e4bf6817370e1a71833a02285515694afcda7599vboxsync off = rtDwarfCursor_GetUOff(pCursor, 0);
e4bf6817370e1a71833a02285515694afcda7599vboxsync break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_ref_sig8:
e4bf6817370e1a71833a02285515694afcda7599vboxsync enmWrt = krtDwarfRef_TypeId64;
e4bf6817370e1a71833a02285515694afcda7599vboxsync off = rtDwarfCursor_GetU64(pCursor, 0);
e4bf6817370e1a71833a02285515694afcda7599vboxsync break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync default:
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertMsgFailedReturn(("%#x\n", uForm), VERR_DWARF_UNEXPECTED_FORM);
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (RT_FAILURE(pCursor->rc))
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pCursor->rc;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync /* Validate the offset and convert to debug_info relative offsets. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (enmWrt == krtDwarfRef_InfoSection)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (off >= pCursor->pDwarfMod->aSections[krtDbgModDwarfSect_info].cb)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync Log(("rtDwarfDecode_Reference: bad info off=%#llx\n", off));
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pCursor->rc = VERR_DWARF_BAD_POS;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync else if (enmWrt == krtDwarfRef_SameUnit)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync PRTDWARFDIECOMPILEUNIT pUnit = rtDwarfDie_GetCompileUnit(pDie);
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (off >= pUnit->cbUnit)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync Log(("rtDwarfDecode_Reference: bad unit off=%#llx\n", off));
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pCursor->rc = VERR_DWARF_BAD_POS;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync off += pUnit->offUnit;
e4bf6817370e1a71833a02285515694afcda7599vboxsync enmWrt = krtDwarfRef_InfoSection;
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync /* else: not bother verifying/resolving the indirect type reference yet. */
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync /* Store it */
e4bf6817370e1a71833a02285515694afcda7599vboxsync PRTDWARFREF pRef = (PRTDWARFREF)pbMember;
e4bf6817370e1a71833a02285515694afcda7599vboxsync pRef->enmWrt = enmWrt;
e4bf6817370e1a71833a02285515694afcda7599vboxsync pRef->off = off;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log4((" %-20s %d:%#010llx [%s]\n", rtDwarfLog_AttrName(pDesc->uAttr), enmWrt, off, rtDwarfLog_FormName(uForm)));
e4bf6817370e1a71833a02285515694afcda7599vboxsync return VINF_SUCCESS;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** @callback_method_impl{FNRTDWARFATTRDECODER} */
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic DECLCALLBACK(int) rtDwarfDecode_SectOff(PRTDWARFDIE pDie, uint8_t *pbMember, PCRTDWARFATTRDESC pDesc,
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint32_t uForm, PRTDWARFCURSOR pCursor)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertReturn(ATTR_GET_SIZE(pDesc) == sizeof(RTDWARFREF), VERR_INTERNAL_ERROR_3);
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync NOREF(pDie);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t off;
e4bf6817370e1a71833a02285515694afcda7599vboxsync switch (uForm)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case DW_FORM_data4: off = rtDwarfCursor_GetU32(pCursor, 0); break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case DW_FORM_data8: off = rtDwarfCursor_GetU64(pCursor, 0); break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case DW_FORM_sec_offset: off = rtDwarfCursor_GetUOff(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync default:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync AssertMsgFailedReturn(("%#x (%s)\n", uForm, rtDwarfLog_FormName(uForm)), VERR_DWARF_UNEXPECTED_FORM);
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (RT_FAILURE(pCursor->rc))
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pCursor->rc;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync krtDbgModDwarfSect enmSect;
e4bf6817370e1a71833a02285515694afcda7599vboxsync krtDwarfRef enmWrt;
e4bf6817370e1a71833a02285515694afcda7599vboxsync switch (pDesc->uAttr)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case DW_AT_stmt_list: enmSect = krtDbgModDwarfSect_line; enmWrt = krtDwarfRef_LineSection; break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case DW_AT_macro_info: enmSect = krtDbgModDwarfSect_loc; enmWrt = krtDwarfRef_LocSection; break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_AT_ranges: enmSect = krtDbgModDwarfSect_ranges; enmWrt = krtDwarfRef_RangesSection; break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync default:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync AssertMsgFailedReturn(("%u (%s)\n", pDesc->uAttr, rtDwarfLog_AttrName(pDesc->uAttr)), VERR_INTERNAL_ERROR_4);
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync size_t cbSect = pCursor->pDwarfMod->aSections[enmSect].cb;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (off >= cbSect)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync /* Watcom generates offset past the end of the section, increasing the
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync offset by one for each compile unit. So, just fudge it. */
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync Log(("rtDwarfDecode_SectOff: bad off=%#llx, attr %#x (%s), enmSect=%d cb=%#llx; Assuming watcom/gcc.\n", off,
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pDesc->uAttr, rtDwarfLog_AttrName(pDesc->uAttr), enmSect, cbSect));
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync off = cbSect;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync PRTDWARFREF pRef = (PRTDWARFREF)pbMember;
e4bf6817370e1a71833a02285515694afcda7599vboxsync pRef->enmWrt = enmWrt;
e4bf6817370e1a71833a02285515694afcda7599vboxsync pRef->off = off;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log4((" %-20s %d:%#010llx [%s]\n", rtDwarfLog_AttrName(pDesc->uAttr), enmWrt, off, rtDwarfLog_FormName(uForm)));
e4bf6817370e1a71833a02285515694afcda7599vboxsync return VINF_SUCCESS;
e4bf6817370e1a71833a02285515694afcda7599vboxsync}
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** @callback_method_impl{FNRTDWARFATTRDECODER} */
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic DECLCALLBACK(int) rtDwarfDecode_String(PRTDWARFDIE pDie, uint8_t *pbMember, PCRTDWARFATTRDESC pDesc,
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint32_t uForm, PRTDWARFCURSOR pCursor)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync{
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertReturn(ATTR_GET_SIZE(pDesc) == sizeof(const char *), VERR_INTERNAL_ERROR_3);
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync NOREF(pDie);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync const char *psz;
e4bf6817370e1a71833a02285515694afcda7599vboxsync switch (uForm)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_string:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync psz = rtDwarfCursor_GetSZ(pCursor, NULL);
e4bf6817370e1a71833a02285515694afcda7599vboxsync break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_strp:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync psz = rtDwarfDecodeHlp_GetStrp(pCursor->pDwarfMod, pCursor, NULL);
e4bf6817370e1a71833a02285515694afcda7599vboxsync break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync default:
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertMsgFailedReturn(("%#x\n", uForm), VERR_DWARF_UNEXPECTED_FORM);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync }
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync *(const char **)pbMember = psz;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log4((" %-20s '%s' [%s]\n", rtDwarfLog_AttrName(pDesc->uAttr), psz, rtDwarfLog_FormName(uForm)));
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pCursor->rc;
e4bf6817370e1a71833a02285515694afcda7599vboxsync}
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/** @callback_method_impl{FNRTDWARFATTRDECODER} */
e4bf6817370e1a71833a02285515694afcda7599vboxsyncstatic DECLCALLBACK(int) rtDwarfDecode_UnsignedInt(PRTDWARFDIE pDie, uint8_t *pbMember, PCRTDWARFATTRDESC pDesc,
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint32_t uForm, PRTDWARFCURSOR pCursor)
e4bf6817370e1a71833a02285515694afcda7599vboxsync{
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync NOREF(pDie);
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t u64Val;
e4bf6817370e1a71833a02285515694afcda7599vboxsync switch (uForm)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_udata: u64Val = rtDwarfCursor_GetULeb128(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_data1: u64Val = rtDwarfCursor_GetU8(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_data2: u64Val = rtDwarfCursor_GetU16(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_data4: u64Val = rtDwarfCursor_GetU32(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync case DW_FORM_data8: u64Val = rtDwarfCursor_GetU64(pCursor, 0); break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync default:
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertMsgFailedReturn(("%#x\n", uForm), VERR_DWARF_UNEXPECTED_FORM);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (RT_FAILURE(pCursor->rc))
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pCursor->rc;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync switch (ATTR_GET_SIZE(pDesc))
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync case 1:
e4bf6817370e1a71833a02285515694afcda7599vboxsync *pbMember = (uint8_t)u64Val;
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (*pbMember != u64Val)
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync {
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync AssertFailed();
e4bf6817370e1a71833a02285515694afcda7599vboxsync return VERR_OUT_OF_RANGE;
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync case 2:
e4bf6817370e1a71833a02285515694afcda7599vboxsync *(uint16_t *)pbMember = (uint16_t)u64Val;
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (*(uint16_t *)pbMember != u64Val)
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync {
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync AssertFailed();
e4bf6817370e1a71833a02285515694afcda7599vboxsync return VERR_OUT_OF_RANGE;
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync case 4:
e4bf6817370e1a71833a02285515694afcda7599vboxsync *(uint32_t *)pbMember = (uint32_t)u64Val;
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (*(uint32_t *)pbMember != u64Val)
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync {
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync AssertFailed();
e4bf6817370e1a71833a02285515694afcda7599vboxsync return VERR_OUT_OF_RANGE;
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync case 8:
e4bf6817370e1a71833a02285515694afcda7599vboxsync *(uint64_t *)pbMember = (uint64_t)u64Val;
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (*(uint64_t *)pbMember != u64Val)
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync {
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync AssertFailed();
e4bf6817370e1a71833a02285515694afcda7599vboxsync return VERR_OUT_OF_RANGE;
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync break;
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync default:
e4bf6817370e1a71833a02285515694afcda7599vboxsync AssertMsgFailedReturn(("%#x\n", ATTR_GET_SIZE(pDesc)), VERR_INTERNAL_ERROR_2);
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync return VINF_SUCCESS;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync}
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/**
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * Initialize location interpreter state from cursor & form.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync *
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @returns IPRT status code.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @retval VERR_NOT_FOUND if no location information (i.e. there is source but
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * it resulted in no byte code).
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param pLoc The location state structure to initialize.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param pCursor The cursor to read from.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param uForm The attribute form.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsyncstatic int rtDwarfLoc_Init(PRTDWARFLOCST pLoc, PRTDWARFCURSOR pCursor, uint32_t uForm)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync{
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uint32_t cbBlock;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync switch (uForm)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_FORM_block1:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync cbBlock = rtDwarfCursor_GetU8(pCursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_FORM_block2:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync cbBlock = rtDwarfCursor_GetU16(pCursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_FORM_block4:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync cbBlock = rtDwarfCursor_GetU32(pCursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_FORM_block:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync cbBlock = rtDwarfCursor_GetULeb128(pCursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync default:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync AssertMsgFailedReturn(("uForm=%#x\n", uForm), VERR_DWARF_UNEXPECTED_FORM);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (!cbBlock)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return VERR_NOT_FOUND;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync int rc = rtDwarfCursor_InitForBlock(&pLoc->Cursor, pCursor, cbBlock);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (RT_FAILURE(rc))
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return rc;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pLoc->iTop = -1;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return VINF_SUCCESS;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync}
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/**
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * Pushes a value onto the stack.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync *
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @returns VINF_SUCCESS or VERR_DWARF_STACK_OVERFLOW.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param pLoc The state.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync * @param uValue The value to push.
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsyncstatic int rtDwarfLoc_Push(PRTDWARFLOCST pLoc, uint64_t uValue)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync{
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync int iTop = pLoc->iTop + 1;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync AssertReturn((unsigned)iTop < RT_ELEMENTS(pLoc->auStack), VERR_DWARF_STACK_OVERFLOW);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pLoc->auStack[iTop] = uValue;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync pLoc->iTop = iTop;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return VINF_SUCCESS;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync}
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsyncstatic int rtDwarfLoc_Evaluate(PRTDWARFLOCST pLoc, void *pvLater, void *pvUser)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync{
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync while (!rtDwarfCursor_IsAtEndOfUnit(&pLoc->Cursor))
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync /* Read the next opcode.*/
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uint8_t const bOpcode = rtDwarfCursor_GetU8(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync /* Get its operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uint64_t uOperand1 = 0;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uint64_t uOperand2 = 0;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync switch (bOpcode)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_addr:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand1 = rtDwarfCursor_GetNativeUOff(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_pick:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const1u:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_deref_size:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_xderef_size:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand1 = rtDwarfCursor_GetU8(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const1s:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand1 = (int8_t)rtDwarfCursor_GetU8(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const2u:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand1 = rtDwarfCursor_GetU16(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_skip:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_bra:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const2s:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand1 = (int16_t)rtDwarfCursor_GetU16(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const4u:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand1 = rtDwarfCursor_GetU32(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const4s:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand1 = (int32_t)rtDwarfCursor_GetU32(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const8u:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand1 = rtDwarfCursor_GetU64(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const8s:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand1 = rtDwarfCursor_GetU64(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_regx:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_piece:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_plus_uconst:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_constu:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand1 = rtDwarfCursor_GetULeb128(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_consts:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_fbreg:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+0: case DW_OP_breg0+1: case DW_OP_breg0+2: case DW_OP_breg0+3:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+4: case DW_OP_breg0+5: case DW_OP_breg0+6: case DW_OP_breg0+7:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+8: case DW_OP_breg0+9: case DW_OP_breg0+10: case DW_OP_breg0+11:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+12: case DW_OP_breg0+13: case DW_OP_breg0+14: case DW_OP_breg0+15:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+16: case DW_OP_breg0+17: case DW_OP_breg0+18: case DW_OP_breg0+19:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+20: case DW_OP_breg0+21: case DW_OP_breg0+22: case DW_OP_breg0+23:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+24: case DW_OP_breg0+25: case DW_OP_breg0+26: case DW_OP_breg0+27:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+28: case DW_OP_breg0+29: case DW_OP_breg0+30: case DW_OP_breg0+31:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand1 = rtDwarfCursor_GetSLeb128(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_bregx:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand1 = rtDwarfCursor_GetULeb128(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uOperand2 = rtDwarfCursor_GetSLeb128(&pLoc->Cursor, 0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (RT_FAILURE(pLoc->Cursor.rc))
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync /* Interpret the opcode. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync int rc;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync switch (bOpcode)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const1u:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const1s:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const2u:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const2s:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const4u:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const4s:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const8u:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_const8s:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_constu:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_consts:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_addr:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync rc = rtDwarfLoc_Push(pLoc, uOperand1);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_lit0 + 0: case DW_OP_lit0 + 1: case DW_OP_lit0 + 2: case DW_OP_lit0 + 3:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_lit0 + 4: case DW_OP_lit0 + 5: case DW_OP_lit0 + 6: case DW_OP_lit0 + 7:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_lit0 + 8: case DW_OP_lit0 + 9: case DW_OP_lit0 + 10: case DW_OP_lit0 + 11:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_lit0 + 12: case DW_OP_lit0 + 13: case DW_OP_lit0 + 14: case DW_OP_lit0 + 15:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_lit0 + 16: case DW_OP_lit0 + 17: case DW_OP_lit0 + 18: case DW_OP_lit0 + 19:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_lit0 + 20: case DW_OP_lit0 + 21: case DW_OP_lit0 + 22: case DW_OP_lit0 + 23:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_lit0 + 24: case DW_OP_lit0 + 25: case DW_OP_lit0 + 26: case DW_OP_lit0 + 27:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_lit0 + 28: case DW_OP_lit0 + 29: case DW_OP_lit0 + 30: case DW_OP_lit0 + 31:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync rc = rtDwarfLoc_Push(pLoc, bOpcode - DW_OP_lit0);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_nop:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync break;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_dup: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_drop: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_over: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_pick: /** @todo 1 operands, a 1-byte stack index. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_swap: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_rot: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_abs: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_and: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_div: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_minus: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_mod: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_mul: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_neg: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_not: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_or: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_plus: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_plus_uconst: /** @todo 1 operands, a ULEB128 addend. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_shl: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_shr: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_shra: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_xor: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_skip: /** @todo 1 signed 2-byte constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_bra: /** @todo 1 signed 2-byte constant. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_eq: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_ge: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_gt: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_le: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_lt: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_ne: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_reg0 + 0: case DW_OP_reg0 + 1: case DW_OP_reg0 + 2: case DW_OP_reg0 + 3: /** @todo 0 operands - reg 0..31. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_reg0 + 4: case DW_OP_reg0 + 5: case DW_OP_reg0 + 6: case DW_OP_reg0 + 7:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_reg0 + 8: case DW_OP_reg0 + 9: case DW_OP_reg0 + 10: case DW_OP_reg0 + 11:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_reg0 + 12: case DW_OP_reg0 + 13: case DW_OP_reg0 + 14: case DW_OP_reg0 + 15:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_reg0 + 16: case DW_OP_reg0 + 17: case DW_OP_reg0 + 18: case DW_OP_reg0 + 19:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_reg0 + 20: case DW_OP_reg0 + 21: case DW_OP_reg0 + 22: case DW_OP_reg0 + 23:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_reg0 + 24: case DW_OP_reg0 + 25: case DW_OP_reg0 + 26: case DW_OP_reg0 + 27:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_reg0 + 28: case DW_OP_reg0 + 29: case DW_OP_reg0 + 30: case DW_OP_reg0 + 31:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+ 0: case DW_OP_breg0+ 1: case DW_OP_breg0+ 2: case DW_OP_breg0+ 3: /** @todo 1 operand, a SLEB128 offset. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+ 4: case DW_OP_breg0+ 5: case DW_OP_breg0+ 6: case DW_OP_breg0+ 7:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+ 8: case DW_OP_breg0+ 9: case DW_OP_breg0+ 10: case DW_OP_breg0+ 11:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+ 12: case DW_OP_breg0+ 13: case DW_OP_breg0+ 14: case DW_OP_breg0+ 15:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+ 16: case DW_OP_breg0+ 17: case DW_OP_breg0+ 18: case DW_OP_breg0+ 19:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+ 20: case DW_OP_breg0+ 21: case DW_OP_breg0+ 22: case DW_OP_breg0+ 23:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+ 24: case DW_OP_breg0+ 25: case DW_OP_breg0+ 26: case DW_OP_breg0+ 27:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_breg0+ 28: case DW_OP_breg0+ 29: case DW_OP_breg0+ 30: case DW_OP_breg0+ 31:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_piece: /** @todo 1 operand, a ULEB128 size of piece addressed. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_regx: /** @todo 1 operand, a ULEB128 register. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_fbreg: /** @todo 1 operand, a SLEB128 offset. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_bregx: /** @todo 2 operands, a ULEB128 register followed by a SLEB128 offset. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_deref: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_deref_size: /** @todo 1 operand, a 1-byte size of data retrieved. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_xderef: /** @todo 0 operands. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync case DW_OP_xderef_size: /** @todo 1 operand, a 1-byte size of data retrieved. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync AssertMsgFailedReturn(("bOpcode=%#x\n", bOpcode), VERR_DWARF_TODO);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync default:
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync AssertMsgFailedReturn(("bOpcode=%#x\n", bOpcode), VERR_DWARF_UNKNOWN_LOC_OPCODE);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return pLoc->Cursor.rc;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync}
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync/** @callback_method_impl{FNRTDWARFATTRDECODER} */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsyncstatic DECLCALLBACK(int) rtDwarfDecode_SegmentLoc(PRTDWARFDIE pDie, uint8_t *pbMember, PCRTDWARFATTRDESC pDesc,
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uint32_t uForm, PRTDWARFCURSOR pCursor)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync{
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync NOREF(pDie);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync AssertReturn(ATTR_GET_SIZE(pDesc) == 2, VERR_DWARF_IPE);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync RTDWARFLOCST LocSt;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync int rc = rtDwarfLoc_Init(&LocSt, pCursor, uForm);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (RT_SUCCESS(rc))
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync rc = rtDwarfLoc_Evaluate(&LocSt, NULL, NULL);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (RT_SUCCESS(rc))
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (LocSt.iTop >= 0)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync *(uint16_t *)pbMember = LocSt.auStack[LocSt.iTop];
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync Log4((" %-20s %#06llx [%s]\n", rtDwarfLog_AttrName(pDesc->uAttr),
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync LocSt.auStack[LocSt.iTop], rtDwarfLog_FormName(uForm)));
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return VINF_SUCCESS;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = VERR_DWARF_STACK_UNDERFLOW;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return rc;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync}
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/*
e4bf6817370e1a71833a02285515694afcda7599vboxsync *
e4bf6817370e1a71833a02285515694afcda7599vboxsync * DWARF debug_info parser
e4bf6817370e1a71833a02285515694afcda7599vboxsync * DWARF debug_info parser
e4bf6817370e1a71833a02285515694afcda7599vboxsync * DWARF debug_info parser
e4bf6817370e1a71833a02285515694afcda7599vboxsync *
e4bf6817370e1a71833a02285515694afcda7599vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync/**
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * Parse the attributes of a DIE.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync *
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @returns IPRT status code.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @param pThis The DWARF instance.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @param pDie The internal DIE structure to fill.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsyncstatic int rtDwarfInfo_SnoopSymbols(PRTDBGMODDWARF pThis, PRTDWARFDIE pDie)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync{
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync int rc = VINF_SUCCESS;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync switch (pDie->uTag)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case DW_TAG_subprogram:
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync PCRTDWARFDIESUBPROGRAM pSubProgram = (PCRTDWARFDIESUBPROGRAM)pDie;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (pSubProgram->PcRange.cAttrs)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (pSubProgram->PcRange.fHaveRanges)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync Log5(("subprogram %s (%s) <implement ranges>\n", pSubProgram->pszName, pSubProgram->pszLinkageName));
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync else
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync Log5(("subprogram %s (%s) %#llx-%#llx%s\n", pSubProgram->pszName, pSubProgram->pszLinkageName,
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pSubProgram->PcRange.uLowAddress, pSubProgram->PcRange.uHighAddress,
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pSubProgram->PcRange.cAttrs == 2 ? "" : " !bad!"));
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if ( pSubProgram->pszName
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync && pSubProgram->PcRange.cAttrs == 2)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (pThis->iWatcomPass == 1)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = rtDbgModDwarfRecordSegOffset(pThis, pSubProgram->uSegment, pSubProgram->PcRange.uHighAddress);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync else
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync RTDBGSEGIDX iSeg;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync RTUINTPTR offSeg;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = rtDbgModDwarfLinkAddressToSegOffset(pThis, pSubProgram->uSegment,
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pSubProgram->PcRange.uLowAddress,
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync &iSeg, &offSeg);
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync AssertRC(rc);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (RT_SUCCESS(rc))
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = RTDbgModSymbolAdd(pThis->hCnt, pSubProgram->pszName, iSeg, offSeg,
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pSubProgram->PcRange.uHighAddress - pSubProgram->PcRange.uLowAddress,
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync 0 /*fFlags*/, NULL /*piOrdinal*/);
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync AssertRC(rc);
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync else
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync Log5(("rtDbgModDwarfLinkAddressToSegOffset failed: %Rrc\n", rc));
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync else
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync Log5(("subprogram %s (%s) external\n", pSubProgram->pszName, pSubProgram->pszLinkageName));
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync case DW_TAG_label:
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync PCRTDWARFDIELABEL pLabel = (PCRTDWARFDIELABEL)pDie;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (pLabel->fExternal)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync Log5(("label %s %#x:%#llx\n", pLabel->pszName, pLabel->uSegment, pLabel->Address.uAddress));
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (pThis->iWatcomPass == 1)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = rtDbgModDwarfRecordSegOffset(pThis, pLabel->uSegment, pLabel->Address.uAddress);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync else
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync RTDBGSEGIDX iSeg;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync RTUINTPTR offSeg;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = rtDbgModDwarfLinkAddressToSegOffset(pThis, pLabel->uSegment, pLabel->Address.uAddress,
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync &iSeg, &offSeg);
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync AssertRC(rc);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (RT_SUCCESS(rc))
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = RTDbgModSymbolAdd(pThis->hCnt, pLabel->pszName, iSeg, offSeg, 0 /*cb*/,
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync 0 /*fFlags*/, NULL /*piOrdinal*/);
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync AssertRC(rc);
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync else
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync Log5(("rtDbgModDwarfLinkAddressToSegOffset failed: %Rrc\n", rc));
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync break;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync return rc;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync}
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync/**
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * Initializes the non-core fields of an internal DIE structure.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync *
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @param pDie The DIE structure.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @param pDieDesc The DIE descriptor.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsyncstatic void rtDwarfInfo_InitDie(PRTDWARFDIE pDie, PCRTDWARFDIEDESC pDieDesc)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync{
ed521f15dde29451cbdb1df104f666204e04ba65vboxsync size_t i = pDieDesc->cAttributes;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync while (i-- > 0)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync switch (pDieDesc->paAttributes[i].cbInit & ATTR_INIT_MASK)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case ATTR_INIT_ZERO:
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /* Nothing to do (RTMemAllocZ). */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync break;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case ATTR_INIT_FFFS:
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync switch (pDieDesc->paAttributes[i].cbInit & ATTR_SIZE_MASK)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case 1:
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync *(uint8_t *)((uintptr_t)pDie + pDieDesc->paAttributes[i].off) = UINT8_MAX;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case 2:
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync *(uint16_t *)((uintptr_t)pDie + pDieDesc->paAttributes[i].off) = UINT16_MAX;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case 4:
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync *(uint32_t *)((uintptr_t)pDie + pDieDesc->paAttributes[i].off) = UINT32_MAX;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync case 8:
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync *(uint64_t *)((uintptr_t)pDie + pDieDesc->paAttributes[i].off) = UINT64_MAX;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync default:
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync AssertFailed();
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync memset((uint8_t *)pDie + pDieDesc->paAttributes[i].off, 0xff,
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pDieDesc->paAttributes[i].cbInit & ATTR_SIZE_MASK);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync break;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync default:
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync AssertFailed();
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync }
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync}
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync/**
e4bf6817370e1a71833a02285515694afcda7599vboxsync * Creates a new internal DIE structure and links it up.
e4bf6817370e1a71833a02285515694afcda7599vboxsync *
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @returns Pointer to the new DIE structure.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @param pThis The DWARF instance.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @param pDieDesc The DIE descriptor (for size and init).
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @param pAbbrev The abbreviation cache entry.
e4bf6817370e1a71833a02285515694afcda7599vboxsync * @param pParent The parent DIE (NULL if unit).
e4bf6817370e1a71833a02285515694afcda7599vboxsync */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsyncstatic PRTDWARFDIE rtDwarfInfo_NewDie(PRTDBGMODDWARF pThis, PCRTDWARFDIEDESC pDieDesc,
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync PCRTDWARFABBREV pAbbrev, PRTDWARFDIE pParent)
e4bf6817370e1a71833a02285515694afcda7599vboxsync{
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync NOREF(pThis);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync Assert(pDieDesc->cbDie >= sizeof(RTDWARFDIE));
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync PRTDWARFDIE pDie = (PRTDWARFDIE)RTMemAllocZ(pDieDesc->cbDie);
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (pDie)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync rtDwarfInfo_InitDie(pDie, pDieDesc);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync pDie->uTag = pAbbrev->uTag;
e4bf6817370e1a71833a02285515694afcda7599vboxsync pDie->offSpec = pAbbrev->offSpec;
e4bf6817370e1a71833a02285515694afcda7599vboxsync pDie->pParent = pParent;
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (pParent)
e4bf6817370e1a71833a02285515694afcda7599vboxsync RTListAppend(&pParent->ChildList, &pDie->SiblingNode);
e4bf6817370e1a71833a02285515694afcda7599vboxsync else
e4bf6817370e1a71833a02285515694afcda7599vboxsync RTListInit(&pDie->SiblingNode);
e4bf6817370e1a71833a02285515694afcda7599vboxsync RTListInit(&pDie->ChildList);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync return pDie;
e4bf6817370e1a71833a02285515694afcda7599vboxsync}
e4bf6817370e1a71833a02285515694afcda7599vboxsync
e4bf6817370e1a71833a02285515694afcda7599vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Skips a form.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @returns IPRT status code
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param pCursor The cursor.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param uForm The form to skip.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsyncstatic int rtDwarfInfo_SkipForm(PRTDWARFCURSOR pCursor, uint32_t uForm)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync{
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync switch (uForm)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync {
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_addr:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rtDwarfCursor_SkipBytes(pCursor, pCursor->cbNativeAddr);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_block:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_exprloc:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rtDwarfCursor_SkipBytes(pCursor, rtDwarfCursor_GetULeb128(pCursor, 0));
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_block1:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rtDwarfCursor_SkipBytes(pCursor, rtDwarfCursor_GetU8(pCursor, 0));
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_block2:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rtDwarfCursor_SkipBytes(pCursor, rtDwarfCursor_GetU16(pCursor, 0));
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_block4:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rtDwarfCursor_SkipBytes(pCursor, rtDwarfCursor_GetU32(pCursor, 0));
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_data1:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_ref1:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_flag:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rtDwarfCursor_SkipBytes(pCursor, 1);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_data2:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_ref2:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rtDwarfCursor_SkipBytes(pCursor, 2);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_data4:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_ref4:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rtDwarfCursor_SkipBytes(pCursor, 4);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_data8:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_ref8:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_ref_sig8:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rtDwarfCursor_SkipBytes(pCursor, 8);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_udata:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_sdata:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_ref_udata:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rtDwarfCursor_SkipLeb128(pCursor);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_string:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync rtDwarfCursor_GetSZ(pCursor, NULL);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return pCursor->rc;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_indirect:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rtDwarfInfo_SkipForm(pCursor, rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX));
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_strp:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_ref_addr:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_sec_offset:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rtDwarfCursor_SkipBytes(pCursor, pCursor->f64bitDwarf ? 8 : 4);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync case DW_FORM_flag_present:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return pCursor->rc; /* no data */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync default:
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return VERR_DWARF_UNKNOWN_FORM;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync }
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync}
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
70aa086e9e9d2f85d2e997d0e69169018a001e54vboxsync#ifdef SOME_UNUSED_FUNCTION
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync/**
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * Skips a DIE.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync *
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @returns IPRT status code.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param pCursor The cursor.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync * @param pAbbrevCursor The abbreviation cursor.
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync */
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsyncstatic int rtDwarfInfo_SkipDie(PRTDWARFCURSOR pCursor, PRTDWARFCURSOR pAbbrevCursor)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync{
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync for (;;)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync {
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync uint32_t uAttr = rtDwarfCursor_GetULeb128AsU32(pAbbrevCursor, 0);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync uint32_t uForm = rtDwarfCursor_GetULeb128AsU32(pAbbrevCursor, 0);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync if (uAttr == 0 && uForm == 0)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync break;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync int rc = rtDwarfInfo_SkipForm(pCursor, uForm);
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync if (RT_FAILURE(rc))
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return rc;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync }
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync return RT_FAILURE(pCursor->rc) ? pCursor->rc : pAbbrevCursor->rc;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync}
70aa086e9e9d2f85d2e997d0e69169018a001e54vboxsync#endif
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/**
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * Parse the attributes of a DIE.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync *
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @returns IPRT status code.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pThis The DWARF instance.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @param pDie The internal DIE structure to fill.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @param pDieDesc The DIE descriptor.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pCursor The debug_info cursor.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @param pAbbrev The abbreviation cache entry.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsyncstatic int rtDwarfInfo_ParseDie(PRTDBGMODDWARF pThis, PRTDWARFDIE pDie, PCRTDWARFDIEDESC pDieDesc,
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync PRTDWARFCURSOR pCursor, PCRTDWARFABBREV pAbbrev)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync RTDWARFCURSOR AbbrevCursor;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync int rc = rtDwarfCursor_InitWithOffset(&AbbrevCursor, pThis, krtDbgModDwarfSect_abbrev, pAbbrev->offSpec);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (RT_FAILURE(rc))
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync return rc;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync rtDwarfInfo_InitDie(pDie, pDieDesc);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync for (;;)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync uint32_t uAttr = rtDwarfCursor_GetULeb128AsU32(&AbbrevCursor, 0);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync uint32_t uForm = rtDwarfCursor_GetULeb128AsU32(&AbbrevCursor, 0);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (uAttr == 0)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (uForm == DW_FORM_indirect)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync uForm = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /* Look up the attribute in the descriptor and invoke the decoder. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync PCRTDWARFATTRDESC pAttr = NULL;
ed521f15dde29451cbdb1df104f666204e04ba65vboxsync size_t i = pDieDesc->cAttributes;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync while (i-- > 0)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (pDieDesc->paAttributes[i].uAttr == uAttr)
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pAttr = &pDieDesc->paAttributes[i];
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync rc = pAttr->pfnDecoder(pDie, (uint8_t *)pDie + pAttr->off, pAttr, uForm, pCursor);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync break;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync }
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /* Some house keeping. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (pAttr)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pDie->cDecodedAttrs++;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync else
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pDie->cUnhandledAttrs++;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync rc = rtDwarfInfo_SkipForm(pCursor, uForm);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log4((" %-20s [%s]\n", rtDwarfLog_AttrName(uAttr), rtDwarfLog_FormName(uForm)));
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (RT_FAILURE(rc))
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync rc = rtDwarfCursor_Delete(&AbbrevCursor, rc);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (RT_SUCCESS(rc))
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync rc = pCursor->rc;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /*
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync * Snoop up symbols on the way out.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (RT_SUCCESS(rc))
015d66d7947b8b6a38619a0c205842f86c832fe3vboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync rc = rtDwarfInfo_SnoopSymbols(pThis, pDie);
015d66d7947b8b6a38619a0c205842f86c832fe3vboxsync /* Ignore duplicates, get work done instead. */
015d66d7947b8b6a38619a0c205842f86c832fe3vboxsync /** @todo clean up global/static symbol mess. */
015d66d7947b8b6a38619a0c205842f86c832fe3vboxsync if (rc == VERR_DBG_DUPLICATE_SYMBOL)
015d66d7947b8b6a38619a0c205842f86c832fe3vboxsync rc = VINF_SUCCESS;
015d66d7947b8b6a38619a0c205842f86c832fe3vboxsync }
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync return rc;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync/**
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * Load the debug information of a unit.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync *
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @returns IPRT status code.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @param pThis The DWARF instance.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @param pCursor The debug_info cursor.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * @param fKeepDies Whether to keep the DIEs or discard them as soon
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * as possible.
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsyncstatic int rtDwarfInfo_LoadUnit(PRTDBGMODDWARF pThis, PRTDWARFCURSOR pCursor, bool fKeepDies)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync{
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log(("rtDwarfInfo_LoadUnit: %#x\n", rtDwarfCursor_CalcSectOffsetU32(pCursor)));
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Read the compilation unit header.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t offUnit = rtDwarfCursor_CalcSectOffsetU32(pCursor);
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint64_t cbUnit = rtDwarfCursor_GetInitalLength(pCursor);
e4bf6817370e1a71833a02285515694afcda7599vboxsync cbUnit += rtDwarfCursor_CalcSectOffsetU32(pCursor) - offUnit;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint16_t const uVer = rtDwarfCursor_GetUHalf(pCursor, 0);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if ( uVer < 2
ad66a27959d7085aa31760f63ce082943be60e89vboxsync || uVer > 4)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return rtDwarfCursor_SkipUnit(pCursor);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint64_t const offAbbrev = rtDwarfCursor_GetUOff(pCursor, UINT64_MAX);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint8_t const cbNativeAddr = rtDwarfCursor_GetU8(pCursor, UINT8_MAX);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (RT_FAILURE(pCursor->rc))
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return pCursor->rc;
1025ef7261a6961d07d390e85a095d806ccb88d9vboxsync Log((" uVer=%d offAbbrev=%#llx cbNativeAddr=%d\n", uVer, offAbbrev, cbNativeAddr));
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Set up the abbreviation cache and store the native address size in the cursor.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (offAbbrev > UINT32_MAX)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log(("Unexpected abbrviation code offset of %#llx\n", offAbbrev));
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return VERR_DWARF_BAD_INFO;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
ed521f15dde29451cbdb1df104f666204e04ba65vboxsync rtDwarfAbbrev_SetUnitOffset(pThis, (uint32_t)offAbbrev);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pCursor->cbNativeAddr = cbNativeAddr;
d3dea25ec07f6546715fe3af943ea863294b392evboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /*
e4bf6817370e1a71833a02285515694afcda7599vboxsync * The first DIE is a compile or partial unit, parse it here.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
e4bf6817370e1a71833a02285515694afcda7599vboxsync uint32_t uAbbrCode = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (!uAbbrCode)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log(("Unexpected abbrviation code of zero\n"));
e4bf6817370e1a71833a02285515694afcda7599vboxsync return VERR_DWARF_BAD_INFO;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync PCRTDWARFABBREV pAbbrev = rtDwarfAbbrev_Lookup(pThis, uAbbrCode);
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (!pAbbrev)
e4bf6817370e1a71833a02285515694afcda7599vboxsync return VERR_DWARF_ABBREV_NOT_FOUND;
e4bf6817370e1a71833a02285515694afcda7599vboxsync if ( pAbbrev->uTag != DW_TAG_compile_unit
e4bf6817370e1a71833a02285515694afcda7599vboxsync && pAbbrev->uTag != DW_TAG_partial_unit)
e4bf6817370e1a71833a02285515694afcda7599vboxsync {
e4bf6817370e1a71833a02285515694afcda7599vboxsync Log(("Unexpected compile/partial unit tag %#x\n", pAbbrev->uTag));
e4bf6817370e1a71833a02285515694afcda7599vboxsync return VERR_DWARF_BAD_INFO;
e4bf6817370e1a71833a02285515694afcda7599vboxsync }
e4bf6817370e1a71833a02285515694afcda7599vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync PRTDWARFDIECOMPILEUNIT pUnit;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pUnit = (PRTDWARFDIECOMPILEUNIT)rtDwarfInfo_NewDie(pThis, &g_CompileUnitDesc, pAbbrev, NULL /*pParent*/);
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (!pUnit)
e4bf6817370e1a71833a02285515694afcda7599vboxsync return VERR_NO_MEMORY;
e4bf6817370e1a71833a02285515694afcda7599vboxsync pUnit->offUnit = offUnit;
e4bf6817370e1a71833a02285515694afcda7599vboxsync pUnit->cbUnit = cbUnit;
e4bf6817370e1a71833a02285515694afcda7599vboxsync pUnit->offAbbrev = offAbbrev;
e4bf6817370e1a71833a02285515694afcda7599vboxsync pUnit->cbNativeAddr = cbNativeAddr;
ed521f15dde29451cbdb1df104f666204e04ba65vboxsync pUnit->uDwarfVer = (uint8_t)uVer;
e4bf6817370e1a71833a02285515694afcda7599vboxsync RTListAppend(&pThis->CompileUnitList, &pUnit->Core.SiblingNode);
e4bf6817370e1a71833a02285515694afcda7599vboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync int rc = rtDwarfInfo_ParseDie(pThis, &pUnit->Core, &g_CompileUnitDesc, pCursor, pAbbrev);
e4bf6817370e1a71833a02285515694afcda7599vboxsync if (RT_FAILURE(rc))
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync return rc;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Parse DIEs.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync uint32_t cDepth = 0;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync PRTDWARFDIE pParentDie = &pUnit->Core;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync while (!rtDwarfCursor_IsAtEndOfUnit(pCursor))
d3dea25ec07f6546715fe3af943ea863294b392evboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#ifdef LOG_ENABLED
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uint32_t offLog = rtDwarfCursor_CalcSectOffsetU32(pCursor);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync#endif
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync uAbbrCode = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (!uAbbrCode)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync /* End of siblings, up one level. (Is this correct?) */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pParentDie = pParentDie->pParent;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (!pParentDie)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync /* Padding. */
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync while (!rtDwarfCursor_IsAtEndOfUnit(pCursor))
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync uAbbrCode = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync if (uAbbrCode)
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync {
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log(("%08x: End of DIE stack, but still more info to parse: uAbbrCode=%#x (+%u bytes).\n",
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync offLog, uAbbrCode, pCursor->cbUnitLeft));
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return VERR_DWARF_BAD_INFO;
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync }
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync break;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync cDepth--;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync /* Unlink and free child DIEs if told to do so. */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (!fKeepDies && pParentDie->pParent)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync PRTDWARFDIE pChild, pNextChild;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync RTListForEachSafe(&pParentDie->ChildList, pChild, pNextChild, RTDWARFDIE, SiblingNode)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync RTListNodeRemove(&pChild->SiblingNode);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync RTMemFree(pChild);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync }
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync }
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync else
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync {
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /*
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * Look up the abbreviation and match the tag up with a descriptor.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pAbbrev = rtDwarfAbbrev_Lookup(pThis, uAbbrCode);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (!pAbbrev)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync return VERR_DWARF_ABBREV_NOT_FOUND;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync PCRTDWARFDIEDESC pDieDesc;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync const char *pszName;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (pAbbrev->uTag < RT_ELEMENTS(g_aTagDescs))
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync Assert(g_aTagDescs[pAbbrev->uTag].uTag == pAbbrev->uTag || g_aTagDescs[pAbbrev->uTag].uTag == 0);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pszName = g_aTagDescs[pAbbrev->uTag].pszName;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pDieDesc = g_aTagDescs[pAbbrev->uTag].pDesc;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync else
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pszName = "<unknown>";
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pDieDesc = g_aTagDescs[0].pDesc;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync }
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync Log4(("%08x: %*stag=%s (%#x)%s\n", offLog, cDepth * 2, "", pszName,
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pAbbrev->uTag, pAbbrev->fChildren ? " has children" : ""));
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /*
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * Create a new internal DIE structure and parse the
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync * attributes.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync PRTDWARFDIE pNewDie = rtDwarfInfo_NewDie(pThis, pDieDesc, pAbbrev, pParentDie);
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (!pNewDie)
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync return VERR_NO_MEMORY;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync if (pAbbrev->fChildren)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync {
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync pParentDie = pNewDie;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync cDepth++;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync rc = rtDwarfInfo_ParseDie(pThis, pNewDie, pDieDesc, pCursor, pAbbrev);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (RT_FAILURE(rc))
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync return rc;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync }
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync } /* while more DIEs */
d3dea25ec07f6546715fe3af943ea863294b392evboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return RT_SUCCESS(rc) ? pCursor->rc : rc;
d3dea25ec07f6546715fe3af943ea863294b392evboxsync}
d3dea25ec07f6546715fe3af943ea863294b392evboxsync
d3dea25ec07f6546715fe3af943ea863294b392evboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/**
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Extracts the symbols.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync *
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * The symbols are insered into the debug info container.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync *
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @returns IPRT status code
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * @param pThis The DWARF instance.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsyncstatic int rtDwarfInfo_LoadAll(PRTDBGMODDWARF pThis)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync{
ad66a27959d7085aa31760f63ce082943be60e89vboxsync RTDWARFCURSOR Cursor;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync int rc = rtDwarfCursor_Init(&Cursor, pThis, krtDbgModDwarfSect_info);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (RT_SUCCESS(rc))
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync while ( !rtDwarfCursor_IsAtEnd(&Cursor)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync && RT_SUCCESS(rc))
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = rtDwarfInfo_LoadUnit(pThis, &Cursor, false /* fKeepDies */);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = rtDwarfCursor_Delete(&Cursor, rc);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync return rc;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync}
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/*
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Debug module implementation.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Debug module implementation.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF Debug module implementation.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnLineByAddr} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_LineByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTINTPTR poffDisp, PRTDBGLINE pLineInfo)
d3dea25ec07f6546715fe3af943ea863294b392evboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModLineByAddr(pThis->hCnt, iSeg, off, poffDisp, pLineInfo);
d3dea25ec07f6546715fe3af943ea863294b392evboxsync}
d3dea25ec07f6546715fe3af943ea863294b392evboxsync
d3dea25ec07f6546715fe3af943ea863294b392evboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnLineByOrdinal} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_LineByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo)
d3dea25ec07f6546715fe3af943ea863294b392evboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModLineByOrdinal(pThis->hCnt, iOrdinal, pLineInfo);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnLineCount} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(uint32_t) rtDbgModDwarf_LineCount(PRTDBGMODINT pMod)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModLineCount(pThis->hCnt);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnLineAdd} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_LineAdd(PRTDBGMODINT pMod, const char *pszFile, size_t cchFile, uint32_t uLineNo,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint32_t iSeg, RTUINTPTR off, uint32_t *piOrdinal)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync Assert(!pszFile[cchFile]); NOREF(cchFile);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModLineAdd(pThis->hCnt, pszFile, uLineNo, iSeg, off, piOrdinal);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByAddr} */
2d8870843ff566fee9bd3a6a5942414254106479vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SymbolByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
2d8870843ff566fee9bd3a6a5942414254106479vboxsync return RTDbgModSymbolByAddr(pThis->hCnt, iSeg, off, fFlags, poffDisp, pSymInfo);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByName} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SymbolByName(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGSYMBOL pSymInfo)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync Assert(!pszSymbol[cchSymbol]);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSymbolByName(pThis->hCnt, pszSymbol/*, cchSymbol*/, pSymInfo);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByOrdinal} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SymbolByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSymbolByOrdinal(pThis->hCnt, iOrdinal, pSymInfo);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolCount} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(uint32_t) rtDbgModDwarf_SymbolCount(PRTDBGMODINT pMod)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSymbolCount(pThis->hCnt);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolAdd} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SymbolAdd(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync RTDBGSEGIDX iSeg, RTUINTPTR off, RTUINTPTR cb, uint32_t fFlags,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint32_t *piOrdinal)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync Assert(!pszSymbol[cchSymbol]); NOREF(cchSymbol);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSymbolAdd(pThis->hCnt, pszSymbol, iSeg, off, cb, fFlags, piOrdinal);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentByIndex} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SegmentByIndex(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSegmentByIndex(pThis->hCnt, iSeg, pSegInfo);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentCount} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(RTDBGSEGIDX) rtDbgModDwarf_SegmentCount(PRTDBGMODINT pMod)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSegmentCount(pThis->hCnt);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentAdd} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SegmentAdd(PRTDBGMODINT pMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName, size_t cchName,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync uint32_t fFlags, PRTDBGSEGIDX piSeg)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync Assert(!pszName[cchName]); NOREF(cchName);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSegmentAdd(pThis->hCnt, uRva, cb, pszName, fFlags, piSeg);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnImageSize} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(RTUINTPTR) rtDbgModDwarf_ImageSize(PRTDBGMODINT pMod)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync RTUINTPTR cb1 = RTDbgModImageSize(pThis->hCnt);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync RTUINTPTR cb2 = pThis->pImgMod->pImgVt->pfnImageSize(pMod);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RT_MAX(cb1, cb2);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnRvaToSegOff} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(RTDBGSEGIDX) rtDbgModDwarf_RvaToSegOff(PRTDBGMODINT pMod, RTUINTPTR uRva, PRTUINTPTR poffSeg)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModRvaToSegOff(pThis->hCnt, uRva, poffSeg);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnClose} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_Close(PRTDBGMODINT pMod)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync for (unsigned iSect = 0; iSect < RT_ELEMENTS(pThis->aSections); iSect++)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync if (pThis->aSections[iSect].pv)
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pThis->pDbgInfoMod->pImgVt->pfnUnmapPart(pThis->pDbgInfoMod, pThis->aSections[iSect].cb, &pThis->aSections[iSect].pv);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync RTDbgModRelease(pThis->hCnt);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync RTMemFree(pThis->paCachedAbbrevs);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync if (pThis->pNestedMod)
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync {
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pThis->pNestedMod->pImgVt->pfnClose(pThis->pNestedMod);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync RTStrCacheRelease(g_hDbgModStrCache, pThis->pNestedMod->pszName);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync RTStrCacheRelease(g_hDbgModStrCache, pThis->pNestedMod->pszDbgFile);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync RTMemFree(pThis->pNestedMod);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pThis->pNestedMod = NULL;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync }
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync RTMemFree(pThis);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return VINF_SUCCESS;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync}
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** @callback_method_impl{FNRTLDRENUMDBG} */
daa94352f51be2329ac8660f70396e03a7cb983bvboxsyncstatic DECLCALLBACK(int) rtDbgModDwarfEnumCallback(RTLDRMOD hLdrMod, PCRTLDRDBGINFO pDbgInfo, void *pvUser)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync{
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * Skip stuff we can't handle.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync */
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync if (pDbgInfo->enmType != RTLDRDBGINFOTYPE_DWARF)
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync return VINF_SUCCESS;
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync const char *pszSection = pDbgInfo->u.Dwarf.pszSection;
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync if (!pszSection || !*pszSection)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync return VINF_SUCCESS;
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync Assert(!pDbgInfo->pszExtFile);
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /*
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Must have a part name starting with debug_ and possibly prefixed by dots
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * or underscores.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync if (!strncmp(pszSection, RT_STR_TUPLE(".debug_"))) /* ELF */
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync pszSection += sizeof(".debug_") - 1;
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync else if (!strncmp(pszSection, RT_STR_TUPLE("__debug_"))) /* Mach-O */
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync pszSection += sizeof("__debug_") - 1;
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync else if (!strcmp(pszSection, ".WATCOM_references"))
113a43aca041000560f93f9a8ee23dfcf01a9e7cvboxsync return VINF_SUCCESS; /* Ignore special watcom section for now.*/
5b0a093ca572a855886faa6747ad46df859dd041vboxsync else
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync AssertMsgFailedReturn(("%s\n", pszSection), VINF_SUCCESS /*ignore*/);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /*
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Figure out which part we're talking about.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect enmSect;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (0) { /* dummy */ }
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync#define ELSE_IF_STRCMP_SET(a_Name) else if (!strcmp(pszSection, #a_Name)) enmSect = krtDbgModDwarfSect_ ## a_Name
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(abbrev);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(aranges);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(frame);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(info);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(inlined);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(line);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(loc);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(macinfo);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(pubnames);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(pubtypes);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(ranges);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(str);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync ELSE_IF_STRCMP_SET(types);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#undef ELSE_IF_STRCMP_SET
5b0a093ca572a855886faa6747ad46df859dd041vboxsync else
5b0a093ca572a855886faa6747ad46df859dd041vboxsync {
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync AssertMsgFailed(("%s\n", pszSection));
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return VINF_SUCCESS;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync }
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /*
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Record the section.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pvUser;
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync AssertMsgReturn(!pThis->aSections[enmSect].fPresent, ("duplicate %s\n", pszSection), VINF_SUCCESS /*ignore*/);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync pThis->aSections[enmSect].fPresent = true;
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync pThis->aSections[enmSect].offFile = pDbgInfo->offFile;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync pThis->aSections[enmSect].pv = NULL;
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync pThis->aSections[enmSect].cb = (size_t)pDbgInfo->cb;
3bb3e26b3306b9f62b18c17380bdf2ca3a98ca49vboxsync pThis->aSections[enmSect].iDbgInfo = pDbgInfo->iDbgInfo;
daa94352f51be2329ac8660f70396e03a7cb983bvboxsync if (pThis->aSections[enmSect].cb != pDbgInfo->cb)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync pThis->aSections[enmSect].cb = ~(size_t)0;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync return VINF_SUCCESS;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync}
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
d1e9999d55e7ac80a28692c161710be98071fc00vboxsyncstatic int rtDbgModDwarfTryOpenDbgFile(PRTDBGMODINT pDbgMod, PRTDBGMODDWARF pThis, RTLDRARCH enmArch)
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync{
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync if ( !pDbgMod->pszDbgFile
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync || RTPathIsSame(pDbgMod->pszDbgFile, pDbgMod->pszImgFile) == true /* returns VERR too */)
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync return VERR_DBG_NO_MATCHING_INTERPRETER;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync /*
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync * Only open the image.
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync */
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync PRTDBGMODINT pDbgInfoMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgInfoMod));
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync if (!pDbgInfoMod)
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync return VERR_NO_MEMORY;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync int rc;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pDbgInfoMod->u32Magic = RTDBGMOD_MAGIC;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pDbgInfoMod->cRefs = 1;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync if (RTStrCacheRetain(pDbgMod->pszDbgFile) != UINT32_MAX)
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync {
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pDbgInfoMod->pszImgFile = pDbgMod->pszDbgFile;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync if (RTStrCacheRetain(pDbgMod->pszName) != UINT32_MAX)
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync {
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pDbgInfoMod->pszName = pDbgMod->pszName;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pDbgInfoMod->pImgVt = &g_rtDbgModVtImgLdr;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync rc = pDbgInfoMod->pImgVt->pfnTryOpen(pDbgInfoMod, enmArch);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync if (RT_SUCCESS(rc))
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync {
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pThis->pDbgInfoMod = pDbgInfoMod;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pThis->pNestedMod = pDbgInfoMod;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync return VINF_SUCCESS;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync }
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync RTStrCacheRelease(g_hDbgModStrCache, pDbgInfoMod->pszName);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync }
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync else
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync rc = VERR_NO_STR_MEMORY;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync RTStrCacheRelease(g_hDbgModStrCache, pDbgInfoMod->pszImgFile);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync }
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync else
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync rc = VERR_NO_STR_MEMORY;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync RTMemFree(pDbgInfoMod);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync return rc;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync}
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnTryOpen} */
d1e9999d55e7ac80a28692c161710be98071fc00vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_TryOpen(PRTDBGMODINT pMod, RTLDRARCH enmArch)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync{
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * DWARF is only supported when part of an image.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync if (!pMod->pImgVt)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync return VERR_DBG_NO_MATCHING_INTERPRETER;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync * Create the module instance data.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)RTMemAllocZ(sizeof(*pThis));
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync if (!pThis)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync return VERR_NO_MEMORY;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pThis->pDbgInfoMod = pMod;
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pThis->pImgMod = pMod;
725fba5c64717677ac66072bae37e5b3686f3e6dvboxsync RTListInit(&pThis->CompileUnitList);
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync /*
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync * If the debug file name is set, let's see if it's an ELF image with DWARF
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync * inside it. In that case we'll have to deal with two image modules, one
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync * for segments and address translation and one for the debug information.
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync */
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync if (pMod->pszDbgFile != NULL)
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync rtDbgModDwarfTryOpenDbgFile(pMod, pThis, enmArch);
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync /*
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync * Enumerate the debug info in the module, looking for DWARF bits.
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync */
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync int rc = pThis->pDbgInfoMod->pImgVt->pfnEnumDbgInfo(pThis->pDbgInfoMod, rtDbgModDwarfEnumCallback, pThis);
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync if (RT_SUCCESS(rc))
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync {
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (pThis->aSections[krtDbgModDwarfSect_info].fPresent)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync {
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /*
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Extract / explode the data we want (symbols and line numbers)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * storing them in a container module.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync rc = RTDbgModCreate(&pThis->hCnt, pMod->pszName, 0 /*cbSeg*/, 0 /*fFlags*/);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (RT_SUCCESS(rc))
5b0a093ca572a855886faa6747ad46df859dd041vboxsync {
d3dea25ec07f6546715fe3af943ea863294b392evboxsync pMod->pvDbgPriv = pThis;
d3dea25ec07f6546715fe3af943ea863294b392evboxsync
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync rc = rtDbgModDwarfAddSegmentsFromImage(pThis);
d3dea25ec07f6546715fe3af943ea863294b392evboxsync if (RT_SUCCESS(rc))
ad66a27959d7085aa31760f63ce082943be60e89vboxsync rc = rtDwarfInfo_LoadAll(pThis);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (RT_SUCCESS(rc))
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync rc = rtDwarfLine_ExplodeAll(pThis);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (RT_SUCCESS(rc) && pThis->iWatcomPass == 1)
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync {
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = rtDbgModDwarfAddSegmentsFromPass1(pThis);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync pThis->iWatcomPass = 2;
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (RT_SUCCESS(rc))
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = rtDwarfInfo_LoadAll(pThis);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync if (RT_SUCCESS(rc))
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync rc = rtDwarfLine_ExplodeAll(pThis);
4b8c66482cbc69a01ac399b8588b8bc80b310523vboxsync }
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (RT_SUCCESS(rc))
5b0a093ca572a855886faa6747ad46df859dd041vboxsync {
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Free the cached abbreviations and unload all sections.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pThis->cCachedAbbrevs = pThis->cCachedAbbrevsAlloced = 0;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync RTMemFree(pThis->paCachedAbbrevs);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync for (unsigned iSect = 0; iSect < RT_ELEMENTS(pThis->aSections); iSect++)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (pThis->aSections[iSect].pv)
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync pThis->pDbgInfoMod->pImgVt->pfnUnmapPart(pThis->pDbgInfoMod, pThis->aSections[iSect].cb,
d1e9999d55e7ac80a28692c161710be98071fc00vboxsync &pThis->aSections[iSect].pv);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return VINF_SUCCESS;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync }
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /* bail out. */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync RTDbgModRelease(pThis->hCnt);
d3dea25ec07f6546715fe3af943ea863294b392evboxsync pMod->pvDbgPriv = NULL;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync }
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync }
5b0a093ca572a855886faa6747ad46df859dd041vboxsync else
5b0a093ca572a855886faa6747ad46df859dd041vboxsync rc = VERR_DBG_NO_MATCHING_INTERPRETER;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync }
ad66a27959d7085aa31760f63ce082943be60e89vboxsync RTMemFree(pThis->paCachedAbbrevs);
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync RTMemFree(pThis);
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync return rc;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync}
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** Virtual function table for the DWARF debug info reader. */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsyncDECL_HIDDEN_CONST(RTDBGMODVTDBG) const g_rtDbgModVtDbgDwarf =
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync{
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.u32Magic = */ RTDBGMODVTDBG_MAGIC,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.fSupports = */ RT_DBGTYPE_DWARF,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pszName = */ "dwarf",
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnTryOpen = */ rtDbgModDwarf_TryOpen,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnClose = */ rtDbgModDwarf_Close,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnRvaToSegOff = */ rtDbgModDwarf_RvaToSegOff,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnImageSize = */ rtDbgModDwarf_ImageSize,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSegmentAdd = */ rtDbgModDwarf_SegmentAdd,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSegmentCount = */ rtDbgModDwarf_SegmentCount,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSegmentByIndex = */ rtDbgModDwarf_SegmentByIndex,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSymbolAdd = */ rtDbgModDwarf_SymbolAdd,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSymbolCount = */ rtDbgModDwarf_SymbolCount,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSymbolByOrdinal = */ rtDbgModDwarf_SymbolByOrdinal,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSymbolByName = */ rtDbgModDwarf_SymbolByName,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnSymbolByAddr = */ rtDbgModDwarf_SymbolByAddr,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnLineAdd = */ rtDbgModDwarf_LineAdd,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnLineCount = */ rtDbgModDwarf_LineCount,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnLineByOrdinal = */ rtDbgModDwarf_LineByOrdinal,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.pfnLineByAddr = */ rtDbgModDwarf_LineByAddr,
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*.u32EndMagic = */ RTDBGMODVTDBG_MAGIC
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync};
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync