Skip to content

Commit 716db1e

Browse files
committed
New internal function _dwarf_has_SECT_fission
to unify access .debug_cu/tu_* sections for .debug_rnglilsts and .debug_loclists. modified: src/lib/libdwarf/dwarf_fission_to_cu.c Added prototype for the function. modified: src/lib/libdwarf/dwarf_opaque.h Corrected an error report string to ensure it is not identical to another report here. modified: src/lib/libdwarf/dwarf_form.c Significan correction for DWARF5 loclists modified: src/lib/libdwarf/dwarf_loc.c modified: src/lib/libdwarf/dwarf_loclists.c Slight modification of library internal function prototype. modified: src/lib/libdwarf/dwarf_loc.h Significan correction for DWARF5 rnglists Now rnglists and loclists handling is as similar as possible (or close to it). modified: src/lib/libdwarf/dwarf_rnglists.c
1 parent b27b8cb commit 716db1e

File tree

7 files changed

+367
-473
lines changed

7 files changed

+367
-473
lines changed

src/lib/libdwarf/dwarf_fission_to_cu.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,29 @@
4949
#include "dwarf_loclists.h"
5050
#include "dwarf_rnglists.h"
5151

52+
/* RETURNS DW_DLV_OK and sets values
53+
through the return-value pointers.
54+
Or returns DW_DLV_NO_ENTRY */
55+
int
56+
_dwarf_has_SECT_fission(Dwarf_CU_Context ctx,
57+
unsigned int SECT_number,
58+
Dwarf_Bool *hasfissionoffset,
59+
Dwarf_Unsigned *loclistsbase)
60+
{
61+
struct Dwarf_Debug_Fission_Per_CU_s *fis = 0;
62+
Dwarf_Unsigned fisindex = SECT_number;
63+
64+
fis = &ctx->cc_dwp_offsets;
65+
if (fis->pcu_type && fis->pcu_size[fisindex]) {
66+
*loclistsbase = fis->pcu_offset[fisindex];
67+
*hasfissionoffset = TRUE;
68+
return DW_DLV_OK;
69+
}
70+
return DW_DLV_NO_ENTRY;
71+
}
72+
73+
74+
5275
/* ASSERT: dbg,cu_context, and fsd are non-NULL
5376
as the caller ensured that.
5477
With no DW_AT_loclists_base this computes one. */

