aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/py-prettyprint.c
AgeCommit message (Collapse)AuthorFilesLines
2017-08-21Fix type casts losing typedefs and reimplement "whatis" typedef strippingPedro Alves1-0/+9
(Ref: https://sourceware.org/ml/gdb/2017-06/msg00020.html) Assuming int_t is a typedef to int: typedef int int_t; gdb currently loses this expression's typedef: (gdb) p (int_t) 0 $1 = 0 (gdb) whatis $1 type = int or: (gdb) whatis (int_t) 0 type = int or, to get "whatis" out of the way: (gdb) maint print type (int_t) 0 ... name 'int' code 0x8 (TYPE_CODE_INT) ... This prevents a type printer for "int_t" kicking in, with e.g.: (gdb) p (int_t) 0 From the manual, we can see that that "whatis (int_t) 0" command invocation should have printed "type = int_t": If @var{arg} is a variable or an expression, @code{whatis} prints its literal type as it is used in the source code. If the type was defined using a @code{typedef}, @code{whatis} will @emph{not} print the data type underlying the @code{typedef}. (...) If @var{arg} is a type name that was defined using @code{typedef}, @code{whatis} @dfn{unrolls} only one level of that @code{typedef}. That one-level stripping is currently done here, in gdb/eval.c:evaluate_subexp_standard, handling OP_TYPE: ... else if (noside == EVAL_AVOID_SIDE_EFFECTS) { struct type *type = exp->elts[pc + 1].type; /* If this is a typedef, then find its immediate target. We use check_typedef to resolve stubs, but we ignore its result because we do not want to dig past all typedefs. */ check_typedef (type); if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) type = TYPE_TARGET_TYPE (type); return allocate_value (type); } However, this stripping is reachable in both: #1 - (gdb) whatis (int_t)0 # ARG is an expression with a cast to # typedef type. #2 - (gdb) whatis int_t # ARG is a type name. while only case #2 should strip the typedef. Removing that code from evaluate_subexp_standard is part of the fix. Instead, we make the "whatis" command implementation itself strip one level of typedefs when the command argument is a type name. We then run into another problem, also fixed by this commit: value_cast always drops any typedefs of the destination type. With all that fixed, "whatis (int_t) 0" now works as expected: (gdb) whatis int_t type = int (gdb) whatis (int_t)0 type = int_t value_cast has many different exit/convertion paths, for handling many different kinds of casts/conversions, and most of them had to be tweaked to construct the value of the right "to" type. The new tests try to exercise most of it, by trying castin of many different combinations of types. With: $ make check TESTS="*/whatis-ptype*.exp */gnu_vector.exp */dfp-test.exp" ... due to combinatorial explosion, the testsuite results for the tests above alone grow like: - # of expected passes 246 + # of expected passes 3811 You'll note that the tests exposed one GCC buglet, filed here: Missing DW_AT_type in DW_TAG_typedef of "typedef of typedef of void" https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81267 gdb/ChangeLog: 2017-08-21 Pedro Alves <palves@redhat.com> * eval.c (evaluate_subexp_standard) <OP_TYPE>: Don't dig past typedefs. * typeprint.c (whatis_exp): If handling "whatis", and expression is OP_TYPE, strip one typedef level. Otherwise don't strip typedefs here. * valops.c (value_cast): Save "to" type before resolving stubs/typedefs. Use that type as resulting value's type. gdb/testsuite/ChangeLog: 2017-08-21 Pedro Alves <palves@redhat.com> * gdb.base/dfp-test.c (d32_t, d64_t, d128_t, d32_t2, d64_t2, d128_t2, v_d32_t, v_d64_t) (v_d128_t, v_d32_t2, v_d64_t2, v_d128_t2): New. * gdb.base/dfp-test.exp: Add whatis/ptype/cast tests. * gdb.base/gnu_vector.exp: Add whatis/ptype/cast tests. * gdb.base/whatis-ptype-typedefs.c: New. * gdb.base/whatis-ptype-typedefs.exp: New. * gdb.python/py-prettyprint.c (int_type, int_type2): New typedefs. (an_int, an_int_type, an_int_type2): New globals. * gdb.python/py-prettyprint.exp (run_lang_tests): Add tests involving typedefs and cast expressions. * gdb.python/py-prettyprint.py (class pp_int_typedef): New. (lookup_typedefs_function): New. (typedefs_pretty_printers_dict): New. (top level): Register lookup_typedefs_function in gdb.pretty_printers.
2017-01-01update copyright year range in GDB filesJoel Brobecker1-1/+1
This applies the second part of GDB's End of Year Procedure, which updates the copyright year range in all of GDB's files. gdb/ChangeLog: Update copyright year range in all GDB files.
2016-01-01GDB copyright headers update after running GDB's copyright.py script.Joel Brobecker1-1/+1
gdb/ChangeLog: Update year range in copyright notice of all files.
2015-05-26PR python/18438Doug Evans1-2/+9
gdb/ChangeLog: * python/py-lazy-string.c (stpy_convert_to_value): Use gdbpy_gdb_memory_error not PyExc_MemoryError. (gdbpy_create_lazy_string_object): Ditto. gdb/testsuite/ChangeLog: * gdb.python/py-lazy-string.c: New file. * gdb.python/py-lazy-string.exp: New file. * gdb.python/py-prettyprint.c (lazystring) <len>: New member. (main): Update. Add estring3. * gdb.python/py-prettyprint.exp: Add tests for strings at address 0. * gdb.python/py-prettyprint.py (pp_ls): Handle length.
2015-01-01Update year range in copyright notice of all files owned by the GDB project.Joel Brobecker1-1/+1
gdb/ChangeLog: Update year range in copyright notice of all files.
2014-04-24Ensure unreferenced static symbols aren't omitted by clang (either marking ↵David Blaikie1-1/+1
them __attribute__((used)) or making them non-static) gdb/testsuite/ * gdb.base/catch-syscall.c: Make unreferenced statics non-static to ensure clang would not discard them. * gdb.base/gdbvars.c: Ditto. * gdb.base/memattr.c: Ditto. * gdb.base/whatis.c: Ditto. * gdb.python/py-prettyprint.c: Ditto. * gdb.trace/actions.c: Ditto. * gdb.cp/ptype-cv-cp.cc: Mark unused global const int as used to ensure clang would not discard it.
2014-01-01Update Copyright year range in all files maintained by GDB.Joel Brobecker1-1/+1
2013-01-01Update years in copyright notice for the GDB files.Joel Brobecker1-1/+1
Two modifications: 1. The addition of 2013 to the copyright year range for every file; 2. The use of a single year range, instead of potentially multiple year ranges, as approved by the FSF.
2012-12-062012-12-06 Jens Elmenthaler <jens.elmenthaler@advantest.com>Tom Tromey1-1/+18
PR mi/14741: * mi/mi-cmd-var.c (varobj_update_one): Take value of attribute "dynamic" and "displayhint" from printed child, not the root variable. * gdb.python/py-mi.exp: Correct expected results for attribute "dynamic" returned by -var-update. Add test case for correct handling of "diplayhint" for children of dynamic varobjs. * gdb.python/py-prettyprint.c (set_itme): New function. (bug_14741) New function. (main) Add call to bug_14741(). * gdb.python/py-prettyprint.py (class ArrayPrinter): New class.
2012-08-06 PR python/14386:Tom Tromey1-0/+5
* varobj.c (update_dynamic_varobj_children): Don't call PyIter_Check. gdb/testsuite * gdb.python/py-mi.exp: Add test for printer whose children are a list. * gdb.python/py-prettyprint.c (struct children_as_list): New. (main): New variable children_as_list. * gdb.python/py-prettyprint.py (class pp_children_as_list): New. (register_pretty_printers): Register new printer.
2012-07-16gdb/Jan Kratochvil1-0/+18
PR 11914 * f-valprint.c (info_common_command): New variable frame_id. Reinitialize FI form FRAME_ID after each print_variable_and_value. * printcmd.c (print_variable_and_value): Extend function comment. Add comment for invalidated FRAME. * stack.c (backtrace_command_1): New variable frame_id. Reinitialize FI form FRAME_ID after each print_frame_local_vars. (struct print_variable_and_value_data): Change frame to frame_id. (do_print_variable_and_value): New variable frame, initialize it from p->frame_id. Add comment for invalidated FRAME. (print_frame_local_vars, print_frame_arg_vars): New function comment. Update CB_DATA.FRAME to CB_DATA.FRAME_ID initialization. Add comment for invalidated FRAME. gdb/testsuite/ PR 11914 * gdb.python/py-prettyprint.c (eval_func, eval_sub): New. (main): Call eval_sub. * gdb.python/py-prettyprint.exp: (python execfile ('py-prettyprint.py')): Move it earlier. New breakpoint for eval-break. (continue to breakpoint: eval-break, info locals): New test. (python execfile ('py-prettyprint.py')): Move it from here. * gdb.python/py-prettyprint.py (class pp_eval_type): New. (register_pretty_printers): Register pp_eval_type.
2012-01-04Copyright year update in most files of the GDB Project.Joel Brobecker1-1/+1
gdb/ChangeLog: Copyright year update in most files of the GDB Project.
2011-07-282011-07-28 Phil Muldoon <pmuldoon@redhat.com>Phil Muldoon1-0/+8
* varobj.c (value_get_print_value): Move hint check later into the function. Comment function. Free thevalue before reusing it. 2011-07-28 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/py-mi.exp: Test printers returning string hint, and also not returning a value. * gdb.python/py-prettyprint.c: Add testcase for above. * gdb.python/py-prettyprint.py: Add test printer for above.
2011-04-292011-04-29 Phil Muldoon <pmuldoon@redhat.com>Phil Muldoon1-0/+11
PR mi/12531 * varobj.c (install_default_visualizer): Do not install a visualizer if the varobj is CPLUS_FAKE_CHILD. (construct_visualizer): Likewise. 2011-04-29 Phil Muldoon <pmuldoon@redhat.com> PR mi/12531 * gdb.python/py-mi.exp: Add CPLUS_FAKE_CHILD tests and a C++ compile target. * gdb.python/py-prettyprint.exp: Add C++ object for CPLUS_FAKE_CHILD test.
2011-04-11gdb/testsuite/Jan Kratochvil1-0/+5
* gdb.python/py-prettyprint.c (struct hint_error): New. (main): New variable hint_error. * gdb.python/py-prettyprint.exp (run_lang_tests): New testcase "print hint_error". * gdb.python/py-prettyprint.py (class pp_hint_error): New. (register_pretty_printers): Register it.
2011-03-31gdbTom Tromey1-1/+3
* varobj.c (update_dynamic_varobj_children): Properly handle errors from iterator. gdb/testsuite * gdb.python/py-prettyprint.py (exception_flag): New global. (NoStringContainerPrinter._iterator.next): Check it. * gdb.python/py-prettyprint.c (main): New variable nstype2. * gdb.python/py-mi.exp: Set exception_flag and do more tests.
2011-01-01run copyright.sh for 2011.Joel Brobecker1-1/+1
2010-11-12gdbTom Tromey1-1/+5
* varobj.c (value_get_print_value): Rearrange. Pass stream to apply_varobj_pretty_printer. * c-lang.c: Include exceptions.h. (c_get_string): Throw MEMORY_ERROR when appropriate. * python/py-prettyprint.c (enum string_repr_result): New. (print_stack_unless_memory_error): New function. (print_string_repr): Change return type. Use print_stack_unless_memory_error. (print_children): Use print_stack_unless_memory_error. (apply_val_pretty_printer): Update. Don't print children if string representation threw an exception. (apply_varobj_pretty_printer): Add 'stream' argument. Use print_stack_unless_memory_error. * python/python.c (gdbpy_gdb_error, gdbpy_gdb_memory_error): New globals. (_initialize_python): Initialize them. * python/python-internal.h (GDB_PY_HANDLE_EXCEPTION): Use gdbpy_convert_exception. (GDB_PY_SET_HANDLE_EXCEPTION): Likewise. (gdbpy_gdb_error, gdbpy_gdb_memory_error): Declare. (gdbpy_convert_exception): Declare. (apply_varobj_pretty_printer): Update. * python/py-utils.c (gdbpy_convert_exception): New function. gdb/doc * gdb.texinfo (Basic Python): Update. Add xref. (Exception Handling): Document new exception classes. (Types In Python): Update. (Frames In Python): Update. gdb/testsuite * gdb.python/py-prettyprint.c (main): Add new 'ns2' local. * gdb.python/py-prettyprint.exp (run_lang_tests): Add test for MemoryError. * gdb.python/python.exp (gdb_py_test_multiple): Update exception type. * gdb.python/py-value.exp (test_value_in_inferior): Add test for MemoryError. (test_subscript_regression): Update exception type.
2010-10-18gdbTom Tromey1-2/+6
* valprint.c (val_print_string): Pass 'encoding' to LA_PRINT_STRING. gdb/testsuite * gdb.python/py-prettyprint.exp (run_lang_tests): Test encoding argument to lazy_string. * gdb.python/py-prettyprint.py (pp_ls_encoding): New global. (pp_ls.to_string): Use it. * gdb.python/py-prettyprint.c (main): Move declarations to top. Add "estring2" local.
2010-07-142010-07-13 Emmanuel Thomé <Emmanuel.Thome@gmail.com>Tom Tromey1-0/+11
* c-valprint.c (c_val_print): Add embedded_offset to address in call to val_print_array_elements. 2010-07-13 Tom Tromey <tromey@redhat.com> * gdb.python/py-prettyprint.c (struct arraystruct): New struct. (main): Use it. * gdb.python/py-prettyprint.exp (run_lang_tests): Add test.
2010-04-142010-04-14 Phil Muldoon <pmuldoon@redhat.com>Phil Muldoon1-1/+16
PR python/11381 * python/py-prettyprint.c (pretty_print_one_value): Test for Py_None. (print_string_repr): Test for Py_None. Set flags accordingly. Return value depending on return type. (print_children): Take a value indicating whether data was printed before this function was called. Alter output accordingly. (apply_val_pretty_printer): Capture return value from print_string_repr and pass to print_children. 2010-04-14 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/py-prettyprint.py (NoStringContainerPrinter): New printer. * gdb.python/py-prettyprint.c: Add justchildren struct, typedefs. * gdb.python/py-prettyprint.exp: New test for to_string returning None. * gdb.python/py-mi.exp: New test for to_string returning None. 2010-04-14 Phil Muldoon <pmuldoon@redhat.com> * gdb.texinfo (Pretty Printing): Document behaviour when to_string returns None.
2010-01-142010-01-13 Phil Muldoon <pmuldoon@redhat.com>Phil Muldoon1-0/+8
PR python/10705 * python/python-internal.h: Add lazy_string_object_type definition. (create_lazy_string_object, gdbpy_initialize_lazy_string) (gdbpy_is_lazystring, gdbpy_extract_lazy_string): Define. * python/py-value.c (valpy_lazy_string): New function. (convert_value_from_python): Add lazy string conversion. * python/py-prettyprint.c (pretty_print_one_value): Check if return is also a lazy string. (print_string_repr): Add lazy string printing branch. (print_children): Likewise. * python/py-lazy-string.c: New file. Implement lazy strings. * python/python.c (_initialize_python): Call gdbpy_initialize_lazy_string. * varobj.c (value_get_print_value): Add lazy string printing branch. Account for encoding. * c-lang.c (c_printstr): Account for new encoding argument. If encoding is NULL, find encoding suited for type, otherwise use user encoding. * language.h (language_defn): Add encoding argument. (LA_PRINT_STRING): Likewise. * language.c (unk_lang_printstr): Update to reflect new encoding argument to language_defn. * ada-lang.h (ada_printstr): Likewise. * c-lang.h (c_printstr): Likewise. * p-lang.h (pascal_printstr); * f-lang.c (f_printstr): Likewise. * m2-lang.c (m2_printstr): Likewise. * objc-lang.c (objc_printstr): Likewise. * p-lang.c (pascal_printstr): Likewise. * scm-lang.c (scm_printstr): Likewise. * c-valprint.c (c_val_print): Update LA_PRINT_STRING call for encoding argument. * ada-valprint.c (ada_printstr): Likewise. * f-valprint.c (f_val_print): Likewise * m2-valprint.c (m2_val_print): Likewise. * p-valprint.c (pascal_val_print): Likewise. * expprint.c (print_subexp_standard): Likewise. * valprint.c (val_print_string): Likewise. * Makefile.in (SUBDIR_PYTHON_OBS): Add py-lazy-string. (SUBDIR_PYTHON_SRCS): Likewise. (py-lazy-string.o): New rule. 2010-01-13 Phil Muldoon <pmuldoon@redhat.com> * gdb.texinfo (Values From Inferior): Document lazy_string value method. (Python API): Add Lazy strings menu item. (Lazy Strings In Python): New node. 2010-01-13 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/py-value.exp (test_lazy_strings): Add lazy string test. * gdb.python/py-prettyprint.py (pp_ls): New printer. * gdb.python/py-prettyprint.exp (run_lang_tests): Add lazy string test. * gdb.python/py-prettyprint.c: Define lazystring test structure. * gdb.python/py-mi.exp: Add lazy string test.
2010-01-01Update copyright year in most headers.Joel Brobecker1-1/+1
Automatic update by copyright.sh.
2009-09-15gdbTom Tromey1-0/+45
* varobj.h (varobj_update_result_t) <new>: New field. (varobj_get_child_range, varobj_set_child_range): Declare. (varobj_list_children): Update. (varobj_enable_pretty_printing, varobj_has_more) (varobj_pretty_printed_p): Declare. * varobj.c (pretty_printing): New global. (varobj_enable_pretty_printing): New function. (struct varobj_root) <from, to, constructor, child_iter, saved_item>: New fields. (varobj_create): Don't call install_default_visualizer. (instantiate_pretty_printer): Don't use value_copy. (varobj_has_more): New function. (restrict_range): New function. (install_dynamic_child): Likewise. (dynamic_varobj_has_child_method): Likewise. (update_dynamic_varobj_children): Remove 'new_and_unchanged' argument; add 'new', 'unchanged', 'from', and 'to' arguments. Rewrite. (varobj_get_num_children): Call update_dynamic_varobj_children. (varobj_list_children): Add 'from' and 'to' arguments. Ignore result of update_dynamic_varobj_children. Don't call install_default_visualizer. Restrict result range. (varobj_add_child): Don't call install_default_visualizer. (varobj_pretty_printed_p): New function. (install_visualizer): Rewrite. Move earlier in file. (install_default_visualizer): Likewise. (construct_visualizer): New function. (install_new_value_visualizer): Likewise. (install_new_value): Don't call release_value. Special case pretty-printed objects. Use value_incref. Rearrange "changed" logic. (varobj_get_child_range): New function. (varobj_set_child_range): Likewise. (varobj_set_visualizer): Rewrite. (varobj_update): Rewrite pretty-printing logic. (new_variable): Initialize new fields. (free_variable): Destroy new fields. (value_of_root): Copy 'from' and 'to'. (my_value_of_variable): Handle pretty-printers. (value_get_print_value): Rework pretty-printing logic. (cplus_describe_child): Don't use release_value. * mi/mi-cmds.h (mi_cmd_enable_pretty_printing) (mi_cmd_var_set_update_range): Declare. * mi/mi-cmds.c (mi_cmds): Add enable-pretty-printing and var-set-update-range. * mi/mi-cmd-var.c (print_varobj): Update. Emit "dynamic" attribute. (mi_cmd_var_create): Emit "has_more" attribute. (mi_cmd_var_set_format): Plug memory leak. (mi_print_value_p): Replace 'type' argument with 'var'. Handle pretty-printed varobjs. (mi_cmd_var_list_children): Accept 'from' and 'to' arguments. Emit "has_more" attribute. (mi_cmd_var_evaluate_expression): Plug memory leak. (mi_cmd_var_assign): Likewise. (varobj_update_one): Likewise. Emit "dynamic", "has_more", and "new_children" attributes. (mi_cmd_enable_pretty_printing): New function. (mi_cmd_var_set_update_range): Likewise. gdb/doc * gdb.texinfo (GDB/MI Variable Objects): Document -enable-pretty-printing, -var-set-update-range, dynamic varobjs. Expand -var-update documentation. gdb/testsuite * lib/mi-support.exp (mi_create_varobj): Update. (mi_create_floating_varobj): Likewise. (mi_create_dynamic_varobj): New proc. (mi_varobj_update): Update. (mi_varobj_update_with_type_change): Likewise. (mi_varobj_update_kv_helper): New proc. (mi_varobj_update_dynamic_helper): Rewrite. (mi_varobj_update_dynamic): New proc. (mi_list_varobj_children): Update. (mi_list_varobj_children_range): Add 'from' and 'to' arguments. * gdb.python/python-prettyprint.py (pp_outer): New class. (pp_nullstr): Likewise. (lookup_function): Register new printers. * gdb.python/python-prettyprint.c (struct substruct): New type. (struct outerstruct): Likewise. (substruct_test): New function. (struct nullstr): New type. (string_1, string_2): New globals. (main): Add new tests. * gdb.python/python-mi.exp: Added regression tests. * gdb.mi/mi2-var-display.exp: Update. * gdb.mi/mi2-var-cmd.exp: Update. * gdb.mi/mi2-var-child.exp: Update. * gdb.mi/mi2-var-block.exp: Update. * gdb.mi/mi-var-invalidate.exp: Update. * gdb.mi/mi-var-display.exp: Update. * gdb.mi/mi-var-cmd.exp: Update. * gdb.mi/mi-var-child.exp: Update. * gdb.mi/mi-var-block.exp: Update. * gdb.mi/mi-break.exp: Update. * gdb.mi/gdb701.exp: Update.
2009-09-09Checking in this patch for Thiago: Rename python-* files into py-*,Joel Brobecker1-0/+200
more 8+3 friendly. gdb/ * Makefile.in (py-cmd.o): Renamed from python-cmd.o. Updated references. (py-frame.o): Renamed from python-frame.o. Updated references. (py-function.o): Renamed from python-function.o. Updated references. (py-objfile.o): Renamed from python-objfile.o. Updated references. (py-prettyprint.o): Renamed from python-prettyprint.o. Updated +references. (py-type.o): Renamed from python-type.o. Updated references. (py-utils.o): Renamed from python-utils.o. Updated references. (py-value.o): Renamed from python-value.o. Updated references. * py-cmd.o: Renamed from python-cmd.o. * py-frame.o: Renamed from python-frame.o. * py-function.o: Renamed from python-function.o. * py-objfile.o: Renamed from python-objfile.o. * py-prettyprint.o: Renamed from python-prettyprint.o. * py-type.o: Renamed from python-type.o. * py-utils.o: Renamed from python-utils.o. * py-value.o: Renamed from python-value.o. gdb/testsuite/ * gdb.python/Makefile.in (EXECUTABLES): Adjust to new executable names, add missing ones. * gdb.python/py-cmd.exp: Rename from python-cmd.exp. * gdb.python/py-frame.c: Rename from python-frame.c. * gdb.python/py-frame.exp: Rename from python-frame.exp. Adjust testfile name. * gdb.python/py-function.exp: Rename from python-function.exp. * gdb.python/py-mi.exp: Rename from python-mi.exp. Adjust testfile name. * gdb.python/py-prettyprint.c: Rename from python-prettyprint.c. * gdb.python/py-prettyprint.exp: Rename from python-prettyprint.exp. Adjust testfile name. * gdb.python/py-prettyprint.py: Rename from python-prettyprint.py. * gdb.python/py-template.cc: Rename from python-template.cc. * gdb.python/py-template.exp: Rename from python-template.exp. Adjust testfile name. * gdb.python/py-value.c: Rename from python-value.c. * gdb.python/py-value.exp: Rename from python-value.exp. Adjust testfile name.