diff options
author | Tom de Vries <tdevries@suse.de> | 2020-04-10 09:29:52 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2020-04-10 09:29:52 +0200 |
commit | bdfc1e8a0b176257bfc700de755463d3aaf69849 (patch) | |
tree | e6bc80562d94cb41dbdbcd0d129da3801a0e9803 /gdb/python | |
parent | 6993bae0747240e6a632233d9700bd72f46fd55d (diff) | |
download | gdb-bdfc1e8a0b176257bfc700de755463d3aaf69849.zip gdb-bdfc1e8a0b176257bfc700de755463d3aaf69849.tar.gz gdb-bdfc1e8a0b176257bfc700de755463d3aaf69849.tar.bz2 |
[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.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/lib/gdb/__init__.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py index a1aac00..3dfb51b 100644 --- a/gdb/python/lib/gdb/__init__.py +++ b/gdb/python/lib/gdb/__init__.py @@ -216,7 +216,7 @@ try: def colorize(filename, contents): # Don't want any errors. try: - lexer = lexers.get_lexer_for_filename(filename) + lexer = lexers.get_lexer_for_filename(filename, stripnl=False) formatter = formatters.TerminalFormatter() return highlight(contents, lexer, formatter) except: |