Skip to content
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

Warn unsuspecting readers that thread stacks are in reverse order #63505

Closed
gvanrossum opened this issue Oct 20, 2013 · 8 comments
Closed

Warn unsuspecting readers that thread stacks are in reverse order #63505

gvanrossum opened this issue Oct 20, 2013 · 8 comments
Assignees
Labels
easy type-feature A feature request or enhancement

Comments

@gvanrossum
Copy link
Member

BPO 19306
Nosy @gvanrossum, @pitrou, @vstinner
Files
  • traceback.diff
  • traceback2.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/vstinner'
    closed_at = <Date 2013-10-21.02:18:37.670>
    created_at = <Date 2013-10-20.00:23:25.145>
    labels = ['easy', 'type-feature']
    title = 'Warn unsuspecting readers that thread stacks are in reverse order'
    updated_at = <Date 2013-10-21.08:00:25.051>
    user = 'https://github.com/gvanrossum'

    bugs.python.org fields:

    activity = <Date 2013-10-21.08:00:25.051>
    actor = 'vstinner'
    assignee = 'vstinner'
    closed = True
    closed_date = <Date 2013-10-21.02:18:37.670>
    closer = 'gvanrossum'
    components = []
    creation = <Date 2013-10-20.00:23:25.145>
    creator = 'gvanrossum'
    dependencies = []
    files = ['32236', '32267']
    hgrepos = []
    issue_num = 19306
    keywords = ['patch', 'easy']
    message_count = 8.0
    messages = ['200527', '200537', '200550', '200655', '200660', '200678', '200685', '200712']
    nosy_count = 4.0
    nosy_names = ['gvanrossum', 'pitrou', 'vstinner', 'python-dev']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue19306'
    versions = ['Python 3.4']

    @gvanrossum
    Copy link
    Member Author

    I was confused for a while when seeing the thread stacks dumped by the faulthandler module. (See bpo-19293.)

    I propose the following tweaks of the output to make this more obvious. The first chunk changes the header written when called as _Py_DumpTraceback(), the second change the per-thread headers printed by _Py_DumpTracebackThreads().

    diff -r 02f6922e6a7e Python/traceback.c
    --- a/Python/traceback.c        Sat Oct 19 17:04:25 2013 -0700
    +++ b/Python/traceback.c        Sat Oct 19 17:19:29 2013 -0700
    @@ -603,7 +603,7 @@
         unsigned int depth;
         if (write_header)
    -        PUTS(fd, "Traceback (most recent call first):\n");
    +        PUTS(fd, "Stack (most recent call first):\n");
         frame = _PyThreadState_GetFrame(tstate);
         if (frame == NULL)
    @@ -642,7 +642,7 @@
         else
             PUTS(fd, "Thread 0x");
         dump_hexadecimal(sizeof(long)*2, (unsigned long)tstate->thread_id, fd);
    -    PUTS(fd, ":\n");
    +    PUTS(fd, " (most recent call first):\n");
     }

    const char*

    @gvanrossum gvanrossum added easy type-feature A feature request or enhancement labels Oct 20, 2013
    @pitrou pitrou assigned vstinner and unassigned pitrou Oct 20, 2013
    @gvanrossum
    Copy link
    Member Author

    BTW, another oddity in traceback.c: dump_hexadecimal() has the "int fd" argument at the end, while all other dump_*() functions have it at the front -- even its cousin dump_decimal(). Here's a patch that includes a fix.

    @vstinner
    Copy link
    Member

    You must update unit tests in test_faulthandler.

    @gvanrossum
    Copy link
    Member Author

    New patch, with fixed test.

    TBH now I'm getting worried that other programs may exist that parse this format and will get confused.

    @vstinner
    Copy link
    Member

    TBH now I'm getting worried that other programs may exist that parse this format and will get confused.

    A program parsing faulthandler output? Seriously? It would be nice, but I don't know any.

    Anyway, such program would probably use a regex to parse the output, and it's very easy to support Python 3.3 format and patched (future 3.4) format.

    New patch, with fixed test.

    Thanks. The patch looks good to me, you can push it.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 21, 2013

    New changeset cc8c37b5b449 by Guido van Rossum in branch 'default':
    bpo-19306: Add extra hints to faulthandler stack dumps that they are upside down.
    http://hg.python.org/cpython/rev/cc8c37b5b449

    @gvanrossum
    Copy link
    Member Author

    On Victor's authority, committed. I've also (separately) committed some doc changes.

    @vstinner
    Copy link
    Member

    Thanks. "(most recent call first)" was already present in some cases, but I forgot to mention it in all cases.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants