<rdar://problem/13941992>

Accept mach-o files with bad segments. Many core files are not created correctly and we should still be able to glean any information we can from them.



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@183247 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 140272e..9f27c1c 100644
--- a/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -994,8 +994,9 @@
                                                  lc_segment_name,
                                                  load_cmd.fileoff,
                                                  m_length);
-                        m_sections_ap->Clear();
-                        return 0;
+                        
+                        load_cmd.fileoff = 0;
+                        load_cmd.filesize = 0;
                     }
                     
                     if (load_cmd.fileoff + load_cmd.filesize > m_length)
@@ -1006,13 +1007,14 @@
                         // is null out the SectionList vector and if a process has been set up, dump a message
                         // to stdout.  The most common case here is core file debugging with a truncated file.
                         const char *lc_segment_name = load_cmd.cmd == LoadCommandSegment64 ? "LC_SEGMENT_64" : "LC_SEGMENT";
-                        GetModule()->ReportError("is a corrupt mach-o file: load command %u %s has a fileoff + filesize (0x%" PRIx64 ") that extends beyond the end of the file (0x%" PRIx64 ")",
+                        GetModule()->ReportError("is a corrupt mach-o file: load command %u %s has a fileoff + filesize (0x%" PRIx64 ") that extends beyond the end of the file (0x%" PRIx64 "), the segment will be truncated",
                                                  i,
                                                  lc_segment_name,
                                                  load_cmd.fileoff + load_cmd.filesize,
                                                  m_length);
-                        m_sections_ap->Clear();
-                        return 0;
+                        
+                        // Tuncase the length
+                        load_cmd.filesize = m_length - load_cmd.fileoff;
                     }
                 }
                 if (m_data.GetU32(&offset, &load_cmd.maxprot, 4))