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

Fix the Mac debugger attachment on segfault #1386

Closed
jdeans289 opened this issue Nov 4, 2022 · 2 comments
Closed

Fix the Mac debugger attachment on segfault #1386

jdeans289 opened this issue Nov 4, 2022 · 2 comments
Assignees

Comments

@jdeans289
Copy link
Contributor

Currently, code to attach a debugger and dump a stack trace is failing on Mac. This has been useful in the past, but now is hanging and crashing terminals on Mac, so it has been removed. Investigate this issue and try to restore the stack trace on segfault.

This issue can be closed when:

  1. Stack traces can be dumped on Macs without hanging the terminal
  2. A test is written verifying this behavior (possibly, might be difficult since it would involve a segfault and using debuggers in github CI, but an attempt should be made
  • OR -
  1. It is determined that this is no longer possible or not fixable with a reasonable amount of work.
@jmpenn
Copy link
Contributor

jmpenn commented Jan 24, 2024

The problematic code referred-to (above) was removed from trick_source/sim_services/Executive/Executive_signal_handler.cpp
in commit 1cf4ef5 , associated with issue #1383.

72 #elif __APPLE__
73          char command[2048];
74          char path[1024] ;
75          uint32_t size = sizeof(path) ;
76          if (_NSGetExecutablePath(path, &size) == 0 ) {
77              if (attach_debugger == true) {
78                  write( 2 , "Attempting to attach debugger... standby.\n" , 41 ) ;
79                  sprintf(command, "%s -silent %s %d", debugger_command.c_str(), path, getpid());
80                  system(command);
81              } else if (stack_trace == true ) {
82                  write( 2 , "Attempting to generate stack trace... standby.\n" , 47 ) ;
83                  sprintf(command, "%s -batch -s ${TRICK_HOME}/share/trick/lldb_commands -p %d",
84                   debugger_command.c_str(), getpid());
85                 system(command);
86              }
87          }

@jmpenn
Copy link
Contributor

jmpenn commented Jan 24, 2024

The debugger_command string is set in Trick::Executive::Executive(), in Executive.cpp.

24    struct stat st ;
25    if ( stat("/usr/bin/gdb",&st) == 0 ) {
26        debugger_command = std::string("/usr/bin/gdb") ;
27    } else if ( stat("/usr/bin/lldb",&st) == 0 ) {
28        debugger_command = std::string("/usr/bin/lldb") ;
29    }

@jmpenn jmpenn self-assigned this Feb 6, 2024
jmpenn added a commit that referenced this issue Feb 27, 2024
sharmeye pushed a commit that referenced this issue Feb 27, 2024
@jmpenn jmpenn closed this as completed Mar 4, 2024
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