Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
42 changes: 37 additions & 5 deletions lldb/source/Commands/CommandObjectSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ class CommandObjectSourceList : public CommandObjectParsed {
bool check_inlines = false;
SymbolContextList sc_list;
size_t num_matches = 0;
uint32_t start_line = m_options.start_line;

if (!m_options.modules.empty()) {
ModuleList matching_modules;
Expand All @@ -1114,15 +1115,15 @@ class CommandObjectSourceList : public CommandObjectParsed {
matching_modules.Clear();
target.GetImages().FindModules(module_spec, matching_modules);
num_matches += matching_modules.ResolveSymbolContextForFilePath(
filename, 0, check_inlines,
filename, start_line, check_inlines,
SymbolContextItem(eSymbolContextModule |
eSymbolContextCompUnit),
sc_list);
}
}
} else {
num_matches = target.GetImages().ResolveSymbolContextForFilePath(
filename, 0, check_inlines,
filename, start_line, check_inlines,
eSymbolContextModule | eSymbolContextCompUnit, sc_list);
}

Expand Down Expand Up @@ -1170,10 +1171,41 @@ class CommandObjectSourceList : public CommandObjectParsed {
if (m_options.num_lines == 0)
m_options.num_lines = 10;
const uint32_t column = 0;

// Headers aren't always in the DWARF but if they have
// executable code (eg., inlined-functions) then the callsite's
// file(s) will be found. So if a header was requested and we got a
// primary file (ie., something with a different name), then look thru
// its support file(s) for the header.
lldb::SupportFileSP found_file_sp =
sc.comp_unit->GetPrimarySupportFile();

if (!llvm::StringRef(found_file_sp->GetSpecOnly().GetPath())
.ends_with(filename)) {
int support_matches_count = 0;
for (auto &file : sc.comp_unit->GetSupportFiles()) {
if (llvm::StringRef(file->GetSpecOnly().GetPath())
.ends_with(filename)) {
found_file_sp = file;
++support_matches_count;
}
}
if (support_matches_count == 0) {
result.AppendErrorWithFormat(
"No file found for requested file: \"%s.\"\n", filename);
return;
} else if (support_matches_count > 1) {
result.AppendErrorWithFormat(
"Multiple files found for requested file: \"%s.\"\n",
filename);
return;
}
}

target.GetSourceManager().DisplaySourceLinesWithLineNumbers(
sc.comp_unit->GetPrimarySupportFile(),
m_options.start_line, column, 0, m_options.num_lines, "",
&result.GetOutputStream(), GetBreakpointLocations());
found_file_sp, m_options.start_line, column, 0,
m_options.num_lines, "", &result.GetOutputStream(),
GetBreakpointLocations());

result.SetStatus(eReturnStatusSuccessFinishResult);
} else {
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Core/ModuleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ uint32_t ModuleList::ResolveSymbolContextsForFileSpec(
const FileSpec &file_spec, uint32_t line, bool check_inlines,
SymbolContextItem resolve_scope, SymbolContextList &sc_list) const {
std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
// If we're looking for a header (not source), then need to check inline.
check_inlines = check_inlines || !file_spec.IsSourceImplementationFile();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be done here. The breakpoint setting code also goes through this code path and it works fine without it. I suggest looking at how that works and emulating it. I suspect it involves looking at the target.inline-breakpoint-strategy setting. I think it'd make sense to do that here as well (if anyone disagrees with that, do chime in), even though the setting is called inline-breakpoint-strategy, as the setting is really about where we go to search when looking up a file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thanks for the pointer! :)

for (const ModuleSP &module_sp : m_modules) {
module_sp->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
resolve_scope, sc_list);
Expand Down
57 changes: 57 additions & 0 deletions lldb/test/Shell/Commands/list-header.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Test that `list header.h:<line>` works correctly when header is available.
##
# RUN: split-file %s %t

# RUN: %clang_host -g %t/main_with_inlined.cc %t/foo.cc -o %t/main_with_inlined.out
# RUN: %clang_host -g %t/main_no_inlined.cc %t/foo.cc -o %t/main_no_inlined.out

# RUN: %lldb %t/main_with_inlined.out -o "list foo.h:2" -o "exit" 2>&1 \
# RUN: | FileCheck %s --check-prefix=CHECK-INLINED

## Would be nice if this listed the header too - but probably not something
## we want to support right now.
# RUN: echo quit | %lldb %t/main_no_inlined.out -o "list foo.h:2" -o "exit" 2>&1 \
# RUN: | FileCheck %s --check-prefix=CHECK-NO-INLINED

# CHECK-INLINED: 2 extern int* ptr;
# CHECK-INLINED: 3 void f(int x);
# CHECK-INLINED: 4
# CHECK-INLINED: 5 inline void g(int x) {
# CHECK-INLINED: 6 *ptr = x; // should raise a SIGILL
# CHECK-INLINED: 7 }

# CHECK-NO-INLINED: error: Could not find source file "foo.h".

#--- foo.h
// foo.h
extern int* ptr;
void f(int x);

inline void g(int x) {
*ptr = x; // should raise a SIGILL
}

#--- foo.cc
#include "foo.h"

int* ptr;

void f(int x) {
*ptr = x;
}

#--- main_with_inlined.cc
#include "foo.h"

int main() {
g(123); // Call the inlined function
return 0;
}

#--- main_no_inlined.cc
#include "foo.h"

int main() {
f(234);
return 0;
}
Loading