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

Is there a method for the terminal window to also receive the "segmentation fault (core dumped) ./a.exe" message? #293

Open
0BananaBig0 opened this issue Jan 25, 2025 · 6 comments

Comments

@0BananaBig0
Copy link

I found that if the segmentation fault occurred because of my bad code, the terminal window does not receive or display this information. Is there a method to address this issue?

#include <iostream>

class DerivedA {
   public:
      ~DerivedA() { delete this; };
};

class DerivedB {};

int main() {
   [[maybe_unused]] DerivedA a;
   return 0;
}
@skywind3000
Copy link
Owner

So what's wrong with this plugin? What command do you use?

@0BananaBig0
Copy link
Author

So what's wrong with this plugin? What command do you use?

I have tried both AsyncRun! -mode=term g++ ./a.cpp -o a.exe && ./a.exe and AsyncRun! -mode=async g++ ./a.cpp -o a.exe && ./a.exe. In theory, the output window should display [1] 3546 segmentation fault (core dumped) ./a.exe due to a double deletion in my code. However, nothing appears in the Vim output window. Is there a method to make the output window capture and display the segmentation fault information?

@0BananaBig0
Copy link
Author

So what's wrong with this plugin? What command do you use?

My async configuration:

  let g:asyncrun_bell = 1
  let g:asyncrun_save = 1
  let g:asyncrun_mode = 'term'

@0BananaBig0
Copy link
Author

Perhaps I know why the terminal doesn't receive "segmentation fault (core dumped) ./a.exe".
Recently, I have been learning about multi-process programs. If the parent process terminates before the child process, any messages sent by the child process may not be received by the terminal. This happens because the child's parent process ID (PPID) is reassigned to the init process, preventing the terminal from receiving its messages.
The following code example demonstrates this behavior:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>

int main() {
   int pid;
   pid = fork();

   /* Child process */
   if( pid == 0 ) {
      sleep( 1 );
      printf( "Child: pid is %d and ppid is %d\n", getpid(), getppid() );
   } else { /* Parent process */
      // sleep(1);
      printf( "Parent: pid is %d and ppid is %d\n", getpid(), getppid() );
   }
   return 0;
}

@0BananaBig0
Copy link
Author

However, the strange thing is that AsyncRun! -mode=async g++ ./a.cpp -o a.exe && ./a.exe can receive the complete output from the above code but does not receive [1] 3546 segmentation fault (core dumped) ./a.exe.

@0BananaBig0
Copy link
Author

However, the strange thing is that AsyncRun! -mode=async g++ ./a.cpp -o a.exe && ./a.exe can receive the complete output from the above code but does not receive [1] 3546 segmentation fault (core dumped) ./a.exe.

Quickfix can receive the complete output from the above code but does not receive [1] 3546 segmentation fault (core dumped) ./a.exe.
Term cannot receive either the complete output from the above code or [1] 3546 segmentation fault (core dumped) ./a.exe.

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

No branches or pull requests

2 participants