This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch][python] Auto-load gdb.command and gdb.function modules
- From: Tom Tromey <tromey at redhat dot com>
- To: pmuldoon at redhat dot com
- Cc: gdb-patches at sourceware dot org
- Date: Thu, 04 Aug 2011 11:11:52 -0600
- Subject: Re: [patch][python] Auto-load gdb.command and gdb.function modules
- References: <m3ty9xgluh.fsf@redhat.com>
>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
Phil> This patch enables module auto-importing for the gdb.command and
Phil> gdb.function name-spaces. Any Python file (which is not __init__.py)
Phil> located in {data-directory}/gdb/python/command and
Phil> {data-directory}/gdb/python/function is now automatically imported, and
Phil> available immediately upon GDB start.
Phil> Tested on X86-64 with no regressions.
Phil> OK?
Phil> +module_dict = {\
Phil> +'gdb.function': os.path.join(gdb.PYTHONDIR, 'gdb', 'function'),\
Phil> +'gdb.command': os.path.join(gdb.PYTHONDIR, 'gdb', 'command')\
Phil> +}
You don't need the trailing "\"s, please remove them.
I think the lines in the dict should be indented, that looks better.
Phil> + py_files = filter(lambda x: x.endswith('.py') and x != '__init__.py',\
Phil> + os.listdir(location))
Indentation of the second line looks wrong.
I don't think you need that "\".
Phil> + for py_file in py_files:
Phil> + py_file = py_file.rstrip('.py')
Phil> + py_file = module + '.' + py_file
Phil> + try:
Phil> + exec('import ' + py_file)
Phil> + except:
Phil> + print 'Error importing: ', py_file
It seems like this should print the real error from the exception.
Tom