aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-12-04 02:22:16 +0000
committerGreg Clayton <gclayton@apple.com>2012-12-04 02:22:16 +0000
commite14e19253df64b750ced6da0948418f6c80da6c9 (patch)
tree1b41fd23856f63691ed4ec09cca23977dda7d446
parent15a2860b09c55e2531b1e70b69d7dc56a05060e9 (diff)
downloadllvm-e14e19253df64b750ced6da0948418f6c80da6c9.zip
llvm-e14e19253df64b750ced6da0948418f6c80da6c9.tar.gz
llvm-e14e19253df64b750ced6da0948418f6c80da6c9.tar.bz2
<rdar://problem/12750060>
Add the ability to get a symbol or symbols by name and type from a SBModule, and also the ability to get all symbols by name and type from SBTarget objects. llvm-svn: 169205
-rw-r--r--lldb/include/lldb/API/SBModule.h8
-rw-r--r--lldb/include/lldb/API/SBTarget.h4
-rw-r--r--lldb/scripts/Python/interface/SBModule.i16
-rw-r--r--lldb/scripts/Python/interface/SBTarget.i3
-rw-r--r--lldb/source/API/SBModule.cpp62
-rw-r--r--lldb/source/API/SBTarget.cpp21
6 files changed, 111 insertions, 3 deletions
diff --git a/lldb/include/lldb/API/SBModule.h b/lldb/include/lldb/API/SBModule.h
index 07143ef..48c5b04 100644
--- a/lldb/include/lldb/API/SBModule.h
+++ b/lldb/include/lldb/API/SBModule.h
@@ -120,6 +120,14 @@ public:
lldb::SBSymbol
GetSymbolAtIndex (size_t idx);
+ lldb::SBSymbol
+ FindSymbol (const char *name,
+ lldb::SymbolType type = eSymbolTypeAny);
+
+ lldb::SBSymbolContextList
+ FindSymbols (const char *name,
+ lldb::SymbolType type = eSymbolTypeAny);
+
size_t
GetNumSections ();
diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 5dd9393..edc36d1 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -731,6 +731,10 @@ public:
lldb::SBInstructionList
GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size);
+ lldb::SBSymbolContextList
+ FindSymbols (const char *name,
+ lldb::SymbolType type = eSymbolTypeAny);
+
bool
operator == (const lldb::SBTarget &rhs) const;
diff --git a/lldb/scripts/Python/interface/SBModule.i b/lldb/scripts/Python/interface/SBModule.i
index ccfbed6..b98afde 100644
--- a/lldb/scripts/Python/interface/SBModule.i
+++ b/lldb/scripts/Python/interface/SBModule.i
@@ -177,6 +177,15 @@ public:
lldb::SBSymbol
GetSymbolAtIndex (size_t idx);
+ lldb::SBSymbol
+ FindSymbol (const char *name,
+ lldb::SymbolType type = eSymbolTypeAny);
+
+ lldb::SBSymbolContextList
+ FindSymbols (const char *name,
+ lldb::SymbolType type = eSymbolTypeAny);
+
+
size_t
GetNumSections ();
@@ -269,9 +278,10 @@ public:
return self.sbmodule.GetSymbolAtIndex(key)
elif type(key) is str:
matches = []
- for idx in range(count):
- symbol = self.sbmodule.GetSymbolAtIndex(idx)
- if symbol.name == key or symbol.mangled == key:
+ sc_list = self.sbmodule.FindSymbols(key)
+ for sc in sc_list:
+ symbol = sc.symbol
+ if symbol:
matches.append(symbol)
return matches
elif isinstance(key, self.re_compile_type):
diff --git a/lldb/scripts/Python/interface/SBTarget.i b/lldb/scripts/Python/interface/SBTarget.i
index 8a304ee..bc4c228 100644
--- a/lldb/scripts/Python/interface/SBTarget.i
+++ b/lldb/scripts/Python/interface/SBTarget.i
@@ -687,6 +687,9 @@ public:
lldb::SBInstructionList
GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size);
+ lldb::SBSymbolContextList
+ FindSymbols (const char *name, lldb::SymbolType type = eSymbolTypeAny);
+
bool
GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level);
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index 446a693..933e803 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -328,6 +328,68 @@ SBModule::GetSymbolAtIndex (size_t idx)
return sb_symbol;
}
+lldb::SBSymbol
+SBModule::FindSymbol (const char *name,
+ lldb::SymbolType symbol_type)
+{
+ SBSymbol sb_symbol;
+ if (name && name[0])
+ {
+ ModuleSP module_sp (GetSP ());
+ if (module_sp)
+ {
+ ObjectFile *obj_file = module_sp->GetObjectFile();
+ if (obj_file)
+ {
+ Symtab *symtab = obj_file->GetSymtab();
+ if (symtab)
+ sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(ConstString(name), symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny));
+ }
+ }
+ }
+ return sb_symbol;
+}
+
+
+lldb::SBSymbolContextList
+SBModule::FindSymbols (const char *name, lldb::SymbolType symbol_type)
+{
+ SBSymbolContextList sb_sc_list;
+ if (name && name[0])
+ {
+ ModuleSP module_sp (GetSP ());
+ if (module_sp)
+ {
+ ObjectFile *obj_file = module_sp->GetObjectFile();
+ if (obj_file)
+ {
+ Symtab *symtab = obj_file->GetSymtab();
+ if (symtab)
+ {
+ std::vector<uint32_t> matching_symbol_indexes;
+ const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(ConstString(name), symbol_type, matching_symbol_indexes);
+ if (num_matches)
+ {
+ SymbolContext sc;
+ sc.module_sp = module_sp;
+ SymbolContextList &sc_list = *sb_sc_list;
+ for (size_t i=0; i<num_matches; ++i)
+ {
+ sc.symbol = symtab->SymbolAtIndex (matching_symbol_indexes[i]);
+ if (sc.symbol)
+ sc_list.Append(sc);
+ }
+ }
+ }
+ }
+ }
+ }
+ return sb_sc_list;
+
+}
+
+
+
size_t
SBModule::GetNumSections ()
{
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 611da77..d519ffb 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -2355,3 +2355,24 @@ SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
}
+lldb::SBSymbolContextList
+SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
+{
+ SBSymbolContextList sb_sc_list;
+ if (name && name[0])
+ {
+ TargetSP target_sp(GetSP());
+ if (target_sp)
+ {
+ bool append = true;
+ target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
+ symbol_type,
+ *sb_sc_list,
+ append);
+ }
+ }
+ return sb_sc_list;
+
+}
+
+