gdb/system-gdbinit/elinos.py - gdb

Functions defined

Source code

  1. # Copyright (C) 2011-2015 Free Software Foundation, Inc.

  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program.  If not, see <http://www.gnu.org/licenses/>.

  14. """Configure GDB using the ELinOS environment."""

  15. import os
  16. import glob
  17. import gdb


  18. def warn(msg):
  19.     print "warning: %s" % msg


  20. def get_elinos_environment():
  21.     """Return the ELinOS environment.

  22.     If the ELinOS environment is properly set up, return a dictionary
  23.     which contains:
  24.       * The path to the ELinOS project at key 'project';
  25.       * The path to the ELinOS CDK at key 'cdk';
  26.       * The ELinOS target name at key 'target' (Eg. 'i486-linux');
  27.       * A list of Xenomai install prefixes (which could be empty, if
  28.         the ELinOS project does not include Xenomai) at key 'xenomai'.

  29.     If one of these cannot be found, print a warning; the corresponding
  30.     value in the returned dictionary will be None.
  31.     """
  32.     result = {}
  33.     for key in ("project", "cdk", "target"):
  34.         var = "ELINOS_" + key.upper()
  35.         if var in os.environ:
  36.             result[key] = os.environ[var]
  37.         else:
  38.             warn("%s not set" % var)
  39.             result[key] = None

  40.     if result["project"] is not None:
  41.         result["xenomai"] = glob.glob(result["project"] + "/xenomai-[0-9.]*")
  42.     else:
  43.         result["xenomai"] = []

  44.     return result


  45. def elinos_init():
  46.     """Initialize debugger environment for ELinOS.

  47.     Let the debugger know where to find the ELinOS libraries on host. This
  48.     assumes that an ELinOS environment is properly set up. If some environment
  49.     variables are missing, warn about which library may be missing.
  50.     """
  51.     elinos_env = get_elinos_environment()

  52.     solib_dirs = []

  53.     # System libraries
  54.     if None in (elinos_env[key] for key in ("cdk", "target")):
  55.         warn("ELinOS system libraries will not be loaded")
  56.     else:
  57.         solib_prefix = "%s/%s" % (elinos_env["cdk"], elinos_env["target"])
  58.         solib_dirs += ["%s/%s" % (solib_prefix, "lib")]
  59.         gdb.execute("set solib-absolute-prefix %s" % solib_prefix)

  60.     # Xenomai libraries. Those are optional, so have a lighter warning
  61.     # if they cannot be located.
  62.     if elinos_env["project"] is None:
  63.         warn("Xenomai libraries may not be loaded")
  64.     else:
  65.         for dir in elinos_env['xenomai']:
  66.             solib_dirs += ["%s/%s"
  67.                            % (dir, "xenomai-build/usr/realtime/lib")]

  68.     if len(solib_dirs) != 0:
  69.         gdb.execute("set solib-search-path %s" % ":".join(solib_dirs))


  70. if __name__ == "__main__":
  71.     elinos_init()