aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog21
-rw-r--r--gdb/cli-out.c1
-rw-r--r--gdb/mi/mi-out.c1
-rw-r--r--gdb/ui-out.c43
-rw-r--r--gdb/ui-out.h6
5 files changed, 68 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 80d4898..a40756c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,24 @@
+2013-02-11 Siva Chandra Reddy <sivachandra@google.com>
+
+ Add support for a destructor for ui_out data and use it to
+ provide a ui_out destructor.
+ * ui-out.h: Declare the new ui_out destructor.
+ (ui_out_impl): Add a field for data destructor in ui_out_impl.
+ * ui-out.c (default_data_destroy): Add a default data destructor
+ which does nothing.
+ (default_ui_out_impl): Set the new data_destroy field to
+ default_data_destroy
+ (uo_data_destroy): Local function which invokes the data
+ destructor if present.
+ (clear_table): Local function which clears the table data of a
+ ui_out object.
+ (ui_out_destroy): Public function which frees a ui_out object.
+ (ui_out_table_end): Use the new clear_table function.
+ * cli-out.c (cli_ui_out_impl): Set the new data_destroy field to
+ NULL.
+ * mi/mi-out.c (mi_ui_out_impl): Set the new data_destroy field
+ to NULL.
+
2013-02-11 Doug Evans <dje@google.com>
* printcmd.c (printf_c_string,printf_wide_c_string): New functions.
diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index 58b7e11..380352b 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -370,6 +370,7 @@ struct ui_out_impl cli_ui_out_impl =
cli_wrap_hint,
cli_flush,
cli_redirect,
+ 0,
0, /* Does not need MI hacks (i.e. needs CLI hacks). */
};
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index c96a74e..90a4c1c 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -88,6 +88,7 @@ struct ui_out_impl mi_ui_out_impl =
mi_wrap_hint,
mi_flush,
mi_redirect,
+ 0,
1, /* Needs MI hacks. */
};
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index cd7e33e..36c4b15 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -185,6 +185,7 @@ static void default_message (struct ui_out *uiout, int verbosity,
va_list args) ATTRIBUTE_PRINTF (3, 0);
static void default_wrap_hint (struct ui_out *uiout, char *identstring);
static void default_flush (struct ui_out *uiout);
+static void default_data_destroy (struct ui_out *uiout);
/* This is the default ui-out implementation functions vector. */
@@ -206,6 +207,7 @@ struct ui_out_impl default_ui_out_impl =
default_wrap_hint,
default_flush,
NULL,
+ default_data_destroy,
0, /* Does not need MI hacks. */
};
@@ -254,6 +256,7 @@ static void uo_message (struct ui_out *uiout, int verbosity,
static void uo_wrap_hint (struct ui_out *uiout, char *identstring);
static void uo_flush (struct ui_out *uiout);
static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream);
+static void uo_data_destroy (struct ui_out *uiout);
/* Prototypes for local functions */
@@ -264,6 +267,7 @@ static void append_header_to_list (struct ui_out *uiout, int width,
static int get_next_header (struct ui_out *uiout, int *colno, int *width,
int *alignment, char **colhdr);
static void clear_header_list (struct ui_out *uiout);
+static void clear_table (struct ui_out *uiout);
static void verify_field (struct ui_out *uiout, int *fldno, int *width,
int *align);
@@ -328,10 +332,7 @@ ui_out_table_end (struct ui_out *uiout)
uiout->table.flag = 0;
uo_table_end (uiout);
-
- if (uiout->table.id)
- xfree (uiout->table.id);
- clear_header_list (uiout);
+ clear_table (uiout);
}
void
@@ -749,6 +750,11 @@ default_flush (struct ui_out *uiout)
{
}
+static void
+default_data_destroy (struct ui_out *uiout)
+{
+}
+
/* Interface to the implementation functions. */
void
@@ -787,6 +793,16 @@ uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
uiout->impl->table_header (uiout, width, align, col_name, colhdr);
}
+/* Clear the table associated with UIOUT. */
+
+static void
+clear_table (struct ui_out *uiout)
+{
+ if (uiout->table.id)
+ xfree (uiout->table.id);
+ clear_header_list (uiout);
+}
+
void
uo_begin (struct ui_out *uiout,
enum ui_out_type type,
@@ -901,6 +917,15 @@ uo_redirect (struct ui_out *uiout, struct ui_file *outstream)
return 0;
}
+void
+uo_data_destroy (struct ui_out *uiout)
+{
+ if (!uiout->impl->data_destroy)
+ return;
+
+ uiout->impl->data_destroy (uiout);
+}
+
/* local functions */
/* List of column headers manipulation routines. */
@@ -1079,6 +1104,16 @@ ui_out_new (struct ui_out_impl *impl, void *data,
return uiout;
}
+/* Free UIOUT and the memory areas it references. */
+
+void
+ui_out_destroy (struct ui_out *uiout)
+{
+ uo_data_destroy (uiout);
+ clear_table (uiout);
+ xfree (uiout);
+}
+
/* Standard gdb initialization hook. */
void
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index 3de567a..b07496e 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -197,6 +197,7 @@ typedef void (wrap_hint_ftype) (struct ui_out * uiout, char *identstring);
typedef void (flush_ftype) (struct ui_out * uiout);
typedef int (redirect_ftype) (struct ui_out * uiout,
struct ui_file * outstream);
+typedef void (data_destroy_ftype) (struct ui_out *uiout);
/* ui-out-impl */
@@ -221,6 +222,7 @@ struct ui_out_impl
wrap_hint_ftype *wrap_hint;
flush_ftype *flush;
redirect_ftype *redirect;
+ data_destroy_ftype *data_destroy;
int is_mi_like_p;
};
@@ -236,6 +238,10 @@ extern struct ui_out *ui_out_new (struct ui_out_impl *impl,
void *data,
int flags);
+/* Destroy a ui_out object. */
+
+extern void ui_out_destroy (struct ui_out *uiout);
+
/* Redirect the ouptut of a ui_out object temporarily. */
extern int ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream);