Changing the stack format of pdb

Hi all,

There’s an issue Improve stack trace from where command in pdb · Issue #104316 · python/cpython · GitHub proposing an improvement for pdb stack output. The format not only lives in “where” command, but also every time the debugger is triggered.

I like the proposal, but it’s a breaking change and might affect the existing tools that depend on it.

The reason I like it is because it displays the most interesting information at the start of the line - where most people pay attention to first. Also, it would be nice to have a consistent file:lineno format in pdb(breakpoint uses it).

Before

(Pdb) w
  /home/gaogaotiantian/programs/cpython/scrabble.py(5)<module>()
-> f()
> /home/gaogaotiantian/programs/cpython/scrabble.py(3)f()
-> a = 1

After

(Pdb) w
  <module> (/home/gaogaotiantian/programs/cpython/scrabble.py:5)
-> f()
> f (/home/gaogaotiantian/programs/cpython/scrabble.py:3)
-> a = 1

Anyone has opinions on this change or something that I did not think of that could negatively affect the users?

1 Like

Don’t want to enter a bikeshed argument, but the current format with the function name at the end is consistent with regular exception tracebacks.

That’s true, but in tracebacks, it’s much better formatted and the function name stands out well.

File "/home/gaogaotiantian/programs/cpython/scrabble.py", line 3, in f

is significantly better than

/home/gaogaotiantian/programs/cpython/scrabble.py(3)f()

Then why not make pdb tracebacks more similar to exception tracebacks?

Hi!

I think this is “little” change with a big impact. I’m not sure, but it can break not only tests, also other tools (I don’t know). Did you check those points?

That’s another possibility. My concern is that if the stack format is too similar to the exception, the user might think they got an error when they print the stack - it’s just their impression when they see that format.

Yes, we need to change tests for pdb, and it’s possible that other libraries rely on that format, and that’s why I’m asking for opinions. The test modification for pdb is easy, I don’t know how many tools out there are relying on this specific format. pdb is a relatively independent tool and I believe most of the debuggers that are built on pdb are implementing the stack format themselves.

It is definitely a trade off. I’m in favor of changing it but I’m not pushing it. I’m open to all ideas and suggestions.