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.
42 bool CMICmnLLDBProxySBValue::GetValueAsUnsigned( const lldb::SBValue & vrValue, MIuint64 & vwValue )
44 lldb::SBValue & rValue = const_cast< lldb::SBValue & >( vrValue );
45 bool bCompositeType = true;
46 MIuint64 nFailValue = 0;
47 MIuint64 nValue = rValue.GetValueAsUnsigned( nFailValue );
48 if( nValue == nFailValue )
50 nFailValue = 5; // Some arbitary number
51 nValue = rValue.GetValueAsUnsigned( nFailValue );
52 if( nValue != nFailValue )
54 bCompositeType = false;
60 bCompositeType = false;
64 return (bCompositeType ? MIstatus::failure : MIstatus::success);
67 //++ ------------------------------------------------------------------------------------
68 // Details: Retrieve the numerical value from the SBValue object. If the function fails
69 // it could indicate the SBValue object does not represent an internal type.
70 // Type: Static method.
71 // Args: vrValue - (R) The SBValue object to get a value from.
72 // vwValue - (W) The numerical value.
73 // Return: MIstatus::success - Functionality succeeded.
74 // MIstatus::failure - Functionality failed.
77 bool CMICmnLLDBProxySBValue::GetValueAsSigned( const lldb::SBValue & vrValue, MIint64 & vwValue )
79 lldb::SBValue & rValue = const_cast< lldb::SBValue & >( vrValue );
80 bool bCompositeType = true;
81 MIuint64 nFailValue = 0;
82 MIuint64 nValue = rValue.GetValueAsSigned( nFailValue );
83 if( nValue == nFailValue )
85 nFailValue = 5; // Some arbitary number
86 nValue = rValue.GetValueAsSigned( nFailValue );
87 if( nValue != nFailValue )
89 bCompositeType = false;
95 bCompositeType = false;
99 return (bCompositeType ? MIstatus::failure : MIstatus::success);
102 //++ ------------------------------------------------------------------------------------
103 // Details: Retrieve the NUL terminated string from the SBValue object if it of the type
105 // Type: Static method.
106 // Args: vrValue - (R) The SBValue object to get a value from.
107 // vwCString - (W) The text data '\0' terminated.
108 // Return: MIstatus::success - Functionality succeeded.
109 // MIstatus::failure - Functionality failed, not suitable type.
112 bool CMICmnLLDBProxySBValue::GetCString( const lldb::SBValue & vrValue, CMIUtilString & vwCString )
114 lldb::SBValue & rValue = const_cast< lldb::SBValue & >( vrValue );
115 const MIchar * pCType = rValue.GetTypeName();
116 if( pCType == nullptr )
117 return MIstatus::failure;
119 const MIchar * pType = "unsigned char *";
120 if( !CMIUtilString::Compare( pCType, pType ) )
121 return MIstatus::failure;
123 const CMIUtilString strAddr( rValue.GetValue() );
125 if( !strAddr.ExtractNumber( nNum ) )
126 return MIstatus::failure;
128 CMICmnLLDBDebugSessionInfo & rSessionInfo( CMICmnLLDBDebugSessionInfo::Instance() );
129 lldb::SBProcess & rProcess = rSessionInfo.m_lldbProcess;
130 MIuint nBufferSize = 64;
131 bool bNeedResize = false;
132 MIchar * pBuffer = static_cast< MIchar * >( ::malloc( nBufferSize ) );
136 const size_t nReadSize = rProcess.ReadCStringFromMemory( (lldb::addr_t) nNum, pBuffer, nBufferSize, error );
137 if( nReadSize == (nBufferSize - 1) )
140 nBufferSize = nBufferSize << 1;
141 pBuffer = static_cast< MIchar * >( ::realloc( pBuffer, nBufferSize ) );
146 while( bNeedResize );
149 free( (void *) pBuffer );
151 return MIstatus::success;