mirror of
https://github.com/tromey/gdb-gui.git
synced 2025-07-21 21:11:25 +02:00
make it work with both python2 and python3
I ran 2to3, fixed up the output a tiny bit, and fixed the C module as well. I smoke tested with both versions of Python but didn't use it in anger yet. Fix #29
This commit is contained in:
6
Makefile
6
Makefile
@@ -1,3 +1,7 @@
|
|||||||
|
# This is passed to pkg-config to determine which python to use. It
|
||||||
|
# has to match your gdb.
|
||||||
|
pyname = python
|
||||||
|
|
||||||
all: gdb-gui.py gui/fix_signals.so
|
all: gdb-gui.py gui/fix_signals.so
|
||||||
@:
|
@:
|
||||||
|
|
||||||
@@ -5,7 +9,7 @@ gdb-gui.py: gdb-gui.py.in
|
|||||||
sed -e "s,HERE,`pwd`," < gdb-gui.py.in > gdb-gui.py
|
sed -e "s,HERE,`pwd`," < gdb-gui.py.in > gdb-gui.py
|
||||||
|
|
||||||
gui/fix_signals.so: gui/fix-signals.c
|
gui/fix_signals.so: gui/fix-signals.c
|
||||||
gcc -shared -fPIC -g -o gui/fix_signals.so gui/fix-signals.c `pkg-config --cflags python` `pkg-config --libs python`
|
gcc -shared -fPIC -g -o gui/fix_signals.so gui/fix-signals.c `pkg-config --cflags $(pyname)` `pkg-config --libs $(pyname)`
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm gdb-gui.py gui/fix_signals.so
|
-rm gdb-gui.py gui/fix_signals.so
|
||||||
|
12
gui/adapt.py
12
gui/adapt.py
@@ -46,10 +46,10 @@ def notify_bug(bugno):
|
|||||||
return
|
return
|
||||||
if not (bugno in bugs):
|
if not (bugno in bugs):
|
||||||
return
|
return
|
||||||
print "################"
|
print("################")
|
||||||
print bugs[bugno]
|
print(bugs[bugno])
|
||||||
print _warning % bugno
|
print(_warning % bugno)
|
||||||
print ""
|
print("")
|
||||||
print "You can use 'set gui mention-missing off' to disable this message."
|
print("You can use 'set gui mention-missing off' to disable this message.")
|
||||||
print "################"
|
print("################")
|
||||||
del bugs[bugno]
|
del bugs[bugno]
|
||||||
|
@@ -65,7 +65,7 @@ LINESPEC is a line specification of the form given to 'break'."""
|
|||||||
if sals is None:
|
if sals is None:
|
||||||
raise gdb.GdbError('not found')
|
raise gdb.GdbError('not found')
|
||||||
if len(sals) > 1:
|
if len(sals) > 1:
|
||||||
print "Ambiguous linespec, only showing first result"
|
print("Ambiguous linespec, only showing first result")
|
||||||
sal = sals[0]
|
sal = sals[0]
|
||||||
if sal.symtab is None or sal.symtab.filename is None:
|
if sal.symtab is None or sal.symtab.filename is None:
|
||||||
raise gdb.GdbError('could not find file for symbol')
|
raise gdb.GdbError('could not find file for symbol')
|
||||||
@@ -122,7 +122,7 @@ gui print @5 variable"""
|
|||||||
def invoke(self, arg, from_tty):
|
def invoke(self, arg, from_tty):
|
||||||
self.dont_repeat()
|
self.dont_repeat()
|
||||||
window = gui.logwindow.LogWindow()
|
window = gui.logwindow.LogWindow()
|
||||||
print "Created log window %d; now the default" % window.number
|
print("Created log window %d; now the default" % window.number)
|
||||||
|
|
||||||
class GuiPrintBase(gdb.Command):
|
class GuiPrintBase(gdb.Command):
|
||||||
def __init__(self, command):
|
def __init__(self, command):
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2013 Tom Tromey <tom@tromey.com>
|
/* Copyright (C) 2013, 2015 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -53,8 +53,33 @@ static PyMethodDef methods[] =
|
|||||||
{ NULL, NULL, 0, NULL }
|
{ NULL, NULL, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
|
||||||
|
static struct PyModuleDef module =
|
||||||
|
{
|
||||||
|
PyModuleDef_HEAD_INIT,
|
||||||
|
"fix_signals",
|
||||||
|
NULL,
|
||||||
|
-1,
|
||||||
|
methods,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
PyMODINIT_FUNC
|
||||||
|
PyInit_fix_signals (void)
|
||||||
|
{
|
||||||
|
PyModule_Create (&module);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
PyMODINIT_FUNC
|
PyMODINIT_FUNC
|
||||||
initfix_signals (void)
|
initfix_signals (void)
|
||||||
{
|
{
|
||||||
Py_InitModule ("fix_signals", methods);
|
Py_InitModule ("fix_signals", methods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@@ -70,7 +70,7 @@ class _StoredParameter(gdb.Parameter):
|
|||||||
elif p_kind is gdb.PARAM_ZINTEGER:
|
elif p_kind is gdb.PARAM_ZINTEGER:
|
||||||
val = storage.getint(self.storage_name)
|
val = storage.getint(self.storage_name)
|
||||||
else:
|
else:
|
||||||
raise "WHOOPS"
|
raise Error("missing case in gdb gui code")
|
||||||
# Don't record the first setting.
|
# Don't record the first setting.
|
||||||
self.storage = None
|
self.storage = None
|
||||||
if val is None:
|
if val is None:
|
||||||
|
@@ -15,23 +15,30 @@
|
|||||||
|
|
||||||
import gdb
|
import gdb
|
||||||
import threading
|
import threading
|
||||||
import Queue
|
try:
|
||||||
|
import queue
|
||||||
|
except ImportError:
|
||||||
|
# Python 2.
|
||||||
|
import Queue
|
||||||
|
queue = Queue
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import gui
|
import gui
|
||||||
|
|
||||||
import fix_signals
|
from . import fix_signals
|
||||||
fix_signals.save()
|
fix_signals.save()
|
||||||
|
|
||||||
from gi.repository import Gtk, Gdk, GObject, GtkSource, GLib, GdkPixbuf
|
from gi.repository import Gtk, Gdk, GObject, GtkSource, GLib, GdkPixbuf
|
||||||
|
|
||||||
(read_pipe, write_pipe) = os.pipe()
|
(read_pipe, write_pipe) = os.pipe()
|
||||||
|
|
||||||
_event_queue = Queue.Queue()
|
_event_queue = queue.Queue()
|
||||||
|
|
||||||
def send_to_gtk(func):
|
def send_to_gtk(func):
|
||||||
_event_queue.put(func)
|
_event_queue.put(func)
|
||||||
os.write(write_pipe, 'x')
|
# The payload is arbitrary, and bytes(1) is chosen to work on both
|
||||||
|
# Python 2 and Python 3.
|
||||||
|
os.write(write_pipe, bytes(1))
|
||||||
|
|
||||||
class _GtkThread(threading.Thread):
|
class _GtkThread(threading.Thread):
|
||||||
def handle_queue(self, source, condition):
|
def handle_queue(self, source, condition):
|
||||||
|
@@ -18,7 +18,12 @@
|
|||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
import os
|
import os
|
||||||
import errno
|
import errno
|
||||||
import ConfigParser
|
try:
|
||||||
|
import configparser
|
||||||
|
except ImportError:
|
||||||
|
# Python 2.
|
||||||
|
import ConfigParser
|
||||||
|
configparser = ConfigParser
|
||||||
import atexit
|
import atexit
|
||||||
|
|
||||||
class StorageManager:
|
class StorageManager:
|
||||||
@@ -26,11 +31,11 @@ class StorageManager:
|
|||||||
self.dir = os.path.join(GLib.get_user_config_dir(), 'gdb')
|
self.dir = os.path.join(GLib.get_user_config_dir(), 'gdb')
|
||||||
self.file = os.path.join(self.dir, 'settings')
|
self.file = os.path.join(self.dir, 'settings')
|
||||||
try:
|
try:
|
||||||
os.mkdir(self.dir, 0700)
|
os.mkdir(self.dir, 0o700)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
if exc.errno is not errno.EEXIST:
|
if exc.errno is not errno.EEXIST:
|
||||||
self.file = None
|
self.file = None
|
||||||
self.config = ConfigParser.RawConfigParser()
|
self.config = configparser.RawConfigParser()
|
||||||
if self.file is not None:
|
if self.file is not None:
|
||||||
self.config.read(self.file)
|
self.config.read(self.file)
|
||||||
if not self.config.has_section('general'):
|
if not self.config.has_section('general'):
|
||||||
@@ -56,7 +61,7 @@ class StorageManager:
|
|||||||
self.config.set('general', name, value)
|
self.config.set('general', name, value)
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
with open(self.file, 'wb') as save_file:
|
with open(self.file, 'wt') as save_file:
|
||||||
self.config.write(save_file)
|
self.config.write(save_file)
|
||||||
|
|
||||||
storage_manager = StorageManager()
|
storage_manager = StorageManager()
|
||||||
|
@@ -70,15 +70,15 @@ class _ToplevelState(object):
|
|||||||
def display(self):
|
def display(self):
|
||||||
with self.toplevel_lock:
|
with self.toplevel_lock:
|
||||||
if len(self.toplevels) == 0:
|
if len(self.toplevels) == 0:
|
||||||
print "No windows"
|
print("No windows")
|
||||||
return
|
return
|
||||||
|
|
||||||
print ' Num Name'
|
print(' Num Name')
|
||||||
for winno in range(1, self.next_toplevel):
|
for winno in range(1, self.next_toplevel):
|
||||||
if winno in self.toplevels:
|
if winno in self.toplevels:
|
||||||
window = self.toplevels[winno]
|
window = self.toplevels[winno]
|
||||||
print ' %3d %s' % (window.number,
|
print(' %3d %s' % (window.number,
|
||||||
window.window.get_title())
|
window.window.get_title()))
|
||||||
|
|
||||||
@in_gtk_thread
|
@in_gtk_thread
|
||||||
def _do_set_font(self, font_name):
|
def _do_set_font(self, font_name):
|
||||||
@@ -123,7 +123,7 @@ class _ToplevelState(object):
|
|||||||
|
|
||||||
@in_gtk_thread
|
@in_gtk_thread
|
||||||
def windows(self):
|
def windows(self):
|
||||||
return self.toplevels.values()
|
return list(self.toplevels.values())
|
||||||
|
|
||||||
state = _ToplevelState()
|
state = _ToplevelState()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user