I have a very minimal understanding of Python. I am also not too experienced with GDB. I'm trying to use GDB's --init-command
flag to initialize some set up for me. I have two processors to debug which require setting up a JLink debug server. Since there's minor differences between the two, I wanted to create a class that would be imported by their respective init files. So Module1.init and Module2.init would import another file called Module.py which contains shared functions and a class to inherit from.
It looks something like the following.
Note: I've replaced some of the names and hid other information with ...
for confidentiality, but the structure is the same.
Module.py
import os, sys, subprocess
import atexit
sys.path.insert(0, 'C:/.../libcxx-pretty-printers-master/src/')
from libcxx.v1.printers import register_libcxx_printers
register_libcxx_printers (None)
def handleSignals(e):
if (not isinstance(e, gdb.SignalEvent)):
return
elif (e.stop_signal == 'SIGILL'):
gdb.execute("continue")
class Module:
...
def connectToDebugServer(self):
gdb.execute(...)
Module1.init
(which looks almost identical to Module2.init
except for parameters
python
import os, sys
sys.path.insert(0, 'C:/.../scripts/GDB/init/')
import Module
class Module1(Module.Module):
def __init__(self):
super().__init__(...)
...
inst = Module1()
inst.startDebugServer()
inst.connectToDebugServer()
end
set print pretty on
set print array on
set print demangle on
set print asm-demangle on
set print object on
I call these with gdb --init-command=/path/to/Module1.init
. I get this error
Traceback (most recent call last):
File "<string>", line 15, in <module>
File "C:/.../scripts/GDB/init\Module.py", line 49, in connectToDebugServer
gdb.execute(...)
NameError: name 'gdb' is not defined
C:\...\scripts\GDB\init\Module1.init:21: Error in sourced command file:
Error while executing Python code.
When I call it instead like gdb --init-command=/path/to/Module1.init --data-directory=/path/containing/Module1.init and Module.py/
, I get the following error:
Traceback (most recent call last):
File "<string>", line 5, in <module>
File "C:/.../scripts/GDB/init\Module.py", line 5, in <module>
from libcxx.v1.printers import register_libcxx_printers
File "C:/.../scripts/GDB/lib/libcxx-pretty-printers-master/src\libcxx\v1\printers.py", line 19, in <module>
import gdb
ModuleNotFoundError: No module named 'gdb'
C:\...\scripts\GDB\init\Module1.init:21: Error in sourced command file:
Error while executing Python code.
Alternatively, if there is a way to pass arguments to an init file that would work too. That was my original idea but I couldn't find a way to do it.