-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-127604: Don't rely on dprintf() for faulthandler C stacks
#132800
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1210,7 +1210,7 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size) | |
| || info[i].dli_fname == NULL | ||
| || info[i].dli_fname[0] == '\0' | ||
| ) { | ||
| dprintf(fd, " Binary file '<unknown>' [%p]\n", array[i]); | ||
| _Py_fdprintf(fd, " Binary file '<unknown>' [%p]\n", array[i]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be safer to not use printf family but use traceback.c functions to write directly into the fd. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, but then we have to deal with stack limits. I'll probably end up using those regardless, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote #132854 to replace dprintf() with _Py_write_noraise(). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Which stack limits? traceback.c code is designed to use little stack memory and be async-signal safe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking of a |
||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -1222,9 +1222,9 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size) | |
|
|
||
| if (info[i].dli_sname == NULL | ||
| && info[i].dli_saddr == 0) { | ||
| dprintf(fd, " Binary file \"%s\" [%p]\n", | ||
| info[i].dli_fname, | ||
| array[i]); | ||
| _Py_fdprintf(fd, " Binary file \"%s\" [%p]\n", | ||
| info[i].dli_fname, | ||
| array[i]); | ||
| } | ||
| else { | ||
| char sign; | ||
|
|
@@ -1238,10 +1238,10 @@ _Py_backtrace_symbols_fd(int fd, void *const *array, Py_ssize_t size) | |
| offset = info[i].dli_saddr - array[i]; | ||
| } | ||
| const char *symbol_name = info[i].dli_sname != NULL ? info[i].dli_sname : ""; | ||
| dprintf(fd, " Binary file \"%s\", at %s%c%#tx [%p]\n", | ||
| info[i].dli_fname, | ||
| symbol_name, | ||
| sign, offset, array[i]); | ||
| _Py_fdprintf(fd, " Binary file \"%s\", at %s%c%#tx [%p]\n", | ||
| info[i].dli_fname, | ||
| symbol_name, | ||
| sign, offset, array[i]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need
close()here, becausefclose()closes the file descriptor.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm not used to going between
FILE *andintlike this. Fixed it.