Skip to content

Commit 003e085

Browse files
cjihrigBethGriggs
authored andcommitted
report: add cwd to report
The diagnostic report currently contains command line information, and the environment, which contains the PWD environment variable. This combination covers the majority of cases, but it would be useful to have the result of uv_cwd() as an additional data point. This commit adds that information. PR-URL: #27022 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>
1 parent 4d06ef4 commit 003e085

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

doc/api/report.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ is provided below for reference.
2828
"dumpEventTime": "2018-12-21T00:50:11Z",
2929
"dumpEventTimeStamp": "1545371411331",
3030
"processId": 8974,
31+
"cwd": "/home/nodeuser/project/node",
3132
"commandLine": [
3233
"/home/nodeuser/project/node/out/Release/node",
3334
"--experimental-report",

src/node_report.cc

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
#include <atomic>
1919
#include <fstream>
2020
#include <iomanip>
21+
#include <climits> // PATH_MAX
22+
23+
#ifdef _WIN32
24+
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
25+
#define PATH_MAX_BYTES (MAX_PATH * 4)
26+
#else
27+
#define PATH_MAX_BYTES (PATH_MAX)
28+
#endif
2129

2230
#ifndef _WIN32
2331
extern char** environ;
@@ -213,6 +221,14 @@ static void WriteNodeReport(Isolate* isolate,
213221
// Report native process ID
214222
writer.json_keyvalue("processId", pid);
215223

224+
{
225+
// Report the process cwd.
226+
char buf[PATH_MAX_BYTES];
227+
size_t cwd_size = sizeof(buf);
228+
if (uv_cwd(buf, &cwd_size) == 0)
229+
writer.json_keyvalue("cwd", buf);
230+
}
231+
216232
// Report out the command line.
217233
if (!node::per_process::cli_options->cmdline.empty()) {
218234
writer.json_arraystart("commandLine");

test/common/report.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function _validateContent(data) {
6363
'nodejsVersion', 'wordSize', 'arch', 'platform',
6464
'componentVersions', 'release', 'osName', 'osRelease',
6565
'osVersion', 'osMachine', 'host', 'glibcVersionRuntime',
66-
'glibcVersionCompiler'];
66+
'glibcVersionCompiler', 'cwd'];
6767
checkForUnknownFields(header, headerFields);
6868
assert.strictEqual(typeof header.event, 'string');
6969
assert.strictEqual(typeof header.trigger, 'string');
@@ -76,6 +76,7 @@ function _validateContent(data) {
7676
assert(String(+header.dumpEventTimeStamp), header.dumpEventTimeStamp);
7777

7878
assert(Number.isSafeInteger(header.processId));
79+
assert.strictEqual(typeof header.cwd, 'string');
7980
assert(Array.isArray(header.commandLine));
8081
header.commandLine.forEach((arg) => {
8182
assert.strictEqual(typeof arg, 'string');

0 commit comments

Comments
 (0)