This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch][python] Auto-load gdb.command and gdb.function modules


>>>>> "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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]