aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/lib
AgeCommit message (Collapse)AuthorFilesLines
2020-04-10[gdb/cli] Don't let python colorize strip leading newlinesTom de Vries1-1/+1
Consider the test-case gdb.base/async.exp. Using the executable, I run to main, and land on a line advertised as line 26: ... $ gdb outputs/gdb.base/async/async -ex start Reading symbols from outputs/gdb.base/async/async... Temporary breakpoint 1 at 0x4004e4: file gdb.base/async.c, line 26. Starting program: outputs/gdb.base/async/async Temporary breakpoint 1, main () at gdb.base/async.c:26 26 y = foo (); ... But actually, the line turns out to be line 28: ... $ cat -n gdb.base/async.c ... 26 y = 2; 27 z = 9; 28 y = foo (); ... This is caused by the following: the python colorizer initializes the lexer with default options (no second argument to get_lexer_for_filename): ... def colorize(filename, contents): # Don't want any errors. try: lexer = lexers.get_lexer_for_filename(filename) formatter = formatters.TerminalFormatter() return highlight(contents, lexer, formatter) ... which include option stripnl=True, which strips leading and trailing newlines. This causes the python colorizer to strip the two leading newlines of async.c. Fix this by initializing the lexer with stripnl=False. Build and reg-tested on x86_64-linux. gdb/ChangeLog: 2020-04-10 Tom de Vries <tdevries@suse.de> PR cli/25808 * python/lib/gdb/__init__.py: Initialize lexer with stripnl=False. gdb/testsuite/ChangeLog: 2020-04-10 Tom de Vries <tdevries@suse.de> PR cli/25808 * gdb.base/style.c: Add leading newlines. * gdb.base/style.exp: Use gdb_get_line_number to get specific lines. Check listing of main's one-line body.
2020-01-21Allow use of Pygments to colorize source codeTom Tromey1-0/+14
While GNU Source Highlight is good, it's also difficult to build and distribute. For one thing, it needs Boost. For another, it has an unusual configuration and installation setup. Pygments, a Python library, doesn't suffer from these issues, and so I thought it would be a reasonable fallback. This patch implements this idea. GNU Source Highlight is preferred, but if it is unavailable (or fails), the extension languages are tried. This patch also implements support for Pygments. Something similar could be done for Guile, using: https://dthompson.us/projects/guile-syntax-highlight.html However, I don't know enough about Guile internals to make this happen, so I have not done it here. gdb/ChangeLog 2020-01-21 Tom Tromey <tromey@adacore.com> * source-cache.c (source_cache::ensure): Call ext_lang_colorize. * python/python.c (python_extension_ops): Update. (gdbpy_colorize): New function. * python/lib/gdb/__init__.py (colorize): New function. * extension.h (ext_lang_colorize): Declare. * extension.c (ext_lang_colorize): New function. * extension-priv.h (struct extension_language_ops) <colorize>: New member. * cli/cli-style.c (_initialize_cli_style): Update help text. Change-Id: I5e21623ee05f1f66baaa6deaeca78b578c031bf4
2020-01-01Update copyright year range in all GDB files.Joel Brobecker23-23/+23
gdb/ChangeLog: Update copyright year range in all GDB files.
2019-10-09[gdb/target] Fix pretty-printer for MPX bnd registersTom de Vries1-1/+1
I'm seeing this failure: ... (gdb) print /x $bnd0 = {0x10, 0x20}^M $23 = {lbound = 0x10, ubound = 0x20}^M (gdb) FAIL: gdb.arch/i386-mpx.exp: verify size for bnd0 ... The test expects a pretty printer to be actived printing 'size 17': ... set test_string ".*\\\: size 17.*" gdb_test "print /x \$bnd0 = {0x10, 0x20}" "$test_string" "verify size for bnd0" ... but that doesn't happen. The pretty printer is for the type of the $bnd0 register, which is created here in i386_bnd_type: ... t = arch_composite_type (gdbarch, "__gdb_builtin_type_bound128", TYPE_CODE_STRUCT); append_composite_type_field (t, "lbound", bt->builtin_data_ptr); append_composite_type_field (t, "ubound", bt->builtin_data_ptr); TYPE_NAME (t) = "builtin_type_bound128"; ... And the pretty-printer is registered here in gdb/python/lib/gdb/printer/bound_registers.py: ... gdb.printing.add_builtin_pretty_printer ('mpx_bound128', '^__gdb_builtin_type_bound128', MpxBound128Printer) ... Fix the pretty printer by changing the regexp argument of add_builtin_pretty_printer to match "builtin_type_bound128", the TYPE_NAME. Tested on x86_64-linux. gdb/ChangeLog: 2019-10-09 Tom de Vries <tdevries@suse.de> * python/lib/gdb/printer/bound_registers.py: Use '^builtin_type_bound128' as regexp argument for add_builtin_pretty_printer.
2019-08-22Make GDB compile with Python 3 on MinGWChristian Biesinger1-0/+26
PyFile_FromString and PyFile_AsFile have been removed in Python 3. There is no obvious replacement that works here, and we can't just pass our FILE* to a DLL in Windows because it may use a different C runtime. So we just call a Python function which reads and executes file contents. Care must be taken to execute it in the context of __main__. Tested by inverting the ifdef and running the testsuite on Debian Linux (even without the patch, I failed at running the testsuite on Windows). I did test with both Python 2 and 3. gdb/ChangeLog: 2019-08-22 Christian Biesinger <cbiesinger@google.com> * python/lib/gdb/__init__.py (_execute_file): New function. * python/python.c (python_run_simple_file): Call gdb._execute_file on Windows.
2019-08-15Rename internal Python functions to start with an underscoreChristian Biesinger1-8/+8
I could not tell if GdbSetPythonDirectory is internal or not because I could not find any references to it, so I left it as-is. Tested by running the testsuite on gdb.python/*.exp; everything still passes. 2019-08-15 Christian Biesinger <cbiesinger@google.com> * python/lib/gdb/__init__.py (GdbOutputFile): Rename to have a leading underscore. (GdbOutputErrorFile): Likewise. (global scope): Adjust constructor calls to GdbOutput{,Error}File accordingly. (execute_unwinders): Rename to have a leading underscore. (auto_load_packages): Likewise. (global scope): Adjust call to auto_load_packages accordingly. (GdbSetPythonDirectory): Likewise. * python/py-unwind.c (pyuw_sniffer): Call _execute_unwinders instead of execute_unwinders. gdb/testsuite/ChangeLog: 2019-08-15 Christian Biesinger <cbiesinger@google.com> * gdb.python/python.exp: Expect a leading underscore on GdbOutput{,Error}File.
2019-08-07Make first and last lines of 'command help documentation' consistent.Philippe Waroquiers1-4/+4
With this patch, the help docs now respect 2 invariants: * The first line of a command help is terminated by a '.' character. * The last character of a command help is not a newline character. Note that the changes for the last invariant were done by Tom, as part of : [PATCH] Remove trailing newlines from help text https://sourceware.org/ml/gdb-patches/2019-06/msg00050.html but some occurrences have been re-introduced since then. Some help docs had to be rephrased/restructured to respect the above invariants. Before this patch, print_doc_line was printing the first line of a command help documentation, but stopping at the first '.' or ',' character. This was giving inconsistent results : * The first line of command helps was sometimes '.' terminated, sometimes not. * The first line of command helps was not always designed to be readable/understandable/unambiguous when stopping at the first '.' or ',' character. This e.g. created the following inconsistencies/problems: < catch exception -- Catch Ada exceptions < catch handlers -- Catch Ada exceptions < catch syscall -- Catch system calls by their names < down-silently -- Same as the `down' command while the new help is: > catch exception -- Catch Ada exceptions, when raised. > catch handlers -- Catch Ada exceptions, when handled. > catch syscall -- Catch system calls by their names, groups and/or numbers. > down-silently -- Same as the `down' command, but does not print anything. Also, the command help doc should not be terminated by a newline character, but this was not respected by all commands. The cli-option -OPT framework re-introduced some occurences. So, the -OPT build help framework was changed to not output newlines at the end of %OPTIONS% replacement. This patch changes the help documentations to ensure the 2 invariants given above. It implied to slightly rephrase or restructure some help docs. Based on the above invariants, print_doc_line (called by 'apropos' and 'help' commands to print the first line of a command help) now outputs the full first line of a command help. This all results in a lot of small changes in the produced help docs. There are less code changes than changes in the help docs, as a lot of docs are produced by some code (e.g. the remote packet usage settings). gdb/ChangeLog 2019-08-07 Philippe Waroquiers <philippe.waroquiers@skynet.be> * cli/cli-decode.h (print_doc_line): Add for_value_prefix argument. * cli/cli-decode.c (print_doc_line): Likewise. It now prints the full first line, except when FOR_VALUE_PREFIX. In this case, the trailing '.' is not output, and the first character is uppercased. (print_help_for_command): Update call to print_doc_line. (print_doc_of_command): Likewise. * cli/cli-setshow.c (deprecated_show_value_hack): Likewise. * cli/cli-option.c (append_indented_doc): Do not append newline. (build_help_option): Append newline after first appended_indented_doc only if a second call is done. (build_help): Append 2 new lines before each option, except the first one. * compile/compile.c (_initialize_compile): Add new lines after %OPTIONS%, when not at the end of the help. Change help doc or code producing the help doc to respect the invariants. * maint-test-options.c (_initialize_maint_test_options): Likewise. Also removed the new line after 'Options:', as all other commands do not put an empty line between 'Options:' and the first option. * printcmd.c (_initialize_printcmd): Likewise. * stack.c (_initialize_stack): Likewise. * interps.c (interpreter_exec_cmd): Fix "Usage:" line that was incorrectly telling COMMAND is optional. * ada-lang.c (_initialize_ada_language): Change help doc or code producing the help doc to respect the invariants. * ada-tasks.c (_initialize_ada_tasks): Likewise. * breakpoint.c (_initialize_breakpoint): Likewise. * cli/cli-cmds.c (_initialize_cli_cmds): Likewise. * cli/cli-logging.c (_initialize_cli_logging): Likewise. * cli/cli-setshow.c (_initialize_cli_setshow): Likewise. * cli/cli-style.c (cli_style_option::add_setshow_commands, _initialize_cli_style): Likewise. * corelow.c (core_target_info): Likewise. * dwarf-index-cache.c (_initialize_index_cache): Likewise. * dwarf2read.c (_initialize_dwarf2_read): Likewise. * filesystem.c (_initialize_filesystem): Likewise. * frame.c (_initialize_frame): Likewise. * gnu-nat.c (add_task_commands): Likewise. * infcall.c (_initialize_infcall): Likewise. * infcmd.c (_initialize_infcmd): Likewise. * interps.c (_initialize_interpreter): Likewise. * language.c (_initialize_language): Likewise. * linux-fork.c (_initialize_linux_fork): Likewise. * maint-test-settings.c (_initialize_maint_test_settings): Likewise. * maint.c (_initialize_maint_cmds): Likewise. * memattr.c (_initialize_mem): Likewise. * printcmd.c (_initialize_printcmd): Likewise. * python/lib/gdb/function/strfns.py (_MemEq, _StrLen, _StrEq, _RegEx): Likewise. * ravenscar-thread.c (_initialize_ravenscar): Likewise. * record-btrace.c (_initialize_record_btrace): Likewise. * record-full.c (_initialize_record_full): Likewise. * record.c (_initialize_record): Likewise. * regcache-dump.c (_initialize_regcache_dump): Likewise. * regcache.c (_initialize_regcache): Likewise. * remote.c (add_packet_config_cmd, init_remote_threadtests, _initialize_remote): Likewise. * ser-tcp.c (_initialize_ser_tcp): Likewise. * serial.c (_initialize_serial): Likewise. * skip.c (_initialize_step_skip): Likewise. * source.c (_initialize_source): Likewise. * stack.c (_initialize_stack): Likewise. * symfile.c (_initialize_symfile): Likewise. * symtab.c (_initialize_symtab): Likewise. * target-descriptions.c (_initialize_target_descriptions): Likewise. * top.c (init_main): Likewise. * tracefile-tfile.c (tfile_target_info): Likewise. * tracepoint.c (_initialize_tracepoint): Likewise. * tui/tui-win.c (_initialize_tui_win): Likewise. * utils.c (add_internal_problem_command): Likewise. * valprint.c (value_print_option_defs): Likewise. gdb/testsuite/ChangeLog 2019-08-07 Philippe Waroquiers <philippe.waroquiers@skynet.be> * gdb.base/style.exp: Update tests for help doc new invariants. * gdb.base/help.exp: Likewise.
2019-05-04Fix incorrect use of 'is' operator for comparison in ↵Raul Tambre1-2/+2
python/lib/gdb/command/prompt.py The 'is' operator is not meant to be used for comparisons. It currently working is an implementation detail of CPython. CPython 3.8 has added a SyntaxWarning for this.
2019-01-01Update copyright year range in all GDB files.Joel Brobecker23-23/+23
This commit applies all changes made after running the gdb/copyright.py script. Note that one file was flagged by the script, due to an invalid copyright header (gdb/unittests/basic_string_view/element_access/char/empty.cc). As the file was copied from GCC's libstdc++-v3 testsuite, this commit leaves this file untouched for the time being; a patch to fix the header was sent to gcc-patches first. gdb/ChangeLog: Update copyright year range in all GDB files.
2018-11-08Fix output indentation for "info pretty-printers"Tom Tromey1-1/+1
I noticed that "info pretty-printers" will indent the "objfile" line like: (top-gdb) info pretty-printer global pretty-printers: builtin mpx_bound128 objfile /home/tromey/gdb/build/gdb/gdb pretty-printers: type_lookup_function I think the "objfile" line should be "out-dented", following the same style as the "global" and "progspace" (not shown) lines. This patch implements this. gdb/ChangeLog 2018-11-08 Tom Tromey <tom@tromey.com> * python/lib/gdb/command/pretty_printers.py (InfoPrettyPrinter.invoke): Don't indent "objfile" heading.
2018-10-06Update help text for commands implemented in PythonTom Tromey9-218/+173
Philippe pointed out that the "enable frame-filter" help text looked funny. While fixing this I noticed a few more problems in the help text of commands written in Python: * Trailing newlines * Wrong style for metasyntactic variables * Indentation of the text * ... and finally, I thought the function usage lines didn't need that extra newline -- someday I'd like to be able to write a "usage" command that just greps for the Usage line, so ideally it would be tighter than what was done here This patch fixes all the problems I noticed. gdb/ChangeLog 2018-10-06 Tom Tromey <tom@tromey.com> * python/lib/gdb/function/strfns.py (_MemEq, _StrLen, _StrEq) (_RegEx): Reformat help text. * python/lib/gdb/function/caller_is.py (CallerIs, CallerMatches) (AnyCallerIs, AnyCallerMatches): Reformat help text. * python/lib/gdb/function/as_string.py (_AsString): Reformat help text. * python/lib/gdb/command/xmethods.py (InfoXMethod) (EnableXMethod, DisableXMethod): Remove help indentation. Capitalize meta-syntactic variables. * python/lib/gdb/command/unwinders.py (InfoUnwinder) (EnableUnwinder, DisableUnwinder): Remove help indentation. Capitalize meta-syntactic variables. * python/lib/gdb/command/explore.py (ExploreCommand) (ExploreValueCommand, ExploreTypeCommand): Reformat help text. * python/lib/gdb/command/type_printers.py (InfoTypePrinter) (EnableTypePrinter, DisableTypePrinter): Remove help indentation. * python/lib/gdb/command/pretty_printers.py (InfoPrettyPrinter): Remove help indentation. (EnablePrettyPrinter, DisablePrettyPrinter): Likewise. * python/lib/gdb/command/frame_filters.py (EnableFrameFilter) (DisableFrameFilter, SetFrameFilterPriority) (ShowFrameFilterPriority, InfoFrameFilter): Reword help text.
2018-09-18[OBVIOUS] enable frame-filter short help uses disable instead of enablePhilippe Waroquiers1-1/+1
Without the patch: (gdb) apropos able frame-filter disable frame-filter -- GDB command to disable the specified frame-filter enable frame-filter -- GDB command to disable the specified frame-filter With the patch: (gdb) apropos able frame-filter disable frame-filter -- GDB command to disable the specified frame-filter enable frame-filter -- GDB command to enable the specified frame-filter Pushed as obvious
2018-09-16Add more methods to gdb.ProgspaceTom Tromey1-3/+24
There are a number of global functions in the gdb Python module which really should be methods on Progspace. This patch adds new methods to Progspace and then redefines these globals in terms of these new methods. This version has been rebased on the related changes that Simon recently put in. Built and regtested on x86-64 Fedora 28. gdb/ChangeLog 2018-09-16 Tom Tromey <tom@tromey.com> * python/lib/gdb/__init__.py (current_progspace, objfiles) (solib_name, block_for_pc, find_pc_line): New functions. (execute_unwinders): Update. * python/py-block.c (gdbpy_block_for_pc): Remove. * python/py-inferior.c (infpy_get_progspace): New function. (inferior_object_getset) <progspace>: Add. * python/py-progspace.c (pspy_objfiles): Rewrite. (pspy_solib_name, pspy_block_for_pc) (pspy_find_pc_line, pspy_is_valid): New functions. (progspace_object_methods): Add entries for solib_name, block_for_pc, find_pc_line, is_valid. * python/python-internal.h (gdbpy_block_for_pc) (build_objfiles_list): Don't declare. * python/python.c: Don't include solib.h. (gdbpy_solib_name, gdbpy_find_pc_line) (gdbpy_get_current_progspace, build_objfiles_list) (gdbpy_objfiles): Remove. (GdbMethods) <current_progspace, objfiles, block_for_pc, solib_name, find_pc_line>: Remove entries. gdb/doc/ChangeLog 2018-09-16 Tom Tromey <tom@tromey.com> * python.texi (Basic Python): Update docs for find_pc_line, solib_name. (Progspaces In Python): Update docs for current_progspace. Document block_for_pc, find_pc_line, is_valid, nsolib_name. Move method documentation before example.
2018-01-02Update copyright year range in all GDB filesJoel Brobecker23-23/+23
gdb/ChangeLog: Update copyright year range in all GDB files
2017-03-22Import sys in gdb/python/lib/gdb/printer/bound_registers.pyJonah Graham1-0/+2
Pick up missing bits from the patch merged in. 2017-03-22 Jonah Graham <jonah@kichwacoders.com> PR gdb/19637 * python/lib/gdb/printer/bound_registers.py: Import sys.
2017-03-20Support rvalue references in the gdb python module (includes doc/)Artemiy Volkov2-2/+4
This patch adds the ability to inspect rvalue reference types and values using the gdb python module. This is achieved by creating two wrappers for valpy_reference_value(), using the ReferenceExplorer class to handle the objects of rvalue reference types and placing necessary checks for a TYPE_CODE_RVALUE_REF type code next to the checks for a TYPE_CODE_REF type code. gdb/ChangeLog PR gdb/14441 * doc/python.texi (Types in Python): Add TYPE_CODE_RVALUE_REF to table of constants. * python/lib/gdb/command/explore.py: Support exploring values of rvalue reference types. * python/lib/gdb/types.py: Implement get_basic_type() for rvalue reference types. * python/py-type.c (pyty_codes) <TYPE_CODE_RVALUE_REF>: New constant. * python/py-value.c (valpy_getitem): Add an rvalue reference check. (valpy_reference_value): Add new parameter "refcode". (valpy_lvalue_reference_value, valpy_rvalue_reference_value): New wrappers for valpy_reference_value(). * python/py-xmethods.c (gdbpy_get_xmethod_result_type) (gdbpy_invoke_xmethod): Likewise.
2017-03-17Fix PR gdb/19637: bound_registers.py: Add support for Python 3Jonah Graham1-0/+5
Fix this the same way gdb/python/lib/gdb/printing.py handles it. gdb/Changelog: 2017-03-17 Jonah Graham <jonah@kichwacoders.com> PR gdb/19637 * python/lib/gdb/printer/bound_registers.py: Add support for Python 3.
2017-01-01update copyright year range in GDB filesJoel Brobecker23-23/+23
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-07-12PR python/19293 - invalidate frame cache when unwinders changeTom Tromey2-0/+3
PR python/19293 notes that when a Python unwinder is disabled, the frame cache is not invalidated. This means that disabling an unwinder doesn't have any immediate effect -- but in my experience it's often the case that I want to enable or disable an unwinder in order to see what happens. This patch adds a new gdb.invalidate_cached_frames function and arranges for the relevant bits of library code to call it. I've only partially documented this function, considering a warning sufficient without going into all the reasons ordinary code should not call it. The name of the new function was taken from a comment in frame.h next to reinit_frame_cache. No new test as I think the updates to the existing test are sufficient to show that the code is working as intended. Built and regtested on x86-64 Fedora 23. 2016-07-12 Tom Tromey <tom@tromey.com> PR python/19293: * python/lib/gdb/command/unwinders.py (do_enable_unwinder): Call gdb.invalidate_cached_frames. * python/lib/gdb/unwinder.py (register_unwinder): Call gdb.invalidate_cached_frames. * python/python.c (gdbpy_invalidate_cached_frames): New function. (python_GdbMethods): Add entry for invalidate_cached_frames. 2016-07-12 Tom Tromey <tom@tromey.com> PR python/19293: * python.texi (Frames In Python): Document gdb.invalidate_cached_frames. 2016-07-12 Tom Tromey <tom@tromey.com> PR python/19293: * gdb.python/py-unwind-maint.exp: Update tests.
2016-06-29Fix PR python/20129 - use of non-existing variableTom Tromey1-2/+2
PR python/20129 concerns the error message one gets from a command like "disable frame-filter global NoSuchFilter". Currently this throws a second, unexpected, exception due to the use of a non-existing variable named "name". This patch adds regression tests and fixes a couple of spots to use the correct variable name. Built and regtested on x86-64 Fedora 23. 2016-06-29 Tom Tromey <tom@tromey.com> PR python/20129: * python/lib/gdb/command/frame_filters.py (_do_enable_frame_filter) (SetFrameFilterPriority._set_filter_priority): Use "frame_filter", not "name". 2016-06-29 Tom Tromey <tom@tromey.com> PR python/20129: * gdb.python/py-framefilter.exp: Add tests for setting priority and disabling of non-existent frame filter.
2016-06-23PR gdb/16483 - simplify "info frame-filters" outputTom Tromey1-32/+24
PR gdb/16483 notes that the output of "info frame-filters" is quite voluminous. In particular it prints an entry for each objfile, even if only to say that the objfile does not have any associated frame filters. I think it's better to only print output when there is a frame filter. There's nothing worth doing with the no-frame-filter information, and limiting the output makes it much more readable. Built and regtested on x86-64 Fedora 23. 2016-06-23 Tom Tromey <tom@tromey.com> PR gdb/16483: * python/lib/gdb/command/frame_filters.py (InfoFrameFilter.list_frame_filters): Rename to print_list. Print nothing if no filters found. Return value indicating whether filters were printed. (InfoFrameFilter.print_list): Remove. (InfoFrameFilter.invoke): Print message if no frame filters found. 2016-06-23 Tom Tromey <tom@tromey.com> PR gdb/16483: * gdb.python/py-framefilter.exp: Add "info frame-filter" test before any filters are loaded.
2016-03-10Add $_as_string convenience functionSimon Marchi1-0/+39
This patch is a follow-up to "Add printf format specifier for printing enumerator": https://sourceware.org/ml/gdb-patches/2016-02/msg00144.html Instead of having a solution specific to the printf command, Pedro suggested adding a general purpose function $_as_string() that would cover this use case and more. So, in order to print the textual label of an enum, one can use: (gdb) printf "Visiting node of type %s\n", $_as_string(node) Visiting node of type NODE_INTEGER gdb/ChangeLog: * data-directory/Makefile.in (PYTHON_FILE_LIST): Install gdb/function/as_string.py. * python/lib/gdb/function/as_string.py: New file. * NEWS: Mention the new $_as_string function. gdb/testsuite/ChangeLog: * gdb.python/py-as-string.exp: New file. * gdb.python/py-as-string.c: New file. gdb/doc/ChangeLog: * gdb.texinfo (Convenience Functions): Document $_as_string.
2016-01-20Fix sorting of enum values in FlagEnumerationPrinterSimon Marchi1-1/+1
The lambda function used to sort the enumerator list does not work properly. This list consists of tuples, (enum label, enum value). The key function returns x.enumval. enumval not being defined for a tuple, we see this exception in the test log: Python Exception <class 'AttributeError'> 'tuple' object has no attribute 'enumval' The function should return the second item of the tuple, which is the enumval. The pretty-printer still worked mostly correctly, except that the enumeration values were not sorted. The test still passed because the enumeration values are already sorted where they are defined. The test also passed despite the exception being printed, because the right output was printed after the exception: print (enum flag_enum) (FLAG_1) Python Exception <type 'exceptions.AttributeError'> 'tuple' objecthas no attribute 'enumval':M $7 = 0x1 [FLAG_1] (gdb) PASS: gdb.python/py-pp-maint.exp: print FLAG_1 New in v2: - Improved test case, I stole Pedro's example directly. It verifies that the sorting of enumerators by value works, by checking that printing FOO_MASK appears as FOO_1 | FOO_2 | FOO_3. I noticed that I could change the regexps to almost anything and the tests would still pass. I think it was because of the | in there. I made them more robust by using string_to_regexp. I used curly braces { } instead of quoting marks " " for strings, so that I could use square brackets [ ] in them without having to escape them all. I also removed the "message" part of the tests, since they are redundant with the command, and it's just more maintenance to have to update them. Tested with Python 2.7 and 3.5. gdb/ChangeLog: * python/lib/gdb/printing.py (FlagEnumerationPrinter.__call__): Fix enumerators sort key function. gdb/testsuite/ChangeLog: * gdb.python/py-pp-maint.exp: Change/add enum flag tests. * gdb.python/py-pp-maint.c (enum flag_enum): Use more complex enum flag values.
2016-01-19Fix enum flag with Python 3Simon Marchi1-1/+1
Using Python 3.5 (I assume it's the same with 3.4 and lower, but I didn't test), I see this: print (enum flag_enum) (FLAG_1)^M Python Exception <class 'TypeError'> %x format: an integer is required, not gdb.Value: ^M $7 = ^M (gdb) FAIL: gdb.python/py-pp-maint.exp: print FLAG_1 Apparently, this idiom, where v is a gdb.Value, was possible with Python 2, but not with Python 3: '%x' % v In Python 2, it would automatically get converted to an integer. To solve it, I simply added wrapped v in a call to int(). '%x' % int(v) In Python 2, the int type is implemented with a "long" in C, so on x86-32 it's 32-bits. I was worried that doing int(v) would truncate the value and give wrong results for enum values > 32-bits. However, the int type != the int function. The int function does the right thing, selecting the right integer type for the given value. I tested with large enum values on x86-32 and Python 2, and everything works as expected. gdb/ChangeLog: * python/lib/gdb/printing.py (_EnumInstance.to_string): Explicitly convert gdb.Value to integer type using int().
2016-01-01GDB copyright headers update after running GDB's copyright.py script.Joel Brobecker22-22/+22
gdb/ChangeLog: Update year range in copyright notice of all files.
2015-08-06PR python/17136Clem Dickey1-1/+1
gdb/ChangeLog: * python/lib/gdb/command/type_printers.py (InfoTypePrinter): Fix typo.
2015-05-08[PR python/18291] Fix printing of "disabled" status of xmethod matchers.Siva Chandra1-2/+2
gdb/ChangeLog: PR python/18291 * python/lib/gdb/command/xmethods.py (print_xm_info): Fix typo. Print xmethod matcher status. gdb/testsuite/ChangeLog: PR python/18291 * gdb.python/py-xmethods.exp: Add tests.
2015-04-29PR python/18285Doug Evans1-2/+18
gdb/ChangeLog: PR python/18285 * NEWS: Document new gdb.XMethodWorker.get_result_type method. * eval.c (evaluate_subexp_standard) <OP_FUNCALL>: Handle EVAL_AVOID_SIDE_EFFECTS for xmethods. * extension-priv.h (struct extension_language_ops) <get_xmethod_result_type>: New member. * extension.c (get_xmethod_result_type): New function. * extension.h (get_xmethod_result_type): Declare. * python/py-xmethods.c (get_result_type_method_name): New static global. (py_get_result_type_method_name): Ditto. (gdbpy_get_xmethod_result_type): New function. (gdbpy_initialize_xmethods): Initialize py_get_result_type_method_name. * python/python-internal.h (gdbpy_get_xmethod_result_type): Declare. * python/python.c (python_extension_ops): Add gdbpy_get_xmethod_result_type. * python/lib/gdb/xmethod.py (XMethodWorker): Add get_result_type. * valarith.c (value_x_binop): Handle EVAL_AVOID_SIDE_EFFECTS for xmethods. (value_x_unop): Ditto. * value.c (result_type_of_xmethod): New function. * value.h (result_type_of_xmethod): Declare. gdb/testsuite/ChangeLog: * gdb.python/py-xmethods.exp: Add ptype tests. * gdb.python/py-xmethods.py (E_method_char_worker): Add get_result_type method. gdb/doc/ChangeLog: * python.texi (Xmethod API) <gdb.XMethodWorker.get_result_type>: Document. (Writing an Xmethod): Add get_result_type to example.
2015-04-28PR python/18299Doug Evans1-3/+9
gdb/ChangeLog: PR python/18299 * python/lib/gdb/printing.py (register_pretty_printer): Handle name or __name__ attributes. Handle gdb module as first argument. gdb/testsuite/ChangeLog: * gdb.python/py-pp-maint.py: Move "replace" testing to ... * gdb.python/py-pp-registration.exp: ... here. New file. * gdb.python/py-pp-registration.c: New file. * gdb.python/py-pp-registration.py: New file.
2015-04-15Some Python 3 fixesSimon Marchi1-1/+1
Some missing parentheses and one itertools.imap (Py2) vs map (Py3) issue. gdb/ChangeLog: * python/lib/gdb/command/unwinders.py: Add parentheses. gdb/testsuite/ChangeLog: * gdb.python/py-framefilter.py (ErrorFilter.filter): Use map function if itertools.imap is not present. * gdb.python/py-objfile.exp: Add parentheses. * gdb.python/py-type.exp: Same. * gdb.python/py-unwind-maint.py: Same.
2015-04-01Add support for writing unwinders in Python.Sasha Smundak3-1/+329
gdb/ChangeLog: * Makefile.in (SUBDIR_PYTHON_OBJS): Add py-unwind.o. (SUBDIR_PYTHON_SRCS): Add py-unwind.c. (py-unwind.o): New recipe. * NEWS: mention Python frame unwinding. * data-directory/Makefile.in (PYTHON_FILE_LIST): Add gdb/unwinder.py and gdb/command/unwinder.py * python/lib/gdb/__init__.py (packages): Add frame_unwinders list. (execute_unwinders): New function. * python/lib/gdb/command/unwinders.py: New file. * python/lib/gdb/unwinder.py: New file. * python/py-objfile.c (objfile_object): Add frame_unwinders field. (objfpy_dealloc): Decrement frame_unwinders reference count. (objfpy_initialize): Create frame_unwinders list. (objfpy_get_frame_unwinders): New function. (objfpy_set_frame_unwinders): Ditto. (objfile_getset): Add frame_unwinders attribute to Objfile. * python/py-progspace.c (pspace_object): Add frame_unwinders field. (pspy_dealloc): Decrement frame_unwinders reference count. (pspy_initialize): Create frame_unwinders list. (pspy_get_frame_unwinders): New function. (pspy_set_frame_unwinders): Ditto. (pspy_getset): Add frame_unwinders attribute to gdb.Progspace. * python/py-unwind.c: New file. * python/python-internal.h (pspy_get_name_unwinders): New prototype. (objpy_get_frame_unwinders): New prototype. (gdbpy_initialize_unwind): New prototype. * python/python.c (gdbpy_apply_type_printers): Call gdbpy_initialize_unwind. gdb/doc/ChangeLog: * doc/python.texi (Writing a Frame Unwinder in Python): Add section. gdb/testsuite/ChangeLog: * gdb.python/py-unwind-maint.c: New file. * gdb.python/py-unwind-maint.exp: New test. * gdb.python/py-unwind-maint.py: New file. * gdb.python/py-unwind.c: New file. * gdb.python/py-unwind.exp: New test. * gdb.python/py-unwind.py: New test.
2015-01-01Update year range in copyright notice of all files owned by the GDB project.Joel Brobecker20-20/+20
gdb/ChangeLog: Update year range in copyright notice of all files.
2014-12-15python extended prompt: Use os.getcwd() instead of os.getcwdu()Simon Marchi1-1/+1
It seems like using os.getcwdu() here is wrong both for Python 2 and Python 3. For Python 2, this returns a 'unicode' object, which tries to get concatenated to a 'str' object in substitute_prompt. The implicit conversion works when the unicode string contains no accent. When it does contain an accent though, displaying the prompt results in the following error: (gdb) set extended-prompt \w ... File "/home/simark/build/binutils-gdb-python2/gdb/data-directory/python/gdb/prompt.py", line 138, in substitute_prompt result += str(cmd(arg)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 49: ordinal not in range(128) When using os.getcwd() instead, it works correctly. I suppose that Python does the necessary decoding internally. For Python 3, this method simply does not exist. It works fine with os.getcwd(). gdb/ChangeLog: * python/lib/gdb/prompt.py (_prompt_pwd): Use os.getcwd() instead of os.getcwdu().
2014-10-30Don't replace '\' with '\\' in before_prompt_hookYao Qi1-2/+1
In gdb/command/prompt.py:before_prompt_hook, the '\' in the new prompt is replaced with '\\', shown as below, > def before_prompt_hook(self, current): > if self.value is not '': > newprompt = gdb.prompt.substitute_prompt(self.value) > return newprompt.replace('\\', '\\\\') > else: > return None I don't see any explanations on this in comments nor email. As doc said, "set extended-prompt \w" substitute the current working directory, but it prints something different from what pwd or os.getcwdu() prints on mingw32 host. (gdb) python print os.getcwdu()^M \\build2-lucid-cs\yqi\yqi\arm-none-eabi (gdb) pwd^M Working directory \\build2-lucid-cs\yqi\yqi\arm-none-eabi (gdb) set extended-prompt \w \\\\build2-lucid-cs\\yqi\\yqi\\arm-none-eabi This makes me think whether the substitution in before_prompt_hook is necessary or not. This patch is to remove this substitution. Run gdb.python on x86_64-linux and arm-none-eabi on mingw32 host. No regressions. gdb: 2014-10-30 Yao Qi <yao@codesourcery.com> * python/lib/gdb/command/prompt.py (before_prompt_hook): Don't replace '\\' with '\\\\'.
2014-10-15PR python/17364Doug Evans4-16/+36
gdb/ChangeLog: * python/lib/gdb/__init__.py (packages): Add "printer". * python/lib/gdb/command/bound_registers.py: Moved to ... * python/lib/gdb/printer/bound_registers.py: ... here. Add printer to global set of builtin printers. Rename printer from "bound" to "mpx_bound128". * python/lib/gdb/printing.py (_builtin_pretty_printers): New global, registered as global "builtin" printer. (add_builtin_pretty_printer): New function. * data-directory/Makefile.in (PYTHON_FILE_LIST): Update, and add gdb/printer/__init__.py.
2014-09-06PR 15276: Add $_caller_is, $_caller_matches, $_any_caller_is, ↵Doug Evans1-0/+160
$_any_caller_matches gdb/ChangeLog: PR 15276 * NEWS: Mention $_caller_is, $_caller_matches, $_any_caller_is, $_any_caller_matches. * data-directory/Makefile.in (PYTHON_FILE_LIST): Add caller_is.py. * python/lib/gdb/function/caller_is.py: New file. gdb/testsuite/ChangeLog: PR 15276 * gdb.python/py-caller-is.c: New file. * gdb.python/py-caller-is.exp: New file. gdb/doc/ChangeLog: PR 15276 * gdb.texinfo (Convenience Funs): Document $_caller_is, $_caller_matches, $_any_caller_is, $_any_caller_matches.
2014-08-15Fix xmethod Python so that it works with Python3.Siva Chandra1-1/+1
gdb/ * python/lib/gdb/command/xmethods.py (set_xm_status1): Use the 'items' methods instead of 'iteritems' method on dictionaries. gdb/testsuite/ * gdb.python/py-xmethods.py (A_getarrayind) (E_method_char_worker.__call__, E_method_int_worker.__call__): Use 'print' with function call syntax. (E_method_matcher.match): Fix tab vs space indentation mixup.
2014-06-23Align behavior of xmethod commands with that of pretty-printer commands.Siva Chandra1-4/+6
Currently, the xmethod commands lookup xmethod matchers in the current progspace even if the locus regular expression matches the progspace's filename. Pretty printer commands do not match the current progspace's filename. gdb/ * python/lib/gdb/command/xmethods.py (get_method_matchers_in_loci): Lookup xmethod matchers in the current progspace only if the string "progspace" matches LOCUS_RE. gdb/testsuite * gdb.python/py-xmethods.exp: Use "progspace" instead of the progspace's filename in 'info', 'enable' and 'disable' command tests.
2014-06-03Xmethod support in Python.Siva Chandra3-0/+533
* python/py-xmethods.c: New file. * python/py-objfile.c (objfile_object): New field 'xmethods'. (objfpy_dealloc): XDECREF on the new xmethods field. (objfpy_new, objfile_to_objfile_object): Initialize xmethods field. (objfpy_get_xmethods): New function. (objfile_getset): New entry 'xmethods'. * python/py-progspace.c (pspace_object): New field 'xmethods'. (pspy_dealloc): XDECREF on the new xmethods field. (pspy_new, pspace_to_pspace_object): Initialize xmethods field. (pspy_get_xmethods): New function. (pspace_getset): New entry 'xmethods'. * python/python-internal.h: Add declarations for new functions. * python/python.c (_initialize_python): Invoke gdbpy_initialize_xmethods. * python/lib/gdb/__init__.py (xmethods): New attribute. * python/lib/gdb/xmethod.py: New file. * python/lib/gdb/command/xmethods.py: New file. testuite/ * gdb.python/py-xmethods.cc: New testcase to test xmethods. * gdb.python/py-xmethods.exp: New tests to test xmethods. * gdb.python/py-xmethods.py: Python script supporting the new testcase and tests.
2014-02-26[Python] Make regexp collection printers work with typedefs as well.Joel Brobecker1-0/+2
Consider the following type for which we would like to provide a pretty-printer and manage it via RegexpCollectionPrettyPrinter: typedef long time_t; Currently, this does not work because this framework only considers the type's tag name: typename = gdb.types.get_basic_type(val.type).tag if not typename: return None This patch extends it to use the type's name if the basic type does not have a tag name, thus allowing the framework to also work with typedefs like the above. gdb/ChangeLog: * python/lib/gdb/printing.py (RegexpCollectionPrettyPrinter): Use the type's name if its basic type does not have a tag. gdb/testsuite/ChangeLog: * testsuite/gdb.python/py-pp-re-notag.c: New file. * testsuite/gdb.python/py-pp-re-notag.ex: New file. * testsuite/gdb.python/py-pp-re-notag.p: New file.
2014-01-23avoid python exception in FrameDecorator.pyTom Tromey1-2/+10
This fixes a bug in FrameDecorator.py. FrameVars seems to assume that Frame.block can return None if there is no block. However, it actually throws an exception. I saw this bug while developing a frame filter, but unfortunately I don't know how to reproduce it. It seems to me that the SAL tests in _is_limited_frame should exclude the bad cases; and in my attempts to write a test they do. Nevertheless I think the fix is reasonably obvious and ought to go in. 2014-01-23 Tom Tromey <tromey@redhat.com> PR python/16485: * python/lib/gdb/FrameDecorator.py: (FrameVars.fetch_frame_args): Handle exception from frame.block. (FrameVars.fetch_frame_locals): Likewise.
2014-01-01Update Copyright year range in all files maintained by GDB.Joel Brobecker16-16/+16
2013-11-20Add pretty-printer for MPX bnd registers.Walfred Tedeschi1-0/+45
Boundary length is simpler implemented by means of a pretty printer. This simplifies users life when examining a bound register. Changelog: 2013-11-20 Walfred Tedeschi <walfred.tedeschi@intel.com> * python/lib/gdb/command/bound_register.py: New file. * gdb/data-directory/Makefile.in: copy bond_register.py to the right path to be initialized at gdb startup. testsuite/ * gdb.python/py-pp-maint.exp: Consider new pretty-print added for registers. Change-Id: Id4f39845e5ece56c370a1fd4343648909f08b731 Signed-off-by: Walfred Tedeschi <walfred.tedeschi@intel.com> Conflicts: gdb/ChangeLog
2013-10-022013-10-02 Phil Muldoon <pmuldoon@redhat.com>Phil Muldoon1-2/+5
* python/lib/gdb/command/frame_filters.py (InfoFrameFilter.list_frame_filters): Retrieve exception manually. (ShowFrameFilterPriority.invoke): Ditto.
2013-08-292013-08-29 Phil Muldoon <pmuldoon@redhat.com>Phil Muldoon4-18/+35
* python/py-framefilter.c (py_print_frame): Remove usage of PyString_AsString. Use python_string_to_host_string instead. Refactor function to work with a string as a new allocation instead of a pointer. (py_print_frame): Ditto. * python/lib/gdb/frames.py (return_list): Cain iterators together instead of adding them as a list. (_sort_list): Call return_list, and remove duplicate code. (execute_frame_filters): Convert iterator to a list with list(). * python/lib/gdb/command/frame_filters.py (SetFrameFilterPriority._set_filter_priority): Convert priority attribute to an integer. * python/lib/gdb/FrameIterator.py (FrameIterator.next): Define wrapper function __next__. * python/lib/gdb/FrameDecorator.py: If basestring not defined, define as "str". 2013-08-29 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/py-framefilter.py (FrameFilter.filter): Check itertools for imap attribute. Otherwise use map(). (ElidingIterator): Define wrapper function __next__. * gdb.python/py-framefilter-mi.exp: Do not use execfile, use exec (open (read ())) instead. * gdb.python/py-framefilter.exp: Ditto. * gdb.python/py-arch.exp: Update print based test to Python 3.x compliance. * gdb.python/py-frame.exp: Ditto. * gdb.python/py-type.exp: Ditto.
2013-05-102013-05-10 Phil Muldoon <pmuldoon@redhat.com>Phil Muldoon5-0/+1022
* stack.c (backtrace_command_1): Add "no-filters", and Python frame filter logic. (backtrace_command): Add "no-filters" option parsing. (_initialize_stack): Alter help to reflect "no-filters" option. * Makefile.in (SUBDIR_PYTHON_OBS): Add py-framefilter.o (SUBDIR_PYTHON_SRCS): Add py-framefilter.c (py-frame.o): Add target * data-directory/Makefile.in (PYTHON_DIR): Add Python frame filter files. * python/python.h: Add new frame filter constants, and flag enum. (apply_frame_filter): Add definition. * python/python.c (apply_frame_filter): New non-Python enabled function. * python/py-utils.c (py_xdecref): New function. (make_cleanup_py_xdecref): Ditto. * python/py-objfile.c: Declare frame_filters dictionary. (objfpy_dealloc): Add frame_filters dealloc. (objfpy_new): Initialize frame_filters attribute. (objfile_to_objfile_object): Ditto. (objfpy_get_frame_filters): New function. (objfpy_set_frame_filters): New function. * python/py-progspace.c: Declare frame_filters dictionary. (pspy_dealloc): Add frame_filters dealloc. (pspy_new): Initialize frame_filters attribute. (pspacee_to_pspace_object): Ditto. (pspy_get_frame_filters): New function. (pspy_set_frame_filters): New function. * python/py-framefilter.c: New file. * python/lib/gdb/command/frame_filters.py: New file. * python/lib/gdb/frames.py: New file. * python/lib/gdb/__init__.py: Initialize global frame_filters dictionary * python/lib/gdb/FrameDecorator.py: New file. * python/lib/gdb/FrameIterator.py: New file. * mi/mi-cmds.c (mi_cmds): Add frame filters command. * mi/mi-cmds.h: Declare. * mi/mi-cmd-stack.c (mi_cmd_stack_list_frames): Add --no-frame-filter logic, and Python frame filter logic. (stack_enable_frame_filters): New function. (parse_no_frame_option): Ditto. (mi_cmd_stack_list_frames): Add --no-frame-filter and Python frame filter logic. (mi_cmd_stack_list_locals): Ditto. (mi_cmd_stack_list_args): Ditto. (mi_cmd_stack_list_variables): Ditto. * NEWS: Add frame filter note. 2013-05-10 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/py-framefilter.py: New File. * gdb.python/py-framefilter-mi.exp: Ditto. * gdb.python/py-framefilter.c: Ditto. * gdb.python/py-framefilter-mi.exp: Ditto. * gdb.python/py-framefilter-mi.c: Ditto, * gdb.python/py-framefilter-gdb.py.in: Ditto. 2013-05-10 Phil Muldoon <pmuldoon@redhat.com> * gdb.texinfo (Backtrace): Add "no-filter" argument. (Python API): Add Frame Filters API, Frame Wrapper API, Writing a Frame Filter/Wrapper, Managing Management of Frame Filters chapter entries. (Frame Filters API): New Node. (Frame Wrapper API): New Node. (Writing a Frame Filter): New Node. (Managing Frame Filters): New Node. (Progspaces In Python): Add note about frame_filters attribute. (Objfiles in Python): Ditto. (GDB/MI Stack Manipulation): Add -enable-frame-filters command, @anchors and --no-frame-filters option to -stack-list-variables, -stack-list-frames, -stack-list-locals and -stack-list-arguments commands.
2013-01-21 * python/lib/gdb/commands/explore.pySiva Chandra Reddy1-1/+2
(CompoundExplorer.explore_expr): Correct the name of a method being invoked. (ExploreTypeCommand.invoke): Add a missing 'return'. * testsuite/gdb.python/py-explore.exp: Improve a test
2013-01-01Update years in copyright notice for the GDB files.Joel Brobecker11-11/+11
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-12Add support for Python 3.Paul Koning6-55/+54
* NEWS: Mention Python 3 support. * varobj.c (value_get_print_value): Use python_string_to_target_string. * python/py-block.c: Use PyVarObject_HEAD_INIT in initialization of type objects. * python/py-breakpoint.c: Ditto. * python/py-cmd.c: Ditto. * python/py-event.c: Ditto. * python/py-event.h: Ditto. * python/py-evtregistry.c: Ditto. * python/py-finishbreakpoint.c: Ditto. * python/py-frame.c: Ditto. * python/py-function.c: Ditto. * python/py-infthread.c: Ditto. * python/py-lazy-string.c: Ditto. * python/py-progspace.c: Ditto. * /python/py-symbol.c: Ditto. * python/py-evts.c: (gdbpy_initialize_py_events): Add module initialization for Python 3. * python/py-inferior.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (infpy_read_memory): Return memoryview object if Python 3. (infpy_write_memory): Use "s*" operand parsing code for Python 3. (infpy_search_memory): Ditto. (get_buffer): New function for Python 3. * python/py-objfile.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (objfpy_dealloc): Use Py_TYPE to call tp_free. * python/py-param.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (get_attr): Use PyUnicode_CompareWithASCIIString if Python 3. (set_attr): Ditto. * python/py-prettyprint.c (print_string_repr): use PyBytes methods instead of PyString methods if Python 3. (print_children): Skip push_dummy_python_frame call if Python 3. * python/py-symtab.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (salpy_dealloc): Use Py_TYPE to call tp_free. * python/py-type.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (field_dealloc): Use Py_TYPE to call tp_free. (typy_dealloc): Ditto. (type_object_as_number): Adjust struct initializations for differences in layout for Python 2 vs. Python 3. * python/py-utils.c (python_string_to_unicode): Omit non-Unicode string case for Python 3. (unicode_to_encoded_python_string): Shorten code (no functional change). (python_string_to_target_python_string): Comment that in Python 3 returned value is a Python "bytes" type. (gdbpy_is_string): Omit non-Unicode string check in Python 3. (gdb_py_object_from_longest): Omit non-long integer case in Python 3. (gdb_py_object_from_ulongest): Ditto. * python/py-value.c: Use PyVarObject_HEAD_INIT in initialization of type objects. (valpy_dealloc): Use Py_TYPE to call tp_free. (valpy_int): Omit function if Python 3. (convert_value_from_python): Use "%S" format (Python object as a string) if Python 3. (value_object_as_number): Adjust struct initializations for differences in layout for Python 2 vs. Python 3. * python/python-config.py: Adjust syntax for Python 3 compatibility. Include "sys.abiflags" string as part of python library name, if that attribute exists (Python 3). * python/python-internal.h (IS_PY3): Define if Python 3. (Py_TPFLAGS_HAVE_ITER, Py_TPFLAGS_CHECKTYPES): Define with placeholder value if Python 3. (PyInt_Check, PyInt_FromLong, PyInt_AsLong, PyString_FromString, PyString_Decode, PyString_FromFormat, PyString_Check): Define as analogous Python 3 API function if Python 3. (PyVarObject_HEAD_INIT): Define if not already defined. (Py_TYPE): Ditto. * python/python.c (eval_python_command): Omit Py_FlushLine call if Python 3. Check return values of all Python API calls for error. Supply dummy "python" and "python-interactive" commands if Python initialization failed. (_initialize_python): Convert argc to wchar_t** if Python 3. Add module initialization for Python 3. (finish_python_initialization): Pass wchar_t * argument to PySys_SetPath if Python 3. * python/lib/gdb/__init__.py: Define "reload" if Python 3. (_GdbFile): New class for common output file behavior. (GdbOutFile): Subclass from _GdbFile. (GdbOutputErrorFile): Ditto. (auto_load_packages): Adjust syntax for Python 3 compatibility. * python/lib/gdb/printing.py: Define basestr and int if Python 3. * python/lib/gdb/prompt.py: Use sorted() function rather than sort() method. * python/lib/gdb/command/explore.py: Define raw_input if Python 3. Adjust syntax for Python 3 compatibility. * python/lib/gdb/command/pretty_printers.py: Use sorted() function rather than sort() method. Adjust syntax for Python 3 compatibility. * python/lib/gdb/command/type_printers.py: Ditto. * doc/gdb.texinfo (Inferior.read_memory): Mention that the return value is a memoryview object if Python 3.
2012-11-12 * NEWS: Update.Tom Tromey3-0/+193
* data-directory/Makefile.in (PYTHON_FILES): Add type_printers.py. * python/lib/gdb/command/type_printers.py: New file. * python/lib/gdb/command/types.py (TypePrinter): New class. (_get_some_type_recognizers, get_type_recognizers, apply_type_recognizers, register_type_printer): New functions. * python/py-objfile.c (objfile_object) <type_printers>: New field. (objfpy_dealloc): Decref new field. (objfpy_new): Set new field. (objfpy_get_type_printers, objfpy_set_type_printers): New functions. (objfile_to_objfile_object): Set new field. (objfile_getset): Add "type_printers". * python/py-progspace.c (pspace_object) <type_printers>: New field. (pspy_dealloc): Decref new field. (pspy_new): Set new field. (pspy_get_type_printers, pspy_set_type_printers): New functions. (pspace_to_pspace_object): Set new field. (pspace_getset): Add "type_printers". * python/python.c (start_type_printers, apply_type_printers, free_type_printers): New functions. (_initialize_python): Set gdb.type_printers. * python/python.h (start_type_printers, apply_type_printers, free_type_printers): Declare. * typeprint.c (type_print_raw_options, default_ptype_flags): Update for new fields. (do_free_global_table, create_global_typedef_table, find_global_typedef): New functions. (find_typedef_in_hash): Use find_global_typedef. (whatis_exp): Use create_global_typedef_table. Change cleanup handling. * typeprint.h (struct type_print_options) <global_typedefs, global_printers>: New fields. doc * gdb.texinfo (Symbols): Document "info type-printers", "enable type-printer" and "disable type-printer". (Python API): Add new node to menu. (Type Printing API): New node. (Progspaces In Python): Document type_printers field. (Objfiles In Python): Likewise. (gdb.types) <get_type_recognizers, apply_type_recognizers, register_type_printer, TypePrinter>: Document. testsuite * gdb.base/completion.exp: Update for "info type-printers". * gdb.python/py-typeprint.cc: New file. * gdb.python/py-typeprint.exp: New file. * gdb.python/py-typeprint.py: New file.