How to import 'GDB' in Python -


i using python 2.7 , python 3.1.3. in python unable "import gdb".

it giving me error as:

>>> import gdb traceback (most recent call last):   file "<interactive input>", line 1, in <module> importerror: no module named gdb >>> 

what's reason this? how should solve problem?

import gdb works when python code running within gdb process. it's not supposed work regular system python interpreter.

explanation

  • gdb embeds python interpreter can use python extension language.
  • you can't import gdb /usr/bin/python it's ordinary python library because gdb isn't structured library.
  • what can source my-script.py within gdb (equivalent running gdb -x my-script.py).

example program

here's self contained example. save file below t.py:

import gdb gdb.execute('file /bin/cat') o = gdb.execute('disassemble exit', to_string=true) print(o) gdb.execute('quit') 

run:

$ gdb -q -x t.py  

and you'll see plt stub exit() disassembled. on x86-64 linux:

dump of assembler code function exit@plt:    0x0000000000401ae0 <+0>:  jmpq   *0x20971a(%rip)    # 0x60b200 <exit@got.plt>    0x0000000000401ae6 <+6>:  pushq  $0x3d    0x0000000000401aeb <+11>: jmpq   0x401700 end of assembler dump. 

i've collected resources on learning gdb python api here.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -