From 3b3c10cee0d38f9396fdb6cf028ceb8917822bb7 Mon Sep 17 00:00:00 2001 From: Jens Carl Date: Wed, 10 Apr 2019 10:50:10 -0700 Subject: Fix Python exception in gdb pretty-printer basegfx Add single quotes around the namespace::class construct, when calling gdb.parse_and_eval(), otherwise this exception is thrown: "Python Exception A syntax error in expression, near `)xxx)->count($'.:" The reason is a possible conflict with '::' referring a static variable (https://sourceware.org/gdb/onlinedocs/gdb/Variables.html). Also improved the B2DPolyPolygonPrinter::children method to avoid a segmentation fault, when accessing member m_value. Change-Id: I1c15a4b786e1e374c67ace445d28c1ce210a4c04 Reviewed-on: https://gerrit.libreoffice.org/70537 Tested-by: Jenkins Reviewed-by: Noel Grandin --- solenv/gdb/libreoffice/basegfx.py | 41 +++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'solenv/gdb') diff --git a/solenv/gdb/libreoffice/basegfx.py b/solenv/gdb/libreoffice/basegfx.py index 81901fe8dae8..c14968c91eb2 100644 --- a/solenv/gdb/libreoffice/basegfx.py +++ b/solenv/gdb/libreoffice/basegfx.py @@ -58,15 +58,19 @@ class B2DPolygonPrinter(object): self.typename) def _count(self): + # It's a call into the inferior (being debugged) process. + # Will not work with core dumps and can cause a deadlock. return int(gdb.parse_and_eval( - '((basegfx::B2DPolygon*)%d)->count()' % self.value.address)) + "(('basegfx::B2DPolygon' *) {})->count()".format(self.value.address))) def _isEmpty(self): return self._count() == 0 def _hasCurves(self): + # It's a call into the inferior (being debugged) process. + # Will not work with core dumps and can cause a deadlock. return int(gdb.parse_and_eval( - '((basegfx::B2DPolygon*)%d)->areControlPointsUsed()' % self.value.address)) != 0 + "(('basegfx::B2DPolygon' *) {})->areControlPointsUsed()".format(self.value.address))) != 0 def _children(self): if self._hasCurves(): @@ -113,12 +117,15 @@ class B2DPolygonPrinter(object): #currPoint = gdb.parse_and_eval( # '((basegfx::B2DPolygon*)%d)->getB2DPoint(%d)' % ( # self.value.address, self.index)) + + # It's a call into the inferior (being debugged) process. + # Will not work with core dumps and can cause a deadlock. prevControl = gdb.parse_and_eval( - '((basegfx::B2DPolygon*)%d)->getPrevControlPoint(%d)' % ( - self.value.address, self.index)) + "(('basegfx::B2DPolygon' *) {})->getPrevControlPoint({:d})".format(self.value.address, self.index)) + # It's a call into the inferior (being debugged) process. + # Will not work with core dumps and can cause a deadlock. nextControl = gdb.parse_and_eval( - '((basegfx::B2DPolygon*)%d)->getNextControlPoint(%d)' % ( - self.value.address, self.index)) + "(('basegfx::B2DPolygon' *) {})->getNextControlPoint({:d})".format(self.value.address, self.index)) self.index += 1 return ('point %d' % (self.index-1), 'p: (%15f, %15f) c-1: (%15f, %15f) c1: (%15f, %15f)' % @@ -142,21 +149,31 @@ class B2DPolyPolygonPrinter(object): self._count()) def _count(self): + # It's a call into the inferior (being debugged) process. + # Will not work with core dumps and can cause a deadlock. return int(gdb.parse_and_eval( - '((basegfx::B2DPolyPolygon*)%d)->count()' % self.value.address)) + "(('basegfx::B2DPolyPolygon' *) {})->count()".format(self.value.address))) def _isClosed(self): + # It's a call into the inferior (being debugged) process. + # Will not work with core dumps and can cause a deadlock. return int(gdb.parse_and_eval( - '((basegfx::B2DPolyPolygon*)%d)->isClosed()' % self.value.address)) != 0 + "(('basegfx::B2DPolyPolygon' *) {})->isClosed()".format(self.value.address))) != 0 def _isEmpty(self): return self._count() == 0 def children(self): - impl = self.value['mpPolyPolygon']['m_pimpl'] - vector = self.value['mpPolyPolygon']['m_pimpl'].dereference()['m_value']['maPolygons'] - import libstdcxx.v6.printers as std - return std.StdVectorPrinter("std::vector", vector).children() + if self.value['mpPolyPolygon']['m_pimpl'].type.code in (gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_MEMBERPTR): + if self.value['mpPolyPolygon']['m_pimpl']: + try: + vector = self.value['mpPolyPolygon']['m_pimpl'].dereference()['m_value']['maPolygons'] + import libstdcxx.v6.printers as std + return std.StdVectorPrinter("std::vector", vector).children() + except RuntimeError: + gdb.write("Cannot access memory at address " + str(self.value['mpPolyPolygon']['m_pimpl'].address)) + + return None printer = None -- cgit v1.2.3