LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
printers.py
Go to the documentation of this file.
1 import gdb
2 import math, re
3 
4 try:
5  debug
6 except:
7  debug = False
8 
9 import optparse
10 argparse = None # we're using optparse
11 
12 class GdbOptionParser(optparse.OptionParser):
13  """A subclass of the standard optparse OptionParser for gdb
14 
15 GdbOptionParser raises GdbError rather than exiting when asked for help, or
16 when given an illegal value. E.g.
17 
18 parser = gdb.printing.GdbOptionParser("show image")
19 parser.add_option("-a", "--all", action="store_true",
20  help="Display the whole image")
21 parser.add_option("-w", "--width", type="int", default=8,
22  help="Field width for pixels")
23 
24 opts, args = parser.parse_args(args)
25 """
26 
27  def __init__(self, prog, *args, **kwargs):
28  """
29 Like optparse.OptionParser's API, but with an initial command name argument
30 """
31  # OptionParser is an old-style class, so no super
32  if not kwargs.get("prog"):
33  kwargs["prog"] = prog
34  optparse.OptionParser.__init__(self, *args, **kwargs)
35 
36  def parse_args(self, args, values=None):
37  """Call OptionParser.parse_args after running gdb.string_to_argv"""
38  if args is None: # defaults to sys.argv
39  args = ""
40  try:
41  args = gdb.string_to_argv(args)
42  except TypeError:
43  pass
44 
45  help = ("-h" in args or "--help" in args)
46  opts, args = optparse.OptionParser.parse_args(self, args, values)
47  opts.help = help
48  if help:
49  args = []
50 
51  return opts, args
52 
53  def exit(self, status=0, msg=""):
54  """Raise GdbError rather than exiting"""
55  if status == 0:
56  if msg:
57  print >> sys.stderr, msg
58  else:
59  raise gdb.GdbError(msg)
60 
61 try:
62  import gdb.printing
63 
64  class SharedPtrPrinter(object):
65  "Print a shared_ptr"
66 
67  def __init__(self, val):
68  self.val = val
69 
70  def to_string(self):
71  if self.val["px"]:
72  return "shared_ptr(%s)" % self.val["px"].dereference()
73  else:
74  return "NULL"
75 
76  class GilPixelPrinter(object):
77  "Print a boost::gil pixel"
78 
79  def __init__(self, val):
80  self.val = val
81 
82  def to_string(self):
83  import pdb; pdb.set_trace()
84  return self.val["_v0"]
85 
86  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
87 
89  m_storage = val["m_storage"]
90  try:
91  nx, ny = m_storage["m_cols"], m_storage["m_rows"]
92  except gdb.error: # only available for dynamic Matrices
93  try:
94  nx, ny = val.type.template_argument(1), val.type.template_argument(2)
95  except RuntimeError:
96  # should get dimens from template, but that's gdb bug #11060
97  size = m_storage["m_data"]["array"].type.sizeof
98  size0 = m_storage["m_data"]["array"].dereference().type.sizeof
99  # guess! Assume square
100  nx = int(math.sqrt(size/size0))
101  ny = size/(nx*size0)
102 
103  return nx, ny
104 
105  def getEigenValue(var, x, y=0):
106  if re.search(r"Matrix", str(var.type)):
107  if False:
108  return var["operator()(int, int)"](x, y)
109 
110  NX, NY = getEigenMatrixDimensions(var)
111 
112  if x < 0 or x >= NX or y < 0 or y >= NY:
113  raise gdb.GdbError("Element (%d, %d) is out of range 0:%d, 0:%d" %
114  (x, y, NX - 1, NY - 1))
115 
116  m_data = var["m_storage"]["m_data"]
117  if False:
118  # convert to a pointer to the start of the array
119  import pdb; pdb.set_trace()
120  m_data = m_data.address.cast(m_data.type)
121 
122  try:
123  val = m_data[x + y*NX]
124  except:
125  val = m_data["array"][x + y*NX]
126  else: # Vector
127  if False:
128  return var["operator()(int)"](x)
129 
130  NX = getEigenMatrixDimensions(var)[0]
131 
132  if x < 0 or x >= NX:
133  raise gdb.GdbError("Element (%d) is out of range 0:%d" % (x, NX - 1))
134 
135  m_data = var["m_storage"]["m_data"]
136 
137  if False:
138  # convert to a pointer to the start of the array
139  m_data = m_data.address.cast(m_data.type)
140 
141  try:
142  val = m_data[x]
143  except:
144  val = m_data["array"][x]
145 
146  if val.type.code == gdb.TYPE_CODE_INT:
147  val = int(val)
148  elif val.type.code == gdb.TYPE_CODE_FLT:
149  val = float(val)
150 
151  return val
152 
153  class EigenMatrixPrinter(object):
154  "Print an Eigen Matrix"
155 
156  def __init__(self, val):
157  self.val = val
158 
159  def to_string(self):
160  nx, ny = getEigenMatrixDimensions(self.val)
161 
162  return "%s{%dx%d}" % (self.val.type, nx, ny)
163 
164  class EigenVectorPrinter(object):
165  "Print an Eigen Vector"
166 
167  def __init__(self, val):
168  self.val = val
169 
170  def to_string(self):
171  m_storage = self.val["m_storage"]
172 
173  try:
174  n = m_storage["n"]
175  except gdb.error: # only available for dynamic Matrices
176  try:
177  n = m_storage.type.template_argument(1)
178  except RuntimeError:
179  # should get dimens from template, but that's gdb bug #11060
180  size = m_storage["m_data"]["array"].type.sizeof
181  size0 = m_storage["m_data"]["array"].dereference().type.sizeof
182  n = math.sqrt(size/size0)
183 
184  return "{%d}" % (n)
185 
186  class PrintEigenCommand(gdb.Command):
187  """Print an eigen Matrix or Vector
188  Usage: show eigen <matrix> [x0 y0 [nx ny]]
189  show eigen <vector> [x0 [nx]]
190  """
191 
192  def __init__ (self):
193  super (PrintEigenCommand, self).__init__ ("show eigen",
194  gdb.COMMAND_DATA,
195  gdb.COMPLETE_SYMBOL)
196 
197 
198  def _mget(self, var, x, y=0):
199  return getEigenValue(var, x, y)
200 
201  def _vget(self, var, x):
202  return getEigenValue(var, x)
203 
204  def invoke (self, args, fromTty):
205  self.dont_repeat()
206 
207  parser = GdbOptionParser("show eigen")
208  parser.add_option("-d", "--dataFmt", default="%.2f", help="Format for values")
209  parser.add_option("-f", "--formatWidth", type="int", default=8, help="Field width for values")
210  parser.add_option("-o", "--origin", type="str", nargs="+",
211  help="Origin of the part of the object to print")
212  if False:
213  parser.add_option("eigenObject", help="Expression giving Eigen::Matrix/Vector to show")
214  parser.add_option("nx", help="Width of patch to print", type="int", default=0, nargs="?")
215  parser.add_option("ny", help="Height of patch to print", type="int", default=0, nargs="?")
216 
217  opts = parser.parse_args(args)
218  if opts.help:
219  return
220  else:
221  (opts, args) = parser.parse_args(args)
222  if opts.help:
223  return
224 
225  if not args:
226  raise gdb.GdbError("Please specify an object")
227  opts.eigenObject = args.pop(0)
228 
229  opts.nx, opts.ny = 0, 0
230  if args:
231  opts.nx = int(args.pop(0))
232  if args:
233  opts.ny = int(args.pop(0))
234 
235  if args:
236  raise gdb.GdbError("Unrecognised trailing arguments: %s" % " ".join(args))
237 
238  var = gdb.parse_and_eval(opts.eigenObject)
239 
240  if not re.search(r"(Eigen|LinearTransform)::(Matrix|Vector)", str(var.type)):
241  raise gdb.GdbError("Please specify an eigen matrix or vector, not %s" % var.type)
242 
243  if re.search(r"shared_ptr<", str(var.type)):
244  var = var["px"].dereference()
245 
246  if var.type.code == gdb.TYPE_CODE_PTR:
247  var = var.dereference() # be nice
248 
249  isMatrix = re.search(r"Matrix", str(var.type))
250  if isMatrix:
251  NX, NY = getEigenMatrixDimensions(var)
252 
253  if opts.origin:
254  if len(opts.origin) != 2:
255  raise gdb.GdbError("Please specify both x0 and y0")
256 
257  x0 = gdb.parse_and_eval(opts.origin[0])
258  y0 = gdb.parse_and_eval(opts.origin[1])
259  else:
260  x0, y0 = 0, 0
261 
262  nx = opts.nx
263  ny = opts.ny
264  if nx == 0:
265  nx = NX
266  if ny == 0:
267  ny = NY
268 
269  if nx == 1 and ny == 1:
270  print "%g" % self._vget(var, x0)
271  return
272  else:
273  NX = 0, var["m_storage"]["n"]
274 
275  if opts.origin:
276  if len(opts.origin) != 1:
277  raise gdb.GdbError("Please only specify x0")
278 
279  x0 = gdb.parse_and_eval(opts.origin[0])
280  else:
281  x0 = 0
282 
283  nx = opts.nx
284  if nx == 0:
285  nx = NX
286 
287  if nx == 1:
288  print "%g" % self._vget(var, x0)
289  return
290  #
291  # OK, finally time to print
292  #
293  if isMatrix:
294  print "%-4s" % "",
295  for x in range(x0, min(NX, x0 + nx)):
296  print "%*d" % (opts.formatWidth, x),
297  print ""
298 
299  for y in range(y0, min(NY, y0 + ny)):
300  print "%-4d" % y,
301  for x in range(x0, min(NX, x0 + nx)):
302  print "%*s" % (opts.formatWidth, (opts.dataFmt % self._mget(var, x, y))),
303  print ""
304  else:
305  for x in range(x0, min(NX, x0 + nx)):
306  print "%*s" % (opts.formatWidth, (opts.dataFmt % self._vget(var, x))),
307  print ""
308 
310 
311  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
312 
313  class CitizenPrinter(object):
314  "Print a Citizen"
315 
316  def __init__(self, val):
317  self.val = val
318 
319  def to_string(self):
320  sentinel = long(self.val["_sentinel"].cast(gdb.lookup_type("unsigned int")))
321  return "{%s %d 0x%x}" % (self.val.address, self.val["_CitizenId"], sentinel)
322 
323  class PrintCitizenCommand(gdb.Command):
324  """Print a Citizen
325  Usage: show citizen <obj>
326  """
327 
328  def __init__ (self):
329  super (PrintCitizenCommand, self).__init__ ("show citizen",
330  gdb.COMMAND_DATA,
331  gdb.COMPLETE_SYMBOL)
332 
333  def invoke (self, args, fromTty):
334  self.dont_repeat()
335 
336  parser = GdbOptionParser("show citizen")
337  if False:
338  parser.add_option("object", help="The object in question")
339 
340  opts = parser.parse_args(args)
341  if opts.help:
342  return
343  else:
344  opts, args = parser.parse_args(args)
345  if opts.help:
346  return
347 
348  if not args:
349  raise gdb.GdbError("Please specify an object")
350  opts.object = args.pop(0)
351 
352  if args:
353  raise gdb.GdbError("Unrecognised trailing arguments: %s" % " ".join(args))
354 
355  var = gdb.parse_and_eval(opts.object)
356  if re.search(r"shared_ptr<", str(var.type)):
357  var = var["px"]
358 
359  if var.type.code != gdb.TYPE_CODE_PTR:
360  var = var.address
361 
362  citizen = var.dynamic_cast(gdb.lookup_type("lsst::daf::base::Citizen").pointer())
363 
364  if not citizen:
365  raise gdb.GdbError("Failed to cast %s to Citizen -- is it a subclass?" % opts.object)
366 
367  citizen = citizen.dereference()
368 
369  print citizen
370 
372 
373  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
374  # afw
375 
377  "Print a BaseSourceAttributes"
378 
379  def __init__(self, val):
380  self.val = val
381 
382  def to_string(self):
383  return "Base: {id=%d astrom=(%.3f, %.3f)}" % (self.val["_id"], self.val["_xAstrom"], self.val["_yAstrom"])
384 
385  class SourcePrinter(object):
386  "Print a Source"
387 
388  def __init__(self, val):
389  self.val = val
390 
391  def to_string(self):
392  return "Source{id=%d astrom=(%.3f, %.3f)}" % (self.val["_id"],
393  self.val["_xAstrom"], self.val["_yAstrom"])
394 
395  class DetectorPrinter(object):
396  "Print a cameraGeom::Detector"
397 
398  def __init__(self, val):
399  self.val = val
400 
401  def to_string(self):
402  return "Detector{name: %s id: %s type: %s bbox: %s}" % (self.val["_name"], self.val["_id"],
403  self.val["_type"], self.val["_bbox"])
404 
405  class FootprintPrinter(object):
406  "Print a Footprint"
407 
408  def __init__(self, val):
409  self.val = val
410 
411  def to_string(self):
412  if False:
413  nspan = self.val["_spans"]["size"]() # Fails (as its type is METHOD, not CODE)
414  else:
415  vec_impl = self.val["_spans"]["_M_impl"]
416  nspan = vec_impl["_M_finish"] - vec_impl["_M_start"]
417 
418  return "Footprint{id=%d, nspan=%d, area=%d; BBox %s}" % (self.val["_fid"], nspan,
419  self.val["_area"], self.val["_bbox"])
420 
421  class FootprintSetPrinter(object):
422  "Print a FootprintSet"
423 
424  def __init__(self, val):
425  self.val = val
426 
427  def to_string(self):
428  return "FootprintSet{%s; %s}" % (self.val["_region"], self.val["_footprints"])
429 
430  class PeakPrinter(object):
431  "Print a Peak"
432 
433  def __init__(self, val):
434  self.val = val
435 
436  def to_string(self):
437  return "Peak{%d, (%.2f, %.2f)}" % (self.val["_id"], self.val["_fx"], self.val["_fy"])
438 
439  class PsfPrinter(object):
440  "Print a Psf"
441 
442  def to_string(self):
443  return "%s" % (self.typeName())
444 
445  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
446 
447  class Box2Printer(object):
448  "Print a Box2"
449 
450  def __init__(self, val):
451  self.val = val
452 
453  def to_string(self):
454  # Make sure &foo works, too.
455  type = self.val.type
456  if type.code == gdb.TYPE_CODE_REF:
457  type = type.target ()
458 
459  llc = [getEigenValue(self.val["_minimum"]["_vector"], i) for i in range(2)]
460  dims = [getEigenValue(self.val["_dimensions"]["_vector"], i) for i in range(2)]
461 
462  return "Box2{(%s,%s)--(%s,%s)}" % (llc[0], llc[1],
463  llc[0] + dims[0] - 1, llc[1] + dims[1] - 1)
464 
465  def display_hint (self):
466  return "array"
467 
468  class CoordinateBasePrinter(object):
469  "Print a CoordinateBase"
470 
471  def __init__(self, val):
472  self.val = val
473 
474  def to_string(self):
475  return self.val["_vector"]["m_storage"]["m_data"]["array"]
476 
477  def display_hint (self):
478  return "array"
479 
480  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
481 
482  class AxesPrinter(object):
483  "Print an ellipse::Axes"
484 
485  def __init__(self, val):
486  self.val = val
487 
488  def to_string(self):
489  vec = self.val["_vector"]
490  return "[%g, %g, %g]" % (getEigenValue(vec, 0), getEigenValue(vec, 1), getEigenValue(vec, 2))
491 
492  class QuadrupolePrinter(object):
493  "Print an ellipse::Quadrupole"
494 
495  def __init__(self, val):
496  self.val = val
497 
498  def to_string(self):
499  mat = self.val["_matrix"]
500 
501  if False:
502  return mat
503  else:
504  return "[[%g, %g], [%g, %g]]" % (getEigenValue(mat, 0, 0), getEigenValue(mat, 0, 1),
505  getEigenValue(mat, 1, 0), getEigenValue(mat, 1, 1))
506 
507  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
508 
509  class ImagePrinter(object):
510  "Print an ImageBase or derived class"
511 
512  def dimenStr(self, val=None):
513  if val is None:
514  val = self.val
515 
516  # Make sure &foo works, too.
517  type = val.type
518  if type.code == gdb.TYPE_CODE_REF:
519  type = type.target()
520 
521  gilView = val["_gilView"]
522  arr = val["_origin"]["_vector"]["m_storage"]["m_data"]["array"]
523 
524  x0, y0 = arr[0], arr[1]
525  return "%dx%d%s%d%s%d" % (
526  #val["getWidth"](), val["getHeight"](),
527  gilView["_dimensions"]["x"], gilView["_dimensions"]["y"],
528  ["", "+"][x0 >= 0], x0, # i.e. "+" if x0 >= 0 else "" in python >= 2.5
529  ["", "+"][y0 >= 0], y0)
530 
531  def typeName(self):
532  return self.typename.split(":")[-1]
533 
534  def __init__(self, val):
535  self.typename = str(val.type)
536  self.val = val
537 
538  def to_string(self):
539  return "%s(%s)" % (self.typeName(), self.dimenStr())
540 
542  "Print a MaskedImage"
543 
544  def to_string(self):
545  return "%s(%s)" % (self.typeName(), self.dimenStr(self.val["_image"]["px"].dereference()))
546 
548  "Print an Exposure"
549 
550  def to_string(self):
551  return "%s(%s)" % (self.typeName(),
552  self.dimenStr(self.val["_maskedImage"]["_image"]["px"].dereference()))
553 
554  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
555 
556  class PrintImageCommand(gdb.Command):
557  """Print an Image"""
558 
559  def __init__ (self):
560  super (PrintImageCommand, self).__init__ ("show image",
561  gdb.COMMAND_DATA,
562  gdb.COMPLETE_SYMBOL)
563 
564  def get(self, var, x, y):
565  if False:
566  return var["operator()(int, int, bool)"](x, y, True)
567  else:
568  dimensions = var["_gilView"]["_dimensions"]
569  if x < 0 or x >= dimensions["x"] or y < 0 or y >= dimensions["y"]:
570  raise gdb.GdbError("Pixel (%d, %d) is out of range 0:%d, 0:%d" %
571  (x, y, dimensions["x"] - 1, dimensions["y"] - 1))
572 
573  pixels = var["_gilView"]["_pixels"]["_p"]
574  step = pixels["_step_fn"]["_step"]/var.type.template_argument(0).sizeof
575 
576  return pixels["m_iterator"][x + y*step]["_v0"]
577 
578  def invoke (self, args, fromTty):
579  self.dont_repeat()
580 
581  parser = GdbOptionParser("show image" + ("" if argparse else " <image> [<nx> [<ny>]]"))
582  parser.add_option("-a", "--all", action="store_true", help="Display the whole image/mask")
583  parser.add_option("-c", "--center", type="str", nargs=2, default=(None, None,),
584  help="Center the output at (x, y)")
585  parser.add_option("-o", "--origin", type="str", nargs=2, default=(None, None,),
586  help="Print the region starting at (x, y)")
587  parser.add_option("-x", "--xy0", action="store_true", help="Obey the image's (x0, y0)")
588  parser.add_option("-f", "--formatWidth", type="int", default=8, help="Field width for values")
589  parser.add_option("-d", "--dataFmt", default="%.2f", help="Format for values")
590 
591  if argparse:
592  parser.add_option("image", help="Expression giving image to show")
593  parser.add_option("width", help="Width of patch to print", default=1, nargs="?")
594  parser.add_option("height", help="Height of patch to print", default=1, nargs="?")
595 
596  opts = parser.parse_args(args)
597  if opts.help:
598  return
599  else:
600  opts, args = parser.parse_args(args)
601  if opts.help:
602  return
603 
604  if not args:
605  raise gdb.GdbError("Please specify an image")
606 
607  opts.image = args.pop(0)
608 
609  opts.width, opts.height = 1, 1
610  if args:
611  opts.width = int(args.pop(0))
612  if args:
613  opts.height = int(args.pop(0))
614 
615  if args:
616  raise gdb.GdbError("Unrecognised trailing arguments: %s" % " ".join(args))
617 
618  for i in range(2):
619  val = "0"
620  if opts.origin[i] is None:
621  if opts.center[i] is not None:
622  val = opts.center[i]
623  else:
624  val = opts.origin[i]
625  if opts.center[i] is not None:
626  raise gdb.GdbError("You may not specify both --center and --origin")
627 
628  val = gdb.parse_and_eval(val)
629  if i == 0: x0 = val
630  else: y0 = val
631 
632  if opts.all:
633  nx, ny = 0, 0
634  else:
635  nx, ny = opts.width, opts.height
636 
637  var = gdb.parse_and_eval(opts.image)
638 
639  if re.search(r"shared_ptr<", str(var.type)):
640  var = var["px"].dereference()
641 
642  if not re.search(r"(lsst::afw::image::)?(Image|Mask|MaskedImage)", str(var.type.unqualified())):
643  raise gdb.GdbError("Please specify an image, not %s" % var.type)
644 
645  if re.search(r"MaskedImage", str(var.type)) and \
646  not re.search(r"::Image(\s*&)?$", str(var.type)):
647  print "N.b. %s is a MaskedImage; showing image" % (opts.image)
648  var = var["_image"]
649 
650  if re.search(r"shared_ptr<", str(var.type)):
651  var = var["px"].dereference()
652 
653  if var.type.code == gdb.TYPE_CODE_PTR:
654  var = var.dereference() # be nice
655 
656  pixelTypeName = str(var.type.template_argument(0))
657  if opts.dataFmt:
658  dataFmt = opts.dataFmt
659  elif pixelTypeName in ["short", "unsigned short"]:
660  dataFmt = "0x%x"
661  elif pixelTypeName in ["int", "unsigned int"]:
662  dataFmt = "%d"
663  else:
664  dataFmt = "%.2f"
665 
666  if nx == 0:
667  nx = var["_gilView"]["_dimensions"]["x"]
668  if ny == 0:
669  ny = var["_gilView"]["_dimensions"]["y"]
670 
671  if opts.center[0]:
672  x0 -= nx//2
673  y0 -= ny//2
674 
675  if opts.xy0 and not opts.all:
676  arr = var["_origin"]["_vector"]["m_storage"]["m_data"]["array"]
677 
678  x0 -= arr[0]
679  y0 -= arr[1]
680  #
681  # OK, finally time to print
682  #
683  print "%-4s" % "",
684  for x in range(x0, x0 + nx):
685  print "%*d" % (opts.formatWidth, x),
686  print ""
687 
688  for y in reversed(range(y0, y0 + ny)):
689  print "%-4d" % y,
690  for x in range(x0, x0 + nx):
691  print "%*s" % (opts.formatWidth, dataFmt % self.get(var, x, y)),
692  print ""
693 
695 
696  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
697 
698  class BackgroundPrinter(object):
699  "Print a Background"
700 
701  def __init__(self, val):
702  self.typename = str(val.type)
703  self.val = val
704 
705  def to_string(self):
706  return "Background(%dx%d) %s %s" % (
707  self.val["_imgWidth"], self.val["_imgHeight"],
708  self.val["_bctrl"])
709 
711  "Print a BackgroundControl"
712 
713  def __init__(self, val):
714  self.typename = str(val.type)
715  self.val = val
716 
717  def to_string(self):
718  return "{%s %s %s %s}" % (re.sub(r"lsst::afw::math::Interpolate::", "", str(self.val["_style"])),
719  re.sub(r"lsst::afw::math::", "", str(self.val["_prop"])),
720  re.sub(r"lsst::afw::math::", "", str(self.val["_undersampleStyle"])),
721  self.val["_sctrl"]["px"].dereference())
722 
723  class KernelPrinter(object):
724  "Print a Kernel"
725 
726  def __init__(self, val):
727  self.typename = str(val.type)
728  self.val = val
729 
730  def to_string(self):
731  return "%s(%dx%d)" % (self.typename,
732  self.val["_width"], self.val["_height"])
733 
734 
735 
737  "Print a StatisticsControl"
738 
739  def __init__(self, val):
740  self.typename = str(val.type)
741  self.val = val
742 
743  def to_string(self):
744  return "{nSigma=%g nIter=%d ignore=0x%x}" % (self.val["_numSigmaClip"],
745  self.val["_numIter"],
746  self.val["_andMask"])
747 
748  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
749 
750  class TablePrinter(object):
751  "Print a table::Table"
752 
753  def __init__(self, val):
754  self.typename = str(val.type)
755  self.val = val
756 
757  def to_string(self):
758  return "{schema = %s, md=%s}" % (self.val["_schema"], self.val["_metadata"])
759 
760  class TableSchemaPrinter(object):
761  "Print a table::Schema"
762 
763  def __init__(self, val):
764  self.typename = str(val.type)
765  self.val = val
766 
767  def to_string(self):
768  names = str(self.val["_impl"]["px"]["_names"])
769  names = re.sub(r"^[^{]*{|}|[\[\]\"\"]|\s*=\s*[^,]*", "", names)
770 
771  return "%s" % (names)
772 
773  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
774 
775  printers = []
776 
777  def register(obj=None):
778  "Register my pretty-printers with objfile Obj."
779 
780  if obj is None:
781  obj = gdb
782 
783  for p in printers:
784  gdb.printing.register_pretty_printer(obj, p, replace=True)
785 
786  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
787 
789  """Surely this must be somewhere standard?"""
790 
791  printer = gdb.printing.RegexpCollectionPrettyPrinter("rhl-boost")
792 
793  printer.add_printer('boost::shared_ptr',
794  '^(boost|tr1|std)::shared_ptr', SharedPtrPrinter)
795  printer.add_printer('boost::gil::pixel',
796  'boost::gil::.*pixel_t', GilPixelPrinter)
797 
798  return printer
799 
800  printers.append(build_boost_dictionary())
801 
803  """Surely this must be somewhere standard?"""
804 
805  printer = gdb.printing.RegexpCollectionPrettyPrinter("rhl-eigen")
806 
807  printer.add_printer('eigen::Matrix',
808  '^Eigen::Matrix', EigenMatrixPrinter)
809  printer.add_printer('eigen::Vector',
810  '^Eigen::Vector', EigenVectorPrinter)
811 
812  return printer
813 
814  printers.append(build_eigen_dictionary())
815 
816 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
817 
819  printer = gdb.printing.RegexpCollectionPrettyPrinter("afw")
820 
821  printer.add_printer('lsst::afw::cameraGeom::Detector',
822  '^lsst::afw::cameraGeom::(Amp|Ccd|Detector|DetectorMosaic)$', DetectorPrinter)
823 
824  printer.add_printer('lsst::afw::detection::Footprint',
825  '^lsst::afw::detection::Footprint$', FootprintPrinter)
826  printer.add_printer('lsst::afw::detection::FootprintSet',
827  '^lsst::afw::detection::FootprintSet', FootprintSetPrinter)
828  printer.add_printer('lsst::afw::detection::Peak',
829  '^lsst::afw::detection::Peak$', PeakPrinter)
830  printer.add_printer('lsst::afw::detection::Psf',
831  '^lsst::afw::detection::Psf$', PsfPrinter)
832  printer.add_printer('lsst::afw::detection::Source',
833  '^lsst::afw::detection::Source$', SourcePrinter)
834  printer.add_printer('lsst::afw::detection::BaseSourceAttributes',
835  '^lsst::afw::detection::BaseSourceAttributes$', BaseSourceAttributesPrinter)
836 
837  printer.add_printer('lsst::afw::geom::Box',
838  '^lsst::afw::geom::Box', Box2Printer)
839  printer.add_printer('lsst::afw::geom::Extent',
840  '^lsst::afw::geom::Extent', CoordinateBasePrinter)
841  printer.add_printer('lsst::afw::geom::Point',
842  '^lsst::afw::geom::Point', CoordinateBasePrinter)
843 
844  printer.add_printer('lsst::afw::geom::ellipses::Axes',
845  '^lsst::afw::geom::ellipses::Axes', AxesPrinter)
846  printer.add_printer('lsst::afw::geom::ellipses::Quadrupole',
847  '^lsst::afw::geom::ellipses::Quadrupole', QuadrupolePrinter)
848 
849  printer.add_printer('lsst::afw::image::ImageBase',
850  'lsst::afw::image::ImageBase<[^>]+>$', ImagePrinter)
851  printer.add_printer('lsst::afw::image::Image',
852  'lsst::afw::image::Image<[^>]+>$', ImagePrinter)
853  printer.add_printer('lsst::afw::image::Mask',
854  '^lsst::afw::image::Mask<[^>]+>$', ImagePrinter)
855  printer.add_printer('lsst::afw::image::MaskedImage',
856  '^lsst::afw::image::MaskedImage<[^>]+>$', MaskedImagePrinter)
857  printer.add_printer('lsst::afw::image::Exposure',
858  '^lsst::afw::image::Exposure', ExposurePrinter)
859 
860  printer.add_printer('lsst::afw::math::Background',
861  '^lsst::afw::math::Background$', BackgroundPrinter)
862  printer.add_printer('lsst::afw::math::BackgroundControl',
863  '^lsst::afw::math::BackgroundControl$', BackgroundControlPrinter)
864  printer.add_printer('lsst::afw::math::Kernel',
865  '^lsst::afw::math::.*Kernel', KernelPrinter)
866  printer.add_printer('lsst::afw::math::StatisticsControl',
867  '^lsst::afw::math::StatisticsControl', StatisticsControlPrinter)
868 
869  printer.add_printer('lsst::afw::table::Table',
870  '^lsst::afw::table::.*Table$', TablePrinter)
871  printer.add_printer('lsst::afw::table::Schema',
872  '^lsst::afw::table::Schema$', TableSchemaPrinter)
873 
874  return printer
875 
876  printers.append(build_afw_dictionary())
877 
879  printer = gdb.printing.RegexpCollectionPrettyPrinter("daf::base")
880 
881  printer.add_printer('lsst::daf::base::Citizen',
882  'lsst::daf::base::Citizen', CitizenPrinter)
883 
884  return printer
885 
886  printers.append(build_daf_base_dictionary())
887 except ImportError, e:
888  print "RHL", e
889  from printers_oldgdb import *