1//===-- DWARFLocationList.cpp -----------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#include "DWARFLocationList.h" 11 12#include "lldb/Core/Stream.h" 13 14#include "DWARFCompileUnit.h" 15#include "DWARFDebugInfo.h" 16#include "DWARFLocationDescription.h" 17 18using namespace lldb_private; 19 20dw_offset_t 21DWARFLocationList::Dump(Stream &s, const DWARFCompileUnit* cu, const DataExtractor& debug_loc_data, lldb::offset_t offset) 22{ 23 uint64_t start_addr, end_addr; 24 uint32_t addr_size = DWARFCompileUnit::GetAddressByteSize(cu); 25 s.SetAddressByteSize(DWARFCompileUnit::GetAddressByteSize(cu)); 26 dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0; 27 while (debug_loc_data.ValidOffset(offset)) 28 { 29 start_addr = debug_loc_data.GetMaxU64(&offset,addr_size); 30 end_addr = debug_loc_data.GetMaxU64(&offset,addr_size); 31 32 if (start_addr == 0 && end_addr == 0) 33 break; 34 35 s.PutCString("\n "); 36 s.Indent(); 37 if (cu) 38 s.AddressRange (start_addr + base_addr, 39 end_addr + base_addr, 40 cu->GetAddressByteSize(), 41 NULL, 42 ": "); 43 uint32_t loc_length = debug_loc_data.GetU16(&offset); 44 45 DataExtractor locationData(debug_loc_data, offset, loc_length); 46 // if ( dump_flags & DWARFDebugInfo::eDumpFlag_Verbose ) *ostrm_ptr << " ( "; 47 print_dwarf_expression (s, locationData, addr_size, 4, false); 48 offset += loc_length; 49 } 50 51 return offset; 52} 53 54bool 55DWARFLocationList::Extract(const DataExtractor& debug_loc_data, lldb::offset_t* offset_ptr, DataExtractor& location_list_data) 56{ 57 // Initialize with no data just in case we don't find anything 58 location_list_data.Clear(); 59 60 size_t loc_list_length = Size(debug_loc_data, *offset_ptr); 61 if (loc_list_length > 0) 62 { 63 location_list_data.SetData(debug_loc_data, *offset_ptr, loc_list_length); 64 *offset_ptr += loc_list_length; 65 return true; 66 } 67 68 return false; 69} 70 71size_t 72DWARFLocationList::Size(const DataExtractor& debug_loc_data, lldb::offset_t offset) 73{ 74 const dw_offset_t debug_loc_offset = offset; 75 76 while (debug_loc_data.ValidOffset(offset)) 77 { 78 dw_addr_t start_addr = debug_loc_data.GetAddress(&offset); 79 dw_addr_t end_addr = debug_loc_data.GetAddress(&offset); 80 81 if (start_addr == 0 && end_addr == 0) 82 break; 83 84 uint16_t loc_length = debug_loc_data.GetU16(&offset); 85 offset += loc_length; 86 } 87 88 if (offset > debug_loc_offset) 89 return offset - debug_loc_offset; 90 return 0; 91} 92 93 94 95