From f870a310ee7fbfd6ccaea95d632063cbdbd2b9c9 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 5 Mar 2010 20:18:19 +0000 Subject: gdb 2010-03-05 Corinna Vinschen Tom Tromey * utils.c (host_char_to_target): Add 'gdbarch' argument. (parse_escape): Likewise. * python/py-utils.c (unicode_to_target_string): Update. (unicode_to_target_python_string): Update. (target_string_to_unicode): Update. * printcmd.c (printf_command): Update. * p-exp.y (yylex): Update. * objc-exp.y (yylex): Update. * mi/mi-parse.c: Include charset.h. (mi_parse_escape): New function. (mi_parse_argv): Use it. * jv-exp.y (yylex): Update. * i386-cygwin-tdep.c (i386_cygwin_auto_wide_charset): New function. (i386_cygwin_init_abi): Call set_gdbarch_auto_wide_charset. * gdbarch.sh (auto_charset, auto_wide_charset): New. * gdbarch.c: Rebuild. * gdbarch.h: Rebuild. * defs.h (parse_escape): Update. * cli/cli-setshow.c: Include arch-utils.h. (do_setshow_command): Update. * cli/cli-cmds.c (echo_command): Update. * charset.h (target_charset, target_wide_charset): Update. * charset.c: Include arch-utils.h. (target_charset_name): Default to "auto". (target_wide_charset_name): Likewise. (show_target_charset_name): Handle "auto". (show_target_wide_charset_name): Likewise. (be_le_arch): New global. (set_be_le_names): Add 'gdbarch' argument. (validate): Likewise. Don't call set_be_le_names. (set_charset_sfunc, set_host_charset_sfunc) (set_target_charset_sfunc, set_target_wide_charset_sfunc): Update. (target_charset): Add 'gdbarch' argument. (target_wide_charset): Likewise. Remove 'byte_order' argument. (auto_target_charset_name): New global. (default_auto_charset, default_auto_wide_charset): New functions. (_initialize_charset): Set auto_target_charset_name. Allow "auto" for target charsets. Copy result of nl_langinfo. Use GetACP if USE_WIN32API. * c-lang.c (charset_for_string_type): Add 'gdbarch' argument, remove 'byte_order' argument. Update. (classify_type): Likewise. (c_emit_char): Update. (c_printchar): Update. (c_printstr): Update. (c_get_string): Update. (evaluate_subexp_c): Update. * arch-utils.h (default_auto_charset, default_auto_wide_charset): Declare. * python/python.c (gdbpy_target_charset): New function. (gdbpy_target_wide_charset): Likewise. (GdbMethods): Update. * NEWS: Update. gdb/doc * gdb.texinfo (Basic Python): Document target_charset and target_wide_charset. gdb/testsuite * gdb.python/py-prettyprint.py (pp_nullstr.to_string): Use gdb.target_charset. (pp_ns.to_string): Likewise. --- gdb/python/py-utils.c | 8 +++++--- gdb/python/python.c | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) (limited to 'gdb/python') diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 4ccf97f..aed8fff 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -129,7 +129,8 @@ unicode_to_encoded_python_string (PyObject *unicode_str, const char *charset) char * unicode_to_target_string (PyObject *unicode_str) { - return unicode_to_encoded_string (unicode_str, target_charset ()); + return unicode_to_encoded_string (unicode_str, + target_charset (python_gdbarch)); } /* Returns a PyObject with the contents of the given unicode string @@ -139,7 +140,8 @@ unicode_to_target_string (PyObject *unicode_str) PyObject * unicode_to_target_python_string (PyObject *unicode_str) { - return unicode_to_encoded_python_string (unicode_str, target_charset ()); + return unicode_to_encoded_python_string (unicode_str, + target_charset (python_gdbarch)); } /* Converts a python string (8-bit or unicode) to a target string in @@ -208,7 +210,7 @@ target_string_to_unicode (const gdb_byte *str, int length) if (length == -1) length = strlen (str); - return PyUnicode_Decode (str, length, target_charset (), NULL); + return PyUnicode_Decode (str, length, target_charset (python_gdbarch), NULL); } /* Return true if OBJ is a Python string or unicode object, false diff --git a/gdb/python/python.c b/gdb/python/python.c index 3d38de6..9a89eed 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -283,6 +283,24 @@ gdbpy_parameter (PyObject *self, PyObject *args) return parameter_to_python (cmd); } +/* Wrapper for target_charset. */ + +static PyObject * +gdbpy_target_charset (PyObject *self, PyObject *args) +{ + const char *cset = target_charset (python_gdbarch); + return PyUnicode_Decode (cset, strlen (cset), host_charset (), NULL); +} + +/* Wrapper for target_wide_charset. */ + +static PyObject * +gdbpy_target_wide_charset (PyObject *self, PyObject *args) +{ + const char *cset = target_wide_charset (python_gdbarch); + return PyUnicode_Decode (cset, strlen (cset), host_charset (), NULL); +} + /* A Python function which evaluates a string using the gdb CLI. */ static PyObject * @@ -740,6 +758,13 @@ a boolean indicating if name is a field of the current implied argument\n\ Parse String as an expression, evaluate it, and return the result as a Value." }, + { "target_charset", gdbpy_target_charset, METH_NOARGS, + "target_charset () -> string.\n\ +Return the name of the current target charset." }, + { "target_wide_charset", gdbpy_target_wide_charset, METH_NOARGS, + "target_wide_charset () -> string.\n\ +Return the name of the current target wide charset." }, + { "write", gdbpy_write, METH_VARARGS, "Write a string using gdb's filtered stream." }, { "flush", gdbpy_flush, METH_NOARGS, -- cgit v1.1