dbgmoddwarf.cpp revision c553cea6bfe2ce63ff5517ca4ec288502a890e99
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/* $Id$ */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** @file
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * IPRT - Debug Info Reader For DWARF.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/*
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * Copyright (C) 2011 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>
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync#include <iprt/log.h>
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#include <iprt/mem.h>
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#include <iprt/path.h>
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#include <iprt/string.h>
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync#include "internal/dbgmod.h"
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/*******************************************************************************
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync* Defined Constants And Macros *
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync*******************************************************************************/
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync/** @name Standard DWARF Line Number Opcodes
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @{ */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_extended UINT8_C(0)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_copy UINT8_C(1)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_advance_pc UINT8_C(2)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_advance_line UINT8_C(3)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_set_file UINT8_C(4)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_set_column UINT8_C(5)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_negate_stmt UINT8_C(6)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_set_basic_block UINT8_C(7)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_const_add_pc UINT8_C(8)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_fixed_advance_pc UINT8_C(9)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_set_prologue_end UINT8_C(10)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_set_epilogue_begin UINT8_C(11)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync#define DW_LNS_set_isa UINT8_C(12)
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
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/*******************************************************************************
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync* Structures and Typedefs *
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync*******************************************************************************/
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
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;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /** Pointer to back to the debug info module (no reference ofc). */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync PRTDBGMODINT pMod;
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;
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. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync PRTDWARFABBREV paCachedAbbrevs;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /** Used by rtDwarfAbbrev_Lookup when the result is uncachable. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync RTDWARFABBREV LookupAbbrev;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync} RTDBGMODDWARF;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** Pointer to instance data of the DWARF reader. */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsynctypedef RTDBGMODDWARF *PRTDBGMODDWARF;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * DWARF cursor for reading byte data.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync */
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsynctypedef struct RTDWARFSECTRDR
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;
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync/** Pointer to a DWARF section reader. */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsynctypedef RTDWARFCURSOR *PRTDWARFCURSOR;
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;
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
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @callback_method_impl{FNRTLDRENUMSEGS} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModHlpAddSegmentCallback(RTLDRMOD hLdrMod, PCRTLDRSEG pSeg, void *pvUser)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODINT pMod = (PRTDBGMODINT)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));
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync RTLDRADDR cb = RT_MAX(pSeg->cb, pSeg->cbMapped);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync#if 1
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return pMod->pDbgVt->pfnSegmentAdd(pMod, pSeg->RVA, cb, pSeg->pchName, pSeg->cchName, 0 /*fFlags*/, NULL);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync#else
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return pMod->pDbgVt->pfnSegmentAdd(pMod, pSeg->LinkAddress, cb, pSeg->pchName, pSeg->cchName, 0 /*fFlags*/, NULL);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync#endif
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/**
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * Calls pfnSegmentAdd for each segment in the executable image.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync *
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @returns IPRT status code.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync * @param pMod The debug module.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncDECLHIDDEN(int) rtDbgModHlpAddSegmentsFromImage(PRTDBGMODINT pMod)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync AssertReturn(pMod->pImgVt, VERR_INTERNAL_ERROR_2);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return pMod->pImgVt->pfnEnumSegments(pMod, rtDbgModHlpAddSegmentCallback, pMod);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
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 */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return pThis->pMod->pImgVt->pfnMapPart(pThis->pMod, pThis->aSections[enmSect].offFile, pThis->aSections[enmSect].cb,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync &pThis->aSections[enmSect].pv);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync}
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
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
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync int rc = pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[enmSect].cb, &pThis->aSections[enmSect].pv);
d3dea25ec07f6546715fe3af943ea863294b392evboxsync AssertRC(rc);
d3dea25ec07f6546715fe3af943ea863294b392evboxsync return rc;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync}
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{
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.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param LinkAddress The address to convert..
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param piSeg The segment index.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * @param poffSeg Where to return the segment offset.
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsyncstatic int rtDbgModDwarfLinkAddressToSegOffset(PRTDBGMODDWARF pThis, uint64_t LinkAddress,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGSEGIDX piSeg, PRTLDRADDR poffSeg)
b26e5b503baa3dffc58048982eaf17ad1b53f207vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return pThis->pMod->pImgVt->pfnLinkAddressToSegOffset(pThis->pMod, 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{
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
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
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{
ad66a27959d7085aa31760f63ce082943be60e89vboxsync size_t off = (uint8_t const *)pCursor->pDwarfMod->aSections[pCursor->enmSect].pv - pCursor->pb;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync uint32_t offRet = (uint32_t)off;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (offRet != off)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync {
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 {
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)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync return pCursor->rc = VERR_DWARF_BAD_POS;
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)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return VERR_DWARF_BAD_POS;
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
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.
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic int rtDwarfLine_AddLine(PRTDWARFLINESTATE pLnState)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync const char *pszFile = pLnState->Regs.iFile < pLnState->cFileNames
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync ? pLnState->papszFileNames[pLnState->Regs.iFile]
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync : "<bad file name index>";
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync RTDBGSEGIDX iSeg;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync RTUINTPTR offSeg;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync int rc = rtDbgModDwarfLinkAddressToSegOffset(pLnState->pDwarfMod, pLnState->Regs.uAddress, &iSeg, &offSeg);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync if (RT_SUCCESS(rc))
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync {
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync Log2(("rtDwarfLine_AddLine: %x:%08llx (%#llx) %s(%d)\n", iSeg, offSeg, pLnState->Regs.uAddress, pszFile, pLnState->Regs.uLine));
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync rc = RTDbgModLineAdd(pLnState->pDwarfMod->hCnt, pszFile, pLnState->Regs.uLine, iSeg, offSeg, NULL);
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync /* Ignore address conflicts for now. */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync if (rc == VERR_DBG_ADDRESS_CONFLICT)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync rc = VINF_SUCCESS;
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;
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 {
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint8_t bOpCode = rtDwarfCursor_GetUByte(pCursor, DW_LNS_extended);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync 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
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync uint64_t uTmp = bOpCode + pLnState->Regs.idxOp + bOpCode;
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;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW Special Opcode %#04x: uLine + %d => %u; uAddress + %#llx => %#llx; idxOp + %#llx => %#llx\n",
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync bLogOpCode, cLineDelta, pLnState->Regs.uLine, cAddressDelta, pLnState->Regs.uAddress,
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync cOpIndexDelta, pLnState->Regs.idxOp));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync rc = rtDwarfLine_AddLine(pLnState);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync else
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync switch (bOpCode)
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync /*
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync * Standard opcode.
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync */
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_copy:
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_copy\n"));
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync rc = rtDwarfLine_AddLine(pLnState);
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;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_advance_pc\n"));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_advance_line:
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync {
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync int32_t cLineDelta = rtDwarfCursor_GetSLeb128AsS32(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.uLine += cLineDelta;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_advance_line: uLine + %d => %u\n", cLineDelta, pLnState->Regs.uLine));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync }
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_set_file:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.iFile = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_set_file: iFile=%u\n", pLnState->Regs.iFile));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_set_column:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uColumn = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_set_column\n"));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_negate_stmt:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fIsStatement = !pLnState->Regs.fIsStatement;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_negate_stmt\n"));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_set_basic_block:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fBasicBlock = true;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_set_basic_block\n"));
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;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_const_add_pc\n"));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_fixed_advance_pc:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uAddress += rtDwarfCursor_GetUHalf(pCursor, 0);
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.idxOp = 0;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_fixed_advance_pc\n"));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_set_prologue_end:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fPrologueEnd = true;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_set_prologue_end\n"));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_set_epilogue_begin:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.fEpilogueBegin = true;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_set_epilogue_begin\n"));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNS_set_isa:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync pLnState->Regs.uIsa = rtDwarfCursor_GetULeb128AsU32(pCursor, 0);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNS_set_isa %#x\n", pLnState->Regs.uIsa));
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync break;
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync default:
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync {
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync unsigned cOpsToSkip = pLnState->Hdr.pacStdOperands[bOpCode - 1];
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("rtDwarfLine_RunProgram: Unknown standard opcode %#x, %#x operands\n", bOpCode, cOpsToSkip));
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;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync rc = rtDwarfLine_AddLine(pLnState);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync#endif
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rtDwarfLine_ResetState(pLnState);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNE_end_sequence\n"));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNE_set_address:
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync switch (cbInstr - 1)
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync {
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync case 2: pLnState->Regs.uAddress = rtDwarfCursor_GetU16(pCursor, UINT16_MAX); break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync case 4: pLnState->Regs.uAddress = rtDwarfCursor_GetU32(pCursor, UINT32_MAX); break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync case 8: pLnState->Regs.uAddress = rtDwarfCursor_GetU64(pCursor, UINT64_MAX); break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync default:
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync AssertMsgFailed(("%d\n", cbInstr));
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pLnState->Regs.uAddress = rtDwarfCursor_GetNativeUOff(pCursor, UINT64_MAX);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync }
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.idxOp = 0;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNE_set_address: %#llx\n", 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 */
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNE_define_file: {%d}/%s\n", idxInc, pszFilename));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rc = rtDwarfCursor_AdvanceToPos(pCursor, pbEndOfInstr);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync if (RT_SUCCESS(rc))
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync rc = rtDwarfLine_DefineFileName(pLnState, pszFilename, idxInc);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync }
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
71e045383a3316b27563b2f44b0e0e1231968bdcvboxsync case DW_LNE_set_descriminator:
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync pLnState->Regs.uDiscriminator = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("DW_LNE_set_descriminator: %u\n", pLnState->Regs.uDiscriminator));
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync break;
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync default:
5a5b5956f8b592c807c94785d58c25e717d430c4vboxsync Log2(("rtDwarfLine_RunProgram: Unknown extended opcode %#x, length %#x\n", bOpCode, cbInstr));
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? */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync 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);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync } while (uAttr != 0 && uForm != 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);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync } while (uAttr != 0 && uForm != 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
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/*
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync *
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * DWARF DIE stack (used by the debug_info parser).
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * DWARF DIE stack (used by the debug_info parser).
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * DWARF DIE stack (used by the debug_info parser).
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync *
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/**
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * DWARF DIE stack entry.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsynctypedef struct RTDWARFDIESTACKENTRY
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** The abbreviation code. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync uint32_t uAbbrCode;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** The tag. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync uint16_t uTag;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** The offset into the debug_info section of the data. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync uint32_t offData;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** The associated name. (Points into some dwarf section.) */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync const char *pszName;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync} RTDWARFDIESTACKENTRY;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Pointer to a DIE stack entry. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsynctypedef RTDWARFDIESTACKENTRY *PRTDWARFDIESTACKENTRY;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/**
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * DWARF DIE stack.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsynctypedef struct RTDWARFDIESTACK
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** The number of items on the stack. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync uint32_t cOnStack;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** The number of stack entries we've allocated. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync uint32_t cAlloced;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /** Pointer to the stack entries. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync PRTDWARFDIESTACKENTRY paEntries;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync} RTDWARFDIESTACK;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Pointer to a DIE stack. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsynctypedef RTDWARFDIESTACK *PRTDWARFDIESTACK;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/** Pointer to a const DIE stack. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsynctypedef RTDWARFDIESTACK const *PCRTDWARFDIESTACK;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic int rtDwarfDieStack_SetName(PRTDWARFDIESTACK pStack, const char *pszName)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync uint32_t i = pStack->cOnStack;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (i == 0)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return VERR_DWARF_BAD_INFO;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync i--;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->paEntries[i].pszName = pszName;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return VINF_SUCCESS;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic int rtDwarfDieStack_Push(PRTDWARFDIESTACK pStack, uint32_t uAbbrCode, uint16_t uTag, uint32_t offData)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync uint32_t i = pStack->cOnStack;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (i == pStack->cAlloced)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync {
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync size_t cNewSize = pStack->cAlloced ? pStack->cAlloced * 2 : 1 /*16*/;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync void *pv = RTMemRealloc(pStack->paEntries, sizeof(pStack->paEntries[0]) * cNewSize);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (!pv)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return VERR_NO_MEMORY;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->paEntries = (PRTDWARFDIESTACKENTRY)pv;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->cAlloced = cNewSize;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync }
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync Assert(i < pStack->cAlloced);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->paEntries[i].uAbbrCode = uAbbrCode;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->paEntries[i].uTag = uTag;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->paEntries[i].offData = offData;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->paEntries[i].pszName = NULL;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->cOnStack = i + 1;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return VINF_SUCCESS;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic int rtDwarfDieStack_Pop(PRTDWARFDIESTACK pStack)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (pStack->cOnStack == 0)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return VERR_DWARF_BAD_INFO;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->cOnStack--;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return VINF_SUCCESS;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic void rtDwarfDieStack_Init(PRTDWARFDIESTACK pStack)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->cOnStack = 0;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->cAlloced = 0;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->paEntries = NULL;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic void rtDwarfDieStack_Delete(PRTDWARFDIESTACK pStack)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync RTMemFree(pStack->paEntries);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync pStack->paEntries = NULL;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync/*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync *
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * DWARF debug_info parser
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * DWARF debug_info parser
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * DWARF debug_info parser
ad66a27959d7085aa31760f63ce082943be60e89vboxsync *
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync/**
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * Parse a DIE.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync *
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @returns IPRT status code.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pThis The DWARF instance.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pCursor The debug_info cursor.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pAbbrev The abbreviation entry.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pAbbrevCursor The abbreviation cursor.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * @param pStack The DIE stack.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsyncstatic int rtDwarfInfo_ParseDie(PRTDBGMODDWARF pThis, PRTDWARFCURSOR pCursor,
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync PCRTDWARFABBREV pAbbrev, PRTDWARFCURSOR pAbbrevCursor,
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync PRTDWARFDIESTACK pStack)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync{
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return VERR_NOT_IMPLEMENTED;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync}
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsyncstatic int rtDwarfInfo_LoadUnit(PRTDBGMODDWARF pThis, PRTDWARFCURSOR pCursor)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync{
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Read the compilation unit header.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync rtDwarfCursor_GetInitalLength(pCursor);
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;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Set up the abbreviation cache and store the native address size in the cursor.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (offAbbrev > UINT32_MAX)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync return VERR_DWARF_BAD_INFO;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync rtDwarfAbbrev_SetUnitOffset(pThis, offAbbrev);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pCursor->cbNativeAddr = cbNativeAddr;
d3dea25ec07f6546715fe3af943ea863294b392evboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /*
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * We want a DIE stack as well.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync RTDWARFDIESTACK Stack;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rtDwarfDieStack_Init(&Stack);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync /*
ad66a27959d7085aa31760f63ce082943be60e89vboxsync * Parse DIEs.
ad66a27959d7085aa31760f63ce082943be60e89vboxsync */
ad66a27959d7085aa31760f63ce082943be60e89vboxsync int rc = VINF_SUCCESS;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync while (!rtDwarfCursor_IsAtEndOfUnit(pCursor))
d3dea25ec07f6546715fe3af943ea863294b392evboxsync {
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync uint32_t uAbbrCode = rtDwarfCursor_GetULeb128AsU32(pCursor, UINT32_MAX);
d3dea25ec07f6546715fe3af943ea863294b392evboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (!uAbbrCode)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync {
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /* End of siblings, pop the stack. */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rc = rtDwarfDieStack_Pop(&Stack);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (RT_FAILURE(rc))
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync break;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync }
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync else
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync {
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /*
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * Look up the abbreviation.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync PCRTDWARFABBREV pAbbrev = rtDwarfAbbrev_Lookup(pThis, uAbbrCode);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (!pAbbrev)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync {
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rc = VERR_DWARF_ABBREV_NOT_FOUND;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync break;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync }
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /*
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * If this DIE has children, push it onto the stack.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (pAbbrev->fChildren)
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync {
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rc = rtDwarfDieStack_Push(&Stack, uAbbrCode, pAbbrev->uTag, rtDwarfCursor_CalcSectOffsetU32(pCursor));
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (RT_FAILURE(rc))
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync break;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync }
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync /*
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync * Parse it.
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync */
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync RTDWARFCURSOR AbbrevCursor;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rc = rtDwarfCursor_InitWithOffset(&AbbrevCursor, pThis, krtDbgModDwarfSect_abbrev, pAbbrev->offSpec);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (RT_SUCCESS(rc))
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync {
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rc = rtDwarfInfo_ParseDie(pThis, pCursor, pAbbrev, &AbbrevCursor, &Stack);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rc = rtDwarfCursor_Delete(&AbbrevCursor, rc);
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync }
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync if (RT_FAILURE(rc))
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync break;
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync }
d3dea25ec07f6546715fe3af943ea863294b392evboxsync }
d3dea25ec07f6546715fe3af943ea863294b392evboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync rtDwarfDieStack_Delete(&Stack);
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);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync if (RT_FAILURE(rc))
1b1592b7ed076977cda6d2b1fae320626609b836vboxsync return rc;
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
ad66a27959d7085aa31760f63ce082943be60e89vboxsync while ( !rtDwarfCursor_IsAtEnd(&Cursor)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync && RT_SUCCESS(rc))
ad66a27959d7085aa31760f63ce082943be60e89vboxsync rc = rtDwarfInfo_LoadUnit(pThis, &Cursor);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync
c553cea6bfe2ce63ff5517ca4ec288502a890e99vboxsync return rtDwarfCursor_Delete(&Cursor, 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;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModLineAdd(pThis->hCnt, pszFile, uLineNo, iSeg, off, piOrdinal);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync}
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByAddr} */
4bf996d915405be92dc4394b2db1395e00e14d58vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_SymbolByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync{
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return RTDbgModSymbolByAddr(pThis->hCnt, iSeg, off, 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;
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;
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);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync RTUINTPTR cb2 = pMod->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)
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[iSect].cb, &pThis->aSections[iSect].pv);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync RTDbgModRelease(pThis->hCnt);
ad66a27959d7085aa31760f63ce082943be60e89vboxsync RTMemFree(pThis->paCachedAbbrevs);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync RTMemFree(pThis);
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync return VINF_SUCCESS;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync}
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** @callback_method_impl{FNRTLDRENUMDBG} */
5b0a093ca572a855886faa6747ad46df859dd041vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarfEnumCallback(RTLDRMOD hLdrMod, uint32_t iDbgInfo, RTLDRDBGINFOTYPE enmType,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync uint16_t iMajorVer, uint16_t iMinorVer, const char *pszPartNm,
d3dea25ec07f6546715fe3af943ea863294b392evboxsync RTFOFF offFile, RTLDRADDR LinkAddress, RTLDRADDR cb,
5b0a093ca572a855886faa6747ad46df859dd041vboxsync const char *pszExtFile, void *pvUser)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync{
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync /*
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync * Skip stuff we can't handle.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync if ( enmType != RTLDRDBGINFOTYPE_DWARF
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync || !pszPartNm
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync || pszExtFile)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync return VINF_SUCCESS;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /*
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Must have a part name starting with debug_ and possibly prefixed by dots
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * or underscores.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
d3dea25ec07f6546715fe3af943ea863294b392evboxsync if (!strncmp(pszPartNm, ".debug_", sizeof(".debug_") - 1)) /* ELF */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync pszPartNm += sizeof(".debug_") - 1;
d3dea25ec07f6546715fe3af943ea863294b392evboxsync else if (!strncmp(pszPartNm, "__debug_", sizeof("__debug_") - 1)) /* Mach-O */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync pszPartNm += sizeof("__debug_") - 1;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync else
5b0a093ca572a855886faa6747ad46df859dd041vboxsync AssertMsgFailedReturn(("%s\n", pszPartNm), VINF_SUCCESS /*ignore*/);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /*
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Figure out which part we're talking about.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
5b0a093ca572a855886faa6747ad46df859dd041vboxsync krtDbgModDwarfSect enmSect;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (0) { /* dummy */ }
5b0a093ca572a855886faa6747ad46df859dd041vboxsync#define ELSE_IF_STRCMP_SET(a_Name) else if (!strcmp(pszPartNm, #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 {
5b0a093ca572a855886faa6747ad46df859dd041vboxsync AssertMsgFailed(("%s\n", pszPartNm));
5b0a093ca572a855886faa6747ad46df859dd041vboxsync return VINF_SUCCESS;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync }
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync /*
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Record the section.
5b0a093ca572a855886faa6747ad46df859dd041vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pvUser;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync AssertMsgReturn(!pThis->aSections[enmSect].fPresent, ("duplicate %s\n", pszPartNm), VINF_SUCCESS /*ignore*/);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync pThis->aSections[enmSect].fPresent = true;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync pThis->aSections[enmSect].offFile = offFile;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync pThis->aSections[enmSect].pv = NULL;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync pThis->aSections[enmSect].cb = (size_t)cb;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (pThis->aSections[enmSect].cb != cb)
5b0a093ca572a855886faa6747ad46df859dd041vboxsync pThis->aSections[enmSect].cb = ~(size_t)0;
5b0a093ca572a855886faa6747ad46df859dd041vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync return VINF_SUCCESS;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync}
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync/** @interface_method_impl{RTDBGMODVTDBG,pfnTryOpen} */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsyncstatic DECLCALLBACK(int) rtDbgModDwarf_TryOpen(PRTDBGMODINT pMod)
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 /*
5b0a093ca572a855886faa6747ad46df859dd041vboxsync * Enumerate the debug info in the module, looking for DWARF bits.
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync */
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)RTMemAllocZ(sizeof(*pThis));
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync if (!pThis)
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync return VERR_NO_MEMORY;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync pThis->pMod = pMod;
c58c758d3642ac45d3f12356c406c631fcd8f538vboxsync
5b0a093ca572a855886faa6747ad46df859dd041vboxsync int rc = pMod->pImgVt->pfnEnumDbgInfo(pMod, 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
d3dea25ec07f6546715fe3af943ea863294b392evboxsync rc = rtDbgModHlpAddSegmentsFromImage(pMod);
d3dea25ec07f6546715fe3af943ea863294b392evboxsync if (RT_SUCCESS(rc))
ad66a27959d7085aa31760f63ce082943be60e89vboxsync rc = rtDwarfInfo_LoadAll(pThis);
5b0a093ca572a855886faa6747ad46df859dd041vboxsync if (RT_SUCCESS(rc))
4bf996d915405be92dc4394b2db1395e00e14d58vboxsync rc = rtDwarfLine_ExplodeAll(pThis);
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)
ad66a27959d7085aa31760f63ce082943be60e89vboxsync pThis->pMod->pImgVt->pfnUnmapPart(pThis->pMod, pThis->aSections[iSect].cb,
ad66a27959d7085aa31760f63ce082943be60e89vboxsync &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