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

Add instruction to suppress SIGUSR1 in Posix with LLDB debugger #1245

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

bhoomrs
Copy link
Member

@bhoomrs bhoomrs commented Feb 12, 2025

Add instruction to suppress SIGUSR1 in Posix with LLDB debugger (macOS)

Description

While using the macOS default LLDB debugger, a call to vTaskEndScheduler results in an unhandled SIGUSR1 (aka SIGRESUME) when restoring the scheduler thread's signals with pthread_sigmask. This crashes the program.

Added instructions in portable/ThirdParty/GCC/Posix/port.c to suppress SIGUSR1 to prevent LLDB debugger interference when exiting xPortStartScheduler

Thanks to: @johnboiles for pointing it out in 1224

Test Steps

Tested with this example:

#include <FreeRTOS.h>
#include <task.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

void task_function(void *param) {
    ( void ) param;
    printf("FreeRTOS scheduler started\n");
    vTaskDelay(pdMS_TO_TICKS(1000));
    printf("Task Done, ending scheduler\n");
    vTaskEndScheduler();
    assert(0 && "After scheduler ended (SHOULD NOT GET HERE)");
}

int main_test() {
    TaskHandle_t task;
    xTaskCreate( task_function, "start", 10000, NULL, 1, &task );
    printf("Starting FreeRTOS scheduler\n");
    vTaskStartScheduler();
    printf("FreeRTOS scheduler exited\n");
    vTaskDelete(task);
    return 0;
}

Before the fix:

(lldb) pro la
Process 28916 launched: '/Users/johnboiles/Developer/repos/FreeRTOS/freertos-pr1224/build/freertos_posix_example' (arm64)
Starting FreeRTOS scheduler
FreeRTOS scheduler started
Task Done, ending scheduler
Process 28916 stopped and restarted: thread 1 received signal: SIGUSR1
Process 28916 exited with status = 30 (0x0000001e) Terminated due to signal 30

After the fix:

(lldb) run
Process 59557 launched: '/Users/bhoomrs/P3/FreeRTOS/FreeRTOS/Demo/Posix_GCC/build/posix_demo' (arm64)

Trace started.
The trace will be dumped to disk if a call to configASSERT() fails.
Starting full demo
Starting FreeRTOS scheduler
FreeRTOS scheduler started
Task Done, ending scheduler
FreeRTOS scheduler exited
Process 59557 exited with status = 0 (0x00000000) 

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

#1224

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@bhoomrs bhoomrs requested a review from a team as a code owner February 12, 2025 09:08
@bhoomrs bhoomrs changed the title Add instruction to suppress SIGUSR1 in Posix with lldb debugger Add instruction to suppress SIGUSR1 in Posix with LLDB debugger Feb 12, 2025
@bhoomrs bhoomrs merged commit 51a1598 into FreeRTOS:main Feb 12, 2025
17 checks passed
* Note: When using LLDB (the default debugger on macOS) with this port,
* suppress SIGUSR1 to prevent debugger interference. This can be
* done by adding the following line to ~/.lldbinit:
* `process handle SIGUSR1 -n true -p true -s false`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still does not work for me. I had to set both PASS and STOP to false. NOTIFY had no effect for me

process handle SIGUSR1 -p false -s false
> echo 'process handle SIGUSR1 -n true -p true -s false' > ~/.lldbinit
> lldb build/freertos_posix_example
NAME         PASS     STOP     NOTIFY
===========  =======  =======  =======
SIGUSR1      true     false    true
(lldb) target create "build/freertos_posix_example"
Current executable set to '/Users/johnboiles/Developer/repos/FreeRTOS/freertos-pr1224/build/freertos_posix_example' (arm64).
(lldb) pro la
Process 92245 launched: '/Users/johnboiles/Developer/repos/FreeRTOS/freertos-pr1224/build/freertos_posix_example' (arm64)
Starting FreeRTOS scheduler
FreeRTOS scheduler started
Task Done, ending scheduler
Process 92245 stopped and restarted: thread 1 received signal: SIGUSR1
Process 92245 exited with status = 30 (0x0000001e) Terminated due to signal 30
(lldb) ^D
> echo 'process handle SIGUSR1 -p false -s false' > ~/.lldbinit
> lldb build/freertos_posix_example
NAME         PASS     STOP     NOTIFY
===========  =======  =======  =======
SIGUSR1      false    false    not set
(lldb) target create "build/freertos_posix_example"
Current executable set to '/Users/johnboiles/Developer/repos/FreeRTOS/freertos-pr1224/build/freertos_posix_example' (arm64).
(lldb) pro la
Process 24334 launched: '/Users/johnboiles/Developer/repos/FreeRTOS/freertos-pr1224/build/freertos_posix_example' (arm64)
Starting FreeRTOS scheduler
FreeRTOS scheduler started
Task Done, ending scheduler
Process 24334 stopped and restarted: thread 1 received signal: SIGUSR1
FreeRTOS scheduler exited
Process 24334 exited with status = 0 (0x00000000)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, yes. That seems right! Will update that, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants