0

I have a python script, which is extending gdb for C debugging. I run gdb project_name/gdb/target.elf to start gdb. I'm on Windows 10 using the cygwin terminal. When i'm in the gdb console I type source project_name/gdb/debug.py. In my debug.py file I have a class StartupHandler:

class StartupHandler(gdb.Command):
    def __init__ (self):
        super (StartupHandler, self).__init__ ("startup-handler", gdb.COMMAND_NONE)
    def invoke (self, args):

which is getting inizialized using the code StartupHandler(). After that I can run startup_handler args in the gdb console which calls the invoke() method, that makes some initialization. After that I can debug my target.

Now I would like to factor out some global variables I'm using in project_name/gdb/debug.py in an additional file called project_name/gdb/debug_data.py and import the global vars like from debug_data import var1

By importing the global vars from the new file I'm getting the Error:

 File "c:\current\share\gdb/python\gdb\__init__.py", line 130, in _execute_file
    exec(compiled, globals, globals)
  File "project/gdb/debug.py", line 17, in <module>
    from debug_data import var1
ModuleNotFoundError: No module named 'debug_data'

when I type in source hymap/gdb/debug.py in the gdb console. Does anyone know why the python interpreter inside gdb throws the ModuleNotFoundError?

Simon Rechermann
  • 467
  • 3
  • 18
  • What's the code on line 17 of `project/gdb/debug.py`? – ssbssa May 04 '21 at 10:48
  • 4
    For `import` to be able to find `debug_data`, you need to have `'project_name/gdb'` in Python's `sys.path` list. Try `sys.path.append('project_name/gdb')`. – Mark Plotnick May 04 '21 at 15:21
  • @ssbssa from debug_data import var1 – Simon Rechermann May 06 '21 at 08:02
  • @MarkPlotnick You might want to post it as answer (or close as duplicate of [Python can't find module in the same folder - Stack Overflow](https://stackoverflow.com/questions/24722212/python-cant-find-module-in-the-same-folder) ? Although I don't know if gdb Python environment makes the relative import different) – user202729 Dec 07 '21 at 07:23

0 Answers0