Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Disabled remote-debugging by default and appshell.app.getRemoteDebuggingPort() needs a callback argument to work #668

Merged
merged 6 commits into from
Nov 12, 2019

Conversation

g-217
Copy link
Contributor

@g-217 g-217 commented Nov 6, 2019

  • Disabling remote debugging by default, and it can be enabled by passing a command line arg as --remote-debugging-port=xxxx
  • Changed appshell.app.getRemoteDebuggingPort() implementation to require a callback
  • Added validation for port range, and also without remote-debugging-port we will not be able to debug brackets using a browser, and if browser debugging is disabled, appshell.app.getRemoteDebuggingPort(callback) will print 0

CefString debugger_port = command_line->GetSwitchValue("remote-debugging-port");
if (!debugger_port.empty()) {
int port = atoi(debugger_port.ToString().c_str());
static const int max_port_num = static_cast<int>(std::numeric_limits<uint16_t>::max());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the port is already in use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked with python -m SimpleHTTPServer 9999 and Brackets snatches the port from Python HTTP Server.

@@ -842,6 +842,8 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
uberDict->SetList(0, dirContents);
uberDict->SetList(1, allStats);
responseArgs->SetList(2, uberDict);
} else if (message_name == "GetRemoteDebuggingPort") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're changing the normal function to one that takes callback? Does this have any impact on existing usages? This is a breaking change, though I guess no extensions will ideally use this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does impact one use case, and fixed that with commit: adobe/brackets@8677756

CefString debugger_port = command_line->GetSwitchValue("remote-debugging-port");
if (!debugger_port.empty()) {
int port = atoi(debugger_port.ToString().c_str());
static const int max_port_num = static_cast<int>(std::numeric_limits<uint16_t>::max());
Copy link
Collaborator

@shubhsnov shubhsnov Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get away without needing limits header?
I am not comfortable with the need for unsetting standard functions.
You can compute uint16 max as such, which will work for all platforms

uint16_t max_limit = 0;
max_limit = ~max_limit;

Copy link
Contributor Author

@g-217 g-217 Nov 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::numeric_limits<> is C++ equivalent of C macros denoting MAX and MIN of a default numeric data types. So, instead of std::numeric_limits<uint16_t>::max(), I could use UINT16_MAX defined in stdint.h

uint16 max_limit = 0;
max_limit = ~max_limit;
max_limit = max_limit >> 1

Bitwise gymnastics suggested above is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't bother about header, it's C++, not JS.

@g-217
Copy link
Contributor Author

g-217 commented Nov 11, 2019

Addressed all the review comments.

@swmitra
Copy link
Collaborator

swmitra commented Nov 11, 2019

@vickramdhawal Can you please take a quick look?

@@ -82,7 +82,7 @@

#endif

#define REMOTE_DEBUGGING_PORT 9234
extern int g_remote_debugging_port;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed here ? use it in appshell_extensions.cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -19,6 +19,7 @@
#include "config.h"

CefRefPtr<ClientHandler> g_handler;
int g_remote_debugging_port = 0;
Copy link
Collaborator

@vickramdhawal vickramdhawal Nov 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use unsigned int.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since, we are going to use atom or strtol further, as suggested by you using int is better for comparisons.

Comment on lines 102 to 103
static const int max_port_num = 65535;
static const int max_reserved_port_num = 1024;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use unsigned int.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using strtol for integer parsing, so moved to signed long.

settings.remote_debugging_port = REMOTE_DEBUGGING_PORT;
CefString debugger_port = command_line->GetSwitchValue("remote-debugging-port");
if (!debugger_port.empty()) {
int port = atoi(debugger_port.ToString().c_str());
Copy link
Collaborator

@vickramdhawal vickramdhawal Nov 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using atoi seems acceptable in this case since the string is coming from the CommandLine handler. Better would be to use strtol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed parsing to use strtol.

…e to use g_handler to hold remote-debugging-port as g_handler does not get initialized while we are parsing command line
@g-217
Copy link
Contributor Author

g-217 commented Nov 11, 2019

@vickramdhawal Addressed review comments. It is not possible to use g_handler to hold remote-debugging-port as g_handler does not get initialized while we are parsing command line.

LOG(ERROR) << "Error while parsing remote-debugging-port arg: "<< debugger_port.ToString();
errno = 0;
}
static const long max_port_num = 65535;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of this should then be in the else case if errno is not ERANGE, since we know the port was not parsed properly and comparisons further may not give desired results.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Collaborator

@vickramdhawal vickramdhawal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :+1

Copy link
Collaborator

@swmitra swmitra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@swmitra swmitra merged commit fd8fce7 into adobe:master Nov 12, 2019
g-217 added a commit to g-217/brackets-shell that referenced this pull request Nov 18, 2019
…ingPort() needs a callback argument to work (adobe#668)

* Disabled remote-debugging by default and appshell.app.getRemoteDebuggingPort() needs a callback argument to work

* Addressing review comments

* Addressing review comments

* Updating error meesage for port validation

* Addressing review comments from vickramdhawal, also it is not possible to use g_handler to hold remote-debugging-port as g_handler does not get initialized while we are parsing command line

* More error message correction
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants