[Lldb-commits] [lldb] 4016c6b - [lldb/Reproducer] Prevent crash when GDB multi-loader can't be created.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 10 23:17:17 PDT 2020


Author: Jonas Devlieghere
Date: 2020-03-10T23:16:55-07:00
New Revision: 4016c6b07f2ade01c65750d1297f72b43f9eb244

URL: https://github.com/llvm/llvm-project/commit/4016c6b07f2ade01c65750d1297f72b43f9eb244
DIFF: https://github.com/llvm/llvm-project/commit/4016c6b07f2ade01c65750d1297f72b43f9eb244.diff

LOG: [lldb/Reproducer] Prevent crash when GDB multi-loader can't be created.

Check that the multi loader isn't null and print an error otherwise.
This patch also extends the test to cover these error paths.

Added: 
    

Modified: 
    lldb/source/Commands/CommandObjectReproducer.cpp
    lldb/test/Shell/Reproducer/TestDump.test

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectReproducer.cpp b/lldb/source/Commands/CommandObjectReproducer.cpp
index a3b49b1979b3..d73fa78231a5 100644
--- a/lldb/source/Commands/CommandObjectReproducer.cpp
+++ b/lldb/source/Commands/CommandObjectReproducer.cpp
@@ -422,8 +422,8 @@ class CommandObjectReproducerDump : public CommandObjectParsed {
           repro::MultiLoader<repro::CommandProvider>::Create(loader);
       if (!multi_loader) {
         SetError(result,
-                 make_error<StringError>(llvm::inconvertibleErrorCode(),
-                                         "Unable to create command loader."));
+                 make_error<StringError>("Unable to create command loader.",
+                                         llvm::inconvertibleErrorCode()));
         return false;
       }
 
@@ -448,6 +448,14 @@ class CommandObjectReproducerDump : public CommandObjectParsed {
       std::unique_ptr<repro::MultiLoader<repro::GDBRemoteProvider>>
           multi_loader =
               repro::MultiLoader<repro::GDBRemoteProvider>::Create(loader);
+
+      if (!multi_loader) {
+        SetError(result,
+                 make_error<StringError>("Unable to create GDB loader.",
+                                         llvm::inconvertibleErrorCode()));
+        return false;
+      }
+
       llvm::Optional<std::string> gdb_file;
       while ((gdb_file = multi_loader->GetNextFile())) {
         auto error_or_file = MemoryBuffer::getFile(*gdb_file);

diff  --git a/lldb/test/Shell/Reproducer/TestDump.test b/lldb/test/Shell/Reproducer/TestDump.test
index 3d4d21d98e50..c193b806b547 100644
--- a/lldb/test/Shell/Reproducer/TestDump.test
+++ b/lldb/test/Shell/Reproducer/TestDump.test
@@ -24,3 +24,11 @@
 # GDB: read packet: $OK#9a
 
 # RUN: %lldb --replay %t.repro | FileCheck %s --check-prefix FILES
+
+# RUN: rm %t.repro/gdb-remote.yaml
+# RUN: %lldb -b -o 'reproducer dump -p gdb -f %t.repro' 2>&1 | FileCheck %s --check-prefix GDB-ERROR
+# GDB-ERROR: error: Unable to create GDB loader.
+
+# RUN: rm %t.repro/command-interpreter.yaml
+# RUN: %lldb -b -o 'reproducer dump -p commands -f %t.repro' 2>&1 | FileCheck %s --check-prefix COMMANDS-ERROR
+# COMMANDS-ERROR: error: Unable to create command loader.


        


More information about the lldb-commits mailing list