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

« back to all changes in this revision

Viewing changes to gdb/varobj.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
/* Implementation of the GDB variable objects API.
2
2
 
3
3
   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4
 
   2009 Free Software Foundation, Inc.
 
4
   2009, 2010 Free Software Foundation, Inc.
5
5
 
6
6
   This program is free software; you can redistribute it and/or modify
7
7
   it under the terms of the GNU General Public License as published by
293
293
 
294
294
static int is_root_p (struct varobj *var);
295
295
 
 
296
#if HAVE_PYTHON
 
297
 
296
298
static struct varobj *
297
299
varobj_add_child (struct varobj *var, const char *name, struct value *value);
298
300
 
 
301
#endif /* HAVE_PYTHON */
 
302
 
299
303
/* C implementation */
300
304
 
301
305
static int c_number_of_children (struct varobj *var);
759
763
  return delcount;
760
764
}
761
765
 
 
766
#if HAVE_PYTHON
 
767
 
762
768
/* Convenience function for varobj_set_visualizer.  Instantiate a
763
769
   pretty-printer for a given value.  */
764
770
static PyObject *
765
771
instantiate_pretty_printer (PyObject *constructor, struct value *value)
766
772
{
767
 
#if HAVE_PYTHON
768
773
  PyObject *val_obj = NULL; 
769
774
  PyObject *printer;
770
775
 
775
780
  printer = PyObject_CallFunctionObjArgs (constructor, val_obj, NULL);
776
781
  Py_DECREF (val_obj);
777
782
  return printer;
778
 
#endif
779
783
  return NULL;
780
784
}
781
785
 
 
786
#endif
 
787
 
782
788
/* Set/Get variable object display format */
783
789
 
784
790
enum varobj_display_formats
899
905
    }
900
906
}
901
907
 
 
908
#if HAVE_PYTHON
 
909
 
902
910
/* A helper for update_dynamic_varobj_children that installs a new
903
911
   child when needed.  */
904
912
 
935
943
    }
936
944
}
937
945
 
938
 
#if HAVE_PYTHON
939
 
 
940
946
static int
941
947
dynamic_varobj_has_child_method (struct varobj *var)
942
948
{
1158
1164
  return var->children;
1159
1165
}
1160
1166
 
 
1167
#if HAVE_PYTHON
 
1168
 
1161
1169
static struct varobj *
1162
1170
varobj_add_child (struct varobj *var, const char *name, struct value *value)
1163
1171
{
1168
1176
  return v;
1169
1177
}
1170
1178
 
 
1179
#endif /* HAVE_PYTHON */
 
1180
 
1171
1181
/* Obtain the type of an object Variable as a string similar to the one gdb
1172
1182
   prints on the console */
1173
1183
 
1583
1593
    {
1584
1594
      xfree (print_value);
1585
1595
      print_value = value_get_print_value (var->value, var->format, var);
1586
 
      if (!var->print_value || strcmp (var->print_value, print_value) != 0)
 
1596
      if ((var->print_value == NULL && print_value != NULL)
 
1597
          || (var->print_value != NULL && print_value == NULL)
 
1598
          || (var->print_value != NULL && print_value != NULL
 
1599
              && strcmp (var->print_value, print_value) != 0))
1587
1600
        changed = 1;
1588
1601
    }
1589
1602
  if (var->print_value)
1690
1703
 
1691
1704
  if (!(*varp)->root->is_valid)
