Automatic date update in version.in
[binutils-gdb.git] / gdb / system-gdbinit / elinos.py
blobda82687a76f29aec45ab6df9326be08aacee95dc
1 # Copyright (C) 2011-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 """Configure GDB using the ELinOS environment."""
18 import glob
19 import os
21 import gdb
24 def warn(msg):
25 print("warning: %s" % msg)
28 def get_elinos_environment():
29 """Return the ELinOS environment.
31 If the ELinOS environment is properly set up, return a dictionary
32 which contains:
33 * The path to the ELinOS project at key 'project';
34 * The path to the ELinOS CDK at key 'cdk';
35 * The ELinOS target name at key 'target' (Eg. 'i486-linux');
36 * A list of Xenomai install prefixes (which could be empty, if
37 the ELinOS project does not include Xenomai) at key 'xenomai'.
39 If one of these cannot be found, print a warning; the corresponding
40 value in the returned dictionary will be None.
41 """
42 result = {}
43 for key in ("project", "cdk", "target"):
44 var = "ELINOS_" + key.upper()
45 if var in os.environ:
46 result[key] = os.environ[var]
47 else:
48 warn("%s not set" % var)
49 result[key] = None
51 if result["project"] is not None:
52 result["xenomai"] = glob.glob(result["project"] + "/xenomai-[0-9.]*")
53 else:
54 result["xenomai"] = []
56 return result
59 def elinos_init():
60 """Initialize debugger environment for ELinOS.
62 Let the debugger know where to find the ELinOS libraries on host. This
63 assumes that an ELinOS environment is properly set up. If some environment
64 variables are missing, warn about which library may be missing.
65 """
66 elinos_env = get_elinos_environment()
68 solib_dirs = []
70 # System libraries
71 if None in (elinos_env[key] for key in ("cdk", "target")):
72 warn("ELinOS system libraries will not be loaded")
73 else:
74 solib_prefix = "%s/%s" % (elinos_env["cdk"], elinos_env["target"])
75 solib_dirs += ["%s/%s" % (solib_prefix, "lib")]
76 gdb.execute("set solib-absolute-prefix %s" % solib_prefix)
78 # Xenomai libraries. Those are optional, so have a lighter warning
79 # if they cannot be located.
80 if elinos_env["project"] is None:
81 warn("Xenomai libraries may not be loaded")
82 else:
83 for dir in elinos_env["xenomai"]:
84 solib_dirs += ["%s/%s" % (dir, "xenomai-build/usr/realtime/lib")]
86 if len(solib_dirs) != 0:
87 gdb.execute("set solib-search-path %s" % ":".join(solib_dirs))
90 if __name__ == "__main__":
91 elinos_init()