2010-06-09 00:52:24 +08:00
|
|
|
//===-- Module.cpp ----------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-05 08:20:57 +08:00
|
|
|
#include "lldb/lldb-python.h"
|
|
|
|
|
2012-11-08 10:22:02 +08:00
|
|
|
#include "lldb/Core/Error.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2012-02-05 10:38:54 +08:00
|
|
|
#include "lldb/Core/DataBuffer.h"
|
|
|
|
#include "lldb/Core/DataBufferHeap.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
|
|
|
#include "lldb/Core/ModuleList.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Core/ModuleSpec.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/RegularExpression.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Core/Section.h"
|
2011-11-28 09:45:00 +08:00
|
|
|
#include "lldb/Core/StreamString.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Timer.h"
|
2012-01-05 11:57:59 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
2012-11-08 10:22:02 +08:00
|
|
|
#include "lldb/Host/Symbols.h"
|
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
#include "lldb/Interpreter/ScriptInterpreter.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/lldb-private-log.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
|
|
|
#include "lldb/Symbol/SymbolVendor.h"
|
2012-02-05 10:38:54 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2011-08-09 08:01:09 +08:00
|
|
|
// Shared pointers to modules track module lifetimes in
|
|
|
|
// targets and in the global module, but this collection
|
|
|
|
// will track all module objects that are still alive
|
|
|
|
typedef std::vector<Module *> ModuleCollection;
|
|
|
|
|
|
|
|
static ModuleCollection &
|
|
|
|
GetModuleCollection()
|
|
|
|
{
|
2011-11-01 07:47:10 +08:00
|
|
|
// This module collection needs to live past any module, so we could either make it a
|
|
|
|
// shared pointer in each module or just leak is. Since it is only an empty vector by
|
|
|
|
// the time all the modules have gone away, we just leak it for now. If we decide this
|
|
|
|
// is a big problem we can introduce a Finalize method that will tear everything down in
|
|
|
|
// a predictable order.
|
|
|
|
|
|
|
|
static ModuleCollection *g_module_collection = NULL;
|
|
|
|
if (g_module_collection == NULL)
|
|
|
|
g_module_collection = new ModuleCollection();
|
|
|
|
|
|
|
|
return *g_module_collection;
|
2011-08-09 08:01:09 +08:00
|
|
|
}
|
|
|
|
|
2012-01-28 02:08:35 +08:00
|
|
|
Mutex *
|
2011-08-09 08:01:09 +08:00
|
|
|
Module::GetAllocationModuleCollectionMutex()
|
|
|
|
{
|
2012-01-28 02:08:35 +08:00
|
|
|
// NOTE: The mutex below must be leaked since the global module list in
|
|
|
|
// the ModuleList class will get torn at some point, and we can't know
|
|
|
|
// if it will tear itself down before the "g_module_collection_mutex" below
|
|
|
|
// will. So we leak a Mutex object below to safeguard against that
|
|
|
|
|
|
|
|
static Mutex *g_module_collection_mutex = NULL;
|
|
|
|
if (g_module_collection_mutex == NULL)
|
|
|
|
g_module_collection_mutex = new Mutex (Mutex::eMutexTypeRecursive); // NOTE: known leak
|
|
|
|
return g_module_collection_mutex;
|
2011-08-09 08:01:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
Module::GetNumberAllocatedModules ()
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (GetAllocationModuleCollectionMutex());
|
|
|
|
return GetModuleCollection().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
Module *
|
|
|
|
Module::GetAllocatedModuleAtIndex (size_t idx)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (GetAllocationModuleCollectionMutex());
|
|
|
|
ModuleCollection &modules = GetModuleCollection();
|
|
|
|
if (idx < modules.size())
|
|
|
|
return modules[idx];
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-28 02:45:39 +08:00
|
|
|
#if 0
|
2011-08-09 08:01:09 +08:00
|
|
|
|
2012-01-28 02:45:39 +08:00
|
|
|
// These functions help us to determine if modules are still loaded, yet don't require that
|
|
|
|
// you have a command interpreter and can easily be called from an external debugger.
|
|
|
|
namespace lldb {
|
2011-08-09 08:01:09 +08:00
|
|
|
|
2012-01-28 02:45:39 +08:00
|
|
|
void
|
|
|
|
ClearModuleInfo (void)
|
|
|
|
{
|
2012-04-10 04:22:01 +08:00
|
|
|
const bool mandatory = true;
|
|
|
|
ModuleList::RemoveOrphanSharedModules(mandatory);
|
2012-01-28 02:45:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DumpModuleInfo (void)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (Module::GetAllocationModuleCollectionMutex());
|
|
|
|
ModuleCollection &modules = GetModuleCollection();
|
|
|
|
const size_t count = modules.size();
|
2012-11-30 05:49:15 +08:00
|
|
|
printf ("%s: %" PRIu64 " modules:\n", __PRETTY_FUNCTION__, (uint64_t)count);
|
2012-01-28 02:45:39 +08:00
|
|
|
for (size_t i=0; i<count; ++i)
|
|
|
|
{
|
|
|
|
|
|
|
|
StreamString strm;
|
|
|
|
Module *module = modules[i];
|
|
|
|
const bool in_shared_module_list = ModuleList::ModuleIsInCache (module);
|
|
|
|
module->GetDescription(&strm, eDescriptionLevelFull);
|
|
|
|
printf ("%p: shared = %i, ref_count = %3u, module = %s\n",
|
|
|
|
module,
|
|
|
|
in_shared_module_list,
|
|
|
|
(uint32_t)module->use_count(),
|
|
|
|
strm.GetString().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2012-10-09 06:41:53 +08:00
|
|
|
|
2012-02-26 13:51:37 +08:00
|
|
|
Module::Module (const ModuleSpec &module_spec) :
|
|
|
|
m_mutex (Mutex::eMutexTypeRecursive),
|
|
|
|
m_mod_time (module_spec.GetFileSpec().GetModificationTime()),
|
|
|
|
m_arch (module_spec.GetArchitecture()),
|
|
|
|
m_uuid (),
|
|
|
|
m_file (module_spec.GetFileSpec()),
|
|
|
|
m_platform_file(module_spec.GetPlatformFileSpec()),
|
|
|
|
m_symfile_spec (module_spec.GetSymbolFileSpec()),
|
|
|
|
m_object_name (module_spec.GetObjectName()),
|
|
|
|
m_object_offset (module_spec.GetObjectOffset()),
|
|
|
|
m_objfile_sp (),
|
|
|
|
m_symfile_ap (),
|
|
|
|
m_ast (),
|
2012-03-16 05:01:31 +08:00
|
|
|
m_source_mappings (),
|
2012-02-26 13:51:37 +08:00
|
|
|
m_did_load_objfile (false),
|
|
|
|
m_did_load_symbol_vendor (false),
|
|
|
|
m_did_parse_uuid (false),
|
|
|
|
m_did_init_ast (false),
|
|
|
|
m_is_dynamic_loader_module (false),
|
2012-07-13 06:51:12 +08:00
|
|
|
m_file_has_changed (false),
|
|
|
|
m_first_file_changed_log (false)
|
2012-02-26 13:51:37 +08:00
|
|
|
{
|
|
|
|
// Scope for locker below...
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (GetAllocationModuleCollectionMutex());
|
|
|
|
GetModuleCollection().push_back(this);
|
|
|
|
}
|
|
|
|
|
2012-10-09 06:41:53 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
|
2012-02-26 13:51:37 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("%p Module::Module((%s) '%s/%s%s%s%s')",
|
|
|
|
this,
|
|
|
|
m_arch.GetArchitectureName(),
|
|
|
|
m_file.GetDirectory().AsCString(""),
|
|
|
|
m_file.GetFilename().AsCString(""),
|
|
|
|
m_object_name.IsEmpty() ? "" : "(",
|
|
|
|
m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
|
|
|
|
m_object_name.IsEmpty() ? "" : ")");
|
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
Module::Module(const FileSpec& file_spec,
|
|
|
|
const ArchSpec& arch,
|
|
|
|
const ConstString *object_name,
|
|
|
|
off_t object_offset) :
|
2010-06-09 00:52:24 +08:00
|
|
|
m_mutex (Mutex::eMutexTypeRecursive),
|
|
|
|
m_mod_time (file_spec.GetModificationTime()),
|
|
|
|
m_arch (arch),
|
|
|
|
m_uuid (),
|
|
|
|
m_file (file_spec),
|
Many improvements to the Platform base class and subclasses. The base Platform
class now implements the Host functionality for a lot of things that make
sense by default so that subclasses can check:
int
PlatformSubclass::Foo ()
{
if (IsHost())
return Platform::Foo (); // Let the platform base class do the host specific stuff
// Platform subclass specific code...
int result = ...
return result;
}
Added new functions to the platform:
virtual const char *Platform::GetUserName (uint32_t uid);
virtual const char *Platform::GetGroupName (uint32_t gid);
The user and group names are cached locally so that remote platforms can avoid
sending packets multiple times to resolve this information.
Added the parent process ID to the ProcessInfo class.
Added a new ProcessInfoMatch class which helps us to match processes up
and changed the Host layer over to using this new class. The new class allows
us to search for processs:
1 - by name (equal to, starts with, ends with, contains, and regex)
2 - by pid
3 - And further check for parent pid == value, uid == value, gid == value,
euid == value, egid == value, arch == value, parent == value.
This is all hookup up to the "platform process list" command which required
adding dumping routines to dump process information. If the Host class
implements the process lookup routines, you can now lists processes on
your local machine:
machine1.foo.com % lldb
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
94727 244 username usergroup username usergroup x86_64-apple-darwin Xcode
92742 92710 username usergroup username usergroup i386-apple-darwin debugserver
This of course also works remotely with the lldb-platform:
machine1.foo.com % lldb-platform --listen 1234
machine2.foo.com % lldb
(lldb) platform create remote-macosx
Platform: remote-macosx
Connected: no
(lldb) platform connect connect://localhost:1444
Platform: remote-macosx
Triple: x86_64-apple-darwin
OS Version: 10.6.7 (10J869)
Kernel: Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386
Hostname: machine1.foo.com
Connected: yes
(lldb) platform process list
PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE NAME
====== ====== ========== ========== ========== ========== ======================== ============================
99556 244 username usergroup username usergroup x86_64-apple-darwin trustevaluation
99548 65539 username usergroup username usergroup x86_64-apple-darwin lldb
99538 1 username usergroup username usergroup x86_64-apple-darwin FileMerge
94943 1 username usergroup username usergroup x86_64-apple-darwin mdworker
94852 244 username usergroup username usergroup x86_64-apple-darwin Safari
The lldb-platform implements everything with the Host:: layer, so this should
"just work" for linux. I will probably be adding more stuff to the Host layer
for launching processes and attaching to processes so that this support should
eventually just work as well.
Modified the target to be able to be created with an architecture that differs
from the main executable. This is needed for iOS debugging since we can have
an "armv6" binary which can run on an "armv7" machine, so we want to be able
to do:
% lldb
(lldb) platform create remote-ios
(lldb) file --arch armv7 a.out
Where "a.out" is an armv6 executable. The platform then can correctly decide
to open all "armv7" images for all dependent shared libraries.
Modified the disassembly to show the current PC value. Example output:
(lldb) disassemble --frame
a.out`main:
0x1eb7: pushl %ebp
0x1eb8: movl %esp, %ebp
0x1eba: pushl %ebx
0x1ebb: subl $20, %esp
0x1ebe: calll 0x1ec3 ; main + 12 at test.c:18
0x1ec3: popl %ebx
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
0x1edb: leal 213(%ebx), %eax
0x1ee1: movl %eax, (%esp)
0x1ee4: calll 0x1f1e ; puts
0x1ee9: calll 0x1f0c ; getchar
0x1eee: movl $20, (%esp)
0x1ef5: calll 0x1e6a ; sleep_loop at test.c:6
0x1efa: movl $12, %eax
0x1eff: addl $20, %esp
0x1f02: popl %ebx
0x1f03: leave
0x1f04: ret
This can be handy when dealing with the new --line options that was recently
added:
(lldb) disassemble --line
a.out`main + 13 at test.c:19
18 {
-> 19 printf("Process: %i\n\n", getpid());
20 puts("Press any key to continue..."); getchar();
-> 0x1ec4: calll 0x1f12 ; getpid
0x1ec9: movl %eax, 4(%esp)
0x1ecd: leal 199(%ebx), %eax
0x1ed3: movl %eax, (%esp)
0x1ed6: calll 0x1f18 ; printf
Modified the ModuleList to have a lookup based solely on a UUID. Since the
UUID is typically the MD5 checksum of a binary image, there is no need
to give the path and architecture when searching for a pre-existing
image in an image list.
Now that we support remote debugging a bit better, our lldb_private::Module
needs to be able to track what the original path for file was as the platform
knows it, as well as where the file is locally. The module has the two
following functions to retrieve both paths:
const FileSpec &Module::GetFileSpec () const;
const FileSpec &Module::GetPlatformFileSpec () const;
llvm-svn: 128563
2011-03-31 02:16:51 +08:00
|
|
|
m_platform_file(),
|
2012-02-24 09:59:29 +08:00
|
|
|
m_symfile_spec (),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_object_name (),
|
2011-04-12 13:54:46 +08:00
|
|
|
m_object_offset (object_offset),
|
2011-09-19 02:59:15 +08:00
|
|
|
m_objfile_sp (),
|
2010-09-08 07:40:05 +08:00
|
|
|
m_symfile_ap (),
|
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
|
|
|
m_ast (),
|
2012-03-16 05:01:31 +08:00
|
|
|
m_source_mappings (),
|
2010-09-08 07:40:05 +08:00
|
|
|
m_did_load_objfile (false),
|
|
|
|
m_did_load_symbol_vendor (false),
|
|
|
|
m_did_parse_uuid (false),
|
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
|
|
|
m_did_init_ast (false),
|
2012-01-05 11:57:59 +08:00
|
|
|
m_is_dynamic_loader_module (false),
|
2012-07-13 06:51:12 +08:00
|
|
|
m_file_has_changed (false),
|
|
|
|
m_first_file_changed_log (false)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-08-09 08:01:09 +08:00
|
|
|
// Scope for locker below...
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (GetAllocationModuleCollectionMutex());
|
|
|
|
GetModuleCollection().push_back(this);
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (object_name)
|
|
|
|
m_object_name = *object_name;
|
2012-10-09 06:41:53 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
|
2010-06-09 00:52:24 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("%p Module::Module((%s) '%s/%s%s%s%s')",
|
|
|
|
this,
|
2011-02-23 08:35:02 +08:00
|
|
|
m_arch.GetArchitectureName(),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_file.GetDirectory().AsCString(""),
|
|
|
|
m_file.GetFilename().AsCString(""),
|
|
|
|
m_object_name.IsEmpty() ? "" : "(",
|
|
|
|
m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
|
|
|
|
m_object_name.IsEmpty() ? "" : ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
Module::~Module()
|
|
|
|
{
|
2011-08-09 08:01:09 +08:00
|
|
|
// Scope for locker below...
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (GetAllocationModuleCollectionMutex());
|
|
|
|
ModuleCollection &modules = GetModuleCollection();
|
|
|
|
ModuleCollection::iterator end = modules.end();
|
|
|
|
ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
|
2012-10-09 06:41:53 +08:00
|
|
|
assert (pos != end);
|
|
|
|
modules.erase(pos);
|
2011-08-09 08:01:09 +08:00
|
|
|
}
|
2012-10-09 06:41:53 +08:00
|
|
|
LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
|
2010-06-09 00:52:24 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("%p Module::~Module((%s) '%s/%s%s%s%s')",
|
|
|
|
this,
|
2011-02-23 08:35:02 +08:00
|
|
|
m_arch.GetArchitectureName(),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_file.GetDirectory().AsCString(""),
|
|
|
|
m_file.GetFilename().AsCString(""),
|
|
|
|
m_object_name.IsEmpty() ? "" : "(",
|
|
|
|
m_object_name.IsEmpty() ? "" : m_object_name.AsCString(""),
|
|
|
|
m_object_name.IsEmpty() ? "" : ")");
|
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
|
|
|
// Release any auto pointers before we start tearing down our member
|
|
|
|
// variables since the object file and symbol files might need to make
|
|
|
|
// function calls back into this module object. The ordering is important
|
|
|
|
// here because symbol files can require the module object file. So we tear
|
|
|
|
// down the symbol file first, then the object file.
|
|
|
|
m_symfile_ap.reset();
|
2011-09-19 02:59:15 +08:00
|
|
|
m_objfile_sp.reset();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-02-25 05:55:59 +08:00
|
|
|
ObjectFile *
|
|
|
|
Module::GetMemoryObjectFile (const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Error &error)
|
|
|
|
{
|
|
|
|
if (m_objfile_sp)
|
|
|
|
{
|
|
|
|
error.SetErrorString ("object file already exists");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
|
|
|
if (process_sp)
|
|
|
|
{
|
|
|
|
m_did_load_objfile = true;
|
|
|
|
std::auto_ptr<DataBufferHeap> data_ap (new DataBufferHeap (512, 0));
|
|
|
|
Error readmem_error;
|
|
|
|
const size_t bytes_read = process_sp->ReadMemory (header_addr,
|
|
|
|
data_ap->GetBytes(),
|
|
|
|
data_ap->GetByteSize(),
|
|
|
|
readmem_error);
|
|
|
|
if (bytes_read == 512)
|
|
|
|
{
|
|
|
|
DataBufferSP data_sp(data_ap.release());
|
|
|
|
m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp, header_addr, data_sp);
|
|
|
|
if (m_objfile_sp)
|
|
|
|
{
|
2012-04-21 03:50:20 +08:00
|
|
|
StreamString s;
|
2012-11-30 05:49:15 +08:00
|
|
|
s.Printf("0x%16.16" PRIx64, header_addr);
|
2012-04-21 03:50:20 +08:00
|
|
|
m_object_name.SetCString (s.GetData());
|
|
|
|
|
|
|
|
// Once we get the object file, update our module with the object file's
|
2012-02-25 05:55:59 +08:00
|
|
|
// architecture since it might differ in vendor/os if some parts were
|
|
|
|
// unknown.
|
|
|
|
m_objfile_sp->GetArchitecture (m_arch);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorString ("unable to find suitable object file plug-in");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorStringWithFormat ("unable to read header from memory: %s", readmem_error.AsCString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorString ("invalid process");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_objfile_sp.get();
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-02-05 02:53:10 +08:00
|
|
|
const lldb_private::UUID&
|
2010-06-09 00:52:24 +08:00
|
|
|
Module::GetUUID()
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
2010-09-08 07:40:05 +08:00
|
|
|
if (m_did_parse_uuid == false)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
ObjectFile * obj_file = GetObjectFile ();
|
|
|
|
|
|
|
|
if (obj_file != NULL)
|
|
|
|
{
|
|
|
|
obj_file->GetUUID(&m_uuid);
|
2010-09-08 07:40:05 +08:00
|
|
|
m_did_parse_uuid = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_uuid;
|
|
|
|
}
|
|
|
|
|
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
|
|
|
ClangASTContext &
|
|
|
|
Module::GetClangASTContext ()
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
|
|
|
if (m_did_init_ast == false)
|
|
|
|
{
|
|
|
|
ObjectFile * objfile = GetObjectFile();
|
2011-02-16 05:59:32 +08:00
|
|
|
ArchSpec object_arch;
|
|
|
|
if (objfile && objfile->GetArchitecture(object_arch))
|
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
|
|
|
{
|
|
|
|
m_did_init_ast = true;
|
2012-10-17 04:45:49 +08:00
|
|
|
|
|
|
|
// LLVM wants this to be set to iOS or MacOSX; if we're working on
|
|
|
|
// a bare-boards type image, change the triple for llvm's benefit.
|
|
|
|
if (object_arch.GetTriple().getVendor() == llvm::Triple::Apple
|
|
|
|
&& object_arch.GetTriple().getOS() == llvm::Triple::UnknownOS)
|
|
|
|
{
|
|
|
|
if (object_arch.GetTriple().getArch() == llvm::Triple::arm ||
|
|
|
|
object_arch.GetTriple().getArch() == llvm::Triple::thumb)
|
|
|
|
{
|
|
|
|
object_arch.GetTriple().setOS(llvm::Triple::IOS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
object_arch.GetTriple().setOS(llvm::Triple::MacOSX);
|
|
|
|
}
|
|
|
|
}
|
2011-02-16 05:59:32 +08:00
|
|
|
m_ast.SetArchitecture (object_arch);
|
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_ast;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
|
|
|
Module::ParseAllDebugSymbols()
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
|
|
|
uint32_t num_comp_units = GetNumCompileUnits();
|
|
|
|
if (num_comp_units == 0)
|
|
|
|
return;
|
|
|
|
|
2011-09-17 15:23:18 +08:00
|
|
|
SymbolContext sc;
|
2012-01-30 04:56:30 +08:00
|
|
|
sc.module_sp = shared_from_this();
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t cu_idx;
|
|
|
|
SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
|
|
|
|
for (cu_idx = 0; cu_idx < num_comp_units; cu_idx++)
|
|
|
|
{
|
|
|
|
sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
|
|
|
|
if (sc.comp_unit)
|
|
|
|
{
|
|
|
|
sc.function = NULL;
|
|
|
|
symbols->ParseVariablesForContext(sc);
|
|
|
|
|
|
|
|
symbols->ParseCompileUnitFunctions(sc);
|
|
|
|
|
|
|
|
uint32_t func_idx;
|
|
|
|
for (func_idx = 0; (sc.function = sc.comp_unit->GetFunctionAtIndex(func_idx).get()) != NULL; ++func_idx)
|
|
|
|
{
|
|
|
|
symbols->ParseFunctionBlocks(sc);
|
|
|
|
|
|
|
|
// Parse the variables for this function and all its blocks
|
|
|
|
symbols->ParseVariablesForContext(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Parse all types for this compile unit
|
|
|
|
sc.function = NULL;
|
|
|
|
symbols->ParseTypes(sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Module::CalculateSymbolContext(SymbolContext* sc)
|
|
|
|
{
|
2012-01-30 04:56:30 +08:00
|
|
|
sc->module_sp = shared_from_this();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP
|
2011-08-13 05:40:01 +08:00
|
|
|
Module::CalculateSymbolContextModule ()
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
return shared_from_this();
|
2011-08-13 05:40:01 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
|
|
|
Module::DumpSymbolContext(Stream *s)
|
|
|
|
{
|
2011-09-21 05:44:10 +08:00
|
|
|
s->Printf(", Module{%p}", this);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Module::GetNumCompileUnits()
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
|
|
|
Timer scoped_timer(__PRETTY_FUNCTION__, "Module::GetNumCompileUnits (module = %p)", this);
|
|
|
|
SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
if (symbols)
|
|
|
|
return symbols->GetNumCompileUnits();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CompUnitSP
|
|
|
|
Module::GetCompileUnitAtIndex (uint32_t index)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
|
|
|
uint32_t num_comp_units = GetNumCompileUnits ();
|
|
|
|
CompUnitSP cu_sp;
|
|
|
|
|
|
|
|
if (index < num_comp_units)
|
|
|
|
{
|
|
|
|
SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
if (symbols)
|
|
|
|
cu_sp = symbols->GetCompileUnitAtIndex(index);
|
|
|
|
}
|
|
|
|
return cu_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Module::ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
2012-11-30 05:49:15 +08:00
|
|
|
Timer scoped_timer(__PRETTY_FUNCTION__, "Module::ResolveFileAddress (vm_addr = 0x%" PRIx64 ")", vm_addr);
|
2010-06-09 00:52:24 +08:00
|
|
|
ObjectFile* ofile = GetObjectFile();
|
|
|
|
if (ofile)
|
|
|
|
return so_addr.ResolveAddressUsingFileSections(vm_addr, ofile->GetSectionList());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
|
|
|
uint32_t resolved_flags = 0;
|
|
|
|
|
|
|
|
// Clear the result symbol context in case we don't find anything
|
|
|
|
sc.Clear();
|
|
|
|
|
|
|
|
// Get the section from the section/offset address.
|
2012-02-24 09:59:29 +08:00
|
|
|
SectionSP section_sp (so_addr.GetSection());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Make sure the section matches this module before we try and match anything
|
2012-02-24 09:59:29 +08:00
|
|
|
if (section_sp && section_sp->GetModule().get() == this)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// If the section offset based address resolved itself, then this
|
|
|
|
// is the right module.
|
2012-01-30 04:56:30 +08:00
|
|
|
sc.module_sp = shared_from_this();
|
2010-06-09 00:52:24 +08:00
|
|
|
resolved_flags |= eSymbolContextModule;
|
|
|
|
|
|
|
|
// Resolve the compile unit, function, block, line table or line
|
|
|
|
// entry if requested.
|
|
|
|
if (resolve_scope & eSymbolContextCompUnit ||
|
|
|
|
resolve_scope & eSymbolContextFunction ||
|
|
|
|
resolve_scope & eSymbolContextBlock ||
|
|
|
|
resolve_scope & eSymbolContextLineEntry )
|
|
|
|
{
|
|
|
|
SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
if (symbols)
|
|
|
|
resolved_flags |= symbols->ResolveSymbolContext (so_addr, resolve_scope, sc);
|
|
|
|
}
|
|
|
|
|
2010-09-01 07:51:36 +08:00
|
|
|
// Resolve the symbol if requested, but don't re-look it up if we've already found it.
|
|
|
|
if (resolve_scope & eSymbolContextSymbol && !(resolved_flags & eSymbolContextSymbol))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
ObjectFile* ofile = GetObjectFile();
|
|
|
|
if (ofile)
|
|
|
|
{
|
|
|
|
Symtab *symtab = ofile->GetSymtab();
|
|
|
|
if (symtab)
|
|
|
|
{
|
|
|
|
if (so_addr.IsSectionOffset())
|
|
|
|
{
|
|
|
|
sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());
|
|
|
|
if (sc.symbol)
|
|
|
|
resolved_flags |= eSymbolContextSymbol;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resolved_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2010-10-21 04:54:39 +08:00
|
|
|
Module::ResolveSymbolContextForFilePath
|
|
|
|
(
|
|
|
|
const char *file_path,
|
|
|
|
uint32_t line,
|
|
|
|
bool check_inlines,
|
|
|
|
uint32_t resolve_scope,
|
|
|
|
SymbolContextList& sc_list
|
|
|
|
)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-21 04:54:39 +08:00
|
|
|
FileSpec file_spec(file_path, false);
|
2010-06-09 00:52:24 +08:00
|
|
|
return ResolveSymbolContextsForFileSpec (file_spec, line, check_inlines, resolve_scope, sc_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
Module::ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
|
|
|
Timer scoped_timer(__PRETTY_FUNCTION__,
|
|
|
|
"Module::ResolveSymbolContextForFilePath (%s%s%s:%u, check_inlines = %s, resolve_scope = 0x%8.8x)",
|
|
|
|
file_spec.GetDirectory().AsCString(""),
|
|
|
|
file_spec.GetDirectory() ? "/" : "",
|
|
|
|
file_spec.GetFilename().AsCString(""),
|
|
|
|
line,
|
|
|
|
check_inlines ? "yes" : "no",
|
|
|
|
resolve_scope);
|
|
|
|
|
|
|
|
const uint32_t initial_count = sc_list.GetSize();
|
|
|
|
|
|
|
|
SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
if (symbols)
|
|
|
|
symbols->ResolveSymbolContext (file_spec, line, check_inlines, resolve_scope, sc_list);
|
|
|
|
|
|
|
|
return sc_list.GetSize() - initial_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t
|
2011-10-12 10:08:07 +08:00
|
|
|
Module::FindGlobalVariables(const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
if (symbols)
|
2011-10-13 09:49:10 +08:00
|
|
|
return symbols->FindGlobalVariables(name, namespace_decl, append, max_matches, variables);
|
2010-06-09 00:52:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
uint32_t
|
|
|
|
Module::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
|
|
|
|
{
|
|
|
|
SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
if (symbols)
|
|
|
|
return symbols->FindGlobalVariables(regex, append, max_matches, variables);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-07 09:59:51 +08:00
|
|
|
uint32_t
|
|
|
|
Module::FindCompileUnits (const FileSpec &path,
|
|
|
|
bool append,
|
|
|
|
SymbolContextList &sc_list)
|
|
|
|
{
|
|
|
|
if (!append)
|
|
|
|
sc_list.Clear();
|
|
|
|
|
|
|
|
const uint32_t start_size = sc_list.GetSize();
|
|
|
|
const uint32_t num_compile_units = GetNumCompileUnits();
|
|
|
|
SymbolContext sc;
|
2012-01-30 04:56:30 +08:00
|
|
|
sc.module_sp = shared_from_this();
|
2011-07-07 09:59:51 +08:00
|
|
|
const bool compare_directory = path.GetDirectory();
|
|
|
|
for (uint32_t i=0; i<num_compile_units; ++i)
|
|
|
|
{
|
|
|
|
sc.comp_unit = GetCompileUnitAtIndex(i).get();
|
2012-04-24 06:00:21 +08:00
|
|
|
if (sc.comp_unit)
|
|
|
|
{
|
|
|
|
if (FileSpec::Equal (*sc.comp_unit, path, compare_directory))
|
|
|
|
sc_list.Append(sc);
|
|
|
|
}
|
2011-07-07 09:59:51 +08:00
|
|
|
}
|
|
|
|
return sc_list.GetSize() - start_size;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t
|
2011-10-12 10:08:07 +08:00
|
|
|
Module::FindFunctions (const ConstString &name,
|
|
|
|
const ClangNamespaceDecl *namespace_decl,
|
2011-01-27 14:44:37 +08:00
|
|
|
uint32_t name_type_mask,
|
2012-02-11 06:52:19 +08:00
|
|
|
bool include_symbols,
|
|
|
|
bool include_inlines,
|
2011-01-27 14:44:37 +08:00
|
|
|
bool append,
|
|
|
|
SymbolContextList& sc_list)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-01-27 14:44:37 +08:00
|
|
|
if (!append)
|
|
|
|
sc_list.Clear();
|
|
|
|
|
|
|
|
const uint32_t start_size = sc_list.GetSize();
|
|
|
|
|
|
|
|
// Find all the functions (not symbols, but debug information functions...
|
2010-06-09 00:52:24 +08:00
|
|
|
SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
if (symbols)
|
2012-02-11 06:52:19 +08:00
|
|
|
symbols->FindFunctions(name, namespace_decl, name_type_mask, include_inlines, append, sc_list);
|
2011-01-27 14:44:37 +08:00
|
|
|
|
|
|
|
// Now check our symbol table for symbols that are code symbols if requested
|
|
|
|
if (include_symbols)
|
|
|
|
{
|
|
|
|
ObjectFile *objfile = GetObjectFile();
|
|
|
|
if (objfile)
|
|
|
|
{
|
|
|
|
Symtab *symtab = objfile->GetSymtab();
|
|
|
|
if (symtab)
|
|
|
|
{
|
|
|
|
std::vector<uint32_t> symbol_indexes;
|
|
|
|
symtab->FindAllSymbolsWithNameAndType (name, eSymbolTypeCode, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
|
|
|
|
const uint32_t num_matches = symbol_indexes.size();
|
|
|
|
if (num_matches)
|
|
|
|
{
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
const bool merge_symbol_into_function = true;
|
2011-01-27 14:44:37 +08:00
|
|
|
SymbolContext sc(this);
|
|
|
|
for (uint32_t i=0; i<num_matches; i++)
|
|
|
|
{
|
|
|
|
sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
sc_list.AppendIfUnique (sc, merge_symbol_into_function);
|
2011-01-27 14:44:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sc_list.GetSize() - start_size;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2011-01-27 14:44:37 +08:00
|
|
|
Module::FindFunctions (const RegularExpression& regex,
|
2012-02-11 06:52:19 +08:00
|
|
|
bool include_symbols,
|
|
|
|
bool include_inlines,
|
2011-01-27 14:44:37 +08:00
|
|
|
bool append,
|
|
|
|
SymbolContextList& sc_list)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-01-27 14:44:37 +08:00
|
|
|
if (!append)
|
|
|
|
sc_list.Clear();
|
|
|
|
|
|
|
|
const uint32_t start_size = sc_list.GetSize();
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
if (symbols)
|
2012-02-11 06:52:19 +08:00
|
|
|
symbols->FindFunctions(regex, include_inlines, append, sc_list);
|
2011-01-27 14:44:37 +08:00
|
|
|
// Now check our symbol table for symbols that are code symbols if requested
|
|
|
|
if (include_symbols)
|
|
|
|
{
|
|
|
|
ObjectFile *objfile = GetObjectFile();
|
|
|
|
if (objfile)
|
|
|
|
{
|
|
|
|
Symtab *symtab = objfile->GetSymtab();
|
|
|
|
if (symtab)
|
|
|
|
{
|
|
|
|
std::vector<uint32_t> symbol_indexes;
|
|
|
|
symtab->AppendSymbolIndexesMatchingRegExAndType (regex, eSymbolTypeCode, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
|
|
|
|
const uint32_t num_matches = symbol_indexes.size();
|
|
|
|
if (num_matches)
|
|
|
|
{
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
const bool merge_symbol_into_function = true;
|
2011-01-27 14:44:37 +08:00
|
|
|
SymbolContext sc(this);
|
|
|
|
for (uint32_t i=0; i<num_matches; i++)
|
|
|
|
{
|
|
|
|
sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
|
Added the ability to get the min and max instruction byte size for
an architecture into ArchSpec:
uint32_t
ArchSpec::GetMinimumOpcodeByteSize() const;
uint32_t
ArchSpec::GetMaximumOpcodeByteSize() const;
Added an AddressClass to the Instruction class in Disassembler.h.
This allows decoded instructions to know know if they are code,
code with alternate ISA (thumb), or even data which can be mixed
into code. The instruction does have an address, but it is a good
idea to cache this value so we don't have to look it up more than
once.
Fixed an issue in Opcode::SetOpcodeBytes() where the length wasn't
getting set.
Changed:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc);
To:
bool
SymbolContextList::AppendIfUnique (const SymbolContext& sc,
bool merge_symbol_into_function);
This function was typically being used when looking up functions
and symbols. Now if you lookup a function, then find the symbol,
they can be merged into the same symbol context and not cause
multiple symbol contexts to appear in a symbol context list that
describes the same function.
Fixed the SymbolContext not equal operator which was causing mixed
mode disassembly to not work ("disassembler --mixed --name main").
Modified the disassembler classes to know about the fact we know,
for a given architecture, what the min and max opcode byte sizes
are. The InstructionList class was modified to return the max
opcode byte size for all of the instructions in its list.
These two fixes means when disassemble a list of instructions and dump
them and show the opcode bytes, we can format the output more
intelligently when showing opcode bytes. This affects any architectures
that have varying opcode byte sizes (x86_64 and i386). Knowing the max
opcode byte size also helps us to be able to disassemble N instructions
without having to re-read data if we didn't read enough bytes.
Added the ability to set the architecture for the disassemble command.
This means you can easily cross disassemble data for any supported
architecture. I also added the ability to specify "thumb" as an
architecture so that we can force disassembly into thumb mode when
needed. In GDB this was done using a hack of specifying an odd
address when disassembling. I don't want to repeat this hack in LLDB,
so the auto detection between ARM and thumb is failing, just specify
thumb when disassembling:
(lldb) disassemble --arch thumb --name main
You can also have data in say an x86_64 file executable and disassemble
data as any other supported architecture:
% lldb a.out
Current executable set to 'a.out' (x86_64).
(lldb) b main
(lldb) run
(lldb) disassemble --arch thumb --count 2 --start-address 0x0000000100001080 --bytes
0x100001080: 0xb580 push {r7, lr}
0x100001082: 0xaf00 add r7, sp, #0
Fixed Target::ReadMemory(...) to be able to deal with Address argument object
that isn't section offset. When an address object was supplied that was
out on the heap or stack, target read memory would fail. Disassembly uses
Target::ReadMemory(...), and the example above where we disassembler thumb
opcodes in an x86 binary was failing do to this bug.
llvm-svn: 128347
2011-03-27 03:14:58 +08:00
|
|
|
sc_list.AppendIfUnique (sc, merge_symbol_into_function);
|
2011-01-27 14:44:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sc_list.GetSize() - start_size;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-08-03 09:26:16 +08:00
|
|
|
uint32_t
|
2012-03-27 07:03:23 +08:00
|
|
|
Module::FindTypes_Impl (const SymbolContext& sc,
|
|
|
|
const ConstString &name,
|
|
|
|
const ClangNamespaceDecl *namespace_decl,
|
|
|
|
bool append,
|
|
|
|
uint32_t max_matches,
|
|
|
|
TypeList& types)
|
2010-08-03 09:26:16 +08:00
|
|
|
{
|
|
|
|
Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
|
|
|
|
if (sc.module_sp.get() == NULL || sc.module_sp.get() == this)
|
|
|
|
{
|
|
|
|
SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
if (symbols)
|
2011-10-13 09:49:10 +08:00
|
|
|
return symbols->FindTypes(sc, name, namespace_decl, append, max_matches, types);
|
2010-08-03 09:26:16 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-27 07:03:23 +08:00
|
|
|
uint32_t
|
|
|
|
Module::FindTypesInNamespace (const SymbolContext& sc,
|
|
|
|
const ConstString &type_name,
|
|
|
|
const ClangNamespaceDecl *namespace_decl,
|
|
|
|
uint32_t max_matches,
|
|
|
|
TypeList& type_list)
|
2011-07-30 03:53:35 +08:00
|
|
|
{
|
2012-03-27 07:03:23 +08:00
|
|
|
const bool append = true;
|
|
|
|
return FindTypes_Impl(sc, type_name, namespace_decl, append, max_matches, type_list);
|
2011-07-30 03:53:35 +08:00
|
|
|
}
|
|
|
|
|
2012-12-06 05:24:42 +08:00
|
|
|
lldb::TypeSP
|
|
|
|
Module::FindFirstType (const SymbolContext& sc,
|
|
|
|
const ConstString &name,
|
|
|
|
bool exact_match)
|
|
|
|
{
|
|
|
|
TypeList type_list;
|
|
|
|
const uint32_t num_matches = FindTypes (sc, name, exact_match, 1, type_list);
|
|
|
|
if (num_matches)
|
|
|
|
return type_list.GetTypeAtIndex(0);
|
|
|
|
return TypeSP();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-30 03:53:35 +08:00
|
|
|
uint32_t
|
2012-03-27 07:03:23 +08:00
|
|
|
Module::FindTypes (const SymbolContext& sc,
|
|
|
|
const ConstString &name,
|
|
|
|
bool exact_match,
|
|
|
|
uint32_t max_matches,
|
|
|
|
TypeList& types)
|
2011-07-30 03:53:35 +08:00
|
|
|
{
|
2012-03-27 07:03:23 +08:00
|
|
|
uint32_t num_matches = 0;
|
|
|
|
const char *type_name_cstr = name.GetCString();
|
|
|
|
std::string type_scope;
|
|
|
|
std::string type_basename;
|
|
|
|
const bool append = true;
|
2012-10-23 00:19:56 +08:00
|
|
|
TypeClass type_class = eTypeClassAny;
|
|
|
|
if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class))
|
2011-07-30 03:53:35 +08:00
|
|
|
{
|
2012-03-27 07:03:23 +08:00
|
|
|
// Check if "name" starts with "::" which means the qualified type starts
|
|
|
|
// from the root namespace and implies and exact match. The typenames we
|
|
|
|
// get back from clang do not start with "::" so we need to strip this off
|
|
|
|
// in order to get the qualfied names to match
|
|
|
|
|
|
|
|
if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':')
|
|
|
|
{
|
|
|
|
type_scope.erase(0,2);
|
|
|
|
exact_match = true;
|
|
|
|
}
|
|
|
|
ConstString type_basename_const_str (type_basename.c_str());
|
|
|
|
if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types))
|
|
|
|
{
|
2012-10-23 00:19:56 +08:00
|
|
|
types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);
|
2012-03-27 07:03:23 +08:00
|
|
|
num_matches = types.GetSize();
|
|
|
|
}
|
2011-07-30 03:53:35 +08:00
|
|
|
}
|
|
|
|
else
|
2012-03-27 07:03:23 +08:00
|
|
|
{
|
|
|
|
// The type is not in a namespace/class scope, just search for it by basename
|
2012-10-23 00:19:56 +08:00
|
|
|
if (type_class != eTypeClassAny)
|
|
|
|
{
|
|
|
|
// The "type_name_cstr" will have been modified if we have a valid type class
|
|
|
|
// prefix (like "struct", "class", "union", "typedef" etc).
|
|
|
|
num_matches = FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types);
|
|
|
|
types.RemoveMismatchedTypes (type_class);
|
|
|
|
num_matches = types.GetSize();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types);
|
|
|
|
}
|
2012-03-27 07:03:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return num_matches;
|
2011-07-30 03:53:35 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//uint32_t
|
|
|
|
//Module::FindTypes(const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, Type::Encoding encoding, const char *udt_name, TypeList& types)
|
|
|
|
//{
|
|
|
|
// Timer scoped_timer(__PRETTY_FUNCTION__);
|
|
|
|
// SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
// if (symbols)
|
|
|
|
// return symbols->FindTypes(sc, regex, append, max_matches, encoding, udt_name, types);
|
|
|
|
// return 0;
|
|
|
|
//
|
|
|
|
//}
|
|
|
|
|
|
|
|
SymbolVendor*
|
|
|
|
Module::GetSymbolVendor (bool can_create)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
2010-09-08 07:40:05 +08:00
|
|
|
if (m_did_load_symbol_vendor == false && can_create)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
ObjectFile *obj_file = GetObjectFile ();
|
|
|
|
if (obj_file != NULL)
|
|
|
|
{
|
|
|
|
Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
|
2012-02-24 09:59:29 +08:00
|
|
|
m_symfile_ap.reset(SymbolVendor::FindPlugin(shared_from_this()));
|
2010-09-08 07:40:05 +08:00
|
|
|
m_did_load_symbol_vendor = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_symfile_ap.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Module::SetFileSpecAndObjectName (const FileSpec &file, const ConstString &object_name)
|
|
|
|
{
|
|
|
|
// Container objects whose paths do not specify a file directly can call
|
|
|
|
// this function to correct the file and object names.
|
|
|
|
m_file = file;
|
|
|
|
m_mod_time = file.GetModificationTime();
|
|
|
|
m_object_name = object_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ArchSpec&
|
|
|
|
Module::GetArchitecture () const
|
|
|
|
{
|
|
|
|
return m_arch;
|
|
|
|
}
|
|
|
|
|
2010-10-26 11:11:13 +08:00
|
|
|
void
|
2011-11-28 09:45:00 +08:00
|
|
|
Module::GetDescription (Stream *s, lldb::DescriptionLevel level)
|
2010-10-26 11:11:13 +08:00
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
|
|
|
|
2011-11-28 09:45:00 +08:00
|
|
|
if (level >= eDescriptionLevelFull)
|
|
|
|
{
|
|
|
|
if (m_arch.IsValid())
|
|
|
|
s->Printf("(%s) ", m_arch.GetArchitectureName());
|
|
|
|
}
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2011-11-28 09:45:00 +08:00
|
|
|
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);
|
|
|
|
}
|
2010-10-31 11:01:06 +08:00
|
|
|
|
|
|
|
const char *object_name = m_object_name.GetCString();
|
|
|
|
if (object_name)
|
|
|
|
s->Printf("(%s)", object_name);
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
|
|
|
|
2011-11-28 09:45:00 +08:00
|
|
|
void
|
|
|
|
Module::ReportError (const char *format, ...)
|
|
|
|
{
|
2012-01-05 11:57:59 +08:00
|
|
|
if (format && format[0])
|
|
|
|
{
|
|
|
|
StreamString strm;
|
|
|
|
strm.PutCString("error: ");
|
|
|
|
GetDescription(&strm, lldb::eDescriptionLevelBrief);
|
2012-01-11 09:59:18 +08:00
|
|
|
strm.PutChar (' ');
|
2012-01-05 11:57:59 +08:00
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
|
|
|
strm.PrintfVarArg(format, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
const int format_len = strlen(format);
|
|
|
|
if (format_len > 0)
|
|
|
|
{
|
|
|
|
const char last_char = format[format_len-1];
|
|
|
|
if (last_char != '\n' || last_char != '\r')
|
|
|
|
strm.EOL();
|
|
|
|
}
|
|
|
|
Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-13 06:51:12 +08:00
|
|
|
bool
|
|
|
|
Module::FileHasChanged () const
|
|
|
|
{
|
|
|
|
if (m_file_has_changed == false)
|
|
|
|
m_file_has_changed = (m_file.GetModificationTime() != m_mod_time);
|
|
|
|
return m_file_has_changed;
|
|
|
|
}
|
|
|
|
|
2012-01-05 11:57:59 +08:00
|
|
|
void
|
|
|
|
Module::ReportErrorIfModifyDetected (const char *format, ...)
|
|
|
|
{
|
2012-07-13 06:51:12 +08:00
|
|
|
if (m_first_file_changed_log == false)
|
2012-01-05 11:57:59 +08:00
|
|
|
{
|
2012-07-13 06:51:12 +08:00
|
|
|
if (FileHasChanged ())
|
2012-01-05 11:57:59 +08:00
|
|
|
{
|
2012-07-13 06:51:12 +08:00
|
|
|
m_first_file_changed_log = true;
|
|
|
|
if (format)
|
2012-01-05 11:57:59 +08:00
|
|
|
{
|
2012-07-13 06:51:12 +08:00
|
|
|
StreamString strm;
|
|
|
|
strm.PutCString("error: the object file ");
|
|
|
|
GetDescription(&strm, lldb::eDescriptionLevelFull);
|
|
|
|
strm.PutCString (" has been modified\n");
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
|
|
|
strm.PrintfVarArg(format, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
const int format_len = strlen(format);
|
|
|
|
if (format_len > 0)
|
|
|
|
{
|
|
|
|
const char last_char = format[format_len-1];
|
|
|
|
if (last_char != '\n' || last_char != '\r')
|
|
|
|
strm.EOL();
|
|
|
|
}
|
|
|
|
strm.PutCString("The debug session should be aborted as the original debug information has been overwritten.\n");
|
|
|
|
Host::SystemLog (Host::eSystemLogError, "%s", strm.GetString().c_str());
|
2012-01-05 11:57:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-28 09:45:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Module::ReportWarning (const char *format, ...)
|
|
|
|
{
|
2012-01-05 11:57:59 +08:00
|
|
|
if (format && format[0])
|
|
|
|
{
|
|
|
|
StreamString strm;
|
|
|
|
strm.PutCString("warning: ");
|
2012-01-11 09:59:18 +08:00
|
|
|
GetDescription(&strm, lldb::eDescriptionLevelFull);
|
|
|
|
strm.PutChar (' ');
|
2012-01-05 11:57:59 +08:00
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
|
|
|
strm.PrintfVarArg(format, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
const int format_len = strlen(format);
|
|
|
|
if (format_len > 0)
|
|
|
|
{
|
|
|
|
const char last_char = format[format_len-1];
|
|
|
|
if (last_char != '\n' || last_char != '\r')
|
|
|
|
strm.EOL();
|
|
|
|
}
|
|
|
|
Host::SystemLog (Host::eSystemLogWarning, "%s", strm.GetString().c_str());
|
|
|
|
}
|
2011-11-28 09:45:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Module::LogMessage (Log *log, const char *format, ...)
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
StreamString log_message;
|
2012-01-11 09:59:18 +08:00
|
|
|
GetDescription(&log_message, lldb::eDescriptionLevelFull);
|
2011-11-28 09:45:00 +08:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-24 06:55:20 +08:00
|
|
|
void
|
|
|
|
Module::LogMessageVerboseBacktrace (Log *log, const char *format, ...)
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
StreamString log_message;
|
|
|
|
GetDescription(&log_message, lldb::eDescriptionLevelFull);
|
|
|
|
log_message.PutCString (": ");
|
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
|
|
|
log_message.PrintfVarArg (format, args);
|
|
|
|
va_end (args);
|
|
|
|
if (log->GetVerbose())
|
|
|
|
Host::Backtrace (log_message, 1024);
|
|
|
|
log->PutCString(log_message.GetString().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
|
|
|
Module::Dump(Stream *s)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
2010-10-08 08:21:05 +08:00
|
|
|
//s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Indent();
|
|
|
|
s->Printf("Module %s/%s%s%s%s\n",
|
|
|
|
m_file.GetDirectory().AsCString(),
|
|
|
|
m_file.GetFilename().AsCString(),
|
|
|
|
m_object_name ? "(" : "",
|
|
|
|
m_object_name ? m_object_name.GetCString() : "",
|
|
|
|
m_object_name ? ")" : "");
|
|
|
|
|
|
|
|
s->IndentMore();
|
|
|
|
ObjectFile *objfile = GetObjectFile ();
|
|
|
|
|
|
|
|
if (objfile)
|
|
|
|
objfile->Dump(s);
|
|
|
|
|
|
|
|
SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
|
|
|
|
if (symbols)
|
|
|
|
symbols->Dump(s);
|
|
|
|
|
|
|
|
s->IndentLess();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TypeList*
|
|
|
|
Module::GetTypeList ()
|
|
|
|
{
|
|
|
|
SymbolVendor *symbols = GetSymbolVendor ();
|
|
|
|
if (symbols)
|
|
|
|
return &symbols->GetTypeList();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
Module::GetObjectName() const
|
|
|
|
{
|
|
|
|
return m_object_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectFile *
|
|
|
|
Module::GetObjectFile()
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
2010-09-08 07:40:05 +08:00
|
|
|
if (m_did_load_objfile == false)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-08 07:40:05 +08:00
|
|
|
m_did_load_objfile = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
Timer scoped_timer(__PRETTY_FUNCTION__,
|
|
|
|
"Module::GetObjectFile () module = %s", GetFileSpec().GetFilename().AsCString(""));
|
2012-01-12 13:25:17 +08:00
|
|
|
DataBufferSP file_data_sp;
|
2012-02-24 09:59:29 +08:00
|
|
|
m_objfile_sp = ObjectFile::FindPlugin (shared_from_this(),
|
|
|
|
&m_file,
|
|
|
|
m_object_offset,
|
|
|
|
m_file.GetByteSize(),
|
|
|
|
file_data_sp);
|
2011-09-21 11:57:31 +08:00
|
|
|
if (m_objfile_sp)
|
|
|
|
{
|
|
|
|
// Once we get the object file, update our module with the object file's
|
|
|
|
// architecture since it might differ in vendor/os if some parts were
|
|
|
|
// unknown.
|
|
|
|
m_objfile_sp->GetArchitecture (m_arch);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-09-19 02:59:15 +08:00
|
|
|
return m_objfile_sp.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Symbol *
|
|
|
|
Module::FindFirstSymbolWithNameAndType (const ConstString &name, SymbolType symbol_type)
|
|
|
|
{
|
|
|
|
Timer scoped_timer(__PRETTY_FUNCTION__,
|
|
|
|
"Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
|
|
|
|
name.AsCString(),
|
|
|
|
symbol_type);
|
|
|
|
ObjectFile *objfile = GetObjectFile();
|
|
|
|
if (objfile)
|
|
|
|
{
|
|
|
|
Symtab *symtab = objfile->GetSymtab();
|
|
|
|
if (symtab)
|
2010-09-11 11:13:28 +08:00
|
|
|
return symtab->FindFirstSymbolWithNameAndType (name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
void
|
|
|
|
Module::SymbolIndicesToSymbolContextList (Symtab *symtab, std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list)
|
|
|
|
{
|
|
|
|
// No need to protect this call using m_mutex all other method calls are
|
|
|
|
// already thread safe.
|
|
|
|
|
|
|
|
size_t num_indices = symbol_indexes.size();
|
|
|
|
if (num_indices > 0)
|
|
|
|
{
|
|
|
|
SymbolContext sc;
|
|
|
|
CalculateSymbolContext (&sc);
|
|
|
|
for (size_t i = 0; i < num_indices; i++)
|
|
|
|
{
|
|
|
|
sc.symbol = symtab->SymbolAtIndex (symbol_indexes[i]);
|
|
|
|
if (sc.symbol)
|
|
|
|
sc_list.Append (sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2011-10-14 00:49:47 +08:00
|
|
|
Module::FindSymbolsWithNameAndType (const ConstString &name, SymbolType symbol_type, SymbolContextList &sc_list)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// No need to protect this call using m_mutex all other method calls are
|
|
|
|
// already thread safe.
|
|
|
|
|
|
|
|
|
|
|
|
Timer scoped_timer(__PRETTY_FUNCTION__,
|
|
|
|
"Module::FindSymbolsWithNameAndType (name = %s, type = %i)",
|
|
|
|
name.AsCString(),
|
|
|
|
symbol_type);
|
|
|
|
const size_t initial_size = sc_list.GetSize();
|
|
|
|
ObjectFile *objfile = GetObjectFile ();
|
|
|
|
if (objfile)
|
|
|
|
{
|
|
|
|
Symtab *symtab = objfile->GetSymtab();
|
|
|
|
if (symtab)
|
|
|
|
{
|
|
|
|
std::vector<uint32_t> symbol_indexes;
|
|
|
|
symtab->FindAllSymbolsWithNameAndType (name, symbol_type, symbol_indexes);
|
|
|
|
SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sc_list.GetSize() - initial_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
Module::FindSymbolsMatchingRegExAndType (const RegularExpression ®ex, SymbolType symbol_type, SymbolContextList &sc_list)
|
|
|
|
{
|
|
|
|
// No need to protect this call using m_mutex all other method calls are
|
|
|
|
// already thread safe.
|
|
|
|
|
|
|
|
Timer scoped_timer(__PRETTY_FUNCTION__,
|
|
|
|
"Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
|
|
|
|
regex.GetText(),
|
|
|
|
symbol_type);
|
|
|
|
const size_t initial_size = sc_list.GetSize();
|
|
|
|
ObjectFile *objfile = GetObjectFile ();
|
|
|
|
if (objfile)
|
|
|
|
{
|
|
|
|
Symtab *symtab = objfile->GetSymtab();
|
|
|
|
if (symtab)
|
|
|
|
{
|
|
|
|
std::vector<uint32_t> symbol_indexes;
|
2010-09-11 11:13:28 +08:00
|
|
|
symtab->FindAllSymbolsMatchingRexExAndType (regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny, symbol_indexes);
|
2010-06-09 00:52:24 +08:00
|
|
|
SymbolIndicesToSymbolContextList (symtab, symbol_indexes, sc_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sc_list.GetSize() - initial_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TimeValue &
|
|
|
|
Module::GetModificationTime () const
|
|
|
|
{
|
|
|
|
return m_mod_time;
|
|
|
|
}
|
2010-08-10 07:31:02 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
Module::IsExecutable ()
|
|
|
|
{
|
|
|
|
if (GetObjectFile() == NULL)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return GetObjectFile()->IsExecutable();
|
|
|
|
}
|
|
|
|
|
2011-08-03 09:03:17 +08:00
|
|
|
bool
|
|
|
|
Module::IsLoadedInTarget (Target *target)
|
|
|
|
{
|
|
|
|
ObjectFile *obj_file = GetObjectFile();
|
|
|
|
if (obj_file)
|
|
|
|
{
|
|
|
|
SectionList *sections = obj_file->GetSectionList();
|
|
|
|
if (sections != NULL)
|
|
|
|
{
|
|
|
|
size_t num_sections = sections->GetSize();
|
|
|
|
for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++)
|
|
|
|
{
|
|
|
|
SectionSP section_sp = sections->GetSectionAtIndex(sect_idx);
|
|
|
|
if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-08 10:22:02 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
Module::LoadScriptingResourceInTarget (Target *target, Error& error)
|
|
|
|
{
|
|
|
|
if (!target)
|
|
|
|
{
|
|
|
|
error.SetErrorString("invalid destination Target");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlatformSP platform_sp(target->GetPlatform());
|
|
|
|
|
|
|
|
if (!platform_sp)
|
|
|
|
{
|
|
|
|
error.SetErrorString("invalid Platform");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ModuleSpec module_spec(GetFileSpec());
|
|
|
|
FileSpec scripting_fspec = platform_sp->LocateExecutableScriptingResource(module_spec);
|
|
|
|
Debugger &debugger(target->GetDebugger());
|
|
|
|
if (scripting_fspec && scripting_fspec.Exists())
|
|
|
|
{
|
|
|
|
ScriptInterpreter *script_interpreter = debugger.GetCommandInterpreter().GetScriptInterpreter();
|
|
|
|
if (script_interpreter)
|
|
|
|
{
|
|
|
|
StreamString scripting_stream;
|
|
|
|
scripting_fspec.Dump(&scripting_stream);
|
2012-12-08 01:43:38 +08:00
|
|
|
const bool can_reload = false;
|
|
|
|
const bool init_lldb_globals = false;
|
|
|
|
bool did_load = script_interpreter->LoadScriptingModule(scripting_stream.GetData(), can_reload, init_lldb_globals, error);
|
2012-11-08 10:22:02 +08:00
|
|
|
if (!did_load)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorString("invalid ScriptInterpreter");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-08-10 07:31:02 +08:00
|
|
|
Module::SetArchitecture (const ArchSpec &new_arch)
|
|
|
|
{
|
2011-02-23 08:35:02 +08:00
|
|
|
if (!m_arch.IsValid())
|
2010-08-10 07:31:02 +08:00
|
|
|
{
|
|
|
|
m_arch = new_arch;
|
|
|
|
return true;
|
2011-02-23 08:35:02 +08:00
|
|
|
}
|
2012-12-14 06:07:14 +08:00
|
|
|
return m_arch.IsExactMatch(new_arch);
|
2010-08-10 07:31:02 +08:00
|
|
|
}
|
|
|
|
|
2012-02-05 10:38:54 +08:00
|
|
|
bool
|
|
|
|
Module::SetLoadAddress (Target &target, lldb::addr_t offset, bool &changed)
|
|
|
|
{
|
2012-03-28 05:10:07 +08:00
|
|
|
size_t num_loaded_sections = 0;
|
|
|
|
ObjectFile *objfile = GetObjectFile();
|
|
|
|
if (objfile)
|
2012-02-05 10:38:54 +08:00
|
|
|
{
|
2012-03-28 05:10:07 +08:00
|
|
|
SectionList *section_list = objfile->GetSectionList ();
|
2012-02-05 10:38:54 +08:00
|
|
|
if (section_list)
|
|
|
|
{
|
|
|
|
const size_t num_sections = section_list->GetSize();
|
|
|
|
size_t sect_idx = 0;
|
|
|
|
for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
|
|
|
|
{
|
|
|
|
// Iterate through the object file sections to find the
|
|
|
|
// first section that starts of file offset zero and that
|
|
|
|
// has bytes in the file...
|
2012-07-07 09:24:12 +08:00
|
|
|
SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
|
2012-03-28 05:10:07 +08:00
|
|
|
// Only load non-thread specific sections when given a slide
|
2012-07-07 09:24:12 +08:00
|
|
|
if (section_sp && !section_sp->IsThreadSpecific())
|
2012-02-05 10:38:54 +08:00
|
|
|
{
|
2012-07-07 09:24:12 +08:00
|
|
|
if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + offset))
|
2012-03-28 05:10:07 +08:00
|
|
|
++num_loaded_sections;
|
2012-02-05 10:38:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-28 05:10:07 +08:00
|
|
|
changed = num_loaded_sections > 0;
|
|
|
|
return num_loaded_sections > 0;
|
2012-02-05 10:38:54 +08:00
|
|
|
}
|
|
|
|
|
2012-02-26 13:51:37 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
Module::MatchesModuleSpec (const ModuleSpec &module_ref)
|
|
|
|
{
|
|
|
|
const UUID &uuid = module_ref.GetUUID();
|
|
|
|
|
|
|
|
if (uuid.IsValid())
|
|
|
|
{
|
|
|
|
// If the UUID matches, then nothing more needs to match...
|
|
|
|
if (uuid == GetUUID())
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FileSpec &file_spec = module_ref.GetFileSpec();
|
|
|
|
if (file_spec)
|
|
|
|
{
|
|
|
|
if (!FileSpec::Equal (file_spec, m_file, file_spec.GetDirectory()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
|
|
|
|
if (platform_file_spec)
|
|
|
|
{
|
2012-10-02 14:04:17 +08:00
|
|
|
if (!FileSpec::Equal (platform_file_spec, GetPlatformFileSpec (), platform_file_spec.GetDirectory()))
|
2012-02-26 13:51:37 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ArchSpec &arch = module_ref.GetArchitecture();
|
|
|
|
if (arch.IsValid())
|
|
|
|
{
|
2012-12-14 06:07:14 +08:00
|
|
|
if (!m_arch.IsCompatibleMatch(arch))
|
2012-02-26 13:51:37 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &object_name = module_ref.GetObjectName();
|
|
|
|
if (object_name)
|
|
|
|
{
|
|
|
|
if (object_name != GetObjectName())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-16 05:01:31 +08:00
|
|
|
bool
|
|
|
|
Module::FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
|
|
|
return m_source_mappings.FindFile (orig_spec, new_spec);
|
|
|
|
}
|
|
|
|
|
2012-03-20 06:22:41 +08:00
|
|
|
bool
|
|
|
|
Module::RemapSourceFile (const char *path, std::string &new_path) const
|
|
|
|
{
|
|
|
|
Mutex::Locker locker (m_mutex);
|
|
|
|
return m_source_mappings.RemapPath(path, new_path);
|
|
|
|
}
|
|
|
|
|
2012-09-05 02:47:54 +08:00
|
|
|
uint32_t
|
|
|
|
Module::GetVersion (uint32_t *versions, uint32_t num_versions)
|
|
|
|
{
|
|
|
|
ObjectFile *obj_file = GetObjectFile();
|
|
|
|
if (obj_file)
|
|
|
|
return obj_file->GetVersion (versions, num_versions);
|
|
|
|
|
|
|
|
if (versions && num_versions)
|
|
|
|
{
|
|
|
|
for (uint32_t i=0; i<num_versions; ++i)
|
|
|
|
versions[i] = UINT32_MAX;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|