[Lldb-commits] [PATCH] D39969: Set error status in ObjectFile::LoadInMemory if it is not set

Tatyana Krasnukha via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 13 10:45:12 PST 2017


tatyana-krasnukha created this revision.
Herald added a subscriber: ki.stfu.

When breakpoints intersect a section, process->WriteMemory returns 0 without setting the error, LoadInMemory breaks execution and returns this error, but client code treat it as success.

Just added setting of error status for this case.

Applied clang-format.


Repository:
  rL LLVM

https://reviews.llvm.org/D39969

Files:
  source/Symbol/ObjectFile.cpp


Index: source/Symbol/ObjectFile.cpp
===================================================================
--- source/Symbol/ObjectFile.cpp
+++ source/Symbol/ObjectFile.cpp
@@ -78,8 +78,8 @@
         // and object container plug-ins can use these bytes to see if they
         // can parse this file.
         if (file_size > 0) {
-          data_sp =
-              DataBufferLLVM::CreateSliceFromPath(file->GetPath(), 512, file_offset);
+          data_sp = DataBufferLLVM::CreateSliceFromPath(file->GetPath(), 512,
+                                                        file_offset);
           data_offset = 0;
         }
       }
@@ -122,8 +122,8 @@
             }
             // We failed to find any cached object files in the container
             // plug-ins, so lets read the first 512 bytes and try again below...
-            data_sp = DataBufferLLVM::CreateSliceFromPath(archive_file.GetPath(),
-                                                     512, file_offset);
+            data_sp = DataBufferLLVM::CreateSliceFromPath(
+                archive_file.GetPath(), 512, file_offset);
           }
         }
       }
@@ -211,7 +211,8 @@
                                            lldb::offset_t file_offset,
                                            lldb::offset_t file_size,
                                            ModuleSpecList &specs) {
-  DataBufferSP data_sp = DataBufferLLVM::CreateSliceFromPath(file.GetPath(), 512, file_offset);
+  DataBufferSP data_sp =
+      DataBufferLLVM::CreateSliceFromPath(file.GetPath(), 512, file_offset);
   if (data_sp) {
     if (file_size == 0) {
       const lldb::offset_t actual_file_size = file.GetByteSize();
@@ -665,7 +666,6 @@
 }
 
 Status ObjectFile::LoadInMemory(Target &target, bool set_pc) {
-  Status error;
   ProcessSP process = target.CalculateProcess();
   if (!process)
     return Status("No Process");
@@ -675,6 +675,8 @@
   SectionList *section_list = GetSectionList();
   if (!section_list)
     return Status("No section in object file");
+
+  Status error;
   size_t section_count = section_list->GetNumSections(0);
   for (size_t i = 0; i < section_count; ++i) {
     SectionSP section_sp = section_list->GetSectionAtIndex(i);
@@ -687,8 +689,13 @@
       section_sp->GetSectionData(section_data);
       lldb::offset_t written = process->WriteMemory(
           addr, section_data.GetDataStart(), section_data.GetByteSize(), error);
-      if (written != section_data.GetByteSize())
+      if (written != section_data.GetByteSize()) {
+        if (!error.Fail())
+          error.SetErrorStringWithFormat(
+              "One or more breakpoints intersect section '%s'",
+              section_sp->GetName().AsCString());
         return error;
+      }
     }
   }
   if (set_pc) {
@@ -701,6 +708,4 @@
   return error;
 }
 
-void ObjectFile::RelocateSection(lldb_private::Section *section)
-{
-}
+void ObjectFile::RelocateSection(lldb_private::Section *section) {}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39969.122686.patch
Type: text/x-patch
Size: 2955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20171113/8a8b9680/attachment.bin>


More information about the lldb-commits mailing list