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 | |
Deepak Panickal | 7f6edd5 | 2014-08-08 17:39:47 +0000 | [diff] [blame] | 10 | #include <stdlib.h> |
| 11 | |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 12 | // Third Party Headers: |
Greg Clayton | ee3626e | 2015-01-20 00:04:26 +0000 | [diff] [blame] | 13 | #include "lldb/API/SBError.h" |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 14 | |
| 15 | // In-house headers: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 16 | #include "MICmnLLDBDebugSessionInfo.h" |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 17 | #include "MICmnLLDBProxySBValue.h" |
| 18 | #include "MIUtilString.h" |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 19 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 20 | //++ |
| 21 | //------------------------------------------------------------------------------------ |
| 22 | // Details: Retrieve the numerical value from the SBValue object. If the |
| 23 | // function fails |
| 24 | // it could indicate the SBValue object does not represent an internal |
| 25 | // type. |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 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. |
| 31 | // Throws: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 32 | //-- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | bool CMICmnLLDBProxySBValue::GetValueAsUnsigned(const lldb::SBValue &vrValue, |
| 34 | MIuint64 &vwValue) { |
| 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; |
| 44 | vwValue = nValue; |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 45 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 46 | } else { |
| 47 | bCompositeType = false; |
| 48 | vwValue = nValue; |
| 49 | } |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | return (bCompositeType ? MIstatus::failure : MIstatus::success); |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | //++ |
| 55 | //------------------------------------------------------------------------------------ |
| 56 | // Details: Retrieve the numerical value from the SBValue object. If the |
| 57 | // function fails |
| 58 | // it could indicate the SBValue object does not represent an internal |
| 59 | // type. |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 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. |
| 65 | // Throws: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 66 | //-- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | bool CMICmnLLDBProxySBValue::GetValueAsSigned(const lldb::SBValue &vrValue, |
| 68 | 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) { |
| 74 | nFailValue = 5; // Some arbitrary number |
| 75 | nValue = rValue.GetValueAsSigned(nFailValue); |
| 76 | if (nValue != nFailValue) { |
| 77 | bCompositeType = false; |
| 78 | vwValue = nValue; |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 79 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | } else { |
| 81 | bCompositeType = false; |
| 82 | vwValue = nValue; |
| 83 | } |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 84 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | return (bCompositeType ? MIstatus::failure : MIstatus::success); |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | //++ |
| 89 | //------------------------------------------------------------------------------------ |
| 90 | // Details: Retrieve the NUL terminated string from the SBValue object if it of |
| 91 | // the type |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 92 | // unsigned char *. |
| 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. |
| 98 | // Throws: None. |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 99 | //-- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 106 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | const char *pType = "unsigned char *"; |
| 108 | if (!CMIUtilString::Compare(pCType, pType)) |
| 109 | return MIstatus::failure; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 110 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 111 | const CMIUtilString strAddr(rValue.GetValue()); |
| 112 | MIint64 nNum = 0; |
| 113 | if (!strAddr.ExtractNumber(nNum)) |
| 114 | return MIstatus::failure; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 115 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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)); |
| 122 | do { |
| 123 | lldb::SBError error; |
| 124 | const size_t nReadSize = sbProcess.ReadCStringFromMemory( |
| 125 | (lldb::addr_t)nNum, pBuffer, nBufferSize, error); |
| 126 | if (nReadSize == (nBufferSize - 1)) { |
| 127 | bNeedResize = true; |
| 128 | nBufferSize = nBufferSize << 1; |
| 129 | pBuffer = static_cast<char *>(::realloc(pBuffer, nBufferSize)); |
| 130 | } else |
| 131 | bNeedResize = false; |
| 132 | } while (bNeedResize); |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 133 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 134 | vwCString = pBuffer; |
| 135 | free((void *)pBuffer); |
Zachary Turner | 1d6af02 | 2014-11-17 18:06:21 +0000 | [diff] [blame] | 136 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 137 | return MIstatus::success; |
Deepak Panickal | 6f9c468 | 2014-05-16 10:51:01 +0000 | [diff] [blame] | 138 | } |