Skip to content

[lldb/Target] Slide source display for artificial locations at function start #3648

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 22 additions & 3 deletions lldb/source/Target/StackFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1892,14 +1892,33 @@ bool StackFrame::GetStatus(Stream &strm, bool show_frame_info, bool show_source,
if (m_sc.comp_unit && m_sc.line_entry.IsValid()) {
have_debuginfo = true;
if (source_lines_before > 0 || source_lines_after > 0) {
uint32_t start_line = m_sc.line_entry.line;
if (!start_line && m_sc.function) {
FileSpec source_file;
m_sc.function->GetStartLineSourceInfo(source_file, start_line);
}

size_t num_lines =
target->GetSourceManager().DisplaySourceLinesWithLineNumbers(
m_sc.line_entry.file, m_sc.line_entry.line,
m_sc.line_entry.column, source_lines_before,
source_lines_after, "->", &strm);
m_sc.line_entry.file, start_line, m_sc.line_entry.column,
source_lines_before, source_lines_after, "->", &strm);
if (num_lines != 0)
have_source = true;
// TODO: Give here a one time warning if source file is missing.
if (!m_sc.line_entry.line) {
ConstString fn_name = m_sc.GetFunctionName();

if (!fn_name.IsEmpty())
strm.Printf("Warning: the current PC is an artificial location "
"in function %s.",
fn_name.AsCString());
else
strm.Printf(
"Warning: the current PC is an artificial location "
"but lldb couldn't associate it with a function in %s.",
m_sc.line_entry.file.GetFilename().GetCString());
strm.EOL();
}
}
}
switch (disasm_display) {
Expand Down
17 changes: 16 additions & 1 deletion lldb/test/API/source-manager/TestSourceManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ def test_modify_source_file_while_debugging(self):
SOURCE_DISPLAYED_CORRECTLY,
substrs=['Hello world'])


# The '-b' option shows the line table locations from the debug information
# that indicates valid places to set source level breakpoints.

Expand Down Expand Up @@ -270,3 +269,19 @@ def test_set_breakpoint_with_absolute_path(self):
substrs=['stopped',
'main-copy.c:%d' % self.line,
'stop reason = breakpoint'])

def test_artificial_source_location(self):
src_file = 'artificial_location.c'
d = {'C_SOURCES': src_file }
self.build(dictionary=d)

lldbutil.run_to_source_breakpoint(
self, 'main',
lldb.SBFileSpec(src_file, False))

self.expect("run", RUN_SUCCEEDED,
substrs=['stop reason = breakpoint', '%s:%d' % (src_file,0),
'Warning: the current PC is an artificial ',
'location in function '
])

6 changes: 6 additions & 0 deletions lldb/test/API/source-manager/artificial_location.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int foo() { return 42; }

int main() {
#line 0
return foo();
}