5799c0b969
* charset.c (intermediate_encoding): Remove unused i. * completer.c (signal_completer): Remove unused i. * continuations.c (discard_my_continuations_1): Remove unused continuation_ptr. * corelow.c (core_close): Remove unuseD name. (get_core_siginfo): Remove unused pid. * cp-namespace.c (cp_lookup_symbol_imports_or_template): Remove unused i, cps. * dwarf2loc.c (dwarf2_compile_expr_to_ax): Remove unused base_offset. (loclist_describe_location): Remove unused first. * event-top.c (command_line_handler): Remove unused got_eof. * exec.c (exec_close_1): Remove unused need_symtab_cleanup. (resize_section_table): Remove unused old_value. * gdb_bfd.c (gdb_bfd_map_section): Remove unused header. * gnu-v3-abi.c (compute_vtable_size): Remove unused addr. * i386-tdep.c (i386_process_record): Remove unused rex. * infcmd.c (get_return_value): Remove unused uiout. * jv-lang.c (type_from_class): Remove unused is_array. * jv-valprint.c (java_val_print): Remove unused i. * linux-nat.c (linux_nat_stop_lwp): Remove unused ptid. * linux-thread-db.c (thread_db_find_new_threads_2): Remove unuseD pid. * m2-typeprint.c (m2_print_type): Remove unused code. * macroexp.c (get_character_constant): Remove unused body_start. (macro_stringify): Remove unused result. * objc-lang.c (find_methods): Remove unused gdbarch. * objfiles.c (filter_overlapping_sections): Remove unused abfd1, abfd2. * regcache.c (regcache_cooked_read): Remove unused gdbarch. * stack.c (print_frame_args): Remove unused summary. * thread.c (thread_apply_command): Remove unused p. * valarith.c (value_x_unop): Remove unused mangle_ptr. * valops.c (search_struct_method): Remove unused skip. * valprint.c (generic_val_print): Remove unused byte_order. * varobj.c (varobj_update): Remove unused changed. * cli/cli-cmds.c (complete_command): Remove unused next_item. (alias_command): Remove unused c. * mi/mi-cmd-catch.c (mi_catch_load_unload): Remove unused c. * mi/mi-main.c (mi_cmd_data_write_register_values): Remove unused format. (mi_cmd_data_write_memory): Remove unused word_format. (mi_cmd_data_write_memory_bytes): Remove unused r. * python/py-gdb-readline.c (gdbpy_readline_wrapper): Remove unused p_start, p_end. * python/python.c (_initialize_python): Remove unused cmd_name, cmd. * tui/tui-disasm.c (tui_set_disassem_content): Remove unused line_width. Reference: http://sourceware.org/ml/gdb-patches/2013-01/msg00766.html
113 lines
3.2 KiB
C
113 lines
3.2 KiB
C
/* Readline support for Python.
|
|
|
|
Copyright (C) 2012-2013 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#include "defs.h"
|
|
#include "python-internal.h"
|
|
#include "exceptions.h"
|
|
#include "top.h"
|
|
#include "cli/cli-utils.h"
|
|
#include "gdb_string.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
/* Readline function suitable for PyOS_ReadlineFunctionPointer, which
|
|
is used for Python's interactive parser and raw_input. In both
|
|
cases, sys_stdin and sys_stdout are always stdin and stdout
|
|
respectively, as far as I can tell; they are ignored and
|
|
command_line_input is used instead. */
|
|
|
|
static char *
|
|
gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
|
|
char *prompt)
|
|
{
|
|
int n;
|
|
char *p = NULL, *q;
|
|
volatile struct gdb_exception except;
|
|
|
|
TRY_CATCH (except, RETURN_MASK_ALL)
|
|
p = command_line_input (prompt, 0, "python");
|
|
|
|
/* Detect user interrupt (Ctrl-C). */
|
|
if (except.reason == RETURN_QUIT)
|
|
return NULL;
|
|
|
|
/* Handle errors by raising Python exceptions. */
|
|
if (except.reason < 0)
|
|
{
|
|
/* The thread state is nulled during gdbpy_readline_wrapper,
|
|
with the original value saved in the following undocumented
|
|
variable (see Python's Parser/myreadline.c and
|
|
Modules/readline.c). */
|
|
PyEval_RestoreThread (_PyOS_ReadlineTState);
|
|
gdbpy_convert_exception (except);
|
|
PyEval_SaveThread ();
|
|
return NULL;
|
|
}
|
|
|
|
/* Detect EOF (Ctrl-D). */
|
|
if (p == NULL)
|
|
{
|
|
q = PyMem_Malloc (1);
|
|
if (q != NULL)
|
|
q[0] = '\0';
|
|
return q;
|
|
}
|
|
|
|
n = strlen (p);
|
|
|
|
/* Copy the line to Python and return. */
|
|
q = PyMem_Malloc (n + 2);
|
|
if (q != NULL)
|
|
{
|
|
strncpy (q, p, n);
|
|
q[n] = '\n';
|
|
q[n + 1] = '\0';
|
|
}
|
|
return q;
|
|
}
|
|
|
|
/* Initialize Python readline support. */
|
|
|
|
void
|
|
gdbpy_initialize_gdb_readline (void)
|
|
{
|
|
/* Python's readline module conflicts with GDB's use of readline
|
|
since readline is not reentrant. Ideally, a reentrant wrapper to
|
|
GDB's readline should be implemented to replace Python's readline
|
|
and prevent conflicts. For now, this file implements a
|
|
sys.meta_path finder that simply fails to import the readline
|
|
module. */
|
|
PyRun_SimpleString ("\
|
|
import sys\n\
|
|
\n\
|
|
class GdbRemoveReadlineFinder:\n\
|
|
def find_module(self, fullname, path=None):\n\
|
|
if fullname == 'readline' and path is None:\n\
|
|
return self\n\
|
|
return None\n\
|
|
\n\
|
|
def load_module(self, fullname):\n\
|
|
raise ImportError('readline module disabled under GDB')\n\
|
|
\n\
|
|
sys.meta_path.append(GdbRemoveReadlineFinder())\n\
|
|
");
|
|
|
|
PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper;
|
|
}
|
|
|