1 # Copyright (C) 2010-2013 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/>.
21 if sys
.version_info
[0] > 2:
22 # Python 3 moved "reload"
23 from imp
import reload
27 class _GdbFile (object):
28 # These two are needed in Python 3
39 def writelines(self
, iterable
):
46 class GdbOutputFile (_GdbFile
):
48 write(s
, stream
=STDOUT
)
50 sys
.stdout
= GdbOutputFile()
52 class GdbOutputErrorFile (_GdbFile
):
54 write(s
, stream
=STDERR
)
56 sys
.stderr
= GdbOutputErrorFile()
58 # Default prompt hook does nothing.
61 # Ensure that sys.argv is set to something.
62 # We do not use PySys_SetArgvEx because it did not appear until 2.6.6.
65 # Initial pretty printers.
68 # Initial type printers.
70 # Initial frame filters.
73 # Convenience variable to GDB's python directory
74 PYTHONDIR
= os
.path
.dirname(os
.path
.dirname(__file__
))
76 # Auto-load all functions/commands.
78 # Packages to auto-load.
85 # pkgutil.iter_modules is not available prior to Python 2.6. Instead,
86 # manually iterate the list, collating the Python files in each module
87 # path. Construct the module name, and import.
89 def auto_load_packages():
90 for package
in packages
:
91 location
= os
.path
.join(os
.path
.dirname(__file__
), package
)
92 if os
.path
.exists(location
):
93 py_files
= filter(lambda x
: x
.endswith('.py')
94 and x
!= '__init__.py',
97 for py_file
in py_files
:
98 # Construct from foo.py, gdb.module.foo
99 modname
= "%s.%s.%s" % ( __name__
, package
, py_file
[:-3] )
101 if modname
in sys
.modules
:
102 # reload modules with duplicate names
103 reload(__import__(modname
))
107 sys
.stderr
.write (traceback
.format_exc() + "\n")
111 def GdbSetPythonDirectory(dir):
112 """Update sys.path, reload gdb and auto-load packages."""
116 sys
.path
.remove(PYTHONDIR
)
119 sys
.path
.insert(0, dir)
123 # note that reload overwrites the gdb module without deleting existing
125 reload(__import__(__name__
))
This page took 0.042356 seconds and 4 git commands to generate.