Bonjour à tous,

Avant, pour débugger je faisais des printf. Mais avec le temps et la complexité toujours croissante de mes programme...
... ça devenait insoutenable. Alors j'ai implémenté des fonctions de sérialisation du style my_object_to_string() mais très vite ca deviens l'enfer dans ma console.

Aujourd'hui j'utilise gdb pour visualiser les données mais ce n'est pas toujours évident avec les GList, les GObject, GtkWidget, etc...

Ainsi, j'ai commencer a utiliser ce qu'on appel des pretty-printer. Et j'en suis plutôt content.

Seulement voila. Hier, je suis tombé sur un nouveau bug avec les cairo_path_t j'ai donc créer le nécessaire pour visualiser ce que contenait CairoPath et ainsi détecter rapidement le bug.
Sans pretty-printer Avec pretty-printer Avec pretty-printer
Nom : qtcreator_cairo_path_t.png
Affichages : 382
Taille : 25,4 Ko Nom : cairo_path_t.png
Affichages : 391
Taille : 14,5 Ko Nom : console_cairo_path_t.png
Affichages : 322
Taille : 7,9 Ko

Le code nécessaire
Code py : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
class cairo__PathPrinter:
	"Prints a cairo_path_t"
 
	class _iterator:
		"Iterator by cairo_path_data_t.header"
 
		def __init__(self, path):
			self.path = path
			if path:
				self.data   = path["data"]
				self.num_data = path["num_data"]
				#self.status = path["status"]
			self.pos = 0
			self.command = ""
			self.points = {}
			self.attributes= []
 
		def __iter__(self):
			return self
 
		def next(self):
			if not self.path:
				raise StopIteration
			if self.pos >= self.num_data:
				raise StopIteration
 
			length = int(self.data[self.pos]["header"]["length"])
			end = self.pos + length
			self.command = self.data[self.pos]["header"]["type"]
			self.points = {}
			self.attributes= []
			index = 1
			suff = ""
			if length>2:
				suff = "1"
			self.pos += 1
			while self.pos < end:
				self.points["x%s" % suff] = float(self.data[self.pos]["point"]["x"])
				self.points["y%s" % suff] = float(self.data[self.pos]["point"]["y"])
				self.attributes.append("x%s" % suff)
				self.attributes.append("y%s" % suff)
				self.pos += 1
				index += 1
				suff = "%d" % index
			return (self.command, self.points, self.attributes)
 
		__next__ = next # Python 3: def __next__(self)
 
	def __init__ (self, val):
		self.path = val
 
	def segment(self):
		return self._iterator(self.path)
 
	def count(self):
		size = 0
		for seg in self.segment(): size += 1
		return size
Mais je dois bien me rendre a l'évidence que je ne suis pas un killer en Phython et je perd beaucoup de temps simplement pour pourvoir voir les données en mémoire.


Aujourd'hui je voudrai utiliser les pretty-printer avec gdb dans mes programme utilisant GLib, Cairo, GObject, Gtk+. Savez-vous ou je pourrai trouver ces fonctions ?

Citation Envoyé par Documentation gdb
Suppose we have three pretty-printers installed: one from library1.so named foo that prints objects of type foo, and another from library2.so named bar that prints two types of objects, bar1 and bar2.
Savez-vous ou je pourrais trouver ces fameuses fonctions pour chaque bibliothèque (GLib, GObject, Cairo, Gtk+) ?
J'ai cherché partout, et je m'étonne de ne pas trouver... Comment gnome peut-il bien faire sans ?