8000 Make lltrace output human-readable. · Issue #91462 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Make lltrace output human-readable. #91462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sweeneyde opened this issue Apr 12, 2022 · 1 comment
Closed

Make lltrace output human-readable. #91462

sweeneyde opened this issue Apr 12, 2022 · 1 comment
Labels
type-feature A feature request or enhancement

Comments

@sweeneyde
Copy link
Member

Now:

Python 3.11.0a7+ (main, Apr 11 2022, 20:06:08) [MSC v.1931 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():
...     for i in range(2):
...         print(i)
...
>>> __ltrace__ = 1
>>> f()
-1: 151, 0
0: 2
1: 101, 0
push <function f at 0x00000256998C2360>
2: 166, 0
3: 171, 0
stackadj <function f at 0x00000256998C2360>
stackadj <function f at 0x00000256998C2360>
-1: 151, 0
0: 116, 1
stackadj <nil>
push <class 'range'>
1: 100, 1
push 2
7: 166, 1
8: 171, 1
stackadj 2
stackadj <class 'range'>
push range(0, 2)
10: 68
push 0
pop 0
17: 116, 3
stackadj <nil>
push <built-in function print>
18: 124, 0
push 0
24: 166, 1
25: 171, 1
0
stackadj 0
stackadj <built-in function print>
push None
27: 1
pop None
32: 140, 18
33: 93, 17
push 1
pop 1
17: 116, 3
stackadj <nil>
push <built-in function print>
18: 124, 0
push 1
24: 166, 1
25: 171, 1
1
stackadj 1
stackadj <built-in function print>
push None
27: 1
pop None
32: 140, 18
33: 93, 17
stackadj <range_iterator object at 0x000002569973F240>
16: 100, 0
push None
34: 83
pop None
9: 70
pop None
10: 100, 0
push None
11: 83
pop None

What's possible:

Python 3.11.0a7+ (main, Apr 11 2022, 20:06:08) [MSC v.1931 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():
...     for i in range(2):
...         print(i)
...
>>> __ltrace__ = 1
>>> f()
Resuming frame for '<module>'
[]
-1: RESUME 0
[]
0: PUSH_NULL
[<nil>, ]
1: LOAD_NAME 0
[<nil>, <function f at 0x0000016650F52360>, ]
2: PRECALL 0
[<nil>, <function f at 0x0000016650F52360>, ]
3: CALL 0
Resuming frame for 'f' in module '__main__'
[]
-1: RESUME 0
[]
0: LOAD_GLOBAL 1
[<nil>, <class 'range'>, ]
1: LOAD_CONST 1
[<nil>, <class 'range'>, 2, ]
7: PRECALL 1
[<nil>, <class 'range'>, 2, ]
8: CALL 1
[range(0, 2), ]
10: GET_ITER
[<range_iterator object at 0x0000016650D3F240>, ]
17: LOAD_GLOBAL 3
[<range_iterator object at 0x0000016650D3F240>, <nil>, <built-in function print>, ]
18: LOAD_FAST 0
[<range_iterator object at 0x0000016650D3F240>, <nil>, <built-in function print>, 0, ]
24: PRECALL 1
[<range_iterator object at 0x0000016650D3F240>, <nil>, <built-in function print>, 0, ]
25: CALL 1
0
[<range_iterator object at 0x0000016650D3F240>, None, ]
27: POP_TOP
[<range_iterator object at 0x0000016650D3F240>, ]
32: JUMP_BACKWARD 18
[<range_iterator object at 0x0000016650D3F240>, ]
33: FOR_ITER 17
[<range_iterator object at 0x0000016650D3F240>, ]
17: LOAD_GLOBAL 3
[<range_iterator object at 0x0000016650D3F240>, <nil>, <built-in function print>, ]
18: LOAD_FAST 0
[<range_iterator object at 0x0000016650D3F240>, <nil>, <built-in function print>, 1, ]
24: PRECALL 1
[<range_iterator object at 0x0000016650D3F240>, <nil>, <built-in function print>, 1, ]
25: CALL 1
1
[<range_iterator object at 0x0000016650D3F240>, None, ]
27: POP_TOP
[<range_iterator object at 0x0000016650D3F240>, ]
32: JUMP_BACKWARD 18
[<range_iterator object at 0x0000016650D3F240>, ]
33: FOR_ITER 17
[]
16: LOAD_CONST 0
[None, ]
34: RETURN_VALUE
Resuming frame for '<module>'
[None, ]
9: PRINT_EXPR
[]
10: LOAD_CONST 0
[None, ]
11: RETURN_VALUE

This can make use of the new _PyOpcode_OpName[256] from #91428.

@sweeneyde
Copy link
Member Author

By the way, it looks like the reason it's __ltrace__ is not __lltrace__ is a typo from 10 years ago that's persisted ever since: 3c1e481

sweeneyde added a commit that referenced this issue Apr 16, 2022
* Transform opcodes into opnames
* Print the whole stack at each opcode, and eliminate prtrace output at each (push/pop/stackadj)
* Display info about the function at each resume_frame
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants
0