Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Document Tips for Debugging C Extensions #35100
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
Document Tips for Debugging C Extensions #35100
Changes from 2 commits
4fa85c6
a792267
61654dd
aa8ad1f
ca29cfd
177ad89
e699c5b
7166d52
0f5dd5e
83762ba
644acef
5ca314f
d80688c
1c67b2d
aa324e5
3b8de2e
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I guess Python by default (at least locally and looking at some of the CI builds) includes the
-g
flag as part of the CFLAGS that distutils uses to compile extensions, so in the current setup this does nothing.According to SO we can override that by appending here, which might help reduce file size by removing those symbols:
https://stackoverflow.com/a/37952343/621736
I can also remove this from this PR if deemed too orthogonal. IIRC @xhochy or @TomAugspurger may have experience with stripping debug symbols from built distributions
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.
Multibuild may do this by default now? I don't recall.
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.
Yes, multibuild includes this nowadays.
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.
distutils adds NDEBUG and -O3 by default it seems without a feasible way to remove those compilation flags. Appending these at the end should override those according to the SO link shared above
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.
I don't recommend building with
-O0
actually as it hides a lot of problems. In case of-O0
memory is mored often zeroed and thus invalid memory access is not that fatal (in the higher-Ox
cases you would get random data). This makes the detection of bugs a lot harder. It might be better to keep the optimization level here and add flags that make debugging easier. Personally I like-ggdb -fno-omit-frame-pointer
. This gives better stacktraces and a bit more debugging information.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.
gdb suggests turning off optimizations:
https://sourceware.org/gdb/onlinedocs/gdb/Optimized-Code.html
There are certainly exceptions but I think as a general rule (especially for people that aren't super well versed in debugging the extensions yet) that no optimizations will be easier to follow
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.
Yes, the debug information with
-O0
is definitely better, I would like to leave-fno-omit-frame-pointer
somewhere here in the document as this is the option that provides the most debug information for the smallest performance hit and is really useful if you have an memory-out-of-bounds issue that wouldn't occur easily in the unoptimized version.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.
Sounds good. I think this is off by default with -O0 per the docs but doesn't hurt to add again
https://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Optimize-Options.html