Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lldb] Change SymbolContext::GetAddressRangeFromHereToEndLine to return Expected (NFC) #110718

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lldb/include/lldb/Symbol/SymbolContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ class SymbolContext {
bool GetAddressRange(uint32_t scope, uint32_t range_idx,
bool use_inline_block_range, AddressRange &range) const;

bool GetAddressRangeFromHereToEndLine(uint32_t end_line, AddressRange &range,
Status &error);
llvm::Expected<bool> GetAddressRangeFromHereToEndLine(uint32_t end_line,
AbdAlRahmanGad marked this conversation as resolved.
Show resolved Hide resolved
AddressRange &range);

/// Find the best global data symbol visible from this context.
///
Expand Down
8 changes: 7 additions & 1 deletion lldb/source/API/SBThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,14 @@ void SBThread::StepInto(const char *target_name, uint32_t end_line,
if (end_line == LLDB_INVALID_LINE_NUMBER)
range = sc.line_entry.range;
else {
if (!sc.GetAddressRangeFromHereToEndLine(end_line, range, error.ref()))
auto get_address_range_from_here_to_end_line_or_err =
sc.GetAddressRangeFromHereToEndLine(end_line, range);
if (!get_address_range_from_here_to_end_line_or_err) {
error = Status::FromErrorString(
toString(get_address_range_from_here_to_end_line_or_err.takeError())
.c_str());
return;
}
}

const LazyBool step_out_avoids_code_without_debug_info =
Expand Down
13 changes: 8 additions & 5 deletions lldb/source/Commands/CommandObjectThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,14 @@ class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
AddressRange range;
SymbolContext sc = frame->GetSymbolContext(eSymbolContextEverything);
if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER) {
Status error;
if (!sc.GetAddressRangeFromHereToEndLine(m_options.m_end_line, range,
error)) {
result.AppendErrorWithFormat("invalid end-line option: %s.",
error.AsCString());
auto get_address_range_from_here_to_end_line_or_err =
sc.GetAddressRangeFromHereToEndLine(m_options.m_end_line, range);
if (!get_address_range_from_here_to_end_line_or_err) {
result.AppendErrorWithFormat(
AbdAlRahmanGad marked this conversation as resolved.
Show resolved Hide resolved
"invalid end-line option: %s.",
toString(
get_address_range_from_here_to_end_line_or_err.takeError())
.c_str());
return;
}
} else if (m_options.m_end_line_is_block_end) {
Expand Down
21 changes: 8 additions & 13 deletions lldb/source/Symbol/SymbolContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,20 +706,18 @@ LineEntry SymbolContext::GetFunctionStartLineEntry() const {
return LineEntry();
}

bool SymbolContext::GetAddressRangeFromHereToEndLine(uint32_t end_line,
AddressRange &range,
Status &error) {
llvm::Expected<bool>
SymbolContext::GetAddressRangeFromHereToEndLine(uint32_t end_line,
AddressRange &range) {
if (!line_entry.IsValid()) {
error = Status::FromErrorString("Symbol context has no line table.");
return false;
return llvm::createStringError("Symbol context has no line table.");
}

range = line_entry.range;
if (line_entry.line > end_line) {
error = Status::FromErrorStringWithFormat(
return llvm::createStringError(
"end line option %d must be after the current line: %d", end_line,
line_entry.line);
return false;
}

uint32_t line_index = 0;
Expand All @@ -740,29 +738,26 @@ bool SymbolContext::GetAddressRangeFromHereToEndLine(uint32_t end_line,
if (!found) {
// Can't find the index of the SymbolContext's line entry in the
// SymbolContext's CompUnit.
error = Status::FromErrorString(
return llvm::createStringError(
"Can't find the current line entry in the CompUnit - can't process "
"the end-line option");
return false;
}

line_index = comp_unit->FindLineEntry(line_index, end_line, nullptr, false,
&end_entry);
if (line_index == UINT32_MAX) {
error = Status::FromErrorStringWithFormat(
return llvm::createStringError(
"could not find a line table entry corresponding "
"to end line number %d",
end_line);
return false;
}

Block *func_block = GetFunctionBlock();
if (func_block && func_block->GetRangeIndexContainingAddress(
end_entry.range.GetBaseAddress()) == UINT32_MAX) {
error = Status::FromErrorStringWithFormat(
return llvm::createStringError(
"end line number %d is not contained within the current function.",
end_line);
return false;
}

lldb::addr_t range_size = end_entry.range.GetBaseAddress().GetFileAddress() -
Expand Down
Loading