@@ -153,10 +153,16 @@ Function *Block::CalculateSymbolContextFunction() {
153
153
154
154
Block *Block::CalculateSymbolContextBlock () { return this ; }
155
155
156
- void Block::DumpSymbolContext (Stream *s) {
156
+ Function &Block::GetFunction () {
157
+ // Blocks always have an enclosing function because their parent is either a
158
+ // function or a block (which has a parent, inductively).
157
159
Function *function = CalculateSymbolContextFunction ();
158
- if (function)
159
- function->DumpSymbolContext (s);
160
+ assert (function);
161
+ return *function;
162
+ }
163
+
164
+ void Block::DumpSymbolContext (Stream *s) {
165
+ GetFunction ().DumpSymbolContext (s);
160
166
s->Printf (" , Block{0x%8.8" PRIx64 " }" , GetID ());
161
167
}
162
168
@@ -241,20 +247,17 @@ bool Block::GetRangeContainingOffset(const addr_t offset, Range &range) {
241
247
242
248
bool Block::GetRangeContainingAddress (const Address &addr,
243
249
AddressRange &range) {
244
- Function *function = CalculateSymbolContextFunction ();
245
- if (function) {
246
- if (uint32_t idx = GetRangeIndexContainingAddress (addr);
247
- idx != UINT32_MAX) {
248
- const Range *range_ptr = m_ranges.GetEntryAtIndex (idx);
249
- assert (range_ptr);
250
-
251
- Address func_addr = function->GetAddress ();
252
- range.GetBaseAddress () =
253
- Address (func_addr.GetFileAddress () + range_ptr->GetRangeBase (),
254
- func_addr.GetModule ()->GetSectionList ());
255
- range.SetByteSize (range_ptr->GetByteSize ());
256
- return true ;
257
- }
250
+ Function &function = GetFunction ();
251
+ if (uint32_t idx = GetRangeIndexContainingAddress (addr); idx != UINT32_MAX) {
252
+ const Range *range_ptr = m_ranges.GetEntryAtIndex (idx);
253
+ assert (range_ptr);
254
+
255
+ Address func_addr = function.GetAddress ();
256
+ range.GetBaseAddress () =
257
+ Address (func_addr.GetFileAddress () + range_ptr->GetRangeBase (),
258
+ func_addr.GetModule ()->GetSectionList ());
259
+ range.SetByteSize (range_ptr->GetByteSize ());
260
+ return true ;
258
261
}
259
262
range.Clear ();
260
263
return false ;
@@ -269,11 +272,9 @@ bool Block::GetRangeContainingLoadAddress(lldb::addr_t load_addr,
269
272
}
270
273
271
274
uint32_t Block::GetRangeIndexContainingAddress (const Address &addr) {
272
- Function *function = CalculateSymbolContextFunction ();
273
- if (!function)
274
- return UINT32_MAX;
275
+ Function &function = GetFunction ();
275
276
276
- const Address &func_addr = function-> GetAddress ();
277
+ const Address &func_addr = function. GetAddress ();
277
278
if (addr.GetModule () != func_addr.GetModule ())
278
279
return UINT32_MAX;
279
280
@@ -283,29 +284,25 @@ uint32_t Block::GetRangeIndexContainingAddress(const Address &addr) {
283
284
}
284
285
285
286
bool Block::GetRangeAtIndex (uint32_t range_idx, AddressRange &range) {
286
- if (range_idx < m_ranges.GetSize ()) {
287
- Function *function = CalculateSymbolContextFunction ();
288
- if (function) {
289
- const Range &vm_range = m_ranges.GetEntryRef (range_idx);
290
- range.GetBaseAddress () = function->GetAddress ();
291
- range.GetBaseAddress ().Slide (vm_range.GetRangeBase ());
292
- range.SetByteSize (vm_range.GetByteSize ());
293
- return true ;
294
- }
295
- }
296
- return false ;
287
+ if (range_idx >= m_ranges.GetSize ())
288
+ return false ;
289
+
290
+ Function &function = GetFunction ();
291
+ const Range &vm_range = m_ranges.GetEntryRef (range_idx);
292
+ range.GetBaseAddress () = function.GetAddress ();
293
+ range.GetBaseAddress ().Slide (vm_range.GetRangeBase ());
294
+ range.SetByteSize (vm_range.GetByteSize ());
295
+ return true ;
297
296
}
298
297
299
298
AddressRanges Block::GetRanges () {
300
299
AddressRanges ranges;
301
- Function *function = CalculateSymbolContextFunction ();
302
- if (!function)
303
- return ranges;
300
+ Function &function = GetFunction ();
304
301
for (size_t i = 0 , e = m_ranges.GetSize (); i < e; ++i) {
305
302
ranges.emplace_back ();
306
303
auto &range = ranges.back ();
307
304
const Range &vm_range = m_ranges.GetEntryRef (i);
308
- range.GetBaseAddress () = function-> GetAddress ();
305
+ range.GetBaseAddress () = function. GetAddress ();
309
306
range.GetBaseAddress ().Slide (vm_range.GetRangeBase ());
310
307
range.SetByteSize (vm_range.GetByteSize ());
311
308
}
@@ -316,13 +313,10 @@ bool Block::GetStartAddress(Address &addr) {
316
313
if (m_ranges.IsEmpty ())
317
314
return false ;
318
315
319
- Function *function = CalculateSymbolContextFunction ();
320
- if (function) {
321
- addr = function->GetAddress ();
322
- addr.Slide (m_ranges.GetEntryRef (0 ).GetRangeBase ());
323
- return true ;
324
- }
325
- return false ;
316
+ Function &function = GetFunction ();
317
+ addr = function.GetAddress ();
318
+ addr.Slide (m_ranges.GetEntryRef (0 ).GetRangeBase ());
319
+ return true ;
326
320
}
327
321
328
322
void Block::FinalizeRanges () {
@@ -336,11 +330,11 @@ void Block::AddRange(const Range &range) {
336
330
Log *log = GetLog (LLDBLog::Symbols);
337
331
if (log) {
338
332
ModuleSP module_sp (m_parent_scope.CalculateSymbolContextModule ());
339
- Function * function = m_parent_scope. CalculateSymbolContextFunction ();
340
- const addr_t function_file_addr = function-> GetAddress ().GetFileAddress ();
333
+ Function & function = GetFunction ();
334
+ const addr_t function_file_addr = function. GetAddress ().GetFileAddress ();
341
335
const addr_t block_start_addr = function_file_addr + range.GetRangeBase ();
342
336
const addr_t block_end_addr = function_file_addr + range.GetRangeEnd ();
343
- Type *func_type = function-> GetType ();
337
+ Type *func_type = function. GetType ();
344
338
345
339
const Declaration &func_decl = func_type->GetDeclaration ();
346
340
if (func_decl.GetLine ()) {
@@ -351,7 +345,7 @@ void Block::AddRange(const Range &range) {
351
345
" } in function {0x%8.8" PRIx64 " } from %s" ,
352
346
func_decl.GetFile ().GetPath ().c_str (), func_decl.GetLine (),
353
347
GetID (), (uint32_t )m_ranges.GetSize (), block_start_addr,
354
- block_end_addr, parent_block->GetID (), function-> GetID (),
348
+ block_end_addr, parent_block->GetID (), function. GetID (),
355
349
module_sp->GetFileSpec ().GetPath ().c_str ());
356
350
} else {
357
351
LLDB_LOGF (log,
@@ -360,7 +354,7 @@ void Block::AddRange(const Range &range) {
360
354
" ) which is not contained in parent block {0x%8.8" PRIx64
361
355
" } in function {0x%8.8" PRIx64 " } from %s" ,
362
356
GetID (), (uint32_t )m_ranges.GetSize (), block_start_addr,
363
- block_end_addr, parent_block->GetID (), function-> GetID (),
357
+ block_end_addr, parent_block->GetID (), function. GetID (),
364
358
module_sp->GetFileSpec ().GetPath ().c_str ());
365
359
}
366
360
}
0 commit comments