CommandObjectProcess was recently changed to automatically use the platform
to launch a process for debugging. Since this isn't supported on all platforms,
we need to do what we used to do if this isn't supported. I added:
bool
Platform::CanDebugProcess ();
This will get checked before trying to launch a process for debugging and then
fall back to launching the process through the current host debugger. This
should solve the issue for linux and keep the platform code clean.
Centralized logging code for logging errors, warnings and logs when reporting
things for modules or symbol files. Both lldb_private::Module and
lldb_private::SymbolFile now have the following member functions:
void
LogMessage (Log *log, const char *format, ...);
void
ReportWarning (const char *format, ...);
void
ReportError (const char *format, ...);
These will all output the module name and object (if any) such as:
"error: lldb.so ...."
"warning: my_archive.a(foo.o) ...."
This will keep the output consistent and stop a lot of logging calls from
having to try and output all of the information that uniquely identifies
a module or symbol file. Many places in the code were grabbing the path to the
object file manually and if the module represented a .o file in an archive, we
would see log messages like:
error: foo.a - some error happened
llvm-svn: 145219
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 64677e0..cfe61ef 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -11,6 +11,7 @@
#include "lldb/Core/Log.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/RegularExpression.h"
+#include "lldb/Core/StreamString.h"
#include "lldb/Core/Timer.h"
#include "lldb/lldb-private-log.h"
#include "lldb/Symbol/ObjectFile.h"
@@ -578,16 +579,28 @@
}
void
-Module::GetDescription (Stream *s)
+Module::GetDescription (Stream *s, lldb::DescriptionLevel level)
{
Mutex::Locker locker (m_mutex);
- if (m_arch.IsValid())
- s->Printf("(%s) ", m_arch.GetArchitectureName());
+ if (level >= eDescriptionLevelFull)
+ {
+ if (m_arch.IsValid())
+ s->Printf("(%s) ", m_arch.GetArchitectureName());
+ }
- char path[PATH_MAX];
- if (m_file.GetPath(path, sizeof(path)))
- s->PutCString(path);
+ if (level == eDescriptionLevelBrief)
+ {
+ const char *filename = m_file.GetFilename().GetCString();
+ if (filename)
+ s->PutCString (filename);
+ }
+ else
+ {
+ char path[PATH_MAX];
+ if (m_file.GetPath(path, sizeof(path)))
+ s->PutCString(path);
+ }
const char *object_name = m_object_name.GetCString();
if (object_name)
@@ -595,6 +608,48 @@
}
void
+Module::ReportError (const char *format, ...)
+{
+ StreamString module_description;
+ GetDescription(&module_description, lldb::eDescriptionLevelBrief);
+ ::fprintf (stderr, "error: %s ", module_description.GetString().c_str());
+
+ va_list args;
+ va_start (args, format);
+ vfprintf (stderr, format, args);
+ va_end (args);
+}
+
+void
+Module::ReportWarning (const char *format, ...)
+{
+ StreamString module_description;
+ GetDescription(&module_description, lldb::eDescriptionLevelBrief);
+ ::fprintf (stderr, "warning: %s ", module_description.GetString().c_str());
+
+ va_list args;
+ va_start (args, format);
+ vfprintf (stderr, format, args);
+ va_end (args);
+}
+
+void
+Module::LogMessage (Log *log, const char *format, ...)
+{
+ if (log)
+ {
+ StreamString log_message;
+ GetDescription(&log_message, lldb::eDescriptionLevelBrief);
+ log_message.PutCString (": ");
+ va_list args;
+ va_start (args, format);
+ log_message.PrintfVarArg (format, args);
+ va_end (args);
+ log->PutCString(log_message.GetString().c_str());
+ }
+}
+
+void
Module::Dump(Stream *s)
{
Mutex::Locker locker (m_mutex);