~ubuntu-branches/debian/jessie/gdb/jessie

« back to all changes in this revision

Viewing changes to gdb/python/py-value.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Jacobowitz
  • Date: 2010-03-20 01:21:29 UTC
  • mfrom: (1.3.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100320012129-t7h25y8zgr8c2369
Tags: 7.1-1
* New upstream release, including:
  - PIE support (Closes: #346409).
  - C++ improvements, including static_cast<> et al, namespace imports,
    and bug fixes in printing virtual base classes.
  - Multi-program debugging.  One GDB can now debug multiple programs
    at the same time.
  - Python scripting improvements, including gdb.parse_and_eval.
  - Updated MIPS Linux signal frame layout (Closes: #570875).
  - No internal error stepping over _dl_debug_state (Closes: #569551).
* Update to Standards-Version: 3.8.4 (no changes required).
* Include more relevant (and smaller) docs in the gdbserver package
  (Closes: #571132).
* Do not duplicate documentation in gdb64, gdb-source, and libgdb-dev.
* Fix crash when switching into TUI mode (Closes: #568489).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Python interface to values.
2
2
 
3
 
   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
 
3
   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
4
4
 
5
5
   This file is part of GDB.
6
6
 
220
220
  return obj->type;
221
221
}
222
222
 
 
223
/* Implementation of gdb.Value.lazy_string ([encoding] [, length]) ->
 
224
   string.  Return a PyObject representing a lazy_string_object type.
 
225
   A lazy string is a pointer to a string with an optional encoding and
 
226
   length.  If ENCODING is not given, encoding is set to None.  If an
 
227
   ENCODING is provided the encoding parameter is set to ENCODING, but
 
228
   the string is not encoded.  If LENGTH is provided then the length
 
229
   parameter is set to LENGTH, otherwise length will be set to -1 (first
 
230
   null of appropriate with).  */
 
231
static PyObject *
 
232
valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
 
233
{
 
234
  int length = -1;
 
235
  struct value *value = ((value_object *) self)->value;
 
236
  const char *user_encoding = NULL;
 
237
  static char *keywords[] = { "encoding", "length", NULL };
 
238
  PyObject *str_obj;
 
239
 
 
240
  if (!PyArg_ParseTupleAndKeywords (args, kw, "|si", keywords,
 
241
                                    &user_encoding, &length))
 
242
    return NULL;
 
243
 
 
244
  if (TYPE_CODE (value_type (value)) == TYPE_CODE_PTR)
 
245
    value = value_ind (value);
 
246
 
 
247
  str_obj = gdbpy_create_lazy_string_object (value_address (value), length,
 
248
                                             user_encoding, value_type (value));
 
249
 
 
250
  return (PyObject *) str_obj;
 
251
}
 
252
 
223
253
/* Implementation of gdb.Value.string ([encoding] [, errors]
224
254
   [, length]) -> string.  Return Unicode string with value contents.
225
255
   If ENCODING is not given, the string is assumed to be encoded in
238
268
  const char *errors = NULL;
239
269
  const char *user_encoding = NULL;
240
270
  const char *la_encoding = NULL;
 
271
  struct type *char_type;
241
272
  static char *keywords[] = { "encoding", "errors", "length", NULL };
242
273
 
243
274
  if (!PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
246
277
 
247
278
  TRY_CATCH (except, RETURN_MASK_ALL)
248
279
    {
249
 
      LA_GET_STRING (value, &buffer, &length, &la_encoding);
 
280
      LA_GET_STRING (value, &buffer, &length, &char_type, &la_encoding);
250
281
    }
251
282
  GDB_PY_HANDLE_EXCEPTION (except);
252
283
 
253
284
  encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding;
254
 
  unicode = PyUnicode_Decode (buffer, length, encoding, errors);
 
285
  unicode = PyUnicode_Decode (buffer, length * TYPE_LENGTH (char_type),
 
286
                              encoding, errors);
255
287
  xfree (buffer);
256
288
 
257
289
  return unicode;
937
969
        }
938
970
      else if (PyObject_TypeCheck (obj, &value_object_type))
939
971
        value = value_copy (((value_object *) obj)->value);
 
972
      else if (gdbpy_is_lazy_string (obj))
 
973
        {
 
974
          PyObject *result;
 
975
          PyObject *function = PyString_FromString ("value");
 
976
          result = PyObject_CallMethodObjArgs (obj, function,  NULL);
 
977
          value = value_copy (((value_object *) result)->value);
 
978
        }
940
979
      else
941
980
        PyErr_Format (PyExc_TypeError, _("Could not convert Python object: %s"),
942
981
                      PyString_AsString (PyObject_Str (obj)));
999
1038
static PyMethodDef value_object_methods[] = {
1000
1039
  { "cast", valpy_cast, METH_VARARGS, "Cast the value to the supplied type." },
1001
1040
  { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
 
1041
  { "lazy_string", (PyCFunction) valpy_lazy_string, METH_VARARGS | METH_KEYWORDS,
 
1042
    "lazy_string ([encoding]  [, length]) -> lazy_string\n\
 
1043
Return a lazy string representation of the value." },
1002
1044
  { "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS,
1003
1045
    "string ([encoding] [, errors] [, length]) -> string\n\
1004
1046
Return Unicode string representation of the value." },