Closed
Bug 1399777
Opened 7 years ago
Closed 7 years ago
Fprinter should output to the Windows debug console when it outputs to stderr
Categories
(Core :: JavaScript Engine, enhancement, P5)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla58
Tracking | Status | |
---|---|---|
firefox58 | --- | fixed |
People
(Reporter: Yoric, Assigned: sourav.mukherjee619, Mentored)
Details
(Whiteboard: [good first bug][c++])
Attachments
(1 file)
In vm/Printer.*, we define several generic printers that are used among other things to display debugging information to stderr in DEBUG builds. Under Windows, stderr is not nearly as useful as the Windows Debugging console, so we should make sure that the data is duplicated there.
We can do this by patching `Fprinter::put` to:
(under Windows)
- check if `file_` is `stderr`;
- check if `IsDebuggerPresent()`;
- if so, copy the string and use `OutputDebugStringA` to pass it to the debugger.
Reporter | ||
Updated•7 years ago
|
Whiteboard: [good first bug][c++]
Updated•7 years ago
|
Priority: -- → P5
Assignee | ||
Comment 1•7 years ago
|
||
I want to work on this one.
Updated•7 years ago
|
Assignee: nobody → sourav.mukherjee619
Status: NEW → ASSIGNED
Comment hidden (mozreview-request) |
Reporter | ||
Comment 3•7 years ago
|
||
mozreview-review |
Comment on attachment 8908618 [details]
Bug 1399777 Fprinter directing output to Windows debug console when it outputs to stderr.
https://reviewboard.mozilla.org/r/180284/#review185436
::: js/src/vm/Printer.cpp:453
(Diff revision 1)
> int i = fwrite(s, /*size=*/ 1, /*nitems=*/ len, file_);
> if (size_t(i) != len) {
> reportOutOfMemory();
> return false;
> }
> +#ifdef WIN32
You could replace this with
```c++
#if defined(WIN32) && defined(DEBUG)
```
On the other hand, please use `XP_WIN32` instead of `WIN32`.
::: js/src/vm/Printer.cpp:455
(Diff revision 1)
> reportOutOfMemory();
> return false;
> }
> +#ifdef WIN32
> +#ifdef DEBUG
> + if(file_==stderr) {
Nit: `if (file_ == stderr) {` (with the whitespace).
::: js/src/vm/Printer.cpp:455
(Diff revision 1)
> reportOutOfMemory();
> return false;
> }
> +#ifdef WIN32
> +#ifdef DEBUG
> + if(file_==stderr) {
You also need to make sure that a debugger is present, as in the code you removed with your previous patch.
Use `IsDebuggerPresent()` for this.
::: js/src/vm/Printer.cpp:456
(Diff revision 1)
> return false;
> }
> +#ifdef WIN32
> +#ifdef DEBUG
> + if(file_==stderr) {
> + char *copy=js_strdup(s);
`OutputDebugStringA` expects the string to end with a `\0`, as is usual in C, but `put` doesn't guarantee that.
So you'd need to create an array of length `len + 1`, copy `len` bytes starting from `s`, then set the last byte to `0`.
::: js/src/vm/Printer.cpp:462
(Diff revision 1)
> + OutputDebugStringA(copy);
> + js_free(copy);
> + }
> +#endif
> +#endif
> return true;
Have you checked that it builds? You may need to include `<windows.h>`.
Comment hidden (mozreview-request) |
Reporter | ||
Comment 5•7 years ago
|
||
mozreview-review |
Comment on attachment 8908618 [details]
Bug 1399777 Fprinter directing output to Windows debug console when it outputs to stderr.
https://reviewboard.mozilla.org/r/180284/#review185538
::: js/src/vm/Printer.cpp:458
(Diff revisions 1 - 2)
> if (size_t(i) != len) {
> reportOutOfMemory();
> return false;
> }
> -#ifdef WIN32
> -#ifdef DEBUG
> +#ifdef XP_WIN32
> + if((file_ == stderr) && (IsDebuggerPresent()) ) {
Looks good, but could you addspaces after `,`, around `=` and `+`?
Also, could you use `PodCopy` (defined here: http://searchfox.org/mozilla-central/source/mfbt/PodOperations.h#97 ) instead of `std::copy`?
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Assignee | ||
Comment 8•7 years ago
|
||
Some jobs failed in the try server. All of them are intermittent test failure.
Does it mean there is a problem which I have to solve ? Or is it fine ?
Flags: needinfo?(dteller)
Reporter | ||
Comment 9•7 years ago
|
||
I have difficulties relaunching stuff on Try. I *think* that the problem are not caused by your code, but I'd like try to confirm my intuition. I'll keep you updated.
Flags: needinfo?(dteller)
Comment 10•7 years ago
|
||
mozreview-review |
Comment on attachment 8908618 [details]
Bug 1399777 Fprinter directing output to Windows debug console when it outputs to stderr.
https://reviewboard.mozilla.org/r/180284/#review186458
::: js/src/vm/Printer.cpp:22
(Diff revision 4)
> #include "jsutil.h"
>
> #include "ds/LifoAlloc.h"
>
> +#ifdef XP_WIN32
> +#include <windows.h>
Please use jswin.h to include windows.h (http://searchfox.org/mozilla-central/source/js/src/jswin.h)
::: js/src/vm/Printer.cpp:458
(Diff revision 4)
> if (size_t(i) != len) {
> reportOutOfMemory();
> return false;
> }
> +#ifdef XP_WIN32
> + if((file_ == stderr) && (IsDebuggerPresent()) ) {
Nit: extra whitespace and unneeded parentheses in `(IsDebuggerPresent()) )`.
::: js/src/vm/Printer.cpp:459
(Diff revision 4)
> reportOutOfMemory();
> return false;
> }
> +#ifdef XP_WIN32
> + if((file_ == stderr) && (IsDebuggerPresent()) ) {
> + char *cpy = (char *) js_malloc(len + 1);
You need to handle the case when `js_malloc` returns nullptr on OOM. For example like in http://searchfox.org/mozilla-central/rev/1c13d5cf85f904afb8976c02a80daa252b893fca/js/src/vm/Printer.cpp#131-135
Nit: SpiderMonkey style is to keep `*` next to the type, that means `char*` in the declaration and the cast.
::: js/src/vm/Printer.cpp:463
(Diff revision 4)
> + if((file_ == stderr) && (IsDebuggerPresent()) ) {
> + char *cpy = (char *) js_malloc(len + 1);
> + PodCopy(cpy, s, len);
> + cpy[len] = '\0';
> + OutputDebugStringA(cpy);
> + js_free(cpy);
Nit: You could use `UniqueChars buf(static_cast<char*>(js_malloc(len + 1)));`, that way you don't need to manually free the memory.
Attachment #8908618 -
Flags: review-
Comment 11•7 years ago
|
||
(In reply to André Bargull from comment #10)
> Nit: You could use `UniqueChars buf(static_cast<char*>(js_malloc(len +
> 1)));`, that way you don't need to manually free the memory.
s/buf/cpy/
Reporter | ||
Comment 12•7 years ago
|
||
Double-checked: try is now happy. Still, can you apply André's changes before we land this patch?
Flags: needinfo?(sourav.mukherjee619)
Comment hidden (mozreview-request) |
Assignee | ||
Comment 14•7 years ago
|
||
(In reply to David Teller [:Yoric] (please use "needinfo") from comment #12)
> Double-checked: try is now happy. Still, can you apply André's changes
> before we land this patch?
I have made the changes suggested and pushed them to the review.
Flags: needinfo?(sourav.mukherjee619)
Reporter | ||
Comment 15•7 years ago
|
||
mozreview-review |
Comment on attachment 8908618 [details]
Bug 1399777 Fprinter directing output to Windows debug console when it outputs to stderr.
https://reviewboard.mozilla.org/r/180284/#review187428
Looks good to me. Can you fix that last missing whitespace while I'm running it through our try server?
::: js/src/vm/Printer.cpp:460
(Diff revision 5)
> return false;
> }
> +#ifdef XP_WIN32
> + if((file_ == stderr) && (IsDebuggerPresent())) {
> + UniqueChars buf(static_cast<char*>(js_malloc(len + 1)));
> + if(!buf) {
Nit: `if (` (missing whitespace).
Attachment #8908618 -
Flags: review?(dteller) → review+
Comment hidden (mozreview-request) |
Reporter | ||
Comment 17•7 years ago
|
||
mozreview-review |
Comment on attachment 8908618 [details]
Bug 1399777 Fprinter directing output to Windows debug console when it outputs to stderr.
https://reviewboard.mozilla.org/r/180284/#review187502
Ah, a few more things before we can land this:
1/ your commit message contains too many `MozReview-Commit-ID`. Could you edit it to keep only the first one? Otherwise, I don't think AutoLander will let me land this;
2/ in reviewboard, could you mark as fixed all the issues that you have fixed?
Comment hidden (mozreview-request) |
Reporter | ||
Comment 19•7 years ago
|
||
Note: there is still one issue marked as unfixed.
Assignee | ||
Comment 20•7 years ago
|
||
(In reply to David Teller [:Yoric] (please use "needinfo") from comment #19)
> Note: there is still one issue marked as unfixed.
Sorry for missing it. Fixed it.
Comment 21•7 years ago
|
||
Pushed by dteller@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/83afa692da84
Fprinter directing output to Windows debug console when it outputs to stderr. r=Yoric
Comment 22•7 years ago
|
||
bugherder |
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
status-firefox58:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla58
Reporter | ||
Comment 23•7 years ago
|
||
Thanks for fixing this bug, sourav. Tell me if you need help finding another bug :)
Flags: needinfo?(sourav.mukherjee619)
Assignee | ||
Comment 24•7 years ago
|
||
(In reply to David Teller [:Yoric] (please use "needinfo") from comment #23)
> Thanks for fixing this bug, sourav. Tell me if you need help finding another
> bug :)
Thanks for mentoring me.
I need help finding another bug.
Flags: needinfo?(sourav.mukherjee619)
Reporter | ||
Comment 25•7 years ago
|
||
Would you be interested in bug 1403034? It's part of a larger set of cleanups we're doing in the code to avoid errors.
Flags: needinfo?(sourav.mukherjee619)
Reporter | ||
Comment 26•7 years ago
|
||
Ah, it's already taken, but other similar bugs of the same cleanup (bug 1277133) are still available.
Assignee | ||
Comment 27•7 years ago
|
||
(In reply to David Teller [:Yoric] (please use "needinfo") from comment #25)
> Would you be interested in bug 1403034? It's part of a larger set of
> cleanups we're doing in the code to avoid errors.
(In reply to David Teller [:Yoric] (please use "needinfo") from comment #26)
> Ah, it's already taken, but other similar bugs of the same cleanup (bug
> 1277133) are still available.
Both the bugs are taken by someone else. Can you find me another bug ?
Flags: needinfo?(sourav.mukherjee619)
You need to log in
before you can comment on or make changes to this bug.
Description
•