+2017-01-26 Yao Qi <yao.qi@linaro.org>
+
+ * disasm.c (do_ui_file_delete): Delete.
+ (gdb_insn_length): Move code creating stream to ...
+ * utils.c (null_stream): ... here. New function.
+ * utils.h (null_stream): Declare.
+
2017-01-23 Simon Marchi <simon.marchi@polymtl.ca>
* python/py-inferior.c (find_thread_object): Return directly
return length;
}
-static void
-do_ui_file_delete (void *arg)
-{
- ui_file_delete ((struct ui_file *) arg);
-}
-
/* Return the length in bytes of the instruction at address MEMADDR in
debugged memory. */
int
gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR addr)
{
- static struct ui_file *null_stream = NULL;
-
- /* Dummy file descriptor for the disassembler. */
- if (!null_stream)
- {
- null_stream = ui_file_new ();
- make_final_cleanup (do_ui_file_delete, null_stream);
- }
-
- return gdb_print_insn (gdbarch, addr, null_stream, NULL);
+ return gdb_print_insn (gdbarch, addr, null_stream (), NULL);
}
/* fprintf-function for gdb_buffered_insn_length. This function is a
return make_cleanup (do_ui_file_delete, arg);
}
+struct ui_file *
+null_stream (void)
+{
+ /* A simple implementation of singleton pattern. */
+ static struct ui_file *stream = NULL;
+
+ if (stream == NULL)
+ {
+ stream = ui_file_new ();
+ /* Delete it on gdb exit. */
+ make_final_cleanup (do_ui_file_delete, stream);
+ }
+ return stream;
+}
+
/* Helper function for make_cleanup_ui_out_redirect_pop. */
static void
extern struct ui_file *gdb_stdtargerr;
extern struct ui_file *gdb_stdtargin;
+/* Return a null stream. */
+extern struct ui_file *null_stream (void);
+
/* Set the screen dimensions to WIDTH and HEIGHT. */
extern void set_screen_width_and_height (int width, int height);