简体   繁体   中英

“No module named”. Python error in gdb

I'm working on a class project (don't worry, this question is not homework) and recently moved from department machines to my own machine. The project is to build a simple operating system. To make the task easier, we are provided with the ability to "attach" gdb to QEMU in which our program runs. Running this program without attaching gdb on my computer works fine, however it is when I start trying to use gdb that it does not run. The main thing to note (I think) is that it runs fine on the department computers (gdb 7.4.1-debian) but not on mine (7.6.1-ubuntu).

The error I am getting pertaining to python is that gdb extensions are written in python but they do not seem to be found. I am also getting syntax error. A run of the program looks like this:

/usr/bin/qemu-system-i386
GNU gdb (GDB) 7.6.1-ubuntu
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/alfonso/course/cs167/weenix/kernel/weenix.dbg...done.

After which it hangs for a bit, then gives me this error:

inittmp.gdb:1: Error in sourced command file:
localhost:1234: Connection timed out.
Traceback (most recent call last):
  File "/home/alfonso/course/cs167/weenix/kernel/mm/memcheck.py", line 5, in <module>
    import weenix
ImportError: No module named 'weenix'
  File "/home/alfonso/course/cs167/weenix/kernel/mm/page.py", line 15
    print "pagesize: {0}".format(weenix.kmem.pagesize())
                        ^
SyntaxError: invalid syntax
  File "/home/alfonso/course/cs167/weenix/kernel/mm/slab.py", line 40
    print "{1:<{0}} {3:>{2}} {5:>{4}} {7:>{6}}".format(
                                              ^
SyntaxError: invalid syntax
  File "/home/alfonso/course/cs167/weenix/kernel/proc/proc.py", line 17
    print weenix.proc.str_proc_tree()
               ^
SyntaxError: invalid syntax
Traceback (most recent call last):
  File "/home/alfonso/course/cs167/weenix/kernel/util/debug.py", line 3, in <module>
    import weenix
ImportError: No module named 'weenix'
Traceback (most recent call last):
  File "/home/alfonso/course/cs167/weenix/kernel/util/list.py", line 3, in <module>
    import weenix
ImportError: No module named 'weenix'
Breakpoint 1 at 0xc0008f04: file util/debug.c, line 190.
Breakpoint 2 at 0xc0007016: file main/kmain.c, line 298.
Breakpoint 3 at 0xc0006cf3: file main/kmain.c, line 129.
init.gdb:6: Error in sourced command file:
The program is not being run.

Of course, the import errors and invalid syntaxes made me initially think about my PYTHONPATH and/or package settings, but that is something that works fine (tested it). The only thing I can think of is that I have some configuration problems that I am overlooking.

If you would like me to, I can post the bash script, .gdb files and the rest, but since this works fine on department computers, I doubt this is the problem.

Python versions: (department: "2.7.3", me: "2.7.5+")

EDIT: After some searching, I have realized that the newest Linux Mint(petra) uses gdb that interprets python as python3. I am currently looking for a way to configure gdb, but as I have never done it before, I would appreciate if someone could direct me in doing so.

You use Python 3 for this debug mode.

$ python3 test33.py
  File "test33.py", line 1
    print "hello".format()
                ^
SyntaxError: invalid syntax

Make sure you use Python 2 as you say.

I'm doing this homework, too. (I guess weenix is too commonly used for OS courses.)

Regarding "import weenix" problem, it's because weenix's python script isn't in gdb's data directory . When using gdb with python, this dir will be added to python's PATH automatically. Therefore, just put "weenix/python/weenix" under your data directory/python . As for me, it's /usr/shared/gdb/ .

Having fun with weenix!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM