16498aff2SJonas Devlieghere //===-- SWIG Interface for SBModule -----------------------------*- C++ -*-===//
26498aff2SJonas Devlieghere //
36498aff2SJonas Devlieghere // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
46498aff2SJonas Devlieghere // See https://llvm.org/LICENSE.txt for license information.
56498aff2SJonas Devlieghere // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66498aff2SJonas Devlieghere //
76498aff2SJonas Devlieghere //===----------------------------------------------------------------------===//
86498aff2SJonas Devlieghere 
96498aff2SJonas Devlieghere namespace lldb {
106498aff2SJonas Devlieghere 
116498aff2SJonas Devlieghere #ifdef SWIGPYTHON
126498aff2SJonas Devlieghere %pythoncode%{
136498aff2SJonas Devlieghere # ==================================
146498aff2SJonas Devlieghere # Helper function for SBModule class
156498aff2SJonas Devlieghere # ==================================
166498aff2SJonas Devlieghere def in_range(symbol, section):
176498aff2SJonas Devlieghere     """Test whether a symbol is within the range of a section."""
186498aff2SJonas Devlieghere     symSA = symbol.GetStartAddress().GetFileAddress()
196498aff2SJonas Devlieghere     symEA = symbol.GetEndAddress().GetFileAddress()
206498aff2SJonas Devlieghere     secSA = section.GetFileAddress()
216498aff2SJonas Devlieghere     secEA = secSA + section.GetByteSize()
226498aff2SJonas Devlieghere 
236498aff2SJonas Devlieghere     if symEA != LLDB_INVALID_ADDRESS:
246498aff2SJonas Devlieghere         if secSA <= symSA and symEA <= secEA:
256498aff2SJonas Devlieghere             return True
266498aff2SJonas Devlieghere         else:
276498aff2SJonas Devlieghere             return False
286498aff2SJonas Devlieghere     else:
296498aff2SJonas Devlieghere         if secSA <= symSA and symSA < secEA:
306498aff2SJonas Devlieghere             return True
316498aff2SJonas Devlieghere         else:
326498aff2SJonas Devlieghere             return False
336498aff2SJonas Devlieghere %}
346498aff2SJonas Devlieghere #endif
356498aff2SJonas Devlieghere 
366498aff2SJonas Devlieghere %feature("docstring",
376498aff2SJonas Devlieghere "Represents an executable image and its associated object and symbol files.
386498aff2SJonas Devlieghere 
396498aff2SJonas Devlieghere The module is designed to be able to select a single slice of an
406498aff2SJonas Devlieghere executable image as it would appear on disk and during program
416498aff2SJonas Devlieghere execution.
426498aff2SJonas Devlieghere 
434017c6feSRaphael Isemann You can retrieve SBModule from :py:class:`SBSymbolContext` , which in turn is available
446498aff2SJonas Devlieghere from SBFrame.
456498aff2SJonas Devlieghere 
464017c6feSRaphael Isemann SBModule supports symbol iteration, for example, ::
476498aff2SJonas Devlieghere 
486498aff2SJonas Devlieghere     for symbol in module:
496498aff2SJonas Devlieghere         name = symbol.GetName()
506498aff2SJonas Devlieghere         saddr = symbol.GetStartAddress()
516498aff2SJonas Devlieghere         eaddr = symbol.GetEndAddress()
526498aff2SJonas Devlieghere 
534017c6feSRaphael Isemann and rich comparison methods which allow the API program to use, ::
546498aff2SJonas Devlieghere 
556498aff2SJonas Devlieghere     if thisModule == thatModule:
566498aff2SJonas Devlieghere         print('This module is the same as that module')
576498aff2SJonas Devlieghere 
586498aff2SJonas Devlieghere to test module equality.  A module also contains object file sections, namely
594017c6feSRaphael Isemann :py:class:`SBSection` .  SBModule supports section iteration through section_iter(), for
604017c6feSRaphael Isemann example, ::
616498aff2SJonas Devlieghere 
626498aff2SJonas Devlieghere     print('Number of sections: %d' % module.GetNumSections())
636498aff2SJonas Devlieghere     for sec in module.section_iter():
646498aff2SJonas Devlieghere         print(sec)
656498aff2SJonas Devlieghere 
664017c6feSRaphael Isemann And to iterate the symbols within a SBSection, use symbol_in_section_iter(), ::
676498aff2SJonas Devlieghere 
686498aff2SJonas Devlieghere     # Iterates the text section and prints each symbols within each sub-section.
696498aff2SJonas Devlieghere     for subsec in text_sec:
706498aff2SJonas Devlieghere         print(INDENT + repr(subsec))
716498aff2SJonas Devlieghere         for sym in exe_module.symbol_in_section_iter(subsec):
726498aff2SJonas Devlieghere             print(INDENT2 + repr(sym))
736498aff2SJonas Devlieghere             print(INDENT2 + 'symbol type: %s' % symbol_type_to_str(sym.GetType()))
746498aff2SJonas Devlieghere 
754017c6feSRaphael Isemann produces this following output: ::
766498aff2SJonas Devlieghere 
776498aff2SJonas Devlieghere     [0x0000000100001780-0x0000000100001d5c) a.out.__TEXT.__text
786498aff2SJonas Devlieghere         id = {0x00000004}, name = 'mask_access(MaskAction, unsigned int)', range = [0x00000001000017c0-0x0000000100001870)
796498aff2SJonas Devlieghere         symbol type: code
806498aff2SJonas Devlieghere         id = {0x00000008}, name = 'thread_func(void*)', range = [0x0000000100001870-0x00000001000019b0)
816498aff2SJonas Devlieghere         symbol type: code
826498aff2SJonas Devlieghere         id = {0x0000000c}, name = 'main', range = [0x00000001000019b0-0x0000000100001d5c)
836498aff2SJonas Devlieghere         symbol type: code
846498aff2SJonas Devlieghere         id = {0x00000023}, name = 'start', address = 0x0000000100001780
856498aff2SJonas Devlieghere         symbol type: code
866498aff2SJonas Devlieghere     [0x0000000100001d5c-0x0000000100001da4) a.out.__TEXT.__stubs
876498aff2SJonas Devlieghere         id = {0x00000024}, name = '__stack_chk_fail', range = [0x0000000100001d5c-0x0000000100001d62)
886498aff2SJonas Devlieghere         symbol type: trampoline
896498aff2SJonas Devlieghere         id = {0x00000028}, name = 'exit', range = [0x0000000100001d62-0x0000000100001d68)
906498aff2SJonas Devlieghere         symbol type: trampoline
916498aff2SJonas Devlieghere         id = {0x00000029}, name = 'fflush', range = [0x0000000100001d68-0x0000000100001d6e)
926498aff2SJonas Devlieghere         symbol type: trampoline
936498aff2SJonas Devlieghere         id = {0x0000002a}, name = 'fgets', range = [0x0000000100001d6e-0x0000000100001d74)
946498aff2SJonas Devlieghere         symbol type: trampoline
956498aff2SJonas Devlieghere         id = {0x0000002b}, name = 'printf', range = [0x0000000100001d74-0x0000000100001d7a)
966498aff2SJonas Devlieghere         symbol type: trampoline
976498aff2SJonas Devlieghere         id = {0x0000002c}, name = 'pthread_create', range = [0x0000000100001d7a-0x0000000100001d80)
986498aff2SJonas Devlieghere         symbol type: trampoline
996498aff2SJonas Devlieghere         id = {0x0000002d}, name = 'pthread_join', range = [0x0000000100001d80-0x0000000100001d86)
1006498aff2SJonas Devlieghere         symbol type: trampoline
1016498aff2SJonas Devlieghere         id = {0x0000002e}, name = 'pthread_mutex_lock', range = [0x0000000100001d86-0x0000000100001d8c)
1026498aff2SJonas Devlieghere         symbol type: trampoline
1036498aff2SJonas Devlieghere         id = {0x0000002f}, name = 'pthread_mutex_unlock', range = [0x0000000100001d8c-0x0000000100001d92)
1046498aff2SJonas Devlieghere         symbol type: trampoline
1056498aff2SJonas Devlieghere         id = {0x00000030}, name = 'rand', range = [0x0000000100001d92-0x0000000100001d98)
1066498aff2SJonas Devlieghere         symbol type: trampoline
1076498aff2SJonas Devlieghere         id = {0x00000031}, name = 'strtoul', range = [0x0000000100001d98-0x0000000100001d9e)
1086498aff2SJonas Devlieghere         symbol type: trampoline
1096498aff2SJonas Devlieghere         id = {0x00000032}, name = 'usleep', range = [0x0000000100001d9e-0x0000000100001da4)
1106498aff2SJonas Devlieghere         symbol type: trampoline
1116498aff2SJonas Devlieghere     [0x0000000100001da4-0x0000000100001e2c) a.out.__TEXT.__stub_helper
1126498aff2SJonas Devlieghere     [0x0000000100001e2c-0x0000000100001f10) a.out.__TEXT.__cstring
1136498aff2SJonas Devlieghere     [0x0000000100001f10-0x0000000100001f68) a.out.__TEXT.__unwind_info
1146498aff2SJonas Devlieghere     [0x0000000100001f68-0x0000000100001ff8) a.out.__TEXT.__eh_frame
1156498aff2SJonas Devlieghere "
1166498aff2SJonas Devlieghere ) SBModule;
1176498aff2SJonas Devlieghere class SBModule
1186498aff2SJonas Devlieghere {
1196498aff2SJonas Devlieghere public:
1206498aff2SJonas Devlieghere 
1216498aff2SJonas Devlieghere     SBModule ();
1226498aff2SJonas Devlieghere 
1236498aff2SJonas Devlieghere     SBModule (const lldb::SBModule &rhs);
1246498aff2SJonas Devlieghere 
1256498aff2SJonas Devlieghere     SBModule (const lldb::SBModuleSpec &module_spec);
1266498aff2SJonas Devlieghere 
1276498aff2SJonas Devlieghere     SBModule (lldb::SBProcess &process,
1286498aff2SJonas Devlieghere               lldb::addr_t header_addr);
1296498aff2SJonas Devlieghere 
1306498aff2SJonas Devlieghere     ~SBModule ();
1316498aff2SJonas Devlieghere 
1326498aff2SJonas Devlieghere     bool
1336498aff2SJonas Devlieghere     IsValid () const;
1346498aff2SJonas Devlieghere 
1356498aff2SJonas Devlieghere     explicit operator bool() const;
1366498aff2SJonas Devlieghere 
1376498aff2SJonas Devlieghere     void
1386498aff2SJonas Devlieghere     Clear();
1396498aff2SJonas Devlieghere 
140*ff52ef33SMed Ismail Bennani     %feature("docstring", "Check if the module is file backed.
141*ff52ef33SMed Ismail Bennani     @return
142*ff52ef33SMed Ismail Bennani         True, if the module is backed by an object file on disk.
143*ff52ef33SMed Ismail Bennani         False, if the module is backed by an object file in memory.") IsFileBacked;
144*ff52ef33SMed Ismail Bennani     bool
145*ff52ef33SMed Ismail Bennani     IsFileBacked() const;
146*ff52ef33SMed Ismail Bennani 
1476498aff2SJonas Devlieghere     %feature("docstring", "
1486498aff2SJonas Devlieghere     Get const accessor for the module file specification.
1496498aff2SJonas Devlieghere 
1506498aff2SJonas Devlieghere     This function returns the file for the module on the host system
1516498aff2SJonas Devlieghere     that is running LLDB. This can differ from the path on the
1526498aff2SJonas Devlieghere     platform since we might be doing remote debugging.
1536498aff2SJonas Devlieghere 
1546498aff2SJonas Devlieghere     @return
1556498aff2SJonas Devlieghere         A const reference to the file specification object.") GetFileSpec;
1566498aff2SJonas Devlieghere     lldb::SBFileSpec
1576498aff2SJonas Devlieghere     GetFileSpec () const;
1586498aff2SJonas Devlieghere 
1596498aff2SJonas Devlieghere     %feature("docstring", "
1606498aff2SJonas Devlieghere     Get accessor for the module platform file specification.
1616498aff2SJonas Devlieghere 
1626498aff2SJonas Devlieghere     Platform file refers to the path of the module as it is known on
1636498aff2SJonas Devlieghere     the remote system on which it is being debugged. For local
1646498aff2SJonas Devlieghere     debugging this is always the same as Module::GetFileSpec(). But
1656498aff2SJonas Devlieghere     remote debugging might mention a file '/usr/lib/liba.dylib'
1666498aff2SJonas Devlieghere     which might be locally downloaded and cached. In this case the
1676498aff2SJonas Devlieghere     platform file could be something like:
1686498aff2SJonas Devlieghere     '/tmp/lldb/platform-cache/remote.host.computer/usr/lib/liba.dylib'
1696498aff2SJonas Devlieghere     The file could also be cached in a local developer kit directory.
1706498aff2SJonas Devlieghere 
1716498aff2SJonas Devlieghere     @return
1726498aff2SJonas Devlieghere         A const reference to the file specification object.") GetPlatformFileSpec;
1736498aff2SJonas Devlieghere     lldb::SBFileSpec
1746498aff2SJonas Devlieghere     GetPlatformFileSpec () const;
1756498aff2SJonas Devlieghere 
1766498aff2SJonas Devlieghere     bool
1776498aff2SJonas Devlieghere     SetPlatformFileSpec (const lldb::SBFileSpec &platform_file);
1786498aff2SJonas Devlieghere 
1796498aff2SJonas Devlieghere     lldb::SBFileSpec
1806498aff2SJonas Devlieghere     GetRemoteInstallFileSpec ();
1816498aff2SJonas Devlieghere 
1826498aff2SJonas Devlieghere     bool
1836498aff2SJonas Devlieghere     SetRemoteInstallFileSpec (lldb::SBFileSpec &file);
1846498aff2SJonas Devlieghere 
1856498aff2SJonas Devlieghere     %feature("docstring", "Returns the UUID of the module as a Python string."
1866498aff2SJonas Devlieghere     ) GetUUIDString;
1876498aff2SJonas Devlieghere     const char *
1886498aff2SJonas Devlieghere     GetUUIDString () const;
1896498aff2SJonas Devlieghere 
1906498aff2SJonas Devlieghere     bool operator==(const lldb::SBModule &rhs) const;
1916498aff2SJonas Devlieghere 
1926498aff2SJonas Devlieghere     bool operator!=(const lldb::SBModule &rhs) const;
1936498aff2SJonas Devlieghere 
1946498aff2SJonas Devlieghere     lldb::SBSection
1956498aff2SJonas Devlieghere     FindSection (const char *sect_name);
1966498aff2SJonas Devlieghere 
1976498aff2SJonas Devlieghere     lldb::SBAddress
1986498aff2SJonas Devlieghere     ResolveFileAddress (lldb::addr_t vm_addr);
1996498aff2SJonas Devlieghere 
2006498aff2SJonas Devlieghere     lldb::SBSymbolContext
2016498aff2SJonas Devlieghere     ResolveSymbolContextForAddress (const lldb::SBAddress& addr,
2026498aff2SJonas Devlieghere                                     uint32_t resolve_scope);
2036498aff2SJonas Devlieghere 
2046498aff2SJonas Devlieghere     bool
2056498aff2SJonas Devlieghere     GetDescription (lldb::SBStream &description);
2066498aff2SJonas Devlieghere 
2076498aff2SJonas Devlieghere     uint32_t
2086498aff2SJonas Devlieghere     GetNumCompileUnits();
2096498aff2SJonas Devlieghere 
2106498aff2SJonas Devlieghere     lldb::SBCompileUnit
2116498aff2SJonas Devlieghere     GetCompileUnitAtIndex (uint32_t);
2126498aff2SJonas Devlieghere 
2136498aff2SJonas Devlieghere     %feature("docstring", "
214f446fc5aSRaphael Isemann     Find compile units related to this module and passed source
2156498aff2SJonas Devlieghere     file.
2166498aff2SJonas Devlieghere 
2176498aff2SJonas Devlieghere     @param[in] sb_file_spec
218f446fc5aSRaphael Isemann         A :py:class:`SBFileSpec` object that contains source file
2196498aff2SJonas Devlieghere         specification.
2206498aff2SJonas Devlieghere 
2216498aff2SJonas Devlieghere     @return
222f446fc5aSRaphael Isemann         A :py:class:`SBSymbolContextList` that gets filled in with all of
2236498aff2SJonas Devlieghere         the symbol contexts for all the matches.") FindCompileUnits;
2246498aff2SJonas Devlieghere     lldb::SBSymbolContextList
2256498aff2SJonas Devlieghere     FindCompileUnits (const lldb::SBFileSpec &sb_file_spec);
2266498aff2SJonas Devlieghere 
2276498aff2SJonas Devlieghere     size_t
2286498aff2SJonas Devlieghere     GetNumSymbols ();
2296498aff2SJonas Devlieghere 
2306498aff2SJonas Devlieghere     lldb::SBSymbol
2316498aff2SJonas Devlieghere     GetSymbolAtIndex (size_t idx);
2326498aff2SJonas Devlieghere 
2336498aff2SJonas Devlieghere     lldb::SBSymbol
2346498aff2SJonas Devlieghere     FindSymbol (const char *name,
2356498aff2SJonas Devlieghere                 lldb::SymbolType type = eSymbolTypeAny);
2366498aff2SJonas Devlieghere 
2376498aff2SJonas Devlieghere     lldb::SBSymbolContextList
2386498aff2SJonas Devlieghere     FindSymbols (const char *name,
2396498aff2SJonas Devlieghere                  lldb::SymbolType type = eSymbolTypeAny);
2406498aff2SJonas Devlieghere 
2416498aff2SJonas Devlieghere 
2426498aff2SJonas Devlieghere     size_t
2436498aff2SJonas Devlieghere     GetNumSections ();
2446498aff2SJonas Devlieghere 
2456498aff2SJonas Devlieghere     lldb::SBSection
2466498aff2SJonas Devlieghere     GetSectionAtIndex (size_t idx);
2476498aff2SJonas Devlieghere 
2486498aff2SJonas Devlieghere 
2496498aff2SJonas Devlieghere     %feature("docstring", "
2506498aff2SJonas Devlieghere     Find functions by name.
2516498aff2SJonas Devlieghere 
2526498aff2SJonas Devlieghere     @param[in] name
2536498aff2SJonas Devlieghere         The name of the function we are looking for.
2546498aff2SJonas Devlieghere 
2556498aff2SJonas Devlieghere     @param[in] name_type_mask
2566498aff2SJonas Devlieghere         A logical OR of one or more FunctionNameType enum bits that
2576498aff2SJonas Devlieghere         indicate what kind of names should be used when doing the
2586498aff2SJonas Devlieghere         lookup. Bits include fully qualified names, base names,
2596498aff2SJonas Devlieghere         C++ methods, or ObjC selectors.
2606498aff2SJonas Devlieghere         See FunctionNameType for more details.
2616498aff2SJonas Devlieghere 
2626498aff2SJonas Devlieghere     @return
2636498aff2SJonas Devlieghere         A symbol context list that gets filled in with all of the
2646498aff2SJonas Devlieghere         matches.") FindFunctions;
2656498aff2SJonas Devlieghere     lldb::SBSymbolContextList
2666498aff2SJonas Devlieghere     FindFunctions (const char *name,
2676498aff2SJonas Devlieghere                    uint32_t name_type_mask = lldb::eFunctionNameTypeAny);
2686498aff2SJonas Devlieghere 
2696498aff2SJonas Devlieghere     lldb::SBType
2706498aff2SJonas Devlieghere     FindFirstType (const char* name);
2716498aff2SJonas Devlieghere 
2726498aff2SJonas Devlieghere     lldb::SBTypeList
2736498aff2SJonas Devlieghere     FindTypes (const char* type);
2746498aff2SJonas Devlieghere 
2756498aff2SJonas Devlieghere     lldb::SBType
2766498aff2SJonas Devlieghere     GetTypeByID (lldb::user_id_t uid);
2776498aff2SJonas Devlieghere 
2786498aff2SJonas Devlieghere     lldb::SBType
2796498aff2SJonas Devlieghere     GetBasicType(lldb::BasicType type);
2806498aff2SJonas Devlieghere 
2816498aff2SJonas Devlieghere     %feature("docstring", "
2826498aff2SJonas Devlieghere     Get all types matching type_mask from debug info in this
2836498aff2SJonas Devlieghere     module.
2846498aff2SJonas Devlieghere 
2856498aff2SJonas Devlieghere     @param[in] type_mask
2866498aff2SJonas Devlieghere         A bitfield that consists of one or more bits logically OR'ed
2876498aff2SJonas Devlieghere         together from the lldb::TypeClass enumeration. This allows
2886498aff2SJonas Devlieghere         you to request only structure types, or only class, struct
2896498aff2SJonas Devlieghere         and union types. Passing in lldb::eTypeClassAny will return
2906498aff2SJonas Devlieghere         all types found in the debug information for this module.
2916498aff2SJonas Devlieghere 
2926498aff2SJonas Devlieghere     @return
2936498aff2SJonas Devlieghere         A list of types in this module that match type_mask") GetTypes;
2946498aff2SJonas Devlieghere     lldb::SBTypeList
2956498aff2SJonas Devlieghere     GetTypes (uint32_t type_mask = lldb::eTypeClassAny);
2966498aff2SJonas Devlieghere 
2976498aff2SJonas Devlieghere     %feature("docstring", "
2986498aff2SJonas Devlieghere     Find global and static variables by name.
2996498aff2SJonas Devlieghere 
3006498aff2SJonas Devlieghere     @param[in] target
3016498aff2SJonas Devlieghere         A valid SBTarget instance representing the debuggee.
3026498aff2SJonas Devlieghere 
3036498aff2SJonas Devlieghere     @param[in] name
3046498aff2SJonas Devlieghere         The name of the global or static variable we are looking
3056498aff2SJonas Devlieghere         for.
3066498aff2SJonas Devlieghere 
3076498aff2SJonas Devlieghere     @param[in] max_matches
3086498aff2SJonas Devlieghere         Allow the number of matches to be limited to max_matches.
3096498aff2SJonas Devlieghere 
3106498aff2SJonas Devlieghere     @return
3116498aff2SJonas Devlieghere         A list of matched variables in an SBValueList.") FindGlobalVariables;
3126498aff2SJonas Devlieghere     lldb::SBValueList
3136498aff2SJonas Devlieghere     FindGlobalVariables (lldb::SBTarget &target,
3146498aff2SJonas Devlieghere                          const char *name,
3156498aff2SJonas Devlieghere                          uint32_t max_matches);
3166498aff2SJonas Devlieghere 
3176498aff2SJonas Devlieghere     %feature("docstring", "
3186498aff2SJonas Devlieghere     Find the first global (or static) variable by name.
3196498aff2SJonas Devlieghere 
3206498aff2SJonas Devlieghere     @param[in] target
3216498aff2SJonas Devlieghere         A valid SBTarget instance representing the debuggee.
3226498aff2SJonas Devlieghere 
3236498aff2SJonas Devlieghere     @param[in] name
3246498aff2SJonas Devlieghere         The name of the global or static variable we are looking
3256498aff2SJonas Devlieghere         for.
3266498aff2SJonas Devlieghere 
3276498aff2SJonas Devlieghere     @return
3286498aff2SJonas Devlieghere         An SBValue that gets filled in with the found variable (if any).") FindFirstGlobalVariable;
3296498aff2SJonas Devlieghere     lldb::SBValue
3306498aff2SJonas Devlieghere     FindFirstGlobalVariable (lldb::SBTarget &target, const char *name);
3316498aff2SJonas Devlieghere 
3326498aff2SJonas Devlieghere     lldb::ByteOrder
3336498aff2SJonas Devlieghere     GetByteOrder ();
3346498aff2SJonas Devlieghere 
3356498aff2SJonas Devlieghere     uint32_t
3366498aff2SJonas Devlieghere     GetAddressByteSize();
3376498aff2SJonas Devlieghere 
3386498aff2SJonas Devlieghere     const char *
3396498aff2SJonas Devlieghere     GetTriple ();
3406498aff2SJonas Devlieghere 
3416498aff2SJonas Devlieghere     uint32_t
3426498aff2SJonas Devlieghere     GetVersion (uint32_t *versions,
3436498aff2SJonas Devlieghere                 uint32_t num_versions);
3446498aff2SJonas Devlieghere 
3456498aff2SJonas Devlieghere     lldb::SBFileSpec
3466498aff2SJonas Devlieghere     GetSymbolFileSpec() const;
3476498aff2SJonas Devlieghere 
3486498aff2SJonas Devlieghere     lldb::SBAddress
3496498aff2SJonas Devlieghere     GetObjectFileHeaderAddress() const;
3506498aff2SJonas Devlieghere 
3516498aff2SJonas Devlieghere     lldb::SBAddress
3526498aff2SJonas Devlieghere     GetObjectFileEntryPointAddress() const;
3536498aff2SJonas Devlieghere 
354da601ea7SJonas Devlieghere     %feature("docstring", "
355da601ea7SJonas Devlieghere     Returns the number of modules in the module cache. This is an
356da601ea7SJonas Devlieghere     implementation detail exposed for testing and should not be relied upon.
357da601ea7SJonas Devlieghere 
358da601ea7SJonas Devlieghere     @return
359da601ea7SJonas Devlieghere         The number of modules in the module cache.") GetNumberAllocatedModules;
360da601ea7SJonas Devlieghere     static uint32_t
361da601ea7SJonas Devlieghere     GetNumberAllocatedModules();
362da601ea7SJonas Devlieghere 
363c2f9454aSRaphael Isemann     %feature("docstring", "
364c2f9454aSRaphael Isemann     Removes all modules which are no longer needed by any part of LLDB from
365c2f9454aSRaphael Isemann     the module cache.
366c2f9454aSRaphael Isemann 
367c2f9454aSRaphael Isemann     This is an implementation detail exposed for testing and should not be
368c2f9454aSRaphael Isemann     relied upon. Use SBDebugger::MemoryPressureDetected instead to reduce
369c2f9454aSRaphael Isemann     LLDB's memory consumption during execution.
370c2f9454aSRaphael Isemann     ") GarbageCollectAllocatedModules;
371c2f9454aSRaphael Isemann     static void
372c2f9454aSRaphael Isemann     GarbageCollectAllocatedModules();
373c2f9454aSRaphael Isemann 
3746498aff2SJonas Devlieghere     STRING_EXTENSION(SBModule)
3756498aff2SJonas Devlieghere 
3766498aff2SJonas Devlieghere #ifdef SWIGPYTHON
3776498aff2SJonas Devlieghere     %pythoncode %{
3786498aff2SJonas Devlieghere         def __len__(self):
3796498aff2SJonas Devlieghere             '''Return the number of symbols in a lldb.SBModule object.'''
3806498aff2SJonas Devlieghere             return self.GetNumSymbols()
3816498aff2SJonas Devlieghere 
3826498aff2SJonas Devlieghere         def __iter__(self):
3836498aff2SJonas Devlieghere             '''Iterate over all symbols in a lldb.SBModule object.'''
3846498aff2SJonas Devlieghere             return lldb_iter(self, 'GetNumSymbols', 'GetSymbolAtIndex')
3856498aff2SJonas Devlieghere 
3866498aff2SJonas Devlieghere         def section_iter(self):
3876498aff2SJonas Devlieghere             '''Iterate over all sections in a lldb.SBModule object.'''
3886498aff2SJonas Devlieghere             return lldb_iter(self, 'GetNumSections', 'GetSectionAtIndex')
3896498aff2SJonas Devlieghere 
3906498aff2SJonas Devlieghere         def compile_unit_iter(self):
3916498aff2SJonas Devlieghere             '''Iterate over all compile units in a lldb.SBModule object.'''
3926498aff2SJonas Devlieghere             return lldb_iter(self, 'GetNumCompileUnits', 'GetCompileUnitAtIndex')
3936498aff2SJonas Devlieghere 
3946498aff2SJonas Devlieghere         def symbol_in_section_iter(self, section):
3956498aff2SJonas Devlieghere             '''Given a module and its contained section, returns an iterator on the
3966498aff2SJonas Devlieghere             symbols within the section.'''
3976498aff2SJonas Devlieghere             for sym in self:
3986498aff2SJonas Devlieghere                 if in_range(sym, section):
3996498aff2SJonas Devlieghere                     yield sym
4006498aff2SJonas Devlieghere 
4016498aff2SJonas Devlieghere         class symbols_access(object):
4026498aff2SJonas Devlieghere             re_compile_type = type(re.compile('.'))
4036498aff2SJonas Devlieghere             '''A helper object that will lazily hand out lldb.SBSymbol objects for a module when supplied an index, name, or regular expression.'''
4046498aff2SJonas Devlieghere             def __init__(self, sbmodule):
4056498aff2SJonas Devlieghere                 self.sbmodule = sbmodule
4066498aff2SJonas Devlieghere 
4076498aff2SJonas Devlieghere             def __len__(self):
4086498aff2SJonas Devlieghere                 if self.sbmodule:
4096498aff2SJonas Devlieghere                     return int(self.sbmodule.GetNumSymbols())
4106498aff2SJonas Devlieghere                 return 0
4116498aff2SJonas Devlieghere 
4126498aff2SJonas Devlieghere             def __getitem__(self, key):
4136498aff2SJonas Devlieghere                 count = len(self)
4146498aff2SJonas Devlieghere                 if type(key) is int:
4156498aff2SJonas Devlieghere                     if key < count:
4166498aff2SJonas Devlieghere                         return self.sbmodule.GetSymbolAtIndex(key)
4176498aff2SJonas Devlieghere                 elif type(key) is str:
4186498aff2SJonas Devlieghere                     matches = []
4196498aff2SJonas Devlieghere                     sc_list = self.sbmodule.FindSymbols(key)
4206498aff2SJonas Devlieghere                     for sc in sc_list:
4216498aff2SJonas Devlieghere                         symbol = sc.symbol
4226498aff2SJonas Devlieghere                         if symbol:
4236498aff2SJonas Devlieghere                             matches.append(symbol)
4246498aff2SJonas Devlieghere                     return matches
4256498aff2SJonas Devlieghere                 elif isinstance(key, self.re_compile_type):
4266498aff2SJonas Devlieghere                     matches = []
4276498aff2SJonas Devlieghere                     for idx in range(count):
4286498aff2SJonas Devlieghere                         symbol = self.sbmodule.GetSymbolAtIndex(idx)
4296498aff2SJonas Devlieghere                         added = False
4306498aff2SJonas Devlieghere                         name = symbol.name
4316498aff2SJonas Devlieghere                         if name:
4326498aff2SJonas Devlieghere                             re_match = key.search(name)
4336498aff2SJonas Devlieghere                             if re_match:
4346498aff2SJonas Devlieghere                                 matches.append(symbol)
4356498aff2SJonas Devlieghere                                 added = True
4366498aff2SJonas Devlieghere                         if not added:
4376498aff2SJonas Devlieghere                             mangled = symbol.mangled
4386498aff2SJonas Devlieghere                             if mangled:
4396498aff2SJonas Devlieghere                                 re_match = key.search(mangled)
4406498aff2SJonas Devlieghere                                 if re_match:
4416498aff2SJonas Devlieghere                                     matches.append(symbol)
4426498aff2SJonas Devlieghere                     return matches
4436498aff2SJonas Devlieghere                 else:
4446498aff2SJonas Devlieghere                     print("error: unsupported item type: %s" % type(key))
4456498aff2SJonas Devlieghere                 return None
4466498aff2SJonas Devlieghere 
4476498aff2SJonas Devlieghere         def get_symbols_access_object(self):
4486498aff2SJonas Devlieghere             '''An accessor function that returns a symbols_access() object which allows lazy symbol access from a lldb.SBModule object.'''
4496498aff2SJonas Devlieghere             return self.symbols_access (self)
4506498aff2SJonas Devlieghere 
4516498aff2SJonas Devlieghere         def get_compile_units_access_object (self):
4526498aff2SJonas Devlieghere             '''An accessor function that returns a compile_units_access() object which allows lazy compile unit access from a lldb.SBModule object.'''
4536498aff2SJonas Devlieghere             return self.compile_units_access (self)
4546498aff2SJonas Devlieghere 
4556498aff2SJonas Devlieghere         def get_symbols_array(self):
4566498aff2SJonas Devlieghere             '''An accessor function that returns a list() that contains all symbols in a lldb.SBModule object.'''
4576498aff2SJonas Devlieghere             symbols = []
4586498aff2SJonas Devlieghere             for idx in range(self.num_symbols):
4596498aff2SJonas Devlieghere                 symbols.append(self.GetSymbolAtIndex(idx))
4606498aff2SJonas Devlieghere             return symbols
4616498aff2SJonas Devlieghere 
4626498aff2SJonas Devlieghere         class sections_access(object):
4636498aff2SJonas Devlieghere             re_compile_type = type(re.compile('.'))
4646498aff2SJonas Devlieghere             '''A helper object that will lazily hand out lldb.SBSection objects for a module when supplied an index, name, or regular expression.'''
4656498aff2SJonas Devlieghere             def __init__(self, sbmodule):
4666498aff2SJonas Devlieghere                 self.sbmodule = sbmodule
4676498aff2SJonas Devlieghere 
4686498aff2SJonas Devlieghere             def __len__(self):
4696498aff2SJonas Devlieghere                 if self.sbmodule:
4706498aff2SJonas Devlieghere                     return int(self.sbmodule.GetNumSections())
4716498aff2SJonas Devlieghere                 return 0
4726498aff2SJonas Devlieghere 
4736498aff2SJonas Devlieghere             def __getitem__(self, key):
4746498aff2SJonas Devlieghere                 count = len(self)
4756498aff2SJonas Devlieghere                 if type(key) is int:
4766498aff2SJonas Devlieghere                     if key < count:
4776498aff2SJonas Devlieghere                         return self.sbmodule.GetSectionAtIndex(key)
4786498aff2SJonas Devlieghere                 elif type(key) is str:
4796498aff2SJonas Devlieghere                     for idx in range(count):
4806498aff2SJonas Devlieghere                         section = self.sbmodule.GetSectionAtIndex(idx)
4816498aff2SJonas Devlieghere                         if section.name == key:
4826498aff2SJonas Devlieghere                             return section
4836498aff2SJonas Devlieghere                 elif isinstance(key, self.re_compile_type):
4846498aff2SJonas Devlieghere                     matches = []
4856498aff2SJonas Devlieghere                     for idx in range(count):
4866498aff2SJonas Devlieghere                         section = self.sbmodule.GetSectionAtIndex(idx)
4876498aff2SJonas Devlieghere                         name = section.name
4886498aff2SJonas Devlieghere                         if name:
4896498aff2SJonas Devlieghere                             re_match = key.search(name)
4906498aff2SJonas Devlieghere                             if re_match:
4916498aff2SJonas Devlieghere                                 matches.append(section)
4926498aff2SJonas Devlieghere                     return matches
4936498aff2SJonas Devlieghere                 else:
4946498aff2SJonas Devlieghere                     print("error: unsupported item type: %s" % type(key))
4956498aff2SJonas Devlieghere                 return None
4966498aff2SJonas Devlieghere 
4976498aff2SJonas Devlieghere         class compile_units_access(object):
4986498aff2SJonas Devlieghere             re_compile_type = type(re.compile('.'))
4996498aff2SJonas Devlieghere             '''A helper object that will lazily hand out lldb.SBCompileUnit objects for a module when supplied an index, full or partial path, or regular expression.'''
5006498aff2SJonas Devlieghere             def __init__(self, sbmodule):
5016498aff2SJonas Devlieghere                 self.sbmodule = sbmodule
5026498aff2SJonas Devlieghere 
5036498aff2SJonas Devlieghere             def __len__(self):
5046498aff2SJonas Devlieghere                 if self.sbmodule:
5056498aff2SJonas Devlieghere                     return int(self.sbmodule.GetNumCompileUnits())
5066498aff2SJonas Devlieghere                 return 0
5076498aff2SJonas Devlieghere 
5086498aff2SJonas Devlieghere             def __getitem__(self, key):
5096498aff2SJonas Devlieghere                 count = len(self)
5106498aff2SJonas Devlieghere                 if type(key) is int:
5116498aff2SJonas Devlieghere                     if key < count:
5126498aff2SJonas Devlieghere                         return self.sbmodule.GetCompileUnitAtIndex(key)
5136498aff2SJonas Devlieghere                 elif type(key) is str:
5146498aff2SJonas Devlieghere                     is_full_path = key[0] == '/'
5156498aff2SJonas Devlieghere                     for idx in range(count):
5166498aff2SJonas Devlieghere                         comp_unit = self.sbmodule.GetCompileUnitAtIndex(idx)
5176498aff2SJonas Devlieghere                         if is_full_path:
5186498aff2SJonas Devlieghere                             if comp_unit.file.fullpath == key:
5196498aff2SJonas Devlieghere                                 return comp_unit
5206498aff2SJonas Devlieghere                         else:
5216498aff2SJonas Devlieghere                             if comp_unit.file.basename == key:
5226498aff2SJonas Devlieghere                                 return comp_unit
5236498aff2SJonas Devlieghere                 elif isinstance(key, self.re_compile_type):
5246498aff2SJonas Devlieghere                     matches = []
5256498aff2SJonas Devlieghere                     for idx in range(count):
5266498aff2SJonas Devlieghere                         comp_unit = self.sbmodule.GetCompileUnitAtIndex(idx)
5276498aff2SJonas Devlieghere                         fullpath = comp_unit.file.fullpath
5286498aff2SJonas Devlieghere                         if fullpath:
5296498aff2SJonas Devlieghere                             re_match = key.search(fullpath)
5306498aff2SJonas Devlieghere                             if re_match:
5316498aff2SJonas Devlieghere                                 matches.append(comp_unit)
5326498aff2SJonas Devlieghere                     return matches
5336498aff2SJonas Devlieghere                 else:
5346498aff2SJonas Devlieghere                     print("error: unsupported item type: %s" % type(key))
5356498aff2SJonas Devlieghere                 return None
5366498aff2SJonas Devlieghere 
5376498aff2SJonas Devlieghere         def get_sections_access_object(self):
5386498aff2SJonas Devlieghere             '''An accessor function that returns a sections_access() object which allows lazy section array access.'''
5396498aff2SJonas Devlieghere             return self.sections_access (self)
5406498aff2SJonas Devlieghere 
5416498aff2SJonas Devlieghere         def get_sections_array(self):
5426498aff2SJonas Devlieghere             '''An accessor function that returns an array object that contains all sections in this module object.'''
5436498aff2SJonas Devlieghere             if not hasattr(self, 'sections_array'):
5446498aff2SJonas Devlieghere                 self.sections_array = []
5456498aff2SJonas Devlieghere                 for idx in range(self.num_sections):
5466498aff2SJonas Devlieghere                     self.sections_array.append(self.GetSectionAtIndex(idx))
5476498aff2SJonas Devlieghere             return self.sections_array
5486498aff2SJonas Devlieghere 
5496498aff2SJonas Devlieghere         def get_compile_units_array(self):
5506498aff2SJonas Devlieghere             '''An accessor function that returns an array object that contains all compile_units in this module object.'''
5516498aff2SJonas Devlieghere             if not hasattr(self, 'compile_units_array'):
5526498aff2SJonas Devlieghere                 self.compile_units_array = []
5536498aff2SJonas Devlieghere                 for idx in range(self.GetNumCompileUnits()):
5546498aff2SJonas Devlieghere                     self.compile_units_array.append(self.GetCompileUnitAtIndex(idx))
5556498aff2SJonas Devlieghere             return self.compile_units_array
5566498aff2SJonas Devlieghere 
5576498aff2SJonas Devlieghere         symbols = property(get_symbols_array, None, doc='''A read only property that returns a list() of lldb.SBSymbol objects contained in this module.''')
5586498aff2SJonas Devlieghere         symbol = property(get_symbols_access_object, None, doc='''A read only property that can be used to access symbols by index ("symbol = module.symbol[0]"), name ("symbols = module.symbol['main']"), or using a regular expression ("symbols = module.symbol[re.compile(...)]"). The return value is a single lldb.SBSymbol object for array access, and a list() of lldb.SBSymbol objects for name and regular expression access''')
5596498aff2SJonas Devlieghere         sections = property(get_sections_array, None, doc='''A read only property that returns a list() of lldb.SBSection objects contained in this module.''')
5606498aff2SJonas Devlieghere         compile_units = property(get_compile_units_array, None, doc='''A read only property that returns a list() of lldb.SBCompileUnit objects contained in this module.''')
5616498aff2SJonas Devlieghere         section = property(get_sections_access_object, None, doc='''A read only property that can be used to access symbols by index ("section = module.section[0]"), name ("sections = module.section[\'main\']"), or using a regular expression ("sections = module.section[re.compile(...)]"). The return value is a single lldb.SBSection object for array access, and a list() of lldb.SBSection objects for name and regular expression access''')
5626498aff2SJonas Devlieghere         section = property(get_sections_access_object, None, doc='''A read only property that can be used to access compile units by index ("compile_unit = module.compile_unit[0]"), name ("compile_unit = module.compile_unit[\'main.cpp\']"), or using a regular expression ("compile_unit = module.compile_unit[re.compile(...)]"). The return value is a single lldb.SBCompileUnit object for array access or by full or partial path, and a list() of lldb.SBCompileUnit objects regular expressions.''')
5636498aff2SJonas Devlieghere 
5646498aff2SJonas Devlieghere         def get_uuid(self):
5656498aff2SJonas Devlieghere             return uuid.UUID (self.GetUUIDString())
5666498aff2SJonas Devlieghere 
5676498aff2SJonas Devlieghere         uuid = property(get_uuid, None, doc='''A read only property that returns a standard python uuid.UUID object that represents the UUID of this module.''')
5686498aff2SJonas Devlieghere         file = property(GetFileSpec, None, doc='''A read only property that returns an lldb object that represents the file (lldb.SBFileSpec) for this object file for this module as it is represented where it is being debugged.''')
5696498aff2SJonas Devlieghere         platform_file = property(GetPlatformFileSpec, None, doc='''A read only property that returns an lldb object that represents the file (lldb.SBFileSpec) for this object file for this module as it is represented on the current host system.''')
5706498aff2SJonas Devlieghere         byte_order = property(GetByteOrder, None, doc='''A read only property that returns an lldb enumeration value (lldb.eByteOrderLittle, lldb.eByteOrderBig, lldb.eByteOrderInvalid) that represents the byte order for this module.''')
5716498aff2SJonas Devlieghere         addr_size = property(GetAddressByteSize, None, doc='''A read only property that returns the size in bytes of an address for this module.''')
5726498aff2SJonas Devlieghere         triple = property(GetTriple, None, doc='''A read only property that returns the target triple (arch-vendor-os) for this module.''')
5736498aff2SJonas Devlieghere         num_symbols = property(GetNumSymbols, None, doc='''A read only property that returns number of symbols in the module symbol table as an integer.''')
5746498aff2SJonas Devlieghere         num_sections = property(GetNumSections, None, doc='''A read only property that returns number of sections in the module as an integer.''')
5756498aff2SJonas Devlieghere 
5766498aff2SJonas Devlieghere     %}
5776498aff2SJonas Devlieghere #endif
5786498aff2SJonas Devlieghere 
5796498aff2SJonas Devlieghere };
5806498aff2SJonas Devlieghere 
5816498aff2SJonas Devlieghere } // namespace lldb
582