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 //===----------------------------------------------------------------------===//
11 // File: MICmnLLDBProxySBValue.cpp
13 // Overview: CMICmnLLDBProxySBValue implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
24 // Third Party Headers:
25 #include <lldb/API/SBError.h>
28 #include "MICmnLLDBProxySBValue.h"
29 #include "MIUtilString.h"
30 #include "MICmnLLDBDebugSessionInfo.h"
32 //++ ------------------------------------------------------------------------------------
33 // Details: Retrieve the numerical value from the SBValue object. If the function fails
34 // it could indicate the SBValue object does not represent an internal type.
35 // Type: Static method.
36 // Args: vrValue - (R) The SBValue object to get a value from.
37 // vwValue - (W) The numerical value.
38 // Return: MIstatus::success - Functionality succeeded.
39 // MIstatus::failure - Functionality failed.
43 CMICmnLLDBProxySBValue::GetValueAsUnsigned(const lldb::SBValue &vrValue, MIuint64 &vwValue)
45 lldb::SBValue &rValue = const_cast<lldb::SBValue &>(vrValue);
46 bool bCompositeType = true;
47 MIuint64 nFailValue = 0;
48 MIuint64 nValue = rValue.GetValueAsUnsigned(nFailValue);
49 if (nValue == nFailValue)
51 nFailValue = 5; // Some arbitary number
52 nValue = rValue.GetValueAsUnsigned(nFailValue);
53 if (nValue != nFailValue)
55 bCompositeType = false;
61 bCompositeType = false;
65 return (bCompositeType ? MIstatus::failure : MIstatus::success);
68 //++ ------------------------------------------------------------------------------------
69 // Details: Retrieve the numerical value from the SBValue object. If the function fails
70 // it could indicate the SBValue object does not represent an internal type.
71 // Type: Static method.
72 // Args: vrValue - (R) The SBValue object to get a value from.
73 // vwValue - (W) The numerical value.
74 // Return: MIstatus::success - Functionality succeeded.
75 // MIstatus::failure - Functionality failed.
79 CMICmnLLDBProxySBValue::GetValueAsSigned(const lldb::SBValue &vrValue, MIint64 &vwValue)
81 lldb::SBValue &rValue = const_cast<lldb::SBValue &>(vrValue);
82 bool bCompositeType = true;
83 MIuint64 nFailValue = 0;
84 MIuint64 nValue = rValue.GetValueAsSigned(nFailValue);
85 if (nValue == nFailValue)
87 nFailValue = 5; // Some arbitary number
88 nValue = rValue.GetValueAsSigned(nFailValue);
89 if (nValue != nFailValue)
91 bCompositeType = false;
97 bCompositeType = false;
101 return (bCompositeType ? MIstatus::failure : MIstatus::success);
104 //++ ------------------------------------------------------------------------------------
105 // Details: Retrieve the NUL terminated string from the SBValue object if it of the type
107 // Type: Static method.
108 // Args: vrValue - (R) The SBValue object to get a value from.
109 // vwCString - (W) The text data '\0' terminated.
110 // Return: MIstatus::success - Functionality succeeded.
111 // MIstatus::failure - Functionality failed, not suitable type.
115 CMICmnLLDBProxySBValue::GetCString(const lldb::SBValue &vrValue, CMIUtilString &vwCString)
117 lldb::SBValue &rValue = const_cast<lldb::SBValue &>(vrValue);
118 const MIchar *pCType = rValue.GetTypeName();
119 if (pCType == nullptr)
120 return MIstatus::failure;
122 const MIchar *pType = "unsigned char *";
123 if (!CMIUtilString::Compare(pCType, pType))
124 return MIstatus::failure;
126 const CMIUtilString strAddr(rValue.GetValue());
128 if (!strAddr.ExtractNumber(nNum))
129 return MIstatus::failure;
131 CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
132 lldb::SBProcess &rProcess = rSessionInfo.m_lldbProcess;
133 MIuint nBufferSize = 64;
134 bool bNeedResize = false;
135 MIchar *pBuffer = static_cast<MIchar *>(::malloc(nBufferSize));
139 const size_t nReadSize = rProcess.ReadCStringFromMemory((lldb::addr_t)nNum, pBuffer, nBufferSize, error);
140 if (nReadSize == (nBufferSize - 1))
143 nBufferSize = nBufferSize << 1;
144 pBuffer = static_cast<MIchar *>(::realloc(pBuffer, nBufferSize));
148 } while (bNeedResize);
151 free((void *)pBuffer);
153 return MIstatus::success;