| |   |
| 33 | 33 | #include "cli/cli-decode.h" |
| 34 | 34 | #include "cli/cli-script.h" |
| 35 | 35 | #include "gdb_assert.h" |
| 36 | |
| 37 | #ifdef HAVE_PYTHON |
| 36 | 38 | #include "python/python.h" |
| 39 | #endif |
| 37 | 40 | |
| 38 | 41 | /* Prototypes for local functions */ |
| 39 | 42 | |
| … | … | |
| 229 | 229 | continue; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | #ifdef HAVE_PYTHON |
| 232 | 233 | if (list->control_type == python_control) |
| 233 | 234 | { |
| 234 | 235 | ui_out_field_string (uiout, NULL, "python"); |
| … | … | |
| 241 | 241 | list = list->next; |
| 242 | 242 | continue; |
| 243 | 243 | } |
| 244 | #endif |
| 244 | 245 | |
| 245 | 246 | /* ignore illegal command type and try next */ |
| 246 | 247 | list = list->next; |
| … | … | |
| 546 | 546 | break; |
| 547 | 547 | } |
| 548 | 548 | case python_control: |
| 549 | #ifdef HAVE_PYTHON |
| 549 | 550 | { |
| 550 | 551 | eval_python_from_control_command (cmd); |
| 551 | 552 | ret = simple_control; |
| 552 | 553 | break; |
| 553 | 554 | } |
| 555 | #else |
| 556 | warning (_("Python scripting is not supported in this copy of GDB.")); |
| 557 | break; |
| 558 | #endif |
| 554 | 559 | |
| 555 | 560 | default: |
| 556 | 561 | warning (_("Invalid control type in canned commands structure.")); |
| … | … | |
| 925 | 925 | first_arg++; |
| 926 | 926 | *command = build_command_line (commands_control, first_arg); |
| 927 | 927 | } |
| 928 | #ifdef HAVE_PYTHON |
| 928 | 929 | else if (p1 - p == 6 && !strncmp (p, "python", 6)) |
| 929 | 930 | { |
| 930 | 931 | /* Note that we ignore the inline "python command" form |
| 931 | 932 | here. */ |
| 932 | 933 | *command = build_command_line (python_control, ""); |
| 933 | 934 | } |
| 935 | #endif |
| 934 | 936 | else if (p1 - p == 10 && !strncmp (p, "loop_break", 10)) |
| 935 | 937 | { |
| 936 | 938 | *command = (struct command_line *) |
| … | … | |
| 1013 | 1013 | { |
| 1014 | 1014 | if (current_cmd->control_type == while_control |
| 1015 | 1015 | || current_cmd->control_type == if_control |
| 1016 | | || current_cmd->control_type == commands_control |
| 1017 | | || current_cmd->control_type == python_control) |
| 1016 | #ifdef HAVE_PYTHON |
| 1017 | || current_cmd->control_type == python_control |
| 1018 | #endif |
| 1019 | || current_cmd->control_type == commands_control) |
| 1018 | 1020 | { |
| 1019 | 1021 | /* Success reading an entire canned sequence of commands. */ |
| 1020 | 1022 | ret = simple_control; |
| … | … | |
| 1067 | 1067 | on it. */ |
| 1068 | 1068 | if (next->control_type == while_control |
| 1069 | 1069 | || next->control_type == if_control |
| 1070 | | || next->control_type == commands_control |
| 1071 | | || next->control_type == python_control) |
| 1070 | #ifdef HAVE_PYTHON |
| 1071 | || next->control_type == python_control |
| 1072 | #endif |
| 1073 | || next->control_type == commands_control) |
| 1072 | 1074 | { |
| 1073 | 1075 | control_level++; |
| 1074 | 1076 | ret = recurse_read_control_structure (next); |
| … | … | |
| 1143 | 1143 | |
| 1144 | 1144 | if (next->control_type == while_control |
| 1145 | 1145 | || next->control_type == if_control |
| 1146 | | || next->control_type == commands_control |
| 1147 | | || next->control_type == python_control) |
| 1146 | #ifdef HAVE_PYTHON |
| 1147 | || next->control_type == python_control |
| 1148 | #endif |
| 1149 | || next->control_type == commands_control) |
| 1148 | 1150 | { |
| 1149 | 1151 | control_level++; |
| 1150 | 1152 | ret = recurse_read_control_structure (next); |
| toggle raw diff |
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -33,7 +33,10 @@
#include "cli/cli-decode.h"
#include "cli/cli-script.h"
#include "gdb_assert.h"
+
+#ifdef HAVE_PYTHON
#include "python/python.h"
+#endif
/* Prototypes for local functions */
@@ -226,6 +229,7 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd,
continue;
}
+#ifdef HAVE_PYTHON
if (list->control_type == python_control)
{
ui_out_field_string (uiout, NULL, "python");
@@ -237,6 +241,7 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd,
list = list->next;
continue;
}
+#endif
/* ignore illegal command type and try next */
list = list->next;
@@ -541,11 +546,16 @@ execute_control_command (struct command_line *cmd)
break;
}
case python_control:
+#ifdef HAVE_PYTHON
{
eval_python_from_control_command (cmd);
ret = simple_control;
break;
}
+#else
+ warning (_("Python scripting is not supported in this copy of GDB."));
+ break;
+#endif
default:
warning (_("Invalid control type in canned commands structure."));
@@ -915,12 +925,14 @@ read_next_line (struct command_line **command, int special_processing)
first_arg++;
*command = build_command_line (commands_control, first_arg);
}
+#ifdef HAVE_PYTHON
else if (p1 - p == 6 && !strncmp (p, "python", 6))
{
/* Note that we ignore the inline "python command" form
here. */
*command = build_command_line (python_control, "");
}
+#endif
else if (p1 - p == 10 && !strncmp (p, "loop_break", 10))
{
*command = (struct command_line *)
@@ -1001,8 +1013,10 @@ recurse_read_control_structure (struct command_line *current_cmd)
{
if (current_cmd->control_type == while_control
|| current_cmd->control_type == if_control
- || current_cmd->control_type == commands_control
- || current_cmd->control_type == python_control)
+#ifdef HAVE_PYTHON
+ || current_cmd->control_type == python_control
+#endif
+ || current_cmd->control_type == commands_control)
{
/* Success reading an entire canned sequence of commands. */
ret = simple_control;
@@ -1053,8 +1067,10 @@ recurse_read_control_structure (struct command_line *current_cmd)
on it. */
if (next->control_type == while_control
|| next->control_type == if_control
- || next->control_type == commands_control
- || next->control_type == python_control)
+#ifdef HAVE_PYTHON
+ || next->control_type == python_control
+#endif
+ || next->control_type == commands_control)
{
control_level++;
ret = recurse_read_control_structure (next);
@@ -1127,8 +1143,10 @@ read_command_lines (char *prompt_arg, int from_tty, int special_processing)
if (next->control_type == while_control
|| next->control_type == if_control
- || next->control_type == commands_control
- || next->control_type == python_control)
+#ifdef HAVE_PYTHON
+ || next->control_type == python_control
+#endif
+ || next->control_type == commands_control)
{
control_level++;
ret = recurse_read_control_structure (next); |
| |   |
| 161 | 161 | { "var-list-children", { NULL, 0 }, 0, mi_cmd_var_list_children}, |
| 162 | 162 | { "var-set-format", { NULL, 0 }, 0, mi_cmd_var_set_format}, |
| 163 | 163 | { "var-set-frozen", { NULL, 0 }, 0, mi_cmd_var_set_frozen}, |
| 164 | #ifdef HAVE_PYTHON |
| 164 | 165 | { "var-set-type-visualizer", { NULL, 0 }, 0, mi_cmd_var_set_type_visualizer}, |
| 165 | 166 | { "var-clear-type-visualizers", { NULL, 0 }, 0, |
| 166 | 167 | mi_cmd_var_clear_type_visualizers}, |
| 167 | 168 | { "var-set-visualizer", { NULL, 0 }, 0, mi_cmd_var_set_visualizer}, |
| 169 | #endif |
| 168 | 170 | { "var-show-attributes", { NULL, 0 }, 0, mi_cmd_var_show_attributes}, |
| 169 | 171 | { "var-show-format", { NULL, 0 }, 0, mi_cmd_var_show_format}, |
| 170 | 172 | { "var-update", { NULL, 0 }, 0, mi_cmd_var_update}, |
| toggle raw diff |
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -161,10 +161,12 @@ struct mi_cmd mi_cmds[] =
{ "var-list-children", { NULL, 0 }, 0, mi_cmd_var_list_children},
{ "var-set-format", { NULL, 0 }, 0, mi_cmd_var_set_format},
{ "var-set-frozen", { NULL, 0 }, 0, mi_cmd_var_set_frozen},
+#ifdef HAVE_PYTHON
{ "var-set-type-visualizer", { NULL, 0 }, 0, mi_cmd_var_set_type_visualizer},
{ "var-clear-type-visualizers", { NULL, 0 }, 0,
mi_cmd_var_clear_type_visualizers},
{ "var-set-visualizer", { NULL, 0 }, 0, mi_cmd_var_set_visualizer},
+#endif
{ "var-show-attributes", { NULL, 0 }, 0, mi_cmd_var_show_attributes},
{ "var-show-format", { NULL, 0 }, 0, mi_cmd_var_show_format},
{ "var-update", { NULL, 0 }, 0, mi_cmd_var_update}, |
| |   |
| 33 | 33 | #include "varobj.h" |
| 34 | 34 | #include "vec.h" |
| 35 | 35 | |
| 36 | #ifdef HAVE_PYTHON |
| 36 | 37 | #include "python/python.h" |
| 37 | 38 | #include "python/python-internal.h" |
| 39 | #endif |
| 38 | 40 | |
| 39 | 41 | /* Non-zero if we want to see trace of varobj level stuff. */ |
| 40 | 42 | |
| … | … | |
| 132 | 132 | /* Children of this object. */ |
| 133 | 133 | VEC (varobj_p) *children; |
| 134 | 134 | |
| 135 | #ifdef HAVE_PYTHON |
| 135 | 136 | /* Whether the children of this varobj were requested. This field is |
| 136 | 137 | used to decide if dynamic varobj should recompute their children. |
| 137 | 138 | In the event that the frontend never asked for the children, we |
| 138 | 139 | can avoid that. */ |
| 139 | 140 | int children_requested; |
| 141 | #endif |
| 140 | 142 | |
| 141 | 143 | /* Description of the root variable. Points to root variable for children. */ |
| 142 | 144 | struct varobj_root *root; |
| … | … | |
| 162 | 162 | frozen. */ |
| 163 | 163 | int not_fetched; |
| 164 | 164 | |
| 165 | #ifdef HAVE_PYTHON |
| 165 | 166 | /* A Python object used to visualize this variable object. |
| 166 | 167 | FIXME: free this in dtor. |
| 167 | 168 | */ |
| 168 | 169 | PyObject *value_formatter; |
| 169 | 170 | PyObject *children_lister; |
| 171 | #endif |
| 170 | 172 | }; |
| 171 | 173 | |
| 172 | 174 | struct cpstack |
| … | … | |
| 185 | 185 | struct vlist *next; |
| 186 | 186 | }; |
| 187 | 187 | |
| 188 | #ifdef HAVE_PYTHON |
| 188 | 189 | typedef struct type_visualizer |
| 189 | 190 | { |
| 190 | 191 | char *type_regexp; |
| … | … | |
| 193 | 193 | } type_visualizer; |
| 194 | 194 | |
| 195 | 195 | DEF_VEC_O (type_visualizer); |
| 196 | #endif |
| 196 | 197 | |
| 197 | 198 | /* Private function prototypes */ |
| 198 | 199 | |
| … | … | |
| 239 | 239 | static int install_new_value (struct varobj *var, struct value *value, |
| 240 | 240 | int initial); |
| 241 | 241 | |
| 242 | #ifdef HAVE_PYTHON |
| 242 | 243 | static void install_default_visualizer (struct varobj *var); |
| 244 | #endif |
| 243 | 245 | |
| 244 | 246 | static struct value * |
| 245 | 247 | value_struct_element_by_name (struct value *value, const char *name); |
| … | … | |
| 263 | 263 | static char *my_value_of_variable (struct varobj *var); |
| 264 | 264 | |
| 265 | 265 | static char *value_get_print_value (struct value *value, |
| 266 | | enum varobj_display_formats format, |
| 267 | | PyObject *value_formatter); |
| 266 | enum varobj_display_formats format |
| 267 | #ifdef HAVE_PYTHON |
| 268 | , PyObject *value_formatter |
| 269 | #endif |
| 270 | ); |
| 268 | 271 | |
| 269 | 272 | static int varobj_value_is_changeable_p (struct varobj *var); |
| 270 | 273 | |
| … | … | |
| 436 | 436 | /* Pointer to the varobj hash table (built at run time) */ |
| 437 | 437 | static struct vlist **varobj_table; |
| 438 | 438 | |
| 439 | #ifdef HAVE_PYTHON |
| 439 | 440 | static VEC (type_visualizer) *type_visualizers = NULL; |
| 441 | #endif |
| 440 | 442 | |
| 441 | 443 | /* Is the variable X one of our "fake" children? */ |
| 442 | 444 | #define CPLUS_FAKE_CHILD(x) \ |
| … | … | |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | discard_cleanups (old_chain); |
| 602 | #ifdef HAVE_PYTHON |
| 602 | 603 | install_default_visualizer (var); |
| 604 | #endif |
| 603 | 605 | return var; |
| 604 | 606 | } |
| 605 | 607 | |
| … | … | |
| 731 | 731 | && var->value && !value_lazy (var->value)) |
| 732 | 732 | { |
| 733 | 733 | free (var->print_value); |
| 734 | | var->print_value = value_get_print_value (var->value, var->format, |
| 735 | | var->value_formatter); |
| 734 | var->print_value = value_get_print_value (var->value, var->format |
| 735 | #ifdef HAVE_PYTHON |
| 736 | , var->value_formatter |
| 737 | #endif |
| 738 | ); |
| 736 | 739 | } |
| 737 | 740 | |
| 738 | 741 | return var->format; |
| 739 | 742 | } |
| 740 | 743 | |
| 744 | #ifdef HAVE_PYTHON |
| 741 | 745 | void |
| 742 | 746 | varobj_set_visualizer (struct varobj *var, const char *visualizer) |
| 743 | 747 | { |
| … | … | |
| 823 | 823 | { |
| 824 | 824 | VEC_free (type_visualizer, type_visualizers); |
| 825 | 825 | } |
| 826 | #endif /* HAVE_PYTHON */ |
| 826 | 827 | |
| 827 | 828 | enum varobj_display_formats |
| 828 | 829 | varobj_get_display_format (struct varobj *var) |
| … | … | |
| 860 | 860 | return var->num_children; |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | #ifdef HAVE_PYTHON |
| 863 | 864 | static |
| 864 | 865 | int update_dynamic_varobj_children (struct varobj *var, |
| 865 | 866 | VEC (varobj_p) **changed, |
| … | … | |
| 951 | 951 | |
| 952 | 952 | return children_changed; |
| 953 | 953 | } |
| 954 | #endif /* HAVE_PYTHON */ |
| 954 | 955 | |
| 955 | 956 | /* Creates a list of the immediate children of a variable object; |
| 956 | 957 | the return code is the number of such children or -1 on error */ |
| … | … | |
| 963 | 963 | char *name; |
| 964 | 964 | int i; |
| 965 | 965 | |
| 966 | #ifdef HAVE_PYTHON |
| 966 | 967 | var->children_requested = 1; |
| 967 | 968 | |
| 968 | 969 | if (var->children_lister) |
| … | … | |
| 974 | 974 | update_dynamic_varobj_children (var, NULL, NULL); |
| 975 | 975 | return var->children; |
| 976 | 976 | } |
| 977 | #endif |
| 977 | 978 | |
| 978 | 979 | if (var->num_children == -1) |
| 979 | 980 | var->num_children = number_of_children (var); |
| … | … | |
| 1000 | 1000 | name = name_of_child (var, i); |
| 1001 | 1001 | existing = create_child (var, i, name); |
| 1002 | 1002 | VEC_replace (varobj_p, var->children, i, existing); |
| 1003 | #ifdef HAVE_PYTHON |
| 1003 | 1004 | install_default_visualizer (existing); |
| 1005 | #endif |
| 1004 | 1006 | } |
| 1005 | 1007 | } |
| 1006 | 1008 | |
| 1007 | 1009 | return var->children; |
| 1008 | 1010 | } |
| 1009 | 1011 | |
| 1012 | #ifdef HAVE_PYTHON |
| 1010 | 1013 | struct varobj * |
| 1011 | 1014 | varobj_add_child (struct varobj *var, const char *name, struct value *value) |
| 1012 | 1015 | { |
| … | … | |
| 1020 | 1020 | install_default_visualizer (v); |
| 1021 | 1021 | return v; |
| 1022 | 1022 | } |
| 1023 | #endif |
| 1023 | 1024 | |
| 1024 | 1025 | /* Obtain the type of an object Variable as a string similar to the one gdb |
| 1025 | 1026 | prints on the console */ |
| … | … | |
| 1222 | 1222 | gdb_assert (var->type || CPLUS_FAKE_CHILD (var)); |
| 1223 | 1223 | changeable = varobj_value_is_changeable_p (var); |
| 1224 | 1224 | |
| 1225 | #ifdef HAVE_PYTHON |
| 1225 | 1226 | /* If the type has custom visualizer, we consider it to be always |
| 1226 | 1227 | changeable. FIXME: need to make sure this behaviour will not |
| 1227 | 1228 | mess up read-sensitive values. */ |
| 1228 | 1229 | if (var->value_formatter || var->children_lister) |
| 1229 | 1230 | changeable = 1; |
| 1231 | #endif |
| 1230 | 1232 | |
| 1231 | 1233 | need_to_fetch = changeable; |
| 1232 | 1234 | |
| … | … | |
| 1287 | 1287 | should not be fetched. */ |
| 1288 | 1288 | if (value && !value_lazy (value)) |
| 1289 | 1289 | { |
| 1290 | | print_value = value_get_print_value (value, var->format, |
| 1291 | | var->value_formatter); |
| 1290 | print_value = value_get_print_value (value, var->format |
| 1291 | #ifdef HAVE_PYTHON |
| 1292 | , var->value_formatter |
| 1293 | #endif |
| 1294 | ); |
| 1292 | 1295 | } |
| 1293 | 1296 | |
| 1294 | 1297 | /* If the type is changeable, compare the old and the new values. |
| … | … | |
| 1357 | 1357 | return changed; |
| 1358 | 1358 | } |
| 1359 | 1359 | |
| 1360 | #ifdef HAVE_PYTHON |
| 1360 | 1361 | void install_default_visualizer (struct varobj *var) |
| 1361 | 1362 | { |
| 1362 | 1363 | char *type = varobj_get_type (var); |
| … | … | |
| 1377 | 1377 | xfree (type); |
| 1378 | 1378 | } |
| 1379 | 1379 | } |
| 1380 | #endif |
| 1380 | 1381 | |
| 1381 | 1382 | /* Update the values for a variable and its children. This is a |
| 1382 | 1383 | two-pronged attack. First, re-parse the value for the root's |
| … | … | |
| 1456 | 1456 | r.status = VAROBJ_NOT_IN_SCOPE; |
| 1457 | 1457 | r.value_installed = 1; |
| 1458 | 1458 | |
| 1459 | #ifdef HAVE_PYTHON |
| 1459 | 1460 | if (r.type_changed) |
| 1460 | 1461 | install_default_visualizer (*varp); |
| 1462 | #endif |
| 1461 | 1463 | |
| 1462 | 1464 | if (r.status == VAROBJ_NOT_IN_SCOPE) |
| 1463 | 1465 | { |
| … | … | |
| 1495 | 1495 | } |
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | #ifdef HAVE_PYTHON |
| 1498 | 1499 | /* We probably should not get children of a varobj that has |
| 1499 | 1500 | children_lister, but for which -var-list-children was never |
| 1500 | 1501 | invoked. Presumably, such varobj is not yet expanded in the |
| … | … | |
| 1531 | 1531 | VEC_safe_push (varobj_update_result, result, &r); |
| 1532 | 1532 | continue; |
| 1533 | 1533 | } |
| 1534 | #endif /* HAVE_PYTHON */ |
| 1534 | 1535 | |
| 1535 | 1536 | /* Push any children. Use reverse order so that the first |
| 1536 | 1537 | child is popped from the work stack first, and so |
| … | … | |
| 1817 | 1817 | var->print_value = NULL; |
| 1818 | 1818 | var->frozen = 0; |
| 1819 | 1819 | var->not_fetched = 0; |
| 1820 | #ifdef HAVE_PYTHON |
| 1820 | 1821 | var->value_formatter = NULL; |
| 1821 | 1822 | var->children_lister = NULL; |
| 1822 | 1823 | var->children_requested = 0; |
| 1824 | #endif |
| 1823 | 1825 | |
| 1824 | 1826 | return var; |
| 1825 | 1827 | } |
| … | … | |
| 1854 | 1854 | xfree (var->root); |
| 1855 | 1855 | } |
| 1856 | 1856 | |
| 1857 | #ifdef HAVE_PYTHON |
| 1857 | 1858 | Py_XDECREF (var->value_formatter); |
| 1858 | 1859 | Py_XDECREF (var->children_lister); |
| 1860 | #endif |
| 1859 | 1861 | |
| 1860 | 1862 | xfree (var->name); |
| 1861 | 1863 | xfree (var->obj_name); |
| … | … | |
| 2130 | 2130 | } |
| 2131 | 2131 | |
| 2132 | 2132 | static char * |
| 2133 | | value_get_print_value (struct value *value, enum varobj_display_formats format, |
| 2134 | | PyObject *value_formatter) |
| 2133 | value_get_print_value (struct value *value, enum varobj_display_formats format |
| 2134 | #ifdef HAVE_PYTHON |
| 2135 | /* FIXME: this ifdef block is very ugly! */ |
| 2136 | , PyObject *value_formatter |
| 2137 | #endif |
| 2138 | ) |
| 2135 | 2139 | { |
| 2136 | 2140 | long dummy; |
| 2137 | 2141 | struct ui_file *stb; |
| … | … | |
| 2145 | 2145 | if (value == NULL) |
| 2146 | 2146 | return NULL; |
| 2147 | 2147 | |
| 2148 | #ifdef HAVE_PYTHON |
| 2148 | 2149 | if (value_formatter) |
| 2149 | 2150 | { |
| 2150 | 2151 | /* FIXME: we *might* want to provide this functionality as |
| … | … | |
| 2182 | 2182 | do_cleanups (back_to); |
| 2183 | 2183 | return xstrdup (s); |
| 2184 | 2184 | } |
| 2185 | #endif /* HAVE_PYTHON */ |
| 2185 | 2186 | |
| 2186 | 2187 | stb = mem_fileopen (); |
| 2187 | 2188 | old_chain = make_cleanup_ui_file_delete (stb); |
| … | … | |
| 2643 | 2643 | catch that case explicitly. */ |
| 2644 | 2644 | struct type *type = get_type (var); |
| 2645 | 2645 | |
| 2646 | #ifdef HAVE_PYTHON |
| 2646 | 2647 | /* If we have a custom formatter, return whatever string it has |
| 2647 | 2648 | produced. */ |
| 2648 | 2649 | if (var->value_formatter && var->print_value) |
| 2649 | 2650 | return xstrdup (var->print_value); |
| 2651 | #endif |
| 2650 | 2652 | |
| 2651 | 2653 | /* Strip top-level references. */ |
| 2652 | 2654 | while (TYPE_CODE (type) == TYPE_CODE_REF) |
| toggle raw diff |
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -33,8 +33,10 @@
#include "varobj.h"
#include "vec.h"
+#ifdef HAVE_PYTHON
#include "python/python.h"
#include "python/python-internal.h"
+#endif
/* Non-zero if we want to see trace of varobj level stuff. */
@@ -130,11 +132,13 @@ struct varobj
/* Children of this object. */
VEC (varobj_p) *children;
+#ifdef HAVE_PYTHON
/* Whether the children of this varobj were requested. This field is
used to decide if dynamic varobj should recompute their children.
In the event that the frontend never asked for the children, we
can avoid that. */
int children_requested;
+#endif
/* Description of the root variable. Points to root variable for children. */
struct varobj_root *root;
@@ -158,11 +162,13 @@ struct varobj
frozen. */
int not_fetched;
+#ifdef HAVE_PYTHON
/* A Python object used to visualize this variable object.
FIXME: free this in dtor.
*/
PyObject *value_formatter;
PyObject *children_lister;
+#endif
};
struct cpstack
@@ -179,6 +185,7 @@ struct vlist
struct vlist *next;
};
+#ifdef HAVE_PYTHON
typedef struct type_visualizer
{
char *type_regexp;
@@ -186,6 +193,7 @@ typedef struct type_visualizer
} type_visualizer;
DEF_VEC_O (type_visualizer);
+#endif
/* Private function prototypes */
@@ -231,7 +239,9 @@ static char *cppop (struct cpstack **pstack);
static int install_new_value (struct varobj *var, struct value *value,
int initial);
+#ifdef HAVE_PYTHON
static void install_default_visualizer (struct varobj *var);
+#endif
static struct value *
value_struct_element_by_name (struct value *value, const char *name);
@@ -253,8 +263,11 @@ static struct value *value_of_child (struct varobj *parent, int index);
static char *my_value_of_variable (struct varobj *var);
static char *value_get_print_value (struct value *value,
- enum varobj_display_formats format,
- PyObject *value_formatter);
+ enum varobj_display_formats format
+#ifdef HAVE_PYTHON
+ , PyObject *value_formatter
+#endif
+ );
static int varobj_value_is_changeable_p (struct varobj *var);
@@ -423,7 +436,9 @@ static int rootcount = 0; /* number of root varobjs in the list */
/* Pointer to the varobj hash table (built at run time) */
static struct vlist **varobj_table;
+#ifdef HAVE_PYTHON
static VEC (type_visualizer) *type_visualizers = NULL;
+#endif
/* Is the variable X one of our "fake" children? */
#define CPLUS_FAKE_CHILD(x) \
@@ -584,7 +599,9 @@ varobj_create (char *objname,
}
discard_cleanups (old_chain);
+#ifdef HAVE_PYTHON
install_default_visualizer (var);
+#endif
return var;
}
@@ -714,13 +731,17 @@ varobj_set_display_format (struct varobj *var,
&& var->value && !value_lazy (var->value))
{
free (var->print_value);
- var->print_value = value_get_print_value (var->value, var->format,
- var->value_formatter);
+ var->print_value = value_get_print_value (var->value, var->format
+#ifdef HAVE_PYTHON
+ , var->value_formatter
+#endif
+ );
}
return var->format;
}
+#ifdef HAVE_PYTHON
void
varobj_set_visualizer (struct varobj *var, const char *visualizer)
{
@@ -802,6 +823,7 @@ varobj_clear_type_visualizers (const char *type_regexp, const char *visualizer)
{
VEC_free (type_visualizer, type_visualizers);
}
+#endif /* HAVE_PYTHON */
enum varobj_display_formats
varobj_get_display_format (struct varobj *var)
@@ -838,6 +860,7 @@ varobj_get_num_children (struct varobj *var)
return var->num_children;
}
+#ifdef HAVE_PYTHON
static
int update_dynamic_varobj_children (struct varobj *var,
VEC (varobj_p) **changed,
@@ -928,6 +951,7 @@ int update_dynamic_varobj_children (struct varobj *var,
return children_changed;
}
+#endif /* HAVE_PYTHON */
/* Creates a list of the immediate children of a variable object;
the return code is the number of such children or -1 on error */
@@ -939,6 +963,7 @@ varobj_list_children (struct varobj *var)
char *name;
int i;
+#ifdef HAVE_PYTHON
var->children_requested = 1;
if (var->children_lister)
@@ -949,6 +974,7 @@ varobj_list_children (struct varobj *var)
update_dynamic_varobj_children (var, NULL, NULL);
return var->children;
}
+#endif
if (var->num_children == -1)
var->num_children = number_of_children (var);
@@ -974,13 +1000,16 @@ varobj_list_children (struct varobj *var)
name = name_of_child (var, i);
existing = create_child (var, i, name);
VEC_replace (varobj_p, var->children, i, existing);
+#ifdef HAVE_PYTHON
install_default_visualizer (existing);
+#endif
}
}
return var->children;
}
+#ifdef HAVE_PYTHON
struct varobj *
varobj_add_child (struct varobj *var, const char *name, struct value *value)
{
@@ -991,6 +1020,7 @@ varobj_add_child (struct varobj *var, const char *name, struct value *value)
install_default_visualizer (v);
return v;
}
+#endif
/* Obtain the type of an object Variable as a string similar to the one gdb
prints on the console */
@@ -1192,11 +1222,13 @@ install_new_value (struct varobj *var, struct value *value, int initial)
gdb_assert (var->type || CPLUS_FAKE_CHILD (var));
changeable = varobj_value_is_changeable_p (var);
+#ifdef HAVE_PYTHON
/* If the type has custom visualizer, we consider it to be always
changeable. FIXME: need to make sure this behaviour will not
mess up read-sensitive values. */
if (var->value_formatter || var->children_lister)
changeable = 1;
+#endif
need_to_fetch = changeable;
@@ -1255,8 +1287,11 @@ install_new_value (struct varobj *var, struct value *value, int initial)
should not be fetched. */
if (value && !value_lazy (value))
{
- print_value = value_get_print_value (value, var->format,
- var->value_formatter);
+ print_value = value_get_print_value (value, var->format
+#ifdef HAVE_PYTHON
+ , var->value_formatter
+#endif
+ );
}
/* If the type is changeable, compare the old and the new values.
@@ -1322,6 +1357,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
return changed;
}
+#ifdef HAVE_PYTHON
void install_default_visualizer (struct varobj *var)
{
char *type = varobj_get_type (var);
@@ -1341,6 +1377,7 @@ void install_default_visualizer (struct varobj *var)
xfree (type);
}
}
+#endif
/* Update the values for a variable and its children. This is a
two-pronged attack. First, re-parse the value for the root's
@@ -1419,8 +1456,10 @@ varobj_update (struct varobj **varp, int explicit)
r.status = VAROBJ_NOT_IN_SCOPE;
r.value_installed = 1;
+#ifdef HAVE_PYTHON
if (r.type_changed)
install_default_visualizer (*varp);
+#endif
if (r.status == VAROBJ_NOT_IN_SCOPE)
{
@@ -1456,6 +1495,7 @@ varobj_update (struct varobj **varp, int explicit)
}
}
+#ifdef HAVE_PYTHON
/* We probably should not get children of a varobj that has
children_lister, but for which -var-list-children was never
invoked. Presumably, such varobj is not yet expanded in the
@@ -1491,6 +1531,7 @@ varobj_update (struct varobj **varp, int explicit)
VEC_safe_push (varobj_update_result, result, &r);
continue;
}
+#endif /* HAVE_PYTHON */
/* Push any children. Use reverse order so that the first
child is popped from the work stack first, and so
@@ -1776,9 +1817,11 @@ new_variable (void)
var->print_value = NULL;
var->frozen = 0;
var->not_fetched = 0;
+#ifdef HAVE_PYTHON
var->value_formatter = NULL;
var->children_lister = NULL;
var->children_requested = 0;
+#endif
return var;
}
@@ -1811,8 +1854,10 @@ free_variable (struct varobj *var)
xfree (var->root);
}
+#ifdef HAVE_PYTHON
Py_XDECREF (var->value_formatter);
Py_XDECREF (var->children_lister);
+#endif
xfree (var->name);
xfree (var->obj_name);
@@ -2085,8 +2130,12 @@ my_value_of_variable (struct varobj *var)
}
static char *
-value_get_print_value (struct value *value, enum varobj_display_formats format,
- PyObject *value_formatter)
+value_get_print_value (struct value *value, enum varobj_display_formats format
+#ifdef HAVE_PYTHON
+/* FIXME: this ifdef block is very ugly! */
+ , PyObject *value_formatter
+#endif
+ )
{
long dummy;
struct ui_file *stb;
@@ -2096,6 +2145,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
if (value == NULL)
return NULL;
+#ifdef HAVE_PYTHON
if (value_formatter)
{
/* FIXME: we *might* want to provide this functionality as
@@ -2132,6 +2182,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
do_cleanups (back_to);
return xstrdup (s);
}
+#endif /* HAVE_PYTHON */
stb = mem_fileopen ();
old_chain = make_cleanup_ui_file_delete (stb);
@@ -2592,10 +2643,12 @@ c_value_of_variable (struct varobj *var)
catch that case explicitly. */
struct type *type = get_type (var);
+#ifdef HAVE_PYTHON
/* If we have a custom formatter, return whatever string it has
produced. */
if (var->value_formatter && var->print_value)
return xstrdup (var->print_value);
+#endif
/* Strip top-level references. */
while (TYPE_CODE (type) == TYPE_CODE_REF) |