1 //===-- OptionValueFormat.cpp ---------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Interpreter/OptionValueFormat.h" 10 11 #include "lldb/DataFormatters/FormatManager.h" 12 #include "lldb/Interpreter/OptionArgParser.h" 13 #include "lldb/Utility/Stream.h" 14 15 using namespace lldb; 16 using namespace lldb_private; 17 18 void OptionValueFormat::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 19 uint32_t dump_mask) { 20 if (dump_mask & eDumpOptionType) 21 strm.Printf("(%s)", GetTypeAsCString()); 22 if (dump_mask & eDumpOptionValue) { 23 if (dump_mask & eDumpOptionType) 24 strm.PutCString(" = "); 25 strm.PutCString(FormatManager::GetFormatAsCString(m_current_value)); 26 } 27 } 28 29 llvm::json::Value OptionValueFormat::ToJSON(const ExecutionContext *exe_ctx) { 30 return FormatManager::GetFormatAsCString(m_current_value); 31 } 32 33 Status OptionValueFormat::SetValueFromString(llvm::StringRef value, 34 VarSetOperationType op) { 35 Status error; 36 switch (op) { 37 case eVarSetOperationClear: 38 Clear(); 39 NotifyValueChanged(); 40 break; 41 42 case eVarSetOperationReplace: 43 case eVarSetOperationAssign: { 44 Format new_format; 45 error = OptionArgParser::ToFormat(value.str().c_str(), new_format, nullptr); 46 if (error.Success()) { 47 m_value_was_set = true; 48 m_current_value = new_format; 49 NotifyValueChanged(); 50 } 51 } break; 52 53 case eVarSetOperationInsertBefore: 54 case eVarSetOperationInsertAfter: 55 case eVarSetOperationRemove: 56 case eVarSetOperationAppend: 57 case eVarSetOperationInvalid: 58 error = OptionValue::SetValueFromString(value, op); 59 break; 60 } 61 return error; 62 } 63