Skip to content

Commit 6f2ebc4

Browse files
[lldb] Change SymbolContext::GetAddressRangeFromHereToEndLine to return Expected (NFC) (#110718)
Signed-off-by: AbdAlRahman Gad <[email protected]> Co-authored-by: Adrian Prantl <[email protected]>
1 parent cc5ddae commit 6f2ebc4

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

lldb/include/lldb/Symbol/SymbolContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ class SymbolContext {
201201
bool GetAddressRange(uint32_t scope, uint32_t range_idx,
202202
bool use_inline_block_range, AddressRange &range) const;
203203

204-
bool GetAddressRangeFromHereToEndLine(uint32_t end_line, AddressRange &range,
205-
Status &error);
204+
llvm::Error GetAddressRangeFromHereToEndLine(uint32_t end_line,
205+
AddressRange &range);
206206

207207
/// Find the best global data symbol visible from this context.
208208
///

lldb/source/API/SBThread.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,11 @@ void SBThread::StepInto(const char *target_name, uint32_t end_line,
605605
if (end_line == LLDB_INVALID_LINE_NUMBER)
606606
range = sc.line_entry.range;
607607
else {
608-
if (!sc.GetAddressRangeFromHereToEndLine(end_line, range, error.ref()))
608+
llvm::Error err = sc.GetAddressRangeFromHereToEndLine(end_line, range);
609+
if (err) {
610+
error = Status::FromErrorString(llvm::toString(std::move(err)).c_str());
609611
return;
612+
}
610613
}
611614

612615
const LazyBool step_out_avoids_code_without_debug_info =

lldb/source/Commands/CommandObjectThread.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,11 @@ class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
489489
AddressRange range;
490490
SymbolContext sc = frame->GetSymbolContext(eSymbolContextEverything);
491491
if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER) {
492-
Status error;
493-
if (!sc.GetAddressRangeFromHereToEndLine(m_options.m_end_line, range,
494-
error)) {
495-
result.AppendErrorWithFormat("invalid end-line option: %s.",
496-
error.AsCString());
492+
llvm::Error err =
493+
sc.GetAddressRangeFromHereToEndLine(m_options.m_end_line, range);
494+
if (err) {
495+
result.AppendErrorWithFormatv("invalid end-line option: {0}.",
496+
llvm::toString(std::move(err)));
497497
return;
498498
}
499499
} else if (m_options.m_end_line_is_block_end) {

lldb/source/Symbol/SymbolContext.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -706,20 +706,18 @@ LineEntry SymbolContext::GetFunctionStartLineEntry() const {
706706
return LineEntry();
707707
}
708708

709-
bool SymbolContext::GetAddressRangeFromHereToEndLine(uint32_t end_line,
710-
AddressRange &range,
711-
Status &error) {
709+
llvm::Error
710+
SymbolContext::GetAddressRangeFromHereToEndLine(uint32_t end_line,
711+
AddressRange &range) {
712712
if (!line_entry.IsValid()) {
713-
error = Status::FromErrorString("Symbol context has no line table.");
714-
return false;
713+
return llvm::createStringError("Symbol context has no line table.");
715714
}
716715

717716
range = line_entry.range;
718717
if (line_entry.line > end_line) {
719-
error = Status::FromErrorStringWithFormat(
718+
return llvm::createStringError(
720719
"end line option %d must be after the current line: %d", end_line,
721720
line_entry.line);
722-
return false;
723721
}
724722

725723
uint32_t line_index = 0;
@@ -740,35 +738,32 @@ bool SymbolContext::GetAddressRangeFromHereToEndLine(uint32_t end_line,
740738
if (!found) {
741739
// Can't find the index of the SymbolContext's line entry in the
742740
// SymbolContext's CompUnit.
743-
error = Status::FromErrorString(
741+
return llvm::createStringError(
744742
"Can't find the current line entry in the CompUnit - can't process "
745743
"the end-line option");
746-
return false;
747744
}
748745

749746
line_index = comp_unit->FindLineEntry(line_index, end_line, nullptr, false,
750747
&end_entry);
751748
if (line_index == UINT32_MAX) {
752-
error = Status::FromErrorStringWithFormat(
749+
return llvm::createStringError(
753750
"could not find a line table entry corresponding "
754751
"to end line number %d",
755752
end_line);
756-
return false;
757753
}
758754

759755
Block *func_block = GetFunctionBlock();
760756
if (func_block && func_block->GetRangeIndexContainingAddress(
761757
end_entry.range.GetBaseAddress()) == UINT32_MAX) {
762-
error = Status::FromErrorStringWithFormat(
758+
return llvm::createStringError(
763759
"end line number %d is not contained within the current function.",
764760
end_line);
765-
return false;
766761
}
767762

768763
lldb::addr_t range_size = end_entry.range.GetBaseAddress().GetFileAddress() -
769764
range.GetBaseAddress().GetFileAddress();
770765
range.SetByteSize(range_size);
771-
return true;
766+
return llvm::Error::success();
772767
}
773768

774769
const Symbol *SymbolContext::FindBestGlobalDataSymbol(ConstString name,

0 commit comments

Comments
 (0)