[lldb-dev] [BUG?] Confusion between translation units?

Ramkumar Ramachandra via lldb-dev lldb-dev at lists.llvm.org
Wed Oct 21 08:45:55 PDT 2015


So first, an addendum: I found a way to make the project build without
using a symlink, and use a direct reference instead. The problem still
persists. It may be that symlink is one of the problems, but it is
certainly not the only problem.

On Tue, Oct 20, 2015 at 8:22 PM, Greg Clayton <gclayton at apple.com> wrote:
> int
> Declaration::Compare(const Declaration& a, const Declaration& b)
> {
>     int result = FileSpec::Compare(a.m_file, b.m_file, true);
>     if (result)

Wait, won't FileSpec::Compare be true iff a.m_file is the same as
b.m_file (excluding symlink resolution)? If so, why are we putting the
symlink-checking logic in the true branch of the original
FileSpec::Compare? Aren't we expanding the scope of what we match,
instead of narrowing it?

>     {
>         int symlink_result = result;
>         if (a.m_file.GetFilename() == b.m_file.GetFilename())
>         {
>             // Check if the directories in a and b are symlinks to each other
>             FileSpec resolved_a;
>             FileSpec resolved_b;
>             if (FileSystem::ResolveSymbolicLink(a.m_file, resolved_a).Success() &&
>                 FileSystem::ResolveSymbolicLink(b.m_file, resolved_b).Success())
>             {
>                 symlink_result = FileSpec::Compare(resolved_a, resolved_b, true);

I'm confused. Shouldn't the logic be "check literal equality; if true,
return immediately; if not, check equality with symlink resolution"?

>             }
>         }
>         if (symlink_result != 0)
>             return symlink_result;
>     }
>     if (a.m_line < b.m_line)
>         return -1;
>     else if (a.m_line > b.m_line)
>         return 1;
> #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
>     if (a.m_column < b.m_column)
>         return -1;
>     else if (a.m_column > b.m_column)
>         return 1;
> #endif
>     return 0;
> }

Here's my version of the patch, although I'm not sure when the code
will be reached.

int
Declaration::Compare(const Declaration& a, const Declaration& b)
{
    int result = FileSpec::Compare(a.m_file, b.m_file, true);
    if (result)
        return result;
    if (a.m_file.GetFilename() == b.m_file.GetFilename()) {
        // Check if one of the directories is a symlink to the other
        int symlink_result = result;
        FileSpec resolved_a;
        FileSpec resolved_b;
        if (FileSystem::ResolveSymbolicLink(a.m_file, resolved_a).Success() &&
            FileSystem::ResolveSymbolicLink(b.m_file, resolved_b).Success())
        {
            symlink_result = FileSpec::Compare(resolved_a, resolved_b, true);
            if (symlink_result)
                return symlink_result;
        }
    }
    if (a.m_line < b.m_line)
        return -1;
    else if (a.m_line > b.m_line)
        return 1;
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
    if (a.m_column < b.m_column)
        return -1;
    else if (a.m_column > b.m_column)
        return 1;
#endif
    return 0;
}

If you're confident that this solves a problem, I can send it as a
code review or something (and set up git-svn, sigh).


More information about the lldb-dev mailing list