[Lldb-commits] [lldb] [lldb]Make `list` command work with headers when possible. (PR #139002)

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Thu May 8 10:50:49 PDT 2025


================
@@ -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 header: \"%s.\"\n", filename);
----------------
bulbazord wrote:

The error message implies that you're looking for a header, but maybe somebody's not looking for a header per se. You could do something like `#include "foo.inc"` and maybe a developer wouldn't conceptualize that as including a header.

Maybe a more generic message like `Failed to find requested file`?

https://github.com/llvm/llvm-project/pull/139002


More information about the lldb-commits mailing list