Remove the UUID::GetAsCString() method which required a buffer to save the
UUID string in; added UUID::GetAsString() which returns the uuid string in
a std::string. Updated callers to use the new method.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@181078 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBModule.cpp b/source/API/SBModule.cpp
index 85bece8..3938fa8 100644
--- a/source/API/SBModule.cpp
+++ b/source/API/SBModule.cpp
@@ -180,15 +180,22 @@
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
- static char uuid_string[80];
- const char * uuid_c_string = NULL;
+ static char uuid_string_buffer[80];
+ const char *uuid_c_string = NULL;
+ std::string uuid_string;
ModuleSP module_sp (GetSP ());
if (module_sp)
- uuid_c_string = (const char *)module_sp->GetUUID().GetAsCString(uuid_string, sizeof(uuid_string));
+ uuid_string = module_sp->GetUUID().GetAsString();
+
+ if (!uuid_string.empty())
+ {
+ strncpy (uuid_string_buffer, uuid_string.c_str(), sizeof (uuid_string_buffer));
+ uuid_c_string = uuid_string_buffer;
+ }
if (log)
{
- if (uuid_c_string)
+ if (!uuid_string.empty())
{
StreamString s;
module_sp->GetUUID().Dump (&s);
diff --git a/source/Commands/CommandObjectTarget.cpp b/source/Commands/CommandObjectTarget.cpp
index 6234378..899db4c 100644
--- a/source/Commands/CommandObjectTarget.cpp
+++ b/source/Commands/CommandObjectTarget.cpp
@@ -2928,7 +2928,7 @@
}
else
{
- char uuid_cstr[64];
+ std::string uuid_str;
if (module_spec.GetFileSpec())
module_spec.GetFileSpec().GetPath (path, sizeof(path));
@@ -2936,16 +2936,14 @@
path[0] = '\0';
if (module_spec.GetUUIDPtr())
- module_spec.GetUUID().GetAsCString(uuid_cstr, sizeof(uuid_cstr));
- else
- uuid_cstr[0] = '\0';
+ uuid_str = module_spec.GetUUID().GetAsString();
if (num_matches > 1)
{
result.AppendErrorWithFormat ("multiple modules match%s%s%s%s:\n",
path[0] ? " file=" : "",
path,
- uuid_cstr[0] ? " uuid=" : "",
- uuid_cstr);
+ !uuid_str.empty() ? " uuid=" : "",
+ uuid_str.c_str());
for (size_t i=0; i<num_matches; ++i)
{
if (matching_modules.GetModulePointerAtIndex(i)->GetFileSpec().GetPath (path, sizeof(path)))
@@ -2957,8 +2955,8 @@
result.AppendErrorWithFormat ("no modules were found that match%s%s%s%s.\n",
path[0] ? " file=" : "",
path,
- uuid_cstr[0] ? " uuid=" : "",
- uuid_cstr);
+ !uuid_str.empty() ? " uuid=" : "",
+ uuid_str.c_str());
}
result.SetStatus (eReturnStatusFailed);
}
diff --git a/source/Core/ModuleList.cpp b/source/Core/ModuleList.cpp
index ff5d225..376d046 100644
--- a/source/Core/ModuleList.cpp
+++ b/source/Core/ModuleList.cpp
@@ -651,17 +651,15 @@
if (log)
{
Mutex::Locker locker(m_modules_mutex);
- char uuid_cstr[256];
collection::const_iterator pos, begin = m_modules.begin(), end = m_modules.end();
for (pos = begin; pos != end; ++pos)
{
Module *module = pos->get();
- module->GetUUID().GetAsCString (uuid_cstr, sizeof(uuid_cstr));
const FileSpec &module_file_spec = module->GetFileSpec();
log->Printf ("%s[%u] %s (%s) \"%s\"",
prefix_cstr ? prefix_cstr : "",
(uint32_t)std::distance (begin, pos),
- uuid_cstr,
+ module->GetUUID().GetAsString().c_str(),
module->GetArchitecture().GetArchitectureName(),
module_file_spec.GetPath().c_str());
}
@@ -806,7 +804,6 @@
ModuleList &shared_module_list = GetSharedModuleList ();
Mutex::Locker locker(shared_module_list.m_modules_mutex);
char path[PATH_MAX];
- char uuid_cstr[64];
Error error;
@@ -906,16 +903,14 @@
module_file_spec.GetPath(path, sizeof(path));
if (file_spec.Exists())
{
+ std::string uuid_str;
if (uuid_ptr && uuid_ptr->IsValid())
- uuid_ptr->GetAsCString(uuid_cstr, sizeof (uuid_cstr));
- else
- uuid_cstr[0] = '\0';
-
+ uuid_str = uuid_ptr->GetAsString();
if (arch.IsValid())
{
- if (uuid_cstr[0])
- error.SetErrorStringWithFormat("'%s' does not contain the %s architecture and UUID %s", path, arch.GetArchitectureName(), uuid_cstr);
+ if (!uuid_str.empty())
+ error.SetErrorStringWithFormat("'%s' does not contain the %s architecture and UUID %s", path, arch.GetArchitectureName(), uuid_str.c_str());
else
error.SetErrorStringWithFormat("'%s' does not contain the %s architecture.", path, arch.GetArchitectureName());
}
@@ -985,13 +980,12 @@
}
else
{
+ std::string uuid_str;
if (uuid_ptr && uuid_ptr->IsValid())
- uuid_ptr->GetAsCString(uuid_cstr, sizeof (uuid_cstr));
- else
- uuid_cstr[0] = '\0';
+ uuid_str = uuid_ptr->GetAsString();
- if (uuid_cstr[0])
- error.SetErrorStringWithFormat("cannot locate a module for UUID '%s'", uuid_cstr);
+ if (!uuid_str.empty())
+ error.SetErrorStringWithFormat("cannot locate a module for UUID '%s'", uuid_str.c_str());
else
error.SetErrorStringWithFormat("cannot locate a module");
}
diff --git a/source/Core/UUID.cpp b/source/Core/UUID.cpp
index bfd6c18..e84c13e 100644
--- a/source/Core/UUID.cpp
+++ b/source/Core/UUID.cpp
@@ -14,6 +14,8 @@
#include <ctype.h>
// C++ Includes
+#include <string>
+
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Stream.h"
@@ -62,16 +64,20 @@
return m_uuid;
}
-char *
-UUID::GetAsCString (char *dst, size_t dst_len) const
+std::string
+UUID::GetAsString () const
{
+ std::string result;
+ char buf[64];
const uint8_t *u = (const uint8_t *)GetBytes();
- if (dst_len > snprintf (dst,
- dst_len,
+ if (sizeof (buf) > snprintf (buf,
+ sizeof (buf),
"%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X",
u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7],u[8],u[9],u[10],u[11],u[12],u[13],u[14],u[15]))
- return dst;
- return NULL;
+ {
+ result.append (buf);
+ }
+ return result;
}
void
diff --git a/source/Host/macosx/Symbols.cpp b/source/Host/macosx/Symbols.cpp
index b2e0ca1..138fec7 100644
--- a/source/Host/macosx/Symbols.cpp
+++ b/source/Host/macosx/Symbols.cpp
@@ -364,9 +364,7 @@
CFDictionaryRef uuid_dict = NULL;
if (dict.get())
{
- char uuid_cstr_buf[64];
- const char *uuid_cstr = uuid->GetAsCString (uuid_cstr_buf, sizeof(uuid_cstr_buf));
- CFCString uuid_cfstr (uuid_cstr);
+ CFCString uuid_cfstr (uuid->GetAsString().c_str());
uuid_dict = static_cast<CFDictionaryRef>(::CFDictionaryGetValue (dict.get(), uuid_cfstr.get()));
if (uuid_dict)
{
@@ -719,21 +717,19 @@
}
if (g_dsym_for_uuid_exe_exists)
{
- char uuid_cstr_buffer[64];
+ std::string uuid_str;
char file_path[PATH_MAX];
- uuid_cstr_buffer[0] = '\0';
file_path[0] = '\0';
- const char *uuid_cstr = NULL;
if (uuid_ptr)
- uuid_cstr = uuid_ptr->GetAsCString(uuid_cstr_buffer, sizeof(uuid_cstr_buffer));
+ uuid_str = uuid_ptr->GetAsString();
if (file_spec_ptr)
file_spec_ptr->GetPath(file_path, sizeof(file_path));
StreamString command;
- if (uuid_cstr)
- command.Printf("%s --ignoreNegativeCache --copyExecutable %s", g_dsym_for_uuid_exe_path, uuid_cstr);
+ if (!uuid_str.empty())
+ command.Printf("%s --ignoreNegativeCache --copyExecutable %s", g_dsym_for_uuid_exe_path, uuid_str.c_str());
else if (file_path && file_path[0])
command.Printf("%s --ignoreNegativeCache --copyExecutable %s", g_dsym_for_uuid_exe_path, file_path);
@@ -760,9 +756,9 @@
if (plist.get() && CFGetTypeID (plist.get()) == CFDictionaryGetTypeID ())
{
- if (uuid_cstr)
+ if (!uuid_str.empty())
{
- CFCString uuid_cfstr(uuid_cstr);
+ CFCString uuid_cfstr(uuid_str.c_str());
CFDictionaryRef uuid_dict = (CFDictionaryRef)CFDictionaryGetValue (plist.get(), uuid_cfstr.get());
success = GetModuleSpecInfoFromUUIDDictionary (uuid_dict, module_spec);
}
diff --git a/source/Interpreter/OptionValueUUID.cpp b/source/Interpreter/OptionValueUUID.cpp
index 0e3c9cb..340f1e5 100644
--- a/source/Interpreter/OptionValueUUID.cpp
+++ b/source/Interpreter/OptionValueUUID.cpp
@@ -91,7 +91,6 @@
const size_t num_modules = target->GetImages().GetSize();
if (num_modules > 0)
{
- char uuid_cstr[64];
UUID::ValueType uuid_bytes;
const size_t num_bytes_decoded = UUID::DecodeUUIDBytesFromCString(s, uuid_bytes, NULL);
for (size_t i=0; i<num_modules; ++i)
@@ -109,8 +108,10 @@
add_uuid = ::memcmp(module_uuid.GetBytes(), uuid_bytes, num_bytes_decoded) == 0;
if (add_uuid)
{
- if (module_uuid.GetAsCString(uuid_cstr, sizeof(uuid_cstr)))
- matches.AppendString(uuid_cstr);
+ std::string uuid_str;
+ uuid_str = module_uuid.GetAsString();
+ if (!uuid_str.empty())
+ matches.AppendString(uuid_str.c_str());
}
}
}
diff --git a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index 12ded3c..5913b32 100644
--- a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -720,11 +720,9 @@
Stream *s = &process->GetTarget().GetDebugger().GetOutputStream();
if (s)
{
- char memory_module_uuidbuf[64];
- char exe_module_uuidbuf[64];
s->Printf ("warning: Host-side kernel file has Mach-O UUID of %s but remote kernel has a UUID of %s -- a mismatched kernel file will result in a poor debugger experience.\n",
- exe_module->GetUUID().GetAsCString(exe_module_uuidbuf, sizeof (exe_module_uuidbuf)),
- m_uuid.GetAsCString(memory_module_uuidbuf, sizeof (memory_module_uuidbuf)));
+ exe_module->GetUUID().GetAsString().c_str(),
+ m_uuid.GetAsString().c_str());
s->Flush ();
}
}
@@ -770,8 +768,7 @@
Stream *s = &target.GetDebugger().GetOutputStream();
if (s)
{
- char uuidbuf[64];
- s->Printf ("Kernel UUID: %s\n", m_memory_module_sp->GetUUID().GetAsCString(uuidbuf, sizeof (uuidbuf)));
+ s->Printf ("Kernel UUID: %s\n", m_memory_module_sp->GetUUID().GetAsString().c_str());
s->Printf ("Load Address: 0x%" PRIx64 "\n", m_load_address);
}
}
@@ -872,9 +869,8 @@
Stream *s = &target.GetDebugger().GetOutputStream();
if (s)
{
- char uuidbuf[64];
s->Printf ("warning: Can't find binary/dSYM for %s (%s)\n",
- m_name.c_str(), m_uuid.GetAsCString(uuidbuf, sizeof (uuidbuf)));
+ m_name.c_str(), m_uuid.GetAsString().c_str());
}
}
diff --git a/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp b/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
index c04ad78..4b271b4 100644
--- a/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
+++ b/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
@@ -208,16 +208,15 @@
lldb_private::UUID dsym_uuid;
if (dsym_objfile_sp->GetUUID(&dsym_uuid))
{
- char uuid_cstr_buf[64];
- const char *uuid_cstr = dsym_uuid.GetAsCString (uuid_cstr_buf, sizeof(uuid_cstr_buf));
- if (uuid_cstr)
+ std::string uuid_str = dsym_uuid.GetAsString ();
+ if (!uuid_str.empty())
{
char *resources = strstr (dsym_path, "/Contents/Resources/");
if (resources)
{
char dsym_uuid_plist_path[PATH_MAX];
resources[strlen("/Contents/Resources/")] = '\0';
- snprintf(dsym_uuid_plist_path, sizeof(dsym_uuid_plist_path), "%s%s.plist", dsym_path, uuid_cstr);
+ snprintf(dsym_uuid_plist_path, sizeof(dsym_uuid_plist_path), "%s%s.plist", dsym_path, uuid_str.c_str());
FileSpec dsym_uuid_plist_spec(dsym_uuid_plist_path, false);
if (dsym_uuid_plist_spec.Exists())
{