Add tests for Ada changes
[deliverable/binutils-gdb.git] / gdb / extension.c
index 4e3b3e94bb93ac324378527e51c238b2435f92d6..09aa7d91c315e54aedcb027add6f61e1af806ead 100644 (file)
@@ -1,6 +1,6 @@
 /* Interface between gdb and its extension languages.
 
-   Copyright (C) 2014-2018 Free Software Foundation, Inc.
+   Copyright (C) 2014-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -154,6 +154,9 @@ get_ext_lang_of_file (const char *file)
   int i;
   const struct extension_language_defn *extlang;
 
+  if (has_extension (file, extension_language_gdb.suffix))
+    return &extension_language_gdb;
+
   ALL_EXTENSION_LANGUAGES (i, extlang)
     {
       if (has_extension (file, extlang->suffix))
@@ -405,21 +408,16 @@ auto_load_ext_lang_scripts_for_objfile (struct objfile *objfile)
    We don't know in advance which extension language will provide a
    pretty-printer for the type, so all are initialized.  */
 
-struct ext_lang_type_printers *
-start_ext_lang_type_printers (void)
+ext_lang_type_printers::ext_lang_type_printers ()
 {
-  struct ext_lang_type_printers *printers
-    = XCNEW (struct ext_lang_type_printers);
   int i;
   const struct extension_language_defn *extlang;
 
   ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang)
     {
       if (extlang->ops->start_type_printers != NULL)
-       extlang->ops->start_type_printers (extlang, printers);
+       extlang->ops->start_type_printers (extlang, this);
     }
-
-  return printers;
 }
 
 /* Iteratively try the type pretty-printers specified by PRINTERS
@@ -460,11 +458,7 @@ apply_ext_lang_type_printers (struct ext_lang_type_printers *printers,
   return NULL;
 }
 
-/* Call this after pretty-printing a type to release all memory held
-   by PRINTERS.  */
-
-void
-free_ext_lang_type_printers (struct ext_lang_type_printers *printers)
+ext_lang_type_printers::~ext_lang_type_printers ()
 {
   int i;
   const struct extension_language_defn *extlang;
@@ -472,18 +466,13 @@ free_ext_lang_type_printers (struct ext_lang_type_printers *printers)
   ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang)
     {
       if (extlang->ops->free_type_printers != NULL)
-       extlang->ops->free_type_printers (extlang, printers);
+       extlang->ops->free_type_printers (extlang, this);
     }
-
-  xfree (printers);
 }
 \f
-/* Try to pretty-print a value of type TYPE located at VAL's contents
-   buffer + EMBEDDED_OFFSET, which came from the inferior at address
-   ADDRESS + EMBEDDED_OFFSET, onto stdio stream STREAM according to
-   OPTIONS.
-   VAL is the whole object that came from ADDRESS.
-   Returns non-zero if the value was successfully pretty-printed.
+/* Try to pretty-print a value onto stdio stream STREAM according to
+   OPTIONS.  VAL is the object to print.  Returns non-zero if the
+   value was successfully pretty-printed.
 
    Extension languages are tried in the order specified by
    extension_languages.  The first one to provide a pretty-printed
@@ -496,10 +485,8 @@ free_ext_lang_type_printers (struct ext_lang_type_printers *printers)
    errors that trigger an exception in the extension language.  */
 
 int
-apply_ext_lang_val_pretty_printer (struct type *type,
-                                  LONGEST embedded_offset, CORE_ADDR address,
+apply_ext_lang_val_pretty_printer (struct value *val,
                                   struct ui_file *stream, int recurse,
-                                  struct value *val,
                                   const struct value_print_options *options,
                                   const struct language_defn *language)
 {
@@ -512,10 +499,8 @@ apply_ext_lang_val_pretty_printer (struct type *type,
 
       if (extlang->ops->apply_val_pretty_printer == NULL)
        continue;
-      rc = extlang->ops->apply_val_pretty_printer (extlang, type,
-                                                  embedded_offset, address,
-                                                  stream, recurse, val,
-                                                  options, language);
+      rc = extlang->ops->apply_val_pretty_printer (extlang, val, stream,
+                                                  recurse, options, language);
       switch (rc)
        {
        case EXT_LANG_RC_OK:
@@ -881,12 +866,12 @@ get_matching_xmethod_workers (struct type *type, const char *method_name,
 
 /* See extension.h.  */
 
-type **
-xmethod_worker::get_arg_types (int *nargs)
+std::vector<type *>
+xmethod_worker::get_arg_types ()
 {
-  type **type_array = NULL;
+  std::vector<type *> type_array;
 
-  ext_lang_rc rc = do_get_arg_types (nargs, &type_array);
+  ext_lang_rc rc = do_get_arg_types (&type_array);
   if (rc == EXT_LANG_RC_ERROR)
     error (_("Error while looking for arg types of a xmethod worker "
             "defined in %s."), m_extlang->capitalized_name);
@@ -897,11 +882,11 @@ xmethod_worker::get_arg_types (int *nargs)
 /* See extension.h.  */
 
 struct type *
-xmethod_worker::get_result_type (value *object, value **args, int nargs)
+xmethod_worker::get_result_type (value *object, gdb::array_view<value *> args)
 {
   type *result_type;
 
-  ext_lang_rc rc = do_get_result_type (object, args, nargs, &result_type);
+  ext_lang_rc rc = do_get_result_type (object, args, &result_type);
   if (rc == EXT_LANG_RC_ERROR)
     {
       error (_("Error while fetching result type of an xmethod worker "
@@ -911,6 +896,27 @@ xmethod_worker::get_result_type (value *object, value **args, int nargs)
   return result_type;
 }
 
+/* See extension.h.  */
+
+gdb::optional<std::string>
+ext_lang_colorize (const std::string &filename, const std::string &contents)
+{
+  int i;
+  const struct extension_language_defn *extlang;
+  gdb::optional<std::string> result;
+
+  ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang)
+    {
+      if (extlang->ops->colorize == nullptr)
+       continue;
+      result = extlang->ops->colorize (filename, contents);
+      if (result.has_value ())
+       return result;
+    }
+
+  return result;
+}
+
 /* Called via an observer before gdb prints its prompt.
    Iterate over the extension languages giving them a chance to
    change the prompt.  The first one to change the prompt wins,
@@ -942,8 +948,9 @@ ext_lang_before_prompt (const char *current_gdb_prompt)
     }
 }
 
+void _initialize_extension ();
 void
-_initialize_extension (void)
+_initialize_extension ()
 {
   gdb::observers::before_prompt.attach (ext_lang_before_prompt);
 }
This page took 0.026575 seconds and 4 git commands to generate.