4848#include "dwarf_loc.h"
4949#include "dwarf_string.h"
5050
51+ #define DEBUG_LOCLIST 1
52+ #undef DEBUG_LOCLIST
53+
5154static 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 ;
0 commit comments