[Lldb-commits] [lldb] r213436 - In Process::LoadImage, use the same function call both to call dlopen and to collect

Jim Ingham jingham at apple.com
Fri Jul 18 17:37:06 PDT 2014


Author: jingham
Date: Fri Jul 18 19:37:06 2014
New Revision: 213436

URL: http://llvm.org/viewvc/llvm-project?rev=213436&view=rev
Log:
In Process::LoadImage, use the same function call both to call dlopen and to collect
the error if there is one.

Modified:
    lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=213436&r1=213435&r2=213436&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Fri Jul 18 19:37:06 2014
@@ -1525,8 +1525,24 @@ Process::LoadImage (const FileSpec &imag
                 expr_options.SetIgnoreBreakpoints(true);
                 expr_options.SetExecutionPolicy(eExecutionPolicyAlways);
                 StreamString expr;
-                expr.Printf("dlopen (\"%s\", 2)", path);
-                const char *prefix = "extern \"C\" void* dlopen (const char *path, int mode);\n";
+                expr.Printf(R"(
+                               struct __lldb_dlopen_result { void *image_ptr; const char *error_str; } the_result;
+                               the_result.image_ptr = dlopen ("%s", 2);
+                               if (the_result.image_ptr == (void *) 0x0)
+                               {
+                                   the_result.error_str = dlerror();
+                               }
+                               else
+                               {
+                                   the_result.error_str = (const char *) 0x0;
+                               }
+                               the_result;
+                              )",
+                              path);
+                const char *prefix = R"(
+                                        extern "C" void* dlopen (const char *path, int mode);
+                                        extern "C" const char *dlerror (void);
+                                        )";
                 lldb::ValueObjectSP result_valobj_sp;
                 Error expr_error;
                 ClangUserExpression::Evaluate (exe_ctx,
@@ -1541,7 +1557,8 @@ Process::LoadImage (const FileSpec &imag
                     if (error.Success())
                     {
                         Scalar scalar;
-                        if (result_valobj_sp->ResolveValue (scalar))
+                        ValueObjectSP image_ptr_sp = result_valobj_sp->GetChildAtIndex(0, true);
+                        if (image_ptr_sp && image_ptr_sp->ResolveValue (scalar))
                         {
                             addr_t image_ptr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
                             if (image_ptr != 0 && image_ptr != LLDB_INVALID_ADDRESS)
@@ -1552,25 +1569,17 @@ Process::LoadImage (const FileSpec &imag
                             }
                             else if (image_ptr == 0)
                             {
-                                prefix = "extern \"C\" const char *dlerror(void);\n";
-                                expr.Clear();
-                                expr.PutCString("dlerror()");
-                                ClangUserExpression::Evaluate (exe_ctx,
-                                                               expr_options,
-                                                               expr.GetData(),
-                                                               prefix,
-                                                               result_valobj_sp,
-                                                               expr_error);
-                                if (result_valobj_sp && error.Success())
+                                ValueObjectSP error_str_sp = result_valobj_sp->GetChildAtIndex(1, true);
+                                if (error_str_sp)
                                 {
-                                    if (result_valobj_sp->IsCStringContainer(true))
+                                    if (error_str_sp->IsCStringContainer(true))
                                     {
                                         StreamString s;
-                                        size_t num_chars = result_valobj_sp->ReadPointedString (s, error);
+                                        size_t num_chars = error_str_sp->ReadPointedString (s, error);
                                         if (error.Success() && num_chars > 0)
                                         {
                                             error.Clear();
-                                            error.SetErrorStringWithFormat("dlopen failed: %s", s.GetData());
+                                            error.SetErrorStringWithFormat("dlopen error: %s", s.GetData());
                                         }
                                     }
                                 }





More information about the lldb-commits mailing list