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

[Logs] print size and caps when malloc fails (IDFGH-9267) #10650

Conversation

chipweinberger
Copy link
Contributor

@chipweinberger chipweinberger commented Jan 30, 2023

Before: Memory allocation failed.

After: Mem alloc fail. size 1600 caps 0x8

When memory allocation fails, we don't get many details. This adds a little bit more info.

I avoided using snprintf, due stack size concerns.

@chipweinberger chipweinberger force-pushed the user/chip/malloc-fail-abort-string branch from f9c613d to 42bc51e Compare January 30, 2023 11:01
@espressif-bot espressif-bot added the Status: Opened Issue is new label Jan 30, 2023
@github-actions github-actions bot changed the title [Logs] print size and caps when malloc fails [Logs] print size and caps when malloc fails (IDFGH-9267) Jan 30, 2023
@espressif-bot espressif-bot added Status: Selected for Development Issue is selected for development and removed Status: Opened Issue is new labels Jan 31, 2023
@chipweinberger chipweinberger force-pushed the user/chip/malloc-fail-abort-string branch from 42bc51e to 526a73e Compare February 1, 2023 01:01
@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Selected for Development Issue is selected for development labels Feb 1, 2023
@chipweinberger chipweinberger force-pushed the user/chip/malloc-fail-abort-string branch from 526a73e to 910544c Compare February 1, 2023 11:04
@SoucheSouche
Copy link
Collaborator

@chipweinberger Thanks for the update. I will sync the PR if you don't plan on adding more changes.

@chipweinberger
Copy link
Contributor Author

all good! no more to change.

@SoucheSouche
Copy link
Collaborator

SoucheSouche commented Feb 9, 2023

@chipweinberger,
There seem to be an issue with this PR. The function fmt_abort_str() needs to placed in RAM as the caller heap_caps_alloc_failed() has to be placed in RAM as well. Unfortunately for us, itoa() is placed in flash on certain boards which makes it impossible to use in fmt_abort_str().

The only viable alternatives I can see here are:

  • implement ourselves print_hex() and print_dec() and put them in RAM, and lose available heap
  • drop the feature all together.

@chipweinberger
Copy link
Contributor Author

I'll update the PR. A simple function will suffice for hex.

// print a hex number to a buffer
void shex(char buf[8], uint32_t n) {
    for (int i = 0; i < 8; i++) {
        uint8_t b4 = (n >> 28 - (i * 4)) & 0b1111;
        buf[i] = b4 <= 9 ? '0' + b4 : 'a' + b4 - 10; 
    }
}

@chipweinberger
Copy link
Contributor Author

updated!

@chipweinberger chipweinberger force-pushed the user/chip/malloc-fail-abort-string branch 10 times, most recently from 7675b16 to 92b7149 Compare February 9, 2023 14:49
@chipweinberger chipweinberger force-pushed the user/chip/malloc-fail-abort-string branch from 92b7149 to f11256d Compare February 9, 2023 14:49
@chipweinberger
Copy link
Contributor Author

should be all good now. tested it.

@SoucheSouche
Copy link
Collaborator

@chipweinberger, I just merged this feature on our gitlab repository. It should be available in master on github in the next sync.

@espressif-bot espressif-bot added Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: In Progress Work is in progress Resolution: NA Issue resolution is unavailable labels Feb 13, 2023
@chipweinberger
Copy link
Contributor Author

appreciate your work on the PRs. thanks

@espressif-bot espressif-bot merged commit f11256d into espressif:master Feb 14, 2023
@chipweinberger chipweinberger deleted the user/chip/malloc-fail-abort-string branch May 20, 2023 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants