Home | History | Annotate | Download | only in Interpreter
      1 //===-- OptionValueUUID.cpp ------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #include "lldb/lldb-python.h"
     11 
     12 #include "lldb/Interpreter/OptionValueUUID.h"
     13 
     14 // C Includes
     15 // C++ Includes
     16 // Other libraries and framework includes
     17 // Project includes
     18 #include "lldb/Core/Module.h"
     19 #include "lldb/Core/Stream.h"
     20 #include "lldb/Core/StringList.h"
     21 #include "lldb/Interpreter/CommandInterpreter.h"
     22 
     23 using namespace lldb;
     24 using namespace lldb_private;
     25 
     26 void
     27 OptionValueUUID::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
     28 {
     29     if (dump_mask & eDumpOptionType)
     30         strm.Printf ("(%s)", GetTypeAsCString ());
     31     if (dump_mask & eDumpOptionValue)
     32     {
     33         if (dump_mask & eDumpOptionType)
     34             strm.PutCString (" = ");
     35         m_uuid.Dump (&strm);
     36     }
     37 }
     38 
     39 Error
     40 OptionValueUUID::SetValueFromCString (const char *value_cstr,
     41                                       VarSetOperationType op)
     42 {
     43     Error error;
     44     switch (op)
     45     {
     46         case eVarSetOperationClear:
     47             Clear();
     48             break;
     49 
     50         case eVarSetOperationReplace:
     51         case eVarSetOperationAssign:
     52             {
     53                 if (m_uuid.SetFromCString(value_cstr) == 0)
     54                     error.SetErrorStringWithFormat ("invalid uuid string value '%s'", value_cstr);
     55                 else
     56                     m_value_was_set = true;
     57             }
     58             break;
     59 
     60         case eVarSetOperationInsertBefore:
     61         case eVarSetOperationInsertAfter:
     62         case eVarSetOperationRemove:
     63         case eVarSetOperationAppend:
     64         case eVarSetOperationInvalid:
     65             error = OptionValue::SetValueFromCString (value_cstr, op);
     66             break;
     67     }
     68     return error;
     69 }
     70 
     71 lldb::OptionValueSP
     72 OptionValueUUID::DeepCopy () const
     73 {
     74     return OptionValueSP(new OptionValueUUID(*this));
     75 }
     76 
     77 size_t
     78 OptionValueUUID::AutoComplete (CommandInterpreter &interpreter,
     79                                const char *s,
     80                                int match_start_point,
     81                                int max_return_elements,
     82                                bool &word_complete,
     83                                StringList &matches)
     84 {
     85     word_complete = false;
     86     matches.Clear();
     87     ExecutionContext exe_ctx(interpreter.GetExecutionContext());
     88     Target *target = exe_ctx.GetTargetPtr();
     89     if (target)
     90     {
     91         const size_t num_modules = target->GetImages().GetSize();
     92         if (num_modules > 0)
     93         {
     94             UUID::ValueType uuid_bytes;
     95             const size_t num_bytes_decoded = UUID::DecodeUUIDBytesFromCString(s, uuid_bytes, NULL);
     96             for (size_t i=0; i<num_modules; ++i)
     97             {
     98                 ModuleSP module_sp (target->GetImages().GetModuleAtIndex(i));
     99                 if (module_sp)
    100                 {
    101                     const UUID &module_uuid = module_sp->GetUUID();
    102                     if (module_uuid.IsValid())
    103                     {
    104                         bool add_uuid = false;
    105                         if (num_bytes_decoded == 0)
    106                             add_uuid = true;
    107                         else
    108                             add_uuid = ::memcmp(module_uuid.GetBytes(), uuid_bytes, num_bytes_decoded) == 0;
    109                         if (add_uuid)
    110                         {
    111                             std::string uuid_str;
    112                             uuid_str = module_uuid.GetAsString();
    113                             if (!uuid_str.empty())
    114                                 matches.AppendString(uuid_str.c_str());
    115                         }
    116                     }
    117                 }
    118             }
    119         }
    120     }
    121     return matches.GetSize();
    122 }
    123 
    124