/*
Copyright (C) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
Portions Copyright (C) 2007-2010 David Anderson. All Rights Reserved.
under the terms of version 2.1 of the GNU Lesser General Public License
as published by the Free Software Foundation.
This program is distributed in the hope that it would be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Further, this software is distributed without any warranty that it is
free of the rightful claim of any third person regarding infringement
or the like. Any license provided herein, whether implied or
otherwise, applies only to this software file. Patent licenses, if
any, provided herein do not apply to combinations of this program with
other software, or any other product whatsoever.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
USA.
Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
Mountain View, CA 94043, or:
For further information regarding this notice, see:
*/
/* The address of the Free Software Foundation is
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
SGI has moved from the Crittenden Lane address.
*/
#include "config.h"
#include "dwarf_incl.h"
#include "dwarf_loc.h"
#include <stdio.h> /* for debugging only. */
/*
Given a Dwarf_Block that represents a location expression,
this function returns a pointer to a Dwarf_Locdesc struct
that has its ld_cents field set to the number of location
operators in the block, and its ld_s field pointing to a
contiguous block of Dwarf_Loc structs. However, the
ld_lopc and ld_hipc values are uninitialized. Returns
NULL on error. This function assumes that the length of
the block is greater than 0. Zero length location expressions
to represent variables that have been optimized away are
handled in the calling function.
*/
static Dwarf_Locdesc *
Dwarf_Error * error)
{
/* Size of the block containing the location expression. */
/* Sweeps the block containing the location expression. */
/* Current location operator. */
/* Offset of current operator from start of block. */
/* Operands of current location operator. */
/* Used to chain the Dwarf_Loc_Chain_s structs. */
/* Count of the number of location operators. */
/* Contiguous block of Dwarf_Loc's for Dwarf_Locdesc. */
/* Dwarf_Locdesc pointer to be returned. */
Dwarf_Unsigned i = 0;
/* ***** BEGIN CODE ***** */
offset = 0;
op_count = 0;
operand1 = 0;
operand2 = 0;
op_count++;
loc_ptr++;
offset++;
curr_loc =
1);
return (NULL);
}
switch (atom) {
case DW_OP_reg0:
case DW_OP_reg1:
case DW_OP_reg2:
case DW_OP_reg3:
case DW_OP_reg4:
case DW_OP_reg5:
case DW_OP_reg6:
case DW_OP_reg7:
case DW_OP_reg8:
case DW_OP_reg9:
case DW_OP_reg10:
case DW_OP_reg11:
case DW_OP_reg12:
case DW_OP_reg13:
case DW_OP_reg14:
case DW_OP_reg15:
case DW_OP_reg16:
case DW_OP_reg17:
case DW_OP_reg18:
case DW_OP_reg19:
case DW_OP_reg20:
case DW_OP_reg21:
case DW_OP_reg22:
case DW_OP_reg23:
case DW_OP_reg24:
case DW_OP_reg25:
case DW_OP_reg26:
case DW_OP_reg27:
case DW_OP_reg28:
case DW_OP_reg29:
case DW_OP_reg30:
case DW_OP_reg31:
break;
case DW_OP_regx:
break;
case DW_OP_lit0:
case DW_OP_lit1:
case DW_OP_lit2:
case DW_OP_lit3:
case DW_OP_lit4:
case DW_OP_lit5:
case DW_OP_lit6:
case DW_OP_lit7:
case DW_OP_lit8:
case DW_OP_lit9:
case DW_OP_lit10:
case DW_OP_lit11:
case DW_OP_lit12:
case DW_OP_lit13:
case DW_OP_lit14:
case DW_OP_lit15:
case DW_OP_lit16:
case DW_OP_lit17:
case DW_OP_lit18:
case DW_OP_lit19:
case DW_OP_lit20:
case DW_OP_lit21:
case DW_OP_lit22:
case DW_OP_lit23:
case DW_OP_lit24:
case DW_OP_lit25:
case DW_OP_lit26:
case DW_OP_lit27:
case DW_OP_lit28:
case DW_OP_lit29:
case DW_OP_lit30:
case DW_OP_lit31:
break;
case DW_OP_addr:
loc_ptr += address_size;
offset += address_size;
break;
case DW_OP_const1u:
break;
case DW_OP_const1s:
break;
case DW_OP_const2u:
break;
case DW_OP_const2s:
break;
case DW_OP_const4u:
break;
case DW_OP_const4s:
break;
case DW_OP_const8u:
break;
case DW_OP_const8s:
break;
case DW_OP_constu:
break;
case DW_OP_consts:
break;
case DW_OP_fbreg:
break;
case DW_OP_breg0:
case DW_OP_breg1:
case DW_OP_breg2:
case DW_OP_breg3:
case DW_OP_breg4:
case DW_OP_breg5:
case DW_OP_breg6:
case DW_OP_breg7:
case DW_OP_breg8:
case DW_OP_breg9:
case DW_OP_breg10:
case DW_OP_breg11:
case DW_OP_breg12:
case DW_OP_breg13:
case DW_OP_breg14:
case DW_OP_breg15:
case DW_OP_breg16:
case DW_OP_breg17:
case DW_OP_breg18:
case DW_OP_breg19:
case DW_OP_breg20:
case DW_OP_breg21:
case DW_OP_breg22:
case DW_OP_breg23:
case DW_OP_breg24:
case DW_OP_breg25:
case DW_OP_breg26:
case DW_OP_breg27:
case DW_OP_breg28:
case DW_OP_breg29:
case DW_OP_breg30:
case DW_OP_breg31:
break;
case DW_OP_bregx:
/* uleb reg num followed by sleb offset */
break;
case DW_OP_dup:
case DW_OP_drop:
break;
case DW_OP_pick:
break;
case DW_OP_over:
case DW_OP_swap:
case DW_OP_rot:
case DW_OP_deref:
break;
case DW_OP_deref_size:
break;
case DW_OP_xderef:
break;
case DW_OP_xderef_size:
break;
case DW_OP_abs:
case DW_OP_and:
case DW_OP_div:
case DW_OP_minus:
case DW_OP_mod:
case DW_OP_mul:
case DW_OP_neg:
case DW_OP_not:
case DW_OP_or:
case DW_OP_plus:
break;
case DW_OP_plus_uconst:
break;
case DW_OP_shl:
case DW_OP_shr:
case DW_OP_shra:
case DW_OP_xor:
break;
case DW_OP_le:
case DW_OP_ge:
case DW_OP_eq:
case DW_OP_lt:
case DW_OP_gt:
case DW_OP_ne:
break;
case DW_OP_skip:
case DW_OP_bra:
break;
case DW_OP_piece:
break;
case DW_OP_nop:
break;
case DW_OP_push_object_address: /* DWARF3 */
break;
case DW_OP_call2: /* DWARF3 */
break;
case DW_OP_call4: /* DWARF3 */
break;
case DW_OP_call_ref: /* DWARF3 */
break;
case DW_OP_form_tls_address: /* DWARF3f */
break;
case DW_OP_call_frame_cfa: /* DWARF3f */
break;
case DW_OP_bit_piece: /* DWARF3f */
/* uleb size in bits followed by uleb offset in bits */
break;
case DW_OP_implicit_value: /* DWARF4 */
/* uleb length of value bytes followed by that
number of bytes of the value. */
/* Second operand is block of 'operand1' bytes of stuff. */
/* This using the second operand as a pointer
is quite ugly. */
/* This gets an ugly compiler warning. Sorry. */
break;
case DW_OP_stack_value: /* DWARF4 */
break;
default:
return (NULL);
}
else {
}
}
return (NULL);
}
for (i = 0; i < op_count; i++) {
}
locdesc =
return (NULL);
}
return (locdesc);
}
/* Using a loclist offset to get the in-memory
address of .debug_loc data to read, returns the loclist
'header' info in return_block.
*/
static int
Dwarf_Error * error)
{
/* We're at the end. No more present. */
return DW_DLV_NO_ENTRY;
}
/* If it goes past end, error */
return DW_DLV_ERROR;
}
if (start_addr == 0 && end_addr == 0) {
/* If start_addr and end_addr are 0, it's the end and no
exprblock_size field follows. */
exprblock_size = 0;
exprblock_off -= sizeof(Dwarf_Half);
} else if (start_addr == MAX_ADDR) {
/* end address is a base address, no exprblock_size field here
either */
exprblock_size = 0;
exprblock_off -= sizeof(Dwarf_Half);
} else {
/* exprblock_size can be zero, means no expression */
return DW_DLV_ERROR;
}
}
*lowpc = start_addr;
return DW_DLV_OK;
}
static int
{
int count = 0;
for (;;) {
Dwarf_Block b;
return res;
}
break;
}
count++;
}
*loclist_count = count;
return DW_DLV_OK;
}
/* Helper routine to avoid code duplication.
*/
static int
{
return (DW_DLV_ERROR);
}
return (DW_DLV_ERROR);
}
return (DW_DLV_ERROR);
}
return blkres;
}
return DW_DLV_OK;
}
/* Helper routine to avoid code duplication.
*/
static int
Dwarf_Error * error)
{
return (blkres);
}
return secload;
}
}
return DW_DLV_OK;
}
/* When llbuf (see dwarf_loclist_n) is partially set up
and an error is encountered, tear it down as it
won't be used.
*/
static void
{
int i;
for (i = 0; i < count; ++i) {
}
}
/*
Handles simple location entries and loclists.
Returns all the Locdesc's thru llbuf.
*/
int
Dwarf_Locdesc *** llbuf_out,
{
/*
Dwarf_Attribute that describes the DW_AT_location in die, if
present. */
/* Dwarf_Block that describes a single location expression. */
/* A pointer to the current Dwarf_Locdesc read. */
unsigned address_size = 0;
/* ***** BEGIN CODE ***** */
return setup_res;
}
/* If this is a form_block then it's a location expression. If it's
DW_FORM_data4 or DW_FORM_data8 it's a loclist offset */
form == DW_FORM_sec_offset))
{
/* A reference to .debug_loc, with an offset in .debug_loc of a
loclist */
int loclist_count;
int lli;
error);
return off_res;
}
&loclist_count, error);
return count_res;
}
if (loclist_count == 0) {
return DW_DLV_NO_ENTRY;
}
llbuf = (Dwarf_Locdesc **)
if (!llbuf) {
return (DW_DLV_ERROR);
}
&lowpc,
&highpc,
error);
return (blkres);
}
/* low level error already set: let it be passed back */
return (DW_DLV_ERROR);
}
/* Now get to next loclist entry offset. */
}
} else {
return (blkres);
}
/* We copied tblock contents to the stack var, so can dealloc
tblock now. Avoids leaks. */
lowpc = 0; /* HACK */
/* An empty location description (block length 0) means the
code generator emitted no variable, the variable was not
generated, it was unused or perhaps never tested after being
set. Dwarf2, section 2.4.1 In other words, it is not an
error, and we don't test for block length 0 specially here. */
/* low level error already set: let it be passed back */
return (DW_DLV_ERROR);
}
llbuf = (Dwarf_Locdesc **)
if (!llbuf) {
/* Free the locdesc we allocated but won't use. */
return (DW_DLV_ERROR);
}
}
*listlen_out = listlen;
return (DW_DLV_OK);
}
/*
Handles only a location expression.
If called on a loclist, just returns one of those.
Cannot not handle a real loclist.
It returns the location expression as a loclist with
a single entry.
See dwarf_loclist_n() which handles any number
of location list entries.
This is the original definition, and it simply
does not work for loclists. Kept for compatibility.
*/
int
Dwarf_Locdesc ** llbuf,
{
/* Dwarf_Attribute that describes the DW_AT_location in die, if
present. */
/* Dwarf_Block that describes a single location expression. */
/* A pointer to the current Dwarf_Locdesc read. */
unsigned address_size = 0;
/* ***** BEGIN CODE ***** */
return setup_res;
}
/* If this is a form_block then it's a location expression. If it's
DW_FORM_data4 or DW_FORM_data8 it's a loclist offset */
form == DW_FORM_sec_offset))
{
/* A reference to .debug_loc, with an offset in .debug_loc of a
loclist */
error);
return off_res;
}
/* With dwarf_loclist, just read a single entry */
&lowpc,
&highpc,
error);
return (blkres);
}
} else {
return (blkres);
}
/* We copied tblock contents to the stack var, so can dealloc
tblock now. Avoids leaks. */
lowpc = 0; /* HACK */
}
/* An empty location description (block length 0) means the code
generator emitted no variable, the variable was not generated,
it was unused or perhaps never tested after being set. Dwarf2,
section 2.4.1 In other words, it is not an error, and we don't
test for block length 0 specially here.
See *dwarf_loclist_n() which handles the general case, this case
handles only a single location expression. */
/* low level error already set: let it be passed back */
return (DW_DLV_ERROR);
}
*listlen = 1;
return (DW_DLV_OK);
}
/*
Handles only a location expression.
It returns the location expression as a loclist with
a single entry.
Usable to access dwarf expressions from any source, but
specifically from
DW_CFA_def_cfa_expression
DW_CFA_expression
DW_CFA_val_expression
expression_in must point to a valid dwarf expression
set of bytes of length expression_length. Not
a DW_FORM_block*, just the expression bytes.
If the address_size != de_pointer_size this will not work
right. FIXME.
*/
int
Dwarf_Locdesc ** llbuf,
{
int res = 0;
return res;
}
/* New April 27 2009. Adding addr_size argument for the rare
* cases where an object has CUs with a different address_size. */
int
Dwarf_Locdesc ** llbuf,
{
/* Dwarf_Block that describes a single location expression. */
/* A pointer to the current Dwarf_Locdesc read. */
/* An empty location description (block length 0) means the code
generator emitted no variable, the variable was not generated,
it was unused or perhaps never tested after being set. Dwarf2,
section 2.4.1 In other words, it is not an error, and we don't
test for block length 0 specially here. */
/* low level error already set: let it be passed back */
return (DW_DLV_ERROR);
}
*listlen = 1;
return (DW_DLV_OK);
}
/* Usable to read a single loclist or to read a block of them
or to read an entire section's loclists.
It's broken because it's not safe to read a loclist entry
when we do not know the address size (in any object where
address size can vary by compilation unit).
*/
/*ARGSUSED*/ int
Dwarf_Error * error)
{
Dwarf_Block b;
return secload;
}
}
/* FIXME: address_size is not necessarily the same in every frame. */
return res;
}
*hipc_offset = highpc;
*lopc_offset = lowpc;
return DW_DLV_OK;
}