180814287SRaphael Isemann //===-- OptionValueUUID.cpp -----------------------------------------------===//
267cc0636SGreg Clayton //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
667cc0636SGreg Clayton //
767cc0636SGreg Clayton //===----------------------------------------------------------------------===//
867cc0636SGreg Clayton
967cc0636SGreg Clayton #include "lldb/Interpreter/OptionValueUUID.h"
1067cc0636SGreg Clayton
11b5f0feabSGreg Clayton #include "lldb/Core/Module.h"
12b5f0feabSGreg Clayton #include "lldb/Interpreter/CommandInterpreter.h"
13bf9a7730SZachary Turner #include "lldb/Utility/Stream.h"
14573ab909SZachary Turner #include "lldb/Utility/StringList.h"
1567cc0636SGreg Clayton
1667cc0636SGreg Clayton using namespace lldb;
1767cc0636SGreg Clayton using namespace lldb_private;
1867cc0636SGreg Clayton
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)19b9c1b51eSKate Stone void OptionValueUUID::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
20b9c1b51eSKate Stone uint32_t dump_mask) {
2167cc0636SGreg Clayton if (dump_mask & eDumpOptionType)
2267cc0636SGreg Clayton strm.Printf("(%s)", GetTypeAsCString());
23b9c1b51eSKate Stone if (dump_mask & eDumpOptionValue) {
2467cc0636SGreg Clayton if (dump_mask & eDumpOptionType)
2567cc0636SGreg Clayton strm.PutCString(" = ");
2667cc0636SGreg Clayton m_uuid.Dump(&strm);
2767cc0636SGreg Clayton }
2867cc0636SGreg Clayton }
2967cc0636SGreg Clayton
SetValueFromString(llvm::StringRef value,VarSetOperationType op)3097206d57SZachary Turner Status OptionValueUUID::SetValueFromString(llvm::StringRef value,
31b9c1b51eSKate Stone VarSetOperationType op) {
3297206d57SZachary Turner Status error;
33b9c1b51eSKate Stone switch (op) {
3467cc0636SGreg Clayton case eVarSetOperationClear:
3567cc0636SGreg Clayton Clear();
36332e8b1cSGreg Clayton NotifyValueChanged();
3767cc0636SGreg Clayton break;
3867cc0636SGreg Clayton
3967cc0636SGreg Clayton case eVarSetOperationReplace:
40b9c1b51eSKate Stone case eVarSetOperationAssign: {
41*1beffc18SJaroslav Sevcik if (!m_uuid.SetFromStringRef(value))
42b9c1b51eSKate Stone error.SetErrorStringWithFormat("invalid uuid string value '%s'",
43b9c1b51eSKate Stone value.str().c_str());
44b9c1b51eSKate Stone else {
4567cc0636SGreg Clayton m_value_was_set = true;
46332e8b1cSGreg Clayton NotifyValueChanged();
47332e8b1cSGreg Clayton }
48b9c1b51eSKate Stone } break;
4967cc0636SGreg Clayton
5067cc0636SGreg Clayton case eVarSetOperationInsertBefore:
5167cc0636SGreg Clayton case eVarSetOperationInsertAfter:
5267cc0636SGreg Clayton case eVarSetOperationRemove:
5367cc0636SGreg Clayton case eVarSetOperationAppend:
5467cc0636SGreg Clayton case eVarSetOperationInvalid:
55c95f7e2aSPavel Labath error = OptionValue::SetValueFromString(value, op);
5667cc0636SGreg Clayton break;
5767cc0636SGreg Clayton }
5867cc0636SGreg Clayton return error;
5967cc0636SGreg Clayton }
6067cc0636SGreg Clayton
AutoComplete(CommandInterpreter & interpreter,CompletionRequest & request)61ae34ed2cSRaphael Isemann void OptionValueUUID::AutoComplete(CommandInterpreter &interpreter,
62a2e76c0bSRaphael Isemann CompletionRequest &request) {
63b5f0feabSGreg Clayton ExecutionContext exe_ctx(interpreter.GetExecutionContext());
64b5f0feabSGreg Clayton Target *target = exe_ctx.GetTargetPtr();
651153dc96SRaphael Isemann if (!target)
661153dc96SRaphael Isemann return;
67a2e76c0bSRaphael Isemann auto prefix = request.GetCursorArgumentPrefix();
6877c397f4SPavel Labath llvm::SmallVector<uint8_t, 20> uuid_bytes;
691153dc96SRaphael Isemann if (!UUID::DecodeUUIDBytesFromString(prefix, uuid_bytes).empty())
701153dc96SRaphael Isemann return;
71b5f0feabSGreg Clayton const size_t num_modules = target->GetImages().GetSize();
72b9c1b51eSKate Stone for (size_t i = 0; i < num_modules; ++i) {
73b5f0feabSGreg Clayton ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i));
741153dc96SRaphael Isemann if (!module_sp)
751153dc96SRaphael Isemann continue;
76b5f0feabSGreg Clayton const UUID &module_uuid = module_sp->GetUUID();
771153dc96SRaphael Isemann if (!module_uuid.IsValid())
781153dc96SRaphael Isemann continue;
7993ca36d7SRaphael Isemann request.TryCompleteCurrentArg(module_uuid.GetAsString());
80b5f0feabSGreg Clayton }
81b5f0feabSGreg Clayton }
82