Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vxworks support #14

Merged
merged 11 commits into from
Mar 11, 2021
353 changes: 20 additions & 333 deletions src/Juicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2938,8 +2938,26 @@ void Juicer::process_DW_TAG_structure_type(ElfFile& elf, Symbol& symbol, Dwarf_D
}
else
{
if(bdata
memberLocation = (uint32_t) bdata->bl_len;
if(bdata->bl_from_loclist == 0)
{
uint8_t *data = (uint8_t*)bdata->bl_data;
if(DW_OP_plus_uconst == data[0])
{
int i = 0;
int shift = 0;
uint8_t *leb128 = &data[1];
memberLocation = 0;

for (i = 1; i < bdata->bl_len; ++i)
{
memberLocation |= (*leb128++ & ((1 << 7) - 1)) << shift; shift += 7;
mbenson1 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
else
{
logger.logError("Cannot parse %s. loclist %d not supported. line=%u", memberName, __LINE__, bdata->bl_from_loclist);
}

}

Expand Down Expand Up @@ -3685,334 +3703,3 @@ void Juicer::setIDC(IDataContainer *inIdc)
idc = inIdc;
}





















int __libdw_intern_expression(
Dwarf *dbg,
bool other_byte_order,
unsigned int address_size,
unsigned int ref_size,
void **cache,
const Dwarf_Block *block,
bool cfap,
bool valuep,
Dwarf_Op **llbuf,
size_t *listlen,
int sec_index)
{
/* Empty location expressions don't have any ops to intern. */
if (block->bl_len == 0)
{
*listlen = 0;
return 0;
}

const unsigned char *data = block->bl_data;
const unsigned char *const end_data = data + block->bl_len;
const struct { bool other_byte_order; } bo = { other_byte_order };
struct loclist *loclist = NULL;
unsigned int n = 0;
if (cfap)
{
/* Synthesize the operation to push the CFA before the expression. */
struct loclist *newloc;
newloc = (struct loclist *) alloca (sizeof (struct loclist));
newloc->atom = DW_OP_call_frame_cfa;
newloc->number = 0;
newloc->number2 = 0;
newloc->offset = -1;
newloc->next = loclist;
loclist = newloc;
++n;
}
/* Decode the opcodes. It is possible in some situations to have a
block of size zero. */
while (data < end_data)
{
struct loclist *newloc;
newloc = (struct loclist *) alloca (sizeof (struct loclist));
newloc->number = 0;
newloc->number2 = 0;
newloc->offset = data - block->data;
newloc->next = loclist;
loclist = newloc;
++n;
switch ((newloc->atom = *data++))
{
case DW_OP_addr:
/* Address, depends on address size of CU. */
if (__libdw_read_address_inc (dbg, sec_index, &data,
address_size, &newloc->number))
return -1;
break;
case DW_OP_call_ref:
/* DW_FORM_ref_addr, depends on offset size of CU. */
if (__libdw_read_offset_inc (dbg, sec_index, &data, ref_size,
&newloc->number, IDX_debug_info, 0))
return -1;
break;
case DW_OP_deref:
case DW_OP_dup:
case DW_OP_drop:
case DW_OP_over:
case DW_OP_swap:
case DW_OP_rot:
case DW_OP_xderef:
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:
case DW_OP_shl:
case DW_OP_shr:
case DW_OP_shra:
case DW_OP_xor:
case DW_OP_eq:
case DW_OP_ge:
case DW_OP_gt:
case DW_OP_le:
case DW_OP_lt:
case DW_OP_ne:
case DW_OP_lit0 ... DW_OP_lit31:
case DW_OP_reg0 ... DW_OP_reg31:
case DW_OP_nop:
case DW_OP_push_object_address:
case DW_OP_call_frame_cfa:
case DW_OP_form_tls_address:
case DW_OP_GNU_push_tls_address:
case DW_OP_stack_value:
/* No operand. */
break;
case DW_OP_const1u:
case DW_OP_pick:
case DW_OP_deref_size:
case DW_OP_xderef_size:
if (unlikely (data >= end_data))
{
invalid:
__libdw_seterrno (DWARF_E_INVALID_DWARF);
return -1;
}
newloc->number = *data++;
break;
case DW_OP_const1s:
if (unlikely (data >= end_data))
goto invalid;
newloc->number = *((int8_t *) data);
++data;
break;
case DW_OP_const2u:
if (unlikely (data + 2 > end_data))
goto invalid;
newloc->number = read_2ubyte_unaligned_inc (&bo, data);
break;
case DW_OP_const2s:
case DW_OP_skip:
case DW_OP_bra:
case DW_OP_call2:
if (unlikely (data + 2 > end_data))
goto invalid;
newloc->number = read_2sbyte_unaligned_inc (&bo, data);
break;
case DW_OP_const4u:
if (unlikely (data + 4 > end_data))
goto invalid;
newloc->number = read_4ubyte_unaligned_inc (&bo, data);
break;
case DW_OP_const4s:
case DW_OP_call4:
case DW_OP_GNU_parameter_ref:
if (unlikely (data + 4 > end_data))
goto invalid;
newloc->number = read_4sbyte_unaligned_inc (&bo, data);
break;
case DW_OP_const8u:
if (unlikely (data + 8 > end_data))
goto invalid;
newloc->number = read_8ubyte_unaligned_inc (&bo, data);
break;
case DW_OP_const8s:
if (unlikely (data + 8 > end_data))
goto invalid;
newloc->number = read_8sbyte_unaligned_inc (&bo, data);
break;
case DW_OP_constu:
case DW_OP_plus_uconst:
case DW_OP_regx:
case DW_OP_piece:
case DW_OP_GNU_convert:
case DW_OP_GNU_reinterpret:
/* XXX Check size. */
get_uleb128 (newloc->number, data);
break;
case DW_OP_consts:
case DW_OP_breg0 ... DW_OP_breg31:
case DW_OP_fbreg:
/* XXX Check size. */
get_sleb128 (newloc->number, data);
break;
case DW_OP_bregx:
/* XXX Check size. */
get_uleb128 (newloc->number, data);
get_sleb128 (newloc->number2, data);
break;
case DW_OP_bit_piece:
case DW_OP_GNU_regval_type:
/* XXX Check size. */
get_uleb128 (newloc->number, data);
get_uleb128 (newloc->number2, data);
break;
case DW_OP_implicit_value:
case DW_OP_GNU_entry_value:
/* This cannot be used in a CFI expression. */
if (unlikely (dbg == NULL))
goto invalid;
/* start of block inc. len. */
newloc->number2 = (Dwarf_Word) (uintptr_t) data;
/* XXX Check size. */
get_uleb128 (newloc->number, data); /* Block length. */
if (unlikely ((Dwarf_Word) (end_data - data) < newloc->number))
goto invalid;
data += newloc->number; /* Skip the block. */
break;
case DW_OP_GNU_implicit_pointer:
/* DW_FORM_ref_addr, depends on offset size of CU. */
if (__libdw_read_offset_inc (dbg, sec_index, &data, ref_size,
&newloc->number, IDX_debug_info, 0))
return -1;
/* XXX Check size. */
get_uleb128 (newloc->number2, data); /* Byte offset. */
break;
case DW_OP_GNU_deref_type:
if (unlikely (data >= end_data))
goto invalid;
newloc->number = *data++;
get_uleb128 (newloc->number2, data);
break;
case DW_OP_GNU_const_type:
{
size_t size;
/* XXX Check size. */
get_uleb128 (newloc->number, data);
if (unlikely (data >= end_data))
goto invalid;
/* start of block inc. len. */
newloc->number2 = (Dwarf_Word) (uintptr_t) data;
size = *data++;
if (unlikely ((Dwarf_Word) (end_data - data) < size))
goto invalid;
data += size; /* Skip the block. */
}
break;
default:
goto invalid;
}
}
if (unlikely (n == 0))
{
/* This is not allowed.
It would mean an empty location expression, which we handled
already as a special case above. */
goto invalid;
}
if (valuep)
{
struct loclist *newloc;
newloc = (struct loclist *) alloca (sizeof (struct loclist));
newloc->atom = DW_OP_stack_value;
newloc->number = 0;
newloc->number2 = 0;
newloc->offset = data - block->data;
newloc->next = loclist;
loclist = newloc;
++n;
}
/* Allocate the array. */
Dwarf_Op *result;
if (dbg != NULL)
result = libdw_alloc (dbg, Dwarf_Op, sizeof (Dwarf_Op), n);
else
{
result = malloc (sizeof *result * n);
if (result == NULL)
{
nomem:
__libdw_seterrno (DWARF_E_NOMEM);
return -1;
}
}
/* Store the result. */
*llbuf = result;
*listlen = n;
do
{
/* We populate the array from the back since the list is backwards. */
--n;
result[n].atom = loclist->atom;
result[n].number = loclist->number;
result[n].number2 = loclist->number2;
result[n].offset = loclist->offset;
if (result[n].atom == DW_OP_implicit_value)
store_implicit_value (dbg, cache, &result[n]);
loclist = loclist->next;
}
while (n > 0);
/* Insert a record in the search tree so that we can find it again later. */
struct loc_s *newp;
if (dbg != NULL)
newp = libdw_alloc (dbg, struct loc_s, sizeof (struct loc_s), 1);
else
{
newp = malloc (sizeof *newp);
if (newp == NULL)
{
free (result);
goto nomem;
}
}
newp->addr = block->data;
newp->loc = result;
newp->nloc = *listlen;
(void) tsearch (newp, cache, loc_compare);
/* We did it. */
return 0;
}

static int getlocation (struct Dwarf_CU *cu, const Dwarf_Block *block, Dwarf_Op **llbuf, size_t *listlen, int sec_index)
{
return __libdw_intern_expression (
cu->dbg,
cu->dbg->other_byte_order,
cu->address_size,
(cu->version == 2 ? cu->address_size : cu->offset_size),
&cu->locs,
block,
false,
false,
llbuf,
listlen,
sec_index);
}
11 changes: 2 additions & 9 deletions src/SQLiteDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,20 +530,14 @@ int SQLiteDB::writeFieldsToDatabase(ElfFile& inElf)

if(SQLITE_OK == rc)
{
logger.logDebug("Field values were written to the fields schema with "
"SQLITE_OK status.");

/*Write the id to this field so that other tables can use it as
*a foreign key */
sqlite3_int64 lastRowId = sqlite3_last_insert_rowid(database);
field->setId(lastRowId);


}
else
{
logger.logDebug("There was an error while data to the fields table.");
logger.logDebug("%s.", errorMessage);
logger.logError("There was an error while writing data to the fields table. %s.", errorMessage);

if(sqlite3_extended_errcode(database) == SQLITE_CONSTRAINT_UNIQUE)
{
Expand Down Expand Up @@ -608,8 +602,7 @@ int SQLiteDB::writeEnumerationsToDatabase(ElfFile& inElf)
}
else
{
logger.logDebug("There was an error while data to the enumerations table.");
logger.logDebug("%s.", errorMessage);
logger.logDebug("There was an error while writing data to the enumerations table. %s.", errorMessage);

if(sqlite3_extended_errcode(database) == SQLITE_CONSTRAINT_UNIQUE)
{
Expand Down