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