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