-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax error, script doesn't work #5
Comments
Looks like *args must be after depth parameter. After fixing that, I get a new error:
Does this script require python3? my system uses python2 by default. If that's the issue, how can I tell gdb which python interpreter to use? |
Yes, the script requires python 3.5+. It has internally used type hinting. The main reason why I prefer to use the latest python is that python 2 is deprecated and will not be supported since 2020. I highly recommend you to migrate from python 2 to 3. Unfortunately, python embedded to gdb as a shared library (check with diff --git a/colour_filter.py b/colour_filter.py
index 3de0a5b..fbd7deb 100644
--- a/colour_filter.py
+++ b/colour_filter.py
@@ -2,10 +2,8 @@
# encoding: utf8
# file: colour_filter.py
-from typing import Iterator, Text
-
from gdb import parameter as get_parameter
-from gdb import Frame, frame_filters, execute
+from gdb import frame_filters, execute
from gdb.FrameDecorator import FrameDecorator
@@ -18,10 +16,10 @@ class FrameColorizer(FrameDecorator):
Notes: There is not special support Frame.elided() property.
"""
- def __init__(self, *args, depth=0, **kwargs):
+ def __init__(self, *args, **kwargs):
super(FrameColorizer, self).__init__(*args, **kwargs)
- self._depth = depth
+ self._depth = kwargs.get(depth, 0)
self.frame = super(FrameColorizer, self).inferior_frame()
def __str__(self):
@@ -93,7 +91,7 @@ class FrameColorizer(FrameDecorator):
# Here we have something like
# > raise + 272 in section .text of /usr/lib/libc.so.6
# XXX: gdb.find_pc_line
- symbol = gdb.execute('info symbol 0x%016x' % func, False, True)
+ symbol = execute('info symbol 0x%016x' % func, False, True)
# But here we truncate layout in binary
# > raise + 272
@@ -154,7 +152,7 @@ class FilterProxy:
properly on the first and the sole call.
"""
- def __init__(self, frames: Iterator[Frame]):
+ def __init__(self, frames):
self.frames = (FrameColorizer(frame, depth=ix)
for ix, frame in enumerate(frames))
@@ -189,7 +187,7 @@ class ColourFilter:
# dictionary.
frame_filters[self.name] = self
- def filter(self, iters: Iterator[Frame]) -> Iterator[Frame]:
+ def filter(self, iters):
return FilterProxy(iters)
|
After applying the patch, it looks like some color is there... for example $gdb prompt is shown in red, but when I try to show a backtrace I get this: |
Sorry for so long delay. Try to apply the patch below. The reason is that iterator protocol differs between Python 2 and Python 3. diff --git a/colour_filter.py b/colour_filter.py
index 2970f2a..bddf1d0 100644
--- a/colour_filter.py
+++ b/colour_filter.py
@@ -163,6 +163,9 @@ class FilterProxy:
return self
def __next__(self):
+ return self.next()
+
+ def next(self):
self.unroll_stack()
raise StopIteration
|
hi Dan, after apply this patch, the bt also got an error:
|
@ryanmiao GDB Python API was changed a bit. So, this patch should be usefull if you have applied the previous two. diff --git a/colour_filter.py b/colour_filter.py
index d5b070d..74f5b92 100644
--- a/colour_filter.py
+++ b/colour_filter.py
@@ -16,10 +16,10 @@ class FrameColorizer(FrameDecorator):
Notes: There is not special support Frame.elided() property.
"""
- def __init__(self, *args, **kwargs):
+ def __init__(self, *args, depth=0, **kwargs):
super(FrameColorizer, self).__init__(*args, **kwargs)
- self._depth = kwargs.get(depth, 0)
+ self._depth = depth
self.frame = super(FrameColorizer, self).inferior_frame()
def __str__(self):
Also, it would be better to use Python 3 with GDB since Python 2 is deprecated. |
I was facing some issues with Python 2 even after all these patches, but I fixed them and got colored backtrace to work with the file below, for those still facing issues.
|
@maksimovichsam Nice! However, I still recommend to switch to Python 3 or newer version of GDB with built-in colour support. |
When I include the file in .gdbinit I get the following message:
Regards!
The text was updated successfully, but these errors were encountered: