GDB (xrefs)
Loading...
Searching...
No Matches
modules.py
Go to the documentation of this file.
1# Copyright 2023 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import gdb
17
18from .server import capability, request
19from .startup import in_gdb_thread
20
21
22@in_gdb_thread
23def module_id(objfile):
24 """Return the module ID for the objfile."""
25 return objfile.username
26
27
28@in_gdb_thread
29def is_module(objfile):
30 """Return True if OBJFILE represents a valid Module."""
31 return objfile.is_valid() and objfile.owner is None
32
33
34@in_gdb_thread
35def make_module(objf):
36 """Return a Module representing the objfile OBJF.
37
38 The objfile must pass the 'is_module' test."""
39 result = {
40 "id": module_id(objf),
41 "name": objf.username,
42 }
43 if objf.is_file:
44 result["path"] = objf.filename
45 return result
46
47
48@in_gdb_thread
49def _modules(start, count):
50 # Don't count invalid objfiles or separate debug objfiles.
51 objfiles = [x for x in gdb.objfiles() if is_module(x)]
52 if count == 0:
53 # Use all items.
54 last = len(objfiles)
55 else:
56 last = start + count
57 return {
58 "modules": [make_module(x) for x in objfiles[start:last]],
59 "totalModules": len(objfiles),
60 }
61
62
63@capability("supportsModulesRequest")
64@request("modules")
65def modules(*, startModule: int = 0, moduleCount: int = 0, **args):
66 return _modules(startModule, moduleCount)
module_id(objfile)
Definition modules.py:23
_modules(start, count)
Definition modules.py:49
is_module(objfile)
Definition modules.py:29
make_module(objf)
Definition modules.py:35
objfiles()
Definition __init__.py:216