<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/84327>84327</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            TestPlatformConnect.py fails on AArch64 FreeBSD 14.0
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lldb,
            platform:freebsd
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          DavidSpickett
      </td>
    </tr>
</table>

<pre>
    ```
ec2-user@freebsd:~/llvm-project $ uname -a
FreeBSD freebsd 14.0-RELEASE-p5 FreeBSD 14.0-RELEASE-p5 #0: Tue Feb 13 23:49:05 UTC 2024 root@arm64-builder.daemonology.net:/usr/obj/usr/src/arm64.aarch64/sys/GENERIC arm64
```
This is running on an AWS Graviton instance, just in case hardware or virtualisation is a factor here.
```
********************
FAIL: lldb-api :: commands/platform/connect/TestPlatformConnect.py (22 of 2135)
******************** TEST 'lldb-api :: commands/platform/connect/TestPlatformConnect.py' FAILED ********************
Script:
--
/usr/local/bin/python3 /home/ec2-user/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env ARCHIVER=/usr/bin/llvm-ar --env OBJCOPY=/usr/bin/llvm-objcopy --env LLVM_LIBS_DIR=/home/ec2-user/build-llvm/./lib --env LLVM_INCLUDE_DIR=/home/ec2-user/build-llvm/include --env LLVM_TOOLS_DIR=/home/ec2-user/build-llvm/./bin --arch aarch64 --build-dir /home/ec2-user/build-llvm/lldb-test-build.noindex --lldb-module-cache-dir /home/ec2-user/build-llvm/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/ec2-user/build-llvm/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/ec2-user/build-llvm/./bin/lldb --compiler /home/ec2-user/build-llvm/./bin/clang --dsymutil /home/ec2-user/build-llvm/./bin/dsymutil --llvm-tools-dir /home/ec2-user/build-llvm/./bin --lldb-libs-dir /home/ec2-user/build-llvm/./lib /home/ec2-user/llvm-project/lldb/test/API/commands/platform/connect -p TestPlatformConnect.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 19.0.0git (https://github.com/llvm/llvm-project.git revision 52d5b8e02d258e4c32864eb1bb943cfae119b1d6)
  clang revision 52d5b8e02d258e4c32864eb1bb943cfae119b1d6
  llvm revision 52d5b8e02d258e4c32864eb1bb943cfae119b1d6
Skipping the following test categories: ['libc++', 'libstdcxx', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
failed to start gdbserver: timed out
SIGHUP received, exiting lldb-server...
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/ec2-user/build-llvm/bin/lldb-server platform --listen [::1]:0 --socket-file /home/ec2-user/build-llvm/lldb-test-build.noindex/commands/platform/connect/TestPlatformConnect.test_platform_process_connect/port -- /home/ec2-user/build-llvm/lldb-test-build.noindex/commands/platform/connect/TestPlatformConnect.test_platform_process_connect/a.out foo
#0 0x00000000008aab68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/ec2-user/build-llvm/bin/lldb-server+0x8aab68)
#1 0x00000000008a8a78 llvm::sys::RunSignalHandlers() (/home/ec2-user/build-llvm/bin/lldb-server+0x8a8a78)
#2 0x00000000008ab2a4 SignalHandler(int) Signals.cpp:0:0
#3 0x0000000083b10034 handle_signal /usr/src/lib/libthr/thread/thr_sig.c:0:3
FAIL: LLDB (/home/ec2-user/build-llvm/bin/clang-aarch64) :: test_platform_process_connect (TestPlatformConnect.TestPlatformProcessConnect)
======================================================================
FAIL: test_platform_process_connect (TestPlatformConnect.TestPlatformProcessConnect)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ec2-user/llvm-project/lldb/test/API/commands/platform/connect/TestPlatformConnect.py", line 44, in test_platform_process_connect
 lldbutil.run_break_set_by_symbol(self, "main")
  File "/home/ec2-user/llvm-project/lldb/packages/Python/lldbsuite/test/lldbutil.py", line 416, in run_break_set_by_symbol
    check_breakpoint_result(
 File "/home/ec2-user/llvm-project/lldb/packages/Python/lldbsuite/test/lldbutil.py", line 588, in check_breakpoint_result
 test.assertTrue(
AssertionError: False is not true : Expecting one or more locations, got none.
Config=aarch64-/home/ec2-user/build-llvm/bin/clang
----------------------------------------------------------------------
Ran 1 test in 10.382s

FAILED (failures=1)
```

It appears that the `lldb-server platform` never sees the port number that the `lldb-server gdbserver` writes to the pipe, despite the latter process getting as far as launching the inferior. Which as far as I can tell means it did write to the pipe or at least think it did.

I was not able to find a logic error and also found that you could work around this by building in debug mode (`-O0`) which feels like a race condition to me. Or perhaps an assumption lldb makes about pipe synchronisation that is only true for Linux.

Also, adding a single printf in a specific place in the code would make it work in a release+asserts build:
```
diff --git a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
index 0a832ebad13a..ada202e4ca34 100644
--- a/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
+++ b/lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
@@ -275,6 +275,7 @@ ProcessLauncherPosixFork::LaunchProcess(const ProcessLaunchInfo &launch_info,
   }
   if (pid == 0) {
     // child process
+ printf("Child process!\n"); fflush(stdout);
 pipe.CloseReadFileDescriptor();
 ChildFunc(pipe.ReleaseWriteFileDescriptor(), fork_launch_info);
 }
```
I guess this delays some step enough to make it work, but I could not figure out what.

I'm going to XFAIL this on AArch64 for the time being.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWUtz2zqy_jXwpossCqReCy9kyUp8y_fEZfs87soFgk0JMQiwANCPzf3tUw1SsuSxM0mcMzU1LkUhATTQ6MfXHyDhvdoYxFM2PmPj1Ynowta605V4UNVNq-Q9hnBS2ur5lE2y4ZOtWLZAyZPOo2NFVjvE0lcsX_w_42utH5qkdfYrygCMF9AZ0SAkopdbO8SzmxUMQjAq0iy5Pr88X9ycJ-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