1692
1705
    {
1693
 
      varobj_update_result r = {*varp};
 
1706
      varobj_update_result r = {0};
 
1707
      r.varobj = *varp;
1694
1708
      r.status = VAROBJ_INVALID;
1695
1709
      VEC_safe_push (varobj_update_result, result, &r);
1696
1710
      return result;
1698
1712
 
1699
1713
  if ((*varp)->root->rootvar == *varp)
1700
1714
    {
1701
 
      varobj_update_result r = {*varp};
 
1715
      varobj_update_result r = {0};
 
1716
      r.varobj = *varp;
1702
1717
      r.status = VAROBJ_IN_SCOPE;
1703
1718
 
1704
1719
      /* Update the root variable. value_of_root can return NULL
1728
1743
    }
1729
1744
  else
1730
1745
    {
1731
 
      varobj_update_result r = {*varp};
 
1746
      varobj_update_result r = {0};
 
1747
      r.varobj = *varp;
1732
1748
      VEC_safe_push (varobj_update_result, stack, &r);
1733
1749
    }
1734
1750
 
1805
1821
              for (i = VEC_length (varobj_p, changed) - 1; i >= 0; --i)
1806
1822
                {
1807
1823
                  varobj_p tmp = VEC_index (varobj_p, changed, i);
1808
 
                  varobj_update_result r = {tmp};
 
1824
                  varobj_update_result r = {0};
 
1825
                  r.varobj = tmp;
1809
1826
                  r.changed = 1;
1810
1827
                  r.value_installed = 1;
1811
1828
                  VEC_safe_push (varobj_update_result, stack, &r);
1815
1832
                  varobj_p tmp = VEC_index (varobj_p, unchanged, i);
1816
1833
                  if (!tmp->frozen)
1817
1834
                    {
1818
 
                      varobj_update_result r = {tmp};
 
1835
                      varobj_update_result r = {0};
 
1836
                      r.varobj = tmp;
1819
1837
                      r.value_installed = 1;
1820
1838
                      VEC_safe_push (varobj_update_result, stack, &r);
1821
1839
                    }
1842
1860
          /* Child may be NULL if explicitly deleted by -var-delete.  */
1843
1861
          if (c != NULL && !c->frozen)
1844
1862
            {
1845
 
              varobj_update_result r = {c};
 
1863
              varobj_update_result r = {0};
 
1864
              r.varobj = c;
1846
1865
              VEC_safe_push (varobj_update_result, stack, &r);
1847
1866
            }
1848
1867
        }
2453
2472
  struct cleanup *old_chain;
2454
2473
  gdb_byte *thevalue = NULL;
2455
2474
  struct value_print_options opts;
2456
 
  int len = 0;
 
2475
  struct type *type = NULL;
 
2476
  long len = 0;
 
2477
  char *encoding = NULL;
 
2478
  struct gdbarch *gdbarch = NULL;
2457
2479
 
2458
2480
  if (value == NULL)
2459
2481
    return NULL;
2460
2482
 
 
2483
  gdbarch = get_type_arch (value_type (value));
2461
2484
#if HAVE_PYTHON
2462
2485
  {
2463
2486
    struct cleanup *back_to = varobj_ensure_python_env (var);
2489
2512
                                                  &replacement);
2490
2513
            if (output)
2491
2514
              {
2492
 
                PyObject *py_str
2493
 
                  = python_string_to_target_python_string (output);
2494
 
                if (py_str)
2495
 
                  {
2496
 
                    char *s = PyString_AsString (py_str);
2497
 
                    len = PyString_Size (py_str);
2498
 
                    thevalue = xmemdup (s, len + 1, len + 1);
2499
 
                    Py_DECREF (py_str);
 
2515
                if (gdbpy_is_lazy_string (output))
 
2516
                  {
 
2517
                    thevalue = gdbpy_extract_lazy_string (output, &type,
 
2518
                                                          &len, &encoding);
 
2519
                    string_print = 1;
 
2520
                  }
 
2521
                else
 
2522
                  {
 
2523
                    PyObject *py_str
 
2524
                      = python_string_to_target_python_string (output);
 
2525
                    if (py_str)
 
2526
                      {
 
2527
                        char *s = PyString_AsString (py_str);
 
2528
                        len = PyString_Size (py_str);
 
2529
                        thevalue = xmemdup (s, len + 1, len + 1);
 
2530
                        type = builtin_type (gdbarch)->builtin_char;
 
2531
                        Py_DECREF (py_str);
 
2532
                      }
2500
2533
                  }
2501
2534
                Py_DECREF (output);
2502
2535
              }
2503
2536
            if (thevalue && !string_print)
2504
2537
              {
2505
2538
                do_cleanups (back_to);
 
2539
                xfree (encoding);
2506
2540
                return thevalue;
2507
2541
              }
2508
2542
            if (replacement)
2521
2555
  opts.raw = 1;
2522
2556
  if (thevalue)
2523
2557
    {
2524
 
      struct gdbarch *gdbarch = get_type_arch (value_type (value));
2525
2558
      make_cleanup (xfree, thevalue);
2526
 
      LA_PRINT_STRING (stb, builtin_type (gdbarch)->builtin_char,
2527
 
                       thevalue, len, 0, &opts);
 
2559
      make_cleanup (xfree, encoding);
 
2560
      LA_PRINT_STRING (stb, type, thevalue, len, encoding, 0, &opts);
2528
2561
    }
2529
2562
  else
2530
2563
    common_val_print (value, stb, 0, &opts, current_language);
2793
2826
    {
2794
2827
    case TYPE_CODE_ARRAY:
2795
2828
      if (cname)
2796
 
        *cname = xstrprintf ("%d", index
2797
 
                             + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
 
2829
        *cname = xstrdup (int_string (index 
 
2830
                                      + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
 
2831
                                      10, 1, 0, 0));
2798
2832
 
2799
2833
      if (cvalue && value)
2800
2834
        {
2806
2840
        *ctype = get_target_type (type);
2807
2841
 
2808
2842
      if (cfull_expression)
2809
 
        *cfull_expression = xstrprintf ("(%s)[%d]", parent_expression, 
2810
 
                                        index
2811
 
                                        + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)));
 
2843
        *cfull_expression = 
 
2844
          xstrprintf ("(%s)[%s]", parent_expression, 
 
2845
                      int_string (index
 
2846
                                  + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)),
 
2847
                                  10, 1, 0, 0));
2812
2848
 
2813
2849
 
2814
2850
      break;
3103
3139
static void
3104
3140
cplus_class_num_children (struct type *type, int children[3])
3105
3141
{
3106
 
  int i;
 
3142
  int i, vptr_fieldno;
 
3143
  struct type *basetype = NULL;
3107
3144
 
3108
3145
  children[v_public] = 0;
3109
3146
  children[v_private] = 0;
3110
3147
  children[v_protected] = 0;
3111
3148
 
 
3149
  vptr_fieldno = get_vptr_fieldno (type, &basetype);
3112
3150
  for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
3113
3151
    {
3114
 
      /* If we have a virtual table pointer, omit it. */
3115
 
      if (TYPE_VPTR_BASETYPE (type) == type && TYPE_VPTR_FIELDNO (type) == i)
 
3152
      /* If we have a virtual table pointer, omit it.  Even if virtual
 
3153
         table pointers are not specifically marked in the debug info,
 
3154
         they should be artificial.  */
 
3155
      if ((type == basetype && i == vptr_fieldno)
 
3156
          || TYPE_FIELD_ARTIFICIAL (type, i))
3116
3157
        continue;
3117
3158
 
3118
3159
      if (TYPE_FIELD_PROTECTED (type, i))
3199
3240
             find the indexed field. */
3200
3241
          int type_index = TYPE_N_BASECLASSES (type);
3201
3242
          enum accessibility acc = public_field;
 
3243
          int vptr_fieldno;
 
3244
          struct type *basetype = NULL;
 
3245
 
 
3246
          vptr_fieldno = get_vptr_fieldno (type, &basetype);
3202
3247
          if (strcmp (parent->name, "private") == 0)
3203
3248
            acc = private_field;
3204
3249
          else if (strcmp (parent->name, "protected") == 0)
3206
3251
 
3207
3252
          while (index >= 0)
3208
3253
            {
3209
 
              if (TYPE_VPTR_BASETYPE (type) == type
3210
 
                  && type_index == TYPE_VPTR_FIELDNO (type))
 
3254
              if ((type == basetype && type_index == vptr_fieldno)
 
3255
                  || TYPE_FIELD_ARTIFICIAL (type, type_index))
3211
3256
                ; /* ignore vptr */
3212
3257
              else if (match_accessibility (type, type_index, acc))
3213
3258
                    --index;