blob: da107630b04ca49424073875fca75693ba2afd34 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SymbolFile.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
Chris Lattner24943d22010-06-08 16:52:24 +000010#include "lldb/Symbol/SymbolFile.h"
Greg Clayton75d8c252011-11-28 01:45:00 +000011
12#include "lldb/lldb-private.h"
13#include "lldb/Core/Log.h"
Greg Claytone98ac252010-11-10 04:57:04 +000014#include "lldb/Core/Module.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015#include "lldb/Core/PluginManager.h"
Greg Clayton75d8c252011-11-28 01:45:00 +000016#include "lldb/Core/StreamString.h"
Greg Claytone98ac252010-11-10 04:57:04 +000017#include "lldb/Symbol/ObjectFile.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018
19using namespace lldb_private;
20
21SymbolFile*
22SymbolFile::FindPlugin (ObjectFile* obj_file)
23{
Greg Claytonb01000f2011-01-17 03:46:26 +000024 std::auto_ptr<SymbolFile> best_symfile_ap;
Chris Lattner24943d22010-06-08 16:52:24 +000025 if (obj_file != NULL)
26 {
27 // TODO: Load any plug-ins in the appropriate plug-in search paths and
28 // iterate over all of them to find the best one for the job.
29
30 //----------------------------------------------------------------------
31 // We currently only have one debug symbol parser...
32 //----------------------------------------------------------------------
Chris Lattner24943d22010-06-08 16:52:24 +000033 uint32_t best_symfile_abilities = 0;
34
35 SymbolFileCreateInstance create_callback;
36 for (uint32_t idx = 0; (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(idx)) != NULL; ++idx)
37 {
38 std::auto_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file));
39
40 if (curr_symfile_ap.get())
41 {
42 uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities();
43 if (sym_file_abilities > best_symfile_abilities)
44 {
45 best_symfile_abilities = sym_file_abilities;
Greg Claytonb01000f2011-01-17 03:46:26 +000046 best_symfile_ap = curr_symfile_ap;
Chris Lattner24943d22010-06-08 16:52:24 +000047 }
48 }
49 }
Greg Claytonb01000f2011-01-17 03:46:26 +000050 if (best_symfile_ap.get())
51 {
52 // Let the winning symbol file parser initialize itself more
53 // completely now that it has been chosen
54 best_symfile_ap->InitializeObject();
55 }
Chris Lattner24943d22010-06-08 16:52:24 +000056 }
Greg Claytonb01000f2011-01-17 03:46:26 +000057 return best_symfile_ap.release();
Chris Lattner24943d22010-06-08 16:52:24 +000058}
59
Greg Claytone98ac252010-11-10 04:57:04 +000060TypeList *
61SymbolFile::GetTypeList ()
62{
Greg Claytonb01000f2011-01-17 03:46:26 +000063 if (m_obj_file)
64 return m_obj_file->GetModule()->GetTypeList();
65 return NULL;
Greg Claytone98ac252010-11-10 04:57:04 +000066}
Greg Claytonb01000f2011-01-17 03:46:26 +000067
68lldb_private::ClangASTContext &
69SymbolFile::GetClangASTContext ()
70{
71 return m_obj_file->GetModule()->GetClangASTContext();
72}
73
Greg Clayton75d8c252011-11-28 01:45:00 +000074
75void
76SymbolFile::ReportError (const char *format, ...)
77{
78 StreamString module_description;
79 m_obj_file->GetModule()->GetDescription (&module_description, lldb::eDescriptionLevelBrief);
80 ::fprintf (stderr, "error: %s ", module_description.GetString().c_str());
81
82 va_list args;
83 va_start (args, format);
84 vfprintf (stderr, format, args);
85 va_end (args);
86}
87
88void
89SymbolFile::ReportWarning (const char *format, ...)
90{
91 StreamString module_description;
92 m_obj_file->GetModule()->GetDescription (&module_description, lldb::eDescriptionLevelBrief);
93 ::fprintf (stderr, "warning: %s ", module_description.GetString().c_str());
94
95 va_list args;
96 va_start (args, format);
97 vfprintf (stderr, format, args);
98 va_end (args);
99}
100
101void
102SymbolFile::LogMessage (Log *log, const char *format, ...)
103{
104 if (log)
105 {
106 StreamString log_message;
107 m_obj_file->GetModule()->GetDescription (&log_message, lldb::eDescriptionLevelBrief);
108 log_message.PutChar(' ');
109 va_list args;
110 va_start (args, format);
111 log_message.PrintfVarArg (format, args);
112 va_end (args);
113 log->PutCString (log_message.GetString().c_str());
114 }
115}