X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gdb%2Fextension.c;h=8637bc53f2efdf420767b025f38a07f16a847f9e;hb=0231a51ef7ff49336d3a2f0e4eec09cd17b23c95;hp=c9f5664806ba0b7bfbb20dff2662795b8e0b875d;hpb=6b8505468e64c2be8d0eea1f2b8db86fa3897600;p=external%2Fbinutils.git diff --git a/gdb/extension.c b/gdb/extension.c index c9f5664..8637bc5 100644 --- a/gdb/extension.c +++ b/gdb/extension.c @@ -1,6 +1,6 @@ /* Interface between gdb and its extension languages. - Copyright (C) 2014-2016 Free Software Foundation, Inc. + Copyright (C) 2014-2019 Free Software Foundation, Inc. This file is part of GDB. @@ -28,7 +28,7 @@ #include "event-top.h" #include "extension.h" #include "extension-priv.h" -#include "observer.h" +#include "observable.h" #include "cli/cli-script.h" #include "python/python.h" #include "guile/guile.h" @@ -405,21 +405,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 +455,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,17 +463,15 @@ 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); } -/* Try to pretty-print a value of type TYPE located at VALADDR - + 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. VALADDR must point to - the head of VAL's contents buffer. +/* 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. Extension languages are tried in the order specified by @@ -496,10 +485,10 @@ 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, const gdb_byte *valaddr, +apply_ext_lang_val_pretty_printer (struct type *type, LONGEST embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, - const struct value *val, + struct value *val, const struct value_print_options *options, const struct language_defn *language) { @@ -512,7 +501,7 @@ apply_ext_lang_val_pretty_printer (struct type *type, const gdb_byte *valaddr, if (extlang->ops->apply_val_pretty_printer == NULL) continue; - rc = extlang->ops->apply_val_pretty_printer (extlang, type, valaddr, + rc = extlang->ops->apply_val_pretty_printer (extlang, type, embedded_offset, address, stream, recurse, val, options, language); @@ -553,7 +542,8 @@ apply_ext_lang_val_pretty_printer (struct type *type, const gdb_byte *valaddr, rather than trying filters in other extension languages. */ enum ext_lang_bt_status -apply_ext_lang_frame_filter (struct frame_info *frame, int flags, +apply_ext_lang_frame_filter (struct frame_info *frame, + frame_filter_flags flags, enum ext_lang_frame_args args_type, struct ui_out *out, int frame_low, int frame_high) @@ -750,7 +740,7 @@ set_active_ext_lang (const struct extension_language_defn *now_active) previous->sigint_handler.handler_saved = 0; active_ext_lang = now_active; - if (target_terminal_is_ours ()) + if (target_terminal::is_ours ()) { /* If the newly active extension language uses cooperative SIGINT handling then ensure GDB's SIGINT handler is installed. */ @@ -776,7 +766,7 @@ restore_active_ext_lang (struct active_ext_lang_state *previous) { active_ext_lang = previous->ext_lang; - if (target_terminal_is_ours ()) + if (target_terminal::is_ours ()) { /* Restore the previous SIGINT handler if one was saved. */ if (previous->sigint_handler.handler_saved) @@ -850,68 +840,18 @@ check_quit_flag (void) return result; } - -/* xmethod support. */ - -/* The xmethod API routines do not have "ext_lang" in the name because - the name "xmethod" implies that this routine deals with extension - languages. Plus some of the methods take a xmethod_foo * "self/this" - arg, not an extension_language_defn * arg. */ - -/* Returns a new xmethod_worker with EXTLANG and DATA. Space for the - result must be freed with free_xmethod_worker. */ - -struct xmethod_worker * -new_xmethod_worker (const struct extension_language_defn *extlang, void *data) -{ - struct xmethod_worker *worker = XCNEW (struct xmethod_worker); - - worker->extlang = extlang; - worker->data = data; - worker->value = NULL; - - return worker; -} -/* Clones WORKER and returns a new but identical worker. - The function get_matching_xmethod_workers (see below), returns a - vector of matching workers. If a particular worker is selected by GDB - to invoke a method, then this function can help in cloning the - selected worker and freeing up the vector via a cleanup. +/* See extension.h. */ - Space for the result must be freed with free_xmethod_worker. */ - -struct xmethod_worker * -clone_xmethod_worker (struct xmethod_worker *worker) -{ - struct xmethod_worker *new_worker; - const struct extension_language_defn *extlang = worker->extlang; - - gdb_assert (extlang->ops->clone_xmethod_worker_data != NULL); - - new_worker = new_xmethod_worker - (extlang, - extlang->ops->clone_xmethod_worker_data (extlang, worker->data)); - - return new_worker; -} - -/* If a method with name METHOD_NAME is to be invoked on an object of type - TYPE, then all entension languages are searched for implementations of - methods with name METHOD. All matches found are returned as a vector - of 'xmethod_worker_ptr' objects. If no matching methods are - found, NULL is returned. */ - -VEC (xmethod_worker_ptr) * -get_matching_xmethod_workers (struct type *type, const char *method_name) +void +get_matching_xmethod_workers (struct type *type, const char *method_name, + std::vector *workers) { - VEC (xmethod_worker_ptr) *workers = NULL; int i; const struct extension_language_defn *extlang; ALL_ENABLED_EXTENSION_LANGUAGES (i, extlang) { - VEC (xmethod_worker_ptr) *lang_workers, *new_vec; enum ext_lang_rc rc; /* If an extension language does not support xmethods, ignore @@ -921,115 +861,45 @@ get_matching_xmethod_workers (struct type *type, const char *method_name) rc = extlang->ops->get_matching_xmethod_workers (extlang, type, method_name, - &lang_workers); + workers); if (rc == EXT_LANG_RC_ERROR) - { - free_xmethod_worker_vec (workers); - error (_("Error while looking for matching xmethod workers " - "defined in %s."), extlang->capitalized_name); - } - - new_vec = VEC_merge (xmethod_worker_ptr, workers, lang_workers); - /* Free only the vectors and not the elements as NEW_VEC still - contains them. */ - VEC_free (xmethod_worker_ptr, workers); - VEC_free (xmethod_worker_ptr, lang_workers); - workers = new_vec; + error (_("Error while looking for matching xmethod workers " + "defined in %s."), extlang->capitalized_name); } - - return workers; } -/* Return the arg types of the xmethod encapsulated in WORKER. - An array of arg types is returned. The length of the array is returned in - NARGS. The type of the 'this' object is returned as the first element of - array. */ +/* See extension.h. */ -struct type ** -get_xmethod_arg_types (struct xmethod_worker *worker, int *nargs) +std::vector +xmethod_worker::get_arg_types () { - enum ext_lang_rc rc; - struct type **type_array = NULL; - const struct extension_language_defn *extlang = worker->extlang; - - gdb_assert (extlang->ops->get_xmethod_arg_types != NULL); + std::vector type_array; - rc = extlang->ops->get_xmethod_arg_types (extlang, worker, 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."), extlang->capitalized_name); - } + error (_("Error while looking for arg types of a xmethod worker " + "defined in %s."), m_extlang->capitalized_name); return type_array; } -/* Return the type of the result of the xmethod encapsulated in WORKER. - OBJECT, ARGS, NARGS are the same as for invoke_xmethod. */ +/* See extension.h. */ struct type * -get_xmethod_result_type (struct xmethod_worker *worker, - struct value *object, struct value **args, int nargs) +xmethod_worker::get_result_type (value *object, gdb::array_view args) { - enum ext_lang_rc rc; - struct type *result_type; - const struct extension_language_defn *extlang = worker->extlang; - - gdb_assert (extlang->ops->get_xmethod_arg_types != NULL); + type *result_type; - rc = extlang->ops->get_xmethod_result_type (extlang, worker, - 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 " - "defined in %s."), extlang->capitalized_name); + "defined in %s."), m_extlang->capitalized_name); } return result_type; } -/* Invokes the xmethod encapsulated in WORKER and returns the result. - The method is invoked on OBJ with arguments in the ARGS array. NARGS is - the length of the this array. */ - -struct value * -invoke_xmethod (struct xmethod_worker *worker, struct value *obj, - struct value **args, int nargs) -{ - gdb_assert (worker->extlang->ops->invoke_xmethod != NULL); - - return worker->extlang->ops->invoke_xmethod (worker->extlang, worker, - obj, args, nargs); -} - -/* Frees the xmethod worker WORKER. */ - -void -free_xmethod_worker (struct xmethod_worker *worker) -{ - gdb_assert (worker->extlang->ops->free_xmethod_worker_data != NULL); - worker->extlang->ops->free_xmethod_worker_data (worker->extlang, - worker->data); - xfree (worker); -} - -/* Frees a vector of xmethod_workers VEC. */ - -void -free_xmethod_worker_vec (void *vec) -{ - int i; - struct xmethod_worker *worker; - VEC (xmethod_worker_ptr) *v = (VEC (xmethod_worker_ptr) *) vec; - - for (i = 0; VEC_iterate (xmethod_worker_ptr, v, i, worker); i++) - free_xmethod_worker (worker); - - VEC_free (xmethod_worker_ptr, v); -} - /* 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, @@ -1061,10 +931,8 @@ ext_lang_before_prompt (const char *current_gdb_prompt) } } -extern initialize_file_ftype _initialize_extension; - void _initialize_extension (void) { - observer_attach_before_prompt (ext_lang_before_prompt); + gdb::observers::before_prompt.attach (ext_lang_before_prompt); }