Open Bug 1807043 Opened 2 years ago Updated 1 year ago

`firefox.exe -xpcshell` is broken on windows

Categories

(Core :: XPConnect, defect)

defect

Tracking

()

People

(Reporter: bhearsum, Unassigned)

References

Details

This appears to have been the case forever, per https://bugzilla.mozilla.org/show_bug.cgi?id=1238769#c8. I did some rudimentary debugging and I was surprised to find that while it didn't work with a regular opt build, as soon as I tried to attach a debugger in a debug build - it suddenly worked. In fact, even simply adding a printf statement at the beginning of ProcessArgs is enough to make it work in a debug build (but not opt). Because of this, I thought that it may be some sort of race - so I tried adding a 10 second sleep in the same spot, but again I couldn't reproduce in an opt build.

Given all of the above, it almost feels like something is getting optimized wrong, and breaking this somehow? But I am far from an expert here.

(The reason this is coming up now is because I was hoping to use this functionality to enable xpcshell tests against MSIX builds.)

What happens if you run firefox.exe -xpcshell script.js | cat?

(In reply to Mike Hommey [:glandium] from comment #1)

What happens if you run firefox.exe -xpcshell script.js | cat?

Oh, interesting. Maybe only interactive js is broken. I made foo.js with:

console.log("test test");

And ran:

.\firefox.exe -xpcshell foo.js | more

...and got:

console.log: "test test"

(I tried feeding it an xpcshell test as well - that didn't entirely work due to some things being undefined, but that's probably because head.js and whatever else needs to be run.)

So it's "just" the console setup. This also means that it should work properly out of the box on a debug build.

Try this:

diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp
index f03059aca1fc3..41735c288ff85 100644
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -60,6 +60,7 @@
 #  include "mozilla/ScopeExit.h"
 #  include "mozilla/widget/AudioSession.h"
 #  include "mozilla/WinDllServices.h"
+#  include "mozilla/WindowsConsole.h"
 #  include <windows.h>
 #  if defined(MOZ_SANDBOX)
 #    include "XREShellData.h"
@@ -1080,6 +1081,9 @@ int XRE_XPCShellMain(int argc, char** argv, char** envp,
   int result = 0;
   nsresult rv;
 
+#ifdef XP_WIN
+  UseParentConsole();
+#endif
 #ifdef ANDROID
   gOutFile = aShellData->outFile;
   gErrFile = aShellData->errFile;

(In reply to Mike Hommey [:glandium] from comment #4)

Try this:

diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp
index f03059aca1fc3..41735c288ff85 100644
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -60,6 +60,7 @@
 #  include "mozilla/ScopeExit.h"
 #  include "mozilla/widget/AudioSession.h"
 #  include "mozilla/WinDllServices.h"
+#  include "mozilla/WindowsConsole.h"
 #  include <windows.h>
 #  if defined(MOZ_SANDBOX)
 #    include "XREShellData.h"
@@ -1080,6 +1081,9 @@ int XRE_XPCShellMain(int argc, char** argv, char** envp,
   int result = 0;
   nsresult rv;
 
+#ifdef XP_WIN
+  UseParentConsole();
+#endif
 #ifdef ANDROID
   gOutFile = aShellData->outFile;
   gErrFile = aShellData->errFile;

Doesn't seem to help.

The Bugbug bot thinks this bug should belong to the 'Firefox::Installer' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: General → Installer

This isn't an installer issue.

I'm surprised :glandium's patch didn't address the issue; I'll try to take a look myself.

Component: Installer → General
Severity: -- → S4
Component: General → XPConnect
Product: Firefox → Core
You need to log in before you can comment on or make changes to this bug.