0

below code is working fine as a python code(without gdb module), but it is not working inside gdb?

#!/usr/bin/env python
import csv
import gdb

list = []
x = open("file.txt")
with x as csv_data:
    entries = csv.reader(csv_data, delimiter=",")
    for entry in entries:
        list.append({
            "name": entry[0],
            "type": entry[1],
            "link": entry[2],
            "level": entry[3]
        })

the error is :

(gdb) source script.py
 File "script.py", line 6
   with x as csv_data:
        ^
 SyntaxError: invalid syntax

file.txt is:

Mac, char, list, one
John, char, list, three
...
...

It seems there is issue with with and as keyword.

Baijnath Jaiswal
  • 377
  • 5
  • 17

1 Answers1

0

gdb is probably linked against a different version of Python than whatever it is you are expecting.

You can check this using the usual Python methods, or with "ldd gdb".

Python lets you import "with" from "future" -- search for this.

Tom Tromey
  • 21,507
  • 2
  • 45
  • 63
  • could not resolve yet,i have python 3.0.1 installed.output of`ldd gdb` is `libncurses.so.5 => /usr/lib64/libncurses.so.5 (0x0000003c29200000)` `libz.so.1 => /usr/lib64/libz.so.1 (0x0000003c17c00000)``libm.so.6 => /lib64/libm.so.6 (0x0000003c16c00000)``libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003c17400000)``libdl.so.2 => /lib64/libdl.so.2 (0x0000003c17000000)``libutil.so.1 => /lib64/libutil.so.1 (0x0000003c24600000)``libexpat.so.0 => /lib64/libexpat.so.0 (0x0000003c1b800000)``libc.so.6 => /lib64/libc.so.6 (0x0000003c16800000)``/lib64/ld-linux-x86-64.so.2 (0x0000003c16400000)` – Baijnath Jaiswal Jul 05 '13 at 06:53
  • Then you've done something weird, since according to that your gdb doesn't include python at all. – Tom Tromey Jul 05 '13 at 20:42
  • but python is working inside it. Can you suggest me what should i do.? I can install it from scratch if required.. – Baijnath Jaiswal Jul 06 '13 at 10:01
  • You can use any pythonic method to find the version. Offhand I don't know what these might be but I am sure they are documented. Or you an attach to a running gdb and use "info shared". Or there are probably other ways as well. – Tom Tromey Jul 06 '13 at 20:28