Commit 38870af8 authored by Pavel Labath's avatar Pavel Labath
Browse files

[lldb] Remove FileSpec->CompileUnit inheritance

Summary:
CompileUnit is a complicated class. Having it be implicitly convertible
to a FileSpec makes reasoning about it even harder.

This patch replaces the inheritance by a simple member and an accessor
function. This avoid the need for casting in places where one needed to
force a CompileUnit to be treated as a FileSpec, and does not add much
verbosity elsewhere.

It also fixes a bug where we were wrongly comparing CompileUnit& and a
CompileUnit*, which compiled due to a combination of this inheritance
and the FileSpec*->FileSpec implicit constructor.

Reviewers: teemperor, JDevlieghere, jdoerfert

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70827
parent e478385e
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#include "lldb/Core/ModuleChild.h"
#include "lldb/Symbol/DebugMacros.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/SourceModule.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/UserID.h"
@@ -35,7 +36,6 @@ namespace lldb_private {
/// table.
class CompileUnit : public std::enable_shared_from_this<CompileUnit>,
                    public ModuleChild,
                    public FileSpec,
                    public UserID,
                    public SymbolContextScope {
public:
@@ -116,9 +116,6 @@ public:
              const FileSpec &file_spec, lldb::user_id_t uid,
              lldb::LanguageType language, lldb_private::LazyBool is_optimized);

  /// Destructor
  ~CompileUnit() override;

  /// Add a function to this compile unit.
  ///
  /// Typically called by the SymbolFile plug-ins as they partially parse the
@@ -225,6 +222,9 @@ public:
                         const FileSpec *file_spec_ptr, bool exact,
                         LineEntry *line_entry);

  /// Return the primary source file associated with this compile unit.
  const FileSpec &GetPrimaryFile() const { return m_file_spec; }

  /// Get the line table for the compile unit.
  ///
  /// Called by clients and the SymbolFile plug-in. The SymbolFile plug-ins
@@ -415,6 +415,8 @@ protected:
  /// All modules, including the current module, imported by this
  /// compile unit.
  std::vector<SourceModule> m_imported_modules;
  /// The primary file associated with this compile unit.
  FileSpec m_file_spec;
  /// Files associated with this compile unit's line table and
  /// declarations.
  FileSpecList m_support_files;
+2 −2
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ SBFileSpec SBCompileUnit::GetFileSpec() const {

  SBFileSpec file_spec;
  if (m_opaque_ptr)
    file_spec.SetFileSpec(*m_opaque_ptr);
    file_spec.SetFileSpec(m_opaque_ptr->GetPrimaryFile());
  return LLDB_RECORD_RESULT(file_spec);
}

@@ -106,7 +106,7 @@ uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
    if (inline_file_spec && inline_file_spec->IsValid())
      file_spec = inline_file_spec->ref();
    else
      file_spec = *m_opaque_ptr;
      file_spec = m_opaque_ptr->GetPrimaryFile();

    index = m_opaque_ptr->FindLineEntry(
        start_idx, line, inline_file_spec ? inline_file_spec->get() : nullptr,
+2 −1
Original line number Diff line number Diff line
@@ -638,7 +638,8 @@ static bool SymbolContextsMightBeEquivalent(SymbolContext &old_sc,
  } else {
    // Otherwise we will compare by name...
    if (old_sc.comp_unit && new_sc.comp_unit) {
      if (FileSpec::Equal(*old_sc.comp_unit, *new_sc.comp_unit, true)) {
      if (FileSpec::Equal(old_sc.comp_unit->GetPrimaryFile(),
                          new_sc.comp_unit->GetPrimaryFile(), true)) {
        // Now check the functions:
        if (old_sc.function && new_sc.function &&
            (old_sc.function->GetName() == new_sc.function->GetName())) {
+1 −1
Original line number Diff line number Diff line
@@ -525,7 +525,7 @@ void BreakpointLocation::GetDescription(Stream *s,
      if (sc.comp_unit != nullptr) {
        s->EOL();
        s->Indent("compile unit = ");
        static_cast<FileSpec *>(sc.comp_unit)->GetFilename().Dump(s);
        sc.comp_unit->GetPrimaryFile().GetFilename().Dump(s);

        if (sc.function != nullptr) {
          s->EOL();
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ Searcher::CallbackReturn BreakpointResolverFileRegex::SearchCallback(
    return eCallbackReturnContinue;

  CompileUnit *cu = context.comp_unit;
  FileSpec cu_file_spec = *(static_cast<FileSpec *>(cu));
  FileSpec cu_file_spec = cu->GetPrimaryFile();
  std::vector<uint32_t> line_matches;
  context.target_sp->GetSourceManager().FindLinesMatchingRegex(
      cu_file_spec, m_regex, 1, UINT32_MAX, line_matches);
Loading