1 //===-- MICmnLLDBProxySBValue.cpp -------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // Third Party Headers:
13 #include "lldb/API/SBError.h"
16 #include "MICmnLLDBDebugSessionInfo.h"
17 #include "MICmnLLDBProxySBValue.h"
18 #include "MIUtilString.h"
21 //------------------------------------------------------------------------------------
22 // Details: Retrieve the numerical value from the SBValue object. If the
24 // it could indicate the SBValue object does not represent an internal
26 // Type: Static method.
27 // Args: vrValue - (R) The SBValue object to get a value from.
28 // vwValue - (W) The numerical value.
29 // Return: MIstatus::success - Functionality succeeded.
30 // MIstatus::failure - Functionality failed.
33 bool CMICmnLLDBProxySBValue::GetValueAsUnsigned(const lldb::SBValue &vrValue,
35 lldb::SBValue &rValue = const_cast<lldb::SBValue &>(vrValue);
36 bool bCompositeType = true;
37 MIuint64 nFailValue = 0;
38 MIuint64 nValue = rValue.GetValueAsUnsigned(nFailValue);
39 if (nValue == nFailValue) {
40 nFailValue = 5; // Some arbitrary number
41 nValue = rValue.GetValueAsUnsigned(nFailValue);
42 if (nValue != nFailValue) {
43 bCompositeType = false;
47 bCompositeType = false;
51 return (bCompositeType ? MIstatus::failure : MIstatus::success);
55 //------------------------------------------------------------------------------------
56 // Details: Retrieve the numerical value from the SBValue object. If the
58 // it could indicate the SBValue object does not represent an internal
60 // Type: Static method.
61 // Args: vrValue - (R) The SBValue object to get a value from.
62 // vwValue - (W) The numerical value.
63 // Return: MIstatus::success - Functionality succeeded.
64 // MIstatus::failure - Functionality failed.
67 bool CMICmnLLDBProxySBValue::GetValueAsSigned(const lldb::SBValue &vrValue,
69 lldb::SBValue &rValue = const_cast<lldb::SBValue &>(vrValue);
70 bool bCompositeType = true;
71 MIuint64 nFailValue = 0;
72 MIuint64 nValue = rValue.GetValueAsSigned(nFailValue);
73 if (nValue == nFailValue) {
74 nFailValue = 5; // Some arbitrary number
75 nValue = rValue.GetValueAsSigned(nFailValue);
76 if (nValue != nFailValue) {
77 bCompositeType = false;
81 bCompositeType = false;
85 return (bCompositeType ? MIstatus::failure : MIstatus::success);
89 //------------------------------------------------------------------------------------
90 // Details: Retrieve the NUL terminated string from the SBValue object if it of
93 // Type: Static method.
94 // Args: vrValue - (R) The SBValue object to get a value from.
95 // vwCString - (W) The text data '\0' terminated.
96 // Return: MIstatus::success - Functionality succeeded.
97 // MIstatus::failure - Functionality failed, not suitable type.
100 bool CMICmnLLDBProxySBValue::GetCString(const lldb::SBValue &vrValue,
101 CMIUtilString &vwCString) {
102 lldb::SBValue &rValue = const_cast<lldb::SBValue &>(vrValue);
103 const char *pCType = rValue.GetTypeName();
104 if (pCType == nullptr)
105 return MIstatus::failure;
107 const char *pType = "unsigned char *";
108 if (!CMIUtilString::Compare(pCType, pType))
109 return MIstatus::failure;
111 const CMIUtilString strAddr(rValue.GetValue());
113 if (!strAddr.ExtractNumber(nNum))
114 return MIstatus::failure;
116 CMICmnLLDBDebugSessionInfo &rSessionInfo(
117 CMICmnLLDBDebugSessionInfo::Instance());
118 lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
119 MIuint nBufferSize = 64;
120 bool bNeedResize = false;
121 char *pBuffer = static_cast<char *>(::malloc(nBufferSize));
124 const size_t nReadSize = sbProcess.ReadCStringFromMemory(
125 (lldb::addr_t)nNum, pBuffer, nBufferSize, error);
126 if (nReadSize == (nBufferSize - 1)) {
128 nBufferSize = nBufferSize << 1;
129 pBuffer = static_cast<char *>(::realloc(pBuffer, nBufferSize));
132 } while (bNeedResize);
135 free((void *)pBuffer);
137 return MIstatus::success;