src/lib/libdwarf/dwarf_form.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ _dwarf_internal_global_formref_b(Dwarf_Attribute attr,
990990

991991
dwarfstring_constructor(&m);
992992
dwarfstring_append_printf_u(&m,
993-
"DW_DLE_BAD_REF_FORM: The form code is 0x%x ",
993+
"DW_DLE_BAD_REF_FORM: The form code is 0x%x.. ",
994994
formcode);
995995
fcres = dwarf_get_FORM_name (formcode,&name);
996996
if (fcres != DW_DLV_OK) {

src/lib/libdwarf/dwarf_loc.c

Lines changed: 92 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
#include "dwarf_loc.h"
4949
#include "dwarf_string.h"
5050

51+
#define DEBUG_LOCLIST 1
52+
#undef DEBUG_LOCLIST
53+
5154
static int _dwarf_read_loc_section_dwo(Dwarf_Debug dbg,
5255
Dwarf_Block_c * return_block,
5356
Dwarf_Addr * lowpc,
@@ -1588,17 +1591,21 @@ dwarf_get_loclist_c(Dwarf_Attribute attr,
15881591
Dwarf_Unsigned * listlen_out,
15891592
Dwarf_Error * error)
15901593
{
1591-
Dwarf_Debug dbg = 0;
1592-
Dwarf_Half form = 0;
1593-
Dwarf_Loc_Head_c llhead = 0;
1594-
Dwarf_CU_Context cucontext = 0;
1595-
unsigned address_size = 0;
1596-
Dwarf_Half cuversionstamp = 0;
1597-
Dwarf_Bool is_cu = FALSE;
1598-
Dwarf_Unsigned attrnum = 0;
1599-
Dwarf_Bool is_dwo = 0;
1600-
int setup_res = DW_DLV_ERROR;
1601-
int lkind = 0;
1594+
Dwarf_Debug dbg = 0;
1595+
Dwarf_Half form = 0;
1596+
Dwarf_Loc_Head_c llhead = 0;
1597+
unsigned address_size = 0;
1598+
Dwarf_Half cuversionstamp = 0;
1599+
Dwarf_Bool is_cu = FALSE;
1600+
Dwarf_Unsigned attrnum = 0;
1601+
Dwarf_Bool is_dwo = 0;
1602+
int lkind = 0;
1603+
Dwarf_CU_Context ctx = 0;
1604+
Dwarf_Bool is_loclistx = FALSE;
1605+
Dwarf_Unsigned attr_val = 0;
1606+
Dwarf_Bool offset_is_info = TRUE;
1607+
int res = 0;
1608+
int setup_res = 0;
16021609

16031610
if (!attr) {
16041611
_dwarf_error_string(dbg, error,DW_DLE_ATTR_NULL,
@@ -1608,18 +1615,73 @@ dwarf_get_loclist_c(Dwarf_Attribute attr,
16081615
"dwarf_get_loclist_c()");
16091616
return DW_DLV_ERROR;
16101617
}
1611-
dbg = attr->ar_dbg;
1612-
CHECK_DBG(dbg,error,"dwarf_get_loclist_c()");
1613-
1614-
/* ***** BEGIN CODE ***** */
1615-
setup_res = _dwarf_setup_loc(attr, &dbg,&cucontext, &form, error);
1618+
setup_res = _dwarf_setup_loc(attr, &dbg,&ctx, &form, error);
16161619
if (setup_res != DW_DLV_OK) {
16171620
return setup_res;
16181621
}
1622+
1623+
CHECK_DBG(dbg,error,"dwarf_get_loclist_c()");
1624+
if (form == DW_FORM_loclistx) {
1625+
is_loclistx = TRUE;
1626+
}
16191627
attrnum = attr->ar_attribute;
1620-
cuversionstamp = cucontext->cc_version_stamp;
1621-
address_size = cucontext->cc_address_size;
1622-
is_dwo = cucontext->cc_is_dwo;
1628+
cuversionstamp = ctx->cc_version_stamp;
1629+
address_size = ctx->cc_address_size;
1630+
is_dwo = ctx->cc_is_dwo;
1631+
lkind = determine_location_lkind(cuversionstamp,
1632+
form, is_dwo);
1633+
1634+
if (form == DW_FORM_loclistx || form == DW_FORM_sec_offset) {
1635+
/* Aimed at DWARF5 and later */
1636+
res = dwarf_global_formref_b(attr,&attr_val,
1637+
&offset_is_info,error);
1638+
if (res != DW_DLV_OK) {
1639+
return res;
1640+
}
1641+
}
1642+
if (lkind == DW_LKIND_loclists) {
1643+
if (is_loclistx) {
1644+
if (ctx->cc_loclists_base_present ||
1645+
dbg->de_loclists_context_count == 1) {
1646+
/* leave on primary.
1647+
WARNING: It is not clear whether
1648+
looking for a context count of 1
1649+
is actually correct, but it
1650+
seems to work. */
1651+
} else if (DBG_HAS_SECONDARY(dbg)){
1652+
dbg = dbg->de_secondary_dbg;
1653+
CHECK_DBG(dbg,error,
1654+
"dwarf_loclists_get_lle_head() via attribute(sec)");
1655+
}
1656+
} else {
1657+
/* attr_val is .debug_loclists[.dwo]
1658+
section global offset
1659+
of a location list*/
1660+
if (!dbg->de_debug_loclists.dss_size ||
1661+
attr_val >= dbg->de_debug_loclists.dss_size) {
1662+
if (DBG_HAS_SECONDARY(dbg)) {
1663+
dbg = dbg->de_secondary_dbg;
1664+
CHECK_DBG(dbg,error,
1665+
"dwarf_loclists_get_lle_head() "
1666+
"via attribute(secb)");
1667+
} else {
1668+
/* There is an error to be
1669+
generated later */
1670+
}
1671+
}
1672+
}
1673+
res = _dwarf_load_section(dbg,
1674+
&dbg->de_debug_loclists,
1675+
error);
1676+
if (res == DW_DLV_ERROR) {
1677+
return res;
1678+
}
1679+
}
1680+
1681+
attrnum = attr->ar_attribute;
1682+
cuversionstamp = ctx->cc_version_stamp;
1683+
address_size = ctx->cc_address_size;
1684+
is_dwo = ctx->cc_is_dwo;
16231685
lkind = determine_location_lkind(cuversionstamp,
16241686
form, is_dwo);
16251687
if (lkind == DW_LKIND_unknown) {
@@ -1664,29 +1726,29 @@ dwarf_get_loclist_c(Dwarf_Attribute attr,
16641726
llhead->ll_attrform = (Dwarf_Half)form;
16651727
llhead->ll_dbg = dbg;
16661728
llhead->ll_address_size = address_size;
1667-
llhead->ll_offset_size = cucontext->cc_length_size;
1668-
llhead->ll_context = cucontext;
1729+
llhead->ll_offset_size = ctx->cc_length_size;
1730+
llhead->ll_context = ctx;
16691731
llhead->ll_magic = LOCLISTS_MAGIC;
16701732

16711733
llhead->ll_at_loclists_base_present =
1672-
cucontext->cc_loclists_base_present;
1673-
llhead->ll_at_loclists_base = cucontext->cc_loclists_base;
1734+
ctx->cc_loclists_base_present;
1735+
llhead->ll_at_loclists_base = ctx->cc_loclists_base;
16741736
llhead->ll_cu_base_address_present =
1675-
cucontext->cc_base_address_present;
1676-
llhead->ll_cu_base_address = cucontext->cc_base_address;
1737+
ctx->cc_base_address_present;
1738+
llhead->ll_cu_base_address = ctx->cc_base_address;
16771739

1678-
llhead->ll_cu_addr_base_offset = cucontext->cc_addr_base_offset;
1740+
llhead->ll_cu_addr_base_offset = ctx->cc_addr_base_offset;
16791741
llhead->ll_cu_addr_base_offset_present =
1680-
cucontext->cc_addr_base_offset_present;
1742+
ctx->cc_addr_base_offset_present;
16811743

16821744
if (lkind == DW_LKIND_loclist ||
16831745
lkind == DW_LKIND_GNU_exp_list) {
16841746
int ores = 0;
16851747
/* Here we have a loclist to deal with. */
1686-
ores = context_is_cu_not_tu(cucontext,&is_cu);
1748+
ores = context_is_cu_not_tu(ctx,&is_cu);
16871749
if (ores != DW_DLV_OK) {
16881750
dwarf_dealloc_loc_head_c(llhead);
1689-
return setup_res;
1751+
return ores;
16901752
}
16911753
ores = _dwarf_original_loclist_build(dbg,
16921754
llhead, attr, error);
@@ -1718,7 +1780,7 @@ dwarf_get_loclist_c(Dwarf_Attribute attr,
17181780
int leres = 0;
17191781

17201782
leres = _dwarf_loclists_fill_in_lle_head(dbg,
1721-
attr,llhead,error);
1783+
attr,form,attr_val,llhead,error);
17221784
if (leres != DW_DLV_OK) {
17231785
dwarf_dealloc_loc_head_c(llhead);
17241786
return leres;

src/lib/libdwarf/dwarf_loc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ void _dwarf_loclists_head_destructor(void *l);
253253

254254
int _dwarf_loclists_fill_in_lle_head(Dwarf_Debug dbg,
255255
Dwarf_Attribute attr,
256+
Dwarf_Half theform,
257+
Dwarf_Unsigned attr_val,
256258
Dwarf_Loc_Head_c llhead,
257259
Dwarf_Error *error);
258260

0 commit comments

Comments
 (0)