Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 1 | //===-- MICmnLLDBProxySBValue.cpp -------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | //++ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 11 | // File: MICmnLLDBProxySBValue.cpp |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 12 | // |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 13 | // Overview: CMICmnLLDBProxySBValue implementation. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 14 | // |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 15 | // Environment: Compilers: Visual C++ 12. |
| 16 | // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 |
| 17 | // Libraries: See MIReadmetxt. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 18 | // |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 19 | // Copyright: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 20 | //-- |
| 21 | |
Deepak Panickal | 7f6edd5 | 2014-08-08 17:39:47 +0000 | [diff] [blame] | 22 | #include <stdlib.h> |
| 23 | |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 24 | // Third Party Headers: |
| 25 | #include <lldb/API/SBError.h> |
| 26 | |
| 27 | // In-house headers: |
| 28 | #include "MICmnLLDBProxySBValue.h" |
| 29 | #include "MIUtilString.h" |
| 30 | #include "MICmnLLDBDebugSessionInfo.h" |
| 31 | |
| 32 | //++ ------------------------------------------------------------------------------------ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 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. |
| 40 | // Throws: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 41 | //-- |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 42 | bool |
| 43 | CMICmnLLDBProxySBValue::GetValueAsUnsigned(const lldb::SBValue &vrValue, MIuint64 &vwValue) |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 44 | { |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 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) |
| 50 | { |
| 51 | nFailValue = 5; // Some arbitary number |
| 52 | nValue = rValue.GetValueAsUnsigned(nFailValue); |
| 53 | if (nValue != nFailValue) |
| 54 | { |
| 55 | bCompositeType = false; |
| 56 | vwValue = nValue; |
| 57 | } |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | bCompositeType = false; |
| 62 | vwValue = nValue; |
| 63 | } |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 64 | |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 65 | return (bCompositeType ? MIstatus::failure : MIstatus::success); |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | //++ ------------------------------------------------------------------------------------ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 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. |
| 76 | // Throws: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 77 | //-- |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 78 | bool |
| 79 | CMICmnLLDBProxySBValue::GetValueAsSigned(const lldb::SBValue &vrValue, MIint64 &vwValue) |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 80 | { |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 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) |
| 86 | { |
| 87 | nFailValue = 5; // Some arbitary number |
| 88 | nValue = rValue.GetValueAsSigned(nFailValue); |
| 89 | if (nValue != nFailValue) |
| 90 | { |
| 91 | bCompositeType = false; |
| 92 | vwValue = nValue; |
| 93 | } |
| 94 | } |
| 95 | else |
| 96 | { |
| 97 | bCompositeType = false; |
| 98 | vwValue = nValue; |
| 99 | } |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 100 | |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 101 | return (bCompositeType ? MIstatus::failure : MIstatus::success); |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | //++ ------------------------------------------------------------------------------------ |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 105 | // Details: Retrieve the NUL terminated string from the SBValue object if it of the type |
| 106 | // unsigned char *. |
| 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. |
| 112 | // Throws: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 113 | //-- |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 114 | bool |
| 115 | CMICmnLLDBProxySBValue::GetCString(const lldb::SBValue &vrValue, CMIUtilString &vwCString) |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 116 | { |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 117 | lldb::SBValue &rValue = const_cast<lldb::SBValue &>(vrValue); |
| 118 | const MIchar *pCType = rValue.GetTypeName(); |
| 119 | if (pCType == nullptr) |
| 120 | return MIstatus::failure; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 121 | |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 122 | const MIchar *pType = "unsigned char *"; |
| 123 | if (!CMIUtilString::Compare(pCType, pType)) |
| 124 | return MIstatus::failure; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 125 | |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 126 | const CMIUtilString strAddr(rValue.GetValue()); |
| 127 | MIint64 nNum = 0; |
| 128 | if (!strAddr.ExtractNumber(nNum)) |
| 129 | return MIstatus::failure; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 130 | |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 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)); |
| 136 | do |
| 137 | { |
| 138 | lldb::SBError error; |
| 139 | const size_t nReadSize = rProcess.ReadCStringFromMemory((lldb::addr_t)nNum, pBuffer, nBufferSize, error); |
| 140 | if (nReadSize == (nBufferSize - 1)) |
| 141 | { |
| 142 | bNeedResize = true; |
| 143 | nBufferSize = nBufferSize << 1; |
| 144 | pBuffer = static_cast<MIchar *>(::realloc(pBuffer, nBufferSize)); |
| 145 | } |
| 146 | else |
| 147 | bNeedResize = false; |
| 148 | } while (bNeedResize); |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 149 | |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame^] | 150 | vwCString = pBuffer; |
| 151 | free((void *)pBuffer); |
| 152 | |
| 153 | return MIstatus::success; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 154 | } |