xref: /src/contrib/llvm-project/lldb/source/Interpreter/OptionValueUUID.cpp (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e) !
1cfca06d7SDimitry Andric //===-- OptionValueUUID.cpp -----------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
9f034231aSEd Maste #include "lldb/Interpreter/OptionValueUUID.h"
10f034231aSEd Maste 
11f034231aSEd Maste #include "lldb/Core/Module.h"
12f034231aSEd Maste #include "lldb/Interpreter/CommandInterpreter.h"
1374a628f7SDimitry Andric #include "lldb/Utility/Stream.h"
1474a628f7SDimitry Andric #include "lldb/Utility/StringList.h"
15f034231aSEd Maste 
16f034231aSEd Maste using namespace lldb;
17f034231aSEd Maste using namespace lldb_private;
18f034231aSEd Maste 
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)1914f1b3e8SDimitry Andric void OptionValueUUID::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
2014f1b3e8SDimitry Andric                                 uint32_t dump_mask) {
21f034231aSEd Maste   if (dump_mask & eDumpOptionType)
22f034231aSEd Maste     strm.Printf("(%s)", GetTypeAsCString());
2314f1b3e8SDimitry Andric   if (dump_mask & eDumpOptionValue) {
24f034231aSEd Maste     if (dump_mask & eDumpOptionType)
25f034231aSEd Maste       strm.PutCString(" = ");
267fa27ce4SDimitry Andric     m_uuid.Dump(strm);
27f034231aSEd Maste   }
28f034231aSEd Maste }
29f034231aSEd Maste 
SetValueFromString(llvm::StringRef value,VarSetOperationType op)30b76161e4SDimitry Andric Status OptionValueUUID::SetValueFromString(llvm::StringRef value,
3114f1b3e8SDimitry Andric                                            VarSetOperationType op) {
32b76161e4SDimitry Andric   Status error;
3314f1b3e8SDimitry Andric   switch (op) {
34f034231aSEd Maste   case eVarSetOperationClear:
35f034231aSEd Maste     Clear();
36205afe67SEd Maste     NotifyValueChanged();
37f034231aSEd Maste     break;
38f034231aSEd Maste 
39f034231aSEd Maste   case eVarSetOperationReplace:
4014f1b3e8SDimitry Andric   case eVarSetOperationAssign: {
41cfca06d7SDimitry Andric     if (!m_uuid.SetFromStringRef(value))
4214f1b3e8SDimitry Andric       error.SetErrorStringWithFormat("invalid uuid string value '%s'",
4314f1b3e8SDimitry Andric                                      value.str().c_str());
4414f1b3e8SDimitry Andric     else {
45f034231aSEd Maste       m_value_was_set = true;
46205afe67SEd Maste       NotifyValueChanged();
47205afe67SEd Maste     }
4814f1b3e8SDimitry Andric   } break;
49f034231aSEd Maste 
50f034231aSEd Maste   case eVarSetOperationInsertBefore:
51f034231aSEd Maste   case eVarSetOperationInsertAfter:
52f034231aSEd Maste   case eVarSetOperationRemove:
53f034231aSEd Maste   case eVarSetOperationAppend:
54f034231aSEd Maste   case eVarSetOperationInvalid:
555e95aa85SEd Maste     error = OptionValue::SetValueFromString(value, op);
56f034231aSEd Maste     break;
57f034231aSEd Maste   }
58f034231aSEd Maste   return error;
59f034231aSEd Maste }
60f034231aSEd Maste 
AutoComplete(CommandInterpreter & interpreter,CompletionRequest & request)61ead24645SDimitry Andric void OptionValueUUID::AutoComplete(CommandInterpreter &interpreter,
62f73363f1SDimitry Andric                                    CompletionRequest &request) {
63f034231aSEd Maste   ExecutionContext exe_ctx(interpreter.GetExecutionContext());
64f034231aSEd Maste   Target *target = exe_ctx.GetTargetPtr();
65ead24645SDimitry Andric   if (!target)
66ead24645SDimitry Andric     return;
67f73363f1SDimitry Andric   auto prefix = request.GetCursorArgumentPrefix();
68f73363f1SDimitry Andric   llvm::SmallVector<uint8_t, 20> uuid_bytes;
69ead24645SDimitry Andric   if (!UUID::DecodeUUIDBytesFromString(prefix, uuid_bytes).empty())
70ead24645SDimitry Andric     return;
71f034231aSEd Maste   const size_t num_modules = target->GetImages().GetSize();
7214f1b3e8SDimitry Andric   for (size_t i = 0; i < num_modules; ++i) {
73f034231aSEd Maste     ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i));
74ead24645SDimitry Andric     if (!module_sp)
75ead24645SDimitry Andric       continue;
76f034231aSEd Maste     const UUID &module_uuid = module_sp->GetUUID();
77ead24645SDimitry Andric     if (!module_uuid.IsValid())
78ead24645SDimitry Andric       continue;
79ead24645SDimitry Andric     request.TryCompleteCurrentArg(module_uuid.GetAsString());
80f034231aSEd Maste   }
81f034231aSEd Maste }
82