binutils-gdb/gdb/python
Tom de Vries bdfc1e8a0b [gdb/cli] Don't let python colorize strip leading newlines
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-04-10 09:29:52 +02:00
..
lib/gdb [gdb/cli] Don't let python colorize strip leading newlines 2020-04-10 09:29:52 +02:00
py-all-events.def Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-arch.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-auto-load.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-block.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-bpevent.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-breakpoint.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-cmd.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-continueevent.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-event-types.def Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-event.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-event.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-events.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-evtregistry.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-evts.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-exitedevent.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-finishbreakpoint.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-frame.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-framefilter.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-function.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-gdb-readline.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-inferior.c gdb: remove use of iterate_over_inferiors in py-inferior.c 2020-01-17 09:51:10 -05:00
py-infevents.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-infthread.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-instruction.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-instruction.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-lazy-string.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-linetable.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-newobjfileevent.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-objfile.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-param.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-prettyprint.c Change extension language pretty-printers to use value API 2020-03-13 18:03:42 -06:00
py-progspace.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-record-btrace.c Fix some spelling errors. 2020-01-16 16:46:25 -06:00
py-record-btrace.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-record-full.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-record-full.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-record.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-record.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-ref.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-signalevent.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-stopevent.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-stopevent.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-symbol.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-symtab.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-threadevent.c Multi-target support 2020-01-10 20:06:08 +00:00
py-tui.c Fix py-tui.c build problem 2020-03-31 14:09:36 -06:00
py-type.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-unwind.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-utils.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-value.c Change extension language pretty-printers to use value API 2020-03-13 18:03:42 -06:00
py-varobj.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
py-xmethods.c Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00
python-config.py configure uses incorrect link order when testing libpython 2018-05-04 10:08:09 -04:00
python-internal.h Change extension language pretty-printers to use value API 2020-03-13 18:03:42 -06:00
python.c Allow TUI windows in Python 2020-02-22 12:57:25 -07:00
python.h Update copyright year range in all GDB files. 2020-01-01 10:20:53 +04:00