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 "MICmnLLDBProxySBValue.h"
17 #include "MIUtilString.h"
18 #include "MICmnLLDBDebugSessionInfo.h"
20 //++ ------------------------------------------------------------------------------------
21 // Details: Retrieve the numerical value from the SBValue object. If the function fails
22 // it could indicate the SBValue object does not represent an internal type.
23 // Type: Static method.
24 // Args: vrValue - (R) The SBValue object to get a value from.
25 // vwValue - (W) The numerical value.
26 // Return: MIstatus::success - Functionality succeeded.
27 // MIstatus::failure - Functionality failed.
31 CMICmnLLDBProxySBValue::GetValueAsUnsigned(const lldb::SBValue &vrValue, MIuint64 &vwValue)
33 lldb::SBValue &rValue = const_cast<lldb::SBValue &>(vrValue);
34 bool bCompositeType = true;
35 MIuint64 nFailValue = 0;
36 MIuint64 nValue = rValue.GetValueAsUnsigned(nFailValue);
37 if (nValue == nFailValue)
39 nFailValue = 5; // Some arbitary number
40 nValue = rValue.GetValueAsUnsigned(nFailValue);
41 if (nValue != nFailValue)
43 bCompositeType = false;
49 bCompositeType = false;
53 return (bCompositeType ? MIstatus::failure : MIstatus::success);
56 //++ ------------------------------------------------------------------------------------
57 // Details: Retrieve the numerical value from the SBValue object. If the function fails
58 // it could indicate the SBValue object does not represent an internal type.
59 // Type: Static method.
60 // Args: vrValue - (R) The SBValue object to get a value from.
61 // vwValue - (W) The numerical value.
62 // Return: MIstatus::success - Functionality succeeded.
63 // MIstatus::failure - Functionality failed.
67 CMICmnLLDBProxySBValue::GetValueAsSigned(const lldb::SBValue &vrValue, MIint64 &vwValue)
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)
75 nFailValue = 5; // Some arbitary number
76 nValue = rValue.GetValueAsSigned(nFailValue);
77 if (nValue != nFailValue)
79 bCompositeType = false;
85 bCompositeType = false;
89 return (bCompositeType ? MIstatus::failure : MIstatus::success);
92 //++ ------------------------------------------------------------------------------------
93 // Details: Retrieve the NUL terminated string from the SBValue object if it of the type
95 // Type: Static method.
96 // Args: vrValue - (R) The SBValue object to get a value from.
97 // vwCString - (W) The text data '\0' terminated.
98 // Return: MIstatus::success - Functionality succeeded.
99 // MIstatus::failure - Functionality failed, not suitable type.
103 CMICmnLLDBProxySBValue::GetCString(const lldb::SBValue &vrValue, CMIUtilString &vwCString)
105 lldb::SBValue &rValue = const_cast<lldb::SBValue &>(vrValue);
106 const char *pCType = rValue.GetTypeName();
107 if (pCType == nullptr)
108 return MIstatus::failure;
110 const char *pType = "unsigned char *";
111 if (!CMIUtilString::Compare(pCType, pType))
112 return MIstatus::failure;
114 const CMIUtilString strAddr(rValue.GetValue());
116 if (!strAddr.ExtractNumber(nNum))
117 return MIstatus::failure;
119 CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
120 lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
121 MIuint nBufferSize = 64;
122 bool bNeedResize = false;
123 char *pBuffer = static_cast<char *>(::malloc(nBufferSize));
127 const size_t nReadSize = sbProcess.ReadCStringFromMemory((lldb::addr_t)nNum, pBuffer, nBufferSize, error);
128 if (nReadSize == (nBufferSize - 1))
131 nBufferSize = nBufferSize << 1;
132 pBuffer = static_cast<char *>(::realloc(pBuffer, nBufferSize));
136 } while (bNeedResize);
139 free((void *)pBuffer);
141 return MIstatus::success;