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?

4
  • What's the code on line 17 of project/gdb/debug.py? Commented May 4, 2021 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'). Commented May 4, 2021 at 15:21
  • @ssbssa from debug_data import var1 Commented May 6, 2021 at 8: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 ? Although I don't know if gdb Python environment makes the relative import different) Commented Dec 7, 2021 at 7:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.