[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 08:23:27 +01:00
|
|
|
//===-- Module.cpp --------------------------------------------------------===//
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2016-03-11 20:20:38 +00:00
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
|
|
2018-11-11 23:16:43 +00:00
|
|
|
#include "lldb/Core/AddressRange.h"
|
2013-09-12 02:20:34 +00:00
|
|
|
#include "lldb/Core/AddressResolverFileLine.h"
|
Added the ability to cache the finalized symbol tables subsequent debug sessions to start faster.
This is an updated version of the https://reviews.llvm.org/D113789 patch with the following changes:
- We no longer modify modification times of the cache files
- Use LLVM caching and cache pruning instead of making a new cache mechanism (See DataFileCache.h/.cpp)
- Add signature to start of each file since we are not using modification times so we can tell when caches are stale and remove and re-create the cache file as files are changed
- Add settings to control the cache size, disk percentage and expiration in days to keep cache size under control
This patch enables symbol tables to be cached in the LLDB index cache directory. All cache files are in a single directory and the files use unique names to ensure that files from the same path will re-use the same file as files get modified. This means as files change, their cache files will be deleted and updated. The modification time of each of the cache files is not modified so that access based pruning of the cache can be implemented.
The symbol table cache files start with a signature that uniquely identifies a file on disk and contains one or more of the following items:
- object file UUID if available
- object file mod time if available
- object name for BSD archive .o files that are in .a files if available
If none of these signature items are available, then the file will not be cached. This keeps temporary object files from expressions from being cached.
When the cache files are loaded on subsequent debug sessions, the signature is compare and if the file has been modified (uuid changes, mod time changes, or object file mod time changes) then the cache file is deleted and re-created.
Module caching must be enabled by the user before this can be used:
symbols.enable-lldb-index-cache (boolean) = false
(lldb) settings set symbols.enable-lldb-index-cache true
There is also a setting that allows the user to specify a module cache directory that defaults to a directory that defaults to being next to the symbols.clang-modules-cache-path directory in a temp directory:
(lldb) settings show symbols.lldb-index-cache-path
/var/folders/9p/472sr0c55l9b20x2zg36b91h0000gn/C/lldb/IndexCache
If this setting is enabled, the finalized symbol tables will be serialized and saved to disc so they can be quickly loaded next time you debug.
Each module can cache one or more files in the index cache directory. The cache file names must be unique to a file on disk and its architecture and object name for .o files in BSD archives. This allows universal mach-o files to support caching multuple architectures in the same module cache directory. Making the file based on the this info allows this cache file to be deleted and replaced when the file gets updated on disk. This keeps the cache from growing over time during the compile/edit/debug cycle and prevents out of space issues.
If the cache is enabled, the symbol table will be loaded from the cache the next time you debug if the module has not changed.
The cache also has settings to control the size of the cache on disk. Each time LLDB starts up with the index cache enable, the cache will be pruned to ensure it stays within the user defined settings:
(lldb) settings set symbols.lldb-index-cache-expiration-days <days>
A value of zero will disable cache files from expiring when the cache is pruned. The default value is 7 currently.
(lldb) settings set symbols.lldb-index-cache-max-byte-size <size>
A value of zero will disable pruning based on a total byte size. The default value is zero currently.
(lldb) settings set symbols.lldb-index-cache-max-percent <percentage-of-disk-space>
A value of 100 will allow the disc to be filled to the max, a value of zero will disable percentage pruning. The default value is zero.
Reviewed By: labath, wallace
Differential Revision: https://reviews.llvm.org/D115324
2021-12-16 09:59:25 -08:00
|
|
|
#include "lldb/Core/DataFileCache.h"
|
2018-11-11 23:16:43 +00:00
|
|
|
#include "lldb/Core/Debugger.h"
|
|
|
|
|
#include "lldb/Core/FileSpecList.h"
|
|
|
|
|
#include "lldb/Core/Mangled.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-29 21:13:06 +00:00
|
|
|
#include "lldb/Core/ModuleSpec.h"
|
2018-11-11 23:16:43 +00:00
|
|
|
#include "lldb/Core/SearchFilter.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-29 21:13:06 +00:00
|
|
|
#include "lldb/Core/Section.h"
|
2016-11-01 16:11:14 +00:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2012-01-05 03:57:59 +00:00
|
|
|
#include "lldb/Host/Host.h"
|
2020-05-04 13:52:10 -07:00
|
|
|
#include "lldb/Host/HostInfo.h"
|
2012-11-08 02:22:02 +00:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
|
#include "lldb/Interpreter/ScriptInterpreter.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-29 21:13:06 +00:00
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
2018-11-11 23:16:43 +00:00
|
|
|
#include "lldb/Symbol/Function.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
2018-11-11 23:16:43 +00:00
|
|
|
#include "lldb/Symbol/Symbol.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
TypeSystem is now a plugin interface and removed any "ClangASTContext &Class::GetClangASTContext()" functions.
This cleans up type systems to be more pluggable. Prior to this we had issues:
- Module, SymbolFile, and many others has "ClangASTContext &GetClangASTContext()" functions. All have been switched over to use "TypeSystem *GetTypeSystemForLanguage()"
- Cleaned up any places that were using the GetClangASTContext() functions to use TypeSystem
- Cleaned up Module so that it no longer has dedicated type system member variables:
lldb::ClangASTContextUP m_ast; ///< The Clang AST context for this module.
lldb::GoASTContextUP m_go_ast; ///< The Go AST context for this module.
Now we have a type system map:
typedef std::map<lldb::LanguageType, lldb::TypeSystemSP> TypeSystemMap;
TypeSystemMap m_type_system_map; ///< A map of any type systems associated with this module
- Many places in code were using ClangASTContext static functions to place with CompilerType objects and add modifiers (const, volatile, restrict) and to make typedefs, L and R value references and more. These have been made into CompilerType functions that are abstract:
class CompilerType
{
...
//----------------------------------------------------------------------
// Return a new CompilerType that is a L value reference to this type if
// this type is valid and the type system supports L value references,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
GetLValueReferenceType () const;
//----------------------------------------------------------------------
// Return a new CompilerType that is a R value reference to this type if
// this type is valid and the type system supports R value references,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
GetRValueReferenceType () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a const modifier to this type if
// this type is valid and the type system supports const modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddConstModifier () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a volatile modifier to this type if
// this type is valid and the type system supports volatile modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddVolatileModifier () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a restrict modifier to this type if
// this type is valid and the type system supports restrict modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddRestrictModifier () const;
//----------------------------------------------------------------------
// Create a typedef to this type using "name" as the name of the typedef
// this type is valid and the type system supports typedefs, else return
// an invalid type.
//----------------------------------------------------------------------
CompilerType
CreateTypedef (const char *name, const CompilerDeclContext &decl_ctx) const;
};
Other changes include:
- Removed "CompilerType TypeSystem::GetIntTypeFromBitSize(...)" and CompilerType TypeSystem::GetFloatTypeFromBitSize(...) and replaced it with "CompilerType TypeSystem::GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size);"
- Fixed code in Type.h to not request the full type for a type for no good reason, just request the forward type and let the type expand as needed
llvm-svn: 247953
2015-09-17 22:23:34 +00:00
|
|
|
#include "lldb/Symbol/SymbolFile.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Symbol/SymbolVendor.h"
|
2018-11-11 23:16:43 +00:00
|
|
|
#include "lldb/Symbol/Symtab.h"
|
|
|
|
|
#include "lldb/Symbol/Type.h"
|
|
|
|
|
#include "lldb/Symbol/TypeList.h"
|
2015-10-08 09:45:41 +00:00
|
|
|
#include "lldb/Symbol/TypeMap.h"
|
TypeSystem is now a plugin interface and removed any "ClangASTContext &Class::GetClangASTContext()" functions.
This cleans up type systems to be more pluggable. Prior to this we had issues:
- Module, SymbolFile, and many others has "ClangASTContext &GetClangASTContext()" functions. All have been switched over to use "TypeSystem *GetTypeSystemForLanguage()"
- Cleaned up any places that were using the GetClangASTContext() functions to use TypeSystem
- Cleaned up Module so that it no longer has dedicated type system member variables:
lldb::ClangASTContextUP m_ast; ///< The Clang AST context for this module.
lldb::GoASTContextUP m_go_ast; ///< The Go AST context for this module.
Now we have a type system map:
typedef std::map<lldb::LanguageType, lldb::TypeSystemSP> TypeSystemMap;
TypeSystemMap m_type_system_map; ///< A map of any type systems associated with this module
- Many places in code were using ClangASTContext static functions to place with CompilerType objects and add modifiers (const, volatile, restrict) and to make typedefs, L and R value references and more. These have been made into CompilerType functions that are abstract:
class CompilerType
{
...
//----------------------------------------------------------------------
// Return a new CompilerType that is a L value reference to this type if
// this type is valid and the type system supports L value references,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
GetLValueReferenceType () const;
//----------------------------------------------------------------------
// Return a new CompilerType that is a R value reference to this type if
// this type is valid and the type system supports R value references,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
GetRValueReferenceType () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a const modifier to this type if
// this type is valid and the type system supports const modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddConstModifier () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a volatile modifier to this type if
// this type is valid and the type system supports volatile modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddVolatileModifier () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a restrict modifier to this type if
// this type is valid and the type system supports restrict modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddRestrictModifier () const;
//----------------------------------------------------------------------
// Create a typedef to this type using "name" as the name of the typedef
// this type is valid and the type system supports typedefs, else return
// an invalid type.
//----------------------------------------------------------------------
CompilerType
CreateTypedef (const char *name, const CompilerDeclContext &decl_ctx) const;
};
Other changes include:
- Removed "CompilerType TypeSystem::GetIntTypeFromBitSize(...)" and CompilerType TypeSystem::GetFloatTypeFromBitSize(...) and replaced it with "CompilerType TypeSystem::GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size);"
- Fixed code in Type.h to not request the full type for a type for no good reason, just request the forward type and let the type expand as needed
llvm-svn: 247953
2015-09-17 22:23:34 +00:00
|
|
|
#include "lldb/Symbol/TypeSystem.h"
|
2015-09-02 01:06:46 +00:00
|
|
|
#include "lldb/Target/Language.h"
|
2012-02-05 02:38:54 +00:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
|
#include "lldb/Target/Target.h"
|
2017-03-04 01:30:05 +00:00
|
|
|
#include "lldb/Utility/DataBufferHeap.h"
|
2018-05-02 20:06:17 +00:00
|
|
|
#include "lldb/Utility/LLDBAssert.h"
|
2022-02-03 13:26:10 +01:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2017-03-03 20:56:28 +00:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-02-02 21:39:50 +00:00
|
|
|
#include "lldb/Utility/RegularExpression.h"
|
2017-05-12 04:51:55 +00:00
|
|
|
#include "lldb/Utility/Status.h"
|
2018-11-11 23:16:43 +00:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-02-02 21:39:50 +00:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2017-06-29 14:32:17 +00:00
|
|
|
#include "lldb/Utility/Timer.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2018-04-10 13:33:45 +00:00
|
|
|
#if defined(_WIN32)
|
2018-11-11 23:16:43 +00:00
|
|
|
#include "lldb/Host/windows/PosixApi.h"
|
2017-04-06 21:28:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
|
2021-08-24 14:52:17 -07:00
|
|
|
#include "Plugins/Language/ObjC/ObjCLanguage.h"
|
2014-03-24 23:10:19 +00:00
|
|
|
|
2018-11-11 23:16:43 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
|
#include "llvm/Support/Compiler.h"
|
Added the ability to cache the finalized symbol tables subsequent debug sessions to start faster.
This is an updated version of the https://reviews.llvm.org/D113789 patch with the following changes:
- We no longer modify modification times of the cache files
- Use LLVM caching and cache pruning instead of making a new cache mechanism (See DataFileCache.h/.cpp)
- Add signature to start of each file since we are not using modification times so we can tell when caches are stale and remove and re-create the cache file as files are changed
- Add settings to control the cache size, disk percentage and expiration in days to keep cache size under control
This patch enables symbol tables to be cached in the LLDB index cache directory. All cache files are in a single directory and the files use unique names to ensure that files from the same path will re-use the same file as files get modified. This means as files change, their cache files will be deleted and updated. The modification time of each of the cache files is not modified so that access based pruning of the cache can be implemented.
The symbol table cache files start with a signature that uniquely identifies a file on disk and contains one or more of the following items:
- object file UUID if available
- object file mod time if available
- object name for BSD archive .o files that are in .a files if available
If none of these signature items are available, then the file will not be cached. This keeps temporary object files from expressions from being cached.
When the cache files are loaded on subsequent debug sessions, the signature is compare and if the file has been modified (uuid changes, mod time changes, or object file mod time changes) then the cache file is deleted and re-created.
Module caching must be enabled by the user before this can be used:
symbols.enable-lldb-index-cache (boolean) = false
(lldb) settings set symbols.enable-lldb-index-cache true
There is also a setting that allows the user to specify a module cache directory that defaults to a directory that defaults to being next to the symbols.clang-modules-cache-path directory in a temp directory:
(lldb) settings show symbols.lldb-index-cache-path
/var/folders/9p/472sr0c55l9b20x2zg36b91h0000gn/C/lldb/IndexCache
If this setting is enabled, the finalized symbol tables will be serialized and saved to disc so they can be quickly loaded next time you debug.
Each module can cache one or more files in the index cache directory. The cache file names must be unique to a file on disk and its architecture and object name for .o files in BSD archives. This allows universal mach-o files to support caching multuple architectures in the same module cache directory. Making the file based on the this info allows this cache file to be deleted and replaced when the file gets updated on disk. This keeps the cache from growing over time during the compile/edit/debug cycle and prevents out of space issues.
If the cache is enabled, the symbol table will be loaded from the cache the next time you debug if the module has not changed.
The cache also has settings to control the size of the cache on disk. Each time LLDB starts up with the index cache enable, the cache will be pruned to ensure it stays within the user defined settings:
(lldb) settings set symbols.lldb-index-cache-expiration-days <days>
A value of zero will disable cache files from expiring when the cache is pruned. The default value is 7 currently.
(lldb) settings set symbols.lldb-index-cache-max-byte-size <size>
A value of zero will disable pruning based on a total byte size. The default value is zero currently.
(lldb) settings set symbols.lldb-index-cache-max-percent <percentage-of-disk-space>
A value of 100 will allow the disc to be filled to the max, a value of zero will disable percentage pruning. The default value is zero.
Reviewed By: labath, wallace
Differential Revision: https://reviews.llvm.org/D115324
2021-12-16 09:59:25 -08:00
|
|
|
#include "llvm/Support/DJB.h"
|
2017-04-06 21:28:29 +00:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
Added the ability to cache the finalized symbol tables subsequent debug sessions to start faster.
This is an updated version of the https://reviews.llvm.org/D113789 patch with the following changes:
- We no longer modify modification times of the cache files
- Use LLVM caching and cache pruning instead of making a new cache mechanism (See DataFileCache.h/.cpp)
- Add signature to start of each file since we are not using modification times so we can tell when caches are stale and remove and re-create the cache file as files are changed
- Add settings to control the cache size, disk percentage and expiration in days to keep cache size under control
This patch enables symbol tables to be cached in the LLDB index cache directory. All cache files are in a single directory and the files use unique names to ensure that files from the same path will re-use the same file as files get modified. This means as files change, their cache files will be deleted and updated. The modification time of each of the cache files is not modified so that access based pruning of the cache can be implemented.
The symbol table cache files start with a signature that uniquely identifies a file on disk and contains one or more of the following items:
- object file UUID if available
- object file mod time if available
- object name for BSD archive .o files that are in .a files if available
If none of these signature items are available, then the file will not be cached. This keeps temporary object files from expressions from being cached.
When the cache files are loaded on subsequent debug sessions, the signature is compare and if the file has been modified (uuid changes, mod time changes, or object file mod time changes) then the cache file is deleted and re-created.
Module caching must be enabled by the user before this can be used:
symbols.enable-lldb-index-cache (boolean) = false
(lldb) settings set symbols.enable-lldb-index-cache true
There is also a setting that allows the user to specify a module cache directory that defaults to a directory that defaults to being next to the symbols.clang-modules-cache-path directory in a temp directory:
(lldb) settings show symbols.lldb-index-cache-path
/var/folders/9p/472sr0c55l9b20x2zg36b91h0000gn/C/lldb/IndexCache
If this setting is enabled, the finalized symbol tables will be serialized and saved to disc so they can be quickly loaded next time you debug.
Each module can cache one or more files in the index cache directory. The cache file names must be unique to a file on disk and its architecture and object name for .o files in BSD archives. This allows universal mach-o files to support caching multuple architectures in the same module cache directory. Making the file based on the this info allows this cache file to be deleted and replaced when the file gets updated on disk. This keeps the cache from growing over time during the compile/edit/debug cycle and prevents out of space issues.
If the cache is enabled, the symbol table will be loaded from the cache the next time you debug if the module has not changed.
The cache also has settings to control the size of the cache on disk. Each time LLDB starts up with the index cache enable, the cache will be pruned to ensure it stays within the user defined settings:
(lldb) settings set symbols.lldb-index-cache-expiration-days <days>
A value of zero will disable cache files from expiring when the cache is pruned. The default value is 7 currently.
(lldb) settings set symbols.lldb-index-cache-max-byte-size <size>
A value of zero will disable pruning based on a total byte size. The default value is zero currently.
(lldb) settings set symbols.lldb-index-cache-max-percent <percentage-of-disk-space>
A value of 100 will allow the disc to be filled to the max, a value of zero will disable percentage pruning. The default value is zero.
Reviewed By: labath, wallace
Differential Revision: https://reviews.llvm.org/D115324
2021-12-16 09:59:25 -08:00
|
|
|
#include "llvm/Support/FormatVariadic.h"
|
|
|
|
|
#include "llvm/Support/JSON.h"
|
2017-04-06 21:28:29 +00:00
|
|
|
#include "llvm/Support/Signals.h"
|
2018-11-11 23:16:43 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-04-06 21:28:29 +00:00
|
|
|
|
2021-05-26 12:19:37 +02:00
|
|
|
#include <cassert>
|
|
|
|
|
#include <cinttypes>
|
|
|
|
|
#include <cstdarg>
|
2018-11-11 23:16:43 +00:00
|
|
|
#include <cstdint>
|
2021-05-26 12:19:37 +02:00
|
|
|
#include <cstring>
|
2018-11-11 23:16:43 +00:00
|
|
|
#include <map>
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
#include <utility>
|
2017-04-06 21:28:29 +00:00
|
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
|
class CompilerDeclContext;
|
|
|
|
|
}
|
|
|
|
|
namespace lldb_private {
|
|
|
|
|
class VariableList;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2018-04-30 16:49:04 +00: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
|
2011-08-09 00:01:09 +00:00
|
|
|
typedef std::vector<Module *> ModuleCollection;
|
|
|
|
|
|
|
|
|
|
static ModuleCollection &GetModuleCollection() {
|
2011-10-31 23:47:10 +00:00
|
|
|
// This module collection needs to live past any module, so we could either
|
2018-04-30 16:49:04 +00:00
|
|
|
// 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.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-03-11 20:20:38 +00:00
|
|
|
static ModuleCollection *g_module_collection = nullptr;
|
|
|
|
|
if (g_module_collection == nullptr)
|
2011-10-31 23:47:10 +00:00
|
|
|
g_module_collection = new ModuleCollection();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-10-31 23:47:10 +00:00
|
|
|
return *g_module_collection;
|
2011-08-09 00:01:09 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-08-09 00:01:09 +00:00
|
|
|
std::recursive_mutex &Module::GetAllocationModuleCollectionMutex() {
|
2012-01-27 18:08:35 +00:00
|
|
|
// NOTE: The mutex below must be leaked since the global module list in
|
2018-04-30 16:49:04 +00:00
|
|
|
// 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
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-05-18 01:59:10 +00:00
|
|
|
static std::recursive_mutex *g_module_collection_mutex = nullptr;
|
2016-03-11 20:20:38 +00:00
|
|
|
if (g_module_collection_mutex == nullptr)
|
2016-05-18 01:59:10 +00:00
|
|
|
g_module_collection_mutex = new std::recursive_mutex; // NOTE: known leak
|
|
|
|
|
return *g_module_collection_mutex;
|
2011-08-09 00:01:09 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-08-09 00:01:09 +00:00
|
|
|
size_t Module::GetNumberAllocatedModules() {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
|
GetAllocationModuleCollectionMutex());
|
2011-08-09 00:01:09 +00:00
|
|
|
return GetModuleCollection().size();
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-08-09 00:01:09 +00:00
|
|
|
Module *Module::GetAllocatedModuleAtIndex(size_t idx) {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
|
GetAllocationModuleCollectionMutex());
|
2011-08-09 00:01:09 +00:00
|
|
|
ModuleCollection &modules = GetModuleCollection();
|
|
|
|
|
if (idx < modules.size())
|
|
|
|
|
return modules[idx];
|
2016-03-11 20:20:38 +00:00
|
|
|
return nullptr;
|
2011-08-09 00:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-18 01:59:10 +00:00
|
|
|
Module::Module(const ModuleSpec &module_spec)
|
2022-03-14 13:32:03 -07:00
|
|
|
: m_file_has_changed(false), m_first_file_changed_log(false) {
|
2016-05-18 01:59:10 +00:00
|
|
|
// Scope for locker below...
|
2016-09-06 20:57:50 +00:00
|
|
|
{
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
|
GetAllocationModuleCollectionMutex());
|
2012-02-26 05:51:37 +00:00
|
|
|
GetModuleCollection().push_back(this);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-31 15:57:48 +01:00
|
|
|
Log *log(GetLog(LLDBLog::Object | LLDBLog::Modules));
|
2016-03-11 20:20:38 +00:00
|
|
|
if (log != nullptr)
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "%p Module::Module((%s) '%s%s%s%s')",
|
|
|
|
|
static_cast<void *>(this),
|
|
|
|
|
module_spec.GetArchitecture().GetArchitectureName(),
|
|
|
|
|
module_spec.GetFileSpec().GetPath().c_str(),
|
|
|
|
|
module_spec.GetObjectName().IsEmpty() ? "" : "(",
|
2022-07-07 20:27:05 +00:00
|
|
|
module_spec.GetObjectName().AsCString(""),
|
2019-07-24 17:56:10 +00:00
|
|
|
module_spec.GetObjectName().IsEmpty() ? "" : ")");
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2020-07-09 14:14:36 -07:00
|
|
|
auto data_sp = module_spec.GetData();
|
|
|
|
|
lldb::offset_t file_size = 0;
|
|
|
|
|
if (data_sp)
|
|
|
|
|
file_size = data_sp->GetByteSize();
|
|
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// First extract all module specifications from the file using the local file
|
|
|
|
|
// path. If there are no specifications, then don't fill anything in
|
2014-03-04 21:20:23 +00:00
|
|
|
ModuleSpecList modules_specs;
|
2020-07-09 14:14:36 -07:00
|
|
|
if (ObjectFile::GetModuleSpecifications(
|
|
|
|
|
module_spec.GetFileSpec(), 0, file_size, modules_specs, data_sp) == 0)
|
2014-03-04 21:20:23 +00:00
|
|
|
return;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-03-04 21:20:23 +00:00
|
|
|
// Now make sure that one of the module specifications matches what we just
|
|
|
|
|
// extract. We might have a module specification that specifies a file
|
2018-04-30 16:49:04 +00:00
|
|
|
// "/usr/lib/dyld" with UUID XXX, but we might have a local version of
|
|
|
|
|
// "/usr/lib/dyld" that has
|
2014-03-04 21:20:23 +00:00
|
|
|
// UUID YYY and we don't want those to match. If they don't match, just don't
|
|
|
|
|
// fill any ivars in so we don't accidentally grab the wrong file later since
|
|
|
|
|
// they don't match...
|
|
|
|
|
ModuleSpec matching_module_spec;
|
2018-08-07 18:00:30 +00:00
|
|
|
if (!modules_specs.FindMatchingModuleSpec(module_spec,
|
|
|
|
|
matching_module_spec)) {
|
|
|
|
|
if (log) {
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "Found local object file but the specs didn't match");
|
2018-08-07 18:00:30 +00:00
|
|
|
}
|
2014-03-04 21:20:23 +00:00
|
|
|
return;
|
2018-08-07 18:00:30 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2020-07-09 14:14:36 -07:00
|
|
|
// Set m_data_sp if it was initially provided in the ModuleSpec. Note that
|
|
|
|
|
// we cannot use the data_sp variable here, because it will have been
|
|
|
|
|
// modified by GetModuleSpecifications().
|
|
|
|
|
if (auto module_spec_data_sp = module_spec.GetData()) {
|
|
|
|
|
m_data_sp = module_spec_data_sp;
|
|
|
|
|
m_mod_time = {};
|
|
|
|
|
} else {
|
|
|
|
|
if (module_spec.GetFileSpec())
|
|
|
|
|
m_mod_time =
|
|
|
|
|
FileSystem::Instance().GetModificationTime(module_spec.GetFileSpec());
|
|
|
|
|
else if (matching_module_spec.GetFileSpec())
|
|
|
|
|
m_mod_time = FileSystem::Instance().GetModificationTime(
|
|
|
|
|
matching_module_spec.GetFileSpec());
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// Copy the architecture from the actual spec if we got one back, else use
|
|
|
|
|
// the one that was specified
|
2014-05-29 21:33:45 +00:00
|
|
|
if (matching_module_spec.GetArchitecture().IsValid())
|
|
|
|
|
m_arch = matching_module_spec.GetArchitecture();
|
|
|
|
|
else if (module_spec.GetArchitecture().IsValid())
|
2014-03-04 21:20:23 +00:00
|
|
|
m_arch = module_spec.GetArchitecture();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-07-01 21:22:11 +00:00
|
|
|
// Copy the file spec over and use the specified one (if there was one) so we
|
2014-05-29 21:33:45 +00:00
|
|
|
// don't use a path that might have gotten resolved a path in
|
|
|
|
|
// 'matching_module_spec'
|
|
|
|
|
if (module_spec.GetFileSpec())
|
|
|
|
|
m_file = module_spec.GetFileSpec();
|
|
|
|
|
else if (matching_module_spec.GetFileSpec())
|
|
|
|
|
m_file = matching_module_spec.GetFileSpec();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-05-29 21:33:45 +00:00
|
|
|
// Copy the platform file spec over
|
|
|
|
|
if (module_spec.GetPlatformFileSpec())
|
|
|
|
|
m_platform_file = module_spec.GetPlatformFileSpec();
|
|
|
|
|
else if (matching_module_spec.GetPlatformFileSpec())
|
|
|
|
|
m_platform_file = matching_module_spec.GetPlatformFileSpec();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-05-29 21:33:45 +00:00
|
|
|
// Copy the symbol file spec over
|
|
|
|
|
if (module_spec.GetSymbolFileSpec())
|
|
|
|
|
m_symfile_spec = module_spec.GetSymbolFileSpec();
|
|
|
|
|
else if (matching_module_spec.GetSymbolFileSpec())
|
|
|
|
|
m_symfile_spec = matching_module_spec.GetSymbolFileSpec();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-05-29 21:33:45 +00:00
|
|
|
// Copy the object name over
|
|
|
|
|
if (matching_module_spec.GetObjectName())
|
|
|
|
|
m_object_name = matching_module_spec.GetObjectName();
|
2014-03-04 21:20:23 +00:00
|
|
|
else
|
2014-05-29 21:33:45 +00:00
|
|
|
m_object_name = module_spec.GetObjectName();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// Always trust the object offset (file offset) and object modification time
|
|
|
|
|
// (for mod time in a BSD static archive) of from the matching module
|
|
|
|
|
// specification
|
2014-05-29 17:52:46 +00:00
|
|
|
m_object_offset = matching_module_spec.GetObjectOffset();
|
|
|
|
|
m_object_mod_time = matching_module_spec.GetObjectModificationTime();
|
2012-02-26 05:51:37 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-05-18 01:59:10 +00:00
|
|
|
Module::Module(const FileSpec &file_spec, const ArchSpec &arch,
|
|
|
|
|
const ConstString *object_name, lldb::offset_t object_offset,
|
2016-11-09 09:59:18 +00:00
|
|
|
const llvm::sys::TimePoint<> &object_mod_time)
|
2021-12-09 12:09:56 +01:00
|
|
|
: m_mod_time(FileSystem::Instance().GetModificationTime(file_spec)),
|
|
|
|
|
m_arch(arch), m_file(file_spec), m_object_offset(object_offset),
|
2016-11-09 09:59:18 +00:00
|
|
|
m_object_mod_time(object_mod_time), m_file_has_changed(false),
|
|
|
|
|
m_first_file_changed_log(false) {
|
2011-08-09 00:01:09 +00:00
|
|
|
// Scope for locker below...
|
|
|
|
|
{
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
|
GetAllocationModuleCollectionMutex());
|
2011-08-09 00:01:09 +00:00
|
|
|
GetModuleCollection().push_back(this);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
if (object_name)
|
|
|
|
|
m_object_name = *object_name;
|
2014-04-04 04:06:10 +00:00
|
|
|
|
2022-01-31 15:57:48 +01:00
|
|
|
Log *log(GetLog(LLDBLog::Object | LLDBLog::Modules));
|
2016-03-11 20:20:38 +00:00
|
|
|
if (log != nullptr)
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "%p Module::Module((%s) '%s%s%s%s')",
|
|
|
|
|
static_cast<void *>(this), m_arch.GetArchitectureName(),
|
|
|
|
|
m_file.GetPath().c_str(), m_object_name.IsEmpty() ? "" : "(",
|
2022-07-07 20:27:05 +00:00
|
|
|
m_object_name.AsCString(""), m_object_name.IsEmpty() ? "" : ")");
|
2016-05-18 01:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Module::Module() : m_file_has_changed(false), m_first_file_changed_log(false) {
|
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
|
GetAllocationModuleCollectionMutex());
|
|
|
|
|
GetModuleCollection().push_back(this);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-18 01:59:10 +00:00
|
|
|
Module::~Module() {
|
2018-04-30 16:49:04 +00:00
|
|
|
// Lock our module down while we tear everything down to make sure we don't
|
|
|
|
|
// get any access to the module while it is being destroyed
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2011-08-09 00:01:09 +00:00
|
|
|
// Scope for locker below...
|
2016-09-06 20:57:50 +00:00
|
|
|
{
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(
|
|
|
|
|
GetAllocationModuleCollectionMutex());
|
|
|
|
|
ModuleCollection &modules = GetModuleCollection();
|
|
|
|
|
ModuleCollection::iterator end = modules.end();
|
2014-03-24 23:10:19 +00:00
|
|
|
ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
|
2012-10-08 22:41:53 +00:00
|
|
|
assert(pos != end);
|
|
|
|
|
modules.erase(pos);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2022-01-31 15:57:48 +01:00
|
|
|
Log *log(GetLog(LLDBLog::Object | LLDBLog::Modules));
|
2016-03-11 20:20:38 +00:00
|
|
|
if (log != nullptr)
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "%p Module::~Module((%s) '%s%s%s%s')",
|
|
|
|
|
static_cast<void *>(this), m_arch.GetArchitectureName(),
|
|
|
|
|
m_file.GetPath().c_str(), m_object_name.IsEmpty() ? "" : "(",
|
2022-07-07 20:27:05 +00:00
|
|
|
m_object_name.AsCString(""), m_object_name.IsEmpty() ? "" : ")");
|
2013-05-22 20:13:22 +00: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.
|
2019-02-13 06:25:41 +00:00
|
|
|
m_sections_up.reset();
|
|
|
|
|
m_symfile_up.reset();
|
2011-09-18 18:59:15 +00:00
|
|
|
m_objfile_sp.reset();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-22 20:13:22 +00:00
|
|
|
ObjectFile *Module::GetMemoryObjectFile(const lldb::ProcessSP &process_sp,
|
2017-05-12 04:51:55 +00:00
|
|
|
lldb::addr_t header_addr, Status &error,
|
2014-03-05 10:12:43 +00:00
|
|
|
size_t size_to_read) {
|
2012-02-24 21:55:59 +00:00
|
|
|
if (m_objfile_sp) {
|
2013-05-22 20:13:22 +00:00
|
|
|
error.SetErrorString("object file already exists");
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2011-08-09 00:01:09 +00:00
|
|
|
if (process_sp) {
|
2016-05-18 01:59:10 +00:00
|
|
|
m_did_load_objfile = true;
|
2022-04-05 13:33:55 -07:00
|
|
|
std::shared_ptr<DataBufferHeap> data_sp =
|
|
|
|
|
std::make_shared<DataBufferHeap>(size_to_read, 0);
|
2017-05-12 04:51:55 +00:00
|
|
|
Status readmem_error;
|
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 03:46:26 +00:00
|
|
|
const size_t bytes_read =
|
2022-04-05 13:33:55 -07:00
|
|
|
process_sp->ReadMemory(header_addr, data_sp->GetBytes(),
|
|
|
|
|
data_sp->GetByteSize(), readmem_error);
|
2020-02-27 11:17:10 -08:00
|
|
|
if (bytes_read < size_to_read)
|
2022-04-05 13:33:55 -07:00
|
|
|
data_sp->SetByteSize(bytes_read);
|
|
|
|
|
if (data_sp->GetByteSize() > 0) {
|
2014-03-05 10:12:43 +00:00
|
|
|
m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp,
|
|
|
|
|
header_addr, data_sp);
|
2012-02-24 21:55:59 +00:00
|
|
|
if (m_objfile_sp) {
|
|
|
|
|
StreamString s;
|
2012-11-29 21:49:15 +00:00
|
|
|
s.Printf("0x%16.16" PRIx64, header_addr);
|
2016-11-16 21:15:24 +00:00
|
|
|
m_object_name.SetString(s.GetString());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-04-20 19:50:20 +00:00
|
|
|
// Once we get the object file, update our module with the object
|
2018-04-30 16:49:04 +00:00
|
|
|
// file's architecture since it might differ in vendor/os if some
|
|
|
|
|
// parts were unknown.
|
2019-01-03 10:37:19 +00:00
|
|
|
m_arch = m_objfile_sp->GetArchitecture();
|
2019-02-20 23:12:56 +00:00
|
|
|
|
|
|
|
|
// Augment the arch with the target's information in case
|
|
|
|
|
// we are unable to extract the os/environment from memory.
|
|
|
|
|
m_arch.MergeFrom(process_sp->GetTarget().GetArchitecture());
|
2012-02-24 21:55:59 +00:00
|
|
|
} else {
|
|
|
|
|
error.SetErrorString("unable to find suitable object file plug-in");
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2012-02-24 21:55:59 +00:00
|
|
|
error.SetErrorStringWithFormat("unable to read header from memory: %s",
|
|
|
|
|
readmem_error.AsCString());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2012-02-24 21:55:59 +00:00
|
|
|
error.SetErrorString("invalid process");
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-02-24 21:55:59 +00:00
|
|
|
return m_objfile_sp.get();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-04 18:53:10 +00:00
|
|
|
const lldb_private::UUID &Module::GetUUID() {
|
2018-05-02 20:06:17 +00:00
|
|
|
if (!m_did_set_uuid.load()) {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2018-05-02 20:06:17 +00:00
|
|
|
if (!m_did_set_uuid.load()) {
|
2015-07-24 23:38:01 +00:00
|
|
|
ObjectFile *obj_file = GetObjectFile();
|
|
|
|
|
|
2016-03-11 20:20:38 +00:00
|
|
|
if (obj_file != nullptr) {
|
2019-02-11 16:14:02 +00:00
|
|
|
m_uuid = obj_file->GetUUID();
|
2018-05-02 20:06:17 +00:00
|
|
|
m_did_set_uuid = true;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
return m_uuid;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 20:06:17 +00:00
|
|
|
void Module::SetUUID(const lldb_private::UUID &uuid) {
|
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
|
|
|
|
if (!m_did_set_uuid) {
|
|
|
|
|
m_uuid = uuid;
|
|
|
|
|
m_did_set_uuid = true;
|
|
|
|
|
} else {
|
2018-05-02 22:21:11 +00:00
|
|
|
lldbassert(0 && "Attempting to overwrite the existing module UUID");
|
2018-05-02 20:06:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-30 22:12:34 +00:00
|
|
|
llvm::Expected<TypeSystem &>
|
|
|
|
|
Module::GetTypeSystemForLanguage(LanguageType language) {
|
2015-10-08 21:04:34 +00:00
|
|
|
return m_type_system_map.GetTypeSystemForLanguage(language, this, true);
|
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 03:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
void Module::ParseAllDebugSymbols() {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2013-01-25 18:06:21 +00:00
|
|
|
size_t num_comp_units = GetNumCompileUnits();
|
2010-06-08 16:52:24 +00:00
|
|
|
if (num_comp_units == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-08-02 08:16:35 +00:00
|
|
|
SymbolFile *symbols = GetSymbolFile();
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2013-01-25 18:06:21 +00:00
|
|
|
for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++) {
|
2020-02-18 13:33:59 +01:00
|
|
|
SymbolContext sc;
|
|
|
|
|
sc.module_sp = shared_from_this();
|
2010-06-08 16:52:24 +00:00
|
|
|
sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
|
2019-01-11 18:03:20 +00:00
|
|
|
if (!sc.comp_unit)
|
|
|
|
|
continue;
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2019-01-11 18:03:20 +00:00
|
|
|
symbols->ParseVariablesForContext(sc);
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2019-01-11 18:03:20 +00:00
|
|
|
symbols->ParseFunctions(*sc.comp_unit);
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2019-01-11 18:03:20 +00:00
|
|
|
sc.comp_unit->ForeachFunction([&sc, &symbols](const FunctionSP &f) {
|
2019-01-14 22:40:41 +00:00
|
|
|
symbols->ParseBlocksRecursive(*f);
|
|
|
|
|
|
2019-01-11 18:03:20 +00:00
|
|
|
// Parse the variables for this function and all its blocks
|
2019-01-14 22:40:41 +00:00
|
|
|
sc.function = f.get();
|
2019-01-11 18:03:20 +00:00
|
|
|
symbols->ParseVariablesForContext(sc);
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Parse all types for this compile unit
|
|
|
|
|
symbols->ParseTypes(*sc.comp_unit);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Module::CalculateSymbolContext(SymbolContext *sc) {
|
2012-01-29 20:56:30 +00:00
|
|
|
sc->module_sp = shared_from_this();
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-12 21:40:01 +00:00
|
|
|
ModuleSP Module::CalculateSymbolContextModule() { return shared_from_this(); }
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
void Module::DumpSymbolContext(Stream *s) {
|
2014-04-04 04:06:10 +00:00
|
|
|
s->Printf(", Module{%p}", static_cast<void *>(this));
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t Module::GetNumCompileUnits() {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2020-12-21 13:41:57 -08:00
|
|
|
LLDB_SCOPED_TIMERF("Module::GetNumCompileUnits (module = %p)",
|
2014-04-04 04:06:10 +00:00
|
|
|
static_cast<void *>(this));
|
2019-08-02 08:16:35 +00:00
|
|
|
if (SymbolFile *symbols = GetSymbolFile())
|
2010-06-08 16:52:24 +00:00
|
|
|
return symbols->GetNumCompileUnits();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-25 18:06:21 +00:00
|
|
|
CompUnitSP Module::GetCompileUnitAtIndex(size_t index) {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2013-01-25 18:06:21 +00:00
|
|
|
size_t num_comp_units = GetNumCompileUnits();
|
2010-06-08 16:52:24 +00:00
|
|
|
CompUnitSP cu_sp;
|
|
|
|
|
|
|
|
|
|
if (index < num_comp_units) {
|
2019-08-02 08:16:35 +00:00
|
|
|
if (SymbolFile *symbols = GetSymbolFile())
|
2010-06-08 16:52:24 +00:00
|
|
|
cu_sp = symbols->GetCompileUnitAtIndex(index);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
return cu_sp;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
bool Module::ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr) {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2013-07-10 01:23:25 +00:00
|
|
|
SectionList *section_list = GetSectionList();
|
|
|
|
|
if (section_list)
|
|
|
|
|
return so_addr.ResolveAddressUsingFileSections(vm_addr, section_list);
|
2010-06-08 16:52:24 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2013-09-24 15:34:13 +00:00
|
|
|
uint32_t Module::ResolveSymbolContextForAddress(
|
2018-10-25 20:45:19 +00:00
|
|
|
const Address &so_addr, lldb::SymbolContextItem resolve_scope,
|
|
|
|
|
SymbolContext &sc, bool resolve_tail_call_address) {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-06-08 16:52:24 +00:00
|
|
|
uint32_t resolved_flags = 0;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-02-23 04:12:47 +00:00
|
|
|
// Clear the result symbol context in case we don't find anything, but don't
|
|
|
|
|
// clear the target
|
|
|
|
|
sc.Clear(false);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
// Get the section from the section/offset address.
|
2012-02-24 01:59:29 +00:00
|
|
|
SectionSP section_sp(so_addr.GetSection());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
// Make sure the section matches this module before we try and match anything
|
2012-02-24 01:59:29 +00:00
|
|
|
if (section_sp && section_sp->GetModule().get() == this) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// If the section offset based address resolved itself, then this is the
|
|
|
|
|
// right module.
|
2012-01-29 20:56:30 +00:00
|
|
|
sc.module_sp = shared_from_this();
|
2010-06-08 16:52:24 +00:00
|
|
|
resolved_flags |= eSymbolContextModule;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-08-02 08:16:35 +00:00
|
|
|
SymbolFile *symfile = GetSymbolFile();
|
|
|
|
|
if (!symfile)
|
2013-09-16 22:00:17 +00:00
|
|
|
return resolved_flags;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// Resolve the compile unit, function, block, line table or line entry if
|
|
|
|
|
// requested.
|
2010-06-08 16:52:24 +00:00
|
|
|
if (resolve_scope & eSymbolContextCompUnit ||
|
|
|
|
|
resolve_scope & eSymbolContextFunction ||
|
|
|
|
|
resolve_scope & eSymbolContextBlock ||
|
2016-06-21 20:00:36 +00:00
|
|
|
resolve_scope & eSymbolContextLineEntry ||
|
|
|
|
|
resolve_scope & eSymbolContextVariable) {
|
2022-04-20 07:30:53 -07:00
|
|
|
symfile->SetLoadDebugInfoEnabled();
|
2010-06-08 16:52:24 +00:00
|
|
|
resolved_flags |=
|
2019-08-02 08:16:35 +00:00
|
|
|
symfile->ResolveSymbolContext(so_addr, resolve_scope, sc);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// Resolve the symbol if requested, but don't re-look it up if we've
|
|
|
|
|
// already found it.
|
2012-01-29 20:56:30 +00:00
|
|
|
if (resolve_scope & eSymbolContextSymbol &&
|
2010-06-08 16:52:24 +00:00
|
|
|
!(resolved_flags & eSymbolContextSymbol)) {
|
2019-08-02 08:16:35 +00:00
|
|
|
Symtab *symtab = symfile->GetSymtab();
|
2013-09-16 22:00:17 +00:00
|
|
|
if (symtab && so_addr.IsSectionOffset()) {
|
|
|
|
|
Symbol *matching_symbol = nullptr;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
symtab->ForEachSymbolContainingFileAddress(
|
|
|
|
|
so_addr.GetFileAddress(),
|
|
|
|
|
[&matching_symbol](Symbol *symbol) -> bool {
|
|
|
|
|
if (symbol->GetType() != eSymbolTypeInvalid) {
|
2016-01-26 00:58:09 +00:00
|
|
|
matching_symbol = symbol;
|
2010-06-08 16:52:24 +00:00
|
|
|
return false; // Stop iterating
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-26 00:58:09 +00:00
|
|
|
return true; // Keep iterating
|
2016-09-06 20:57:50 +00:00
|
|
|
});
|
2010-06-08 16:52:24 +00:00
|
|
|
sc.symbol = matching_symbol;
|
|
|
|
|
if (!sc.symbol && resolve_scope & eSymbolContextFunction &&
|
2016-06-21 20:00:36 +00:00
|
|
|
!(resolved_flags & eSymbolContextFunction)) {
|
2013-09-16 22:00:17 +00:00
|
|
|
bool verify_unique = false; // No need to check again since
|
|
|
|
|
// ResolveSymbolContext failed to find a
|
|
|
|
|
// symbol at this address.
|
|
|
|
|
if (ObjectFile *obj_file = sc.module_sp->GetObjectFile())
|
|
|
|
|
sc.symbol =
|
|
|
|
|
obj_file->ResolveSymbolForAddress(so_addr, verify_unique);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2010-08-31 23:51:36 +00:00
|
|
|
if (sc.symbol) {
|
|
|
|
|
if (sc.symbol->IsSynthetic()) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// We have a synthetic symbol so lets check if the object file from
|
|
|
|
|
// the symbol file in the symbol vendor is different than the
|
|
|
|
|
// object file for the module, and if so search its symbol table to
|
|
|
|
|
// see if we can come up with a better symbol. For example dSYM
|
|
|
|
|
// files on MacOSX have an unstripped symbol table inside of them.
|
2013-09-24 15:34:13 +00:00
|
|
|
ObjectFile *symtab_objfile = symtab->GetObjectFile();
|
2013-10-11 22:03:48 +00:00
|
|
|
if (symtab_objfile && symtab_objfile->IsStripped()) {
|
2019-08-02 08:16:35 +00:00
|
|
|
ObjectFile *symfile_objfile = symfile->GetObjectFile();
|
|
|
|
|
if (symfile_objfile != symtab_objfile) {
|
|
|
|
|
Symtab *symfile_symtab = symfile_objfile->GetSymtab();
|
|
|
|
|
if (symfile_symtab) {
|
|
|
|
|
Symbol *symbol =
|
|
|
|
|
symfile_symtab->FindSymbolContainingFileAddress(
|
|
|
|
|
so_addr.GetFileAddress());
|
|
|
|
|
if (symbol && !symbol->IsSynthetic()) {
|
|
|
|
|
sc.symbol = symbol;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2013-10-11 22:03:48 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2013-09-16 22:00:17 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2013-09-16 22:00:17 +00:00
|
|
|
resolved_flags |= eSymbolContextSymbol;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-09-16 22:00:17 +00:00
|
|
|
|
|
|
|
|
// For function symbols, so_addr may be off by one. This is a convention
|
2018-04-30 16:49:04 +00:00
|
|
|
// consistent with FDE row indices in eh_frame sections, but requires extra
|
|
|
|
|
// logic here to permit symbol lookup for disassembly and unwind.
|
2013-09-16 22:00:17 +00:00
|
|
|
if (resolve_scope & eSymbolContextSymbol &&
|
|
|
|
|
!(resolved_flags & eSymbolContextSymbol) && resolve_tail_call_address &&
|
2013-09-24 15:34:13 +00:00
|
|
|
so_addr.IsSectionOffset()) {
|
2013-09-16 22:00:17 +00:00
|
|
|
Address previous_addr = so_addr;
|
2013-09-18 20:03:31 +00:00
|
|
|
previous_addr.Slide(-1);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-09-24 15:34:13 +00:00
|
|
|
bool do_resolve_tail_call_address = false; // prevent recursion
|
|
|
|
|
const uint32_t flags = ResolveSymbolContextForAddress(
|
|
|
|
|
previous_addr, resolve_scope, sc, do_resolve_tail_call_address);
|
2013-09-16 22:00:17 +00:00
|
|
|
if (flags & eSymbolContextSymbol) {
|
|
|
|
|
AddressRange addr_range;
|
|
|
|
|
if (sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
|
|
|
|
|
false, addr_range)) {
|
|
|
|
|
if (addr_range.GetBaseAddress().GetSection() ==
|
|
|
|
|
so_addr.GetSection()) {
|
|
|
|
|
// If the requested address is one past the address range of a
|
2018-04-30 16:49:04 +00:00
|
|
|
// function (i.e. a tail call), or the decremented address is the
|
|
|
|
|
// start of a function (i.e. some forms of trampoline), indicate
|
|
|
|
|
// that the symbol has been resolved.
|
2013-09-16 22:00:17 +00:00
|
|
|
if (so_addr.GetOffset() ==
|
|
|
|
|
addr_range.GetBaseAddress().GetOffset() ||
|
2021-12-09 12:09:56 +01:00
|
|
|
so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() +
|
|
|
|
|
addr_range.GetByteSize()) {
|
2013-09-16 22:00:17 +00:00
|
|
|
resolved_flags |= flags;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2013-09-24 15:34:13 +00:00
|
|
|
sc.symbol =
|
2013-09-16 22:00:17 +00:00
|
|
|
nullptr; // Don't trust the symbol if the sections didn't match.
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
return resolved_flags;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-10-25 20:45:19 +00:00
|
|
|
uint32_t Module::ResolveSymbolContextForFilePath(
|
|
|
|
|
const char *file_path, uint32_t line, bool check_inlines,
|
|
|
|
|
lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSpec file_spec(file_path);
|
2010-06-08 16:52:24 +00:00
|
|
|
return ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
|
|
|
|
|
resolve_scope, sc_list);
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-10-25 20:45:19 +00:00
|
|
|
uint32_t Module::ResolveSymbolContextsForFileSpec(
|
|
|
|
|
const FileSpec &file_spec, uint32_t line, bool check_inlines,
|
|
|
|
|
lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2020-12-21 13:41:57 -08:00
|
|
|
LLDB_SCOPED_TIMERF("Module::ResolveSymbolContextForFilePath (%s:%u, "
|
2013-04-29 17:25:54 +00:00
|
|
|
"check_inlines = %s, resolve_scope = 0x%8.8x)",
|
|
|
|
|
file_spec.GetPath().c_str(), line,
|
2010-06-08 16:52:24 +00:00
|
|
|
check_inlines ? "yes" : "no", resolve_scope);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
const uint32_t initial_count = sc_list.GetSize();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2021-05-04 23:03:10 +00:00
|
|
|
if (SymbolFile *symbols = GetSymbolFile()) {
|
|
|
|
|
// TODO: Handle SourceLocationSpec column information
|
|
|
|
|
SourceLocationSpec location_spec(file_spec, line, /*column=*/llvm::None,
|
|
|
|
|
check_inlines, /*exact_match=*/false);
|
|
|
|
|
|
|
|
|
|
symbols->ResolveSymbolContext(location_spec, resolve_scope, sc_list);
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
return sc_list.GetSize() - initial_count;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-10-17 19:56:40 +00:00
|
|
|
void Module::FindGlobalVariables(ConstString name,
|
2020-02-17 19:25:52 +01:00
|
|
|
const CompilerDeclContext &parent_decl_ctx,
|
2019-10-17 19:56:40 +00:00
|
|
|
size_t max_matches, VariableList &variables) {
|
2019-08-02 08:16:35 +00:00
|
|
|
if (SymbolFile *symbols = GetSymbolFile())
|
2019-10-17 19:56:40 +00:00
|
|
|
symbols->FindGlobalVariables(name, parent_decl_ctx, max_matches, variables);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-10-17 19:56:40 +00:00
|
|
|
void Module::FindGlobalVariables(const RegularExpression ®ex,
|
|
|
|
|
size_t max_matches, VariableList &variables) {
|
2019-08-02 08:16:35 +00:00
|
|
|
SymbolFile *symbols = GetSymbolFile();
|
2010-06-08 16:52:24 +00:00
|
|
|
if (symbols)
|
2019-10-17 19:56:40 +00:00
|
|
|
symbols->FindGlobalVariables(regex, max_matches, variables);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-10-17 19:56:40 +00:00
|
|
|
void Module::FindCompileUnits(const FileSpec &path,
|
|
|
|
|
SymbolContextList &sc_list) {
|
2013-01-25 18:06:21 +00:00
|
|
|
const size_t num_compile_units = GetNumCompileUnits();
|
2011-07-07 01:59:51 +00:00
|
|
|
SymbolContext sc;
|
2012-01-29 20:56:30 +00:00
|
|
|
sc.module_sp = shared_from_this();
|
2016-03-11 20:20:38 +00:00
|
|
|
for (size_t i = 0; i < num_compile_units; ++i) {
|
2011-07-07 01:59:51 +00:00
|
|
|
sc.comp_unit = GetCompileUnitAtIndex(i).get();
|
2012-04-23 22:00:21 +00:00
|
|
|
if (sc.comp_unit) {
|
[lldb] s/FileSpec::Equal/FileSpec::Match
Summary:
The FileSpec class is often used as a sort of a pattern -- one specifies
a bare file name to search, and we check if in matches the full file
name of an existing module (for example).
These comparisons used FileSpec::Equal, which had some support for it
(via the full=false argument), but it was not a good fit for this job.
For one, it did a symmetric comparison, which makes sense for a function
called "equal", but not for typical searches (when searching for
"/foo/bar.so", we don't want to find a module whose name is just
"bar.so"). This resulted in patterns like:
if (FileSpec::Equal(pattern, file, pattern.GetDirectory()))
which would request a "full" match only if the pattern really contained
a directory. This worked, but the intended behavior was very unobvious.
On top of that, a lot of the code wanted to handle the case of an
"empty" pattern, and treat it as matching everything. This resulted in
conditions like:
if (pattern && !FileSpec::Equal(pattern, file, pattern.GetDirectory())
which are nearly impossible to decipher.
This patch introduces a FileSpec::Match function, which does exactly
what most of FileSpec::Equal callers want, an asymmetric match between a
"pattern" FileSpec and a an actual FileSpec. Empty paterns match
everything, filename-only patterns match only the filename component.
I've tried to update all callers of FileSpec::Equal to use a simpler
interface. Those that hardcoded full=true have been changed to use
operator==. Those passing full=pattern.GetDirectory() have been changed
to use FileSpec::Match.
There was also a handful of places which hardcoded full=false. I've
changed these to use FileSpec::Match too. This is a slight change in
semantics, but it does not look like that was ever intended, and it was
more likely a result of a misunderstanding of the "proper" way to use
FileSpec::Equal.
[In an ideal world a "FileSpec" and a "FileSpec pattern" would be two
different types, but given how widespread FileSpec is, it is unlikely
we'll get there in one go. This at least provides a good starting point
by centralizing all matching behavior.]
Reviewers: teemperor, JDevlieghere, jdoerfert
Subscribers: emaste, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D70851
2019-11-29 11:31:00 +01:00
|
|
|
if (FileSpec::Match(path, sc.comp_unit->GetPrimaryFile()))
|
2012-04-23 22:00:21 +00:00
|
|
|
sc_list.Append(sc);
|
2011-07-07 01:59:51 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-07-07 01:59:51 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-03-06 21:22:25 +00:00
|
|
|
Module::LookupInfo::LookupInfo(ConstString name,
|
2018-10-25 20:45:40 +00:00
|
|
|
FunctionNameType name_type_mask,
|
2021-08-24 14:52:17 -07:00
|
|
|
LanguageType language)
|
2022-03-14 13:32:03 -07:00
|
|
|
: m_name(name), m_lookup_name(), m_language(language) {
|
2021-08-24 14:52:17 -07:00
|
|
|
const char *name_cstr = name.GetCString();
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
llvm::StringRef basename;
|
|
|
|
|
llvm::StringRef context;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
if (name_type_mask & eFunctionNameTypeAuto) {
|
2021-08-24 14:52:17 -07:00
|
|
|
if (CPlusPlusLanguage::IsCPPMangledName(name_cstr))
|
|
|
|
|
m_name_type_mask = eFunctionNameTypeFull;
|
|
|
|
|
else if ((language == eLanguageTypeUnknown ||
|
|
|
|
|
Language::LanguageIsObjC(language)) &&
|
|
|
|
|
ObjCLanguage::IsPossibleObjCMethodName(name_cstr))
|
|
|
|
|
m_name_type_mask = eFunctionNameTypeFull;
|
|
|
|
|
else if (Language::LanguageIsC(language)) {
|
|
|
|
|
m_name_type_mask = eFunctionNameTypeFull;
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
} else {
|
2021-08-24 14:52:17 -07:00
|
|
|
if ((language == eLanguageTypeUnknown ||
|
|
|
|
|
Language::LanguageIsObjC(language)) &&
|
|
|
|
|
ObjCLanguage::IsPossibleObjCSelector(name_cstr))
|
|
|
|
|
m_name_type_mask |= eFunctionNameTypeSelector;
|
|
|
|
|
|
|
|
|
|
CPlusPlusLanguage::MethodName cpp_method(name);
|
|
|
|
|
basename = cpp_method.GetBasename();
|
|
|
|
|
if (basename.empty()) {
|
|
|
|
|
if (CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context,
|
|
|
|
|
basename))
|
|
|
|
|
m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
|
|
|
|
|
else
|
|
|
|
|
m_name_type_mask |= eFunctionNameTypeFull;
|
|
|
|
|
} else {
|
|
|
|
|
m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
m_name_type_mask = name_type_mask;
|
2021-08-24 14:52:17 -07:00
|
|
|
if (name_type_mask & eFunctionNameTypeMethod ||
|
|
|
|
|
name_type_mask & eFunctionNameTypeBase) {
|
|
|
|
|
// If they've asked for a CPP method or function name and it can't be
|
|
|
|
|
// that, we don't even need to search for CPP methods or names.
|
|
|
|
|
CPlusPlusLanguage::MethodName cpp_method(name);
|
|
|
|
|
if (cpp_method.IsValid()) {
|
|
|
|
|
basename = cpp_method.GetBasename();
|
|
|
|
|
|
|
|
|
|
if (!cpp_method.GetQualifiers().empty()) {
|
|
|
|
|
// There is a "const" or other qualifier following the end of the
|
|
|
|
|
// function parens, this can't be a eFunctionNameTypeBase
|
|
|
|
|
m_name_type_mask &= ~(eFunctionNameTypeBase);
|
|
|
|
|
if (m_name_type_mask == eFunctionNameTypeNone)
|
|
|
|
|
return;
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
}
|
2021-08-24 14:52:17 -07:00
|
|
|
} else {
|
|
|
|
|
// If the CPP method parser didn't manage to chop this up, try to fill
|
|
|
|
|
// in the base name if we can. If a::b::c is passed in, we need to just
|
|
|
|
|
// look up "c", and then we'll filter the result later.
|
|
|
|
|
CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context,
|
|
|
|
|
basename);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2021-08-24 14:52:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (name_type_mask & eFunctionNameTypeSelector) {
|
|
|
|
|
if (!ObjCLanguage::IsPossibleObjCSelector(name_cstr)) {
|
|
|
|
|
m_name_type_mask &= ~(eFunctionNameTypeSelector);
|
|
|
|
|
if (m_name_type_mask == eFunctionNameTypeNone)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Still try and get a basename in case someone specifies a name type mask
|
|
|
|
|
// of eFunctionNameTypeFull and a name like "A::func"
|
|
|
|
|
if (basename.empty()) {
|
|
|
|
|
if (name_type_mask & eFunctionNameTypeFull &&
|
|
|
|
|
!CPlusPlusLanguage::IsCPPMangledName(name_cstr)) {
|
|
|
|
|
CPlusPlusLanguage::MethodName cpp_method(name);
|
|
|
|
|
basename = cpp_method.GetBasename();
|
|
|
|
|
if (basename.empty())
|
|
|
|
|
CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context,
|
|
|
|
|
basename);
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
if (!basename.empty()) {
|
2021-08-24 14:52:17 -07:00
|
|
|
// The name supplied was a partial C++ path like "a::count". In this case
|
|
|
|
|
// we want to do a lookup on the basename "count" and then make sure any
|
|
|
|
|
// matching results contain "a::count" so that it would match "b::a::count"
|
|
|
|
|
// and "a::count". This is why we set "match_name_after_lookup" to true
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
m_lookup_name.SetString(basename);
|
|
|
|
|
m_match_name_after_lookup = true;
|
2021-08-24 14:52:17 -07:00
|
|
|
} else {
|
|
|
|
|
// The name is already correct, just use the exact name as supplied, and we
|
|
|
|
|
// won't need to check if any matches contain "name"
|
|
|
|
|
m_lookup_name = name;
|
|
|
|
|
m_match_name_after_lookup = false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
void Module::LookupInfo::Prune(SymbolContextList &sc_list,
|
|
|
|
|
size_t start_idx) const {
|
|
|
|
|
if (m_match_name_after_lookup && m_name) {
|
|
|
|
|
SymbolContext sc;
|
|
|
|
|
size_t i = start_idx;
|
|
|
|
|
while (i < sc_list.GetSize()) {
|
|
|
|
|
if (!sc_list.GetContextAtIndex(i, sc))
|
|
|
|
|
break;
|
2022-05-12 11:00:18 -07:00
|
|
|
|
2022-08-04 11:51:47 -07:00
|
|
|
llvm::StringRef user_name = m_name.GetStringRef();
|
|
|
|
|
bool keep_it = true;
|
|
|
|
|
Language *language = Language::FindPlugin(sc.GetLanguage());
|
|
|
|
|
// If the symbol has a language, then let the language make the match.
|
|
|
|
|
// Otherwise just check that the demangled name contains the user name.
|
|
|
|
|
if (language)
|
|
|
|
|
keep_it = language->DemangledNameContainsPath(m_name.GetStringRef(),
|
|
|
|
|
sc.GetFunctionName());
|
|
|
|
|
else {
|
|
|
|
|
llvm::StringRef full_name = sc.GetFunctionName().GetStringRef();
|
|
|
|
|
// We always keep unnamed symbols:
|
|
|
|
|
if (!full_name.empty())
|
|
|
|
|
keep_it = full_name.contains(user_name);
|
|
|
|
|
}
|
2022-05-12 11:00:18 -07:00
|
|
|
if (keep_it)
|
|
|
|
|
++i;
|
|
|
|
|
else
|
|
|
|
|
sc_list.RemoveContextAtIndex(i);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-22 16:19:56 +00:00
|
|
|
// If we have only full name matches we might have tried to set breakpoint on
|
2017-02-13 21:34:58 +00:00
|
|
|
// "func" and specified eFunctionNameTypeFull, but we might have found
|
|
|
|
|
// "a::func()", "a::b::func()", "c::func()", "func()" and "func". Only
|
|
|
|
|
// "func()" and "func" should end up matching.
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
if (m_name_type_mask == eFunctionNameTypeFull) {
|
|
|
|
|
SymbolContext sc;
|
|
|
|
|
size_t i = start_idx;
|
|
|
|
|
while (i < sc_list.GetSize()) {
|
|
|
|
|
if (!sc_list.GetContextAtIndex(i, sc))
|
|
|
|
|
break;
|
2018-04-30 16:49:04 +00:00
|
|
|
// Make sure the mangled and demangled names don't match before we try to
|
|
|
|
|
// pull anything out
|
2017-02-13 21:34:58 +00:00
|
|
|
ConstString mangled_name(sc.GetFunctionName(Mangled::ePreferMangled));
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
ConstString full_name(sc.GetFunctionName());
|
2021-12-09 12:09:56 +01:00
|
|
|
if (mangled_name != m_name && full_name != m_name) {
|
2017-02-13 21:34:58 +00:00
|
|
|
CPlusPlusLanguage::MethodName cpp_method(full_name);
|
|
|
|
|
if (cpp_method.IsValid()) {
|
|
|
|
|
if (cpp_method.GetContext().empty()) {
|
|
|
|
|
if (cpp_method.GetBasename().compare(m_name.GetStringRef()) != 0) {
|
|
|
|
|
sc_list.RemoveContextAtIndex(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
std::string qualified_name;
|
|
|
|
|
llvm::StringRef anon_prefix("(anonymous namespace)");
|
|
|
|
|
if (cpp_method.GetContext() == anon_prefix)
|
|
|
|
|
qualified_name = cpp_method.GetBasename().str();
|
|
|
|
|
else
|
|
|
|
|
qualified_name = cpp_method.GetScopeQualifiedName();
|
2018-12-21 22:46:10 +00:00
|
|
|
if (qualified_name != m_name.GetCString()) {
|
2017-02-13 21:34:58 +00:00
|
|
|
sc_list.RemoveContextAtIndex(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
++i;
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-12 08:51:30 -07:00
|
|
|
void Module::FindFunctions(ConstString name,
|
|
|
|
|
const CompilerDeclContext &parent_decl_ctx,
|
|
|
|
|
FunctionNameType name_type_mask,
|
|
|
|
|
const ModuleFunctionSearchOptions &options,
|
|
|
|
|
SymbolContextList &sc_list) {
|
|
|
|
|
const size_t old_size = sc_list.GetSize();
|
2022-08-04 11:51:47 -07:00
|
|
|
|
|
|
|
|
// Find all the functions (not symbols, but debug information functions...
|
|
|
|
|
SymbolFile *symbols = GetSymbolFile();
|
|
|
|
|
|
2022-07-12 08:51:30 -07:00
|
|
|
if (name_type_mask & eFunctionNameTypeAuto) {
|
2022-08-04 11:51:47 -07:00
|
|
|
LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
|
|
|
|
|
|
|
|
|
|
if (symbols) {
|
|
|
|
|
symbols->FindFunctions(lookup_info.GetLookupName(), parent_decl_ctx,
|
|
|
|
|
lookup_info.GetNameTypeMask(),
|
|
|
|
|
options.include_inlines, sc_list);
|
|
|
|
|
|
|
|
|
|
// Now check our symbol table for symbols that are code symbols if
|
|
|
|
|
// requested
|
|
|
|
|
if (options.include_symbols) {
|
|
|
|
|
Symtab *symtab = symbols->GetSymtab();
|
|
|
|
|
if (symtab)
|
|
|
|
|
symtab->FindFunctionSymbols(lookup_info.GetLookupName(),
|
|
|
|
|
lookup_info.GetNameTypeMask(), sc_list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-03 02:00:15 +00:00
|
|
|
const size_t new_size = sc_list.GetSize();
|
2022-08-04 11:51:47 -07:00
|
|
|
|
2013-01-25 18:06:21 +00:00
|
|
|
if (old_size < new_size)
|
2013-06-12 00:46:38 +00:00
|
|
|
lookup_info.Prune(sc_list, old_size);
|
2022-08-04 11:51:47 -07:00
|
|
|
} else {
|
|
|
|
|
if (symbols) {
|
|
|
|
|
symbols->FindFunctions(name, parent_decl_ctx, name_type_mask,
|
|
|
|
|
options.include_inlines, sc_list);
|
|
|
|
|
|
|
|
|
|
// Now check our symbol table for symbols that are code symbols if
|
|
|
|
|
// requested
|
|
|
|
|
if (options.include_symbols) {
|
|
|
|
|
Symtab *symtab = symbols->GetSymtab();
|
|
|
|
|
if (symtab)
|
|
|
|
|
symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-08-03 01:26:16 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2021-08-05 09:27:19 -07:00
|
|
|
void Module::FindFunctions(const RegularExpression ®ex,
|
|
|
|
|
const ModuleFunctionSearchOptions &options,
|
2019-10-17 19:56:40 +00:00
|
|
|
SymbolContextList &sc_list) {
|
2012-03-26 23:03:23 +00:00
|
|
|
const size_t start_size = sc_list.GetSize();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-08-02 08:16:35 +00:00
|
|
|
if (SymbolFile *symbols = GetSymbolFile()) {
|
2021-08-05 09:27:19 -07:00
|
|
|
symbols->FindFunctions(regex, options.include_inlines, sc_list);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// Now check our symbol table for symbols that are code symbols if
|
|
|
|
|
// requested
|
2021-08-05 09:27:19 -07:00
|
|
|
if (options.include_symbols) {
|
2016-02-10 21:28:13 +00:00
|
|
|
Symtab *symtab = symbols->GetSymtab();
|
2013-04-03 02:00:15 +00:00
|
|
|
if (symtab) {
|
2016-02-10 21:28:13 +00:00
|
|
|
std::vector<uint32_t> symbol_indexes;
|
|
|
|
|
symtab->AppendSymbolIndexesMatchingRegExAndType(
|
|
|
|
|
regex, eSymbolTypeAny, Symtab::eDebugAny, Symtab::eVisibilityAny,
|
2013-02-27 20:13:38 +00:00
|
|
|
symbol_indexes);
|
2016-02-10 21:28:13 +00:00
|
|
|
const size_t num_matches = symbol_indexes.size();
|
2012-12-05 21:24:42 +00:00
|
|
|
if (num_matches) {
|
2012-03-26 23:03:23 +00:00
|
|
|
SymbolContext sc(this);
|
|
|
|
|
const size_t end_functions_added_index = sc_list.GetSize();
|
2013-01-25 18:06:21 +00:00
|
|
|
size_t num_functions_added_to_sc_list =
|
2016-02-10 21:28:13 +00:00
|
|
|
end_functions_added_index - start_size;
|
2013-06-12 00:46:38 +00:00
|
|
|
if (num_functions_added_to_sc_list == 0) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// No functions were added, just symbols, so we can just append
|
|
|
|
|
// them
|
2013-01-25 18:06:21 +00:00
|
|
|
for (size_t i = 0; i < num_matches; ++i) {
|
2012-03-26 23:03:23 +00:00
|
|
|
sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
|
2012-10-22 16:19:56 +00:00
|
|
|
SymbolType sym_type = sc.symbol->GetType();
|
|
|
|
|
if (sc.symbol && (sym_type == eSymbolTypeCode ||
|
|
|
|
|
sym_type == eSymbolTypeResolver))
|
|
|
|
|
sc_list.Append(sc);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-07-29 19:53:35 +00:00
|
|
|
} else {
|
2012-03-26 23:03:23 +00:00
|
|
|
typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap;
|
|
|
|
|
FileAddrToIndexMap file_addr_to_index;
|
|
|
|
|
for (size_t i = start_size; i < end_functions_added_index; ++i) {
|
|
|
|
|
const SymbolContext &sc = sc_list[i];
|
|
|
|
|
if (sc.block)
|
2013-06-12 00:46:38 +00:00
|
|
|
continue;
|
2012-03-26 23:03:23 +00:00
|
|
|
file_addr_to_index[sc.function->GetAddressRange()
|
|
|
|
|
.GetBaseAddress()
|
2014-07-01 21:22:11 +00:00
|
|
|
.GetFileAddress()] = i;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-03-26 23:03:23 +00:00
|
|
|
|
2016-03-11 20:20:38 +00:00
|
|
|
FileAddrToIndexMap::const_iterator end = file_addr_to_index.end();
|
|
|
|
|
// Functions were added so we need to merge symbols into any
|
2013-06-12 00:46:38 +00:00
|
|
|
// existing function symbol contexts
|
2016-03-11 20:20:38 +00:00
|
|
|
for (size_t i = start_size; i < num_matches; ++i) {
|
|
|
|
|
sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
|
|
|
|
|
SymbolType sym_type = sc.symbol->GetType();
|
|
|
|
|
if (sc.symbol && sc.symbol->ValueIsAddress() &&
|
2015-10-08 09:45:41 +00:00
|
|
|
(sym_type == eSymbolTypeCode ||
|
|
|
|
|
sym_type == eSymbolTypeResolver)) {
|
|
|
|
|
FileAddrToIndexMap::const_iterator pos =
|
|
|
|
|
file_addr_to_index.find(
|
|
|
|
|
sc.symbol->GetAddressRef().GetFileAddress());
|
|
|
|
|
if (pos == end)
|
|
|
|
|
sc_list.Append(sc);
|
2016-09-06 20:57:50 +00:00
|
|
|
else
|
2013-06-12 00:46:38 +00:00
|
|
|
sc_list[pos->second].symbol = sc.symbol;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-26 23:03:23 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-07-29 19:53:35 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-12 02:20:34 +00:00
|
|
|
void Module::FindAddressesForLine(const lldb::TargetSP target_sp,
|
|
|
|
|
const FileSpec &file, uint32_t line,
|
|
|
|
|
Function *function,
|
|
|
|
|
std::vector<Address> &output_local,
|
|
|
|
|
std::vector<Address> &output_extern) {
|
|
|
|
|
SearchFilterByModule filter(target_sp, m_file);
|
2021-05-04 23:03:10 +00:00
|
|
|
|
|
|
|
|
// TODO: Handle SourceLocationSpec column information
|
|
|
|
|
SourceLocationSpec location_spec(file, line, /*column=*/llvm::None,
|
|
|
|
|
/*check_inlines=*/true,
|
|
|
|
|
/*exact_match=*/false);
|
|
|
|
|
AddressResolverFileLine resolver(location_spec);
|
2013-09-12 02:20:34 +00:00
|
|
|
resolver.ResolveAddress(filter);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-03-11 20:20:38 +00:00
|
|
|
for (size_t n = 0; n < resolver.GetNumberOfAddresses(); n++) {
|
2013-09-12 02:20:34 +00:00
|
|
|
Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress();
|
|
|
|
|
Function *f = addr.CalculateSymbolContextFunction();
|
|
|
|
|
if (f && f == function)
|
|
|
|
|
output_local.push_back(addr);
|
2011-07-29 19:53:35 +00:00
|
|
|
else
|
2012-03-26 23:03:23 +00:00
|
|
|
output_extern.push_back(addr);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 15:40:41 +00:00
|
|
|
void Module::FindTypes_Impl(
|
2020-02-17 19:25:52 +01:00
|
|
|
ConstString name, const CompilerDeclContext &parent_decl_ctx,
|
2019-09-30 16:42:28 +00:00
|
|
|
size_t max_matches,
|
2012-03-26 23:03:23 +00:00
|
|
|
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
|
2015-10-08 09:45:41 +00:00
|
|
|
TypeMap &types) {
|
2019-08-02 08:16:35 +00:00
|
|
|
if (SymbolFile *symbols = GetSymbolFile())
|
2019-10-01 15:40:41 +00:00
|
|
|
symbols->FindTypes(name, parent_decl_ctx, max_matches,
|
|
|
|
|
searched_symbol_files, types);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-01 15:40:41 +00:00
|
|
|
void Module::FindTypesInNamespace(ConstString type_name,
|
2020-02-17 19:25:52 +01:00
|
|
|
const CompilerDeclContext &parent_decl_ctx,
|
2019-10-01 15:40:41 +00:00
|
|
|
size_t max_matches, TypeList &type_list) {
|
2015-10-08 09:45:41 +00:00
|
|
|
TypeMap types_map;
|
2016-03-11 20:20:38 +00:00
|
|
|
llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
|
2019-10-01 15:40:41 +00:00
|
|
|
FindTypes_Impl(type_name, parent_decl_ctx, max_matches, searched_symbol_files,
|
|
|
|
|
types_map);
|
|
|
|
|
if (types_map.GetSize()) {
|
2019-01-14 22:41:21 +00:00
|
|
|
SymbolContext sc;
|
|
|
|
|
sc.module_sp = shared_from_this();
|
2016-03-11 20:20:38 +00:00
|
|
|
sc.SortTypeList(types_map, type_list);
|
2019-01-14 22:41:21 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-09 12:09:56 +01:00
|
|
|
lldb::TypeSP Module::FindFirstType(const SymbolContext &sc, ConstString name,
|
|
|
|
|
bool exact_match) {
|
2012-12-05 21:24:42 +00:00
|
|
|
TypeList type_list;
|
2016-02-10 21:28:13 +00:00
|
|
|
llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
|
2019-10-01 15:40:41 +00:00
|
|
|
FindTypes(name, exact_match, 1, searched_symbol_files, type_list);
|
|
|
|
|
if (type_list.GetSize())
|
2015-10-08 09:45:41 +00:00
|
|
|
return type_list.GetTypeAtIndex(0);
|
|
|
|
|
return TypeSP();
|
2012-10-22 16:19:56 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-10-01 15:40:41 +00:00
|
|
|
void Module::FindTypes(
|
2019-03-06 21:22:25 +00:00
|
|
|
ConstString name, bool exact_match, size_t max_matches,
|
2016-03-11 20:20:38 +00:00
|
|
|
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
|
|
|
|
|
TypeList &types) {
|
|
|
|
|
const char *type_name_cstr = name.GetCString();
|
2017-01-10 11:13:59 +00:00
|
|
|
llvm::StringRef type_scope;
|
|
|
|
|
llvm::StringRef type_basename;
|
2012-10-22 16:19:56 +00:00
|
|
|
TypeClass type_class = eTypeClassAny;
|
2016-03-11 20:20:38 +00:00
|
|
|
TypeMap typesmap;
|
2018-05-08 03:08:46 +00:00
|
|
|
|
2016-03-11 20:20:38 +00:00
|
|
|
if (Type::GetTypeScopeAndBasename(type_name_cstr, type_scope, type_basename,
|
2012-10-22 16:19:56 +00:00
|
|
|
type_class)) {
|
2012-03-26 23:03:23 +00:00
|
|
|
// Check if "name" starts with "::" which means the qualified type starts
|
2016-03-11 20:20:38 +00:00
|
|
|
// from the root namespace and implies and exact match. The typenames we
|
2012-03-26 23:03:23 +00:00
|
|
|
// get back from clang do not start with "::" so we need to strip this off
|
2014-07-01 21:22:11 +00:00
|
|
|
// in order to get the qualified names to match
|
2017-01-10 11:13:59 +00:00
|
|
|
exact_match = type_scope.consume_front("::");
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-01-10 11:13:59 +00:00
|
|
|
ConstString type_basename_const_str(type_basename);
|
2020-02-17 19:25:52 +01:00
|
|
|
FindTypes_Impl(type_basename_const_str, CompilerDeclContext(), max_matches,
|
2019-10-01 15:40:41 +00:00
|
|
|
searched_symbol_files, typesmap);
|
|
|
|
|
if (typesmap.GetSize())
|
2022-07-07 19:47:46 +00:00
|
|
|
typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class,
|
2015-07-24 23:38:01 +00:00
|
|
|
exact_match);
|
2010-06-08 16:52:24 +00:00
|
|
|
} else {
|
|
|
|
|
// The type is not in a namespace/class scope, just search for it by
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
// basename
|
2018-04-30 21:06:30 +00:00
|
|
|
if (type_class != eTypeClassAny && !type_basename.empty()) {
|
2010-06-08 16:52:24 +00:00
|
|
|
// The "type_name_cstr" will have been modified if we have a valid type
|
2018-04-30 16:49:04 +00:00
|
|
|
// class prefix (like "struct", "class", "union", "typedef" etc).
|
2020-02-17 19:25:52 +01:00
|
|
|
FindTypes_Impl(ConstString(type_basename), CompilerDeclContext(),
|
|
|
|
|
UINT_MAX, searched_symbol_files, typesmap);
|
2022-07-07 19:47:46 +00:00
|
|
|
typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class,
|
2018-04-30 21:06:30 +00:00
|
|
|
exact_match);
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2020-02-17 19:25:52 +01:00
|
|
|
FindTypes_Impl(name, CompilerDeclContext(), UINT_MAX,
|
|
|
|
|
searched_symbol_files, typesmap);
|
2018-04-30 21:06:30 +00:00
|
|
|
if (exact_match) {
|
2022-07-07 19:58:41 +00:00
|
|
|
typesmap.RemoveMismatchedTypes(type_scope, name.GetStringRef(),
|
2020-01-28 20:23:46 +01:00
|
|
|
type_class, exact_match);
|
2018-04-30 21:06:30 +00:00
|
|
|
}
|
2013-04-29 17:25:54 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2019-10-01 15:40:41 +00:00
|
|
|
if (typesmap.GetSize()) {
|
2019-01-14 22:41:21 +00:00
|
|
|
SymbolContext sc;
|
|
|
|
|
sc.module_sp = shared_from_this();
|
2013-04-29 17:25:54 +00:00
|
|
|
sc.SortTypeList(typesmap, types);
|
2019-01-14 22:41:21 +00:00
|
|
|
}
|
2013-04-29 17:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
2019-11-12 09:25:59 -08:00
|
|
|
void Module::FindTypes(
|
|
|
|
|
llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
|
|
|
|
|
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
|
|
|
|
|
TypeMap &types) {
|
2022-03-11 11:16:06 -08:00
|
|
|
// If a scoped timer is needed, place it in a SymbolFile::FindTypes override.
|
|
|
|
|
// A timer here is too high volume for some cases, for example when calling
|
|
|
|
|
// FindTypes on each object file.
|
2019-08-22 21:45:58 +00:00
|
|
|
if (SymbolFile *symbols = GetSymbolFile())
|
2019-11-12 09:25:59 -08:00
|
|
|
symbols->FindTypes(pattern, languages, searched_symbol_files, types);
|
2019-08-22 21:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-08 07:34:07 +00:00
|
|
|
SymbolFile *Module::GetSymbolFile(bool can_create, Stream *feedback_strm) {
|
|
|
|
|
if (!m_did_load_symfile.load()) {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2019-08-08 07:34:07 +00:00
|
|
|
if (!m_did_load_symfile.load() && can_create) {
|
2011-11-28 01:45:00 +00:00
|
|
|
ObjectFile *obj_file = GetObjectFile();
|
|
|
|
|
if (obj_file != nullptr) {
|
2020-12-21 13:41:57 -08:00
|
|
|
LLDB_SCOPED_TIMER();
|
2019-02-13 06:25:41 +00:00
|
|
|
m_symfile_up.reset(
|
2011-11-28 01:45:00 +00:00
|
|
|
SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
|
2019-08-08 07:34:07 +00:00
|
|
|
m_did_load_symfile = true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-11-28 01:45:00 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2019-08-08 07:34:07 +00:00
|
|
|
return m_symfile_up ? m_symfile_up->GetSymbolFile() : nullptr;
|
2019-08-02 08:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 09:21:47 +00:00
|
|
|
Symtab *Module::GetSymtab() {
|
|
|
|
|
if (SymbolFile *symbols = GetSymbolFile())
|
|
|
|
|
return symbols->GetSymtab();
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
void Module::SetFileSpecAndObjectName(const FileSpec &file,
|
2019-03-06 21:22:25 +00:00
|
|
|
ConstString object_name) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// Container objects whose paths do not specify a file directly can call this
|
|
|
|
|
// function to correct the file and object names.
|
2010-06-08 16:52:24 +00:00
|
|
|
m_file = file;
|
2018-10-31 21:49:27 +00:00
|
|
|
m_mod_time = FileSystem::Instance().GetModificationTime(file);
|
2010-06-08 16:52:24 +00:00
|
|
|
m_object_name = object_name;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-26 05:51:37 +00:00
|
|
|
const ArchSpec &Module::GetArchitecture() const { return m_arch; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
std::string Module::GetSpecificationDescription() const {
|
2015-03-31 21:01:48 +00:00
|
|
|
std::string spec(GetFileSpec().GetPath());
|
2013-04-29 17:25:54 +00:00
|
|
|
if (m_object_name) {
|
|
|
|
|
spec += '(';
|
2010-10-31 03:01:06 +00:00
|
|
|
spec += m_object_name.GetCString();
|
2013-04-29 17:25:54 +00:00
|
|
|
spec += ')';
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-03-15 21:01:31 +00:00
|
|
|
return spec;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-04 09:20:42 +01:00
|
|
|
void Module::GetDescription(llvm::raw_ostream &s,
|
|
|
|
|
lldb::DescriptionLevel level) {
|
2011-11-28 01:45:00 +00:00
|
|
|
if (level >= eDescriptionLevelFull) {
|
2011-02-23 00:35:02 +00:00
|
|
|
if (m_arch.IsValid())
|
2019-12-04 09:20:42 +01:00
|
|
|
s << llvm::formatv("({0}) ", m_arch.GetArchitectureName());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-28 01:45:00 +00:00
|
|
|
if (level == eDescriptionLevelBrief) {
|
2010-10-31 03:01:06 +00:00
|
|
|
const char *filename = m_file.GetFilename().GetCString();
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-13 17:12:24 +00:00
|
|
|
if (filename)
|
2019-12-04 09:20:42 +01:00
|
|
|
s << filename;
|
2011-11-28 01:45:00 +00:00
|
|
|
} else {
|
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
if (m_file.GetPath(path, sizeof(path)))
|
2019-12-04 09:20:42 +01:00
|
|
|
s << path;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-31 03:01:06 +00:00
|
|
|
const char *object_name = m_object_name.GetCString();
|
|
|
|
|
if (object_name)
|
2019-12-04 09:20:42 +01:00
|
|
|
s << llvm::formatv("({0})", object_name);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-28 01:45:00 +00:00
|
|
|
bool Module::FileHasChanged() const {
|
2020-07-09 14:14:36 -07:00
|
|
|
// We have provided the DataBuffer for this module to avoid accessing the
|
|
|
|
|
// filesystem. We never want to reload those files.
|
|
|
|
|
if (m_data_sp)
|
|
|
|
|
return false;
|
2016-03-11 20:20:38 +00:00
|
|
|
if (!m_file_has_changed)
|
2016-11-01 16:11:14 +00:00
|
|
|
m_file_has_changed =
|
2018-10-31 21:49:27 +00:00
|
|
|
(FileSystem::Instance().GetModificationTime(m_file) != m_mod_time);
|
2012-07-12 22:51:12 +00:00
|
|
|
return m_file_has_changed;
|
2011-11-28 01:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-14 10:46:57 -07:00
|
|
|
void Module::ReportWarningOptimization(
|
|
|
|
|
llvm::Optional<lldb::user_id_t> debugger_id) {
|
|
|
|
|
ConstString file_name = GetFileSpec().GetFilename();
|
|
|
|
|
if (file_name.IsEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
StreamString ss;
|
|
|
|
|
ss << file_name.GetStringRef()
|
|
|
|
|
<< " was compiled with optimization - stepping may behave "
|
|
|
|
|
"oddly; variables may not be available.";
|
|
|
|
|
Debugger::ReportWarning(std::string(ss.GetString()), debugger_id,
|
|
|
|
|
&m_optimization_warning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Module::ReportWarningUnsupportedLanguage(
|
|
|
|
|
LanguageType language, llvm::Optional<lldb::user_id_t> debugger_id) {
|
|
|
|
|
StreamString ss;
|
|
|
|
|
ss << "This version of LLDB has no plugin for the language \""
|
|
|
|
|
<< Language::GetNameForLanguageType(language)
|
|
|
|
|
<< "\". "
|
|
|
|
|
"Inspection of frame variables will be limited.";
|
|
|
|
|
Debugger::ReportWarning(std::string(ss.GetString()), debugger_id,
|
|
|
|
|
&m_language_warning);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-28 01:45:00 +00:00
|
|
|
void Module::ReportErrorIfModifyDetected(const char *format, ...) {
|
|
|
|
|
if (!m_first_file_changed_log) {
|
2012-07-12 22:51:12 +00:00
|
|
|
if (FileHasChanged()) {
|
2011-11-28 01:45:00 +00:00
|
|
|
m_first_file_changed_log = true;
|
2012-01-05 03:57:59 +00:00
|
|
|
if (format) {
|
|
|
|
|
StreamString strm;
|
2022-06-24 09:36:29 -07:00
|
|
|
strm.PutCString("the object file ");
|
2019-12-04 09:20:42 +01:00
|
|
|
GetDescription(strm.AsRawOstream(), lldb::eDescriptionLevelFull);
|
2012-01-11 01:59:18 +00:00
|
|
|
strm.PutCString(" has been modified\n");
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-01-05 03:57:59 +00:00
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
strm.PrintfVarArg(format, args);
|
|
|
|
|
va_end(args);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-01-05 03:57:59 +00:00
|
|
|
const int format_len = strlen(format);
|
|
|
|
|
if (format_len > 0) {
|
|
|
|
|
const char last_char = format[format_len - 1];
|
2019-04-16 07:48:11 +00:00
|
|
|
if (last_char != '\n' && last_char != '\r')
|
2012-01-05 03:57:59 +00:00
|
|
|
strm.EOL();
|
|
|
|
|
}
|
|
|
|
|
strm.PutCString("The debug session should be aborted as the original "
|
2022-06-24 09:36:29 -07:00
|
|
|
"debug information has been overwritten.");
|
|
|
|
|
Debugger::ReportError(std::string(strm.GetString()));
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-01-05 03:57:59 +00:00
|
|
|
}
|
2011-11-28 01:45:00 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 09:36:29 -07:00
|
|
|
void Module::ReportError(const char *format, ...) {
|
|
|
|
|
if (format && format[0]) {
|
|
|
|
|
StreamString strm;
|
|
|
|
|
GetDescription(strm.AsRawOstream(), lldb::eDescriptionLevelBrief);
|
|
|
|
|
strm.PutChar(' ');
|
|
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
strm.PrintfVarArg(format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
|
|
Debugger::ReportError(std::string(strm.GetString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-28 01:45:00 +00:00
|
|
|
void Module::ReportWarning(const char *format, ...) {
|
2016-03-11 20:20:38 +00:00
|
|
|
if (format && format[0]) {
|
2011-11-28 01:45:00 +00:00
|
|
|
StreamString strm;
|
2019-12-04 09:20:42 +01:00
|
|
|
GetDescription(strm.AsRawOstream(), lldb::eDescriptionLevelFull);
|
2011-11-28 01:45:00 +00:00
|
|
|
strm.PutChar(' ');
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-11-28 01:45:00 +00:00
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
strm.PrintfVarArg(format, args);
|
|
|
|
|
va_end(args);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2022-06-24 09:36:29 -07:00
|
|
|
Debugger::ReportWarning(std::string(strm.GetString()));
|
2011-11-28 01:45:00 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-23 22:55:20 +00:00
|
|
|
void Module::LogMessage(Log *log, const char *format, ...) {
|
|
|
|
|
if (log != nullptr) {
|
|
|
|
|
StreamString log_message;
|
2019-12-04 09:20:42 +01:00
|
|
|
GetDescription(log_message.AsRawOstream(), lldb::eDescriptionLevelFull);
|
2012-04-23 22:55:20 +00:00
|
|
|
log_message.PutCString(": ");
|
2012-01-05 03:57:59 +00:00
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
log_message.PrintfVarArg(format, args);
|
|
|
|
|
va_end(args);
|
2016-11-16 21:15:24 +00:00
|
|
|
log->PutCString(log_message.GetData());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-23 22:55:20 +00:00
|
|
|
void Module::LogMessageVerboseBacktrace(Log *log, const char *format, ...) {
|
2016-03-11 20:20:38 +00:00
|
|
|
if (log != nullptr) {
|
2012-04-23 22:55:20 +00:00
|
|
|
StreamString log_message;
|
2019-12-04 09:20:42 +01:00
|
|
|
GetDescription(log_message.AsRawOstream(), lldb::eDescriptionLevelFull);
|
2012-04-23 22:55:20 +00:00
|
|
|
log_message.PutCString(": ");
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
log_message.PrintfVarArg(format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
if (log->GetVerbose()) {
|
2015-03-06 20:45:43 +00:00
|
|
|
std::string back_trace;
|
|
|
|
|
llvm::raw_string_ostream stream(back_trace);
|
|
|
|
|
llvm::sys::PrintStackTrace(stream);
|
2016-11-02 20:34:10 +00:00
|
|
|
log_message.PutCString(back_trace);
|
2012-04-23 22:55:20 +00:00
|
|
|
}
|
2016-11-16 21:15:24 +00:00
|
|
|
log->PutCString(log_message.GetData());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-04-23 22:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
void Module::Dump(Stream *s) {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-10-08 00:21:05 +00:00
|
|
|
// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
|
2010-06-08 16:52:24 +00:00
|
|
|
s->Indent();
|
2013-04-29 17:25:54 +00:00
|
|
|
s->Printf("Module %s%s%s%s\n", m_file.GetPath().c_str(),
|
2010-06-08 16:52:24 +00:00
|
|
|
m_object_name ? "(" : "",
|
|
|
|
|
m_object_name ? m_object_name.GetCString() : "",
|
|
|
|
|
m_object_name ? ")" : "");
|
|
|
|
|
|
|
|
|
|
s->IndentMore();
|
|
|
|
|
|
|
|
|
|
ObjectFile *objfile = GetObjectFile();
|
|
|
|
|
if (objfile)
|
|
|
|
|
objfile->Dump(s);
|
|
|
|
|
|
2019-08-05 09:21:47 +00:00
|
|
|
if (SymbolFile *symbols = GetSymbolFile())
|
|
|
|
|
symbols->Dump(*s);
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
s->IndentLess();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-06 21:22:25 +00:00
|
|
|
ConstString Module::GetObjectName() const { return m_object_name; }
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
ObjectFile *Module::GetObjectFile() {
|
|
|
|
|
if (!m_did_load_objfile.load()) {
|
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2016-03-11 20:20:38 +00:00
|
|
|
if (!m_did_load_objfile.load()) {
|
2020-12-21 13:41:57 -08:00
|
|
|
LLDB_SCOPED_TIMERF("Module::GetObjectFile () module = %s",
|
2010-06-08 16:52:24 +00:00
|
|
|
GetFileSpec().GetFilename().AsCString(""));
|
2015-07-24 23:38:01 +00:00
|
|
|
lldb::offset_t data_offset = 0;
|
2020-07-09 14:14:36 -07:00
|
|
|
lldb::offset_t file_size = 0;
|
|
|
|
|
|
|
|
|
|
if (m_data_sp)
|
|
|
|
|
file_size = m_data_sp->GetByteSize();
|
|
|
|
|
else if (m_file)
|
|
|
|
|
file_size = FileSystem::Instance().GetByteSize(m_file);
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
if (file_size > m_object_offset) {
|
|
|
|
|
m_did_load_objfile = true;
|
2020-07-09 14:14:36 -07:00
|
|
|
// FindPlugin will modify its data_sp argument. Do not let it
|
|
|
|
|
// modify our m_data_sp member.
|
|
|
|
|
auto data_sp = m_data_sp;
|
2012-02-24 21:55:59 +00:00
|
|
|
m_objfile_sp = ObjectFile::FindPlugin(
|
2010-06-08 16:52:24 +00:00
|
|
|
shared_from_this(), &m_file, m_object_offset,
|
|
|
|
|
file_size - m_object_offset, data_sp, data_offset);
|
|
|
|
|
if (m_objfile_sp) {
|
2015-07-24 23:38:01 +00:00
|
|
|
// Once we get the object file, update our module with the object
|
2018-04-30 16:49:04 +00:00
|
|
|
// file's architecture since it might differ in vendor/os if some
|
|
|
|
|
// parts were unknown. But since the matching arch might already be
|
|
|
|
|
// more specific than the generic COFF architecture, only merge in
|
|
|
|
|
// those values that overwrite unspecified unknown values.
|
2019-01-03 10:37:19 +00:00
|
|
|
m_arch.MergeFrom(m_objfile_sp->GetArchitecture());
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2010-06-08 16:52:24 +00:00
|
|
|
ReportError("failed to load objfile for %s",
|
|
|
|
|
GetFileSpec().GetPath().c_str());
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
return m_objfile_sp.get();
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-08 00:01:36 +00:00
|
|
|
SectionList *Module::GetSectionList() {
|
2019-02-13 06:25:41 +00:00
|
|
|
// Populate m_sections_up with sections from objfile.
|
|
|
|
|
if (!m_sections_up) {
|
2013-07-10 01:23:25 +00:00
|
|
|
ObjectFile *obj_file = GetObjectFile();
|
2013-01-08 00:01:36 +00:00
|
|
|
if (obj_file != nullptr)
|
2013-07-10 01:23:25 +00:00
|
|
|
obj_file->CreateSections(*GetUnifiedSectionList());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2019-02-13 06:25:41 +00:00
|
|
|
return m_sections_up.get();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-22 02:46:46 +00:00
|
|
|
void Module::SectionFileAddressesChanged() {
|
2013-07-10 01:23:25 +00:00
|
|
|
ObjectFile *obj_file = GetObjectFile();
|
2014-08-22 02:46:46 +00:00
|
|
|
if (obj_file)
|
|
|
|
|
obj_file->SectionFileAddressesChanged();
|
2019-08-02 08:16:35 +00:00
|
|
|
if (SymbolFile *symbols = GetSymbolFile())
|
|
|
|
|
symbols->SectionFileAddressesChanged();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-18 10:45:02 +00:00
|
|
|
UnwindTable &Module::GetUnwindTable() {
|
|
|
|
|
if (!m_unwind_table)
|
|
|
|
|
m_unwind_table.emplace(*this);
|
|
|
|
|
return *m_unwind_table;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-01 19:45:50 +00:00
|
|
|
SectionList *Module::GetUnifiedSectionList() {
|
2019-02-13 06:25:41 +00:00
|
|
|
if (!m_sections_up)
|
2019-08-14 22:19:23 +00:00
|
|
|
m_sections_up = std::make_unique<SectionList>();
|
2019-02-13 06:25:41 +00:00
|
|
|
return m_sections_up.get();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-06 21:22:25 +00:00
|
|
|
const Symbol *Module::FindFirstSymbolWithNameAndType(ConstString name,
|
2013-01-08 00:01:36 +00:00
|
|
|
SymbolType symbol_type) {
|
2020-12-21 13:41:57 -08:00
|
|
|
LLDB_SCOPED_TIMERF(
|
|
|
|
|
"Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
|
2013-01-08 00:01:36 +00:00
|
|
|
name.AsCString(), symbol_type);
|
2019-08-05 09:21:47 +00:00
|
|
|
if (Symtab *symtab = GetSymtab())
|
|
|
|
|
return symtab->FindFirstSymbolWithNameAndType(
|
|
|
|
|
name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
|
2016-03-11 20:20:38 +00:00
|
|
|
return nullptr;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
void Module::SymbolIndicesToSymbolContextList(
|
2013-01-08 00:01:36 +00:00
|
|
|
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
|
2010-06-08 16:52:24 +00:00
|
|
|
// already thread safe.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-01-08 00:01:36 +00:00
|
|
|
size_t num_indices = symbol_indexes.size();
|
|
|
|
|
if (num_indices > 0) {
|
2010-06-08 16:52:24 +00:00
|
|
|
SymbolContext sc;
|
|
|
|
|
CalculateSymbolContext(&sc);
|
2013-01-08 00:01:36 +00:00
|
|
|
for (size_t i = 0; i < num_indices; i++) {
|
|
|
|
|
sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
|
2010-06-08 16:52:24 +00:00
|
|
|
if (sc.symbol)
|
2013-06-12 00:46:38 +00:00
|
|
|
sc_list.Append(sc);
|
2013-01-08 00:01:36 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2013-01-08 00:01:36 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2021-12-09 12:09:56 +01:00
|
|
|
void Module::FindFunctionSymbols(ConstString name, uint32_t name_type_mask,
|
|
|
|
|
SymbolContextList &sc_list) {
|
2020-12-21 13:41:57 -08:00
|
|
|
LLDB_SCOPED_TIMERF("Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
|
2012-03-26 23:03:23 +00:00
|
|
|
name.AsCString(), name_type_mask);
|
2019-08-05 09:21:47 +00:00
|
|
|
if (Symtab *symtab = GetSymtab())
|
2019-10-17 19:56:40 +00:00
|
|
|
symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-17 19:56:40 +00:00
|
|
|
void Module::FindSymbolsWithNameAndType(ConstString name,
|
2021-12-09 12:09:56 +01:00
|
|
|
SymbolType symbol_type,
|
|
|
|
|
SymbolContextList &sc_list) {
|
2010-06-08 16:52:24 +00:00
|
|
|
// No need to protect this call using m_mutex all other method calls are
|
|
|
|
|
// already thread safe.
|
2019-08-05 09:21:47 +00:00
|
|
|
if (Symtab *symtab = GetSymtab()) {
|
|
|
|
|
std::vector<uint32_t> symbol_indexes;
|
|
|
|
|
symtab->FindAllSymbolsWithNameAndType(name, symbol_type, symbol_indexes);
|
|
|
|
|
SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2022-07-29 15:19:17 -07:00
|
|
|
void Module::FindSymbolsMatchingRegExAndType(
|
|
|
|
|
const RegularExpression ®ex, SymbolType symbol_type,
|
|
|
|
|
SymbolContextList &sc_list, Mangled::NamePreference mangling_preference) {
|
2010-06-08 16:52:24 +00:00
|
|
|
// No need to protect this call using m_mutex all other method calls are
|
|
|
|
|
// already thread safe.
|
2020-12-21 13:41:57 -08:00
|
|
|
LLDB_SCOPED_TIMERF(
|
2010-06-08 16:52:24 +00:00
|
|
|
"Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
|
2016-09-21 16:01:28 +00:00
|
|
|
regex.GetText().str().c_str(), symbol_type);
|
2019-08-05 09:21:47 +00:00
|
|
|
if (Symtab *symtab = GetSymtab()) {
|
|
|
|
|
std::vector<uint32_t> symbol_indexes;
|
|
|
|
|
symtab->FindAllSymbolsMatchingRexExAndType(
|
|
|
|
|
regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny,
|
2022-07-29 15:19:17 -07:00
|
|
|
symbol_indexes, mangling_preference);
|
2019-08-05 09:21:47 +00:00
|
|
|
SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2017-04-28 00:51:06 +00:00
|
|
|
void Module::PreloadSymbols() {
|
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2019-08-02 08:16:35 +00:00
|
|
|
SymbolFile *sym_file = GetSymbolFile();
|
|
|
|
|
if (!sym_file)
|
2017-04-28 00:51:06 +00:00
|
|
|
return;
|
2019-08-02 08:16:35 +00:00
|
|
|
|
2021-11-17 21:18:24 -08:00
|
|
|
// Load the object file symbol table and any symbols from the SymbolFile that
|
|
|
|
|
// get appended using SymbolFile::AddSymbols(...).
|
2019-08-02 08:16:35 +00:00
|
|
|
if (Symtab *symtab = sym_file->GetSymtab())
|
2017-04-28 00:51:06 +00:00
|
|
|
symtab->PreloadSymbols();
|
2021-11-17 21:18:24 -08:00
|
|
|
|
|
|
|
|
// Now let the symbol file preload its data and the symbol table will be
|
|
|
|
|
// available without needing to take the module lock.
|
|
|
|
|
sym_file->PreloadSymbols();
|
2017-04-28 00:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-18 18:10:51 +00:00
|
|
|
void Module::SetSymbolFileFileSpec(const FileSpec &file) {
|
2018-11-01 17:09:25 +00:00
|
|
|
if (!FileSystem::Instance().Exists(file))
|
2015-03-31 21:01:48 +00:00
|
|
|
return;
|
2019-02-13 06:25:41 +00:00
|
|
|
if (m_symfile_up) {
|
2015-03-31 21:01:48 +00:00
|
|
|
// Remove any sections in the unified section list that come from the
|
|
|
|
|
// current symbol vendor.
|
2013-07-10 01:23:25 +00:00
|
|
|
SectionList *section_list = GetSectionList();
|
2019-08-02 08:16:35 +00:00
|
|
|
SymbolFile *symbol_file = GetSymbolFile();
|
2013-08-13 16:46:35 +00:00
|
|
|
if (section_list && symbol_file) {
|
2015-03-31 21:01:48 +00:00
|
|
|
ObjectFile *obj_file = symbol_file->GetObjectFile();
|
|
|
|
|
// Make sure we have an object file and that the symbol vendor's objfile
|
2018-04-30 16:49:04 +00:00
|
|
|
// isn't the same as the module's objfile before we remove any sections
|
|
|
|
|
// for it...
|
2015-03-31 21:01:48 +00:00
|
|
|
if (obj_file) {
|
|
|
|
|
// Check to make sure we aren't trying to specify the file we already
|
|
|
|
|
// have
|
|
|
|
|
if (obj_file->GetFileSpec() == file) {
|
|
|
|
|
// We are being told to add the exact same file that we already have
|
|
|
|
|
// we don't have to do anything.
|
|
|
|
|
return;
|
2013-07-01 19:45:50 +00:00
|
|
|
}
|
2013-04-18 18:10:51 +00:00
|
|
|
|
2010-08-09 23:31:02 +00:00
|
|
|
// Cleare the current symtab as we are going to replace it with a new
|
2016-09-06 20:57:50 +00:00
|
|
|
// one
|
2010-08-09 23:31:02 +00:00
|
|
|
obj_file->ClearSymtab();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-03-18 10:45:02 +00:00
|
|
|
// Clear the unwind table too, as that may also be affected by the
|
|
|
|
|
// symbol file information.
|
|
|
|
|
m_unwind_table.reset();
|
|
|
|
|
|
2010-08-09 23:31:02 +00:00
|
|
|
// The symbol file might be a directory bundle ("/tmp/a.out.dSYM")
|
2018-04-30 16:49:04 +00:00
|
|
|
// instead of a full path to the symbol file within the bundle
|
2016-03-11 20:20:38 +00:00
|
|
|
// ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to
|
2012-03-26 23:03:23 +00:00
|
|
|
// check this
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-11-08 00:14:50 +00:00
|
|
|
if (FileSystem::Instance().IsDirectory(file)) {
|
2016-03-11 20:20:38 +00:00
|
|
|
std::string new_path(file.GetPath());
|
2010-08-09 23:31:02 +00:00
|
|
|
std::string old_path(obj_file->GetFileSpec().GetPath());
|
2020-03-31 20:56:24 +02:00
|
|
|
if (llvm::StringRef(old_path).startswith(new_path)) {
|
2010-08-09 23:31:02 +00:00
|
|
|
// We specified the same bundle as the symbol file that we already
|
2016-09-06 20:57:50 +00:00
|
|
|
// have
|
2010-08-09 23:31:02 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-08-09 23:31:02 +00:00
|
|
|
|
2011-08-03 01:03:17 +00:00
|
|
|
if (obj_file != m_objfile_sp.get()) {
|
|
|
|
|
size_t num_sections = section_list->GetNumSections(0);
|
|
|
|
|
for (size_t idx = num_sections; idx > 0; --idx) {
|
|
|
|
|
lldb::SectionSP section_sp(
|
|
|
|
|
section_list->GetSectionAtIndex(idx - 1));
|
|
|
|
|
if (section_sp->GetObjectFile() == obj_file) {
|
|
|
|
|
section_list->DeleteSection(idx - 1);
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-08-03 01:03:17 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-08-03 01:03:17 +00:00
|
|
|
}
|
2015-03-31 21:01:48 +00:00
|
|
|
// Keep all old symbol files around in case there are any lingering type
|
2018-04-30 16:49:04 +00:00
|
|
|
// references in any SBValue objects that might have been handed out.
|
2019-02-13 06:25:41 +00:00
|
|
|
m_old_symfiles.push_back(std::move(m_symfile_up));
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2013-04-18 18:10:51 +00:00
|
|
|
m_symfile_spec = file;
|
2019-02-13 06:25:41 +00:00
|
|
|
m_symfile_up.reset();
|
2019-08-08 07:34:07 +00:00
|
|
|
m_did_load_symfile = false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
bool Module::IsExecutable() {
|
2016-03-11 20:20:38 +00:00
|
|
|
if (GetObjectFile() == nullptr)
|
2011-08-03 01:03:17 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
else
|
2013-03-23 00:50:58 +00:00
|
|
|
return GetObjectFile()->IsExecutable();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-03 01:03:17 +00:00
|
|
|
bool Module::IsLoadedInTarget(Target *target) {
|
2013-07-10 01:23:25 +00:00
|
|
|
ObjectFile *obj_file = GetObjectFile();
|
2014-08-22 02:46:46 +00:00
|
|
|
if (obj_file) {
|
2013-07-10 01:23:25 +00:00
|
|
|
SectionList *sections = GetSectionList();
|
2016-03-11 20:20:38 +00:00
|
|
|
if (sections != nullptr) {
|
2015-03-31 21:01:48 +00:00
|
|
|
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);
|
2011-08-03 01:03:17 +00:00
|
|
|
if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS) {
|
|
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-09 23:31:02 +00:00
|
|
|
return false;
|
2011-08-03 01:03:17 +00:00
|
|
|
}
|
2012-11-08 02:22:02 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
bool Module::LoadScriptingResourceInTarget(Target *target, Status &error,
|
2013-05-21 00:00:30 +00:00
|
|
|
Stream *feedback_stream) {
|
2012-11-08 02:22:02 +00:00
|
|
|
if (!target) {
|
|
|
|
|
error.SetErrorString("invalid destination Target");
|
2013-01-11 23:44:27 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2012-11-08 02:22:02 +00:00
|
|
|
|
2013-03-23 00:50:58 +00:00
|
|
|
LoadScriptFromSymFile should_load =
|
|
|
|
|
target->TargetProperties::GetLoadScriptFromSymbolFile();
|
2016-03-11 20:20:38 +00:00
|
|
|
|
2013-03-23 00:50:58 +00:00
|
|
|
if (should_load == eLoadScriptFromSymFileFalse)
|
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-03-23 00:50:58 +00:00
|
|
|
Debugger &debugger = target->GetDebugger();
|
|
|
|
|
const ScriptLanguage script_language = debugger.GetScriptLanguage();
|
|
|
|
|
if (script_language != eScriptLanguageNone) {
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-03-11 20:20:38 +00:00
|
|
|
PlatformSP platform_sp(target->GetPlatform());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-03-11 20:20:38 +00:00
|
|
|
if (!platform_sp) {
|
2013-01-11 23:44:27 +00:00
|
|
|
error.SetErrorString("invalid Platform");
|
2010-08-09 23:31:02 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-11 23:44:27 +00:00
|
|
|
FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources(
|
2013-07-01 18:49:43 +00:00
|
|
|
target, *this, feedback_stream);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-07-01 18:49:43 +00:00
|
|
|
const uint32_t num_specs = file_specs.GetSize();
|
2013-01-11 23:44:27 +00:00
|
|
|
if (num_specs) {
|
2019-04-26 22:43:16 +00:00
|
|
|
ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter();
|
2012-11-08 02:22:02 +00:00
|
|
|
if (script_interpreter) {
|
2016-03-11 20:20:38 +00:00
|
|
|
for (uint32_t i = 0; i < num_specs; ++i) {
|
2013-07-01 18:49:43 +00:00
|
|
|
FileSpec scripting_fspec(file_specs.GetFileSpecAtIndex(i));
|
2018-11-01 17:09:25 +00:00
|
|
|
if (scripting_fspec &&
|
|
|
|
|
FileSystem::Instance().Exists(scripting_fspec)) {
|
2013-07-01 18:49:43 +00:00
|
|
|
if (should_load == eLoadScriptFromSymFileWarn) {
|
2013-01-11 23:44:27 +00:00
|
|
|
if (feedback_stream)
|
|
|
|
|
feedback_stream->Printf(
|
|
|
|
|
"warning: '%s' contains a debug script. To run this script "
|
2013-03-23 00:50:58 +00:00
|
|
|
"in "
|
|
|
|
|
"this debug session:\n\n command script import "
|
2013-07-01 18:49:43 +00:00
|
|
|
"\"%s\"\n\n"
|
2013-03-23 00:50:58 +00:00
|
|
|
"To run all discovered debug scripts in this session:\n\n"
|
|
|
|
|
" settings set target.load-script-from-symbol-file "
|
2016-09-06 20:57:50 +00:00
|
|
|
"true\n",
|
2013-03-23 00:50:58 +00:00
|
|
|
GetFileSpec().GetFileNameStrippingExtension().GetCString(),
|
|
|
|
|
scripting_fspec.GetPath().c_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-01-11 23:44:27 +00:00
|
|
|
StreamString scripting_stream;
|
2019-12-06 08:38:23 +01:00
|
|
|
scripting_fspec.Dump(scripting_stream.AsRawOstream());
|
[lldb] Add the ability to silently import scripted commands
Add the ability to silence command script import. The motivation for
this change is being able to add command script import -s
lldb.macosx.crashlog to your ~/.lldbinit without it printing the
following message at the beginning of every debug session.
"malloc_info", "ptr_refs", "cstr_refs", "find_variable", and
"objc_refs" commands have been installed, use the "--help" options on
these commands for detailed help.
In addition to forwarding the silent option to LoadScriptingModule, this
also changes ScriptInterpreterPythonImpl::ExecuteOneLineWithReturn and
ScriptInterpreterPythonImpl::ExecuteMultipleLines to honor the enable IO
option in ExecuteScriptOptions, which until now was ignored.
Note that IO is only enabled (or disabled) at the start of a session,
and for this particular use case, that's done when taking the Python
lock in LoadScriptingModule, which means that the changes to these two
functions are not strictly necessary, but (IMO) desirable nonetheless.
Differential revision: https://reviews.llvm.org/D105327
2021-07-09 09:23:54 -07:00
|
|
|
LoadScriptOptions options;
|
2014-07-01 21:22:11 +00:00
|
|
|
bool did_load = script_interpreter->LoadScriptingModule(
|
[lldb] Add the ability to silently import scripted commands
Add the ability to silence command script import. The motivation for
this change is being able to add command script import -s
lldb.macosx.crashlog to your ~/.lldbinit without it printing the
following message at the beginning of every debug session.
"malloc_info", "ptr_refs", "cstr_refs", "find_variable", and
"objc_refs" commands have been installed, use the "--help" options on
these commands for detailed help.
In addition to forwarding the silent option to LoadScriptingModule, this
also changes ScriptInterpreterPythonImpl::ExecuteOneLineWithReturn and
ScriptInterpreterPythonImpl::ExecuteMultipleLines to honor the enable IO
option in ExecuteScriptOptions, which until now was ignored.
Note that IO is only enabled (or disabled) at the start of a session,
and for this particular use case, that's done when taking the Python
lock in LoadScriptingModule, which means that the changes to these two
functions are not strictly necessary, but (IMO) desirable nonetheless.
Differential revision: https://reviews.llvm.org/D105327
2021-07-09 09:23:54 -07:00
|
|
|
scripting_stream.GetData(), options, error);
|
2016-03-11 20:20:38 +00:00
|
|
|
if (!did_load)
|
2010-08-09 23:31:02 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-11-08 02:22:02 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2013-01-11 23:44:27 +00:00
|
|
|
error.SetErrorString("invalid ScriptInterpreter");
|
2010-08-09 23:31:02 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-11-08 02:22:02 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-11-08 02:22:02 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-09 23:31:02 +00:00
|
|
|
bool Module::SetArchitecture(const ArchSpec &new_arch) {
|
2011-02-23 00:35:02 +00:00
|
|
|
if (!m_arch.IsValid()) {
|
2010-08-09 23:31:02 +00:00
|
|
|
m_arch = new_arch;
|
|
|
|
|
return true;
|
2011-02-23 00:35:02 +00:00
|
|
|
}
|
2015-02-26 22:15:16 +00:00
|
|
|
return m_arch.IsCompatibleMatch(new_arch);
|
2010-08-09 23:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-07 22:54:47 +00:00
|
|
|
bool Module::SetLoadAddress(Target &target, lldb::addr_t value,
|
|
|
|
|
bool value_is_offset, bool &changed) {
|
2014-02-06 19:02:19 +00:00
|
|
|
ObjectFile *object_file = GetObjectFile();
|
2016-03-11 20:20:38 +00:00
|
|
|
if (object_file != nullptr) {
|
2014-02-07 22:54:47 +00:00
|
|
|
changed = object_file->SetLoadAddress(target, value, value_is_offset);
|
2014-02-06 20:10:16 +00:00
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
changed = false;
|
2012-02-05 02:38:54 +00:00
|
|
|
}
|
2014-02-06 19:02:19 +00:00
|
|
|
return false;
|
2012-02-05 02:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-26 05:51:37 +00: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...
|
2016-03-11 20:20:38 +00:00
|
|
|
return (uuid == GetUUID());
|
2012-02-26 05:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FileSpec &file_spec = module_ref.GetFileSpec();
|
[lldb] s/FileSpec::Equal/FileSpec::Match
Summary:
The FileSpec class is often used as a sort of a pattern -- one specifies
a bare file name to search, and we check if in matches the full file
name of an existing module (for example).
These comparisons used FileSpec::Equal, which had some support for it
(via the full=false argument), but it was not a good fit for this job.
For one, it did a symmetric comparison, which makes sense for a function
called "equal", but not for typical searches (when searching for
"/foo/bar.so", we don't want to find a module whose name is just
"bar.so"). This resulted in patterns like:
if (FileSpec::Equal(pattern, file, pattern.GetDirectory()))
which would request a "full" match only if the pattern really contained
a directory. This worked, but the intended behavior was very unobvious.
On top of that, a lot of the code wanted to handle the case of an
"empty" pattern, and treat it as matching everything. This resulted in
conditions like:
if (pattern && !FileSpec::Equal(pattern, file, pattern.GetDirectory())
which are nearly impossible to decipher.
This patch introduces a FileSpec::Match function, which does exactly
what most of FileSpec::Equal callers want, an asymmetric match between a
"pattern" FileSpec and a an actual FileSpec. Empty paterns match
everything, filename-only patterns match only the filename component.
I've tried to update all callers of FileSpec::Equal to use a simpler
interface. Those that hardcoded full=true have been changed to use
operator==. Those passing full=pattern.GetDirectory() have been changed
to use FileSpec::Match.
There was also a handful of places which hardcoded full=false. I've
changed these to use FileSpec::Match too. This is a slight change in
semantics, but it does not look like that was ever intended, and it was
more likely a result of a misunderstanding of the "proper" way to use
FileSpec::Equal.
[In an ideal world a "FileSpec" and a "FileSpec pattern" would be two
different types, but given how widespread FileSpec is, it is unlikely
we'll get there in one go. This at least provides a good starting point
by centralizing all matching behavior.]
Reviewers: teemperor, JDevlieghere, jdoerfert
Subscribers: emaste, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D70851
2019-11-29 11:31:00 +01:00
|
|
|
if (!FileSpec::Match(file_spec, m_file) &&
|
|
|
|
|
!FileSpec::Match(file_spec, m_platform_file))
|
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-10-03 22:27:29 +00:00
|
|
|
const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
|
[lldb] s/FileSpec::Equal/FileSpec::Match
Summary:
The FileSpec class is often used as a sort of a pattern -- one specifies
a bare file name to search, and we check if in matches the full file
name of an existing module (for example).
These comparisons used FileSpec::Equal, which had some support for it
(via the full=false argument), but it was not a good fit for this job.
For one, it did a symmetric comparison, which makes sense for a function
called "equal", but not for typical searches (when searching for
"/foo/bar.so", we don't want to find a module whose name is just
"bar.so"). This resulted in patterns like:
if (FileSpec::Equal(pattern, file, pattern.GetDirectory()))
which would request a "full" match only if the pattern really contained
a directory. This worked, but the intended behavior was very unobvious.
On top of that, a lot of the code wanted to handle the case of an
"empty" pattern, and treat it as matching everything. This resulted in
conditions like:
if (pattern && !FileSpec::Equal(pattern, file, pattern.GetDirectory())
which are nearly impossible to decipher.
This patch introduces a FileSpec::Match function, which does exactly
what most of FileSpec::Equal callers want, an asymmetric match between a
"pattern" FileSpec and a an actual FileSpec. Empty paterns match
everything, filename-only patterns match only the filename component.
I've tried to update all callers of FileSpec::Equal to use a simpler
interface. Those that hardcoded full=true have been changed to use
operator==. Those passing full=pattern.GetDirectory() have been changed
to use FileSpec::Match.
There was also a handful of places which hardcoded full=false. I've
changed these to use FileSpec::Match too. This is a slight change in
semantics, but it does not look like that was ever intended, and it was
more likely a result of a misunderstanding of the "proper" way to use
FileSpec::Equal.
[In an ideal world a "FileSpec" and a "FileSpec pattern" would be two
different types, but given how widespread FileSpec is, it is unlikely
we'll get there in one go. This at least provides a good starting point
by centralizing all matching behavior.]
Reviewers: teemperor, JDevlieghere, jdoerfert
Subscribers: emaste, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D70851
2019-11-29 11:31:00 +01:00
|
|
|
if (!FileSpec::Match(platform_file_spec, GetPlatformFileSpec()))
|
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-02-26 05:51:37 +00:00
|
|
|
const ArchSpec &arch = module_ref.GetArchitecture();
|
|
|
|
|
if (arch.IsValid()) {
|
2012-12-13 22:07:14 +00:00
|
|
|
if (!m_arch.IsCompatibleMatch(arch))
|
2012-02-26 05:51:37 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-03-06 21:22:25 +00:00
|
|
|
ConstString object_name = module_ref.GetObjectName();
|
2012-02-26 05:51:37 +00:00
|
|
|
if (object_name) {
|
|
|
|
|
if (object_name != GetObjectName())
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-15 21:01:31 +00:00
|
|
|
bool Module::FindSourceFile(const FileSpec &orig_spec,
|
|
|
|
|
FileSpec &new_spec) const {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2021-06-29 14:59:12 -07:00
|
|
|
if (auto remapped = m_source_mappings.FindFile(orig_spec)) {
|
|
|
|
|
new_spec = *remapped;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2012-03-15 21:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-09 12:09:56 +01:00
|
|
|
llvm::Optional<std::string>
|
|
|
|
|
Module::RemapSourceFile(llvm::StringRef path) const {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2021-06-29 15:19:31 -07:00
|
|
|
if (auto remapped = m_source_mappings.RemapPath(path))
|
|
|
|
|
return remapped->GetPath();
|
|
|
|
|
return {};
|
2012-03-19 22:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-09 12:09:56 +01:00
|
|
|
void Module::RegisterXcodeSDK(llvm::StringRef sdk_name,
|
|
|
|
|
llvm::StringRef sysroot) {
|
2020-03-19 18:51:36 -07:00
|
|
|
XcodeSDK sdk(sdk_name.str());
|
2021-11-01 22:14:48 -07:00
|
|
|
llvm::StringRef sdk_path(HostInfo::GetXcodeSDKPath(sdk));
|
|
|
|
|
if (sdk_path.empty())
|
2020-03-19 18:51:36 -07:00
|
|
|
return;
|
2020-05-04 13:52:10 -07:00
|
|
|
// If the SDK changed for a previously registered source path, update it.
|
2020-03-19 18:51:36 -07:00
|
|
|
// This could happend with -fdebug-prefix-map, otherwise it's unlikely.
|
2021-11-01 22:14:48 -07:00
|
|
|
if (!m_source_mappings.Replace(sysroot, sdk_path, true))
|
2020-03-19 18:51:36 -07:00
|
|
|
// In the general case, however, append it to the list.
|
2021-11-01 22:14:48 -07:00
|
|
|
m_source_mappings.Append(sysroot, sdk_path, false);
|
2020-03-19 18:51:36 -07:00
|
|
|
}
|
|
|
|
|
|
2019-09-04 17:23:15 +00:00
|
|
|
bool Module::MergeArchitecture(const ArchSpec &arch_spec) {
|
|
|
|
|
if (!arch_spec.IsValid())
|
|
|
|
|
return false;
|
2022-01-31 15:57:48 +01:00
|
|
|
LLDB_LOGF(GetLog(LLDBLog::Object | LLDBLog::Modules),
|
2021-11-18 10:40:06 -08:00
|
|
|
"module has arch %s, merging/replacing with arch %s",
|
|
|
|
|
m_arch.GetTriple().getTriple().c_str(),
|
|
|
|
|
arch_spec.GetTriple().getTriple().c_str());
|
2019-09-04 17:23:15 +00:00
|
|
|
if (!m_arch.IsCompatibleMatch(arch_spec)) {
|
|
|
|
|
// The new architecture is different, we just need to replace it.
|
|
|
|
|
return SetArchitecture(arch_spec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Merge bits from arch_spec into "merged_arch" and set our architecture.
|
|
|
|
|
ArchSpec merged_arch(m_arch);
|
|
|
|
|
merged_arch.MergeFrom(arch_spec);
|
|
|
|
|
// SetArchitecture() is a no-op if m_arch is already valid.
|
|
|
|
|
m_arch = ArchSpec();
|
|
|
|
|
return SetArchitecture(merged_arch);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-18 15:02:23 +00:00
|
|
|
llvm::VersionTuple Module::GetVersion() {
|
|
|
|
|
if (ObjectFile *obj_file = GetObjectFile())
|
|
|
|
|
return obj_file->GetVersion();
|
|
|
|
|
return llvm::VersionTuple();
|
2012-09-04 18:47:54 +00:00
|
|
|
}
|
2013-04-03 02:00:15 +00:00
|
|
|
|
2015-02-05 02:01:34 +00:00
|
|
|
bool Module::GetIsDynamicLinkEditor() {
|
|
|
|
|
ObjectFile *obj_file = GetObjectFile();
|
|
|
|
|
|
|
|
|
|
if (obj_file)
|
|
|
|
|
return obj_file->GetIsDynamicLinkEditor();
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
Added the ability to cache the finalized symbol tables subsequent debug sessions to start faster.
This is an updated version of the https://reviews.llvm.org/D113789 patch with the following changes:
- We no longer modify modification times of the cache files
- Use LLVM caching and cache pruning instead of making a new cache mechanism (See DataFileCache.h/.cpp)
- Add signature to start of each file since we are not using modification times so we can tell when caches are stale and remove and re-create the cache file as files are changed
- Add settings to control the cache size, disk percentage and expiration in days to keep cache size under control
This patch enables symbol tables to be cached in the LLDB index cache directory. All cache files are in a single directory and the files use unique names to ensure that files from the same path will re-use the same file as files get modified. This means as files change, their cache files will be deleted and updated. The modification time of each of the cache files is not modified so that access based pruning of the cache can be implemented.
The symbol table cache files start with a signature that uniquely identifies a file on disk and contains one or more of the following items:
- object file UUID if available
- object file mod time if available
- object name for BSD archive .o files that are in .a files if available
If none of these signature items are available, then the file will not be cached. This keeps temporary object files from expressions from being cached.
When the cache files are loaded on subsequent debug sessions, the signature is compare and if the file has been modified (uuid changes, mod time changes, or object file mod time changes) then the cache file is deleted and re-created.
Module caching must be enabled by the user before this can be used:
symbols.enable-lldb-index-cache (boolean) = false
(lldb) settings set symbols.enable-lldb-index-cache true
There is also a setting that allows the user to specify a module cache directory that defaults to a directory that defaults to being next to the symbols.clang-modules-cache-path directory in a temp directory:
(lldb) settings show symbols.lldb-index-cache-path
/var/folders/9p/472sr0c55l9b20x2zg36b91h0000gn/C/lldb/IndexCache
If this setting is enabled, the finalized symbol tables will be serialized and saved to disc so they can be quickly loaded next time you debug.
Each module can cache one or more files in the index cache directory. The cache file names must be unique to a file on disk and its architecture and object name for .o files in BSD archives. This allows universal mach-o files to support caching multuple architectures in the same module cache directory. Making the file based on the this info allows this cache file to be deleted and replaced when the file gets updated on disk. This keeps the cache from growing over time during the compile/edit/debug cycle and prevents out of space issues.
If the cache is enabled, the symbol table will be loaded from the cache the next time you debug if the module has not changed.
The cache also has settings to control the size of the cache on disk. Each time LLDB starts up with the index cache enable, the cache will be pruned to ensure it stays within the user defined settings:
(lldb) settings set symbols.lldb-index-cache-expiration-days <days>
A value of zero will disable cache files from expiring when the cache is pruned. The default value is 7 currently.
(lldb) settings set symbols.lldb-index-cache-max-byte-size <size>
A value of zero will disable pruning based on a total byte size. The default value is zero currently.
(lldb) settings set symbols.lldb-index-cache-max-percent <percentage-of-disk-space>
A value of 100 will allow the disc to be filled to the max, a value of zero will disable percentage pruning. The default value is zero.
Reviewed By: labath, wallace
Differential Revision: https://reviews.llvm.org/D115324
2021-12-16 09:59:25 -08:00
|
|
|
|
|
|
|
|
uint32_t Module::Hash() {
|
|
|
|
|
std::string identifier;
|
|
|
|
|
llvm::raw_string_ostream id_strm(identifier);
|
|
|
|
|
id_strm << m_arch.GetTriple().str() << '-' << m_file.GetPath();
|
|
|
|
|
if (m_object_name)
|
|
|
|
|
id_strm << '(' << m_object_name.GetStringRef() << ')';
|
|
|
|
|
if (m_object_offset > 0)
|
|
|
|
|
id_strm << m_object_offset;
|
|
|
|
|
const auto mtime = llvm::sys::toTimeT(m_object_mod_time);
|
|
|
|
|
if (mtime > 0)
|
|
|
|
|
id_strm << mtime;
|
|
|
|
|
return llvm::djbHash(id_strm.str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Module::GetCacheKey() {
|
|
|
|
|
std::string key;
|
|
|
|
|
llvm::raw_string_ostream strm(key);
|
|
|
|
|
strm << m_arch.GetTriple().str() << '-' << m_file.GetFilename();
|
|
|
|
|
if (m_object_name)
|
|
|
|
|
strm << '(' << m_object_name.GetStringRef() << ')';
|
|
|
|
|
strm << '-' << llvm::format_hex(Hash(), 10);
|
|
|
|
|
return strm.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataFileCache *Module::GetIndexCache() {
|
|
|
|
|
if (!ModuleList::GetGlobalModuleListProperties().GetEnableLLDBIndexCache())
|
|
|
|
|
return nullptr;
|
|
|
|
|
// NOTE: intentional leak so we don't crash if global destructor chain gets
|
|
|
|
|
// called as other threads still use the result of this function
|
2022-04-20 07:30:53 -07:00
|
|
|
static DataFileCache *g_data_file_cache =
|
|
|
|
|
new DataFileCache(ModuleList::GetGlobalModuleListProperties()
|
|
|
|
|
.GetLLDBIndexCachePath()
|
|
|
|
|
.GetPath());
|
Added the ability to cache the finalized symbol tables subsequent debug sessions to start faster.
This is an updated version of the https://reviews.llvm.org/D113789 patch with the following changes:
- We no longer modify modification times of the cache files
- Use LLVM caching and cache pruning instead of making a new cache mechanism (See DataFileCache.h/.cpp)
- Add signature to start of each file since we are not using modification times so we can tell when caches are stale and remove and re-create the cache file as files are changed
- Add settings to control the cache size, disk percentage and expiration in days to keep cache size under control
This patch enables symbol tables to be cached in the LLDB index cache directory. All cache files are in a single directory and the files use unique names to ensure that files from the same path will re-use the same file as files get modified. This means as files change, their cache files will be deleted and updated. The modification time of each of the cache files is not modified so that access based pruning of the cache can be implemented.
The symbol table cache files start with a signature that uniquely identifies a file on disk and contains one or more of the following items:
- object file UUID if available
- object file mod time if available
- object name for BSD archive .o files that are in .a files if available
If none of these signature items are available, then the file will not be cached. This keeps temporary object files from expressions from being cached.
When the cache files are loaded on subsequent debug sessions, the signature is compare and if the file has been modified (uuid changes, mod time changes, or object file mod time changes) then the cache file is deleted and re-created.
Module caching must be enabled by the user before this can be used:
symbols.enable-lldb-index-cache (boolean) = false
(lldb) settings set symbols.enable-lldb-index-cache true
There is also a setting that allows the user to specify a module cache directory that defaults to a directory that defaults to being next to the symbols.clang-modules-cache-path directory in a temp directory:
(lldb) settings show symbols.lldb-index-cache-path
/var/folders/9p/472sr0c55l9b20x2zg36b91h0000gn/C/lldb/IndexCache
If this setting is enabled, the finalized symbol tables will be serialized and saved to disc so they can be quickly loaded next time you debug.
Each module can cache one or more files in the index cache directory. The cache file names must be unique to a file on disk and its architecture and object name for .o files in BSD archives. This allows universal mach-o files to support caching multuple architectures in the same module cache directory. Making the file based on the this info allows this cache file to be deleted and replaced when the file gets updated on disk. This keeps the cache from growing over time during the compile/edit/debug cycle and prevents out of space issues.
If the cache is enabled, the symbol table will be loaded from the cache the next time you debug if the module has not changed.
The cache also has settings to control the size of the cache on disk. Each time LLDB starts up with the index cache enable, the cache will be pruned to ensure it stays within the user defined settings:
(lldb) settings set symbols.lldb-index-cache-expiration-days <days>
A value of zero will disable cache files from expiring when the cache is pruned. The default value is 7 currently.
(lldb) settings set symbols.lldb-index-cache-max-byte-size <size>
A value of zero will disable pruning based on a total byte size. The default value is zero currently.
(lldb) settings set symbols.lldb-index-cache-max-percent <percentage-of-disk-space>
A value of 100 will allow the disc to be filled to the max, a value of zero will disable percentage pruning. The default value is zero.
Reviewed By: labath, wallace
Differential Revision: https://reviews.llvm.org/D115324
2021-12-16 09:59:25 -08:00
|
|
|
return g_data_file_cache;
|
|
|
|
|
}
|