1eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
2eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/*--------------------------------------------------------------------*/
3eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/*--- Format-neutral storage of and querying of info acquired from ---*/
4eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/*--- ELF/XCOFF stabs/dwarf1/dwarf2 debug info.                    ---*/
5eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/*---                                               priv_storage.h ---*/
6eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/*--------------------------------------------------------------------*/
7eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
8eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/*
9eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   This file is part of Valgrind, a dynamic binary instrumentation
10eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   framework.
11eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
120f157ddb404bcde7815a1c5bf2d7e41c114f3d73sewardj   Copyright (C) 2000-2013 Julian Seward
13eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj      jseward@acm.org
14eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
15eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   This program is free software; you can redistribute it and/or
16eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   modify it under the terms of the GNU General Public License as
17eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   published by the Free Software Foundation; either version 2 of the
18eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   License, or (at your option) any later version.
19eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
20eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   This program is distributed in the hope that it will be useful, but
21eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   WITHOUT ANY WARRANTY; without even the implied warranty of
22eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   General Public License for more details.
24eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
25eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   You should have received a copy of the GNU General Public License
26eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   along with this program; if not, write to the Free Software
27eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   02111-1307, USA.
29eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
30eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   The GNU General Public License is contained in the file COPYING.
31eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj*/
32eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/*
33eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   Stabs reader greatly improved by Nick Nethercote, Apr 02.
34eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   This module was also extensively hacked on by Jeremy Fitzhardinge
35eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   and Tom Hughes.
36eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj*/
37c6d3f6f0aec8607dded979fd15a9876a486ec682sewardj/* See comment at top of debuginfo.c for explanation of
38c6d3f6f0aec8607dded979fd15a9876a486ec682sewardj   the _svma / _avma / _image / _bias naming scheme.
39c6d3f6f0aec8607dded979fd15a9876a486ec682sewardj*/
40b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* Note this is not freestanding; needs pub_core_xarray.h and
41b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   priv_tytypes.h to be included before it. */
42eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
43eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj#ifndef __PRIV_STORAGE_H
44eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj#define __PRIV_STORAGE_H
45eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
46535fb1b49a80f2e880f755ee618381de3e222ddfflorian#include "pub_core_basics.h"   // Addr
47535fb1b49a80f2e880f755ee618381de3e222ddfflorian#include "pub_core_xarray.h"   // XArray
487293d2530f8c60c1060f9f003e214cc341d35266philippe#include "pub_core_deduppoolalloc.h" // DedupPoolAlloc
49535fb1b49a80f2e880f755ee618381de3e222ddfflorian#include "priv_d3basics.h"     // GExpr et al.
50535fb1b49a80f2e880f755ee618381de3e222ddfflorian#include "priv_image.h"        // DiCursor
51535fb1b49a80f2e880f755ee618381de3e222ddfflorian
52eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* --------------------- SYMBOLS --------------------- */
53eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
54a5cace0c2a3e212931badbf6398a0cd98393121asewardj/* A structure to hold an ELF/MachO symbol (very crudely).  Usually
55a5cace0c2a3e212931badbf6398a0cd98393121asewardj   the symbol only has one name, which is stored in ::pri_name, and
56a5cace0c2a3e212931badbf6398a0cd98393121asewardj   ::sec_names is NULL.  If there are other names, these are stored in
57a5cace0c2a3e212931badbf6398a0cd98393121asewardj   ::sec_names, which is a NULL terminated vector holding the names.
58a5cace0c2a3e212931badbf6398a0cd98393121asewardj   The vector is allocated in VG_AR_DINFO, the names themselves live
597293d2530f8c60c1060f9f003e214cc341d35266philippe   in DebugInfo::strpool.
60a5cace0c2a3e212931badbf6398a0cd98393121asewardj
61a5cace0c2a3e212931badbf6398a0cd98393121asewardj   From the point of view of ELF, the primary vs secondary distinction
62a5cace0c2a3e212931badbf6398a0cd98393121asewardj   is artificial: they are all just names associated with the address,
63a5cace0c2a3e212931badbf6398a0cd98393121asewardj   none of which has higher precedence than any other.  However, from
64a5cace0c2a3e212931badbf6398a0cd98393121asewardj   the point of view of mapping an address to a name to display to the
65a5cace0c2a3e212931badbf6398a0cd98393121asewardj   user, we need to choose one "preferred" name, and so that might as
66a5cace0c2a3e212931badbf6398a0cd98393121asewardj   well be installed as the pri_name, whilst all others can live in
67a5cace0c2a3e212931badbf6398a0cd98393121asewardj   sec_names[].  This has the convenient side effect that, in the
68a5cace0c2a3e212931badbf6398a0cd98393121asewardj   common case where there is only one name for the address,
69a5cace0c2a3e212931badbf6398a0cd98393121asewardj   sec_names[] does not need to be allocated.
70a5cace0c2a3e212931badbf6398a0cd98393121asewardj*/
71eadcd86d1b0f59efed44c162ef4378ccfb528290sewardjtypedef
724cace66777ca9ee73ea156210c04e9d4cc178395philippe   struct {
734cace66777ca9ee73ea156210c04e9d4cc178395philippe      SymAVMAs avmas;    /* Symbol Actual VMAs: lowest address of entity,
744cace66777ca9ee73ea156210c04e9d4cc178395philippe                            + platform specific fields, to access with
754cace66777ca9ee73ea156210c04e9d4cc178395philippe                            the macros defined in pub_core_debuginfo.h */
761ef70c6f00ab1b50d1936f77037e9923d8ed8c59florian      const HChar*  pri_name;  /* primary name, never NULL */
771ef70c6f00ab1b50d1936f77037e9923d8ed8c59florian      const HChar** sec_names; /* NULL, or a NULL term'd array of other names */
78a5cace0c2a3e212931badbf6398a0cd98393121asewardj      // XXX: this could be shrunk (on 32-bit platforms) by using 30
79a5cace0c2a3e212931badbf6398a0cd98393121asewardj      // bits for the size and 1 bit each for isText and isIFunc.  If you
80a5cace0c2a3e212931badbf6398a0cd98393121asewardj      // do this, make sure that all assignments to the latter two use
81a5cace0c2a3e212931badbf6398a0cd98393121asewardj      // 0 or 1 (or True or False), and that a positive number larger
82a5cace0c2a3e212931badbf6398a0cd98393121asewardj      // than 1 is never used to represent True.
83a5cace0c2a3e212931badbf6398a0cd98393121asewardj      UInt    size;    /* size in bytes */
84a5cace0c2a3e212931badbf6398a0cd98393121asewardj      Bool    isText;
85a5cace0c2a3e212931badbf6398a0cd98393121asewardj      Bool    isIFunc; /* symbol is an indirect function? */
86eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   }
87eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   DiSym;
88eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
89eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* --------------------- SRCLOCS --------------------- */
90eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
91eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* Line count at which overflow happens, due to line numbers being
92eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   stored as shorts in `struct nlist' in a.out.h. */
93eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj#define LINENO_OVERFLOW (1 << (sizeof(short) * 8))
94eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
95eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj#define LINENO_BITS     20
96eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj#define LOC_SIZE_BITS  (32 - LINENO_BITS)
97eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj#define MAX_LINENO     ((1 << LINENO_BITS) - 1)
98eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
99eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* Unlikely to have any lines with instruction ranges > 4096 bytes */
100eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj#define MAX_LOC_SIZE   ((1 << LOC_SIZE_BITS) - 1)
101eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
102eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* Number used to detect line number overflows; if one line is
103b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   60000-odd smaller than the previous, it was probably an overflow.
104eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj */
105eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj#define OVERFLOW_DIFFERENCE     (LINENO_OVERFLOW - 5000)
106eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
10759e1f3c79e870a978d24add86db6d8c5450c8b63philippe/* Filename and Dirname pair. FnDn are stored in di->fndnpool
10859e1f3c79e870a978d24add86db6d8c5450c8b63philippe   and are allocated using VG_(allocFixedEltDedupPA).
10959e1f3c79e870a978d24add86db6d8c5450c8b63philippe   The filename/dirname strings are themselves stored in di->strpool. */
11059e1f3c79e870a978d24add86db6d8c5450c8b63philippetypedef
11159e1f3c79e870a978d24add86db6d8c5450c8b63philippe   struct {
11259e1f3c79e870a978d24add86db6d8c5450c8b63philippe      const HChar* filename;     /* source filename */
11359e1f3c79e870a978d24add86db6d8c5450c8b63philippe      const HChar* dirname;      /* source directory name */
11459e1f3c79e870a978d24add86db6d8c5450c8b63philippe   } FnDn;
11559e1f3c79e870a978d24add86db6d8c5450c8b63philippe
116eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* A structure to hold addr-to-source info for a single line.  There
117eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj  can be a lot of these, hence the dense packing. */
118eadcd86d1b0f59efed44c162ef4378ccfb528290sewardjtypedef
119eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   struct {
120eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj      /* Word 1 */
121eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj      Addr   addr;               /* lowest address for this line */
122eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj      /* Word 2 */
123eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj      UShort size:LOC_SIZE_BITS; /* # bytes; we catch overflows of this */
124eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj      UInt   lineno:LINENO_BITS; /* source line number, or zero */
125eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   }
126eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   DiLoc;
127eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
128a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe#define LEVEL_BITS  (32 - LINENO_BITS)
129a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe#define MAX_LEVEL     ((1 << LEVEL_BITS) - 1)
130a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe
131a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe/* A structure to hold addr-to-inlined fn info.  There
13259e1f3c79e870a978d24add86db6d8c5450c8b63philippe   can be a lot of these, hence the dense packing.
13359e1f3c79e870a978d24add86db6d8c5450c8b63philippe   Only caller source filename and lineno are stored.
13459e1f3c79e870a978d24add86db6d8c5450c8b63philippe   Handling dirname should be done using fndn_ix technique
13559e1f3c79e870a978d24add86db6d8c5450c8b63philippe   similar to  ML_(addLineInfo). */
136a0a73939b0398b6608fd6dbde49820ce6530d12cphilippetypedef
137a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   struct {
138a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe      /* Word 1 */
139a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe      Addr   addr_lo;            /* lowest address for inlined fn */
140a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe      /* Word 2 */
141a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe      Addr   addr_hi;            /* highest address following the inlined fn */
142a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe      /* Word 3 */
143a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe      const HChar* inlinedfn;    /* inlined function name */
144666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe      /* Word 4 and 5 */
145666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe      UInt   fndn_ix;            /* index in di->fndnpool of caller source
146666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe                                    dirname/filename */
147a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe      UInt   lineno:LINENO_BITS; /* caller line number */
148a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe      UShort level:LEVEL_BITS;   /* level of inlining */
149a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   }
150a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   DiInlLoc;
151a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe
152eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* --------------------- CF INFO --------------------- */
153eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1543026f71684a930286186aa10fef266c304672e8fsewardj/* DiCfSI: a structure to summarise DWARF2/3 CFA info for the code
1553026f71684a930286186aa10fef266c304672e8fsewardj   address range [base .. base+len-1].
1563026f71684a930286186aa10fef266c304672e8fsewardj
1573026f71684a930286186aa10fef266c304672e8fsewardj   On x86 and amd64 ("IA"), if you know ({e,r}sp, {e,r}bp, {e,r}ip) at
1583026f71684a930286186aa10fef266c304672e8fsewardj   some point and {e,r}ip is in the range [base .. base+len-1], it
1593026f71684a930286186aa10fef266c304672e8fsewardj   tells you how to calculate ({e,r}sp, {e,r}bp) for the caller of the
1603026f71684a930286186aa10fef266c304672e8fsewardj   current frame and also ra, the return address of the current frame.
161eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
162eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   First off, calculate CFA, the Canonical Frame Address, thusly:
163eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
16472427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj     cfa = case cfa_how of
1653026f71684a930286186aa10fef266c304672e8fsewardj              CFIC_IA_SPREL -> {e,r}sp + cfa_off
1663026f71684a930286186aa10fef266c304672e8fsewardj              CFIC_IA_BPREL -> {e,r}bp + cfa_off
167821283b2110420321fd3f60afcc799b287788c68sewardj              CFIC_EXPR     -> expr whose index is in cfa_off
168eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1693026f71684a930286186aa10fef266c304672e8fsewardj   Once that is done, the previous frame's {e,r}sp/{e,r}bp values and
1703026f71684a930286186aa10fef266c304672e8fsewardj   this frame's {e,r}ra value can be calculated like this:
171eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1723026f71684a930286186aa10fef266c304672e8fsewardj     old_{e,r}sp/{e,r}bp/ra
1733026f71684a930286186aa10fef266c304672e8fsewardj         = case {e,r}sp/{e,r}bp/ra_how of
174eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj              CFIR_UNKNOWN   -> we don't know, sorry
175eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj              CFIR_SAME      -> same as it was before (sp/fp only)
1763026f71684a930286186aa10fef266c304672e8fsewardj              CFIR_CFAREL    -> cfa + sp/bp/ra_off
1773026f71684a930286186aa10fef266c304672e8fsewardj              CFIR_MEMCFAREL -> *( cfa + sp/bp/ra_off )
1783026f71684a930286186aa10fef266c304672e8fsewardj              CFIR_EXPR      -> expr whose index is in sp/bp/ra_off
179eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1803026f71684a930286186aa10fef266c304672e8fsewardj   On ARM it's pretty much the same, except we have more registers to
1813026f71684a930286186aa10fef266c304672e8fsewardj   keep track of:
18272427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj
1833026f71684a930286186aa10fef266c304672e8fsewardj     cfa = case cfa_how of
184821283b2110420321fd3f60afcc799b287788c68sewardj              CFIC_ARM_R13REL -> r13 + cfa_off
185821283b2110420321fd3f60afcc799b287788c68sewardj              CFIC_ARM_R12REL -> r12 + cfa_off
186821283b2110420321fd3f60afcc799b287788c68sewardj              CFIC_ARM_R11REL -> r11 + cfa_off
187821283b2110420321fd3f60afcc799b287788c68sewardj              CFIC_ARM_R7REL  -> r7  + cfa_off
188821283b2110420321fd3f60afcc799b287788c68sewardj              CFIR_EXPR       -> expr whose index is in cfa_off
189eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
190fa5ce5616a17e79828fbc79f30b02b5085151e3csewardj     old_r14/r13/r12/r11/r7/ra
191fa5ce5616a17e79828fbc79f30b02b5085151e3csewardj         = case r14/r13/r12/r11/r7/ra_how of
1923026f71684a930286186aa10fef266c304672e8fsewardj              CFIR_UNKNOWN   -> we don't know, sorry
193fa5ce5616a17e79828fbc79f30b02b5085151e3csewardj              CFIR_SAME      -> same as it was before (r14/r13/r12/r11/r7 only)
194fa5ce5616a17e79828fbc79f30b02b5085151e3csewardj              CFIR_CFAREL    -> cfa + r14/r13/r12/r11/r7/ra_off
195fa5ce5616a17e79828fbc79f30b02b5085151e3csewardj              CFIR_MEMCFAREL -> *( cfa + r14/r13/r12/r11/r7/ra_off )
196fa5ce5616a17e79828fbc79f30b02b5085151e3csewardj              CFIR_EXPR      -> expr whose index is in r14/r13/r12/r11/r7/ra_off
197b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj
198821283b2110420321fd3f60afcc799b287788c68sewardj   On ARM64:
199821283b2110420321fd3f60afcc799b287788c68sewardj
200821283b2110420321fd3f60afcc799b287788c68sewardj     cfa = case cfa_how of
201821283b2110420321fd3f60afcc799b287788c68sewardj              CFIC_ARM64_SPREL  -> sp + cfa_off
202821283b2110420321fd3f60afcc799b287788c68sewardj              CFIC_ARM64_X29REL -> x29 + cfa_off
203821283b2110420321fd3f60afcc799b287788c68sewardj              CFIC_EXPR         -> expr whose index is in cfa_off
204821283b2110420321fd3f60afcc799b287788c68sewardj
205821283b2110420321fd3f60afcc799b287788c68sewardj     old_sp/x30/x29/ra
206821283b2110420321fd3f60afcc799b287788c68sewardj         = case sp/x30/x29/ra_how of
207821283b2110420321fd3f60afcc799b287788c68sewardj              CFIR_UNKNOWN   -> we don't know, sorry
208821283b2110420321fd3f60afcc799b287788c68sewardj              CFIR_SAME      -> same as it was before
209821283b2110420321fd3f60afcc799b287788c68sewardj              CFIR_CFAREL    -> cfa + sp/x30/x29/ra_how
210821283b2110420321fd3f60afcc799b287788c68sewardj              CFIR_MEMCFAREL -> *( cfa + sp/x30/x29/ra_how )
211821283b2110420321fd3f60afcc799b287788c68sewardj              CFIR_EXPR      -> expr whose index is in sp/x30/x29/ra_off
212821283b2110420321fd3f60afcc799b287788c68sewardj
213b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj   On s390x we have a similar logic as x86 or amd64. We need the stack pointer
214b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj   (r15), the frame pointer r11 (like BP) and together with the instruction
215b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj   address in the PSW we can calculate the previous values:
216b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj     cfa = case cfa_how of
217b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj              CFIC_IA_SPREL -> r15 + cfa_off
218b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj              CFIC_IA_BPREL -> r11 + cfa_off
219821283b2110420321fd3f60afcc799b287788c68sewardj              CFIC_EXPR     -> expr whose index is in cfa_off
220b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj
221b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj     old_sp/fp/ra
222b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj         = case sp/fp/ra_how of
223b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj              CFIR_UNKNOWN   -> we don't know, sorry
224b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj              CFIR_SAME      -> same as it was before (sp/fp only)
225b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj              CFIR_CFAREL    -> cfa + sp/fp/ra_off
226b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj              CFIR_MEMCFAREL -> *( cfa + sp/fp/ra_off )
227b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj              CFIR_EXPR      -> expr whose index is in sp/fp/ra_off
2283026f71684a930286186aa10fef266c304672e8fsewardj*/
2293026f71684a930286186aa10fef266c304672e8fsewardj
2303026f71684a930286186aa10fef266c304672e8fsewardj#define CFIC_IA_SPREL     ((UChar)1)
2313026f71684a930286186aa10fef266c304672e8fsewardj#define CFIC_IA_BPREL     ((UChar)2)
232821283b2110420321fd3f60afcc799b287788c68sewardj#define CFIC_ARM_R13REL   ((UChar)3)
233821283b2110420321fd3f60afcc799b287788c68sewardj#define CFIC_ARM_R12REL   ((UChar)4)
234821283b2110420321fd3f60afcc799b287788c68sewardj#define CFIC_ARM_R11REL   ((UChar)5)
235821283b2110420321fd3f60afcc799b287788c68sewardj#define CFIC_ARM_R7REL    ((UChar)6)
236821283b2110420321fd3f60afcc799b287788c68sewardj#define CFIC_ARM64_SPREL  ((UChar)7)
237821283b2110420321fd3f60afcc799b287788c68sewardj#define CFIC_ARM64_X29REL ((UChar)8)
238821283b2110420321fd3f60afcc799b287788c68sewardj#define CFIC_EXPR         ((UChar)9)  /* all targets */
2393026f71684a930286186aa10fef266c304672e8fsewardj
2403026f71684a930286186aa10fef266c304672e8fsewardj#define CFIR_UNKNOWN      ((UChar)64)
2413026f71684a930286186aa10fef266c304672e8fsewardj#define CFIR_SAME         ((UChar)65)
2423026f71684a930286186aa10fef266c304672e8fsewardj#define CFIR_CFAREL       ((UChar)66)
2433026f71684a930286186aa10fef266c304672e8fsewardj#define CFIR_MEMCFAREL    ((UChar)67)
2443026f71684a930286186aa10fef266c304672e8fsewardj#define CFIR_EXPR         ((UChar)68)
2453026f71684a930286186aa10fef266c304672e8fsewardj
2465c3dba227192de63d86f65ec7d9597c132818c37philippe/* Definition of the DiCfSI_m DiCfSI machine dependent part.
2475c3dba227192de63d86f65ec7d9597c132818c37philippe   These are highly duplicated, and are stored in a pool. */
2483026f71684a930286186aa10fef266c304672e8fsewardj#if defined(VGA_x86) || defined(VGA_amd64)
249eadcd86d1b0f59efed44c162ef4378ccfb528290sewardjtypedef
250eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   struct {
2513026f71684a930286186aa10fef266c304672e8fsewardj      UChar cfa_how; /* a CFIC_IA value */
25272427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      UChar ra_how;  /* a CFIR_ value */
25372427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      UChar sp_how;  /* a CFIR_ value */
2543026f71684a930286186aa10fef266c304672e8fsewardj      UChar bp_how;  /* a CFIR_ value */
255eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj      Int   cfa_off;
256eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj      Int   ra_off;
257eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj      Int   sp_off;
2583026f71684a930286186aa10fef266c304672e8fsewardj      Int   bp_off;
2593026f71684a930286186aa10fef266c304672e8fsewardj   }
2605c3dba227192de63d86f65ec7d9597c132818c37philippe   DiCfSI_m;
2613026f71684a930286186aa10fef266c304672e8fsewardj#elif defined(VGA_arm)
2623026f71684a930286186aa10fef266c304672e8fsewardjtypedef
2633026f71684a930286186aa10fef266c304672e8fsewardj   struct {
2643026f71684a930286186aa10fef266c304672e8fsewardj      UChar cfa_how; /* a CFIC_ value */
2653026f71684a930286186aa10fef266c304672e8fsewardj      UChar ra_how;  /* a CFIR_ value */
2663026f71684a930286186aa10fef266c304672e8fsewardj      UChar r14_how; /* a CFIR_ value */
2673026f71684a930286186aa10fef266c304672e8fsewardj      UChar r13_how; /* a CFIR_ value */
2683026f71684a930286186aa10fef266c304672e8fsewardj      UChar r12_how; /* a CFIR_ value */
2693026f71684a930286186aa10fef266c304672e8fsewardj      UChar r11_how; /* a CFIR_ value */
270fa5ce5616a17e79828fbc79f30b02b5085151e3csewardj      UChar r7_how;  /* a CFIR_ value */
2713026f71684a930286186aa10fef266c304672e8fsewardj      Int   cfa_off;
2723026f71684a930286186aa10fef266c304672e8fsewardj      Int   ra_off;
2733026f71684a930286186aa10fef266c304672e8fsewardj      Int   r14_off;
2743026f71684a930286186aa10fef266c304672e8fsewardj      Int   r13_off;
2753026f71684a930286186aa10fef266c304672e8fsewardj      Int   r12_off;
2763026f71684a930286186aa10fef266c304672e8fsewardj      Int   r11_off;
277fa5ce5616a17e79828fbc79f30b02b5085151e3csewardj      Int   r7_off;
278ade2eddf567a868bafad9110ed92acf7373a972bsewardj      // If you add additional fields, don't forget to update the
279ade2eddf567a868bafad9110ed92acf7373a972bsewardj      // initialisation of this in readexidx.c accordingly.
280eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   }
2815c3dba227192de63d86f65ec7d9597c132818c37philippe   DiCfSI_m;
282821283b2110420321fd3f60afcc799b287788c68sewardj#elif defined(VGA_arm64)
283821283b2110420321fd3f60afcc799b287788c68sewardjtypedef
284821283b2110420321fd3f60afcc799b287788c68sewardj   struct {
285821283b2110420321fd3f60afcc799b287788c68sewardj      UChar cfa_how; /* a CFIC_ value */
286821283b2110420321fd3f60afcc799b287788c68sewardj      UChar ra_how;  /* a CFIR_ value */
287821283b2110420321fd3f60afcc799b287788c68sewardj      UChar sp_how;  /* a CFIR_ value */ /*dw31=SP*/
288821283b2110420321fd3f60afcc799b287788c68sewardj      UChar x30_how; /* a CFIR_ value */ /*dw30=LR*/
289821283b2110420321fd3f60afcc799b287788c68sewardj      UChar x29_how; /* a CFIR_ value */ /*dw29=FP*/
290821283b2110420321fd3f60afcc799b287788c68sewardj      Int   cfa_off;
291821283b2110420321fd3f60afcc799b287788c68sewardj      Int   ra_off;
292821283b2110420321fd3f60afcc799b287788c68sewardj      Int   sp_off;
293821283b2110420321fd3f60afcc799b287788c68sewardj      Int   x30_off;
294821283b2110420321fd3f60afcc799b287788c68sewardj      Int   x29_off;
295821283b2110420321fd3f60afcc799b287788c68sewardj   }
2965c3dba227192de63d86f65ec7d9597c132818c37philippe   DiCfSI_m;
297cae0cc22b83ffb260ee8379e92099c5a701944cbcarll#elif defined(VGA_ppc32) || defined(VGA_ppc64be) || defined(VGA_ppc64le)
298f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj/* Just have a struct with the common fields in, so that code that
299f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj   processes the common fields doesn't have to be ifdef'd against
300f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj   VGP_/VGA_ symbols.  These are not used in any way on ppc32/64-linux
301f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj   at the moment. */
302f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardjtypedef
303f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj   struct {
304f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj      UChar cfa_how; /* a CFIC_ value */
305f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj      UChar ra_how;  /* a CFIR_ value */
306f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj      Int   cfa_off;
307f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj      Int   ra_off;
308f5f1e12bd89408917c1ffeb22ec23a1fd11b7a23sewardj   }
3095c3dba227192de63d86f65ec7d9597c132818c37philippe   DiCfSI_m;
310b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj#elif defined(VGA_s390x)
311b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardjtypedef
312b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj   struct {
313b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj      UChar cfa_how; /* a CFIC_ value */
314b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj      UChar sp_how;  /* a CFIR_ value */
315b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj      UChar ra_how;  /* a CFIR_ value */
316b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj      UChar fp_how;  /* a CFIR_ value */
317b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj      Int   cfa_off;
318b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj      Int   sp_off;
319b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj      Int   ra_off;
320b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj      Int   fp_off;
321b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj   }
3225c3dba227192de63d86f65ec7d9597c132818c37philippe   DiCfSI_m;
3234df0bfc0614379192c780c944415dc420d9cfe8epetarj#elif defined(VGA_mips32) || defined(VGA_mips64)
3245db15403e889d4db339b342bc2a824ef0bfaa654sewardjtypedef
3255db15403e889d4db339b342bc2a824ef0bfaa654sewardj   struct {
3265db15403e889d4db339b342bc2a824ef0bfaa654sewardj      UChar cfa_how; /* a CFIC_ value */
3275db15403e889d4db339b342bc2a824ef0bfaa654sewardj      UChar ra_how;  /* a CFIR_ value */
3285db15403e889d4db339b342bc2a824ef0bfaa654sewardj      UChar sp_how;  /* a CFIR_ value */
3295db15403e889d4db339b342bc2a824ef0bfaa654sewardj      UChar fp_how;  /* a CFIR_ value */
3305db15403e889d4db339b342bc2a824ef0bfaa654sewardj      Int   cfa_off;
3315db15403e889d4db339b342bc2a824ef0bfaa654sewardj      Int   ra_off;
3325db15403e889d4db339b342bc2a824ef0bfaa654sewardj      Int   sp_off;
3335db15403e889d4db339b342bc2a824ef0bfaa654sewardj      Int   fp_off;
3345db15403e889d4db339b342bc2a824ef0bfaa654sewardj   }
3355c3dba227192de63d86f65ec7d9597c132818c37philippe   DiCfSI_m;
336112711afefcfcd43680c7c4aa8d38ef180e8811esewardj#elif defined(VGA_tilegx)
337112711afefcfcd43680c7c4aa8d38ef180e8811esewardjtypedef
338112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   struct {
339112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      UChar cfa_how; /* a CFIC_IA value */
340112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      UChar ra_how;  /* a CFIR_ value */
341112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      UChar sp_how;  /* a CFIR_ value */
342112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      UChar fp_how;  /* a CFIR_ value */
343112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      Int   cfa_off;
344112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      Int   ra_off;
345112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      Int   sp_off;
346112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      Int   fp_off;
347112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   }
348112711afefcfcd43680c7c4aa8d38ef180e8811esewardj   DiCfSI_m;
3493026f71684a930286186aa10fef266c304672e8fsewardj#else
3503026f71684a930286186aa10fef266c304672e8fsewardj#  error "Unknown arch"
3513026f71684a930286186aa10fef266c304672e8fsewardj#endif
352eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
3535c3dba227192de63d86f65ec7d9597c132818c37philippetypedef
3545c3dba227192de63d86f65ec7d9597c132818c37philippe   struct {
3555c3dba227192de63d86f65ec7d9597c132818c37philippe      Addr  base;
3565c3dba227192de63d86f65ec7d9597c132818c37philippe      UInt  len;
3575c3dba227192de63d86f65ec7d9597c132818c37philippe      UInt  cfsi_m_ix;
3585c3dba227192de63d86f65ec7d9597c132818c37philippe   }
3595c3dba227192de63d86f65ec7d9597c132818c37philippe   DiCfSI;
36072427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj
36172427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardjtypedef
36272427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj   enum {
36340628facff2285b0fce592381c6e26fdcd2a1252tom      Cunop_Abs=0x231,
36440628facff2285b0fce592381c6e26fdcd2a1252tom      Cunop_Neg,
36540628facff2285b0fce592381c6e26fdcd2a1252tom      Cunop_Not
36640628facff2285b0fce592381c6e26fdcd2a1252tom   }
36740628facff2285b0fce592381c6e26fdcd2a1252tom   CfiUnop;
36840628facff2285b0fce592381c6e26fdcd2a1252tom
36940628facff2285b0fce592381c6e26fdcd2a1252tomtypedef
37040628facff2285b0fce592381c6e26fdcd2a1252tom   enum {
371f6716dd8f025c9ace67541f3360d7f4523496d8atom      Cbinop_Add=0x321,
372f6716dd8f025c9ace67541f3360d7f4523496d8atom      Cbinop_Sub,
373f6716dd8f025c9ace67541f3360d7f4523496d8atom      Cbinop_And,
374f6716dd8f025c9ace67541f3360d7f4523496d8atom      Cbinop_Mul,
375f6716dd8f025c9ace67541f3360d7f4523496d8atom      Cbinop_Shl,
376f6716dd8f025c9ace67541f3360d7f4523496d8atom      Cbinop_Shr,
377f6716dd8f025c9ace67541f3360d7f4523496d8atom      Cbinop_Eq,
378f6716dd8f025c9ace67541f3360d7f4523496d8atom      Cbinop_Ge,
379f6716dd8f025c9ace67541f3360d7f4523496d8atom      Cbinop_Gt,
380f6716dd8f025c9ace67541f3360d7f4523496d8atom      Cbinop_Le,
381f6716dd8f025c9ace67541f3360d7f4523496d8atom      Cbinop_Lt,
382f6716dd8f025c9ace67541f3360d7f4523496d8atom      Cbinop_Ne
38372427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj   }
384f6716dd8f025c9ace67541f3360d7f4523496d8atom   CfiBinop;
38572427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj
38672427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardjtypedef
38772427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj   enum {
388ade2eddf567a868bafad9110ed92acf7373a972bsewardj      Creg_INVALID=0x213,
389ade2eddf567a868bafad9110ed92acf7373a972bsewardj      Creg_IA_SP,
3903026f71684a930286186aa10fef266c304672e8fsewardj      Creg_IA_BP,
3913026f71684a930286186aa10fef266c304672e8fsewardj      Creg_IA_IP,
3923026f71684a930286186aa10fef266c304672e8fsewardj      Creg_ARM_R13,
3933026f71684a930286186aa10fef266c304672e8fsewardj      Creg_ARM_R12,
3943026f71684a930286186aa10fef266c304672e8fsewardj      Creg_ARM_R15,
395b5b87408c0c99f9f6938d8cd921e2a5f420577c4sewardj      Creg_ARM_R14,
396ade2eddf567a868bafad9110ed92acf7373a972bsewardj      Creg_ARM_R7,
397821283b2110420321fd3f60afcc799b287788c68sewardj      Creg_ARM64_X30,
398b6ba6d288e6000a8f95fba1dea671e0b53e26043florian      Creg_S390_IA,
399b6ba6d288e6000a8f95fba1dea671e0b53e26043florian      Creg_S390_SP,
400b6ba6d288e6000a8f95fba1dea671e0b53e26043florian      Creg_S390_FP,
401b6ba6d288e6000a8f95fba1dea671e0b53e26043florian      Creg_S390_LR,
402112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      Creg_MIPS_RA,
403112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      Creg_TILEGX_IP,
404112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      Creg_TILEGX_SP,
405112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      Creg_TILEGX_BP,
406112711afefcfcd43680c7c4aa8d38ef180e8811esewardj      Creg_TILEGX_LR
40772427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj   }
40872427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj   CfiReg;
40972427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj
41072427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardjtypedef
41172427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj   enum {
41272427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      Cex_Undef=0x123,
41372427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      Cex_Deref,
41472427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      Cex_Const,
41540628facff2285b0fce592381c6e26fdcd2a1252tom      Cex_Unop,
41672427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      Cex_Binop,
41772427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      Cex_CfiReg,
41872427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      Cex_DwReg
41972427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj   }
42072427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj   CfiExprTag;
42172427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj
42272427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardjtypedef
42372427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj   struct {
42472427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      CfiExprTag tag;
42572427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      union {
42672427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj         struct {
42772427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj         } Undef;
42872427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj         struct {
42972427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj            Int ixAddr;
43072427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj         } Deref;
43172427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj         struct {
43272427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj            UWord con;
43372427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj         } Const;
43472427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj         struct {
43540628facff2285b0fce592381c6e26fdcd2a1252tom            CfiUnop op;
43640628facff2285b0fce592381c6e26fdcd2a1252tom            Int ix;
43740628facff2285b0fce592381c6e26fdcd2a1252tom         } Unop;
43840628facff2285b0fce592381c6e26fdcd2a1252tom         struct {
439f6716dd8f025c9ace67541f3360d7f4523496d8atom            CfiBinop op;
44072427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj            Int ixL;
44172427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj            Int ixR;
44272427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj         } Binop;
44372427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj         struct {
44472427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj            CfiReg reg;
44572427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj         } CfiReg;
44672427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj         struct {
44772427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj            Int reg;
44872427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj         } DwReg;
44972427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      }
45072427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      Cex;
45172427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj   }
45272427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj   CfiExpr;
45372427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj
45472427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardjextern Int ML_(CfiExpr_Undef) ( XArray* dst );
45572427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardjextern Int ML_(CfiExpr_Deref) ( XArray* dst, Int ixAddr );
45672427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardjextern Int ML_(CfiExpr_Const) ( XArray* dst, UWord con );
45740628facff2285b0fce592381c6e26fdcd2a1252tomextern Int ML_(CfiExpr_Unop)  ( XArray* dst, CfiUnop op, Int ix );
458f6716dd8f025c9ace67541f3360d7f4523496d8atomextern Int ML_(CfiExpr_Binop) ( XArray* dst, CfiBinop op, Int ixL, Int ixR );
45972427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardjextern Int ML_(CfiExpr_CfiReg)( XArray* dst, CfiReg reg );
46072427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardjextern Int ML_(CfiExpr_DwReg) ( XArray* dst, Int reg );
46172427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj
462518850bf0da07ed3e2244e307268ae0fd80e93a8florianextern void ML_(ppCfiExpr)( const XArray* src, Int ix );
46372427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj
464c8259b85b701d25d72aabe9dc0a8154517f96913sewardj/* ---------------- FPO INFO (Windows PE) -------------- */
465c8259b85b701d25d72aabe9dc0a8154517f96913sewardj
466c8259b85b701d25d72aabe9dc0a8154517f96913sewardj/* for apps using Wine: MSVC++ PDB FramePointerOmitted: somewhat like
467c8259b85b701d25d72aabe9dc0a8154517f96913sewardj   a primitive CFI */
468c8259b85b701d25d72aabe9dc0a8154517f96913sewardjtypedef
469c8259b85b701d25d72aabe9dc0a8154517f96913sewardj   struct _FPO_DATA {  /* 16 bytes */
470c8259b85b701d25d72aabe9dc0a8154517f96913sewardj      UInt   ulOffStart; /* offset of 1st byte of function code */
471c8259b85b701d25d72aabe9dc0a8154517f96913sewardj      UInt   cbProcSize; /* # bytes in function */
472c8259b85b701d25d72aabe9dc0a8154517f96913sewardj      UInt   cdwLocals;  /* # bytes/4 in locals */
473c8259b85b701d25d72aabe9dc0a8154517f96913sewardj      UShort cdwParams;  /* # bytes/4 in params */
474c8259b85b701d25d72aabe9dc0a8154517f96913sewardj      UChar  cbProlog;   /* # bytes in prolog */
475c8259b85b701d25d72aabe9dc0a8154517f96913sewardj      UChar  cbRegs :3;  /* # regs saved */
476c8259b85b701d25d72aabe9dc0a8154517f96913sewardj      UChar  fHasSEH:1;  /* Structured Exception Handling */
477c8259b85b701d25d72aabe9dc0a8154517f96913sewardj      UChar  fUseBP :1;  /* EBP has been used */
478c8259b85b701d25d72aabe9dc0a8154517f96913sewardj      UChar  reserved:1;
479c8259b85b701d25d72aabe9dc0a8154517f96913sewardj      UChar  cbFrame:2;  /* frame type */
480c8259b85b701d25d72aabe9dc0a8154517f96913sewardj   }
481c8259b85b701d25d72aabe9dc0a8154517f96913sewardj   FPO_DATA;
482c8259b85b701d25d72aabe9dc0a8154517f96913sewardj
483c8259b85b701d25d72aabe9dc0a8154517f96913sewardj#define PDB_FRAME_FPO  0
484c8259b85b701d25d72aabe9dc0a8154517f96913sewardj#define PDB_FRAME_TRAP 1
485c8259b85b701d25d72aabe9dc0a8154517f96913sewardj#define PDB_FRAME_TSS  2
486c8259b85b701d25d72aabe9dc0a8154517f96913sewardj
487b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* --------------------- VARIABLES --------------------- */
488b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
489b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjtypedef
490b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   struct {
491b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      Addr    aMin;
492b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      Addr    aMax;
493b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      XArray* /* of DiVariable */ vars;
494b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   }
495b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   DiAddrRange;
496b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
497b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjtypedef
498b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   struct {
4991ef70c6f00ab1b50d1936f77037e9923d8ed8c59florian      const  HChar* name;  /* in DebugInfo.strpool */
5009c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj      UWord  typeR; /* a cuOff */
5013297124fa2116737066ac3cd709f18fdd5405163florian      const GExpr* gexpr; /* on DebugInfo.gexprs list */
5023297124fa2116737066ac3cd709f18fdd5405163florian      const GExpr* fbGX;  /* SHARED. */
503666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe      UInt   fndn_ix; /* where declared; may be zero. index
504666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe                         in DebugInfo.fndnpool */
505b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      Int    lineNo;   /* where declared; may be zero. */
506b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   }
507b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   DiVariable;
508b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
509b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjWord
510b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjML_(cmp_for_DiAddrRange_range) ( const void* keyV, const void* elemV );
511b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
512b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* --------------------- DEBUGINFO --------------------- */
513eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
514eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* This is the top-level data type.  It's a structure which contains
515b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   information pertaining to one mapped ELF object.  This type is
516eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   exported only abstractly - in pub_tool_debuginfo.h. */
517eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
518a5acac39bf3be7546222b1316faee5ee524be0d1sewardj/* First though, here's an auxiliary data structure.  It is only ever
519a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   used as part of a struct _DebugInfo.  We use it to record
520a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   observations about mappings and permission changes to the
521a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   associated file, so as to decide when to read debug info.  It's
522a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   essentially an ultra-trivial finite state machine which, when it
523a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   reaches an accept state, signals that we should now read debug info
524a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   from the object into the associated struct _DebugInfo.  The accept
525a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   state is arrived at when have_rx_map and have_rw_map both become
526731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj   true.  The initial state is one in which we have no observations,
527731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj   so have_rx_map and have_rw_map are both false.
528a5acac39bf3be7546222b1316faee5ee524be0d1sewardj
5296b5625bb609b154766d2e138b61e15655f60b710sewardj   This all started as a rather ad-hoc solution, but was further
5306b5625bb609b154766d2e138b61e15655f60b710sewardj   expanded to handle weird object layouts, e.g. more than one rw
5316b5625bb609b154766d2e138b61e15655f60b710sewardj   or rx mapping for one binary.
532731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj
533731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj   The normal sequence of events is one of
534731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj
535731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj   start  -->  r-x mapping  -->  rw- mapping  -->  accept
536731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj   start  -->  rw- mapping  -->  r-x mapping  -->  accept
537731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj
538731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj   that is, take the first r-x and rw- mapping we see, and we're done.
539731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj
540588cd4ebce3305d0cf91896c1f6322ef9775d6c1sewardj   On MacOSX >= 10.7, 32-bit, there appears to be a new variant:
541731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj
542731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj   start  -->  r-- mapping  -->  rw- mapping
543731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj          -->  upgrade r-- mapping to r-x mapping  -->  accept
544731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj
545588cd4ebce3305d0cf91896c1f6322ef9775d6c1sewardj   where the upgrade is done by a call to mach_vm_protect (OSX 10.7)
546588cd4ebce3305d0cf91896c1f6322ef9775d6c1sewardj   or kernelrpc_mach_vm_protect_trap (OSX 10.9 and possibly 10.8).
547588cd4ebce3305d0cf91896c1f6322ef9775d6c1sewardj   Hence we need to also track this possibility.
548588cd4ebce3305d0cf91896c1f6322ef9775d6c1sewardj
549588cd4ebce3305d0cf91896c1f6322ef9775d6c1sewardj   From perusal of dyld sources, it appears that this scheme could
550588cd4ebce3305d0cf91896c1f6322ef9775d6c1sewardj   also be used 64 bit libraries, although that doesn't seem to happen
551588cd4ebce3305d0cf91896c1f6322ef9775d6c1sewardj   in practice.  dyld uses this scheme when the text section requires
552588cd4ebce3305d0cf91896c1f6322ef9775d6c1sewardj   relocation, which only appears to be the case for 32 bit objects.
553a5acac39bf3be7546222b1316faee5ee524be0d1sewardj*/
5546b5625bb609b154766d2e138b61e15655f60b710sewardj
555518850bf0da07ed3e2244e307268ae0fd80e93a8floriantypedef struct
556a5acac39bf3be7546222b1316faee5ee524be0d1sewardj{
5576b5625bb609b154766d2e138b61e15655f60b710sewardj   Addr  avma; /* these fields record the file offset, length */
5586b5625bb609b154766d2e138b61e15655f60b710sewardj   SizeT size; /* and map address of each mapping             */
5596b5625bb609b154766d2e138b61e15655f60b710sewardj   OffT  foff;
5606b5625bb609b154766d2e138b61e15655f60b710sewardj   Bool  rx, rw, ro;  /* memory access flags for this mapping */
561518850bf0da07ed3e2244e307268ae0fd80e93a8florian} DebugInfoMapping;
562a5acac39bf3be7546222b1316faee5ee524be0d1sewardj
5636b5625bb609b154766d2e138b61e15655f60b710sewardjstruct _DebugInfoFSM
5646b5625bb609b154766d2e138b61e15655f60b710sewardj{
5651636d33c13958b9c0e7d3059cdd5005746418eb2florian   HChar*  filename;  /* in mallocville (VG_AR_DINFO)               */
566c5af2ae7cec426721577d4a249d4a7b7c0eeb65emjw   HChar*  dbgname;   /* in mallocville (VG_AR_DINFO)               */
567518850bf0da07ed3e2244e307268ae0fd80e93a8florian   XArray* maps;      /* XArray of DebugInfoMapping structs         */
568a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   Bool  have_rx_map; /* did we see a r?x mapping yet for the file? */
569a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   Bool  have_rw_map; /* did we see a rw? mapping yet for the file? */
570731f9cf9fd4d507b44f1a0fdc2d3b8e8efae02e3sewardj   Bool  have_ro_map; /* did we see a r-- mapping yet for the file? */
571a5acac39bf3be7546222b1316faee5ee524be0d1sewardj};
572a5acac39bf3be7546222b1316faee5ee524be0d1sewardj
573a5acac39bf3be7546222b1316faee5ee524be0d1sewardj
5747293d2530f8c60c1060f9f003e214cc341d35266philippe/* To do with the string table in struct _DebugInfo (::strpool) */
5750b9d0646949bd382758763664d3bf2d6115993aephilippe#define SEGINFO_STRPOOLSIZE (64*1024)
576eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
577a5acac39bf3be7546222b1316faee5ee524be0d1sewardj
578452e89a9f847975609b3ad318943830f2cce841csewardj/* We may encounter more than one .eh_frame section in an object --
579452e89a9f847975609b3ad318943830f2cce841csewardj   unusual but apparently allowed by ELF.  See
580452e89a9f847975609b3ad318943830f2cce841csewardj   http://sourceware.org/bugzilla/show_bug.cgi?id=12675
581452e89a9f847975609b3ad318943830f2cce841csewardj*/
582452e89a9f847975609b3ad318943830f2cce841csewardj#define N_EHFRAME_SECTS 2
583452e89a9f847975609b3ad318943830f2cce841csewardj
584a5acac39bf3be7546222b1316faee5ee524be0d1sewardj
585a5acac39bf3be7546222b1316faee5ee524be0d1sewardj/* So, the main structure for holding debug info for one object. */
586a5acac39bf3be7546222b1316faee5ee524be0d1sewardj
587b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjstruct _DebugInfo {
588b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
589b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   /* Admin stuff */
590b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
591b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   struct _DebugInfo* next;   /* list of DebugInfos */
592b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Bool               mark;   /* marked for deletion? */
593b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
5949c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj   /* An abstract handle, which can be used by entities outside of
5959c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj      m_debuginfo to (in an abstract datatype sense) refer to this
5969c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj      struct _DebugInfo.  A .handle of zero is invalid; valid handles
5979c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj      are 1 and above.  The same handle is never issued twice (in any
5989c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj      given run of Valgrind), so a handle becomes invalid when the
5999c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj      associated struct _DebugInfo is discarded, and remains invalid
6009c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj      forever thereafter.  The .handle field is set as soon as this
6019c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj      structure is allocated. */
6029c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj   ULong handle;
6039c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj
604b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   /* Used for debugging only - indicate what stuff to dump whilst
605b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      reading stuff into the seginfo.  Are computed as early in the
606b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      lifetime of the DebugInfo as possible -- at the point when it is
607b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      created.  Use these when deciding what to spew out; do not use
608b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      the global VG_(clo_blah) flags. */
609b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
610b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Bool trace_symtab; /* symbols, our style */
611b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Bool trace_cfi;    /* dwarf frame unwind, our style */
612b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Bool ddump_syms;   /* mimic /usr/bin/readelf --syms */
613b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Bool ddump_line;   /* mimic /usr/bin/readelf --debug-dump=line */
614b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Bool ddump_frames; /* mimic /usr/bin/readelf --debug-dump=frames */
615b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
616a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   /* The "decide when it is time to read debuginfo" state machine.
617a5acac39bf3be7546222b1316faee5ee524be0d1sewardj      This structure must get filled in before we can start reading
618a5acac39bf3be7546222b1316faee5ee524be0d1sewardj      anything from the ELF/MachO file.  This structure is filled in
619a5acac39bf3be7546222b1316faee5ee524be0d1sewardj      by VG_(di_notify_mmap) and its immediate helpers. */
620a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   struct _DebugInfoFSM fsm;
621a5acac39bf3be7546222b1316faee5ee524be0d1sewardj
622a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   /* Once the ::fsm has reached an accept state -- typically, when
623a5acac39bf3be7546222b1316faee5ee524be0d1sewardj      both a rw? and r?x mapping for .filename have been observed --
624a5acac39bf3be7546222b1316faee5ee524be0d1sewardj      we can go on to read the symbol tables and debug info.
625a5acac39bf3be7546222b1316faee5ee524be0d1sewardj      .have_dinfo changes from False to True when the debug info has
626a5acac39bf3be7546222b1316faee5ee524be0d1sewardj      been completely read in and postprocessed (canonicalised) and is
627a5acac39bf3be7546222b1316faee5ee524be0d1sewardj      now suitable for querying. */
628a5acac39bf3be7546222b1316faee5ee524be0d1sewardj   /* If have_dinfo is False, then all fields below this point are
629a5acac39bf3be7546222b1316faee5ee524be0d1sewardj      invalid and should not be consulted. */
630b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Bool  have_dinfo; /* initially False */
631b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
632b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   /* All the rest of the fields in this structure are filled in once
633b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      we have committed to reading the symbols and debug info (that
634b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      is, at the point where .have_dinfo is set to True). */
635b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
636f1e1aa691d7a2f0f2f933daf060bec5ae6938705philippe   /* The file's soname. */
6371636d33c13958b9c0e7d3059cdd5005746418eb2florian   HChar* soname;
638eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
639b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   /* Description of some important mapped segments.  The presence or
640b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      absence of the mapping is denoted by the _present field, since
641b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      in some obscure circumstances (to do with data/sdata/bss) it is
642b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      possible for the mapping to be present but have zero size.
643b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      Certainly text_ is mandatory on all platforms; not sure about
644f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      the rest though.
645f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj
646bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      --------------------------------------------------------
647bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
648f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      Comment_on_IMPORTANT_CFSI_REPRESENTATIONAL_INVARIANTS: we require that
649f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj
6506b5625bb609b154766d2e138b61e15655f60b710sewardj      either (size of all rx maps == 0 && cfsi == NULL) (the degenerate case)
651f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj
652f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      or the normal case, which is the AND of the following:
6536b5625bb609b154766d2e138b61e15655f60b710sewardj      (0) size of at least one rx mapping > 0
6546b5625bb609b154766d2e138b61e15655f60b710sewardj      (1) no two DebugInfos with some rx mapping of size > 0
6556b5625bb609b154766d2e138b61e15655f60b710sewardj          have overlapping rx mappings
6566b5625bb609b154766d2e138b61e15655f60b710sewardj      (2) [cfsi_minavma,cfsi_maxavma] does not extend beyond
6576b5625bb609b154766d2e138b61e15655f60b710sewardj          [avma,+size) of one rx mapping; that is, the former
6586b5625bb609b154766d2e138b61e15655f60b710sewardj          is a subrange or equal to the latter.
659f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      (3) all DiCfSI in the cfsi array all have ranges that fall within
6606b5625bb609b154766d2e138b61e15655f60b710sewardj          [avma,+size) of that rx mapping.
661f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      (4) all DiCfSI in the cfsi array are non-overlapping
662f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj
663f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      The cumulative effect of these restrictions is to ensure that
664f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      all the DiCfSI records in the entire system are non overlapping.
665f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      Hence any address falls into either exactly one DiCfSI record,
666f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      or none.  Hence it is safe to cache the results of searches for
667f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      DiCfSI records.  This is the whole point of these restrictions.
668f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      The caching of DiCfSI searches is done in VG_(use_CF_info).  The
669f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      cache is flushed after any change to debugInfo_list.  DiCfSI
670f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      searches are cached because they are central to stack unwinding
671f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      on amd64-linux.
672f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj
673f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      Where are these invariants imposed and checked?
674f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj
675f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      They are checked after a successful read of debuginfo into
676f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      a DebugInfo*, in check_CFSI_related_invariants.
677f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj
678f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      (1) is not really imposed anywhere.  We simply assume that the
679f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      kernel will not map the text segments from two different objects
680f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      into the same space.  Sounds reasonable.
681f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj
682f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      (2) follows from (4) and (3).  It is ensured by canonicaliseCFI.
683f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      (3) is ensured by ML_(addDiCfSI).
684f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj      (4) is ensured by canonicaliseCFI.
685bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
686bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      --------------------------------------------------------
687bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
688bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      Comment_on_DEBUG_SVMA_and_DEBUG_BIAS_fields:
689bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
690bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      The _debug_{svma,bias} fields were added as part of a fix to
691bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      #185816.  The problem encompassed in that bug report was that it
692bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      wasn't correct to use apply the bias values deduced for a
693bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      primary object to its associated debuginfo object, because the
694bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      debuginfo object (or the primary) could have been prelinked to a
695bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      different SVMA.  Hence debuginfo and primary objects need to
696bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      have their own biases.
697bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
698bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      ------ JRS: (referring to r9329): ------
699bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      Let me see if I understand the workings correctly.  Initially
700bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      the _debug_ values are set to the same values as the "normal"
701bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      ones, as there's a bunch of bits of code like this (in
702bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      readelf.c)
703bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
704bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj         di->text_svma = svma;
705bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj         ...
706bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj         di->text_bias = rx_bias;
707bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj         di->text_debug_svma = svma;
708bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj         di->text_debug_bias = rx_bias;
709bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
710bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      If a debuginfo object subsequently shows up then the
711bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      _debug_svma/bias are set for the debuginfo object.  Result is
712bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      that if there's no debuginfo object then the values are the same
713bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      as the primary-object values, and if there is a debuginfo object
714bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      then they will (or at least may) be different.
715bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
716bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      Then when we need to actually bias something, we'll have to
717bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      decide whether to use the primary bias or the debuginfo bias.
718bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      And the strategy is to use the primary bias for ELF symbols but
719bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      the debuginfo bias for anything pulled out of Dwarf.
720bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
721bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      ------ THH: ------
722bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      Correct - the debug_svma and bias values apply to any address
723bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      read from the debug data regardless of where that debug data is
724bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      stored and the other values are used for addresses from other
725bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      places (primarily the symbol table).
726bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
727bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      ------ JRS: ------
728bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      Ok; so this was my only area of concern.  Are there any
729bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      corner-case scenarios where this wouldn't be right?  It sounds
730bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      like we're assuming the ELF symbols come from the primary object
731bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      and, if there is a debug object, then all the Dwarf comes from
732bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      there.  But what if (eg) both symbols and Dwarf come from the
733bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      debug object?  Is that even possible or allowable?
734bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
735bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      ------ THH: ------
736bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      You may have a point...
737bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
738bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      The current logic is to try and take any one set of data from
739bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      either the base object or the debug object. There are four sets
740bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      of data we consider:
741bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
742bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj         - Symbol Table
743bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj         - Stabs
744bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj         - DWARF1
745bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj         - DWARF2
746bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
747bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      If we see the primary section for a given set in the base object
748bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      then we ignore all sections relating to that set in the debug
749bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      object.
750bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
751bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      Now in principle if we saw a secondary section (like debug_line
752bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      say) in the base object, but not the main section (debug_info in
753bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      this case) then we would take debug_info from the debug object
754bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      but would use the debug_line from the base object unless we saw
755bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      a replacement copy in the debug object. That's probably unlikely
756bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      however.
757bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
758bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      A bigger issue might be, as you say, the symbol table as we will
759bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      pick that up from the debug object if it isn't in the base. The
760bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      dynamic symbol table will always have to be in the base object
761bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      though so we will have to be careful when processing symbols to
762bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      know which table we are reading in that case.
763bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
764bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      What we probably need to do is tell read_elf_symtab which object
765bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      the symbols it is being asked to read came from.
766bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj
767bcaa2c8a0a0a30e67bfdfd4a140fb886f382e260sewardj      (A followup patch to deal with this was committed in r9469).
768f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj   */
769b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   /* .text */
770c4431bfe04c7490ea2d74939d222d87f13f30960njn   Bool     text_present;
771c4431bfe04c7490ea2d74939d222d87f13f30960njn   Addr     text_avma;
772c4431bfe04c7490ea2d74939d222d87f13f30960njn   Addr     text_svma;
773c4431bfe04c7490ea2d74939d222d87f13f30960njn   SizeT    text_size;
774c4431bfe04c7490ea2d74939d222d87f13f30960njn   PtrdiffT text_bias;
775402c9eed11b9b60c6e134d05db938e395466cf99tom   Addr     text_debug_svma;
776402c9eed11b9b60c6e134d05db938e395466cf99tom   PtrdiffT text_debug_bias;
777b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   /* .data */
778c4431bfe04c7490ea2d74939d222d87f13f30960njn   Bool     data_present;
779c4431bfe04c7490ea2d74939d222d87f13f30960njn   Addr     data_svma;
780c4431bfe04c7490ea2d74939d222d87f13f30960njn   Addr     data_avma;
781c4431bfe04c7490ea2d74939d222d87f13f30960njn   SizeT    data_size;
782c4431bfe04c7490ea2d74939d222d87f13f30960njn   PtrdiffT data_bias;
783402c9eed11b9b60c6e134d05db938e395466cf99tom   Addr     data_debug_svma;
784402c9eed11b9b60c6e134d05db938e395466cf99tom   PtrdiffT data_debug_bias;
785b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   /* .sdata */
786c4431bfe04c7490ea2d74939d222d87f13f30960njn   Bool     sdata_present;
787c4431bfe04c7490ea2d74939d222d87f13f30960njn   Addr     sdata_svma;
788c4431bfe04c7490ea2d74939d222d87f13f30960njn   Addr     sdata_avma;
789c4431bfe04c7490ea2d74939d222d87f13f30960njn   SizeT    sdata_size;
790c4431bfe04c7490ea2d74939d222d87f13f30960njn   PtrdiffT sdata_bias;
791402c9eed11b9b60c6e134d05db938e395466cf99tom   Addr     sdata_debug_svma;
792402c9eed11b9b60c6e134d05db938e395466cf99tom   PtrdiffT sdata_debug_bias;
793160d5a82d2d5d7d0964140dea17751c1daa3315etom   /* .rodata */
794160d5a82d2d5d7d0964140dea17751c1daa3315etom   Bool     rodata_present;
795160d5a82d2d5d7d0964140dea17751c1daa3315etom   Addr     rodata_svma;
796160d5a82d2d5d7d0964140dea17751c1daa3315etom   Addr     rodata_avma;
797160d5a82d2d5d7d0964140dea17751c1daa3315etom   SizeT    rodata_size;
798160d5a82d2d5d7d0964140dea17751c1daa3315etom   PtrdiffT rodata_bias;
799402c9eed11b9b60c6e134d05db938e395466cf99tom   Addr     rodata_debug_svma;
800402c9eed11b9b60c6e134d05db938e395466cf99tom   PtrdiffT rodata_debug_bias;
801b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   /* .bss */
802c4431bfe04c7490ea2d74939d222d87f13f30960njn   Bool     bss_present;
803c4431bfe04c7490ea2d74939d222d87f13f30960njn   Addr     bss_svma;
804c4431bfe04c7490ea2d74939d222d87f13f30960njn   Addr     bss_avma;
805c4431bfe04c7490ea2d74939d222d87f13f30960njn   SizeT    bss_size;
806c4431bfe04c7490ea2d74939d222d87f13f30960njn   PtrdiffT bss_bias;
807402c9eed11b9b60c6e134d05db938e395466cf99tom   Addr     bss_debug_svma;
808402c9eed11b9b60c6e134d05db938e395466cf99tom   PtrdiffT bss_debug_bias;
809160d5a82d2d5d7d0964140dea17751c1daa3315etom   /* .sbss */
810160d5a82d2d5d7d0964140dea17751c1daa3315etom   Bool     sbss_present;
811160d5a82d2d5d7d0964140dea17751c1daa3315etom   Addr     sbss_svma;
812160d5a82d2d5d7d0964140dea17751c1daa3315etom   Addr     sbss_avma;
813160d5a82d2d5d7d0964140dea17751c1daa3315etom   SizeT    sbss_size;
814160d5a82d2d5d7d0964140dea17751c1daa3315etom   PtrdiffT sbss_bias;
815402c9eed11b9b60c6e134d05db938e395466cf99tom   Addr     sbss_debug_svma;
816402c9eed11b9b60c6e134d05db938e395466cf99tom   PtrdiffT sbss_debug_bias;
817ade2eddf567a868bafad9110ed92acf7373a972bsewardj   /* .ARM.exidx -- sometimes present on arm32, containing unwind info. */
818ade2eddf567a868bafad9110ed92acf7373a972bsewardj   Bool     exidx_present;
819ade2eddf567a868bafad9110ed92acf7373a972bsewardj   Addr     exidx_avma;
820ade2eddf567a868bafad9110ed92acf7373a972bsewardj   Addr     exidx_svma;
821ade2eddf567a868bafad9110ed92acf7373a972bsewardj   SizeT    exidx_size;
822ade2eddf567a868bafad9110ed92acf7373a972bsewardj   PtrdiffT exidx_bias;
823ade2eddf567a868bafad9110ed92acf7373a972bsewardj   /* .ARM.extab -- sometimes present on arm32, containing unwind info. */
824ade2eddf567a868bafad9110ed92acf7373a972bsewardj   Bool     extab_present;
825ade2eddf567a868bafad9110ed92acf7373a972bsewardj   Addr     extab_avma;
826ade2eddf567a868bafad9110ed92acf7373a972bsewardj   Addr     extab_svma;
827ade2eddf567a868bafad9110ed92acf7373a972bsewardj   SizeT    extab_size;
828ade2eddf567a868bafad9110ed92acf7373a972bsewardj   PtrdiffT extab_bias;
829b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   /* .plt */
830b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Bool   plt_present;
831b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Addr	  plt_avma;
832b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   SizeT  plt_size;
833b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   /* .got */
834b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Bool   got_present;
835b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Addr   got_avma;
836b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   SizeT  got_size;
837092b6268cc4a38ae9ee41d1e3355937536ddc579bart   /* .got.plt */
838092b6268cc4a38ae9ee41d1e3355937536ddc579bart   Bool   gotplt_present;
839092b6268cc4a38ae9ee41d1e3355937536ddc579bart   Addr   gotplt_avma;
840092b6268cc4a38ae9ee41d1e3355937536ddc579bart   SizeT  gotplt_size;
841582d58245637ab05272d89fb94b12fd0f18fa0f8carll   /* .opd -- needed on ppc64be-linux for finding symbols */
842b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Bool   opd_present;
843b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Addr   opd_avma;
844b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   SizeT  opd_size;
845452e89a9f847975609b3ad318943830f2cce841csewardj   /* .ehframe -- needed on amd64-linux for stack unwinding.  We might
846452e89a9f847975609b3ad318943830f2cce841csewardj      see more than one, hence the arrays. */
847452e89a9f847975609b3ad318943830f2cce841csewardj   UInt   n_ehframe;  /* 0 .. N_EHFRAME_SECTS */
848452e89a9f847975609b3ad318943830f2cce841csewardj   Addr   ehframe_avma[N_EHFRAME_SECTS];
849452e89a9f847975609b3ad318943830f2cce841csewardj   SizeT  ehframe_size[N_EHFRAME_SECTS];
850b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
851b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   /* Sorted tables of stuff we snarfed from the file.  This is the
852b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      eventual product of reading the debug info.  All this stuff
853b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      lives in VG_AR_DINFO. */
854b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
855eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   /* An expandable array of symbols. */
856eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   DiSym*  symtab;
857b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   UWord   symtab_used;
858b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   UWord   symtab_size;
85959e1f3c79e870a978d24add86db6d8c5450c8b63philippe   /* Two expandable arrays, storing locations and their filename/dirname. */
860eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   DiLoc*  loctab;
86159e1f3c79e870a978d24add86db6d8c5450c8b63philippe   UInt    sizeof_fndn_ix;  /* Similar use as sizeof_cfsi_m_ix below. */
86259e1f3c79e870a978d24add86db6d8c5450c8b63philippe   void*   loctab_fndn_ix;  /* loctab[i] filename/dirname is identified by
86359e1f3c79e870a978d24add86db6d8c5450c8b63philippe                               loctab_fnindex_ix[i] (an index in di->fndnpool)
86459e1f3c79e870a978d24add86db6d8c5450c8b63philippe                               0 means filename/dirname unknown.
86559e1f3c79e870a978d24add86db6d8c5450c8b63philippe                               The void* is an UChar* or UShort* or UInt*
86659e1f3c79e870a978d24add86db6d8c5450c8b63philippe                               depending on sizeof_fndn_ix. */
867b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   UWord   loctab_used;
868b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   UWord   loctab_size;
869a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   /* An expandable array of inlined fn info.
870a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe      maxinl_codesz is the biggest inlined piece of code
871a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe      in inltab (i.e. the max of 'addr_hi - addr_lo'. */
872a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   DiInlLoc* inltab;
873a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   UWord   inltab_used;
874a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   UWord   inltab_size;
875a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   SizeT   maxinl_codesz;
8765c3dba227192de63d86f65ec7d9597c132818c37philippe
8775c3dba227192de63d86f65ec7d9597c132818c37philippe   /* A set of expandable arrays to store CFI summary info records.
8785c3dba227192de63d86f65ec7d9597c132818c37philippe      The machine specific information (i.e. the DiCfSI_m struct)
8795c3dba227192de63d86f65ec7d9597c132818c37philippe      are stored in cfsi_m_pool, as these are highly duplicated.
8805c3dba227192de63d86f65ec7d9597c132818c37philippe      The DiCfSI_m are allocated in cfsi_m_pool and identified using
8815c3dba227192de63d86f65ec7d9597c132818c37philippe      a (we hope) small integer : often one byte is enough, sometimes
8825c3dba227192de63d86f65ec7d9597c132818c37philippe      2 bytes are needed.
8835c3dba227192de63d86f65ec7d9597c132818c37philippe
8845c3dba227192de63d86f65ec7d9597c132818c37philippe      cfsi_base contains the bases of the code address ranges.
8855c3dba227192de63d86f65ec7d9597c132818c37philippe      cfsi_size is the size of the cfsi_base array.
8865c3dba227192de63d86f65ec7d9597c132818c37philippe      The elements cfsi_base[0] till cfsi_base[cfsi_used-1] are used.
8875c3dba227192de63d86f65ec7d9597c132818c37philippe      Following elements are not used (yet).
8885c3dba227192de63d86f65ec7d9597c132818c37philippe
8895c3dba227192de63d86f65ec7d9597c132818c37philippe      For each base in cfsi_base, an index into cfsi_m_pool is stored
8905c3dba227192de63d86f65ec7d9597c132818c37philippe      in cfsi_m_ix array. The size of cfsi_m_ix is equal to
89159e1f3c79e870a978d24add86db6d8c5450c8b63philippe      cfsi_size*sizeof_cfsi_m_ix. The used portion of cfsi_m_ix is
89259e1f3c79e870a978d24add86db6d8c5450c8b63philippe      cfsi_m_ix[0] till cfsi_m_ix[(cfsi_used-1)*sizeof_cfsi_m_ix].
8935c3dba227192de63d86f65ec7d9597c132818c37philippe
8945c3dba227192de63d86f65ec7d9597c132818c37philippe      cfsi_base[i] gives the base address of a code range covered by
8955c3dba227192de63d86f65ec7d9597c132818c37philippe      some CF Info. The corresponding CF Info is identified by an index
8965c3dba227192de63d86f65ec7d9597c132818c37philippe      in cfsi_m_pool. The DiCfSI_m index in cfsi_m_pool corresponding to
8975c3dba227192de63d86f65ec7d9597c132818c37philippe      cfsi_base[i] is given
89859e1f3c79e870a978d24add86db6d8c5450c8b63philippe        by ((UChar*) cfsi_m_ix)[i] if sizeof_cfsi_m_ix == 1
89959e1f3c79e870a978d24add86db6d8c5450c8b63philippe        by ((UShort*)cfsi_m_ix)[i] if sizeof_cfsi_m_ix == 2
90059e1f3c79e870a978d24add86db6d8c5450c8b63philippe        by ((UInt*)  cfsi_m_ix)[i] if sizeof_cfsi_m_ix == 4.
9015c3dba227192de63d86f65ec7d9597c132818c37philippe
9025c3dba227192de63d86f65ec7d9597c132818c37philippe      The end of the code range starting at cfsi_base[i] is given by
9035c3dba227192de63d86f65ec7d9597c132818c37philippe      cfsi_base[i+1]-1 (or cfsi_maxavma for  cfsi_base[cfsi_used-1]).
9045c3dba227192de63d86f65ec7d9597c132818c37philippe      Some code ranges between cfsi_minavma and cfsi_maxavma might not
9055c3dba227192de63d86f65ec7d9597c132818c37philippe      be covered by cfi information. Such not covered ranges are stored by
9065c3dba227192de63d86f65ec7d9597c132818c37philippe      a base in cfsi_base and a corresponding 0 index in cfsi_m_ix.
9075c3dba227192de63d86f65ec7d9597c132818c37philippe
9085c3dba227192de63d86f65ec7d9597c132818c37philippe      A variable size representation has been chosen for the elements of
9095c3dba227192de63d86f65ec7d9597c132818c37philippe      cfsi_m_ix as in many case, one byte is good enough. For big
9105c3dba227192de63d86f65ec7d9597c132818c37philippe      objects, 2 bytes are needed. No object has yet been found where
9115c3dba227192de63d86f65ec7d9597c132818c37philippe      4 bytes are needed (but the code is ready to handle this case).
9125c3dba227192de63d86f65ec7d9597c132818c37philippe      Not covered ranges ('cfi holes') are stored explicitely in
9135c3dba227192de63d86f65ec7d9597c132818c37philippe      cfsi_base/cfsi_m_ix as this is more memory efficient than storing
9145c3dba227192de63d86f65ec7d9597c132818c37philippe      a length for each covered range : on x86 or amd64, we typically have
9155c3dba227192de63d86f65ec7d9597c132818c37philippe      a hole every 8 covered ranges. On arm64, we have very few holes
9165c3dba227192de63d86f65ec7d9597c132818c37philippe      (1 every 50 or 100 ranges).
9175c3dba227192de63d86f65ec7d9597c132818c37philippe
9185c3dba227192de63d86f65ec7d9597c132818c37philippe      The cfsi information is read and prepared in the cfsi_rd array.
9195c3dba227192de63d86f65ec7d9597c132818c37philippe      Once all the information has been read, the cfsi_base and cfsi_m_ix
9205c3dba227192de63d86f65ec7d9597c132818c37philippe      arrays will be filled in from cfsi_rd. cfsi_rd will then be freed.
9215c3dba227192de63d86f65ec7d9597c132818c37philippe      This is all done by ML_(finish_CFSI_arrays).
9225c3dba227192de63d86f65ec7d9597c132818c37philippe
9235c3dba227192de63d86f65ec7d9597c132818c37philippe      Also includes summary address bounds, showing the min and max address
9245c3dba227192de63d86f65ec7d9597c132818c37philippe      covered by any of the records, as an aid to fast searching.  And, if the
92572427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      records require any expression nodes, they are stored in
92672427fa91a5e05e3323b5a8a407bd8d7b04c75ccsewardj      cfsi_exprs. */
9275c3dba227192de63d86f65ec7d9597c132818c37philippe   Addr* cfsi_base;
92859e1f3c79e870a978d24add86db6d8c5450c8b63philippe   UInt  sizeof_cfsi_m_ix; /* size in byte of indexes stored in cfsi_m_ix. */
9296df28a8ede81f7392a7b9b5d777980063f974359philippe   void* cfsi_m_ix; /* Each index occupies sizeof_cfsi_m_ix bytes.
9306df28a8ede81f7392a7b9b5d777980063f974359philippe                       The void* is an UChar* or UShort* or UInt*
9316df28a8ede81f7392a7b9b5d777980063f974359philippe                       depending on sizeof_cfsi_m_ix.  */
9325c3dba227192de63d86f65ec7d9597c132818c37philippe
9335c3dba227192de63d86f65ec7d9597c132818c37philippe   DiCfSI* cfsi_rd; /* Only used during reading, NULL once info is read. */
9345c3dba227192de63d86f65ec7d9597c132818c37philippe
935f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj   UWord   cfsi_used;
936f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj   UWord   cfsi_size;
9375c3dba227192de63d86f65ec7d9597c132818c37philippe
9385c3dba227192de63d86f65ec7d9597c132818c37philippe   DedupPoolAlloc *cfsi_m_pool;
939b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Addr    cfsi_minavma;
940b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   Addr    cfsi_maxavma;
941b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   XArray* cfsi_exprs; /* XArray of CfiExpr */
942eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
943c8259b85b701d25d72aabe9dc0a8154517f96913sewardj   /* Optimized code under Wine x86: MSVC++ PDB FramePointerOmitted
944c8259b85b701d25d72aabe9dc0a8154517f96913sewardj      data.  Non-expandable array, hence .size == .used. */
945c8259b85b701d25d72aabe9dc0a8154517f96913sewardj   FPO_DATA* fpo;
946c8259b85b701d25d72aabe9dc0a8154517f96913sewardj   UWord     fpo_size;
947c8259b85b701d25d72aabe9dc0a8154517f96913sewardj   Addr      fpo_minavma;
948c8259b85b701d25d72aabe9dc0a8154517f96913sewardj   Addr      fpo_maxavma;
94954c45db2f978055aeca91aaccb05aac825523e6csewardj   Addr      fpo_base_avma;
950c8259b85b701d25d72aabe9dc0a8154517f96913sewardj
9517293d2530f8c60c1060f9f003e214cc341d35266philippe   /* Pool of strings -- the string table.  Pointers
9527293d2530f8c60c1060f9f003e214cc341d35266philippe      into this are stable (the memory is not reallocated). */
9537293d2530f8c60c1060f9f003e214cc341d35266philippe   DedupPoolAlloc *strpool;
954eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
95559e1f3c79e870a978d24add86db6d8c5450c8b63philippe   /* Pool of FnDn -- filename and dirname.
95659e1f3c79e870a978d24add86db6d8c5450c8b63philippe      Elements in the pool are allocated using VG_(allocFixedEltDedupPA). */
95759e1f3c79e870a978d24add86db6d8c5450c8b63philippe   DedupPoolAlloc *fndnpool;
95859e1f3c79e870a978d24add86db6d8c5450c8b63philippe
959b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   /* Variable scope information, as harvested from Dwarf3 files.
960eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
961b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      In short it's an
962f767d967b9ef331dcd7d0cd4584f6570cd829333sewardj
963b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj         array of (array of PC address ranges and variables)
964b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
965b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      The outer array indexes over scopes, with Entry 0 containing
966b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      information on variables which exist for any value of the program
967b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      counter (PC) -- that is, the outermost scope.  Entries 1, 2, 3,
968b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      etc contain information on increasinly deeply nested variables.
969b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
970b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      Each inner array is an array of (an address range, and a set
971b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      of variables that are in scope over that address range).
972b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
973b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      The address ranges may not overlap.
974b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
975b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      Since Entry 0 in the outer array holds information on variables
976b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      that exist for any value of the PC (that is, global vars), it
977b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      follows that Entry 0's inner array can only have one address
978b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      range pair, one that covers the entire address space.
979b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   */
980b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   XArray* /* of OSet of DiAddrRange */varinfo;
981b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
9829c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj   /* These are arrays of the relevant typed objects, held here
9839c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj      partially for the purposes of visiting each object exactly once
984b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj      when we need to delete them. */
985b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
9869c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj   /* An array of TyEnts.  These are needed to make sense of any types
9879c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj      in the .varinfo.  Also, when deleting this DebugInfo, we must
9889c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj      first traverse this array and throw away malloc'd stuff hanging
9899c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj      off it -- by calling ML_(TyEnt__make_EMPTY) on each entry. */
9909c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj   XArray* /* of TyEnt */ admin_tyents;
991b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
9929c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj   /* An array of guarded DWARF3 expressions. */
9939c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj   XArray* admin_gexprs;
9946b5625bb609b154766d2e138b61e15655f60b710sewardj
9956b5625bb609b154766d2e138b61e15655f60b710sewardj   /* Cached last rx mapping matched and returned by ML_(find_rx_mapping).
9966b5625bb609b154766d2e138b61e15655f60b710sewardj      This helps performance a lot during ML_(addLineInfo) etc., which can
9976b5625bb609b154766d2e138b61e15655f60b710sewardj      easily be invoked hundreds of thousands of times. */
998518850bf0da07ed3e2244e307268ae0fd80e93a8florian   DebugInfoMapping* last_rx_map;
999eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj};
1000eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1001eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* --------------------- functions --------------------- */
1002eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1003eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* ------ Adding ------ */
1004eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1005a5cace0c2a3e212931badbf6398a0cd98393121asewardj/* Add a symbol to si's symbol table.  The contents of 'sym' are
1006a5cace0c2a3e212931badbf6398a0cd98393121asewardj   copied.  It is assumed (and checked) that 'sym' only contains one
1007a5cace0c2a3e212931badbf6398a0cd98393121asewardj   name, so there is no auxiliary ::sec_names vector to duplicate.
1008a5cace0c2a3e212931badbf6398a0cd98393121asewardj   IOW, the copy is a shallow copy, and there are assertions in place
1009a5cace0c2a3e212931badbf6398a0cd98393121asewardj   to ensure that's OK. */
1010b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjextern void ML_(addSym) ( struct _DebugInfo* di, DiSym* sym );
1011eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
101259e1f3c79e870a978d24add86db6d8c5450c8b63philippe/* Add a filename/dirname pair to a DebugInfo and returns the index
101359e1f3c79e870a978d24add86db6d8c5450c8b63philippe   in the fndnpool fixed pool. */
101459e1f3c79e870a978d24add86db6d8c5450c8b63philippeextern UInt ML_(addFnDn) (struct _DebugInfo* di,
101559e1f3c79e870a978d24add86db6d8c5450c8b63philippe                          const HChar* filename,
101659e1f3c79e870a978d24add86db6d8c5450c8b63philippe                          const HChar* dirname);  /* NULL is allowable */
101759e1f3c79e870a978d24add86db6d8c5450c8b63philippe
1018666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe/* Returns the filename of the fndn pair identified by fndn_ix.
1019666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe   Returns "???" if fndn_ix is 0. */
1020518850bf0da07ed3e2244e307268ae0fd80e93a8florianextern const HChar* ML_(fndn_ix2filename) (const DebugInfo* di,
1021666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe                                           UInt fndn_ix);
1022666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe
1023666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe/* Returns the dirname of the fndn pair identified by fndn_ix.
1024666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe   Returns "" if fndn_ix is 0 or fndn->dirname is NULL. */
1025518850bf0da07ed3e2244e307268ae0fd80e93a8florianextern const HChar* ML_(fndn_ix2dirname) (const DebugInfo* di,
1026666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe                                          UInt fndn_ix);
1027666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe
102859e1f3c79e870a978d24add86db6d8c5450c8b63philippe/* Returns the fndn_ix for the LineInfo locno in di->loctab.
102959e1f3c79e870a978d24add86db6d8c5450c8b63philippe   0 if filename/dirname are unknown. */
1030518850bf0da07ed3e2244e307268ae0fd80e93a8florianextern UInt ML_(fndn_ix) (const DebugInfo* di, Word locno);
103159e1f3c79e870a978d24add86db6d8c5450c8b63philippe
103259e1f3c79e870a978d24add86db6d8c5450c8b63philippe/* Add a line-number record to a DebugInfo.
103359e1f3c79e870a978d24add86db6d8c5450c8b63philippe   fndn_ix is an index in di->fndnpool, allocated using  ML_(addFnDn).
103459e1f3c79e870a978d24add86db6d8c5450c8b63philippe   Give a 0 index for a unknown filename/dirname pair. */
1035eadcd86d1b0f59efed44c162ef4378ccfb528290sewardjextern
1036b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjvoid ML_(addLineInfo) ( struct _DebugInfo* di,
103759e1f3c79e870a978d24add86db6d8c5450c8b63philippe                        UInt fndn_ix,
1038eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj                        Addr this, Addr next, Int lineno, Int entry);
1039eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1040a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe/* Add a call inlined record to a DebugInfo.
1041a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   A call to the below means that inlinedfn code has been
1042a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   inlined, resulting in code from [addr_lo, addr_hi[.
1043a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   Note that addr_hi is excluded, i.e. is not part of the inlined code.
1044666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe   fndn_ix and lineno identifies the location of the call that caused
1045666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe   this inlining.
1046666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe   fndn_ix is an index in di->fndnpool, allocated using  ML_(addFnDn).
1047666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe   Give a 0 index for an unknown filename/dirname pair.
1048a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   In case of nested inlining, a small level indicates the call
1049a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe   is closer to main that a call with a higher level. */
1050a0a73939b0398b6608fd6dbde49820ce6530d12cphilippeextern
1051a0a73939b0398b6608fd6dbde49820ce6530d12cphilippevoid ML_(addInlInfo) ( struct _DebugInfo* di,
1052a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe                       Addr addr_lo, Addr addr_hi,
1053a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe                       const HChar* inlinedfn,
1054666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe                       UInt fndn_ix,
1055a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe                       Int lineno, UShort level);
1056a0a73939b0398b6608fd6dbde49820ce6530d12cphilippe
10575c3dba227192de63d86f65ec7d9597c132818c37philippe/* Add a CFI summary record.  The supplied DiCfSI_m is copied. */
10585c3dba227192de63d86f65ec7d9597c132818c37philippeextern void ML_(addDiCfSI) ( struct _DebugInfo* di,
10595c3dba227192de63d86f65ec7d9597c132818c37philippe                             Addr base, UInt len, DiCfSI_m* cfsi_m );
10605c3dba227192de63d86f65ec7d9597c132818c37philippe
10615c3dba227192de63d86f65ec7d9597c132818c37philippe/* Given a position in the di->cfsi_base/cfsi_m_ix arrays, return
10625c3dba227192de63d86f65ec7d9597c132818c37philippe   the corresponding cfsi_m*. Return NULL if the position corresponds
10635c3dba227192de63d86f65ec7d9597c132818c37philippe   to a cfsi hole. */
1064518850bf0da07ed3e2244e307268ae0fd80e93a8florianDiCfSI_m* ML_(get_cfsi_m) (const DebugInfo* di, UInt pos);
1065eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1066b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* Add a string to the string table of a DebugInfo.  If len==-1,
1067eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   ML_(addStr) will itself measure the length of the string. */
10681ef70c6f00ab1b50d1936f77037e9923d8ed8c59florianextern const HChar* ML_(addStr) ( DebugInfo* di, const HChar* str, Int len );
1069b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
10705d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj/* Add a string to the string table of a DebugInfo, by copying the
10715d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj   string from the given DiCursor.  Measures the length of the string
10725d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj   itself. */
10731ef70c6f00ab1b50d1936f77037e9923d8ed8c59florianextern const HChar* ML_(addStrFromCursor)( DebugInfo* di, DiCursor c );
1074b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
1075b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjextern void ML_(addVar)( struct _DebugInfo* di,
1076b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj                         Int    level,
1077b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj                         Addr   aMin,
1078b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj                         Addr   aMax,
10791ef70c6f00ab1b50d1936f77037e9923d8ed8c59florian                         const  HChar* name,
10809c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj                         UWord  typeR, /* a cuOff */
10813297124fa2116737066ac3cd709f18fdd5405163florian                         const GExpr* gexpr,
10823297124fa2116737066ac3cd709f18fdd5405163florian                         const GExpr* fbGX, /* SHARED. */
1083666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe                         UInt   fndn_ix, /* where decl'd - may be zero */
1084b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj                         Int    lineNo, /* where decl'd - may be zero */
1085b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj                         Bool   show );
1086666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe/* Note: fndn_ix identifies a filename/dirname pair similarly to
1087666ee9df4c2b6d801b199b8168208dbb46573c9dphilippe   ML_(addInlInfo) and ML_(addLineInfo). */
1088b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj
1089b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* Canonicalise the tables held by 'di', in preparation for use.  Call
1090eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   this after finishing adding entries to these tables. */
1091b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjextern void ML_(canonicaliseTables) ( struct _DebugInfo* di );
1092eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
10933c9cf3442185b5891e15450d6e3058aeff6796fetom/* Canonicalise the call-frame-info table held by 'di', in preparation
10943c9cf3442185b5891e15450d6e3058aeff6796fetom   for use. This is called by ML_(canonicaliseTables) but can also be
10953c9cf3442185b5891e15450d6e3058aeff6796fetom   called on it's own to sort just this table. */
10963c9cf3442185b5891e15450d6e3058aeff6796fetomextern void ML_(canonicaliseCFI) ( struct _DebugInfo* di );
10973c9cf3442185b5891e15450d6e3058aeff6796fetom
10985c3dba227192de63d86f65ec7d9597c132818c37philippe/* ML_(finish_CFSI_arrays) fills in the cfsi_base and cfsi_m_ix arrays
10995c3dba227192de63d86f65ec7d9597c132818c37philippe   from cfsi_rd array. cfsi_rd is then freed. */
11005c3dba227192de63d86f65ec7d9597c132818c37philippeextern void ML_(finish_CFSI_arrays) ( struct _DebugInfo* di );
11015c3dba227192de63d86f65ec7d9597c132818c37philippe
1102eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* ------ Searching ------ */
1103eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1104eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* Find a symbol-table index containing the specified pointer, or -1
1105eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   if not found.  Binary search.  */
1106518850bf0da07ed3e2244e307268ae0fd80e93a8florianextern Word ML_(search_one_symtab) ( const DebugInfo* di, Addr ptr,
1107f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj                                     Bool match_anywhere_in_sym,
1108f98e1c03ce4bea1fb092cdea5571c41f29f6df9bsewardj                                     Bool findText );
1109eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1110eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* Find a location-table index containing the specified pointer, or -1
1111eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   if not found.  Binary search.  */
1112518850bf0da07ed3e2244e307268ae0fd80e93a8florianextern Word ML_(search_one_loctab) ( const DebugInfo* di, Addr ptr );
1113eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1114eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* Find a CFI-table index containing the specified pointer, or -1 if
1115eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj   not found.  Binary search.  */
1116518850bf0da07ed3e2244e307268ae0fd80e93a8florianextern Word ML_(search_one_cfitab) ( const DebugInfo* di, Addr ptr );
1117eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1118c8259b85b701d25d72aabe9dc0a8154517f96913sewardj/* Find a FPO-table index containing the specified pointer, or -1
1119c8259b85b701d25d72aabe9dc0a8154517f96913sewardj   if not found.  Binary search.  */
1120518850bf0da07ed3e2244e307268ae0fd80e93a8florianextern Word ML_(search_one_fpotab) ( const DebugInfo* di, Addr ptr );
1121c8259b85b701d25d72aabe9dc0a8154517f96913sewardj
1122db3f3e6e7bde198592d44642a0da2613a89a8eb5sewardj/* Helper function for the most often needed searching for an rx
1123db3f3e6e7bde198592d44642a0da2613a89a8eb5sewardj   mapping containing the specified address range.  The range must
1124db3f3e6e7bde198592d44642a0da2613a89a8eb5sewardj   fall entirely within the mapping to be considered to be within it.
1125db3f3e6e7bde198592d44642a0da2613a89a8eb5sewardj   Asserts if lo > hi; caller must ensure this doesn't happen. */
1126518850bf0da07ed3e2244e307268ae0fd80e93a8florianextern DebugInfoMapping* ML_(find_rx_mapping) ( DebugInfo* di,
1127518850bf0da07ed3e2244e307268ae0fd80e93a8florian                                                Addr lo, Addr hi );
11286b5625bb609b154766d2e138b61e15655f60b710sewardj
1129eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* ------ Misc ------ */
1130eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1131205a42f1b48012de8b9633982d3a2d21cb26e006florian/* Show a non-fatal debug info reading error.  Use VG_(core_panic) for
1132205a42f1b48012de8b9633982d3a2d21cb26e006florian   fatal errors.  'serious' errors are always shown, not 'serious' ones
1133b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj   are shown only at verbosity level 2 and above. */
1134b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjextern
1135518850bf0da07ed3e2244e307268ae0fd80e93a8florianvoid ML_(symerr) ( const DebugInfo* di, Bool serious, const HChar* msg );
1136eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1137eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* Print a symbol. */
1138518850bf0da07ed3e2244e307268ae0fd80e93a8florianextern void ML_(ppSym) ( Int idx, const DiSym* sym );
1139eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1140eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/* Print a call-frame-info summary. */
1141518850bf0da07ed3e2244e307268ae0fd80e93a8florianextern void ML_(ppDiCfSI) ( const XArray* /* of CfiExpr */ exprs,
11425c3dba227192de63d86f65ec7d9597c132818c37philippe                            Addr base, UInt len,
1143518850bf0da07ed3e2244e307268ae0fd80e93a8florian                            const DiCfSI_m* si_m );
1144eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1145eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
11465d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj#define TRACE_SYMTAB_ENABLED (di->trace_symtab)
1147eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj#define TRACE_SYMTAB(format, args...) \
11485d616dfbb8439dfd51a40ddf1dba970938baa1ebsewardj   if (TRACE_SYMTAB_ENABLED) { VG_(printf)(format, ## args); }
1149eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1150eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1151eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj#endif /* ndef __PRIV_STORAGE_H */
1152eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj
1153eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/*--------------------------------------------------------------------*/
1154eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/*--- end                                                          ---*/
1155eadcd86d1b0f59efed44c162ef4378ccfb528290sewardj/*--------------------------------------------------------------------*/
1156