summaryrefslogtreecommitdiffstats
path: root/lldb/tools/lldb-mi/MIUtilString.cpp
diff options
context:
space:
mode:
authorIlia K <ki.stfu@gmail.com>2015-02-13 18:42:25 +0000
committerIlia K <ki.stfu@gmail.com>2015-02-13 18:42:25 +0000
commitb4a110f051b623f20808c57aa7b07400768c51b3 (patch)
treec97804f9ab4a6178f924882af9cdf6bf3699b06a /lldb/tools/lldb-mi/MIUtilString.cpp
parenta4897fe79c9db88d9eaf0bf787a64c36ff2a609e (diff)
downloadbcm5719-llvm-b4a110f051b623f20808c57aa7b07400768c51b3.tar.gz
bcm5719-llvm-b4a110f051b623f20808c57aa7b07400768c51b3.zip
Fix -data-read-memory-bytes command (MI)
Summary: * Add IsHexadecimalNumber method to CMIUtilString (MI) * Add number format (dec,hex,auto) to CMICmdArgValNumber (MI) * Fix -data-read-memory-bytes to pass address in hex format (MI) * Fix output begin/end/offset fields format in -data-read-memory-bytes * Fix CMICmdArgValNumber::ExtractNumber to extract 64bit value * + tests All tests passed on OS X Reviewers: abidh, zturner, clayborg Reviewed By: clayborg Subscribers: lldb-commits, zturner, clayborg, abidh Differential Revision: http://reviews.llvm.org/D7610 llvm-svn: 229132
Diffstat (limited to 'lldb/tools/lldb-mi/MIUtilString.cpp')
-rw-r--r--lldb/tools/lldb-mi/MIUtilString.cpp38
1 files changed, 30 insertions, 8 deletions
diff --git a/lldb/tools/lldb-mi/MIUtilString.cpp b/lldb/tools/lldb-mi/MIUtilString.cpp
index 08540926901..70294285d9f 100644
--- a/lldb/tools/lldb-mi/MIUtilString.cpp
+++ b/lldb/tools/lldb-mi/MIUtilString.cpp
@@ -23,7 +23,7 @@
#include <memory> // std::unique_ptr
#include <stdarg.h> // va_list, va_start, var_end
#include <sstream> // std::stringstream
-#include <string.h> // for strcpy
+#include <string.h> // for strncmp
#include <limits.h> // for ULONG_MAX
// In-house headers:
@@ -395,6 +395,28 @@ CMIUtilString::IsNumber(void) const
}
//++ ------------------------------------------------------------------------------------
+// Details: Check if *this string is a hexadecimal number.
+// Type: Method.
+// Args: None.
+// Return: bool - True = yes number, false not a number.
+// Throws: None.
+//--
+bool
+CMIUtilString::IsHexadecimalNumber(void) const
+{
+ // Compare '0x..' prefix
+ if ((strncmp(c_str(), "0x", 2) != 0) && (strncmp(c_str(), "0X", 2) != 0))
+ return false;
+
+ // Skip '0x..' prefix
+ const MIint nPos = find_first_not_of("01234567890ABCDEFabcedf", 2);
+ if (nPos != (MIint)std::string::npos)
+ return false;
+
+ return true;
+}
+
+//++ ------------------------------------------------------------------------------------
// Details: Extract the number from the string. The number can be either a hexadecimal or
// natural number. It cannot contain other non-numeric characters.
// Type: Method.
@@ -433,16 +455,16 @@ CMIUtilString::ExtractNumberFromHexadecimal(MIint64 &vwrNumber) const
{
vwrNumber = 0;
- const MIint nPos = find_first_not_of("x01234567890ABCDEFabcedf");
+ const MIint nPos = find_first_not_of("xX01234567890ABCDEFabcedf");
if (nPos != (MIint)std::string::npos)
return false;
- const MIint64 nNum = ::strtoul(this->c_str(), nullptr, 16);
- if (nNum != LONG_MAX)
- {
- vwrNumber = nNum;
- return true;
- }
+ errno = 0;
+ const MIuint64 nNum = ::strtoull(this->c_str(), nullptr, 16);
+ if (errno == ERANGE)
+ return false;
+
+ vwrNumber = static_cast<MIint64>(nNum);
return true;
}
OpenPOWER on IntegriCloud