GDB (API)
|
00001 # Copyright (C) 2011-2013 Free Software Foundation, Inc. 00002 00003 # This program is free software; you can redistribute it and/or modify 00004 # it under the terms of the GNU General Public License as published by 00005 # the Free Software Foundation; either version 3 of the License, or 00006 # (at your option) any later version. 00007 # 00008 # This program is distributed in the hope that it will be useful, 00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 # GNU General Public License for more details. 00012 # 00013 # You should have received a copy of the GNU General Public License 00014 # along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 00016 """Configure GDB using the ELinOS environment.""" 00017 00018 import os 00019 import glob 00020 import gdb 00021 00022 00023 def warn(msg): 00024 print "warning: %s" % msg 00025 00026 00027 def get_elinos_environment(): 00028 """Return the ELinOS environment. 00029 00030 If the ELinOS environment is properly set up, return a dictionary 00031 which contains: 00032 * The path to the ELinOS project at key 'project'; 00033 * The path to the ELinOS CDK at key 'cdk'; 00034 * The ELinOS target name at key 'target' (Eg. 'i486-linux'); 00035 * A list of Xenomai install prefixes (which could be empty, if 00036 the ELinOS project does not include Xenomai) at key 'xenomai'. 00037 00038 If one of these cannot be found, print a warning; the corresponding 00039 value in the returned dictionary will be None. 00040 """ 00041 result = {} 00042 for key in ("project", "cdk", "target"): 00043 var = "ELINOS_" + key.upper() 00044 if var in os.environ: 00045 result[key] = os.environ[var] 00046 else: 00047 warn("%s not set" % var) 00048 result[key] = None 00049 00050 if result["project"] is not None: 00051 result["xenomai"] = glob.glob(result["project"] + "/xenomai-[0-9.]*") 00052 else: 00053 result["xenomai"] = [] 00054 00055 return result 00056 00057 00058 def elinos_init(): 00059 """Initialize debugger environment for ELinOS. 00060 00061 Let the debugger know where to find the ELinOS libraries on host. This 00062 assumes that an ELinOS environment is properly set up. If some environment 00063 variables are missing, warn about which library may be missing. 00064 """ 00065 elinos_env = get_elinos_environment() 00066 00067 solib_dirs = [] 00068 00069 # System libraries 00070 if None in (elinos_env[key] for key in ("cdk", "target")): 00071 warn("ELinOS system libraries will not be loaded") 00072 else: 00073 solib_prefix = "%s/%s" % (elinos_env["cdk"], elinos_env["target"]) 00074 solib_dirs += ["%s/%s" % (solib_prefix, "lib")] 00075 gdb.execute("set solib-absolute-prefix %s" % solib_prefix) 00076 00077 # Xenomai libraries. Those are optional, so have a lighter warning 00078 # if they cannot be located. 00079 if elinos_env["project"] is None: 00080 warn("Xenomai libraries may not be loaded") 00081 else: 00082 for dir in elinos_env['xenomai']: 00083 solib_dirs += ["%s/%s" 00084 % (dir, "xenomai-build/usr/realtime/lib")] 00085 00086 if len(solib_dirs) != 0: 00087 gdb.execute("set solib-search-path %s" % ":".join(solib_dirs)) 00088 00089 00090 if __name__ == "__main__": 00091 elinos_init()