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"
22 using namespace lldb_private;
24 AddressResolverName::AddressResolverName
26 const char *func_name,
27 AddressResolver::MatchType type
30 m_func_name (func_name),
35 if (m_match_type == AddressResolver::Regexp)
37 if (!m_regex.Compile (m_func_name.AsCString()))
39 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
42 log->Warning ("function name regexp: \"%s\" did not compile.", m_func_name.AsCString());
47 AddressResolverName::AddressResolverName
49 RegularExpression &func_regex
55 m_match_type (AddressResolver::Regexp)
60 AddressResolverName::AddressResolverName
62 const char *class_name,
64 AddressResolver::MatchType type
68 m_class_name (class_name),
75 AddressResolverName::~AddressResolverName ()
79 // FIXME: Right now we look at the module level, and call the module's "FindFunctions".
80 // Greg says he will add function tables, maybe at the CompileUnit level to accelerate function
81 // lookup. At that point, we should switch the depth to CompileUnit, and look in these tables.
83 Searcher::CallbackReturn
84 AddressResolverName::SearchCallback
87 SymbolContext &context,
92 SymbolContextList func_list;
93 SymbolContextList sym_list;
95 bool skip_prologue = true;
100 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
105 log->Warning ("Class/method function specification not supported yet.\n");
106 return Searcher::eCallbackReturnStop;
109 const bool include_symbols = false;
110 const bool include_inlines = true;
111 const bool append = false;
112 switch (m_match_type)
114 case AddressResolver::Exact:
115 if (context.module_sp)
117 context.module_sp->FindSymbolsWithNameAndType (m_func_name,
120 context.module_sp->FindFunctions (m_func_name,
122 eFunctionNameTypeAuto,
130 case AddressResolver::Regexp:
131 if (context.module_sp)
133 context.module_sp->FindSymbolsMatchingRegExAndType (m_regex,
136 context.module_sp->FindFunctions (m_regex,
144 case AddressResolver::Glob:
146 log->Warning ("glob is not supported yet.");
150 // Remove any duplicates between the function list and the symbol list
151 if (func_list.GetSize())
153 for (i = 0; i < func_list.GetSize(); i++)
155 if (func_list.GetContextAtIndex(i, sc) == false)
158 if (sc.function == NULL)
161 while (j < sym_list.GetSize())
163 SymbolContext symbol_sc;
164 if (sym_list.GetContextAtIndex(j, symbol_sc))
166 if (symbol_sc.symbol && symbol_sc.symbol->ValueIsAddress())
168 if (sc.function->GetAddressRange().GetBaseAddress() == symbol_sc.symbol->GetAddressRef())
170 sym_list.RemoveContextAtIndex(j);
171 continue; // Don't increment j
180 for (i = 0; i < func_list.GetSize(); i++)
182 if (func_list.GetContextAtIndex(i, sc))
186 func_addr = sc.function->GetAddressRange().GetBaseAddress();
187 addr_t byte_size = sc.function->GetAddressRange().GetByteSize();
190 const uint32_t prologue_byte_size = sc.function->GetPrologueByteSize();
191 if (prologue_byte_size)
193 func_addr.SetOffset (func_addr.GetOffset() + prologue_byte_size);
194 byte_size -= prologue_byte_size;
198 if (filter.AddressPasses (func_addr))
200 AddressRange new_range (func_addr, byte_size);
201 m_address_ranges.push_back (new_range);
208 for (i = 0; i < sym_list.GetSize(); i++)
210 if (sym_list.GetContextAtIndex(i, sc))
212 if (sc.symbol && sc.symbol->ValueIsAddress())
214 func_addr = sc.symbol->GetAddressRef();
215 addr_t byte_size = sc.symbol->GetByteSize();
219 const uint32_t prologue_byte_size = sc.symbol->GetPrologueByteSize();
220 if (prologue_byte_size)
222 func_addr.SetOffset (func_addr.GetOffset() + prologue_byte_size);
223 byte_size -= prologue_byte_size;
227 if (filter.AddressPasses (func_addr))
229 AddressRange new_range (func_addr, byte_size);
230 m_address_ranges.push_back (new_range);
235 return Searcher::eCallbackReturnContinue;
239 AddressResolverName::GetDepth()
241 return Searcher::eDepthModule;
245 AddressResolverName::GetDescription (Stream *s)
247 s->PutCString("Address by function name: ");
249 if (m_match_type == AddressResolver::Regexp)
250 s->Printf("'%s' (regular expression)", m_regex.GetText());
252 s->Printf("'%s'", m_func_name.AsCString());