lldb crashes on Linux

Hello,
I finally managed to compile LLDB on Linux but the programm debugged seems to crash in the first instruction with a SIGSEGV.

The Output of the compiler is:
si_code = 128
lldb: ProcessMonitor.cpp:1123: static ProcessMessage::CrashReason ProcessMonitor::GetCrashReasonForSIGSEGV(const siginfo*): Assertion `false && "unexpected si_code for SIGSEGV"' failed.

First of all I had to apply a small patch to lldb

--- source/Expression/ASTDumper.cpp (revision 134085)
+++ source/Expression/ASTDumper.cpp (working copy)
@@ -406,7 +406,7 @@
     m_stream.Indent(); m_stream.Printf("isCanonicalUnqualified() : %s\n", SfB(type->isCanonicalUnqualified()));
     m_stream.Indent(); m_stream.Printf("isIncompleteType() : %s\n", SfB(type->isIncompleteType()));
     m_stream.Indent(); m_stream.Printf("isObjectType() : %s\n", SfB(type->isObjectType()));
- m_stream.Indent(); m_stream.Printf("isPODType() : %s\n", SfB(type->isPODType()));
+ //m_stream.Indent(); m_stream.Printf("isPODType() : %s\n", SfB(type->isPODType()));
     m_stream.Indent(); m_stream.Printf("isLiteralType() : %s\n", SfB(type->isLiteralType()));
     m_stream.Indent(); m_stream.Printf("isBuiltinType() : %s\n", SfB(type->isBuiltinType()));
     m_stream.Indent(); m_stream.Printf("isPlaceholderType() : %s\n", SfB(type->isPlaceholderType()));
Index: source/Plugins/Process/Linux/ProcessMonitor.cpp

The patch might make things compile but 2 or the 3 file patches do not address any of the issues you are running into.

Comments below with each file:

Hello,
I finally managed to compile LLDB on Linux but the programm debugged seems to crash in the first instruction with a SIGSEGV.

The Output of the compiler is:
si_code = 128
lldb: ProcessMonitor.cpp:1123: static ProcessMessage::CrashReason ProcessMonitor::GetCrashReasonForSIGSEGV(const siginfo*): Assertion `false && "unexpected si_code for SIGSEGV"' failed.

First of all I had to apply a small patch to lldb

--- source/Expression/ASTDumper.cpp (revision 134085)
+++ source/Expression/ASTDumper.cpp (working copy)
@@ -406,7 +406,7 @@
    m_stream.Indent(); m_stream.Printf("isCanonicalUnqualified() : %s\n", SfB(type->isCanonicalUnqualified()));
    m_stream.Indent(); m_stream.Printf("isIncompleteType() : %s\n", SfB(type->isIncompleteType()));
    m_stream.Indent(); m_stream.Printf("isObjectType() : %s\n", SfB(type->isObjectType()));

Is an assertion firing off down in llvm/clang code? If so, we should figure that out and fix the root cause. We don't see this on MacOSX. Also, who is trying to dump this? What is the stack backtrace when this gets hit?

- m_stream.Indent(); m_stream.Printf("isPODType() : %s\n", SfB(type->isPODType()));
+ //m_stream.Indent(); m_stream.Printf("isPODType() : %s\n", SfB(type->isPODType()));
    m_stream.Indent(); m_stream.Printf("isLiteralType() : %s\n", SfB(type->isLiteralType()));
    m_stream.Indent(); m_stream.Printf("isBuiltinType() : %s\n", SfB(type->isBuiltinType()));
    m_stream.Indent(); m_stream.Printf("isPlaceholderType() : %s\n", SfB(type->isPlaceholderType()));

I will let the linux folks comment on the patch below, looks ok to me though.

Index: source/Plugins/Process/Linux/ProcessMonitor.cpp

--- source/Plugins/Process/Linux/ProcessMonitor.cpp (revision 134085)
+++ source/Plugins/Process/Linux/ProcessMonitor.cpp (working copy)
@@ -31,7 +31,10 @@
#include "ProcessLinux.h"
#include "ProcessMonitor.h"

+//for debugging the debugger
+#include <iostream>

+
using namespace lldb_private;

//------------------------------------------------------------------------------
@@ -241,7 +244,7 @@

    // Set errno to zero so that we can detect a failed peek.
    errno = 0;
- unsigned long data = ptrace(PTRACE_PEEKUSER, pid, m_offset, NULL);
+ uint32_t data = ptrace(PTRACE_PEEKUSER, pid, m_offset, NULL);

    if (data == -1UL && errno)
        m_result = false;
@@ -1074,8 +1077,10 @@
            return ProcessMessage::Signal(pid, signo);
    }

+
    if (signo == SIGSEGV) {
        lldb::addr_t fault_addr = reinterpret_cast<lldb::addr_t>(info->si_addr);
+ std::cerr << "SIGSEGV on Linux at \n";
        ProcessMessage::CrashReason reason = GetCrashReasonForSIGSEGV(info);
        return ProcessMessage::Crash(pid, reason, signo, fault_addr);
    }
@@ -1114,6 +1119,7 @@
    switch (info->si_code)
    {
    default:
+ std::cerr << "si_code" << info->si_code;
        assert(false && "unexpected si_code for SIGSEGV");
        break;
    case SEGV_MAPERR:
@@ -1285,7 +1291,8 @@

            assert(status == sizeof(op));
            op->Execute(monitor);
- write(fdset.fd, &op, sizeof(op));
+ int wr=write(fdset.fd, &op, sizeof(op));
+ if(wr<0) return;//FIXME error check
        }
    }
}
@@ -1298,7 +1305,8 @@
    Mutex::Locker lock(m_server_mutex);

    // FIXME: Do proper error checking here.
- write(m_client_fd, &op, sizeof(op));
+ int wr=write(m_client_fd, &op, sizeof(op));
+ if(wr<0) return;

READ_AGAIN:
    if ((status = read(m_client_fd, &ack, sizeof(ack))) < 0)

You commented out any struct, union or class from ever getting any fields added to them so you will never see anything any aggregate data types when/if you are able to dump variables.

Why did you comment this out? Does it not compile? What is the "BAD style" comment about?

Index: source/Symbol/ClangASTContext.cpp

--- source/Symbol/ClangASTContext.cpp (revision 134085)
+++ source/Symbol/ClangASTContext.cpp (working copy)
@@ -6,7 +6,6 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-
#include "lldb/Symbol/ClangASTContext.h"

// C Includes
@@ -1591,6 +1590,7 @@
                APInt bitfield_bit_size_apint(ast->getTypeSize(ast->IntTy), bitfield_bit_size);
                bit_width = new (*ast)IntegerLiteral (*ast, bitfield_bit_size_apint, ast->IntTy, SourceLocation());
            }
+ #if 0 //BAD style
            FieldDecl *field = FieldDecl::Create (*ast,
                                                  record_decl,
                                                  SourceLocation(),
@@ -1607,6 +1607,8 @@
            {
                record_decl->addDecl(field);
            }
+ #endif
+ FieldDecl *field = NULL;
        }
        else
        {
@@ -3123,6 +3125,7 @@
                    }
                }

You have also commented out being able to find any child member by name. Why did you comment this out? Doesn't compile?