1 //===-- AddressResolverName.cpp ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/AddressResolverName.h"
13 #include "lldb/Core/Log.h"
14 #include "lldb/Core/Module.h"
15 #include "lldb/Core/StreamString.h"
16 #include "lldb/Symbol/ClangNamespaceDecl.h"
17 #include "lldb/Symbol/Function.h"
18 #include "lldb/Symbol/SymbolContext.h"
19 #include "lldb/Symbol/Symbol.h"
20 #include "lldb/lldb-private-log.h"
23 using namespace lldb_private;
25 AddressResolverName::AddressResolverName
27 const char *func_name,
28 AddressResolver::MatchType type
31 m_func_name (func_name),
36 if (m_match_type == AddressResolver::Regexp)
38 if (!m_regex.Compile (m_func_name.AsCString()))
40 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
43 log->Warning ("function name regexp: \"%s\" did not compile.", m_func_name.AsCString());
48 AddressResolverName::AddressResolverName
50 RegularExpression &func_regex
56 m_match_type (AddressResolver::Regexp)
61 AddressResolverName::AddressResolverName
63 const char *class_name,
65 AddressResolver::MatchType type
69 m_class_name (class_name),
76 AddressResolverName::~AddressResolverName ()
80 // FIXME: Right now we look at the module level, and call the module's "FindFunctions".
81 // Greg says he will add function tables, maybe at the CompileUnit level to accelerate function
82 // lookup. At that point, we should switch the depth to CompileUnit, and look in these tables.
84 Searcher::CallbackReturn
85 AddressResolverName::SearchCallback
88 SymbolContext &context,
93 SymbolContextList func_list;
94 SymbolContextList sym_list;
96 bool skip_prologue = true;
101 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
106 log->Warning ("Class/method function specification not supported yet.\n");
107 return Searcher::eCallbackReturnStop;
110 const bool include_symbols = false;
111 const bool include_inlines = true;
112 const bool append = false;
113 switch (m_match_type)
115 case AddressResolver::Exact:
116 if (context.module_sp)
118 context.module_sp->FindSymbolsWithNameAndType (m_func_name,
121 context.module_sp->FindFunctions (m_func_name,
123 eFunctionNameTypeAuto,
131 case AddressResolver::Regexp:
132 if (context.module_sp)
134 context.module_sp->FindSymbolsMatchingRegExAndType (m_regex,
137 context.module_sp->FindFunctions (m_regex,
145 case AddressResolver::Glob:
147 log->Warning ("glob is not supported yet.");
151 // Remove any duplicates between the funcion list and the symbol list
152 if (func_list.GetSize())
154 for (i = 0; i < func_list.GetSize(); i++)
156 if (func_list.GetContextAtIndex(i, sc) == false)
159 if (sc.function == NULL)
162 while (j < sym_list.GetSize())
164 SymbolContext symbol_sc;
165 if (sym_list.GetContextAtIndex(j, symbol_sc))
167 if (symbol_sc.symbol && symbol_sc.symbol->ValueIsAddress())
169 if (sc.function->GetAddressRange().GetBaseAddress() == symbol_sc.symbol->GetAddress())
171 sym_list.RemoveContextAtIndex(j);
172 continue; // Don't increment j
181 for (i = 0; i < func_list.GetSize(); i++)
183 if (func_list.GetContextAtIndex(i, sc))
187 func_addr = sc.function->GetAddressRange().GetBaseAddress();
188 addr_t byte_size = sc.function->GetAddressRange().GetByteSize();
191 const uint32_t prologue_byte_size = sc.function->GetPrologueByteSize();
192 if (prologue_byte_size)
194 func_addr.SetOffset (func_addr.GetOffset() + prologue_byte_size);
195 byte_size -= prologue_byte_size;
199 if (filter.AddressPasses (func_addr))
201 AddressRange new_range (func_addr, byte_size);
202 m_address_ranges.push_back (new_range);
209 for (i = 0; i < sym_list.GetSize(); i++)
211 if (sym_list.GetContextAtIndex(i, sc))
213 if (sc.symbol && sc.symbol->ValueIsAddress())
215 func_addr = sc.symbol->GetAddress();
216 addr_t byte_size = sc.symbol->GetByteSize();
220 const uint32_t prologue_byte_size = sc.symbol->GetPrologueByteSize();
221 if (prologue_byte_size)
223 func_addr.SetOffset (func_addr.GetOffset() + prologue_byte_size);
224 byte_size -= prologue_byte_size;
228 if (filter.AddressPasses (func_addr))
230 AddressRange new_range (func_addr, byte_size);
231 m_address_ranges.push_back (new_range);
236 return Searcher::eCallbackReturnContinue;
240 AddressResolverName::GetDepth()
242 return Searcher::eDepthModule;
246 AddressResolverName::GetDescription (Stream *s)
248 s->PutCString("Address by function name: ");
250 if (m_match_type == AddressResolver::Regexp)
251 s->Printf("'%s' (regular expression)", m_regex.GetText());
253 s->Printf("'%s'", m_func_name.AsCString());