================ @@ -370,6 +370,31 @@ bool SymbolContext::GetAddressRange(uint32_t scope, uint32_t range_idx, return false; } +Address SymbolContext::GetAddress(uint32_t scope, + bool use_inline_block_range) const { + if ((scope & eSymbolContextLineEntry) && line_entry.IsValid()) + return line_entry.range.GetBaseAddress(); + + if (scope & eSymbolContextBlock) { + Block *block_to_use = (block && use_inline_block_range) + ? block->GetContainingInlinedBlock() + : block; + if (block_to_use) { + Address addr; + block_to_use->GetStartAddress(addr); + return addr; + } + } ---------------- jimingham wrote:
I needed to think about this a little more. For functions, there's an actually useful notion of "Start" - functions get entered from one address, and the question "where would I put a breakpoint to capture the first instruction of this function's execution" is one we want the answer to. Even if you have alternate entry points, those usually are named separately, and I think you'd be surprised if you asked to stop on the function name and got one of the alternate entry points instead. So calling it GetStartAddress was reasonable, and when asking for the "address" of a SymbolContext that's just got a Function, the entry point address is pretty clearly what you want to know. But there's no similar useful notion for blocks. After all, C++ goto's don't make new scopes, so you can't say "this is the first bit of code that will get executed when this block is executed." We probably should have called Block::GetStartAddress: Block::GetLowestAddress. I confused myself because I'm more often using LineEntry's and not Blocks. Those entities seem similar but the are not. Blocks actually represent logical entities and contain all the ranges for that logical entity. But LineEntry's do not represent the logical entity "the contributions to the code from this source line". They are "one out of many possible contributions from this source line." So when you ask a LineEntry for it's address, you're just getting "the lowest address of the particular range that the address you made the SymbolContext from happened to lie within". However, some kind of consistency would be useful. For instance, if I get the outermost Function Block from a Function, make a SymbolContext from that Block, and then ask for it's Address, it really should return the same answer as if I had made the SymbolContext from the Function directly. If I'm reading the code correctly, that won't necessarily be true, will it? For the Function, you promise to return the entry point, but for the Function's outermost Block, we return the start of the first address range. That does seem potentially confusing to me. https://github.com/llvm/llvm-project/pull/123340 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits