15d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj/* -*- mode: C; c-basic-offset: 3; -*- */ 2b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--------------------------------------------------------------------*/ 4fba428cd266b8a39db641c5fd9523daa8939bed0tom/*--- Read DWARF3/4 ".debug_info" sections (DIE trees). ---*/ 5b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- readdwarf3.c ---*/ 6b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--------------------------------------------------------------------*/ 7b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 8b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* 9b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj This file is part of Valgrind, a dynamic binary instrumentation 10b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj framework. 11b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 12b3a1e4bffbdbbf38304f216af405009868f43628sewardj Copyright (C) 2008-2015 OpenWorks LLP 13b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj info@open-works.co.uk 14b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 15b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj This program is free software; you can redistribute it and/or 16b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj modify it under the terms of the GNU General Public License as 17b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj published by the Free Software Foundation; either version 2 of the 18b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj License, or (at your option) any later version. 19b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 20b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj This program is distributed in the hope that it will be useful, but 21b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj WITHOUT ANY WARRANTY; without even the implied warranty of 22b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj General Public License for more details. 24b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 25b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj You should have received a copy of the GNU General Public License 26b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj along with this program; if not, write to the Free Software 27b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 28b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 02111-1307, USA. 29b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 30b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj The GNU General Public License is contained in the file COPYING. 31b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 32b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Neither the names of the U.S. Department of Energy nor the 33b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj University of California nor the names of its contributors may be 34b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj used to endorse or promote products derived from this software 35b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj without prior written permission. 36b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj*/ 37b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 388eb8bab992e3998c33770b0cdb16059a8b918a06sewardj#if defined(VGO_linux) || defined(VGO_darwin) || defined(VGO_solaris) 398b68b64759254d514d98328c496cbd88cde4c9a5njn 40b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* REFERENCE (without which this code will not make much sense): 41b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 42b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DWARF Debugging Information Format, Version 3, 43b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj dated 20 December 2005 (the "D3 spec"). 44b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 45b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Available at http://www.dwarfstd.org/Dwarf3.pdf. There's also a 46b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj .doc (MS Word) version, but for some reason the section numbers 47b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj between the Word and PDF versions differ by 1 in the first digit. 48b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj All section references in this code are to the PDF version. 49b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 50b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj CURRENT HACKS: 51b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 52b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_TAG_{const,volatile}_type no DW_AT_type is allowed; it is 53b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj assumed to mean "const void" or "volatile void" respectively. 54b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj GDB appears to interpret them like this, anyway. 55b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 56b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj In many cases it is important to know the svma of a CU (the "base 57b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj address of the CU", as the D3 spec calls it). There are some 58b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj situations in which the spec implies this value is unknown, but the 59b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Dwarf3 produced by gcc-4.1 seems to assume is not unknown but 60b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj merely zero when not explicitly stated. So we too have to make 61b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj that assumption. 62b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 639c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj POTENTIAL BUG? Spotted 6 Sept 08. Why doesn't 649c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj unitary_range_list() bias the resulting range list in the same way 659c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj that its more general cousin, get_range_list(), does? I don't 669c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj know. 679c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 68b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TODO, 2008 Feb 17: 69b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 70b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj get rid of cu_svma_known and document the assumed-zero svma hack. 71b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 72b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ML_(sizeOfType): differentiate between zero sized types and types 73b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj for which the size is unknown. Is this important? I don't know. 74b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 75a2af13d238de6b212f1d69e7b316538f37a7abbasewardj DW_TAG_array_types: deal with explicit sizes (currently we compute 76b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj the size from the bounds and the element size, although that's 77b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj fragile, if the bounds incompletely specified, or completely 78b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj absent) 79b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 80b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Document reason for difference (by 1) of stack preening depth in 81b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parse_var_DIE vs parse_type_DIE. 82b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 83b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Don't hand to ML_(addVars), vars whose locations are entirely in 84b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj registers (DW_OP_reg*). This is merely a space-saving 85b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj optimisation, as ML_(evaluate_Dwarf3_Expr) should handle these 86b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj expressions correctly, by failing to evaluate them and hence 87b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj effectively ignoring the variable with which they are associated. 88b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 89a2af13d238de6b212f1d69e7b316538f37a7abbasewardj Deal with DW_TAG_array_types which have element size != stride 90b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 91b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj In some cases, the info for a variable is split between two 92b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj different DIEs (generally a declarer and a definer). We punt on 93b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj these. Could do better here. 94b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 95b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj The 'data_bias' argument passed to the expression evaluator 96b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (ML_(evaluate_Dwarf3_Expr)) should really be changed to a 97b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj MaybeUWord, to make it clear when we do vs don't know what it is 98b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj for the evaluation of an expression. At the moment zero is passed 99b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj for this parameter in the don't know case. That's a bit fragile 100b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj and obscure; using a MaybeUWord would be clearer. 101b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 102b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj POTENTIAL PERFORMANCE IMPROVEMENTS: 103b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1049c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Currently, duplicate removal and all other queries for the type 1059c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj entities array is done using cuOffset-based pointing, which 1069c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj involves a binary search (VG_(lookupXA)) for each access. This is 1079c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj wildly inefficient, although simple. It would be better to 1089c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj translate all the cuOffset-based references (iow, all the "R" and 1099c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj "Rs" fields in the TyEnts in 'tyents') to direct index numbers in 1109c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 'tyents' right at the start of dedup_types(), and use direct 1119c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj indexing (VG_(indexXA)) wherever possible after that. 1129c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 1139c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj cmp__XArrays_of_AddrRange is also a performance bottleneck. Move 1149c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(indexXA) into pub_tool_xarray.h so it can be inlined at all use 1159c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj points, and possibly also make an _UNCHECKED version which skips 1169c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj the range checks in performance-critical situations such as this. 117b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 118b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Handle interaction between read_DIE and parse_{var,type}_DIE 119b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj better. Currently read_DIE reads the entire DIE just to find where 120b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj the end is (and for debug printing), so that it can later reliably 121b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj move the cursor to the end regardless of what parse_{var,type}_DIE 122b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj do. This means many DIEs (most, even?) are read twice. It would 123b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj be smarter to make parse_{var,type}_DIE return a Bool indicating 124b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj whether or not they advanced the DIE cursor, and only if they 125b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj didn't should read_DIE itself read through the DIE. 126b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 127b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ML_(addVar) and add_var_to_arange: quite a lot of DiAddrRanges have 128b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj zero variables in their .vars XArray. Rather than have an XArray 129b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj with zero elements (which uses 2 malloc'd blocks), allow the .vars 130b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj pointer to be NULL in this case. 131b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 132b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj More generally, reduce the amount of memory allocated and freed 133b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while reading Dwarf3 type/variable information. Even modest (20MB) 134b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj objects cause this module to allocate and free hundreds of 135b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj thousands of small blocks, and ML_(arena_malloc) and its various 136b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj groupies always show up at the top of performance profiles. */ 137b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 138b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#include "pub_core_basics.h" 139588658b13b5ad77672f323d48fe9da0ca60b0bcbtom#include "pub_core_debuginfo.h" 140b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#include "pub_core_libcbase.h" 141b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#include "pub_core_libcassert.h" 142b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#include "pub_core_libcprint.h" 1436c591e15c1d6402a2a755310f005f795b68e7e38sewardj#include "pub_core_libcsetjmp.h" // setjmp facilities 144d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj#include "pub_core_hashtable.h" 145b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#include "pub_core_options.h" 146f76d27a697a7b0bf3b84490baf60623fc96a23afnjn#include "pub_core_tooliface.h" /* VG_(needs) */ 147b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#include "pub_core_xarray.h" 1489c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj#include "pub_core_wordfm.h" 149b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#include "priv_misc.h" /* dinfo_zalloc/free */ 1505d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj#include "priv_image.h" 151b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#include "priv_tytypes.h" 152b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#include "priv_d3basics.h" 153b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#include "priv_storage.h" 154b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#include "priv_readdwarf3.h" /* self */ 155b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 156b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 157b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 158b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 159b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- Basic machinery for parsing DIEs. ---*/ 160b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 161b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 162b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 163b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#define TRACE_D3(format, args...) \ 164a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (UNLIKELY(td3)) { VG_(printf)(format, ## args); } 165e0bd5910153720d5d15697db8063d0d4caa59d8fphilippe#define TD3 (UNLIKELY(td3)) 166b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1679c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj#define D3_INVALID_CUOFF ((UWord)(-1UL)) 1689c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj#define D3_FAKEVOID_CUOFF ((UWord)(-2UL)) 169b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 170b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjtypedef 171b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj struct { 1725d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice sli; // to which this cursor applies 1735d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiOffT sli_next; // offset in underlying DiImage; must be >= sli.ioff 1746bd9dc18c043927c1196caba20a327238a179c42florian void (*barf)( const HChar* ) __attribute__((noreturn)); 1756bd9dc18c043927c1196caba20a327238a179c42florian const HChar* barfstr; 176b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 177b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Cursor; 178b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 179518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic inline Bool is_sane_Cursor ( const Cursor* c ) { 180b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (!c) return False; 181b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (!c->barf) return False; 182b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (!c->barfstr) return False; 1835d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (!ML_(sli_is_valid)(c->sli)) return False; 1845d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (c->sli.ioff == DiOffT_INVALID) return False; 1855d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (c->sli_next < c->sli.ioff) return False; 186b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return True; 187b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 188b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1895d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj// Initialise a cursor from a DiSlice (ELF section, really) so as to 1905d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj// start reading at offset |sli_initial_offset| from the start of the 1915d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj// slice. 1925d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardjstatic void init_Cursor ( /*OUT*/Cursor* c, 1935d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice sli, 1945d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong sli_initial_offset, 1955d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj __attribute__((noreturn)) void (*barf)(const HChar*), 1966bd9dc18c043927c1196caba20a327238a179c42florian const HChar* barfstr ) 197b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 198b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(c); 1995d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj VG_(bzero_inline)(c, sizeof(*c)); 2005d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj c->sli = sli; 2015d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj c->sli_next = c->sli.ioff + sli_initial_offset; 202b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj c->barf = barf; 203b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj c->barfstr = barfstr; 204b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(is_sane_Cursor(c)); 205b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 206b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 207518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic Bool is_at_end_Cursor ( const Cursor* c ) { 208b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(is_sane_Cursor(c)); 2095d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj return c->sli_next >= c->sli.ioff + c->sli.szB; 210b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 211b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 212518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic inline ULong get_position_of_Cursor ( const Cursor* c ) { 213b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(is_sane_Cursor(c)); 2145d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj return c->sli_next - c->sli.ioff; 215b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 2165d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardjstatic inline void set_position_of_Cursor ( Cursor* c, ULong pos ) { 2175d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj c->sli_next = c->sli.ioff + pos; 218b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(is_sane_Cursor(c)); 219b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 220e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippestatic inline void advance_position_of_Cursor ( Cursor* c, ULong delta ) { 221e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe c->sli_next += delta; 222e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe vg_assert(is_sane_Cursor(c)); 223e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe} 224b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 225518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic /*signed*/Long get_remaining_length_Cursor ( const Cursor* c ) { 226b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(is_sane_Cursor(c)); 2275d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj return c->sli.ioff + c->sli.szB - c->sli_next; 228b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 229b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2305d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj//static void* get_address_of_Cursor ( Cursor* c ) { 2315d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj// vg_assert(is_sane_Cursor(c)); 2325d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj// return &c->region_start_img[ c->region_next ]; 2335d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj//} 2345d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj 2353297124fa2116737066ac3cd709f18fdd5405163florianstatic DiCursor get_DiCursor_from_Cursor ( const Cursor* c ) { 2365d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj return mk_DiCursor(c->sli.img, c->sli_next); 237b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 238b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 239b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* FIXME: document assumptions on endianness for 240b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj get_UShort/UInt/ULong. */ 241b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic inline UChar get_UChar ( Cursor* c ) { 242b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar r; 2435d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj vg_assert(is_sane_Cursor(c)); 2445d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (c->sli_next + sizeof(UChar) > c->sli.ioff + c->sli.szB) { 245b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj c->barf(c->barfstr); 246b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*NOTREACHED*/ 247b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(0); 248b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2495d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj r = ML_(img_get_UChar)(c->sli.img, c->sli_next); 2505d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj c->sli_next += sizeof(UChar); 251b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return r; 252b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 253b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic UShort get_UShort ( Cursor* c ) { 254b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UShort r; 255b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(is_sane_Cursor(c)); 2565d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (c->sli_next + sizeof(UShort) > c->sli.ioff + c->sli.szB) { 257b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj c->barf(c->barfstr); 258b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*NOTREACHED*/ 259b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(0); 260b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2615d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj r = ML_(img_get_UShort)(c->sli.img, c->sli_next); 2625d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj c->sli_next += sizeof(UShort); 263b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return r; 264b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 265b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic UInt get_UInt ( Cursor* c ) { 266b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UInt r; 267b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(is_sane_Cursor(c)); 2685d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (c->sli_next + sizeof(UInt) > c->sli.ioff + c->sli.szB) { 269b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj c->barf(c->barfstr); 270b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*NOTREACHED*/ 271b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(0); 272b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2735d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj r = ML_(img_get_UInt)(c->sli.img, c->sli_next); 2745d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj c->sli_next += sizeof(UInt); 275b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return r; 276b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 277b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic ULong get_ULong ( Cursor* c ) { 278b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ULong r; 279b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(is_sane_Cursor(c)); 2805d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (c->sli_next + sizeof(ULong) > c->sli.ioff + c->sli.szB) { 281b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj c->barf(c->barfstr); 282b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*NOTREACHED*/ 283b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(0); 284b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2855d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj r = ML_(img_get_ULong)(c->sli.img, c->sli_next); 2865d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj c->sli_next += sizeof(ULong); 287b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return r; 288b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 2895d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardjstatic ULong get_ULEB128 ( Cursor* c ) { 290b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ULong result; 291b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Int shift; 292b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar byte; 293b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* unroll first iteration */ 294b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj byte = get_UChar( c ); 295b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj result = (ULong)(byte & 0x7f); 296b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (LIKELY(!(byte & 0x80))) return result; 297b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj shift = 7; 298b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* end unroll first iteration */ 299b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj do { 300b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj byte = get_UChar( c ); 301b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj result |= ((ULong)(byte & 0x7f)) << shift; 302b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj shift += 7; 303b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } while (byte & 0x80); 304b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return result; 305b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 306b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic Long get_SLEB128 ( Cursor* c ) { 307b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ULong result = 0; 308b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Int shift = 0; 309b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar byte; 310b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj do { 311b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj byte = get_UChar(c); 312b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj result |= ((ULong)(byte & 0x7f)) << shift; 313b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj shift += 7; 314b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } while (byte & 0x80); 315b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (shift < 64 && (byte & 0x40)) 316b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj result |= -(1ULL << shift); 317b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return result; 318b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 319b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3205d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj/* Assume 'c' points to the start of a string. Return a DiCursor of 3215d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj whatever it points at, and advance it past the terminating zero. 3225d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj This makes it safe for the caller to then copy the string with 3235d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ML_(addStr), since (w.r.t. image overruns) the process of advancing 3245d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj past the terminating zero will already have "vetted" the string. */ 3255d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardjstatic DiCursor get_AsciiZ ( Cursor* c ) { 3265d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj UChar uc; 3275d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiCursor res = get_DiCursor_from_Cursor(c); 328b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj do { uc = get_UChar(c); } while (uc != 0); 329b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return res; 330b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 331b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 332b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic ULong peek_ULEB128 ( Cursor* c ) { 3335d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiOffT here = c->sli_next; 3345d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong r = get_ULEB128( c ); 3355d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj c->sli_next = here; 336b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return r; 337b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 338b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic UChar peek_UChar ( Cursor* c ) { 3395d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiOffT here = c->sli_next; 3405d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj UChar r = get_UChar( c ); 3415d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj c->sli_next = here; 342b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return r; 343b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 344b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 345b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic ULong get_Dwarfish_UWord ( Cursor* c, Bool is_dw64 ) { 346b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return is_dw64 ? get_ULong(c) : (ULong) get_UInt(c); 347b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 348b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 349b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic UWord get_UWord ( Cursor* c ) { 350b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(sizeof(UWord) == sizeof(void*)); 351b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (sizeof(UWord) == 4) return get_UInt(c); 352b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (sizeof(UWord) == 8) return get_ULong(c); 353b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(0); 354b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 355b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 356b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* Read a DWARF3 'Initial Length' field */ 357b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic ULong get_Initial_Length ( /*OUT*/Bool* is64, 358b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Cursor* c, 3596bd9dc18c043927c1196caba20a327238a179c42florian const HChar* barfMsg ) 360b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 361b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ULong w64; 362b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UInt w32; 363b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj *is64 = False; 364b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj w32 = get_UInt( c ); 365b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (w32 >= 0xFFFFFFF0 && w32 < 0xFFFFFFFF) { 366b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj c->barf( barfMsg ); 367b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 368b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj else if (w32 == 0xFFFFFFFF) { 369b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj *is64 = True; 370b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj w64 = get_ULong( c ); 371b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else { 372b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj *is64 = False; 373b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj w64 = (ULong)w32; 374b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 375b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return w64; 376b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 377b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 378b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 379b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 380b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 381b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- "CUConst" structure ---*/ 382b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 383b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 384b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 385746e97e7098def65d59c79d5d661f9a757a837cdphilippetypedef 386746e97e7098def65d59c79d5d661f9a757a837cdphilippe struct _name_form { 387e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe ULong at_name; // Dwarf Attribute name 3888167a03ce124625e2f950e89e7b6cf7e69e6945aphilippe ULong at_form; // Dwarf Attribute form 389e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe UInt skip_szB; // Nr of bytes skippable from here ... 390e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe UInt next_nf; // ... to reach this attr/form index in the g_abbv.nf 391746e97e7098def65d59c79d5d661f9a757a837cdphilippe } name_form; 3928167a03ce124625e2f950e89e7b6cf7e69e6945aphilippe/* skip_szB and next_nf are used to optimise the skipping of uninteresting DIEs. 393e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe Each name_form maintains how many (fixed) nr of bytes can be skipped from 394e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe the beginning of this form till the next attr/form to look at. 395e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe The next form to look can be: 396e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe an 'interesting' attr/form to read while skipping a DIE 397e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe (currently, this is only DW_AT_sibling) 398e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe or 399e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe a variable length form which must be read to be skipped. 400e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe For a variable length form, the skip_szB will be equal to VARSZ_FORM. 401e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe 402e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe Note: this technique could also be used to speed up the parsing 403e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe of DIEs : for each parser kind, we could have the nr of bytes 404e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe to skip to directly reach the interesting form(s) for the parser. */ 405746e97e7098def65d59c79d5d661f9a757a837cdphilippe 406746e97e7098def65d59c79d5d661f9a757a837cdphilippetypedef 407746e97e7098def65d59c79d5d661f9a757a837cdphilippe struct _g_abbv { 408746e97e7098def65d59c79d5d661f9a757a837cdphilippe struct _g_abbv *next; // read/write by hash table. 409746e97e7098def65d59c79d5d661f9a757a837cdphilippe UWord abbv_code; // key, read by hash table 410746e97e7098def65d59c79d5d661f9a757a837cdphilippe ULong atag; 411746e97e7098def65d59c79d5d661f9a757a837cdphilippe ULong has_children; 412746e97e7098def65d59c79d5d661f9a757a837cdphilippe name_form nf[0]; 413746e97e7098def65d59c79d5d661f9a757a837cdphilippe /* Variable-length array of name/form pairs, terminated 414e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe by a 0/0 pair. 415e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe The skip_szB/next_nf allows to skip efficiently a DIE 416e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe described by this g_abbv; */ 417746e97e7098def65d59c79d5d661f9a757a837cdphilippe } g_abbv; 418b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 419b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* Holds information that is constant through the parsing of a 420b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Compilation Unit. This is basically plumbed through to 421b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj everywhere. */ 422b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjtypedef 423b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj struct { 424b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Call here if anything goes wrong */ 4256bd9dc18c043927c1196caba20a327238a179c42florian void (*barf)( const HChar* ) __attribute__((noreturn)); 426b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Is this 64-bit DWARF ? */ 427b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool is_dw64; 428fba428cd266b8a39db641c5fd9523daa8939bed0tom /* Which DWARF version ? (2, 3 or 4) */ 429b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UShort version; 430055b0f85aaa42477a803d445885c389561d3d3c8sewardj /* Length of this Compilation Unit, as stated in the 431055b0f85aaa42477a803d445885c389561d3d3c8sewardj .unit_length :: InitialLength field of the CU Header. 432055b0f85aaa42477a803d445885c389561d3d3c8sewardj However, this size (as specified by the D3 spec) does not 433055b0f85aaa42477a803d445885c389561d3d3c8sewardj include the size of the .unit_length field itself, which is 434055b0f85aaa42477a803d445885c389561d3d3c8sewardj either 4 or 12 bytes (32-bit or 64-bit Dwarf3). That value 435055b0f85aaa42477a803d445885c389561d3d3c8sewardj can be obtained through the expression ".is_dw64 ? 12 : 4". */ 436b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ULong unit_length; 437b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Offset of start of this unit in .debug_info */ 438b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord cu_start_offset; 439b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* SVMA for this CU. In the D3 spec, is known as the "base 440b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj address of the compilation unit (last para sec 3.1.1). 441b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Needed for (amongst things) interpretation of location-list 442b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj values. */ 443b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr cu_svma; 444b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool cu_svma_known; 4455d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj 446b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* The debug_abbreviations table to be used for this Unit */ 4475d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj //UChar* debug_abbv; 448b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Upper bound on size thereof (an overestimate, in general) */ 4495d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj //UWord debug_abbv_maxszB; 4505d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj /* A bounded area of the image, to be used as the 4515d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj debug_abbreviations table tobe used for this Unit. */ 4525d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice debug_abbv; 4535d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj 4545d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj /* Image information for various sections. */ 4555d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_str; 4565d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_ranges; 4575d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_loc; 4585d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_line; 4595d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_info; 4605d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_types; 4615d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_info_alt; 4625d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_str_alt; 463f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj /* How much to add to .debug_types resp. alternate .debug_info offsets 464f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj in cook_die*. */ 465f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj UWord types_cuOff_bias; 466f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj UWord alt_cuOff_bias; 467b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* --- Needed so we can add stuff to the string table. --- */ 468b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj struct _DebugInfo* di; 469746e97e7098def65d59c79d5d661f9a757a837cdphilippe /* --- a hash table of g_abbv (i.e. parsed abbreviations) --- */ 47009a4c794458cdb9dea743fa40e450150a2725257florian VgHashTable *ht_abbvs; 471d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 472d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* True if this came from .debug_types; otherwise it came from 473d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj .debug_info. */ 474d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj Bool is_type_unit; 475d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* For a unit coming from .debug_types, these hold the TU's type 476d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj signature and the uncooked DIE offset of the TU's signatured 477d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj type. For a unit coming from .debug_info, these are unused. */ 478d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj ULong type_signature; 479d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj ULong type_offset; 480d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 481d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* Signatured type hash; computed once and then shared by all 482d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj CUs. */ 48309a4c794458cdb9dea743fa40e450150a2725257florian VgHashTable *signature_types; 484f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj 485f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj /* True if this came from alternate .debug_info; otherwise 486f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj it came from normal .debug_info or .debug_types. */ 487f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj Bool is_alt_info; 488b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 489b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj CUConst; 490b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 491b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 492d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj/* Return the cooked value of DIE depending on whether CC represents a 493f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj .debug_types unit. To cook a DIE, we pretend that the .debug_info, 494f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj .debug_types and optional alternate .debug_info sections form 495f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj a contiguous whole, so that DIEs coming from .debug_types are numbered 496f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj starting at the end of .debug_info and DIEs coming from alternate 497f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj .debug_info are numbered starting at the end of .debug_types. */ 498518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic UWord cook_die( const CUConst* cc, UWord die ) 499d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj{ 500d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj if (cc->is_type_unit) 501f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj die += cc->types_cuOff_bias; 502f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj else if (cc->is_alt_info) 503f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj die += cc->alt_cuOff_bias; 504d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj return die; 505d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj} 506d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 507d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj/* Like cook_die, but understand that DIEs coming from a 508f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj DW_FORM_ref_sig8 reference are already cooked. Also, handle 509f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj DW_FORM_GNU_ref_alt from within primary .debug_info or .debug_types 510f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj as reference to alternate .debug_info. */ 511518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic UWord cook_die_using_form( const CUConst *cc, UWord die, DW_FORM form) 512d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj{ 513d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj if (form == DW_FORM_ref_sig8) 514d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj return die; 515f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj if (form == DW_FORM_GNU_ref_alt) 516f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj return die + cc->alt_cuOff_bias; 517d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj return cook_die( cc, die ); 518d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj} 519d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 520f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj/* Return the uncooked offset of DIE and set *TYPE_FLAG to true if the DIE 521f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj came from the .debug_types section and *ALT_FLAG to true if the DIE 522f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj came from alternate .debug_info section. */ 523518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic UWord uncook_die( const CUConst *cc, UWord die, /*OUT*/Bool *type_flag, 524f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj Bool *alt_flag ) 525d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj{ 526f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj *alt_flag = False; 527f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj *type_flag = False; 5285d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj /* The use of escn_debug_{info,types}.szB seems safe to me even if 5295d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj escn_debug_{info,types} are DiSlice_INVALID (meaning the 5305d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj sections were not found), because DiSlice_INVALID.szB is always 5315d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj zero. That said, it seems unlikely we'd ever get here if 5325d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj .debug_info or .debug_types were missing. */ 5335d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (die >= cc->escn_debug_info.szB) { 5345d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (die >= cc->escn_debug_info.szB + cc->escn_debug_types.szB) { 535f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj *alt_flag = True; 5365d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj die -= cc->escn_debug_info.szB + cc->escn_debug_types.szB; 537f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj } else { 538f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj *type_flag = True; 5395d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj die -= cc->escn_debug_info.szB; 540f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj } 541d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj } 542d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj return die; 543d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj} 544d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 545b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 546b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 547b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- Helper functions for Guarded Expressions ---*/ 548b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 549b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 550b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 551b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* Parse the location list starting at img-offset 'debug_loc_offset' 552b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj in .debug_loc. Results are biased with 'svma_of_referencing_CU' 553b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj and so I believe are correct SVMAs for the object as a whole. This 554b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj function allocates the UChar*, and the caller must deallocate it. 555b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj The resulting block is in so-called Guarded-Expression format. 556b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 557b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Guarded-Expression format is similar but not identical to the DWARF3 558b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj location-list format. The format of each returned block is: 559b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 560b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar biasMe; 561b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar isEnd; 562b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj followed by zero or more of 563b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 564b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (Addr aMin; Addr aMax; UShort nbytes; ..bytes..; UChar isEnd) 565b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 566b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj '..bytes..' is an standard DWARF3 location expression which is 567b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj valid when aMin <= pc <= aMax (possibly after suitable biasing). 568b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 569b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj The number of bytes in '..bytes..' is nbytes. 570b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 571b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj The end of the sequence is marked by an isEnd == 1 value. All 572b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj previous isEnd values must be zero. 573b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 574b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj biasMe is 1 if the aMin/aMax fields need this DebugInfo's 575b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj text_bias added before use, and 0 if the GX is this is not 576b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj necessary (is ready to go). 577b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 578b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Hence the block can be quickly parsed and is self-describing. Note 579b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj that aMax is 1 less than the corresponding value in a DWARF3 580b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj location list. Zero length ranges, with aMax == aMin-1, are not 581b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj allowed. 582b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj*/ 5839c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj/* 2008-sept-12: moved ML_(pp_GX) from here to d3basics.c, where 5849c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj it more logically belongs. */ 5859c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 586b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 587402c9eed11b9b60c6e134d05db938e395466cf99tom/* Apply a text bias to a GX. */ 588518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic void bias_GX ( /*MOD*/GExpr* gx, const DebugInfo* di ) 589b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 590b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UShort nbytes; 591b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar* p = &gx->payload[0]; 59286781fabbfc019b752f9605e487cfce77b2a592atom UChar* pA; 593b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar uc; 594b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj uc = *p++; /*biasMe*/ 595b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (uc == 0) 596b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return; 597b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(uc == 1); 598b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj p[-1] = 0; /* mark it as done */ 599b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 600b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj uc = *p++; 601b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (uc == 1) 602b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; /*isEnd*/ 603b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(uc == 0); 60468a2ebd9384661a85a4674fe8310c595ad494305sewardj /* t-bias aMin */ 60586781fabbfc019b752f9605e487cfce77b2a592atom pA = (UChar*)p; 60686781fabbfc019b752f9605e487cfce77b2a592atom ML_(write_Addr)(pA, ML_(read_Addr)(pA) + di->text_debug_bias); 60768a2ebd9384661a85a4674fe8310c595ad494305sewardj p += sizeof(Addr); 60868a2ebd9384661a85a4674fe8310c595ad494305sewardj /* t-bias aMax */ 60986781fabbfc019b752f9605e487cfce77b2a592atom pA = (UChar*)p; 61086781fabbfc019b752f9605e487cfce77b2a592atom ML_(write_Addr)(pA, ML_(read_Addr)(pA) + di->text_debug_bias); 61168a2ebd9384661a85a4674fe8310c595ad494305sewardj p += sizeof(Addr); 61268a2ebd9384661a85a4674fe8310c595ad494305sewardj /* nbytes, and actual expression */ 61386781fabbfc019b752f9605e487cfce77b2a592atom nbytes = ML_(read_UShort)(p); p += sizeof(UShort); 614b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj p += nbytes; 615b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 616b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 617b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 618b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj__attribute__((noinline)) 6195d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardjstatic GExpr* make_singleton_GX ( DiCursor block, ULong nbytes ) 620b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 621b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj SizeT bytesReqd; 622b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj GExpr* gx; 623b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar *p, *pstart; 624b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 625b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(sizeof(UWord) == sizeof(Addr)); 626b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(nbytes <= 0xFFFF); /* else we overflow the nbytes field */ 627b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj bytesReqd 628b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj = sizeof(UChar) /*biasMe*/ + sizeof(UChar) /*!isEnd*/ 629b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj + sizeof(UWord) /*aMin*/ + sizeof(UWord) /*aMax*/ 6305d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj + sizeof(UShort) /*nbytes*/ + (SizeT)nbytes 631b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj + sizeof(UChar); /*isEnd*/ 632b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 6339c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj gx = ML_(dinfo_zalloc)( "di.readdwarf3.msGX.1", 6349c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj sizeof(GExpr) + bytesReqd ); 635b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 636b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj p = pstart = &gx->payload[0]; 637b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 63886781fabbfc019b752f9605e487cfce77b2a592atom p = ML_(write_UChar)(p, 0); /*biasMe*/ 63986781fabbfc019b752f9605e487cfce77b2a592atom p = ML_(write_UChar)(p, 0); /*!isEnd*/ 64086781fabbfc019b752f9605e487cfce77b2a592atom p = ML_(write_Addr)(p, 0); /*aMin*/ 64186781fabbfc019b752f9605e487cfce77b2a592atom p = ML_(write_Addr)(p, ~0); /*aMax*/ 64286781fabbfc019b752f9605e487cfce77b2a592atom p = ML_(write_UShort)(p, nbytes); /*nbytes*/ 6435d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ML_(cur_read_get)(p, block, nbytes); p += nbytes; 64486781fabbfc019b752f9605e487cfce77b2a592atom p = ML_(write_UChar)(p, 1); /*isEnd*/ 645b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 646b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert( (SizeT)(p - pstart) == bytesReqd); 647b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert( &gx->payload[bytesReqd] 648b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj == ((UChar*)gx) + sizeof(GExpr) + bytesReqd ); 649b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 650b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return gx; 651b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 652b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 653b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj__attribute__((noinline)) 654518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic GExpr* make_general_GX ( const CUConst* cc, 655b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool td3, 6565d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong debug_loc_offset, 657b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr svma_of_referencing_CU ) 658b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 659b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr base; 660b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Cursor loc; 661b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj XArray* xa; /* XArray of UChar */ 662b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj GExpr* gx; 663b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Word nbytes; 664b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 665b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(sizeof(UWord) == sizeof(Addr)); 6665d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (!ML_(sli_is_valid)(cc->escn_debug_loc) || cc->escn_debug_loc.szB == 0) 667b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->barf("make_general_GX: .debug_loc is empty/missing"); 668b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 6695d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj init_Cursor( &loc, cc->escn_debug_loc, 0, cc->barf, 670b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj "Overrun whilst reading .debug_loc section(2)" ); 671b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj set_position_of_Cursor( &loc, debug_loc_offset ); 672b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 6735d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("make_general_GX (.debug_loc_offset = %llu, ioff = %llu) {\n", 674c6e5d76e9eea8625f385ff844545c688c91938daflorian debug_loc_offset, get_DiCursor_from_Cursor(&loc).ioff ); 675b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 676b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Who frees this xa? It is freed before this fn exits. */ 6779c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj xa = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.mgGX.1", 6789c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ML_(dinfo_free), 679b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj sizeof(UChar) ); 680b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 681b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj { UChar c = 1; /*biasMe*/ VG_(addBytesToXA)( xa, &c, sizeof(c) ); } 682b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 683b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj base = 0; 684b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 685b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool acquire; 686b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord len; 687b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Read a (host-)word pair. This is something of a hack since 688b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj the word size to read is really dictated by the ELF file; 689b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj however, we assume we're reading a file with the same 690b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj word-sizeness as the host. Reasonably enough. */ 691b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord w1 = get_UWord( &loc ); 692b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord w2 = get_UWord( &loc ); 693b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 694b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3(" %08lx %08lx\n", w1, w2); 695b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (w1 == 0 && w2 == 0) 696b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; /* end of list */ 697b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 698b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (w1 == -1UL) { 699b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* new value for 'base' */ 700b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj base = w2; 701b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj continue; 702b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 703b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 704b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* else a location expression follows */ 705b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* else enumerate [w1+base, w2+base) */ 706b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* w2 is 1 past end of range, as per D3 defn for "DW_AT_high_pc" 707b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (sec 2.17.2) */ 708b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (w1 > w2) { 709b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("negative range is for .debug_loc expr at " 7105d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj "file offset %llu\n", 711b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj debug_loc_offset); 712b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->barf( "negative range in .debug_loc section" ); 713b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 714b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 715b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* ignore zero length ranges */ 716b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj acquire = w1 < w2; 717b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj len = (UWord)get_UShort( &loc ); 718b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 719b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (acquire) { 720b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord w; 721b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UShort s; 722b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar c; 723b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj c = 0; /* !isEnd*/ 724b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(addBytesToXA)( xa, &c, sizeof(c) ); 725b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj w = w1 + base + svma_of_referencing_CU; 726b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(addBytesToXA)( xa, &w, sizeof(w) ); 727b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj w = w2 -1 + base + svma_of_referencing_CU; 728b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(addBytesToXA)( xa, &w, sizeof(w) ); 729b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj s = (UShort)len; 730b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(addBytesToXA)( xa, &s, sizeof(s) ); 731b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 732b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 733b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (len > 0) { 734b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar byte = get_UChar( &loc ); 735b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("%02x", (UInt)byte); 736b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (acquire) 737b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(addBytesToXA)( xa, &byte, 1 ); 738b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj len--; 739b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 740b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("\n"); 741b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 742b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 743b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj { UChar c = 1; /*isEnd*/ VG_(addBytesToXA)( xa, &c, sizeof(c) ); } 744b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 745b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj nbytes = VG_(sizeXA)( xa ); 746b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(nbytes >= 1); 747b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 7489c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj gx = ML_(dinfo_zalloc)( "di.readdwarf3.mgGX.2", sizeof(GExpr) + nbytes ); 749b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(memcpy)( &gx->payload[0], (UChar*)VG_(indexXA)(xa,0), nbytes ); 750b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert( &gx->payload[nbytes] 751b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj == ((UChar*)gx) + sizeof(GExpr) + nbytes ); 752b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 753b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(deleteXA)( xa ); 754b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 755b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("}\n"); 756b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 757b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return gx; 758b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 759b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 760b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 761b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 762b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 763b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- Helper functions for range lists and CU headers ---*/ 764b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 765b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 766b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 767b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* Denotes an address range. Both aMin and aMax are included in the 768b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj range; hence a complete range is (0, ~0) and an empty range is any 769b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (X, X-1) for X > 0.*/ 770b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjtypedef 771b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj struct { Addr aMin; Addr aMax; } 772b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj AddrRange; 773b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 774b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 7759c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj/* Generate an arbitrary structural total ordering on 7769c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj XArray* of AddrRange. */ 7773297124fa2116737066ac3cd709f18fdd5405163florianstatic Word cmp__XArrays_of_AddrRange ( const XArray* rngs1, 7783297124fa2116737066ac3cd709f18fdd5405163florian const XArray* rngs2 ) 7799c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj{ 7809c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Word n1, n2, i; 781e2800c958044937e72eefa371c10ae47ac40e089florian vg_assert(rngs1 && rngs2); 7829c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj n1 = VG_(sizeXA)( rngs1 ); 7839c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj n2 = VG_(sizeXA)( rngs2 ); 7849c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (n1 < n2) return -1; 7859c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (n1 > n2) return 1; 7869c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj for (i = 0; i < n1; i++) { 7879c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj AddrRange* rng1 = (AddrRange*)VG_(indexXA)( rngs1, i ); 7889c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj AddrRange* rng2 = (AddrRange*)VG_(indexXA)( rngs2, i ); 7899c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (rng1->aMin < rng2->aMin) return -1; 7909c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (rng1->aMin > rng2->aMin) return 1; 7919c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (rng1->aMax < rng2->aMax) return -1; 7929c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (rng1->aMax > rng2->aMax) return 1; 7939c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 7949c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj return 0; 7959c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj} 7969c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 7979c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 798b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj__attribute__((noinline)) 799b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic XArray* /* of AddrRange */ empty_range_list ( void ) 800b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 801b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj XArray* xa; /* XArray of AddrRange */ 802b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Who frees this xa? varstack_preen() does. */ 8039c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj xa = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.erl.1", 8049c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ML_(dinfo_free), 805b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj sizeof(AddrRange) ); 806b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return xa; 807b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 808b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 809b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 8109c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj__attribute__((noinline)) 811b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic XArray* unitary_range_list ( Addr aMin, Addr aMax ) 812b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 813b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj XArray* xa; 814b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj AddrRange pair; 815b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(aMin <= aMax); 816b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Who frees this xa? varstack_preen() does. */ 8179c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj xa = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.url.1", 8189c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ML_(dinfo_free), 819b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj sizeof(AddrRange) ); 820b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj pair.aMin = aMin; 821b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj pair.aMax = aMax; 822b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(addToXA)( xa, &pair ); 823b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return xa; 824b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 825b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 826b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 827b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* Enumerate the address ranges starting at img-offset 828b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 'debug_ranges_offset' in .debug_ranges. Results are biased with 829b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 'svma_of_referencing_CU' and so I believe are correct SVMAs for the 830b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj object as a whole. This function allocates the XArray, and the 831b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj caller must deallocate it. */ 832b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj__attribute__((noinline)) 833b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic XArray* /* of AddrRange */ 834518850bf0da07ed3e2244e307268ae0fd80e93a8florianget_range_list ( const CUConst* cc, 835518850bf0da07ed3e2244e307268ae0fd80e93a8florian Bool td3, 836518850bf0da07ed3e2244e307268ae0fd80e93a8florian UWord debug_ranges_offset, 837518850bf0da07ed3e2244e307268ae0fd80e93a8florian Addr svma_of_referencing_CU ) 838b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 839b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr base; 840b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Cursor ranges; 841b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj XArray* xa; /* XArray of AddrRange */ 842b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj AddrRange pair; 843b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 8445d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (!ML_(sli_is_valid)(cc->escn_debug_ranges) 8455d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj || cc->escn_debug_ranges.szB == 0) 846b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->barf("get_range_list: .debug_ranges is empty/missing"); 847b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 8485d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj init_Cursor( &ranges, cc->escn_debug_ranges, 0, cc->barf, 849b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj "Overrun whilst reading .debug_ranges section(2)" ); 850b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj set_position_of_Cursor( &ranges, debug_ranges_offset ); 851b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 852b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Who frees this xa? varstack_preen() does. */ 8539c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj xa = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.grl.1", ML_(dinfo_free), 854b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj sizeof(AddrRange) ); 855b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj base = 0; 856b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 857b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Read a (host-)word pair. This is something of a hack since 858b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj the word size to read is really dictated by the ELF file; 859b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj however, we assume we're reading a file with the same 860b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj word-sizeness as the host. Reasonably enough. */ 861b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord w1 = get_UWord( &ranges ); 862b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord w2 = get_UWord( &ranges ); 863b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 864b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (w1 == 0 && w2 == 0) 865b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; /* end of list. */ 866b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 867b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (w1 == -1UL) { 868b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* new value for 'base' */ 869b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj base = w2; 870b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj continue; 871b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 872b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 873b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* else enumerate [w1+base, w2+base) */ 874b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* w2 is 1 past end of range, as per D3 defn for "DW_AT_high_pc" 875b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (sec 2.17.2) */ 876b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (w1 > w2) 877b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->barf( "negative range in .debug_ranges section" ); 878b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (w1 < w2) { 879b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj pair.aMin = w1 + base + svma_of_referencing_CU; 880b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj pair.aMax = w2 - 1 + base + svma_of_referencing_CU; 881b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(pair.aMin <= pair.aMax); 882b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(addToXA)( xa, &pair ); 883b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 884b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 885b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return xa; 886b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 887b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 888e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe#define VARSZ_FORM 0xffffffff 889518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic UInt get_Form_szB (const CUConst* cc, DW_FORM form ); 890e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe 891746e97e7098def65d59c79d5d661f9a757a837cdphilippe/* Initialises the hash table of abbreviations. 892746e97e7098def65d59c79d5d661f9a757a837cdphilippe We do a single scan of the abbv slice to parse and 893746e97e7098def65d59c79d5d661f9a757a837cdphilippe build all abbreviations, for the following reasons: 894746e97e7098def65d59c79d5d661f9a757a837cdphilippe * all or most abbreviations will be needed in any case 895746e97e7098def65d59c79d5d661f9a757a837cdphilippe (at least for var-info reading). 896746e97e7098def65d59c79d5d661f9a757a837cdphilippe * re-reading each time an abbreviation causes a lot of calls 897746e97e7098def65d59c79d5d661f9a757a837cdphilippe to get_ULEB128. 898746e97e7098def65d59c79d5d661f9a757a837cdphilippe * a CU should not have many abbreviations. */ 899746e97e7098def65d59c79d5d661f9a757a837cdphilippestatic void init_ht_abbvs (CUConst* cc, 900746e97e7098def65d59c79d5d661f9a757a837cdphilippe Bool td3) 901746e97e7098def65d59c79d5d661f9a757a837cdphilippe{ 902746e97e7098def65d59c79d5d661f9a757a837cdphilippe Cursor c; 903746e97e7098def65d59c79d5d661f9a757a837cdphilippe g_abbv *ta; // temporary abbreviation, reallocated if needed. 904746e97e7098def65d59c79d5d661f9a757a837cdphilippe UInt ta_nf_maxE; // max nr of pairs in ta.nf[], doubled when reallocated. 905746e97e7098def65d59c79d5d661f9a757a837cdphilippe UInt ta_nf_n; // nr of pairs in ta->nf that are initialised. 906e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe g_abbv *ht_ta; // abbv to insert in hash table. 907e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe Int i; 908746e97e7098def65d59c79d5d661f9a757a837cdphilippe 909746e97e7098def65d59c79d5d661f9a757a837cdphilippe #define SZ_G_ABBV(_nf_szE) (sizeof(g_abbv) + _nf_szE * sizeof(name_form)) 910746e97e7098def65d59c79d5d661f9a757a837cdphilippe 911746e97e7098def65d59c79d5d661f9a757a837cdphilippe ta_nf_maxE = 10; // starting with enough for 9 pairs+terminating pair. 912746e97e7098def65d59c79d5d661f9a757a837cdphilippe ta = ML_(dinfo_zalloc) ("di.readdwarf3.ht_ta_nf", SZ_G_ABBV(ta_nf_maxE)); 913746e97e7098def65d59c79d5d661f9a757a837cdphilippe cc->ht_abbvs = VG_(HT_construct) ("di.readdwarf3.ht_abbvs"); 914746e97e7098def65d59c79d5d661f9a757a837cdphilippe 915746e97e7098def65d59c79d5d661f9a757a837cdphilippe init_Cursor( &c, cc->debug_abbv, 0, cc->barf, 916746e97e7098def65d59c79d5d661f9a757a837cdphilippe "Overrun whilst parsing .debug_abbrev section(2)" ); 917746e97e7098def65d59c79d5d661f9a757a837cdphilippe while (True) { 918746e97e7098def65d59c79d5d661f9a757a837cdphilippe ta->abbv_code = get_ULEB128( &c ); 919746e97e7098def65d59c79d5d661f9a757a837cdphilippe if (ta->abbv_code == 0) break; /* end of the table */ 920746e97e7098def65d59c79d5d661f9a757a837cdphilippe 921746e97e7098def65d59c79d5d661f9a757a837cdphilippe ta->atag = get_ULEB128( &c ); 922746e97e7098def65d59c79d5d661f9a757a837cdphilippe ta->has_children = get_UChar( &c ); 923746e97e7098def65d59c79d5d661f9a757a837cdphilippe ta_nf_n = 0; 924746e97e7098def65d59c79d5d661f9a757a837cdphilippe while (True) { 925746e97e7098def65d59c79d5d661f9a757a837cdphilippe if (ta_nf_n >= ta_nf_maxE) { 926746e97e7098def65d59c79d5d661f9a757a837cdphilippe g_abbv *old_ta = ta; 927746e97e7098def65d59c79d5d661f9a757a837cdphilippe ta = ML_(dinfo_zalloc) ("di.readdwarf3.ht_ta_nf", 928746e97e7098def65d59c79d5d661f9a757a837cdphilippe SZ_G_ABBV(2 * ta_nf_maxE)); 929746e97e7098def65d59c79d5d661f9a757a837cdphilippe ta_nf_maxE = 2 * ta_nf_maxE; 930746e97e7098def65d59c79d5d661f9a757a837cdphilippe VG_(memcpy) (ta, old_ta, SZ_G_ABBV(ta_nf_n)); 931746e97e7098def65d59c79d5d661f9a757a837cdphilippe ML_(dinfo_free) (old_ta); 932746e97e7098def65d59c79d5d661f9a757a837cdphilippe } 933746e97e7098def65d59c79d5d661f9a757a837cdphilippe ta->nf[ta_nf_n].at_name = get_ULEB128( &c ); 934746e97e7098def65d59c79d5d661f9a757a837cdphilippe ta->nf[ta_nf_n].at_form = get_ULEB128( &c ); 935746e97e7098def65d59c79d5d661f9a757a837cdphilippe if (ta->nf[ta_nf_n].at_name == 0 && ta->nf[ta_nf_n].at_form == 0) { 936746e97e7098def65d59c79d5d661f9a757a837cdphilippe ta_nf_n++; 937746e97e7098def65d59c79d5d661f9a757a837cdphilippe break; 938746e97e7098def65d59c79d5d661f9a757a837cdphilippe } 939746e97e7098def65d59c79d5d661f9a757a837cdphilippe ta_nf_n++; 940746e97e7098def65d59c79d5d661f9a757a837cdphilippe } 941e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe 942e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe // Initialises the skip_szB/next_nf elements : an element at position 943e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe // i must contain the sum of its own size + the sizes of all elements 944e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe // following i till either the next variable size element, the next 945e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe // sibling element or the end of the DIE. 946e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe ta->nf[ta_nf_n - 1].skip_szB = 0; 947e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe ta->nf[ta_nf_n - 1].next_nf = 0; 948e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe for (i = ta_nf_n - 2; i >= 0; i--) { 949e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe const UInt form_szB = get_Form_szB (cc, (DW_FORM)ta->nf[i].at_form); 950e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe 951e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe if (ta->nf[i+1].at_name == DW_AT_sibling 952e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe || ta->nf[i+1].skip_szB == VARSZ_FORM) { 953e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe ta->nf[i].skip_szB = form_szB; 954e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe ta->nf[i].next_nf = i+1; 955e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe } else if (form_szB == VARSZ_FORM) { 956e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe ta->nf[i].skip_szB = form_szB; 957e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe ta->nf[i].next_nf = i+1; 958e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe } else { 959e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe ta->nf[i].skip_szB = ta->nf[i+1].skip_szB + form_szB; 960e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe ta->nf[i].next_nf = ta->nf[i+1].next_nf; 961e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe } 962e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe } 963e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe 964746e97e7098def65d59c79d5d661f9a757a837cdphilippe ht_ta = ML_(dinfo_zalloc) ("di.readdwarf3.ht_ta", SZ_G_ABBV(ta_nf_n)); 965746e97e7098def65d59c79d5d661f9a757a837cdphilippe VG_(memcpy) (ht_ta, ta, SZ_G_ABBV(ta_nf_n)); 966746e97e7098def65d59c79d5d661f9a757a837cdphilippe VG_(HT_add_node) ( cc->ht_abbvs, ht_ta ); 967e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe if (TD3) { 968c6e5d76e9eea8625f385ff844545c688c91938daflorian TRACE_D3(" Adding abbv_code %lu TAG %s [%s] nf %u ", 969c6e5d76e9eea8625f385ff844545c688c91938daflorian ht_ta->abbv_code, ML_(pp_DW_TAG)(ht_ta->atag), 970e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe ML_(pp_DW_children)(ht_ta->has_children), 971e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe ta_nf_n); 972e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe TRACE_D3(" "); 973e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe for (i = 0; i < ta_nf_n; i++) 974e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe TRACE_D3("[%u,%u] ", ta->nf[i].skip_szB, ta->nf[i].next_nf); 975e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe TRACE_D3("\n"); 976e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe } 977746e97e7098def65d59c79d5d661f9a757a837cdphilippe } 978746e97e7098def65d59c79d5d661f9a757a837cdphilippe 979746e97e7098def65d59c79d5d661f9a757a837cdphilippe ML_(dinfo_free) (ta); 980746e97e7098def65d59c79d5d661f9a757a837cdphilippe #undef SZ_G_ABBV 981746e97e7098def65d59c79d5d661f9a757a837cdphilippe} 982746e97e7098def65d59c79d5d661f9a757a837cdphilippe 983518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic g_abbv* get_abbv (const CUConst* cc, ULong abbv_code) 984746e97e7098def65d59c79d5d661f9a757a837cdphilippe{ 985746e97e7098def65d59c79d5d661f9a757a837cdphilippe g_abbv *abbv; 986746e97e7098def65d59c79d5d661f9a757a837cdphilippe 987746e97e7098def65d59c79d5d661f9a757a837cdphilippe abbv = VG_(HT_lookup) (cc->ht_abbvs, abbv_code); 988746e97e7098def65d59c79d5d661f9a757a837cdphilippe if (!abbv) 989746e97e7098def65d59c79d5d661f9a757a837cdphilippe cc->barf ("abbv_code not found in ht_abbvs table"); 990746e97e7098def65d59c79d5d661f9a757a837cdphilippe return abbv; 991746e97e7098def65d59c79d5d661f9a757a837cdphilippe} 992746e97e7098def65d59c79d5d661f9a757a837cdphilippe 993746e97e7098def65d59c79d5d661f9a757a837cdphilippe/* Free the memory allocated in CUConst. */ 994746e97e7098def65d59c79d5d661f9a757a837cdphilippestatic void clear_CUConst (CUConst* cc) 995746e97e7098def65d59c79d5d661f9a757a837cdphilippe{ 996746e97e7098def65d59c79d5d661f9a757a837cdphilippe VG_(HT_destruct) ( cc->ht_abbvs, ML_(dinfo_free)); 997746e97e7098def65d59c79d5d661f9a757a837cdphilippe cc->ht_abbvs = NULL; 998746e97e7098def65d59c79d5d661f9a757a837cdphilippe} 999b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1000b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* Parse the Compilation Unit header indicated at 'c' and 1001b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj initialise 'cc' accordingly. */ 1002b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic __attribute__((noinline)) 1003b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjvoid parse_CU_Header ( /*OUT*/CUConst* cc, 1004b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool td3, 1005b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Cursor* c, 10065d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_abbv, 1007f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj Bool type_unit, 1008f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj Bool alt_info ) 1009b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 1010b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar address_size; 10115d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong debug_abbrev_offset; 1012b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1013b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(memset)(cc, 0, sizeof(*cc)); 1014b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(c && c->barf); 1015b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->barf = c->barf; 1016b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1017b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* initial_length field */ 1018b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->unit_length 1019b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj = get_Initial_Length( &cc->is_dw64, c, 1020b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj "parse_CU_Header: invalid initial-length field" ); 1021b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1022c6e5d76e9eea8625f385ff844545c688c91938daflorian TRACE_D3(" Length: %llu\n", cc->unit_length ); 1023b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1024b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* version */ 1025b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->version = get_UShort( c ); 1026fba428cd266b8a39db641c5fd9523daa8939bed0tom if (cc->version != 2 && cc->version != 3 && cc->version != 4) 1027fba428cd266b8a39db641c5fd9523daa8939bed0tom cc->barf( "parse_CU_Header: is neither DWARF2 nor DWARF3 nor DWARF4" ); 1028b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3(" Version: %d\n", (Int)cc->version ); 1029b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1030b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* debug_abbrev_offset */ 1031b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj debug_abbrev_offset = get_Dwarfish_UWord( c, cc->is_dw64 ); 10325d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (debug_abbrev_offset >= escn_debug_abbv.szB) 1033b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->barf( "parse_CU_Header: invalid debug_abbrev_offset" ); 1034c6e5d76e9eea8625f385ff844545c688c91938daflorian TRACE_D3(" Abbrev Offset: %llu\n", debug_abbrev_offset ); 1035b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1036b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* address size. If this isn't equal to the host word size, just 1037b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj give up. This makes it safe to assume elsewhere that 103831452303b095a76295b08096b2840276db808b81sewardj DW_FORM_addr and DW_FORM_ref_addr can be treated as a host 103931452303b095a76295b08096b2840276db808b81sewardj word. */ 1040b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj address_size = get_UChar( c ); 1041b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (address_size != sizeof(void*)) 1042b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->barf( "parse_CU_Header: invalid address_size" ); 1043b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3(" Pointer Size: %d\n", (Int)address_size ); 1044b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1045d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cc->is_type_unit = type_unit; 1046f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj cc->is_alt_info = alt_info; 1047d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 1048d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj if (type_unit) { 1049d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cc->type_signature = get_ULong( c ); 1050d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cc->type_offset = get_Dwarfish_UWord( c, cc->is_dw64 ); 1051d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj } 1052d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 10535d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj /* Set up cc->debug_abbv to point to the relevant table for this 10545d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj CU. Set its .szB so that at least we can't read off the end of 10555d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj the debug_abbrev section -- potentially (and quite likely) too 10565d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj big, if this isn't the last table in the section, but at least 10575d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj it's safe. 10585d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj 10595d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj This amounts to taking debug_abbv_escn and moving the start 10605d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj position along by debug_abbrev_offset bytes, hence forming a 10615d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj smaller DiSlice which has the same end point. Since we checked 10625d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj just above that debug_abbrev_offset is less than the size of 10635d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj debug_abbv_escn, this should leave us with a nonempty slice. */ 10645d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj vg_assert(debug_abbrev_offset < escn_debug_abbv.szB); 10655d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc->debug_abbv = escn_debug_abbv; 10665d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc->debug_abbv.ioff += debug_abbrev_offset; 10675d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc->debug_abbv.szB -= debug_abbrev_offset; 10685d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj 1069746e97e7098def65d59c79d5d661f9a757a837cdphilippe init_ht_abbvs(cc, td3); 1070b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 1071b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1072d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj/* This represents a single signatured type. It maps a type signature 1073d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj (a ULong) to a cooked DIE offset. Objects of this type are stored 1074d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj in the type signature hash table. */ 1075d935068fc7b53c8a826b3436cdfccd5b7d446903sewardjtypedef 1076d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj struct D3SignatureType { 1077d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj struct D3SignatureType *next; 1078d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj UWord data; 1079d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj ULong type_signature; 1080d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj UWord die; 1081d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj } 1082d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj D3SignatureType; 1083d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 1084d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj/* Record a signatured type in the hash table. */ 108509a4c794458cdb9dea743fa40e450150a2725257florianstatic void record_signatured_type ( VgHashTable *tab, 1086d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj ULong type_signature, 1087d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj UWord die ) 1088d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj{ 1089d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj D3SignatureType *dstype = ML_(dinfo_zalloc) ( "di.readdwarf3.sigtype", 1090d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj sizeof(D3SignatureType) ); 1091d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj dstype->data = (UWord) type_signature; 1092d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj dstype->type_signature = type_signature; 1093d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj dstype->die = die; 1094d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj VG_(HT_add_node) ( tab, dstype ); 1095d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj} 1096d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 1097d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj/* Given a type signature hash table and a type signature, return the 1098d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cooked DIE offset of the type. If the type cannot be found, call 1099d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj BARF. */ 110009a4c794458cdb9dea743fa40e450150a2725257florianstatic UWord lookup_signatured_type ( const VgHashTable *tab, 1101d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj ULong type_signature, 11026bd9dc18c043927c1196caba20a327238a179c42florian void (*barf)( const HChar* ) __attribute__((noreturn)) ) 1103d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj{ 1104d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj D3SignatureType *dstype = VG_(HT_lookup) ( tab, (UWord) type_signature ); 1105d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* This may be unwarranted chumminess with the hash table 1106d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj implementation. */ 1107d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj while ( dstype != NULL && dstype->type_signature != type_signature) 1108d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj dstype = dstype->next; 1109d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj if (dstype == NULL) { 1110d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj barf("lookup_signatured_type: could not find signatured type"); 1111d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /*NOTREACHED*/ 1112d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj vg_assert(0); 1113d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj } 1114d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj return dstype->die; 1115d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj} 1116b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1117b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 11185d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj/* Represents Form data. If szB is 1/2/4/8 then the result is in the 11195d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj lowest 1/2/4/8 bytes of u.val. If szB is zero or negative then the 11205d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj result is an image section beginning at u.cur and with size -szB. 11215d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj No other szB values are allowed. */ 11225d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardjtypedef 11235d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj struct { 11245d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj Long szB; // 1, 2, 4, 8 or non-positive values only. 11255d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj union { ULong val; DiCursor cur; } u; 11265d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj } 11275d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj FormContents; 1128b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 11295d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj/* From 'c', get the Form data into 'cts'. Either it gets a 1/2/4/8 11305d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj byte scalar value, or (a reference to) zero or more bytes starting 11315d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj at a DiCursor.*/ 1132b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic 11335d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardjvoid get_Form_contents ( /*OUT*/FormContents* cts, 1134518850bf0da07ed3e2244e307268ae0fd80e93a8florian const CUConst* cc, Cursor* c, 1135b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool td3, DW_FORM form ) 1136b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 11375d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj VG_(bzero_inline)(cts, sizeof(*cts)); 1138e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe // !!! keep switch in sync with get_Form_szB. The nr of characters read below 1139e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe // must be computed similarly in get_Form_szB. 1140e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe // The consistency is verified in trace_DIE. 1141b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj switch (form) { 1142b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_FORM_data1: 11435d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)(UChar)get_UChar(c); 11445d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = 1; 11455d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("%u", (UInt)cts->u.val); 1146b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; 1147b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_FORM_data2: 11485d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)(UShort)get_UShort(c); 11495d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = 2; 11505d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("%u", (UInt)cts->u.val); 1151b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; 1152b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_FORM_data4: 11535d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)(UInt)get_UInt(c); 11545d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = 4; 11555d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("%u", (UInt)cts->u.val); 1156b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; 11570b5bf911d9d40b8dd3130f6043ef7ba68a9f446esewardj case DW_FORM_data8: 11585d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = get_ULong(c); 11595d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = 8; 11605d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("%llu", cts->u.val); 11610b5bf911d9d40b8dd3130f6043ef7ba68a9f446esewardj break; 1162fba428cd266b8a39db641c5fd9523daa8939bed0tom case DW_FORM_sec_offset: 11635d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)get_Dwarfish_UWord( c, cc->is_dw64 ); 11645d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = cc->is_dw64 ? 8 : 4; 11655d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("%llu", cts->u.val); 1166fba428cd266b8a39db641c5fd9523daa8939bed0tom break; 1167b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_FORM_sdata: 11685d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)(Long)get_SLEB128(c); 11695d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = 8; 1170c6e5d76e9eea8625f385ff844545c688c91938daflorian TRACE_D3("%llu", cts->u.val); 1171b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; 1172fba428cd266b8a39db641c5fd9523daa8939bed0tom case DW_FORM_udata: 11735d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)(Long)get_ULEB128(c); 11745d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = 8; 1175c6e5d76e9eea8625f385ff844545c688c91938daflorian TRACE_D3("%llu", cts->u.val); 1176fba428cd266b8a39db641c5fd9523daa8939bed0tom break; 1177b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_FORM_addr: 1178b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* note, this is a hack. DW_FORM_addr is defined as getting 1179b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj a word the size of the target machine as defined by the 1180b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj address_size field in the CU Header. However, 1181b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parse_CU_Header() rejects all inputs except those for 1182b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj which address_size == sizeof(Word), hence we can just 1183b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj treat it as a (host) Word. */ 11845d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)(UWord)get_UWord(c); 11855d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = sizeof(UWord); 11865d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("0x%lx", (UWord)cts->u.val); 1187b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; 118831452303b095a76295b08096b2840276db808b81sewardj 118931452303b095a76295b08096b2840276db808b81sewardj case DW_FORM_ref_addr: 119031452303b095a76295b08096b2840276db808b81sewardj /* We make the same word-size assumption as DW_FORM_addr. */ 119131452303b095a76295b08096b2840276db808b81sewardj /* What does this really mean? From D3 Sec 7.5.4, 119231452303b095a76295b08096b2840276db808b81sewardj description of "reference", it would appear to reference 119331452303b095a76295b08096b2840276db808b81sewardj some other DIE, by specifying the offset from the 119431452303b095a76295b08096b2840276db808b81sewardj beginning of a .debug_info section. The D3 spec mentions 119531452303b095a76295b08096b2840276db808b81sewardj that this might be in some other shared object and 119631452303b095a76295b08096b2840276db808b81sewardj executable. But I don't see how the name of the other 119731452303b095a76295b08096b2840276db808b81sewardj object/exe is specified. 119831452303b095a76295b08096b2840276db808b81sewardj 119931452303b095a76295b08096b2840276db808b81sewardj At least for the DW_FORM_ref_addrs created by icc11, the 120031452303b095a76295b08096b2840276db808b81sewardj references seem to be within the same object/executable. 120131452303b095a76295b08096b2840276db808b81sewardj So for the moment we merely range-check, to see that they 120231452303b095a76295b08096b2840276db808b81sewardj actually do specify a plausible offset within this 120331452303b095a76295b08096b2840276db808b81sewardj object's .debug_info, and return the value unchanged. 1204ee93cdbee1e6a0db21be1ec4533a4022c9566388sewardj 1205ee93cdbee1e6a0db21be1ec4533a4022c9566388sewardj In DWARF 2, DW_FORM_ref_addr is address-sized, but in 1206ee93cdbee1e6a0db21be1ec4533a4022c9566388sewardj DWARF 3 and later, it is offset-sized. 120731452303b095a76295b08096b2840276db808b81sewardj */ 1208ee93cdbee1e6a0db21be1ec4533a4022c9566388sewardj if (cc->version == 2) { 12095d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)(UWord)get_UWord(c); 12105d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = sizeof(UWord); 1211ee93cdbee1e6a0db21be1ec4533a4022c9566388sewardj } else { 12125d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = get_Dwarfish_UWord(c, cc->is_dw64); 12135d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = cc->is_dw64 ? sizeof(ULong) : sizeof(UInt); 1214ee93cdbee1e6a0db21be1ec4533a4022c9566388sewardj } 12155d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("0x%lx", (UWord)cts->u.val); 12165d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (0) VG_(printf)("DW_FORM_ref_addr 0x%lx\n", (UWord)cts->u.val); 12175d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (/* the following is surely impossible, but ... */ 12185d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj !ML_(sli_is_valid)(cc->escn_debug_info) 12195d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj || cts->u.val >= (ULong)cc->escn_debug_info.szB) { 122031452303b095a76295b08096b2840276db808b81sewardj /* Hmm. Offset is nonsensical for this object's .debug_info 122131452303b095a76295b08096b2840276db808b81sewardj section. Be safe and reject it. */ 122231452303b095a76295b08096b2840276db808b81sewardj cc->barf("get_Form_contents: DW_FORM_ref_addr points " 122331452303b095a76295b08096b2840276db808b81sewardj "outside .debug_info"); 122431452303b095a76295b08096b2840276db808b81sewardj } 122531452303b095a76295b08096b2840276db808b81sewardj break; 122631452303b095a76295b08096b2840276db808b81sewardj 1227b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_FORM_strp: { 1228b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* this is an offset into .debug_str */ 1229b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord uw = (UWord)get_Dwarfish_UWord( c, cc->is_dw64 ); 12305d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (!ML_(sli_is_valid)(cc->escn_debug_str) 12315d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj || uw >= cc->escn_debug_str.szB) 123231452303b095a76295b08096b2840276db808b81sewardj cc->barf("get_Form_contents: DW_FORM_strp " 1233b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj "points outside .debug_str"); 1234b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* FIXME: check the entire string lies inside debug_str, 1235b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj not just the first byte of it. */ 12365d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiCursor str 12375d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = ML_(cur_plus)( ML_(cur_from_sli)(cc->escn_debug_str), uw ); 1238e0bd5910153720d5d15697db8063d0d4caa59d8fphilippe if (TD3) { 12395d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj HChar* tmp = ML_(cur_read_strdup)(str, "di.getFC.1"); 12405d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("(indirect string, offset: 0x%lx): %s", uw, tmp); 12415d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ML_(dinfo_free)(tmp); 12425d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj } 12435d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.cur = str; 12445d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = - (Long)(1 + (ULong)ML_(cur_strlen)(str)); 1245b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; 1246b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1247b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_FORM_string: { 12485d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiCursor str = get_AsciiZ(c); 1249e0bd5910153720d5d15697db8063d0d4caa59d8fphilippe if (TD3) { 12505d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj HChar* tmp = ML_(cur_read_strdup)(str, "di.getFC.2"); 12515d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("%s", tmp); 12525d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ML_(dinfo_free)(tmp); 12535d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj } 12545d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.cur = str; 1255b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* strlen is safe because get_AsciiZ already 'vetted' the 1256b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj entire string */ 12575d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = - (Long)(1 + (ULong)ML_(cur_strlen)(str)); 1258b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; 1259b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1260fba428cd266b8a39db641c5fd9523daa8939bed0tom case DW_FORM_ref1: { 12615d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj UChar u8 = get_UChar(c); 12625d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj UWord res = cc->cu_start_offset + (UWord)u8; 12635d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)res; 12645d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = sizeof(UWord); 1265fba428cd266b8a39db641c5fd9523daa8939bed0tom TRACE_D3("<%lx>", res); 1266fba428cd266b8a39db641c5fd9523daa8939bed0tom break; 1267fba428cd266b8a39db641c5fd9523daa8939bed0tom } 1268fba428cd266b8a39db641c5fd9523daa8939bed0tom case DW_FORM_ref2: { 12695d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj UShort u16 = get_UShort(c); 12705d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj UWord res = cc->cu_start_offset + (UWord)u16; 12715d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)res; 12725d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = sizeof(UWord); 1273fba428cd266b8a39db641c5fd9523daa8939bed0tom TRACE_D3("<%lx>", res); 1274fba428cd266b8a39db641c5fd9523daa8939bed0tom break; 1275fba428cd266b8a39db641c5fd9523daa8939bed0tom } 1276b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_FORM_ref4: { 12775d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj UInt u32 = get_UInt(c); 12785d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj UWord res = cc->cu_start_offset + (UWord)u32; 12795d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)res; 12805d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = sizeof(UWord); 1281b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("<%lx>", res); 1282b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; 1283b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1284fba428cd266b8a39db641c5fd9523daa8939bed0tom case DW_FORM_ref8: { 12855d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong u64 = get_ULong(c); 12865d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj UWord res = cc->cu_start_offset + (UWord)u64; 12875d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)res; 12885d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = sizeof(UWord); 1289fba428cd266b8a39db641c5fd9523daa8939bed0tom TRACE_D3("<%lx>", res); 1290fba428cd266b8a39db641c5fd9523daa8939bed0tom break; 1291fba428cd266b8a39db641c5fd9523daa8939bed0tom } 1292fba428cd266b8a39db641c5fd9523daa8939bed0tom case DW_FORM_ref_udata: { 12935d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong u64 = get_ULEB128(c); 12945d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj UWord res = cc->cu_start_offset + (UWord)u64; 12955d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)res; 12965d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = sizeof(UWord); 1297fba428cd266b8a39db641c5fd9523daa8939bed0tom TRACE_D3("<%lx>", res); 1298fba428cd266b8a39db641c5fd9523daa8939bed0tom break; 1299fba428cd266b8a39db641c5fd9523daa8939bed0tom } 1300b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_FORM_flag: { 1301b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar u8 = get_UChar(c); 1302b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("%u", (UInt)u8); 13035d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = (ULong)u8; 13045d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = 1; 1305b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; 1306b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1307fba428cd266b8a39db641c5fd9523daa8939bed0tom case DW_FORM_flag_present: 1308fba428cd266b8a39db641c5fd9523daa8939bed0tom TRACE_D3("1"); 13095d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = 1; 13105d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = 1; 1311fba428cd266b8a39db641c5fd9523daa8939bed0tom break; 1312b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_FORM_block1: { 13135d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong u64b; 13145d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong u64 = (ULong)get_UChar(c); 13155d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiCursor block = get_DiCursor_from_Cursor(c); 1316b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("%llu byte block: ", u64); 1317b2250d38b573099db3bde67e8f1bbeb789542076sewardj for (u64b = u64; u64b > 0; u64b--) { 1318b2250d38b573099db3bde67e8f1bbeb789542076sewardj UChar u8 = get_UChar(c); 1319b2250d38b573099db3bde67e8f1bbeb789542076sewardj TRACE_D3("%x ", (UInt)u8); 1320b2250d38b573099db3bde67e8f1bbeb789542076sewardj } 13215d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.cur = block; 13225d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = - (Long)u64; 1323b2250d38b573099db3bde67e8f1bbeb789542076sewardj break; 1324b2250d38b573099db3bde67e8f1bbeb789542076sewardj } 1325b2250d38b573099db3bde67e8f1bbeb789542076sewardj case DW_FORM_block2: { 13265d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong u64b; 13275d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong u64 = (ULong)get_UShort(c); 13285d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiCursor block = get_DiCursor_from_Cursor(c); 1329b2250d38b573099db3bde67e8f1bbeb789542076sewardj TRACE_D3("%llu byte block: ", u64); 1330b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj for (u64b = u64; u64b > 0; u64b--) { 1331b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar u8 = get_UChar(c); 1332b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("%x ", (UInt)u8); 1333b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 13345d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.cur = block; 13355d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = - (Long)u64; 1336b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; 1337b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1338fba428cd266b8a39db641c5fd9523daa8939bed0tom case DW_FORM_block4: { 13395d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong u64b; 13405d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong u64 = (ULong)get_UInt(c); 13415d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiCursor block = get_DiCursor_from_Cursor(c); 1342fba428cd266b8a39db641c5fd9523daa8939bed0tom TRACE_D3("%llu byte block: ", u64); 1343fba428cd266b8a39db641c5fd9523daa8939bed0tom for (u64b = u64; u64b > 0; u64b--) { 1344fba428cd266b8a39db641c5fd9523daa8939bed0tom UChar u8 = get_UChar(c); 1345fba428cd266b8a39db641c5fd9523daa8939bed0tom TRACE_D3("%x ", (UInt)u8); 1346fba428cd266b8a39db641c5fd9523daa8939bed0tom } 13475d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.cur = block; 13485d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = - (Long)u64; 1349fba428cd266b8a39db641c5fd9523daa8939bed0tom break; 1350fba428cd266b8a39db641c5fd9523daa8939bed0tom } 1351fba428cd266b8a39db641c5fd9523daa8939bed0tom case DW_FORM_exprloc: 1352fba428cd266b8a39db641c5fd9523daa8939bed0tom case DW_FORM_block: { 13535d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong u64b; 13545d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong u64 = (ULong)get_ULEB128(c); 13555d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiCursor block = get_DiCursor_from_Cursor(c); 1356fba428cd266b8a39db641c5fd9523daa8939bed0tom TRACE_D3("%llu byte block: ", u64); 1357fba428cd266b8a39db641c5fd9523daa8939bed0tom for (u64b = u64; u64b > 0; u64b--) { 1358fba428cd266b8a39db641c5fd9523daa8939bed0tom UChar u8 = get_UChar(c); 1359fba428cd266b8a39db641c5fd9523daa8939bed0tom TRACE_D3("%x ", (UInt)u8); 1360fba428cd266b8a39db641c5fd9523daa8939bed0tom } 13615d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.cur = block; 13625d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = - (Long)u64; 1363fba428cd266b8a39db641c5fd9523daa8939bed0tom break; 1364fba428cd266b8a39db641c5fd9523daa8939bed0tom } 1365fba428cd266b8a39db641c5fd9523daa8939bed0tom case DW_FORM_ref_sig8: { 1366fba428cd266b8a39db641c5fd9523daa8939bed0tom ULong u64b; 1367d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj ULong signature = get_ULong (c); 1368d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj ULong work = signature; 1369fba428cd266b8a39db641c5fd9523daa8939bed0tom TRACE_D3("8 byte signature: "); 1370fba428cd266b8a39db641c5fd9523daa8939bed0tom for (u64b = 8; u64b > 0; u64b--) { 1371d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj UChar u8 = work & 0xff; 1372fba428cd266b8a39db641c5fd9523daa8939bed0tom TRACE_D3("%x ", (UInt)u8); 1373d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj work >>= 8; 1374fba428cd266b8a39db641c5fd9523daa8939bed0tom } 1375bb861b524aabbe064269ddb78fa32dc682dd7657philippe 1376bb861b524aabbe064269ddb78fa32dc682dd7657philippe /* cc->signature_types is only built/initialised when 1377bb861b524aabbe064269ddb78fa32dc682dd7657philippe VG_(clo_read_var_info) is set. In this case, 1378bb861b524aabbe064269ddb78fa32dc682dd7657philippe the DW_FORM_ref_sig8 can be looked up. 1379bb861b524aabbe064269ddb78fa32dc682dd7657philippe But we can also arrive here when only reading inline info 1380bb861b524aabbe064269ddb78fa32dc682dd7657philippe and VG_(clo_trace_symtab) is set. In such a case, 1381bb861b524aabbe064269ddb78fa32dc682dd7657philippe we cannot lookup the DW_FORM_ref_sig8, we rather assign 1382bb861b524aabbe064269ddb78fa32dc682dd7657philippe a dummy value. This is a kludge, but otherwise, 1383bb861b524aabbe064269ddb78fa32dc682dd7657philippe the 'dwarf inline info reader' tracing would have to 1384bb861b524aabbe064269ddb78fa32dc682dd7657philippe do type processing/reading. It is better to avoid 1385bb861b524aabbe064269ddb78fa32dc682dd7657philippe adding significant 'real' processing only due to tracing. */ 1386bb861b524aabbe064269ddb78fa32dc682dd7657philippe if (VG_(clo_read_var_info)) { 1387bb861b524aabbe064269ddb78fa32dc682dd7657philippe /* Due to the way that the hash table is constructed, the 1388bb861b524aabbe064269ddb78fa32dc682dd7657philippe resulting DIE offset here is already "cooked". See 1389bb861b524aabbe064269ddb78fa32dc682dd7657philippe cook_die_using_form. */ 1390bb861b524aabbe064269ddb78fa32dc682dd7657philippe cts->u.val = lookup_signatured_type (cc->signature_types, signature, 1391bb861b524aabbe064269ddb78fa32dc682dd7657philippe c->barf); 1392bb861b524aabbe064269ddb78fa32dc682dd7657philippe } else { 1393bb861b524aabbe064269ddb78fa32dc682dd7657philippe vg_assert (td3); 1394bb861b524aabbe064269ddb78fa32dc682dd7657philippe vg_assert (VG_(clo_read_inline_info)); 1395bb861b524aabbe064269ddb78fa32dc682dd7657philippe TRACE_D3("<not dereferencing signature type>"); 1396bb861b524aabbe064269ddb78fa32dc682dd7657philippe cts->u.val = 0; /* Assign a dummy/rubbish value */ 1397bb861b524aabbe064269ddb78fa32dc682dd7657philippe } 13985d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = sizeof(UWord); 1399fba428cd266b8a39db641c5fd9523daa8939bed0tom break; 1400fba428cd266b8a39db641c5fd9523daa8939bed0tom } 1401fba428cd266b8a39db641c5fd9523daa8939bed0tom case DW_FORM_indirect: 14025d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents (cts, cc, c, td3, (DW_FORM)get_ULEB128(c)); 1403fba428cd266b8a39db641c5fd9523daa8939bed0tom return; 1404fba428cd266b8a39db641c5fd9523daa8939bed0tom 1405f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj case DW_FORM_GNU_ref_alt: 14065d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.val = get_Dwarfish_UWord(c, cc->is_dw64); 14075d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = cc->is_dw64 ? sizeof(ULong) : sizeof(UInt); 14085d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("0x%lx", (UWord)cts->u.val); 14095d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (0) VG_(printf)("DW_FORM_GNU_ref_alt 0x%lx\n", (UWord)cts->u.val); 14105d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (/* the following is surely impossible, but ... */ 14113e49e4c2cb9a4394fd12780618e50d19d3c3a404mjw !ML_(sli_is_valid)(cc->escn_debug_info_alt)) 14123e49e4c2cb9a4394fd12780618e50d19d3c3a404mjw cc->barf("get_Form_contents: DW_FORM_GNU_ref_addr used, " 14133e49e4c2cb9a4394fd12780618e50d19d3c3a404mjw "but no alternate .debug_info"); 14143e49e4c2cb9a4394fd12780618e50d19d3c3a404mjw else if (cts->u.val >= (ULong)cc->escn_debug_info_alt.szB) { 1415f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj /* Hmm. Offset is nonsensical for this object's .debug_info 1416f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj section. Be safe and reject it. */ 14173e49e4c2cb9a4394fd12780618e50d19d3c3a404mjw cc->barf("get_Form_contents: DW_FORM_GNU_ref_addr points " 1418f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj "outside alternate .debug_info"); 1419f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj } 1420f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj break; 1421f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj 1422f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj case DW_FORM_GNU_strp_alt: { 1423f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj /* this is an offset into alternate .debug_str */ 14245d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj SizeT uw = (UWord)get_Dwarfish_UWord( c, cc->is_dw64 ); 14253e49e4c2cb9a4394fd12780618e50d19d3c3a404mjw if (!ML_(sli_is_valid)(cc->escn_debug_str_alt)) 14263e49e4c2cb9a4394fd12780618e50d19d3c3a404mjw cc->barf("get_Form_contents: DW_FORM_GNU_strp_alt used, " 14273e49e4c2cb9a4394fd12780618e50d19d3c3a404mjw "but no alternate .debug_str"); 14283e49e4c2cb9a4394fd12780618e50d19d3c3a404mjw else if (uw >= cc->escn_debug_str_alt.szB) 1429f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj cc->barf("get_Form_contents: DW_FORM_GNU_strp_alt " 1430f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj "points outside alternate .debug_str"); 1431f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj /* FIXME: check the entire string lies inside debug_str, 1432f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj not just the first byte of it. */ 14335d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiCursor str 14345d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = ML_(cur_plus)( ML_(cur_from_sli)(cc->escn_debug_str_alt), uw); 1435e0bd5910153720d5d15697db8063d0d4caa59d8fphilippe if (TD3) { 14365d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj HChar* tmp = ML_(cur_read_strdup)(str, "di.getFC.3"); 14375d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("(indirect alt string, offset: 0x%lx): %s", uw, tmp); 14385d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ML_(dinfo_free)(tmp); 14395d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj } 14405d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.cur = str; 14415d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->szB = - (Long)(1 + (ULong)ML_(cur_strlen)(str)); 1442f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj break; 1443f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj } 1444f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj 1445b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj default: 144631452303b095a76295b08096b2840276db808b81sewardj VG_(printf)( 1447c6e5d76e9eea8625f385ff844545c688c91938daflorian "get_Form_contents: unhandled %u (%s) at <%llx>\n", 144831452303b095a76295b08096b2840276db808b81sewardj form, ML_(pp_DW_FORM)(form), get_position_of_Cursor(c)); 1449b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj c->barf("get_Form_contents: unhandled DW_FORM"); 1450b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1451b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 1452b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1453e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippestatic inline UInt sizeof_Dwarfish_UWord (Bool is_dw64) 1454e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe{ 1455e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe if (is_dw64) 1456e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return sizeof(ULong); 1457e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe else 1458e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return sizeof(UInt); 1459e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe} 1460e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe 1461e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe#define VARSZ_FORM 0xffffffff 1462e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe/* If the form is a fixed length form, return the nr of bytes for this form. 1463e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe If the form is a variable length form, return VARSZ_FORM. */ 1464e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippestatic 1465518850bf0da07ed3e2244e307268ae0fd80e93a8florianUInt get_Form_szB (const CUConst* cc, DW_FORM form ) 1466e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe{ 1467e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe // !!! keep switch in sync with get_Form_contents : the nr of bytes 1468e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe // read from a cursor by get_Form_contents must be returned by 1469e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe // the below switch. 1470e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe // The consistency is verified in trace_DIE. 1471e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe switch (form) { 1472e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_data1: return 1; 1473e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_data2: return 2; 1474e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_data4: return 4; 1475e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_data8: return 8; 1476e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_sec_offset: 1477e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe if (cc->is_dw64) 1478e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return 8; 1479e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe else 1480e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return 4; 1481e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_sdata: 1482e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return VARSZ_FORM; 1483e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_udata: 1484e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return VARSZ_FORM; 1485e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_addr: // See hack in get_Form_contents 1486e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return sizeof(UWord); 1487e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_ref_addr: // See hack in get_Form_contents 1488e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe if (cc->version == 2) 1489e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return sizeof(UWord); 1490e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe else 1491e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return sizeof_Dwarfish_UWord (cc->is_dw64); 1492e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_strp: 1493e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return sizeof_Dwarfish_UWord (cc->is_dw64); 1494e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_string: 1495e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return VARSZ_FORM; 1496e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_ref1: 1497e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return 1; 1498e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_ref2: 1499e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return 2; 1500e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_ref4: 1501e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return 4; 1502e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_ref8: 1503e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return 8; 1504e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_ref_udata: 1505e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return VARSZ_FORM; 1506e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_flag: 1507e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return 1; 1508e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_flag_present: 1509e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return 0; // !!! special case, no data. 1510e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_block1: 1511e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return VARSZ_FORM; 1512e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_block2: 1513e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return VARSZ_FORM; 1514e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_block4: 1515e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return VARSZ_FORM; 1516e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_exprloc: 1517e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_block: 1518e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return VARSZ_FORM; 1519e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_ref_sig8: 1520d4636ab82334c239c311b296cba66cc559048e36philippe return 8; 1521e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_indirect: 1522e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return VARSZ_FORM; 1523e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_GNU_ref_alt: 1524e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return sizeof_Dwarfish_UWord(cc->is_dw64); 1525e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe case DW_FORM_GNU_strp_alt: 1526e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe return sizeof_Dwarfish_UWord(cc->is_dw64); 1527e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe default: 1528e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe VG_(printf)( 1529c6e5d76e9eea8625f385ff844545c688c91938daflorian "get_Form_szB: unhandled %u (%s)\n", 1530e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe form, ML_(pp_DW_FORM)(form)); 1531e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe cc->barf("get_Form_contents: unhandled DW_FORM"); 1532e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe } 1533e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe} 1534e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe 1535e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe/* Skip a DIE as described by abbv. 1536e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe If the DIE has a sibling, *sibling is set to the skipped DIE sibling value. */ 1537e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippestatic 1538e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippevoid skip_DIE (UWord *sibling, 1539e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe Cursor* c_die, 1540518850bf0da07ed3e2244e307268ae0fd80e93a8florian const g_abbv *abbv, 1541518850bf0da07ed3e2244e307268ae0fd80e93a8florian const CUConst* cc) 1542e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe{ 1543e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe UInt nf_i; 1544e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe FormContents cts; 1545e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe nf_i = 0; 1546e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe while (True) { 1547e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe if (abbv->nf[nf_i].at_name == DW_AT_sibling) { 1548e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe get_Form_contents( &cts, cc, c_die, False /*td3*/, 1549e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe (DW_FORM)abbv->nf[nf_i].at_form ); 1550e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe if ( cts.szB > 0 ) 1551e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe *sibling = cts.u.val; 1552e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe nf_i++; 1553e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe } else if (abbv->nf[nf_i].skip_szB == VARSZ_FORM) { 1554e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe get_Form_contents( &cts, cc, c_die, False /*td3*/, 1555e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe (DW_FORM)abbv->nf[nf_i].at_form ); 1556e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe nf_i++; 1557e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe } else { 1558e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe advance_position_of_Cursor (c_die, (ULong)abbv->nf[nf_i].skip_szB); 1559e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe nf_i = abbv->nf[nf_i].next_nf; 1560e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe } 1561e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe if (nf_i == 0) 1562e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe break; 1563e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe } 1564e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe} 1565e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe 1566b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1567b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 1568b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 1569b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- Parsing of variable-related DIEs ---*/ 1570b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 1571b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 1572b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1573b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjtypedef 1574b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj struct _TempVar { 15751ef70c6f00ab1b50d1936f77037e9923d8ed8c59florian const HChar* name; /* in DebugInfo's .strpool */ 1576b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Represent ranges economically. nRanges is the number of 1577b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ranges. Cases: 1578b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 0: .rngOneMin .rngOneMax .manyRanges are all zero 1579b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1: .rngOneMin .rngOneMax hold the range; .rngMany is NULL 1580b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2: .rngOneMin .rngOneMax are zero; .rngMany holds the ranges. 1581b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj This is merely an optimisation to avoid having to allocate 1582b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj and free the XArray in the common (98%) of cases where there 1583b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj is zero or one address ranges. */ 1584b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord nRanges; 1585b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr rngOneMin; 1586b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr rngOneMax; 15879c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj XArray* rngMany; /* of AddrRange. NON-UNIQUE PTR in AR_DINFO. */ 15889c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* Do not free .rngMany, since many TempVars will have the same 15899c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj value. Instead the associated storage is to be freed by 15909c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj deleting 'rangetree', which stores a single copy of each 15919c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj range. */ 1592b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* --- */ 1593b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Int level; 15949c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj UWord typeR; /* a cuOff */ 1595b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj GExpr* gexpr; /* for this variable */ 1596b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj GExpr* fbGX; /* to find the frame base of the enclosing fn, if 1597b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj any */ 1598666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe UInt fndn_ix; /* declaring file/dirname index in fndnpool, or 0 */ 1599b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Int fLine; /* declaring file line number, or zero */ 1600b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* offset in .debug_info, so that abstract instances can be 1601b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj found to satisfy references from concrete instances. */ 1602b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord dioff; 1603b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord absOri; /* so the absOri fields refer to dioff fields 1604b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj in some other, related TempVar. */ 1605b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1606b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TempVar; 1607b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1608b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjtypedef 1609b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj struct { 1610b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Contains the range stack: a stack of address ranges, one 1611b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj stack entry for each nested scope. 1612b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1613b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Some scope entries are created by function definitions 1614b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (DW_AT_subprogram), and for those, we also note the GExpr 1615b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj derived from its DW_AT_frame_base attribute, if any. 1616b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Consequently it should be possible to find, for any 1617ad4e979f408239dabbaae955d8ffcb84a51a5c85florian variable's DIE, the GExpr for the containing function's 1618b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_frame_base by scanning back through the stack to find 1619b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj the nearest entry associated with a function. This somewhat 1620b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj elaborate scheme is provided so as to make it possible to 1621b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj obtain the correct DW_AT_frame_base expression even in the 1622b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj presence of nested functions (or to be more precise, in the 1623b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj presence of nested DW_AT_subprogram DIEs). 1624b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj */ 1625b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Int sp; /* [sp] is innermost active entry; sp==-1 for empty 1626b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj stack */ 1627611fd68095bd837171574815cceb2225ed2aeb9dflorian Int stack_size; 1628611fd68095bd837171574815cceb2225ed2aeb9dflorian XArray **ranges; /* XArray of AddrRange */ 1629611fd68095bd837171574815cceb2225ed2aeb9dflorian Int *level; /* D3 DIE levels */ 1630611fd68095bd837171574815cceb2225ed2aeb9dflorian Bool *isFunc; /* from DW_AT_subprogram? */ 1631611fd68095bd837171574815cceb2225ed2aeb9dflorian GExpr **fbGX; /* if isFunc, contains the FB expr, else NULL */ 1632666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe /* The fndn_ix file name/dirname table. Is a mapping from dwarf 1633666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe integer index to the index in di->fndnpool. */ 1634666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe XArray* /* of UInt* */ fndn_ix_Table; 1635b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1636b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj D3VarParser; 1637b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1638611fd68095bd837171574815cceb2225ed2aeb9dflorian/* Completely initialise a variable parser object */ 1639611fd68095bd837171574815cceb2225ed2aeb9dflorianstatic void 1640611fd68095bd837171574815cceb2225ed2aeb9dflorianvar_parser_init ( D3VarParser *parser ) 1641611fd68095bd837171574815cceb2225ed2aeb9dflorian{ 1642611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->sp = -1; 1643611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->stack_size = 0; 1644611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->ranges = NULL; 1645611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->level = NULL; 1646611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->isFunc = NULL; 1647611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->fbGX = NULL; 1648611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->fndn_ix_Table = NULL; 1649611fd68095bd837171574815cceb2225ed2aeb9dflorian} 1650611fd68095bd837171574815cceb2225ed2aeb9dflorian 1651611fd68095bd837171574815cceb2225ed2aeb9dflorian/* Release any memory hanging off a variable parser object */ 1652611fd68095bd837171574815cceb2225ed2aeb9dflorianstatic void 1653611fd68095bd837171574815cceb2225ed2aeb9dflorianvar_parser_release ( D3VarParser *parser ) 1654611fd68095bd837171574815cceb2225ed2aeb9dflorian{ 1655611fd68095bd837171574815cceb2225ed2aeb9dflorian ML_(dinfo_free)( parser->ranges ); 1656611fd68095bd837171574815cceb2225ed2aeb9dflorian ML_(dinfo_free)( parser->level ); 1657611fd68095bd837171574815cceb2225ed2aeb9dflorian ML_(dinfo_free)( parser->isFunc ); 1658611fd68095bd837171574815cceb2225ed2aeb9dflorian ML_(dinfo_free)( parser->fbGX ); 1659611fd68095bd837171574815cceb2225ed2aeb9dflorian} 1660611fd68095bd837171574815cceb2225ed2aeb9dflorian 1661518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic void varstack_show ( const D3VarParser* parser, const HChar* str ) 1662518850bf0da07ed3e2244e307268ae0fd80e93a8florian{ 1663b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Word i, j; 1664b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(printf)(" varstack (%s) {\n", str); 1665b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj for (i = 0; i <= parser->sp; i++) { 1666b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj XArray* xa = parser->ranges[i]; 1667b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(xa); 1668b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(printf)(" [%ld] (level %d)", i, parser->level[i]); 1669b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (parser->isFunc[i]) { 1670b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(printf)(" (fbGX=%p)", parser->fbGX[i]); 1671b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else { 1672b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(parser->fbGX[i] == NULL); 1673b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1674b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(printf)(": "); 1675b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (VG_(sizeXA)( xa ) == 0) { 1676b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(printf)("** empty PC range array **"); 1677b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else { 1678b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj for (j = 0; j < VG_(sizeXA)( xa ); j++) { 1679b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj AddrRange* range = (AddrRange*) VG_(indexXA)( xa, j ); 1680b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(range); 1681a0b6b2cf9abc7b0d87be1215a245eaccc0452af9bart VG_(printf)("[%#lx,%#lx] ", range->aMin, range->aMax); 1682b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1683b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1684b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(printf)("\n"); 1685b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1686b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(printf)(" }\n"); 1687b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 1688b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1689b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* Remove from the stack, all entries with .level > 'level' */ 1690b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic 1691b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjvoid varstack_preen ( D3VarParser* parser, Bool td3, Int level ) 1692b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 1693b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool changed = False; 1694611fd68095bd837171574815cceb2225ed2aeb9dflorian vg_assert(parser->sp < parser->stack_size); 1695b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 1696b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(parser->sp >= -1); 1697b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (parser->sp == -1) break; 1698b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (parser->level[parser->sp] <= level) break; 1699b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (0) 1700b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("BBBBAAAA varstack_pop [newsp=%d]\n", parser->sp-1); 1701b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(parser->ranges[parser->sp]); 1702b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Who allocated this xa? get_range_list() or 1703b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj unitary_range_list(). */ 1704b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(deleteXA)( parser->ranges[parser->sp] ); 1705b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->sp--; 1706b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj changed = True; 1707b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1708b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (changed && td3) 1709b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj varstack_show( parser, "after preen" ); 1710b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 1711b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1712518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic void varstack_push ( const CUConst* cc, 1713b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj D3VarParser* parser, 1714b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool td3, 1715b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj XArray* ranges, Int level, 1716b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool isFunc, GExpr* fbGX ) { 1717b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (0) 1718b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("BBBBAAAA varstack_push[newsp=%d]: %d %p\n", 1719b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->sp+1, level, ranges); 1720b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1721b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* First we need to zap everything >= 'level', as we are about to 1722b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj replace any previous entry at 'level', so .. */ 1723b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj varstack_preen(parser, /*td3*/False, level-1); 1724b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1725b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(parser->sp >= -1); 1726611fd68095bd837171574815cceb2225ed2aeb9dflorian vg_assert(parser->sp < parser->stack_size); 1727611fd68095bd837171574815cceb2225ed2aeb9dflorian if (parser->sp == parser->stack_size - 1) { 1728611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->stack_size += 48; 1729611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->ranges = 1730611fd68095bd837171574815cceb2225ed2aeb9dflorian ML_(dinfo_realloc)("di.readdwarf3.varpush.1", parser->ranges, 1731611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->stack_size * sizeof parser->ranges[0]); 1732611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->level = 1733611fd68095bd837171574815cceb2225ed2aeb9dflorian ML_(dinfo_realloc)("di.readdwarf3.varpush.2", parser->level, 1734611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->stack_size * sizeof parser->level[0]); 1735611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->isFunc = 1736611fd68095bd837171574815cceb2225ed2aeb9dflorian ML_(dinfo_realloc)("di.readdwarf3.varpush.3", parser->isFunc, 1737611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->stack_size * sizeof parser->isFunc[0]); 1738611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->fbGX = 1739611fd68095bd837171574815cceb2225ed2aeb9dflorian ML_(dinfo_realloc)("di.readdwarf3.varpush.4", parser->fbGX, 1740611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->stack_size * sizeof parser->fbGX[0]); 1741611fd68095bd837171574815cceb2225ed2aeb9dflorian } 1742b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (parser->sp >= 0) 1743b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(parser->level[parser->sp] < level); 1744b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->sp++; 1745b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(ranges != NULL); 1746b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (!isFunc) vg_assert(fbGX == NULL); 1747b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->ranges[parser->sp] = ranges; 1748b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->level[parser->sp] = level; 1749b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->isFunc[parser->sp] = isFunc; 1750b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->fbGX[parser->sp] = fbGX; 1751e0bd5910153720d5d15697db8063d0d4caa59d8fphilippe if (TD3) 1752b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj varstack_show( parser, "after push" ); 1753b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 1754b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1755b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 17565d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj/* cts is derived from a DW_AT_location and so refers either to a 17575d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj location expression or to a location list. Figure out which, and 17585d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj in both cases bundle the expression or location list into a 17595d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj so-called GExpr (guarded expression). */ 1760b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj__attribute__((noinline)) 1761518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic GExpr* get_GX ( const CUConst* cc, Bool td3, const FormContents* cts ) 1762b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 1763b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj GExpr* gexpr = NULL; 17645d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (cts->szB < 0) { 17655d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj /* represents a non-empty in-line location expression, and 17665d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cts->u.cur points at the image bytes */ 17675d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj gexpr = make_singleton_GX( cts->u.cur, (ULong)(- cts->szB) ); 1768b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1769b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj else 17705d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (cts->szB > 0) { 17715d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj /* represents a location list. cts->u.val is the offset of it 17725d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj in .debug_loc. */ 1773b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (!cc->cu_svma_known) 1774b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->barf("get_GX: location list, but CU svma is unknown"); 17755d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj gexpr = make_general_GX( cc, td3, cts->u.val, cc->cu_svma ); 1776b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1777b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj else { 1778b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(0); /* else caller is bogus */ 1779b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1780b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return gexpr; 1781b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 1782b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1783666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe/* Returns an xarray* of directory names (indexed by the dwarf dirname 1784666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe integer). 1785666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe If 'compdir' is NULL, entry [0] will be set to "." 1786666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe otherwise entry [0] is set to compdir. 1787666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe Entry [0] basically means "the current directory of the compilation", 1788666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe whatever that means, according to the DWARF3 spec. 1789666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe FIXME??? readdwarf3.c/readdwarf.c have a lot of duplicated code */ 1790666ee9df4c2b6d801b199b8168208dbb46573c9dphilippestatic 1791518850bf0da07ed3e2244e307268ae0fd80e93a8florianXArray* read_dirname_xa (DebugInfo* di, const HChar *compdir, 1792666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe Cursor *c, 1793666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe Bool td3 ) 1794666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe{ 1795666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe XArray* dirname_xa; /* xarray of HChar* dirname */ 1796666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe const HChar* dirname; 1797c505820a8b10066dcbdcc7ab36b8ae55bd671575florian UInt compdir_len; 1798666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe 1799666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe dirname_xa = VG_(newXA) (ML_(dinfo_zalloc), "di.rdxa.1", ML_(dinfo_free), 1800666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe sizeof(HChar*) ); 1801666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe 1802666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe if (compdir == NULL) { 1803666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe dirname = "."; 1804c505820a8b10066dcbdcc7ab36b8ae55bd671575florian compdir_len = 1; 1805666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe } else { 1806666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe dirname = compdir; 1807666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe compdir_len = VG_(strlen)(compdir); 1808666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe } 1809666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(addToXA) (dirname_xa, &dirname); 1810666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe 1811666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe TRACE_D3(" The Directory Table%s\n", 1812666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe peek_UChar(c) == 0 ? " is empty." : ":" ); 1813666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe 1814666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe while (peek_UChar(c) != 0) { 1815666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe 1816666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe DiCursor cur = get_AsciiZ(c); 1817666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe HChar* data_str = ML_(cur_read_strdup)( cur, "dirname_xa.1" ); 1818666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe TRACE_D3(" %s\n", data_str); 1819666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe 1820666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe /* If data_str[0] is '/', then 'data' is an absolute path and we 1821c505820a8b10066dcbdcc7ab36b8ae55bd671575florian don't mess with it. Otherwise, construct the 1822666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe path 'compdir' ++ "/" ++ 'data'. */ 1823666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe 1824666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe if (data_str[0] != '/' 1825666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe /* not an absolute path */ 1826666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe && compdir 1827666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe /* actually got something sensible for compdir */ 1828c505820a8b10066dcbdcc7ab36b8ae55bd671575florian && compdir_len) 1829666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe { 1830c505820a8b10066dcbdcc7ab36b8ae55bd671575florian SizeT len = compdir_len + 1 + VG_(strlen)(data_str); 1831c505820a8b10066dcbdcc7ab36b8ae55bd671575florian HChar *buf = ML_(dinfo_zalloc)("dirname_xa.2", len + 1); 1832c505820a8b10066dcbdcc7ab36b8ae55bd671575florian 1833c505820a8b10066dcbdcc7ab36b8ae55bd671575florian VG_(strcpy)(buf, compdir); 1834666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(strcat)(buf, "/"); 1835666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(strcat)(buf, data_str); 1836c505820a8b10066dcbdcc7ab36b8ae55bd671575florian 1837c505820a8b10066dcbdcc7ab36b8ae55bd671575florian dirname = ML_(addStr)(di, buf, len); 1838666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(addToXA) (dirname_xa, &dirname); 1839666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe if (0) VG_(printf)("rel path %s\n", buf); 1840c505820a8b10066dcbdcc7ab36b8ae55bd671575florian ML_(dinfo_free)(buf); 1841666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe } else { 1842666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe /* just use 'data'. */ 1843666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe dirname = ML_(addStr)(di,data_str,-1); 1844666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(addToXA) (dirname_xa, &dirname); 1845666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe if (0) VG_(printf)("abs path %s\n", data_str); 1846666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe } 1847666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe 1848666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe ML_(dinfo_free)(data_str); 1849666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe } 1850666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe 1851666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe TRACE_D3 ("\n"); 1852666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe 1853666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe if (get_UChar (c) != 0) { 1854666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe ML_(symerr)(NULL, True, 1855666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe "could not get NUL at end of DWARF directory table"); 1856666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(deleteXA)(dirname_xa); 1857666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe return NULL; 1858666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe } 1859666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe 1860666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe return dirname_xa; 1861666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe} 1862b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1863b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic 1864666ee9df4c2b6d801b199b8168208dbb46573c9dphilippevoid read_filename_table( /*MOD*/XArray* /* of UInt* */ fndn_ix_Table, 18651ef70c6f00ab1b50d1936f77037e9923d8ed8c59florian const HChar* compdir, 1866518850bf0da07ed3e2244e307268ae0fd80e93a8florian const CUConst* cc, ULong debug_line_offset, 1867b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool td3 ) 1868b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 1869b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool is_dw64; 1870b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Cursor c; 1871b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Word i; 1872b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UShort version; 1873b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar opcode_base; 1874518850bf0da07ed3e2244e307268ae0fd80e93a8florian const HChar* str; 1875666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe XArray* dirname_xa; /* xarray of HChar* dirname */ 1876666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe ULong dir_xa_ix; /* Index in dirname_xa, as read from dwarf info. */ 1877518850bf0da07ed3e2244e307268ae0fd80e93a8florian const HChar* dirname; 1878666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe UInt fndn_ix; 1879b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1880666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe vg_assert(fndn_ix_Table && cc && cc->barf); 18815d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (!ML_(sli_is_valid)(cc->escn_debug_line) 18825d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj || cc->escn_debug_line.szB <= debug_line_offset) { 1883b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->barf("read_filename_table: .debug_line is missing?"); 18845d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj } 1885b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 18865d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj init_Cursor( &c, cc->escn_debug_line, debug_line_offset, cc->barf, 1887b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj "Overrun whilst reading .debug_line section(1)" ); 1888b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 18894c245e595b9f6300d3120408ca873f7115d9cc7dnjn /* unit_length = */ 1890e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe get_Initial_Length( &is_dw64, &c, 1891e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe "read_filename_table: invalid initial-length field" ); 1892b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj version = get_UShort( &c ); 1893fba428cd266b8a39db641c5fd9523daa8939bed0tom if (version != 2 && version != 3 && version != 4) 1894fba428cd266b8a39db641c5fd9523daa8939bed0tom cc->barf("read_filename_table: Only DWARF version 2, 3 and 4 line info " 1895b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj "is currently supported."); 18964c245e595b9f6300d3120408ca873f7115d9cc7dnjn /*header_length = (ULong)*/ get_Dwarfish_UWord( &c, is_dw64 ); 18974c245e595b9f6300d3120408ca873f7115d9cc7dnjn /*minimum_instruction_length = */ get_UChar( &c ); 1898fba428cd266b8a39db641c5fd9523daa8939bed0tom if (version >= 4) 1899fba428cd266b8a39db641c5fd9523daa8939bed0tom /*maximum_operations_per_insn = */ get_UChar( &c ); 19004c245e595b9f6300d3120408ca873f7115d9cc7dnjn /*default_is_stmt = */ get_UChar( &c ); 19014c245e595b9f6300d3120408ca873f7115d9cc7dnjn /*line_base = (Char)*/ get_UChar( &c ); 19024c245e595b9f6300d3120408ca873f7115d9cc7dnjn /*line_range = */ get_UChar( &c ); 1903b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj opcode_base = get_UChar( &c ); 1904b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* skip over "standard_opcode_lengths" */ 1905b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj for (i = 1; i < (Word)opcode_base; i++) 1906b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (void)get_UChar( &c ); 1907b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1908666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe dirname_xa = read_dirname_xa(cc->di, compdir, &c, td3); 1909b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1910b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Read and record the file names table */ 1911666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe vg_assert( VG_(sizeXA)( fndn_ix_Table ) == 0 ); 1912b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Add a dummy index-zero entry. DWARF3 numbers its files 1913b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj from 1, for some reason. */ 1914666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe fndn_ix = ML_(addFnDn) ( cc->di, "<unknown_file>", NULL ); 1915666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(addToXA)( fndn_ix_Table, &fndn_ix ); 1916b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (peek_UChar(&c) != 0) { 19175d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiCursor cur = get_AsciiZ(&c); 19185d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj str = ML_(addStrFromCursor)( cc->di, cur ); 1919666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe dir_xa_ix = get_ULEB128( &c ); 1920666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe if (dirname_xa != NULL 1921666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe && dir_xa_ix >= 0 && dir_xa_ix < VG_(sizeXA) (dirname_xa)) 1922666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe dirname = *(HChar**)VG_(indexXA) ( dirname_xa, dir_xa_ix ); 1923666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe else 1924666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe dirname = NULL; 1925666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe fndn_ix = ML_(addFnDn)( cc->di, str, dirname); 1926c6e5d76e9eea8625f385ff844545c688c91938daflorian TRACE_D3(" read_filename_table: %ld fndn_ix %u %s %s\n", 1927666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(sizeXA)(fndn_ix_Table), fndn_ix, 1928666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe dirname, str); 1929666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(addToXA)( fndn_ix_Table, &fndn_ix ); 1930b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (void)get_ULEB128( &c ); /* skip last mod time */ 1931b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (void)get_ULEB128( &c ); /* file size */ 1932b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 1933b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* We're done! The rest of it is not interesting. */ 1934666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe if (dirname_xa != NULL) 1935666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(deleteXA)(dirname_xa); 1936b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 1937b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 1938a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe/* setup_cu_svma to be called when a cu is found at level 0, 1939a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe to establish the cu_svma. */ 1940a0a73939b0398b6608fd6dbde49820ce6530d12cphilippestatic void setup_cu_svma(CUConst* cc, Bool have_lo, Addr ip_lo, Bool td3) 1941a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe{ 1942a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Addr cu_svma; 1943a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* We have potentially more than one type of parser parsing the 1944a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe dwarf information. At least currently, each parser establishes 1945a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe the cu_svma. So, in case cu_svma_known, we check that the same 1946a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe result is obtained by the 2nd parsing of the cu. 1947a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 1948a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Alternatively, we could reset cu_svma_known after each parsing 1949a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe and then check that we only see a single DW_TAG_compile_unit DIE 1950a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe at level 0, DWARF3 only allows exactly one top level DIE per 1951a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe CU. */ 1952a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 1953a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (have_lo) 1954a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cu_svma = ip_lo; 1955a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe else { 1956a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Now, it may be that this DIE doesn't tell us the CU's 1957a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe SVMA, by way of not having a DW_AT_low_pc. That's OK -- 1958a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe the CU doesn't *have* to have its SVMA specified. 1959a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 1960a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe But as per last para D3 spec sec 3.1.1 ("Normal and 1961a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Partial Compilation Unit Entries", "If the base address 1962a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe (viz, the SVMA) is undefined, then any DWARF entry of 1963a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe structure defined interms of the base address of that 1964a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe compilation unit is not valid.". So that means, if whilst 1965a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe processing the children of this top level DIE (or their 1966a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe children, etc) we see a DW_AT_range, and cu_svma_known is 1967a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe False, then the DIE that contains it is (per the spec) 1968a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe invalid, and we can legitimately stop and complain. */ 1969a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* .. whereas The Reality is, simply assume the SVMA is zero 1970a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if it isn't specified. */ 1971a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cu_svma = 0; 1972a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 1973a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 1974a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (cc->cu_svma_known) { 1975a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert (cu_svma == cc->cu_svma); 1976a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } else { 1977a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc->cu_svma_known = True; 1978a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc->cu_svma = cu_svma; 1979a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (0) 1980a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("setup_cu_svma: acquire CU_SVMA of %p\n", (void*) cc->cu_svma); 1981a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 1982a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe} 1983a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 198486be6ed340d2373ffded269f57aa87765430ddccphilippestatic void trace_DIE( 1985a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe DW_TAG dtag, 1986a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe UWord posn, 1987a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Int level, 198886be6ed340d2373ffded269f57aa87765430ddccphilippe UWord saved_die_c_offset, 1989518850bf0da07ed3e2244e307268ae0fd80e93a8florian const g_abbv *abbv, 1990518850bf0da07ed3e2244e307268ae0fd80e93a8florian const CUConst* cc) 1991a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe{ 199286be6ed340d2373ffded269f57aa87765430ddccphilippe Cursor c; 1993a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe FormContents cts; 1994e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe UWord sibling = 0; 1995a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe UInt nf_i; 1996a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Bool debug_types_flag; 1997a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Bool alt_flag; 1998e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe Cursor check_skip; 1999e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe UWord check_sibling = 0; 2000a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2001a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe posn = uncook_die( cc, posn, &debug_types_flag, &alt_flag ); 200286be6ed340d2373ffded269f57aa87765430ddccphilippe init_Cursor (&c, 200386be6ed340d2373ffded269f57aa87765430ddccphilippe debug_types_flag ? cc->escn_debug_types : 200486be6ed340d2373ffded269f57aa87765430ddccphilippe alt_flag ? cc->escn_debug_info_alt : cc->escn_debug_info, 200586be6ed340d2373ffded269f57aa87765430ddccphilippe saved_die_c_offset, cc->barf, 200686be6ed340d2373ffded269f57aa87765430ddccphilippe "Overrun trace_DIE"); 2007e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe check_skip = c; 200886be6ed340d2373ffded269f57aa87765430ddccphilippe VG_(printf)(" <%d><%lx>: Abbrev Number: %llu (%s)%s%s\n", 200986be6ed340d2373ffded269f57aa87765430ddccphilippe level, posn, (ULong) abbv->abbv_code, ML_(pp_DW_TAG)( dtag ), 201086be6ed340d2373ffded269f57aa87765430ddccphilippe debug_types_flag ? " (in .debug_types)" : "", 201186be6ed340d2373ffded269f57aa87765430ddccphilippe alt_flag ? " (in alternate .debug_info)" : ""); 2012a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe nf_i = 0; 2013a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe while (True) { 2014a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 2015a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 2016a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe nf_i++; 2017a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (attr == 0 && form == 0) break; 2018866862a87a06a70e2e0c0d7e5c773e252db8ecddflorian VG_(printf)(" %-18s: ", ML_(pp_DW_AT)(attr)); 2019a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Get the form contents, so as to print them */ 202086be6ed340d2373ffded269f57aa87765430ddccphilippe get_Form_contents( &cts, cc, &c, True, form ); 2021e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe if (attr == DW_AT_sibling && cts.szB > 0) { 2022e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe sibling = cts.u.val; 2023e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe } 2024a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(printf)("\t\n"); 2025a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2026e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe 2027e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe /* Verify that skipping a DIE gives the same displacement as 2028e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe tracing (i.e. reading) a DIE. If there is an inconsistency in 2029e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe the nr of bytes read by get_Form_contents and get_Form_szB, this 2030e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe should be detected by the below. Using --trace-symtab=yes 2031e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe --read-var-info=yes will ensure all DIEs are systematically 2032e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe verified. */ 2033e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe skip_DIE (&check_sibling, &check_skip, abbv, cc); 2034e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe vg_assert (check_sibling == sibling); 2035e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe vg_assert (get_position_of_Cursor (&check_skip) 2036e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe == get_position_of_Cursor (&c)); 203786be6ed340d2373ffded269f57aa87765430ddccphilippe} 203886be6ed340d2373ffded269f57aa87765430ddccphilippe 203986be6ed340d2373ffded269f57aa87765430ddccphilippe__attribute__((noreturn)) 204086be6ed340d2373ffded269f57aa87765430ddccphilippestatic void dump_bad_die_and_barf( 204186be6ed340d2373ffded269f57aa87765430ddccphilippe const HChar *whichparser, 204286be6ed340d2373ffded269f57aa87765430ddccphilippe DW_TAG dtag, 204386be6ed340d2373ffded269f57aa87765430ddccphilippe UWord posn, 204486be6ed340d2373ffded269f57aa87765430ddccphilippe Int level, 204586be6ed340d2373ffded269f57aa87765430ddccphilippe Cursor* c_die, 204686be6ed340d2373ffded269f57aa87765430ddccphilippe UWord saved_die_c_offset, 2047518850bf0da07ed3e2244e307268ae0fd80e93a8florian const g_abbv *abbv, 2048518850bf0da07ed3e2244e307268ae0fd80e93a8florian const CUConst* cc) 204986be6ed340d2373ffded269f57aa87765430ddccphilippe{ 205086be6ed340d2373ffded269f57aa87765430ddccphilippe trace_DIE (dtag, posn, level, saved_die_c_offset, abbv, cc); 205186be6ed340d2373ffded269f57aa87765430ddccphilippe VG_(printf)("%s:\n", whichparser); 2052896a3bfd1b98aa3358a2e77be3bb728cb3d2926fphilippe cc->barf("confused by the above DIE"); 2053a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe} 2054a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 20555c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe__attribute__((noinline)) 20565c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippestatic void bad_DIE_confusion(int linenr) 20575c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe{ 2058896a3bfd1b98aa3358a2e77be3bb728cb3d2926fphilippe VG_(printf)("\nparse DIE(readdwarf3.c:%d): confused by:\n", linenr); 20595c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe} 20605c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe#define goto_bad_DIE do {bad_DIE_confusion(__LINE__); goto bad_DIE;} while (0) 2061b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2062b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj__attribute__((noinline)) 20639c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjstatic void parse_var_DIE ( 20649c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/WordFM* /* of (XArray* of AddrRange, void) */ rangestree, 20659c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/XArray* /* of TempVar* */ tempvars, 20669c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/XArray* /* of GExpr* */ gexprs, 20679c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/D3VarParser* parser, 20689c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj DW_TAG dtag, 20699c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj UWord posn, 20709c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Int level, 20719c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Cursor* c_die, 2072518850bf0da07ed3e2244e307268ae0fd80e93a8florian const g_abbv *abbv, 20739c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj CUConst* cc, 20749c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Bool td3 20759c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj) 2076b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 20775d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj FormContents cts; 2078746e97e7098def65d59c79d5d661f9a757a837cdphilippe UInt nf_i; 2079b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2080b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord saved_die_c_offset = get_position_of_Cursor( c_die ); 2081b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2082b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj varstack_preen( parser, td3, level-1 ); 2083b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2084f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj if (dtag == DW_TAG_compile_unit 2085f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj || dtag == DW_TAG_type_unit 2086f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj || dtag == DW_TAG_partial_unit) { 2087b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool have_lo = False; 2088b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool have_hi1 = False; 2089de065a05bd7e802669c9074b129268bd9a5c308csewardj Bool hiIsRelative = False; 2090b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool have_range = False; 2091b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr ip_lo = 0; 2092b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr ip_hi1 = 0; 2093b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr rangeoff = 0; 20941ef70c6f00ab1b50d1936f77037e9923d8ed8c59florian const HChar *compdir = NULL; 2095746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 2096b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 2097746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 2098746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 2099746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 2100b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 21015d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 21025d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_low_pc && cts.szB > 0) { 21035d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ip_lo = cts.u.val; 2104b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj have_lo = True; 2105b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 21065d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_high_pc && cts.szB > 0) { 21075d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ip_hi1 = cts.u.val; 2108b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj have_hi1 = True; 2109de065a05bd7e802669c9074b129268bd9a5c308csewardj if (form != DW_FORM_addr) 2110de065a05bd7e802669c9074b129268bd9a5c308csewardj hiIsRelative = True; 2111b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 21125d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_ranges && cts.szB > 0) { 21135d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj rangeoff = cts.u.val; 2114b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj have_range = True; 2115b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2116666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe if (attr == DW_AT_comp_dir) { 2117666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe if (cts.szB >= 0) 2118666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe cc->barf("parse_var_DIE compdir: expecting indirect string"); 2119666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe HChar *str = ML_(cur_read_strdup)( cts.u.cur, 2120666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe "parse_var_DIE.compdir" ); 2121666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe compdir = ML_(addStr)(cc->di, str, -1); 2122666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe ML_(dinfo_free) (str); 2123666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe } 21245d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_stmt_list && cts.szB > 0) { 2125666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe read_filename_table( parser->fndn_ix_Table, compdir, 2126666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe cc, cts.u.val, td3 ); 2127b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2128b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2129de065a05bd7e802669c9074b129268bd9a5c308csewardj if (have_lo && have_hi1 && hiIsRelative) 2130de065a05bd7e802669c9074b129268bd9a5c308csewardj ip_hi1 += ip_lo; 2131a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2132b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Now, does this give us an opportunity to find this 2133b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj CU's svma? */ 2134a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (level == 0) 2135a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe setup_cu_svma(cc, have_lo, ip_lo, td3); 2136a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2137b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Do we have something that looks sane? */ 2138b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (have_lo && have_hi1 && (!have_range)) { 2139b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (ip_lo < ip_hi1) 2140b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj varstack_push( cc, parser, td3, 2141b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj unitary_range_list(ip_lo, ip_hi1 - 1), 2142b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj level, 2143b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj False/*isFunc*/, NULL/*fbGX*/ ); 21448130f91dc99a9ad90e516f8b449970ddaeaee911philippe else if (ip_lo == 0 && ip_hi1 == 0) 21458130f91dc99a9ad90e516f8b449970ddaeaee911philippe /* CU has no code, presumably? 21468130f91dc99a9ad90e516f8b449970ddaeaee911philippe Such situations have been encountered for code 21478130f91dc99a9ad90e516f8b449970ddaeaee911philippe compiled with -ffunction-sections -fdata-sections 21488130f91dc99a9ad90e516f8b449970ddaeaee911philippe and linked with --gc-sections. Completely 21498130f91dc99a9ad90e516f8b449970ddaeaee911philippe eliminated CU gives such 0 lo/hi pc. Similarly 21508130f91dc99a9ad90e516f8b449970ddaeaee911philippe to a CU which has no lo/hi/range pc, we push 21518130f91dc99a9ad90e516f8b449970ddaeaee911philippe an empty range list. */ 21528130f91dc99a9ad90e516f8b449970ddaeaee911philippe varstack_push( cc, parser, td3, 21538130f91dc99a9ad90e516f8b449970ddaeaee911philippe empty_range_list(), 21548130f91dc99a9ad90e516f8b449970ddaeaee911philippe level, 21558130f91dc99a9ad90e516f8b449970ddaeaee911philippe False/*isFunc*/, NULL/*fbGX*/ ); 2156b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else 2157b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if ((!have_lo) && (!have_hi1) && have_range) { 2158b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj varstack_push( cc, parser, td3, 2159b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj get_range_list( cc, td3, 2160b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj rangeoff, cc->cu_svma ), 2161b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj level, 2162b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj False/*isFunc*/, NULL/*fbGX*/ ); 2163b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else 2164b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if ((!have_lo) && (!have_hi1) && (!have_range)) { 2165b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* CU has no code, presumably? */ 2166b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj varstack_push( cc, parser, td3, 2167b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj empty_range_list(), 2168b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj level, 2169b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj False/*isFunc*/, NULL/*fbGX*/ ); 2170b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else 2171f578a69a862391896fa2f03359c3744022ae9783sewardj if (have_lo && (!have_hi1) && have_range && ip_lo == 0) { 2172f578a69a862391896fa2f03359c3744022ae9783sewardj /* broken DIE created by gcc-4.3.X ? Ignore the 2173f578a69a862391896fa2f03359c3744022ae9783sewardj apparently-redundant DW_AT_low_pc and use the DW_AT_ranges 2174f578a69a862391896fa2f03359c3744022ae9783sewardj instead. */ 2175f578a69a862391896fa2f03359c3744022ae9783sewardj varstack_push( cc, parser, td3, 2176f578a69a862391896fa2f03359c3744022ae9783sewardj get_range_list( cc, td3, 2177f578a69a862391896fa2f03359c3744022ae9783sewardj rangeoff, cc->cu_svma ), 2178f578a69a862391896fa2f03359c3744022ae9783sewardj level, 2179f578a69a862391896fa2f03359c3744022ae9783sewardj False/*isFunc*/, NULL/*fbGX*/ ); 2180f578a69a862391896fa2f03359c3744022ae9783sewardj } else { 2181f578a69a862391896fa2f03359c3744022ae9783sewardj if (0) VG_(printf)("I got hlo %d hhi1 %d hrange %d\n", 2182f578a69a862391896fa2f03359c3744022ae9783sewardj (Int)have_lo, (Int)have_hi1, (Int)have_range); 21835c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 2184f578a69a862391896fa2f03359c3744022ae9783sewardj } 2185b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2186b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2187b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (dtag == DW_TAG_lexical_block || dtag == DW_TAG_subprogram) { 2188b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool have_lo = False; 2189b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool have_hi1 = False; 2190b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool have_range = False; 2191de065a05bd7e802669c9074b129268bd9a5c308csewardj Bool hiIsRelative = False; 2192b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr ip_lo = 0; 2193b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr ip_hi1 = 0; 2194b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr rangeoff = 0; 2195b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool isFunc = dtag == DW_TAG_subprogram; 2196b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj GExpr* fbGX = NULL; 2197746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 2198b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 2199746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 2200746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 2201746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 2202b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 22035d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 22045d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_low_pc && cts.szB > 0) { 22055d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ip_lo = cts.u.val; 2206b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj have_lo = True; 2207b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 22085d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_high_pc && cts.szB > 0) { 22095d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ip_hi1 = cts.u.val; 2210b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj have_hi1 = True; 2211de065a05bd7e802669c9074b129268bd9a5c308csewardj if (form != DW_FORM_addr) 2212de065a05bd7e802669c9074b129268bd9a5c308csewardj hiIsRelative = True; 2213b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 22145d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_ranges && cts.szB > 0) { 22155d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj rangeoff = cts.u.val; 2216b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj have_range = True; 2217b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2218b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (isFunc 2219b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj && attr == DW_AT_frame_base 22205d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj && cts.szB != 0 /* either scalar or nonempty block */) { 22215d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj fbGX = get_GX( cc, False/*td3*/, &cts ); 2222b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(fbGX); 222359a2d18d0ddfa241850017252b0804d469187d79sewardj VG_(addToXA)(gexprs, &fbGX); 2224b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2225b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2226de065a05bd7e802669c9074b129268bd9a5c308csewardj if (have_lo && have_hi1 && hiIsRelative) 2227de065a05bd7e802669c9074b129268bd9a5c308csewardj ip_hi1 += ip_lo; 2228b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Do we have something that looks sane? */ 2229b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (dtag == DW_TAG_subprogram 2230b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj && (!have_lo) && (!have_hi1) && (!have_range)) { 2231b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* This is legit - ignore it. Sec 3.3.3: "A subroutine entry 2232b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj representing a subroutine declaration that is not also a 2233b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj definition does not have code address or range 2234b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj attributes." */ 2235b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else 2236b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (dtag == DW_TAG_lexical_block 2237b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj && (!have_lo) && (!have_hi1) && (!have_range)) { 2238b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* I believe this is legit, and means the lexical block 2239b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj contains no insns (whatever that might mean). Ignore. */ 2240b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else 2241b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (have_lo && have_hi1 && (!have_range)) { 2242b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* This scope supplies just a single address range. */ 2243b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (ip_lo < ip_hi1) 2244b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj varstack_push( cc, parser, td3, 2245b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj unitary_range_list(ip_lo, ip_hi1 - 1), 2246b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj level, isFunc, fbGX ); 2247b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else 2248b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if ((!have_lo) && (!have_hi1) && have_range) { 2249b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* This scope supplies multiple address ranges via the use of 2250b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj a range list. */ 2251b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj varstack_push( cc, parser, td3, 2252b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj get_range_list( cc, td3, 2253b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj rangeoff, cc->cu_svma ), 2254b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj level, isFunc, fbGX ); 2255b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else 2256b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (have_lo && (!have_hi1) && (!have_range)) { 2257b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* This scope is bogus. The D3 spec sec 3.4 (Lexical Block 2258b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Entries) says fairly clearly that a scope must have either 2259b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj _range or (_low_pc and _high_pc). */ 2260b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* The spec is a bit ambiguous though. Perhaps a single byte 2261b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj range is intended? See sec 2.17 (Code Addresses And Ranges) */ 2262b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* This case is here because icc9 produced this: 2263b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj <2><13bd>: DW_TAG_lexical_block 2264b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_decl_line : 5229 2265b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_decl_column : 37 2266b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_decl_file : 1 2267b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_low_pc : 0x401b03 2268b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj */ 2269b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Ignore (seems safe than pushing a single byte range) */ 2270b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else 22715c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 2272b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2273b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2274b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (dtag == DW_TAG_variable || dtag == DW_TAG_formal_parameter) { 22751ef70c6f00ab1b50d1936f77037e9923d8ed8c59florian const HChar* name = NULL; 22769c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj UWord typeR = D3_INVALID_CUOFF; 227781d24c396c66dde7db2d9b567451f99081a2eab7philippe Bool global = False; 2278b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj GExpr* gexpr = NULL; 2279b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Int n_attrs = 0; 2280b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord abs_ori = (UWord)D3_INVALID_CUOFF; 2281b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Int lineNo = 0; 2282666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe UInt fndn_ix = 0; 2283746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 2284b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 2285746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 2286746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 2287746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 2288b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 22895d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 2290b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj n_attrs++; 22915d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_name && cts.szB < 0) { 22925d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj name = ML_(addStrFromCursor)( cc->di, cts.u.cur ); 2293b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2294b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == DW_AT_location 22955d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj && cts.szB != 0 /* either scalar or nonempty block */) { 22965d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj gexpr = get_GX( cc, False/*td3*/, &cts ); 2297b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(gexpr); 229859a2d18d0ddfa241850017252b0804d469187d79sewardj VG_(addToXA)(gexprs, &gexpr); 2299b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 23005d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_type && cts.szB > 0) { 23015d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj typeR = cook_die_using_form( cc, cts.u.val, form ); 2302b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 23035d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_external && cts.szB > 0 && cts.u.val > 0) { 230481d24c396c66dde7db2d9b567451f99081a2eab7philippe global = True; 2305b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 23065d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_abstract_origin && cts.szB > 0) { 23075d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj abs_ori = (UWord)cts.u.val; 2308b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 23095d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_declaration && cts.szB > 0 && cts.u.val > 0) { 23104c245e595b9f6300d3120408ca873f7115d9cc7dnjn /*declaration = True;*/ 2311b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 23125d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_decl_line && cts.szB > 0) { 23135d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj lineNo = (Int)cts.u.val; 2314b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 23155d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_decl_file && cts.szB > 0) { 23165d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj Int ftabIx = (Int)cts.u.val; 2317b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (ftabIx >= 1 2318666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe && ftabIx < VG_(sizeXA)( parser->fndn_ix_Table )) { 2319666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe fndn_ix = *(UInt*)VG_(indexXA)( parser->fndn_ix_Table, ftabIx ); 2320b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2321c6e5d76e9eea8625f385ff844545c688c91938daflorian if (0) VG_(printf)("XXX filename fndn_ix = %u %s\n", fndn_ix, 2322666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe ML_(fndn_ix2filename) (cc->di, fndn_ix)); 2323b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2324b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 232581d24c396c66dde7db2d9b567451f99081a2eab7philippe if (!global && dtag == DW_TAG_variable && level == 1) { 232681d24c396c66dde7db2d9b567451f99081a2eab7philippe /* Case of a static variable. It is better to declare 232781d24c396c66dde7db2d9b567451f99081a2eab7philippe it global as the variable is not really related to 232881d24c396c66dde7db2d9b567451f99081a2eab7philippe a PC range, as its address can be used by program 232981d24c396c66dde7db2d9b567451f99081a2eab7philippe counters outside of the ranges where it is visible . */ 233081d24c396c66dde7db2d9b567451f99081a2eab7philippe global = True; 233181d24c396c66dde7db2d9b567451f99081a2eab7philippe } 233281d24c396c66dde7db2d9b567451f99081a2eab7philippe 2333b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* We'll collect it under if one of the following three 2334b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj conditions holds: 2335b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (1) has location and type -> completed 2336b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (2) has type only -> is an abstract instance 2337b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (3) has location and abs_ori -> is a concrete instance 2338666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe Name, fndn_ix and line number are all optional frills. 2339b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj */ 2340b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if ( /* 1 */ (gexpr && typeR != D3_INVALID_CUOFF) 2341b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* 2 */ || (typeR != D3_INVALID_CUOFF) 2342b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* 3 */ || (gexpr && abs_ori != (UWord)D3_INVALID_CUOFF) ) { 2343b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2344b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Add this variable to the list of interesting looking 2345b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj variables. Crucially, note along with it the address 2346b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj range(s) associated with the variable, which for locals 2347b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj will be the address ranges at the top of the varparser's 2348b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj stack. */ 2349b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj GExpr* fbGX = NULL; 2350b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Word i, nRanges; 2351518850bf0da07ed3e2244e307268ae0fd80e93a8florian const XArray* /* of AddrRange */ xa; 2352b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TempVar* tv; 2353b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Stack can't be empty; we put a dummy entry on it for the 2354b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj entire address range before starting with the DIEs for 2355b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj this CU. */ 2356b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(parser->sp >= 0); 2357b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 235881d24c396c66dde7db2d9b567451f99081a2eab7philippe /* If this is a local variable (non-global), try to find 2359b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj the GExpr for the DW_AT_frame_base of the containing 2360b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj function. It should have been pushed on the stack at the 2361b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj time we encountered its DW_TAG_subprogram DIE, so the way 2362b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj to find it is to scan back down the stack looking for it. 2363b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj If there isn't an enclosing stack entry marked 'isFunc' 2364b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj then we must be seeing variable or formal param DIEs 2365b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj outside of a function, so we deem the Dwarf to be 2366b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj malformed if that happens. Note that the fbGX may be NULL 2367b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if the containing DT_TAG_subprogram didn't supply a 2368b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_frame_base -- that's OK, but there must actually be 2369b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj a containing DW_TAG_subprogram. */ 237081d24c396c66dde7db2d9b567451f99081a2eab7philippe if (!global) { 2371b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool found = False; 2372b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj for (i = parser->sp; i >= 0; i--) { 2373b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (parser->isFunc[i]) { 2374b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj fbGX = parser->fbGX[i]; 2375b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj found = True; 2376b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; 2377b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2378b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2379b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (!found) { 2380b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (0 && VG_(clo_verbosity) >= 0) { 2381b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(message)(Vg_DebugMsg, 238281d24c396c66dde7db2d9b567451f99081a2eab7philippe "warning: parse_var_DIE: non-global variable " 2383738856f99eea33d86ce91dcb1d6cd5b151e307casewardj "outside DW_TAG_subprogram\n"); 2384b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 23855c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe /* goto_bad_DIE; */ 2386b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* This seems to happen a lot. Just ignore it -- if, 2387b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj when we come to evaluation of the location (guarded) 2388b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj expression, it requires a frame base value, and 2389b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj there's no expression for that, then evaluation as a 2390b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj whole will fail. Harmless - a bit of a waste of 2391b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cycles but nothing more. */ 2392b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2393b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2394b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 239581d24c396c66dde7db2d9b567451f99081a2eab7philippe /* re "global ? 0 : parser->sp" (twice), if the var is 239681d24c396c66dde7db2d9b567451f99081a2eab7philippe marked 'global' then we must put it at the global scope, 2397b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj as only the global scope (level 0) covers the entire PC 2398b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj address space. It is asserted elsewhere that level 0 2399b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj always covers the entire address space. */ 240081d24c396c66dde7db2d9b567451f99081a2eab7philippe xa = parser->ranges[global ? 0 : parser->sp]; 2401b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj nRanges = VG_(sizeXA)(xa); 2402b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(nRanges >= 0); 2403b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 24049c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj tv = ML_(dinfo_zalloc)( "di.readdwarf3.pvD.1", sizeof(TempVar) ); 2405b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->name = name; 240681d24c396c66dde7db2d9b567451f99081a2eab7philippe tv->level = global ? 0 : parser->sp; 2407b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->typeR = typeR; 2408b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->gexpr = gexpr; 2409b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->fbGX = fbGX; 2410666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe tv->fndn_ix= fndn_ix; 2411b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->fLine = lineNo; 2412b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->dioff = posn; 2413b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->absOri = abs_ori; 2414b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2415b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* See explanation on definition of type TempVar for the 2416b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj reason for this elaboration. */ 2417b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->nRanges = nRanges; 2418b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->rngOneMin = 0; 2419b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->rngOneMax = 0; 2420b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->rngMany = NULL; 2421b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (nRanges == 1) { 2422b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj AddrRange* range = VG_(indexXA)(xa, 0); 2423b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->rngOneMin = range->aMin; 2424b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj tv->rngOneMax = range->aMax; 2425b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2426b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj else if (nRanges > 1) { 24279c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* See if we already have a range list which is 24289c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj structurally identical. If so, use that; if not, clone 24299c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj this one, and add it to our collection. */ 24309c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj UWord keyW, valW; 24319c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (VG_(lookupFM)( rangestree, &keyW, &valW, (UWord)xa )) { 24329c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj XArray* old = (XArray*)keyW; 2433e2800c958044937e72eefa371c10ae47ac40e089florian vg_assert(valW == 0); 2434e2800c958044937e72eefa371c10ae47ac40e089florian vg_assert(old != xa); 24359c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj tv->rngMany = old; 24369c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } else { 24379c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj XArray* cloned = VG_(cloneXA)( "di.readdwarf3.pvD.2", xa ); 24389c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj tv->rngMany = cloned; 24399c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(addToFM)( rangestree, (UWord)cloned, 0 ); 24409c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 2441b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2442b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 244359a2d18d0ddfa241850017252b0804d469187d79sewardj VG_(addToXA)( tempvars, &tv ); 2444b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2445b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3(" Recording this variable, with %ld PC range(s)\n", 2446b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(sizeXA)(xa) ); 2447b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* collect stats on how effective the ->ranges special 2448b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj casing is */ 2449b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (0) { 24509c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj static Int ntot=0, ngt=0; 24519c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ntot++; 24529c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (tv->rngMany) ngt++; 24539c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (0 == (ntot % 100000)) 24549c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(printf)("XXXX %d tot, %d cloned\n", ntot, ngt); 2455b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2456b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2457b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2458b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2459b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Here are some other weird cases seen in the wild: 2460b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2461b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj We have a variable with a name and a type, but no 2462b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj location. I guess that's a sign that it has been 2463b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj optimised away. Ignore it. Here's an example: 2464b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2465b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj static Int lc_compar(void* n1, void* n2) { 2466b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj MC_Chunk* mc1 = *(MC_Chunk**)n1; 2467b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj MC_Chunk* mc2 = *(MC_Chunk**)n2; 2468b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return (mc1->data < mc2->data ? -1 : 1); 2469b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2470b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2471b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Both mc1 and mc2 are like this 2472b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj <2><5bc>: Abbrev Number: 21 (DW_TAG_variable) 2473b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_name : mc1 2474b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_decl_file : 1 2475b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_decl_line : 216 2476b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_type : <5d3> 2477b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2478b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj whereas n1 and n2 do have locations specified. 2479b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2480b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj --------------------------------------------- 2481b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2482b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj We see a DW_TAG_formal_parameter with a type, but 2483b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj no name and no location. It's probably part of a function type 2484b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj construction, thusly, hence ignore it: 2485b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj <1><2b4>: Abbrev Number: 12 (DW_TAG_subroutine_type) 2486b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_sibling : <2c9> 2487b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_prototyped : 1 2488b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_type : <114> 2489b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj <2><2be>: Abbrev Number: 13 (DW_TAG_formal_parameter) 2490b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_type : <13e> 2491b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj <2><2c3>: Abbrev Number: 13 (DW_TAG_formal_parameter) 2492b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_type : <133> 2493b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2494b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj --------------------------------------------- 2495b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2496b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Is very minimal, like this: 2497b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj <4><81d>: Abbrev Number: 44 (DW_TAG_variable) 2498b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_abstract_origin: <7ba> 2499b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj What that signifies I have no idea. Ignore. 2500b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2501b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ---------------------------------------------- 2502b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2503b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Is very minimal, like this: 2504b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj <200f>: DW_TAG_formal_parameter 2505b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_abstract_ori: <1f4c> 2506b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_location : 13440 2507b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj What that signifies I have no idea. Ignore. 2508b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj It might be significant, though: the variable at least 2509b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj has a location and so might exist somewhere. 2510b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Maybe we should handle this. 2511b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2512b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj --------------------------------------------- 2513b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2514b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj <22407>: DW_TAG_variable 2515b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_name : (indirect string, offset: 0x6579): 2516b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vgPlain_trampoline_stuff_start 2517b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_decl_file : 29 2518b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_decl_line : 56 2519b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_external : 1 2520b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_declaration : 1 2521b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2522b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Nameless and typeless variable that has a location? Who 2523b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj knows. Not me. 2524b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj <2><3d178>: Abbrev Number: 22 (DW_TAG_variable) 2525b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_location : 9 byte block: 3 c0 c7 13 38 0 0 0 0 2526b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (DW_OP_addr: 3813c7c0) 2527b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2528b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj No, really. Check it out. gcc is quite simply borked. 2529b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj <3><168cc>: Abbrev Number: 141 (DW_TAG_variable) 2530b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj // followed by no attributes, and the next DIE is a sibling, 2531b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj // not a child 2532b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj */ 2533b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2534b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return; 2535b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2536b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj bad_DIE: 2537896a3bfd1b98aa3358a2e77be3bb728cb3d2926fphilippe dump_bad_die_and_barf("parse_var_DIE", dtag, posn, level, 2538a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe c_die, saved_die_c_offset, 2539a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe abbv, 2540a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc); 2541a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /*NOTREACHED*/ 2542a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe} 2543a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2544a0a73939b0398b6608fd6dbde49820ce6530d12cphilippetypedef 2545a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe struct { 2546666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe /* The fndn_ix file name/dirname table. Is a mapping from dwarf 2547666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe integer index to the index in di->fndnpool. */ 2548666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe XArray* /* of UInt* */ fndn_ix_Table; 2549d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe UWord sibling; // sibling of the last read DIE (if it has a sibling). 2550f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj } 2551a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe D3InlParser; 2552a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2553a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe/* Return the function name corresponding to absori. 25546ae06edfc65c35528efd5459572349f5b918efd5philippe 25556ae06edfc65c35528efd5459572349f5b918efd5philippe absori is a 'cooked' reference to a DIE, i.e. absori can be either 25566ae06edfc65c35528efd5459572349f5b918efd5philippe in cc->escn_debug_info or in cc->escn_debug_info_alt. 25576ae06edfc65c35528efd5459572349f5b918efd5philippe get_inlFnName will uncook absori. 25586ae06edfc65c35528efd5459572349f5b918efd5philippe 25596ae06edfc65c35528efd5459572349f5b918efd5philippe The returned value is a (permanent) string in DebugInfo's .strchunks. 25606ae06edfc65c35528efd5459572349f5b918efd5philippe 25616ae06edfc65c35528efd5459572349f5b918efd5philippe LIMITATION: absori must point in the CU of cc. If absori points 25626ae06edfc65c35528efd5459572349f5b918efd5philippe in another CU, returns "UnknownInlinedFun". 25636ae06edfc65c35528efd5459572349f5b918efd5philippe 25646ae06edfc65c35528efd5459572349f5b918efd5philippe Here are the problems to retrieve the fun name if absori is in 25656ae06edfc65c35528efd5459572349f5b918efd5philippe another CU: the DIE reading code cannot properly extract data from 25666ae06edfc65c35528efd5459572349f5b918efd5philippe another CU, as the abbv code retrieved in the other CU cannot be 25676ae06edfc65c35528efd5459572349f5b918efd5philippe translated in an abbreviation. Reading data from the alternate debug 25686ae06edfc65c35528efd5459572349f5b918efd5philippe info also gives problems as the string reference is also in the alternate 25696ae06edfc65c35528efd5459572349f5b918efd5philippe file, but when reading the alt DIE, the string form is a 'local' string, 25706ae06edfc65c35528efd5459572349f5b918efd5philippe but cannot be read in the current CU, but must be read in the alt CU. 25716ae06edfc65c35528efd5459572349f5b918efd5philippe See bug 338803 comment#3 and attachment for a failed attempt to handle 25726ae06edfc65c35528efd5459572349f5b918efd5philippe these problems (failed because with the patch, only one alt abbrev hash 25736ae06edfc65c35528efd5459572349f5b918efd5philippe table is kept, while we must handle all abbreviations in all CUs 25746ae06edfc65c35528efd5459572349f5b918efd5philippe referenced by an absori (being a reference to an alt CU, or a previous 25756ae06edfc65c35528efd5459572349f5b918efd5philippe or following CU). */ 2576518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic const HChar* get_inlFnName (Int absori, const CUConst* cc, Bool td3) 2577a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe{ 2578a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Cursor c; 2579518850bf0da07ed3e2244e307268ae0fd80e93a8florian const g_abbv *abbv; 2580a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ULong atag, abbv_code; 2581a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe UInt has_children; 2582a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe UWord posn; 25836ae06edfc65c35528efd5459572349f5b918efd5philippe Bool type_flag, alt_flag; 25841ef70c6f00ab1b50d1936f77037e9923d8ed8c59florian const HChar *ret = NULL; 2585a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe FormContents cts; 2586a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe UInt nf_i; 2587a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 25886ae06edfc65c35528efd5459572349f5b918efd5philippe posn = uncook_die( cc, absori, &type_flag, &alt_flag); 25896ae06edfc65c35528efd5459572349f5b918efd5philippe if (type_flag) 25906ae06edfc65c35528efd5459572349f5b918efd5philippe cc->barf("get_inlFnName: uncooked absori in type debug info"); 25916ae06edfc65c35528efd5459572349f5b918efd5philippe 25926ae06edfc65c35528efd5459572349f5b918efd5philippe /* LIMITATION: check we are in the same CU. 25936ae06edfc65c35528efd5459572349f5b918efd5philippe If not, return unknown inlined function name. */ 25946ae06edfc65c35528efd5459572349f5b918efd5philippe /* if crossing between alt debug info<>normal info 25956ae06edfc65c35528efd5459572349f5b918efd5philippe or posn not in the cu range, 25966ae06edfc65c35528efd5459572349f5b918efd5philippe then it is in another CU. */ 25976ae06edfc65c35528efd5459572349f5b918efd5philippe if (alt_flag != cc->is_alt_info 25986ae06edfc65c35528efd5459572349f5b918efd5philippe || posn < cc->cu_start_offset 25996ae06edfc65c35528efd5459572349f5b918efd5philippe || posn >= cc->cu_start_offset + cc->unit_length) { 26006ae06edfc65c35528efd5459572349f5b918efd5philippe static Bool reported = False; 2601ba60227fa4fb14672c0e5e91486b25234fb1becamjw if (!reported && VG_(clo_verbosity) > 1) { 26026ae06edfc65c35528efd5459572349f5b918efd5philippe VG_(message)(Vg_DebugMsg, 26036ae06edfc65c35528efd5459572349f5b918efd5philippe "Warning: cross-CU LIMITATION: some inlined fn names\n" 26046ae06edfc65c35528efd5459572349f5b918efd5philippe "might be shown as UnknownInlinedFun\n"); 26056ae06edfc65c35528efd5459572349f5b918efd5philippe reported = True; 26066ae06edfc65c35528efd5459572349f5b918efd5philippe } 26076ae06edfc65c35528efd5459572349f5b918efd5philippe TRACE_D3(" <get_inlFnName><%lx>: cross-CU LIMITATION", posn); 26086ae06edfc65c35528efd5459572349f5b918efd5philippe return ML_(addStr)(cc->di, "UnknownInlinedFun", -1); 26096ae06edfc65c35528efd5459572349f5b918efd5philippe } 26106ae06edfc65c35528efd5459572349f5b918efd5philippe 26116ae06edfc65c35528efd5459572349f5b918efd5philippe init_Cursor (&c, cc->escn_debug_info, posn, cc->barf, 2612a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe "Overrun get_inlFnName absori"); 2613a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2614a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe abbv_code = get_ULEB128( &c ); 2615a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe abbv = get_abbv ( cc, abbv_code); 2616a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe atag = abbv->atag; 2617a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3(" <get_inlFnName><%lx>: Abbrev Number: %llu (%s)\n", 2618a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe posn, abbv_code, ML_(pp_DW_TAG)( atag ) ); 2619a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2620a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (atag == 0) 2621a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc->barf("get_inlFnName: invalid zero tag on DIE"); 2622a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2623a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe has_children = abbv->has_children; 2624a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (has_children != DW_children_no && has_children != DW_children_yes) 2625a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc->barf("get_inlFnName: invalid has_children value"); 2626a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2627a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (atag != DW_TAG_subprogram) 2628a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc->barf("get_inlFnName: absori not a subprogram"); 2629a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2630746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 2631b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 2632746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 2633746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 2634746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 2635b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 2636a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe get_Form_contents( &cts, cc, &c, False/*td3*/, form ); 2637a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (attr == DW_AT_name) { 2638a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe HChar *fnname; 2639a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (cts.szB >= 0) 2640a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc->barf("get_inlFnName: expecting indirect string"); 2641a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe fnname = ML_(cur_read_strdup)( cts.u.cur, 2642a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe "get_inlFnName.1" ); 2643a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ret = ML_(addStr)(cc->di, fnname, -1); 2644a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(dinfo_free) (fnname); 26450ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe break; /* Name found, get out of the loop, as this has priority over 26460ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe DW_AT_specification. */ 26470ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe } 26480ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe if (attr == DW_AT_specification) { 26496ae06edfc65c35528efd5459572349f5b918efd5philippe UWord cdie; 26506ae06edfc65c35528efd5459572349f5b918efd5philippe 26510ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe if (cts.szB == 0) 26520ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe cc->barf("get_inlFnName: AT specification missing"); 26536ae06edfc65c35528efd5459572349f5b918efd5philippe 26546ae06edfc65c35528efd5459572349f5b918efd5philippe /* The recursive call to get_inlFnName will uncook its arg. 26556ae06edfc65c35528efd5459572349f5b918efd5philippe So, we need to cook it here, so as to reference the 26566ae06edfc65c35528efd5459572349f5b918efd5philippe correct section (e.g. the alt info). */ 26576ae06edfc65c35528efd5459572349f5b918efd5philippe cdie = cook_die_using_form(cc, (UWord)cts.u.val, form); 26586ae06edfc65c35528efd5459572349f5b918efd5philippe 26590ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe /* hoping that there is no loop */ 26606ae06edfc65c35528efd5459572349f5b918efd5philippe ret = get_inlFnName (cdie, cc, td3); 26616ae06edfc65c35528efd5459572349f5b918efd5philippe /* Unclear if having both DW_AT_specification and DW_AT_name is 26620ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe possible but in any case, we do not break here. 26630ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe If we find later on a DW_AT_name, it will override the name found 26640ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe in the DW_AT_specification.*/ 2665a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2666b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2667a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2668a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (ret) 2669a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe return ret; 26700ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe else { 26710ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe TRACE_D3("AbsOriFnNameNotFound"); 2672a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe return ML_(addStr)(cc->di, "AbsOriFnNameNotFound", -1); 26730ff164112b6a398fa7e60dffed3c2b6dcf9dda25philippe } 2674a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe} 2675a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2676a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe/* Returns True if the (possibly) childrens of the current DIE are interesting 2677a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe to parse. Returns False otherwise. 2678a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe If the current DIE has a sibling, the non interesting children can 2679a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe maybe be skipped (if the DIE has a DW_AT_sibling). */ 2680a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe__attribute__((noinline)) 2681a0a73939b0398b6608fd6dbde49820ce6530d12cphilippestatic Bool parse_inl_DIE ( 2682a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /*MOD*/D3InlParser* parser, 2683a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe DW_TAG dtag, 2684a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe UWord posn, 2685a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Int level, 2686a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Cursor* c_die, 2687518850bf0da07ed3e2244e307268ae0fd80e93a8florian const g_abbv *abbv, 2688a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe CUConst* cc, 2689a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Bool td3 2690a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe) 2691a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe{ 2692a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe FormContents cts; 2693a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe UInt nf_i; 2694a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2695a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe UWord saved_die_c_offset = get_position_of_Cursor( c_die ); 2696a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2697a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Get info about DW_TAG_compile_unit and DW_TAG_partial_unit 'which 2698a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe in theory could also contain inlined fn calls). */ 2699a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (dtag == DW_TAG_compile_unit || dtag == DW_TAG_partial_unit) { 2700a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Bool have_lo = False; 2701a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Addr ip_lo = 0; 27021ef70c6f00ab1b50d1936f77037e9923d8ed8c59florian const HChar *compdir = NULL; 2703a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2704a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe nf_i = 0; 2705a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe while (True) { 2706a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 2707a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 2708a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe nf_i++; 2709a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (attr == 0 && form == 0) break; 2710a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 2711a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (attr == DW_AT_low_pc && cts.szB > 0) { 2712a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ip_lo = cts.u.val; 2713a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe have_lo = True; 2714a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2715666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe if (attr == DW_AT_comp_dir) { 2716666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe if (cts.szB >= 0) 2717666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe cc->barf("parse_inl_DIE compdir: expecting indirect string"); 2718666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe HChar *str = ML_(cur_read_strdup)( cts.u.cur, 2719666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe "parse_inl_DIE.compdir" ); 2720666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe compdir = ML_(addStr)(cc->di, str, -1); 2721666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe ML_(dinfo_free) (str); 2722666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe } 2723a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (attr == DW_AT_stmt_list && cts.szB > 0) { 2724666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe read_filename_table( parser->fndn_ix_Table, compdir, 2725666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe cc, cts.u.val, td3 ); 2726a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2727d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe if (attr == DW_AT_sibling && cts.szB > 0) { 2728d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe parser->sibling = cts.u.val; 2729d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe } 2730a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2731a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (level == 0) 2732a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe setup_cu_svma (cc, have_lo, ip_lo, td3); 2733a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2734a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2735a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (dtag == DW_TAG_inlined_subroutine) { 2736a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Bool have_lo = False; 2737a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Bool have_hi1 = False; 2738a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Bool have_range = False; 2739a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Bool hiIsRelative = False; 2740a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Addr ip_lo = 0; 2741a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Addr ip_hi1 = 0; 2742a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Addr rangeoff = 0; 2743666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe UInt caller_fndn_ix = 0; 2744a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Int caller_lineno = 0; 2745a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Int inlinedfn_abstract_origin = 0; 2746a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2747a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe nf_i = 0; 2748a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe while (True) { 2749a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 2750a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 2751a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe nf_i++; 2752a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (attr == 0 && form == 0) break; 2753a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 2754a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (attr == DW_AT_call_file && cts.szB > 0) { 2755a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Int ftabIx = (Int)cts.u.val; 2756a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (ftabIx >= 1 2757666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe && ftabIx < VG_(sizeXA)( parser->fndn_ix_Table )) { 2758666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe caller_fndn_ix = *(UInt*) 2759666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(indexXA)( parser->fndn_ix_Table, ftabIx ); 2760a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2761c6e5d76e9eea8625f385ff844545c688c91938daflorian if (0) VG_(printf)("XXX caller_fndn_ix = %u %s\n", caller_fndn_ix, 2762666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe ML_(fndn_ix2filename) (cc->di, caller_fndn_ix)); 2763a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2764a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (attr == DW_AT_call_line && cts.szB > 0) { 2765a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe caller_lineno = cts.u.val; 2766a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2767a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2768a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (attr == DW_AT_abstract_origin && cts.szB > 0) { 27696ae06edfc65c35528efd5459572349f5b918efd5philippe inlinedfn_abstract_origin 27706ae06edfc65c35528efd5459572349f5b918efd5philippe = cook_die_using_form (cc, (UWord)cts.u.val, form); 2771a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2772a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2773a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (attr == DW_AT_low_pc && cts.szB > 0) { 2774a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ip_lo = cts.u.val; 2775a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe have_lo = True; 2776a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2777a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (attr == DW_AT_high_pc && cts.szB > 0) { 2778a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ip_hi1 = cts.u.val; 2779a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe have_hi1 = True; 2780a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (form != DW_FORM_addr) 2781a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe hiIsRelative = True; 2782a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2783a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (attr == DW_AT_ranges && cts.szB > 0) { 2784a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe rangeoff = cts.u.val; 2785a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe have_range = True; 2786a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2787d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe if (attr == DW_AT_sibling && cts.szB > 0) { 2788d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe parser->sibling = cts.u.val; 2789d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe } 2790a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2791a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (have_lo && have_hi1 && hiIsRelative) 2792a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ip_hi1 += ip_lo; 2793a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Do we have something that looks sane? */ 2794a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (dtag == DW_TAG_inlined_subroutine 2795a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe && (!have_lo) && (!have_hi1) && (!have_range)) { 2796a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Seems strange. How can an inlined subroutine have 2797a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe no code ? */ 2798a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe goto_bad_DIE; 2799a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } else 2800a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (have_lo && have_hi1 && (!have_range)) { 2801a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* This inlined call is just a single address range. */ 2802a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (ip_lo < ip_hi1) { 2803e2d41dc65a214f6950f42d0b02cd9cc2d932d927philippe /* Apply text debug biasing */ 2804e2d41dc65a214f6950f42d0b02cd9cc2d932d927philippe ip_lo += cc->di->text_debug_bias; 2805e2d41dc65a214f6950f42d0b02cd9cc2d932d927philippe ip_hi1 += cc->di->text_debug_bias; 2806a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(addInlInfo) (cc->di, 2807a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ip_lo, ip_hi1, 2808a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe get_inlFnName (inlinedfn_abstract_origin, cc, td3), 2809666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe caller_fndn_ix, 2810a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe caller_lineno, level); 2811a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2812a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } else if (have_range) { 2813a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* This inlined call is several address ranges. */ 2814a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe XArray *ranges; 2815a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Word j; 28161ef70c6f00ab1b50d1936f77037e9923d8ed8c59florian const HChar *inlfnname = 28171ef70c6f00ab1b50d1936f77037e9923d8ed8c59florian get_inlFnName (inlinedfn_abstract_origin, cc, td3); 2818a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 28198b662d50e99428ea6b76d44a80ffaaf73eb51584philippe /* Ranges are biased for the inline info using the same logic 28208b662d50e99428ea6b76d44a80ffaaf73eb51584philippe as what is used for biasing ranges for the var info, for which 28218b662d50e99428ea6b76d44a80ffaaf73eb51584philippe ranges are read using cc->cu_svma (see parse_var_DIE). 28228b662d50e99428ea6b76d44a80ffaaf73eb51584philippe Then text_debug_bias is added when a (non global) var 28238b662d50e99428ea6b76d44a80ffaaf73eb51584philippe is recorded (see just before the call to ML_(addVar)) */ 2824a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ranges = get_range_list( cc, td3, 2825a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe rangeoff, cc->cu_svma ); 2826a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe for (j = 0; j < VG_(sizeXA)( ranges ); j++) { 2827a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe AddrRange* range = (AddrRange*) VG_(indexXA)( ranges, j ); 2828a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(addInlInfo) (cc->di, 28298b662d50e99428ea6b76d44a80ffaaf73eb51584philippe range->aMin + cc->di->text_debug_bias, 28308b662d50e99428ea6b76d44a80ffaaf73eb51584philippe range->aMax+1 + cc->di->text_debug_bias, 2831a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe // aMax+1 as range has its last bound included 2832a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe // while ML_(addInlInfo) expects last bound not 2833a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe // included. 2834a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe inlfnname, 2835666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe caller_fndn_ix, 2836a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe caller_lineno, level); 2837a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2838a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(deleteXA)( ranges ); 2839a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } else 2840a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe goto_bad_DIE; 2841a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 2842a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2843a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe // Only recursively parse the (possible) children for the DIE which 2844a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe // might maybe contain a DW_TAG_inlined_subroutine: 2845a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe return dtag == DW_TAG_lexical_block || dtag == DW_TAG_subprogram 2846a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe || dtag == DW_TAG_inlined_subroutine 2847a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe || dtag == DW_TAG_compile_unit || dtag == DW_TAG_partial_unit; 2848a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 2849a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe bad_DIE: 2850896a3bfd1b98aa3358a2e77be3bb728cb3d2926fphilippe dump_bad_die_and_barf("parse_inl_DIE", dtag, posn, level, 2851a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe c_die, saved_die_c_offset, 2852a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe abbv, 2853a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc); 2854b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*NOTREACHED*/ 2855b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 2856b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2857b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2858b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 2859b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 2860b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- Parsing of type-related DIEs ---*/ 2861b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 2862b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 2863b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2864b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjtypedef 2865b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj struct { 28662acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj /* What source language? 'A'=Ada83/95, 28672acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj 'C'=C/C++, 28682acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj 'F'=Fortran, 28692acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj '?'=other 2870b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Established once per compilation unit. */ 2871b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar language; 2872b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* A stack of types which are currently under construction */ 2873b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Int sp; /* [sp] is innermost active entry; sp==-1 for empty 2874b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj stack */ 2875611fd68095bd837171574815cceb2225ed2aeb9dflorian Int stack_size; 28769c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* Note that the TyEnts in qparentE are temporary copies of the 28779c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ones accumulating in the main tyent array. So it is not safe 28789c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj to free up anything on them when popping them off the stack 28799c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj (iow, it isn't safe to use TyEnt__make_EMPTY on them). Just 28809c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj memset them to zero when done. */ 2881611fd68095bd837171574815cceb2225ed2aeb9dflorian TyEnt *qparentE; /* parent TyEnts */ 2882611fd68095bd837171574815cceb2225ed2aeb9dflorian Int *qlevel; 2883b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2884b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj D3TypeParser; 2885b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2886611fd68095bd837171574815cceb2225ed2aeb9dflorian/* Completely initialise a type parser object */ 2887611fd68095bd837171574815cceb2225ed2aeb9dflorianstatic void 2888611fd68095bd837171574815cceb2225ed2aeb9dfloriantype_parser_init ( D3TypeParser *parser ) 2889611fd68095bd837171574815cceb2225ed2aeb9dflorian{ 2890611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->sp = -1; 2891611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->language = '?'; 2892611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->stack_size = 0; 2893611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->qparentE = NULL; 2894611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->qlevel = NULL; 2895611fd68095bd837171574815cceb2225ed2aeb9dflorian} 2896611fd68095bd837171574815cceb2225ed2aeb9dflorian 2897611fd68095bd837171574815cceb2225ed2aeb9dflorian/* Release any memory hanging off a type parser object */ 2898611fd68095bd837171574815cceb2225ed2aeb9dflorianstatic void 2899611fd68095bd837171574815cceb2225ed2aeb9dfloriantype_parser_release ( D3TypeParser *parser ) 2900611fd68095bd837171574815cceb2225ed2aeb9dflorian{ 2901611fd68095bd837171574815cceb2225ed2aeb9dflorian ML_(dinfo_free)( parser->qparentE ); 2902611fd68095bd837171574815cceb2225ed2aeb9dflorian ML_(dinfo_free)( parser->qlevel ); 2903611fd68095bd837171574815cceb2225ed2aeb9dflorian} 2904611fd68095bd837171574815cceb2225ed2aeb9dflorian 2905518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic void typestack_show ( const D3TypeParser* parser, const HChar* str ) 2906518850bf0da07ed3e2244e307268ae0fd80e93a8florian{ 2907b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Word i; 2908b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(printf)(" typestack (%s) {\n", str); 2909b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj for (i = 0; i <= parser->sp; i++) { 2910b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(printf)(" [%ld] (level %d): ", i, parser->qlevel[i]); 29119c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ML_(pp_TyEnt)( &parser->qparentE[i] ); 2912b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(printf)("\n"); 2913b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2914b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(printf)(" }\n"); 2915b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 2916b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2917b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* Remove from the stack, all entries with .level > 'level' */ 2918b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstatic 2919b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjvoid typestack_preen ( D3TypeParser* parser, Bool td3, Int level ) 2920b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 2921b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool changed = False; 2922611fd68095bd837171574815cceb2225ed2aeb9dflorian vg_assert(parser->sp < parser->stack_size); 2923b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 2924b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(parser->sp >= -1); 2925b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (parser->sp == -1) break; 2926b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (parser->qlevel[parser->sp] <= level) break; 2927b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (0) 2928b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("BBBBAAAA typestack_pop [newsp=%d]\n", parser->sp-1); 29299c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ML_(TyEnt__is_type)(&parser->qparentE[parser->sp])); 2930b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->sp--; 2931b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj changed = True; 2932b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 2933b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (changed && td3) 2934b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj typestack_show( parser, "after preen" ); 2935b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 2936b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2937518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic Bool typestack_is_empty ( const D3TypeParser* parser ) 2938518850bf0da07ed3e2244e307268ae0fd80e93a8florian{ 2939611fd68095bd837171574815cceb2225ed2aeb9dflorian vg_assert(parser->sp >= -1 && parser->sp < parser->stack_size); 2940b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return parser->sp == -1; 2941b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 2942b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2943518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic void typestack_push ( const CUConst* cc, 2944b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj D3TypeParser* parser, 2945b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool td3, 2946611fd68095bd837171574815cceb2225ed2aeb9dflorian const TyEnt* parentE, Int level ) 29473297124fa2116737066ac3cd709f18fdd5405163florian{ 2948b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (0) 29499c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TRACE_D3("BBBBAAAA typestack_push[newsp=%d]: %d %05lx\n", 29509c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj parser->sp+1, level, parentE->cuOff); 2951b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2952b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* First we need to zap everything >= 'level', as we are about to 2953b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj replace any previous entry at 'level', so .. */ 2954b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj typestack_preen(parser, /*td3*/False, level-1); 2955b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2956b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(parser->sp >= -1); 2957611fd68095bd837171574815cceb2225ed2aeb9dflorian vg_assert(parser->sp < parser->stack_size); 2958611fd68095bd837171574815cceb2225ed2aeb9dflorian if (parser->sp == parser->stack_size - 1) { 2959611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->stack_size += 16; 2960611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->qparentE = 2961611fd68095bd837171574815cceb2225ed2aeb9dflorian ML_(dinfo_realloc)("di.readdwarf3.typush.1", parser->qparentE, 2962611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->stack_size * sizeof parser->qparentE[0]); 2963611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->qlevel = 2964611fd68095bd837171574815cceb2225ed2aeb9dflorian ML_(dinfo_realloc)("di.readdwarf3.typush.2", parser->qlevel, 2965611fd68095bd837171574815cceb2225ed2aeb9dflorian parser->stack_size * sizeof parser->qlevel[0]); 2966611fd68095bd837171574815cceb2225ed2aeb9dflorian } 2967b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (parser->sp >= 0) 2968b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(parser->qlevel[parser->sp] < level); 2969b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->sp++; 29709c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(parentE); 29719c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ML_(TyEnt__is_type)(parentE)); 29729c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(parentE->cuOff != D3_INVALID_CUOFF); 29739c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj parser->qparentE[parser->sp] = *parentE; 2974b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->qlevel[parser->sp] = level; 2975e0bd5910153720d5d15697db8063d0d4caa59d8fphilippe if (TD3) 2976b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj typestack_show( parser, "after push" ); 2977b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 2978b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 29792acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj/* True if the subrange type being parsed gives the bounds of an array. */ 2980518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic Bool subrange_type_denotes_array_bounds ( const D3TypeParser* parser, 29812acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj DW_TAG dtag ) { 29822acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj vg_assert(dtag == DW_TAG_subrange_type); 29832acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj /* For most languages, a subrange_type dtag always gives the 29842acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj bounds of an array. 29852acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj For Ada, there are additional conditions as a subrange_type 29862acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj is also used for other purposes. */ 29872acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj if (parser->language != 'A') 29882acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj /* not Ada, so it definitely denotes an array bound. */ 29892acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj return True; 29902acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj else 29912acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj /* Extra constraints for Ada: it only denotes an array bound if .. */ 29922acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj return (! typestack_is_empty(parser) 29932acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj && parser->qparentE[parser->sp].tag == Te_TyArray); 29942acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj} 2995b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2996b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* Parse a type-related DIE. 'parser' holds the current parser state. 2997b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 'admin' is where the completed types are dumped. 'dtag' is the tag 2998b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj for this DIE. 'c_die' points to the start of the data fields (FORM 2999746e97e7098def65d59c79d5d661f9a757a837cdphilippe stuff) for the DIE. abbv is the parsed abbreviation which describe 3000746e97e7098def65d59c79d5d661f9a757a837cdphilippe the DIE. 3001b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3002b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj We may find the DIE uninteresting, in which case we should ignore 3003b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj it. 30049c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 30059c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj What happens: the DIE is examined. If uninteresting, it is ignored. 30069c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Otherwise, the DIE gives rise to two things: 30079c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 30089c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj (1) the offset of this DIE in the CU -- the cuOffset, a UWord 30099c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj (2) a TyAdmin structure, which holds the type, or related stuff 30109c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 30119c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj (2) is added at the end of 'tyadmins', at some index, say 'i'. 30129c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 30139c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj A pair (cuOffset, i) is added to 'tydict'. 30149c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 30159c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Hence 'tyadmins' holds the actual type entities, and 'tydict' holds 30169c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj a mapping from cuOffset to the index of the corresponding entry in 30179c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 'tyadmin'. 30189c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 30199c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj When resolving a cuOffset to a TyAdmin, first look up the cuOffset 30209c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj in the tydict (by binary search). This gives an index into 30219c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj tyadmins, and the required entity lives in tyadmins at that index. 3022b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj*/ 3023b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj__attribute__((noinline)) 30249c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjstatic void parse_type_DIE ( /*MOD*/XArray* /* of TyEnt */ tyents, 3025b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*MOD*/D3TypeParser* parser, 3026b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_TAG dtag, 3027b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord posn, 3028b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Int level, 3029b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Cursor* c_die, 3030518850bf0da07ed3e2244e307268ae0fd80e93a8florian const g_abbv *abbv, 3031518850bf0da07ed3e2244e307268ae0fd80e93a8florian const CUConst* cc, 3032b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool td3 ) 3033b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 30345d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj FormContents cts; 3035a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe UInt nf_i; 30369c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEnt typeE; 30379c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEnt atomE; 30389c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEnt fieldE; 30399c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEnt boundE; 3040b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3041b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord saved_die_c_offset = get_position_of_Cursor( c_die ); 3042b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 30439c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)( &typeE, 0xAA, sizeof(typeE) ); 30449c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)( &atomE, 0xAA, sizeof(atomE) ); 30459c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)( &fieldE, 0xAA, sizeof(fieldE) ); 30469c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)( &boundE, 0xAA, sizeof(boundE) ); 30479c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 3048b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* If we've returned to a level at or above any previously noted 3049b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parent, un-note it, so we don't believe we're still collecting 3050b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj its children. */ 3051b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj typestack_preen( parser, td3, level-1 ); 3052b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3053f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj if (dtag == DW_TAG_compile_unit 3054f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj || dtag == DW_TAG_type_unit 3055f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj || dtag == DW_TAG_partial_unit) { 3056b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* See if we can find DW_AT_language, since it is important for 3057b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj establishing array bounds (see DW_TAG_subrange_type below in 3058b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj this fn) */ 3059746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 3060b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 3061746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 3062746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 3063746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 3064b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 30655d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 3066b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr != DW_AT_language) 3067b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj continue; 30685d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (cts.szB <= 0) 30695c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 30705d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj switch (cts.u.val) { 3071b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_LANG_C89: case DW_LANG_C: 3072b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_LANG_C_plus_plus: case DW_LANG_ObjC: 3073b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_LANG_ObjC_plus_plus: case DW_LANG_UPC: 3074b527a5b139b310d593c5ad7c0a1ceaf58249f5e1mjw case DW_LANG_Upc: case DW_LANG_C99: case DW_LANG_C11: 3075b527a5b139b310d593c5ad7c0a1ceaf58249f5e1mjw case DW_LANG_C_plus_plus_11: case DW_LANG_C_plus_plus_14: 3076b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->language = 'C'; break; 3077b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_LANG_Fortran77: case DW_LANG_Fortran90: 3078ebb889307951acf917213ba93e2b6f02801d1647mjw case DW_LANG_Fortran95: case DW_LANG_Fortran03: 3079ebb889307951acf917213ba93e2b6f02801d1647mjw case DW_LANG_Fortran08: 3080b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->language = 'F'; break; 30812acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj case DW_LANG_Ada83: case DW_LANG_Ada95: 30822acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj parser->language = 'A'; break; 30832acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj case DW_LANG_Cobol74: 3084b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_LANG_Cobol85: case DW_LANG_Pascal83: 3085b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_LANG_Modula2: case DW_LANG_Java: 30862acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj case DW_LANG_PLI: 3087b527a5b139b310d593c5ad7c0a1ceaf58249f5e1mjw case DW_LANG_D: case DW_LANG_Python: case DW_LANG_Go: 3088b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_LANG_Mips_Assembler: 3089b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parser->language = '?'; break; 3090b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj default: 30915c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 3092b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3093b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3094b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3095b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3096b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (dtag == DW_TAG_base_type) { 3097b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* We can pick up a new base type any time. */ 30989c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)(&typeE, 0, sizeof(typeE)); 30999c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.cuOff = D3_INVALID_CUOFF; 31009c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.tag = Te_TyBase; 3101746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 3102b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 3103746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 3104746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 3105746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 3106b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 31075d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 31085d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_name && cts.szB < 0) { 31099c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyBase.name 31105d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = ML_(cur_read_strdup)( cts.u.cur, 31115d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj "di.readdwarf3.ptD.base_type.1" ); 3112b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 31135d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_byte_size && cts.szB > 0) { 31145d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj typeE.Te.TyBase.szB = cts.u.val; 3115b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 31165d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_encoding && cts.szB > 0) { 31175d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj switch (cts.u.val) { 3118b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_ATE_unsigned: case DW_ATE_unsigned_char: 311950c5093772c2b23fd0897d3590dcfaec1c92ac83tom case DW_ATE_UTF: /* since DWARF4, e.g. char16_t from C++ */ 3120b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_ATE_boolean:/* FIXME - is this correct? */ 31215db15403e889d4db339b342bc2a824ef0bfaa654sewardj case DW_ATE_unsigned_fixed: 31229c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyBase.enc = 'U'; break; 3123b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_ATE_signed: case DW_ATE_signed_char: 31245db15403e889d4db339b342bc2a824ef0bfaa654sewardj case DW_ATE_signed_fixed: 31259c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyBase.enc = 'S'; break; 3126b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_ATE_float: 31279c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyBase.enc = 'F'; break; 3128b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case DW_ATE_complex_float: 31299c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyBase.enc = 'C'; break; 3130b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj default: 31315c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 3132b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3133b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3134b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3135b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3136b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Invent a name if it doesn't have one. gcc-4.3 3137b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj -ftree-vectorize is observed to emit nameless base types. */ 31389c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (!typeE.Te.TyBase.name) 31399c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyBase.name 31409c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj = ML_(dinfo_strdup)( "di.readdwarf3.ptD.base_type.2", 31419c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj "<anon_base_type>" ); 3142b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3143b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Do we have something that looks sane? */ 3144b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (/* must have a name */ 31459c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyBase.name == NULL 3146b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* and a plausible size. Yes, really 32: "complex long 3147b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj double" apparently has size=32 */ 31489c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj || typeE.Te.TyBase.szB < 0 || typeE.Te.TyBase.szB > 32 3149b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* and a plausible encoding */ 31509c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj || (typeE.Te.TyBase.enc != 'U' 31519c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj && typeE.Te.TyBase.enc != 'S' 31529c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj && typeE.Te.TyBase.enc != 'F' 31539c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj && typeE.Te.TyBase.enc != 'C')) 31545c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 3155b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Last minute hack: if we see this 3156b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj <1><515>: DW_TAG_base_type 3157b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_byte_size : 0 3158b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_encoding : 5 3159b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_name : void 3160b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj convert it into a real Void type. */ 31619c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (typeE.Te.TyBase.szB == 0 31629c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj && 0 == VG_(strcmp)("void", typeE.Te.TyBase.name)) { 31639c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ML_(TyEnt__make_EMPTY)(&typeE); 31649c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.tag = Te_TyVoid; 31659c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyVoid.isFake = False; /* it's a real one! */ 3166b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 31679c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 3168b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj goto acquire_Type; 3169b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3170b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 31710e947cfedebda6da2e84fb61af431db5cf1275fcbart /* 31720e947cfedebda6da2e84fb61af431db5cf1275fcbart * An example of DW_TAG_rvalue_reference_type: 31730e947cfedebda6da2e84fb61af431db5cf1275fcbart * 31740e947cfedebda6da2e84fb61af431db5cf1275fcbart * $ readelf --debug-dump /usr/lib/debug/usr/lib/libstdc++.so.6.0.16.debug 31750e947cfedebda6da2e84fb61af431db5cf1275fcbart * <1><1014>: Abbrev Number: 55 (DW_TAG_rvalue_reference_type) 31760e947cfedebda6da2e84fb61af431db5cf1275fcbart * <1015> DW_AT_byte_size : 4 31770e947cfedebda6da2e84fb61af431db5cf1275fcbart * <1016> DW_AT_type : <0xe52> 31780e947cfedebda6da2e84fb61af431db5cf1275fcbart */ 3179b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (dtag == DW_TAG_pointer_type || dtag == DW_TAG_reference_type 31800e947cfedebda6da2e84fb61af431db5cf1275fcbart || dtag == DW_TAG_ptr_to_member_type 31810e947cfedebda6da2e84fb61af431db5cf1275fcbart || dtag == DW_TAG_rvalue_reference_type) { 3182b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* This seems legit for _pointer_type and _reference_type. I 3183b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj don't know if rolling _ptr_to_member_type in here really is 3184b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj legit, but it's better than not handling it at all. */ 31859c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)(&typeE, 0, sizeof(typeE)); 31869c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.cuOff = D3_INVALID_CUOFF; 31870e947cfedebda6da2e84fb61af431db5cf1275fcbart switch (dtag) { 31880e947cfedebda6da2e84fb61af431db5cf1275fcbart case DW_TAG_pointer_type: 31890e947cfedebda6da2e84fb61af431db5cf1275fcbart typeE.tag = Te_TyPtr; 31900e947cfedebda6da2e84fb61af431db5cf1275fcbart break; 31910e947cfedebda6da2e84fb61af431db5cf1275fcbart case DW_TAG_reference_type: 31920e947cfedebda6da2e84fb61af431db5cf1275fcbart typeE.tag = Te_TyRef; 31930e947cfedebda6da2e84fb61af431db5cf1275fcbart break; 31940e947cfedebda6da2e84fb61af431db5cf1275fcbart case DW_TAG_ptr_to_member_type: 31950e947cfedebda6da2e84fb61af431db5cf1275fcbart typeE.tag = Te_TyPtrMbr; 31960e947cfedebda6da2e84fb61af431db5cf1275fcbart break; 31970e947cfedebda6da2e84fb61af431db5cf1275fcbart case DW_TAG_rvalue_reference_type: 31980e947cfedebda6da2e84fb61af431db5cf1275fcbart typeE.tag = Te_TyRvalRef; 31990e947cfedebda6da2e84fb61af431db5cf1275fcbart break; 32000e947cfedebda6da2e84fb61af431db5cf1275fcbart default: 32010e947cfedebda6da2e84fb61af431db5cf1275fcbart vg_assert(False); 32020e947cfedebda6da2e84fb61af431db5cf1275fcbart } 3203b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* target type defaults to void */ 32049c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyPorR.typeR = D3_FAKEVOID_CUOFF; 32050e947cfedebda6da2e84fb61af431db5cf1275fcbart /* These four type kinds don't *have* to specify their size, in 320631452303b095a76295b08096b2840276db808b81sewardj which case we assume it's a machine word. But if they do 320731452303b095a76295b08096b2840276db808b81sewardj specify it, it must be a machine word :-) This probably 320831452303b095a76295b08096b2840276db808b81sewardj assumes that the word size of the Dwarf3 we're reading is the 320931452303b095a76295b08096b2840276db808b81sewardj same size as that on the machine. gcc appears to give a size 321031452303b095a76295b08096b2840276db808b81sewardj whereas icc9 doesn't. */ 321131452303b095a76295b08096b2840276db808b81sewardj typeE.Te.TyPorR.szB = sizeof(UWord); 3212746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 3213b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 3214746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 3215746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 3216746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 3217b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 32185d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 32195d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_byte_size && cts.szB > 0) { 32205d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj typeE.Te.TyPorR.szB = cts.u.val; 3221b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 32225d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_type && cts.szB > 0) { 32235d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj typeE.Te.TyPorR.typeR 32245d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = cook_die_using_form( cc, (UWord)cts.u.val, form ); 3225b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3226b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3227b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Do we have something that looks sane? */ 322831452303b095a76295b08096b2840276db808b81sewardj if (typeE.Te.TyPorR.szB != sizeof(UWord)) 32295c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 3230b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj else 3231b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj goto acquire_Type; 3232b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3233b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3234b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (dtag == DW_TAG_enumeration_type) { 3235b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Create a new Type to hold the results. */ 32369c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)(&typeE, 0, sizeof(typeE)); 32379c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.cuOff = posn; 32389c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.tag = Te_TyEnum; 32399d82d0f293c83ff2b8c3ab07065d8454059452bemjw Bool is_decl = False; 32409c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyEnum.atomRs 32419c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.ptD.enum_type.1", 32429c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ML_(dinfo_free), 32439c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj sizeof(UWord) ); 3244746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i=0; 3245b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 3246746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 3247746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 3248746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 3249b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 32505d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 32515d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_name && cts.szB < 0) { 32529c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyEnum.name 32535d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = ML_(cur_read_strdup)( cts.u.cur, 32545d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj "di.readdwarf3.pTD.enum_type.2" ); 3255b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 32565d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_byte_size && cts.szB > 0) { 32575d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj typeE.Te.TyEnum.szB = cts.u.val; 3258b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 32599d82d0f293c83ff2b8c3ab07065d8454059452bemjw if (attr == DW_AT_declaration) { 32609d82d0f293c83ff2b8c3ab07065d8454059452bemjw is_decl = True; 32619d82d0f293c83ff2b8c3ab07065d8454059452bemjw } 3262b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 32636ece231961274337eb8303aba3ac5247fc7d1ef9sewardj 32646ece231961274337eb8303aba3ac5247fc7d1ef9sewardj if (!typeE.Te.TyEnum.name) 32656ece231961274337eb8303aba3ac5247fc7d1ef9sewardj typeE.Te.TyEnum.name 32666ece231961274337eb8303aba3ac5247fc7d1ef9sewardj = ML_(dinfo_strdup)( "di.readdwarf3.pTD.enum_type.3", 32676ece231961274337eb8303aba3ac5247fc7d1ef9sewardj "<anon_enum_type>" ); 32686ece231961274337eb8303aba3ac5247fc7d1ef9sewardj 3269b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Do we have something that looks sane? */ 32702acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj if (typeE.Te.TyEnum.szB == 0 32712acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj /* we must know the size */ 32722acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj /* but not for Ada, which uses such dummy 32739d82d0f293c83ff2b8c3ab07065d8454059452bemjw enumerations as helper for gdb ada mode. 32749d82d0f293c83ff2b8c3ab07065d8454059452bemjw Also GCC allows incomplete enums as GNU extension. 32759d82d0f293c83ff2b8c3ab07065d8454059452bemjw http://gcc.gnu.org/onlinedocs/gcc/Incomplete-Enums.html 32769d82d0f293c83ff2b8c3ab07065d8454059452bemjw These are marked as DW_AT_declaration and won't have 32779d82d0f293c83ff2b8c3ab07065d8454059452bemjw a size. They can only be used in declaration or as 32789d82d0f293c83ff2b8c3ab07065d8454059452bemjw pointer types. You can't allocate variables or storage 32799d82d0f293c83ff2b8c3ab07065d8454059452bemjw using such an enum type. (Also GCC seems to have a bug 32809d82d0f293c83ff2b8c3ab07065d8454059452bemjw that will put such an enumeration_type into a .debug_types 32819d82d0f293c83ff2b8c3ab07065d8454059452bemjw unit which should only contain complete types.) */ 32829d82d0f293c83ff2b8c3ab07065d8454059452bemjw && (parser->language != 'A' && !is_decl)) { 32835c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 3284d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj } 3285d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 3286b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* On't stack! */ 32879c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typestack_push( cc, parser, td3, &typeE, level ); 3288b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj goto acquire_Type; 3289b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3290b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3291f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj /* gcc (GCC) 4.4.0 20081017 (experimental) occasionally produces 3292f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj DW_TAG_enumerator with only a DW_AT_name but no 3293f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj DW_AT_const_value. This is in violation of the Dwarf3 standard, 3294f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj and appears to be a new "feature" of gcc - versions 4.3.x and 3295f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj earlier do not appear to do this. So accept DW_TAG_enumerator 3296f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj which only have a name but no value. An example: 3297f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj 3298f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <1><180>: Abbrev Number: 6 (DW_TAG_enumeration_type) 3299f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <181> DW_AT_name : (indirect string, offset: 0xda70): 3300f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj QtMsgType 3301f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <185> DW_AT_byte_size : 4 3302f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <186> DW_AT_decl_file : 14 3303f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <187> DW_AT_decl_line : 1480 3304f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <189> DW_AT_sibling : <0x1a7> 3305f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <2><18d>: Abbrev Number: 7 (DW_TAG_enumerator) 3306f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <18e> DW_AT_name : (indirect string, offset: 0x9e18): 3307f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj QtDebugMsg 3308f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <2><192>: Abbrev Number: 7 (DW_TAG_enumerator) 3309f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <193> DW_AT_name : (indirect string, offset: 0x1505f): 3310f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj QtWarningMsg 3311f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <2><197>: Abbrev Number: 7 (DW_TAG_enumerator) 3312f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <198> DW_AT_name : (indirect string, offset: 0x16f4a): 3313f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj QtCriticalMsg 3314f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <2><19c>: Abbrev Number: 7 (DW_TAG_enumerator) 3315f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <19d> DW_AT_name : (indirect string, offset: 0x156dd): 3316f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj QtFatalMsg 3317f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <2><1a1>: Abbrev Number: 7 (DW_TAG_enumerator) 3318f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj <1a2> DW_AT_name : (indirect string, offset: 0x13660): 3319f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj QtSystemMsg 3320f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj */ 3321b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (dtag == DW_TAG_enumerator) { 33229c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)( &atomE, 0, sizeof(atomE) ); 33239c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj atomE.cuOff = posn; 33249c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj atomE.tag = Te_Atom; 3325746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 3326b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 3327746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 3328746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 3329746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 3330b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 33315d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 33325d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_name && cts.szB < 0) { 33339c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj atomE.Te.Atom.name 33345d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = ML_(cur_read_strdup)( cts.u.cur, 33355d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj "di.readdwarf3.pTD.enumerator.1" ); 3336b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 33375d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_const_value && cts.szB > 0) { 33385d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj atomE.Te.Atom.value = cts.u.val; 3339f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj atomE.Te.Atom.valueKnown = True; 3340b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3341b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3342b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Do we have something that looks sane? */ 3343f3aaa337f0bd3084b339cdcff58ef6fef25bf15fsewardj if (atomE.Te.Atom.name == NULL) 33445c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 3345b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Do we have a plausible parent? */ 33465c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe if (typestack_is_empty(parser)) goto_bad_DIE; 33479c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ML_(TyEnt__is_type)(&parser->qparentE[parser->sp])); 33489c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(parser->qparentE[parser->sp].cuOff != D3_INVALID_CUOFF); 33495c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe if (level != parser->qlevel[parser->sp]+1) goto_bad_DIE; 33505c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe if (parser->qparentE[parser->sp].tag != Te_TyEnum) goto_bad_DIE; 3351b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Record this child in the parent */ 33529c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(parser->qparentE[parser->sp].Te.TyEnum.atomRs); 33539c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(addToXA)( parser->qparentE[parser->sp].Te.TyEnum.atomRs, 33549c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj &atomE ); 3355b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* And record the child itself */ 3356b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj goto acquire_Atom; 3357b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3358b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 33596a3a28409187ca6813b228afaf2af288c1fcd73dsewardj /* Treat DW_TAG_class_type as if it was a DW_TAG_structure_type. I 33606a3a28409187ca6813b228afaf2af288c1fcd73dsewardj don't know if this is correct, but it at least makes this reader 33616a3a28409187ca6813b228afaf2af288c1fcd73dsewardj usable for gcc-4.3 produced Dwarf3. */ 33626a3a28409187ca6813b228afaf2af288c1fcd73dsewardj if (dtag == DW_TAG_structure_type || dtag == DW_TAG_class_type 33636a3a28409187ca6813b228afaf2af288c1fcd73dsewardj || dtag == DW_TAG_union_type) { 3364b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool have_szB = False; 3365b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool is_decl = False; 3366b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool is_spec = False; 3367b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Create a new Type to hold the results. */ 33689c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)(&typeE, 0, sizeof(typeE)); 33699c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.cuOff = posn; 33709c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.tag = Te_TyStOrUn; 33719c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyStOrUn.name = NULL; 33720abc4193f82294904ed9478fa80394224c03fcc0dejanj typeE.Te.TyStOrUn.typeR = D3_INVALID_CUOFF; 33739c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyStOrUn.fieldRs 33749c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.pTD.struct_type.1", 33759c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ML_(dinfo_free), 33769c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj sizeof(UWord) ); 33779c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyStOrUn.complete = True; 33789c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyStOrUn.isStruct = dtag == DW_TAG_structure_type 33799c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj || dtag == DW_TAG_class_type; 3380746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 3381b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 3382746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 3383746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 3384746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 3385b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 33865d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 33875d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_name && cts.szB < 0) { 33889c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyStOrUn.name 33895d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = ML_(cur_read_strdup)( cts.u.cur, 33905d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj "di.readdwarf3.ptD.struct_type.2" ); 3391b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 33925d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_byte_size && cts.szB >= 0) { 33935d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj typeE.Te.TyStOrUn.szB = cts.u.val; 3394b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj have_szB = True; 3395b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 33965d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_declaration && cts.szB > 0 && cts.u.val > 0) { 3397b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj is_decl = True; 3398b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 33995d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_specification && cts.szB > 0 && cts.u.val > 0) { 3400b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj is_spec = True; 3401b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 34020abc4193f82294904ed9478fa80394224c03fcc0dejanj if (attr == DW_AT_signature && form == DW_FORM_ref_sig8 34030abc4193f82294904ed9478fa80394224c03fcc0dejanj && cts.szB > 0) { 34040abc4193f82294904ed9478fa80394224c03fcc0dejanj have_szB = True; 34050abc4193f82294904ed9478fa80394224c03fcc0dejanj typeE.Te.TyStOrUn.szB = 8; 34060abc4193f82294904ed9478fa80394224c03fcc0dejanj typeE.Te.TyStOrUn.typeR 34070abc4193f82294904ed9478fa80394224c03fcc0dejanj = cook_die_using_form( cc, (UWord)cts.u.val, form ); 34080abc4193f82294904ed9478fa80394224c03fcc0dejanj } 3409b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3410b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Do we have something that looks sane? */ 3411b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (is_decl && (!is_spec)) { 3412b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* It's a DW_AT_declaration. We require the name but 3413b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj nothing else. */ 3414ad4e979f408239dabbaae955d8ffcb84a51a5c85florian /* JRS 2012-06-28: following discussion w/ tromey, if the 341500888885d88a5264711c22074cfd3462020cbee6sewardj type doesn't have name, just make one up, and accept it. 341600888885d88a5264711c22074cfd3462020cbee6sewardj It might be referred to by other DIEs, so ignoring it 341700888885d88a5264711c22074cfd3462020cbee6sewardj doesn't seem like a safe option. */ 34189c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (typeE.Te.TyStOrUn.name == NULL) 341900888885d88a5264711c22074cfd3462020cbee6sewardj typeE.Te.TyStOrUn.name 342000888885d88a5264711c22074cfd3462020cbee6sewardj = ML_(dinfo_strdup)( "di.readdwarf3.ptD.struct_type.3", 342100888885d88a5264711c22074cfd3462020cbee6sewardj "<anon_struct_type>" ); 34229c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyStOrUn.complete = False; 3423b34bb1d378ba9e5b09e993ed9adbfaf151238878sewardj /* JRS 2009 Aug 10: <possible kludge>? */ 3424b34bb1d378ba9e5b09e993ed9adbfaf151238878sewardj /* Push this tyent on the stack, even though it's incomplete. 3425b34bb1d378ba9e5b09e993ed9adbfaf151238878sewardj It appears that gcc-4.4 on Fedora 11 will sometimes create 3426b34bb1d378ba9e5b09e993ed9adbfaf151238878sewardj DW_TAG_member entries for it, and so we need to have a 3427b34bb1d378ba9e5b09e993ed9adbfaf151238878sewardj plausible parent present in order for that to work. See 3428b34bb1d378ba9e5b09e993ed9adbfaf151238878sewardj #200029 comments 8 and 9. */ 3429b34bb1d378ba9e5b09e993ed9adbfaf151238878sewardj typestack_push( cc, parser, td3, &typeE, level ); 3430b34bb1d378ba9e5b09e993ed9adbfaf151238878sewardj /* </possible kludge> */ 3431b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj goto acquire_Type; 3432b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3433b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if ((!is_decl) /* && (!is_spec) */) { 3434b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* this is the common, ordinary case */ 34355c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe /* The name can be present, or not */ 34365c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe if (!have_szB) { 34375c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe /* We must know the size. 34385c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe But in Ada, record with discriminants might have no size. 34395c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe But in C, VLA in the middle of a struct (gcc extension) 34405c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe might have no size. 34415c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe Instead, some GNAT dwarf extensions and/or dwarf entries 34425c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe allow to calculate the struct size at runtime. 34435c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe We cannot do that (yet?) so, the temporary kludge is to use 34445c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe a small size. */ 34455c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe typeE.Te.TyStOrUn.szB = 1; 34465c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe } 3447b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* On't stack! */ 34489c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typestack_push( cc, parser, td3, &typeE, level ); 3449b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj goto acquire_Type; 3450b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3451b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj else { 3452b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* don't know how to handle any other variants just now */ 34535c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 3454b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3455b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3456b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3457b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (dtag == DW_TAG_member) { 3458b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Acquire member entries for both DW_TAG_structure_type and 3459b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_TAG_union_type. They differ minorly, in that struct 3460b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj members must have a DW_AT_data_member_location expression 3461b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj whereas union members must not. */ 3462b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool parent_is_struct; 34639c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)( &fieldE, 0, sizeof(fieldE) ); 34649c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj fieldE.cuOff = posn; 34659c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj fieldE.tag = Te_Field; 34669c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj fieldE.Te.Field.typeR = D3_INVALID_CUOFF; 3467746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 3468b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 3469746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 3470746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 3471746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 3472b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 34735d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 34745d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_name && cts.szB < 0) { 34759c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj fieldE.Te.Field.name 34765d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = ML_(cur_read_strdup)( cts.u.cur, 34775d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj "di.readdwarf3.ptD.member.1" ); 3478b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 34795d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_type && cts.szB > 0) { 34805d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj fieldE.Te.Field.typeR 34815d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = cook_die_using_form( cc, (UWord)cts.u.val, form ); 3482b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 34833c9cf3442185b5891e15450d6e3058aeff6796fetom /* There are 2 different cases for DW_AT_data_member_location. 34843c9cf3442185b5891e15450d6e3058aeff6796fetom If it is a constant class attribute, it contains byte offset 34853c9cf3442185b5891e15450d6e3058aeff6796fetom from the beginning of the containing entity. 34863c9cf3442185b5891e15450d6e3058aeff6796fetom Otherwise it is a location expression. */ 34875d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_data_member_location && cts.szB > 0) { 34883c9cf3442185b5891e15450d6e3058aeff6796fetom fieldE.Te.Field.nLoc = -1; 34895d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj fieldE.Te.Field.pos.offset = cts.u.val; 34905d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj } 34915d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_data_member_location && cts.szB <= 0) { 34925d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj fieldE.Te.Field.nLoc = (UWord)(-cts.szB); 34933c9cf3442185b5891e15450d6e3058aeff6796fetom fieldE.Te.Field.pos.loc 34945d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = ML_(cur_read_memdup)( cts.u.cur, 34955d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj (SizeT)fieldE.Te.Field.nLoc, 34965d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj "di.readdwarf3.ptD.member.2" ); 3497b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3498b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3499b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Do we have a plausible parent? */ 35005c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe if (typestack_is_empty(parser)) goto_bad_DIE; 35019c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ML_(TyEnt__is_type)(&parser->qparentE[parser->sp])); 35029c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(parser->qparentE[parser->sp].cuOff != D3_INVALID_CUOFF); 35035c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe if (level != parser->qlevel[parser->sp]+1) goto_bad_DIE; 35045c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe if (parser->qparentE[parser->sp].tag != Te_TyStOrUn) goto_bad_DIE; 3505b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Do we have something that looks sane? If this a member of a 3506b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj struct, we must have a location expression; but if a member 3507b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj of a union that is irrelevant (D3 spec sec 5.6.6). We ought 3508b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj to reject in the latter case, but some compilers have been 3509b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj observed to emit constant-zero expressions. So just ignore 3510b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj them. */ 3511b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj parent_is_struct 35129c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj = parser->qparentE[parser->sp].Te.TyStOrUn.isStruct; 35139c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (!fieldE.Te.Field.name) 35149c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj fieldE.Te.Field.name 35159c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj = ML_(dinfo_strdup)( "di.readdwarf3.ptD.member.3", 35169c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj "<anon_field>" ); 35179c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (fieldE.Te.Field.typeR == D3_INVALID_CUOFF) 35185c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 35193c9cf3442185b5891e15450d6e3058aeff6796fetom if (fieldE.Te.Field.nLoc) { 352007de5ddba10bfebab8416a8f79c349faa62bbaa1tom if (!parent_is_struct) { 352107de5ddba10bfebab8416a8f79c349faa62bbaa1tom /* If this is a union type, pretend we haven't seen the data 352207de5ddba10bfebab8416a8f79c349faa62bbaa1tom member location expression, as it is by definition 352307de5ddba10bfebab8416a8f79c349faa62bbaa1tom redundant (it must be zero). */ 35243c9cf3442185b5891e15450d6e3058aeff6796fetom if (fieldE.Te.Field.nLoc > 0) 35253c9cf3442185b5891e15450d6e3058aeff6796fetom ML_(dinfo_free)(fieldE.Te.Field.pos.loc); 35263c9cf3442185b5891e15450d6e3058aeff6796fetom fieldE.Te.Field.pos.loc = NULL; 352707de5ddba10bfebab8416a8f79c349faa62bbaa1tom fieldE.Te.Field.nLoc = 0; 352807de5ddba10bfebab8416a8f79c349faa62bbaa1tom } 352907de5ddba10bfebab8416a8f79c349faa62bbaa1tom /* Record this child in the parent */ 353007de5ddba10bfebab8416a8f79c349faa62bbaa1tom fieldE.Te.Field.isStruct = parent_is_struct; 353107de5ddba10bfebab8416a8f79c349faa62bbaa1tom vg_assert(parser->qparentE[parser->sp].Te.TyStOrUn.fieldRs); 353207de5ddba10bfebab8416a8f79c349faa62bbaa1tom VG_(addToXA)( parser->qparentE[parser->sp].Te.TyStOrUn.fieldRs, 353307de5ddba10bfebab8416a8f79c349faa62bbaa1tom &posn ); 353407de5ddba10bfebab8416a8f79c349faa62bbaa1tom /* And record the child itself */ 353507de5ddba10bfebab8416a8f79c349faa62bbaa1tom goto acquire_Field; 353607de5ddba10bfebab8416a8f79c349faa62bbaa1tom } else { 353707de5ddba10bfebab8416a8f79c349faa62bbaa1tom /* Member with no location - this can happen with static 353807de5ddba10bfebab8416a8f79c349faa62bbaa1tom const members in C++ code which are compile time constants 353907de5ddba10bfebab8416a8f79c349faa62bbaa1tom that do no exist in the class. They're not of any interest 354007de5ddba10bfebab8416a8f79c349faa62bbaa1tom to us so we ignore them. */ 3541d9df0ea979e3dd5b732b8cced076a105fa45f352philippe ML_(TyEnt__make_EMPTY)(&fieldE); 3542b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3543b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3544b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3545b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (dtag == DW_TAG_array_type) { 35469c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)(&typeE, 0, sizeof(typeE)); 35479c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.cuOff = posn; 35489c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.tag = Te_TyArray; 35499c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyArray.typeR = D3_INVALID_CUOFF; 35509c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyArray.boundRs 35519c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.ptD.array_type.1", 35529c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ML_(dinfo_free), 35539c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj sizeof(UWord) ); 3554746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 3555b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 3556746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 3557746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 3558746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 3559b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 35605d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 35615d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_type && cts.szB > 0) { 35625d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj typeE.Te.TyArray.typeR 35635d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = cook_die_using_form( cc, (UWord)cts.u.val, form ); 3564b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3565b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 35669c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (typeE.Te.TyArray.typeR == D3_INVALID_CUOFF) 35675c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 3568b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* On't stack! */ 35699c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typestack_push( cc, parser, td3, &typeE, level ); 3570b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj goto acquire_Type; 3571b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3572b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 35732acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj /* this is a subrange type defining the bounds of an array. */ 35742acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj if (dtag == DW_TAG_subrange_type 35752acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj && subrange_type_denotes_array_bounds(parser, dtag)) { 3576b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool have_lower = False; 3577b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool have_upper = False; 3578b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool have_count = False; 3579b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Long lower = 0; 3580b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Long upper = 0; 3581b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3582b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj switch (parser->language) { 3583b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case 'C': have_lower = True; lower = 0; break; 3584b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case 'F': have_lower = True; lower = 1; break; 3585b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj case '?': have_lower = False; break; 35862acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj case 'A': have_lower = False; break; 3587b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj default: vg_assert(0); /* assured us by handling of 3588b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_TAG_compile_unit in this fn */ 3589b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 35909c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 35919c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)( &boundE, 0, sizeof(boundE) ); 35929c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj boundE.cuOff = D3_INVALID_CUOFF; 35939c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj boundE.tag = Te_Bound; 3594746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 3595b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 3596746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 3597746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 3598746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 3599b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 36005d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 36015d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_lower_bound && cts.szB > 0) { 36025d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj lower = (Long)cts.u.val; 3603b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj have_lower = True; 3604b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 36055d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_upper_bound && cts.szB > 0) { 36065d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj upper = (Long)cts.u.val; 3607b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj have_upper = True; 3608b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 36095d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_count && cts.szB > 0) { 36105d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj /*count = (Long)cts.u.val;*/ 3611b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj have_count = True; 3612b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3613b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3614b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* FIXME: potentially skip the rest if no parent present, since 3615b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj it could be the case that this subrange type is free-standing 3616b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (not being used to describe the bounds of a containing array 3617b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj type) */ 3618b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Do we have a plausible parent? */ 36195c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe if (typestack_is_empty(parser)) goto_bad_DIE; 36209c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ML_(TyEnt__is_type)(&parser->qparentE[parser->sp])); 36219c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(parser->qparentE[parser->sp].cuOff != D3_INVALID_CUOFF); 36225c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe if (level != parser->qlevel[parser->sp]+1) goto_bad_DIE; 36235c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe if (parser->qparentE[parser->sp].tag != Te_TyArray) goto_bad_DIE; 3624b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3625b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Figure out if we have a definite range or not */ 3626b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (have_lower && have_upper && (!have_count)) { 36279c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj boundE.Te.Bound.knownL = True; 36289c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj boundE.Te.Bound.knownU = True; 36299c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj boundE.Te.Bound.boundL = lower; 36309c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj boundE.Te.Bound.boundU = upper; 363172259920f8cad01708271879caca023969463d16tom } 3632b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj else if (have_lower && (!have_upper) && (!have_count)) { 36339c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj boundE.Te.Bound.knownL = True; 36349c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj boundE.Te.Bound.knownU = False; 36359c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj boundE.Te.Bound.boundL = lower; 36369c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj boundE.Te.Bound.boundU = 0; 363772259920f8cad01708271879caca023969463d16tom } 363872259920f8cad01708271879caca023969463d16tom else if ((!have_lower) && have_upper && (!have_count)) { 363972259920f8cad01708271879caca023969463d16tom boundE.Te.Bound.knownL = False; 364072259920f8cad01708271879caca023969463d16tom boundE.Te.Bound.knownU = True; 364172259920f8cad01708271879caca023969463d16tom boundE.Te.Bound.boundL = 0; 364272259920f8cad01708271879caca023969463d16tom boundE.Te.Bound.boundU = upper; 364372259920f8cad01708271879caca023969463d16tom } 364472259920f8cad01708271879caca023969463d16tom else if ((!have_lower) && (!have_upper) && (!have_count)) { 364572259920f8cad01708271879caca023969463d16tom boundE.Te.Bound.knownL = False; 364672259920f8cad01708271879caca023969463d16tom boundE.Te.Bound.knownU = False; 364772259920f8cad01708271879caca023969463d16tom boundE.Te.Bound.boundL = 0; 364872259920f8cad01708271879caca023969463d16tom boundE.Te.Bound.boundU = 0; 3649b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else { 3650b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* FIXME: handle more cases */ 36515c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 3652b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3653b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3654b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Record this bound in the parent */ 36559c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj boundE.cuOff = posn; 36569c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(parser->qparentE[parser->sp].Te.TyArray.boundRs); 36579c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(addToXA)( parser->qparentE[parser->sp].Te.TyArray.boundRs, 3658471d6b3eba2d617279c3954a13e322174a0eec13sewardj &boundE.cuOff ); 3659b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* And record the child itself */ 36609c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj goto acquire_Bound; 3661b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3662b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 36632acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj /* typedef or subrange_type other than array bounds. */ 36642acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj if (dtag == DW_TAG_typedef 36652acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj || (dtag == DW_TAG_subrange_type 36662acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj && !subrange_type_denotes_array_bounds(parser, dtag))) { 36672acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj /* subrange_type other than array bound is only for Ada. */ 36682acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj vg_assert (dtag == DW_TAG_typedef || parser->language == 'A'); 36692acc87cac77cedb3884e9e3a5188bac6edda5aeesewardj /* We can pick up a new typedef/subrange_type any time. */ 36709c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)(&typeE, 0, sizeof(typeE)); 36719c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.cuOff = D3_INVALID_CUOFF; 36729c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.tag = Te_TyTyDef; 36739c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyTyDef.name = NULL; 36749c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyTyDef.typeR = D3_INVALID_CUOFF; 3675746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 3676b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 3677746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 3678746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 3679746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 3680b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 36815d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 36825d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_name && cts.szB < 0) { 36839c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyTyDef.name 36845d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = ML_(cur_read_strdup)( cts.u.cur, 36855d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj "di.readdwarf3.ptD.typedef.1" ); 3686b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 36875d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_type && cts.szB > 0) { 36885d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj typeE.Te.TyTyDef.typeR 36895d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = cook_die_using_form( cc, (UWord)cts.u.val, form ); 3690b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3691b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3692e5cf4510a6c26279e0b7f625dc615f94b8fbdebfmjw /* Do we have something that looks sane? 3693e5cf4510a6c26279e0b7f625dc615f94b8fbdebfmjw gcc gnat Ada generates minimal typedef 3694e5cf4510a6c26279e0b7f625dc615f94b8fbdebfmjw such as the below 3695e5cf4510a6c26279e0b7f625dc615f94b8fbdebfmjw <6><91cc>: DW_TAG_typedef 3696e5cf4510a6c26279e0b7f625dc615f94b8fbdebfmjw DW_AT_abstract_ori: <9066> 3697e5cf4510a6c26279e0b7f625dc615f94b8fbdebfmjw g++ for OMP can generate artificial functions that have 3698e5cf4510a6c26279e0b7f625dc615f94b8fbdebfmjw parameters that refer to pointers to unnamed typedefs. 3699e5cf4510a6c26279e0b7f625dc615f94b8fbdebfmjw See https://bugs.kde.org/show_bug.cgi?id=273475 3700e5cf4510a6c26279e0b7f625dc615f94b8fbdebfmjw So we cannot require a name for a DW_TAG_typedef. 3701e5cf4510a6c26279e0b7f625dc615f94b8fbdebfmjw */ 3702e5cf4510a6c26279e0b7f625dc615f94b8fbdebfmjw goto acquire_Type; 3703b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3704b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3705b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (dtag == DW_TAG_subroutine_type) { 3706b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* function type? just record that one fact and ask no 3707b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj further questions. */ 37089c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)(&typeE, 0, sizeof(typeE)); 37099c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.cuOff = D3_INVALID_CUOFF; 37109c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.tag = Te_TyFn; 3711b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj goto acquire_Type; 3712b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3713b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3714c81436d329fa0be3dfb4c2bfd1b4783e0489884fmjw if (dtag == DW_TAG_volatile_type || dtag == DW_TAG_const_type 3715c81436d329fa0be3dfb4c2bfd1b4783e0489884fmjw || dtag == DW_TAG_restrict_type) { 3716b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Int have_ty = 0; 37179c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(memset)(&typeE, 0, sizeof(typeE)); 37189c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.cuOff = D3_INVALID_CUOFF; 37199c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.tag = Te_TyQual; 37209c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyQual.qual 3721c81436d329fa0be3dfb4c2bfd1b4783e0489884fmjw = (dtag == DW_TAG_volatile_type ? 'V' 3722c81436d329fa0be3dfb4c2bfd1b4783e0489884fmjw : (dtag == DW_TAG_const_type ? 'C' : 'R')); 3723b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* target type defaults to 'void' */ 37249c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.Te.TyQual.typeR = D3_FAKEVOID_CUOFF; 3725746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i = 0; 3726b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 3727746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_AT attr = (DW_AT) abbv->nf[nf_i].at_name; 3728746e97e7098def65d59c79d5d661f9a757a837cdphilippe DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form; 3729746e97e7098def65d59c79d5d661f9a757a837cdphilippe nf_i++; 3730b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (attr == 0 && form == 0) break; 37315d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj get_Form_contents( &cts, cc, c_die, False/*td3*/, form ); 37325d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (attr == DW_AT_type && cts.szB > 0) { 37335d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj typeE.Te.TyQual.typeR 37345d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj = cook_die_using_form( cc, (UWord)cts.u.val, form ); 3735b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj have_ty++; 3736b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3737b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3738b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* gcc sometimes generates DW_TAG_const/volatile_type without 3739b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj DW_AT_type and GDB appears to interpret the type as 'const 3740b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj void' (resp. 'volatile void'). So just allow it .. */ 3741b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (have_ty == 1 || have_ty == 0) 3742b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj goto acquire_Type; 3743b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj else 37445c5b8fc1da94607b804e408a38f073c4d6f3b76fphilippe goto_bad_DIE; 3745b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 3746b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3747e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart /* 3748e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart * Treat DW_TAG_unspecified_type as type void. An example of DW_TAG_unspecified_type: 3749e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart * 3750e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart * $ readelf --debug-dump /usr/lib/debug/usr/lib/libstdc++.so.6.0.16.debug 3751e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart * <1><10d4>: Abbrev Number: 53 (DW_TAG_unspecified_type) 3752e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart * <10d5> DW_AT_name : (indirect string, offset: 0xdb7): decltype(nullptr) 3753e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart */ 3754e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart if (dtag == DW_TAG_unspecified_type) { 3755e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart VG_(memset)(&typeE, 0, sizeof(typeE)); 3756e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart typeE.cuOff = D3_INVALID_CUOFF; 3757e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart typeE.tag = Te_TyQual; 3758e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart typeE.Te.TyQual.typeR = D3_FAKEVOID_CUOFF; 3759e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart goto acquire_Type; 3760e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart } 3761e64c5a9a6c0d9c87bc7a65629455d2ff7fb9bda4bart 3762b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* else ignore this DIE */ 3763b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return; 3764b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*NOTREACHED*/ 3765b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3766b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj acquire_Type: 3767b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (0) VG_(printf)("YYYY Acquire Type\n"); 37689c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ML_(TyEnt__is_type)( &typeE )); 37699c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(typeE.cuOff == D3_INVALID_CUOFF || typeE.cuOff == posn); 37709c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj typeE.cuOff = posn; 37719c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(addToXA)( tyents, &typeE ); 3772b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return; 3773b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*NOTREACHED*/ 3774b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3775b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj acquire_Atom: 3776b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (0) VG_(printf)("YYYY Acquire Atom\n"); 37779c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(atomE.tag == Te_Atom); 37789c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(atomE.cuOff == D3_INVALID_CUOFF || atomE.cuOff == posn); 37799c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj atomE.cuOff = posn; 37809c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(addToXA)( tyents, &atomE ); 3781b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return; 3782b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*NOTREACHED*/ 3783b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 37849c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj acquire_Field: 3785b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* For union members, Expr should be absent */ 37869c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (0) VG_(printf)("YYYY Acquire Field\n"); 37879c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(fieldE.tag == Te_Field); 37883c9cf3442185b5891e15450d6e3058aeff6796fetom vg_assert(fieldE.Te.Field.nLoc <= 0 || fieldE.Te.Field.pos.loc != NULL); 37893c9cf3442185b5891e15450d6e3058aeff6796fetom vg_assert(fieldE.Te.Field.nLoc != 0 || fieldE.Te.Field.pos.loc == NULL); 37909c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (fieldE.Te.Field.isStruct) { 37913c9cf3442185b5891e15450d6e3058aeff6796fetom vg_assert(fieldE.Te.Field.nLoc != 0); 37929c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } else { 37939c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(fieldE.Te.Field.nLoc == 0); 37949c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 37959c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(fieldE.cuOff == D3_INVALID_CUOFF || fieldE.cuOff == posn); 37969c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj fieldE.cuOff = posn; 37979c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(addToXA)( tyents, &fieldE ); 3798b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return; 3799b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*NOTREACHED*/ 3800b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 38019c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj acquire_Bound: 38029c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (0) VG_(printf)("YYYY Acquire Bound\n"); 38039c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(boundE.tag == Te_Bound); 38049c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(boundE.cuOff == D3_INVALID_CUOFF || boundE.cuOff == posn); 38059c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj boundE.cuOff = posn; 38069c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(addToXA)( tyents, &boundE ); 3807b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return; 3808b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*NOTREACHED*/ 3809b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3810b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj bad_DIE: 3811896a3bfd1b98aa3358a2e77be3bb728cb3d2926fphilippe dump_bad_die_and_barf("parse_type_DIE", dtag, posn, level, 3812a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe c_die, saved_die_c_offset, 3813a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe abbv, 3814a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc); 3815b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*NOTREACHED*/ 3816b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 3817b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3818b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 3819b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 3820b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 38219c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj/*--- Compression of type DIE information ---*/ 3822b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 3823b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 3824b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 38259c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjstatic UWord chase_cuOff ( Bool* changed, 38263297124fa2116737066ac3cd709f18fdd5405163florian const XArray* /* of TyEnt */ ents, 38279c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEntIndexCache* ents_cache, 38289c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj UWord cuOff ) 38299c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj{ 38309c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEnt* ent; 38319c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ent = ML_(TyEnts__index_by_cuOff)( ents, ents_cache, cuOff ); 3832b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 38339c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (!ent) { 38349c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(printf)("chase_cuOff: no entry for 0x%05lx\n", cuOff); 38359c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj *changed = False; 38369c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj return cuOff; 38379c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 383859a2d18d0ddfa241850017252b0804d469187d79sewardj 38399c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ent->tag != Te_EMPTY); 38409c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (ent->tag != Te_INDIR) { 38419c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj *changed = False; 38429c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj return cuOff; 38439c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } else { 38449c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ent->Te.INDIR.indR < cuOff); 38459c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj *changed = True; 38469c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj return ent->Te.INDIR.indR; 3847b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 38489c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj} 3849b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 38509c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjstatic 38519c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjvoid chase_cuOffs_in_XArray ( Bool* changed, 38523297124fa2116737066ac3cd709f18fdd5405163florian const XArray* /* of TyEnt */ ents, 38539c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEntIndexCache* ents_cache, 38549c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/XArray* /* of UWord */ cuOffs ) 38559c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj{ 38569c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Bool b2 = False; 38579c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Word i, n = VG_(sizeXA)( cuOffs ); 38589c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj for (i = 0; i < n; i++) { 38599c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Bool b = False; 38609c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj UWord* p = VG_(indexXA)( cuOffs, i ); 38619c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj *p = chase_cuOff( &b, ents, ents_cache, *p ); 38629c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (b) 38639c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj b2 = True; 38649c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 38659c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj *changed = b2; 3866b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 3867b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 38683297124fa2116737066ac3cd709f18fdd5405163florianstatic Bool TyEnt__subst_R_fields ( const XArray* /* of TyEnt */ ents, 38699c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEntIndexCache* ents_cache, 38709c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/TyEnt* te ) 38719c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj{ 38729c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Bool b, changed = False; 38739c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj switch (te->tag) { 38749c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_EMPTY: 38759c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 38769c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_INDIR: 38779c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj te->Te.INDIR.indR 38789c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj = chase_cuOff( &b, ents, ents_cache, te->Te.INDIR.indR ); 38799c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (b) changed = True; 38809c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 38819c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_UNKNOWN: 38829c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 38839c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_Atom: 38849c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 38859c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_Field: 38869c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj te->Te.Field.typeR 38879c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj = chase_cuOff( &b, ents, ents_cache, te->Te.Field.typeR ); 38889c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (b) changed = True; 38899c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 38909c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_Bound: 38919c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 38929c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_TyBase: 38939c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 38940e947cfedebda6da2e84fb61af431db5cf1275fcbart case Te_TyPtr: 38950e947cfedebda6da2e84fb61af431db5cf1275fcbart case Te_TyRef: 38960e947cfedebda6da2e84fb61af431db5cf1275fcbart case Te_TyPtrMbr: 38970e947cfedebda6da2e84fb61af431db5cf1275fcbart case Te_TyRvalRef: 38989c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj te->Te.TyPorR.typeR 38999c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj = chase_cuOff( &b, ents, ents_cache, te->Te.TyPorR.typeR ); 39009c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (b) changed = True; 39019c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 39029c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_TyTyDef: 39039c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj te->Te.TyTyDef.typeR 39049c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj = chase_cuOff( &b, ents, ents_cache, te->Te.TyTyDef.typeR ); 39059c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (b) changed = True; 39069c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 39079c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_TyStOrUn: 39089c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj chase_cuOffs_in_XArray( &b, ents, ents_cache, te->Te.TyStOrUn.fieldRs ); 39099c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (b) changed = True; 39109c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 39119c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_TyEnum: 39129c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj chase_cuOffs_in_XArray( &b, ents, ents_cache, te->Te.TyEnum.atomRs ); 39139c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (b) changed = True; 39149c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 39159c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_TyArray: 39169c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj te->Te.TyArray.typeR 39179c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj = chase_cuOff( &b, ents, ents_cache, te->Te.TyArray.typeR ); 39189c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (b) changed = True; 39199c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj chase_cuOffs_in_XArray( &b, ents, ents_cache, te->Te.TyArray.boundRs ); 39209c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (b) changed = True; 39219c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 39229c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_TyFn: 39239c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 39249c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_TyQual: 39259c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj te->Te.TyQual.typeR 39269c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj = chase_cuOff( &b, ents, ents_cache, te->Te.TyQual.typeR ); 39279c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (b) changed = True; 39289c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 39299c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj case Te_TyVoid: 39309c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj break; 39319c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj default: 39329c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ML_(pp_TyEnt)(te); 39339c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(0); 39349c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 39359c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj return changed; 39369c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj} 393759a2d18d0ddfa241850017252b0804d469187d79sewardj 39389c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj/* Make a pass over 'ents'. For each tyent, inspect the target of any 39399c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 'R' or 'Rs' fields (those which refer to other tyents), and replace 39409c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj any which point to INDIR nodes with the target of the indirection 39419c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj (which should not itself be an indirection). In summary, this 39429c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj routine shorts out all references to indirection nodes. */ 39439c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjstatic 39449c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjWord dedup_types_substitution_pass ( /*MOD*/XArray* /* of TyEnt */ ents, 39459c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEntIndexCache* ents_cache ) 39469c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj{ 39479c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Word i, n, nChanged = 0; 39489c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Bool b; 39499c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj n = VG_(sizeXA)( ents ); 39509c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj for (i = 0; i < n; i++) { 39519c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEnt* ent = VG_(indexXA)( ents, i ); 39529c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ent->tag != Te_EMPTY); 39539c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* We have to substitute everything, even indirections, so as to 39549c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ensure that chains of indirections don't build up. */ 39559c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj b = TyEnt__subst_R_fields( ents, ents_cache, ent ); 39569c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (b) 39579c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj nChanged++; 39589c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 395959a2d18d0ddfa241850017252b0804d469187d79sewardj 39609c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj return nChanged; 39619c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj} 396259a2d18d0ddfa241850017252b0804d469187d79sewardj 396359a2d18d0ddfa241850017252b0804d469187d79sewardj 39649c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj/* Make a pass over 'ents', building a dictionary of TyEnts as we go. 39659c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Look up each new tyent in the dictionary in turn. If it is already 39669c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj in the dictionary, replace this tyent with an indirection to the 39679c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj existing one, and delete any malloc'd stuff hanging off this one. 39689c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj In summary, this routine commons up all tyents that are identical 39699c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj as defined by TyEnt__cmp_by_all_except_cuOff. */ 39709c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjstatic 39719c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjWord dedup_types_commoning_pass ( /*MOD*/XArray* /* of TyEnt */ ents ) 3972b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 39739c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Word n, i, nDeleted; 39749c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj WordFM* dict; /* TyEnt* -> void */ 39759c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEnt* ent; 39769c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj UWord keyW, valW; 39779c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 39789c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj dict = VG_(newFM)( 39799c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ML_(dinfo_zalloc), "di.readdwarf3.dtcp.1", 39809c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ML_(dinfo_free), 39819c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj (Word(*)(UWord,UWord)) ML_(TyEnt__cmp_by_all_except_cuOff) 39829c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ); 39839c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 39849c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj nDeleted = 0; 39859c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj n = VG_(sizeXA)( ents ); 39869c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj for (i = 0; i < n; i++) { 39879c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ent = VG_(indexXA)( ents, i ); 39889c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ent->tag != Te_EMPTY); 39899c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 39909c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* Ignore indirections, although check that they are 39919c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj not forming a cycle. */ 39929c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (ent->tag == Te_INDIR) { 39939c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ent->Te.INDIR.indR < ent->cuOff); 39949c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj continue; 39959c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 3996b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 39979c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj keyW = valW = 0; 39989c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (VG_(lookupFM)( dict, &keyW, &valW, (UWord)ent )) { 39999c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* it's already in the dictionary. */ 40009c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEnt* old = (TyEnt*)keyW; 40019c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(valW == 0); 40029c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(old != ent); 40039c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(old->tag != Te_INDIR); 40049c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* since we are traversing the array in increasing order of 40059c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj cuOff: */ 40069c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(old->cuOff < ent->cuOff); 40079c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* So anyway, dump this entry and replace it with an 40089c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj indirection to the one in the dictionary. Note that the 40099c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj assertion above guarantees that we cannot create cycles of 40109c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj indirections, since we are always creating an indirection 40119c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj to a tyent with a cuOff lower than this one. */ 40129c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ML_(TyEnt__make_EMPTY)( ent ); 40139c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ent->tag = Te_INDIR; 40149c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ent->Te.INDIR.indR = old->cuOff; 40159c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj nDeleted++; 40169c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } else { 40179c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* not in dictionary; add it and keep going. */ 40189c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(addToFM)( dict, (UWord)ent, 0 ); 40199c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 40209c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 40219c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 40229c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(deleteFM)( dict, NULL, NULL ); 402359a2d18d0ddfa241850017252b0804d469187d79sewardj 40249c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj return nDeleted; 40259c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj} 4026b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4027b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 40289c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjstatic 40299c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjvoid dedup_types ( Bool td3, 40309c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/XArray* /* of TyEnt */ ents, 40319c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEntIndexCache* ents_cache ) 40329c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj{ 40339c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Word m, n, i, nDel, nSubst, nThresh; 40349c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (0) td3 = True; 40359c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 40369c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj n = VG_(sizeXA)( ents ); 40379c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 40389c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* If a commoning pass and a substitution pass both make fewer than 40399c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj this many changes, just stop. It's pointless to burn up CPU 40409c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj time trying to compress the last 1% or so out of the array. */ 40419c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj nThresh = n / 200; 40429c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 40439c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* First we must sort .ents by its .cuOff fields, so we 40449c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj can index into it. */ 40456bd9dc18c043927c1196caba20a327238a179c42florian VG_(setCmpFnXA)( ents, (XACmpFn_t) ML_(TyEnt__cmp_by_cuOff_only) ); 40469c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(sortXA)( ents ); 40479c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 40489c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* Now repeatedly do commoning and substitution passes over 40499c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj the array, until there are no more changes. */ 40509c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj do { 40519c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj nDel = dedup_types_commoning_pass ( ents ); 40529c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj nSubst = dedup_types_substitution_pass ( ents, ents_cache ); 40539c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(nDel >= 0 && nSubst >= 0); 40549c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TRACE_D3(" %ld deletions, %ld substitutions\n", nDel, nSubst); 40559c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } while (nDel > nThresh || nSubst > nThresh); 40569c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 40579c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* Sanity check: all INDIR nodes should point at a non-INDIR thing. 40589c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj In fact this should be true at the end of every loop iteration 40599c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj above (a commoning pass followed by a substitution pass), but 40609c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj checking it on every iteration is excessively expensive. Note, 40619c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj this loop also computes 'm' for the stats printing below it. */ 40629c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj m = 0; 40639c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj n = VG_(sizeXA)( ents ); 406459a2d18d0ddfa241850017252b0804d469187d79sewardj for (i = 0; i < n; i++) { 40659c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEnt *ent, *ind; 40669c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ent = VG_(indexXA)( ents, i ); 40679c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (ent->tag != Te_INDIR) continue; 40689c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj m++; 40699c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ind = ML_(TyEnts__index_by_cuOff)( ents, ents_cache, 40709c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ent->Te.INDIR.indR ); 40719c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ind); 40729c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ind->tag != Te_INDIR); 4073b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4074b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 40759c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TRACE_D3("Overall: %ld before, %ld after\n", n, n-m); 40769c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj} 40779c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 40789c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 40799c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj/*------------------------------------------------------------*/ 40809c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj/*--- ---*/ 40819c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj/*--- Resolution of references to type DIEs ---*/ 40829c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj/*--- ---*/ 40839c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj/*------------------------------------------------------------*/ 40849c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 40859c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj/* Make a pass through the (temporary) variables array. Examine the 40869c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj type of each variable, check is it found, and chase any Te_INDIRs. 40879c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Postcondition is: each variable has a typeR field that refers to a 40889c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj valid type in tyents, or a Te_UNKNOWN, and is certainly guaranteed 40899c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj not to refer to a Te_INDIR. (This is so that we can throw all the 40909c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Te_INDIRs away later). */ 40919c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 40929c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj__attribute__((noinline)) 40939c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjstatic void resolve_variable_types ( 40946bd9dc18c043927c1196caba20a327238a179c42florian void (*barf)( const HChar* ) __attribute__((noreturn)), 40959c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*R-O*/XArray* /* of TyEnt */ ents, 40969c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/TyEntIndexCache* ents_cache, 40979c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/XArray* /* of TempVar* */ vars 40989c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ) 40999c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj{ 41009c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Word i, n; 410159a2d18d0ddfa241850017252b0804d469187d79sewardj n = VG_(sizeXA)( vars ); 410259a2d18d0ddfa241850017252b0804d469187d79sewardj for (i = 0; i < n; i++) { 410359a2d18d0ddfa241850017252b0804d469187d79sewardj TempVar* var = *(TempVar**)VG_(indexXA)( vars, i ); 41049c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* This is the stated type of the variable. But it might be 41059c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj an indirection, so be careful. */ 41069c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TyEnt* ent = ML_(TyEnts__index_by_cuOff)( ents, ents_cache, 41079c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj var->typeR ); 41089c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (ent && ent->tag == Te_INDIR) { 41099c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ent = ML_(TyEnts__index_by_cuOff)( ents, ents_cache, 41109c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj ent->Te.INDIR.indR ); 41119c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ent); 41129c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ent->tag != Te_INDIR); 41139c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 4114b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 41159c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* Deal first with "normal" cases */ 41169c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (ent && ML_(TyEnt__is_type)(ent)) { 41179c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj var->typeR = ent->cuOff; 41189c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj continue; 41199c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 41209c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 41219c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* If there's no ent, it probably we did not manage to read a 41229c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj type at the cuOffset which is stated as being this variable's 41239c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj type. Maybe a deficiency in parse_type_DIE. Complain. */ 41249c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj if (ent == NULL) { 41259c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj VG_(printf)("\n: Invalid cuOff = 0x%05lx\n", var->typeR ); 41269c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj barf("resolve_variable_types: " 41279c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj "cuOff does not refer to a known type"); 41289c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 41299c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ent); 41309c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* If ent has any other tag, something bad happened, along the 41319c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj lines of var->typeR not referring to a type at all. */ 41329c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj vg_assert(ent->tag == Te_UNKNOWN); 41339c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /* Just accept it; the type will be useless, but at least keep 41349c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj going. */ 41359c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj var->typeR = ent->cuOff; 4136b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4137b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 4138b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4139b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4140b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 4141b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 4142b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- Parsing of Compilation Units ---*/ 4143b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 4144b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 4145b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 41466bd9dc18c043927c1196caba20a327238a179c42florianstatic Int cmp_TempVar_by_dioff ( const void* v1, const void* v2 ) { 41473e7986312a0ffc7646b0552d4c4ea3744a870e73florian const TempVar* t1 = *(const TempVar *const *)v1; 41483e7986312a0ffc7646b0552d4c4ea3744a870e73florian const TempVar* t2 = *(const TempVar *const *)v2; 4149b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (t1->dioff < t2->dioff) return -1; 4150b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (t1->dioff > t2->dioff) return 1; 4151b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj return 0; 4152b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 4153b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 41549c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardjstatic void read_DIE ( 41559c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/WordFM* /* of (XArray* of AddrRange, void) */ rangestree, 41569c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/XArray* /* of TyEnt */ tyents, 41579c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/XArray* /* of TempVar* */ tempvars, 41589c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/XArray* /* of GExpr* */ gexprs, 41599c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/D3TypeParser* typarser, 41609c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj /*MOD*/D3VarParser* varparser, 4161a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /*MOD*/D3InlParser* inlparser, 41629c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Cursor* c, Bool td3, CUConst* cc, Int level 41639c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj) 4164b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 4165518850bf0da07ed3e2244e307268ae0fd80e93a8florian const g_abbv *abbv; 4166b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ULong atag, abbv_code; 4167b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord posn; 4168b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UInt has_children; 4169746e97e7098def65d59c79d5d661f9a757a837cdphilippe UWord start_die_c_offset; 4170746e97e7098def65d59c79d5d661f9a757a837cdphilippe UWord after_die_c_offset; 4171a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe // If the DIE we will parse has a sibling and the parser(s) are 4172a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe // all indicating that parse_children is not necessary, then 4173a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe // we will skip the children by jumping to the sibling of this DIE 4174a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe // (if it has a sibling). 4175a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe UWord sibling = 0; 4176a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Bool parse_children = False; 4177b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4178b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* --- Deal with this DIE --- */ 4179d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj posn = cook_die( cc, get_position_of_Cursor( c ) ); 4180b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj abbv_code = get_ULEB128( c ); 4181746e97e7098def65d59c79d5d661f9a757a837cdphilippe abbv = get_abbv(cc, abbv_code); 4182746e97e7098def65d59c79d5d661f9a757a837cdphilippe atag = abbv->atag; 418386be6ed340d2373ffded269f57aa87765430ddccphilippe 4184e0bd5910153720d5d15697db8063d0d4caa59d8fphilippe if (TD3) { 418586be6ed340d2373ffded269f57aa87765430ddccphilippe TRACE_D3("\n"); 418686be6ed340d2373ffded269f57aa87765430ddccphilippe trace_DIE ((DW_TAG)atag, posn, level, 418786be6ed340d2373ffded269f57aa87765430ddccphilippe get_position_of_Cursor( c ), abbv, cc); 418886be6ed340d2373ffded269f57aa87765430ddccphilippe } 4189b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4190b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (atag == 0) 4191b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->barf("read_DIE: invalid zero tag on DIE"); 4192b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4193746e97e7098def65d59c79d5d661f9a757a837cdphilippe has_children = abbv->has_children; 4194b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (has_children != DW_children_no && has_children != DW_children_yes) 4195b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj cc->barf("read_DIE: invalid has_children value"); 4196b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4197b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* We're set up to look at the fields of this DIE. Hand it off to 4198b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj any parser(s) that want to see it. Since they will in general 41990d2ea9d1cfd6f1fff0992096c2d15881becfe2e1philippe advance the DIE cursor, remember the current settings so that we 4200d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe can then back up. . */ 4201b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj start_die_c_offset = get_position_of_Cursor( c ); 4202d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe after_die_c_offset = 0; // set to c position if a parser has read the DIE. 4203b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4204a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (VG_(clo_read_var_info)) { 4205a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe parse_type_DIE( tyents, 4206a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe typarser, 4207a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe (DW_TAG)atag, 4208a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe posn, 4209a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe level, 4210a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe c, /* DIE cursor */ 4211a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe abbv, /* abbrev */ 4212a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc, 4213a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe td3 ); 4214d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe if (get_position_of_Cursor( c ) != start_die_c_offset) { 4215d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe after_die_c_offset = get_position_of_Cursor( c ); 4216d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe set_position_of_Cursor( c, start_die_c_offset ); 4217d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe } 4218a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4219a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe parse_var_DIE( rangestree, 4220a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tempvars, 4221a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe gexprs, 4222a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varparser, 4223a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe (DW_TAG)atag, 4224a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe posn, 4225a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe level, 4226a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe c, /* DIE cursor */ 4227a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe abbv, /* abbrev */ 4228a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc, 4229a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe td3 ); 4230d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe if (get_position_of_Cursor( c ) != start_die_c_offset) { 4231d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe after_die_c_offset = get_position_of_Cursor( c ); 4232d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe set_position_of_Cursor( c, start_die_c_offset ); 4233d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe } 4234a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4235a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe parse_children = True; 4236d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe // type and var parsers do not have logic to skip childrens and establish 4237d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe // the value of sibling. 4238a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4239a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4240a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (VG_(clo_read_inline_info)) { 4241d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe inlparser->sibling = 0; 4242a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe parse_children = 4243a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe parse_inl_DIE( inlparser, 4244a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe (DW_TAG)atag, 4245a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe posn, 4246a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe level, 4247a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe c, /* DIE cursor */ 4248a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe abbv, /* abbrev */ 4249a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc, 4250a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe td3 ) 4251a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe || parse_children; 4252d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe if (get_position_of_Cursor( c ) != start_die_c_offset) { 4253d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe after_die_c_offset = get_position_of_Cursor( c ); 4254d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe // Last parser, no need to reset the cursor to start_die_c_offset. 4255d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe } 4256d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe if (sibling == 0) 4257d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe sibling = inlparser->sibling; 4258d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe vg_assert (inlparser->sibling == 0 || inlparser->sibling == sibling); 4259a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4260b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4261d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe if (after_die_c_offset > 0) { 4262d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe // DIE was read by a parser above, so we know where the DIE ends. 4263d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe set_position_of_Cursor( c, after_die_c_offset ); 4264d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe } else { 4265e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe /* No parser has parsed this DIE. So, we need to skip the DIE, 4266e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe in order to read the next DIE. 4267d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe At the same time, establish sibling value if the DIE has one. */ 4268e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe TRACE_D3(" uninteresting DIE -> skipping ...\n"); 4269e1f94b89c69cb3a71dce6800f6dbf8d045d935f6philippe skip_DIE (&sibling, c, abbv, cc); 4270d16fb63bfee12beb45f85695b4aed7a18bde56e1philippe } 4271b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4272a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* --- Now recurse into its children, if any 4273a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe and the parsing of the children is requested by a parser --- */ 4274b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (has_children == DW_children_yes) { 4275a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (parse_children || sibling == 0) { 4276a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (0) TRACE_D3("BEGIN children of level %d\n", level); 4277a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe while (True) { 4278a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe atag = peek_ULEB128( c ); 4279a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (atag == 0) break; 4280a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe read_DIE( rangestree, tyents, tempvars, gexprs, 4281a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe typarser, varparser, inlparser, 4282a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe c, td3, cc, level+1 ); 4283a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4284a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Now we need to eat the terminating zero */ 4285a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe atag = get_ULEB128( c ); 4286a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(atag == 0); 4287a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (0) TRACE_D3("END children of level %d\n", level); 4288a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } else { 4289a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe // We can skip the childrens, by jumping to the sibling 429086be6ed340d2373ffded269f57aa87765430ddccphilippe TRACE_D3(" SKIPPING DIE's children," 4291a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe "jumping to sibling <%d><%lx>\n", 4292a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe level, sibling); 4293a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe set_position_of_Cursor( c, sibling ); 4294b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4295b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4296b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4297b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 4298b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4299518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic void trace_debug_loc (const DebugInfo* di, 4300c9831572483ed485438553d4c39686605d2625d6philippe __attribute__((noreturn)) void (*barf)( const HChar* ), 4301c9831572483ed485438553d4c39686605d2625d6philippe DiSlice escn_debug_loc) 4302b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 4303b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#if 0 4304b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* This doesn't work properly because it assumes all entries are 4305b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj packed end to end, with no holes. But that doesn't always 4306b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj appear to be the case, so it loses sync. And the D3 spec 4307b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj doesn't appear to require a no-hole situation either. */ 4308b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Display .debug_loc */ 4309b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Addr dl_base; 4310b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UWord dl_offset; 4311b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Cursor loc; /* for showing .debug_loc */ 4312c9831572483ed485438553d4c39686605d2625d6philippe Bool td3 = di->trace_symtab; 4313c9831572483ed485438553d4c39686605d2625d6philippe 4314b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_SYMTAB("\n"); 4315b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_SYMTAB("\n------ The contents of .debug_loc ------\n"); 4316b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_SYMTAB(" Offset Begin End Expression\n"); 4317c9831572483ed485438553d4c39686605d2625d6philippe if (ML_(sli_is_valid)(escn_debug_loc)) { 4318c9831572483ed485438553d4c39686605d2625d6philippe init_Cursor( &loc, escn_debug_loc, 0, barf, 4319c9831572483ed485438553d4c39686605d2625d6philippe "Overrun whilst reading .debug_loc section(1)" ); 4320c9831572483ed485438553d4c39686605d2625d6philippe dl_base = 0; 4321c9831572483ed485438553d4c39686605d2625d6philippe dl_offset = 0; 4322c9831572483ed485438553d4c39686605d2625d6philippe while (True) { 4323c9831572483ed485438553d4c39686605d2625d6philippe UWord w1, w2; 4324c9831572483ed485438553d4c39686605d2625d6philippe UWord len; 4325c9831572483ed485438553d4c39686605d2625d6philippe if (is_at_end_Cursor( &loc )) 4326c9831572483ed485438553d4c39686605d2625d6philippe break; 4327b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4328c9831572483ed485438553d4c39686605d2625d6philippe /* Read a (host-)word pair. This is something of a hack since 4329c9831572483ed485438553d4c39686605d2625d6philippe the word size to read is really dictated by the ELF file; 4330c9831572483ed485438553d4c39686605d2625d6philippe however, we assume we're reading a file with the same 4331c9831572483ed485438553d4c39686605d2625d6philippe word-sizeness as the host. Reasonably enough. */ 4332c9831572483ed485438553d4c39686605d2625d6philippe w1 = get_UWord( &loc ); 4333c9831572483ed485438553d4c39686605d2625d6philippe w2 = get_UWord( &loc ); 4334b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4335c9831572483ed485438553d4c39686605d2625d6philippe if (w1 == 0 && w2 == 0) { 4336c9831572483ed485438553d4c39686605d2625d6philippe /* end of list. reset 'base' */ 4337c9831572483ed485438553d4c39686605d2625d6philippe TRACE_D3(" %08lx <End of list>\n", dl_offset); 4338c9831572483ed485438553d4c39686605d2625d6philippe dl_base = 0; 4339c9831572483ed485438553d4c39686605d2625d6philippe dl_offset = get_position_of_Cursor( &loc ); 4340c9831572483ed485438553d4c39686605d2625d6philippe continue; 4341c9831572483ed485438553d4c39686605d2625d6philippe } 4342b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4343c9831572483ed485438553d4c39686605d2625d6philippe if (w1 == -1UL) { 4344c9831572483ed485438553d4c39686605d2625d6philippe /* new value for 'base' */ 4345c9831572483ed485438553d4c39686605d2625d6philippe TRACE_D3(" %08lx %16lx %08lx (base address)\n", 4346c9831572483ed485438553d4c39686605d2625d6philippe dl_offset, w1, w2); 4347c9831572483ed485438553d4c39686605d2625d6philippe dl_base = w2; 4348c9831572483ed485438553d4c39686605d2625d6philippe continue; 4349c9831572483ed485438553d4c39686605d2625d6philippe } 4350c9831572483ed485438553d4c39686605d2625d6philippe 4351c9831572483ed485438553d4c39686605d2625d6philippe /* else a location expression follows */ 4352c9831572483ed485438553d4c39686605d2625d6philippe TRACE_D3(" %08lx %08lx %08lx ", 4353c9831572483ed485438553d4c39686605d2625d6philippe dl_offset, w1 + dl_base, w2 + dl_base); 4354c9831572483ed485438553d4c39686605d2625d6philippe len = (UWord)get_UShort( &loc ); 4355c9831572483ed485438553d4c39686605d2625d6philippe while (len > 0) { 4356c9831572483ed485438553d4c39686605d2625d6philippe UChar byte = get_UChar( &loc ); 4357c9831572483ed485438553d4c39686605d2625d6philippe TRACE_D3("%02x", (UInt)byte); 4358c9831572483ed485438553d4c39686605d2625d6philippe len--; 4359c9831572483ed485438553d4c39686605d2625d6philippe } 4360c9831572483ed485438553d4c39686605d2625d6philippe TRACE_SYMTAB("\n"); 4361b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4362b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4363b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#endif 4364c9831572483ed485438553d4c39686605d2625d6philippe} 4365c9831572483ed485438553d4c39686605d2625d6philippe 4366518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic void trace_debug_ranges (const DebugInfo* di, 4367c9831572483ed485438553d4c39686605d2625d6philippe __attribute__((noreturn)) void (*barf)( const HChar* ), 4368c9831572483ed485438553d4c39686605d2625d6philippe DiSlice escn_debug_ranges) 4369c9831572483ed485438553d4c39686605d2625d6philippe{ 4370c9831572483ed485438553d4c39686605d2625d6philippe Cursor ranges; /* for showing .debug_ranges */ 4371c9831572483ed485438553d4c39686605d2625d6philippe Addr dr_base; 4372c9831572483ed485438553d4c39686605d2625d6philippe UWord dr_offset; 4373c9831572483ed485438553d4c39686605d2625d6philippe Bool td3 = di->trace_symtab; 4374b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4375b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Display .debug_ranges */ 4376b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_SYMTAB("\n"); 4377b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_SYMTAB("\n------ The contents of .debug_ranges ------\n"); 4378b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_SYMTAB(" Offset Begin End\n"); 43795d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (ML_(sli_is_valid)(escn_debug_ranges)) { 43805d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj init_Cursor( &ranges, escn_debug_ranges, 0, barf, 43815d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj "Overrun whilst reading .debug_ranges section(1)" ); 43825d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj dr_base = 0; 43835d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj dr_offset = 0; 43845d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj while (True) { 43855d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj UWord w1, w2; 4386b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 43875d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (is_at_end_Cursor( &ranges )) 43885d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj break; 4389b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 43905d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj /* Read a (host-)word pair. This is something of a hack since 43915d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj the word size to read is really dictated by the ELF file; 43925d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj however, we assume we're reading a file with the same 43935d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj word-sizeness as the host. Reasonably enough. */ 43945d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj w1 = get_UWord( &ranges ); 43955d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj w2 = get_UWord( &ranges ); 43965d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj 43975d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (w1 == 0 && w2 == 0) { 43985d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj /* end of list. reset 'base' */ 43995d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3(" %08lx <End of list>\n", dr_offset); 44005d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj dr_base = 0; 44015d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj dr_offset = get_position_of_Cursor( &ranges ); 44025d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj continue; 44035d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj } 4404b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 44055d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (w1 == -1UL) { 44065d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj /* new value for 'base' */ 44075d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3(" %08lx %16lx %08lx (base address)\n", 44085d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj dr_offset, w1, w2); 44095d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj dr_base = w2; 44105d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj continue; 44115d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj } 4412b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 44135d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj /* else a range [w1+base, w2+base) is denoted */ 44145d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3(" %08lx %08lx %08lx\n", 44155d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj dr_offset, w1 + dr_base, w2 + dr_base); 4416b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4417b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4418c9831572483ed485438553d4c39686605d2625d6philippe} 4419c9831572483ed485438553d4c39686605d2625d6philippe 4420518850bf0da07ed3e2244e307268ae0fd80e93a8florianstatic void trace_debug_abbrev (const DebugInfo* di, 4421c9831572483ed485438553d4c39686605d2625d6philippe __attribute__((noreturn)) void (*barf)( const HChar* ), 4422c9831572483ed485438553d4c39686605d2625d6philippe DiSlice escn_debug_abbv) 4423c9831572483ed485438553d4c39686605d2625d6philippe{ 4424c9831572483ed485438553d4c39686605d2625d6philippe Cursor abbv; /* for showing .debug_abbrev */ 4425c9831572483ed485438553d4c39686605d2625d6philippe Bool td3 = di->trace_symtab; 4426b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4427b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Display .debug_abbrev */ 4428b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_SYMTAB("\n"); 4429b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_SYMTAB("\n------ The contents of .debug_abbrev ------\n"); 44305d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (ML_(sli_is_valid)(escn_debug_abbv)) { 44315d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj init_Cursor( &abbv, escn_debug_abbv, 0, barf, 44325d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj "Overrun whilst reading .debug_abbrev section" ); 4433b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 44345d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (is_at_end_Cursor( &abbv )) 44355d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj break; 44365d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj /* Read one abbreviation table */ 44375d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3(" Number TAG\n"); 4438b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 44395d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong atag; 44405d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj UInt has_children; 44415d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong acode = get_ULEB128( &abbv ); 44425d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (acode == 0) break; /* end of the table */ 44435d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj atag = get_ULEB128( &abbv ); 44445d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj has_children = get_UChar( &abbv ); 44455d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3(" %llu %s [%s]\n", 44465d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj acode, ML_(pp_DW_TAG)(atag), 44475d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ML_(pp_DW_children)(has_children)); 44485d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj while (True) { 44495d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong at_name = get_ULEB128( &abbv ); 44505d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong at_form = get_ULEB128( &abbv ); 44515d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (at_name == 0 && at_form == 0) break; 4452866862a87a06a70e2e0c0d7e5c773e252db8ecddflorian TRACE_D3(" %-18s %s\n", 44535d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ML_(pp_DW_AT)(at_name), ML_(pp_DW_FORM)(at_form)); 44545d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj } 4455b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4456b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4457b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4458c9831572483ed485438553d4c39686605d2625d6philippe} 4459c9831572483ed485438553d4c39686605d2625d6philippe 4460c9831572483ed485438553d4c39686605d2625d6philippestatic 4461c9831572483ed485438553d4c39686605d2625d6philippevoid new_dwarf3_reader_wrk ( 4462518850bf0da07ed3e2244e307268ae0fd80e93a8florian DebugInfo* di, 4463c9831572483ed485438553d4c39686605d2625d6philippe __attribute__((noreturn)) void (*barf)( const HChar* ), 4464c9831572483ed485438553d4c39686605d2625d6philippe DiSlice escn_debug_info, DiSlice escn_debug_types, 4465c9831572483ed485438553d4c39686605d2625d6philippe DiSlice escn_debug_abbv, DiSlice escn_debug_line, 4466c9831572483ed485438553d4c39686605d2625d6philippe DiSlice escn_debug_str, DiSlice escn_debug_ranges, 4467c9831572483ed485438553d4c39686605d2625d6philippe DiSlice escn_debug_loc, DiSlice escn_debug_info_alt, 4468c9831572483ed485438553d4c39686605d2625d6philippe DiSlice escn_debug_abbv_alt, DiSlice escn_debug_line_alt, 4469c9831572483ed485438553d4c39686605d2625d6philippe DiSlice escn_debug_str_alt 4470c9831572483ed485438553d4c39686605d2625d6philippe) 4471c9831572483ed485438553d4c39686605d2625d6philippe{ 4472c9831572483ed485438553d4c39686605d2625d6philippe XArray* /* of TyEnt */ tyents = NULL; 4473c9831572483ed485438553d4c39686605d2625d6philippe XArray* /* of TyEnt */ tyents_to_keep = NULL; 4474c9831572483ed485438553d4c39686605d2625d6philippe XArray* /* of GExpr* */ gexprs = NULL; 4475c9831572483ed485438553d4c39686605d2625d6philippe XArray* /* of TempVar* */ tempvars = NULL; 4476c9831572483ed485438553d4c39686605d2625d6philippe WordFM* /* of (XArray* of AddrRange, void) */ rangestree = NULL; 4477c9831572483ed485438553d4c39686605d2625d6philippe TyEntIndexCache* tyents_cache = NULL; 4478c9831572483ed485438553d4c39686605d2625d6philippe TyEntIndexCache* tyents_to_keep_cache = NULL; 4479c9831572483ed485438553d4c39686605d2625d6philippe TempVar *varp, *varp2; 4480c9831572483ed485438553d4c39686605d2625d6philippe GExpr* gexpr; 4481c9831572483ed485438553d4c39686605d2625d6philippe Cursor info; /* primary cursor for parsing .debug_info */ 4482c9831572483ed485438553d4c39686605d2625d6philippe D3TypeParser typarser; 4483c9831572483ed485438553d4c39686605d2625d6philippe D3VarParser varparser; 4484c9831572483ed485438553d4c39686605d2625d6philippe D3InlParser inlparser; 4485c9831572483ed485438553d4c39686605d2625d6philippe Word i, j, n; 4486c9831572483ed485438553d4c39686605d2625d6philippe Bool td3 = di->trace_symtab; 4487c9831572483ed485438553d4c39686605d2625d6philippe XArray* /* of TempVar* */ dioff_lookup_tab; 4488c9831572483ed485438553d4c39686605d2625d6philippe Int pass; 448909a4c794458cdb9dea743fa40e450150a2725257florian VgHashTable *signature_types = NULL; 4490c9831572483ed485438553d4c39686605d2625d6philippe 4491c9831572483ed485438553d4c39686605d2625d6philippe /* Display/trace various information, if requested. */ 4492e0bd5910153720d5d15697db8063d0d4caa59d8fphilippe if (TD3) { 4493c9831572483ed485438553d4c39686605d2625d6philippe trace_debug_loc (di, barf, escn_debug_loc); 4494c9831572483ed485438553d4c39686605d2625d6philippe trace_debug_ranges (di, barf, escn_debug_ranges); 4495c9831572483ed485438553d4c39686605d2625d6philippe trace_debug_abbrev (di, barf, escn_debug_abbv); 4496c9831572483ed485438553d4c39686605d2625d6philippe TRACE_SYMTAB("\n"); 4497c9831572483ed485438553d4c39686605d2625d6philippe } 4498c9831572483ed485438553d4c39686605d2625d6philippe 44995612d1a3bcfb43437890c6a27396b839b7c24ef9philippe /* Zero out all parsers. Parsers will really be initialised 45005612d1a3bcfb43437890c6a27396b839b7c24ef9philippe according to VG_(clo_read_*_info). */ 45015612d1a3bcfb43437890c6a27396b839b7c24ef9philippe VG_(memset)( &inlparser, 0, sizeof(inlparser) ); 4502b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4503a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (VG_(clo_read_var_info)) { 4504a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* We'll park the harvested type information in here. Also create 4505a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe a fake "void" entry with offset D3_FAKEVOID_CUOFF, so we always 4506a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe have at least one type entry to refer to. D3_FAKEVOID_CUOFF is 4507a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe huge and presumably will not occur in any valid DWARF3 file -- 4508a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe it would need to have a .debug_info section 4GB long for that to 4509a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe happen. These type entries end up in the DebugInfo. */ 4510a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyents = VG_(newXA)( ML_(dinfo_zalloc), 4511a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe "di.readdwarf3.ndrw.1 (TyEnt temp array)", 4512a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(dinfo_free), sizeof(TyEnt) ); 4513a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe { TyEnt tyent; 4514a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(memset)(&tyent, 0, sizeof(tyent)); 4515a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyent.tag = Te_TyVoid; 4516a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyent.cuOff = D3_FAKEVOID_CUOFF; 4517a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyent.Te.TyVoid.isFake = True; 4518a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(addToXA)( tyents, &tyent ); 4519a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4520a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe { TyEnt tyent; 4521a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(memset)(&tyent, 0, sizeof(tyent)); 4522a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyent.tag = Te_UNKNOWN; 4523a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyent.cuOff = D3_INVALID_CUOFF; 4524a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(addToXA)( tyents, &tyent ); 4525a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4526a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4527a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* This is a tree used to unique-ify the range lists that are 4528a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe manufactured by parse_var_DIE. References to the keys in the 4529a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tree wind up in .rngMany fields in TempVars. We'll need to 4530a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe delete this tree, and the XArrays attached to it, at the end of 4531a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe this function. */ 4532a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe rangestree = VG_(newFM)( ML_(dinfo_zalloc), 4533a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe "di.readdwarf3.ndrw.2 (rangestree)", 4534a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(dinfo_free), 4535a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe (Word(*)(UWord,UWord))cmp__XArrays_of_AddrRange ); 4536a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4537a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* List of variables we're accumulating. These don't end up in the 4538a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe DebugInfo; instead their contents are handed to ML_(addVar) and 4539a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe the list elements are then deleted. */ 4540a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tempvars = VG_(newXA)( ML_(dinfo_zalloc), 4541a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe "di.readdwarf3.ndrw.3 (TempVar*s array)", 4542a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(dinfo_free), 4543a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe sizeof(TempVar*) ); 4544a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4545a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* List of GExprs we're accumulating. These wind up in the 4546a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe DebugInfo. */ 4547a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe gexprs = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.ndrw.4", 4548a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(dinfo_free), sizeof(GExpr*) ); 4549a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4550a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* We need a D3TypeParser to keep track of partially constructed 4551a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe types. It'll be discarded as soon as we've completed the CU, 4552a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe since the resulting information is tipped in to 'tyents' as it 4553a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe is generated. */ 4554611fd68095bd837171574815cceb2225ed2aeb9dflorian type_parser_init(&typarser); 45559c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 4556611fd68095bd837171574815cceb2225ed2aeb9dflorian var_parser_init(&varparser); 4557a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4558a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe signature_types = VG_(HT_construct) ("signature_types"); 45599c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj } 4560b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4561d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* Do an initial pass to scan the .debug_types section, if any, and 4562d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj fill in the signatured types hash table. This lets us handle 4563d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj mapping from a type signature to a (cooked) DIE offset directly 4564d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj in get_Form_contents. */ 4565a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (VG_(clo_read_var_info) && ML_(sli_is_valid)(escn_debug_types)) { 45665d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj init_Cursor( &info, escn_debug_types, 0, barf, 4567d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj "Overrun whilst reading .debug_types section" ); 45685d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3("\n------ Collecting signatures from " 45695d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ".debug_types section ------\n"); 4570b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4571d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj while (True) { 4572d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj UWord cu_start_offset, cu_offset_now; 4573d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj CUConst cc; 4574d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4575d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cu_start_offset = get_position_of_Cursor( &info ); 4576d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj TRACE_D3("\n"); 4577d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj TRACE_D3(" Compilation Unit @ offset 0x%lx:\n", cu_start_offset); 4578746e97e7098def65d59c79d5d661f9a757a837cdphilippe /* parse_CU_header initialises the CU's abbv hash table. */ 45795d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj parse_CU_Header( &cc, td3, &info, escn_debug_abbv, True, False ); 4580d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4581d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* Needed by cook_die. */ 45825d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc.types_cuOff_bias = escn_debug_info.szB; 4583d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4584d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj record_signatured_type( signature_types, cc.type_signature, 4585d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cook_die( &cc, cc.type_offset )); 4586d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4587d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* Until proven otherwise we assume we don't need the icc9 4588d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj workaround in this case; see the DIE-reading loop below 4589d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj for details. */ 4590d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cu_offset_now = (cu_start_offset + cc.unit_length 4591d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj + (cc.is_dw64 ? 12 : 4)); 4592d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4593ede7291ec0a6035a30a97b22620f9bc6c971bd85philippe clear_CUConst ( &cc); 4594ede7291ec0a6035a30a97b22620f9bc6c971bd85philippe 4595746e97e7098def65d59c79d5d661f9a757a837cdphilippe if (cu_offset_now >= escn_debug_types.szB) { 4596d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj break; 4597746e97e7098def65d59c79d5d661f9a757a837cdphilippe } 4598d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4599d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj set_position_of_Cursor ( &info, cu_offset_now ); 4600b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4601d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj } 4602d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4603f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj /* Perform three DIE-reading passes. The first pass reads DIEs from 4604f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj alternate .debug_info (if any), the second pass reads DIEs from 4605f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj .debug_info, and the third pass reads DIEs from .debug_types. 4606d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj Moving the body of this loop into a separate function would 4607d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj require a large number of arguments to be passed in, so it is 4608d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj kept inline instead. */ 4609f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj for (pass = 0; pass < 3; ++pass) { 46105d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong section_size; 4611d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4612d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj if (pass == 0) { 46135d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (!ML_(sli_is_valid)(escn_debug_info_alt)) 4614f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj continue; 4615f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj /* Now loop over the Compilation Units listed in the alternate 4616f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj .debug_info section (see D3SPEC sec 7.5) paras 1 and 2. 4617f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj Each compilation unit contains a Compilation Unit Header 4618f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj followed by precisely one DW_TAG_compile_unit or 4619f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj DW_TAG_partial_unit DIE. */ 46205d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj init_Cursor( &info, escn_debug_info_alt, 0, barf, 4621f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj "Overrun whilst reading alternate .debug_info section" ); 46225d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj section_size = escn_debug_info_alt.szB; 4623f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj 4624f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj TRACE_D3("\n------ Parsing alternate .debug_info section ------\n"); 4625f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj } else if (pass == 1) { 4626d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* Now loop over the Compilation Units listed in the .debug_info 4627d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj section (see D3SPEC sec 7.5) paras 1 and 2. Each compilation 4628d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj unit contains a Compilation Unit Header followed by precisely 4629d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj one DW_TAG_compile_unit or DW_TAG_partial_unit DIE. */ 46305d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj init_Cursor( &info, escn_debug_info, 0, barf, 4631d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj "Overrun whilst reading .debug_info section" ); 46325d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj section_size = escn_debug_info.szB; 4633d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4634d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj TRACE_D3("\n------ Parsing .debug_info section ------\n"); 4635d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj } else { 46365d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (!ML_(sli_is_valid)(escn_debug_types)) 4637d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj continue; 4638e504887521dfee904f4dcea3655515bc99a6801fphilippe if (!VG_(clo_read_var_info)) 4639e504887521dfee904f4dcea3655515bc99a6801fphilippe continue; // Types not needed when only reading inline info. 46405d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj init_Cursor( &info, escn_debug_types, 0, barf, 4641d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj "Overrun whilst reading .debug_types section" ); 46425d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj section_size = escn_debug_types.szB; 4643d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4644d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj TRACE_D3("\n------ Parsing .debug_types section ------\n"); 4645b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4646b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4647d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj while (True) { 46485d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj ULong cu_start_offset, cu_offset_now; 4649d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj CUConst cc; 4650d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* It may be that the stated size of this CU is larger than the 4651d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj amount of stuff actually in it. icc9 seems to generate CUs 4652d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj thusly. We use these variables to figure out if this is 4653d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj indeed the case, and if so how many bytes we need to skip to 4654d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj get to the start of the next CU. Not skipping those bytes 4655d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj causes us to misidentify the start of the next CU, and it all 4656d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj goes badly wrong after that (not surprisingly). */ 4657d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj UWord cu_size_including_IniLen, cu_amount_used; 4658d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4659d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* It seems icc9 finishes the DIE info before debug_info_sz 4660d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj bytes have been used up. So be flexible, and declare the 4661d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj sequence complete if there is not enough remaining bytes to 4662d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj hold even the smallest conceivable CU header. (11 bytes I 4663d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj reckon). */ 4664d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* JRS 23Jan09: I suspect this is no longer necessary now that 4665d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj the code below contains a 'while (cu_amount_used < 4666d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cu_size_including_IniLen ...' style loop, which skips over 4667d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj any leftover bytes at the end of a CU in the case where the 4668d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj CU's stated size is larger than its actual size (as 4669d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj determined by reading all its DIEs). However, for prudence, 4670d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj I'll leave the following test in place. I can't see that a 4671d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj CU header can be smaller than 11 bytes, so I don't think 4672d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj there's any harm possible through the test -- it just adds 4673d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj robustness. */ 4674d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj Word avail = get_remaining_length_Cursor( &info ); 4675d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj if (avail < 11) { 4676d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj if (avail > 0) 4677d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj TRACE_D3("new_dwarf3_reader_wrk: warning: " 4678d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj "%ld unused bytes after end of DIEs\n", avail); 4679d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj break; 4680d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj } 4681d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4682a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (VG_(clo_read_var_info)) { 4683a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Check the varparser's stack is in a sane state. */ 4684a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(varparser.sp == -1); 4685611fd68095bd837171574815cceb2225ed2aeb9dflorian /* Check the typarser's stack is in a sane state. */ 4686611fd68095bd837171574815cceb2225ed2aeb9dflorian vg_assert(typarser.sp == -1); 4687d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj } 4688d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4689d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cu_start_offset = get_position_of_Cursor( &info ); 4690d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj TRACE_D3("\n"); 46915d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj TRACE_D3(" Compilation Unit @ offset 0x%llx:\n", cu_start_offset); 46920d2ea9d1cfd6f1fff0992096c2d15881becfe2e1philippe /* parse_CU_header initialises the CU's hashtable of abbvs ht_abbvs */ 46935d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (pass == 0) { 46945d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj parse_CU_Header( &cc, td3, &info, escn_debug_abbv_alt, 4695f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj False, True ); 46965d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj } else { 46975d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj parse_CU_Header( &cc, td3, &info, escn_debug_abbv, 4698f7c9714ea0cde18daaecb896278e85e780d3bd75sewardj pass == 2, False ); 46995d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj } 47005d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc.escn_debug_str = pass == 0 ? escn_debug_str_alt 47015d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj : escn_debug_str; 47025d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc.escn_debug_ranges = escn_debug_ranges; 47035d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc.escn_debug_loc = escn_debug_loc; 47045d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc.escn_debug_line = pass == 0 ? escn_debug_line_alt 47055d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj : escn_debug_line; 47065d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc.escn_debug_info = pass == 0 ? escn_debug_info_alt 47075d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj : escn_debug_info; 47085d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc.escn_debug_types = escn_debug_types; 47095d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc.escn_debug_info_alt = escn_debug_info_alt; 47105d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc.escn_debug_str_alt = escn_debug_str_alt; 47115d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc.types_cuOff_bias = escn_debug_info.szB; 47125d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc.alt_cuOff_bias = escn_debug_info.szB + escn_debug_types.szB; 47135d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj cc.cu_start_offset = cu_start_offset; 4714d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cc.di = di; 4715d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* The CU's svma can be deduced by looking at the AT_low_pc 4716d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj value in the top level TAG_compile_unit, which is the topmost 4717d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj DIE. We'll leave it for the 'varparser' to acquire that info 4718d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj and fill it in -- since it is the only party to want to know 4719d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj it. */ 4720d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cc.cu_svma_known = False; 4721d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cc.cu_svma = 0; 4722d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4723a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (VG_(clo_read_var_info)) { 4724a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe cc.signature_types = signature_types; 4725a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4726a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Create a fake outermost-level range covering the entire 4727a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe address range. So we always have *something* to catch all 4728a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe variable declarations. */ 4729a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varstack_push( &cc, &varparser, td3, 4730a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe unitary_range_list(0UL, ~0UL), 4731a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe -1, False/*isFunc*/, NULL/*fbGX*/ ); 4732a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4733666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe /* And set up the fndn_ix_Table. When we come across the top 4734a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe level DIE for this CU (which is what the next call to 4735a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe read_DIE should process) we will copy all the file names out 4736a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe of the .debug_line img area and use this table to look up the 4737a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe copies when we later see filename numbers in DW_TAG_variables 4738a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe etc. */ 4739666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe vg_assert(!varparser.fndn_ix_Table ); 4740666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe varparser.fndn_ix_Table 4741a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.ndrw.5var", 4742a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(dinfo_free), 4743666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe sizeof(UInt) ); 4744a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4745a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4746a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (VG_(clo_read_inline_info)) { 4747666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe /* fndn_ix_Table for the inlined call parser */ 4748666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe vg_assert(!inlparser.fndn_ix_Table ); 4749666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe inlparser.fndn_ix_Table 4750a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.ndrw.5inl", 4751a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(dinfo_free), 4752666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe sizeof(UInt) ); 4753a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4754d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4755d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* Now read the one-and-only top-level DIE for this CU. */ 4756a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(!VG_(clo_read_var_info) || varparser.sp == 0); 4757d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj read_DIE( rangestree, 4758d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj tyents, tempvars, gexprs, 4759a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe &typarser, &varparser, &inlparser, 4760d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj &info, td3, &cc, 0 ); 4761d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4762055b0f85aaa42477a803d445885c389561d3d3c8sewardj cu_offset_now = get_position_of_Cursor( &info ); 4763055b0f85aaa42477a803d445885c389561d3d3c8sewardj 47645d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj if (0) VG_(printf)("Travelled: %llu size %llu\n", 4765d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cu_offset_now - cc.cu_start_offset, 4766d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cc.unit_length + (cc.is_dw64 ? 12 : 4)); 47674bad5933e7b59ab9c756fb71da0f7fea7c4e61f0philippe 4768d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* How big the CU claims it is .. */ 4769d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cu_size_including_IniLen = cc.unit_length + (cc.is_dw64 ? 12 : 4); 4770d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* .. vs how big we have found it to be */ 4771d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cu_amount_used = cu_offset_now - cc.cu_start_offset; 4772b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4773c6e5d76e9eea8625f385ff844545c688c91938daflorian if (1) TRACE_D3("offset now %llu, d-i-size %llu\n", 4774d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cu_offset_now, section_size); 4775d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj if (cu_offset_now > section_size) 4776d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj barf("toplevel DIEs beyond end of CU"); 4777d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4778d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* If the CU is bigger than it claims to be, we've got a serious 4779d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj problem. */ 4780d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj if (cu_amount_used > cu_size_including_IniLen) 4781d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj barf("CU's actual size appears to be larger than it claims it is"); 4782d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4783d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* If the CU is smaller than it claims to be, we need to skip some 4784d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj bytes. Loop updates cu_offset_new and cu_amount_used. */ 4785d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj while (cu_amount_used < cu_size_including_IniLen 4786d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj && get_remaining_length_Cursor( &info ) > 0) { 4787d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj if (0) VG_(printf)("SKIP\n"); 4788d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj (void)get_UChar( &info ); 4789d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cu_offset_now = get_position_of_Cursor( &info ); 4790d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj cu_amount_used = cu_offset_now - cc.cu_start_offset; 4791d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj } 4792b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4793a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (VG_(clo_read_var_info)) { 4794a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Preen to level -2. DIEs have level >= 0 so -2 cannot occur 4795a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe anywhere else at all. Our fake the-entire-address-space 4796a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe range is at level -1, so preening to -2 should completely 4797a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe empty the stack out. */ 4798a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("\n"); 4799a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varstack_preen( &varparser, td3, -2 ); 4800a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Similarly, empty the type stack out. */ 4801a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe typestack_preen( &typarser, td3, -2 ); 4802a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4803d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4804a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (VG_(clo_read_var_info)) { 4805666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe vg_assert(varparser.fndn_ix_Table ); 4806666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(deleteXA)( varparser.fndn_ix_Table ); 4807666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe varparser.fndn_ix_Table = NULL; 4808a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4809a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (VG_(clo_read_inline_info)) { 4810666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe vg_assert(inlparser.fndn_ix_Table ); 4811666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe VG_(deleteXA)( inlparser.fndn_ix_Table ); 4812666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe inlparser.fndn_ix_Table = NULL; 4813a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4814746e97e7098def65d59c79d5d661f9a757a837cdphilippe clear_CUConst(&cc); 4815d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 4816d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj if (cu_offset_now == section_size) 4817d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj break; 4818d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj /* else keep going */ 4819d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj } 4820b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4821b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4822b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4823a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (VG_(clo_read_var_info)) { 4824a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* From here on we're post-processing the stuff we got 4825a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe out of the .debug_info section. */ 4826e0bd5910153720d5d15697db8063d0d4caa59d8fphilippe if (TD3) { 4827a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("\n"); 4828a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(pp_TyEnts)(tyents, "Initial type entity (TyEnt) array"); 4829a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("\n"); 4830a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("------ Compressing type entries ------\n"); 4831a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4832a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4833a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyents_cache = ML_(dinfo_zalloc)( "di.readdwarf3.ndrw.6", 4834a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe sizeof(TyEntIndexCache) ); 4835a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(TyEntIndexCache__invalidate)( tyents_cache ); 4836a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe dedup_types( td3, tyents, tyents_cache ); 4837e0bd5910153720d5d15697db8063d0d4caa59d8fphilippe if (TD3) { 4838a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("\n"); 4839a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(pp_TyEnts)(tyents, "After type entity (TyEnt) compression"); 4840a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4841a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 48429c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj TRACE_D3("\n"); 4843a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("------ Resolving the types of variables ------\n" ); 4844a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe resolve_variable_types( barf, tyents, tyents_cache, tempvars ); 48459c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 4846a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Copy all the non-INDIR tyents into a new table. For large 4847a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe .so's, about 90% of the tyents will by now have been resolved to 4848a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe INDIRs, and we no longer need them, and so don't need to store 4849a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe them. */ 4850a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyents_to_keep 4851a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe = VG_(newXA)( ML_(dinfo_zalloc), 4852a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe "di.readdwarf3.ndrw.7 (TyEnt to-keep array)", 4853a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(dinfo_free), sizeof(TyEnt) ); 4854a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe n = VG_(sizeXA)( tyents ); 4855a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe for (i = 0; i < n; i++) { 4856a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TyEnt* ent = VG_(indexXA)( tyents, i ); 4857a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (ent->tag != Te_INDIR) 4858a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(addToXA)( tyents_to_keep, ent ); 4859a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 48609c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 4861a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(deleteXA)( tyents ); 4862a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyents = NULL; 4863a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(dinfo_free)( tyents_cache ); 4864a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyents_cache = NULL; 4865a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4866a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Sort tyents_to_keep so we can lookup in it. A complete (if 4867a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe minor) waste of time, since tyents itself is sorted, but 4868a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe necessary since VG_(lookupXA) refuses to cooperate if we 4869a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe don't. */ 4870a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(setCmpFnXA)( tyents_to_keep, (XACmpFn_t) ML_(TyEnt__cmp_by_cuOff_only) ); 4871a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(sortXA)( tyents_to_keep ); 4872a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4873a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Enable cacheing on tyents_to_keep */ 4874a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyents_to_keep_cache 4875a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe = ML_(dinfo_zalloc)( "di.readdwarf3.ndrw.8", 4876a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe sizeof(TyEntIndexCache) ); 4877a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(TyEntIndexCache__invalidate)( tyents_to_keep_cache ); 4878a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4879a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* And record the tyents in the DebugInfo. We do this before 4880a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe starting to hand variables to ML_(addVar), since if ML_(addVar) 4881a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe wants to do debug printing (of the types of said vars) then it 4882a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe will need the tyents.*/ 4883a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(!di->admin_tyents); 4884a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe di->admin_tyents = tyents_to_keep; 4885a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4886a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Bias all the location expressions. */ 4887a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("\n"); 4888a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("------ Biasing the location expressions ------\n" ); 488968a2ebd9384661a85a4674fe8310c595ad494305sewardj 4890a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe n = VG_(sizeXA)( gexprs ); 4891a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe for (i = 0; i < n; i++) { 4892a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe gexpr = *(GExpr**)VG_(indexXA)( gexprs, i ); 4893a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe bias_GX( gexpr, di ); 4894a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4895b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4896a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("\n"); 4897a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("------ Acquired the following variables: ------\n\n"); 4898a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4899a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Park (pointers to) all the vars in an XArray, so we can look up 4900a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe abstract origins quickly. The array is sorted (hence, looked-up 4901a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe by) the .dioff fields. Since the .dioffs should be in strictly 4902a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ascending order, there is no need to sort the array after 4903a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe construction. The ascendingness is however asserted for. */ 4904a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe dioff_lookup_tab 4905a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe = VG_(newXA)( ML_(dinfo_zalloc), "di.readdwarf3.ndrw.9", 4906a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(dinfo_free), 4907a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe sizeof(TempVar*) ); 4908a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 4909a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe n = VG_(sizeXA)( tempvars ); 4910a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Word first_primary_var = 0; 4911a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe for (first_primary_var = 0; 4912a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe escn_debug_info_alt.szB/*really?*/ && first_primary_var < n; 4913a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe first_primary_var++) { 4914a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp = *(TempVar**)VG_(indexXA)( tempvars, first_primary_var ); 4915a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varp->dioff < escn_debug_info.szB + escn_debug_types.szB) 4916a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe break; 491759a2d18d0ddfa241850017252b0804d469187d79sewardj } 4918a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe for (i = 0; i < n; i++) { 4919a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp = *(TempVar**)VG_(indexXA)( tempvars, (i + first_primary_var) % n ); 4920a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (i > first_primary_var) { 4921a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp2 = *(TempVar**)VG_(indexXA)( tempvars, 4922a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe (i + first_primary_var - 1) % n ); 4923a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* why should this hold? Only, I think, because we've 4924a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe constructed the array by reading .debug_info sequentially, 4925a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe and so the array .dioff fields should reflect that, and be 4926a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe strictly ascending. */ 4927a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(varp2->dioff < varp->dioff); 4928a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4929a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(addToXA)( dioff_lookup_tab, &varp ); 4930a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4931a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(setCmpFnXA)( dioff_lookup_tab, cmp_TempVar_by_dioff ); 4932a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(sortXA)( dioff_lookup_tab ); /* POINTLESS; FIXME: rm */ 4933b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4934a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Now visit each var. Collect up as much info as possible for 4935a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe each var and hand it to ML_(addVar). */ 4936a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe n = VG_(sizeXA)( tempvars ); 4937a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe for (j = 0; j < n; j++) { 4938a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TyEnt* ent; 4939a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp = *(TempVar**)VG_(indexXA)( tempvars, j ); 4940b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4941a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Possibly show .. */ 4942e0bd5910153720d5d15697db8063d0d4caa59d8fphilippe if (TD3) { 4943a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(printf)("<%lx> addVar: level %d: %s :: ", 4944a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp->dioff, 4945a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp->level, 4946a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp->name ? varp->name : "<anon_var>" ); 4947a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varp->typeR) { 4948a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(pp_TyEnt_C_ishly)( tyents_to_keep, varp->typeR ); 4949a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } else { 4950a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(printf)("NULL"); 4951a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4952a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(printf)("\n Loc="); 4953a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varp->gexpr) { 4954a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(pp_GX)(varp->gexpr); 4955a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } else { 4956a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(printf)("NULL"); 4957a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4958b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj VG_(printf)("\n"); 4959a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varp->fbGX) { 4960a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(printf)(" FrB="); 4961a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(pp_GX)( varp->fbGX ); 4962a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(printf)("\n"); 4963a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } else { 4964a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(printf)(" FrB=none\n"); 4965a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 4966c6e5d76e9eea8625f385ff844545c688c91938daflorian VG_(printf)(" declared at: %u %s:%d\n", 4967666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe varp->fndn_ix, 4968666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe ML_(fndn_ix2filename) (di, varp->fndn_ix), 4969a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp->fLine ); 4970a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varp->absOri != (UWord)D3_INVALID_CUOFF) 4971a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(printf)(" abstract origin: <%lx>\n", varp->absOri); 4972b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 4973b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4974a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Skip variables which have no location. These must be 4975a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe abstract instances; they are useless as-is since with no 4976a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe location they have no specified memory location. They will 4977a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe presumably be referred to via the absOri fields of other 4978a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe variables. */ 4979a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (!varp->gexpr) { 4980a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3(" SKIP (no location)\n\n"); 4981bdee918842b4b2d4a09146a4642e999dc71b3652sewardj continue; 4982bdee918842b4b2d4a09146a4642e999dc71b3652sewardj } 4983b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 4984a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* So it has a location, at least. If it refers to some other 4985a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe entry through its absOri field, pull in further info through 4986a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe that. */ 4987a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varp->absOri != (UWord)D3_INVALID_CUOFF) { 4988a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Bool found; 4989a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Word ixFirst, ixLast; 4990a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TempVar key; 4991a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TempVar* keyp = &key; 4992a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TempVar *varAI; 4993a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(memset)(&key, 0, sizeof(key)); /* not necessary */ 4994a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe key.dioff = varp->absOri; /* this is what we want to find */ 4995a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe found = VG_(lookupXA)( dioff_lookup_tab, &keyp, 4996a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe &ixFirst, &ixLast ); 4997a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (!found) { 4998a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* barf("DW_AT_abstract_origin can't be resolved"); */ 4999a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3(" SKIP (DW_AT_abstract_origin can't be resolved)\n\n"); 5000a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe continue; 5001a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 5002a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* If the following fails, there is more than one entry with 5003a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe the same dioff. Which can't happen. */ 5004a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(ixFirst == ixLast); 5005a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varAI = *(TempVar**)VG_(indexXA)( dioff_lookup_tab, ixFirst ); 5006a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* stay sane */ 5007a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(varAI); 5008a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(varAI->dioff == varp->absOri); 5009a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 5010a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Copy what useful info we can. */ 5011a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varAI->typeR && !varp->typeR) 5012a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp->typeR = varAI->typeR; 5013a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varAI->name && !varp->name) 5014a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp->name = varAI->name; 5015666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe if (varAI->fndn_ix && !varp->fndn_ix) 5016666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe varp->fndn_ix = varAI->fndn_ix; 5017a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varAI->fLine > 0 && varp->fLine == 0) 5018a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp->fLine = varAI->fLine; 5019a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 5020a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 5021a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Give it a name if it doesn't have one. */ 5022a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (!varp->name) 5023a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp->name = ML_(addStr)( di, "<anon_var>", -1 ); 5024a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 5025a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* So now does it have enough info to be useful? */ 5026a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* NOTE: re typeR: this is a hack. If typeR is Te_UNKNOWN then 5027a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe the type didn't get resolved. Really, in that case 5028a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe something's broken earlier on, and should be fixed, rather 5029a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe than just skipping the variable. */ 5030a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ent = ML_(TyEnts__index_by_cuOff)( tyents_to_keep, 5031a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyents_to_keep_cache, 5032a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp->typeR ); 5033a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* The next two assertions should be guaranteed by 5034a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe our previous call to resolve_variable_types. */ 5035a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(ent); 5036a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(ML_(TyEnt__is_type)(ent) || ent->tag == Te_UNKNOWN); 5037a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 5038a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (ent->tag == Te_UNKNOWN) continue; 5039a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 5040a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(varp->gexpr); 5041a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(varp->name); 5042a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(varp->typeR); 5043a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(varp->level >= 0); 5044a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 5045a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Ok. So we're going to keep it. Call ML_(addVar) once for 5046a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe each address range in which the variable exists. */ 5047a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3(" ACQUIRE for range(s) "); 5048a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe { AddrRange oneRange; 5049a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe AddrRange* varPcRanges; 5050a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Word nVarPcRanges; 5051a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Set up to iterate over address ranges, however 5052a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe represented. */ 5053a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varp->nRanges == 0 || varp->nRanges == 1) { 5054a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(!varp->rngMany); 5055a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varp->nRanges == 0) { 5056a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(varp->rngOneMin == 0); 5057a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(varp->rngOneMax == 0); 5058a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 5059a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe nVarPcRanges = varp->nRanges; 5060a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe oneRange.aMin = varp->rngOneMin; 5061a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe oneRange.aMax = varp->rngOneMax; 5062a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varPcRanges = &oneRange; 5063a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } else { 5064a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(varp->rngMany); 5065b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(varp->rngOneMin == 0); 5066b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(varp->rngOneMax == 0); 5067a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe nVarPcRanges = VG_(sizeXA)(varp->rngMany); 5068a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(nVarPcRanges >= 2); 5069a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(nVarPcRanges == (Word)varp->nRanges); 5070a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varPcRanges = VG_(indexXA)(varp->rngMany, 0); 5071b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 5072a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varp->level == 0) 5073a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert( nVarPcRanges == 1 ); 5074a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* and iterate */ 5075a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe for (i = 0; i < nVarPcRanges; i++) { 5076a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Addr pcMin = varPcRanges[i].aMin; 5077a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe Addr pcMax = varPcRanges[i].aMax; 5078a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(pcMin <= pcMax); 5079a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Level 0 is the global address range. So at level 0 we 5080a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe don't want to bias pcMin/pcMax; but at all other levels 5081a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe we do since those are derived from svmas in the Dwarf 5082a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe we're reading. Be paranoid ... */ 5083a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varp->level == 0) { 5084a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(pcMin == (Addr)0); 5085a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(pcMax == ~(Addr)0); 5086a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } else { 5087a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* vg_assert(pcMin > (Addr)0); 5088a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe No .. we can legitimately expect to see ranges like 5089a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 0x0-0x11D (pre-biasing, of course). */ 5090a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(pcMax < ~(Addr)0); 5091a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 5092a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 5093a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Apply text biasing, for non-global variables. */ 5094a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (varp->level > 0) { 5095a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe pcMin += di->text_debug_bias; 5096a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe pcMax += di->text_debug_bias; 5097a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 5098a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 5099a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe if (i > 0 && (i%2) == 0) 5100a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("\n "); 5101a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("[%#lx,%#lx] ", pcMin, pcMax ); 5102a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe 5103a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(addVar)( 5104a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe di, varp->level, 5105a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe pcMin, pcMax, 5106a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp->name, varp->typeR, 5107a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp->gexpr, varp->fbGX, 5108666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe varp->fndn_ix, varp->fLine, td3 5109a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ); 5110b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 5111a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 5112b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5113a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe TRACE_D3("\n\n"); 5114a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* and move on to the next var */ 5115b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 5116b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5117a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* Now free all the TempVars */ 5118a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe n = VG_(sizeXA)( tempvars ); 5119a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe for (i = 0; i < n; i++) { 5120a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe varp = *(TempVar**)VG_(indexXA)( tempvars, i ); 5121a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(dinfo_free)(varp); 5122a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 5123a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(deleteXA)( tempvars ); 5124a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tempvars = NULL; 5125b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5126a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* and the temp lookup table */ 5127a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(deleteXA)( dioff_lookup_tab ); 5128b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5129a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* and the ranges tree. Note that we need to also free the XArrays 5130a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe which constitute the keys, hence pass VG_(deleteXA) as a 5131a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe key-finalizer. */ 5132a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(deleteFM)( rangestree, (void(*)(UWord))VG_(deleteXA), NULL ); 51339c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 5134a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* and the tyents_to_keep cache */ 5135a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe ML_(dinfo_free)( tyents_to_keep_cache ); 5136a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe tyents_to_keep_cache = NULL; 51379c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 5138666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe vg_assert( varparser.fndn_ix_Table == NULL ); 5139d935068fc7b53c8a826b3436cdfccd5b7d446903sewardj 5140a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* And the signatured type hash. */ 5141a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe VG_(HT_destruct) ( signature_types, ML_(dinfo_free) ); 51429c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 5143a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe /* record the GExprs in di so they can be freed later */ 5144a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe vg_assert(!di->admin_gexprs); 5145a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe di->admin_gexprs = gexprs; 5146a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe } 5147611fd68095bd837171574815cceb2225ed2aeb9dflorian 5148611fd68095bd837171574815cceb2225ed2aeb9dflorian // Free up dynamically allocated memory 5149611fd68095bd837171574815cceb2225ed2aeb9dflorian if (VG_(clo_read_var_info)) { 5150611fd68095bd837171574815cceb2225ed2aeb9dflorian type_parser_release(&typarser); 5151611fd68095bd837171574815cceb2225ed2aeb9dflorian var_parser_release(&varparser); 5152611fd68095bd837171574815cceb2225ed2aeb9dflorian } 5153b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 5154b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5155b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5156b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 5157b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 5158b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- The "new" DWARF3 reader -- top level control logic ---*/ 5159b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- ---*/ 5160b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*------------------------------------------------------------*/ 5161b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 51626c591e15c1d6402a2a755310f005f795b68e7e38sewardjstatic Bool d3rd_jmpbuf_valid = False; 51636bd9dc18c043927c1196caba20a327238a179c42florianstatic const HChar* d3rd_jmpbuf_reason = NULL; 516497d3ebba515c00930db4ee3f52af571bc84b2ef6sewardjstatic VG_MINIMAL_JMP_BUF(d3rd_jmpbuf); 5165b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 51666bd9dc18c043927c1196caba20a327238a179c42florianstatic __attribute__((noreturn)) void barf ( const HChar* reason ) { 5167b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(d3rd_jmpbuf_valid); 5168b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj d3rd_jmpbuf_reason = reason; 51696c591e15c1d6402a2a755310f005f795b68e7e38sewardj VG_MINIMAL_LONGJMP(d3rd_jmpbuf); 5170b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /*NOTREACHED*/ 5171b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(0); 5172b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 5173b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5174b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5175b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjvoid 5176b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjML_(new_dwarf3_reader) ( 5177518850bf0da07ed3e2244e307268ae0fd80e93a8florian DebugInfo* di, 51785d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_info, DiSlice escn_debug_types, 51795d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_abbv, DiSlice escn_debug_line, 51805d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_str, DiSlice escn_debug_ranges, 51815d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_loc, DiSlice escn_debug_info_alt, 51825d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_abbv_alt, DiSlice escn_debug_line_alt, 51835d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj DiSlice escn_debug_str_alt 5184b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj) 5185b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj{ 5186b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj volatile Int jumped; 5187b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj volatile Bool td3 = di->trace_symtab; 5188b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5189b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Run the _wrk function to read the dwarf3. If it succeeds, it 5190b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj just returns normally. If there is any failure, it longjmp's 5191b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj back here, having first set d3rd_jmpbuf_reason to something 5192b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj useful. */ 5193b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(d3rd_jmpbuf_valid == False); 5194b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(d3rd_jmpbuf_reason == NULL); 5195b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5196b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj d3rd_jmpbuf_valid = True; 51976c591e15c1d6402a2a755310f005f795b68e7e38sewardj jumped = VG_MINIMAL_SETJMP(d3rd_jmpbuf); 5198b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (jumped == 0) { 5199b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* try this ... */ 5200b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj new_dwarf3_reader_wrk( di, barf, 52015d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj escn_debug_info, escn_debug_types, 52025d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj escn_debug_abbv, escn_debug_line, 52035d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj escn_debug_str, escn_debug_ranges, 52045d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj escn_debug_loc, escn_debug_info_alt, 52055d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj escn_debug_abbv_alt, escn_debug_line_alt, 52065d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj escn_debug_str_alt ); 5207b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj d3rd_jmpbuf_valid = False; 5208b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("\n------ .debug_info reading was successful ------\n"); 5209b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } else { 5210b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* It longjmp'd. */ 5211b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj d3rd_jmpbuf_valid = False; 5212b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Can't longjump without giving some sort of reason. */ 5213b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj vg_assert(d3rd_jmpbuf_reason != NULL); 5214b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5215b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("\n------ .debug_info reading failed ------\n"); 5216b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5217b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ML_(symerr)(di, True, d3rd_jmpbuf_reason); 5218b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 5219b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5220b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj d3rd_jmpbuf_valid = False; 5221b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj d3rd_jmpbuf_reason = NULL; 5222b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj} 5223b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5224b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5225b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5226b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* --- Unused code fragments which might be useful one day. --- */ 5227b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5228b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#if 0 5229b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Read the arange tables */ 5230b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_SYMTAB("\n"); 5231b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_SYMTAB("\n------ The contents of .debug_arange ------\n"); 5232b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj init_Cursor( &aranges, debug_aranges_img, 5233b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj debug_aranges_sz, 0, barf, 5234b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj "Overrun whilst reading .debug_aranges section" ); 5235b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 5236b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ULong len, d_i_offset; 5237b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Bool is64; 5238b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UShort version; 5239b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj UChar asize, segsize; 5240b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5241b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (is_at_end_Cursor( &aranges )) 5242b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj break; 5243b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* Read one arange thingy */ 5244b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj /* initial_length field */ 5245b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj len = get_Initial_Length( &is64, &aranges, 5246b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj "in .debug_aranges: invalid initial-length field" ); 5247b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj version = get_UShort( &aranges ); 5248b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj d_i_offset = get_Dwarfish_UWord( &aranges, is64 ); 5249b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj asize = get_UChar( &aranges ); 5250b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj segsize = get_UChar( &aranges ); 5251b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3(" Length: %llu\n", len); 5252b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3(" Version: %d\n", (Int)version); 5253b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3(" Offset into .debug_info: %llx\n", d_i_offset); 5254b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3(" Pointer Size: %d\n", (Int)asize); 5255b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3(" Segment Size: %d\n", (Int)segsize); 5256b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3("\n"); 5257b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3(" Address Length\n"); 5258b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 5259b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while ((get_position_of_Cursor( &aranges ) % (2 * asize)) > 0) { 5260b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj (void)get_UChar( & aranges ); 5261b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 5262b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj while (True) { 5263b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ULong address = get_Dwarfish_UWord( &aranges, asize==8 ); 5264b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj ULong length = get_Dwarfish_UWord( &aranges, asize==8 ); 5265b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_D3(" 0x%016llx 0x%llx\n", address, length); 5266b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj if (address == 0 && length == 0) break; 5267b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 5268b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj } 5269b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj TRACE_SYMTAB("\n"); 5270b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#endif 5271b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 52728eb8bab992e3998c33770b0cdb16059a8b918a06sewardj#endif // defined(VGO_linux) || defined(VGO_darwin) || defined(VGO_solaris) 5273f76d27a697a7b0bf3b84490baf60623fc96a23afnjn 5274b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--------------------------------------------------------------------*/ 52758b68b64759254d514d98328c496cbd88cde4c9a5njn/*--- end ---*/ 5276b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--------------------------------------------------------------------*/ 5277