Esempio n. 1
0
static PyObject *
find_pretty_printer_from_objfiles (PyObject *value)
{
    PyObject *pp_list;
    PyObject *function;
    struct objfile *obj;

    ALL_OBJFILES (obj)
    {
        PyObject *objf = objfile_to_objfile_object (obj);
        if (!objf)
        {
            /* Ignore the error and continue.  */
            PyErr_Clear ();
            continue;
        }

        pp_list = objfpy_get_printers (objf, NULL);
        function = search_pp_list (pp_list, value);
        Py_XDECREF (pp_list);

        /* If there is an error in any objfile list, abort the search and exit.  */
        if (! function)
            return NULL;

        if (function != Py_None)
            return function;

        Py_DECREF (function);
    }

    Py_RETURN_NONE;
}
Esempio n. 2
0
static PyObject *
find_pretty_printer_from_objfiles (PyObject *value)
{
  struct objfile *obj;

  ALL_OBJFILES (obj)
  {
    PyObject *objf = objfile_to_objfile_object (obj);
    if (!objf)
      {
	/* Ignore the error and continue.  */
	PyErr_Clear ();
	continue;
      }

    gdbpy_ref<> pp_list (objfpy_get_printers (objf, NULL));
    gdbpy_ref<> function (search_pp_list (pp_list.get (), value));

    /* If there is an error in any objfile list, abort the search and exit.  */
    if (function == NULL)
      return NULL;

    if (function != Py_None)
      return function.release ();
  }

  Py_RETURN_NONE;
}
/* Find the pretty-printing constructor function for VALUE.  If no
   pretty-printer exists, return None.  If one exists, return a new
   reference.  On error, set the Python error and return NULL.  */
static PyObject *
find_pretty_printer (PyObject *value)
{
  PyObject *pp_list = NULL;
  PyObject *function = NULL;
  struct objfile *obj;
  volatile struct gdb_exception except;

  /* Look at the pretty-printer dictionary for each objfile.  */
  ALL_OBJFILES (obj)
  {
    PyObject *objf = objfile_to_objfile_object (obj);
    if (!objf)
      {
	/* Ignore the error and continue.  */
	PyErr_Clear ();
	continue;
      }

    pp_list = objfpy_get_printers (objf, NULL);
    function = search_pp_list (pp_list, value);

    /* If there is an error in any objfile list, abort the search and
       exit.  */
    if (! function)
      {
	Py_XDECREF (pp_list);
	return NULL;
      }

    if (function != Py_None)
      goto done;
    
    Py_DECREF (function);
    Py_XDECREF (pp_list);
  }

  pp_list = NULL;
  /* Fetch the global pretty printer dictionary.  */
  if (! PyObject_HasAttrString (gdb_module, "pretty_printers"))
    {
      function = Py_None;
      Py_INCREF (function);
      goto done;
    }
  pp_list = PyObject_GetAttrString (gdb_module, "pretty_printers");
  if (! pp_list)
    goto done;
  if (! PyList_Check (pp_list))
    goto done;

  function = search_pp_list (pp_list, value);

 done:
  Py_XDECREF (pp_list);
  
  return function;
}